From: Zbigniew Jędrzejewski-Szmek Date: Fri, 1 Dec 2023 09:36:04 +0000 (+0100) Subject: ukify: avoid deprecated datetime call X-Git-Tag: v255-rc4~14 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=24baee337038af93e8abe754aad2d47d5ddc263c;p=thirdparty%2Fsystemd.git ukify: avoid deprecated datetime call DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC). The difference between the two is that .now(datetime.UTC) returns an object with a timezone attached, "the numbers" are the same. >>> datetime.datetime.utcnow(), datetime.datetime.now(datetime.UTC) (datetime.datetime(2023, 12, 1, 9, 37, 53, 891669), datetime.datetime(2023, 12, 1, 9, 37, 53, 891688, tzinfo=datetime.timezone.utc)) This value is fed to cryptography's x509.CertificateBuilder object, so as long as it can accept a datetime object with tzinfo, the result should be identical. --- diff --git a/src/ukify/ukify.py b/src/ukify/ukify.py index 08f505a2715..b46d775a476 100755 --- a/src/ukify/ukify.py +++ b/src/ukify/ukify.py @@ -874,7 +874,7 @@ def generate_key_cert_pair( # supported/expected: # https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/windows-secure-boot-key-creation-and-management-guidance?view=windows-11#12-public-key-cryptography - now = datetime.datetime.utcnow() + now = datetime.datetime.now(datetime.UTC) key = rsa.generate_private_key( public_exponent=65537,