Why can't a self-signed Root CA work in a one-way SSL verification?

There are two ip: 192.168.31.42 ,192.168.31.50 .Make 192.168.31.72 as server side,192.168.31.42 as client side,all the operating system is debian.The domain name is mylocal.com.

Login server side:

#create the rootCA.keyand rootCA.crt.
openssl req -x509 \
            -sha256 -days 356 \
            -nodes \
            -newkey rsa:2048 \
            -subj "/CN=mylocal.com" \
            -keyout rootCA.key -out rootCA.crt 


#Create the Server Private Key:
sudo openssl genrsa -out /etc/ssl/server.key 2048

#Create Certificate Signing Request Configuration :

cat > csr.conf <<EOF
[ req ]
default_bits = 2048
prompt = no
default_md = sha256
req_extensions = req_ext
distinguished_name = dn

[ dn ]
C = US
CN = mylocal.com

[ req_ext ]
subjectAltName = @alt_names

[ alt_names ]
DNS.1 = 192.168.31.72

EOF

openssl req -new -key server.key -out server.csr -config csr.conf

#Generate SSL certificate With self signed CA:

cat > cert.conf <<EOF

authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names

[alt_names]
DNS.1 = 192.168.31.72
EOF

openssl x509 -req \
    -in server.csr \
    -CA rootCA.crt -CAkey rootCA.key \
    -CAcreateserial -out server.crt \
    -days 365 \
    -sha256 -extfile cert.conf

Now Set configuration on server side's apache2:

<VirtualHost *:80>
    ServerName  mylocal.com
    Redirect permanent / https://mylocal.com/
    DocumentRoot /var/www/html
    <Directory /home/debian/mydoc>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
    </Directory>
</VirtualHost>

<VirtualHost *:443>
    ServerName localhost
    DocumentRoot /var/www/html
    SSLEngine On
    SSLCertificateFile /etc/ssl/server.crt
    SSLCertificateKeyFile /etc/ssl/server.key
    <Directory /var/www/html>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
    </Directory>
</VirtualHost>

Restart apache and quit server ,login my local pc--192.168.31.42.
Pull rootCA.crt into /usr/local/share/ca-certificates,updaate:
sudo update-ca-certificates

Set 192.168.31.72 mylocal.com in /etc/hosts.
Check one-way SSL verification with self singed Root CA :

  1. Innput mylocal.com:443
    one-way-ssl-verification

  2. Check with curl

curl -v --cacert  rootCA.crt   https://mylocal.com:443
*   Trying 192.168.31.72:443...
* Connected to mylocal.com (192.168.31.72) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*  CAfile: rootCA.crt
*  CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (OUT), TLS alert, unknown CA (560):
* SSL certificate problem: unable to get local issuer certificate
* Closing connection 0
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

Am i success or failure?

Not that I can be of any help, but I am just curious, what does the command

openssl s_client -connect mylocal.com:443 -servername mylocal.com

give?
And

openssl s_client -connect mylocal.com:443 -servername mylocal.com -CAfile rootCA.crt

as well.

2 Likes

This has no effect on any (recent) standard Debian configuration known to me. The usual flow to add custom roots in Debian is similar to this:

  1. Create a new sub-directory in /usr/share/ca-certificates, i.e "mycerts". This is technically optional but will make management easier.
  2. Put your custom CA-certificate into /usr/share/ca-certificates/mycerts (or whatever path was choosen in step 1). Ensure that the file ending/suffix is .crt.
  3. Run sudo dpkg-reconfigure ca-certificates. You might get a prompt about the default policy for new certificates, next prompt will ask about what certificates should be installed. Select the new certificate(s) just added.
  4. After confirming, the output should indicate that at least one certificate was added:
Updating certificates in /etc/ssl/certs...
1 added, 0 removed; done.

Note: The dpkg-reconfigure ca-certificates command is actually just a frontend for the configuration file /etc/ca-certificates.conf. The script automatically updates that file then calls update-ca-certificates to regenerate the symlinks. You can also edit that file manually and then call update-ca-certificates, like you did before.


You should also consider fixing your (extended) key usage attributes to avoid potential issues with some clients. The standard values for SSL/TLS RSA certificates are these:

keyUsage = digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth, clientAuth

(in your cert.conf file)

Also, you should have your hostname in your SAN (Subject Alternative Name) list if you intend to connect using that name. Right now you're setting an IP address as DNS-SAN, which is invalid (there are explicit IP-SANs if you want IP addresses in your certificate, but note that these only get used when you're not connecting using a hostname).

2 Likes

1.Rewrite cert.conf:

vim  cert.conf
keyUsage = digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth, clientAuth
subjectAltName = @alt_names

[alt_names]
DNS.1 = 192.168.31.72

2.Install rootCA.crt in debian
The rootCA.crt will not be shown in the prompt window when to execute

