engines/e_capi.c: slip in PROV_RSA_AES for interchangable CSP only.
Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3034)
Andy Polyakov
7 years ago
397 | 397 | # endif |
398 | 398 | |
399 | 399 | static int use_aes_csp = 0; |
400 | static const WCHAR rsa_aes_cspname[] = | |
401 | L"Microsoft Enhanced RSA and AES Cryptographic Provider"; | |
402 | static const WCHAR rsa_enh_cspname[] = | |
403 | L"Microsoft Enhanced Cryptographic Provider v1.0"; | |
400 | 404 | |
401 | 405 | static int capi_init(ENGINE *e) |
402 | 406 | { |
471 | 475 | } |
472 | 476 | # endif |
473 | 477 | |
474 | /* See if we support AES CSP */ | |
475 | ||
476 | if (CryptAcquireContextW(&hprov, NULL, NULL, PROV_RSA_AES, | |
478 | /* See if there is RSA+AES CSP */ | |
479 | if (CryptAcquireContextW(&hprov, NULL, rsa_aes_cspname, PROV_RSA_AES, | |
477 | 480 | CRYPT_VERIFYCONTEXT)) { |
478 | 481 | use_aes_csp = 1; |
479 | 482 | CryptReleaseContext(hprov, 0); |
1458 | 1461 | } |
1459 | 1462 | |
1460 | 1463 | static CAPI_KEY *capi_get_key(CAPI_CTX *ctx, const WCHAR *contname, |
1461 | WCHAR *provname, DWORD ptype, DWORD keyspec) | |
1464 | const WCHAR *provname, DWORD ptype, | |
1465 | DWORD keyspec) | |
1462 | 1466 | { |
1463 | 1467 | DWORD dwFlags = 0; |
1464 | 1468 | CAPI_KEY *key = OPENSSL_malloc(sizeof(*key)); |
1466 | 1470 | if (key == NULL) |
1467 | 1471 | return NULL; |
1468 | 1472 | /* If PROV_RSA_AES supported use it instead */ |
1469 | if (ptype == PROV_RSA_FULL && use_aes_csp) { | |
1470 | provname = NULL; | |
1473 | if (ptype == PROV_RSA_FULL && use_aes_csp && | |
1474 | wcscmp(provname, rsa_enh_cspname) == 0) { | |
1475 | provname = rsa_aes_cspname; | |
1471 | 1476 | ptype = PROV_RSA_AES; |
1472 | CAPI_trace(ctx, "capi_get_key, contname=%s, RSA_AES_CSP\n", contname); | |
1473 | } else if (sizeof(TCHAR) == sizeof(char)) { | |
1474 | CAPI_trace(ctx, "capi_get_key, contname=%s, provname=%s, type=%d\n", | |
1475 | contname, provname, ptype); | |
1476 | } else if (ctx && ctx->debug_level >= CAPI_DBG_TRACE && ctx->debug_file) { | |
1477 | /* above 'if' is optimization to minimize malloc-ations */ | |
1477 | } | |
1478 | if (ctx && ctx->debug_level >= CAPI_DBG_TRACE && ctx->debug_file) { | |
1479 | /* above 'if' is [complementary] copy from CAPI_trace and serves | |
1480 | * as optimization to minimize [below] malloc-ations */ | |
1478 | 1481 | char *_contname = wide_to_asc(contname); |
1479 | 1482 | char *_provname = wide_to_asc(provname); |
1480 | 1483 |