Fetch the peer certificate used for authentication on the specified * connection and return it as a PEM-encoded sds. */
| 961 | * connection and return it as a PEM-encoded sds. |
| 962 | */ |
| 963 | sds connTLSGetPeerCert(connection *conn_) { |
| 964 | tls_connection *conn = (tls_connection *) conn_; |
| 965 | if (conn_->type->get_type(conn_) != CONN_TYPE_TLS || !conn->ssl) return NULL; |
| 966 | |
| 967 | X509 *cert = SSL_get_peer_certificate(conn->ssl); |
| 968 | if (!cert) return NULL; |
| 969 | |
| 970 | BIO *bio = BIO_new(BIO_s_mem()); |
| 971 | if (bio == NULL || !PEM_write_bio_X509(bio, cert)) { |
| 972 | if (bio != NULL) BIO_free(bio); |
| 973 | return NULL; |
| 974 | } |
| 975 | |
| 976 | const char *bio_ptr; |
| 977 | long long bio_len = BIO_get_mem_data(bio, &bio_ptr); |
| 978 | sds cert_pem = sdsnewlen(bio_ptr, bio_len); |
| 979 | BIO_free(bio); |
| 980 | |
| 981 | return cert_pem; |
| 982 | } |
| 983 | |
| 984 | #else /* USE_OPENSSL */ |
| 985 |
no test coverage detected