Skip to content

Commit ad97806

Browse files
committed
Calculate SHA-1 fingerprint when loading the certificate
1 parent 6095fde commit ad97806

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

ssl/crypto_misc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ struct _x509_ctx
7676
uint8_t sig_type;
7777
RSA_CTX *rsa_ctx;
7878
bigint *digest;
79+
bigint *fingerprint;
7980
struct _x509_ctx *next;
8081
};
8182

ssl/x509.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ int x509_new(const uint8_t *cert, int *len, X509_CTX **ctx)
119119

120120
bi_ctx = x509_ctx->rsa_ctx->bi_ctx;
121121

122+
SHA1_CTX sha_fp_ctx;
123+
uint8_t sha_fp_dgst[SHA1_SIZE];
124+
SHA1_Init(&sha_fp_ctx);
125+
SHA1_Update(&sha_fp_ctx, &cert[0], cert_size);
126+
SHA1_Final(sha_fp_dgst, &sha_fp_ctx);
127+
x509_ctx->fingerprint = bi_import(bi_ctx, sha_fp_dgst, SHA1_SIZE);
128+
122129
#ifdef CONFIG_SSL_CERT_VERIFICATION /* only care if doing verification */
123130
/* use the appropriate signature algorithm (SHA1/MD5/MD2) */
124131
if (x509_ctx->sig_type == SIG_TYPE_MD5)
@@ -245,6 +252,11 @@ void x509_free(X509_CTX *x509_ctx)
245252
bi_free(x509_ctx->rsa_ctx->bi_ctx, x509_ctx->digest);
246253
}
247254

255+
if (x509_ctx->fingerprint)
256+
{
257+
bi_free(x509_ctx->rsa_ctx->bi_ctx, x509_ctx->fingerprint);
258+
}
259+
248260
if (x509_ctx->subject_alt_dnsnames)
249261
{
250262
for (i = 0; x509_ctx->subject_alt_dnsnames[i]; ++i)

0 commit comments

Comments
 (0)