Commit 547508e3 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

crypt32: Add support for CRYPT_MACHINE_KEYSET in PFXImportCertStore.

parent b9f1ec8c
...@@ -138,7 +138,7 @@ static HCRYPTPROV import_key( gnutls_x509_privkey_t key, DWORD flags ) ...@@ -138,7 +138,7 @@ static HCRYPTPROV import_key( gnutls_x509_privkey_t key, DWORD flags )
HCRYPTPROV prov = 0; HCRYPTPROV prov = 0;
HCRYPTKEY cryptkey; HCRYPTKEY cryptkey;
BYTE *buf, *src, *dst; BYTE *buf, *src, *dst;
DWORD size; DWORD size, acquire_flags;
if ((ret = pgnutls_x509_privkey_get_pk_algorithm2( key, &bitlen )) < 0) if ((ret = pgnutls_x509_privkey_get_pk_algorithm2( key, &bitlen )) < 0)
{ {
...@@ -208,17 +208,20 @@ static HCRYPTPROV import_key( gnutls_x509_privkey_t key, DWORD flags ) ...@@ -208,17 +208,20 @@ static HCRYPTPROV import_key( gnutls_x509_privkey_t key, DWORD flags )
else src = d.data; else src = d.data;
for (i = bitlen / 8 - 1; i >= 0; i--) *dst++ = src[i]; 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 (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() ); WARN( "CryptAcquireContextW failed %08x\n", GetLastError() );
goto done; 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() ); WARN( "CryptImportKey failed %08x\n", GetLastError() );
CryptReleaseContext( prov, 0 ); CryptReleaseContext( prov, 0 );
...@@ -346,7 +349,7 @@ HCERTSTORE WINAPI PFXImportCertStore( CRYPT_DATA_BLOB *pfx, const WCHAR *passwor ...@@ -346,7 +349,7 @@ HCERTSTORE WINAPI PFXImportCertStore( CRYPT_DATA_BLOB *pfx, const WCHAR *passwor
SetLastError( ERROR_INVALID_PARAMETER ); SetLastError( ERROR_INVALID_PARAMETER );
return NULL; 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 ); FIXME( "flags %08x not supported\n", flags );
return NULL; return NULL;
...@@ -373,7 +376,7 @@ HCERTSTORE WINAPI PFXImportCertStore( CRYPT_DATA_BLOB *pfx, const WCHAR *passwor ...@@ -373,7 +376,7 @@ HCERTSTORE WINAPI PFXImportCertStore( CRYPT_DATA_BLOB *pfx, const WCHAR *passwor
goto error; 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 ))) if (!(store = CertOpenStore( CERT_STORE_PROV_MEMORY, 0, 0, 0, NULL )))
{ {
WARN( "CertOpenStore failed %08x\n", GetLastError() ); WARN( "CertOpenStore failed %08x\n", GetLastError() );
......
...@@ -3348,6 +3348,16 @@ static void test_PFXImportCertStore(void) ...@@ -3348,6 +3348,16 @@ static void test_PFXImportCertStore(void)
ok(ret, "got %u\n", GetLastError()); ok(ret, "got %u\n", GetLastError());
CertFreeCertificateContext( cert ); CertFreeCertificateContext( cert );
CertCloseStore( store, 0 ); 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) static void test_CryptQueryObject(void)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment