Debian Codegraph @

PKG-INFO

raw
1 Metadata-Version: 2.4
2 Name: acme-tiny
3 Version: 5.0.3
4 Summary: A tiny script to issue and renew TLS certs from Let's Encrypt
5 Author-email: Daniel Roesler <[email protected]>
6 Maintainer-email: Daniel Roesler <[email protected]>
7 License-Expression: MIT
8 Project-URL: Homepage, https://github.com/diafygi/acme-tiny
9 Project-URL: Documentation, https://github.com/diafygi/acme-tiny
10 Project-URL: Repository, https://github.com/diafygi/acme-tiny.git
11 Project-URL: Bug Tracker, https://github.com/diafygi/acme-tiny/issues
12 Classifier: Development Status :: 5 - Production/Stable
13 Classifier: Intended Audience :: System Administrators
14 Classifier: Operating System :: OS Independent
15 Classifier: Programming Language :: Python
16 Classifier: Programming Language :: Python :: 2
17 Classifier: Programming Language :: Python :: 2.7
18 Classifier: Programming Language :: Python :: 3
19 Classifier: Programming Language :: Python :: 3.3
20 Classifier: Programming Language :: Python :: 3.4
21 Classifier: Programming Language :: Python :: 3.5
22 Classifier: Programming Language :: Python :: 3.6
23 Classifier: Programming Language :: Python :: 3.7
24 Classifier: Programming Language :: Python :: 3.8
25 Classifier: Programming Language :: Python :: 3.9
26 Classifier: Programming Language :: Python :: 3.10
27 Classifier: Programming Language :: Python :: 3.11
28 Classifier: Programming Language :: Python :: 3.12
29 Classifier: Programming Language :: Python :: 3.13
30 Requires-Python: >=2.7,>=3.7
31 Description-Content-Type: text/markdown
32 License-File: LICENSE
33 Dynamic: license-file
34
35 # acme-tiny
36
37 [![Tests](https://github.com/diafygi/acme-tiny/actions/workflows/full-tests-with-coverage.yml/badge.svg?branch=main)](https://github.com/diafygi/acme-tiny/actions/workflows/full-tests-with-coverage.yml)
38 [![Coverage Status](https://coveralls.io/repos/github/diafygi/acme-tiny/badge.svg?branch=main)](https://coveralls.io/github/diafygi/acme-tiny?branch=main)
39
40 This is a tiny, auditable script that you can throw on your server to issue
41 and renew [Let's Encrypt](https://letsencrypt.org/) certificates. Since it has
42 to be run on your server and have access to your private Let's Encrypt account
43 key, I tried to make it as tiny as possible (currently less than 200 lines).
44 The only prerequisites are python and openssl.
45
46 **PLEASE READ THE SOURCE CODE! YOU MUST TRUST IT WITH YOUR PRIVATE ACCOUNT KEY!**
47
48 ## Donate
49
50 If this script is useful to you, please donate to the EFF. I don't work there,
51 but they do fantastic work.
52
53 [https://eff.org/donate/](https://eff.org/donate/)
54
55 ## How to use this script
56
57 If you already have a Let's Encrypt issued certificate and just want to renew,
58 you should only have to do Steps 3 and 6.
59
60 ### Step 1: Create a Let's Encrypt account private key (if you haven't already)
61
62 You must have a public key registered with Let's Encrypt and sign your requests
63 with the corresponding private key. If you don't understand what I just said,
64 this script likely isn't for you! Please use the official Let's Encrypt
65 [client](https://github.com/letsencrypt/letsencrypt).
66 To accomplish this you need to initially create a key, that can be used by
67 acme-tiny, to register an account for you and sign all following requests.
68
69 ```
70 openssl genrsa 4096 > account.key
71 ```
72
73 #### Use existing Let's Encrypt key
74
75 Alternatively you can convert your key, previously generated by the original
76 Let's Encrypt client.
77
78 The private account key from the Let's Encrypt client is saved in the
79 [JWK](https://tools.ietf.org/html/rfc7517) format. `acme-tiny` is using the PEM
80 key format. To convert the key, you can use the tool
81 [conversion script](https://gist.github.com/JonLundy/f25c99ee0770e19dc595) by JonLundy:
82
83 ```sh
84 # Download the script
85 wget -O - "https://gist.githubusercontent.com/JonLundy/f25c99ee0770e19dc595/raw/6035c1c8938fae85810de6aad1ecf6e2db663e26/conv.py" > conv.py
86
87 # Copy your private key to your working directory
88 cp /etc/letsencrypt/accounts/acme-v01.api.letsencrypt.org/directory/<id>/private_key.json private_key.json
89
90 # Create a DER encoded private key
91 openssl asn1parse -noout -out private_key.der -genconf <(python2 conv.py private_key.json)
92
93 # Convert to PEM
94 openssl rsa -in private_key.der -inform der > account.key
95 ```
96
97 ### Step 2: Create a certificate signing request (CSR) for your domains.
98
99 The ACME protocol (what Let's Encrypt uses) requires a CSR file to be submitted
100 to it, even for renewals. You can use the same CSR for multiple renewals. NOTE:
101 you can't use your account private key as your domain private key!
102
103 ```
104 # Generate a domain private key (if you haven't already)
105 openssl genrsa 4096 > domain.key
106 ```
107
108 ```
109 # For a single domain
110 openssl req -new -sha256 -key domain.key -subj "/CN=yoursite.com" > domain.csr
111
112 # For multiple domains (use this one if you want both www.yoursite.com and yoursite.com)
113 openssl req -new -sha256 -key domain.key -subj "/" -addext "subjectAltName = DNS:yoursite.com, DNS:www.yoursite.com" > domain.csr
114
115 # For multiple domains (same as above but works with openssl < 1.1.1)
116 openssl req -new -sha256 -key domain.key -subj "/" -reqexts SAN -config <(cat /etc/ssl/openssl.cnf <(printf "[SAN]\nsubjectAltName=DNS:yoursite.com,DNS:www.yoursite.com")) > domain.csr
117 ```
118
119 ### Step 3: Make your website host challenge files
120
121 You must prove you own the domains you want a certificate for, so Let's Encrypt
122 requires you host some files on them. This script will generate and write those
123 files in the folder you specify, so all you need to do is make sure that this
124 folder is served under the ".well-known/acme-challenge/" url path. NOTE: Let's
125 Encrypt will perform a plain HTTP request to port 80 on your server, so you
126 must serve the challenge files via HTTP (a redirect to HTTPS is fine too).
127
128 ```
129 # Make some challenge folder (modify to suit your needs)
130 mkdir -p /var/www/challenges/
131 ```
132
133 ```nginx
134 # Example for nginx
135 server {
136 listen 80;
137 server_name yoursite.com www.yoursite.com;
138
139 location /.well-known/acme-challenge/ {
140 alias /var/www/challenges/;
141 try_files $uri =404;
142 }
143
144 ...the rest of your config
145 }
146 ```
147
148 ### Step 4: Get a signed certificate!
149
150 Now that you have setup your server and generated all the needed files, run this
151 script on your server with the permissions needed to write to the above folder
152 and read your private account key and CSR.
153
154 ```
155 # Run the script on your server
156 python acme_tiny.py --account-key ./account.key --csr ./domain.csr --acme-dir /var/www/challenges/ > ./signed_chain.crt
157 ```
158
159 ### Step 5: Install the certificate
160
161 The signed https certificate chain that is output by this script can be used along
162 with your private key to run an https server. You need to include them in the
163 https settings in your web server's configuration. Here's an example on how to
164 configure an nginx server:
165
166 ```nginx
167 server {
168 listen 443 ssl;
169 server_name yoursite.com www.yoursite.com;
170
171 ssl_certificate /path/to/signed_chain.crt;
172 ssl_certificate_key /path/to/domain.key;
173 ssl_session_timeout 5m;
174 ssl_protocols TLSv1.2;
175 ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
176 ssl_session_cache shared:SSL:50m;
177 ssl_dhparam /path/to/server.dhparam;
178 ssl_prefer_server_ciphers on;
179
180 ...the rest of your config
181 }
182
183 server {
184 listen 80;
185 server_name yoursite.com www.yoursite.com;
186
187 location /.well-known/acme-challenge/ {
188 alias /var/www/challenges/;
189 try_files $uri =404;
190 }
191
192 ...the rest of your config
193 }
194 ```
195
196 ### Step 6: Setup an auto-renew cronjob
197
198 Congrats! Your website is now using https! Unfortunately, Let's Encrypt
199 certificates only last for 90 days, so you need to renew them often. No worries!
200 It's automated! Just make a bash script and add it to your crontab (see below
201 for example script).
202
203 Example of a `renew_cert.sh`:
204 ```sh
205 #!/usr/bin/sh
206 python /path/to/acme_tiny.py --account-key /path/to/account.key --csr /path/to/domain.csr --acme-dir /var/www/challenges/ > /path/to/signed_chain.crt.tmp || exit
207 mv /path/to/signed_chain.crt.tmp /path/to/signed_chain.crt
208 service nginx reload
209 ```
210
211 ```
212 # Example line in your crontab (runs once per month)
213 0 0 1 * * /path/to/renew_cert.sh 2>> /var/log/acme_tiny.log
214 ```
215
216 **NOTE:** Since Let's Encrypt's ACME v2 release (acme-tiny 4.0.0+), the intermediate
217 certificate is included in the issued certificate download, so you no longer have
218 to independently download the intermediate certificate and concatenate it to your
219 signed certificate. If you have an shell script or Makefile using acme-tiny &lt;4.0 (e.g. before
220 2018-03-17) with acme-tiny 4.0.0+, then you may be adding the intermediate
221 certificate to your signed_chain.crt twice (which
222 [causes issues with at least GnuTLS 3.7.0](https://gitlab.com/gnutls/gnutls/-/issues/1131)
223 besides making the certificate slightly larger than it needs to be). To fix,
224 simply remove the bash code where you're downloading the intermediate and adding
225 it to the acme-tiny certificate output.
226
227 ## Permissions
228
229 The biggest problem you'll likely come across while setting up and running this
230 script is permissions. You want to limit access to your account private key and
231 challenge web folder as much as possible. I'd recommend creating a user
232 specifically for handling this script, the account private key, and the
233 challenge folder. Then add the ability for that user to write to your installed
234 certificate file (e.g. `/path/to/signed_chain.crt`) and reload your webserver. That
235 way, the cron script will do its thing, overwrite your old certificate, and
236 reload your webserver without having permission to do anything else.
237
238 **BE SURE TO:**
239 * Backup your account private key (e.g. `account.key`)
240 * Don't allow this script to be able to read your domain private key!
241 * Don't allow this script to be run as root!
242
243 ## Staging Environment
244
245 Let's Encrypt recommends testing new configurations against their staging servers,
246 so when testing out your new setup, you can use
247 `--directory-url https://acme-staging-v02.api.letsencrypt.org/directory`
248 to issue fake test certificates instead of real ones from Let's Encrypt's production servers.
249 See [https://letsencrypt.org/docs/staging-environment/](https://letsencrypt.org/docs/staging-environment/)
250 for more details.
251
252 ## Feedback/Contributing
253
254 This project has a very, very limited scope and codebase. I'm happy to receive
255 bug reports and pull requests, but please don't add any new features. This
256 script must stay under 200 lines of code to ensure it can be easily audited by
257 anyone who wants to run it.
258
259 If you want to add features for your own setup to make things easier for you,
260 please do! It's open source, so feel free to fork it and modify as necessary.