Skip to content

Commit 8beffb8

Browse files
authored
Merge pull request #863 from openziti/process-cert-extension-requests
handle cert extension if requested by the network
2 parents 270e402 + 1b44591 commit 8beffb8

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

inc_internal/internal_model.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ XX(posture_query_set, ziti_posture_query_set, array, postureQueries, __VA_ARGS__
6262
XX(is_mfa_required, model_bool, none, isMfaRequired, __VA_ARGS__) \
6363
XX(is_mfa_complete, model_bool, none, isMfaComplete, __VA_ARGS__) \
6464
XX(is_cert_extendable, model_bool, none, isCertExtendable, __VA_ARGS__) \
65+
XX(cert_extend_requested, model_bool, none, isCertExtendRequested, __VA_ARGS__) \
66+
XX(key_roll_requested, model_bool, none, isCertKeyRollRequested, __VA_ARGS__) \
6567
XX(auth_queries, ziti_auth_query_mfa, list, authQueries, __VA_ARGS__) \
6668
XX(authenticator_id, model_string, none, authenticatorId, __VA_ARGS__)
6769

library/ziti.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,28 +2137,38 @@ static void api_session_cb(ziti_api_session *api_sess, const ziti_error *err, vo
21372137
goto done;
21382138
}
21392139

2140-
struct tm exp;
2141-
ztx->id_creds.cert->get_expiration(ztx->id_creds.cert, &exp);
2142-
time_t now = time(0);
2143-
time_t exptime = mktime(&exp);
2144-
2145-
bool renew = exptime - now < ztx->opts.cert_extension_window * ONE_DAY;
2146-
if (!renew) {
2140+
if (!api_sess->is_cert_extendable) {
2141+
ZTX_LOG(DEBUG, "identity certificate is not renewable");
21472142
goto done;
21482143
}
21492144

2150-
if (!api_sess->is_cert_extendable) {
2151-
ZTX_LOG(WARN, "identity certificate is not renewable");
2152-
goto done;
2145+
struct tm exp;
2146+
if (api_sess->cert_extend_requested || api_sess->key_roll_requested) {
2147+
ZTX_LOG(INFO, "controller requested certificate renewal (%s key roll)",
2148+
api_sess->key_roll_requested ? "with" : "without");
2149+
} else {
2150+
ztx->id_creds.cert->get_expiration(ztx->id_creds.cert, &exp);
2151+
time_t now = time(0);
2152+
time_t exptime = mktime(&exp);
2153+
2154+
bool renew = exptime - now < ztx->opts.cert_extension_window * ONE_DAY;
2155+
if (!renew) {
2156+
goto done;
2157+
}
2158+
ZTX_LOG(INFO, "renewing identity certificate exp[%04d-%02d-%02d %02d:%02d]",
2159+
1900 + exp.tm_year, exp.tm_mon + 1, exp.tm_mday, exp.tm_hour, exp.tm_min);
21532160
}
21542161

21552162
if ((ztx->opts.events & ZitiConfigEvent) == 0) {
2156-
ZTX_LOG(WARN, "identity certificate needs to be renewed but application is not handling ZitiConfigEvent");
2163+
ZTX_LOG(WARN, "identity certificate needs to be renewed "
2164+
"but application is not handling ZitiConfigEvent");
21572165
goto done;
21582166
}
21592167

2160-
ZTX_LOG(INFO, "renewing identity certificate exp[%04d-%02d-%02d %02d:%02d]",
2161-
1900 + exp.tm_year, exp.tm_mon + 1, exp.tm_mday, exp.tm_hour, exp.tm_min);
2168+
if (api_sess->key_roll_requested) {
2169+
ZTX_LOG(WARN, "key roll requested, but not yet supported");
2170+
}
2171+
21622172
if (ztx->tlsCtx->generate_csr_to_pem(ztx->id_creds.key, &csr, &len, "O", "OpenZiti",
21632173
"DC", ztx->config.controller_url,
21642174
"CN", api_sess->identity_id,

0 commit comments

Comments
 (0)