IO::Socket::SSL client checking server certificate

mpapec

I want to use server certificate when connecting with IO::Socket::SSL client.

What I did is to extract certificate first,

openssl s_client -showcerts -connect 127.0.0.1:443 </dev/null 2>/dev/null|openssl x509 -outform PEM >/tmp/localhost.crt

-----BEGIN CERTIFICATE-----
MIID1jCCAr6gAwIBAgICBH8wDQYJKoZIhvcNAQELBQAwgZ8xCzAJBgNVBAYTAi0t
MRIwEAYDVQQIDAlTb21lU3RhdGUxETAPBgNVBAcMCFNvbWVDaXR5MRkwFwYDVQQK
DBBTb21lT3JnYW5pemF0aW9uMR8wHQYDVQQLDBZTb21lT3JnYW5pemF0aW9uYWxV
bml0MRAwDgYDVQQDDAdiaWdnZXIyMRswGQYJKoZIhvcNAQkBFgxyb290QGJpZ2dl
cjIwHhcNMTYwODA0MDUyMTA5WhcNMTcwODA0MDUyMTA5WjCBnzELMAkGA1UEBhMC
LS0xEjAQBgNVBAgMCVNvbWVTdGF0ZTERMA8GA1UEBwwIU29tZUNpdHkxGTAXBgNV
BAoMEFNvbWVPcmdhbml6YXRpb24xHzAdBgNVBAsMFlNvbWVPcmdhbml6YXRpb25h
bFVuaXQxEDAOBgNVBAMMB2JpZ2dlcjIxGzAZBgkqhkiG9w0BCQEWDHJvb3RAYmln
Z2VyMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALSJplghG5oD5FhU
1v9IkE8z0k/7g1W29GhUXwf7IKzzjplIgpsZ+Ya/OtDbIctSYZ3gNEMyj+LdlvEW
6rCDCSTULPWwdjuSdHmUiFyeJm+QBtnMIp9I3P7zPCd+W9Cyhue911tXCHiQMg+E
ZNi2WlqnBGf/5l6VFRVMxQTEbTRiTPaH9VFnuyCKcJTk9ephZmZRgfeNmXT7BRjG
nmsYa0jG2rh2UmJGQrJhZOZYmghbq1BL66m7yCxfknsjTHGfy7PS/c+K83fPVI0p
bcBgl0VCA7d8TX6xj4BwMec7nwdi95ISVAG3jjL11+lrlcg6UGs+bd+NVpd1PbVY
XwVcWu8CAwEAAaMaMBgwCQYDVR0TBAIwADALBgNVHQ8EBAMCBeAwDQYJKoZIhvcN
AQELBQADggEBAFkWi/C8UlEqXPO0aDrn78teYzh3D0BIuhB4vawDSUuz68Clq41u
bMLIbdWZS244NFLeWAYJf4k0WDk7/nz5pxWLqlDg4LumZxNOUeSWUSbantRn6NnQ
rJrWZi6gJFgeC/34t3k+XvtmbDl5a2L213TxOtnSZJty/ZxUr3v3Z3Dp5+kfTAyR
xlD/gOlAEHgrOjwv1XofVb5pALPjzGj9gAfe/bpMEG4GORgtJzFz/teugL4yZ4Mk
sk6BhIBd1hTWJXUfvH6GPaoieug46CAkolmvc0q2nfMiU+hZOkDE1rtyqS5XMF5t
O2nma+wuMF6z/naEXFPq65sFOHI8vz+oEaQ=
-----END CERTIFICATE-----

and then connect using ssl_client.pl from examples folder,

ssl_client.pl -d10 --ca /tmp/localhost.crt localhost:443
DEBUG: .../IO/Socket/SSL.pm:2757: new ctx 17132992
DEBUG: .../IO/Socket/SSL.pm:643: socket not yet connected
DEBUG: .../IO/Socket/SSL.pm:645: socket connected
DEBUG: .../IO/Socket/SSL.pm:667: ssl handshake not started
DEBUG: .../IO/Socket/SSL.pm:700: using SNI with hostname localhost
DEBUG: .../IO/Socket/SSL.pm:735: request OCSP stapling
DEBUG: .../IO/Socket/SSL.pm:769: call Net::SSLeay::connect
DEBUG: .../IO/Socket/SSL.pm:2658: did not get stapled OCSP response
DEBUG: .../IO/Socket/SSL.pm:2611: ok=0 [0] /C=--/ST=SomeState/L=SomeCity/O=SomeOrganization/OU=SomeOrganizationalUnit/CN=bigger2/emailAddress=root@bigger2/C=--/ST=SomeState/L=SomeCity/O=SomeOrganization/OU=SomeOrganizationalUnit/CN=bigger2/emailAddress=root@bigger2
DEBUG: .../IO/Socket/SSL.pm:772: done Net::SSLeay::connect -> -1
DEBUG: .../IO/Socket/SSL.pm:775: SSL connect attempt failed

DEBUG: .../IO/Socket/SSL.pm:775: local error: SSL connect attempt failed error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
DEBUG: .../IO/Socket/SSL.pm:778: fatal SSL error: SSL connect attempt failed error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
DEBUG: ...inux/IO/Socket.pm:49: ignoring less severe local error 'IO::Socket::INET configuration failed', keep 'SSL connect attempt failed error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed'
DEBUG: .../IO/Socket/SSL.pm:2779: free ctx 17132992 open=17132992
DEBUG: .../IO/Socket/SSL.pm:2784: free ctx 17132992 callback
DEBUG: .../IO/Socket/SSL.pm:2791: OK free ctx 17132992
failed to connect to localhost:443: ,SSL connect attempt failed error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed at ./ssl_client.pl line 52.

