Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling TLS Certificate rotation #1670

Open
wants to merge 1 commit into
base: unstable
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,18 @@ static SSL_CTX *createSSLContext(serverTLSContextConfig *ctx_config, int protoco
return NULL;
}

/* Given a path to a file, return the last time it was accessed (in seconds) */
static time_t getLastModifiedTime(const char* path){
struct stat path_stat;
stat(path, &path_stat);

#ifdef __APPLE__
return path_stat.st_mtimespec.tv_sec;
#else
return path_stat.st_mtime;
#endif
}

/* Attempt to configure/reconfigure TLS. This operation is atomic and will
* leave the SSL_CTX unchanged if fails.
* @priv: config of serverTLSContextConfig.
Expand Down Expand Up @@ -313,6 +325,14 @@ static int tlsConfigure(void *priv, int reconfigure) {
goto error;
}

/* Update the last modified times for the TLS elements */
ctx_config->key_file_last_modified = getLastModifiedTime(ctx_config->key_file);
ctx_config->cert_file_last_modified = getLastModifiedTime(ctx_config->cert_file);
ctx_config->client_cert_file_last_modified = getLastModifiedTime(ctx_config->client_cert_file);
ctx_config->client_key_file_last_modified = getLastModifiedTime(ctx_config->client_key_file);
ctx_config->ca_cert_dir_last_modified = getLastModifiedTime(ctx_config->ca_cert_dir);
ctx_config->ca_cert_file_last_modified = getLastModifiedTime(ctx_config->ca_cert_file);

int protocols = parseProtocolsConfig(ctx_config->protocols);
if (protocols == -1) goto error;

Expand Down
Loading