X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Fssl.c;h=2204a3cc3996dc59eb6b15968fcf5713fe2350e9;hb=772cee17b53bb6795a5e98f1ae2acb7e7d6c25c1;hp=d2ef7610dbfdddb2a1ae116fda037d1384eb2188;hpb=817236c4ef5a94865a85ca403b24ba721417ecc1;p=umurmur.git diff --git a/src/ssl.c b/src/ssl.c index d2ef761..2204a3c 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -1,5 +1,5 @@ -/* Copyright (C) 2009-2011, Martin Johansson - Copyright (C) 2005-2011, Thorvald Natvig +/* Copyright (C) 2009-2012, Martin Johansson + Copyright (C) 2005-2012, Thorvald Natvig All rights reserved. @@ -168,14 +168,14 @@ void SSLi_deinit(void) } /* Create SHA1 of last certificate in the peer's chain. */ -void SSLi_getSHA1Hash(SSL_handle_t *ssl, uint8_t *hash) +bool_t SSLi_getSHA1Hash(SSL_handle_t *ssl, uint8_t *hash) { x509_cert *cert = ssl->peer_cert; if (!ssl->peer_cert) { - /* XXX what to do? */ - return; + return false; } sha1(cert->raw.p, cert->raw.len, hash); + return true; } SSL_handle_t *SSLi_newconnection(int *fd, bool_t *SSLready) @@ -508,10 +508,10 @@ void SSLi_init(void) { const SSL_METHOD *method; SSL *ssl; - int i, offset = 0; + int i, offset = 0, cipherstringlen = 0; STACK_OF(SSL_CIPHER) *cipherlist = NULL, *cipherlist_new = NULL; SSL_CIPHER *cipher; - char cipherstring[1024]; + char *cipherstring, tempstring[128]; SSL_library_init(); OpenSSL_add_all_algorithms(); /* load & register all cryptos, etc. */ @@ -544,11 +544,16 @@ void SSLi_init(void) } Log_debug("List of ciphers:"); if (cipherlist_new) { - for ( i = 0; (cipher = sk_SSL_CIPHER_value(cipherlist_new, i)) != NULL; i++) { + for (i = 0; (cipher = sk_SSL_CIPHER_value(cipherlist_new, i)) != NULL; i++) { Log_debug("%s", SSL_CIPHER_get_name(cipher)); - offset += snprintf(cipherstring + offset, 1024 - offset, "%s:", SSL_CIPHER_get_name(cipher)); + cipherstringlen += strlen(SSL_CIPHER_get_name(cipher)) + 1; + } + cipherstring = malloc(cipherstringlen + 1); + if (cipherstring == NULL) + Log_fatal("Out of memory"); + for (i = 0; (cipher = sk_SSL_CIPHER_value(cipherlist_new, i)) != NULL; i++) { + offset += sprintf(cipherstring + offset, "%s:", SSL_CIPHER_get_name(cipher)); } - cipherstring[offset - 1] = '\0'; } if (cipherlist_new) @@ -559,6 +564,8 @@ void SSLi_init(void) if (SSL_CTX_set_cipher_list(context, cipherstring) == 0) Log_fatal("Failed to set cipher list!"); + + free(cipherstring); SSL_CTX_set_verify(context, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE, verify_callback); @@ -607,16 +614,15 @@ SSL_handle_t *SSLi_newconnection(int *fd, bool_t *SSLready) } /* Create SHA1 of last certificate in the peer's chain. */ -void SSLi_getSHA1Hash(SSL_handle_t *ssl, uint8_t *hash) +bool_t SSLi_getSHA1Hash(SSL_handle_t *ssl, uint8_t *hash) { X509 *x509; uint8_t *buf, *p; int len; x509 = SSL_get_peer_certificate(ssl); - if (x509) { - /* XXX what to do? */ - return; + if (!x509) { + return false; } len = i2d_X509(x509, NULL); @@ -624,11 +630,13 @@ void SSLi_getSHA1Hash(SSL_handle_t *ssl, uint8_t *hash) if (buf == NULL) { Log_fatal("malloc"); } + + p = buf; + i2d_X509(x509, &p); - i2d_X509(x509, &p); - - SHA1(p, len, hash); + SHA1(buf, len, hash); free(buf); + return true; } void SSLi_closeconnection(SSL_handle_t *ssl) @@ -686,17 +694,16 @@ static int verify_callback(int preverify_ok, X509_STORE_CTX *ctx) X509_STORE_CTX_set_error(ctx, err); } if (!preverify_ok) { - Log_warn("verify error:num=%d:%s:depth=%d:%s\n", err, + Log_warn("SSL: verify error:num=%d:%s:depth=%d:%s\n", err, X509_verify_cert_error_string(err), depth, buf); } /* * At this point, err contains the last verification error. We can use * it for something special */ - if (!preverify_ok && (err == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT)) - { + if (!preverify_ok && (err == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT)) { X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert), buf, 256); - Log_warn("issuer= %s", buf); + Log_warn("issuer= %s", buf); } return 1; }