MCPcopy Create free account
hub / github.com/OpenPrinting/cups / httpSaveCredentials

Function httpSaveCredentials

cups/tls-sspi.c:523–658  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

521 */
522
523int /* O - -1 on error, 0 on success */
524httpSaveCredentials(
525 const char *path, /* I - Keychain path or @code NULL@ for default */
526 cups_array_t *credentials, /* I - Credentials */
527 const char *common_name) /* I - Common name for credentials */
528{
529 HCERTSTORE store = NULL; /* Certificate store */
530 PCCERT_CONTEXT storedContext = NULL; /* Context created from the store */
531 PCCERT_CONTEXT createdContext = NULL; /* Context created by us */
532 DWORD dwSize = 0; /* 32 bit size */
533 PBYTE p = NULL; /* Temporary storage */
534 HCRYPTPROV hProv = (HCRYPTPROV)NULL;
535 /* Handle to a CSP */
536 CRYPT_KEY_PROV_INFO ckp; /* Handle to crypto key */
537 int ret = -1; /* Return value */
538#ifdef DEBUG
539 char error[1024]; /* Error message buffer */
540#endif /* DEBUG */
541
542
543 DEBUG_printf(("httpSaveCredentials(path=\"%s\", credentials=%p, common_name=\"%s\")", path, credentials, common_name));
544
545 (void)path;
546
547 if (!common_name)
548 {
549 DEBUG_puts("1httpSaveCredentials: Bad common name, returning -1.");
550 return (-1);
551 }
552
553 createdContext = http_sspi_create_credential((http_credential_t *)cupsArrayFirst(credentials));
554 if (!createdContext)
555 {
556 DEBUG_puts("1httpSaveCredentials: Bad credentials, returning -1.");
557 return (-1);
558 }
559
560 if (!CryptAcquireContextW(&hProv, L"RememberedContainer", MS_DEF_PROV_W, PROV_RSA_FULL, CRYPT_NEWKEYSET /*| CRYPT_MACHINE_KEYSET*/))
561 {
562 if (GetLastError() == NTE_EXISTS)
563 {
564 if (!CryptAcquireContextW(&hProv, L"RememberedContainer", MS_DEF_PROV_W, PROV_RSA_FULL, 0 /*CRYPT_MACHINE_KEYSET*/))
565 {
566 DEBUG_printf(("1httpSaveCredentials: CryptAcquireContext failed: %s", http_sspi_strerror(error, sizeof(error), GetLastError())));
567 http_sspi_set_error("CryptAquireContext");
568 goto cleanup;
569 }
570 }
571 }
572
573 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");
574
575 if (!store)
576 {
577 DEBUG_printf(("1httpSaveCredentials: CertOpenSystemStore failed: %s", http_sspi_strerror(error, sizeof(error), GetLastError())));
578 http_sspi_set_error("CertOpenSystemStore");
579 goto cleanup;
580 }

Callers

nothing calls this directly

Calls 5

cupsArrayFirstFunction · 0.85
http_sspi_strerrorFunction · 0.85
http_sspi_set_errorFunction · 0.85
_cupsSetHTTPErrorFunction · 0.85

Tested by

no test coverage detected