| 331 | */ |
| 332 | |
| 333 | int // O - Status of call (0 = success) |
| 334 | httpCopyCredentials( |
| 335 | http_t *http, // I - Connection to server |
| 336 | cups_array_t **credentials) // O - Array of credentials |
| 337 | { |
| 338 | STACK_OF(X509) *chain; // Certificate chain |
| 339 | |
| 340 | |
| 341 | DEBUG_printf(("httpCopyCredentials(http=%p, credentials=%p)", http, credentials)); |
| 342 | |
| 343 | if (credentials) |
| 344 | *credentials = NULL; |
| 345 | |
| 346 | if (!http || !http->tls || !credentials) |
| 347 | return (-1); |
| 348 | |
| 349 | *credentials = cupsArrayNew(NULL, NULL); |
| 350 | chain = SSL_get_peer_cert_chain(http->tls); |
| 351 | |
| 352 | DEBUG_printf(("1httpCopyCredentials: chain=%p", chain)); |
| 353 | |
| 354 | if (chain) |
| 355 | { |
| 356 | int i, // Looping var |
| 357 | count; // Number of certs |
| 358 | |
| 359 | for (i = 0, count = sk_X509_num(chain); i < count; i ++) |
| 360 | { |
| 361 | X509 *cert = sk_X509_value(chain, i); |
| 362 | // Current certificate |
| 363 | BIO *bio = BIO_new(BIO_s_mem()); |
| 364 | // Memory buffer for cert |
| 365 | |
| 366 | if (bio) |
| 367 | { |
| 368 | long bytes; // Number of bytes |
| 369 | char *buffer; // Pointer to bytes |
| 370 | |
| 371 | if (PEM_write_bio_X509(bio, cert)) |
| 372 | { |
| 373 | bytes = BIO_get_mem_data(bio, &buffer); |
| 374 | httpAddCredential(*credentials, buffer, (int)bytes); |
| 375 | } |
| 376 | |
| 377 | BIO_free(bio); |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | return (0); |
| 383 | } |
| 384 | |
| 385 | |
| 386 | /* |
nothing calls this directly
no test coverage detected