proxygen
folly::portability::ssl Namespace Reference

Typedefs

using OPENSSL_INIT_SETTINGS = void
 

Functions

BIO_METHOD * BIO_meth_new (int type, const char *name)
 
void BIO_meth_free (BIO_METHOD *biom)
 
int BIO_meth_set_read (BIO_METHOD *biom, int(*read)(BIO *, char *, int))
 
int BIO_meth_set_write (BIO_METHOD *biom, int(*write)(BIO *, const char *, int))
 
int BIO_meth_set_puts (BIO_METHOD *biom, int(*bputs)(BIO *, const char *))
 
int BIO_meth_set_gets (BIO_METHOD *biom, int(*bgets)(BIO *, char *, int))
 
int BIO_meth_set_ctrl (BIO_METHOD *biom, long(*ctrl)(BIO *, int, long, void *))
 
int BIO_meth_set_create (BIO_METHOD *biom, int(*create)(BIO *))
 
int BIO_meth_set_destroy (BIO_METHOD *biom, int(*destroy)(BIO *))
 
void BIO_set_data (BIO *bio, void *ptr)
 
void * BIO_get_data (BIO *bio)
 
void BIO_set_init (BIO *bio, int init)
 
void BIO_set_shutdown (BIO *bio, int shutdown)
 
const SSL_METHOD * TLS_server_method (void)
 
const SSL_METHOD * TLS_client_method (void)
 
const char * SSL_SESSION_get0_hostname (const SSL_SESSION *s)
 
unsigned char * ASN1_STRING_get0_data (const ASN1_STRING *x)
 
int SSL_SESSION_has_ticket (const SSL_SESSION *s)
 
unsigned long SSL_SESSION_get_ticket_lifetime_hint (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)
 
 STACK_OF (X509_OBJECT)*X509_STORE_get0_objects(X509_STORE *store)
 
X509 * X509_STORE_CTX_get0_cert (X509_STORE_CTX *ctx)
 
 STACK_OF (X509)*X509_STORE_CTX_get0_chain(X509_STORE_CTX *ctx)
 
EVP_MD_CTX * EVP_MD_CTX_new ()
 
void EVP_MD_CTX_free (EVP_MD_CTX *ctx)
 
HMAC_CTX * HMAC_CTX_new ()
 
void HMAC_CTX_free (HMAC_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)
 
int ECDSA_SIG_set0 (ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s)
 
void ECDSA_SIG_get0 (const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps)
 
int OPENSSL_init_ssl (uint64_t, const OPENSSL_INIT_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)
 
uint32_t X509_get_extension_flags (X509 *x)
 
uint32_t X509_get_key_usage (X509 *x)
 
uint32_t X509_get_extended_key_usage (X509 *x)
 
int X509_OBJECT_get_type (const X509_OBJECT *obj)
 
X509 * X509_OBJECT_get0_X509 (const X509_OBJECT *obj)
 
const ASN1_TIME * X509_CRL_get0_lastUpdate (const X509_CRL *crl)
 
const ASN1_TIME * X509_CRL_get0_nextUpdate (const X509_CRL *crl)
 
const X509_ALGOR * X509_get0_tbs_sigalg (const X509 *x)
 

Typedef Documentation

Definition at line 189 of file OpenSSL.h.

Function Documentation

unsigned char * folly::portability::ssl::ASN1_STRING_get0_data ( const ASN1_STRING *  x)

Definition at line 199 of file OpenSSL.cpp.

Referenced by folly::ssl::OpenSSLCertUtils::getCommonName(), wangle::SSLUtil::getSubjectAltName(), and folly::ssl::OpenSSLCertUtils::getSubjectAltNames().

199  {
200  return ASN1_STRING_data((ASN1_STRING*)x);
201 }
Definition: InvokeTest.cpp:58
void * folly::portability::ssl::BIO_get_data ( BIO *  bio)

Definition at line 175 of file OpenSSL.cpp.

175  {
176  return bio->ptr;
177 }
void folly::portability::ssl::BIO_meth_free ( BIO_METHOD *  biom)

Definition at line 132 of file OpenSSL.cpp.

132  {
133  OPENSSL_free((void*)biom);
134 }
BIO_METHOD * folly::portability::ssl::BIO_meth_new ( int  type,
const char *  name 
)

Definition at line 121 of file OpenSSL.cpp.

References name, and type.

Referenced by folly::ssl::OpenSSLUtils::newSocketBioMethod().

