diff options
author | Nick Mathewson <nickm@torproject.org> | 2007-11-05 18:15:54 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2007-11-05 18:15:54 +0000 |
commit | 12afd4777c5ef3003b08acb34e9090a09703cf60 (patch) | |
tree | 390b9561dafe722bed1ac7dd9d8ccdd6a3012aa3 /src/common/tortls.c | |
parent | 323490303e9864e9116e5a740a48316ada801983 (diff) | |
download | tor-12afd4777c5ef3003b08acb34e9090a09703cf60.tar.gz tor-12afd4777c5ef3003b08acb34e9090a09703cf60.zip |
r16413@catbus: nickm | 2007-11-05 13:14:18 -0500
Add functions to encode certificates
svn:r12384
Diffstat (limited to 'src/common/tortls.c')
-rw-r--r-- | src/common/tortls.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/common/tortls.c b/src/common/tortls.c index 512847f1de..6c04a362a8 100644 --- a/src/common/tortls.c +++ b/src/common/tortls.c @@ -718,7 +718,7 @@ tor_tls_get_cert_digests(tor_tls_t *tls, { X509 *cert; unsigned int len; - tor_assert(tls->context); + tor_assert(tls && tls->context); cert = tls->context->my_cert; if (cert) { X509_digest(cert, EVP_sha1(), (unsigned char*)my_digest_out, &len); @@ -734,6 +734,26 @@ tor_tls_get_cert_digests(tor_tls_t *tls, return 0; } +/** DOCDOC */ +char * +tor_tls_encode_my_certificate(tor_tls_t *tls, size_t *size_out, + int conn_cert) +{ + unsigned char *result, *cp; + int certlen; + X509 *cert; + tor_assert(tls && tls->context); + cert = conn_cert ? tls->context->my_cert : tls->context->my_id_cert; + tor_assert(cert); + certlen = i2d_X509(cert, NULL); + tor_assert(certlen >= 0); + cp = result = tor_malloc(certlen); + i2d_X509(cert, &cp); + tor_assert(cp-result == certlen); + *size_out = (size_t)certlen; + return (char*) result; +} + /** Warn that a certificate lifetime extends through a certain range. */ static void log_cert_lifetime(X509 *cert, const char *problem) |