From: Tatsuyuki Ishi <ishitatsuyuki@gmail.com> Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=52330 --- dlls/crypt32/tests/store.c | 130 +++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/dlls/crypt32/tests/store.c b/dlls/crypt32/tests/store.c index 7b7266db0b2..678d4810d8b 100644 --- a/dlls/crypt32/tests/store.c +++ b/dlls/crypt32/tests/store.c @@ -3303,6 +3303,98 @@ static const BYTE pfxdata[] = 0x69, 0x02, 0x02, 0x08, 0x00 }; +/* Cert-only PKCS#12 (no private key), empty password, legacy encryption. + * Generated with: + * openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes + * openssl pkcs12 -export -nokeys -in cert.pem -out cert_only.pfx -passout pass: -legacy + */ +static const BYTE pfx_cert_only[] = +{ + 0x30, 0x82, 0x03, 0xdc, 0x02, 0x01, 0x03, 0x30, 0x82, 0x03, 0x9a, 0x06, + 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0xa0, 0x82, + 0x03, 0x8b, 0x04, 0x82, 0x03, 0x87, 0x30, 0x82, 0x03, 0x83, 0x30, 0x82, + 0x03, 0x7f, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, + 0x06, 0xa0, 0x82, 0x03, 0x70, 0x30, 0x82, 0x03, 0x6c, 0x02, 0x01, 0x00, + 0x30, 0x82, 0x03, 0x65, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, + 0x01, 0x07, 0x01, 0x30, 0x1c, 0x06, 0x0a, 0x2a, 0x86, 0x48, 0x86, 0xf7, + 0x0d, 0x01, 0x0c, 0x01, 0x06, 0x30, 0x0e, 0x04, 0x08, 0xbc, 0xb4, 0x1e, + 0xbc, 0x95, 0xfd, 0x2a, 0x73, 0x02, 0x02, 0x08, 0x00, 0x80, 0x82, 0x03, + 0x38, 0x82, 0x05, 0xb7, 0x9d, 0x81, 0xd4, 0x12, 0xc8, 0x3f, 0x9f, 0xc7, + 0x75, 0x76, 0x42, 0x93, 0xae, 0x1f, 0xe8, 0x7d, 0x60, 0x61, 0x56, 0x14, + 0x8d, 0x22, 0x92, 0xa0, 0x08, 0x9f, 0x35, 0xf4, 0x60, 0xe2, 0x0c, 0xf6, + 0x24, 0x67, 0x66, 0x89, 0x43, 0x37, 0xfc, 0xc2, 0x69, 0x32, 0x20, 0x06, + 0x15, 0xb6, 0x01, 0xa6, 0xd5, 0xc0, 0xb0, 0xe8, 0x14, 0x80, 0xe9, 0xda, + 0x7e, 0x2e, 0x7b, 0xeb, 0xf0, 0x5d, 0x76, 0x8c, 0x26, 0xb3, 0xe7, 0xcb, + 0x02, 0x82, 0xf9, 0x50, 0x1a, 0x00, 0xcb, 0x76, 0x08, 0xbd, 0xe0, 0x4a, + 0x0a, 0x50, 0x6a, 0x93, 0x86, 0x0f, 0x0c, 0x29, 0x59, 0x26, 0xa7, 0xa0, + 0xbb, 0x09, 0x13, 0x42, 0xac, 0x15, 0x6b, 0x3e, 0xdd, 0x33, 0x4e, 0xf2, + 0xdb, 0x69, 0xed, 0xd3, 0x54, 0x6a, 0x83, 0x73, 0xba, 0xf7, 0x98, 0x88, + 0xc4, 0x61, 0xed, 0xb8, 0x1a, 0xbd, 0x82, 0x00, 0x1e, 0x53, 0x37, 0xe3, + 0xaf, 0xce, 0x6a, 0x32, 0x2f, 0x8b, 0x24, 0x47, 0x85, 0x1f, 0x0a, 0x92, + 0x22, 0x7a, 0x47, 0xd0, 0x4e, 0xb0, 0x11, 0xdd, 0x2e, 0x4d, 0xdb, 0x7c, + 0xac, 0xda, 0xa7, 0x14, 0x29, 0xce, 0x26, 0x73, 0x0d, 0xf1, 0x29, 0x80, + 0xf9, 0xe7, 0x7f, 0x0f, 0x8f, 0xde, 0x26, 0xdb, 0x75, 0x88, 0x52, 0x0e, + 0x28, 0x79, 0x29, 0x25, 0x60, 0x7e, 0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f8, 0xf3, 0xc9, 0x47, + 0x70, 0x9a, 0xff, 0xbe, 0x63, 0xd4, 0xdf, 0x0b, 0xdd, 0xbe, 0xc6, 0x33, + 0x9d, 0xd3, 0xfa, 0x03, 0x91, 0x3a, 0x45, 0x1d, 0x05, 0xa0, 0xd0, 0x6e, + 0x45, 0x21, 0x60, 0x48, 0xda, 0x4f, 0x41, 0x7e, 0x0f, 0xe5, 0xec, 0xec, + 0x75, 0x8d, 0x73, 0x26, 0x36, 0xa9, 0x6a, 0xc1, 0x4b, 0x99, 0x5f, 0x04, + 0x8a, 0xac, 0xe1, 0x32, 0x2e, 0xa1, 0xfb, 0x86, 0xcd, 0x9f, 0xdd, 0x61, + 0x15, 0xef, 0xf8, 0x3f, 0xeb, 0x41, 0x54, 0x1e, 0xb0, 0xa5, 0x7f, 0x41, + 0x7f, 0xbf, 0xd8, 0x58, 0x3a, 0x80, 0x11, 0x4d, 0x7a, 0xd6, 0x37, 0x13, + 0x1f, 0xd4, 0xb4, 0x25, 0x9b, 0x82, 0x26, 0x60, 0x99, 0x30, 0x39, 0x30, + 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, + 0x04, 0x14, 0x34, 0xa9, 0x11, 0xce, 0xfe, 0xe2, 0x68, 0xff, 0x42, 0x47, + 0xea, 0x7a, 0xfc, 0xe9, 0x5a, 0xed, 0x69, 0x5a, 0x63, 0x9a, 0x04, 0x10, + 0xe5, 0xeb, 0x13, 0x32, 0xa7, 0x47, 0x9b, 0xf8, 0x2f, 0x66, 0x41, 0x01, + 0x1e, 0xc6, 0x23, 0x55, 0x02, 0x02, 0x08, 0x00 +}; + static void test_PFXImportCertStore(void) { HCERTSTORE store; @@ -3320,6 +3412,44 @@ static void test_PFXImportCertStore(void) ok( store == NULL, "got %p\n", store ); ok( GetLastError() == ERROR_INVALID_PARAMETER, "got %lu\n", GetLastError() ); + /* cert-only PKCS#12 (no private key), empty password */ + pfx.pbData = (BYTE *)pfx_cert_only; + pfx.cbData = sizeof(pfx_cert_only); + + ret = PFXIsPFXBlob( &pfx ); + ok( ret, "got %lu\n", GetLastError() ); + + store = PFXImportCertStore( &pfx, L"", 0 ); + ok( store != NULL, "got %lu\n", GetLastError() ); + if (store) + { + count = countCertsInStore( store ); + ok( count == 1, "got %lu\n", count ); + + cert = CertFindCertificateInStore( store, X509_ASN_ENCODING, 0, CERT_FIND_ANY, NULL, NULL ); + ok( cert != NULL, "got %lu\n", GetLastError() ); + if (cert) + { + ok( cert->dwCertEncodingType == X509_ASN_ENCODING, "got %lu\n", cert->dwCertEncodingType ); + ok( cert->pbCertEncoded != NULL, "pbCertEncoded not set\n" ); + ok( cert->pCertInfo != NULL, "pCertInfo not set\n" ); + + /* no private key should be associated */ + size = sizeof(key); + SetLastError( 0xdeadbeef ); + ret = CertGetCertificateContextProperty( cert, CERT_KEY_CONTEXT_PROP_ID, &key, &size ); + ok( !ret && GetLastError() == CRYPT_E_NOT_FOUND, "got %08lx\n", GetLastError() ); + + size = sizeof(buf); + SetLastError( 0xdeadbeef ); + ret = CertGetCertificateContextProperty( cert, CERT_KEY_PROV_INFO_PROP_ID, keyprov, &size ); + ok( !ret && GetLastError() == CRYPT_E_NOT_FOUND, "got %08lx\n", GetLastError() ); + + CertFreeCertificateContext( cert ); + } + CertCloseStore( store, 0 ); + } + pfx.pbData = (BYTE *)pfxdata; pfx.cbData = sizeof(pfxdata); store = PFXImportCertStore( &pfx, NULL, CRYPT_EXPORTABLE|CRYPT_USER_KEYSET|PKCS12_NO_PERSIST_KEY ); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10198