Sets the sha256 certificate fingerprint on the connection * Based on the example here https://fm4dd.com/openssl/certfprint.shtm */
| 533 | /* Sets the sha256 certificate fingerprint on the connection |
| 534 | * Based on the example here https://fm4dd.com/openssl/certfprint.shtm */ |
| 535 | void tlsSetCertificateFingerprint(tls_connection* conn, X509 * cert) { |
| 536 | unsigned int fprint_size; |
| 537 | unsigned char fprint[EVP_MAX_MD_SIZE]; |
| 538 | const EVP_MD *fprint_type = EVP_sha256(); |
| 539 | X509_digest(cert, fprint_type, fprint, &fprint_size); |
| 540 | |
| 541 | if (conn->c.fprint) zfree(conn->c.fprint); |
| 542 | conn->c.fprint = (char*)zcalloc(fprint_size*2+1); |
| 543 | |
| 544 | /* Format fingerprint as hex string */ |
| 545 | char tmp[3]; |
| 546 | for (unsigned int i = 0; i < fprint_size; i++) { |
| 547 | snprintf(tmp, 2, "%02x", (unsigned int)fprint[i]); |
| 548 | strncat(conn->c.fprint, tmp, 2); |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | /* ASN1_STRING_get0_data was introduced in OPENSSL 1.1.1 |
| 553 | * use ASN1_STRING_data for older versions where it is not available */ |
no test coverage detected