1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
|
# ACME Without Sudo
The [Let's Encrypt](https://letsencrypt.org/) initiative is a fantastic program
that offers **free** https certificates! However, the one catch is that you need
to use their command program to get a free certificate. The default instructions
all assume that you will run it on your your server as root, and that it will
edit your apache/nginx config files.
I love the Let's Encrypt devs dearly, but there's no way I'm going to trust
their script to run on my server as root, be able to edit my server configs, and
have access to my private keys. I'd just like the free ssl certificate, please.
So I made a script that does that. You generate your private key and certificate
signing request (CSR) like normal, then run `sign_csr.py` with your CSR to get
it signed. The script goes through the [ACME protocol](https://github.com/ietf-wg-acme/acme/)
with the Let's Encrypt certificate authority and outputs the signed certificate
to stdout.
This script is meant to be run on your computer locally. It requires you to pass
your account private key. If the account private key is encrypted, openssl will
directly ask for the passphrase each time the private key is needed to sign
requests or data.
## Table of Contents
* [Donate](#donate)
* [Prerequisites](#prerequisites)
* Signing script
* [How to use the signing script](#how-to-use-the-signing-script)
* [Example use of the signing script](#example-use-of-the-signing-script)
* [How to use the signed https certificate](#how-to-use-the-signed-https-certificate)
* [Demo](#demo)
* Revocation script
* [How to use the revocation script](#how-to-use-the-revocation-script)
* [Example use of the revocation script](#example-use-of-the-revocation-script)
* [Alternative: Official Let's Encrypt Client](#alternative-official-lets-encrypt-client)
* [Feedback/Contributing](#feedbackcontributing)
## Donate
If this script is useful to you, please donate to the EFF. I don't work there,
but they do fantastic work.
[https://eff.org/donate/](https://eff.org/donate/)
## Prerequisites
* openssl
* python3
## How to use the signing script
First, you need to generate an user account key for Let's Encrypt.
This is the key that you use to register with Let's Encrypt. If you
already have user account key with Let's Encrypt, you can skip this
step.
```sh
openssl genrsa -aes256 4096 > user.key
openssl rsa -in user.key -pubout > user.pub
```
Second, you need to generate the domain key and a certificate request.
This is the key that you will get signed for free for your domain (replace
"example.com" with the domain you own). If you already have a domain key
and CSR for your domain, you can skip this step.
```sh
#Create a CSR for example.com
openssl genrsa -aes256 4096 > domain.key
openssl req -new -sha256 -key domain.key -subj "/CN=example.com" > domain.csr
#Alternatively, if you want both example.com and www.example.com
openssl genrsa -aes256 4096 > domain.key
openssl req -new -sha256 -key domain.key -subj "/" -reqexts SAN -config <(cat /etc/ssl/openssl.cnf <(printf "[SAN]\nsubjectAltName=DNS:example.com,DNS:www.example.com")) > domain.csr
```
Third, you run the script using python and passing in the path to your user
account private key, email address, and the domain CSR. The paths can be
relative or absolute.
```sh
python3 sign_csr.py --account-key user.key --email mail@example.com domain.csr > signed.crt
```
When you run the script, it will:
- Register you with Let's Encrypt using the email address.
- If the `user.key` is encrypted, openssl will ask for the passphrase every time
the private key is used for signing requests or data.
- Ask you to provision a HTTP resource on your web server for the domain for
the ACME HTTP challenge.
- Will write the certificate to `signed.crt` if ACME HTTP challenge is
successful.
### Help text
```
user@hostname:~$ python3 sign_csr.py --help
usage: sign_csr.py [-h] -k ACCOUNT_KEY [-e EMAIL] csr_path
Get a SSL certificate signed by a Let's Encrypt (ACME) certificate
authority and output that signed certificate. You do NOT need to run
this script on your server, it is meant to be run on your
computer. The script will request you to manually deploy the acme
challenge on your server.
NOTE: YOUR ACCOUNT KEY NEEDS TO BE DIFFERENT FROM YOUR DOMAIN KEY.
Prerequisites:
* openssl
* python version 3
Example: Generate an account keypair, a domain key and csr, and have the domain csr signed.
--------------
$ openssl genrsa -aes256 4096 > user.key
$ openssl rsa -in user.key -pubout > user.pub
$ openssl genrsa -aes256 4096 > domain.key
$ openssl req -new -sha256 -key domain.key -subj "/CN=example.com" > domain.csr
$ python3 sign_csr.py --account-key user.key --email user@example.com domain.csr > signed.crt
--------------
positional arguments:
csr_path path to your certificate signing request
optional arguments:
-h, --help show this help message and exit
-k ACCOUNT_KEY, --account-key ACCOUNT_KEY
path to your Let's Encrypt account private key
-e EMAIL, --email EMAIL
contact email, default is webmaster@<shortest_domain>
user@hostname:~$
```
## Example use of the signing script
### Commands (what you do in your main terminal window)
```
user@hostname:~$ openssl genrsa -aes256 4096 > user.key
Generating RSA private key, 4096 bit long modulus
.....................................++++
...................................................++++
e is 65537 (0x10001)
Enter pass phrase:
Verifying - Enter pass phrase:
user@hostname:~$ openssl genrsa -aes256 4096 > domain.key
Generating RSA private key, 4096 bit long modulus
................................................++++
.................................................................................................................++++
e is 65537 (0x10001)
Enter pass phrase:
Verifying - Enter pass phrase:
user@hostname:~$ openssl req -new -sha256 -key domain.key -subj "/CN=letsencrypt.daylightpirates.org" > domain.csr
Enter pass phrase for domain.key:
user@hostname:~$ python3 sign_csr.py -k user.key -e daniel@roesler.cc domain.csr > chained.pem
Reading pubkey file...
Enter pass phrase for user.key:
Found public key!
Reading csr file...
Found domains letsencrypt.daylightpirates.org
Registering daniel@roesler.cc...
Enter pass phrase for user.key:
Already registered!
Making new order for letsencrypt.daylightpirates.org...
Enter pass phrase for user.key:
Requesting challenges...
Enter pass phrase for user.key:
Please update your server to serve the following file at this URL:
--------------
URL: http://letsencrypt.daylightpirates.org/.well-known/acme-challenge/fcGheyb6yNjSQ7oQ3hFXZqCRpKHrkeq9eBFOcloAO_k
File contents: "fcGheyb6yNjSQ7oQ3hFXZqCRpKHrkeq9eBFOcloAO_k.aY_r0djPrHVGZ6MONmcsSN84_mUmUtHydtPGFq7LKWY"
--------------
Notes:
- Do not include the quotes in the file.
- The file should be one line without any spaces.
Press Enter when you've got the file hosted on your server...
Requesting verification for letsencrypt.daylightpirates.org...
Enter pass phrase for user.key:
Enter pass phrase for user.key:
letsencrypt.daylightpirates.org verified!
Enter pass phrase for user.key:
Waiting for letsencrypt.daylightpirates.org challenge to pass...
Enter pass phrase for user.key:
Passed letsencrypt.daylightpirates.org challenge!
Getting certificate...
Enter pass phrase for user.key:
Received certificate!
You can remove the acme-challenge file from your webserver now.
user@hostname:~$ cat chained.pem
-----BEGIN CERTIFICATE-----
MIIGJTCCBQ2gAwIBAgISATBRUGjFwTtjF4adpF7zd/5qMA0GCSqGSIb3DQEBCwUA
MEoxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MSMwIQYDVQQD
ExpMZXQncyBFbmNyeXB0IEF1dGhvcml0eSBYMTAeFw0xNTEwMjQwOTU4MDBaFw0x
NjAxMjIwOTU4MDBaMCoxKDAmBgNVBAMTH2xldHNlbmNyeXB0LmRheWxpZ2h0cGly
YXRlcy5vcmcwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQC2Ac7twhMz
AxreQxmlY0gBq20zrriMOCLTwwdJ3sfv9bNxo+iG7eidu9imLI0FNjZkxtpyJeG/
+4OnvTgChHiT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TZ+sOPAveyxindmjkW8lGy+QsRlG
PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6
KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==
-----END CERTIFICATE-----
user@hostname:~$
```
### Server Commands (the stuff the script asked you to do on your server)
```
ubuntu@letsencrypt.daylightpirates.org:~$ cd /var/www/root
ubuntu@letsencrypt.daylightpirates.org:/var/www/root$ mkdir -p .well-known/acme-challenge/
ubuntu@letsencrypt.daylightpirates.org:/var/www/root$ echo "fcGheyb6yNjSQ7oQ3hFXZqCRpKHrkeq9eBFOcloAO_k.aY_r0djPrHVGZ6MONmcsSN84_mUmUtHydtPGFq7LKWY" > .well-known/acme-challenge/fcGheyb6yNjSQ7oQ3hFXZqCRpKHrkeq9eBFOcloAO_k
ubuntu@letsencrypt.daylightpirates.org:/var/www/root$
```
## How to use the signed https certificate
The signed https certificate that is output by this script can be used along
with your private key to run an https server. You just securely transfer (using
`scp` or similar) the private key and signed certificate to your server, then
include them in the https settings in your web server's configuration. Here's an
example on how to configure an nginx server:
An unencrypted version of the domain private key needs to be deployed on the
server, to decrypt domain private key do:
```
openssl rsa -in domain.key -out domain.d.key
```
```nginx
server {
listen 443;
server_name letsencrypt.daylightpirates.org;
ssl on;
ssl_certificate chained.pem;
ssl_certificate_key domain.d.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA;
ssl_session_cache shared:SSL:50m;
ssl_dhparam /etc/nginx/server.dhparam;
ssl_prefer_server_ciphers on;
location / {
return 200 'Let\'s Encrypt Example: https://github.com/diafygi/acme-nosudo';
add_header Content-Type text/plain;
}
}
```
## Demo
Here's a website that is using a certificate signed using `sign_csr.py`:
[https://letsencrypt.daylightpirates.org/](https://letsencrypt.daylightpirates.org/)
## How to use the revocation script
First, you will need to the user account key for Let's Encrypt that was used
when the certifacate was signed.
Second, you will need the PEM encoded signed certificate that was produced by
`sign_csr.py`.
Third, you run the script using python and passing in the path to your user
account key and the signed domain certificate. The paths can be relative or
absolute.
```sh
python3 revoke_crt.py -k user.key domain.crt
```
### Help text
```
user@hostname:~$ python3 revoke_crt.py --help
usage: revoke_crt.py [-h] -k ACCOUNT_KEY crt_path
Get a SSL certificate revoked by a Let's Encrypt (ACME) certificate
authority. You do NOT need to run this script on your server, it is
meant to be run on your computer.
NOTE: YOUR PUBLIC KEY NEEDS TO BE THE SAME KEY USED TO ISSUE THE CERTIFICATE.
Prerequisites:
* openssl
* python 3
Example:
--------------
$ python3 revoke_crt.py --public-key user.pub domain.crt
--------------
positional arguments:
crt_path path to your signed certificate
optional arguments:
-h, --help show this help message and exit
-k ACCOUNT_KEY, --account-key ACCOUNT_KEY
path to your Let's Encrypt account private key
user@hostname:~$
```
## Example use of the revocation script
### Commands (what you do in your main terminal window)
```
user@hostname:~$ python3 revoke_crt.py -k user.key chained.pem
Reading pubkey file...
Enter pass phrase for user.key:
Found public key!
Getting account info...
Enter pass phrase for user.key:
Enter pass phrase for user.key:
Certificate revoked!
user@hostname:~$
```
## Alternative: Official Let's Encrypt Client
After I released this script, Let's Encrypt added a manual authenticator to
allow the Let's Encrypt client to not have to be run on your server. Hooray!
However, the Let's Encrypt client still has access to your user account private
keys, so please be aware of that. Anyway, check out the comment on issue
[#5](https://github.com/diafygi/acme-nosudo/issues/5#issuecomment-117283651)
to see how to use the manual authenticator in the official Let's Encrypt client.
```
./letsencrypt-auto --email diafygi@gmail.com --text --authenticator manual --work-dir /tmp/work/ --config-dir /tmp/config/ --logs-dir /tmp/logs/ auth --cert-path /tmp/certs/ --chain-path /tmp/chains/ --csr ~/Desktop/domain.csr
```
## Feedback/Contributing
I'd love to receive feedback, issues, and pull requests to make this script
better. The script itself, `sign_csr.py`, is less than 500 lines of code, so
feel free to read through it! I tried to comment things well and make it crystal
clear what it's doing.
For example, it currently can't do any ACME challenges besides 'http-01'. Maybe
someone could do a pull request to add more challenge compatibility?
|