/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
*/
/* "renewing" the certificate from tailscale. Since tailscale has its * own ideas on when to do this, we can only inspect the certificate * it gives us and see if it is different from the current one we have. * (if we have any. first time, lacking a cert, any it gives us is * considered as 'renewed'.)
*/
name = d->md->name;
md_log_perror(MD_LOG_MARK, MD_LOG_DEBUG, 0, d->p, "%s: renewing cert", name);
/* When not explicitly told to reset, we check the existing data. If
* it is incomplete or old, we trigger the reset for a clean start. */ if (!reset_staging) {
md_result_activity_setn(result, "Checking staging area");
rv = md_load(d->store, MD_SG_STAGING, d->md->name, &ts_ctx->md, d->p); if (APR_SUCCESS == rv) { /* So, we have a copy in staging, but is it a recent or an old one? */ if (md_is_newer(d->store, MD_SG_DOMAINS, MD_SG_STAGING, d->md->name, d->p)) {
reset_staging = 1;
}
} elseif (APR_STATUS_IS_ENOENT(rv)) {
reset_staging = 1;
rv = APR_SUCCESS;
}
}
if (reset_staging) {
md_result_activity_setn(result, "Resetting staging area"); /* reset the staging area for this domain */
rv = md_store_purge(d->store, d->p, MD_SG_STAGING, d->md->name);
md_log_perror(MD_LOG_MARK, MD_LOG_TRACE1, rv, d->p, "%s: reset staging area", d->md->name); if (APR_SUCCESS != rv && !APR_STATUS_IS_ENOENT(rv)) {
md_result_printf(result, rv, "resetting staging area"); goto leave;
}
rv = APR_SUCCESS;
ts_ctx->md = NULL;
}
if (!ts_ctx->unix_socket_path) {
rv = APR_ENOTIMPL;
md_result_set(result, rv, "only unix sockets are supported for tailscale connections"); goto leave;
}
rv = md_util_is_unix_socket(ts_ctx->unix_socket_path, d->p); if (APR_SUCCESS != rv) {
md_result_printf(result, rv, "tailscale socket not available, may not be up: %s",
ts_ctx->unix_socket_path); goto leave;
}
url = apr_psprintf(d->p, "http://localhost/localapi/v0/cert/%s?type=crt",
domain);
rv = md_http_GET_perform(http, url, NULL, on_get_cert, ts_ctx); if (APR_SUCCESS != rv) {
md_result_set(result, rv, "retrieving certificate from tailscale"); goto leave;
} if (ts_ctx->chain->nelts <= 0) {
rv = APR_ENOENT;
md_result_set(result, rv, "tailscale returned no certificates"); goto leave;
}
/* Got the key and the chain, is it new? */
rv = md_reg_get_pubcert(&pubcert, d->reg,d->md, 0, d->p); if (APR_SUCCESS == rv) {
old_cert = APR_ARRAY_IDX(pubcert->certs, 0, md_cert_t*);
new_cert = APR_ARRAY_IDX(ts_ctx->chain, 0, md_cert_t*); if (md_certs_are_equal(old_cert, new_cert)) { /* tailscale has not renewed the certificate, yet */
rv = APR_ENOENT;
md_result_set(result, rv, "tailscale has not renewed the certificate yet"); /* let's check this daily */
md_result_delay_set(result, apr_time_now() + apr_time_from_sec(MD_SECS_PER_DAY)); goto leave;
}
}
/* We have a new certificate (or had none before). * Get the key and store both in STAGING.
*/
url = apr_psprintf(d->p, "http://localhost/localapi/v0/cert/%s?type=key",
domain);
rv = md_http_GET_perform(http, url, NULL, on_get_key, ts_ctx); if (APR_SUCCESS != rv) {
md_result_set(result, rv, "retrieving key from tailscale"); goto leave;
}
md_result_set(result, APR_SUCCESS, "A new tailscale certificate has been retrieved successfully and can " "be used. A graceful server restart is recommended.");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.