Let's Encrypte with multiple domains wasn't working for ECC certs

How do I initiate the renewal of the certificate, simply delete the old one from /shared/ssl?

I reckon it does it always when rebuilded so there is no need to delete anything.

1 Like

the certificate was issued yesterday, so normally it needs a --force in the LE scripts. I have now renamed the old certificates and am testing a rebuild.

Apparently this does not work, I do not get the second domain entered: https://ssl-tools.net/webservers/rpg-foren.com

It also doesnā€™t look like everything is replaced correctly, the ecc file is missing the subdomain:

cat /etc/runit/1.d/letsencrypt
#!/bin/bash
/usr/sbin/nginx -c /etc/nginx/letsencrypt.conf

issue_cert() {
  LE_WORKING_DIR="${LETSENCRYPT_DIR}" /shared/letsencrypt/acme.sh --issue $2 -d rpg-foren.com -d www.rpg-foren.com --keylength $1 -w /var/www/discourse/public
}

cert_exists() {
  [[ "$(cd /shared/letsencrypt/rpg-foren.com$1 && openssl verify -CAfile <(openssl x509 -in ca.cer) fullchain.cer | grep "OK")" ]]
}

########################################################
# RSA cert
########################################################
issue_cert "4096"

if ! cert_exists ""; then
  # Try to issue the cert again if something goes wrong
  issue_cert "4096" "--force"
fi

LE_WORKING_DIR="${LETSENCRYPT_DIR}" /shared/letsencrypt/acme.sh \
  --installcert \
  -d rpg-foren.com \
  -d www.rpg-foren.com --fullchainpath /shared/ssl/rpg-foren.com.cer \
  --keypath /shared/ssl/rpg-foren.com.key \
  --reloadcmd "sv reload nginx"

########################################################
# ECDSA cert
########################################################
issue_cert "ec-256"

if ! cert_exists "_ecc"; then
  # Try to issue the cert again if something goes wrong
  issue_cert "ec-256" "--force"
fi

LE_WORKING_DIR="${LETSENCRYPT_DIR}" /shared/letsencrypt/acme.sh \
  --installcert --ecc \
  -d rpg-foren.com \
  --fullchainpath /shared/ssl/rpg-foren.com_ecc.cer \
  --keypath /shared/ssl/rpg-foren.com_ecc.key \
  --reloadcmd "sv reload nginx"

if cert_exists "" || cert_exists "_ecc"; then
  grep -q 'force_https' "/var/www/discourse/config/discourse.conf" || echo "force_https = 'true'" >> "/var/www/discourse/config/discourse.conf"
fi

/usr/sbin/nginx -c /etc/nginx/letsencrypt.conf -s stop

I have just executed the following manually, now the certificates fit:

/shared/letsencrypt/acme.sh --issue --force -d rpg-foren.com -d www.rpg-foren.com --keylength 4096 -w /var/www/discourse/public --server letsencrypt
/shared/letsencrypt/acme.sh --issue --force -d rpg-foren.com -d www.rpg-foren.com --keylength ec-256 -w /var/www/discourse/public --server letsencrypt

/shared/letsencrypt/acme.sh --installcert -d rpg-foren.com -d www.rpg-foren.com --fullchainpath /shared/ssl/rpg-foren.com.cer --keypath /shared/ssl/rpg-foren.com.key --reloadcmd "sv reload nginx"
/shared/letsencrypt/acme.sh --installcert -d rpg-foren.com -d www.rpg-foren.com --fullchainpath /shared/ssl/rpg-foren.com_ecc.cer --keypath /shared/ssl/rpg-foren.com_ecc.key --reloadcmd "sv reload nginx"

this is my rewrite for forwarding:

   # tell letsencrypt what additional certs to get
    - replace:
        filename: "/etc/runit/1.d/letsencrypt"
        from: /--keylength/
        to: "-d www.rpg-foren.com --keylength"
    - replace:
        filename: "/etc/runit/1.d/letsencrypt"
        from: /--fullchainpath/
        to: "-d www.rpg-foren.com --fullchainpath"
    - file:
        path: /etc/nginx/conf.d/discourse_redirect.conf
        contents: |
          server {
            listen 80;
            listen 443 ssl;
            server_name www.rpg-foren.com;
            return 301 $scheme://rpg-foren.com$request_uri;

            ssl_protocols TLSv1.2 TLSv1.3;
            ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
            ssl_prefer_server_ciphers off;

            ssl_certificate /shared/ssl/rpg-foren.com.cer;
            ssl_certificate /shared/ssl/rpg-foren.com_ecc.cer;

            ssl_certificate_key /shared/ssl/rpg-foren.com.key;
            ssl_certificate_key /shared/ssl/rpg-foren.com_ecc.key;

            ssl_session_tickets off;
            ssl_session_timeout 1d;
            ssl_session_cache shared:SSL:1m;
          }

