Help moving SSL cert to different server

I created an SSL cert for my domain (home.mydomain.co.uk) using the Let's Encrypt add-on for Home Assistant (v5.2.9). The domain is registered at Cloudflare. This worked fine for accessing my Home Assistant server. I then introduced an nginx server on another machine, and am now using it to proxy forward requests to my Home Assistant server. I copied the files from the SSL folder on my Home Assistant server (fullchain.pem and privkey.pem) to the /etc/letsencrypt/archive/home.mydomain.co.uk/ folder on the nginx server. I then created symbolic links to them in the /etc/letsencrypt/live/home.mydomain.co.uk/ folder.
I am now trying to write a script to renew the SSL cert - using sudo certbot renew. I already use this method, on the same machine, to renew another LetsEncrypt domain. I am running certbot 0.40.0.
I am getting this error:

CertstorageError: expected /etc/letsencrypt/live/home.mydomain.co.uk/cert.pem to be a symlink

I'm guessing that I do not have the correct files and symlinks in the right places for certbot to perform the renewal. Could anyone guide me on which folders/files/links I need to create for certbot to be able to renew this domain? It currently renews my existing domain without any issues.

It looks like I mis-typed the creation of the symlinks, so have now corrected this and have a different error:

certbot.errors.CertStorageError: renewal config file {'version': '0.40.0', 'archive_dir': '/etc/letsencrypt/archive/home.mydomain.co.uk', 'privkey': '/etc/letsencrypt/live/home.mydomain.co.uk/privkey.pem', 'fullchain': '/etc/letsencrypt/live/home.mydomain.co.uk/fullchain.pem', 'renewalparams': {'account': 'c490a65e0ae73945725caa662ec6ca13', 'pref_challs': ['http-01'], 'authenticator': 'standalone', 'server': 'https://acme-v02.api.letsencrypt.org/directory'}} is missing a required file reference                                                                                                                  
Renewal configuration file /etc/letsencrypt/renewal/home.mydomain.co.uk.conf is broken. Skipping.

This is my renewal config file:

# renew_before_expiry = 30 days
version = 0.40.0
archive_dir = /etc/letsencrypt/archive/home.mydomain.co.uk
privkey = /etc/letsencrypt/live/home.mydomain.co.uk/privkey.pem
fullchain = /etc/letsencrypt/live/home.mydomain.co.uk/fullchain.pem

# Options used in the renewal process
[renewalparams]
account = *****************************
pref_challs = http-01,
authenticator = standalone
server = https://acme-v02.api.letsencrypt.org/directory

???

Welcome to the Let's Encrypt Community.

You appear to have forged someone else's domain in your post. Please don't do that. While it is more difficult to offer assistance when you don't share your real dimain, it is extremely bad form to abuse a domain that is not yours. There are reserved exapmle domains that should be used instead, such as example.com.

Holy smoke! That version is ancient! Certbot versions 0.x, 1.x, and 2.x are all past their prime. Please review the installation instructions for version 3.x at:

If you are going to need to use the same certificate on multiple hosts, it often makes more sense to choose on host to obtain the certificate and automate distribution of that certificate to your other hosts.

I have to hand this off to other volunteers for the moment, but I'll check back later.

2 Likes

If you already have a working Certbot setup for one domain just request a new certificate for the new domain this machine will handle.

Copying over just parts from one system to another isn't worth the effort. Delete the files and folders you copied over and request a new cert.

And, yes, I fully agree that an upgrade from 0.40 is highly recommended.

2 Likes

Oh sorry I was using "mydomain.co.uk" as an example - I didn't realise that this might be considered a real domain. I'll use example.com in the future.

I generated the original certificate quite a while ago, and wasn't aware of the existence of newer versions - I'll look into updating it.

So if I just delete the files and re-request a certificate, will it not matter that there is already a current certificate in existence?

1 Like

No, the same server can have many certificates. And, two different servers can each have a cert for the exact same set of domain names (although this is rarely needed).

I doubt that --standalone option shown in that renewal file is the best choice for a server using nginx. Either the --nginx or --webroot option is likely better. The --standalone requires your nginx to be stopped for the cert request and renewals. These other two options allow nginx to stay running.

There is also a DNS Challenge but that is often more difficult to setup.

If you need help sorting that please provide your actual domain name(s) as well as other info from the form below as it relates to your nginx server. Thanks

==========================

Please fill out the fields below so we can help you better. Note: you must provide your domain name to get help. Domain names for issued certificates are all made public in Certificate Transparency logs (e.g. crt.sh | example.com), so withholding your domain name here does not increase secrecy, but only makes it harder for us to provide help.

My domain is:

I ran this command:

It produced this output:

My web server is (include version):

The operating system my web server runs on is (include version):

My hosting provider, if applicable, is:

