rsaenh: Implement importing PLAINTEXTKEYBLOBs.
This commit is contained in:
parent
64b320b7d9
commit
ff6328efcc
|
@ -2833,6 +2833,53 @@ static BOOL import_symmetric_key(HCRYPTPROV hProv, CONST BYTE *pbData,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* import_plaintext_key [Internal]
|
||||||
|
*
|
||||||
|
* Import a plaintext key into a key container.
|
||||||
|
*
|
||||||
|
* PARAMS
|
||||||
|
* hProv [I] Key container into which the symmetric key is to be imported.
|
||||||
|
* pbData [I] Pointer to a buffer which holds the plaintext key BLOB.
|
||||||
|
* dwDataLen [I] Length of data in buffer at pbData.
|
||||||
|
* dwFlags [I] One of:
|
||||||
|
* CRYPT_EXPORTABLE: the imported key is marked exportable
|
||||||
|
* phKey [O] Handle to the imported key.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTES
|
||||||
|
* Assumes the caller has already checked the BLOBHEADER at pbData to ensure
|
||||||
|
* it's a PLAINTEXTKEYBLOB.
|
||||||
|
*
|
||||||
|
* RETURNS
|
||||||
|
* Success: TRUE.
|
||||||
|
* Failure: FALSE.
|
||||||
|
*/
|
||||||
|
static BOOL import_plaintext_key(HCRYPTPROV hProv, CONST BYTE *pbData,
|
||||||
|
DWORD dwDataLen, DWORD dwFlags,
|
||||||
|
HCRYPTKEY *phKey)
|
||||||
|
{
|
||||||
|
CRYPTKEY *pCryptKey;
|
||||||
|
CONST BLOBHEADER *pBlobHeader = (CONST BLOBHEADER*)pbData;
|
||||||
|
CONST DWORD *pKeyLen = (CONST DWORD *)(pBlobHeader + 1);
|
||||||
|
CONST BYTE *pbKeyStream = (CONST BYTE*)(pKeyLen + 1);
|
||||||
|
|
||||||
|
if (dwDataLen < sizeof(BLOBHEADER)+sizeof(DWORD)+*pKeyLen)
|
||||||
|
{
|
||||||
|
SetLastError(NTE_BAD_DATA); /* FIXME: error code */
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*phKey = new_key(hProv, pBlobHeader->aiKeyAlg, *pKeyLen<<19, &pCryptKey);
|
||||||
|
if (*phKey == (HCRYPTKEY)INVALID_HANDLE_VALUE)
|
||||||
|
return FALSE;
|
||||||
|
memcpy(pCryptKey->abKeyValue, pbKeyStream, *pKeyLen);
|
||||||
|
setup_key(pCryptKey);
|
||||||
|
if (dwFlags & CRYPT_EXPORTABLE)
|
||||||
|
pCryptKey->dwPermissions |= CRYPT_EXPORT;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* import_key [Internal]
|
* import_key [Internal]
|
||||||
*
|
*
|
||||||
|
@ -2893,6 +2940,10 @@ static BOOL import_key(HCRYPTPROV hProv, CONST BYTE *pbData, DWORD dwDataLen,
|
||||||
return import_symmetric_key(hProv, pbData, dwDataLen, hPubKey,
|
return import_symmetric_key(hProv, pbData, dwDataLen, hPubKey,
|
||||||
dwFlags, phKey);
|
dwFlags, phKey);
|
||||||
|
|
||||||
|
case PLAINTEXTKEYBLOB:
|
||||||
|
return import_plaintext_key(hProv, pbData, dwDataLen, dwFlags,
|
||||||
|
phKey);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
SetLastError(NTE_BAD_TYPE); /* FIXME: error code? */
|
SetLastError(NTE_BAD_TYPE); /* FIXME: error code? */
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
Loading…
Reference in New Issue