MCPcopy Create free account
hub / github.com/apache/httpd / md_cert_read_http

Function md_cert_read_http

modules/md/md_crypt.c:1570–1610  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1568}
1569
1570apr_status_t md_cert_read_http(md_cert_t **pcert, apr_pool_t *p,
1571 const md_http_response_t *res)
1572{
1573 const char *ct;
1574 apr_off_t data_len;
1575 char *der;
1576 apr_size_t der_len;
1577 md_cert_t *cert = NULL;
1578 apr_status_t rv;
1579
1580 ct = apr_table_get(res->headers, "Content-Type");
1581 ct = md_util_parse_ct(res->req->pool, ct);
1582 if (!res->body || !ct || strcmp("application/pkix-cert", ct)) {
1583 rv = APR_ENOENT;
1584 goto out;
1585 }
1586
1587 if (APR_SUCCESS == (rv = apr_brigade_length(res->body, 1, &data_len))) {
1588 if (data_len > 1024*1024) { /* certs usually are <2k each */
1589 return APR_EINVAL;
1590 }
1591 if (APR_SUCCESS == (rv = apr_brigade_pflatten(res->body, &der, &der_len, res->req->pool))) {
1592 const unsigned char *bf = (const unsigned char*)der;
1593 X509 *x509;
1594
1595 if (NULL == (x509 = d2i_X509(NULL, &bf, (long)der_len))) {
1596 rv = APR_EINVAL;
1597 goto out;
1598 }
1599 else {
1600 cert = md_cert_make(p, x509);
1601 rv = APR_SUCCESS;
1602 md_log_perror(MD_LOG_MARK, MD_LOG_TRACE2, rv, p,
1603 "parsing cert from content-type=%s, content-length=%ld", ct, (long)data_len);
1604 }
1605 }
1606 }
1607out:
1608 *pcert = (APR_SUCCESS == rv)? cert : NULL;
1609 return rv;
1610}
1611
1612apr_status_t md_cert_chain_read_http(struct apr_array_header_t *chain,
1613 apr_pool_t *p, const struct md_http_response_t *res)

Callers 2

md_cert_chain_read_httpFunction · 0.85
csr_reqFunction · 0.85

Calls 3

md_util_parse_ctFunction · 0.85
md_cert_makeFunction · 0.85
md_log_perrorFunction · 0.85

Tested by

no test coverage detected