[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r12384: Add functions to encode certificates (in tor/trunk: . src/common)



Author: nickm
Date: 2007-11-05 13:15:54 -0500 (Mon, 05 Nov 2007)
New Revision: 12384

Modified:
   tor/trunk/
   tor/trunk/src/common/tortls.c
   tor/trunk/src/common/tortls.h
Log:
 r16413@catbus:  nickm | 2007-11-05 13:14:18 -0500
 Add functions to encode certificates



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r16413] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/src/common/tortls.c
===================================================================
--- tor/trunk/src/common/tortls.c	2007-11-05 18:15:52 UTC (rev 12383)
+++ tor/trunk/src/common/tortls.c	2007-11-05 18:15:54 UTC (rev 12384)
@@ -718,7 +718,7 @@
 {
   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 @@
   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)

Modified: tor/trunk/src/common/tortls.h
===================================================================
--- tor/trunk/src/common/tortls.h	2007-11-05 18:15:52 UTC (rev 12383)
+++ tor/trunk/src/common/tortls.h	2007-11-05 18:15:54 UTC (rev 12384)
@@ -55,6 +55,8 @@
 int tor_tls_peer_has_cert(tor_tls_t *tls);
 int tor_tls_get_cert_digests(tor_tls_t *tls, char *my_digest_out,
                              char *peer_digest_out);
+char *tor_tls_encode_my_certificate(tor_tls_t *tls, size_t *size_out,
+                                    int conn_cert);
 int tor_tls_verify_v1(int severity, tor_tls_t *tls,
                       crypto_pk_env_t **identity);
 int tor_tls_check_lifetime(tor_tls_t *tls, int tolerance);