| 422 | */ |
| 423 | |
| 424 | int /* O - Status of call (0 = success) */ |
| 425 | httpCopyCredentials( |
| 426 | http_t *http, /* I - Connection to server */ |
| 427 | cups_array_t **credentials) /* O - Array of credentials */ |
| 428 | { |
| 429 | OSStatus error; /* Error code */ |
| 430 | SecTrustRef peerTrust; /* Peer trust reference */ |
| 431 | CFIndex count; /* Number of credentials */ |
| 432 | SecCertificateRef secCert; /* Certificate reference */ |
| 433 | CFDataRef data; /* Certificate data */ |
| 434 | CFIndex i; /* Looping var */ |
| 435 | |
| 436 | |
| 437 | DEBUG_printf(("httpCopyCredentials(http=%p, credentials=%p)", (void *)http, (void *)credentials)); |
| 438 | |
| 439 | if (credentials) |
| 440 | *credentials = NULL; |
| 441 | |
| 442 | if (!http || !http->tls || !credentials) |
| 443 | return (-1); |
| 444 | |
| 445 | if (!(error = SSLCopyPeerTrust(http->tls, &peerTrust)) && peerTrust) |
| 446 | { |
| 447 | DEBUG_printf(("2httpCopyCredentials: Peer provided %ld certificates.", (long)SecTrustGetCertificateCount(peerTrust))); |
| 448 | |
| 449 | if ((*credentials = cupsArrayNew(NULL, NULL)) != NULL) |
| 450 | { |
| 451 | count = SecTrustGetCertificateCount(peerTrust); |
| 452 | |
| 453 | for (i = 0; i < count; i ++) |
| 454 | { |
| 455 | secCert = SecTrustGetCertificateAtIndex(peerTrust, i); |
| 456 | |
| 457 | #ifdef DEBUG |
| 458 | CFStringRef cf_name = SecCertificateCopySubjectSummary(secCert); |
| 459 | char name[1024]; |
| 460 | if (cf_name) |
| 461 | CFStringGetCString(cf_name, name, sizeof(name), kCFStringEncodingUTF8); |
| 462 | else |
| 463 | strlcpy(name, "unknown", sizeof(name)); |
| 464 | |
| 465 | DEBUG_printf(("2httpCopyCredentials: Certificate %ld name is \"%s\".", (long)i, name)); |
| 466 | #endif /* DEBUG */ |
| 467 | |
| 468 | if ((data = SecCertificateCopyData(secCert)) != NULL) |
| 469 | { |
| 470 | DEBUG_printf(("2httpCopyCredentials: Adding %ld byte certificate blob.", (long)CFDataGetLength(data))); |
| 471 | |
| 472 | httpAddCredential(*credentials, CFDataGetBytePtr(data), (size_t)CFDataGetLength(data)); |
| 473 | CFRelease(data); |
| 474 | } |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | CFRelease(peerTrust); |
| 479 | } |
| 480 | |
| 481 | return (error); |
no test coverage detected