From: Mingtao Yang Date: Fri, 28 Jul 2017 16:57:24 +0000 (-0700) Subject: Add X509_REVOKED_get0_* OpenSSL shims X-Git-Tag: v2017.07.31.00~15 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=commitdiff_plain;h=45245cb293e3c61deb8b952956507b62e88b0cf9 Add X509_REVOKED_get0_* OpenSSL shims Reviewed By: yfeldblum Differential Revision: D5509756 fbshipit-source-id: 0b9581dafb073c5e3e5a229c032c6cf272ceb2e0 --- diff --git a/folly/portability/OpenSSL.cpp b/folly/portability/OpenSSL.cpp index 5de51036..7a888e2c 100644 --- a/folly/portability/OpenSSL.cpp +++ b/folly/portability/OpenSSL.cpp @@ -392,6 +392,14 @@ void OPENSSL_cleanup() { ERR_clear_error(); } +const ASN1_INTEGER* X509_REVOKED_get0_serialNumber(const X509_REVOKED* r) { + return r->serialNumber; +} + +const ASN1_TIME* X509_REVOKED_get0_revocationDate(const X509_REVOKED* r) { + return r->revocationDate; +} + #endif // !FOLLY_OPENSSL_IS_110 } } diff --git a/folly/portability/OpenSSL.h b/folly/portability/OpenSSL.h index c1ed8c64..353ace8e 100644 --- a/folly/portability/OpenSSL.h +++ b/folly/portability/OpenSSL.h @@ -173,6 +173,9 @@ using OPENSSL_INIT_SETTINGS = void; int OPENSSL_init_ssl(uint64_t opts, const OPENSSL_INIT_SETTINGS* settings); void OPENSSL_cleanup(); +const ASN1_INTEGER* X509_REVOKED_get0_serialNumber(const X509_REVOKED* r); +const ASN1_TIME* X509_REVOKED_get0_revocationDate(const X509_REVOKED* r); + #endif #if FOLLY_OPENSSL_IS_110 diff --git a/folly/portability/test/OpenSSLPortabilityTest.cpp b/folly/portability/test/OpenSSLPortabilityTest.cpp index a0cdc607..731b3058 100644 --- a/folly/portability/test/OpenSSLPortabilityTest.cpp +++ b/folly/portability/test/OpenSSLPortabilityTest.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#include + #include #include @@ -75,3 +77,33 @@ TEST(OpenSSLPortabilityTest, TestEcdsaSigPortability) { EXPECT_FALSE(BN_cmp(r, r_actual)); EXPECT_FALSE(BN_cmp(s, s_actual)); } + +TEST(OpenSSLPortabilityTest, TestX509RevokedApi) { + X509_REVOKED* rev = X509_REVOKED_new(); + + ASN1_INTEGER* serial = ASN1_INTEGER_new(); + ASN1_INTEGER_set(serial, 1234L); + + ASN1_TIME* revocation_date = ASN1_TIME_new(); + time_t t = time(nullptr); + ASN1_TIME_set(revocation_date, t); + + X509_REVOKED_set_serialNumber(rev, serial); + X509_REVOKED_set_revocationDate(rev, revocation_date); + + const ASN1_INTEGER* retrieved_serial = X509_REVOKED_get0_serialNumber(rev); + const ASN1_TIME* retrieved_date = X509_REVOKED_get0_revocationDate(rev); + + EXPECT_EQ(0, ASN1_INTEGER_cmp(serial, retrieved_serial)); + + int diff_days; + int diff_secs; + + ASN1_TIME_diff(&diff_days, &diff_secs, revocation_date, retrieved_date); + EXPECT_EQ(0, diff_days); + EXPECT_EQ(0, diff_secs); + + ASN1_INTEGER_free(serial); + ASN1_TIME_free(revocation_date); + X509_REVOKED_free(rev); +}