forked from wolfSSL/wolfssl
Fix for PKCS7 sign to allow providing a public key only if using crypto callback w/devId. ZD13949.
This commit is contained in:
@ -1762,30 +1762,38 @@ static int wc_PKCS7_RsaSign(PKCS7* pkcs7, byte* in, word32 inSz, ESD* esd)
|
|||||||
idx = 0;
|
idx = 0;
|
||||||
ret = wc_RsaPrivateKeyDecode(pkcs7->privateKey, &idx, privKey,
|
ret = wc_RsaPrivateKeyDecode(pkcs7->privateKey, &idx, privKey,
|
||||||
pkcs7->privateKeySz);
|
pkcs7->privateKeySz);
|
||||||
|
/* If not using old FIPS or CAVP selftest, or not using FAST,
|
||||||
|
* or USER RSA, able to check RSA key. */
|
||||||
|
if (ret == 0) {
|
||||||
|
#if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(HAVE_FAST_RSA) && \
|
||||||
|
!defined(HAVE_USER_RSA) && (!defined(HAVE_FIPS) || \
|
||||||
|
(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) && \
|
||||||
|
!defined(HAVE_SELFTEST) && !defined(HAVE_INTEL_QA)
|
||||||
|
|
||||||
|
#if defined(WOLFSSL_KEY_GEN) && !defined(WOLFSSL_NO_RSA_KEY_CHECK)
|
||||||
|
/* verify imported private key is a valid key before using it */
|
||||||
|
ret = wc_CheckRsaKey(privKey);
|
||||||
|
if (ret != 0) {
|
||||||
|
WOLFSSL_MSG("Invalid RSA private key, check "
|
||||||
|
"pkcs7->privateKey");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#ifdef WOLF_CRYPTO_CB
|
||||||
|
else if (ret == ASN_PARSE_E && pkcs7->devId != INVALID_DEVID) {
|
||||||
|
/* if using crypto callbacks, try public key decode */
|
||||||
|
idx = 0;
|
||||||
|
ret = wc_RsaPublicKeyDecode(pkcs7->privateKey, &idx, privKey,
|
||||||
|
pkcs7->privateKeySz);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else if (pkcs7->devId == INVALID_DEVID) {
|
else if (pkcs7->devId == INVALID_DEVID) {
|
||||||
ret = BAD_FUNC_ARG;
|
ret = BAD_FUNC_ARG;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If not using old FIPS or CAVP selftest, or not using FAST,
|
|
||||||
or USER RSA, able to check RSA key. */
|
|
||||||
#if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(HAVE_FAST_RSA) && \
|
|
||||||
!defined(HAVE_USER_RSA) && (!defined(HAVE_FIPS) || \
|
|
||||||
(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) && \
|
|
||||||
!defined(HAVE_SELFTEST) && !defined(HAVE_INTEL_QA)
|
|
||||||
|
|
||||||
#if defined(WOLFSSL_KEY_GEN) && !defined(WOLFSSL_NO_RSA_KEY_CHECK)
|
|
||||||
/* verify imported private key is a valid key before using it */
|
|
||||||
if (ret == 0) {
|
|
||||||
ret = wc_CheckRsaKey(privKey);
|
|
||||||
if (ret != 0) {
|
|
||||||
WOLFSSL_MSG("Invalid RSA private key, check pkcs7->privateKey");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
do {
|
do {
|
||||||
@ -1844,20 +1852,28 @@ static int wc_PKCS7_EcdsaSign(PKCS7* pkcs7, byte* in, word32 inSz, ESD* esd)
|
|||||||
idx = 0;
|
idx = 0;
|
||||||
ret = wc_EccPrivateKeyDecode(pkcs7->privateKey, &idx, privKey,
|
ret = wc_EccPrivateKeyDecode(pkcs7->privateKey, &idx, privKey,
|
||||||
pkcs7->privateKeySz);
|
pkcs7->privateKeySz);
|
||||||
|
/* verify imported private key is a valid key before using it */
|
||||||
|
if (ret == 0) {
|
||||||
|
ret = wc_ecc_check_key(privKey);
|
||||||
|
if (ret != 0) {
|
||||||
|
WOLFSSL_MSG("Invalid ECC private key, check "
|
||||||
|
"pkcs7->privateKey");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#ifdef WOLF_CRYPTO_CB
|
||||||
|
else if (ret == ASN_PARSE_E && pkcs7->devId != INVALID_DEVID) {
|
||||||
|
/* if using crypto callbacks, try public key decode */
|
||||||
|
idx = 0;
|
||||||
|
ret = wc_EccPublicKeyDecode(pkcs7->privateKey, &idx, privKey,
|
||||||
|
pkcs7->privateKeySz);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else if (pkcs7->devId == INVALID_DEVID) {
|
else if (pkcs7->devId == INVALID_DEVID) {
|
||||||
ret = BAD_FUNC_ARG;
|
ret = BAD_FUNC_ARG;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* verify imported private key is a valid key before using it */
|
|
||||||
if (ret == 0) {
|
|
||||||
ret = wc_ecc_check_key(privKey);
|
|
||||||
if (ret != 0) {
|
|
||||||
WOLFSSL_MSG("Invalid ECC private key, check pkcs7->privateKey");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
outSz = sizeof(esd->encContentDigest);
|
outSz = sizeof(esd->encContentDigest);
|
||||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||||
|
Reference in New Issue
Block a user