From b66a37a8e2a2d17304b049232ea5d7ac8c8d5da2 Mon Sep 17 00:00:00 2001 From: Subrahmanya Manikanta Venkateswarlu Bhamidipati Kameswara Sri Date: Mon, 26 Feb 2024 19:23:44 +0000 Subject: [PATCH] Fixed issue converting Asn1 time to posix on 32-bit systems. Used ASN1_TIME_to_posix API instead of ASN1_TIME_to_time_t to avoid integer overflow on 32-bit systems. Bug: 325853206 Test: vts -m VtsAidlKeyMintTarget Change-Id: I7a01a521d389482a61ad9974b7e40eaa099c3571 --- security/keymint/aidl/vts/functional/KeyMintTest.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/security/keymint/aidl/vts/functional/KeyMintTest.cpp b/security/keymint/aidl/vts/functional/KeyMintTest.cpp index a8f41c3d6a..9575183087 100644 --- a/security/keymint/aidl/vts/functional/KeyMintTest.cpp +++ b/security/keymint/aidl/vts/functional/KeyMintTest.cpp @@ -1086,6 +1086,7 @@ TEST_P(NewKeyGenerationTest, RsaWithSpecifiedValidity) { }; for (auto notBefore : test_vector_not_before_millis) { uint64_t notAfter = notBefore + 378691200000 /* 12 years milliseconds*/; + SCOPED_TRACE(testing::Message() << "notBefore: " << notBefore << " notAfter: " << notAfter); ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder() .RsaSigningKey(2048, 65537) @@ -1101,14 +1102,14 @@ TEST_P(NewKeyGenerationTest, RsaWithSpecifiedValidity) { const ASN1_TIME* not_before = X509_get0_notBefore(cert.get()); ASSERT_NE(not_before, nullptr); - time_t not_before_time; - ASSERT_EQ(ASN1_TIME_to_time_t(not_before, ¬_before_time), 1); + int64_t not_before_time; + ASSERT_EQ(ASN1_TIME_to_posix(not_before, ¬_before_time), 1); EXPECT_EQ(not_before_time, (notBefore / 1000)); const ASN1_TIME* not_after = X509_get0_notAfter(cert.get()); ASSERT_NE(not_after, nullptr); - time_t not_after_time; - ASSERT_EQ(ASN1_TIME_to_time_t(not_after, ¬_after_time), 1); + int64_t not_after_time; + ASSERT_EQ(ASN1_TIME_to_posix(not_after, ¬_after_time), 1); EXPECT_EQ(not_after_time, (notAfter / 1000)); } }