121  {
122  BIO_METHOD* method = (BIO_METHOD*)OPENSSL_malloc(sizeof(BIO_METHOD));
123  if (method == nullptr) {
124  return nullptr;
125  }
126  memset(method, 0, sizeof(BIO_METHOD));
127  method->type = type;
128  method->name = name;
129  return method;
130 }
PskType type
const char * name
Definition: http_parser.c:437
int folly::portability::ssl::BIO_meth_set_create ( BIO_METHOD *  biom,
int(*)(BIO *)  create 
)

Definition at line 161 of file OpenSSL.cpp.

Referenced by folly::ssl::OpenSSLUtils::newSocketBioMethod().

161  {
162  biom->create = create;
163  return 1;
164 }
int folly::portability::ssl::BIO_meth_set_ctrl ( BIO_METHOD *  biom,
long(*)(BIO *, int, long, void *)  ctrl 
)

Definition at line 156 of file OpenSSL.cpp.

Referenced by folly::ssl::OpenSSLUtils::newSocketBioMethod().

156  {
157  biom->ctrl = ctrl;
158  return 1;
159 }
int folly::portability::ssl::BIO_meth_set_destroy ( BIO_METHOD *  biom,
int(*)(BIO *)  destroy 
)

Definition at line 166 of file OpenSSL.cpp.

References destroy().

Referenced by folly::ssl::OpenSSLUtils::newSocketBioMethod().

166  {
167  biom->destroy = destroy;
168  return 1;
169 }
static void destroy()
int folly::portability::ssl::BIO_meth_set_gets ( BIO_METHOD *  biom,
int(*)(BIO *, char *, int)  bgets 
)

Definition at line 151 of file OpenSSL.cpp.

Referenced by folly::ssl::OpenSSLUtils::newSocketBioMethod().

151  {
152  biom->bgets = bgets;
153  return 1;
154 }
int folly::portability::ssl::BIO_meth_set_puts ( BIO_METHOD *  biom,
int(*)(BIO *, const char *)  bputs 
)

Definition at line 146 of file OpenSSL.cpp.

Referenced by folly::ssl::OpenSSLUtils::newSocketBioMethod().

146  {
147  biom->bputs = bputs;
148  return 1;
149 }
int folly::portability::ssl::BIO_meth_set_read ( BIO_METHOD *  biom,
int(*)(BIO *, char *, int)  read 
)

Definition at line 136 of file OpenSSL.cpp.

References fizz::detail::read().

Referenced by folly::ssl::OpenSSLUtils::newSocketBioMethod(), and folly::ssl::OpenSSLUtils::setCustomBioReadMethod().

136  {
137  biom->bread = read;
138  return 1;
139 }
size_t read(T &out, folly::io::Cursor &cursor)
Definition: Types-inl.h:258
int folly::portability::ssl::BIO_meth_set_write ( BIO_METHOD *  biom,
int(*)(BIO *, const char *, int)  write 
)

Definition at line 141 of file OpenSSL.cpp.

References fizz::detail::write().

Referenced by folly::ssl::OpenSSLUtils::newSocketBioMethod(), and folly::ssl::OpenSSLUtils::setCustomBioWriteMethod().

141  {
142  biom->bwrite = write;
143  return 1;
144 }
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
void folly::portability::ssl::BIO_set_data ( BIO *  bio,
void *  ptr 
)

Definition at line 171 of file OpenSSL.cpp.

References ptr.

171  {
172  bio->ptr = ptr;
173 }
void * ptr
void folly::portability::ssl::BIO_set_init ( BIO *  bio,
int  init 
)

Definition at line 179 of file OpenSSL.cpp.

References folly::init().

179  {
180  bio->init = init;
181 }
void init()
void folly::portability::ssl::BIO_set_shutdown ( BIO *  bio,
int  shutdown 
)

Definition at line 183 of file OpenSSL.cpp.

References folly::shutdown().

183  {
184  bio->shutdown = shutdown;
185 }
void shutdown(Counter &)
void folly::portability::ssl::DH_get0_key ( const DH *  dh,
const BIGNUM **  pub_key,
const BIGNUM **  priv_key 
)

Definition at line 262 of file OpenSSL.cpp.

265  {
266  // Based off of https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes
267  if (pub_key != nullptr) {
268  *pub_key = dh->pub_key;
269  }
270  if (priv_key != nullptr) {
271  *priv_key = dh->priv_key;
272  }
273 }
void folly::portability::ssl::DH_get0_pqg ( const DH *  dh,
const BIGNUM **  p,
const BIGNUM **  q,
const BIGNUM **  g 
)

Definition at line 245 of file OpenSSL.cpp.

