Fetch the peer certificate used for authentication on the specified * connection and return it as a PEM-encoded sds. */
| 1307 | * connection and return it as a PEM-encoded sds. |
| 1308 | */ |
| 1309 | sds connTLSGetPeerCert(connection *conn_) { |
| 1310 | tls_connection *conn = (tls_connection *) conn_; |
| 1311 | if (conn_->type->get_type(conn_) != CONN_TYPE_TLS || !conn->ssl) return NULL; |
| 1312 | |
| 1313 | X509 *cert = SSL_get_peer_certificate(conn->ssl); |
| 1314 | if (!cert) return NULL; |
| 1315 | |
| 1316 | BIO *bio = BIO_new(BIO_s_mem()); |
| 1317 | if (bio == NULL || !PEM_write_bio_X509(bio, cert)) { |
| 1318 | if (bio != NULL) BIO_free(bio); |
| 1319 | return NULL; |
| 1320 | } |
| 1321 | |
| 1322 | const char *bio_ptr; |
| 1323 | long long bio_len = BIO_get_mem_data(bio, &bio_ptr); |
| 1324 | sds cert_pem = sdsnewlen(bio_ptr, bio_len); |
| 1325 | BIO_free(bio); |
| 1326 | |
| 1327 | return cert_pem; |
| 1328 | } |
| 1329 | |
| 1330 | #else /* USE_OPENSSL */ |
| 1331 |
no test coverage detected