Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e1560216 authored by Subrahmanyaman's avatar Subrahmanyaman Committed by Subrahmanya Manikanta Venkateswarlu Bhamidipati Kameswara Sri
Browse files

Test to validate a range of certificate validity times.

Bug: 280624515
Test: run VtsAidlKeyMintTarget
Change-Id: Id315c28e2ea114c5c39e235d3ee6be2a0d8bfa71
parent e2955b27
Loading
Loading
Loading
Loading
+44 −23
Original line number Diff line number Diff line
@@ -1064,15 +1064,35 @@ TEST_P(NewKeyGenerationTest, RsaWithMissingValidity) {
TEST_P(NewKeyGenerationTest, RsaWithSpecifiedValidity) {
    vector<uint8_t> key_blob;
    vector<KeyCharacteristics> key_characteristics;
    vector<uint64_t> test_vector_not_before_millis = {
            458046000000,    /* 1984-07-07T11:00:00Z */
            1183806000000,   /* 2007-07-07T11:00:00Z */
            1924991999000,   /* 2030-12-31T23:59:59Z */
            3723753599000,   /* 2087-12-31T23:59:59Z */
            26223868799000,  /* 2800-12-31T23:59:59Z */
            45157996799000,  /* 3400-12-31T23:59:59Z */
            60719587199000,  /* 3894-02-15T23:59:59Z */
            95302051199000,  /* 4989-12-31T23:59:59Z */
            86182012799000,  /* 4700-12-31T23:59:59Z */
            111427574399000, /* 5500-12-31T23:59:59Z */
            136988668799000, /* 6310-12-31T23:59:59Z */
            139828895999000, /* 6400-12-31T23:59:59Z */
            169839503999000, /* 7351-12-31T23:59:59Z */
            171385804799000, /* 7400-12-31T23:59:59Z */
            190320019199000, /* 8000-12-31T23:59:59Z */
            193475692799000, /* 8100-12-31T23:59:59Z */
            242515209599000, /* 9654-12-31T23:59:59Z */
            250219065599000, /* 9899-02-15T23:59:59Z */
    };
    for (auto notBefore : test_vector_not_before_millis) {
        uint64_t notAfter = notBefore + 378691200000 /* 12 years milliseconds*/;
        ASSERT_EQ(ErrorCode::OK,
                  GenerateKey(AuthorizationSetBuilder()
                                      .RsaSigningKey(2048, 65537)
                                      .Digest(Digest::NONE)
                                      .Padding(PaddingMode::NONE)
                                  .Authorization(TAG_CERTIFICATE_NOT_BEFORE,
                                                 1183806000000 /* 2007-07-07T11:00:00Z */)
                                  .Authorization(TAG_CERTIFICATE_NOT_AFTER,
                                                 1916049600000 /* 2030-09-19T12:00:00Z */),
                                      .Authorization(TAG_CERTIFICATE_NOT_BEFORE, notBefore)
                                      .Authorization(TAG_CERTIFICATE_NOT_AFTER, notAfter),
                              &key_blob, &key_characteristics));
        ASSERT_GT(cert_chain_.size(), 0);

@@ -1083,13 +1103,14 @@ TEST_P(NewKeyGenerationTest, RsaWithSpecifiedValidity) {
        ASSERT_NE(not_before, nullptr);
        time_t not_before_time;
        ASSERT_EQ(ASN1_TIME_to_time_t(not_before, &not_before_time), 1);
    EXPECT_EQ(not_before_time, 1183806000);
        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, &not_after_time), 1);
    EXPECT_EQ(not_after_time, 1916049600);
        EXPECT_EQ(not_after_time, (notAfter / 1000));
    }
}

/*