-
Notifications
You must be signed in to change notification settings - Fork 573
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
Let's Encrypt Auto-Renew scripts #142
Closed
Closed
Changes from all commits
Commits
Show all changes
98 commits
Select commit
Hold shift + click to select a range
a424ce2
initial commit
frezbo 7c90008
initial commit
frezbo 346b977
Added Detailed Instructions
frezbo 9114963
Fixed directory locations
frezbo 2222830
Added comments and fixed location issues
frezbo b735b7b
Added nginx config
frezbo 21af7cf
Fixed a typo
frezbo 939ac56
Added patch from PR #116, thanks to andreascherbaum
frezbo 4d4902e
Added ECDSA certificates, fixed openssl key generation issues
frezbo 32a635c
Added missing colon in nginx config, added extra info
frezbo dabb8c9
Changed travis-ci
frezbo d7bc83b
Added python version
frezbo 7d66a7b
Added python version
frezbo dbab375
Addebuild
frezbo 3a63cd7
Addebuild
frezbo cab38c7
Fixed command
frezbo 6966f63
Build
frezbo 21c46cf
Patched test_module
frezbo e8ed35c
testing
frezbo 436a444
test script
frezbo 20ab63f
testing
frezbo c271544
Added missing sudo
frezbo 5cc07d3
fixed
frezbo e081114
added nginx config file
frezbo a0922a3
added nginx config file
frezbo 00102e0
Added sleep time
frezbo 8f35856
Increased sleep time
frezbo ec1a21f
added missing -y flag with apt-get
frezbo e3b03fa
changed sleep time
frezbo b5b3477
changed sleep time
frezbo 3d99cfa
debugging
frezbo 5f93df3
debugging
frezbo 930353e
debugging
frezbo abaa6cb
debugging
frezbo 5cf1597
debugging
frezbo a9a26aa
debugging
frezbo 4a775d4
removed non-existent domain check
frezbo 114bfd5
removed non-existent domain check
frezbo c26cadc
fixed python server not serving challenges correctly
frezbo 5817bf0
removed nginx config
frezbo 3a2fc29
added ngrok for local testing
frezbo bd51e04
build
frezbo 8d21de1
build
frezbo b71df0d
fixed typo
frezbo 0054e69
corrected ENV's
frezbo 674b5ef
corrected typo
frezbo 73f521a
fixed running python server after setting ENV
frezbo 6ef151f
testing on all python versions
frezbo 043ee21
trying non-existent domain check
frezbo e795d55
trying non-existent domain check
frezbo 91a3d53
trying non-existent domain check
frezbo f1a45b8
Added ec key generation
frezbo 4b98adb
Updated README to reflect modified test method
frezbo 23b9570
Changed the name of non-existent domain from default to a non-existen…
frezbo 70e142b
added missing dot
frezbo 16c20f7
Updated readme as per new renwal script
frezbo c1ad541
Removed unwanted line
frezbo ae16578
Added suggestions by aplanas
frezbo 34d82a8
Removed FUSE required and added nginx to serve the files
frezbo b883050
Removed FUSE requirement and added nginx to serve the files
frezbo 276b2fb
Removed fusepy
frezbo d122084
Removed FUSE requirement and added nginx to serve the files
frezbo 97cdfab
Removed FUSE documentation from README
frezbo 3e0494b
Removed server.py as it is no longer needed
frezbo 732088b
Updated to reflect the new test method
frezbo 6dde02e
Added missing permission for /var/www/html/.well-known
frezbo 27e0738
Added missing permission for /var/www/html/.well-known
frezbo ec749b5
testing new method
frezbo 4390744
added permissions
frezbo 263fbbd
testing
frezbo 1e59f0e
testing
frezbo b7a1941
corrected permissions
frezbo dfef983
corrected permissions
frezbo 65b7fd9
Removed delay
frezbo 9ca772e
Added check for test OS release which was causing failed builds
frezbo 1ca2bff
Adding sleep time to debug
frezbo e8daf4a
Added missing sudo
frezbo 9fb0b6b
removed sleep time
frezbo 9953c0a
Updated README
frezbo 62a640a
Added comments
frezbo bf6097e
Removed __init__.py
frezbo 4cbaa84
Updated README
frezbo 66f5a78
Changed default TLD from io to com
frezbo b85ae57
Required for python, adding back
frezbo fa6204f
Added codeclimate
frezbo 79a56f6
Added codeclimate
frezbo 4e57ec3
Changed the file to reflect updated renew.sh
frezbo 57b9fa2
Changed the file to reflect updated renew.sh
frezbo 8c63149
Updated renew.sh and made more parameters as variables
frezbo ca0d80a
Added more variables and comments
frezbo f5f0603
Added full path for let's encrypt intermediate certificate
frezbo b6ab9f7
Added codeclimate coverage
frezbo ac956a0
Added codeclimate coverage
frezbo 05205f6
Updated README
frezbo b231b5d
Updated script to allow authorization for account, when prior authori…
522b723
Fixed typo
e92c7e0
Reverting back to 05205f6
9a9fcf7
Updated script to allow authorization for account, when prior authori…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
engines: | ||
duplication: | ||
enabled: true | ||
config: | ||
languages: | ||
- ruby | ||
- javascript | ||
- python | ||
- php | ||
fixme: | ||
enabled: true | ||
radon: | ||
enabled: true | ||
ratings: | ||
paths: | ||
- "**.inc" | ||
- "**.js" | ||
- "**.jsx" | ||
- "**.module" | ||
- "**.php" | ||
- "**.py" | ||
- "**.rb" | ||
exclude_paths: | ||
- tests/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Lets Encrypt Renewal script | ||
* Please read the scripts before you run them. | ||
|
||
## Setup | ||
|
||
### Assumes that the server has already been configured with nginx with SSL as per the README in acme-tiny | ||
|
||
1. Download the server_setup.sh script: | ||
``` | ||
wget https://raw.githubusercontent.com/frezbo/acme-tiny/master/lets-encrypt_acme_renew_script/server_setup.sh | ||
``` | ||
<br/> | ||
2. Make the script executable: `chmod u+x server_setup.sh` <br/> | ||
3. Run server_setup.sh as root: `./server_setup.sh` <br/> | ||
4. If you did not modify the locations in your scrips, follow the steps below, otherwise make changes as necessary <br/> | ||
5. Copy the existing certificate to /etc/nginx/ssl/certs, make sure it follows the format domain.tld.ec.crt for ec certificates or domain.tld.rsa.crt for rsa certificates. For example if your domain is domain.tld and has subdomains like subdomain.domain.tld do the following: <br/><br/> `cp <path to your certificate> /etc/nginx/ssl/certs` <br/><br/> Make sure to copy the certificates of all the subdomains too. <br/> | ||
6. Copy the domain keys to /etc/nginx/ssl/private, make sure it follows the format domian.com.ec.key for ec keys or domain.tld.rsa.crt for rsa keys. For example if your domain is domain.tld and has subdomains like subdomain.domain.tld do the following: <br/><br/> `cp <path to your domain key> /etc/nginx/ssl/private` <br/><br/> Make sure to copy the certificates of all the subdomains too. <br/> | ||
7. Make the necessary location changes for the domain private key and certificate location in your nginx configuration <br/> | ||
8. Run `nginx -t` and make sure there are no errors. <br/> | ||
9. The script creates a user named *acme* which renews the certificates, the script also creates your private key used for authenticating with lets-encrypt and signing necessary files. Please keep this key very private. The key is located in */usr/local/scripts/acme-tiny/lets-encrypt_acme_renew_script*. <br/> | ||
10. Edit the file domains.cnf located at */usr/local/scripts/acme-tiny/lets-encrypt_acme_renew_script/domains.cnf* and add the email id at line 8, add necessary country code, state,location and organizaion info as required. <br/> | ||
11. Edit the file domains.txt located at */usr/local/scripts/acme-tiny/lets-encrypt_acme_renew_script/domains.txt* and add your domains on each line. For example if your domain is domain.tld and has subdomains like subdomain.domain.tld do the following: | ||
``` | ||
domain | ||
subdomain.domain | ||
``` | ||
<br/> | ||
12. Edit the file renew.sh located at */usr/local/scripts/acme-tiny/lets-encrypt_acme_renew_script/renew.sh* and add your tld in quotes on line 3. <br/> | ||
13. Make a cron job to run every month as user acme to check for renewals: | ||
``` | ||
crontab -eu acme | ||
``` | ||
<br/> | ||
At the end of line add this: | ||
``` | ||
* * 3 * * /usr/local/scripts/acme-tiny/lets-encrypt_acme_renew_script/renew.sh >> /var/log/renew.log 2>&1 | ||
``` | ||
<br/> | ||
14. Make the script executable: `chmod u+x /usr/local/scripts/acme-tiny/lets-encrypt_acme_renew_script/renew.sh` <br/> | ||
15. If you want to manually run the script: | ||
``` | ||
sudo -u acme /usr/local/scripts/acme-tiny/lets-encrypt_acme_renew_script/renew.sh | ||
``` | ||
<br/> | ||
16. Set the nginx configuration as follows: | ||
|
||
### nginx configuration <br/> nginx versions above 1.10.0 supports both ECDSA and RSA certificates together otherwise stick with a single type | ||
|
||
#### Base domain | ||
``` | ||
server { | ||
server_name domain.tld | ||
ssl_certificate /etc/nginx/ssl/certs/domain.tld.ec.crt; | ||
ssl_certificate_key /etc/nginx/ssl/private/domain.tld.ec.key; | ||
ssl_certificate /etc/nginx/ssl/certs/domain.tld.rsa.crt; | ||
ssl_certificate_key /etc/nginx/ssl/private/domain.tld.rsa.key; | ||
location ~ .well-known/ { | ||
root /var/www/html; #change as per your document root | ||
try_files $uri =404; | ||
log_not_found off; | ||
} | ||
} | ||
``` | ||
|
||
#### Sub-domain | ||
``` | ||
server { | ||
server_name subdomain.domain.tld | ||
ssl_certificate /etc/nginx/ssl/certs/subdomain.domain.tld.ec.crt; | ||
ssl_certificate_key /etc/nginx/ssl/private/subdomain.domain.tld.ec.key; | ||
ssl_certificate /etc/nginx/ssl/certs/subdomain.domain.tld.rsa.crt; | ||
ssl_certificate_key /etc/nginx/ssl/private/subdomain.domain.tld.rsa.key; | ||
location ~ .well-known/ { | ||
root /var/www/html; #change as per your document root | ||
try_files $uri =404; | ||
log_not_found off; | ||
} | ||
} | ||
``` | ||
|
||
## Enjoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[req] | ||
prompt = no | ||
distinguished_name = dn | ||
req_extensions = ext | ||
|
||
[dn] | ||
CN = __DOMAIN__ | ||
emailAddress = [email protected] | ||
O = <your-organization> | ||
C = <country-code> | ||
L = <location> | ||
ST = <state> | ||
|
||
[ext] | ||
subjectAltName = DNS:www.__DOMAIN__,DNS:__DOMAIN__ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
domain | ||
subdomain.domain.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/bin/bash | ||
#Author: TechnoMan, mail: [email protected] | ||
tld="com" #set your domain extension, eg: com, edu, org etc | ||
days_to_expire=30 #certificates are renewed before a month of expiry | ||
document_root=/var/www/html # change to your document root | ||
scripts_directory=/usr/local/scripts # scripts directory | ||
acme_directory=acme-tiny/lets-encrypt_acme_renew_script | ||
nginx_config_location=/etc/nginx #change if this is not your config directory | ||
#certificate file location | ||
#private key file | ||
priv_key_file=priv.key | ||
certs_location=${nginx_config_location}/ssl/certs | ||
#domain keys location | ||
keys_location=${nginx_config_location}/ssl/private | ||
#file containing list of domains | ||
domain_file=${scripts_directory}/${acme_directory}/domains.txt | ||
#file containing CSR genreation parameters | ||
csr_params=${scripts_directory}/${acme_directory}/domains.cnf | ||
#intermediate certificate | ||
int_cert=${scripts_directory}/${acme_directory}/intermediate.pem | ||
#current unix time | ||
curr_time=$(date +%s) | ||
touch ${scripts_directory}/${acme_directory}/.rnd | ||
export RANDFILE=${scripts_directory}/${acme_directory}/.rnd | ||
#check whether certifcate expires within the days specified in days_to_expire | ||
for i in $(cat $domain_file) | ||
do | ||
for cert_type in {ec,rsa} | ||
do | ||
if [ ! -e ${keys_location}/$i.$tld.$cert_type.key ] | ||
then | ||
echo "$cert_type key file not found. Copy the $cert_type key file in $i.$tld.$cert_type.key format as specified in README to ${keys_location}" | ||
fi | ||
if [ -e ${certs_location}/$i.$tld.$cert_type.crt ] | ||
then | ||
#certifcate expiry unix time | ||
((cert_expire_time=$(date -d "$(openssl x509 -in ${certs_location}/$i.$tld.$cert_type.crt -noout -enddate | sed s/notAfter=//g)" +%s))) | ||
#days to expire | ||
((cert_days_untill_expiry=(cert_expire_time-curr_time)/86400)) | ||
if [ $cert_days_untill_expiry -le $days_to_expire ] | ||
then | ||
echo "$cert_days_untill_expiry days untill expiry for $cert_type cert" | ||
if [ $cert_type == 'ec' ] | ||
then | ||
openssl genrsa -out ${scripts_directory}/${acme_directory}/$i.$tld.$cert_type.key 4096 | ||
else | ||
openssl ecparam -genkey -name secp384r1 | openssl ec -out ${scripts_directory}/${acme_directory}/$i.$tld.$cert_type.key | ||
fi | ||
chmod 600 ${scripts_directory}/${acme_directory}/$i.$tld.$cert_type.key | ||
sed -i "s/__DOMAIN__/$i.$tld/g" $csr_params | ||
openssl req -new -config $csr_params -key ${scripts_directory}/${acme_directory}/$i.$tld.$cert_type.key -out ${scripts_directory}/${acme_directory}/$i.$tld.$cert_type.csr | ||
sed -i "s/$i.$tld/__DOMAIN__/g" $csr_params | ||
mv ${certs_location}/$i.$tld.$cert_type.crt ${certs_location}/$i.$tld.$cert_type.crt.old | ||
mv ${keys_location}/$i.$tld.$cert_type.key ${keys_location}/$i.$tld.$cert_type.key.old | ||
mv ${scripts_directory}/${acme_directory}/$i.$tld.$cert_type.key ${keys_location} | ||
python ${scripts_directory}/acme-tiny/acme_tiny.py --account-key ${scripts_directory}/${acme_directory}/$priv_key_file --csr ${scripts_directory}/${acme_directory}/$i.$tld.$cert_type.csr --acme-dir ${document_root}/.well-known/acme-challenge > ${scripts_directory}/${acme_directory}/$i.$tld.$cert_type.tmp.crt | ||
cat ${scripts_directory}/${acme_directory}/$i.$tld.$cert_type.tmp.crt ${scripts_directory}/${acme_directory}/$int_cert > ${certs_location}/$i.$tld.$cert_type.crt | ||
rm -f ${scripts_directory}/${acme_directory}/$i.$tld.$cert_type.tmp.crt | ||
rm -f ${scripts_directory}/${acme_directory}/$i.$tld.$cert_type.csr | ||
fi | ||
else | ||
echo "$cert_type certificate file not found. Copy the $cert_type certificate file in $i.$tld.$cert_type.crt format as specified in README to ${certs_location}" | ||
fi | ||
done | ||
done | ||
rm -f ${scripts_directory}/${acme_directory}/.rnd | ||
sudo nginx -s reload |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash | ||
document_root=/var/www/html # change to your document root | ||
nginx_location=$(which nginx) | ||
nginx_config_location=/etc/nginx #change if this is not your config directory | ||
scripts_location=/usr/local/scripts # change if necessary | ||
renew_scripts_location=${scripts_location}/acme-tiny/lets-encrypt_acme_renew_script | ||
key_file=priv.key #if already has a key change this and set ownership to acme | ||
certs_location=ssl | ||
log_file=/var/log/acme_renew.log #log file | ||
mkdir -p ${scripts_location} | ||
useradd -r -d /nodir -s /usr/sbin/nologin acme #creating a user acme with no home directory and no login | ||
git clone https://github.com/frezbo/acme-tiny.git ${scripts_location}/acme-tiny | ||
openssl genrsa -out ${renew_scripts_location}/$key_file 4096 # generating private key for registering to lets encrypt and certificate generation, keep it very secure | ||
chmod 400 ${renew_scripts_location}/$key_file | ||
wget -O ${renew_scripts_location}/intermediate.pem https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem | ||
chown -R acme:acme ${scripts_location}/acme-tiny | ||
chmod 750 ${scripts_location}/acme-tiny | ||
mkdir -p ${document_root}/.well-known/acme-challenge | ||
chown -R www-data:acme ${document_root}/.well-known | ||
chmod -R 770 ${document_root}/.well-known | ||
echo "acme ALL = NOPASSWD: ${nginx_location} -s reload" > /etc/sudoers.d/acme | ||
mkdir -p ${nginx_config_location}/${certs_location}/certs | ||
mkdir -p ${nginx_config_location}/${certs_location}/private | ||
chown -R acme:root ${nginx_config_location}/${certs_location} | ||
chmod -R 770 ${nginx_config_location}/${certs_location} | ||
touch $log_file | ||
chown acme:acme $log_file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,39 +6,12 @@ explains how to setup and test acme-tiny yourself. | |
|
||
## Setup instructions | ||
|
||
1. Make a test subdomain for a server you control. Set it as an environmental | ||
variable on your local test setup. | ||
* On your local: `export TRAVIS_DOMAIN=travis-ci.gethttpsforfree.com` | ||
2. Generate a shared secret between your local test setup and your server. | ||
* `openssl rand -base64 32` | ||
* On your local: `export TRAVIS_SESSION="<random_string_here>"` | ||
3. Copy and run the test suite mini-server on your server: | ||
* `scp server.py [email protected]` | ||
* `ssh [email protected]` | ||
* `export TRAVIS_SESSION="<random_string_here>"` | ||
* `sudo server.py` | ||
4. Install the test requirements on your local (FUSE and optionally coveralls). | ||
* `sudo apt-get install fuse` | ||
* `virtualenv /tmp/venv` | ||
* `source /tmp/venv/bin/activate` | ||
* `pip install -r requirements.txt` | ||
5. Run the test suit on your local. | ||
Install the test requirements on your local machine. <br/> | ||
* install ngrok: https://ngrok.com/ | ||
* `cd /path/to/acme-tiny` | ||
* `chmod u+x tests/tests.sh` | ||
* `./tests/tests.sh` | ||
* `pip install -r tests/requirements.txt` | ||
* `export TRAVIS_DOMAIN=$(grep -Eoi "hostname:[A-za-z0-9]+.ngrok.io" url.log| head -1 | cut -d ":" -f2)` | ||
* `coverage run --source ./ --omit ./tests/server.py -m unittest tests` | ||
|
||
## Why use FUSE? | ||
|
||
Acme-tiny writes the challenge files for certificate issuance. In order to do | ||
full integration tests, we actually need to serve correct challenge files to | ||
the Let's Encrypt staging server on a real domain that they can verify. However, | ||
Travis-CI doesn't have domains associated with their test VMs, so we need to | ||
send the files to the remote server that does have a real domain. | ||
|
||
The test suite uses FUSE to do this. It creates a FUSE folder that simulates | ||
being a real folder to acme-tiny. When acme-tiny writes the challenge files | ||
in the mock folder, FUSE POSTs those files to the real server (which is running | ||
the included server.py), and the server starts serving them. That way, both | ||
acme-tiny and Let's Encrypt staging can verify and issue the test certificate. | ||
This technique allows for high test coverage on automated test runners (e.g. | ||
Travis-CI). | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mkdir -p ${document_root}/.well-known/acme-challenge
will be enough