249  {
250  // Based off of https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes
251  if (p != nullptr) {
252  *p = dh->p;
253  }
254  if (q != nullptr) {
255  *q = dh->q;
256  }
257  if (g != nullptr) {
258  *g = dh->g;
259  }
260 }
g_t g(f_t)
int folly::portability::ssl::DH_set0_pqg ( DH *  dh,
BIGNUM *  p,
BIGNUM *  q,
BIGNUM *  g 
)

Definition at line 212 of file OpenSSL.cpp.

References g().

212  {
213  /* If the fields p and g in d are nullptr, the corresponding input
214  * parameters MUST not be nullptr. q may remain nullptr.
215  */
216  if (dh == nullptr || (dh->p == nullptr && p == nullptr) ||
217  (dh->g == nullptr && g == nullptr)) {
218  return 0;
219  }
220 
221  if (p != nullptr) {
222  BN_free(dh->p);
223  dh->p = p;
224  }
225  if (q != nullptr) {
226  BN_free(dh->q);
227  dh->q = q;
228  }
229  if (g != nullptr) {
230  BN_free(dh->g);
231  dh->g = g;
232  }
233 
234  // In OpenSSL 1.1.0, DH_set0_pqg also sets
235  // dh->length = BN_num_bits(q)
236  // With OpenSSL 1.0.2, the output of openssl dhparam -C 2048 doesn't set
237  // the length field. So as far as the compat lib is concerned, this wrapper
238  // mimics the functionality of OpenSSL 1.0.2
239  // Note: BoringSSL doesn't even have a length field anymore, just something
240  // called 'priv_length'. Let's not mess with that for now.
241 
242  return 1;
243 }
g_t g(f_t)
void folly::portability::ssl::DSA_get0_key ( const DSA *  dsa,
const BIGNUM **  pub_key,
const BIGNUM **  priv_key 
)

Definition at line 292 of file OpenSSL.cpp.

295  {
296  // Based off of https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes
297  if (pub_key != nullptr) {
298  *pub_key = dsa->pub_key;
299  }
300  if (priv_key != nullptr) {
301  *priv_key = dsa->priv_key;
302  }
303 }
void folly::portability::ssl::DSA_get0_pqg ( const DSA *  dsa,
const BIGNUM **  p,
const BIGNUM **  q,
const BIGNUM **  g 
)

Definition at line 275 of file OpenSSL.cpp.

279  {
280  // Based off of https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes
281  if (p != nullptr) {
282  *p = dsa->p;
283  }
284  if (q != nullptr) {
285  *q = dsa->q;
286  }
287  if (g != nullptr) {
288  *g = dsa->g;
289  }
290 }
g_t g(f_t)
void folly::portability::ssl::ECDSA_SIG_get0 ( const ECDSA_SIG *  sig,
const BIGNUM **  pr,
const BIGNUM **  ps 
)

Definition at line 417 of file OpenSSL.cpp.

Referenced by fizz::extensions::TokenBindingConstructor::encodeEcdsaSignature(), and TEST().

420  {
421  // Based off of https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes
422  if (pr != nullptr) {
423  *pr = sig->r;
424  }
425  if (ps != nullptr) {
426  *ps = sig->s;
427  }
428 }
constexpr detail::Sig< Sig > const sig
Definition: Poly.h:1165
int folly::portability::ssl::ECDSA_SIG_set0 ( ECDSA_SIG *  sig,
BIGNUM *  r,
BIGNUM *  s 
)

Definition at line 405 of file OpenSSL.cpp.

References s.

Referenced by fizz::extensions::Validator::constructECDSASig(), and TEST().

405  {
406  // Based off of https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes
407  if (r == nullptr || s == nullptr) {
408  return 0;
409  }
410  BN_clear_free(sig->r);
411  BN_clear_free(sig->s);
412  sig->r = r;
413  sig->s = s;
414  return 1;
415 }
constexpr detail::Sig< Sig > const sig
Definition: Poly.h:1165
static set< string > s
void folly::portability::ssl::EVP_MD_CTX_free ( EVP_MD_CTX *  ctx)

Definition at line 330 of file OpenSSL.cpp.

330  {
331  if (ctx) {
332  EVP_MD_CTX_cleanup(ctx);
333  OPENSSL_free(ctx);
334  }
335 }
EVP_MD_CTX * folly::portability::ssl::EVP_MD_CTX_new ( )

Definition at line 321 of file OpenSSL.cpp.

Referenced by folly::ssl::OpenSSLHash::Digest::Digest(), fizz::detail::ecSign(), fizz::detail::ecVerify(), fizz::detail::rsaPssSign(), and fizz::detail::rsaPssVerify().

