From 4f5079fe2b925b52a21162267614f4f5ed8f5a6b Mon Sep 17 00:00:00 2001 From: Martin Johansson Date: Sat, 25 Feb 2012 01:12:02 +0100 Subject: [PATCH] More hash stuff fixes --- src/ssl.c | 11 ++++++----- src/ssl.h | 8 +++++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/ssl.c b/src/ssl.c index d2ef761..964d7ee 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -168,14 +168,15 @@ 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) @@ -607,7 +608,7 @@ 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; @@ -615,8 +616,7 @@ void SSLi_getSHA1Hash(SSL_handle_t *ssl, uint8_t *hash) x509 = SSL_get_peer_certificate(ssl); if (x509) { - /* XXX what to do? */ - return; + return false; } len = i2d_X509(x509, NULL); @@ -629,6 +629,7 @@ void SSLi_getSHA1Hash(SSL_handle_t *ssl, uint8_t *hash) SHA1(p, len, hash); free(buf); + return true; } void SSLi_closeconnection(SSL_handle_t *ssl) diff --git a/src/ssl.h b/src/ssl.h index 6aa0b1a..f5fa4a8 100644 --- a/src/ssl.h +++ b/src/ssl.h @@ -108,7 +108,7 @@ typedef SSL SSL_handle_t; void SSLi_init(void); void SSLi_deinit(void); SSL_handle_t *SSLi_newconnection(int *fd, bool_t *SSLready); -void SSLi_getSHA1Hash(SSL_handle_t *ssl, uint8_t *hash); +bool_t SSLi_getSHA1Hash(SSL_handle_t *ssl, uint8_t *hash); void SSLi_closeconnection(SSL_handle_t *ssl); int SSLi_nonblockaccept(SSL_handle_t *ssl, bool_t *SSLready); int SSLi_read(SSL_handle_t *ssl, uint8_t *buf, int len); @@ -118,4 +118,10 @@ bool_t SSLi_data_pending(SSL_handle_t *ssl); void SSLi_shutdown(SSL_handle_t *ssl); void SSLi_free(SSL_handle_t *ssl); +static inline void SSLi_hash2hex(uint8_t *hash, char *out) +{ + int i, offset = 0; + for (i = 0; i < 20; i++) + offset += sprintf(out + offset, "%02x", hash[i]); +} #endif -- 2.30.2