integrity.sh 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # $OpenBSD: integrity.sh,v 1.24 2020/01/21 08:06:27 djm Exp $
  2. # Placed in the Public Domain.
  3. tid="integrity"
  4. cp $OBJ/sshd_proxy $OBJ/sshd_proxy_bak
  5. # start at byte 2900 (i.e. after kex) and corrupt at different offsets
  6. tries=10
  7. startoffset=2900
  8. macs=$(${SSH} -Q mac)
  9. # The following are not MACs, but ciphers with integrated integrity. They are
  10. # handled specially below.
  11. macs="$macs $(${SSH} -Q cipher-auth)"
  12. # avoid DH group exchange as the extra traffic makes it harder to get the
  13. # offset into the stream right.
  14. #echo "KexAlgorithms -diffie-hellman-group*" \
  15. # >> $OBJ/ssh_proxy
  16. # sshd-command for proxy (see test-exec.sh)
  17. cmd="$SUDO env SSH_SK_HELPER="$SSH_SK_HELPER" sh ${SRC}/sshd-log-wrapper.sh ${TEST_SSHD_LOGFILE} ${SSHD} -i -f $OBJ/sshd_proxy"
  18. for m in $macs; do
  19. # the none mac is now valid but tests against it will succeed when we expect it to
  20. # fail. so we need to explicity remove it from the list of macs returned.
  21. if [ $m == "none" ]; then
  22. continue
  23. fi
  24. trace "test $tid: mac $m"
  25. elen=0
  26. epad=0
  27. emac=0
  28. etmo=0
  29. ecnt=0
  30. skip=0
  31. for off in $(jot $tries $startoffset); do
  32. skip=$(expr $skip - 1)
  33. if [ $skip -gt 0 ]; then
  34. # avoid modifying the high bytes of the length
  35. continue
  36. fi
  37. cp $OBJ/sshd_proxy_bak $OBJ/sshd_proxy
  38. # modify output from sshd at offset $off
  39. pxy="proxycommand=$cmd | $OBJ/modpipe -wm xor:$off:1"
  40. if ${SSH} -Q cipher-auth | grep "^${m}\$" > /dev/null 2>&1; then
  41. echo "Ciphers=$m" >> $OBJ/sshd_proxy
  42. macopt="-c $m"
  43. else
  44. echo "Ciphers=aes128-ctr" >> $OBJ/sshd_proxy
  45. echo "MACs=$m" >> $OBJ/sshd_proxy
  46. macopt="-m $m -c aes128-ctr"
  47. fi
  48. verbose "test $tid: $m @$off"
  49. ${SSH} $macopt -F $OBJ/ssh_proxy -o "$pxy" \
  50. -oServerAliveInterval=1 -oServerAliveCountMax=30 \
  51. 999.999.999.999 'printf "%4096s" " "' > /dev/null
  52. if [ $? -eq 0 ]; then
  53. fail "ssh -m $m succeeds with bit-flip at $off"
  54. fi
  55. ecnt=$(expr $ecnt + 1)
  56. out=$(egrep -v "^debug" $TEST_SSH_LOGFILE | tail -2 |
  57. tr -s '\r\n' '.')
  58. case "$out" in
  59. Bad?packet*)
  60. elen=$( expr $elen + 1)
  61. skip=3
  62. ;;
  63. Corrupted?MAC* | *message?authentication?code?incorrect*)
  64. emac=$(expr $emac + 1)
  65. skip=0
  66. ;;
  67. padding*)
  68. epad=$( expr $epad + 1)
  69. skip=0
  70. ;;
  71. *Timeout,?server*)
  72. etmo=$(expr $etmo + 1)
  73. skip=0
  74. ;;
  75. *) fail "unexpected error mac $m at $off: $out" ;;
  76. esac
  77. done
  78. verbose "test $tid: $ecnt errors: mac $emac padding $epad length $elen timeout $etmo"
  79. if [ $emac -eq 0 ]; then
  80. fail "$m: no mac errors"
  81. fi
  82. expect=$(expr $ecnt - $epad - $elen - $etmo)
  83. if [ $emac -ne $expect ]; then
  84. fail "$m: expected $expect mac errors, got $emac"
  85. fi
  86. done