1

I need to extract the public key (preferably in PEM format) that a site uses to identify itself with.

E.g. a function that takes a URL as an argument (https://www.example.com/), then establish a connection to that site and fetches the certificate.

Any ideas about how it could be solved with PHP code?

Marcel Korpel
  • 21,536
  • 6
  • 60
  • 80
aksamit
  • 2,325
  • 8
  • 28
  • 40
  • 2
    possible duplicate of [How to get SSL certificate info with CURL in PHP?](http://stackoverflow.com/questions/3081042/how-to-get-ssl-certificate-info-with-curl-in-php) – wimvds May 25 '11 at 13:01

2 Answers2

1

You could use openssl to extract the certificate.

openssl s_client -connect google.com:443 > file.txt

You will find the certificate in file.txt between -----BEGIN CERTIFICATE----- and -----END CERTIFICATE-----, and you can extract it from there. I don't see a way to use the PHP OpenSSL module to do this from within PHP though, unfortunately.

rid
  • 61,078
  • 31
  • 152
  • 193
0

This online tool to perform extraction of all certificate chain

enter image description here

anish
  • 6,884
  • 13
  • 74
  • 140