Is it possible that a replace command is only executed once?

It looks like the cert is valid now?

Iā€™m pretty sure that redirects are handled somewhere else in the chain and you donā€™t need to do anything for that to work. I would probably remove that part from your yml file.

It seems like itā€™s working as expected now.

Yes, but I set it up manually and not via the hook, because the hook didnā€™t do it correctly.

you mean from the subdomain www. to the main domain? At least not via nginx. No url is defined there so that the web server responds to all incoming domains.

.
It works for me (see below).

I mean that anything that resolves to the site redirects to the hostname. For any standard install you can enter the IP address and itā€™ll redirect to the https://hostname. (See below)

I just set this up, creating a new standard install with https://dashboard.literatecomputing.com/, and additionally pasting extrahostname.myforum.us in the domain2 field above and copy/pasting the resulting after_ssl hook immediately after hooks: in web_only.yml (and did it while the script was building the data container, so I didnā€™t have to rebuild after it finished the first time!).

These all work as expected:

1 Like

Does this mean that the subdomain is stored in /etc/runit/1.d/letsencrypt for both the rsa and ecc installation script?
As you can see above, the hook has only stored the subdomain in the rsa part but not in the ecc part.

  --installcert \
  -d rpg-foren.com \
  -d www.rpg-foren.com
  --installcert --ecc \
  -d rpg-foren.com \
  --fullchainpath

Here is /etc/runit/1.d/letsencrypt

#!/bin/bash
/usr/sbin/nginx -c /etc/nginx/letsencrypt.conf

issue_cert() {
  LE_WORKING_DIR="${LETSENCRYPT_DIR}" /shared/letsencrypt/acme.sh --issue $2 -d test.myforum.us -d extrahostname.myforum.us --keylength $1 -w /var/www/discourse/public
}

cert_exists() {
  [[ "$(cd /shared/letsencrypt/test.myforum.us$1 && openssl verify -CAfile <(openssl x509 -in ca.cer) fullchain.cer | grep "OK")" ]]
}

########################################################
# RSA cert
########################################################
issue_cert "4096"

if ! cert_exists ""; then
  # Try to issue the cert again if something goes wrong
  issue_cert "4096" "--force"
fi

LE_WORKING_DIR="${LETSENCRYPT_DIR}" /shared/letsencrypt/acme.sh \
  --installcert \
  -d test.myforum.us \
  -d extrahostname.myforum.us  --fullchainpath /shared/ssl/test.myforum.us.cer \
  --keypath /shared/ssl/test.myforum.us.key \
  --reloadcmd "sv reload nginx"

########################################################
# ECDSA cert
########################################################
issue_cert "ec-256"

if ! cert_exists "_ecc"; then
  # Try to issue the cert again if something goes wrong
  issue_cert "ec-256" "--force"
fi

LE_WORKING_DIR="${LETSENCRYPT_DIR}" /shared/letsencrypt/acme.sh \
  --installcert --ecc \
  -d test.myforum.us \
  --fullchainpath /shared/ssl/test.myforum.us_ecc.cer \
  --keypath /shared/ssl/test.myforum.us_ecc.key \
  --reloadcmd "sv reload nginx"

if cert_exists "" || cert_exists "_ecc"; then
  grep -q 'force_https' "/var/www/discourse/config/discourse.conf" || echo "force_https = 'true'" >> "/var/www/discourse/config/discourse.conf"
fi

/usr/sbin/nginx -c /etc/nginx/letsencrypt.conf -s stop

Ah. I see itā€™s in the RSA (bad) cert, but not in the ECC (good) cert.

OK. now I get it. That --fullcert stanza needs global: true in it. Iā€™m testing it now.

2 Likes

OK. Hereā€™s the new ā€˜/etc/runit/1.d/letsencryptā€™

#!/bin/bash
/usr/sbin/nginx -c /etc/nginx/letsencrypt.conf

issue_cert() {
  LE_WORKING_DIR="${LETSENCRYPT_DIR}" /shared/letsencrypt/acme.sh --issue $2 -d test.myforum.us -d extrahostname.myforum.us --keylength $1 -w /var/www/discourse/public
}

cert_exists() {
  [[ "$(cd /shared/letsencrypt/test.myforum.us$1 && openssl verify -CAfile <(openssl x509 -in ca.cer) fullchain.cer | grep "OK")" ]]
}

########################################################
# RSA cert
########################################################
issue_cert "4096"

if ! cert_exists ""; then
  # Try to issue the cert again if something goes wrong
  issue_cert "4096" "--force"
fi