This doesn't work as expected, so please suggest how to properly verify server using locally stored certificate.

Steffen Ullrich

While your certificate is self-signed (i.e. signed by itself) it is not a CA:

    X509v3 extensions:
        X509v3 Basic Constraints: 
            CA:FALSE

Because it is not a CA it is not allowed to be used as an issuer of a certificate and thus can in theory not even be used to sign itself.

This is at least the logic implemented in OpenSSL (and thus Net::SSLeay, IO::Socket::SSL). Other implementations like NSS seem to work with such certificates probably because they check if the server certificate itself is explicitly trusted. Such a check is different from only checking if it is signed by a trusted CA which is done by using the SSL_ca* options in IO::Socket::SSL (or -CAfile, -CApath arguments in openssl s_client).

Explicitly trusting a specific certificate no matter if it is self-signed, expired, revoked or whatever can be done in IO::Socket::SSL by using the SSL_fingerprint option.

Note that debugging IO::Socket::SSL in this case does not help a lot since the logic in this case is implemented in OpenSSL. There is some small indicator where it is going wrong:

DEBUG: ... ok=0 [0] .../CN=bigger2/emailAddress=root@bigger2 .../CN=bigger2/emailAddress=root@bigger2

This debug statement is called from the verification callback. ok=0 [0] indicates that this callback was called with ok=0 at level certificate level 0, i.e. that the built-in validation of OpenSSL did not consider this certificate as valid.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Socket.io chat server not presenting SSL certificate

From Dev

Java SSL socket -- client certificate proof

From Dev

socket [SSL: CERTIFICATE_VERIFY_FAILED] (_ssl.c:590) from Client.py to Node Server.js

From Dev

socket [SSL: CERTIFICATE_VERIFY_FAILED] (_ssl.c:590) from Client.py to Node Server.js

From Dev

2 Way SSL - Client Certificate Not Sent To Server

From Dev

Perl IO::Socket::SSL with web server hang

From Dev

SSL Socket Connection working even though client is not sending certificate?

From Dev

Python Client to nodeJS Server with Socket.IO

From Dev

socket.io no communication between server and client

From Dev

NullPointerException on Opening SSL Socket to socket-io server

From Dev

Connect to Socket.io server with standard web-socket client

From Dev

Java SSL Certificate Revocation Checking

From Dev

Securing a connection checking SSL Certificate?

From Dev

Client SSL with an Intermediate Certificate

From Dev

SSL Certificate from client

From Dev

Disable client SSL certificate

From Dev

Configure Apache to send SSL Client certificate to backend server

From Dev

Configure Apache to send SSL Client certificate to backend server

From Dev

Whats the impact of server ssl certificate expiration on client application?

From Dev

send data from server to client on server event with socket.io

From Dev

Powershell SSL Socket Client

From Dev

SSL Socket over socks proxy - Is client <---> server data encrypted?

From Dev

SSL Connection with self-signed certificate error (C# Socket connect to Java Server Socket)

From Dev

Server certificate vs Client Certificate

From Dev

Server not receiving client's socket.io message

From Dev

socket.io-client: the server responded with a status of 404 (Not Found)

From Dev

Streaming a file from server to client with socket.io-stream

From Dev

Letting socket.io client version lag behind server version

From Dev

socket IO send form data from client to server

Related Related

  1. 1

    Socket.io chat server not presenting SSL certificate

  2. 2

    Java SSL socket -- client certificate proof

  3. 3

    socket [SSL: CERTIFICATE_VERIFY_FAILED] (_ssl.c:590) from Client.py to Node Server.js

  4. 4

    socket [SSL: CERTIFICATE_VERIFY_FAILED] (_ssl.c:590) from Client.py to Node Server.js

  5. 5

    2 Way SSL - Client Certificate Not Sent To Server

  6. 6

    Perl IO::Socket::SSL with web server hang

  7. 7

    SSL Socket Connection working even though client is not sending certificate?

  8. 8

    Python Client to nodeJS Server with Socket.IO

  9. 9

    socket.io no communication between server and client

  10. 10

    NullPointerException on Opening SSL Socket to socket-io server

  11. 11

    Connect to Socket.io server with standard web-socket client

  12. 12

    Java SSL Certificate Revocation Checking

  13. 13

    Securing a connection checking SSL Certificate?

  14. 14

    Client SSL with an Intermediate Certificate

  15. 15

    SSL Certificate from client

  16. 16

    Disable client SSL certificate

  17. 17

    Configure Apache to send SSL Client certificate to backend server

  18. 18

    Configure Apache to send SSL Client certificate to backend server

  19. 19

    Whats the impact of server ssl certificate expiration on client application?

  20. 20

    send data from server to client on server event with socket.io

  21. 21

    Powershell SSL Socket Client

  22. 22

    SSL Socket over socks proxy - Is client <---> server data encrypted?

  23. 23

    SSL Connection with self-signed certificate error (C# Socket connect to Java Server Socket)

  24. 24

    Server certificate vs Client Certificate

  25. 25

    Server not receiving client's socket.io message

  26. 26

    socket.io-client: the server responded with a status of 404 (Not Found)

  27. 27

    Streaming a file from server to client with socket.io-stream

  28. 28

    Letting socket.io client version lag behind server version

  29. 29

    socket IO send form data from client to server

HotTag

Archive