Using a command line website downloader, such as wget
, curl
or any other one... In a script...
I have the SHA-1 and the SHA-256 certficate fingerprint of a website. Due to security concerns (1) (2), I don't want to use the public SSL certificate authority system. The fingerprint must be hard coded.
Can a wget like application check the SSL fingerprint?
wget does not have such a functionality. (3)
Using wget --ca-certificate
or curl --cacert
I would have to run my own local certificate authority, which I'd like to prevent, because that adds a lot complexity. It's also ultra difficult and no one did that ever before. (4)
Isn't there any tool, like
download --tlsv1 --serial-number xx:yy:zz --fingerprint xxyyzz https://site.com
?
The solution must of course not be vulnerable to TOCTOU. (5) The MITM could let return a valid fingerprint for the openssl client request and tamper with the following wget request.
Source
Install required software:
Download the public SSL certificate:
Or better:
Get SHA-1 fingerprint:
Get SHA-256 fingerprint:
Manually compare SHA-1 and SHA-256 fingerprints with torproject.org FAQ: SSL.
Optionally render the ca-certificates useless for testing purposes. Using curl here, but wget has a bug Bug and uses the ca-files anyway.
Download with curl and the pinned certificate:
In tcsh:
This is also enough:
This is fairly easy to do with the
openssl
command and its client functionality.The following little script will take a given domain (no https prefix) and an SHA-1 fingerprint, and exit with no error (0) if the retrieved fingerprint matches, but with exit code 1 if there is no match. You can then incorporate it into your script by simply testing the last exit code
$?
:source
As is outlined in the Net::SSLeay documentation, this method means verification after the HTTP transaction, and so should not be used if you want to verify you're talking to the right server before sending them data. But if all you're doing is deciding whether or not to trust what you just downloaded (which is sounds like you are from your reference #4) this is fine.
That's my everyday script:
Ouput: