rekey.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. # $OpenBSD: rekey.sh,v 1.18 2018/04/10 00:14:10 djm Exp $
  2. # Placed in the Public Domain.
  3. tid="rekey"
  4. LOG=${TEST_SSH_LOGFILE}
  5. rm -f ${LOG}
  6. cp $OBJ/sshd_proxy $OBJ/sshd_proxy_bak
  7. # Test rekeying based on data volume only.
  8. # Arguments will be passed to ssh.
  9. ssh_data_rekeying()
  10. {
  11. _kexopt=$1
  12. shift
  13. _opts="$@"
  14. if ! test -z "$_kexopts"; then
  15. cp $OBJ/sshd_proxy_bak $OBJ/sshd_proxy
  16. echo "$_kexopt" >> $OBJ/sshd_proxy
  17. _opts="$_opts -o$_kexopt"
  18. fi
  19. rm -f ${COPY} ${LOG}
  20. _opts="$_opts -oCompression=no"
  21. ${SSH} < ${DATA} $_opts -v -F $OBJ/ssh_proxy somehost "cat > ${COPY}"
  22. if [ $? -ne 0 ]; then
  23. fail "ssh failed ($@)"
  24. fi
  25. cmp ${DATA} ${COPY} || fail "corrupted copy ($@)"
  26. n=$(grep 'NEWKEYS sent' ${LOG} | wc -l)
  27. n=$(expr $n - 1)
  28. trace "$n rekeying(s)"
  29. if [ $n -lt 1 ]; then
  30. fail "no rekeying occurred ($@)"
  31. fi
  32. }
  33. increase_datafile_size 300
  34. opts=""
  35. for i in $(${SSH} -Q kex); do
  36. opts="$opts KexAlgorithms=$i"
  37. done
  38. for i in $(${SSH} -Q cipher); do
  39. opts="$opts Ciphers=$i"
  40. done
  41. for i in $(${SSH} -Q mac); do
  42. opts="$opts MACs=$i"
  43. done
  44. for opt in $opts; do
  45. verbose "client rekey $opt"
  46. ssh_data_rekeying "$opt" -oRekeyLimit=256k
  47. done
  48. # AEAD ciphers are magical so test with all KexAlgorithms
  49. if ${SSH} -Q cipher-auth | grep '^.*$' > /dev/null 2>&1; then
  50. for c in $(${SSH} -Q cipher-auth); do
  51. for kex in $(${SSH} -Q kex); do
  52. verbose "client rekey $c $kex"
  53. ssh_data_rekeying "KexAlgorithms=$kex" -oRekeyLimit=256k -oCiphers=$c
  54. done
  55. done
  56. fi
  57. for s in 16 1k 128k 256k; do
  58. verbose "client rekeylimit ${s}"
  59. ssh_data_rekeying "" -oCompression=no -oRekeyLimit=$s
  60. done
  61. for s in 5 10; do
  62. verbose "client rekeylimit default ${s}"
  63. rm -f ${COPY} ${LOG}
  64. ${SSH} < ${DATA} -oCompression=no -oRekeyLimit="default $s" -F \
  65. $OBJ/ssh_proxy somehost "cat >${COPY};sleep $s;sleep 3"
  66. if [ $? -ne 0 ]; then
  67. fail "ssh failed"
  68. fi
  69. cmp ${DATA} ${COPY} || fail "corrupted copy"
  70. n=$(grep 'NEWKEYS sent' ${LOG} | wc -l)
  71. n=$(expr $n - 1)
  72. trace "$n rekeying(s)"
  73. if [ $n -lt 1 ]; then
  74. fail "no rekeying occurred"
  75. fi
  76. done
  77. for s in 5 10; do
  78. verbose "client rekeylimit default ${s} no data"
  79. rm -f ${COPY} ${LOG}
  80. ${SSH} -oCompression=no -oRekeyLimit="default $s" -F \
  81. $OBJ/ssh_proxy somehost "sleep $s;sleep 3"
  82. if [ $? -ne 0 ]; then
  83. fail "ssh failed"
  84. fi
  85. n=$(grep 'NEWKEYS sent' ${LOG} | wc -l)
  86. n=$(expr $n - 1)
  87. trace "$n rekeying(s)"
  88. if [ $n -lt 1 ]; then
  89. fail "no rekeying occurred"
  90. fi
  91. done
  92. for s in 16 1k 128k 256k; do
  93. verbose "server rekeylimit ${s}"
  94. cp $OBJ/sshd_proxy_bak $OBJ/sshd_proxy
  95. echo "rekeylimit ${s}" >> $OBJ/sshd_proxy
  96. rm -f ${COPY} ${LOG}
  97. ${SSH} -oCompression=no -F $OBJ/ssh_proxy somehost "cat ${DATA}" \
  98. > ${COPY}
  99. if [ $? -ne 0 ]; then
  100. fail "ssh failed"
  101. fi
  102. cmp ${DATA} ${COPY} || fail "corrupted copy"
  103. n=$(grep 'NEWKEYS sent' ${LOG} | wc -l)
  104. n=$(expr $n - 1)
  105. trace "$n rekeying(s)"
  106. if [ $n -lt 1 ]; then
  107. fail "no rekeying occurred"
  108. fi
  109. done
  110. for s in 5 10; do
  111. verbose "server rekeylimit default ${s} no data"
  112. cp $OBJ/sshd_proxy_bak $OBJ/sshd_proxy
  113. echo "rekeylimit default ${s}" >> $OBJ/sshd_proxy
  114. rm -f ${COPY} ${LOG}
  115. ${SSH} -oCompression=no -F $OBJ/ssh_proxy somehost "sleep $s;sleep 3"
  116. if [ $? -ne 0 ]; then
  117. fail "ssh failed"
  118. fi
  119. n=$(grep 'NEWKEYS sent' ${LOG} | wc -l)
  120. n=$(expr $n - 1)
  121. trace "$n rekeying(s)"
  122. if [ $n -lt 1 ]; then
  123. fail "no rekeying occurred"
  124. fi
  125. done
  126. verbose "rekeylimit parsing"
  127. for size in 16 1k 1K 1m 1M 1g 1G 4G 8G; do
  128. for time in 1 1m 1M 1h 1H 1d 1D 1w 1W; do
  129. case $size in
  130. 16) bytes=16 ;;
  131. 1k | 1K) bytes=1024 ;;
  132. 1m | 1M) bytes=1048576 ;;
  133. 1g | 1G) bytes=1073741824 ;;
  134. 4g | 4G) bytes=4294967296 ;;
  135. 8g | 8G) bytes=8589934592 ;;
  136. esac
  137. case $time in
  138. 1) seconds=1 ;;
  139. 1m | 1M) seconds=60 ;;
  140. 1h | 1H) seconds=3600 ;;
  141. 1d | 1D) seconds=86400 ;;
  142. 1w | 1W) seconds=604800 ;;
  143. esac
  144. b=$($SUDO ${SSHD} -T -o "rekeylimit $size $time" -f $OBJ/sshd_proxy |
  145. awk '/rekeylimit/{print $2}')
  146. s=$($SUDO ${SSHD} -T -o "rekeylimit $size $time" -f $OBJ/sshd_proxy |
  147. awk '/rekeylimit/{print $3}')
  148. if [ "$bytes" != "$b" ]; then
  149. fatal "rekeylimit size: expected $bytes bytes got $b"
  150. fi
  151. if [ "$seconds" != "$s" ]; then
  152. fatal "rekeylimit time: expected $time seconds got $s"
  153. fi
  154. done
  155. done
  156. rm -f ${COPY} ${DATA}