Add X509_REVOKED_get0_* OpenSSL shims
authorMingtao Yang <mingtao@fb.com>
Fri, 28 Jul 2017 16:57:24 +0000 (09:57 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 28 Jul 2017 17:08:37 +0000 (10:08 -0700)
Reviewed By: yfeldblum

Differential Revision: D5509756

fbshipit-source-id: 0b9581dafb073c5e3e5a229c032c6cf272ceb2e0

folly/portability/OpenSSL.cpp
folly/portability/OpenSSL.h
folly/portability/test/OpenSSLPortabilityTest.cpp

index 5de51036fb2e0291323f69ad67c34f1c79fd24e1..7a888e2c51a7c480ad8b40e6587df2115ebacd15 100644 (file)
@@ -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
 }
 }
index c1ed8c64612924c7de3f1f24a1fba22250151b3c..353ace8e2ded534c1dd4c289a4649160e104e69f 100644 (file)
@@ -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
index a0cdc60752e3c4ddc53133c37bda8636980dcee9..731b3058f77753386d066688077440d2cfaace08 100644 (file)
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+#include <ctime>
+
 #include <folly/portability/GTest.h>
 #include <folly/ssl/OpenSSLPtrTypes.h>
 
@@ -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);
+}