1

I know how to create a self-signed certificate in a one command:

openssl req -x509 -newkey rsa:4096 \
-keyout my.key -passout pass:123456 -out my.crt \
-days 365 \
-subj /CN=localhost/O=home/C=US/[email protected] \
-addext "subjectAltName = DNS:localhost,DNS:web.internal,email:[email protected]" \
-addext keyUsage=digitalSignature -addext extendedKeyUsage=serverAuth

But I know another sequence:

  • generate private key (openssl genrsa)
  • generate CSR (openssl req -new)
  • sign CSR with private key (openssl x509)

like:

 openssl genrsa -out my.key -passout pass:123456 2048

 openssl req -new \
   -key my.key -passin pass:123456 -out my.csr \
   -subj /CN=localhost/O=home/C=US/[email protected]

 openssl x509 -req \
   -in my.csr -signkey my.key -passin pass:123456 -out my.crt \
   -days 3650 -CAcreateserial \
   -extensions v3_ca \
   -extfile <( \
     echo "[v3_ca]"; \
     echo "extendedKeyUsage=serverAuth"; \
     echo "subjectAltName=DNS:localhost,DNS:web.internal,email:[email protected]")

Does it create self-signed certificate functionally identical to above one-liner?

2 Answers 2

3

Does signing of CSR by the same private key create self-signed certificate?

NO. A certificate is not created by signing a CSR, although many people use this inaccurate description. A certificate is created by signing a certificate body which is NOT a CSR, although SOME of it is usually DERIVED from a CSR. You can see (and confirm) this by looking at the contents of the certificate body and of the CSR and seeing they are different.

Does it create self-signed certificate functionally identical to above one-liner?

Almost. The signing part, which you seem focussed on, is indeed identical; a self-signed cert is always signed with the 'same' key it contains, or more exactly the private half of the same keypair whose public half is in the cert. Both your methods do that. So would the other possible combinations: genrsa plus req -new -x509 -key using that key, and req [-new] -newkey -keyout generating a key and CSR and x509 -req -signkey signing a cert for that CSR, with that key. There are OTHER differences however which it appears you did not intend:

  • Your first method generates 4096-bit RSA key; your second does 2048, but could easily be changed.
  • Your first method sets the validity to 365 days; your second does 3650, but could easily be changed.
  • Your first method puts SAN KU EKU PLUS any extensions in the config file for this case, which you didn't show; your second does SAN EKU only, but could be changed to include KU and any other(s) that were in the config.
4
  • I see that when you give CSR to CA it might reject many info from CSR (like keyUsage or SAN). The only identity part (subject) is migrated "literary" and it make sense. So CA sets own expiry dates, SAN, policies in certificate. For self-signed certificate we just in control of a CA signing process... The confusing part is that CA throws away CSR signature, I thought it is embedded into final CRT, the pub key is only migrated from CSR to CRT. Have to check all I said comparing output of CSR & CRT with openssl asn1parse. Tnx!
    – gavenkoa
    Nov 9, 2020 at 10:57
  • 2
    You're welcome. The word I think you want there is 'literally' -- 'exactly the same (letters and) words'. The phrase 'word for word' has the same meaning, as does 'verbatim' which is the Latin (or Latinate) version but now adopted into English. Nov 9, 2020 at 21:32
  • @dave_thompson_085 you are as proficient with the English language as you are with openssl.
    – mti2935
    Jan 10, 2021 at 2:21
  • 1
    @gavenkoa The CSR is self-signed (i.e. it is signed using the private key that corresponds to the public key in the CSR). See crypto.stackexchange.com/questions/40457/… for the reasons for this. Then, the CSR is submitted to the CA, which creates a cert containing the public key and other info from the CSR, and the cert is signed using the CA's private key.
    – mti2935
    Jan 10, 2021 at 2:24
1

To shortly answer your question, yes.

Deepdive:

To understand this better, let me explain how the signing process works. - To sign a certificate, you'll need a ca and the ca cert file's private key or in the case of self signing you'll just need your key used for the CSR and set the CA to null (if it's required as a function) or not specifying any CA via command line.

The reason it's required for a private key and a crt file is to prevent unauthorized access to the CA or sub-CA's infrastructure. To learn more, I'd suggest either googling the topic or looking into one of the following links as they could be quite helpful for beginners. (Or advanced users! :P)

Wishing you the best with your projects!

~ Nathanna

2
  • set the CA to null or not specifying any CA - so it is a special case when you don't provide CA cert?
    – gavenkoa
    Nov 8, 2020 at 7:37
  • 1
    @gavenkoa essentially! in actuality your telling openssl to use the same cert as a ca. :)
    – Nathanna
    Nov 8, 2020 at 7:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .