Dev/SSL Certificate Pinning

From Kicksecure
< Dev
Jump to navigation Jump to search

Technical Design Documentation about SSL Certificate Pinning

DRAFT! UNFINISHED!

Design[edit]

Defaults Discussion[edit]

Reasons for not enabling this feature by default:

  • The feature is not yet implemented.
  • Usefulness.
  • Implementation.
    • torbrowser-launcher is not installable from Debian stable at time of writing. TODO: expand
    • Kicksecure is still installing tb-updaterarchive.org rather than torbrowser-launcherarchive.org by default because, see ticketarchive.org. So the certificate file /usr/share/torbrowser-launcher/torproject.pem is not installed by default.
    • It might be a Debian packaging bug to have whonixcheck depend on torbrowser-launcher for this purpose? Ignorable point, because whonixcheck is too specific to be included into Debian official repository anyhow.
    • We would also have to install torbrowser-launcher on Kicksecure, so the certificate file /usr/share/torbrowser-launcher/torproject.pem gets installed by default. But since by Kicksecure design, users must not use Tor Browser in Kicksecure, we would have to hide (config-package-dev displace) torbrowser-launcher's start menu entries as well as build a wrapper around its binaries to warn against this. This is doable, but no one has implemented that yet.
    • We are unaware of any other package or even project that does provide SSL certificates for direct pinning (do not confuse this with SSL CA pinning), that we could rely on. Apparently there is not even a list of certain domains and their SSL certificates (public key hashes) (do not confuse this with SSL CA pinning).
  • Maintenance burden.
    • The Tor Project (TPO) refused to maintain an OpenPGP signed certificatearchive.org. (They are excused: maintenance burden. TODO: expand)
    • Relying on torbrowser-launcherarchive.org to maintain The Tor Project's SSL certificate file /usr/share/torbrowser-launcher/torproject.pem.
      • One time the maintainer of torbrowser-launcher was busy and needed ~1 month to upgrade TPO's SSL certificate file. (referencearchive.org) He is excused, because he is a volunteer maintaining the software, under no obligations, probably earning no money with torbrowser-launcher, having other obligations. This is Freedom Software. Thank you for torbrowser-launcher!
      • The plan of the maintainer of torbrowser-launcher is to wait until the certificate breaks before upgrading it. This is already the best the maintainer can do in the absence of better support from TPO for this use case. No blame here. Everyone is excused here, also TPO, since maintaining this adds up to the maintenance burden. (referencearchive.org)
      • See also torbrowser-launcher issues search "pin"archive.org for eventual further issues with pinning.

TODO: expand

Technical[edit]

Introduction[edit]

Please don't confuse SSL CA (Certificate Authority) pinning SSL direct pinning.

See also:
https://github.com/Whonix/Whonix/issues/24

PIN Certificate Authority[edit]

Weaker method (still better than no pinning at all), more easy to maintain.

Install required software.

sudo apt install ca-certificates curl

Test, expected to work.

curl --verbose --tlsv1.3 --capath /invalid/ --cacert /usr/share/ca-certificates/mozilla/DigiCert_High_Assurance_EV_Root_CA.crt https://check.torproject.org

Test, expected to fail.

curl --verbose --tlsv1.3 --capath /invalid/ --cacert /usr/share/ca-certificates/mozilla/AddTrust_External_Root.crt https://check.torproject.org

PIN Certificate Directly[edit]

curl method[edit]

Introduction[edit]

Better method, more difficult to maintain.

Get the Certificate[edit]

Introduction[edit]

Install required software:

apt install ca-certificates curl

Download the public SSL certificate.

pem Format[edit]
Method 1[edit]

Method 1 just getting the certificate.

openssl s_client -connect torproject.org:443 >./x.cert </dev/null
Method 2[edit]

Or better method 2, getting the certificate while pinning torproject.org's certificate authority.

openssl s_client -connect torproject.org:443 -CAfile /usr/share/ca-certificates/mozilla/DigiCert_Assured_ID_Root_CA.crt >./x.cert </dev/null
Method 3[edit]

Or even better method 3, getting the certificate while pinning torproject.org's certificate authority and automatically extracting the certificate.

echo -n | openssl s_client -connect torproject.org:443 -CAfile /usr/share/ca-certificates/mozilla/DigiCert_Assured_ID_Root_CA.crt | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ./torproject.pem
der Format[edit]

Untested!

sourcearchive.org

openssl s_client -connect torproject.org:443 2>&1 < /dev/null | sed -n '/-----BEGIN/,/-----END/p' | openssl x509 -noout -pubkey | openssl rsa -pubin -outform DER > torproject.org.der

Verify the Certificate[edit]

Get SHA-256 fingerprint:

openssl x509 -noout -in torproject.pem -fingerprint -sha256

Usage[edit]

Defunct!

Optionally render the ca-certificates useless for testing purposes. Using curl here, but wget has a bugarchive.org and uses the ca-files anyway.

sudo mv /usr/share/ca-certificates /usr/share/ca-certificates_

Download with curl and the pinned certificate:

Broken!

This needs curl 7.39.0 or above, because older versions do not support --pinnedpubkey.

curl --tlsv1.3 --cacert ./torproject.pem https://check.torproject.org/ > check.html

Eventually undo.

sudo mv /usr/share/ca-certificates_ /usr/share/ca-certificates

Alternate perl method[edit]

Sourcearchive.org. Not reviewed!

#!/usr/bin/perl
# https://security.stackexchange.com/questions/20399/how-to-verify-the-ssl-fingerprint-by-command-line-wget-curl
# Code snippets taken from Net::SSLeay documentation and mildly modified.
# Requires a newer version of SSLeay (tested with 1.48)
# Needless to say, verify correct $host and $fingerprint before testing!!!

use Net::SSLeay qw(get_https3);

$host = "www.google.com";
$port = 443;
$fingerprint = "C1:95:6D:C8:A7:DF:B2:A5:A5:69:34:DA:09:77:8E:3A:11:02:33:58";

($p, $resp, $hdrs, $server_cert) = get_https3($host, $port, '/');
if (!defined($server_cert) || ($server_cert == 0)) {
    warn "Subject Name: undefined, Issuer  Name: undefined";
} elsif (Net::SSLeay::X509_get_fingerprint($server_cert, "sha1") ne $fingerprint) {
    warn 'Invalid certificate fingerprint '
        .  Net::SSLeay::X509_get_fingerprint($server_cert, "sha1")
        . ' for ' . Net::SSLeay::X509_NAME_oneline(
             Net::SSLeay::X509_get_subject_name($server_cert));
} else {
    print $p;
}

Sources[edit]

Sources:


Unfinished: This wiki is a work in progress. Please do not report broken links until this notice is removed, use Search Engines First and contribute improving this wiki.

We believe security software like Kicksecure needs to remain Open Source and independent. Would you help sustain and grow the project? Learn more about our 12 year success story and maybe DONATE!