3

If I use OpenSSL to create an X509 certificate that gets signed with a CA certificate and includes an X509v3 SAN (Subject Alternative Name) extension, the generated certificate contains the SAN extension twice, whereas if the certificate is self-signed the SAN extension appears only once (which I would consider correct).

Steps to reproduce:

$ openssl version
OpenSSL 1.0.2n  7 Dec 2017
$ openssl genrsa -out example.key 2048
$ openssl req -new -key example.key -out example.csr
# ... confirm certificate defaults only enter "example.com" as Common Name
$ echo subjectAltName=DNS:example.com,DNS:www.example.com > example.cnf
$ openssl x509 -req -sha256 -days 7300 -text -extfile example.cnf \
  -in example.csr -signkey example.key \
  -CA ../ca.crt -CAkey ../ca.key -set_serial 01 \
  -out example.crt

Afterwards if I inpect the certificate the section "X509v3 Subject Alternative Name" is printed twice:

$ openssl x509 -in example.crt -text -noout
...
        X509v3 extensions:
            X509v3 Subject Alternative Name: 
                DNS:example.com, DNS:www.example.com
            X509v3 Subject Alternative Name: 
                DNS:example.com, DNS:www.example.com
...

This is not the case if no CA is used and the certificate gets self-signed via:

$ openssl x509 -req -sha256 -days 7300 -text -extfile example.cnf \
  -in example.csr -signkey example.key \
  -out example.crt

I can verify this behavior with OpenSSL 1.0.2n as well as OpenSSL 0.9.8zh.

Is this an OpenSSL bug or is there any valid explanation for this?

jww
  • 97,681
  • 90
  • 411
  • 885
Andreas Klöber
  • 5,855
  • 2
  • 27
  • 20
  • 4
    You should not use `-signkey` and `-CA [-CAkey]` together -- these are semantically in conflict because `-signkey` is for selfsigned and `-CA/key` is for not-selfsigned; using either one alone gives me a correct result. However, openssl should (IMO) give an error message or at least fix the problem by suppressing one of the options, not silently do the wrong thing. – dave_thompson_085 Dec 31 '17 at 11:55
  • 1
    You are absolutely right! Does not make any sense and the duplicate entry is gone if `-signkey` is skipped. Anyway, it's still a strange sideeffect. – Andreas Klöber Dec 31 '17 at 13:01
  • Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. – jww Jan 01 '18 at 01:55

1 Answers1

1

See answer of @dave_thompson_085:
Using both -signkey and -CAkey does not make any sense and triggers this strange side-effect.

Andreas Klöber
  • 5,855
  • 2
  • 27
  • 20