File 1158-public_key-Follow-RFC-5280-validity-formatting.patch of Package erlang

From e6b9ccc959982b10e81b623ede6ce98363dc1119 Mon Sep 17 00:00:00 2001
From: Ingela Anderton Andin <ingela@erlang.org>
Date: Fri, 15 Jan 2021 09:47:28 +0100
Subject: [PATCH] public_key: Follow RFC-5280 validity formatting

---
 lib/public_key/src/pubkey_cert.erl | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/lib/public_key/src/pubkey_cert.erl b/lib/public_key/src/pubkey_cert.erl
index 5f8a5bd530..e84edffd53 100644
--- a/lib/public_key/src/pubkey_cert.erl
+++ b/lib/public_key/src/pubkey_cert.erl
@@ -1170,13 +1170,28 @@ validity(Opts) ->
     DefFrom0 = calendar:gregorian_days_to_date(calendar:date_to_gregorian_days(date())-1),
     DefTo0   = calendar:gregorian_days_to_date(calendar:date_to_gregorian_days(date())+7),
     {DefFrom, DefTo} = proplists:get_value(validity, Opts, {DefFrom0, DefTo0}),
-    Format =
+    
+    GenFormat =
         fun({Y,M,D}) ->
                 lists:flatten(
                   io_lib:format("~4..0w~2..0w~2..0w130000Z",[Y,M,D]))
         end,
-    #'Validity'{notBefore={generalTime, Format(DefFrom)},
-		notAfter ={generalTime, Format(DefTo)}}.
+    
+    UTCFormat =
+        fun({Y,M,D}) ->
+                [_, _, Y3, Y4] = integer_to_list(Y),
+                lists:flatten(
+                  io_lib:format("~s~2..0w~2..0w130000Z",[[Y3, Y4],M,D]))
+        end,
+    
+    #'Validity'{notBefore = validity_format(DefFrom, GenFormat, UTCFormat),
+                notAfter = validity_format(DefTo, GenFormat, UTCFormat)}.
+
+validity_format({Year, _, _} = Validity, GenFormat, _UTCFormat) when Year >= 2049 ->
+    {generalTime, GenFormat(Validity)};
+validity_format(Validity, _GenFormat, UTCFormat) ->
+    {utcTime, UTCFormat(Validity)}.
+
 
 sign_algorithm(#'RSAPrivateKey'{}, Opts) ->
     Type = rsa_digest_oid(proplists:get_value(digest, Opts, sha1)),
-- 
2.26.2

openSUSE Build Service is sponsored by