Signed-off-by: Zhang Shuai wxsxsdz@gmail.com --- dlls/dssenh/Makefile.in | 4 +- dlls/dssenh/cryptoprovconfig.h | 86 ++++++++++++++++ dlls/dssenh/dssenh.c | 181 +++++++++++++++++++++++++++++++++ dlls/dssenh/dssenh.spec | 4 +- dlls/dssenh/main.c | 59 ----------- 5 files changed, 272 insertions(+), 62 deletions(-) create mode 100644 dlls/dssenh/cryptoprovconfig.h create mode 100644 dlls/dssenh/dssenh.c delete mode 100644 dlls/dssenh/main.c
diff --git a/dlls/dssenh/Makefile.in b/dlls/dssenh/Makefile.in index 132ad755ee..cb34ad3ae2 100644 --- a/dlls/dssenh/Makefile.in +++ b/dlls/dssenh/Makefile.in @@ -6,6 +6,8 @@ EXTRAINCL = -I$(top_srcdir)/dlls/ EXTRADLLFLAGS = -mno-cygwin
C_SRCS = \ - main.c + dssenh.c \ + ../rsaenh/cryptoprovutils.c \ + ../rsaenh/handle.c
RC_SRCS = rsrc.rc diff --git a/dlls/dssenh/cryptoprovconfig.h b/dlls/dssenh/cryptoprovconfig.h new file mode 100644 index 0000000000..25c1237006 --- /dev/null +++ b/dlls/dssenh/cryptoprovconfig.h @@ -0,0 +1,86 @@ +/* + * dlls/dssenh/cryptoprovconfig.h + * Definitions of some constants used by crypto provider. + * It is copied to build dir then included by cryptoprovutils.h, + * the build dir comes first in include search paths. + * So a new provider implementation only needs to provide its own + * cryptoprovconfig.h. + * + * Copyright 2002 TransGaming Technologies (David Hammerton) + * Copyright 2004 Mike McCormack for CodeWeavers + * Copyright 2004, 2005 Michael Jung + * Copyright 2007 Vijay Kiran Kamuju + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef __WINE_CRYPTOPROVCONFIG_H +#define __WINE_CRYPTOPROVCONFIG_H +#define DSSENH_MAGIC_KEY 0x73620457u +#define DSSENH_MAX_KEY_SIZE 64 +#define DSSENH_MAX_BLOCK_SIZE 24 +#define DSSENH_MAGIC_CONTAINER 0x26384993u +#define DSSENH_REGKEY "Software\Wine\Crypto\DSS\%s" + +/****************************************************************************** + * CRYPTKEY - key objects + */ +#define DSSENH_KEYSTATE_IDLE 0 +#define DSSENH_KEYSTATE_ENCRYPTING 1 +#define DSSENH_KEYSTATE_MASTERKEY 2 +typedef struct _DSSENH_SCHANNEL_INFO +{ + SCHANNEL_ALG saEncAlg; + SCHANNEL_ALG saMACAlg; + CRYPT_DATA_BLOB blobClientRandom; + CRYPT_DATA_BLOB blobServerRandom; +} DSSENH_SCHANNEL_INFO; +#define CRYPTO_PROV_SCHANNEL_INFO DSSENH_SCHANNEL_INFO + +/****************************************************************************** + * KEYCONTAINER - key containers + */ +#define DSSENH_PERSONALITY_BASE 0u +#define DSSENH_PERSONALITY_BASE_DH 1u +#define DSSENH_PERSONALITY_ENHANCED 2u +#define DSSENH_PERSONALITY_SCHANNEL 3u + +/****************************************************************************** + * Used by new_key_container to determine the personality via provider name. + * The first entry in aProvNamePersonalityPairs should be the default personality. + */ +typedef struct tagPROVNAMEPERSONALITYPAIR +{ + LPCSTR pszProvName; + DWORD dwPersonality; +} PROVNAMEPERSONALITYPAIR; + +static const DWORD dwNProvNamePersonalityPairs = 0; +static const PROVNAMEPERSONALITYPAIR aProvNamePersonalityPairs[6] = +{ + {"", DSSENH_PERSONALITY_ENHANCED}, + {MS_DEF_DSS_PROV_A, DSSENH_PERSONALITY_BASE}, + {MS_DEF_DSS_DH_PROV_A, DSSENH_PERSONALITY_BASE_DH}, + {MS_DEF_DH_SCHANNEL_PROV_A, DSSENH_PERSONALITY_SCHANNEL} +}; + +/****************************************************************************** + * Define constants with CRYPTO_PROV prefix + */ +#define CRYPTO_PROV_REGKEY DSSENH_REGKEY +#define CRYPTO_PROV_MAGIC_KEY DSSENH_MAGIC_KEY +#define CRYPTO_PROV_MAGIC_CONTAINER DSSENH_MAGIC_CONTAINER + +#endif /* __WINE_CRYPTOPROVCONFIG_H */ diff --git a/dlls/dssenh/dssenh.c b/dlls/dssenh/dssenh.c new file mode 100644 index 0000000000..a029158672 --- /dev/null +++ b/dlls/dssenh/dssenh.c @@ -0,0 +1,181 @@ +/* + * Copyright 2019 Zhang Shuai + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + + +#include <stdarg.h> + +#include "windef.h" +#include "winbase.h" +#include "winreg.h" +#include "wincrypt.h" +#include "objbase.h" +#include "rpcproxy.h" +#include "rsaenh/handle.h" +#include "rsaenh/cryptoprovutils.h" +#include "wine/debug.h" + + +WINE_DEFAULT_DEBUG_CHANNEL(dssenh); + +static HINSTANCE instance; + +/****************************************************************************** + * CSP's handle table (used by all acquired key containers) + */ +struct handle_table handle_table; + +BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, LPVOID reserved) +{ + TRACE("(0x%p, %d, %p)\n", hInstance, fdwReason, reserved); + + switch (fdwReason) + { + case DLL_PROCESS_ATTACH: + instance = hInstance; + DisableThreadLibraryCalls(hInstance); + init_handle_table(&handle_table); + break; + + case DLL_PROCESS_DETACH: + if (reserved) break; + destroy_handle_table(&handle_table); + break; + } + return TRUE; +} + +/***************************************************** + * DllRegisterServer (DSSENH.@) + */ +HRESULT WINAPI DllRegisterServer(void) +{ + return __wine_register_resources( instance ); +} + +/***************************************************** + * DllUnregisterServer (DSSENH.@) + */ +HRESULT WINAPI DllUnregisterServer(void) +{ + return __wine_unregister_resources( instance ); +} + +/****************************************************************************** + * crypt_export_key [Internal] + * + * Export a key into a binary large object (BLOB). Called by CPExportKey and + * by store_key_pair. + * + * PARAMS + * pCryptKey [I] Key to be exported. + * hPubKey [I] Key used to encrypt sensitive BLOB data. + * dwBlobType [I] SIMPLEBLOB, PUBLICKEYBLOB or PRIVATEKEYBLOB. + * dwFlags [I] Currently none defined. + * force [I] If TRUE, the key is written no matter what the key's + * permissions are. Otherwise the key's permissions are + * checked before exporting. + * pbData [O] Pointer to a buffer where the BLOB will be written to. + * pdwDataLen [I/O] I: Size of buffer at pbData, O: Size of BLOB + * + * RETURNS + * Success: TRUE. + * Failure: FALSE. + */ +BOOL crypt_export_key(CRYPTKEY *pCryptKey, HCRYPTKEY hPubKey, + DWORD dwBlobType, DWORD dwFlags, BOOL force, + BYTE *pbData, DWORD *pdwDataLen) +{ + FIXME("stub\n"); + return FALSE; +} + +/****************************************************************************** + * import_key [Internal] + * + * 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. + * 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 + * 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 import_key(HCRYPTPROV hProv, const BYTE *pbData, DWORD dwDataLen, HCRYPTKEY hPubKey, + DWORD dwFlags, BOOL fStoreKey, HCRYPTKEY *phKey) +{ + FIXME("stub\n"); + return FALSE; +} + +/****************************************************************************** + * CPAcquireContext (DSSENH.@) + * + * Acquire a handle to the key container specified by pszContainer + * + * PARAMS + * phProv [O] Pointer to the location the acquired handle will be written to. + * pszContainer [I] Name of the desired key container. See Notes + * dwFlags [I] Flags. See Notes. + * pVTable [I] Pointer to a VTableProvStruc containing callbacks. + * + * RETURNS + * Success: TRUE + * Failure: FALSE + * + * NOTES + * If pszContainer is NULL or points to a zero length string the user's login + * name will be used as the key container name. + * + * If the CRYPT_NEW_KEYSET flag is set in dwFlags a new keyset will be created. + * If a keyset with the given name already exists, the function fails and sets + * last error to NTE_EXISTS. If CRYPT_NEW_KEYSET is not set and the specified + * key container does not exist, function fails and sets last error to + * NTE_BAD_KEYSET. + */ +BOOL WINAPI DSSENH_CPAcquireContext(HCRYPTPROV *phProv, LPSTR pszContainer, + DWORD dwFlags, PVTableProvStruc pVTable) +{ + return CRYPTO_PROV_CPAcquireContext(phProv, pszContainer, dwFlags, pVTable); +} + +/****************************************************************************** + * CPReleaseContext (DSSENH.@) + * + * Release a key container. + * + * PARAMS + * hProv [I] Key container to be released. + * dwFlags [I] Currently none defined. + * + * RETURNS + * Success: TRUE + * Failure: FALSE + */ +BOOL WINAPI DSSENH_CPReleaseContext(HCRYPTPROV hProv, DWORD dwFlags) +{ + return CRYPTO_PROV_CPReleaseContext(hProv, dwFlags); +} diff --git a/dlls/dssenh/dssenh.spec b/dlls/dssenh/dssenh.spec index c5c2545281..42768f48ae 100644 --- a/dlls/dssenh/dssenh.spec +++ b/dlls/dssenh/dssenh.spec @@ -1,4 +1,4 @@ -@ stub CPAcquireContext +@ stdcall CPAcquireContext(ptr str long ptr) DSSENH_CPAcquireContext @ stub CPCreateHash @ stub CPDecrypt @ stub CPDeriveKey @@ -17,7 +17,7 @@ @ stub CPHashData @ stub CPHashSessionKey @ stub CPImportKey -@ stub CPReleaseContext +@ stdcall CPReleaseContext(long long) DSSENH_CPReleaseContext @ stub CPSetHashParam @ stub CPSetKeyParam @ stub CPSetProvParam diff --git a/dlls/dssenh/main.c b/dlls/dssenh/main.c deleted file mode 100644 index b60b3447a3..0000000000 --- a/dlls/dssenh/main.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2008 Maarten Lankhorst - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - */ - - -#include <stdarg.h> - -#include "windef.h" -#include "winbase.h" -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(dssenh); - -BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) -{ - TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved); - - switch (fdwReason) - { - case DLL_WINE_PREATTACH: - return FALSE; /* prefer native version */ - case DLL_PROCESS_ATTACH: - DisableThreadLibraryCalls(hinstDLL); - break; - } - return TRUE; -} - -/***************************************************** - * DllRegisterServer (DSSENH.@) - */ -HRESULT WINAPI DllRegisterServer(void) -{ - FIXME("Not implemented.\n"); - return E_UNEXPECTED; -} - -/***************************************************** - * DllUnregisterServer (DSSENH.@) - */ -HRESULT WINAPI DllUnregisterServer(void) -{ - FIXME("Not implemented.\n"); - return E_UNEXPECTED; -}