* Either we have an order stored in the STAGING area, or we need to create a * new one at the ACME server. */
| 52 | * new one at the ACME server. |
| 53 | */ |
| 54 | static apr_status_t ad_setup_order(md_proto_driver_t *d, md_result_t *result, int *pis_new) |
| 55 | { |
| 56 | md_acme_driver_t *ad = d->baton; |
| 57 | apr_status_t rv; |
| 58 | md_t *md = ad->md; |
| 59 | const char *profile = NULL; |
| 60 | const char *ari_cert_id = NULL; |
| 61 | |
| 62 | assert(ad->md); |
| 63 | assert(ad->acme); |
| 64 | |
| 65 | /* For each domain in MD: AUTHZ setup |
| 66 | * if an AUTHZ resource is known, check if it is still valid |
| 67 | * if known AUTHZ resource is not valid, remove, goto 4.1.1 |
| 68 | * if no AUTHZ available, create a new one for the domain, store it |
| 69 | */ |
| 70 | if (pis_new) *pis_new = 0; |
| 71 | rv = md_acme_order_load(d->store, MD_SG_STAGING, md->name, &ad->order, d->p); |
| 72 | if (APR_SUCCESS == rv) { |
| 73 | md_result_activity_setn(result, "Loaded order from staging"); |
| 74 | goto leave; |
| 75 | } |
| 76 | else if (!APR_STATUS_IS_ENOENT(rv)) { |
| 77 | md_log_perror(MD_LOG_MARK, MD_LOG_DEBUG, rv, d->p, "%s: loading order", md->name); |
| 78 | md_acme_order_purge(d->store, d->p, MD_SG_STAGING, md, d->env); |
| 79 | } |
| 80 | |
| 81 | if (ad->cred->spec && ad->md->ca_account && ad->md->ari_renewals && |
| 82 | ad->acme->api.v2.renewal_info) { |
| 83 | /* are we replacing a previous certificate on the same account? */ |
| 84 | int i; |
| 85 | for (i = 0; i < md_pkeys_spec_count(d->md->pks); ++i) { |
| 86 | md_pkey_spec_t *spec = md_pkeys_spec_get(d->md->pks, i); |
| 87 | const md_pubcert_t *pubcert; |
| 88 | const md_cert_t *cert; |
| 89 | if (md_pkey_spec_eq(ad->cred->spec, spec)) { |
| 90 | rv = md_reg_get_pubcert(&pubcert, d->reg, d->md, i, d->p); |
| 91 | if (rv == APR_SUCCESS) { |
| 92 | cert = APR_ARRAY_IDX(pubcert->certs, 0, const md_cert_t*); |
| 93 | if (cert) { |
| 94 | md_cert_get_ari_cert_id(&ari_cert_id, cert, d->p); |
| 95 | break; |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | md_result_activity_printf(result, "Creating new order, key-spec=%s, " |
| 103 | "profile=%s, replacing-cert=%s", |
| 104 | ad->cred->spec? md_pkey_spec_to_str(ad->cred->spec, d->p) : "default", |
| 105 | ad->profile? ad->profile : "none", |
| 106 | ari_cert_id? ari_cert_id : "none"); |
| 107 | |
| 108 | if (ad->profile) { |
| 109 | if (ad->acme->api.v2.profiles) { |
| 110 | int i; |
| 111 | for (i = 0; !profile && i < ad->acme->api.v2.profiles->nelts; ++i) { |
no test coverage detected