| 394 | */ |
| 395 | |
| 396 | int /* O - 0 on success, -1 on error */ |
| 397 | httpLoadCredentials( |
| 398 | const char *path, /* I - Keychain path or @code NULL@ for default */ |
| 399 | cups_array_t **credentials, /* IO - Credentials */ |
| 400 | const char *common_name) /* I - Common name for credentials */ |
| 401 | { |
| 402 | HCERTSTORE store = NULL; /* Certificate store */ |
| 403 | PCCERT_CONTEXT storedContext = NULL; /* Context created from the store */ |
| 404 | DWORD dwSize = 0; /* 32 bit size */ |
| 405 | PBYTE p = NULL; /* Temporary storage */ |
| 406 | HCRYPTPROV hProv = (HCRYPTPROV)NULL; |
| 407 | /* Handle to a CSP */ |
| 408 | CERT_NAME_BLOB sib; /* Arbitrary array of bytes */ |
| 409 | #ifdef DEBUG |
| 410 | char error[1024]; /* Error message buffer */ |
| 411 | #endif /* DEBUG */ |
| 412 | |
| 413 | |
| 414 | DEBUG_printf(("httpLoadCredentials(path=\"%s\", credentials=%p, common_name=\"%s\")", path, credentials, common_name)); |
| 415 | |
| 416 | (void)path; |
| 417 | |
| 418 | if (credentials) |
| 419 | { |
| 420 | *credentials = NULL; |
| 421 | } |
| 422 | else |
| 423 | { |
| 424 | DEBUG_puts("1httpLoadCredentials: NULL credentials pointer, returning -1."); |
| 425 | return (-1); |
| 426 | } |
| 427 | |
| 428 | if (!common_name) |
| 429 | { |
| 430 | DEBUG_puts("1httpLoadCredentials: Bad common name, returning -1."); |
| 431 | return (-1); |
| 432 | } |
| 433 | |
| 434 | if (!CryptAcquireContextW(&hProv, L"RememberedContainer", MS_DEF_PROV_W, PROV_RSA_FULL, CRYPT_NEWKEYSET /*| CRYPT_MACHINE_KEYSET*/)) |
| 435 | { |
| 436 | if (GetLastError() == NTE_EXISTS) |
| 437 | { |
| 438 | if (!CryptAcquireContextW(&hProv, L"RememberedContainer", MS_DEF_PROV_W, PROV_RSA_FULL, 0 /*CRYPT_MACHINE_KEYSET*/)) |
| 439 | { |
| 440 | DEBUG_printf(("1httpLoadCredentials: CryptAcquireContext failed: %s", http_sspi_strerror(error, sizeof(error), GetLastError()))); |
| 441 | http_sspi_set_error("CryptAquireContext"); |
| 442 | goto cleanup; |
| 443 | } |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | store = CertOpenStore(CERT_STORE_PROV_SYSTEM, X509_ASN_ENCODING|PKCS_7_ASN_ENCODING, hProv, CERT_SYSTEM_STORE_LOCAL_MACHINE | CERT_STORE_NO_CRYPT_RELEASE_FLAG | CERT_STORE_OPEN_EXISTING_FLAG, L"MY"); |
| 448 | |
| 449 | if (!store) |
| 450 | { |
| 451 | DEBUG_printf(("1httpLoadCredentials: CertOpenSystemStore failed: %s", http_sspi_strerror(error, sizeof(error), GetLastError()))); |
| 452 | http_sspi_set_error("CertOpenSystemStore"); |
| 453 | goto cleanup; |
nothing calls this directly
no test coverage detected