Get certificate fingerprint of HTTPS server from command line?

孤街浪徒 提交于 2019-11-27 03:59:53

问题


Recently Mercurial has added certificate validation when connecting to HTTPS servers. I'm trying to clone the wiki repository for a googlecode project at https://wiki.pydlnadms.googlecode.com/hg/, but the certificate is for *.googlecode.com. I was under the impression that this is called a wildcard domain and valid for all subdomains, but I'm receiving the error:

matt@stanley:~/src$ hg clone https://wiki.pydlnadms.googlecode.com/hg/ pydlnadms-wiki
abort: wiki.pydlnadms.googlecode.com certificate error: certificate is for *.googlecode.com

Allegedly I need to add the certificate fingerprint to my hgrc. How do I retrieve this fingerprint from the command line?

Parent Question: Hosting images on Google Code


回答1:


The page at http://wiki.debuntu.org/wiki/OpenSSL#Retrieving_certificate_informations lists the command lines for that (and printing out the relevant information). From that page and some of the man pages, it seems like what you want is (for bash):

openssl s_client -connect <host>:<port> < /dev/null 2>/dev/null | openssl x509 -fingerprint -noout -in /dev/stdin

If you want the whole certificate, leave off the | symbol and everything after it.




回答2:


this is also enough:

openssl x509 -fingerprint -in server.crt



回答3:


This is an old thread but there is an easier way I found. Assuming you have the crt file:

$ cat server.crt|openssl x509 -fingerprint 
MD5 Fingerprint=D1:BA:B0:17:66:6D:7F:42:7B:91:1E:22:7E:3A:27:D2



回答4:


Background

Since Mercurial 3.9, Mercurial requires the more secure SHA-256 fingerprint, as opposed to SHA-1 from prior versions. Jeremiah's answer explains how to compute the SHA-1 fingerprint. As pointed out in J.Money's comment, one must now add the -sha256 flag to get the correct fingerprint.

The new command:

openssl s_client -connect <host>:<port> < /dev/null 2>/dev/null | openssl x509 -fingerprint -sha256 -noout -in /dev/stdin

where <host>:<port> should be substituted as appropriate. (To answer the original question, one would use wiki.pydlnadms.googlecode.com:443, as noted by yanokwa.) You must omit https:// from the URL, otherwise you will get the error Expecting: TRUSTED CERTIFICATE.

One can then add the resulting SHA-256 fingerprint to Mercurial's global settings file (~/.hgrc).



来源:https://stackoverflow.com/questions/5164804/get-certificate-fingerprint-of-https-server-from-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!