Free certificates using Certes CLI
Certes CLI
is delivered as a dotnet global tool, and it can be install
using dotnet tool
command:
dotnet tool install --global dotnet-certes
Managing ACME account
An ACME account is needed for generating SSL certificates. If you don't have one already, you can register a new account:
certes account new [email protected]
To use an existing account, simply import your account key:
certes account set ./account-key.pem
You may review the current account:
certes account show
The result should look similar to this:
{
"location": "https://acme-v02.api.letsencrypt.org/acme/acct/1",
"resource": {
"status": "valid",
"contact": [
"mailto:[email protected]"
]
}
Ordering SSL Certificates
With an valid ACME account, we can start generating SSL certificates now.
You may add up to 100 domains in one order, and mixing wildcard and non-wildcard domains, as long as the domains don't overlap with each other.
certes order new *.example.com api.example.net
Values that are IP addresses, such as 203.0.113.10, are ordered as IP
identifiers (RFC 8738); everything else is a DNS name. IP identifiers cannot use
the DNS challenge.
To select a certificate profile advertised by the server (listed under
meta.profiles in certes server show), or to mark the order as a renewal of an
earlier certificate (see Renewal information):
certes order new 203.0.113.10 --profile shortlived
certes order new api.example.net --replaces aYhba4dGQEHhs3uEe6CuLN4ByNQ.AIdlQyE
A profile name that the server does not advertise is rejected before the order
is sent. Let's Encrypt issues IP address certificates only under its shortlived
profile.
Keep note of the order location, which we will use it in the next steps:
{
"location": "https://acme-v02.api.letsencrypt.org/acme/order/2/3",
"resource": {
"status": "pending",
"expires": "2018-07-03T04:55:04+00:00",
"identifiers": [
{
"type": "dns",
"value": "*.example.com"
},
{
"type": "dns",
"value": "api.example.net"
}
],
"authorizations": [
"https://acme-v02.api.letsencrypt.org/acme/authz/coHQk9WEhTHTjd9eWFeA2UueKuG8qjBKP3EyVdQXZsk",
"https://acme-v02.api.letsencrypt.org/acme/authz/E1MtjxAiM1l_TyK3OWhMR1n9-u3DYOkUVxchzmZ2OaU"
],
"finalize": "https://acme-v02.api.letsencrypt.org/acme/finalize/2/3"
}
}
Validating Domain Ownership
We will need to prove that we have control of the domains
we claimed in the order, so the ACME server would issue
the SSL certificate. The ACME server may send varies challenges
for each domain, such as DNS, HTTP, and TLS-ALPN, and we
can fullfill any one of them.
For wildcard domains, currently only
DNSchallenge is accepted.
Setup for Challenges
Certes CLI provides commands for generating necessary data to fullfill the challenges.
DNS challenge
To get the TXT record value for DNS challenge:
certes order authz https://acme-v02.api.letsencrypt.org/acme/order/2/3 *.example.com dns
The output will contain the TXT record value.
{
"...": "...",
"dnsTxt": "Uil-TOCuvR9qnC7H3V65ossmqPgDERDg_9ahr6ZYBd0",
"resource": "..."
}
HTTP-01 challenge
To get token and thumbprint value for HTTP-01 challenge:
certes order authz https://acme-v02.api.letsencrypt.org/acme/order/2/3 api.example.com http
The output will contain the two value fields we need to use for order validation.
{
"location": "...",
"resource": {
"type": "http-01",
"url": "https://acme-v02.api.letsencrypt.org/acme/chall-v3/2645311522/sample",
"status": "Pending",
"token": "iuaJR4CdLFxvt4RsmVsgfSU46rqYsrQpzxasdactest"
},
"keyAuthz": "iuaJR4CdLFxvt4RsmVsgfSU46rqYsrQpzxasdactest.Qed9-4Ek4ot3idslj89tmCMGEYlfY5I463X37hCd9i4"
}
On your application server you need to create file which will be available under http://api.example.com/.well-known/acme-challenge/iuaJR4CdLFxvt4RsmVsgfSU46rqYsrQpzxasdactest (resource.token value for last url segment). File content needs to be set as iuaJR4CdLFxvt4RsmVsgfSU46rqYsrQpzxasdactest.Qed9-4Ek4ot3idslj89tmCMGEYlfY5I463X37hCd9i4 (keyAuthz value).
TLS-ALPN-01 challenge
certes order authz https://acme-v02.api.letsencrypt.org/acme/order/2/3 api.example.com tls-alpn
The output includes keyAuthz. The TLS server must answer the acme-tls/1
ALPN protocol on port 443 with a self-signed certificate for the identifier that
carries the SHA-256 digest of keyAuthz in the critical acmeIdentifier extension
(RFC 8737). The CLI does not produce that certificate; the library's
IKey.TlsAlpnCertificate helper can.
Challenge types are dns, http and tls-alpn; dns-01, http-01 and
tls-alpn-01 are accepted too.
Completing Challenges
Once the responses for challenges are ready, we can let the ACME service to perform validation:
certes order validate https://acme-v02.api.letsencrypt.org/acme/order/2/3 *.example.com dns
certes order validate https://acme-v02.api.letsencrypt.org/acme/order/2/3 api.example.net http
The statuses should now changed to valid for the authorizations of the domains.
{
"identifier": {
"type": "dns",
"value": "*.example.com"
},
"status": "valid",
"expires": "2018-07-24T00:01:32Z",
"challenges": [
"..."
],
"wildcard": true
}
Exporting SSL Certificate
Once all the domains are validated, we can finilize the order with a random private key:
certes order finalize https://acme-v02.api.letsencrypt.org/acme/order/2/3 `
--out cert-key.pem
The
--private-keyoption can be used to specify the private key for the certificate.
The
--preferred-chainoption can be used to specify the preferred root certificate.
To export the certificate in PEM:
certes cert pem https://acme-v02.api.letsencrypt.org/acme/order/2/3 `
--out my-cert.pem --preferred-chain "ISRG X1 Root"
Or pack the certificate and private key in PFX:
certes cert pfx https://acme-v02.api.letsencrypt.org/acme/order/2/3 pfx-password `
--private-key cert-key.pem `
--out my-cert.pfx
The PFX is encrypted with AES-256. Add --legacy-encryption for consumers that
cannot read AES-encrypted PFX files, such as Windows Server 2016 and earlier.
That's all, you now have your free SSL certificate ready for deploy.
Renewal information
Servers supporting ACME Renewal Information (RFC 9773) suggest when to renew each
certificate. Pass the certificate PEM, for example the file written by
certes cert pem:
certes cert renewal-info my-cert.pem
{
"certificateId": "aYhba4dGQEHhs3uEe6CuLN4ByNQ.AIdlQyE",
"suggestedWindow": { "start": "2025-01-02T04:00:00+00:00", "end": "2025-01-03T04:00:00+00:00" },
"explanationUrl": null,
"retryAfterSeconds": 21600
}
Renew at a random time within suggestedWindow, and create the new order with
--replaces <certificateId>. Check again after retryAfterSeconds, bounded to a
reasonable range such as one minute to one day. No account key is needed.
Certificate lifetimes are shrinking (Let's Encrypt: 64 days from February 2027, 45 days from February 2028), so scheduling renewals from the suggested window is more reliable than renewing a fixed number of days before expiry.