OpenSSL CA to sign CSR with SHA256 – Sign CSR issued with SHA-256
The overall process is:
- Create CA
- Private CA key
- Create private key
- Check private key
- Public CA certificate
- Create public certificate
- Check public certificate
- Private CA key
- Sign CSR
- SHA-1
- Create CSR using SHA-1
- Check CSR
- Sign CSR enforcing SHA-256
- Check signed certificate
- SHA-256
- Create CSR using SHA-256
- Check CSR
- Sign CSR
- Check signed certificate
- SHA-1
Sign CSR request – SHA-256
When a CSR is created a signature algorithm can be specified. Currently, this should be SHA-256. Installing a TLS certificate that is using SHA-256 ensures that browsers like Chrome, Firefox, etc won`t show a security warning to the user. Signing the CSR using the CA is straight forward.
Create CSR using SHA-256
openssl req -out sha256.csr -new -newkey rsa:2048 -nodes -keyout sha256.key -sha256
The command creates two files: sha256.key containing the private key and sha256.csr containing the certificate request.
Check CSR
openssl req -verify -in sha256.csr -text -noout
The signature algorithm of the CSR is SHA-256
Sign CSR
Singing the CSR using the CA
openssl x509 -req -days 360 -in sha256.csr -CA ca.cert.pem -CAkey ca.key.pem -CAcreateserial -out sha256.crt
This will sign the CSR using SHA-256 as provided by CSR.
Check signed certificate
openssl x509 -text -noout -in sha256.crt
The certificate is signed using SHA-256.
Possible problem: the certificate may be signed using SHA-1.
Why is the certificate signed with SHA1? Without providing –sha256 parameter, openssl is using the default value. Depending on the version of openssl you are using, the default may be using SHA-1. This is the case when you use the default openssl binary available on MacOs.
openssl version –a
This version is old. Better to install a newer one using brew.
After updating, the default algorithm is SHA-256 and not SHA-1 anymore. In case you cannot update the default openssl binary, install a newer version to a different location and use that one.
2 Comments
Ben · March 12, 2021 at 18:25
Please note that the first command under “Create CSR – SHA-256” has a Unicode dash in the “-sha256” part. Copy-pasting it won’t work. Instead, retype it
Tobias Hofmann · March 13, 2021 at 09:05
Hi Ben,
thanks for finding this. I fixed the text, it is working now with copy&paste.