2020 */
2121
2222#include " P_OCSPStapling.h"
23+
2324#if TS_USE_TLS_OCSP
2425
2526#include < openssl/bio.h>
2627#include < openssl/ssl.h>
28+
29+ #if TS_HAS_BORINGOCSP
30+ #include < boringocsp/ocsp.h>
31+ #else
2732#include < openssl/ocsp.h>
33+ #endif
34+
2835#include " P_Net.h"
2936#include " P_SSLConfig.h"
3037#include " P_SSLUtils.h"
@@ -214,6 +221,7 @@ ssl_stapling_init_cert(SSL_CTX *ctx, X509 *cert, const char *certname, const cha
214221 cinf->expire_time = 0 ;
215222
216223 if (cinf->is_prefetched ) {
224+ #ifndef OPENSSL_IS_BORINGSSL
217225 Debug (" ssl_ocsp" , " using OCSP prefetched response file %s" , rsp_file);
218226 rsp_bio = BIO_new_file (rsp_file, " r" );
219227 if (rsp_bio) {
@@ -235,6 +243,9 @@ ssl_stapling_init_cert(SSL_CTX *ctx, X509 *cert, const char *certname, const cha
235243 BIO_free (rsp_bio);
236244 rsp_bio = nullptr ;
237245 }
246+ #else
247+ Warning (" failed to set prefetched OCSP response; this functionality not supported by BoringSSL" );
248+ #endif
238249 }
239250
240251 issuer = stapling_get_issuer (ctx, cert);
@@ -261,10 +272,14 @@ ssl_stapling_init_cert(SSL_CTX *ctx, X509 *cert, const char *certname, const cha
261272 goto err;
262273 }
263274
275+ #ifdef OPENSSL_IS_BORINGSSL
276+ X509_up_ref (cert);
277+ #endif
278+
264279 map->insert (std::make_pair (cert, cinf));
265280 SSL_CTX_set_ex_data (ctx, ssl_stapling_index, map);
266281
267- Note (" successfully initialized stapling for %s into SSL_CTX: %p" , certname, ctx);
282+ Note (" successfully initialized stapling for %s into SSL_CTX: %p uri=%s " , certname, ctx, cinf-> uri );
268283 return true ;
269284
270285err:
@@ -458,7 +473,7 @@ stapling_refresh_response(certinfo *cinf, OCSP_RESPONSE **prsp)
458473 if (!stapling_cache_response (*prsp, cinf)) {
459474 Error (" stapling_refresh_response: can not cache response" );
460475 } else {
461- Debug (" ssl_ocsp" , " stapling_refresh_response: successful refresh OCSP response" );
476+ Debug (" ssl_ocsp" , " stapling_refresh_response: successfully refreshed OCSP response" );
462477 }
463478 goto done;
464479
@@ -489,6 +504,7 @@ ocsp_update()
489504 SSLCertificateConfig::scoped_config certLookup;
490505 const unsigned ctxCount = certLookup->count ();
491506
507+ Debug (" ssl_ocsp" , " updating OCSP data" );
492508 for (unsigned i = 0 ; i < ctxCount; i++) {
493509 SSLCertContext *cc = certLookup->get (i);
494510 if (cc) {
@@ -505,7 +521,7 @@ ocsp_update()
505521 if (cinf->resp_derlen == 0 || cinf->is_expire || cinf->expire_time < current_time) {
506522 ink_mutex_release (&cinf->stapling_mutex );
507523 if (stapling_refresh_response (cinf, &resp)) {
508- Debug (" Successfully refreshed OCSP for %s certificate. url=%s" , cinf->certname , cinf->uri );
524+ Debug (" ssl_ocsp " , " Successfully refreshed OCSP for %s certificate. url=%s" , cinf->certname , cinf->uri );
509525 SSL_INCREMENT_DYN_STAT (ssl_ocsp_refreshed_cert_stat);
510526 } else {
511527 Error (" Failed to refresh OCSP for %s certificate. url=%s" , cinf->certname , cinf->uri );
@@ -523,7 +539,11 @@ ocsp_update()
523539
524540// RFC 6066 Section-8: Certificate Status Request
525541int
542+ #ifndef OPENSSL_IS_BORINGSSL
526543ssl_callback_ocsp_stapling (SSL *ssl)
544+ #else
545+ ssl_callback_ocsp_stapling (SSL *ssl, void *)
546+ #endif
527547{
528548 // Assume SSL_get_SSL_CTX() is the same as reaching into the ssl structure
529549 // Using the official call, to avoid leaking internal openssl knowledge
@@ -533,18 +553,43 @@ ssl_callback_ocsp_stapling(SSL *ssl)
533553 Debug (" ssl_ocsp" , " ssl_callback_ocsp_stapling: failed to get certificate map" );
534554 return SSL_TLSEXT_ERR_NOACK;
535555 }
556+
557+ if (map->empty ()) {
558+ Debug (" ssl_ocsp" , " ssl_callback_ocsp_stapling: certificate map empty" );
559+ return SSL_TLSEXT_ERR_NOACK;
560+ }
561+
536562 // Fetch the specific certificate used in this negotiation
537563 X509 *cert = SSL_get_certificate (ssl);
538564 if (!cert) {
539565 Error (" ssl_callback_ocsp_stapling: failed to get certificate" );
540566 return SSL_TLSEXT_ERR_NOACK;
541567 }
568+
569+ certinfo *cinf = nullptr ;
570+ #ifndef OPENSSL_IS_BORINGSSL
542571 certinfo_map::iterator iter = map->find (cert);
543- if (iter == map->end ()) {
544- Error (" ssl_callback_ocsp_stapling: failed to get certificate information" );
572+ if (iter != map->end ()) {
573+ cinf = iter->second ;
574+ }
575+ #else
576+ for (certinfo_map::iterator iter = map->begin (); iter != map->end (); ++iter) {
577+ X509 *key = iter->first ;
578+ if (key == nullptr ) {
579+ continue ;
580+ }
581+
582+ if (X509_cmp (key, cert) == 0 ) {
583+ cinf = iter->second ;
584+ break ;
585+ }
586+ }
587+ #endif
588+
589+ if (cinf == nullptr ) {
590+ Error (" ssl_callback_ocsp_stapling: failed to get certificate information for ssl=%p" , ssl);
545591 return SSL_TLSEXT_ERR_NOACK;
546592 }
547- certinfo *cinf = iter->second ;
548593
549594 ink_mutex_acquire (&cinf->stapling_mutex );
550595 time_t current_time = time (nullptr );
@@ -554,10 +599,9 @@ ssl_callback_ocsp_stapling(SSL *ssl)
554599 return SSL_TLSEXT_ERR_NOACK;
555600 } else {
556601 unsigned char *p = static_cast <unsigned char *>(OPENSSL_malloc (cinf->resp_derlen ));
557- unsigned int len = cinf->resp_derlen ;
558602 memcpy (p, cinf->resp_der , cinf->resp_derlen );
559603 ink_mutex_release (&cinf->stapling_mutex );
560- SSL_set_tlsext_status_ocsp_resp (ssl, p, len );
604+ SSL_set_tlsext_status_ocsp_resp (ssl, p, cinf-> resp_derlen );
561605 Debug (" ssl_ocsp" , " ssl_callback_ocsp_stapling: successfully got certificate status for %s" , cinf->certname );
562606 return SSL_TLSEXT_ERR_OK;
563607 }
0 commit comments