Practical sample
Getting one certificate for playing with
Using low level openssl
commands:
mkdir /tmp/ssltests
cd $_
openssl s_client -connect www.google.com:443 -ign_eof \
<<<$'HEAD / HTTP/1.0\r\n\r' 2>/dev/null |
sed -ne '/^Server certificate/,${
/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/{
//{/END/{p;q}};p}}' >www.google.com.crt
Maybe not the simpliest way, but between man openssl
and man sed
, I've made a choice...
So you could see what's a SSL cert:
cat www.google.com.crt
-----BEGIN CERTIFICATE-----
MIIEdjCCA16gAwIBAgIIRYUpUVjSfHQwDQYJKoZIhvcNAQEFBQAwSTELMAkGA1UE
BhMC ... AVzv0
OtGjXuOdSfB4nURA7INNYvx8ULMECg5Sj8Gan8kIOfeW3jt9vdxsZrbn0Cu/bcTm
OEK3nH1sBk2Hy5ZBcyludHyUzqTHsXSjnIjwZNPpihVmFrs5I1Ma7iEj
-----END CERTIFICATE-----
sed '1d;$d' www.google.com.crt | tr -d \\n | wc -c
1528
echo $(( 1528 * 6 ))
9168
echo $(( 9168 / 8 ))
1146
There is a bunch of 9168 bits (or 1146 bytes), who contain a lot of details:
In certificate content
A x509 certificat hold a lot of informations like subject, issuer, valid dates, other signed certificates...
You could retrive specific information by:
openssl x509 -in www.google.com.crt -noout -subject
subject= /C=US/ST=California/L=Mountain View/O=Google Inc/CN=www.google.com
or
openssl x509 -in www.google.com.crt -noout -issuer
issuer= /C=US/O=Google Inc/CN=Google Internet Authority G2
or else:
openssl x509 -in www.google.com.crt -noout -text
will dump all details, including the public key, signature algorithms...
Fingerprints
They are like md5sum
for validating a file: to verify (for sample: by phone), you could use one kind of fingerprint.
Fingerprints don't contain readable informations anymore! It's only checksum!!
openssl x509 -in www.google.com.crt -noout -fingerprint
SHA1 Fingerprint=03:30:78:7E:9B:7E:11:4E:66:2E:77:ED:AC:99:71:09:F8:E5:F0:6F
openssl x509 -in www.google.com.crt -noout -md5 -fingerprint
MD5 Fingerprint=5A:4C:B2:35:C4:F2:2E:3A:72:6A:49:F6:BC:EA:5B:20
openssl x509 -in www.google.com.crt -noout -sha256 -fingerprint
SHA256 Fingerprint=E8:55:E1:CC:31:97:F3:36:92:D7:C9:3E:46:B4:47:FB:21:CD:6C:7A:93:CB:B1:AE:58:CF:21:43:DF:24:FC:42
It's ligther to spell than the whole certificate.
In fact, this is really same than using md5sum
on raw datas:
uudecode < <(
sed '1s/^.*$/begin-base64 644 www.google.com.raw/;
$s/^.*$/====/' www.google.com.crt
)
ls -ltr
total 8
-rw-r--r-- 1 user user 1606 Nov 30 13:06 www.google.com.crt
-rw-r--r-- 1 user user 1146 Nov 30 16:30 www.google.com.raw
sha1sum www.google.com.raw
0330787e9b7e114e662e77edac997109f8e5f06f www.google.com.raw
md5sum www.google.com.raw
5a4cb235c4f22e3a726a49f6bcea5b20 www.google.com.raw
There are same results.
Another try:
openssl s_client -connect security.stackexchange.com:443 -ign_eof \
<<<$'HEAD / HTTP/1.0\r\n\r' 2>/dev/null |
sed -ne '
/^Server certificate/,${
/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/{
//{/END/{p;q}};p}}' >security.stackexchange.com.crt
openssl x509 -in security.stackexchange.com.crt -noout -sha256 -fingerprint
SHA256 Fingerprint=73:D8:42:9A:38:78:4D:21:98:29:DD:58:8C:52:6F:23:18:6A:58:99:AD:69:3A:DA:97:98:49:D4:FB:5A:A0:09
openssl x509 -in security.stackexchange.com.crt |
sed '1s/^.*$/begin-base64 644 -/;$s/^.*$/====/' |
uudecode |
sha256sum |
sed 'y|abcdef|ABCDEF|;
:a;
s/^\(\([0-9A-F]\{2\}:\)*\)\([0-9A-F]\{2\}\)\([0-9A-F]\)/\1\3:\4/g;
ta'
73:D8:42:9A:38:78:4D:21:98:29:DD:58:8C:52:6F:23:18:6A:58:99:AD:69:3A:DA:97:98:49:D4:FB:5A:A0:09 -
Fingerprints are only checksums.