[PATCH 03/10] dssenh: refactor rsaenh - move create_container_key, open_container_key, delete_container_key from rsaenh/rsaenh.c to rsaenh/cryptoprovutils.c
shuai zhang
wxsxsdz at gmail.com
Sun Nov 17 09:24:30 CST 2019
Signed-off-by: Zhang Shuai <wxsxsdz at gmail.com>
---
dlls/rsaenh/cryptoprovconfig.h | 7 +++
dlls/rsaenh/cryptoprovutils.c | 89 +++++++++++++++++++++++++++
dlls/rsaenh/cryptoprovutils.h | 16 +++++
dlls/rsaenh/rsaenh.c | 106 ---------------------------------
4 files changed, 112 insertions(+), 106 deletions(-)
diff --git a/dlls/rsaenh/cryptoprovconfig.h b/dlls/rsaenh/cryptoprovconfig.h
index da6d526be2..d282d0db1e 100644
--- a/dlls/rsaenh/cryptoprovconfig.h
+++ b/dlls/rsaenh/cryptoprovconfig.h
@@ -39,6 +39,8 @@
#define RSAENH_PERSONALITY_SCHANNEL 3u
#define RSAENH_PERSONALITY_AES 4u
+#define RSAENH_MAGIC_CONTAINER 0x26384993u
+
/******************************************************************************
* Used by new_key_container to determine the personality via provider name.
* The first entry in aProvNamePersonalityPairs should be the default
personality.
@@ -60,4 +62,9 @@ static const PROVNAMEPERSONALITYPAIR
aProvNamePersonalityPairs[6] =
{MS_ENH_RSA_AES_PROV_XP_A, RSAENH_PERSONALITY_AES}
};
+/******************************************************************************
+ * Some magic constants
+ */
+#define RSAENH_REGKEY "Software\\Wine\\Crypto\\RSA\\%s"
+
#endif /* __WINE_CRYPTOPROVCONFIG_H */
diff --git a/dlls/rsaenh/cryptoprovutils.c b/dlls/rsaenh/cryptoprovutils.c
index 76ee7bbe86..23e0e11626 100644
--- a/dlls/rsaenh/cryptoprovutils.c
+++ b/dlls/rsaenh/cryptoprovutils.c
@@ -32,3 +32,92 @@
#include "handle.h"
#include "cryptoprovutils.h"
#include "wine/debug.h"
+
+/******************************************************************************
+ * create_container_key [Internal]
+ *
+ * Creates the registry key for a key container's persistent storage.
+ *
+ * PARAMS
+ * pKeyContainer [I] Pointer to the key container
+ * sam [I] Desired registry access
+ * phKey [O] Returned key
+ */
+BOOL create_container_key(KEYCONTAINER *pKeyContainer, REGSAM sam, HKEY *phKey)
+{
+ CHAR szRSABase[sizeof(RSAENH_REGKEY) + MAX_PATH];
+ HKEY hRootKey;
+
+ sprintf(szRSABase, RSAENH_REGKEY, pKeyContainer->szName);
+
+ if (pKeyContainer->dwFlags & CRYPT_MACHINE_KEYSET)
+ hRootKey = HKEY_LOCAL_MACHINE;
+ else
+ hRootKey = HKEY_CURRENT_USER;
+
+ /* @@ Wine registry key: HKLM\Software\Wine\Crypto\RSA */
+ /* @@ Wine registry key: HKCU\Software\Wine\Crypto\RSA */
+ return RegCreateKeyExA(hRootKey, szRSABase, 0, NULL,
+ REG_OPTION_NON_VOLATILE, sam, NULL, phKey, NULL)
+ == ERROR_SUCCESS;
+}
+
+/******************************************************************************
+ * open_container_key [Internal]
+ *
+ * Opens a key container's persistent storage for reading.
+ *
+ * PARAMS
+ * pszContainerName [I] Name of the container to be opened. May be the empty
+ * string if the parent key of all containers is to be
+ * opened.
+ * dwFlags [I] Flags indicating which keyset to be opened.
+ * phKey [O] Returned key
+ */
+BOOL open_container_key(LPCSTR pszContainerName, DWORD dwFlags,
REGSAM access, HKEY *phKey)
+{
+ CHAR szRSABase[sizeof(RSAENH_REGKEY) + MAX_PATH];
+ HKEY hRootKey;
+
+ sprintf(szRSABase, RSAENH_REGKEY, pszContainerName);
+
+ if (dwFlags & CRYPT_MACHINE_KEYSET)
+ hRootKey = HKEY_LOCAL_MACHINE;
+ else
+ hRootKey = HKEY_CURRENT_USER;
+
+ /* @@ Wine registry key: HKLM\Software\Wine\Crypto\RSA */
+ /* @@ Wine registry key: HKCU\Software\Wine\Crypto\RSA */
+ return RegOpenKeyExA(hRootKey, szRSABase, 0, access, phKey) ==
+ ERROR_SUCCESS;
+}
+
+/******************************************************************************
+ * delete_container_key [Internal]
+ *
+ * Deletes a key container's persistent storage.
+ *
+ * PARAMS
+ * pszContainerName [I] Name of the container to be opened.
+ * dwFlags [I] Flags indicating which keyset to be opened.
+ */
+BOOL delete_container_key(LPCSTR pszContainerName, DWORD dwFlags)
+{
+ CHAR szRegKey[sizeof(RSAENH_REGKEY) + MAX_PATH];
+ HKEY hRootKey;
+
+ sprintf(szRegKey, RSAENH_REGKEY, pszContainerName);
+
+ if (dwFlags & CRYPT_MACHINE_KEYSET)
+ hRootKey = HKEY_LOCAL_MACHINE;
+ else
+ hRootKey = HKEY_CURRENT_USER;
+ if (!RegDeleteKeyA(hRootKey, szRegKey)) {
+ SetLastError(ERROR_SUCCESS);
+ return TRUE;
+ } else {
+ SetLastError(NTE_BAD_KEYSET);
+ return FALSE;
+ }
+}
+
diff --git a/dlls/rsaenh/cryptoprovutils.h b/dlls/rsaenh/cryptoprovutils.h
index 832b09e4ce..17d665e398 100644
--- a/dlls/rsaenh/cryptoprovutils.h
+++ b/dlls/rsaenh/cryptoprovutils.h
@@ -26,4 +26,20 @@
#define __WINE_CRYPTOPROVUTILS_H
#include <cryptoprovconfig.h>
#include "implglue.h"
+typedef struct tagKEYCONTAINER
+{
+ OBJECTHDR header;
+ DWORD dwFlags;
+ DWORD dwPersonality;
+ DWORD dwEnumAlgsCtr;
+ DWORD dwEnumContainersCtr;
+ CHAR szName[MAX_PATH];
+ CHAR szProvName[MAX_PATH];
+ HCRYPTKEY hKeyExchangeKeyPair;
+ HCRYPTKEY hSignatureKeyPair;
+} KEYCONTAINER;
+
+BOOL create_container_key(KEYCONTAINER *pKeyContainer, REGSAM sam,
HKEY *phKey);
+BOOL open_container_key(LPCSTR pszContainerName, DWORD dwFlags,
REGSAM access, HKEY *phKey);
+BOOL delete_container_key(LPCSTR pszContainerName, DWORD dwFlags);
#endif /* __WINE_CRYPTOPROVUTILS_H */
diff --git a/dlls/rsaenh/rsaenh.c b/dlls/rsaenh/rsaenh.c
index e05785e142..069aee569f 100644
--- a/dlls/rsaenh/rsaenh.c
+++ b/dlls/rsaenh/rsaenh.c
@@ -105,23 +105,6 @@ typedef struct tagCRYPTKEY
CRYPT_DATA_BLOB blobHmacKey;
} CRYPTKEY;
-/******************************************************************************
- * KEYCONTAINER - key containers
- */
-#define RSAENH_MAGIC_CONTAINER 0x26384993u
-typedef struct tagKEYCONTAINER
-{
- OBJECTHDR header;
- DWORD dwFlags;
- DWORD dwPersonality;
- DWORD dwEnumAlgsCtr;
- DWORD dwEnumContainersCtr;
- CHAR szName[MAX_PATH];
- CHAR szProvName[MAX_PATH];
- HCRYPTKEY hKeyExchangeKeyPair;
- HCRYPTKEY hSignatureKeyPair;
-} KEYCONTAINER;
-
/******************************************************************************
* Some magic constants
*/
@@ -144,7 +127,6 @@ typedef struct tagKEYCONTAINER
#define RSAENH_SSL3_VERSION_MINOR 0
#define RSAENH_TLS1_VERSION_MAJOR 3
#define RSAENH_TLS1_VERSION_MINOR 1
-#define RSAENH_REGKEY "Software\\Wine\\Crypto\\RSA\\%s"
#define RSAENH_MIN(a,b) ((a)<(b)?(a):(b))
/******************************************************************************
@@ -1064,94 +1046,6 @@ static void store_key_permissions(HCRYPTKEY
hCryptKey, HKEY hKey, DWORD dwKeySpe
sizeof(pKey->dwPermissions));
}
-/******************************************************************************
- * create_container_key [Internal]
- *
- * Creates the registry key for a key container's persistent storage.
- *
- * PARAMS
- * pKeyContainer [I] Pointer to the key container
- * sam [I] Desired registry access
- * phKey [O] Returned key
- */
-static BOOL create_container_key(KEYCONTAINER *pKeyContainer, REGSAM
sam, HKEY *phKey)
-{
- CHAR szRSABase[sizeof(RSAENH_REGKEY) + MAX_PATH];
- HKEY hRootKey;
-
- sprintf(szRSABase, RSAENH_REGKEY, pKeyContainer->szName);
-
- if (pKeyContainer->dwFlags & CRYPT_MACHINE_KEYSET)
- hRootKey = HKEY_LOCAL_MACHINE;
- else
- hRootKey = HKEY_CURRENT_USER;
-
- /* @@ Wine registry key: HKLM\Software\Wine\Crypto\RSA */
- /* @@ Wine registry key: HKCU\Software\Wine\Crypto\RSA */
- return RegCreateKeyExA(hRootKey, szRSABase, 0, NULL,
- REG_OPTION_NON_VOLATILE, sam, NULL, phKey, NULL)
- == ERROR_SUCCESS;
-}
-
-/******************************************************************************
- * open_container_key [Internal]
- *
- * Opens a key container's persistent storage for reading.
- *
- * PARAMS
- * pszContainerName [I] Name of the container to be opened. May be the empty
- * string if the parent key of all containers is to be
- * opened.
- * dwFlags [I] Flags indicating which keyset to be opened.
- * phKey [O] Returned key
- */
-static BOOL open_container_key(LPCSTR pszContainerName, DWORD
dwFlags, REGSAM access, HKEY *phKey)
-{
- CHAR szRSABase[sizeof(RSAENH_REGKEY) + MAX_PATH];
- HKEY hRootKey;
-
- sprintf(szRSABase, RSAENH_REGKEY, pszContainerName);
-
- if (dwFlags & CRYPT_MACHINE_KEYSET)
- hRootKey = HKEY_LOCAL_MACHINE;
- else
- hRootKey = HKEY_CURRENT_USER;
-
- /* @@ Wine registry key: HKLM\Software\Wine\Crypto\RSA */
- /* @@ Wine registry key: HKCU\Software\Wine\Crypto\RSA */
- return RegOpenKeyExA(hRootKey, szRSABase, 0, access, phKey) ==
- ERROR_SUCCESS;
-}
-
-/******************************************************************************
- * delete_container_key [Internal]
- *
- * Deletes a key container's persistent storage.
- *
- * PARAMS
- * pszContainerName [I] Name of the container to be opened.
- * dwFlags [I] Flags indicating which keyset to be opened.
- */
-static BOOL delete_container_key(LPCSTR pszContainerName, DWORD dwFlags)
-{
- CHAR szRegKey[sizeof(RSAENH_REGKEY) + MAX_PATH];
- HKEY hRootKey;
-
- sprintf(szRegKey, RSAENH_REGKEY, pszContainerName);
-
- if (dwFlags & CRYPT_MACHINE_KEYSET)
- hRootKey = HKEY_LOCAL_MACHINE;
- else
- hRootKey = HKEY_CURRENT_USER;
- if (!RegDeleteKeyA(hRootKey, szRegKey)) {
- SetLastError(ERROR_SUCCESS);
- return TRUE;
- } else {
- SetLastError(NTE_BAD_KEYSET);
- return FALSE;
- }
-}
-
/******************************************************************************
* store_key_container_keys [Internal]
*
--
2.21.0
More information about the wine-devel
mailing list