Commit 37ce6072 authored by Fred Emmott's avatar Fred Emmott Committed by Facebook Github Bot

Add some more OpenSSL 1.1 APIs for folly/portability/

Summary: refs hhvm/packaging#128

Reviewed By: anirudhvr

Differential Revision: D5380271

fbshipit-source-id: 1cc206d9970b843c3582556096f3ceabeb8d01f6
parent d94e4de5
......@@ -90,6 +90,20 @@ RSA* EVP_PKEY_get0_RSA(EVP_PKEY* pkey) {
return pkey->pkey.rsa;
}
DSA* EVP_PKEY_get0_DSA(EVP_PKEY* pkey) {
if (pkey->type != EVP_PKEY_DSA) {
return nullptr;
}
return pkey->pkey.dsa;
}
DH* EVP_PKEY_get0_DH(EVP_PKEY* pkey) {
if (pkey->type != EVP_PKEY_DH) {
return nullptr;
}
return pkey->pkey.dh;
}
EC_KEY* EVP_PKEY_get0_EC_KEY(EVP_PKEY* pkey) {
if (pkey->type != EVP_PKEY_EC) {
return nullptr;
......@@ -163,6 +177,66 @@ int DH_set0_pqg(DH* dh, BIGNUM* p, BIGNUM* q, BIGNUM* g) {
return 1;
}
void DH_get0_pqg(
const DH* dh,
const BIGNUM** p,
const BIGNUM** q,
const BIGNUM** g) {
// Based off of https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes
if (p != nullptr) {
*p = dh->p;
}
if (q != nullptr) {
*q = dh->q;
}
if (g != nullptr) {
*g = dh->g;
}
}
void DH_get0_key(
const DH* dh,
const BIGNUM** pub_key,
const BIGNUM** priv_key) {
// Based off of https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes
if (pub_key != nullptr) {
*pub_key = dh->pub_key;
}
if (priv_key != nullptr) {
*priv_key = dh->priv_key;
}
}
void DSA_get0_pqg(
const DSA* dsa,
const BIGNUM** p,
const BIGNUM** q,
const BIGNUM** g) {
// Based off of https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes
if (p != nullptr) {
*p = dsa->p;
}
if (q != nullptr) {
*q = dsa->q;
}
if (g != nullptr) {
*g = dsa->g;
}
}
void DSA_get0_key(
const DSA* dsa,
const BIGNUM** pub_key,
const BIGNUM** priv_key) {
// Based off of https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes
if (pub_key != nullptr) {
*pub_key = dsa->pub_key;
}
if (priv_key != nullptr) {
*priv_key = dsa->priv_key;
}
}
X509* X509_STORE_CTX_get0_cert(X509_STORE_CTX* ctx) {
return ctx->cert;
}
......@@ -210,9 +284,9 @@ void HMAC_CTX_free(HMAC_CTX* ctx) {
bool RSA_set0_key(RSA* r, BIGNUM* n, BIGNUM* e, BIGNUM* d) {
// Based off of https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes
/**
* If the fields n and e in r are NULL, the corresponding input parameters
* MUST be non-NULL for n and e. d may be left NULL (in case only the public
* key is used).
* If the fields n and e in r are nullptr, the corresponding input parameters
* MUST be non-nullptr for n and e. d may be left NULL (in case only the
* public key is used).
*/
if ((r->n == nullptr && n == nullptr) || (r->e == nullptr && e == nullptr)) {
return false;
......@@ -232,6 +306,33 @@ bool RSA_set0_key(RSA* r, BIGNUM* n, BIGNUM* e, BIGNUM* d) {
return true;
}
void RSA_get0_factors(const RSA* r, const BIGNUM** p, const BIGNUM** q) {
// Based off of https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes
if (p != nullptr) {
*p = r->p;
}
if (q != nullptr) {
*q = r->q;
}
}
void RSA_get0_crt_params(
const RSA* r,
const BIGNUM** dmp1,
const BIGNUM** dmq1,
const BIGNUM** iqmp) {
// Based off of https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes
if (dmp1 != nullptr) {
*dmp1 = r->dmp1;
}
if (dmq1 != nullptr) {
*dmq1 = r->dmq1;
}
if (iqmp != nullptr) {
*iqmp = r->iqmp;
}
}
#endif
}
}
......
......@@ -115,6 +115,8 @@ void RSA_get0_key(
const BIGNUM** e,
const BIGNUM** d);
RSA* EVP_PKEY_get0_RSA(EVP_PKEY* pkey);
DSA* EVP_PKEY_get0_DSA(EVP_PKEY* pkey);
DH* EVP_PKEY_get0_DH(EVP_PKEY* pkey);
EC_KEY* EVP_PKEY_get0_EC_KEY(EVP_PKEY* pkey);
#endif
......@@ -135,11 +137,33 @@ void HMAC_CTX_free(HMAC_CTX* ctx);
unsigned long SSL_SESSION_get_ticket_lifetime_hint(const SSL_SESSION* s);
int SSL_SESSION_has_ticket(const SSL_SESSION* s);
int DH_set0_pqg(DH* dh, BIGNUM* p, BIGNUM* q, BIGNUM* g);
void DH_get0_pqg(
const DH* dh,
const BIGNUM** p,
const BIGNUM** q,
const BIGNUM** g);
void DH_get0_key(const DH* dh, const BIGNUM** pub_key, const BIGNUM** priv_key);
void DSA_get0_pqg(
const DSA* dsa,
const BIGNUM** p,
const BIGNUM** q,
const BIGNUM** g);
void DSA_get0_key(
const DSA* dsa,
const BIGNUM** pub_key,
const BIGNUM** priv_key);
X509* X509_STORE_CTX_get0_cert(X509_STORE_CTX* ctx);
STACK_OF(X509) * X509_STORE_CTX_get0_chain(X509_STORE_CTX* ctx);
STACK_OF(X509) * X509_STORE_CTX_get0_untrusted(X509_STORE_CTX* ctx);
bool RSA_set0_key(RSA* r, BIGNUM* n, BIGNUM* e, BIGNUM* d);
void RSA_get0_factors(const RSA* r, const BIGNUM** p, const BIGNUM** q);
void RSA_get0_crt_params(
const RSA* r,
const BIGNUM** dmp1,
const BIGNUM** dmq1,
const BIGNUM** iqmp);
#endif
#if FOLLY_OPENSSL_IS_110
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment