ppp-over-tls 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #!/bin/sh
  2. #
  3. # Copyright © 2020 Daniel Lenski
  4. #
  5. # This file is part of openconnect.
  6. #
  7. # This is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU Lesser General Public License
  9. # as published by the Free Software Foundation; either version 2.1 of
  10. # the License, or (at your option) any later version.
  11. #
  12. # This library is distributed in the hope that it will be useful, but
  13. # WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. # Lesser General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>
  19. srcdir=${srcdir:-.}
  20. top_builddir=${top_builddir:-..}
  21. . `dirname $0`/common.sh
  22. FINGERPRINT="--servercert=d66b507ae074d03b02eafca40d35f87dd81049d3"
  23. CERT=$certdir/server-cert.pem
  24. KEY=$certdir/server-key.pem
  25. # pppd is very poorly designed for mocking and testing in isolation, and running as non-root.
  26. # See launch_simple_pppd() in common.sh for a number of caveats about using it for these
  27. # purposes.
  28. IPV4_NO="noip"
  29. IPV4_YES="'169.254.1.1:169.254.128.128'" # needs single-quotes to escape for socat
  30. IPV6_NO="noipv6"
  31. IPV6_YES="+ipv6"
  32. OFFER_DNS="ms-dns 1.1.1.1 ms-dns 8.8.8.8"
  33. NO_HDR_COMP="nopcomp noaccomp"
  34. NO_JUNK_COMP="novj noccp"
  35. HDLC_YES=""
  36. HDLC_NO="sync"
  37. IPV4_SUCCESS_1="rcvd [IPCP ConfAck "
  38. IPV4_SUCCESS_2="sent [IPCP ConfAck "
  39. IPV6_SUCCESS_1="rcvd [IPV6CP ConfAck "
  40. IPV6_SUCCESS_2="sent [IPV6CP ConfAck "
  41. TIMEOUT_3S_IDLE="idle 3"
  42. echo "Testing PPP with 'HDLC-like framing' (RFC1662)..."
  43. echo -n "Starting PPP peer (HDLC/RFC1662, IPv4+IPv6, DNS, extraneous VJ and CCP)... "
  44. start=$(date +%s)
  45. launch_simple_pppd $CERT $KEY $HDLC_YES $IPV4_YES $OFFER_DNS $IPV6_YES 2>&1
  46. echo "started in $(( $(date +%s) - start )) seconds"
  47. wait_server "$PID"
  48. echo -n "Connecting to it with openconnect --protocol=nullppp... "
  49. start=$(date +%s)
  50. LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q --protocol=nullppp $ADDRESS:443 -u test $FINGERPRINT --cookie "hdlc,term" -Ss '' >/dev/null 2>&1
  51. took=$(( $(date +%s) - start ))
  52. if grep -qF "$IPV4_SUCCESS_1" $LOGFILE && grep -qF "$IPV4_SUCCESS_2" $LOGFILE && grep -qF "$IPV6_SUCCESS_1" $LOGFILE && grep -qF "$IPV6_SUCCESS_2" $LOGFILE; then
  53. echo "ok (took $took seconds)"
  54. else
  55. echo "failed (after $took seconds)"
  56. echo "Log from pppd"; echo "===== START pppd log ====="
  57. cat $LOGFILE
  58. echo "===== END pppd log ====="
  59. fail "$PID" "Did not negotiate IPCP and IP6CP successfully."
  60. fi
  61. cleanup
  62. echo -n "Starting PPP peer (HDLC/RFC1662, IPv4+IPv6, DNS, extraneous VJ and CCP, no header compression)... "
  63. start=$(date +%s)
  64. launch_simple_pppd $CERT $KEY $HDLC_YES $IPV4_YES $OFFER_DNS $IPV6_YES $NO_HDR_COMP 2>&1
  65. echo "started in $(( $(date +%s) - start )) seconds"
  66. wait_server "$PID"
  67. echo -n "Connecting to it with openconnect --protocol=nullppp... "
  68. start=$(date +%s)
  69. LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q --protocol=nullppp $ADDRESS:443 -u test $FINGERPRINT --cookie "hdlc,term" -Ss '' >/dev/null 2>&1
  70. took=$(( $(date +%s) - start ))
  71. if grep -qF "$IPV4_SUCCESS_1" $LOGFILE && grep -qF "$IPV4_SUCCESS_2" $LOGFILE && grep -qF "$IPV6_SUCCESS_1" $LOGFILE && grep -qF "$IPV6_SUCCESS_2" $LOGFILE; then
  72. echo "ok (took $took seconds)"
  73. else
  74. echo "failed (after $took seconds)"
  75. echo "Log from pppd"; echo "===== START pppd log ====="
  76. cat $LOGFILE
  77. echo "===== END pppd log ====="
  78. fail "$PID" "Did not negotiate IPCP and IP6CP successfully."
  79. fi
  80. cleanup
  81. echo -n "Starting PPP peer (HDLC/RFC1662, IPv4 only)... "
  82. start=$(date +%s)
  83. launch_simple_pppd $CERT $KEY $HDLC_YES $NO_JUNK_COMP $IPV4_YES $IPV6_NO 2>&1
  84. echo "started in $(( $(date +%s) - start )) seconds"
  85. wait_server "$PID"
  86. echo -n "Connecting to it with openconnect --protocol=nullppp... "
  87. start=$(date +%s)
  88. LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q --protocol=nullppp $ADDRESS:443 -u test $FINGERPRINT --cookie "hdlc,term" -Ss '' >/dev/null 2>&1
  89. took=$(( $(date +%s) - start ))
  90. if grep -qF "$IPV4_SUCCESS_1" $LOGFILE && grep -qF "$IPV4_SUCCESS_2" $LOGFILE; then
  91. echo "ok (took $took seconds)"
  92. else
  93. echo "failed (after $took seconds)"
  94. echo "Log from pppd"; echo "===== START pppd log ====="
  95. cat $LOGFILE
  96. echo "===== END pppd log ====="
  97. fail "$PID" "Did not negotiate IPCP successfully."
  98. fi
  99. cleanup
  100. echo -n "Starting PPP peer (HDLC/RFC1662, IPv6 only, 3s idle timeout)... "
  101. start=$(date +%s)
  102. launch_simple_pppd $CERT $KEY $HDLC_YES $NO_JUNK_COMP $IPV4_NO $IPV6_YES $TIMEOUT_3S_IDLE 2>&1
  103. echo "started in $(( $(date +%s) - start )) seconds"
  104. wait_server "$PID"
  105. echo -n "Connecting to it with openconnect --protocol=nullppp... "
  106. start=$(date +%s)
  107. LD_PRELOAD=libsocket_wrapper.so $OPENCONNECT -q --protocol=nullppp $ADDRESS:443 -u test $FINGERPRINT --cookie "hdlc" -Ss '' >/dev/null 2>&1
  108. took=$(( $(date +%s) - start ))
  109. if grep -qF "$IPV6_SUCCESS_1" $LOGFILE && grep -qF "$IPV6_SUCCESS_2" $LOGFILE; then
  110. echo "ok (took $took seconds)"
  111. else
  112. echo "failed (after $took seconds)"
  113. echo "Log from pppd"; echo "===== START pppd log ====="
  114. cat $LOGFILE
  115. echo "===== END pppd log ====="
  116. fail "$PID" "Did not negotiate IP6CP successfully."
  117. fi
  118. cleanup
  119. exit 0