Debian Codegraph @

tests/tls-rsa+ecdsa/t

raw
1 doveconf_remote() {
2 local p k="$1"
3 p="$(doveconf -c "$HOME_remote/.dovecot/config" -hx "$1")"
4 cat <"$p"
5 }
6 pkey_sha256() {
7 openssl x509 -in /dev/stdin -pubkey \
8 | openssl pkey -in /dev/stdin -pubin -outform DER \
9 | openssl dgst -sha256 | sed -rn "/^.*=\\s*/ {s///p;q}"
10 }
11 x509_sha256() {
12 openssl x509 -in /dev/stdin -noout -fingerprint -sha256 \
13 | sed -rn "/^.*=\\s*/ {s///p;q}" | tr -d : | tr "[A-Z]" "[a-z]"
14 }
15
16 PKEY_SHA256="$(doveconf_remote ssl_server/cert_file | pkey_sha256)"
17 X509_SHA256="$(doveconf_remote ssl_server/cert_file | x509_sha256)"
18 PKEY_ALT_SHA256="$(doveconf_remote ssl_server/alt_cert_file | pkey_sha256)"
19 X509_ALT_SHA256="$(doveconf_remote ssl_server/alt_cert_file | x509_sha256)"
20
21 # pinned valid fingerprints
22 cat >>"$XDG_CONFIG_HOME/interimap/config" <<-EOF
23 SSL_fingerprint = sha256\$$PKEY_SHA256 sha256\$$PKEY_ALT_SHA256
24 EOF
25
26 for ((i = 0; i < 32; i++)); do
27 u="$(shuf -n1 -e "local" "remote")"
28 sample_message | deliver -u "$u"
29 done
30 interimap_init
31 check_mailbox_status "INBOX"
32
33 interimap --debug || error
34 # which peer certificate is used is up to libssl
35 grep -Fx -e "remote: Peer certificate fingerprint: sha256\$$X509_SHA256" \
36 -e "remote: Peer certificate fingerprint: sha256\$$X509_ALT_SHA256" \
37 <"$STDERR" || error
38 grep -Fx -e "remote: Peer certificate matches pinned SPKI digest sha256\$$PKEY_SHA256" \
39 -e "remote: Peer certificate matches pinned SPKI digest sha256\$$PKEY_ALT_SHA256" \
40 <"$STDERR" || error
41
42 # force RSA
43 # XXX we also have to force TLS <=1.2 here as the TLSv1.3 ciphersuites
44 # don't specify the certificate type (nor key exchange)
45 cat >>"$XDG_CONFIG_HOME/interimap/config" <<-EOF
46 SSL_protocol_max = TLSv1.2
47 SSL_cipherlist = EECDH+AESGCM+aRSA
48 EOF
49 interimap --debug || error
50 grep -Fx "remote: Peer certificate fingerprint: sha256\$$X509_SHA256" <"$STDERR" || error
51 grep -Fx "remote: Peer certificate matches pinned SPKI digest sha256\$$PKEY_SHA256" <"$STDERR" || error
52
53 # force ECDSA
54 sed -i "s/^SSL_cipherlist\\s*=.*/SSL_cipherlist = EECDH+AESGCM+aECDSA/" -- "$XDG_CONFIG_HOME/interimap/config"
55 interimap --debug || error
56 grep -Fx "remote: Peer certificate fingerprint: sha256\$$X509_ALT_SHA256" <"$STDERR" || error
57 grep -Fx "remote: Peer certificate matches pinned SPKI digest sha256\$$PKEY_ALT_SHA256" <"$STDERR" || error
58
59 # vim: set filetype=bash :