Some more OpenSSL 1.1.0 compat APIs
authorAnirudh Ramachandran <avr@fb.com>
Fri, 9 Jun 2017 06:06:24 +0000 (23:06 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 9 Jun 2017 06:08:32 +0000 (23:08 -0700)
Summary: Add a few more compatibility wrappers for pre-1.1.0 APIs

Reviewed By: yfeldblum

Differential Revision: D5194164

fbshipit-source-id: ae8db08c31370eca729df2927798b6f4d99ee70c

folly/portability/OpenSSL.cpp
folly/portability/OpenSSL.h

index ccaea7657fd32ff312dacfdf787ed6eb61229901..7fdb7b7264d3cd8a7e2db6a75e3c07a81bd6c3e9 100644 (file)
@@ -62,6 +62,40 @@ int SSL_SESSION_up_ref(SSL_SESSION* session) {
 int X509_up_ref(X509* x) {
   return CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509);
 }
+
+int EVP_PKEY_up_ref(EVP_PKEY* evp) {
+  return CRYPTO_add(&evp->references, 1, CRYPTO_LOCK_EVP_PKEY);
+}
+
+void RSA_get0_key(
+    const RSA* r,
+    const BIGNUM** n,
+    const BIGNUM** e,
+    const BIGNUM** d) {
+  if (n != nullptr) {
+    *n = r->n;
+  }
+  if (e != nullptr) {
+    *e = r->e;
+  }
+  if (d != nullptr) {
+    *d = r->d;
+  }
+}
+
+RSA* EVP_PKEY_get0_RSA(EVP_PKEY* pkey) {
+  if (pkey->type != EVP_PKEY_RSA) {
+    return nullptr;
+  }
+  return pkey->pkey.rsa;
+}
+
+EC_KEY* EVP_PKEY_get0_EC_KEY(EVP_PKEY* pkey) {
+  if (pkey->type != EVP_PKEY_EC) {
+    return nullptr;
+  }
+  return pkey->pkey.ec;
+}
 #endif
 
 #if !FOLLY_OPENSSL_IS_110
index 38ebc8e71ca399130590a5b401690ebca46ef152..7fee24fa583d36b257803f07dada66a66629f278 100644 (file)
@@ -108,6 +108,14 @@ int X509_get_signature_nid(X509* cert);
 int SSL_CTX_up_ref(SSL_CTX* session);
 int SSL_SESSION_up_ref(SSL_SESSION* session);
 int X509_up_ref(X509* x);
+int EVP_PKEY_up_ref(EVP_PKEY* evp);
+void RSA_get0_key(
+    const RSA* r,
+    const BIGNUM** n,
+    const BIGNUM** e,
+    const BIGNUM** d);
+RSA* EVP_PKEY_get0_RSA(EVP_PKEY* pkey);
+EC_KEY* EVP_PKEY_get0_EC_KEY(EVP_PKEY* pkey);
 #endif
 
 #if !FOLLY_OPENSSL_IS_110