321  {
322  EVP_MD_CTX* ctx = (EVP_MD_CTX*)OPENSSL_malloc(sizeof(EVP_MD_CTX));
323  if (!ctx) {
324  throw std::runtime_error("Cannot allocate EVP_MD_CTX");
325  }
326  EVP_MD_CTX_init(ctx);
327  return ctx;
328 }
void folly::portability::ssl::HMAC_CTX_free ( HMAC_CTX *  ctx)

Definition at line 346 of file OpenSSL.cpp.

346  {
347  if (ctx) {
348  HMAC_CTX_cleanup(ctx);
349  OPENSSL_free(ctx);
350  }
351 }
HMAC_CTX * folly::portability::ssl::HMAC_CTX_new ( )

Definition at line 337 of file OpenSSL.cpp.

337  {
338  HMAC_CTX* ctx = (HMAC_CTX*)OPENSSL_malloc(sizeof(HMAC_CTX));
339  if (!ctx) {
340  throw std::runtime_error("Cannot allocate HMAC_CTX");
341  }
342  HMAC_CTX_init(ctx);
343  return ctx;
344 }
void folly::portability::ssl::OPENSSL_cleanup ( )

Definition at line 455 of file OpenSSL.cpp.

References folly::ssl::detail::cleanupThreadingLocks().

Referenced by main().

455  {
457  CRYPTO_cleanup_all_ex_data();
458  ERR_free_strings();
459  EVP_cleanup();
460  ERR_clear_error();
461 }
int folly::portability::ssl::OPENSSL_init_ssl ( uint64_t  ,
const OPENSSL_INIT_SETTINGS  
)

Compatibility shim for OpenSSL < 1.1.0.

For now, options and settings are ignored. We implement the most common behavior, which is to add all digests, ciphers, and strings.

Definition at line 436 of file OpenSSL.cpp.

References folly::ssl::detail::installThreadingLocks().

436  {
437  // OpenSSL >= 1.1.0 handles initializing the library, adding digests &
438  // ciphers, loading strings. Additionally, OpenSSL >= 1.1.0 uses platform
439  // native threading & mutexes, which means that we should handle setting up
440  // the necessary threading initialization in the compat layer as well.
441  SSL_library_init();
442  OpenSSL_add_all_ciphers();
443  OpenSSL_add_all_digests();
444  OpenSSL_add_all_algorithms();
445 
446  SSL_load_error_strings();
447  ERR_load_crypto_strings();
448 
449  // The caller should have used SSLContext::setLockTypes() prior to calling
450  // this function.
452  return 0;
453 }
void folly::portability::ssl::RSA_get0_crt_params ( const RSA *  r,
const BIGNUM **  dmp1,
const BIGNUM **  dmq1,
const BIGNUM **  iqmp 
)

Definition at line 388 of file OpenSSL.cpp.

392  {
393  // Based off of https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes
394  if (dmp1 != nullptr) {
395  *dmp1 = r->dmp1;
396  }
397  if (dmq1 != nullptr) {
398  *dmq1 = r->dmq1;
399  }
400  if (iqmp != nullptr) {
401  *iqmp = r->iqmp;
402  }
403 }
void folly::portability::ssl::RSA_get0_factors ( const RSA *  r,
const BIGNUM **  p,
const BIGNUM **  q 
)

Definition at line 378 of file OpenSSL.cpp.

378  {
379  // Based off of https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes
380  if (p != nullptr) {
381  *p = r->p;
382  }
383  if (q != nullptr) {
384  *q = r->q;
385  }
386 }
bool folly::portability::ssl::RSA_set0_key ( RSA *  r,
BIGNUM *  n,
BIGNUM *  e,
BIGNUM *  d 
)

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).

Definition at line 353 of file OpenSSL.cpp.

Referenced by TEST().

353  {
354  // Based off of https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes
360  if ((r->n == nullptr && n == nullptr) || (r->e == nullptr && e == nullptr)) {
361  return false;
362  }
363  if (n != nullptr) {
364  BN_free(r->n);
365  r->n = n;
366  }
367  if (e != nullptr) {
368  BN_free(r->e);
369  r->e = e;
370  }
371  if (d != nullptr) {
372  BN_free(r->d);
373  r->d = d;
374  }
375  return true;
376 }
const char * folly::portability::ssl::SSL_SESSION_get0_hostname ( const SSL_SESSION *  s)

Definition at line 195 of file OpenSSL.cpp.

Referenced by wangle::SSLSessionCallbacks::removeSessionCallback(), and folly::AsyncSSLSocket::sslAccept().

