[PATCH 4/4] Simplify fingerprint calculation

noname <[email protected]> Mon, 10 Nov 2014 16:33:30 +0000
Newsgroups gmane.network.irc.irssi.devel
Message-ID <20141110163330.GA15805@darkstar>
Also remove wrong buffer overflow check
---
 src/core/network-openssl.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/src/core/network-openssl.c b/src/core/network-openssl.c
index 6daa612..c8e2a54 100644
--- a/src/core/network-openssl.c
+++ b/src/core/network-openssl.c
@@ -263,17 +263,12 @@ static gboolean irssi_ssl_verify(SSL *ssl, const char *hostname, int port, X509
 		if (! X509_digest(cert, EVP_sha256(), md, &n))
 			g_warning("  Could not get fingerprint from peer certificate");
 		else {
-			char hex[] = "0123456789ABCDEF";
 			char fp[EVP_MAX_MD_SIZE*3];
-			if (n < sizeof(fp)) {
-				unsigned int i;
-				for (i = 0; i < n; i++) {
-					fp[i*3+0] = hex[(md[i] >> 4) & 0xF];
-					fp[i*3+1] = hex[(md[i] >> 0) & 0xF];
-					fp[i*3+2] = i == n - 1 ? '\0' : ':';
-				}
-				g_warning("  SHA256 Fingerprint : %s", fp);
-			}
+			unsigned int i;
+			for (i = 0; i < n; i++)
+				sprintf(fp + 3 * i, "%02X%c", md[i], i + 1 == n ? '\0' : ':');
+
+			g_warning("  SHA256 Fingerprint : %s", fp);
 		}
 		return FALSE;
 	} else if (! irssi_ssl_verify_hostname(cert, hostname)){
-- 
1.8.4