Merge pull request #1942 from SparkiDev/asn_trad_fix

Return ToTraditional API to original signature
This commit is contained in:
toddouska
2018-11-28 08:08:26 -08:00
committed by GitHub
4 changed files with 30 additions and 13 deletions

View File

@ -6614,7 +6614,7 @@ WOLFSSL_PKCS8_PRIV_KEY_INFO* wolfSSL_d2i_PKCS8_PKEY_bio(WOLFSSL_BIO* bio,
if ((keySz = wc_KeyPemToDer(mem, memSz, mem, memSz, NULL)) < 0) {
WOLFSSL_MSG("Not PEM format");
keySz = memSz;
if ((keySz = ToTraditional((byte*)mem, (word32)keySz, &algId)) < 0) {
if ((keySz = ToTraditional_ex((byte*)mem, (word32)keySz, &algId)) < 0) {
return NULL;
}
}
@ -6834,7 +6834,7 @@ WOLFSSL_EVP_PKEY* wolfSSL_d2i_PrivateKey(int type, WOLFSSL_EVP_PKEY** out,
/* Check if input buffer has PKCS8 header. In the case that it does not
* have a PKCS8 header then do not error out. */
if ((ret = ToTraditionalInline((const byte*)(*in), &idx, (word32)inSz,
if ((ret = ToTraditionalInline_ex((const byte*)(*in), &idx, (word32)inSz,
&algId)) > 0) {
WOLFSSL_MSG("Found and removed PKCS8 header");
}
@ -35531,7 +35531,7 @@ WOLFSSL_EVP_PKEY* wolfSSL_d2i_AutoPrivateKey(WOLFSSL_EVP_PKEY** pkey,
word32 keyLen = (word32)length;
/* Take off PKCS#8 wrapper if found. */
if ((len = ToTraditionalInline(der, &idx, keyLen, &algId)) >= 0) {
if ((len = ToTraditionalInline_ex(der, &idx, keyLen, &algId)) >= 0) {
der += idx;
keyLen = len;
}

View File

@ -2267,8 +2267,8 @@ int wc_RsaPrivateKeyDecode(const byte* input, word32* inOutIdx, RsaKey* key,
/* Remove PKCS8 header, place inOutIdx at beginning of traditional,
* return traditional length on success, negative on error */
int ToTraditionalInline(const byte* input, word32* inOutIdx, word32 sz,
word32* algId)
int ToTraditionalInline_ex(const byte* input, word32* inOutIdx, word32 sz,
word32* algId)
{
word32 idx;
int version, length;
@ -2302,8 +2302,15 @@ int ToTraditionalInline(const byte* input, word32* inOutIdx, word32 sz,
return length;
}
int ToTraditionalInline(const byte* input, word32* inOutIdx, word32 sz)
{
word32 oid;
return ToTraditionalInline_ex(input, inOutIdx, sz, &oid);
}
/* Remove PKCS8 header, move beginning of traditional to beginning of input */
int ToTraditional(byte* input, word32 sz, word32* algId)
int ToTraditional_ex(byte* input, word32 sz, word32* algId)
{
word32 inOutIdx = 0;
int length;
@ -2311,7 +2318,7 @@ int ToTraditional(byte* input, word32 sz, word32* algId)
if (input == NULL)
return BAD_FUNC_ARG;
length = ToTraditionalInline(input, &inOutIdx, sz, algId);
length = ToTraditionalInline_ex(input, &inOutIdx, sz, algId);
if (length < 0)
return length;
@ -2320,6 +2327,12 @@ int ToTraditional(byte* input, word32 sz, word32* algId)
return length;
}
int ToTraditional(byte* input, word32 sz)
{
word32 oid;
return ToTraditional_ex(input, sz, &oid);
}
/* find beginning of traditional key inside PKCS#8 unencrypted buffer
* return traditional length on success, with inOutIdx at beginning of
@ -2333,7 +2346,7 @@ int wc_GetPkcs8TraditionalOffset(byte* input, word32* inOutIdx, word32 sz)
if (input == NULL || inOutIdx == NULL || (*inOutIdx > sz))
return BAD_FUNC_ARG;
length = ToTraditionalInline(input, inOutIdx, sz, &algId);
length = ToTraditionalInline_ex(input, inOutIdx, sz, &algId);
return length;
}
@ -3423,7 +3436,7 @@ exit_tte:
if (ret == 0) {
XMEMMOVE(input, input + inOutIdx, length);
ret = ToTraditional(input, length, algId);
ret = ToTraditional_ex(input, length, algId);
}
return ret;
@ -8999,7 +9012,7 @@ int PemToDer(const unsigned char* buff, long longSz, int type,
) && !encrypted_key)
{
/* pkcs8 key, convert and adjust length */
if ((ret = ToTraditional(der->buffer, der->length, &algId)) > 0) {
if ((ret = ToTraditional_ex(der->buffer, der->length, &algId)) > 0) {
der->length = ret;
}
else {

View File

@ -901,7 +901,7 @@ int wc_PKCS12_parse(WC_PKCS12* pkcs12, const char* psw,
ERROR_OUT(MEMORY_E, exit_pk12par);
}
XMEMCPY(*pkey, data + idx, size);
*pkeySz = ToTraditional(*pkey, size, &algId);
*pkeySz = ToTraditional_ex(*pkey, size, &algId);
}
#ifdef WOLFSSL_DEBUG_PKCS12

View File

@ -982,9 +982,13 @@ WOLFSSL_LOCAL void FreeTrustedPeer(TrustedPeerCert*, void*);
WOLFSSL_LOCAL void FreeTrustedPeerTable(TrustedPeerCert**, int, void*);
#endif /* WOLFSSL_TRUST_PEER_CERT */
WOLFSSL_ASN_API int ToTraditional(byte* buffer, word32 length, word32* algId);
WOLFSSL_ASN_API int ToTraditional(byte* buffer, word32 length);
WOLFSSL_ASN_API int ToTraditional_ex(byte* buffer, word32 length,
word32* algId);
WOLFSSL_LOCAL int ToTraditionalInline(const byte* input, word32* inOutIdx,
word32 length, word32* algId);
word32 length);
WOLFSSL_LOCAL int ToTraditionalInline_ex(const byte* input, word32* inOutIdx,
word32 length, word32* algId);
WOLFSSL_LOCAL int ToTraditionalEnc(byte* buffer, word32 length,const char*,int,
word32* algId);
WOLFSSL_ASN_API int UnTraditionalEnc(byte* key, word32 keySz, byte* out,