lib/pubkey2fp.c: fix CID 62724 correctly.
This commit is contained in:
parent
ec438c36f9
commit
3a71db1d0b
@ -88,29 +88,33 @@ xbps_pubkey2fp(struct xbps_handle *xhp, xbps_data_t pubkey)
|
|||||||
xbps_dbg_printf(xhp,
|
xbps_dbg_printf(xhp,
|
||||||
"unable to decode public key from the given file: %s\n",
|
"unable to decode public key from the given file: %s\n",
|
||||||
ERR_error_string(ERR_get_error(), NULL));
|
ERR_error_string(ERR_get_error(), NULL));
|
||||||
goto error;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EVP_PKEY_type(pPubKey->type) != EVP_PKEY_RSA) {
|
if (EVP_PKEY_type(pPubKey->type) != EVP_PKEY_RSA) {
|
||||||
xbps_dbg_printf(xhp, "only RSA public keys are currently supported\n");
|
xbps_dbg_printf(xhp, "only RSA public keys are currently supported\n");
|
||||||
goto error;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
pRsa = EVP_PKEY_get1_RSA(pPubKey);
|
pRsa = EVP_PKEY_get1_RSA(pPubKey);
|
||||||
if (!pRsa) {
|
if (!pRsa) {
|
||||||
xbps_dbg_printf(xhp, "failed to get RSA public key : %s\n",
|
xbps_dbg_printf(xhp, "failed to get RSA public key : %s\n",
|
||||||
ERR_error_string(ERR_get_error(), NULL));
|
ERR_error_string(ERR_get_error(), NULL));
|
||||||
goto error;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
// reading the modulus
|
// reading the modulus
|
||||||
nLen = BN_num_bytes(pRsa->n);
|
nLen = BN_num_bytes(pRsa->n);
|
||||||
nBytes = (unsigned char*) malloc(nLen);
|
nBytes = (unsigned char*) malloc(nLen);
|
||||||
|
if (nBytes == NULL)
|
||||||
|
goto out;
|
||||||
BN_bn2bin(pRsa->n, nBytes);
|
BN_bn2bin(pRsa->n, nBytes);
|
||||||
|
|
||||||
// reading the public exponent
|
// reading the public exponent
|
||||||
eLen = BN_num_bytes(pRsa->e);
|
eLen = BN_num_bytes(pRsa->e);
|
||||||
eBytes = (unsigned char*) malloc(eLen);
|
eBytes = (unsigned char*) malloc(eLen);
|
||||||
|
if (eBytes == NULL)
|
||||||
|
goto out;
|
||||||
BN_bn2bin(pRsa->e, eBytes);
|
BN_bn2bin(pRsa->e, eBytes);
|
||||||
|
|
||||||
encodingLength = 11 + 4 + eLen + 4 + nLen;
|
encodingLength = 11 + 4 + eLen + 4 + nLen;
|
||||||
@ -135,14 +139,14 @@ xbps_pubkey2fp(struct xbps_handle *xhp, xbps_data_t pubkey)
|
|||||||
EVP_DigestInit_ex(&mdctx, EVP_md5(), NULL);
|
EVP_DigestInit_ex(&mdctx, EVP_md5(), NULL);
|
||||||
EVP_DigestUpdate(&mdctx, pEncoding, encodingLength);
|
EVP_DigestUpdate(&mdctx, pEncoding, encodingLength);
|
||||||
if (EVP_DigestFinal_ex(&mdctx, md_value, &md_len) == 0)
|
if (EVP_DigestFinal_ex(&mdctx, md_value, &md_len) == 0)
|
||||||
goto error;
|
goto out;
|
||||||
EVP_MD_CTX_cleanup(&mdctx);
|
EVP_MD_CTX_cleanup(&mdctx);
|
||||||
/*
|
/*
|
||||||
* Convert result to a compatible OpenSSH hex fingerprint.
|
* Convert result to a compatible OpenSSH hex fingerprint.
|
||||||
*/
|
*/
|
||||||
hexfpstr = fp2str(md_value, md_len);
|
hexfpstr = fp2str(md_value, md_len);
|
||||||
|
|
||||||
error:
|
out:
|
||||||
if (bio)
|
if (bio)
|
||||||
BIO_free_all(bio);
|
BIO_free_all(bio);
|
||||||
if (pRsa)
|
if (pRsa)
|
||||||
|
Loading…
Reference in New Issue
Block a user