| 2012 | } |
| 2013 | |
| 2014 | apr_status_t md_cert_self_sign(md_cert_t **pcert, const char *cn, |
| 2015 | apr_array_header_t *domains, md_pkey_t *pkey, |
| 2016 | apr_interval_time_t valid_for, apr_pool_t *p) |
| 2017 | { |
| 2018 | X509 *x; |
| 2019 | md_cert_t *cert = NULL; |
| 2020 | apr_status_t rv; |
| 2021 | |
| 2022 | assert(domains); |
| 2023 | |
| 2024 | if (APR_SUCCESS != (rv = mk_x509(&x, pkey, cn, valid_for, p))) goto out; |
| 2025 | |
| 2026 | /* add the domain as alt name */ |
| 2027 | if (APR_SUCCESS != (rv = add_ext(x, NID_subject_alt_name, alt_names(domains, p), p))) { |
| 2028 | md_log_perror(MD_LOG_MARK, MD_LOG_ERR, rv, p, "%s: set alt_name ext", cn); |
| 2029 | goto out; |
| 2030 | } |
| 2031 | |
| 2032 | /* keyUsage, ExtendedKeyUsage */ |
| 2033 | |
| 2034 | if (APR_SUCCESS != (rv = add_ext(x, NID_key_usage, "critical,digitalSignature", p))) { |
| 2035 | md_log_perror(MD_LOG_MARK, MD_LOG_ERR, rv, p, "%s: set keyUsage", cn); |
| 2036 | goto out; |
| 2037 | } |
| 2038 | if (APR_SUCCESS != (rv = add_ext(x, NID_ext_key_usage, "serverAuth", p))) { |
| 2039 | md_log_perror(MD_LOG_MARK, MD_LOG_ERR, rv, p, "%s: set extKeyUsage", cn); |
| 2040 | goto out; |
| 2041 | } |
| 2042 | |
| 2043 | /* sign with same key */ |
| 2044 | if (!X509_sign(x, pkey->pkey, pkey_get_MD(pkey))) { |
| 2045 | md_log_perror(MD_LOG_MARK, MD_LOG_ERR, rv, p, "%s: sign x509", cn); |
| 2046 | rv = APR_EGENERAL; goto out; |
| 2047 | } |
| 2048 | |
| 2049 | cert = md_cert_make(p, x); |
| 2050 | rv = APR_SUCCESS; |
| 2051 | |
| 2052 | out: |
| 2053 | *pcert = (APR_SUCCESS == rv)? cert : NULL; |
| 2054 | if (!cert && x) X509_free(x); |
| 2055 | return rv; |
| 2056 | } |
| 2057 | |
| 2058 | #define MD_OID_ACME_VALIDATION_NUM "1.3.6.1.5.5.7.1.31" |
| 2059 | #define MD_OID_ACME_VALIDATION_SNAME "pe-acmeIdentifier" |
no test coverage detected