Juan Lang : rsaenh: Store a key' s value to the registry when a key is imported.
Alexandre Julliard
julliard at winehq.org
Thu Jan 29 09:15:04 CST 2009
Module: wine
Branch: master
Commit: 4eb1ee42776de6f76454f16095ce97e24828ba1d
URL: http://source.winehq.org/git/wine.git/?a=commit;h=4eb1ee42776de6f76454f16095ce97e24828ba1d
Author: Juan Lang <juan.lang at gmail.com>
Date: Wed Jan 28 21:48:45 2009 -0800
rsaenh: Store a key's value to the registry when a key is imported.
---
dlls/rsaenh/rsaenh.c | 77 +++++++++++++++++++++++++++++++++++--------
dlls/rsaenh/tests/rsaenh.c | 1 -
2 files changed, 62 insertions(+), 16 deletions(-)
diff --git a/dlls/rsaenh/rsaenh.c b/dlls/rsaenh/rsaenh.c
index 5da95bd..c94603a 100644
--- a/dlls/rsaenh/rsaenh.c
+++ b/dlls/rsaenh/rsaenh.c
@@ -2451,12 +2451,21 @@ BOOL WINAPI RSAENH_CPExportKey(HCRYPTPROV hProv, HCRYPTKEY hKey, HCRYPTKEY hPubK
* hProv [I] Key container into which the key is to be imported.
* src [I] Key which will replace *dest
* dest [I] Points to key to be released and replaced with src
+ * fStoreKey [I] If TRUE, the newly installed key is stored to the registry.
*/
static void release_and_install_key(HCRYPTPROV hProv, HCRYPTKEY src,
- HCRYPTKEY *dest)
+ HCRYPTKEY *dest, DWORD fStoreKey)
{
RSAENH_CPDestroyKey(hProv, *dest);
copy_handle(&handle_table, src, RSAENH_MAGIC_KEY, dest);
+ if (fStoreKey)
+ {
+ KEYCONTAINER *pKeyContainer;
+
+ if (lookup_handle(&handle_table, hProv, RSAENH_MAGIC_CONTAINER,
+ (OBJECTHDR**)&pKeyContainer))
+ store_key_container_keys(pKeyContainer);
+ }
}
/******************************************************************************
@@ -2470,6 +2479,7 @@ static void release_and_install_key(HCRYPTPROV hProv, HCRYPTKEY src,
* dwDataLen [I] Length of data in buffer at pbData.
* dwFlags [I] One of:
* CRYPT_EXPORTABLE: the imported key is marked exportable
+ * fStoreKey [I] If TRUE, the imported key is stored to the registry.
* phKey [O] Handle to the imported key.
*
*
@@ -2482,7 +2492,7 @@ static void release_and_install_key(HCRYPTPROV hProv, HCRYPTKEY src,
* Failure: FALSE.
*/
static BOOL import_private_key(HCRYPTPROV hProv, CONST BYTE *pbData, DWORD dwDataLen,
- DWORD dwFlags, HCRYPTKEY *phKey)
+ DWORD dwFlags, BOOL fStoreKey, HCRYPTKEY *phKey)
{
KEYCONTAINER *pKeyContainer;
CRYPTKEY *pCryptKey;
@@ -2519,12 +2529,14 @@ static BOOL import_private_key(HCRYPTPROV hProv, CONST BYTE *pbData, DWORD dwDat
case AT_SIGNATURE:
case CALG_RSA_SIGN:
TRACE("installing signing key\n");
- release_and_install_key(hProv, *phKey, &pKeyContainer->hSignatureKeyPair);
+ release_and_install_key(hProv, *phKey, &pKeyContainer->hSignatureKeyPair,
+ fStoreKey);
break;
case AT_KEYEXCHANGE:
case CALG_RSA_KEYX:
TRACE("installing key exchange key\n");
- release_and_install_key(hProv, *phKey, &pKeyContainer->hKeyExchangeKeyPair);
+ release_and_install_key(hProv, *phKey, &pKeyContainer->hKeyExchangeKeyPair,
+ fStoreKey);
break;
}
}
@@ -2542,6 +2554,7 @@ static BOOL import_private_key(HCRYPTPROV hProv, CONST BYTE *pbData, DWORD dwDat
* dwDataLen [I] Length of data in buffer at pbData.
* dwFlags [I] One of:
* CRYPT_EXPORTABLE: the imported key is marked exportable
+ * fStoreKey [I] If TRUE, the imported key is stored to the registry.
* phKey [O] Handle to the imported key.
*
*
@@ -2554,7 +2567,7 @@ static BOOL import_private_key(HCRYPTPROV hProv, CONST BYTE *pbData, DWORD dwDat
* Failure: FALSE.
*/
static BOOL import_public_key(HCRYPTPROV hProv, CONST BYTE *pbData, DWORD dwDataLen,
- DWORD dwFlags, HCRYPTKEY *phKey)
+ DWORD dwFlags, BOOL fStoreKey, HCRYPTKEY *phKey)
{
KEYCONTAINER *pKeyContainer;
CRYPTKEY *pCryptKey;
@@ -2595,7 +2608,8 @@ static BOOL import_public_key(HCRYPTPROV hProv, CONST BYTE *pbData, DWORD dwData
case AT_KEYEXCHANGE:
case CALG_RSA_KEYX:
TRACE("installing public key\n");
- release_and_install_key(hProv, *phKey, &pKeyContainer->hKeyExchangeKeyPair);
+ release_and_install_key(hProv, *phKey, &pKeyContainer->hKeyExchangeKeyPair,
+ fStoreKey);
break;
}
}
@@ -2675,9 +2689,10 @@ static BOOL import_symmetric_key(HCRYPTPROV hProv, CONST BYTE *pbData,
}
/******************************************************************************
- * CPImportKey (RSAENH.@)
+ * import_key [Internal]
*
- * Import a BLOB'ed key into a key container.
+ * Import a BLOB'ed key into a key container, optionally storing the key's
+ * value to the registry.
*
* PARAMS
* hProv [I] Key container into which the key is to be imported.
@@ -2686,21 +2701,20 @@ static BOOL import_symmetric_key(HCRYPTPROV hProv, CONST BYTE *pbData,
* hPubKey [I] Key used to decrypt sensitive BLOB data.
* dwFlags [I] One of:
* CRYPT_EXPORTABLE: the imported key is marked exportable
+ * fStoreKey [I] If TRUE, the imported key is stored to the registry.
* phKey [O] Handle to the imported key.
*
* RETURNS
* Success: TRUE.
* Failure: FALSE.
*/
-BOOL WINAPI RSAENH_CPImportKey(HCRYPTPROV hProv, CONST BYTE *pbData, DWORD dwDataLen,
- HCRYPTKEY hPubKey, DWORD dwFlags, HCRYPTKEY *phKey)
+static BOOL import_key(HCRYPTPROV hProv, CONST BYTE *pbData, DWORD dwDataLen,
+ HCRYPTKEY hPubKey, DWORD dwFlags, BOOL fStoreKey,
+ HCRYPTKEY *phKey)
{
KEYCONTAINER *pKeyContainer;
CONST BLOBHEADER *pBlobHeader = (CONST BLOBHEADER*)pbData;
- TRACE("(hProv=%08lx, pbData=%p, dwDataLen=%d, hPubKey=%08lx, dwFlags=%08x, phKey=%p)\n",
- hProv, pbData, dwDataLen, hPubKey, dwFlags, phKey);
-
if (!lookup_handle(&handle_table, hProv, RSAENH_MAGIC_CONTAINER,
(OBJECTHDR**)&pKeyContainer))
{
@@ -2716,13 +2730,19 @@ BOOL WINAPI RSAENH_CPImportKey(HCRYPTPROV hProv, CONST BYTE *pbData, DWORD dwDat
return FALSE;
}
+ /* If this is a verify-only context, the key is not persisted regardless of
+ * fStoreKey's original value.
+ */
+ fStoreKey = fStoreKey && !(dwFlags & CRYPT_VERIFYCONTEXT);
switch (pBlobHeader->bType)
{
case PRIVATEKEYBLOB:
- return import_private_key(hProv, pbData, dwDataLen, dwFlags, phKey);
+ return import_private_key(hProv, pbData, dwDataLen, dwFlags,
+ fStoreKey, phKey);
case PUBLICKEYBLOB:
- return import_public_key(hProv, pbData, dwDataLen, dwFlags, phKey);
+ return import_public_key(hProv, pbData, dwDataLen, dwFlags,
+ fStoreKey, phKey);
case SIMPLEBLOB:
return import_symmetric_key(hProv, pbData, dwDataLen, hPubKey,
@@ -2735,6 +2755,33 @@ BOOL WINAPI RSAENH_CPImportKey(HCRYPTPROV hProv, CONST BYTE *pbData, DWORD dwDat
}
/******************************************************************************
+ * CPImportKey (RSAENH.@)
+ *
+ * Import a BLOB'ed key into a key container.
+ *
+ * PARAMS
+ * hProv [I] Key container into which the key is to be imported.
+ * pbData [I] Pointer to a buffer which holds the BLOB.
+ * dwDataLen [I] Length of data in buffer at pbData.
+ * hPubKey [I] Key used to decrypt sensitive BLOB data.
+ * dwFlags [I] One of:
+ * CRYPT_EXPORTABLE: the imported key is marked exportable
+ * phKey [O] Handle to the imported key.
+ *
+ * RETURNS
+ * Success: TRUE.
+ * Failure: FALSE.
+ */
+BOOL WINAPI RSAENH_CPImportKey(HCRYPTPROV hProv, CONST BYTE *pbData, DWORD dwDataLen,
+ HCRYPTKEY hPubKey, DWORD dwFlags, HCRYPTKEY *phKey)
+{
+ TRACE("(hProv=%08lx, pbData=%p, dwDataLen=%d, hPubKey=%08lx, dwFlags=%08x, phKey=%p)\n",
+ hProv, pbData, dwDataLen, hPubKey, dwFlags, phKey);
+
+ return import_key(hProv, pbData, dwDataLen, hPubKey, dwFlags, TRUE, phKey);
+}
+
+/******************************************************************************
* CPGenKey (RSAENH.@)
*
* Generate a key in the key container
diff --git a/dlls/rsaenh/tests/rsaenh.c b/dlls/rsaenh/tests/rsaenh.c
index 4f1899e..5d58222 100644
--- a/dlls/rsaenh/tests/rsaenh.c
+++ b/dlls/rsaenh/tests/rsaenh.c
@@ -2233,7 +2233,6 @@ static void test_key_initialization(void)
result = CryptAcquireContext(&prov2, szContainer, szProvider, PROV_RSA_FULL, 0);
ok(result, "%08x\n", GetLastError());
result = CryptGetUserKey(prov2, AT_KEYEXCHANGE, &hKey);
- todo_wine
ok(result, "%08x\n", GetLastError());
if (result) CryptDestroyKey(hKey);
CryptReleaseContext(prov2, 0);
More information about the wine-cvs
mailing list