diff options
author | Nick Mathewson <nickm@torproject.org> | 2017-06-05 15:28:13 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-06-05 15:28:13 -0400 |
commit | 9fea00928cb680f550a5ea9c64227efc025ea69b (patch) | |
tree | 6209a42730f3108c91b350740251280ad585ddaa /src/common/tortls.c | |
parent | 80aca1501ae080ddb9c8f457290226dd5453b08a (diff) | |
parent | ec84fc1d8ecb56fde887eb01d3bca1a031bd1e89 (diff) | |
download | tor-9fea00928cb680f550a5ea9c64227efc025ea69b.tar.gz tor-9fea00928cb680f550a5ea9c64227efc025ea69b.zip |
Merge branch 'bug22460_case2_029_01_squashed' into maint-0.2.9
Diffstat (limited to 'src/common/tortls.c')
-rw-r--r-- | src/common/tortls.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/common/tortls.c b/src/common/tortls.c index 62ed5be344..d61cc2e58a 100644 --- a/src/common/tortls.c +++ b/src/common/tortls.c @@ -677,6 +677,15 @@ MOCK_IMPL(STATIC tor_x509_cert_t *, return cert; } +/** Return a new copy of <b>cert</b>. */ +tor_x509_cert_t * +tor_x509_cert_dup(const tor_x509_cert_t *cert) +{ + tor_assert(cert); + X509 *x509 = cert->cert; + return tor_x509_cert_new(X509_dup(x509)); +} + /** Read a DER-encoded X509 cert, of length exactly <b>certificate_len</b>, * from a <b>certificate</b>. Return a newly allocated tor_x509_cert_t on * success and NULL on failure. */ @@ -2009,7 +2018,8 @@ tor_tls_peer_has_cert(tor_tls_t *tls) return 1; } -/** Return the peer certificate, or NULL if there isn't one. */ +/** Return a newly allocated copy of the peer certificate, or NULL if there + * isn't one. */ MOCK_IMPL(tor_x509_cert_t *, tor_tls_get_peer_cert,(tor_tls_t *tls)) { @@ -2021,6 +2031,24 @@ tor_tls_get_peer_cert,(tor_tls_t *tls)) return tor_x509_cert_new(cert); } +/** Return a newly allocated copy of the cerficate we used on the connection, + * or NULL if somehow we didn't use one. */ +MOCK_IMPL(tor_x509_cert_t *, +tor_tls_get_own_cert,(tor_tls_t *tls)) +{ + X509 *cert = SSL_get_certificate(tls->ssl); + tls_log_errors(tls, LOG_WARN, LD_HANDSHAKE, + "getting own-connection certificate"); + if (!cert) + return NULL; + /* Fun inconsistency: SSL_get_peer_certificate increments the reference + * count, but SSL_get_certificate does not. */ + X509 *duplicate = X509_dup(cert); + if (BUG(duplicate == NULL)) + return NULL; + return tor_x509_cert_new(duplicate); +} + /** Warn that a certificate lifetime extends through a certain range. */ static void log_cert_lifetime(int severity, const X509 *cert, const char *problem) |