2 ################################################
3 ### Managed by someone's ansible provisioner ###
4 ################################################
5 # Part of: https://git.somenet.org/root/pub/somesible.git
6 # 2017-2024 by someone <someone@somenet.org>
10 local DOMAIN="${1}" TOKEN_FILENAME="${2}" TOKEN_VALUE="${3}"
12 # This hook is called once for every domain that needs to be
13 # validated, including any alternative names you may have listed.
17 # The domain name (CN or subject alternative name) being
20 # The name of the file containing the token to be served for HTTP
21 # validation. Should be served by your web server as
22 # /.well-known/acme-challenge/${TOKEN_FILENAME}.
24 # The token value that needs to be served for validation. For DNS
25 # validation, this is what you want to put in the _acme-challenge
26 # TXT record. For HTTP validation it is the value that is expected
27 # be found in the $TOKEN_FILENAME file.
29 # Simple example: Use nsupdate with local named
30 # printf 'server 127.0.0.1\nupdate add _acme-challenge.%s 300 IN TXT "%s"\nsend\n' "${DOMAIN}" "${TOKEN_VALUE}" | nsupdate -k /var/run/named/session.key
34 local DOMAIN="${1}" TOKEN_FILENAME="${2}" TOKEN_VALUE="${3}"
36 # This hook is called after attempting to validate each domain,
37 # whether or not validation was successful. Here you can delete
38 # files or DNS records that are no longer needed.
40 # The parameters are the same as for deploy_challenge.
42 # Simple example: Use nsupdate with local named
43 # printf 'server 127.0.0.1\nupdate delete _acme-challenge.%s TXT "%s"\nsend\n' "${DOMAIN}" "${TOKEN_VALUE}" | nsupdate -k /var/run/named/session.key
47 local DOMAIN="${1}" KEYFILE="${2}" CERTFILE="${3}" FULLCHAINFILE="${4}" CHAINFILE="${5}" TIMESTAMP="${6}"
49 # This hook is called once for each certificate that has been
50 # produced. Here you might, for instance, copy your new certificates
51 # to service-specific locations and reload the service.
55 # The primary domain name, i.e. the certificate common
58 # The path of the file containing the private key.
60 # The path of the file containing the signed certificate.
62 # The path of the file containing the full certificate chain.
64 # The path of the file containing the intermediate certificate(s).
66 # Timestamp when the specified certificate was created.
68 # Simple example: Copy file to nginx config
69 # cp "${KEYFILE}" "${FULLCHAINFILE}" /etc/nginx/ssl/; chown -R nginx: /etc/nginx/ssl
70 # systemctl reload nginx
74 local DOMAIN="${1}" OCSPFILE="${2}" TIMESTAMP="${3}"
76 # This hook is called once for each updated ocsp stapling file that has
77 # been produced. Here you might, for instance, copy your new ocsp stapling
78 # files to service-specific locations and reload the service.
82 # The primary domain name, i.e. the certificate common
85 # The path of the ocsp stapling file
87 # Timestamp when the specified ocsp stapling file was created.
89 # Simple example: Copy file to nginx config
90 # cp "${OCSPFILE}" /etc/nginx/ssl/; chown -R nginx: /etc/nginx/ssl
91 # systemctl reload nginx
96 local DOMAIN="${1}" KEYFILE="${2}" CERTFILE="${3}" FULLCHAINFILE="${4}" CHAINFILE="${5}"
98 # This hook is called once for each certificate that is still
99 # valid and therefore wasn't reissued.
103 # The primary domain name, i.e. the certificate common
106 # The path of the file containing the private key.
108 # The path of the file containing the signed certificate.
110 # The path of the file containing the full certificate chain.
112 # The path of the file containing the intermediate certificate(s).
115 invalid_challenge() {
116 local DOMAIN="${1}" RESPONSE="${2}"
118 # This hook is called if the challenge response has failed, so domain
119 # owners can be aware and act accordingly.
123 # The primary domain name, i.e. the certificate common
126 # The response that the verification server returned
128 # Simple example: Send mail to root
129 # printf "Subject: Validation of ${DOMAIN} failed!\n\nOh noez!" | sendmail root
133 local STATUSCODE="${1}" REASON="${2}" REQTYPE="${3}" HEADERS="${4}"
135 # This hook is called when an HTTP request fails (e.g., when the ACME
136 # server is busy, returns an error, etc). It will be called upon any
137 # response code that does not start with '2'. Useful to alert admins
138 # about problems with requests.
142 # The HTML status code that originated the error.
144 # The specified reason for the error.
146 # The kind of request that was made (GET, POST...)
148 # HTTP headers returned by the CA
150 # Simple example: Send mail to root
151 # printf "Subject: HTTP request failed failed!\n\nA http request failed with status ${STATUSCODE}!" | sendmail root
155 local DOMAIN="${1}" CERTDIR="${2}" ALTNAMES="${3}"
157 # This hook is called before any certificate signing operation takes place.
158 # It can be used to generate or fetch a certificate signing request with external
160 # The output should be just the cerificate signing request formatted as PEM.
164 # The primary domain as specified in domains.txt. This does not need to
165 # match with the domains in the CSR, it's basically just the directory name.
167 # Certificate output directory for this particular certificate. Can be used
168 # for storing additional files.
170 # All domain names for the current certificate as specified in domains.txt.
171 # Again, this doesn't need to match with the CSR, it's just there for convenience.
173 # Simple example: Look for pre-generated CSRs
174 # if [ -e "${CERTDIR}/pre-generated.csr" ]; then
175 # cat "${CERTDIR}/pre-generated.csr"
180 # This hook is called before the cron command to do some initial tasks
181 # (e.g. starting a webserver).
187 # This hook is called at the end of the cron command and can be used to
188 # do some final (cleanup or other) tasks.
189 chmod -R u=rwX,g=rX,o-rwx "$CERTDIR"
194 if [[ "${HANDLER}" =~ ^(deploy_challenge|clean_challenge|deploy_cert|deploy_ocsp|unchanged_cert|invalid_challenge|request_failure|generate_csr|startup_hook|exit_hook)$ ]]; then