Skip to content

Commit af15771

Browse files
committed
Store certificate expiry date to storage
1 parent 8227d90 commit af15771

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

bin/letsencrypt_hooks

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,19 @@ clean_challenge() {
3333

3434
deploy_cert() {
3535
local DOMAIN="${1}" KEYFILE="${2}" CERTFILE="${3}" FULLCHAINFILE="${4}" CHAINFILE="${5}" TIMESTAMP="${6}"
36+
local EXPIRY=$(date --date="$(openssl x509 -enddate -noout -in "$CERTFILE"|cut -d= -f 2)" +%s)
37+
if [ $? -ne 0 ]; then
38+
echo "failed to get the expiry date."
39+
exit 1
40+
fi
3641

3742
curl --silent --show-error --fail -XPOST \
3843
--header "X-Hook-Secret: $HOOK_SECRET" \
3944
--data-urlencode "domain=$DOMAIN" \
4045
--data-urlencode "privkey@$KEYFILE" \
4146
--data-urlencode "cert@$CERTFILE" \
4247
--data-urlencode "fullchain@$FULLCHAINFILE" \
48+
--data-urlencode "expiry=$EXPIRY" \
4349
"http://127.0.0.1:$HOOK_SERVER_PORT/deploy-cert" || { echo "hook request (deploy_cert) failed" 1>&2; exit 1; }
4450
}
4551

lib/resty/auto-ssl/servers/hook.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ return function(auto_ssl_instance)
3939
assert(params["domain"])
4040
assert(params["fullchain"])
4141
assert(params["privkey"])
42-
local _, err = storage:set_cert(params["domain"], params["fullchain"], params["privkey"], params["cert"])
42+
assert(params["expiry"])
43+
local _, err = storage:set_cert(params["domain"], params["fullchain"], params["privkey"], params["cert"], tonumber(params["expiry"]))
4344
if err then
4445
ngx.log(ngx.ERR, "auto-ssl: failed to set cert: ", err)
4546
return ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)

lib/resty/auto-ssl/storage.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ function _M.get_cert(self, domain)
3030
end
3131

3232
local data = cjson.decode(json)
33-
return data["fullchain_pem"], data["privkey_pem"], data["cert_pem"]
33+
return data["fullchain_pem"], data["privkey_pem"], data["cert_pem"], data["expiry"]
3434
end
3535

36-
function _M.set_cert(self, domain, fullchain_pem, privkey_pem, cert_pem)
36+
function _M.set_cert(self, domain, fullchain_pem, privkey_pem, cert_pem, expiry)
3737
-- Store the public certificate and private key as a single JSON string.
3838
--
3939
-- We use a single JSON string so that the storage adapter just has to store
@@ -44,6 +44,7 @@ function _M.set_cert(self, domain, fullchain_pem, privkey_pem, cert_pem)
4444
fullchain_pem = fullchain_pem,
4545
privkey_pem = privkey_pem,
4646
cert_pem = cert_pem,
47+
expiry = expiry,
4748
})
4849

4950
-- Store the cert with the current timestamp, so the old certs are preserved

0 commit comments

Comments
 (0)