Hans Leidekker : crypt32: Add support for CRYPT_MACHINE_KEYSET in PFXImportCertStore.
Alexandre Julliard
julliard at winehq.org
Tue Mar 23 15:07:42 CDT 2021
Module: wine
Branch: oldstable
Commit: e3b72ea20451d88f03b5312aeba97265f3ee9e64
URL: https://source.winehq.org/git/wine.git/?a=commit;h=e3b72ea20451d88f03b5312aeba97265f3ee9e64
Author: Hans Leidekker <hans at codeweavers.com>
Date: Wed Sep 23 12:07:57 2020 +0200
crypt32: Add support for CRYPT_MACHINE_KEYSET in PFXImportCertStore.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=49857
Signed-off-by: Hans Leidekker <hans at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
(cherry picked from commit 547508e374b7e347488f8ce7a8fa40b333a79684)
Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>
---
dlls/crypt32/pfx.c | 15 +++++++++------
dlls/crypt32/tests/store.c | 10 ++++++++++
2 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/dlls/crypt32/pfx.c b/dlls/crypt32/pfx.c
index a5155855869..a0b12975efc 100644
--- a/dlls/crypt32/pfx.c
+++ b/dlls/crypt32/pfx.c
@@ -139,7 +139,7 @@ static HCRYPTPROV import_key( gnutls_x509_privkey_t key, DWORD flags )
HCRYPTPROV prov = 0;
HCRYPTKEY cryptkey;
BYTE *buf, *src, *dst;
- DWORD size;
+ DWORD size, acquire_flags;
if ((ret = pgnutls_x509_privkey_get_pk_algorithm2( key, &bitlen )) < 0)
{
@@ -209,17 +209,20 @@ static HCRYPTPROV import_key( gnutls_x509_privkey_t key, DWORD flags )
else src = d.data;
for (i = bitlen / 8 - 1; i >= 0; i--) *dst++ = src[i];
- if (!CryptAcquireContextW( &prov, NULL, MS_ENHANCED_PROV_W, PROV_RSA_FULL, CRYPT_NEWKEYSET ))
+ acquire_flags = (flags & CRYPT_MACHINE_KEYSET) | CRYPT_NEWKEYSET;
+ if (!CryptAcquireContextW( &prov, NULL, MS_ENHANCED_PROV_W, PROV_RSA_FULL, acquire_flags ))
{
if (GetLastError() != NTE_EXISTS) goto done;
- if (!CryptAcquireContextW( &prov, NULL, MS_ENHANCED_PROV_W, PROV_RSA_FULL, 0 ))
+
+ acquire_flags &= ~CRYPT_NEWKEYSET;
+ if (!CryptAcquireContextW( &prov, NULL, MS_ENHANCED_PROV_W, PROV_RSA_FULL, acquire_flags ))
{
WARN( "CryptAcquireContextW failed %08x\n", GetLastError() );
goto done;
}
}
- if (!CryptImportKey( prov, buf, size, 0, flags, &cryptkey ))
+ if (!CryptImportKey( prov, buf, size, 0, flags & CRYPT_EXPORTABLE, &cryptkey ))
{
WARN( "CryptImportKey failed %08x\n", GetLastError() );
CryptReleaseContext( prov, 0 );
@@ -277,7 +280,7 @@ HCERTSTORE WINAPI PFXImportCertStore( CRYPT_DATA_BLOB *pfx, const WCHAR *passwor
SetLastError( ERROR_INVALID_PARAMETER );
return NULL;
}
- if (flags & ~(CRYPT_EXPORTABLE|CRYPT_USER_KEYSET|PKCS12_NO_PERSIST_KEY))
+ if (flags & ~(CRYPT_EXPORTABLE|CRYPT_USER_KEYSET|CRYPT_MACHINE_KEYSET|PKCS12_NO_PERSIST_KEY))
{
FIXME( "flags %08x not supported\n", flags );
return NULL;
@@ -304,7 +307,7 @@ HCERTSTORE WINAPI PFXImportCertStore( CRYPT_DATA_BLOB *pfx, const WCHAR *passwor
goto error;
}
- if (!(prov = import_key( key, flags & CRYPT_EXPORTABLE ))) goto error;
+ if (!(prov = import_key( key, flags ))) goto error;
if (!(store = CertOpenStore( CERT_STORE_PROV_MEMORY, 0, 0, 0, NULL )))
{
WARN( "CertOpenStore failed %08x\n", GetLastError() );
diff --git a/dlls/crypt32/tests/store.c b/dlls/crypt32/tests/store.c
index b8d0ad6666b..8a511002acf 100644
--- a/dlls/crypt32/tests/store.c
+++ b/dlls/crypt32/tests/store.c
@@ -3330,6 +3330,16 @@ static void test_PFXImportCertStore(void)
ok( !ret && GetLastError() == CRYPT_E_NOT_FOUND, "got %08x\n", GetLastError() );
CertCloseStore( store, 0 );
+
+ /* CRYPT_MACHINE_KEYSET */
+ store = PFXImportCertStore( &pfx, NULL, CRYPT_MACHINE_KEYSET );
+ ok( store != NULL, "got %u\n", GetLastError() );
+
+ cert = CertFindCertificateInStore( store, X509_ASN_ENCODING, 0, CERT_FIND_ANY, NULL, NULL );
+ ok( cert != NULL, "got %08x\n", GetLastError() );
+
+ CertFreeCertificateContext( cert );
+ CertCloseStore( store, 0 );
}
static void test_CryptQueryObject(void)
More information about the wine-cvs
mailing list