195  {
196  return s->tlsext_hostname;
197 }
static set< string > s
unsigned long folly::portability::ssl::SSL_SESSION_get_ticket_lifetime_hint ( const SSL_SESSION *  s)

Definition at line 207 of file OpenSSL.cpp.

Referenced by wangle::SSLSessionPersistentCacheBase< K >::getSSLSession(), and wangle::TEST_F().

207  {
208  return s->tlsext_tick_lifetime_hint;
209 }
static set< string > s
int folly::portability::ssl::SSL_SESSION_has_ticket ( const SSL_SESSION *  s)

Definition at line 203 of file OpenSSL.cpp.

Referenced by wangle::SSLSessionPersistentCacheBase< K >::getSSLSession(), and wangle::TEST_F().

203  {
204  return (s->tlsext_ticklen > 0) ? 1 : 0;
205 }
static set< string > s
folly::portability::ssl::STACK_OF ( X509  )

Definition at line 313 of file OpenSSL.cpp.

References STACK_OF().

313  {
314  return X509_STORE_CTX_get_chain(ctx);
315 }
const SSL_METHOD * folly::portability::ssl::TLS_client_method ( void  )

Definition at line 191 of file OpenSSL.cpp.

191  {
192  return TLSv1_2_client_method();
193 }
const SSL_METHOD * folly::portability::ssl::TLS_server_method ( void  )

Definition at line 187 of file OpenSSL.cpp.

187  {
188  return TLSv1_2_server_method();
189 }
const ASN1_TIME * folly::portability::ssl::X509_CRL_get0_lastUpdate ( const X509_CRL *  crl)

Definition at line 494 of file OpenSSL.cpp.

494  {
495  return X509_CRL_get_lastUpdate(crl);
496 }
const ASN1_TIME * folly::portability::ssl::X509_CRL_get0_nextUpdate ( const X509_CRL *  crl)

Definition at line 498 of file OpenSSL.cpp.

498  {
499  return X509_CRL_get_nextUpdate(crl);
500 }
const X509_ALGOR * folly::portability::ssl::X509_get0_tbs_sigalg ( const X509 *  x)

Definition at line 502 of file OpenSSL.cpp.

502  {
503  return x->cert_info->signature;
504 }
Definition: InvokeTest.cpp:58
uint32_t folly::portability::ssl::X509_get_extended_key_usage ( X509 *  x)

Definition at line 479 of file OpenSSL.cpp.

479  {
480  return x->ex_xkusage;
481 }
Definition: InvokeTest.cpp:58
uint32_t folly::portability::ssl::X509_get_extension_flags ( X509 *  x)

Definition at line 471 of file OpenSSL.cpp.

471  {
472  return x->ex_flags;
473 }
Definition: InvokeTest.cpp:58
uint32_t folly::portability::ssl::X509_get_key_usage ( X509 *  x)

Definition at line 475 of file OpenSSL.cpp.

475  {
476  return x->ex_kusage;
477 }
Definition: InvokeTest.cpp:58
X509 * folly::portability::ssl::X509_OBJECT_get0_X509 ( const X509_OBJECT *  obj)

Definition at line 487 of file OpenSSL.cpp.

Referenced by fizz::JavaCryptoCertificateVerifier::createAuthorities(), and fizz::DefaultCertificateVerifier::createAuthorities().

487  {
488  if (obj == nullptr || obj->type != X509_LU_X509) {
489  return nullptr;
490  }
491  return obj->data.x509;
492 }
int folly::portability::ssl::X509_OBJECT_get_type ( const X509_OBJECT *  obj)

Definition at line 483 of file OpenSSL.cpp.

Referenced by fizz::JavaCryptoCertificateVerifier::createAuthorities(), and fizz::DefaultCertificateVerifier::createAuthorities().

483  {
484  return obj->type;
485 }
const ASN1_TIME * folly::portability::ssl::X509_REVOKED_get0_revocationDate ( const X509_REVOKED *  r)

Definition at line 467 of file OpenSSL.cpp.

Referenced by TEST().

467  {
468  return r->revocationDate;
469 }
const ASN1_INTEGER * folly::portability::ssl::X509_REVOKED_get0_serialNumber ( const X509_REVOKED *  r)

Definition at line 463 of file OpenSSL.cpp.

Referenced by TEST().

463  {
464  return r->serialNumber;
465 }
X509 * folly::portability::ssl::X509_STORE_CTX_get0_cert ( X509_STORE_CTX *  ctx)

Definition at line 309 of file OpenSSL.cpp.

309  {
310  return ctx->cert;
311 }