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,285
  • 5
  • 59
  • 80
aksamit
  • 2,220
  • 7
  • 27
  • 39
  • 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
  • 57,636
  • 30
  • 143
  • 185
0

This online tool to perform extraction of all certificate chain

enter image description here

anish
  • 6,176
  • 13
  • 67
  • 124