--- dlls/rsaenh/cryptoprovutils.c | 111 ++++++++++++++++++++++++++++++++++ dlls/rsaenh/cryptoprovutils.h | 4 ++ dlls/rsaenh/rsaenh.c | 111 ---------------------------------- 3 files changed, 115 insertions(+), 111 deletions(-)
diff --git a/dlls/rsaenh/cryptoprovutils.c b/dlls/rsaenh/cryptoprovutils.c index 9f774bad1d..44bbc923b8 100644 --- a/dlls/rsaenh/cryptoprovutils.c +++ b/dlls/rsaenh/cryptoprovutils.c @@ -208,3 +208,114 @@ void store_key_pair(HCRYPTKEY hCryptKey, HKEY hKey, DWORD dwKeySpec, DWORD dwFla } }
+/****************************************************************************** + * store_key_container_keys [Internal] + * + * Stores key container's keys in a persistent location. + * + * PARAMS + * pKeyContainer [I] Pointer to the key container whose keys are to be saved + */ +void store_key_container_keys(KEYCONTAINER *pKeyContainer) +{ + HKEY hKey; + DWORD dwFlags; + + /* On WinXP, persistent keys are stored in a file located at: + * $AppData$\Microsoft\Crypto\RSA\$SID$\some_hex_string + */ + + if (pKeyContainer->dwFlags & CRYPT_MACHINE_KEYSET) + dwFlags = CRYPTPROTECT_LOCAL_MACHINE; + else + dwFlags = 0; + + if (create_container_key(pKeyContainer, KEY_WRITE, &hKey)) + { + store_key_pair(pKeyContainer->hKeyExchangeKeyPair, hKey, + AT_KEYEXCHANGE, dwFlags); + store_key_pair(pKeyContainer->hSignatureKeyPair, hKey, + AT_SIGNATURE, dwFlags); + RegCloseKey(hKey); + } +} + +/****************************************************************************** + * map_key_spec_to_permissions_name [Internal] + * + * Returns the name of the registry value associated with the permissions for + * a key spec. + * + * PARAMS + * dwKeySpec [I] AT_KEYEXCHANGE or AT_SIGNATURE + * + * RETURNS + * Success: Name of registry value. + * Failure: NULL + */ +LPCSTR map_key_spec_to_permissions_name(DWORD dwKeySpec) +{ + LPCSTR szValueName; + + switch (dwKeySpec) + { + case AT_KEYEXCHANGE: + szValueName = "KeyExchangePermissions"; + break; + case AT_SIGNATURE: + szValueName = "SignaturePermissions"; + break; + default: + WARN("invalid key spec %d\n", dwKeySpec); + szValueName = NULL; + } + return szValueName; +} + +/****************************************************************************** + * store_key_permissions [Internal] + * + * Stores a key's permissions to the registry + * + * PARAMS + * hCryptKey [I] Handle to the key whose permissions are to be stored + * hKey [I] Registry key where the key permissions are to be stored + * dwKeySpec [I] AT_KEYEXCHANGE or AT_SIGNATURE + */ +void store_key_permissions(HCRYPTKEY hCryptKey, HKEY hKey, DWORD dwKeySpec) +{ + LPCSTR szValueName; + CRYPTKEY *pKey; + + if (!(szValueName = map_key_spec_to_permissions_name(dwKeySpec))) + return; + if (lookup_handle(&handle_table, hCryptKey, RSAENH_MAGIC_KEY, + (OBJECTHDR**)&pKey)) + RegSetValueExA(hKey, szValueName, 0, REG_DWORD, + (BYTE *)&pKey->dwPermissions, + sizeof(pKey->dwPermissions)); +} + +/****************************************************************************** + * store_key_container_permissions [Internal] + * + * Stores key container's key permissions in a persistent location. + * + * PARAMS + * pKeyContainer [I] Pointer to the key container whose key permissions are to + * be saved + */ +void store_key_container_permissions(KEYCONTAINER *pKeyContainer) +{ + HKEY hKey; + + if (create_container_key(pKeyContainer, KEY_WRITE, &hKey)) + { + store_key_permissions(pKeyContainer->hKeyExchangeKeyPair, hKey, + AT_KEYEXCHANGE); + store_key_permissions(pKeyContainer->hSignatureKeyPair, hKey, + AT_SIGNATURE); + RegCloseKey(hKey); + } +} + diff --git a/dlls/rsaenh/cryptoprovutils.h b/dlls/rsaenh/cryptoprovutils.h index 499b0b8140..4b5fcf2f22 100644 --- a/dlls/rsaenh/cryptoprovutils.h +++ b/dlls/rsaenh/cryptoprovutils.h @@ -77,4 +77,8 @@ BOOL crypt_export_key(CRYPTKEY *pCryptKey, HCRYPTKEY hPubKey, DWORD dwBlobType, DWORD dwFlags, BOOL force, BYTE *pbData, DWORD *pdwDataLen); LPCSTR map_key_spec_to_key_pair_name(DWORD dwKeySpec); void store_key_pair(HCRYPTKEY hCryptKey, HKEY hKey, DWORD dwKeySpec, DWORD dwFlags); +void store_key_container_keys(KEYCONTAINER *pKeyContainer); +LPCSTR map_key_spec_to_permissions_name(DWORD dwKeySpec); +void store_key_permissions(HCRYPTKEY hCryptKey, HKEY hKey, DWORD dwKeySpec); +void store_key_container_permissions(KEYCONTAINER *pKeyContainer); #endif /* __WINE_CRYPTOPROVUTILS_H */ diff --git a/dlls/rsaenh/rsaenh.c b/dlls/rsaenh/rsaenh.c index 8925abefab..5557068813 100644 --- a/dlls/rsaenh/rsaenh.c +++ b/dlls/rsaenh/rsaenh.c @@ -862,117 +862,6 @@ static HCRYPTKEY new_key(HCRYPTPROV hProv, ALG_ID aiAlgid, DWORD dwFlags, CRYPTK return hCryptKey; }
-/****************************************************************************** - * map_key_spec_to_permissions_name [Internal] - * - * Returns the name of the registry value associated with the permissions for - * a key spec. - * - * PARAMS - * dwKeySpec [I] AT_KEYEXCHANGE or AT_SIGNATURE - * - * RETURNS - * Success: Name of registry value. - * Failure: NULL - */ -static LPCSTR map_key_spec_to_permissions_name(DWORD dwKeySpec) -{ - LPCSTR szValueName; - - switch (dwKeySpec) - { - case AT_KEYEXCHANGE: - szValueName = "KeyExchangePermissions"; - break; - case AT_SIGNATURE: - szValueName = "SignaturePermissions"; - break; - default: - WARN("invalid key spec %d\n", dwKeySpec); - szValueName = NULL; - } - return szValueName; -} - -/****************************************************************************** - * store_key_permissions [Internal] - * - * Stores a key's permissions to the registry - * - * PARAMS - * hCryptKey [I] Handle to the key whose permissions are to be stored - * hKey [I] Registry key where the key permissions are to be stored - * dwKeySpec [I] AT_KEYEXCHANGE or AT_SIGNATURE - */ -static void store_key_permissions(HCRYPTKEY hCryptKey, HKEY hKey, DWORD dwKeySpec) -{ - LPCSTR szValueName; - CRYPTKEY *pKey; - - if (!(szValueName = map_key_spec_to_permissions_name(dwKeySpec))) - return; - if (lookup_handle(&handle_table, hCryptKey, RSAENH_MAGIC_KEY, - (OBJECTHDR**)&pKey)) - RegSetValueExA(hKey, szValueName, 0, REG_DWORD, - (BYTE *)&pKey->dwPermissions, - sizeof(pKey->dwPermissions)); -} - -/****************************************************************************** - * store_key_container_keys [Internal] - * - * Stores key container's keys in a persistent location. - * - * PARAMS - * pKeyContainer [I] Pointer to the key container whose keys are to be saved - */ -static void store_key_container_keys(KEYCONTAINER *pKeyContainer) -{ - HKEY hKey; - DWORD dwFlags; - - /* On WinXP, persistent keys are stored in a file located at: - * $AppData$\Microsoft\Crypto\RSA\$SID$\some_hex_string - */ - - if (pKeyContainer->dwFlags & CRYPT_MACHINE_KEYSET) - dwFlags = CRYPTPROTECT_LOCAL_MACHINE; - else - dwFlags = 0; - - if (create_container_key(pKeyContainer, KEY_WRITE, &hKey)) - { - store_key_pair(pKeyContainer->hKeyExchangeKeyPair, hKey, - AT_KEYEXCHANGE, dwFlags); - store_key_pair(pKeyContainer->hSignatureKeyPair, hKey, - AT_SIGNATURE, dwFlags); - RegCloseKey(hKey); - } -} - -/****************************************************************************** - * store_key_container_permissions [Internal] - * - * Stores key container's key permissions in a persistent location. - * - * PARAMS - * pKeyContainer [I] Pointer to the key container whose key permissions are to - * be saved - */ -static void store_key_container_permissions(KEYCONTAINER *pKeyContainer) -{ - HKEY hKey; - - if (create_container_key(pKeyContainer, KEY_WRITE, &hKey)) - { - store_key_permissions(pKeyContainer->hKeyExchangeKeyPair, hKey, - AT_KEYEXCHANGE); - store_key_permissions(pKeyContainer->hSignatureKeyPair, hKey, - AT_SIGNATURE); - RegCloseKey(hKey); - } -} - /****************************************************************************** * release_key_container_keys [Internal] *