Skip to content

Instantly share code, notes, and snippets.

@polettix
Created October 1, 2016 13:50
Show Gist options
  • Save polettix/e8007a7f2064e7f133d93e060032a880 to your computer and use it in GitHub Desktop.
Save polettix/e8007a7f2064e7f133d93e060032a880 to your computer and use it in GitHub Desktop.

When you set Let's Encrypt up, you will:

  • generate a key on your computer (among other things), which we will call domain.key
  • regularly update a certificate file via Let's Encrypt (most probably using one of the Acme Client Implementations), we will call this file domain.crt

The domain.key file is for your eyes only; you should keep it safe where you run taskd and set server.key to point to it.

The domain.crt file actually contains two certificates: one is for your domain, signed by Let's Encrypt; the other one is a CA intermediate file that tells the world Let's Encrypt is entitled to sign certificates, and it is signed by a "major" CA whose certificate is widespread across browsers/libraries.

For example, this is what I get for polettix.it (I removed some lines inside the certificate):

-----BEGIN CERTIFICATE-----
MIIGNTCCBR2gAwIBAgISAyzjWXqpc+XbdY5msxk1ePBhMA0GCSqGSIb3DQEBCwUA
MEoxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MSMwIQYDVQQD
ExpMZXQncyBFbmNyeXB0IEF1dGhvcml0eSBYMzAeFw0xNjA4MTUyMjEwMDBaFw0x
NjExMTMyMjEwMDBaMBYxFDASBgNVBAMTC3BvbGV0dGl4Lml0MIICIjANBgkqhkiG
9w0BAQEFAAOCAg8AMIICCgKCAgEAusStlvvKLfyyArC7Qs3j7Bis8JSuPS8gGqm8
DWD10Dp2LfudHe4zElYZ8N2JhT7fnyJacdK/vnp978XDhO8qyc170voA3/uvZa/q
orazl1dysqqKyD0BKkBThAXuNnCXKH88BS1mRjq5Bt+gj8WQbq+We21nZ9NvMuAK
dm3bq9hG1utEYQjKWF4f//V3wY7upNTqkjSKcsh0Q3BZsz+wJfcfIczDbFfJC5nT
+MVrq85nMAPq9wdudPclxepZwMQ2Ou1fzBn9BxxuSiD6t8uM1jxHXP7AV1iFlqt7
6qlnKhnyKl3Si/RZ4KWwv7TMxL/J5aYveIdJxwb3+C/FY1nepJ+FG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EK6BlspkENnWA
a6xK8xuQSXgvopZPKiAlKQTGdMDQMc2PMTiVFrqoM7hD8bEfwzB/onkxEz0tNvjj
/PIzark5McWvxI0NHWQWM6r6hCm21AvA2H3DkwIDAQABo4IBfTCCAXkwEgYDVR0T
AQH/BAgwBgEB/wIBADAOBgNVHQ8BAf8EBAMCAYYwfwYIKwYBBQUHAQEEczBxMDIG
CCsGAQUFBzABhiZodHRwOi8vaXNyZy50cnVzdGlkLm9jc3AuaWRlbnRydXN0LmNv
bTA7BggrBgEFBQcwAoYvaHR0cDovL2FwcHMuaWRlbnRydXN0LmNvbS9yb290cy9k
c3Ryb290Y2F4My5wN2MwHwYDVR0jBBgwFoAUxKexpHsscfrb4UuQdf/EFWCFiRAw
VAYDVR0gBE0wSzAIBgZngQwBAgEwPwYLKwYBBAGC3xMBAQEwMDAuBggrBgEFBQcC
ARYiaHR0cDovL2Nwcy5yb290LXgxLmxldHNlbmNyeXB0Lm9yZzA8BgNVHR8ENTAz
MDGgL6AthitodHRwOi8vY3JsLmlkZW50cnVzdC5jb20vRFNUUk9PVENBWDNDUkwu
Y3JsMB0GA1UdDgQWBBSoSmpjBH3duubRObemRWXv86jsoTANBgkqhkiG9w0BAQsF
AAOCAQEA3TPXEfNjWDjdGBX7CVW+dla5cEilaUcne8IkCJLxWh9KEik3JHRRHGJo
uM2VcGfl96S8TihRzZvoroed6ti6WqEBmtzw3Wodatg+VyOeph4EYpr/1wXKtx8/
wApIvJSwtmVi4MFU5aMqrSDE6ea73Mj2tcMyo5jMd6jmeWUHK8so/joWUoHOUgwu
X4Po1QYz+3dszkDqMp4fklxBwXRsW10KXzPMTZ+sOPAveyxindmjkW8lGy+QsRlG
PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6
KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==
-----END CERTIFICATE-----

On the server side, you can just point server.cert to point to where domain.crt is located.

On the client side, you have to take the second certificate from the file, save in a file of its own (e.g. letsencrypt-ca.crt) and configure it as taskd.ca:

sed -n '1d;/BEGIN/,/END/p' domain.crt > letsencrypt-ca.crt
task config --force taskd.ca "$PWD/letsencrypt-ca.crt"

If you don't have domain.crt in your client machine (it's a server-side file after all), but you already set taskd properly, then you can do the following on the client machine to generate letsencrypt-ca.crt:

gnutls-cli --print-cert -p 53589 domain.example.com </dev/zero \
| sed -n '/BEGIN/,/END/p' \
| sed -n '1d;/BEGIN/,/END/p' \
> letsencrypt-ca.crt

My sed-fu is a bit weak, so I decided to do the filtering in two steps, the first to isolate the certificates, the second to remove the first certificate and keep the second one.

The last command above can be useful to update file letsencrypt-ca.crt when needed (because it's a certificate that will eventually expire).

Summing up:

  • generate a key domain.key

  • setup a client for Let's Encrypt to get a certificate domain.crt

  • extract letsencrypt-ca.crt from domain.crt, either directly or using gnutls-cli and some sed magic

  • do the following configurations on the server:

      taskd config --force server.key  /path/to/domain.key
      taskd config --force server.cert /path/to/domain.crt
    
  • do the folloiwing configuration on the client:

      task config --force taskd.ca /path/to/letsencrypt-ca.crt
    
@kwisatz
Copy link

kwisatz commented Feb 10, 2020

Have you used this successfully?
Here it says it's not going to work https://github.com/GothenburgBitFactory/taskserver-setup/blob/master/PITCHME.md#lets-encrypt and I've not been able to make it work either, although I don't actually see why the certificate would not be readable?

Feb 10 21:16:42 nevermore taskd[14256]: 2020-02-10 20:16:42 IP logging off
Feb 10 21:16:42 nevermore taskd[14256]: 2020-02-10 20:16:42 Certificate /etc/letsencrypt/live/domain.tld/cert.pem
Feb 10 21:16:42 nevermore taskd[14256]: 2020-02-10 20:16:42 Server Certificate not readable: '/etc/letsencrypt/live/domain.tld/cert.pem'

@kwisatz
Copy link

kwisatz commented Feb 10, 2020

Never mind, just saw that /etc/letsencrypt/archive is readable by root only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment