@@ -648,25 +648,31 @@ static void ssl_showcert(X509 *cert, const int loglev)
648
648
} else
649
649
putlog (loglev , "*" , "TLS: cannot get issuer name from certificate!" );
650
650
651
- /* Fingerprints */
651
+ /* Certificate fingerprints */
652
652
if (X509_digest (cert , EVP_sha1 (), md , & len )) {
653
653
buf = OPENSSL_buf2hexstr (md , len );
654
654
putlog (loglev , "*" , "TLS: certificate SHA1 Fingerprint: %s" , buf );
655
655
OPENSSL_free (buf );
656
656
}
657
657
if (X509_digest (cert , EVP_sha256 (), md , & len )) {
658
658
buf = OPENSSL_buf2hexstr (md , len );
659
- putlog (loglev , "*" , "TLS: certificate SHA-256 Fingerprint: %s" , buf );
659
+ putlog (loglev , "*" , "TLS: certificate SHA256 Fingerprint: %s" , buf );
660
660
OPENSSL_free (buf );
661
661
}
662
662
663
-
664
663
/* Validity time */
665
664
from = ssl_printtime (X509_get_notBefore (cert ));
666
665
to = ssl_printtime (X509_get_notAfter (cert ));
667
666
putlog (loglev , "*" , "TLS: certificate valid from %s to %s" , from , to );
668
667
nfree (from );
669
668
nfree (to );
669
+
670
+ /* Public key fingerprint */
671
+ if (X509_pubkey_digest (cert , EVP_sha256 (), md , & len )) {
672
+ buf = OPENSSL_buf2hexstr (md , len );
673
+ putlog (loglev , "*" , "TLS: public key SHA256 Fingerprint: %s" , buf );
674
+ OPENSSL_free (buf );
675
+ }
670
676
}
671
677
672
678
/* Certificate validation callback
@@ -768,6 +774,24 @@ static void ssl_info(const SSL *ssl, int where, int ret)
768
774
/* Callback for completed handshake. Cheaper and more convenient than
769
775
using H_tls */
770
776
sock = SSL_get_fd (ssl );
777
+ #if OPENSSL_VERSION_NUMBER >= 0x30000000L
778
+ cert = SSL_get0_peer_certificate (ssl );
779
+ #else
780
+ cert = SSL_get_peer_certificate (ssl );
781
+ #endif
782
+
783
+ /* Verify public key fingerprint */
784
+ int idx = findanyidx (sock );
785
+ if (dcc [idx ].u .fingerprint ) {
786
+ unsigned char md [EVP_MAX_MD_SIZE ];
787
+ unsigned int len ;
788
+ if (X509_pubkey_digest (cert , EVP_sha256 (), md , & len )) {
789
+ char * fingerprint2 = OPENSSL_buf2hexstr (md , len );
790
+ OPENSSL_free (fingerprint2 );
791
+ }
792
+ printf ("DEBUG: Verifying public key fingerprint not implemented yet: %s\n" , dcc [idx ].u .fingerprint );
793
+ }
794
+
771
795
if (data -> cb )
772
796
data -> cb (sock );
773
797
/* Call TLS binds. We allow scripts to take over or disable displaying of
@@ -778,9 +802,11 @@ static void ssl_info(const SSL *ssl, int where, int ret)
778
802
putlog (data -> loglevel , "*" , "TLS: handshake successful. Secure connection "
779
803
"established." );
780
804
781
- if (( cert = SSL_get_peer_certificate ( ssl )) ) {
805
+ if (cert ) {
782
806
ssl_showcert (cert , LOG_DEBUG );
807
+ #if OPENSSL_VERSION_NUMBER < 0x30000000L
783
808
X509_free (cert );
809
+ #endif
784
810
}
785
811
else
786
812
putlog (data -> loglevel , "*" , "TLS: peer did not present a certificate" );
0 commit comments