Browse Source

Add SSL fingerprint check utility

Alois Mahdal 8 years ago
parent
commit
9d0f4144f5
1 changed files with 60 additions and 0 deletions
  1. 60
    0
      bin/ssl_fp

+ 60
- 0
bin/ssl_fp View File

@@ -0,0 +1,60 @@
1
+#!/bin/bash
2
+
3
+. "$(shellfu-get path)" || exit 3
4
+
5
+shellfu import pretty
6
+
7
+usage() {
8
+    mkusage "[-d] SERVER:PORT"
9
+}
10
+
11
+cached() {
12
+    local cache_size=$(stat -c %s "$Cache")
13
+    debug -v Cache cache_size
14
+    if test "$cache_size" -gt 0;
15
+    then
16
+        debug "using cache ($cache_size bytes)"
17
+        cat "$Cache"
18
+    else
19
+        debug "building cache"
20
+        get_cert | tee "$Cache"
21
+    fi
22
+}
23
+
24
+get_cert() {
25
+    debug heya
26
+    </dev/null openssl s_client -connect "$Conn" 2>/dev/null
27
+}
28
+
29
+get_fp() {
30
+    local fun="$1"
31
+    debug -v Conn fun
32
+    cached get_cert \
33
+      | openssl x509 -noout -"$fun" -fingerprint 2>/dev/null
34
+}
35
+
36
+get_fps() {
37
+    get_fp md5
38
+    get_fp sha1
39
+    get_fp sha256
40
+}
41
+
42
+main() {
43
+    local Conn
44
+    local Cache
45
+    local es
46
+    #shellcheck disable=SC2034
47
+    while true; do case "$1" in
48
+        *:*) Conn="$1";             shift ;;
49
+        -d)  SHELLFU_DEBUG=true;    shift ;;
50
+        "")                         break ;;
51
+        *)                          usage ;;
52
+    esac done
53
+    test -n "$Conn" || usage
54
+    Cache="$(mktemp -t ssl_fp.cache.XXXXXXXX)"
55
+    get_fps; es=$?
56
+    rm -f "$Cache"
57
+    return "$es"
58
+}
59
+
60
+main "$@"