I can login to a root shell on my machine (yes or no, or I don't know):

I'm using a control panel to manage my site (no, or provide the name and version of the control panel):

The version of my client is (e.g. output of certbot --version or certbot-auto --version if you're using Certbot):

2 Likes

Many thanks for the advice. I will try the "nginx" option instead of "standalone". I guess I'll have to wait for a few weeks until the first cert expires to see if it all works OK.

Why is waiting needed? You can request a new cert on the new machine today. The limit is 5 identical certs per account per week. Getting that many each week isn't good practice :slight_smile: But, getting an extra or two during transition is perfectly reasonable.

You can even test using --dry-run option. That uses the Let's Encrypt staging (test) system. It won't issue a publicly trusted cert but works great for testing setups.

The --dry-run command for --nginx requires a different syntax than you'll use for your production cert. But, try this first:

sudo certbot certonly --dry-run --nginx -d example.com -d www.example.com  
2 Likes

example.com is the proper domain name to use if you redacted the actual domain name.

As https://example.com/ shows the intended usages

Example Domain
This domain is for use in illustrative examples in documents. You may use this domain in literature without prior coordination or asking for permission.

Also see:

2 Likes

Thanks for the suggestion. I just tried it, and the result looked promising:

You have an existing certificate that contains a portion of the domains you
requested (ref: /etc/letsencrypt/renewal/example.co.uk.conf)

It contains these names: example.ddns.net

You requested these names for the new certificate: example.co.uk,
example.ddns.net.

Do you want to expand and replace this existing certificate with the new
certificate?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(E)xpand/(C)ancel: E
Simulating renewal of an existing certificate for example.co.uk and example.ddns.net
The dry run was successful.

I'm not sure I understand what it means by "expand and replace this existing certificate with the new certificate". It suggests to me a single certificate for both domains
???

yes. you must have a cert with just one name already

1 Like

No - that's the thing. The cert for the first domain was created a few years ago, using certbot directly. The other cert was only created a week or so ago, on a different machine, using the Let's Encrypt add-in for Home Assistant. I wasn't aware that it was possible to have a single cert for two different domains.
If I do a dry run for each cert individually, I get a message for the older cert :

An RSA certificate named example.com already exists. Do you want to update it to ECDSA?
(U)pdate key type / (K)eep existing key type:

Presumably updating would be the best choice?

Interestingly, don't get offered this option if I request certs for both domains at the same time.

The two machines are not aware of which certs each of them got.

I am puzzled. If you have one cert on two different machines are you doing the --dry-run just once on each machine? Or?

If we knew your actual domain name this would be a lot easier.

An ECDSA cert has been the default for a long time and is best for many cases. I don't know if your HA has requirements for one or the other.

Certbot preserves RSA for renewals of prior certs. But, new certs default to ECDSA. I guess when you "expand" it you also get the new default.

2 Likes

I did the dry run separately for each domain on the nginx server only (assuming that the certs on the Home Assistant server would now be redundant). I have now requested new certs for both domains, and got a surprisingly helpful message that a task had been scheduled to renew the certs when the are due to expire.

I now have an different issue, in that it seems incoming https requests to the nginx server are failing, as they are being forwarded to port 443 on the Home Assistant (where I have now disable the SSL certs). Looks like I now have an nginx config issue to address....

Is that your router doing that port forwarding?

1 Like

No it's more complicated than that. My router forwards to the nginx server (which hosts a couple of sites), and the nginx server forwards requests for my Home Assistant domain to the Home Assistant server. In theory nginx should be listening for https requests and forwarding them to the Home Assistant server as http requests, but that doesn't seem to be happening - the HA server seems to be receiving the requests as https, and if I disable the SSL cert on the HA host my requests are failing with an SSL error :0(

1 Like

Ah, yes, sounds like your proxy_pass isn't right. Or, experiment using different proxied ports as debug aid. But, yeah, this is getting outside scope of this place :slight_smile:

1 Like

Sorry to trouble you again, but I think I have made a mistake somewhere in the generation of the SSL cert for my domain. The app that I use to connect to my domain was refusing to connect, due to a "hostname certificate mismatch".

When I query the details of my cert, it is making references to another dynamic domain name which I own (which is pointed at the same IP address as the domain that I am now dealing with). So in the code below, I am querying the cert for home.example.co.uk, but am seeing references to example2.ddns.net:

$ openssl x509 -in /etc/letsencrypt/live/home.example.co.uk/fullchain.pem -text -noout |grep -A1 Subject
        Subject: CN = example2.ddns.net
        Subject Public Key Info:
            Public Key Algorithm: id-ecPublicKey
--
            X509v3 Subject Key Identifier: 
                E5:DA:48:0A:7C:C0:12:8B:07:7D:53:3D:3E:37:D2:40:D0:15:4D:2E
--
            X509v3 Subject Alternative Name: 
                DNS:example2.ddns.net

I'm thinking that this is maybe the reason why my app is objecting?
I know that you'd really need to know the actual name of the domain in question to give a definitive answer, but due to the way I am using it I'd prefer not to share it on a public forum. Maybe I could DM you the actual domain name?

First, I am not sure why your post would have been flagged. Did you flag it yourself because there is enough info in the openssl command to identify your domain? All LE certs are logged in the public Certificate Transparency logs which can be searched using various criteria.

Yes, hiding names makes helping with these kinds of problems very difficult.

But, in short, the domain in the URL must match a name in the cert of the service you connect to. Generally, in nginx each HTTPS server block has a cert for every name listed in server_name. You can proxy from that server block to whatever you want. Even use HTTP if you wish if you are connecting across a trusted network.

I now know the names involved so that wouldn't help. I only help in this public forum so if you won't provide the actual names I don't think I can be much more help.

1 Like

Yes I have no idea why it was flagged/hidden. I had already opened a separate question, but the domain is home.richmondtech.co.uk.
The CN and Alternative Name on the cert is ianmanning.ddns.net

My web server is (include version):nginx 1.18.0

The operating system my web server runs on is (include version):Lubuntu 20.04 LTS

My hosting provider, if applicable, is:Cloudflare

I can login to a root shell on my machine (yes or no, or I don't know):yes

I'm using a control panel to manage my site (no, or provide the name and version of the control panel):Cloudflare

The version of my client is (e.g. output of certbot --version or certbot-auto --version if you're using Certbot): certbot 3.0.1

1 Like