sudo dpkg-reconfigure ca-certificates

I have already verified that "sudo update-ca-certificates" can install the "rootCA.crt" in my os,and "sudo dpkg-reconfigure ca-certificates" can not install the customized "rootCA.crt".

Maybe ,i made it.

openssl s_client -connect mylocal.com:443 -servername mylocal.com
CONNECTED(00000003)
depth=1 CN = mylocal.com
verify return:1
depth=0 C = US, CN = mylocal.com
verify return:1
---
Certificate chain
 0 s:C = US, CN = mylocal.com
   i:CN = mylocal.com
---
Server certificate
-----BEGIN CERTIFICATE-----
!!!pasted part of it
MIIDDzCCAfegAwIBAgIUF0c/L69GqKkyw5lrROV8ZSmTkgswDQYJKoZIhvcNAQEL
BQAwFjEUMBIGA1UEAwwLbXlsb2NhbC5jb20wHhcNMjIwNDE2MDA0NzQxWhcNMjMw
-----END CERTIFICATE-----
subject=C = US, CN = mylocal.com

issuer=CN = mylocal.com

---
No client certificate CA names sent
Peer signing digest: SHA256
Peer signature type: RSA-PSS
Server Temp Key: X25519, 253 bits
---
SSL handshake has read 1343 bytes and written 383 bytes
Verification: OK
---
New, TLSv1.3, Cipher is TLS_AES_256_GCM_SHA384
Server public key is 2048 bit
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
Early data was not sent
Verify return code: 0 (ok)
---
---
Post-Handshake New Session Ticket arrived:
SSL-Session:
    Protocol  : TLSv1.3
    Cipher    : TLS_AES_256_GCM_SHA384
    Session-ID: 4DF746BCAFA5326A621181E248A010486B75AC77DF590C945C96A4A0457A6DCE
    Session-ID-ctx: 
    Resumption PSK: 753DEBB0AD15D9418A1CE574A544D2BD5FC8C05AD832665D3AAD07261466F458E2F5596029EC947CA52F1CCA93988E2D
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    TLS session ticket lifetime hint: 300 (seconds)
    TLS session ticket:
    0000 - a5 e6 8d b3 14 cc 0f f5-e0 b4 3c d5 4f 4d 39 64   ..........<.OM9d
    0010 - 8c 5a 0d 2b 51 03 d0 19-69 99 3c 95 2a 63 1f 16   .Z.+Q...i.<.*c..
    Start Time: 1650071004
    Timeout   : 7200 (sec)
    Verify return code: 0 (ok)
    Extended master secret: no
    Max Early Data: 0
---
read R BLOCK
---
Post-Handshake New Session Ticket arrived:
SSL-Session:
    Protocol  : TLSv1.3
    Cipher    : TLS_AES_256_GCM_SHA384
    Session-ID: 7BCC29F8D349B3A2BF8D93A5B945BC88643B03AFCEBD7192D4A134F4302D5311
    Session-ID-ctx: 
    Resumption PSK: D342976F83E030CB17ED15BC53796AB8EF2F09CEBD6E966F8F1A0F19FE93551A176D307DF090BD95793DB5DF20891DF0
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    TLS session ticket lifetime hint: 300 (seconds)
    TLS session ticket:
    0000 - a5 e6 8d b3 14 cc 0f f5-e0 b4 3c d5 4f 4d 39 64   ..........<.OM9d
    0010 - 8d 4c 54 27 e0 72 c7 8e-fe f4 2c 6e e0 3f f7 44   .LT'.r....,n.?.D
    0020 - 7e 4f f1 99 e8 7a 3d 64-a8 75 ed c7 1f bd 58 15   ~O...z=d.u....X.
    Start Time: 1650071004
    Timeout   : 7200 (sec)
    Verify return code: 0 (ok)
    Extended master secret: no
    Max Early Data: 0
---
read R BLOCK
closed

No failure or fail in the info.

The Not secure flag is still in browser.
still

For that I get:

openssl x509 -in mylocal.pem -text -noout
unable to load certificate
139947655340480:error:0D07209B:asn1 encoding routines:ASN1_get_object:too long:../crypto/asn1/asn1_lib.c:91:
139947655340480:error:0D068066:asn1 encoding routines:asn1_check_tlen:bad object header:../crypto/asn1/tasn_dec.c:1137:
139947655340480:error:0D07803A:asn1 encoding routines:asn1_item_embed_d2i:nested asn1 error:../crypto/asn1/tasn_dec.c:309:Type=X509
139947655340480:error:0906700D:PEM routines:PEM_ASN1_read_bio:ASN1 lib:../crypto/pem/pem_oth.c:33:
2 Likes

I have pasted part of them , it no need to paste all of them to waste content.

You would rather waste time than a few lines - OK.
Best of luck to you.

1 Like

Which browser are you using?

Some have their own root stores.

Try using curl and see if it complains.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.