Auto-regenerate expired self-signed certificates#1590
Conversation
_httpTLSStart checked whether certificate files exist on disk via access() but never verified whether they have expired. When an auto-generated self-signed certificate expired, CUPS continued using it instead of creating a new one. Add a cupsGetCredentialsExpiration() check so that expired certs are treated as missing, triggering the existing auto-create code path. Fixes: OpenPrinting#1519
|
Hi @lzwind, |
The previous commit passed `crtfile` (a path like /etc/cups/ssl/host.crt) to cupsGetCredentialsExpiration(), but that function expects a PEM string, not a file path. Both backends treat the argument as PEM content (BIO_new_mem_buf / gnutls datum over the string bytes), so a path fails to import, the function returns 0, and `0 > time(NULL)` is always false. As a result `have_creds` was always false and CUPS regenerated the self-signed cert on every restart, even when the existing cert was still valid. Load the PEM string first via cupsCopyCredentials() (the same helper cupsGetCredentialsTrust() uses) and pass that to cupsGetCredentialsExpiration(). Only apply the expiration check to CUPS-managed self-signed certs in the keystore; the Let's Encrypt / CA cert branch keeps the pre-existing "exists => use" behavior, since Let's Encrypt is renewed by certbot and auto-regenerating would overwrite a real CA cert with a self-signed one. Fixes: OpenPrinting#1519
|
Hi @abubakarsabir924-cell — thanks for the check-in, and sorry for the silence. I'm still on this and just came back to finish the test plan. While running through it I found (and fixed) a bug in the original change — details below. Bug in the original change
have_creds = !access(crtfile, R_OK) && !access(keyfile, R_OK)
&& cupsGetCredentialsExpiration(crtfile) > time(NULL);Both backends treat the argument as PEM content:
So FixLoad the PEM string first via Both Test plan resultsBuilt the OpenSSL backend (
Direct API calls:
Simulated
Will push the fix as a new commit on this branch shortly. |
Summary
_httpTLSStartchecked whether certificate files exist on disk viaaccess()but never verified whether they have expired. When an auto-generated self-signed certificate expired, CUPS continued using it instead of creating a new one, breaking HTTPS access.cupsGetCredentialsExpiration()check so that expired certificates are treated as missing, triggering the existing auto-create code path.tls-openssl.candtls-gnutls.cbackends.Fixes: #1519
Test plan