From 8eb679e08e08b4bb992c8d43f57c3458aab4cf1a Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Wed, 9 Dec 2015 00:17:20 +0100 Subject: Ship LE's intermediate CA files and add cert validation. --- letsencrypt | 31 +++++++++++++++++++++++++------ letsencryptauthorityx1.pem | 32 ++++++++++++++++++++++++++++++++ letsencryptauthorityx2.pem | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 6 deletions(-) create mode 100644 letsencryptauthorityx1.pem create mode 100644 letsencryptauthorityx2.pem diff --git a/letsencrypt b/letsencrypt index 4c932e4..7465378 100755 --- a/letsencrypt +++ b/letsencrypt @@ -11,13 +11,14 @@ WWW_USER=www-data WWW_GROUP=www-data ACME_WEBSERVER=acme-webserver ACME_CLIENT=acme-slave +CAfile=/usr/share/lets-encrypt/letsencryptauthorityx1.pem declare COMMAND ACCOUNTKEY declare -l GENKEY declare RUNAS QUIET= DEBUG= declare SRVCRT= CHAIN= CSR SRVKEY -delcale -i MIN_AGE=0 +declare -i MIN_AGE=0 declare -l HASH= declare SUBJECT=/ declare SAN= @@ -168,7 +169,7 @@ elif [ "$COMMAND" = 'new-cert' ]; then echo "Error: Missing --output" >&2 exit 1 fi - if [ -s "$SRVCRT" ] && \ + if [ -s "$SRVCRT" ] && [ $MIN_AGE -gt 0 ] && \ exp=$(openssl x509 -noout -enddate <"$SRVCRT" 2>/dev/null) && \ [ $(( $(date -d "${exp#*=}" +%s) - $(date +%s))) -gt $MIN_AGE ]; then [ ! "$DEBUG" ] || echo "Expiration date ($(date -d"${exp#*=}")) is too far away, come back later." >&2 @@ -277,17 +278,35 @@ while read data; do done >"$pipe" if [ "$COMMAND" = 'new-cert' ]; then - # TODO - # Verify: dump and compare public keys - # Valid cert, signed by the right CA - # https://crt.sh/?q=cse-fresti.cse.chalmers.se&iCAID=7395 + # https://crt.sh/?q=mail.fripost.org&iCAID=7395 + # https://crt.sh/?spkisha1=$sha1 + + # Ensure the cert's pubkey matches that of the CSR, and that it's signed by the intended CA + if [ ! -s "$x509" ] || + ! diff <(openssl req -in "$CSR" -pubkey -noout) \ + <(openssl x509 -in "$x509" -pubkey -noout) >/dev/null || + ! openssl verify -CAfile "$CAfile" -purpose sslserver -x509_strict <"$x509" >/dev/null; then + echo "Error: Got an invalid X.509 certificate from the ACME server!" >&2 + exit 1 + fi # if it doesn't exist, create the file with mode 0644 minus the process's umask(2) [ -e "$SRVCRT" ] || touch "$SRVCRT" cat "$x509" >"$SRVCRT" [ ! "$DEBUG" ] || openssl x509 -noout -text <"$SRVCRT" + if [ ! "$QUIET" ]; then + echo "X.509 certificate $SRVCRT has been updated or renewed" + echo + openssl x509 -noout \ + -text -certopt no_header,no_version,no_pubkey,no_sigdump \ + -fingerprint -sha256 <"$SRVCRT" + fi + for (( i=0; i<${#NOTIFY[@]}; i++ )); do ${NOTIFY[$i]} done + +else + [ "$QUIET" ] || echo OK fi diff --git a/letsencryptauthorityx1.pem b/letsencryptauthorityx1.pem new file mode 100644 index 0000000..22c095b --- /dev/null +++ b/letsencryptauthorityx1.pem @@ -0,0 +1,32 @@ +-----BEGIN CERTIFICATE----- +MIIFjTCCA3WgAwIBAgIRAOeTkL6SBwNJGF95dYHlyoMwDQYJKoZIhvcNAQELBQAw +TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh +cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTIwMDIw +WhcNMjAwNjA0MTIwMDIwWjBKMQswCQYDVQQGEwJVUzEWMBQGA1UEChMNTGV0J3Mg +RW5jcnlwdDEjMCEGA1UEAxMaTGV0J3MgRW5jcnlwdCBBdXRob3JpdHkgWDEwggEi +MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCc0wzwWuUuR7dyXTeDs2hjMOrX +NSYZJeG9vjXxcJIvt7hLQQWrqZ41CFjssSrEaIcLo+N15Obzp2JxunmBYB/XkZqf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ib3UHocjlEJfNbDy9zgKTYURcMVweo1dkbH +NbLc5mIjIk/kJ+RPD+chR+gJjy3Gh9xMNkDrZQKfsIO93hxTsZMmgZQ4c+vujC1M +jSak+Ai87YZeYQPh1fCGMSTno5III37DUCtIn8BJxJixuPeOMKsjLLD5AtMVy0fp +d19lcUek4bjDY8/Ujb5/wfn2+Kk7z72SxWdekjtHOWBmKxqq8jDuuMw4ymg1g5n7 +R7TZ/Y3y4bTpWUDkBHFo03xNM21wBFDIrCZZeVhvDW4MtT6+Ass2bcpoHwYcGol2 +gaLDa5k2dkG41OGtXa0fY+TjdryY4cOcstJUKjv2MJku4yaTtjjECX1rJvFLnqYe +wC+FmxjgWPuyRNuLDAWK30mmpcJZ3CmD6dFtAi4h7H37 +-----END CERTIFICATE----- diff --git a/letsencryptauthorityx2.pem b/letsencryptauthorityx2.pem new file mode 100644 index 0000000..612b4a5 --- /dev/null +++ b/letsencryptauthorityx2.pem @@ -0,0 +1,32 @@ +-----BEGIN CERTIFICATE----- +MIIFjTCCA3WgAwIBAgIRAJY2TKc4C+SL3JDGzeC33mgwDQYJKoZIhvcNAQELBQAw +TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh +cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTIwMDMx +WhcNMjAwNjA0MTIwMDMxWjBKMQswCQYDVQQGEwJVUzEWMBQGA1UEChMNTGV0J3Mg +RW5jcnlwdDEjMCEGA1UEAxMaTGV0J3MgRW5jcnlwdCBBdXRob3JpdHkgWDIwggEi +MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDhJHRCe7eRMdlz/ziq2M5EXLc5 +CtxErg29RbmXN2evvVBPX9MQVGv3QdqOY+ZtW8DoQKmMQfzRA4n/YmEJYNYHBXia +kL0aZD5P3M93L4lry2evQU3FjQDAa/6NhNy18pUxqOj2kKBDSpN0XLM+Q2lLiSJ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EaK1hjm314LYpLoYGvYYLJO +/J76XAx8ZgpofqHz1gAEfiMLMLxLQkOjKLXqoUEd5KdnzaO3aLH91gnasy8aD4D5 +9RfEO2xcaozD2rbYsoAMVzcZZHw0Smdmobaz2YazMBjFRcqGntg6s5Xqwusaleiy +snjMCC/9mvIPqGyuVnBPTBaUDFDEhX6qD2MX4dzODL91Z0ogYDWcFLN+uLnZKHje +4JoNuzkJ2FXWOREcsW93KXb+3T8COjhTDKvK4H6ufdrZxxusx60ajJAMBzW0XTf5 +nm2yGEDtyVoMgJLp0rkiPlormgHxSkFDOJbY94J7yxRK +-----END CERTIFICATE----- \ No newline at end of file -- cgit v1.2.3