LE_WORKING_DIR="${LETSENCRYPT_DIR}" /shared/letsencrypt/acme.sh \
  --installcert \
  -d test.myforum.us \
  -d extrahostname.myforum.us  --fullchainpath /shared/ssl/test.myforum.us.cer \
  --keypath /shared/ssl/test.myforum.us.key \
  --reloadcmd "sv reload nginx"

########################################################
# ECDSA cert
########################################################
issue_cert "ec-256"

if ! cert_exists "_ecc"; then
  # Try to issue the cert again if something goes wrong
  issue_cert "ec-256" "--force"
fi

LE_WORKING_DIR="${LETSENCRYPT_DIR}" /shared/letsencrypt/acme.sh \
  --installcert --ecc \
  -d test.myforum.us \
  -d extrahostname.myforum.us  --fullchainpath /shared/ssl/test.myforum.us_ecc.cer \
  --keypath /shared/ssl/test.myforum.us_ecc.key \
  --reloadcmd "sv reload nginx"

if cert_exists "" || cert_exists "_ecc"; then
  grep -q 'force_https' "/var/www/discourse/config/discourse.conf" || echo "force_https = 'true'" >> "/var/www/discourse/config/discourse.conf"
fi

/usr/sbin/nginx -c /etc/nginx/letsencrypt.conf -s stop
~
~

and now I have this, which looks good? https://ssl-tools.net/webservers/extrahostname.myforum.us

Does that look right? If so, Iā€™ll edit the OP to include the global directive.

2 Likes

My Idea:

    # tell letsencrypt what additional certs to get
    - replace:
        filename: "/etc/runit/1.d/letsencrypt"
        from: /--keylength/
        to: "-d www.rpg-foren.com --keylength"
    - replace:
        filename: "/etc/runit/1.d/letsencrypt"
        from: /--installcert \/
        to:  |
          --installcert \
          -d www.rpg-foren.com
    - replace:
        filename: "/etc/runit/1.d/letsencrypt"
        from: /--installcert --ecc \/
        to:  |
          --installcert --ecc \
          -d www.rpg-foren.com

Does mine not work? Itā€™s got 1/3 fewer lines of code.

I donā€™t see a rewrite from you? or am I missing something?
i just wanted to make a nice rewrite so that the file looks good at the end^^

I didnā€™t do it yet. I was waiting to see that you thought it worked.

Hereā€™s the change, just adding global: true to the end of the second replace:

    - replace:
        filename: "/etc/runit/1.d/letsencrypt"
        from: /--fullchainpath/
        to: "-d =domain2=  --fullchainpath"
        global: true

and hereā€™s the whole thing:

  after_ssl:
   # tell letsencrypt what additional certs to get
    - replace:
        filename: "/etc/runit/1.d/letsencrypt"
        from: /--keylength/
        to: "-d extrahostname.myforum.us --keylength"
    - replace:
        filename: "/etc/runit/1.d/letsencrypt"
        from: /--fullchainpath/
        to: "-d extrahostname.myforum.us  --fullchainpath"
        global: true


1 Like

ok so global is the parameter you need for multiple replacements.

looks good from the files you posted, I havenā€™t tried it yet.

Yeah. Sorry that I wasnā€™t paying close enough attention to undertand what you were talking about earlier. From my (bad) test, it ā€œworkedā€, but I didnā€™t notice, and donā€™t know how to check that the ec-whatever cert is really there. Thanks for being persistent.

Does https://ssl-tools.net/webservers/extrahostname.myforum.us make it look like itā€™s got the Right Stuff?

I edited the OP now, so you can give it a shot, and copy/paste from the form above.

If you want to test yourself on a test site and can send me an SSH key, Iā€™ll give you access to the one I just set up. Then you can do a clean install there with your own test domain. Or, you can just do it on your production site and hope for the best. :person_shrugging:

You can find it here:

ls -la /var/discourse/shared/standalone/ssl/
total 24
drwxr-xr-x  2 root root 4096 Sep 24 13:02 .
drwxr-xr-x 15 root root 4096 Sep 23 18:31 ..
-rw-r--r--  1 root root 3941 Sep 25 07:43 rpg-foren.com.cer
-rw-r--r--  1 root root 3941 Sep 25 07:43 rpg-foren.com_ecc.cer
-rw-------  1 root root 3243 Sep 25 07:43 rpg-foren.com_ecc.key
-rw-------  1 root root 3243 Sep 25 07:43 rpg-foren.com.key

the problem is, i donā€™t know how to test ecc and rsa individually.
since the creation file now fits, no further tests are required.

1 Like
root@test-web-only:/shared/ssl# ls -l
total 16
-rw-r--r-- 1 root root 3953 Sep 25 16:41 test.myforum.us.cer
-rw-r--r-- 1 root root 2877 Sep 25 16:41 test.myforum.us_ecc.cer
-rw------- 1 root root  227 Sep 25 16:41 test.myforum.us_ecc.key
-rw------- 1 root root 3247 Sep 25 16:41 test.myforum.us.key

