| 78 | } |
| 79 | |
| 80 | void LoadedTLSConfig::print(FILE* fp) { |
| 81 | int num_certs = 0; |
| 82 | boost::asio::ssl::context context(boost::asio::ssl::context::tls); |
| 83 | try { |
| 84 | ConfigureSSLContext(*this, context); |
| 85 | } catch (Error& e) { |
| 86 | fprintf(fp, "There was an error in loading the certificate chain.\n"); |
| 87 | throw; |
| 88 | } |
| 89 | |
| 90 | X509_STORE* store = SSL_CTX_get_cert_store(context.native_handle()); |
| 91 | X509_STORE_CTX* store_ctx = X509_STORE_CTX_new(); |
| 92 | X509* cert = SSL_CTX_get0_certificate(context.native_handle()); |
| 93 | X509_STORE_CTX_init(store_ctx, store, cert, nullptr); |
| 94 | |
| 95 | X509_verify_cert(store_ctx); |
| 96 | STACK_OF(X509)* chain = X509_STORE_CTX_get0_chain(store_ctx); |
| 97 | |
| 98 | X509_print_fp(fp, cert); |
| 99 | |
| 100 | num_certs = sk_X509_num(chain); |
| 101 | if (num_certs) { |
| 102 | for (int i = 0; i < num_certs; i++) { |
| 103 | printf("\n"); |
| 104 | X509* cert = sk_X509_value(chain, i); |
| 105 | X509_print_fp(fp, cert); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | X509_STORE_CTX_free(store_ctx); |
| 110 | } |
| 111 | |
| 112 | void ConfigureSSLContext(const LoadedTLSConfig& loaded, boost::asio::ssl::context& context) { |
| 113 | try { |