summaryrefslogtreecommitdiff
path: root/src/common/tortls.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-06-05 15:52:06 -0400
committerNick Mathewson <nickm@torproject.org>2017-06-05 15:52:06 -0400
commite3b1573be6aefc91946fa4649591ed1690d77ee8 (patch)
tree449e6a0f317b7ce73a18b3c34477f474247f074f /src/common/tortls.c
parentdd573f72b2f20b9aec310ee298ac4e9b737f835d (diff)
parent91f49bc0f0759d0e0a794fbfe8cce5a9bb07e607 (diff)
downloadtor-e3b1573be6aefc91946fa4649591ed1690d77ee8.tar.gz
tor-e3b1573be6aefc91946fa4649591ed1690d77ee8.zip
Merge branch 'maint-0.3.0'
Diffstat (limited to 'src/common/tortls.c')
-rw-r--r--src/common/tortls.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/common/tortls.c b/src/common/tortls.c
index 42fb91a9f7..44db3aec58 100644
--- a/src/common/tortls.c
+++ b/src/common/tortls.c
@@ -705,11 +705,13 @@ tor_x509_cert_new,(X509 *x509_cert))
return cert;
}
-/** Return a copy of <b>cert</b> */
+/** Return a new copy of <b>cert</b>. */
tor_x509_cert_t *
tor_x509_cert_dup(const tor_x509_cert_t *cert)
{
- return tor_x509_cert_new(X509_dup(cert->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>,
@@ -2047,7 +2049,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))
{
@@ -2059,6 +2062,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,