| 1 |
ssl_server_cert_file="$(doveconf -c "$HOME_remote/.dovecot/config" -hx ssl_server/cert_file)" |
| 2 |
PKEY_SHA256="$(openssl x509 -in "$ssl_server_cert_file" -pubkey \ |
| 3 |
| openssl pkey -in /dev/stdin -pubin -outform DER \ |
| 4 |
| openssl dgst -sha256 | sed -rn "/^.*=\\s*/ {s///p;q}")" |
| 5 |
INVALID_FPR="sha256\$deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef" |
| 6 |
INVALID_FPR2="sha256\$deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbee2" |
| 7 |
|
| 8 |
# backup config |
| 9 |
install -m0600 "$XDG_CONFIG_HOME/interimap/config" "$XDG_CONFIG_HOME/interimap/config~" |
| 10 |
with_remote_config() { |
| 11 |
install -m0600 "$XDG_CONFIG_HOME/interimap/config~" "$XDG_CONFIG_HOME/interimap/config" |
| 12 |
cat >>"$XDG_CONFIG_HOME/interimap/config" |
| 13 |
} |
| 14 |
|
| 15 |
# pinned valid fingerprint |
| 16 |
with_remote_config <<-EOF |
| 17 |
SSL_fingerprint = sha256\$$PKEY_SHA256 |
| 18 |
EOF |
| 19 |
|
| 20 |
for ((i = 0; i < 32; i++)); do |
| 21 |
u="$(shuf -n1 -e "local" "remote")" |
| 22 |
sample_message | deliver -u "$u" |
| 23 |
done |
| 24 |
interimap_init |
| 25 |
check_mailbox_status "INBOX" |
| 26 |
|
| 27 |
|
| 28 |
# with default algorithm (SHA256) |
| 29 |
with_remote_config <<-EOF |
| 30 |
SSL_fingerprint = $INVALID_FPR $PKEY_SHA256 |
| 31 |
EOF |
| 32 |
interimap --debug || error |
| 33 |
grep -Fx "remote: Peer certificate matches pinned SPKI digest sha256\$$PKEY_SHA256" <"$STDERR" || error |
| 34 |
|
| 35 |
|
| 36 |
# and now an invalid one |
| 37 |
with_remote_config <<-EOF |
| 38 |
SSL_fingerprint = $INVALID_FPR |
| 39 |
EOF |
| 40 |
! interimap --debug || error |
| 41 |
|
| 42 |
grep -Fx "remote: ERROR: Can't initiate TLS/SSL handshake" <"$STDERR" || error |
| 43 |
grep -Fx "remote: WARNING: Fingerprint doesn't match! MiTM in action?" <"$STDERR" || error |
| 44 |
grep -Fx "remote: ERROR: Can't initiate TLS/SSL handshake" <"$STDERR" || error |
| 45 |
# make sure we didn't send any credentials or started speaking IMAP |
| 46 |
! grep -E "^remote: C: .* (AUTHENTICATE|LOGIN) " <"$STDERR" || error |
| 47 |
grep -Fx "remote: IMAP traffic (bytes): recv 0 sent 0" <"$STDERR" || error |
| 48 |
|
| 49 |
# two invalid ones |
| 50 |
with_remote_config <<-EOF |
| 51 |
SSL_fingerprint = $INVALID_FPR $INVALID_FPR2 |
| 52 |
EOF |
| 53 |
! interimap --debug || error |
| 54 |
|
| 55 |
grep -Fx "remote: ERROR: Can't initiate TLS/SSL handshake" <"$STDERR" || error |
| 56 |
grep -Fx "remote: WARNING: Fingerprint doesn't match! MiTM in action?" <"$STDERR" || error |
| 57 |
grep -Fx "remote: ERROR: Can't initiate TLS/SSL handshake" <"$STDERR" || error |
| 58 |
# make sure we didn't send any credentials or started speaking IMAP |
| 59 |
! grep -E "^remote: C: .* (AUTHENTICATE|LOGIN) " <"$STDERR" || error |
| 60 |
grep -Fx "remote: IMAP traffic (bytes): recv 0 sent 0" <"$STDERR" || error |
| 61 |
|
| 62 |
|
| 63 |
# valid + invalid |
| 64 |
with_remote_config <<-EOF |
| 65 |
SSL_fingerprint = sha256\$$PKEY_SHA256 $INVALID_FPR |
| 66 |
EOF |
| 67 |
interimap --debug || error |
| 68 |
grep -Fx "remote: Peer certificate matches pinned SPKI digest sha256\$$PKEY_SHA256" <"$STDERR" || error |
| 69 |
|
| 70 |
|
| 71 |
# invalid + valid |
| 72 |
with_remote_config <<-EOF |
| 73 |
SSL_fingerprint = $INVALID_FPR sha256\$$PKEY_SHA256 |
| 74 |
EOF |
| 75 |
interimap --debug || error |
| 76 |
grep -Fx "remote: Peer certificate matches pinned SPKI digest sha256\$$PKEY_SHA256" <"$STDERR" || error |
| 77 |
|
| 78 |
# vim: set filetype=bash : |