openssl: Use openssl_i2chunk when creating ASN.1 chunks

Using the return value of i2d_* directly as input of chunk_alloc imposes
the risk of creating an invalid chunk when the return value of the i2d_*
function is -1. The openssl_i2chunk macro is meant to avoid this.

Signed-off-by: Thomas Egerer <[email protected]>
This commit is contained in:
Thomas Egerer
2026-05-06 10:46:43 +02:00
committed by Tobias Brunner
parent 4821758d46
commit 82c01b7060
2 changed files with 8 additions and 16 deletions
@@ -105,7 +105,6 @@ bool openssl_fingerprint(EVP_PKEY *key, cred_encoding_type_t type, chunk_t *fp)
{
hasher_t *hasher;
chunk_t enc;
u_char *p;
if (lib->encoding->get_cache(lib->encoding, type, key, fp))
{
@@ -114,14 +113,10 @@ bool openssl_fingerprint(EVP_PKEY *key, cred_encoding_type_t type, chunk_t *fp)
switch (type)
{
case KEYID_PUBKEY_SHA1:
enc = chunk_alloc(i2d_PublicKey(key, NULL));
p = enc.ptr;
i2d_PublicKey(key, &p);
enc = openssl_i2chunk(PublicKey, key);
break;
case KEYID_PUBKEY_INFO_SHA1:
enc = chunk_alloc(i2d_PUBKEY(key, NULL));
p = enc.ptr;
i2d_PUBKEY(key, &p);
enc = openssl_i2chunk(PUBKEY, key);
break;
default:
return FALSE;