Cool. If you think this looks good, then Iā€™m going to move this discussion to a new topic since hopefully itā€™s resolved.

1 Like

you can test the certificate like this:

openssl x509 -in /var/discourse/shared/standalone/ssl/test.myforum.us.cer -noout -text
then the domains should be listed under dns:
DNS:rpg-foren.com, DNS:www.rpg-foren.com

1 Like
root@test:/var/discourse# openssl x509 -in /var/discourse/shared/web-only/ssl/test.myforum.us.cer -noout -text                       
Certificate:                                                                                                                         
    Data:                                                                                                                            
        Version: 3 (0x2)                                                                                                             
        Serial Number:                                                                                                               
            03:f8:b5:6a:e0:97:53:7f:22:33:81:22:35:b4:3f:73:75:7f 
        Signature Algorithm: sha256WithRSAEncryption                                                                                 
        Issuer: C = US, O = Let's Encrypt, CN = R10                                                                                  
        Validity                                                                                                                     
            Not Before: Sep 25 14:57:13 2024 GMT                  
            Not After : Dec 24 14:57:12 2024 GMT                                                                                     
        Subject: CN = test.myforum.us                            
        Subject Public Key Info:                                  
            Public Key Algorithm: rsaEncryption                   
                Public-Key: (4096 bit)                                                                                                                     
                Modulus:                                                                                                             
                    00:be:a3:9b:79:78:dd:8f:e2:8f:28:f0:d9:6c:74: 
...                    b0:84:33                                                                                                                               
                Exponent: 65537 (0x10001)                                                                                                                  
        X509v3 extensions:                                                                                                                                                                
            X509v3 Key Usage: critical                           
                Digital Signature, Key Encipherment               
            X509v3 Extended Key Usage:                           
                TLS Web Server Authentication, TLS Web Client Authentication                                                                                                              
            X509v3 Basic Constraints: critical                                                                                                                                            
                CA:FALSE                                                                                                                                                                  
            X509v3 Subject Key Identifier:                                                                                                                                                
                43:55:B7:D6:54:03:CE:B0:FB:C8:D1:2A:42:F5:B7:C5:60:C7:D8:48                                                                                                                                                              
            X509v3 Authority Key Identifier:                                 
                BB:BC:C3:47:A5:E4:BC:A9:C6:C3:A4:72:0C:10:8D:A2:35:E1:C8:E8                                                                                
            Authority Information Access:                                    
                OCSP - URI:http://r10.o.lencr.org                                                                                                                                                                                        
                CA Issuers - URI:http://r10.i.lencr.org/                                                                                                                                                                                 
            X509v3 Subject Alternative Name:                                                                                                                                                                                             
                DNS:extrahostname.myforum.us, DNS:test.myforum.us                                                                                                                                                                        
            X509v3 Certificate Policies:                                     
                Policy: 2.23.140.1.2.1                                                       
            CT Precertificate SCTs:                                                          
                Signed Certificate Timestamp:                                                                                                                                                                                            
                    Version   : v1 (0x0)                                                                                                                                                                                                 
                    Log ID    : DF:E1:56:EB:AA:05:AF:B5:9C:0F:86:71:8D:A8:C0:32:                                                                           
                                4E:AE:56:D9:6E:A7:F5:A5:6A:01:D1:C1:3B:BE:52:5C                                                                            
                    Timestamp : Sep 25 15:55:44.143 2024 GMT                                 
                    Extensions: none                                                                                                                                                                                                     
                    Signature : ecdsa-with-SHA256                                                                                                                                                                                        
                    Signed Certificate Timestamp:                                                                       
                    Version   : v1 (0x0)                                                                            
                    Log ID    : A2:E3:0A:E4:45:EF:BD:AD:9B:7E:38:ED:47:67:77:53:                                                                           
                                D7:82:5B:84:94:D7:2B:5E:1B:2C:C4:B9:50:A4:47:E7                                                                            
                    Timestamp : Sep 25 15:55:45.945 2024 GMT                                                        
                    Extensions: none                                                                                
                    Signature : ecdsa-with-SHA256                                                                   
    Signature Algorithm: sha256WithRSAEncryption                                                                    
    Signature Value:                                                                                                
        cf:c6:59:d8                                  

and that includes:

            X509v3 Subject Alternative Name:                                                 
                DNS:extrahostname.myforum.us, DNS:test.myforum.us  

Ah. OK.

openssl x509 -in /var/discourse/shared/web-only/ssl/test.myforum.us_ecc.cer -noout -text 

contains:

            X509v3 Subject Alternative Name: 
                DNS:extrahostname.myforum.us, DNS:test.myforum.us
1 Like