language
stringlengths
0
24
filename
stringlengths
9
214
code
stringlengths
99
9.93M
Shell Script
aircrack-ng/test/test-aircrack-ng-0018.sh
#!/bin/sh set -ef "${abs_builddir}/../aircrack-ng${EXEEXT}" \ ${AIRCRACK_NG_ARGS} \ -I 'c2ea9449c142e84a0479041702526532*0012bf77162d*0021e924a5e7*574c414e2d373731363938' \ -w "${abs_srcdir}/password-3.lst" \ -l /dev/null | \ ${GREP} "KEY FOUND" | ${GREP} "SP-91862D361" exit 0
Shell Script
aircrack-ng/test/test-aircrack-ng-0019.sh
#!/bin/sh set -ef "${abs_builddir}/../aircrack-ng${EXEEXT}" \ ${AIRCRACK_NG_ARGS} \ -w "${abs_srcdir}/pass.txt" \ "${abs_srcdir}/MOM1.cap" | \ ${GREP} 'KEY FOUND! \[ MOM12345 \]' exit 0
Shell Script
aircrack-ng/test/test-aircrack-ng-0020.sh
#!/bin/sh # -*- tcl -*- # The next line is executed by /bin/sh, but not expect \ exec ${EXPECT:=expect} "$0" ${1+"$@"} set abs_builddir $::env(abs_builddir) set abs_srcdir $::env(abs_srcdir) exit -onexit { exp_internal 1 exec rm -f pipe.cap } puts -nonewline "Aircrack-ng will tail PCAP files: " flush stdout log_user 0 exec cp ${abs_srcdir}/wep_64_ptw_01.cap pipe.cap spawn ${abs_builddir}/../aircrack-ng -X pipe.cap set tool_spawn_id $spawn_id set timeout 900 # wait for startup expect "Opening pipe.cap" expect "got 2551 IVs" expect "Failed. Next try with 5000 IVs." exec cat ${abs_srcdir}/wep_64_ptw_02.cap >> pipe.cap expect "Failed. Next try with 10000 IVs." { sleep 2 } exec cat ${abs_srcdir}/wep_64_ptw_03.cap >> pipe.cap exec cat ${abs_srcdir}/wep_64_ptw_04.cap >> pipe.cap expect "got 10180 IVs" expect { "Failed. Next try with 15000 IVs." { puts "OK\n"; exit 0 } eof { puts "FAILED"; exit 1 } timeout { puts "FAILED(timeout)"; exit 2 } } puts "FAILED(exceptional)" exit 99
Shell Script
aircrack-ng/test/test-aircrack-ng-0021.sh
#!/bin/sh set -ef "${abs_builddir}/../aircrack-ng${EXEEXT}" \ -w "${abs_srcdir}/password.lst" \ "${abs_srcdir}/wpa2.eapol.cap" \ -a 2 \ -N $(mktemp -u) \ -e Harkonen \ -q | \ ${GREP} 'KEY FOUND! \[ 12345678 \]' exit 0
Shell Script
aircrack-ng/test/test-aircrack-ng-0022.sh
#!/bin/sh set -ef "${abs_builddir}/../aircrack-ng${EXEEXT}" \ ${AIRCRACK_NG_ARGS} \ -w "${abs_srcdir}/password.lst" \ -a 2 \ -e WLAN-2 \ -q "${abs_srcdir}/test23.pcap" | \ ${GREP} 'KEY FOUND! \[ 12345678 \]' exit 0
Shell Script
aircrack-ng/test/test-aircrack-ng-0023.sh
#!/bin/sh set -ef "${abs_builddir}/../aircrack-ng${EXEEXT}" \ ${AIRCRACK_NG_ARGS} \ -w "${abs_srcdir}/password.lst" \ -a 2 \ -e WLAN-2 \ -q "${abs_srcdir}/testm1m2m3.pcap" | \ ${GREP} 'KEY FOUND! \[ 12345678 \]' exit 0
Shell Script
aircrack-ng/test/test-aircrack-ng-0024.sh
#!/bin/sh set -ef "${abs_builddir}/../aircrack-ng${EXEEXT}" \ ${AIRCRACK_NG_ARGS} \ -w "${abs_srcdir}/password.lst" \ "${abs_srcdir}/pmkid-not-recognized.cap" 2>&1 | \ ${GREP} -F "8C:DE:F9:D0:B4:61" | \ ${GREP} -vF "PMKID" # Do NOT want to see a Enterprise PMKID here exit 0
Shell Script
aircrack-ng/test/test-airdecap-ng-0001.sh
#!/bin/sh set -ef "${abs_builddir}/../airdecap-ng${EXEEXT}" \ -e linksys \ -p dictionary \ "${abs_srcdir}/wpa2-psk-linksys.cap" \ -o /dev/null \ -c /dev/null | \ ${GREP} "decrypted WPA" | \ ${GREP} 25 exit 0
Shell Script
aircrack-ng/test/test-airdecap-ng-0002.sh
#!/bin/sh set -ef "${abs_builddir}/../airdecap-ng${EXEEXT}" \ -e linksys \ -p dictionary \ "${abs_srcdir}/wpa-psk-linksys.cap" \ -o /dev/null \ -c /dev/null | \ ${GREP} "decrypted WPA" | \ ${GREP} 53 exit 0
Shell Script
aircrack-ng/test/test-airdecap-ng-0003.sh
#!/bin/sh set -ef "${abs_builddir}/../airdecap-ng${EXEEXT}" \ -e test \ -p biscotte \ "${abs_srcdir}/wpa.cap" \ -o /dev/null \ -c /dev/null | \ ${GREP} "decrypted WPA" | \ ${GREP} 2 exit 0
Shell Script
aircrack-ng/test/test-airdecap-ng-0005.sh
#!/bin/sh MD5_BIN="md5sum" TMP_DEC=$(mktemp -u) TMP_MD5=$(mktemp -u) if type "md5" > /dev/null 2>/dev/null ; then MD5_BIN="md5 -q" fi airdecap_output=$("${abs_builddir}/../airdecap-ng${EXEEXT}" \ "${abs_srcdir}/capture_wds-01.cap" \ -e test1 \ -p 12345678 \ -b 00:11:22:00:00:00 \ -o ${TMP_DEC}) # shellcheck disable=SC2181 if [ $? != 0 ]; then echo "$airdecap_output" exit 1 else echo "$airdecap_output" | \ grep -E '(Total|Number) ' | \ cut -b 40- | \ tr -d ' ' | \ ${MD5_BIN} | \ cut -b 1-32 > "${TMP_MD5}" fi if [ "$(cat ${TMP_MD5})" != '45a93bc091a3929a7d63f86ddbb81401' ]; then #rm ${TMP_MD5} ${TMP_DEC} echo "Unexpected airdecap-ng output:" echo "$airdecap_output" echo "Decrypted file: ${TMP_DEC}" exit 1 fi rm ${TMP_MD5} if [ "$(${MD5_BIN} ${TMP_DEC} | cut -b 1-32)" != '340b5bc23bec76e88f6a2df0cd2eeb33' ]; then echo "Unexpected decrypted file: ${TMP_DEC}" exit 1 fi rm ${TMP_DEC} exit 0
Shell Script
aircrack-ng/test/test-airdecap-ng-0006.sh
#!/bin/sh # BSSID changing TMP_OUTPUT=$(mktemp -u) "${abs_builddir}/../airdecap-ng${EXEEXT}" \ "${abs_srcdir}/zn2i.pcap" \ -e dlink \ -p 12345678 \ -o /dev/null > ${TMP_OUTPUT} if [ "$(grep 'Number of decrypted WPA' ${TMP_OUTPUT} | awk '{print $6}')" != '1' ]; then echo "Failed decrypting" exit 1 fi exit 0
Shell Script
aircrack-ng/test/test-airdecap-ng.sh
#! /bin/sh # # Carlos Alberto Lopez Perez <clopez@igalia.com> # Thomas d'Otreppe <tdotreppe@aircrack-ng.org> - Support for sha1 and sh TESTDIR="$(dirname $0)" if [ "$(uname -s)" = 'OpenBSD' ]; then tmpdir="$(mktemp -d -t acng.XXXXXX)" else if test -f /etc/alpine-release; then tmpdir="$(mktemp -d -t acng.XXXXXX)" else tmpdir="$(mktemp -d -t acng.XXXX)" fi fi compute_sha1() { if type "sha1sum" > /dev/null 2>/dev/null ; then sha1sum "${1}" | ${AWK} '{print $1}' elif type "shasum" > /dev/null 2>/dev/null ; then shasum "${1}" | ${AWK} '{print $1}' elif type "sha1" > /dev/null 2>/dev/null ; then sha1 -q "${1}" else echo "Unable to find something to compute sha1" 1>&2 exit 1 fi } # Clean on exit if [ "$(uname -s)" = 'OpenBSD' ]; then trap "rm -rf "${tmpdir}"" EXIT else trap "rm -fr "${tmpdir}"" INT QUIT SEGV PIPE ALRM TERM EXIT fi # Test1 cp -f "${TESTDIR}/wpa.cap" "${tmpdir}" "${abs_builddir}/../airdecap-ng${EXEEXT}" -e test -p biscotte "${tmpdir}/wpa.cap" | \ ${GREP} "Number of decrypted WPA packets 2" || exit 1 [ $? -ne 0 ] && exit 1 result=$(compute_sha1 "${tmpdir}/wpa-dec.cap") if [ "${result}" != "69f8557cf96a26060989e88adfb521a01fc9b122" ] && [ "${result}" != "fb1592b2c0dccef542c1f46297394ee2892f8ed3" ]; then exit 1 fi # Test 2 cp -f "${TESTDIR}/wpa-psk-linksys.cap" "${tmpdir}" "${abs_builddir}/../airdecap-ng${EXEEXT}" -e linksys -p dictionary "${tmpdir}/wpa-psk-linksys.cap" | \ ${GREP} "Number of decrypted WPA packets 53" [ $? -ne 0 ] && exit 1 result=$(compute_sha1 "${tmpdir}/wpa-psk-linksys-dec.cap") if [ "${result}" != "1e75a9af0d9703c4ae4fc8ea454326aeb4abecc1" ] && [ "${result}" != "1c3c4123ba6718bd3db66de251a125ed65cd6ee6" ]; then exit 1 fi # Test 3 cp -f "${TESTDIR}/wpa2-psk-linksys.cap" "${tmpdir}" "${abs_builddir}/../airdecap-ng${EXEEXT}" -e linksys -p dictionary "${tmpdir}/wpa2-psk-linksys.cap" | \ ${GREP} "Number of decrypted WPA packets 25" [ $? -ne 0 ] && exit 1 result=$(compute_sha1 "${tmpdir}/wpa2-psk-linksys-dec.cap") if [ "${result}" != "2da107b96fbe19d926020ffb0da72553b18a5775" ] && [ "${result}" != "dc7d033b9759838d57b74db04185c3586cbd8042" ]; then exit 1 fi exit 0
Shell Script
aircrack-ng/test/test-aireplay-ng-0001.sh
#!/bin/sh # Aireplay-ng fakeauth against hostapd if test ! -z "${CI}"; then exit 77; fi # Load helper functions . "${abs_builddir}/../test/int-test-common.sh" # Check root check_root # Check all required tools are installed check_airmon_ng_deps_present is_tool_present hostapd # Check for interfering processes airmon_ng_check # Cleanup finish() { cleanup [ -n "${OUTPUT_TEMP}" ] && rm -f ${OUTPUT_TEMP} } trap finish INT QUIT SEGV PIPE ALRM TERM EXIT # Load mac80211_hwsim load_module 2 # Check there are two radios check_radios_present 2 # Get interfaces names get_hwsim_interface_name 1 WI_IFACE=${IFACE} get_hwsim_interface_name 2 WI_IFACE2=${IFACE} # Prepare HostAPd configuration SSID=thisrocks CHANNEL=1 cat >> ${TEMP_HOSTAPD_CONF_FILE} << EOF # Aireplay-ng test 1 driver=nl80211 interface=${WI_IFACE} channel=${CHANNEL} hw_mode=g ssid=${SSID} # Aireplay-ng test 1 EOF # Start HostAPd run_hostapd ${TEMP_HOSTAPD_CONF_FILE} [ $? -eq 0 ] && exit 1 # Put other interface in monitor mode set_monitor_mode ${WI_IFACE2} [ $? -eq 1 ] && exit 1 set_interface_channel ${WI_IFACE2} ${CHANNEL} [ $? -eq 1 ] && exit 1 # Run actual test OUTPUT_TEMP=$(mktemp) "${abs_builddir}/../aireplay-ng${EXEEXT}" \ -1 1 \ -e "${SSID}" \ -T 1 \ ${WI_IFACE2} \ 2>&1 >${OUTPUT_TEMP} # Check if association is successful RET=0 [ -z "$(${GREP} 'Association successful' ${OUTPUT_TEMP})" ] && RET=1 && cat ${OUTPUT_TEMP} exit ${RET}
Shell Script
aircrack-ng/test/test-aireplay-ng-0002.sh
#!/bin/sh # Aireplay-ng: broadcast deauth if test ! -z "${CI}"; then exit 77; fi # Load helper functions . "${abs_builddir}/../test/int-test-common.sh" # Check root check_root # Check all required tools are installed check_airmon_ng_deps_present is_tool_present tcpdump # Check for interfering processes airmon_ng_check trap cleanup INT QUIT SEGV PIPE ALRM TERM EXIT # Load mac80211_hwsim load_module 1 # Check there are two radios check_radios_present 1 # Get interfaces names get_hwsim_interface_name 1 WI_IFACE=${IFACE} # Put other interface in monitor mode set_monitor_mode ${WI_IFACE} [ $? -eq 1 ] && exit 1 set_interface_channel ${WI_IFACE} 1 [ $? -eq 1 ] && exit 1 # Check it is in monitor mode [ -z "$(iw dev ${WI_IFACE} info | ${GREP} 'type monitor')" ] && exit 1 # Start tcpdump capture in the background TCPDUMP_IFACE=${WI_IFACE} run_tcpdump # Next test is directed AP_MAC="00:11:22:33:44:55" "${abs_builddir}/../aireplay-ng${EXEEXT}" \ -0 1 \ -a ${AP_MAC} \ -D \ ${WI_IFACE} \ 2>&1 >/dev/null # Wait a second sleep 2 # Kill tcpdump kill_tcpdump # Count packets AMOUNT_PACKETS=$(tcpdump -r ${TEMP_TCPDUMP_PCAP} 2>/dev/null | ${GREP} "DeAuthentication (${AP_MAC}" | wc -l) # There should be exactly 256 deauth [ ${AMOUNT_PACKETS} -eq 256 ] && exit 0 echo "Invalid amount of deauth (${AMOUNT_PACKETS}), expected 256" exit 1
Shell Script
aircrack-ng/test/test-aireplay-ng-0003.sh
#!/bin/sh # Aireplay-ng: directed deauth if test ! -z "${CI}"; then exit 77; fi # Load helper functions . "${abs_builddir}/../test/int-test-common.sh" # Check root check_root # Check all required tools are installed check_airmon_ng_deps_present is_tool_present tcpdump # Check for interfering processes airmon_ng_check trap cleanup INT QUIT SEGV PIPE ALRM TERM EXIT # Load mac80211_hwsim load_module 1 # Check there are two radios check_radios_present 1 # Get interface name get_hwsim_interface_name 1 WI_IFACE=${IFACE} # Put interface in monitor so tcpdump captures in the correct mode set_monitor_mode ${WI_IFACE} [ $? -eq 1 ] && exit 1 # Start tcpdump capture in the background TCPDUMP_IFACE=${WI_IFACE} run_tcpdump # Next test is directed AP_MAC="00:11:22:33:44:55" CLIENT_MAC="00:13:37:00:11:22" "${abs_builddir}/../aireplay-ng${EXEEXT}" \ -0 1 \ -a ${AP_MAC} \ -c ${CLIENT_MAC} \ -D \ ${WI_IFACE} \ 2>&1 >/dev/null # Wait a second sleep 2 # Kill tcpdump kill_tcpdump # Count packets AMOUNT_PACKETS_AP=$(tcpdump -r ${TEMP_TCPDUMP_PCAP} 2>/dev/null | ${GREP} "DeAuthentication (${AP_MAC}" | wc -l) AMOUNT_PACKETS_CLIENT=$(tcpdump -r ${TEMP_TCPDUMP_PCAP} 2>/dev/null | ${GREP} "DeAuthentication (${CLIENT_MAC}" | wc -l) # There should be exactly 256 deauth total RET=0 if [ ${AMOUNT_PACKETS_CLIENT} -ne 128 ]; then RET=1 echo "Expected 128 deauth frames from the client, got ${AMOUNT_PACKETS_CLIENT}" fi if [ ${AMOUNT_PACKETS_AP} -ne 128 ]; then RET=1 echo "Expected 128 deauth frames from the AP, got ${AMOUNT_PACKETS_AP}" fi exit ${RET}
Shell Script
aircrack-ng/test/test-aireplay-ng-0004.sh
#!/bin/sh # Aireplay-ng: injection test if test ! -z "${CI}"; then exit 77; fi # Load helper functions . "${abs_builddir}/../test/int-test-common.sh" # Check root check_root # Check all required tools are installed check_airmon_ng_deps_present is_tool_present hostapd # Check for interfering processes airmon_ng_check # Cleanup finish() { [ -n "${OUTPUT_TEMP}" ] && rm -rf ${OUTPUT_TEMP} cleanup } trap finish INT QUIT SEGV PIPE ALRM TERM EXIT # Load mac80211_hwsim load_module 2 # Check there are two radios check_radios_present 2 # Get interfaces names get_hwsim_interface_name 1 WI_IFACE=${IFACE} get_hwsim_interface_name 2 WI_IFACE2=${IFACE} # Set-up hostapd SSID=thisrocks CHANNEL=1 cat <<EOF > ${TEMP_HOSTAPD_CONF_FILE} driver=nl80211 interface=${WI_IFACE} channel=${CHANNEL} hw_mode=g ssid=${SSID} # Aireplay-ng test 4 EOF # Start HostAPd run_hostapd ${TEMP_HOSTAPD_CONF_FILE} [ $? -eq 0 ] && exit 1 # Put other interface in monitor mode set_monitor_mode ${WI_IFACE2} [ $? -eq 1 ] && exit 1 set_interface_channel ${WI_IFACE2} ${CHANNEL} [ $? -eq 1 ] && exit 1 # Run actual test OUTPUT_TEMP=$(mktemp) "${abs_builddir}/../aireplay-ng${EXEEXT}" \ -9 \ ${WI_IFACE2} \ 2>&1 > ${OUTPUT_TEMP} if [ -z "$(${GREP} 'Injection is working!' ${OUTPUT_TEMP})" ]; then echo "Injection is not working" exit 1 fi if [ -n "$(${GREP} '/30' ${OUTPUT_TEMP})" ]; then if [ -z "$(${GREP} '30/30' ${OUTPUT_TEMP})" ]; then echo "AP not present or failure injecting" exit 1 fi else echo "Some failure while injecting: $(${GREP} '/30' ${OUTPUT_TEMP})" exit 1 fi exit 0
Shell Script
aircrack-ng/test/test-aireplay-ng-0005.sh
#!/bin/sh # Aireplay-ng: Injection test with bitrate if test ! -z "${CI}"; then exit 77; fi # Load helper functions . "${abs_builddir}/../test/int-test-common.sh" # Check root check_root # Check all required tools are installed check_airmon_ng_deps_present is_tool_present hostapd # Check for interfering processes airmon_ng_check # Cleanup finish() { [ -n "${OUTPUT_TEMP}" ] && rm -f ${OUTPUT_TEMP} cleanup } trap finish INT QUIT SEGV PIPE ALRM TERM EXIT # Load mac80211_hwsim load_module 2 # Check there are two radios check_radios_present 2 # Get interfaces names get_hwsim_interface_name 1 WI_IFACE=${IFACE} get_hwsim_interface_name 2 WI_IFACE2=${IFACE} # Set-up hostapd SSID=thisrocks CHANNEL=1 TEMP_HOSTAPD_CONF_FILE=$(mktemp) cat <<EOF > ${TEMP_HOSTAPD_CONF_FILE} driver=nl80211 interface=${WI_IFACE} channel=${CHANNEL} hw_mode=g ssid=${SSID} # Aireplay-ng test 5 EOF # Start HostAPd run_hostapd ${TEMP_HOSTAPD_CONF_FILE} [ $? -eq 0 ] && exit 1 # Put other interface in monitor mode set_monitor_mode ${WI_IFACE2} [ $? -eq 1 ] && exit 1 set_interface_channel ${WI_IFACE2} ${CHANNEL} [ $? -eq 1 ] && exit 1 # Run actual test OUTPUT_TEMP=$(mktemp) "${abs_builddir}/../aireplay-ng${EXEEXT}" \ -9 \ -B \ ${WI_IFACE2} \ 2>&1 > ${OUTPUT_TEMP} # Then checks if [ -z "$(${GREP} 'Injection is working!' ${OUTPUT_TEMP})" ]; then echo "Injection is not working" exit 1 fi if [ -z "$(${GREP} '30/30' ${OUTPUT_TEMP})" ]; then echo "AP not present or failure injecting" exit 1 fi if [ -z "$(${GREP} 'Probing at 54.0 Mbps: 30/30: 100%' ${OUTPUT_TEMP})" ]; then echo "Failed bitrate test" exit 1 fi exit 0
Shell Script
aircrack-ng/test/test-aireplay-ng-0006.sh
#!/bin/sh # Aireplay-ng: deauth test with reason code if test ! -z "${CI}"; then exit 77; fi # Load helper functions . "${abs_builddir}/../test/int-test-common.sh" # Check root check_root # Check all required tools are installed check_airmon_ng_deps_present is_tool_present tcpdump # Check for interfering processes airmon_ng_check trap cleanup INT QUIT SEGV PIPE ALRM TERM EXIT # Load mac80211_hwsim load_module 1 # Check there are two radios check_radios_present 1 # Get interfaces names get_hwsim_interface_name 1 WI_IFACE=${IFACE} # Put interface in monitor so tcpdump captures in the correct mode set_monitor_mode ${WI_IFACE} [ $? -eq 1 ] && exit 1 # Start tcpdump capture in the background TCPDUMP_IFACE=${WI_IFACE} run_tcpdump # Next test is directed AP_MAC="00:11:22:33:44:55" "${abs_builddir}/../aireplay-ng${EXEEXT}" \ -0 1 \ -a ${AP_MAC} \ -D \ --deauth-rc 10 \ ${WI_IFACE} \ 2>&1 >/dev/null # Wait a second sleep 2 # Kill tcpdump kill_tcpdump # There should be exactly 256 deauth AMOUNT_PACKETS=$(tcpdump -r ${TEMP_TCPDUMP_PCAP} 2>/dev/null | ${GREP} "DeAuthentication (${AP_MAC}" | ${GREP} 'Disassociated because the information in the Power Capability element is unacceptable' | wc -l) [ ${AMOUNT_PACKETS} -eq 256 ] && exit 0 echo "Expected 256 deauth frames, got ${AMOUNT_PACKETS}" exit 1
Shell Script
aircrack-ng/test/test-aireplay-ng-0007.sh
#!/bin/sh # Aireplay-ng/Airodump-ng: Fake auth on shared WEP key if test ! -z "${CI}"; then exit 77; fi # Load helper functions . "${abs_builddir}/../test/int-test-common.sh" # Check root check_root # Check all required tools are installed check_airmon_ng_deps_present is_tool_present screen is_tool_present hostapd is_tool_present wpa_supplicant # Check for interfering processes airmon_ng_check # Cleanup finish() { screen_cleanup [ -n "${AD_PID}" ] && kill -9 ${AD_PID} [ -n "${TEMP_FILE}" ] && [ -f "${TEMP_FILE}-01.csv" ] && rm -f ${TEMP_FILE}-01.* [ -n "${XOR_FILE}" ] && [ -f "${XOR_FILE}" ] && rm -f ${XOR_FILE} cleanup } trap finish INT QUIT SEGV PIPE ALRM TERM EXIT # Load mac80211_hwsim load_module 3 # Check there are two radios check_radios_present 3 # Get interfaces names get_hwsim_interface_name 1 WI_IFACE=${IFACE} get_hwsim_interface_name 2 WI_IFACE2=${IFACE} get_hwsim_interface_name 3 WI_IFACE3=${IFACE} # Set-up hostapd SSID=thisrocks CHANNEL=1 TEMP_HOSTAPD_CONF_FILE=$(mktemp) WEP_KEY="abcde" cat <<EOF > ${TEMP_HOSTAPD_CONF_FILE} auth_algs=2 ssid=${SSID} interface=${WI_IFACE} wep_key0="${WEP_KEY}" channel=${CHANNEL} driver=nl80211 # Aireplay-ng test 7 EOF # Start HostAPd run_hostapd ${TEMP_HOSTAPD_CONF_FILE} [ $? -eq 0 ] && exit 1 # Put third interface in monitor mode set_monitor_mode ${WI_IFACE3} [ $? -eq 1 ] && exit 1 set_interface_channel ${WI_IFACE3} ${CHANNEL} [ $? -eq 1 ] && exit 1 # Run airodump-ng in the background TEMP_FILE=$(mktemp -u) screen -AmdS capture \ "${abs_builddir}/../airodump-ng" \ ${WI_IFACE3} \ -c ${CHANNEL} \ -w ${TEMP_FILE} \ --background 1 # Wait 3 secs sleep 3 # Get airodump-ng PID AD_PID=$(ps faux | ${GREP} airodump | ${GREP} "${TEMP_FILE}" | ${GREP} -v grep | ${AWK} '{print $2}') if [ -z "${AD_PID}" ]; then echo "Failed starting airodump-ng" exit 1 fi # Prepare WPA Supplicant cat >> ${TEMP_WPAS_CONF_FILE} << EOF network={ ssid="${SSID}" key_mgmt=NONE auth_alg=SHARED wep_key0="${WEP_KEY}" wep_tx_keyidx=0 } # Aireplay-ng test 7 EOF # Run wpa_supplicant # Set interface up set_interface_channel ${WI_IFACE2} ${CHANNEL} [ $? -eq 1 ] && exit 1 # Start wpa_supplicant run_wpa_supplicant ${TEMP_WPAS_CONF_FILE} ${WI_IFACE2} # Wait for wpa_supplicant to be done sleep 6 # Clean up kill -9 ${AD_PID} kill_wpa_supplicant # Check we have the xor file XOR_FILE="$(ls -1 ${TEMP_FILE}*.xor)" if [ -z "${XOR_FILE}" ]; then echo "Failed getting XOR file from airodump-ng from real authentication" exit 1 fi # Run aireplay-ng fakeauth "${abs_builddir}/../aireplay-ng" \ --fakeauth 0 \ -e "${SSID}" \ -y ${XOR_FILE} \ ${WI_IFACE3} exit $?
Shell Script
aircrack-ng/test/test-aireplay-ng-0008.sh
#!/bin/sh # Aireplay-ng/Airodump-ng: Fake auth on a 5GHz channel if test ! -z "${CI}"; then exit 77; fi # Load helper functions . "${abs_builddir}/../test/int-test-common.sh" # Check root check_root # Check all required tools are installed check_airmon_ng_deps_present is_tool_present screen is_tool_present hostapd # Check for interfering processes airmon_ng_check trap cleanup INT QUIT SEGV PIPE ALRM TERM EXIT # Load mac80211_hwsim load_module 2 # Check there are two radios check_radios_present 2 # Get interfaces names get_hwsim_interface_name 1 WI_IFACE=${IFACE} get_hwsim_interface_name 2 WI_IFACE2=${IFACE} # Check if 5GHz is allowed get_first_5ghz_channel ${WI_IFACE} if [ $? -eq 1 ]; then backup_regdomain set_regdomain US fi get_first_5ghz_channel ${WI_IFACE} if [ $? -eq 1 ]; then echo 'Failed getting a 5GHz channel after setting a regdomain known to allow it' exit 1 fi # Set-up hostapd SSID=thisrocks CHANNEL=${FIRST_5GHZ_CHANNEL} TEMP_HOSTAPD_CONF_FILE=$(mktemp) WEP_KEY="abcdf" cat <<EOF > ${TEMP_HOSTAPD_CONF_FILE} auth_algs=1 ssid=${SSID} interface=${WI_IFACE} wep_key0="${WEP_KEY}" channel=${CHANNEL} hw_mode=a driver=nl80211 # Aireplay-ng test 8 EOF # Start HostAPd run_hostapd ${TEMP_HOSTAPD_CONF_FILE} [ $? -eq 0 ] && exit 1 # Put other interface in monitor mode set_monitor_mode ${WI_IFACE2} [ $? -eq 1 ] && exit 1 set_interface_channel ${WI_IFACE2} ${CHANNEL} [ $? -eq 1 ] && exit 1 # Run aireplay-ng fakeauth "${abs_builddir}/../aireplay-ng" \ --fakeauth 0 \ -e "${SSID}" \ ${WI_IFACE2} exit $?
Shell Script
aircrack-ng/test/test-airodump-ng-0001.sh
#!/bin/sh # Airodump-ng: Check base files generated are good if test ! -z "${CI}"; then exit 77; fi # Load helper functions . "${abs_builddir}/../test/int-test-common.sh" # Check root check_root # Check all required tools are installed check_airmon_ng_deps_present is_tool_present screen # Check for interfering processes airmon_ng_check # Cleanup finish() { screen_cleanup [ -n "${TEMP_FILE}" ] && [ -f "${TEMP_FILE}-01.csv" ] && rm -f ${TEMP_FILE}* cleanup } trap finish INT QUIT SEGV PIPE ALRM TERM EXIT # Load mac80211_hwsim load_module 1 # Check there are two radios check_radios_present 1 # Get interfaces names get_hwsim_interface_name 1 WI_IFACE=${IFACE} CHANNEL=9 # Put interface in monitor mode set_monitor_mode ${WI_IFACE} [ $? -eq 1 ] && exit 1 set_interface_channel ${WI_IFACE} ${CHANNEL} [ $? -eq 1 ] && exit 1 TEMP_FILE=$(mktemp -u) screen -AmdS capture \ timeout 3 \ "${abs_builddir}/../airodump-ng" \ ${WI_IFACE} \ -c 10 \ -w ${TEMP_FILE} \ --background 1 # Wait a few seconds for it to finish sleep 5 # Basic checks if [ $(ls -1 ${TEMP_FILE}-01.* | wc -l) -ne 5 ]; then echo "Failed creating files" exit 1 fi if [ $(md5sum "${TEMP_FILE}-01.cap" | ${AWK} '{print $1}' ) != '50d6b6d03c0e582a1ae60986e5f53832' ]; then echo "Invalid PCAP file" exit 1 fi if [ $(md5sum "${TEMP_FILE}-01.csv" | ${AWK} '{print $1}') != '7b5b92716e839e310d8edda8ec21a469' ]; then echo "Invalid CSV file" exit 1 fi if [ $(md5sum "${TEMP_FILE}-01.kismet.csv" | ${AWK} '{print $1}') != '0f402e05f06f582a7931420075485369' ]; then echo "Invalid Kismet CSV file" exit 1 fi if [ $(md5sum "${TEMP_FILE}-01.log.csv" | ${AWK} '{print $1}') != '6bdaf36ee12b14b2a5a80c3af8ae7160' ]; then echo "Invalid Log CSV" exit 1 fi # TODO: Verify Kismet NetXML echo 'Kismet NetXML is not verified' exit 0
Shell Script
aircrack-ng/test/test-airodump-ng-0002.sh
#!/bin/sh # Airodump-ng: Test WPA3 detection if test ! -z "${CI}"; then exit 77; fi # Load helper functions . "${abs_builddir}/../test/int-test-common.sh" # Check root check_root # Check all required tools are installed check_airmon_ng_deps_present is_tool_present screen is_tool_present hostapd # Check for interfering processes airmon_ng_check # Check HostAPd version supports WPA3 HOSTAPD_VER="$(hostapd -v 2>&1 | ${GREP} hostapd | ${AWK} '{print $2}')" if [ -z "${HOSTAPD_VER}" ]; then echo "Failed getting hostapd version, skipping" exit 1 elif [ "$(echo ${HOSTAPD_VER} | ${GREP} -v -E '^v((2\.([789]|[1-9][0-9]))|(3.[0-9]))(-devel)?$')" ]; then echo "hostapd version does not support WPA3, skipping" echo "v2.7+ required, got ${HOSTAPD_VER}" exit 77 fi # Cleanup finish() { screen_cleanup [ -n "${TEMP_FILE}" ] && [ -f "${TEMP_FILE}-01.csv" ] && rm -f ${TEMP_FILE}* cleanup } trap finish INT QUIT SEGV PIPE ALRM TERM EXIT # Load mac80211_hwsim load_module 1 # Check there are two radios check_radios_present 1 # Get interfaces names get_hwsim_interface_name 1 WI_IFACE=${IFACE} # Start hostapd with WPA3 cat >> ${TEMP_HOSTAPD_CONF_FILE} << EOF interface=${WI_IFACE} ssid=test channel=1 wpa=2 sae_password=password wpa_key_mgmt=SAE rsn_pairwise=CCMP ieee80211w=2 sae_require_mfp=1 # Airodump-ng test 2 EOF # Start hostapd run_hostapd ${TEMP_HOSTAPD_CONF_FILE} # Start hwsim0 ip link set hwsim0 up TEMP_FILE=$(mktemp -u) screen -AmdS capture \ timeout 4 \ "${abs_builddir}/../airodump-ng" \ hwsim0 \ -c 1 \ -w ${TEMP_FILE} \ --background 1 # Wait a few seconds for it to finish sleep 6 # Check CSV ENCRYPTION_SECTION="$(head -n 3 ${TEMP_FILE}-01.csv | tail -n 1 | ${AWK} -F, '{print $6 $7 $8}')" if [ -z "${ENCRYPTION_SECTION}" ]; then echo "Something failed with airodump-ng, did not get info from CSV" exit 1 elif [ "$(echo ${ENCRYPTION_SECTION} | tr -d ' ')" != 'WPA3WPA2CCMPSAE' ]; then echo "Encryption section is not what is expected. Got ${ENCRYPTION_SECTION}" exit 1 fi # Check NetXML if [ ! -f ${TEMP_FILE}-01.kismet.netxml ]; then echo "Kismet netxml file not found" rm -f ${TEMP_FILE}-01.* exit 1 fi ENCRYPTION_SECTION="$(${GREP} '<encryption>WPA+SAE</encryption>' ${TEMP_FILE}-01.kismet.netxml)" if [ -z "${ENCRYPTION_SECTION}" ]; then echo "Failed to find SAE in the kismet netxml" exit 1 fi # Check Kismet CSV if [ ! -f ${TEMP_FILE}-01.kismet.csv ]; then echo 'Kismet CSV not found' exit 1 fi ENCRYPTION_SECTION="$(tail -n 1 ${TEMP_FILE}-01.kismet.csv | ${AWK} -F\; '{print $8}')" if [ "x${ENCRYPTION_SECTION}" != 'xWPA3,AES-CCM,SAE' ]; then echo "Encryption section not found or invalid in Kismet CSV" echo "Expected 'WPA3,AES-CCM,SAE', got ${ENCRYPTION_SECTION}" exit 1 fi exit 0
Shell Script
aircrack-ng/test/test-airodump-ng-0003.sh
#!/bin/sh # Airodump-ng: Test WPA3 (OWE) detection if test ! -z "${CI}"; then exit 77; fi # Load helper functions . "${abs_builddir}/../test/int-test-common.sh" # Check root check_root # Check all required tools are installed check_airmon_ng_deps_present is_tool_present screen is_tool_present hostapd # Check for interfering processes airmon_ng_check # Check HostAPd version supports WPA3 HOSTAPD_VER="$(hostapd -v 2>&1 | ${GREP} hostapd | ${AWK} '{print $2}')" if [ -z "${HOSTAPD_VER}" ]; then echo "Failed getting hostapd version, skipping" exit 1 elif [ "$(echo ${HOSTAPD_VER} | ${GREP} -v -E '^v((2\.([789]|[1-9][0-9]))|(3.[0-9]))(-devel)?$')" ]; then echo "hostapd version does not support WPA3, skipping" echo "v2.7+ required, got ${HOSTAPD_VER}" exit 77 fi # Cleanup finish() { screen_cleanup [ -n "${TEMP_FILE}" ] && [ -f "${TEMP_FILE}-01.csv" ] && rm -f ${TEMP_FILE}* cleanup } trap finish INT QUIT SEGV PIPE ALRM TERM EXIT # Load mac80211_hwsim load_module 1 # Check there are two radios check_radios_present 1 # Get interfaces names get_hwsim_interface_name 1 WI_IFACE=${IFACE} # Start hostapd with WPA3 cat >> ${TEMP_HOSTAPD_CONF_FILE} << EOF interface=${WI_IFACE} ssid=test channel=1 wpa=2 wpa_passphrase=password wpa_key_mgmt=OWE rsn_pairwise=CCMP ieee80211w=2 # Airodump-ng test 3 EOF # Start hostapd run_hostapd ${TEMP_HOSTAPD_CONF_FILE} # Start hwsim0 ip link set hwsim0 up TEMP_FILE=$(mktemp -u) screen -AmdS capture \ timeout 4 \ "${abs_builddir}/../airodump-ng" \ hwsim0 \ -c 1 \ -w ${TEMP_FILE} \ --background 1 # Wait a few seconds for it to finish sleep 6 # Some cleanup cleanup # Check CSV ENCRYPTION_SECTION="$(head -n 3 ${TEMP_FILE}-01.csv | tail -n 1 | ${AWK} -F, '{print $6 $7 $8}')" if [ -z "${ENCRYPTION_SECTION}" ]; then echo "Something failed with airodump-ng, did not get info from CSV" rm -f ${TEMP_FILE}-01.* exit 1 elif [ "$(echo ${ENCRYPTION_SECTION} | tr -d ' ')" != 'WPA3WPA2CCMPOWE' ]; then echo "Encryption section is not what is expected. Got ${ENCRYPTION_SECTION}" rm -f ${TEMP_FILE}-01.* exit 1 fi # Check NetXML if [ ! -f ${TEMP_FILE}-01.kismet.netxml ]; then echo "Kismet netxml file not found" rm -f ${TEMP_FILE}-01.* exit 1 fi ENCRYPTION_SECTION="$(${GREP} '<encryption>WPA+OWE</encryption>' ${TEMP_FILE}-01.kismet.netxml)" if [ -z "${ENCRYPTION_SECTION}" ]; then echo "Failed to find OWE in the kismet netxml" rm -f ${TEMP_FILE}-01.* exit 1 fi # Check Kismet CSV if [ ! -f ${TEMP_FILE}-01.kismet.csv ]; then echo 'Kismet CSV not found' rm -f ${TEMP_FILE}-01.* exit 1 fi ENCRYPTION_SECTION="$(tail -n 1 ${TEMP_FILE}-01.kismet.csv | ${AWK} -F\; '{print $8}')" if [ "x${ENCRYPTION_SECTION}" != 'xWPA3,AES-CCM,OWE' ]; then echo "Encryption section not found or invalid in Kismet CSV" echo "Expected 'OWE,AES-CCM,SAE', got ${ENCRYPTION_SECTION}" rm -f ${TEMP_FILE}-01.* exit 1 fi # Cleanup rm -f ${TEMP_FILE}-01.* exit 0
Shell Script
aircrack-ng/test/test-airodump-ng-0004.sh
#!/bin/sh # Airodump-ng: Test WPA2 detection if test ! -z "${CI}"; then exit 77; fi # Load helper functions . "${abs_builddir}/../test/int-test-common.sh" # Check root check_root # Check all required tools are installed check_airmon_ng_deps_present is_tool_present screen is_tool_present hostapd # Check for interfering processes airmon_ng_check # Cleanup finish() { screen_cleanup [ -n "${TEMP_FILE}" ] && [ -f "${TEMP_FILE}-01.csv" ] && rm -f ${TEMP_FILE}* cleanup } trap finish INT QUIT SEGV PIPE ALRM TERM EXIT # Load mac80211_hwsim load_module 1 # Check there are two radios check_radios_present 1 # Get interfaces names get_hwsim_interface_name 1 WI_IFACE=${IFACE} # Start hostapd with WPA2 CCMP cat >> ${TEMP_HOSTAPD_CONF_FILE} << EOF interface=${WI_IFACE} ssid=test channel=1 wpa=2 wpa_passphrase=password rsn_pairwise=CCMP # Airodump-ng test 4 EOF # Start hostapd run_hostapd ${TEMP_HOSTAPD_CONF_FILE} # Start hwsim0 ip link set hwsim0 up TEMP_FILE=$(mktemp -u) screen -AmdS capture \ timeout 4 \ "${abs_builddir}/../airodump-ng" \ hwsim0 \ -c 1 \ -w ${TEMP_FILE} \ --background 1 # Wait a few seconds for it to finish sleep 6 # Some cleanup cleanup # Check CSV ENCRYPTION_SECTION="$(head -n 3 ${TEMP_FILE}-01.csv | tail -n 1 | ${AWK} -F, '{print $6 $7 $8}')" if [ -z "${ENCRYPTION_SECTION}" ]; then echo "Something failed with airodump-ng, did not get info from CSV" rm -f ${TEMP_FILE}-01.* exit 1 elif [ "$(echo ${ENCRYPTION_SECTION} | tr -d ' ')" != 'WPA2CCMPPSK' ]; then echo "Encryption section is not what is expected. Got ${ENCRYPTION_SECTION}" rm -f ${TEMP_FILE}-01.* exit 1 fi # Check NetXML if [ ! -f ${TEMP_FILE}-01.kismet.netxml ]; then echo "Kismet netxml file not found" rm -f ${TEMP_FILE}-01.* exit 1 fi ENCRYPTION_SECTION="$(${GREP} '<encryption>WPA+PSK</encryption>' ${TEMP_FILE}-01.kismet.netxml)" if [ -z "${ENCRYPTION_SECTION}" ] || [ -z "$(${GREP} '<encryption>WPA+AES-CCM</encryption>' ${TEMP_FILE}-01.kismet.netxml)" ]; then echo "Failed to find PSK and CCMP in the kismet netxml" cat ${TEMP_FILE}-01.kismet.netxml rm -f ${TEMP_FILE}-01.* exit 1 fi # Check Kismet CSV if [ ! -f ${TEMP_FILE}-01.kismet.csv ]; then echo 'Kismet CSV not found' rm -f ${TEMP_FILE}-01.* exit 1 fi ENCRYPTION_SECTION="$(tail -n 1 ${TEMP_FILE}-01.kismet.csv | ${AWK} -F\; '{print $8}')" if [ "x${ENCRYPTION_SECTION}" != 'xWPA2,AES-CCM' ]; then echo "Encryption section not found or invalid in Kismet CSV" echo "Expected 'WPA2,AES-CCM', got ${ENCRYPTION_SECTION}" rm -f ${TEMP_FILE}-01.* exit 1 fi # Cleanup rm -f ${TEMP_FILE}-01.* exit 0
Shell Script
aircrack-ng/test/test-airodump-ng-0005.sh
#!/bin/sh # Airodump-ng: Test WPA PSK TKIP detection if test ! -z "${CI}"; then exit 77; fi # Load helper functions . "${abs_builddir}/../test/int-test-common.sh" # Check root check_root # Check all required tools are installed check_airmon_ng_deps_present is_tool_present screen is_tool_present hostapd # Check for interfering processes airmon_ng_check # Cleanup finish() { screen_cleanup [ -n "${TEMP_FILE}" ] && [ -f "${TEMP_FILE}-01.csv" ] && rm -f ${TEMP_FILE}* cleanup } trap finish INT QUIT SEGV PIPE ALRM TERM EXIT # Load mac80211_hwsim load_module 1 # Check there are two radios check_radios_present 1 # Get interfaces names get_hwsim_interface_name 1 WI_IFACE=${IFACE} # Start hostapd with WPA PSK TKIP cat >> ${TEMP_HOSTAPD_CONF_FILE} << EOF interface=${WI_IFACE} ssid=test channel=1 wpa=1 wpa_pairwise=TKIP wpa_passphrase=password # Airodump-ng test 5 EOF # Start hostapd run_hostapd ${TEMP_HOSTAPD_CONF_FILE} # Start hwsim0 ip link set hwsim0 up TEMP_FILE=$(mktemp -u) screen -AmdS capture \ timeout 4 \ "${abs_builddir}/../airodump-ng" \ hwsim0 \ -c 1 \ -w ${TEMP_FILE} \ --background 1 # Wait a few seconds for it to finish sleep 6 # Check CSV ENCRYPTION_SECTION="$(head -n 3 ${TEMP_FILE}-01.csv | tail -n 1 | ${AWK} -F, '{print $6 $7 $8}')" if [ -z "${ENCRYPTION_SECTION}" ]; then echo "Something failed with airodump-ng, did not get info from CSV" exit 1 elif [ "$(echo ${ENCRYPTION_SECTION} | tr -d ' ')" != 'WPATKIPPSK' ]; then echo "Encryption section is not what is expected. Got ${ENCRYPTION_SECTION}" exit 1 fi # Check NetXML if [ ! -f ${TEMP_FILE}-01.kismet.netxml ]; then echo "Kismet netxml file not found" exit 1 fi ENCRYPTION_SECTION="$(${GREP} '<encryption>WPA+PSK</encryption>' ${TEMP_FILE}-01.kismet.netxml)" if [ -z "${ENCRYPTION_SECTION}" ] || [ -z "$(${GREP} '<encryption>WPA+TKIP</encryption>' ${TEMP_FILE}-01.kismet.netxml)" ]; then echo "Failed to find PSK and TKIP in the kismet netxml" cat ${TEMP_FILE}-01.kismet.netxml exit 1 fi # Check Kismet CSV if [ ! -f ${TEMP_FILE}-01.kismet.csv ]; then echo 'Kismet CSV not found'= exit 1 fi ENCRYPTION_SECTION="$(tail -n 1 ${TEMP_FILE}-01.kismet.csv | ${AWK} -F\; '{print $8}')" if [ "x${ENCRYPTION_SECTION}" != 'xWPA,TKIP' ]; then echo "Encryption section not found or invalid in Kismet CSV" echo "Expected 'WPA,TKIP', got ${ENCRYPTION_SECTION}" exit 1 fi exit 0
Shell Script
aircrack-ng/test/test-airodump-ng-0006.sh
#!/bin/sh # Airodump-ng: Test WPA2 PSK TKIP detection if test ! -z "${CI}"; then exit 77; fi # Load helper functions . "${abs_builddir}/../test/int-test-common.sh" # Check root check_root # Check all required tools are installed check_airmon_ng_deps_present is_tool_present screen is_tool_present hostapd # Check for interfering processes airmon_ng_check # Cleanup finish() { screen_cleanup [ -n "${TEMP_FILE}" ] && [ -f "${TEMP_FILE}-01.csv" ] && rm -f ${TEMP_FILE}* cleanup } trap finish INT QUIT SEGV PIPE ALRM TERM EXIT # Load mac80211_hwsim load_module 1 # Check there are two radios check_radios_present 1 # Get interfaces names get_hwsim_interface_name 1 WI_IFACE=${IFACE} # Start hostapd with WPA PSK TKIP cat >> ${TEMP_HOSTAPD_CONF_FILE} << EOF interface=${WI_IFACE} ssid=test channel=1 wpa=2 wpa_pairwise=TKIP wpa_passphrase=password # Airodump-ng test 5 EOF # Start hostapd run_hostapd ${TEMP_HOSTAPD_CONF_FILE} # Start hwsim0 ip link set hwsim0 up TEMP_FILE=$(mktemp -u) screen -AmdS capture \ timeout 4 \ "${abs_builddir}/../airodump-ng" \ hwsim0 \ -c 1 \ -w ${TEMP_FILE} \ --background 1 # Wait a few seconds for it to finish sleep 6 # Check CSV ENCRYPTION_SECTION="$(head -n 3 ${TEMP_FILE}-01.csv | tail -n 1 | ${AWK} -F, '{print $6 $7 $8}')" if [ -z "${ENCRYPTION_SECTION}" ]; then echo "Something failed with airodump-ng, did not get info from CSV" exit 1 elif [ "$(echo ${ENCRYPTION_SECTION} | tr -d ' ')" != 'WPA2TKIPPSK' ]; then echo "Encryption section is not what is expected. Got ${ENCRYPTION_SECTION}" exit 1 fi # Check NetXML if [ ! -f ${TEMP_FILE}-01.kismet.netxml ]; then echo "Kismet netxml file not found" exit 1 fi ENCRYPTION_SECTION="$(${GREP} '<encryption>WPA+PSK</encryption>' ${TEMP_FILE}-01.kismet.netxml)" if [ -z "${ENCRYPTION_SECTION}" ] || [ -z "$(${GREP} '<encryption>WPA+TKIP</encryption>' ${TEMP_FILE}-01.kismet.netxml)" ]; then echo "Failed to find PSK and WPA in the kismet netxml" cat ${TEMP_FILE}-01.kismet.netxml exit 1 fi # Check Kismet CSV if [ ! -f ${TEMP_FILE}-01.kismet.csv ]; then echo 'Kismet CSV not found'= exit 1 fi ENCRYPTION_SECTION="$(tail -n 1 ${TEMP_FILE}-01.kismet.csv | ${AWK} -F\; '{print $8}')" if [ "x${ENCRYPTION_SECTION}" != 'xWPA2,TKIP' ]; then echo "Encryption section not found or invalid in Kismet CSV" echo "Expected 'WPA2,TKIP', got ${ENCRYPTION_SECTION}" exit 1 fi exit 0
Shell Script
aircrack-ng/test/test-airolib-sqlite.sh
#! /bin/sh # # Carlos Alberto Lopez Perez <clopez@igalia.com> # TESTDIR="$(dirname $0)" if test -f /etc/alpine-release -o "$(uname -s)" = "OpenBSD"; then tmpfile="$(mktemp -u -t acng.XXXXXX)" else tmpfile="$(mktemp -u -t acng.XXXX)" fi # Clean on exit trap "rm -fr "${tmpdir}"" INT QUIT SEGV PIPE ALRM TERM EXIT echo Harkonen | "${abs_builddir}/../airolib-ng${EXEEXT}" "${tmpfile}" --import essid - [ $? -ne 0 ] && exit 1 "${abs_builddir}/../airolib-ng${EXEEXT}" "${tmpfile}" --import passwd "${TESTDIR}/password.lst" [ $? -ne 0 ] && exit 1 "${abs_builddir}/../airolib-ng${EXEEXT}" "${tmpfile}" --batch | ${GREP} "Computed 233 PMK" [ $? -ne 0 ] && exit 1 "${abs_builddir}/../aircrack-ng${EXEEXT}" -q -e Harkonen -r "${tmpfile}" "${TESTDIR}/wpa2.eapol.cap" | ${GREP} 'KEY FOUND! \[ 12345678 \]' [ $? -ne 0 ] && exit 1 exit 0
Shell Script
aircrack-ng/test/test-alltools.sh
#!/bin/sh test_tool() { TOOL_PATH="${top_builddir}/src/${1}${EXEEXT}" if [ -f "${TOOL_PATH}" ]; then "${TOOL_PATH}" # Anything greater than 1 indicates it does not # exist or did not run properly (crash) [ $? -gt 1 ] && exit 1 fi } test_tool airbase-ng test_tool aircrack-ng test_tool airdecap-ng test_tool airdecloak-ng test_tool aireplay-ng test_tool airodump-ng test_tool airolib-ng test_tool airserv-ng test_tool airtun-ng test_tool airventriloquist-ng test_tool besside-ng test_tool besside-ng-crawler # Buddy-ng doesn't have any parameters and requires root #test_tool buddy-ng test_tool easside-ng test_tool ivstools test_tool kstats test_tool makeivs-ng test_tool packetforge-ng test_tool tkiptun-ng test_tool wesside-ng test_tool wpaclean exit 0
Inno Setup Script
aircrack-ng/test/test-env.sh.in
#!/bin/sh abs_builddir="@abs_builddir@"; export abs_builddir abs_srcdir="@abs_srcdir@"; export abs_srcdir top_builddir="@top_builddir@"; export top_builddir top_srcdir="@top_srcdir@"; export top_srcdir EXEEXT="@EXEEXT@"; export EXEEXT EXPECT="@EXPECT@"; export EXPECT AIRCRACK_LIBEXEC_PATH="@abs_top_builddir@/src"; export AIRCRACK_LIBEXEC_PATH AIRCRACK_NG_ARGS="${AIRCRACK_NG_ARGS:--p 4}"; export AIRCRACK_NG_ARGS AWK="@AWK@"; export AWK GREP="@GREP@"; export GREP
C
aircrack-ng/test/test-hex_string_to_array.c
#ifdef HAVE_CONFIG_H #include "config.h" #endif #include <string.h> #include <stdio.h> #include "aircrack-ng/support/common.h" int main(int nbarg, char * argv[]) { #define OUT_LEN 1024 unsigned char out[OUT_LEN]; int out_bytes, i; if (nbarg != 2) { printf("Missing parameter\n"); return 1; } for (i = 0; i < OUT_LEN; ++i) out[i] = 0; out_bytes = hexStringToArray(argv[1], strlen(argv[1]), out, OUT_LEN); if (out_bytes == -1) { printf("Invalid\n"); return 2; } else { printf("Valid (len: %d): ", out_bytes); } for (i = 0; i < out_bytes; ++i) { if (i != 0) printf(":"); printf("%d", out[i]); } return 0; }
Shell Script
aircrack-ng/test/test-hex_string_to_array.sh
#! /bin/sh ./test-hex_string_to_array >/dev/null 2>/dev/null RET=$? if [ ${RET} -ne 1 ]; then "Hex string test fail. Expected return value of 1 (missing parameter), got ${RET} with no parameter." exit 1 fi echo "Test Hex string to array with empty string: failure - Test successful" hex_failing_test() { ./test-hex_string_to_array "${1}" >/dev/null 2>/dev/null RET=$? if [ ${RET} -ne 2 ]; then echo "Hex string failed. Expected return value of 2 (failure), got ${RET} with ${1}." exit 1 fi echo "Test Hex string to array with ${1}: failure - Test successful" } # sh does not support arrays, so we have to do it this way hex_failing_test 'F' hex_failing_test 'A' hex_failing_test 'a' hex_failing_test '1' hex_failing_test '9' hex_failing_test 'G' hex_failing_test 'AG' hex_failing_test '9U' hex_failing_test 'aO' hex_failing_test 'FF:FF:FF:AS' hex_failing_test 'BLAH' hex_success_test() { ./test-hex_string_to_array "${1}" >/dev/null 2>/dev/null RET=$? if [ ${RET} -ne 0 ]; then echo "Hex string test failed. Expected return value of 0 (success), got ${RET} with ${1}" exit 1 fi echo "Test Hex string to array with ${1}: success - Test successful" } hex_success_test 'FF' hex_success_test 'AA' hex_success_test 'aa' hex_success_test '11' hex_success_test '22' hex_success_test 'FF:AA:FF' hex_success_test 'C0:FF:EE:' hex_success_test '00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF' echo "Hex string tests successful." exit 0
Shell Script
aircrack-ng/test/test-wpaclean-0001.sh
#!/bin/sh set -ef if test ! -e "${top_builddir}/wpaclean${EXEEXT}"; then echo "Skipped: $0" exit 0 fi "${top_builddir}/wpaclean${EXEEXT}" \ "$(basename $0).out.log" \ "${abs_srcdir}/wpaclean_crash.pcap" exit 0
Shell Script
aircrack-ng/test/test-wpaclean-0002.sh
#!/bin/sh set -ef if test ! -e "${top_builddir}/wpaclean${EXEEXT}"; then echo "Skipped: $0" exit 0 fi "${top_builddir}/wpaclean${EXEEXT}" \ "$(basename $0).out.log" \ "${abs_srcdir}/wpa.cap" | \ ${GREP} 'Net 00:0d:93:eb:b0:8c test' rm -f "$(basename $0).out.log" exit 0
Python
aircrack-ng/test/verify_inject.py
#!/usr/bin/env python # Usage: https://github.com/aircrack-ng/aircrack-ng/pull/21 from scapy.all import * conf.verbf = 1 interface = "at0" rpkt = Ether( dst = "[AP mac]", src = "[STA mac]" )/\ IP( dst = "[AP ip]", src = "[STA ip]" )/\ UDP( )/\ DNS(rd=1,qd=DNSQR(qname="www.aircrack-ng.org")) sendp( rpkt, iface = interface )
Include
aircrack-ng/test/cryptounittest/Makefile.inc
# Aircrack-ng # # Copyright (C) 2017-2022 Joseph Benden <joe@benden.us> # # Autotool support was written by: Joseph Benden <joe@benden.us> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA # # In addition, as a special exception, the copyright holders give # permission to link the code of portions of this program with the # OpenSSL library under certain conditions as described in each # individual source file, and distribute linked combinations # including the two. # # You must obey the GNU General Public License in all respects # for all of the code used other than OpenSSL. # # If you modify file(s) with this exception, you may extend this # exception to your dnl version of the file(s), but you are not obligated # to do so. # # If you dnl do not wish to do so, delete this exception statement from your # version. # # If you delete this exception statement from all source files in the # program, then also delete it here. SRCS_TEST_EWEP = %D%/test-encrypt-wep.c SRCS_TEST_CPMK = %D%/test-calc-pmk.c SRCS_TEST_CMIC = %D%/test-calc-mic.c SRCS_TEST_CPTK = %D%/test-calc-ptk.c SRCS_TEST_DCMP = %D%/test-decrypt-ccmp.c SRCS_TEST_ECMP = %D%/test-encrypt-ccmp.c test_encrypt_wep_SOURCES = $(SRCS_TEST_EWEP) test_encrypt_wep_CFLAGS = $(PTHREAD_CFLAGS) \ $(CRYPTO_CFLAGS) test_encrypt_wep_LDADD = $(LIBACCRYPTO_LIBS) $(LIBAIRCRACK_LIBS) \ $(PTHREAD_LIBS) \ $(CRYPTO_LDFLAGS) \ $(CRYPTO_LIBS) \ $(ZLIB_LIBS) test_calc_pmk_SOURCES = $(SRCS_TEST_CPMK) test_calc_pmk_CFLAGS = $(PTHREAD_CFLAGS) \ $(CRYPTO_CFLAGS) test_calc_pmk_LDADD = $(LIBACCRYPTO_LIBS) $(LIBAIRCRACK_LIBS) \ $(LIBAIRCRACK_CE_WPA_LIBS) \ $(PTHREAD_LIBS) \ $(CRYPTO_LDFLAGS) \ $(CRYPTO_LIBS) \ $(ZLIB_LIBS) test_calc_mic_SOURCES = $(SRCS_TEST_CMIC) test_calc_mic_CFLAGS = $(PTHREAD_CFLAGS) $(CRYPTO_CFLAGS) test_calc_mic_LDADD = $(LIBACCRYPTO_LIBS) $(LIBAIRCRACK_LIBS) \ $(PTHREAD_LIBS) \ $(CRYPTO_LDFLAGS) \ $(CRYPTO_LIBS) \ $(ZLIB_LIBS) test_calc_ptk_SOURCES = $(SRCS_TEST_CPTK) test_calc_ptk_CFLAGS = $(PTHREAD_CFLAGS) \ $(CRYPTO_CFLAGS) test_calc_ptk_LDADD = $(LIBACCRYPTO_LIBS) $(LIBAIRCRACK_LIBS) \ $(PTHREAD_LIBS) \ $(CRYPTO_LDFLAGS) \ $(CRYPTO_LIBS) \ $(ZLIB_LIBS) test_cipher_arcfour_SOURCES = %D%/test-cipher-arcfour.c test_cipher_arcfour_CFLAGS = $(PTHREAD_CFLAGS) \ $(CRYPTO_CFLAGS) test_cipher_arcfour_LDADD = $(LIBACCRYPTO_LIBS) $(LIBAIRCRACK_LIBS) \ $(PTHREAD_LIBS) \ $(CRYPTO_LDFLAGS) \ $(CRYPTO_LIBS) \ $(ZLIB_LIBS) test_digest_md5_SOURCES = %D%/test-digest-md5.c test_digest_md5_CFLAGS = $(PTHREAD_CFLAGS) \ $(CRYPTO_CFLAGS) test_digest_md5_LDADD = $(LIBACCRYPTO_LIBS) $(LIBAIRCRACK_LIBS) \ $(PTHREAD_LIBS) \ $(CRYPTO_LDFLAGS) \ $(CRYPTO_LIBS) \ $(ZLIB_LIBS) test_mac_hmac_md5_SOURCES = %D%/test-mac-hmac-md5.c test_mac_hmac_md5_CFLAGS = $(PTHREAD_CFLAGS) \ $(CRYPTO_CFLAGS) test_mac_hmac_md5_LDADD = $(LIBACCRYPTO_LIBS) $(LIBAIRCRACK_LIBS) \ $(PTHREAD_LIBS) \ $(CRYPTO_LDFLAGS) \ $(CRYPTO_LIBS) \ $(ZLIB_LIBS) test_mac_hmac_sha1_SOURCES = %D%/test-mac-hmac-sha1.c test_mac_hmac_sha1_CFLAGS = $(PTHREAD_CFLAGS) \ $(CRYPTO_CFLAGS) test_mac_hmac_sha1_LDADD = $(LIBACCRYPTO_LIBS) $(LIBAIRCRACK_LIBS) \ $(PTHREAD_LIBS) \ $(CRYPTO_LDFLAGS) \ $(CRYPTO_LIBS) \ $(ZLIB_LIBS) test_mac_hmac_sha256_SOURCES = %D%/test-mac-hmac-sha256.c test_mac_hmac_sha256_CFLAGS = $(PTHREAD_CFLAGS) \ $(CRYPTO_CFLAGS) test_mac_hmac_sha256_LDADD = $(LIBACCRYPTO_LIBS) $(LIBAIRCRACK_LIBS) \ $(PTHREAD_LIBS) \ $(CRYPTO_LDFLAGS) \ $(CRYPTO_LIBS) \ $(ZLIB_LIBS) test_digest_sha1_SOURCES = %D%/test-digest-sha1.c test_digest_sha1_CFLAGS = $(PTHREAD_CFLAGS) \ $(CRYPTO_CFLAGS) test_digest_sha1_LDADD = $(LIBACCRYPTO_LIBS) $(LIBAIRCRACK_LIBS) \ $(PTHREAD_LIBS) \ $(CRYPTO_LDFLAGS) \ $(CRYPTO_LIBS) \ $(ZLIB_LIBS) test_kdf_pbkdf2_hmac_sha1_SOURCES = %D%/test-kdf-pbkdf2-hmac-sha1.c test_kdf_pbkdf2_hmac_sha1_CFLAGS = $(PTHREAD_CFLAGS) \ $(CRYPTO_CFLAGS) test_kdf_pbkdf2_hmac_sha1_LDADD = $(LIBACCRYPTO_LIBS) $(LIBAIRCRACK_LIBS) \ $(PTHREAD_LIBS) \ $(CRYPTO_LDFLAGS) \ $(CRYPTO_LIBS) \ $(ZLIB_LIBS) test_encrypt_ccmp_SOURCES = $(SRCS_TEST_ECMP) test_encrypt_ccmp_CFLAGS = $(PTHREAD_CFLAGS) \ $(CRYPTO_CFLAGS) test_encrypt_ccmp_LDADD = $(LIBACCRYPTO_LIBS) $(LIBAIRCRACK_LIBS) \ $(PTHREAD_LIBS) \ $(CRYPTO_LDFLAGS) \ $(CRYPTO_LIBS) \ $(ZLIB_LIBS) test_decrypt_ccmp_SOURCES = $(SRCS_TEST_DCMP) test_decrypt_ccmp_CFLAGS = $(PTHREAD_CFLAGS) \ $(CRYPTO_CFLAGS) test_decrypt_ccmp_LDADD = $(LIBACCRYPTO_LIBS) $(LIBAIRCRACK_LIBS) \ $(PTHREAD_LIBS) \ $(CRYPTO_LDFLAGS) \ $(CRYPTO_LIBS) \ $(ZLIB_LIBS) TESTS += test-encrypt-wep \ test-calc-pmk \ test-calc-mic \ test-calc-ptk \ test-cipher-arcfour \ test-digest-md5 \ test-digest-sha1 \ test-encrypt-ccmp \ test-decrypt-ccmp \ test-mac-hmac-md5 \ test-mac-hmac-sha1 \ test-mac-hmac-sha256 \ test-kdf-pbkdf2-hmac-sha1 check_PROGRAMS += test-encrypt-wep \ test-calc-pmk \ test-calc-mic \ test-calc-ptk \ test-cipher-arcfour \ test-digest-md5 \ test-digest-sha1 \ test-encrypt-ccmp \ test-decrypt-ccmp \ test-mac-hmac-md5 \ test-mac-hmac-sha1 \ test-mac-hmac-sha256 \ test-kdf-pbkdf2-hmac-sha1 EXTRA_DIST += %D%/tests.h
aircrack-ng/test/cryptounittest/README
This tests are meant to ensure that all functions of aircrack-ng where OpenSSL code is used [1] perform exactly the same (same input=>same output) when running with OpenSSL or with the alternative crypto (Libgcrypt+sha1-git) To run the tests with OpenSSL (useful for ensuring that the tests are still valid): make clean && make check To run the tests with Libgcrypt+sha1-git: make clean && make check gcrypt=true To check for memory leaks: cd test/cryptounittest; make clean && make valgrind gcrypt=true Return value: Each one of the tests, when successful return zero, and when failed return the number of tests (>0) failed. The "make check" target will fail if any of the tests return non-zero. [1] This are 4 functions of crypto.c {encrypt_wep,calc_pmk,calc_mic,calc_ptk} And 1 function of sha1-see2.h {calc_4pmk} ----------------------------------------------------------------------------- [TEST] file:testedfunction -> usedbyfile:function [test-encrypt-wep.c] crypto.c:encrypt_wep -> airbase-ng.c:encrypt_data airbase-ng.c:getCompleteFrag airtun-ng.c:packet_xmit airtun-ng.c:getCompleteFrag tkiptun-ng.c:do_attack_tkipchop [test-calc-pmk.c] crypto.c:calc_pmk -> aircrack-ng.c:crack_wpa_thread [test-calc-mic.c] crypto.c:calc_mic -> aircrack-ng.c:sql_wpacallback [test-calc-ptk.c] crypto.c:calc_ptk -> airdecap-ng.c:main tkiptun-ng.c:main [test-decrypt-ccmp.c] crypto.c:decrypt_ccmp -> airdecap-ng.c:main (wpa-v2) [test-calc-4pmk.c] sha1-see2.h:calc_4pmk -> aircrack-ng.c:crack_wpa_thread
C
aircrack-ng/test/cryptounittest/test-calc-mic.c
/* * * test-calc-mic.c * * Copyright (C) 2012 Carlos Alberto Lopez Perez <clopez@igalia.com> * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <stdio.h> #include <string.h> #include <strings.h> #include <stdlib.h> #include "aircrack-ng/defs.h" #include "aircrack-ng/aircrack-ng.h" #include "aircrack-ng/crypto/crypto.h" #include "tests.h" int main(int argc, char ** argv) { if (argc < 1) return 1; int error = 0; static unsigned char opmk[32] = "\x6f\xe8\x57\xc0\xb7\x42\xdf\xc2\xda\x8a\x1f\xe8\xb1\xb4\xb4\x62" "\x8d\x9f\xbb\xb0\x60\x82\x6b\x83\xcb\x43\xb6\x4b\x13\xe1\x03\xe8"; static unsigned char optk[80] = "\x28\x00\x00\x00\x00\x00\x00\x00\x18\x81\xd5\x96\xff\x7f\x00\x00" "\x64\x00\x00\x00\x00\x00\x00\x00\x9f\x84\x00\x51\xd8\x7f\x00\x00" "\x58\x33\xcf\x01\x00\x00\x00\x00\x21\x00\x00\x00\x00\x00\x00\x00" "\x10\xb3\xd3\x01\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00" "\x30\x9d\xd3\x01\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00"; static unsigned char omic[20] = "\x01\x00\x00\x00\x00\x00\x00\x00\x64\x00\x00\x00\x00\x00\x00\x00" "\x30\x9d\xd3\x01"; //expected static unsigned char eptk[80] = "\x9a\x75\xef\x0b\xde\x7c\x20\x9c\xca\xe1\x3f\x54\xb1\xb3\x3e\xa3" "\xfa\x01\x66\x16\x6e\x30\x81\x1f\x1b\xaa\xff\x8d\x1c\x1a\xc1\x63" "\x82\xa4\x9b\x50\xb8\x60\x88\xc5\xcb\x79\x3b\x54\x26\x61\xa2\x8a" "\x64\x69\x3c\x72\xb8\x66\x73\xe0\xa8\x2d\x48\xc7\x47\x68\xcb\xf9" "\xa1\xbf\x86\xcc\x30\xb9\xd6\x3d\xe8\x82\x59\x25\xec\x1f\x4d\x3f"; // expected emic when wpa.keyver=2 static unsigned char emic2[20] = "\x6f\x04\x89\xcf\x74\x06\xac\xf0\xae\x8f\xcb\x32\xbc\xe5\x7c\x37" "\x79\x3a\x23\x61"; // expected emic when wpa.keyver=1 static unsigned char emic1[20] = "\x9c\xc3\xfa\xa0\xc6\x85\x96\x1d\x84\x06\xbb\x65\x77\x45\x13\x5d" "\x30\x9d\xd3\x01"; // AP structure struct AP_info l_ap; struct AP_info * ap = &l_ap; bzero(ap, sizeof(struct AP_info)); unsigned char stmac[6] = "\x00\x13\x46\xfe\x32\x0c"; unsigned char snonce[32] = "\x59\x16\x8b\xc3\xa5\xdf\x18\xd7\x1e\xfb\x64\x23\xf3\x40\x08\x8d" "\xab\x9e\x1b\xa2\xbb\xc5\x86\x59\xe0\x7b\x37\x64\xb0\xde\x85\x70"; unsigned char anonce[32] = "\x22\x58\x54\xb0\x44\x4d\xe3\xaf\x06\xd1\x49\x2b\x85\x29\x84\xf0" "\x4c\xf6\x27\x4c\x0e\x32\x18\xb8\x68\x17\x56\x86\x4d\xb7\xa0\x55"; unsigned char keymic[16] = "\xd5\x35\x53\x82\xb8\xa9\xb8\x06\xdc\xaf\x99\xcd\xaf\x56\x4e\xb6"; unsigned char eapol[256] = "\x01\x03\x00\x75\x02\x01\x0a\x00\x10\x00\x00\x00\x00\x00\x00\x00" "\x01\x59\x16\x8b\xc3\xa5\xdf\x18\xd7\x1e\xfb\x64\x23\xf3\x40\x08" "\x8d\xab\x9e\x1b\xa2\xbb\xc5\x86\x59\xe0\x7b\x37\x64\xb0\xde\x85" "\x70\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x16\x30\x14\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac" "\x04\x01\x00\x00\x0f\xac\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; unsigned char bssid[6] = "\x00\x14\x6c\x7e\x40\x80"; unsigned char essid[33] = "Harkonen"; struct WPA_hdsk wpa; /* valid WPA handshake data */ memset(&wpa, 0, sizeof(wpa)); memcpy(&wpa.stmac, &stmac, 6); memcpy(&wpa.snonce, &snonce, 32); memcpy(&wpa.anonce, &anonce, 32); memcpy(&wpa.keymic, &keymic, 16); memcpy(&wpa.eapol, &eapol, 256); wpa.eapol_size = 121; wpa.state = 7; memcpy(&ap->bssid, bssid, 6); memcpy(&ap->essid, essid, 33); unsigned char pmk[32]; memcpy(&pmk, &opmk, 32); unsigned char ptk[80]; memcpy(&ptk, &optk, 80); unsigned char mic[20]; memcpy(&mic, &omic, 20); wpa.keyver = 1; ap->wpa = wpa; calc_mic(ap, pmk, ptk, mic); error += test(pmk, opmk, 32, argv[0]); error += test(ptk, eptk, 80, argv[0]); error += test(mic, emic1, 20, argv[0]); wpa.keyver = 2; ap->wpa = wpa; calc_mic(ap, pmk, ptk, mic); error += test(pmk, opmk, 32, argv[0]); error += test(ptk, eptk, 80, argv[0]); error += test(mic, emic2, 20, argv[0]); return error; }
C
aircrack-ng/test/cryptounittest/test-calc-pmk.c
/* * * test-calc-pmk.c * * Copyright (C) 2012 Carlos Alberto Lopez Perez <clopez@igalia.com> * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <stdio.h> #include <string.h> #include <stdlib.h> #include "aircrack-ng/crypto/crypto.h" #include "tests.h" #define PLEN 32 //40 #define KLEN 14 int main(int argc, char ** argv) { if (argc < 1) return 1; int error = 0; static unsigned char input[PLEN] = "\x72\xea\x7c\xf3\x62\xd0\x63\xb6\xf6\x3b\xd6\xfc\x1c\x6c\xc0\x18" "\xd0\x10\x23\xd6\x86\x4e\x04\xf0\x0e\xc7\x34\xca\x66\x34\x01\xac" /* "\x46\xd4\x7d\x15\x24\xa7\xaa\xb0" */; static unsigned char expected[PLEN] = "\x1d\x4d\xf5\x5d\xd8\xd9\x13\xf5\x54\x0d\x05\x3c\xdb\x57\x83\x53" "\xd0\x6c\x0f\xb3\x50\x71\x10\xee\x48\xda\xce\x2b\x60\xf6\xd0\xd4" /* "\xc2\x24\x39\x9f\xe8\x1d\x1e\x80" */; static uint8_t key[KLEN] = "\x6E\x9C\x7A\x91\x9F\xB8\xAE\x93\xC1\xAB\x80\x3C\x09\x00"; static uint8_t essid[8] = "T3st1ng"; unsigned char pmk[PLEN]; memcpy(&pmk, &input, PLEN); calc_pmk(key, essid, pmk); error += test(pmk, expected, PLEN, argv[0]); calc_pmk(key, essid, pmk); error += test(pmk, expected, PLEN, argv[0]); return error; }
C
aircrack-ng/test/cryptounittest/test-calc-ptk.c
/* * * test-calc-ptk.c * * Copyright (C) 2012 Carlos Alberto Lopez Perez <clopez@igalia.com> * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <assert.h> #include <stdio.h> #include <string.h> #include <strings.h> #include <stdlib.h> #include "aircrack-ng/defs.h" #include "aircrack-ng/crypto/crypto.h" #include "tests.h" int main(int argc, char ** argv) { if (argc < 1) return 1; int error = 0; static unsigned char opmk[32] = "\xee\x51\x88\x37\x93\xa6\xf6\x8e\x96\x15\xfe\x73\xc8\x0a\x3a\xa6" "\xf2\xdd\x0e\xa5\x37\xbc\xe6\x27\xb9\x29\x18\x3c\xc6\xe5\x79\x25"; static unsigned char ostmac[6] = "\x00\x13\x46\xfe\x32\x0c"; static unsigned char obssid[6] = "\x00\x14\x6c\x7e\x40\x80"; static unsigned char osnonce[32] = "\x59\x16\x8b\xc3\xa5\xdf\x18\xd7\x1e\xfb\x64\x23\xf3\x40\x08\x8d" "\xab\x9e\x1b\xa2\xbb\xc5\x86\x59\xe0\x7b\x37\x64\xb0\xde\x85\x70"; static unsigned char oanonce[32] = "\x22\x58\x54\xb0\x44\x4d\xe3\xaf\x06\xd1\x49\x2b\x85\x29\x84\xf0" "\x4c\xf6\x27\x4c\x0e\x32\x18\xb8\x68\x17\x56\x86\x4d\xb7\xa0\x55"; static unsigned char okeymic[20] = "\xd5\x35\x53\x82\xb8\xa9\xb8\x06\xdc\xaf\x99\xcd\xaf\x56\x4e\xb6" "\x00\x00\x00\x00"; static unsigned char optk[80] = "\x0d\xde\xae\x80\x83\xf9\x2c\xa9\xaf\xdb\x25\x0d\xde\xe5\x25\x1b" "\xc0\xee\xb4\x7e\xf2\x2a\xf7\x9e\x25\x34\x6e\x8b\x73\xe2\xca\x7d" "\x94\xb0\x60\x5f\x2e\xed\x66\xd8\x60\x76\xb3\x38\xa6\x65\xfe\xe3" "\x9f\xde\x22\x1e\xb1\x38\x6b\x3d\xa7\xac\x6a\xbe\x7e\xe0\x00\x1f" "\xbd\x92\xab\xec\xc8\xba\x49\xf0\x5d\xff\x8f\x50\x1e\xfa\xaa\xcc"; static unsigned char eptk[80] = "\xea\x0e\x40\x46\x33\xc8\x02\x45\x03\x02\x86\x8c\xca\xa7\x49\xde" "\x5c\xba\x5a\xbc\xb2\x67\xe2\xde\x1d\x5e\x21\xe5\x7a\xcc\xd5\x07" "\x9b\x31\xe9\xff\x22\x0e\x13\x2a\xe4\xf6\xed\x9e\xf1\xac\xc8\x85" "\x45\x82\x5f\xc3\x2e\xe5\x59\x61\x39\x5a\xe4\x37\x34\xd6\xc1\x07" "\x98\xef\x5a\xfe\x42\xc0\x74\x26\x47\x18\x68\xa5\x77\xd4\xd1\x7e"; static unsigned char oeapol[256] = "\x01\x03\x00\x75\x02\x01\x0a\x00\x10\x00\x00\x00\x00\x00\x00\x00" "\x01\x59\x16\x8b\xc3\xa5\xdf\x18\xd7\x1e\xfb\x64\x23\xf3\x40\x08" "\x8d\xab\x9e\x1b\xa2\xbb\xc5\x86\x59\xe0\x7b\x37\x64\xb0\xde\x85" "\x70\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x16\x30\x14\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac" "\x04\x01\x00\x00\x0f\xac\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; unsigned char pmk[32]; memcpy(&pmk, &opmk, 32); struct WPA_ST_info l_wpa; struct WPA_ST_info * wpa = &l_wpa; // default to zero bzero(wpa, sizeof(struct WPA_ST_info)); memcpy(wpa->stmac, &ostmac, 6); memcpy(wpa->bssid, &obssid, 6); memcpy(wpa->ptk, &optk, 80); memcpy(wpa->anonce, &oanonce, 32); // not valid_ptk if ((1 == 1) == (calc_ptk(wpa, pmk))) error++; error += test(pmk, opmk, 32, argv[0]); error += test(wpa->ptk, optk, 80, argv[0]); // calc another one wpa->eapol_size = 121; memcpy(wpa->eapol, &oeapol, 256); memcpy(wpa->keymic, &okeymic, 20); memcpy(wpa->snonce, &osnonce, 32); // valid ptk if ((1 == 1) != (calc_ptk(wpa, pmk))) error++; error += test(pmk, opmk, 32, argv[0]); error += test(wpa->ptk, eptk, 80, argv[0]); return error; }
C
aircrack-ng/test/cryptounittest/test-cipher-arcfour.c
/** * \file test-cipher-arcfour.c * * \brief The ARCFOUR stream cipher unit-tests * * \warning ARCFOUR is considered a weak cipher and its use constitutes a * security risk! We recommend considering stronger ciphers instead! * * \copyright 2022 Joseph Benden <joe@benden.us> * * \license GPL-2.0-OR-LATER */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <stdint.h> #include <stdio.h> #include <string.h> #include <strings.h> #include <stdlib.h> #include "aircrack-ng/crypto/crypto.h" #include "tests.h" // clang-format off /* * ARC4 tests vectors as posted by Eric Rescorla in sep. 1994: * * http://groups.google.com/group/comp.security.misc/msg/10a300c9d21afca0 */ static const uint8_t arc4_test_key[3][8] = {{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}, {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; static const uint8_t arc4_test_pt[3][8] = {{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; static const uint8_t arc4_test_ct[3][8] = {{0x75, 0xB7, 0x87, 0x80, 0x99, 0xE0, 0xC5, 0x96}, {0x74, 0x94, 0xC2, 0xE7, 0x10, 0x4B, 0x08, 0x79}, {0xDE, 0x18, 0x89, 0x41, 0xA3, 0x37, 0x5D, 0x3A}}; // clang-format on int main(int argc, char ** argv) { int i, error = 0; uint8_t ibuf[8]; uint8_t obuf[8]; Cipher_RC4_KEY ctx; (void) argc; for (i = 0; i < 3; i++) { memcpy(ibuf, arc4_test_pt[i], 8); Cipher_RC4_set_key(&ctx, 8, arc4_test_key[i]); Cipher_RC4(&ctx, 8, ibuf, obuf); error |= test(obuf, (uint8_t *) arc4_test_ct[i], 8, argv[0]); } return error; }
C
aircrack-ng/test/cryptounittest/test-decrypt-ccmp.c
/* * * test-decrypt-ccmp.c * * Copyright (C) 2012 Carlos Alberto Lopez Perez <clopez@igalia.com> * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <stdio.h> #include <string.h> #include <strings.h> #include <stdlib.h> #include "aircrack-ng/crypto/crypto.h" #include "tests.h" #define BUFFER_SIZE 65536 int main(int argc, char ** argv) { if (argc < 1) return 1; int error = 0; int caplen1 = 81; unsigned char tk1[16] = "\x1d\x03\x5e\x8b\xeb\x4f\x83\x61\x1d\xc9\x3e\x26\x57\xce\xcf\x69"; unsigned char h80211[1496] = "\x08\x41\x02\x01\x00\x0b\x86\xc2\xa4\x85\x00\x13\xce\x55\x98\xef" "\x00\x0f\x66\xe3\xe4\x01\x20\x2e\x01\x00\x00\x20\x00\x00\x00\x00" "\x95\xc3\x1e\x2d\x02\x01\x58\x9f\x4d\xeb\xe2\x27\xc4\xe9\xc2\x1d" "\xb1\x2c\x7a\x66\x6a\x35\x80\x8a\xbe\x1e\x73\x8d\xab\x1d\xa3\x6b" "\xa0\xf3\x16\x81\x70\x9a\x94\xf0\xb6\x53\x2c\xd6\x93\x5b\x14\x13" "\x59\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x41\xe2\x61\x88\x6d\xb4\xde\x64\x11\x22\xc7\xc2\x24\x02\x60" "\x51\x00\x00\x30\x82\x09\x57\x76\x59\xa9\xd2\x35\x57\x73\x12\xc4" "\x69\x34\x0f\xd0\x2c\x1f\x55\xa9\xcf\x6a\xc3\x08\x03\x6f\xa1\x4a" "\x9e\xa6\xef\x71\x6d\xb6\x2f\xcc\x0c\xbb\x40\x6e\x90\x1d\x3e\xa2" "\x53\xf9\x26\x71\x65\x02\x47\xd1\xb6\xb1\x01\xd9\x48\x80\xcd\x6c" "\x65\x75\x5b\xf4\x95\x1a\x68\xae\xdf\x8b\x8d\xbb\x5f\x4f\xd5\x8b" "\x66\xb1\x3c\x72\x16\xe8\x5b\x70\x6f\x1b\xdd\xa7\x8a\xd8\x24\xed" "\xc9\x77\x1a\xa0\x74\x36\x3e\x70\x5b\x52\xbd\x7c\x11\x50\x60\x1d" "\x24\x85\x8b\x8a\xb3\x63\x5c\x5b\x09\x94\xaf\xa5\xe8\xc4\xae\x65" "\x92\xa8\x26\xfd\x28\x43\x37\x4c\x6d\x19\x79\x14\x95\x40\x5a\xf6" "\x98\xb7\xd7\x79\xfb\xfe\xbd\x0c\xc5\xf8\x77\xaf\x98\x9e\xf4\xad" "\xce\x40\xcc\x28\xeb\xc6\xa9\xd7\xf9\x98\xfc\xbb\xc3\x66\x94\x4e" "\xea\x6e\xdd\x30\x3b\x65\x6b\xfd\x05\xa8\x68\x2e\x7e\xaa\x43\xe4" "\x65\x26\x11\x83\x86\xe1\x68\x15\x90\xdf\x81\x5c\x01\xdf\x3d\x85" "\x56\x34\x14\x31\x2a\xbf\x6f\xb5\xd6\xcf\xbe\xe9\x07\xc9\x36\xe7" "\x31\x83\x5b\xfa\x4a\x29\x62\xfe\x76\x40\xed\x64\xb8\x2a\xc7\x3c" "\xb5\x76\xd9\x07\x2b\x3a\xde\xc1\xaa\xaa\xd5\x24\xbf\x74\x91\xd9" "\x1a\xb3\x93\x83\xda\xa6\xb0\xd2\xc7\xbe\x0c\xdd\x17\x87\xff\xa2" "\x21\x95\xe9\x08\x3b\x97\xde\x62\x3c\x17\x7c\xf1\xfc\x58\x21\x8f" "\x11\x28\x79\xed\x9e\xa5\x4a\xb3\x48\x8a\xf6\xcd\xd1\xb4\x54\xe6" "\xfc\x5b\x87\xd6\x81\x67\x14\x0a\xd4\x4e\xf6\x7a\x66\xc1\x87\xc3" "\x9e\xb0\xbe\x15\xb4\xb8\xca\x6a\x54\x80\x72\x23\xdf\x10\x70\x4a" "\xb5\x6b\xef\x56\x94\x96\xc0\x65\x79\x14\xc0\xc5\x88\x26\x52\xa0" "\x32\xd0\xe2\x2e\x9a\x31\x36\xf1\x4b\x29\x2e\x68\x6c\x07\x67\x36" "\xc0\x43\xe3\x95\xea\x90\xce\xe2\x2d\x34\x3d\x96\x29\x1f\xb4\x4d" "\x61\x8d\xd5\xdb\xde\xce\x65\xcc\xfc\x0e\x30\xa0\xfb\x92\xd2\xd0" "\xac\x9f\x6b\xe4\xf2\x2f\x86\xf6\x91\xd6\x18\x97\x68\x27\xd1\x4b" "\x4f\x92\xda\x63\x32\xbf\x0f\x95\x8a\x10\xb0\xc5\xc2\x5a\xa9\x31" "\x67\x8f\x23\x21\xc5\x96\x97\x2d\x14\x46\xbb\x3f\x82\x4a\x31\x0a" "\x6c\x0f\x21\xab\x52\x4b\x9c\x89\xdf\x00\xbb\x80\x4f\xa8\x78\xe6" "\x9b\x0a\x96\xb8\x81\x03\x74\x93\x32\xc8\x3a\x72\x31\x58\x72\xec" "\xab\x33\x60\xeb\x0c\xb4\x35\x7e\x40\x0c\x74\x24\xb1\xd9\x84\xc6" "\x3d\x88\x6f\x7d\x8c\xfd\xe2\x59\xb5\x24\xe1\x9b\xbf\x84\xf6\x43" "\x67\x95\x88\x52\x87\x82\x47\xc2\x3f\xae\x56\x2a\x31\xd9\x07\x27" "\x01\xc6\xef\x0a\x12\x38\x03\x93\x91\x9c\xaa\xc6\x14\x3a\x1b\x26" "\x6e\x16\x0b\xb1\xc1\xef\x8d\x0c\xa8\x82\xc4\x5a\x28\xd4\xd0\x46" "\x90\xc9\xbc\xac\x37\x68\x03\xbe\x6f\x4f\x60\x6f\xee\xb8\x34\x03" "\x3a\x7d\xd0\x9f\xc9\x8d\x95\xc1\x0f\x3d\xc8\xeb\x84\xfe\x42\xd7" "\xf2\xae\x14\xf0\x1b\xcf\x95\x23\x54\xb7\x2e\x68\x79\xe2\xf3\x22" "\xe7\x6f\x51\x5e\xa2\xe3\xd3\xb5\x6d\xea\x77\xc0\xb3\xbc\x4f\x55" "\xf2\x04\xc8\x63\x14\x8d\x17\xd6\x7f\x79\x8d\x95\xd3\x76\x35\x3a" "\x09\xe4\xb8\x08\xe1\xfb\xe1\xf5\xb7\xc4\x7a\x66\xfb\xe6\x59\xc2" "\x9b\x60\xc5\xe5\xb1\x47\xcc\x12\xdc\xb7\x1f\x9e\xb8\x55\xfb\x5d" "\x01\xcf\x69\x2a\x85\x55\x55\xe9\x67\x64\x39\x66\xda\xe0\x94\x7f" "\xe4\xd1\xd9\x3e\xbd\x54\x13\x1c\xd6\x49\xdd\x22\xdf\xba\xce\x0b" "\xc6\x09\x9f\x17\xea\xea\xdd\x90\x25\xec\xa4\xb1\x31\x79\x53\x60" "\x14\x17\xe3\xe0\x17\x35\x88\x71\xc6\xd5\xe1\x74\x4c\xd0\xb8\xec" "\xdd\xd2\x8f\x39\xe6\xb4\xe4\xfd\x39\xf0\x5b\x56\xce\xe5\x0d\x9c" "\x72\x22\x81\x4e\x9c\xa5\x3b\x6b\x03\x66\x45\x31\xe9\x40\x52\x3b" "\x30\x37\x8c\xb1\xb9\xdb\xdd\x0f\xda\x23\x44\xb8\xd0\x67\x45\xf0" "\x1f\x36\x81\x7b\xc5\x7a\x3d\x71\xe3\xe0\xcc\xe0\x43\x21\x42\x67" "\xc7\x35\x75\x12\x43\x38\x7f\x20\x5b\xab\xda\x6c\xfc\x86\x08\xdb" "\x05\xb8\x73\x2b\x37\x32\xeb\x86\xe0\x9d\xc4\xba\xcb\x19\x41\x5a" "\xb0\xf7\xa8\x41\xb5\xd5\x84\x1a\x07\x78\x0d\x8a\x6c\x52\xb0\xac" "\xaa\x7f\x36\x65\x21\x90\xf1\xf6\x04\x39\x57\x89\xfa\x8b\xbc\xf8" "\x2f\x5a\xe6\x51\xe7\x48\x5f\xdb\x57\xfa\x2b\x85\x64\x74\xb0\x0d" "\x83\x51\x31\x1e\x59\x8b\x5c\x9b\xb8\xc8\x09\x56\x1c\x40\x78\xee" "\x8d\xd6\x69\xbd\x72\x5a\x51\xfb\x97\x03\x17\xe5\x14\xa6\xde\x2f" "\x48\x5b\xf0\xe8\xec\xb2\x6a\x91\x59\x6a\x05\xcb\x4b\xe4\xd2\x9b" "\x4c\xc6\x91\xf1\xe4\x04\xa0\xd3\xf6\xee\x2f\x45\xde\x11\x58\x36" "\xff\x44\x75\x9f\x86\xf6\x09\x35\xba\xfe\x2d\x5c\x93\x80\x21\x3e" "\xa0\xa8\x68\x39\x56\xa6\x23\xe9\x4a\x34\xd7\x67\x24\x5d\x56\x8d" "\xa8\x43\x4d\xe5\xc7\x2a\xee\x36\x91\xec\x79\xbd\x10\x24\xe0\x79" "\xc8\xca\xe9\xbb\x38\x81\x69\xd2\x35\x2c\xcf\x49\x20\x08\x73\xd0" "\x98\x45\xda\x7a\xfd\x6f\xf6\x0c\xee\xbd\xcd\x7f\x48\x6e\xfd\x54" "\xc4\xe3\x0b\xb8\x9a\xc0\xf1\x10\x14\xb7\x3c\x79\x0d\xd5\x9a\x95" "\x56\x47\x8b\x94\xda\x01\xa8\x5a\x2a\xa0\x06\x66\xb7\x51\xe3\x7c" "\x3a\xe6\x1e\x2a\x11\x17\x27\xb9\x37\x0c\xa3\x64\xf6\x29\x00\xdf" "\xd8\x24\xe1\x18\x43\xc0\xbb\xd2\x7c\x50\x5d\xf3\x79\x4e\xd6\x54" "\x93\x5e\x35\x88\xa6\x13\x1e\x98\x38\xa8\x73\xc9\xc6\x88\xc0\xdb" "\x4c\xc8\xbc\x8c\x32\x41\x84\x57\x15\x33\x4b\x60\x7f\xb2\x3f\x85" "\xfe\x5a\x5a\x9f\xf1\x9f\x6c\x76\x33\x41\x13\x8f\x90\x3f\x45\x5a" "\xcc\x81\x03\xa5\x82\x5a\xca\xec\xae\x5b\xc8\x17\xc2\x18\x9b\xa3" "\x99\x0e\x07\x4e\xd2\xa7\xa2\x5a\x24\xd4\xf2\x3a\x6e\x15\x1d\x21" "\x21\x28\xd6\x62\xf6\x90\x80\xbb\xf4\xdb\xf9\x76\xb8\xd9\xeb\xb4" "\xe5\x13\xb6\x1e\x42\x22\x7c\xc4\xdb\xff\xe8\xbb\xf2\xf1\xd3\x4d" "\x18\xcf\xa8\xfd\xd7\xd0\x34\x24\xf2\x5d\xb2\x1c\x6a\x05\x07\xd5" "\xc9\xff\xc0\xe2\x96\xa3\x68\x53\x3f\xba\x0e\x07\xbd\x37\xf7\x5f" "\xae\x5d\x7c\x5e\x3b\x56\x1a\x51\xac\xa8\x46\x4a\x77\xc8\x6a\xc1" "\x68\x49\x11\xa0\x47\x64\x1f\x75\x95\xf2\x26\xf1\x0e\x44\x0b\x62" "\x8c\x81\x31\x75\x0b\xc0\x24\x64\x4b\xad\x2f\x19\x98\xad\x68\xc1" "\xba\x71\xd2\xa1\xc4\xc7\xa9\x9e\xc8\xba\x5d\x9a\xe4\x0b\xd1\x48" "\xb3\x27\xaa\xe7\xf1\x40\xb4\x28\x2d\xac\x38\x68\x14\xc8\xb8\xe2" "\xd4\x4c\xd4\xfa\x2f\x69\x2b\xf5\xaf\x10\x3d\x13\x21\x26\x94\x0b" "\x4c\xb2\x5f\x99\xac\x04\x88\x74\x43\x76\x75\x4c\x27\x5c\x36\xee" "\x32\x75\x3e\x55\x38\xc7\xd5\x76\x9d\xbd\xfc\xa3\x55\x08\xbf\x3a" "\xb3\x82\x89\xb3\x0d\x3e\x54\xbc\x30\xfa\xb7\xc3\xf9\x9f\xbe\xfc" "\x87\x89\x3c\x6d\x0b\x69\x7b\xbf"; unsigned char expected[1496] = "\x08\x41\x02\x01\x00\x0b\x86\xc2\xa4\x85\x00\x13\xce\x55\x98\xef" "\x00\x0f\x66\xe3\xe4\x01\x20\x2e\x01\x00\x00\x20\x00\x00\x00\x00" "\xaa\xaa\x03\x00\x00\x00\x08\x00\x45\x00\x00\x21\x6a\x12\x00\x00" "\x01\x01\xf7\x43\xac\x10\x00\x65\xac\x10\x00\x01\x08\x00\x26\x67" "\x04\x00\x03\x00\x44\x48\x43\x50\x43\x34\x65\x66\x21\x68\xa8\xc7" "\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x41\xe2\x61\x88\x6d\xb4\xde\x64\x11\x22\xc7\xc2\x24\x02\x60" "\x51\x00\x00\x30\x82\x09\x57\x76\x59\xa9\xd2\x35\x57\x73\x12\xc4" "\x69\x34\x0f\xd0\x2c\x1f\x55\xa9\xcf\x6a\xc3\x08\x03\x6f\xa1\x4a" "\x9e\xa6\xef\x71\x6d\xb6\x2f\xcc\x0c\xbb\x40\x6e\x90\x1d\x3e\xa2" "\x53\xf9\x26\x71\x65\x02\x47\xd1\xb6\xb1\x01\xd9\x48\x80\xcd\x6c" "\x65\x75\x5b\xf4\x95\x1a\x68\xae\xdf\x8b\x8d\xbb\x5f\x4f\xd5\x8b" "\x66\xb1\x3c\x72\x16\xe8\x5b\x70\x6f\x1b\xdd\xa7\x8a\xd8\x24\xed" "\xc9\x77\x1a\xa0\x74\x36\x3e\x70\x5b\x52\xbd\x7c\x11\x50\x60\x1d" "\x24\x85\x8b\x8a\xb3\x63\x5c\x5b\x09\x94\xaf\xa5\xe8\xc4\xae\x65" "\x92\xa8\x26\xfd\x28\x43\x37\x4c\x6d\x19\x79\x14\x95\x40\x5a\xf6" "\x98\xb7\xd7\x79\xfb\xfe\xbd\x0c\xc5\xf8\x77\xaf\x98\x9e\xf4\xad" "\xce\x40\xcc\x28\xeb\xc6\xa9\xd7\xf9\x98\xfc\xbb\xc3\x66\x94\x4e" "\xea\x6e\xdd\x30\x3b\x65\x6b\xfd\x05\xa8\x68\x2e\x7e\xaa\x43\xe4" "\x65\x26\x11\x83\x86\xe1\x68\x15\x90\xdf\x81\x5c\x01\xdf\x3d\x85" "\x56\x34\x14\x31\x2a\xbf\x6f\xb5\xd6\xcf\xbe\xe9\x07\xc9\x36\xe7" "\x31\x83\x5b\xfa\x4a\x29\x62\xfe\x76\x40\xed\x64\xb8\x2a\xc7\x3c" "\xb5\x76\xd9\x07\x2b\x3a\xde\xc1\xaa\xaa\xd5\x24\xbf\x74\x91\xd9" "\x1a\xb3\x93\x83\xda\xa6\xb0\xd2\xc7\xbe\x0c\xdd\x17\x87\xff\xa2" "\x21\x95\xe9\x08\x3b\x97\xde\x62\x3c\x17\x7c\xf1\xfc\x58\x21\x8f" "\x11\x28\x79\xed\x9e\xa5\x4a\xb3\x48\x8a\xf6\xcd\xd1\xb4\x54\xe6" "\xfc\x5b\x87\xd6\x81\x67\x14\x0a\xd4\x4e\xf6\x7a\x66\xc1\x87\xc3" "\x9e\xb0\xbe\x15\xb4\xb8\xca\x6a\x54\x80\x72\x23\xdf\x10\x70\x4a" "\xb5\x6b\xef\x56\x94\x96\xc0\x65\x79\x14\xc0\xc5\x88\x26\x52\xa0" "\x32\xd0\xe2\x2e\x9a\x31\x36\xf1\x4b\x29\x2e\x68\x6c\x07\x67\x36" "\xc0\x43\xe3\x95\xea\x90\xce\xe2\x2d\x34\x3d\x96\x29\x1f\xb4\x4d" "\x61\x8d\xd5\xdb\xde\xce\x65\xcc\xfc\x0e\x30\xa0\xfb\x92\xd2\xd0" "\xac\x9f\x6b\xe4\xf2\x2f\x86\xf6\x91\xd6\x18\x97\x68\x27\xd1\x4b" "\x4f\x92\xda\x63\x32\xbf\x0f\x95\x8a\x10\xb0\xc5\xc2\x5a\xa9\x31" "\x67\x8f\x23\x21\xc5\x96\x97\x2d\x14\x46\xbb\x3f\x82\x4a\x31\x0a" "\x6c\x0f\x21\xab\x52\x4b\x9c\x89\xdf\x00\xbb\x80\x4f\xa8\x78\xe6" "\x9b\x0a\x96\xb8\x81\x03\x74\x93\x32\xc8\x3a\x72\x31\x58\x72\xec" "\xab\x33\x60\xeb\x0c\xb4\x35\x7e\x40\x0c\x74\x24\xb1\xd9\x84\xc6" "\x3d\x88\x6f\x7d\x8c\xfd\xe2\x59\xb5\x24\xe1\x9b\xbf\x84\xf6\x43" "\x67\x95\x88\x52\x87\x82\x47\xc2\x3f\xae\x56\x2a\x31\xd9\x07\x27" "\x01\xc6\xef\x0a\x12\x38\x03\x93\x91\x9c\xaa\xc6\x14\x3a\x1b\x26" "\x6e\x16\x0b\xb1\xc1\xef\x8d\x0c\xa8\x82\xc4\x5a\x28\xd4\xd0\x46" "\x90\xc9\xbc\xac\x37\x68\x03\xbe\x6f\x4f\x60\x6f\xee\xb8\x34\x03" "\x3a\x7d\xd0\x9f\xc9\x8d\x95\xc1\x0f\x3d\xc8\xeb\x84\xfe\x42\xd7" "\xf2\xae\x14\xf0\x1b\xcf\x95\x23\x54\xb7\x2e\x68\x79\xe2\xf3\x22" "\xe7\x6f\x51\x5e\xa2\xe3\xd3\xb5\x6d\xea\x77\xc0\xb3\xbc\x4f\x55" "\xf2\x04\xc8\x63\x14\x8d\x17\xd6\x7f\x79\x8d\x95\xd3\x76\x35\x3a" "\x09\xe4\xb8\x08\xe1\xfb\xe1\xf5\xb7\xc4\x7a\x66\xfb\xe6\x59\xc2" "\x9b\x60\xc5\xe5\xb1\x47\xcc\x12\xdc\xb7\x1f\x9e\xb8\x55\xfb\x5d" "\x01\xcf\x69\x2a\x85\x55\x55\xe9\x67\x64\x39\x66\xda\xe0\x94\x7f" "\xe4\xd1\xd9\x3e\xbd\x54\x13\x1c\xd6\x49\xdd\x22\xdf\xba\xce\x0b" "\xc6\x09\x9f\x17\xea\xea\xdd\x90\x25\xec\xa4\xb1\x31\x79\x53\x60" "\x14\x17\xe3\xe0\x17\x35\x88\x71\xc6\xd5\xe1\x74\x4c\xd0\xb8\xec" "\xdd\xd2\x8f\x39\xe6\xb4\xe4\xfd\x39\xf0\x5b\x56\xce\xe5\x0d\x9c" "\x72\x22\x81\x4e\x9c\xa5\x3b\x6b\x03\x66\x45\x31\xe9\x40\x52\x3b" "\x30\x37\x8c\xb1\xb9\xdb\xdd\x0f\xda\x23\x44\xb8\xd0\x67\x45\xf0" "\x1f\x36\x81\x7b\xc5\x7a\x3d\x71\xe3\xe0\xcc\xe0\x43\x21\x42\x67" "\xc7\x35\x75\x12\x43\x38\x7f\x20\x5b\xab\xda\x6c\xfc\x86\x08\xdb" "\x05\xb8\x73\x2b\x37\x32\xeb\x86\xe0\x9d\xc4\xba\xcb\x19\x41\x5a" "\xb0\xf7\xa8\x41\xb5\xd5\x84\x1a\x07\x78\x0d\x8a\x6c\x52\xb0\xac" "\xaa\x7f\x36\x65\x21\x90\xf1\xf6\x04\x39\x57\x89\xfa\x8b\xbc\xf8" "\x2f\x5a\xe6\x51\xe7\x48\x5f\xdb\x57\xfa\x2b\x85\x64\x74\xb0\x0d" "\x83\x51\x31\x1e\x59\x8b\x5c\x9b\xb8\xc8\x09\x56\x1c\x40\x78\xee" "\x8d\xd6\x69\xbd\x72\x5a\x51\xfb\x97\x03\x17\xe5\x14\xa6\xde\x2f" "\x48\x5b\xf0\xe8\xec\xb2\x6a\x91\x59\x6a\x05\xcb\x4b\xe4\xd2\x9b" "\x4c\xc6\x91\xf1\xe4\x04\xa0\xd3\xf6\xee\x2f\x45\xde\x11\x58\x36" "\xff\x44\x75\x9f\x86\xf6\x09\x35\xba\xfe\x2d\x5c\x93\x80\x21\x3e" "\xa0\xa8\x68\x39\x56\xa6\x23\xe9\x4a\x34\xd7\x67\x24\x5d\x56\x8d" "\xa8\x43\x4d\xe5\xc7\x2a\xee\x36\x91\xec\x79\xbd\x10\x24\xe0\x79" "\xc8\xca\xe9\xbb\x38\x81\x69\xd2\x35\x2c\xcf\x49\x20\x08\x73\xd0" "\x98\x45\xda\x7a\xfd\x6f\xf6\x0c\xee\xbd\xcd\x7f\x48\x6e\xfd\x54" "\xc4\xe3\x0b\xb8\x9a\xc0\xf1\x10\x14\xb7\x3c\x79\x0d\xd5\x9a\x95" "\x56\x47\x8b\x94\xda\x01\xa8\x5a\x2a\xa0\x06\x66\xb7\x51\xe3\x7c" "\x3a\xe6\x1e\x2a\x11\x17\x27\xb9\x37\x0c\xa3\x64\xf6\x29\x00\xdf" "\xd8\x24\xe1\x18\x43\xc0\xbb\xd2\x7c\x50\x5d\xf3\x79\x4e\xd6\x54" "\x93\x5e\x35\x88\xa6\x13\x1e\x98\x38\xa8\x73\xc9\xc6\x88\xc0\xdb" "\x4c\xc8\xbc\x8c\x32\x41\x84\x57\x15\x33\x4b\x60\x7f\xb2\x3f\x85" "\xfe\x5a\x5a\x9f\xf1\x9f\x6c\x76\x33\x41\x13\x8f\x90\x3f\x45\x5a" "\xcc\x81\x03\xa5\x82\x5a\xca\xec\xae\x5b\xc8\x17\xc2\x18\x9b\xa3" "\x99\x0e\x07\x4e\xd2\xa7\xa2\x5a\x24\xd4\xf2\x3a\x6e\x15\x1d\x21" "\x21\x28\xd6\x62\xf6\x90\x80\xbb\xf4\xdb\xf9\x76\xb8\xd9\xeb\xb4" "\xe5\x13\xb6\x1e\x42\x22\x7c\xc4\xdb\xff\xe8\xbb\xf2\xf1\xd3\x4d" "\x18\xcf\xa8\xfd\xd7\xd0\x34\x24\xf2\x5d\xb2\x1c\x6a\x05\x07\xd5" "\xc9\xff\xc0\xe2\x96\xa3\x68\x53\x3f\xba\x0e\x07\xbd\x37\xf7\x5f" "\xae\x5d\x7c\x5e\x3b\x56\x1a\x51\xac\xa8\x46\x4a\x77\xc8\x6a\xc1" "\x68\x49\x11\xa0\x47\x64\x1f\x75\x95\xf2\x26\xf1\x0e\x44\x0b\x62" "\x8c\x81\x31\x75\x0b\xc0\x24\x64\x4b\xad\x2f\x19\x98\xad\x68\xc1" "\xba\x71\xd2\xa1\xc4\xc7\xa9\x9e\xc8\xba\x5d\x9a\xe4\x0b\xd1\x48" "\xb3\x27\xaa\xe7\xf1\x40\xb4\x28\x2d\xac\x38\x68\x14\xc8\xb8\xe2" "\xd4\x4c\xd4\xfa\x2f\x69\x2b\xf5\xaf\x10\x3d\x13\x21\x26\x94\x0b" "\x4c\xb2\x5f\x99\xac\x04\x88\x74\x43\x76\x75\x4c\x27\x5c\x36\xee" "\x32\x75\x3e\x55\x38\xc7\xd5\x76\x9d\xbd\xfc\xa3\x55\x08\xbf\x3a" "\xb3\x82\x89\xb3\x0d\x3e\x54\xbc\x30\xfa\xb7\xc3\xf9\x9f\xbe\xfc" "\x87\x89\x3c\x6d\x0b\x69\x7b\xbf"; unsigned char expected_output[BUFFER_SIZE]; unsigned char input[BUFFER_SIZE]; bzero(&expected_output, BUFFER_SIZE); bzero(&input, BUFFER_SIZE); memcpy(&expected_output, expected, sizeof(expected)); memcpy(&input, h80211, sizeof(h80211)); if (!decrypt_ccmp(input, caplen1, tk1)) error++; error += test(input, expected_output, sizeof(expected), argv[0]); return error; }
C
aircrack-ng/test/cryptounittest/test-digest-md5.c
/** * \file test-digest-md5.c * * \brief The MD5 message digest unit-tests * * \warning MD5 is considered a weak message digest and its use constitutes a * security risk! We recommend considering stronger message digests * instead! * * \copyright 2022 Joseph Benden <joe@benden.us> * * \license GPL-2.0-OR-LATER */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <stdint.h> #include <stdio.h> #include <string.h> #include <strings.h> #include <stdlib.h> #include "aircrack-ng/crypto/crypto.h" #include "tests.h" // clang-format off /* * RFC 1321 test vectors */ static const uint8_t md5_test_buf[7][81] = { { "" }, { "a" }, { "abc" }, { "message digest" }, { "abcdefghijklmnopqrstuvwxyz" }, { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" }, { "12345678901234567890123456789012345678901234567890123456789012345678901234567890" } }; static const size_t md5_test_buflen[7] = { 0, 1, 3, 14, 26, 62, 80 }; static const uint8_t md5_test_sum[7][16] = { { 0xD4, 0x1D, 0x8C, 0xD9, 0x8F, 0x00, 0xB2, 0x04, 0xE9, 0x80, 0x09, 0x98, 0xEC, 0xF8, 0x42, 0x7E }, { 0x0C, 0xC1, 0x75, 0xB9, 0xC0, 0xF1, 0xB6, 0xA8, 0x31, 0xC3, 0x99, 0xE2, 0x69, 0x77, 0x26, 0x61 }, { 0x90, 0x01, 0x50, 0x98, 0x3C, 0xD2, 0x4F, 0xB0, 0xD6, 0x96, 0x3F, 0x7D, 0x28, 0xE1, 0x7F, 0x72 }, { 0xF9, 0x6B, 0x69, 0x7D, 0x7C, 0xB7, 0x93, 0x8D, 0x52, 0x5A, 0x2F, 0x31, 0xAA, 0xF1, 0x61, 0xD0 }, { 0xC3, 0xFC, 0xD3, 0xD7, 0x61, 0x92, 0xE4, 0x00, 0x7D, 0xFB, 0x49, 0x6C, 0xCA, 0x67, 0xE1, 0x3B }, { 0xD1, 0x74, 0xAB, 0x98, 0xD2, 0x77, 0xD9, 0xF5, 0xA5, 0x61, 0x1C, 0x2C, 0x9F, 0x41, 0x9D, 0x9F }, { 0x57, 0xED, 0xF4, 0xA2, 0x2B, 0xE3, 0xC9, 0x55, 0xAC, 0x49, 0xDA, 0x2E, 0x21, 0x07, 0xB6, 0x7A } }; // clang-format on int main(int argc, char ** argv) { int i, error = 0; uint8_t md5sum[DIGEST_MD5_MAC_LEN]; (void) argc; for (i = 0; i < 7; i++) { error |= Digest_MD5(md5_test_buf[i], md5_test_buflen[i], md5sum); error |= test(md5sum, md5_test_sum[i], DIGEST_MD5_MAC_LEN, argv[0]); } for (i = 0; i < 7; i++) { error |= Digest_MD5_Vector( 1, (const uint8_t * []){(uint8_t *) &md5_test_buf[i]}, &md5_test_buflen[i], md5sum); error |= test(md5sum, md5_test_sum[i], DIGEST_MD5_MAC_LEN, argv[0]); } return error; }
C
aircrack-ng/test/cryptounittest/test-digest-sha1.c
/** * \file test-digest-sha1.c * * \brief The SHA-1 message digest unit-tests * * \warning SHA-1 is considered a weak message digest and its use constitutes a * security risk! We recommend considering stronger message digests * instead! * * \copyright 2022 Joseph Benden <joe@benden.us> * * \license GPL-2.0-OR-LATER */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <stdint.h> #include <stdio.h> #include <string.h> #include <strings.h> #include <stdlib.h> #include "aircrack-ng/crypto/crypto.h" #include "tests.h" // clang-format off /* * FIPS-180-1 test vectors */ static const unsigned char sha1_test_buf[3][57] = { { "abc" }, { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" }, { "" } }; static const size_t sha1_test_buflen[3] = { 3, 56, 1000 }; static const unsigned char sha1_test_sum[3][20] = { { 0xA9, 0x99, 0x3E, 0x36, 0x47, 0x06, 0x81, 0x6A, 0xBA, 0x3E, 0x25, 0x71, 0x78, 0x50, 0xC2, 0x6C, 0x9C, 0xD0, 0xD8, 0x9D }, { 0x84, 0x98, 0x3E, 0x44, 0x1C, 0x3B, 0xD2, 0x6E, 0xBA, 0xAE, 0x4A, 0xA1, 0xF9, 0x51, 0x29, 0xE5, 0xE5, 0x46, 0x70, 0xF1 }, { 0x34, 0xAA, 0x97, 0x3C, 0xD4, 0xC4, 0xDA, 0xA4, 0xF6, 0x1E, 0xEB, 0x2B, 0xDB, 0xAD, 0x27, 0x31, 0x65, 0x34, 0x01, 0x6F } }; // clang-format on int main(int argc, char ** argv) { int i, error = 0; uint8_t sha1sum[DIGEST_SHA1_MAC_LEN]; (void) argc; for (i = 0; i < 2; i++) { error |= Digest_SHA1(sha1_test_buf[i], sha1_test_buflen[i], sha1sum); error |= test(sha1sum, sha1_test_sum[i], DIGEST_SHA1_MAC_LEN, argv[0]); } for (i = 0; i < 2; i++) { error |= Digest_SHA1_Vector( 1, (const uint8_t * []){(uint8_t *) &sha1_test_buf[i]}, &sha1_test_buflen[i], sha1sum); error |= test(sha1sum, sha1_test_sum[i], DIGEST_SHA1_MAC_LEN, argv[0]); } Digest_SHA1_CTX * ctx = Digest_SHA1_Create(); uint8_t buf[1000]; size_t buflen = sizeof(buf); memset(buf, 'a', buflen); error |= Digest_SHA1_Init(ctx); for (i = 0; i < 1000; i++) { error |= Digest_SHA1_Update(ctx, buf, buflen); } Digest_SHA1_Finish(ctx, sha1sum); error |= test(sha1sum, sha1_test_sum[2], DIGEST_SHA1_MAC_LEN, argv[0]); Digest_SHA1_Destroy(ctx); return error; }
C
aircrack-ng/test/cryptounittest/test-encrypt-ccmp.c
/* * * test-encrypt-ccmp.c * * Copyright (C) 2015 Jorn van Engelen <spamme@quzart.com> * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <stdio.h> #include <string.h> #include <strings.h> #include <stdlib.h> #include "aircrack-ng/crypto/crypto.h" #include "tests.h" #define BUFFER_SIZE 65536 int main(int argc, char ** argv) { int error = 0; int caplen = 44; // CCMP test vector as described in IEEE 802.11(TM)-2012, Section M.6.4. unsigned char tk1[16] = "\xc9\x7c\x1f\x67\xce\x37\x11\x85\x51\x4a\x8a\x19\xf2\xbd\xd5\x2f"; unsigned char pn[6] = "\xb5\x03\x97\x76\xe7\x0c"; unsigned char h80211[44] = "\x08\x48\xc3\x2c\x0f\xd2\xe1\x28\xa5\x7c\x50\x30\xf1\x84\x44\x08" "\xab\xae\xa5\xb8\xfc\xba\x80\x33\xf8\xba\x1a\x55\xd0\x2f\x85\xae" "\x96\x7b\xb6\x2f\xb6\xcd\xa8\xeb\x7e\x78\xa0\x50"; unsigned char expected[60] = "\x08\x48\xc3\x2c\x0f\xd2\xe1\x28\xa5\x7c\x50\x30\xf1\x84\x44\x08" "\xab\xae\xa5\xb8\xfc\xba\x80\x33\x0c\xe7\x00\x20\x76\x97\x03\xb5" "\xf3\xd0\xa2\xfe\x9a\x3d\xbf\x23\x42\xa6\x43\xe4\x32\x46\xe8\x0c" "\x3c\x04\xd0\x19\x78\x45\xce\x0b\x16\xf9\x76\x23"; unsigned char expected_output[BUFFER_SIZE]; unsigned char input[BUFFER_SIZE]; if (argc < 1) return 1; bzero(expected_output, BUFFER_SIZE); bzero(input, BUFFER_SIZE); memcpy(expected_output, expected, sizeof(expected)); memcpy(input, h80211, sizeof(h80211)); caplen = encrypt_ccmp(input, caplen, tk1, pn); if (caplen != sizeof(expected)) error++; error += test(input, expected_output, sizeof(expected), argv[0]); return error; }
C
aircrack-ng/test/cryptounittest/test-encrypt-wep.c
/* * * test-encrypt-wep.c * * Copyright (C) 2012 Carlos Alberto Lopez Perez <clopez@igalia.com> * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <stdio.h> #include <string.h> #include <stdlib.h> #include "aircrack-ng/crypto/crypto.h" #include "tests.h" #define BLEN 256 #define KLEN 13 int main(int argc, char ** argv) { if (argc < 1) return 1; int error = 0; static unsigned char expected[BLEN] = "\x72\xea\x7c\xf3\x62\xd0\x63\xb6\xf6\x3b\xd6\xfc\x1c\x6c\xc0\x18" "\xd0\x10\x23\xd6\x86\x4e\x04\xf0\x0e\xc7\x34\xca\x66\x34\x01\xac" "\x46\xd4\x7d\x15\x24\xa7\xaa\xb0\x06\x01\x4f\x9f\x61\x1c\x4e\x6d" "\x54\x22\x83\x6f\x36\x43\x12\x01\x07\xb8\xdb\x3c\x32\xc6\xe2\x5f" "\x66\x4e\x7e\x55\x4f\x5d\x61\x30\x8a\xb9\xb7\x11\xcb\xae\xe9\x68" "\x66\x10\x7d\xe7\x39\x29\xef\xb0\x69\xca\xec\xcf\x2c\x68\x57\x52" "\x62\x4f\x89\xd6\x58\x05\xe3\x6a\xa1\xd1\xc8\x2c\x0b\x2d\xe4\xc9" "\x73\xd7\xb0\x4f\x65\x57\xa2\x19\xc7\xbf\xa1\xa7\x43\x49\x51\x14" "\xa4\x12\x24\x15\xb1\x71\x39\xde\x5e\x95\x15\xb4\xb9\xb5\x61\x57" "\xbf\x43\x24\xe2\xb8\x9f\x38\x2f\x45\x29\xfa\x95\x80\x18\x0d\x5d" "\x41\x35\x2a\x83\x44\x37\x71\xcb\x80\x3d\x9d\xc4\xdc\xc4\x26\xea" "\x28\xb9\xa7\x2b\x40\x56\x27\xee\xbc\xfa\xf7\x98\x09\x33\xd1\xe3" "\x85\x79\x0d\xd8\x87\xa3\xfe\x8e\x37\xc4\x48\xbf\x66\x86\xfa\x49" "\x0e\x0f\xf2\x82\x42\xfe\x87\xcd\x18\xb0\x8a\x91\xbb\x97\x9b\x4e" "\x92\x36\xb2\x47\x12\xf0\xeb\x09\xdc\x7a\xdf\x60\xdf\xcd\x19\x7c" "\x2d\x72\x4e\x3a\x6d\x8f\x53\x8e\xe1\x03\xeb\x44\x4a\x02\x9f\x52"; static unsigned char key[KLEN] = "\x6E\x9C\x7A\x91\x9F\xB8\xAE\x93\xC1\xAB\x80\x3C\x09"; static unsigned char input[BLEN] = "\x91\xCE\xFF\xF0\x9B\x76\xB1\xC7\xB3\xAE\xE9\xB6\x39\xE2\xE2\xCB" "\x46\xBB\x20\xDA\xEF\x0D\xD8\x65\x75\x37\xFF\x8B\x78\x49\x39\x6E" "\x08\x6D\x93\x0A\x40\xD1\xA7\xE6\x22\x6B\xFF\x94\x21\xA8\x0E\xDB" "\x33\x2B\x4B\x88\x19\x6C\x94\x0E\xF3\xD8\xCC\xCB\xAF\x99\x89\x49" "\x4F\x4B\x42\x4F\xF4\x96\xA6\xD3\xC9\x00\xB7\xC7\x11\x63\x95\x0E" "\x29\x71\x0A\x38\xC2\x04\xDF\xB5\x01\xAA\xCA\x86\x47\x4A\xA3\x41" "\xE6\x1A\x00\xA7\xD6\xFF\xE7\x89\x64\xB5\x38\x2A\x5D\xBC\x13\x94" "\x8E\x0C\x93\xB6\xC8\x4E\x4F\xC6\x06\x9B\xEF\x9B\x56\xE3\x90\x54" "\xCB\x34\x64\x0B\x3D\x12\x02\x62\xFE\xDC\xA8\x8E\x38\xCE\x36\x3A" "\xE8\x4D\xF0\xED\x71\x59\xE5\xED\xA4\xB1\x12\xEB\xD5\x83\xA6\xC9" "\x5C\x76\x98\x8D\x1B\xCB\x3C\x31\xF5\x10\xFE\x40\xCC\x83\x27\xE6" "\xDF\xB9\xE1\x84\xFC\xC3\xCC\x8D\x7A\xA3\xE5\x61\x56\x92\xAD\x7C" "\xA2\x62\x46\x6F\x5C\xA0\x16\xC4\x52\xDB\xF6\x75\xE1\x35\x22\x91" "\xE8\x81\x87\x13\xC1\xC1\x0A\xB0\xBE\x20\xE7\xF5\x55\x55\x0C\xF3" "\x99\x67\x53\xAF\x35\x15\xA9\x48\x72\xD8\xEB\x4A\xCF\x5B\xF5\xB6" "\xBC\x30\x24\xCB\xFD\x6C\x5C\xF5\x62\x5C\xFD\xA5\x65\xD9\xD4\xD7"; unsigned char buffer[BLEN]; memcpy(&buffer, &input, BLEN); encrypt_wep(buffer, BLEN, key, KLEN); error += test(buffer, expected, BLEN, argv[0]); decrypt_wep(buffer, BLEN, key, KLEN); error += test(buffer, input, BLEN, argv[0]); return error; }
C
aircrack-ng/test/cryptounittest/test-kdf-pbkdf2-hmac-sha1.c
/** * \file test-kdf-pbkdf2-hmac-sha1.c * * \brief The PBKDF2 HMAC-SHA-1 unit-tests * * \warning SHA-1 is considered a weak message digest and its use constitutes * a security risk! We recommend considering stronger message digests * instead! * * \copyright 2022 Joseph Benden <joe@benden.us> * * \license GPL-2.0-OR-LATER */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <stdint.h> #include <stdio.h> #include <string.h> #include <strings.h> #include <stdlib.h> #include "aircrack-ng/crypto/crypto.h" #include "tests.h" // clang-format off /* * RFC 6070 test vectors */ struct { uint8_t key[96]; size_t key_len; uint8_t data[128]; size_t data_len; size_t iterations; uint8_t digest[DIGEST_SHA1_MAC_LEN]; } sha1_tests[] = { { "password\0", 8, "salt", 4, 1, {0x0c, 0x60, 0xc8, 0x0f, 0x96, 0x1f, 0x0e, 0x71, 0xf3, 0xa9, 0xb5, 0x24, 0xaf, 0x60, 0x12, 0x06, 0x2f, 0xe0, 0x37, 0xa6} }, { "password\0", 8, "salt", 4, 2, {0xea, 0x6c, 0x01, 0x4d, 0xc7, 0x2d, 0x6f, 0x8c, 0xcd, 0x1e, 0xd9, 0x2a, 0xce, 0x1d, 0x41, 0xf0, 0xd8, 0xde, 0x89, 0x57 } #ifdef EXPENSIVE_TESTS }, { "password\0", 8, "salt", 4, 4096, {0x4b, 0x00, 0x79, 0x01, 0xb7, 0x65, 0x48, 0x9a, 0xbe, 0xad, 0x49, 0xd9, 0x26, 0xf7, 0x21, 0xd0, 0x65, 0xa4, 0x29, 0xc1} }, { "password\0", 8, "salt", 4, 16777216, {0xee, 0xfe, 0x3d, 0x61, 0xcd, 0x4d, 0xa4, 0xe4, 0xe9, 0x94, 0x5b, 0x3d, 0x6b, 0xa2, 0x15, 0x8c, 0x26, 0x34, 0xe9, 0x84} #endif } }; // clang-format on STATIC_ASSERT(ArrayCount(sha1_tests) >= 2u, ensure_at_least_2_entries); int main(int argc, char ** argv) { size_t i; int error = 0; uint8_t sha1sum[DIGEST_SHA1_MAC_LEN]; (void) argc; for (i = 0; i < ArrayCount(sha1_tests); i++) { error |= KDF_PBKDF2_SHA1(sha1_tests[i].key, sha1_tests[i].data, sha1_tests[i].data_len, sha1_tests[i].iterations, sha1sum, DIGEST_SHA1_MAC_LEN); error |= test( sha1sum, sha1_tests[i].digest, DIGEST_SHA1_MAC_LEN, argv[0]); } return error; }
C
aircrack-ng/test/cryptounittest/test-mac-hmac-md5.c
/** * \file test-mac-hmac-md5.c * * \brief The HMAC-MD5 message authentication code unit-tests * * \warning MD5 is considered a weak message digest and its use constitutes a * security risk! We recommend considering stronger message digests * instead! * * \copyright 2022 Joseph Benden <joe@benden.us> * * \license GPL-2.0-OR-LATER */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <stdint.h> #include <stdio.h> #include <string.h> #include <strings.h> #include <stdlib.h> #include "aircrack-ng/crypto/crypto.h" #include "tests.h" // clang-format off /* * RFC 2202 test vectors */ struct { uint8_t key[96]; size_t key_len; uint8_t data[96]; size_t data_len; uint8_t digest[DIGEST_MD5_MAC_LEN]; } md5_tests[] = { { {0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b}, 16, "Hi There", 8, {0x92, 0x94, 0x72, 0x7a, 0x36, 0x38, 0xbb, 0x1c, 0x13, 0xf4, 0x8e, 0xf8, 0x15, 0x8b, 0xfc, 0x9d} }, { "Jefe", 4, "what do ya want for nothing?", 28, {0x75, 0x0c, 0x78, 0x3e, 0x6a, 0xb0, 0xb5, 0x03, 0xea, 0xa8, 0x6e, 0x31, 0x0a, 0x5d, 0xb7, 0x38} #ifdef EXPENSIVE_TESTS }, { {0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa}, 16, {0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd}, 50, {0x56, 0xbe, 0x34, 0x52, 0x1d, 0x14, 0x4c, 0x88, 0xdb, 0xb8, 0xc7, 0x33, 0xf0, 0xe8, 0xb3, 0xf6} }, { {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19}, 25, {0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd}, 50, {0x69, 0x7e, 0xaf, 0x0a, 0xca, 0x3a, 0x3a, 0xea, 0x3a, 0x75, 0x16, 0x47, 0x46, 0xff, 0xaa, 0x79} }, { {0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c}, 16, "Test With Truncation", 20, {0x56, 0x46, 0x1e, 0xf2, 0x34, 0x2e, 0xdc, 0x00, 0xf9, 0xba, 0xb9, 0x95, 0x69, 0x0e, 0xfd, 0x4c} }, { {0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, //32 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, //64 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa}, //80 80, "Test Using Larger Than Block-Size Key - Hash Key First", 54, {0x6b, 0x1a, 0xb7, 0xfe, 0x4b, 0xd7, 0xbf, 0x8f, 0x0b, 0x62, 0xe6, 0xce, 0x61, 0xb9, 0xd0, 0xcd} }, { {0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, //32 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, //64 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa}, //80 80, "Test Using Larger Than Block-Size Key and " "Larger Than One Block-Size Data", 73, {0x6f, 0x63, 0x0f, 0xad, 0x67, 0xcd, 0xa0, 0xee, 0x1f, 0xb1, 0xf5, 0x62, 0xdb, 0x3a, 0xa5, 0x3e} #endif } }; // clang-format on STATIC_ASSERT(ArrayCount(md5_tests) >= 2u, ensure_at_least_2_entries); int main(int argc, char ** argv) { size_t i; int error = 0; uint8_t md5sum[DIGEST_MD5_MAC_LEN]; (void) argc; for (i = 0; i < ArrayCount(md5_tests); i++) { error |= MAC_HMAC_MD5(md5_tests[i].key_len, md5_tests[i].key, md5_tests[i].data_len, md5_tests[i].data, md5sum); error |= test(md5sum, md5_tests[i].digest, DIGEST_MD5_MAC_LEN, argv[0]); } for (i = 0; i < ArrayCount(md5_tests); i++) { error |= MAC_HMAC_MD5_Vector( md5_tests[i].key_len, md5_tests[i].key, 1, (const uint8_t * []){(uint8_t *) &md5_tests[i].data}, &md5_tests[i].data_len, md5sum); error |= test(md5sum, md5_tests[i].digest, DIGEST_MD5_MAC_LEN, argv[0]); } return error; }
C
aircrack-ng/test/cryptounittest/test-mac-hmac-sha1.c
/** * \file test-mac-hmac-sha1.c * * \brief The HMAC-SHA-1 message authentication code unit-tests * * \warning SHA-1 is considered a weak message digest and its use constitutes a * security risk! We recommend considering stronger message digests * instead! * * \copyright 2022 Joseph Benden <joe@benden.us> * * \license GPL-2.0-OR-LATER */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <stdint.h> #include <stdio.h> #include <string.h> #include <strings.h> #include <stdlib.h> #include "aircrack-ng/crypto/crypto.h" #include "tests.h" // clang-format off /* * RFC 2202 test vectors */ struct { uint8_t key[96]; size_t key_len; uint8_t data[96]; size_t data_len; uint8_t digest[DIGEST_SHA1_MAC_LEN]; } sha1_tests[] = { { {0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b}, 20, "Hi There", 8, {0xb6, 0x17, 0x31, 0x86, 0x55, 0x05, 0x72, 0x64, 0xe2, 0x8b, 0xc0, 0xb6, 0xfb, 0x37, 0x8c, 0x8e, 0xf1, 0x46, 0xbe, 0x00} }, { "Jefe", 4, "what do ya want for nothing?", 28, {0xef, 0xfc, 0xdf, 0x6a, 0xe5, 0xeb, 0x2f, 0xa2, 0xd2, 0x74, 0x16, 0xd5, 0xf1, 0x84, 0xdf, 0x9c, 0x25, 0x9a, 0x7c, 0x79} #ifdef EXPENSIVE_TESTS }, { {0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa}, 20, {0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd}, 50, {0x12, 0x5d, 0x73, 0x42, 0xb9, 0xac, 0x11, 0xcd, 0x91, 0xa3, 0x9a, 0xf4, 0x8a, 0xa1, 0x7b, 0x4f, 0x63, 0xf1, 0x75, 0xd3} }, { {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19}, 25, {0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd}, 50, {0x4c, 0x90, 0x07, 0xf4, 0x02, 0x62, 0x50, 0xc6, 0xbc, 0x84, 0x14, 0xf9, 0xbf, 0x50, 0xc8, 0x6c, 0x2d, 0x72, 0x35, 0xda} }, { {0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c}, 20, "Test With Truncation", 20, {0x4c, 0x1a, 0x03, 0x42, 0x4b, 0x55, 0xe0, 0x7f, 0xe7, 0xf2, 0x7b, 0xe1, 0xd5, 0x8b, 0xb9, 0x32, 0x4a, 0x9a, 0x5a, 0x04} }, { {0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, //32 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, //64 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa}, //80 80, "Test Using Larger Than Block-Size Key - Hash Key First", 54, {0xaa, 0x4a, 0xe5, 0xe1, 0x52, 0x72, 0xd0, 0x0e, 0x95, 0x70, 0x56, 0x37, 0xce, 0x8a, 0x3b, 0x55, 0xed, 0x40, 0x21, 0x12} }, { {0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, //32 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, //64 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa}, //80 80, "Test Using Larger Than Block-Size Key and " "Larger Than One Block-Size Data", 73, {0xe8, 0xe9, 0x9d, 0x0f, 0x45, 0x23, 0x7d, 0x78, 0x6d, 0x6b, 0xba, 0xa7, 0x96, 0x5c, 0x78, 0x08, 0xbb, 0xff, 0x1a, 0x91} #endif } }; // clang-format on STATIC_ASSERT(ArrayCount(sha1_tests) >= 2u, ensure_at_least_2_entries); int main(int argc, char ** argv) { size_t i; int error = 0; uint8_t sha1sum[DIGEST_SHA1_MAC_LEN]; (void) argc; for (i = 0; i < ArrayCount(sha1_tests); i++) { error |= MAC_HMAC_SHA1(sha1_tests[i].key_len, sha1_tests[i].key, sha1_tests[i].data_len, sha1_tests[i].data, sha1sum); error |= test( sha1sum, sha1_tests[i].digest, DIGEST_SHA1_MAC_LEN, argv[0]); } for (i = 0; i < ArrayCount(sha1_tests); i++) { error |= MAC_HMAC_SHA1_Vector( sha1_tests[i].key_len, sha1_tests[i].key, 1, (const uint8_t * []){(uint8_t *) &sha1_tests[i].data}, &sha1_tests[i].data_len, sha1sum); error |= test( sha1sum, sha1_tests[i].digest, DIGEST_SHA1_MAC_LEN, argv[0]); } return error; }
C
aircrack-ng/test/cryptounittest/test-mac-hmac-sha256.c
/** * \file test-mac-hmac-sha256.c * * \brief The HMAC-SHA-2-256 message authentication code unit-tests * * \copyright 2022 Joseph Benden <joe@benden.us> * * \license GPL-2.0-OR-LATER */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <stdint.h> #include <stdio.h> #include <string.h> #include <strings.h> #include <stdlib.h> #include "aircrack-ng/crypto/crypto.h" #include "tests.h" // clang-format off /* * RFC 6234 test vectors */ struct { uint8_t key[136]; size_t key_len; uint8_t data[164]; size_t data_len; uint8_t digest[DIGEST_SHA256_MAC_LEN]; } sha256_tests[] = { { {0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b}, 20, "Hi There", 8, {0xB0, 0x34, 0x4C, 0x61, 0xD8, 0xDB, 0x38, 0x53, 0x5C, 0xA8, 0xAF, 0xCE, 0xAF, 0x0B, 0xF1, 0x2B, 0x88, 0x1D, 0xC2, 0x00, 0xC9, 0x83, 0x3D, 0xA7, 0x26, 0xE9, 0x37, 0x6C, 0x2E, 0x32, 0xCF, 0xF7} }, { "Jefe", 4, "what do ya want for nothing?", 28, {0x5B, 0xDC, 0xC1, 0x46, 0xBF, 0x60, 0x75, 0x4E, 0x6A, 0x04, 0x24, 0x26, 0x08, 0x95, 0x75, 0xC7, 0x5A, 0x00, 0x3F, 0x08, 0x9D, 0x27, 0x39, 0x83, 0x9D, 0xEC, 0x58, 0xB9, 0x64, 0xEC, 0x38, 0x43} #ifdef EXPENSIVE_TESTS }, { {0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa}, 20, {0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd}, 50, {0x77, 0x3E, 0xA9, 0x1E, 0x36, 0x80, 0x0E, 0x46, 0x85, 0x4D, 0xB8, 0xEB, 0xD0, 0x91, 0x81, 0xA7, 0x29, 0x59, 0x09, 0x8B, 0x3E, 0xF8, 0xC1, 0x22, 0xD9, 0x63, 0x55, 0x14, 0xCE, 0xD5, 0x65, 0xFE} }, { {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19}, 25, {0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd}, 50, {0x82, 0x55, 0x8A, 0x38, 0x9A, 0x44, 0x3C, 0x0E, 0xA4, 0xCC, 0x81, 0x98, 0x99, 0xF2, 0x08, 0x3A, 0x85, 0xF0, 0xFA, 0xA3, 0xE5, 0x78, 0xF8, 0x07, 0x7A, 0x2E, 0x3F, 0xF4, 0x67, 0x29, 0x66, 0x5B} }, { {0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c}, 20, "Test With Truncation", 20, {0xA3, 0xB6, 0x16, 0x74, 0x73, 0x10, 0x0E, 0xE0, 0x6E, 0x0C, 0x79, 0x6C, 0x29, 0x55, 0x55, 0x2B, 0XFA, 0X6F, 0X7C, 0X0A, 0X6A, 0X8A, 0XEF, 0X8B, 0X93, 0XF8, 0X60, 0XAA, 0XB0, 0XCD, 0X20, 0XC5} }, { {0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, //32 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, //64 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, //96 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, //128 0xaa, 0xaa, 0xaa}, //131 131, "Test Using Larger Than Block-Size Key - Hash Key First", 54, {0x60, 0xE4, 0x31, 0x59, 0x1E, 0xE0, 0xB6, 0x7F, 0x0D, 0x8A, 0x26, 0xAA, 0xCB, 0xF5, 0xB7, 0x7F, 0x8E, 0x0B, 0xC6, 0x21, 0x37, 0x28, 0xC5, 0x14, 0x05, 0x46, 0x04, 0x0F, 0x0E, 0xE3, 0x7F, 0x54} }, { {0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, //32 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, //64 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, //96 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, //128 0xaa, 0xaa, 0xaa}, //131 131, "This is a test using a larger than block-size key and " "a larger than block-size data. The key needs to be hashed " "before being used by the HMAC algorithm.", 152, {0x9B, 0x09, 0xFF, 0xA7, 0x1B, 0x94, 0x2F, 0xCB, 0x27, 0x63, 0x5F, 0xBC, 0xD5, 0xB0, 0xE9, 0x44, 0xBF, 0xDC, 0x63, 0x64, 0x4F, 0x07, 0x13, 0x93, 0x8A, 0x7F, 0x51, 0x53, 0x5C, 0x3A, 0x35, 0xE2} #endif } }; // clang-format on STATIC_ASSERT(ArrayCount(sha256_tests) >= 2u, ensure_at_least_2_entries); int main(int argc, char ** argv) { size_t i; int error = 0; uint8_t sha256sum[DIGEST_SHA256_MAC_LEN]; (void) argc; for (i = 0; i < ArrayCount(sha256_tests); i++) { error |= MAC_HMAC_SHA256(sha256_tests[i].key_len, sha256_tests[i].key, sha256_tests[i].data_len, sha256_tests[i].data, sha256sum); error |= test( sha256sum, sha256_tests[i].digest, DIGEST_SHA256_MAC_LEN, argv[0]); } for (i = 0; i < ArrayCount(sha256_tests); i++) { error |= MAC_HMAC_SHA256_Vector( sha256_tests[i].key_len, sha256_tests[i].key, 1, (const uint8_t * []){(uint8_t *) &sha256_tests[i].data}, &sha256_tests[i].data_len, sha256sum); error |= test( sha256sum, sha256_tests[i].digest, DIGEST_SHA256_MAC_LEN, argv[0]); } return error; }
C/C++
aircrack-ng/test/cryptounittest/tests.h
/* * * tests.h * * Copyright (C) 2012 Carlos Alberto Lopez Perez <clopez@igalia.com> * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * */ int ntest = 1; void hexdump(const unsigned char * buffer, int length) { int i, x = 1; for (i = 0; i < length; i++) { printf("%02x ", buffer[i]); if (x > 15) { x = 0; printf("\n"); } x++; } printf("\n"); } int test(const unsigned char * computed, const unsigned char * expected, int length, const char * name) { int z; int error = 0; for (z = 0; z < length; z++) if (computed[z] != expected[z]) error = 1; if (error == 1) { printf("[%s][Test %d] ERROR: The output don't match. I got:\n", name, ntest++); hexdump(computed, length); printf("And I was expecting:\n"); hexdump(expected, length); } else { printf("[%s][Test %d] OK: Output matches :)\n", name, ntest++); } return error; }
Include
aircrack-ng/test/unit/Makefile.inc
# Aircrack-ng # # Copyright (C) 2018 Joseph Benden <joe@benden.us> # # Autotool support was written by: Joseph Benden <joe@benden.us> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA # # In addition, as a special exception, the copyright holders give # permission to link the code of portions of this program with the # OpenSSL library under certain conditions as described in each # individual source file, and distribute linked combinations # including the two. # # You must obey the GNU General Public License in all respects # for all of the code used other than OpenSSL. # # If you modify file(s) with this exception, you may extend this # exception to your dnl version of the file(s), but you are not obligated # to do so. # # If you dnl do not wish to do so, delete this exception statement from your # version. # # If you delete this exception statement from all source files in the # program, then also delete it here. UNIT_COMMON_CFLAGS = $(PTHREAD_CFLAGS) \ $(CRYPTO_CFLAGS) \ $(ZLIB_CFLAGS) \ $(CMOCKA_CFLAGS) UNIT_COMMON_LDADD = $(PTHREAD_LIBS) \ $(CRYPTO_LDFLAGS) \ $(CRYPTO_LIBS) \ $(ZLIB_LIBS) \ $(LIBAIRCRACK_LIBS) \ $(CMOCKA_LIBS) test_calc_one_pmk_SOURCES = %D%/test-calc-one-pmk.c test_calc_one_pmk_CFLAGS = $(UNIT_COMMON_CFLAGS) test_calc_one_pmk_LDFLAGS = -rdynamic test_calc_one_pmk_LDADD = libaccrypto.la $(LIBAIRCRACK_CE_WPA_LIBS) \ $(UNIT_COMMON_LDADD) test_circular_buffer_SOURCES = %D%/test-circular-buffer.c test_circular_buffer_CFLAGS = $(UNIT_COMMON_CFLAGS) test_circular_buffer_LDFLAGS = -rdynamic test_circular_buffer_LDADD = $(LIBAIRCRACK_LIBS) $(UNIT_COMMON_LDADD) test_circular_queue_SOURCES = %D%/test-circular-queue.c test_circular_queue_CFLAGS = $(UNIT_COMMON_CFLAGS) test_circular_queue_LDFLAGS = -rdynamic test_circular_queue_LDADD = $(LIBAIRCRACK_LIBS) $(UNIT_COMMON_LDADD) test_string_has_suffix_SOURCES = %D%/test-string-has-suffix.c test_string_has_suffix_CFLAGS = $(UNIT_COMMON_CFLAGS) test_string_has_suffix_LDFLAGS = -rdynamic test_string_has_suffix_LDADD = $(LIBAIRCRACK_LIBS) $(UNIT_COMMON_LDADD) test_wpapsk_SOURCES = %D%/test-wpapsk.c test_wpapsk_CFLAGS = "-DLIBAIRCRACK_CE_WPA_PATH=\"$(LIBAIRCRACK_CE_WPA_PATH)\"" \ "-DABS_TOP_SRCDIR=\"$(abs_top_srcdir)\"" \ "-DABS_TOP_BUILDDIR=\"$(abs_top_builddir)\"" \ "-DLIBDIR=\"$(libdir)\"" \ $(UNIT_COMMON_CFLAGS) test_wpapsk_LDFLAGS = -rdynamic test_wpapsk_LDADD = libaccrypto.la $(LIBAIRCRACK_CE_WPA_LIBS) \ $(LIBAIRCRACK_LIBS) \ $(UNIT_COMMON_LDADD) test_wpapsk_cmac_SOURCES = %D%/test-wpapsk-cmac.c test_wpapsk_cmac_CFLAGS = "-DLIBAIRCRACK_CE_WPA_PATH=\"$(LIBAIRCRACK_CE_WPA_PATH)\"" \ "-DABS_TOP_SRCDIR=\"$(abs_top_srcdir)\"" \ "-DABS_TOP_BUILDDIR=\"$(abs_top_builddir)\"" \ "-DLIBDIR=\"$(libdir)\"" \ $(UNIT_COMMON_CFLAGS) test_wpapsk_cmac_LDFLAGS = -rdynamic test_wpapsk_cmac_LDADD = $(LIBAIRCRACK_LIBS) \ $(UNIT_COMMON_LDADD) TESTS += test-calc-one-pmk test-circular-buffer test-circular-queue test-string-has-suffix if !STATIC_BUILD TESTS += test-wpapsk TESTS += test-wpapsk-cmac endif check_PROGRAMS += test-calc-one-pmk test-circular-buffer test-circular-queue test-string-has-suffix if !STATIC_BUILD check_PROGRAMS += test-wpapsk check_PROGRAMS += test-wpapsk-cmac endif
C
aircrack-ng/test/unit/test-calc-one-pmk.c
#ifdef HAVE_CONFIG_H #include "config.h" #endif #include <stdarg.h> #include <stddef.h> #include <setjmp.h> #include <cmocka.h> #include <assert.h> #include <stdio.h> #include <stdlib.h> #include "aircrack-ng/ce-wpa/crypto_engine.h" #include "aircrack-ng/crypto/crypto.h" static void test_calc_one_pmk(void ** state) { (void) state; uint8_t essid[] = "linksys"; uint8_t key[] = "password"; uint8_t pmk[PMK_LEN] = {0}; uint8_t expected[PMK_LEN] = {0xec, 0xc9, 0x99, 0x1e, 0x3c, 0xfb, 0x1b, 0x11, 0x7b, 0xdb, 0xbd, 0x0, 0xde, 0xb4, 0x7, 0xf0, 0x23, 0x29, 0x44, 0xb5, 0x68, 0x21, 0x64, 0x7e, 0x23, 0x49, 0x13, 0x9d, 0x2, 0xfd, 0x2b, 0xfb}; memset(pmk, 0, sizeof(pmk)); ac_crypto_engine_calc_one_pmk(key, essid, strlen((char *) essid), pmk); assert_int_equal(sizeof(pmk), sizeof(expected)); assert_memory_equal(pmk, expected, sizeof(expected)); } static void test_calc_pmk(void ** state) { (void) state; uint8_t essid[33] = "linksys"; wpapsk_password key[MAX_KEYS_PER_CRYPT_SUPPORTED]; ac_crypto_engine_t engine; memset(&engine, 0, sizeof(engine)); ac_crypto_engine_init(&engine); ac_crypto_engine_set_essid(&engine, &essid[0]); ac_crypto_engine_thread_init(&engine, 1); memset(key, 0, sizeof(key)); strcpy((char *) (key[0].v), "password"); key[0].length = 8; ac_crypto_engine_calc_pmk(&engine, key, 1, 1); uint8_t expected[PMK_LEN] = {0xec, 0xc9, 0x99, 0x1e, 0x3c, 0xfb, 0x1b, 0x11, 0x7b, 0xdb, 0xbd, 0x0, 0xde, 0xb4, 0x7, 0xf0, 0x23, 0x29, 0x44, 0xb5, 0x68, 0x21, 0x64, 0x7e, 0x23, 0x49, 0x13, 0x9d, 0x2, 0xfd, 0x2b, 0xfb}; assert_memory_equal((unsigned char *) (engine.thread_data[1]->pmk), expected, sizeof(expected)); ac_crypto_engine_thread_destroy(&engine, 1); ac_crypto_engine_destroy(&engine); } int main(int argc, char * argv[]) { (void) argc; (void) argv; const struct CMUnitTest tests[] = { cmocka_unit_test(test_calc_one_pmk), cmocka_unit_test(test_calc_pmk), }; return cmocka_run_group_tests(tests, NULL, NULL); }
C
aircrack-ng/test/unit/test-circular-buffer.c
#ifdef HAVE_CONFIG_H #include "config.h" #endif #include <stdarg.h> #include <stdbool.h> #include <stddef.h> #include <stdint.h> #include <setjmp.h> #include <cmocka.h> #include "aircrack-ng/adt/circular_buffer.h" static void test_cbuf_init_and_empty(void ** state) { (void) state; // GIVEN #define size 64 uint8_t buffer[size]; // WHEN cbuf_handle_t cbuf = circular_buffer_init(buffer, size, 1); // THEN assert_non_null(cbuf); assert_true(circular_buffer_is_empty(cbuf)); assert_false(circular_buffer_is_full(cbuf)); assert_int_equal(size, circular_buffer_capacity(cbuf)); assert_int_equal(0, circular_buffer_size(cbuf)); // END #undef size circular_buffer_free(cbuf); } static void test_cbuf_byte_size_one_element(void ** state) { (void) state; // GIVEN #define size 2 uint8_t buffer[size]; cbuf_handle_t cbuf = circular_buffer_init(buffer, size, 1); // WHEN circular_buffer_put(cbuf, "a", 1); // THEN assert_int_equal(1, circular_buffer_size(cbuf)); assert_false(circular_buffer_is_empty(cbuf)); assert_false(circular_buffer_is_full(cbuf)); // END #undef size circular_buffer_free(cbuf); } static void test_cbuf_byte_size_two_element(void ** state) { (void) state; // GIVEN #define size 2 uint8_t buffer[size]; cbuf_handle_t cbuf = circular_buffer_init(buffer, size, 1); // WHEN circular_buffer_put(cbuf, "a", 1); circular_buffer_put(cbuf, "b", 1); // THEN assert_int_equal(2, circular_buffer_size(cbuf)); assert_false(circular_buffer_is_empty(cbuf)); assert_true(circular_buffer_is_full(cbuf)); // END #undef size circular_buffer_free(cbuf); } static void test_cbuf_multibyte_compare_buffer(void ** state) { (void) state; // GIVEN #define nb_elements 2 #define elementSize 8 #define size (nb_elements * elementSize) uint8_t buffer[size + 1]; buffer[size] = 0; cbuf_handle_t cbuf = circular_buffer_init(buffer, size, elementSize); // WHEN circular_buffer_put(cbuf, "a1234567", 8); circular_buffer_put(cbuf, "b1234567", 8); // THEN assert_int_equal(nb_elements, circular_buffer_size(cbuf)); assert_false(circular_buffer_is_empty(cbuf)); assert_true(circular_buffer_is_full(cbuf)); assert_memory_equal("a1234567b1234567", buffer, size); // END #undef size #undef elementSize #undef nb_elements circular_buffer_free(cbuf); } static void test_cbuf_multibyte_compare_buffer_of_short_put(void ** state) { (void) state; // GIVEN #define nb_elements 2 #define elementSize 8 #define size (nb_elements * elementSize) uint8_t buffer[size + 1]; buffer[size] = 0; cbuf_handle_t cbuf = circular_buffer_init(buffer, size, elementSize); // WHEN circular_buffer_put(cbuf, "a123", 4); circular_buffer_put(cbuf, "b1234567", 8); // THEN assert_int_equal(nb_elements, circular_buffer_size(cbuf)); assert_false(circular_buffer_is_empty(cbuf)); assert_true(circular_buffer_is_full(cbuf)); assert_memory_equal("a123\0\0\0\0b1234567", buffer, size); // END #undef size #undef elementSize #undef nb_elements circular_buffer_free(cbuf); } static void test_cbuf_multibyte_get_first(void ** state) { (void) state; // GIVEN #define nb_elements 2 #define elementSize 8 #define size (nb_elements * elementSize) uint8_t buffer[size + 1]; buffer[size] = 0; cbuf_handle_t cbuf = circular_buffer_init(buffer, size, elementSize); // WHEN circular_buffer_put(cbuf, "a123", 4); circular_buffer_put(cbuf, "b1234567", 8); uint8_t output[size]; void * p_output = &output[0]; circular_buffer_get(cbuf, &p_output, 8); // THEN assert_memory_equal("a123\0\0\0\0", output, 8); // END #undef size #undef elementSize #undef nb_elements circular_buffer_free(cbuf); } static void test_cbuf_multibyte_get_both(void ** state) { (void) state; // GIVEN #define nb_elements 2 #define elementSize 8 #define size (nb_elements * elementSize) uint8_t buffer[size + 1]; buffer[size] = 0; cbuf_handle_t cbuf = circular_buffer_init(buffer, size, elementSize); // WHEN circular_buffer_put(cbuf, "a123", 4); circular_buffer_put(cbuf, "b1234567", 8); uint8_t output[size]; void * p_output = &output[0]; circular_buffer_get(cbuf, &p_output, 8); // THEN assert_memory_equal("a123\0\0\0\0", output, 8); // AND WHEN circular_buffer_get(cbuf, &p_output, 8); // AND THEN assert_memory_equal("b1234567", output, 8); // END #undef size #undef elementSize #undef nb_elements circular_buffer_free(cbuf); } int main(int argc, char * argv[]) { (void) argc; (void) argv; const struct CMUnitTest tests[] = { cmocka_unit_test(test_cbuf_init_and_empty), cmocka_unit_test(test_cbuf_byte_size_one_element), cmocka_unit_test(test_cbuf_byte_size_two_element), cmocka_unit_test(test_cbuf_multibyte_compare_buffer_of_short_put), cmocka_unit_test(test_cbuf_multibyte_compare_buffer), cmocka_unit_test(test_cbuf_multibyte_get_first), cmocka_unit_test(test_cbuf_multibyte_get_both), }; return cmocka_run_group_tests(tests, NULL, NULL); }
C
aircrack-ng/test/unit/test-circular-queue.c
#ifdef HAVE_CONFIG_H #include "config.h" #endif #include <stdarg.h> #include <stdbool.h> #include <stddef.h> #include <stdint.h> #include <setjmp.h> #include <cmocka.h> #include "aircrack-ng/adt/circular_queue.h" static void test_cqueue_init_and_empty(void ** state) { (void) state; // GIVEN #define size 64 uint8_t buffer[size]; // WHEN cqueue_handle_t cq = circular_queue_init(buffer, size, 1); // THEN assert_non_null(cq); assert_true(circular_queue_is_empty(cq)); assert_false(circular_queue_is_full(cq)); // END #undef size circular_queue_free(cq); } int main(int argc, char * argv[]) { (void) argc; (void) argv; const struct CMUnitTest tests[] = { cmocka_unit_test(test_cqueue_init_and_empty), }; return cmocka_run_group_tests(tests, NULL, NULL); }
C
aircrack-ng/test/unit/test-string-has-suffix.c
#ifdef HAVE_CONFIG_H #include "config.h" #endif #include <stdarg.h> #include <stddef.h> #include <setjmp.h> #include <cmocka.h> #include "aircrack-ng/osdep/byteorder.h" #include "radiotap/platform.h" #include "aircrack-ng/support/common.h" static void test_radiotap_unaligned_access(void ** state) { (void) state; const char bytes[] = {0x00, 0x01, 0x02, 0x00}; assert_true(get_unaligned_le16(bytes + 1) == 0x0201); //-V1032 } static void test_string_has_suffix(void ** state) { (void) state; assert_true(string_has_suffix("", "")); assert_true(!string_has_suffix("", "a")); assert_true(string_has_suffix("a", "")); assert_true(string_has_suffix("a", "a")); assert_true(!string_has_suffix("a", "b")); assert_true(!string_has_suffix("a", "ba")); assert_true(string_has_suffix("abc", "abc")); assert_true(!string_has_suffix("abc", "eeabc")); assert_true(!string_has_suffix("abc", "xbc")); assert_true(!string_has_suffix("abc", "axc")); assert_true(!string_has_suffix("abcdef", "abcxef")); assert_true(!string_has_suffix("abcdef", "abxxef")); assert_true(string_has_suffix("b.a", "")); assert_true(string_has_suffix("b.a", "a")); assert_true(string_has_suffix("b.a", ".a")); assert_true(string_has_suffix("b.a", "b.a")); assert_true(!string_has_suffix("b.a", "x")); assert_true(string_has_suffix("abc.foo.bar", "")); assert_true(string_has_suffix("abc.foo.bar", "r")); assert_true(string_has_suffix("abc.foo.bar", "ar")); assert_true(string_has_suffix("abc.foo.bar", "bar")); assert_true(!string_has_suffix("abc.foo.bar", "xar")); assert_true(string_has_suffix("abc.foo.bar", ".bar")); assert_true(string_has_suffix("abc.foo.bar", "foo.bar")); assert_true(!string_has_suffix("abc.foo.bar", "xoo.bar")); assert_true(!string_has_suffix("abc.foo.bar", "foo.ba")); assert_true(string_has_suffix("abc.foo.bar", ".foo.bar")); assert_true(string_has_suffix("abc.foo.bar", "c.foo.bar")); assert_true(string_has_suffix("abc.foo.bar", "abc.foo.bar")); assert_true(!string_has_suffix("abc.foo.bar", "xabc.foo.bar")); assert_true(!string_has_suffix("abc.foo.bar", "ac.foo.bar")); assert_true(string_has_suffix("abc.foo.foo", ".foo")); assert_true(string_has_suffix("abc.foo.foo", ".foo.foo")); assert_true(string_has_suffix("abcdefgh", "")); assert_true(!string_has_suffix("abcdefgh", " ")); assert_true(string_has_suffix("abcdefgh", "h")); assert_true(string_has_suffix("abcdefgh", "gh")); assert_true(string_has_suffix("abcdefgh", "fgh")); assert_true(!string_has_suffix("abcdefgh", "agh")); assert_true(string_has_suffix("abcdefgh", "abcdefgh")); } int main(int argc, char * argv[]) { (void) argc; (void) argv; const struct CMUnitTest tests[] = { cmocka_unit_test(test_string_has_suffix), cmocka_unit_test(test_radiotap_unaligned_access), }; return cmocka_run_group_tests(tests, NULL, NULL); }
C
aircrack-ng/test/unit/test-wpapsk-cmac.c
/* * Copyright (C) 2018 Joseph Benden <joe@benden.us> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and * NON-INFRINGEMENT. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, * MA 02110-1301, USA. * * In addition, as a special exception, the copyright holders give * permission to link the code of portions of this program with the * OpenSSL library under certain conditions as described in each * individual source file, and distribute linked combinations * including the two. * You must obey the GNU General Public License in all respects * for all of the code used other than OpenSSL. If you modify * file(s) with this exception, you may extend this exception to your * version of the file(s), but you are not obligated to do so. If you * do not wish to do so, delete this exception statement from your * version. If you delete this exception statement from all source * files in the program, then also delete it here. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <stdarg.h> #include <stddef.h> #include <setjmp.h> #include <cmocka.h> #include <assert.h> #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include "aircrack-ng/crypto/crypto.h" #include "aircrack-ng/support/common.h" #include "aircrack-ng/cpu/trampoline.h" #include "aircrack-ng/ce-wpa/crypto_engine.h" #include "aircrack-ng/support/crypto_engine_loader.h" /* * We must force linking to one of the support crypto libraries; however, * because they are linked with our binary and not the crypto engine * DSOs, at run-time we fail to run due to missing symbols. * * The "proper" way to handle this situation is to use --no-as-needed * linker flag, specifying the libraries to always link against. * * Then there is Autoconf... It does not support the above flag. * * So, we force a bit of hacks to ensure we do link against it. */ #ifdef USE_GCRYPT void * keep_libgcrypt_ = (void *) ((uintptr_t) &gcry_md_open); #else void * keep_libcrypto_ = (void *) ((uintptr_t) &HMAC); #endif void perform_unit_testing(void ** state) { (void) state; wpapsk_password key[MAX_KEYS_PER_CRYPT_SUPPORTED]; uint8_t mic[8][20]; uint8_t expected_mic[20] = "\x2e\x13\xc4\x0c\xa1\xc2\xe4\xe2\x03\x7f\x99\xa2\xda\x18\xa4\x6b"; uint8_t stmac[6] = "\x2c\xf0\xa2\xdd\xbc\xd0"; uint8_t snonce[32] = "\x64\x67\x23\x3e\x73\x07\x67\xc3\x3e\x1d\xf8\x75\xc3\xad\x0e\xb5" "\x8a\x51\xad\x70\x4a\x3f\xae\x06\xb8\x18\xc0\xc5\xfc\xeb\xf3\xaf"; uint8_t anonce[32] = "\x02\x18\xc7\xb6\x4e\xce\xf4\x0c\x4f\x15\x91\x5f\xbc\xeb\x19\xc8" "\xd6\x26\x08\x38\x7e\xb6\xb9\x86\xd9\x59\x9a\x8b\xd7\x0d\xc8\x5d"; uint8_t eapol[256] = "\x02\x03\x00\x75\x02\x01\x0B\x00\x10\x00\x00\x00\x00\x00\x00\x00" "\x03\x64\x67\x23\x3E\x73\x07\x67\xC3\x3E\x1D\xF8\x75\xC3\xAD\x0E" "\xB5\x8A\x51\xAD\x70\x4A\x3F\xAE\x06\xB8\x18\xC0\xC5\xFC\xEB\xF3" "\xAF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x16\x30\x14\x01\x00\x00\x0F\xAC\x04\x01\x00\x00\x0F\xAC" "\x04\x01\x00\x00\x0F\xAC\x06\x8C\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; uint32_t eapol_size = 121; ac_crypto_engine_t engine; uint8_t bssid[6] = "\xb0\xb9\x8a\x56\x8d\xea"; uint8_t essid[33] = "Neheb"; int nparallel = dso_ac_crypto_engine_simd_width(); memset(&engine, 0, sizeof(engine)); dso_ac_crypto_engine_init(&engine); dso_ac_crypto_engine_set_essid(&engine, &essid[0]); dso_ac_crypto_engine_thread_init(&engine, 1); dso_ac_crypto_engine_calc_pke(&engine, bssid, stmac, anonce, snonce, 1); // PMK: Ensure single calculator functions memset(key, 0, sizeof(key)); strcpy((char *) (key[0].v), "bo$$password"); key[0].length = 12; uint8_t pmk[40]; memset(pmk, 0, sizeof(pmk)); dso_ac_crypto_engine_calc_one_pmk( key[0].v, essid, strlen((char *) essid), pmk); assert_memory_equal(pmk, "\xfb\x57\x66\x8c\xd3\x38\x37\x44\x12\xc2\x62" "\x08\xd7\x9a\xa5\xc3\x0c\xe4\x0a\x11\x02\x24" "\xf3\xcf\xb5\x92\xa8\xf2\xe8\xbf\x53\xe8", 32); // PMK: Ensure parallel calculator functions memset(key, 0, sizeof(key)); strcpy((char *) (key[0].v), "bo$$password"); key[0].length = 12; dso_ac_crypto_engine_calc_pmk(&engine, key, nparallel, 1); assert_memory_equal(dso_ac_crypto_engine_get_pmk(&engine, 1, 0), "\xfb\x57\x66\x8c\xd3\x38\x37\x44\x12\xc2\x62" "\x08\xd7\x9a\xa5\xc3\x0c\xe4\x0a\x11\x02\x24" "\xf3\xcf\xb5\x92\xa8\xf2\xe8\xbf\x53\xe8", 32); for (int i = 0; i < nparallel; ++i) { int rc = -1; memset(key, 0, sizeof(key)); strcpy((char *) (key[i].v), "bo$$password"); key[i].length = 12; if ((rc = dso_ac_crypto_engine_wpa_crack(&engine, key, eapol, eapol_size, mic, 3, expected_mic, nparallel, 1)) >= 0) { // does the returned SIMD lane equal where we placed the key? assert_int_equal(rc, i); } else { assert_memory_equal(dso_ac_crypto_engine_get_pmk(&engine, 1, i), "\xfb\x57\x66\x8c\xd3\x38\x37\x44\x12\xc2\x62" "\x08\xd7\x9a\xa5\xc3\x0c\xe4\x0a\x11\x02\x24" "\xf3\xcf\xb5\x92\xa8\xf2\xe8\xbf\x53\xe8", 32); assert_memory_equal(dso_ac_crypto_engine_get_ptk(&engine, 1, i), "\x2c\x76\xdc\x59\x2c\x3b\x67\x1b\xac\x23\x0f" "\x6c\x9e\x38\xa0\x62\xa0\xdd\xc9\x8f\x4a\xb4" "\xd6\x12\x90\x22\xfc\x7f\x45\xfe\x92\x64", 32); fail_msg("%s", "While PMK and PTK computed correctly, MIC, etc. failed."); } } dso_ac_crypto_engine_thread_destroy(&engine, 1); dso_ac_crypto_engine_destroy(&engine); } void perform_unit_testing_for(void ** state, int simd_flag) { int simd_features = (int) ((uintptr_t) *state); // load the DSO ac_crypto_engine_loader_load(simd_flag); // Check if this shared library CAN run on the machine, if not; skip testing it. if (simd_features < dso_ac_crypto_engine_supported_features()) { // unit-test cannot run without an illegal instruction. skip(); } else { // Perform the unit-testing; we can run without an illegal instruction exception. perform_unit_testing(state); } #if !defined(SANITIZE_ADDRESS) ac_crypto_engine_loader_unload(); #endif } void test_crypto_engine_x86_avx512f(void ** state) { perform_unit_testing_for(state, SIMD_SUPPORTS_AVX512F); } void test_crypto_engine_x86_avx2(void ** state) { perform_unit_testing_for(state, SIMD_SUPPORTS_AVX2); } void test_crypto_engine_x86_avx(void ** state) { perform_unit_testing_for(state, SIMD_SUPPORTS_AVX); } void test_crypto_engine_x86_sse2(void ** state) { perform_unit_testing_for(state, SIMD_SUPPORTS_SSE2); } void test_crypto_engine_arm_neon(void ** state) { perform_unit_testing_for(state, SIMD_SUPPORTS_NEON); } void test_crypto_engine_ppc_altivec(void ** state) { perform_unit_testing_for(state, SIMD_SUPPORTS_ALTIVEC); } void test_crypto_engine_ppc_power8(void ** state) { perform_unit_testing_for(state, SIMD_SUPPORTS_POWER8); } void test_crypto_engine_generic(void ** state) { perform_unit_testing_for(state, SIMD_SUPPORTS_NONE); } int group_setup(void ** state) { *state = (void *) ((uintptr_t) simd_get_supported_features()); return 0; } int main(int argc, char * argv[]) { (void) argc; (void) argv; #if defined(OPENSSL_WITH_CMAC) || defined(GCRYPT_WITH_CMAC_AES) const struct CMUnitTest tests[] = { cmocka_unit_test(test_crypto_engine_generic), #if defined(__x86_64__) || defined(__i386__) || defined(_M_IX86) #if defined(__AVX512F__) cmocka_unit_test(test_crypto_engine_x86_avx512f), #endif cmocka_unit_test(test_crypto_engine_x86_avx2), cmocka_unit_test(test_crypto_engine_x86_avx), cmocka_unit_test(test_crypto_engine_x86_sse2), #elif defined(__arm) || defined(__aarch64) || defined(__aarch64__) cmocka_unit_test(test_crypto_engine_arm_neon), #elif defined(__PPC__) || defined(__PPC64__) cmocka_unit_test(test_crypto_engine_ppc_altivec), cmocka_unit_test(test_crypto_engine_ppc_power8), #else /* warning "SIMD not available." */ #endif }; return cmocka_run_group_tests(tests, group_setup, NULL); #else fprintf(stderr, "SKIP: Missing CMAC algorithm.\n"); return 0; #endif }
C
aircrack-ng/test/unit/test-wpapsk.c
#ifdef HAVE_CONFIG_H #include "config.h" #endif #include <stdarg.h> #include <stddef.h> #include <setjmp.h> #include <cmocka.h> #include <assert.h> #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include "aircrack-ng/crypto/crypto.h" #include "aircrack-ng/support/common.h" #include "aircrack-ng/cpu/trampoline.h" #include "aircrack-ng/ce-wpa/crypto_engine.h" #include "aircrack-ng/support/crypto_engine_loader.h" /* * We must force linking to one of the support crypto libraries; however, * because they are linked with our binary and not the crypto engine * DSOs, at run-time we fail to run due to missing symbols. * * The "proper" way to handle this situation is to use --no-as-needed * linker flag, specifying the libraries to always link against. * * Then there is Autoconf... It does not support the above flag. * * So, we force a bit of hacks to ensure we do link against it. */ #ifdef USE_GCRYPT void * keep_libgcrypt_ = (void *) ((uintptr_t) &gcry_md_open); #else void * keep_libcrypto_ = (void *) ((uintptr_t) &HMAC); #endif void perform_unit_testing(void ** state) { (void) state; wpapsk_password key[MAX_KEYS_PER_CRYPT_SUPPORTED]; uint8_t mic[8][20]; uint8_t expected_mic[20] = "\xd5\x35\x53\x82\xb8\xa9\xb8\x06\xdc\xaf\x99\xcd\xaf\x56\x4e\xb6"; uint8_t stmac[6] = "\x00\x13\x46\xfe\x32\x0c"; uint8_t snonce[32] = "\x59\x16\x8b\xc3\xa5\xdf\x18\xd7\x1e\xfb\x64\x23\xf3\x40\x08\x8d" "\xab\x9e\x1b\xa2\xbb\xc5\x86\x59\xe0\x7b\x37\x64\xb0\xde\x85\x70"; uint8_t anonce[32] = "\x22\x58\x54\xb0\x44\x4d\xe3\xaf\x06\xd1\x49\x2b\x85\x29\x84\xf0" "\x4c\xf6\x27\x4c\x0e\x32\x18\xb8\x68\x17\x56\x86\x4d\xb7\xa0\x55"; uint8_t eapol[256] = "\x01\x03\x00\x75\x02\x01\x0a\x00\x10\x00\x00\x00\x00\x00\x00\x00" "\x01\x59\x16\x8b\xc3\xa5\xdf\x18\xd7\x1e\xfb\x64\x23\xf3\x40\x08" "\x8d\xab\x9e\x1b\xa2\xbb\xc5\x86\x59\xe0\x7b\x37\x64\xb0\xde\x85" "\x70\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x16\x30\x14\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac" "\x04\x01\x00\x00\x0f\xac\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; uint32_t eapol_size = 121; ac_crypto_engine_t engine; uint8_t bssid[6] = "\x00\x14\x6c\x7e\x40\x80"; uint8_t essid[33] = "Harkonen"; int nparallel = dso_ac_crypto_engine_simd_width(); memset(&engine, 0, sizeof(engine)); dso_ac_crypto_engine_init(&engine); dso_ac_crypto_engine_set_essid(&engine, &essid[0]); dso_ac_crypto_engine_thread_init(&engine, 1); dso_ac_crypto_engine_calc_pke(&engine, bssid, stmac, anonce, snonce, 1); for (int i = 0; i < nparallel; ++i) { int rc; memset(key, 0, sizeof(key)); strcpy((char *) (key[i].v), "12345678"); key[i].length = 8; if ((rc = dso_ac_crypto_engine_wpa_crack(&engine, key, eapol, eapol_size, mic, 2, expected_mic, nparallel, 1)) >= 0) { // does the returned SIMD lane equal where we placed the key? assert_int_equal(rc, i); } else { fail(); } } dso_ac_crypto_engine_thread_destroy(&engine, 1); dso_ac_crypto_engine_destroy(&engine); } void perform_unit_testing_for(void ** state, int simd_flag) { int simd_features = (int) ((uintptr_t) *state); // load the DSO ac_crypto_engine_loader_load(simd_flag); // Check if this shared library CAN run on the machine, if not; skip testing it. if (simd_features < dso_ac_crypto_engine_supported_features()) { // unit-test cannot run without an illegal instruction. skip(); } else { // Perform the unit-testing; we can run without an illegal instruction exception. perform_unit_testing(state); } #if !defined(SANITIZE_ADDRESS) ac_crypto_engine_loader_unload(); #endif } void test_crypto_engine_x86_avx512f(void ** state) { perform_unit_testing_for(state, SIMD_SUPPORTS_AVX512F); } void test_crypto_engine_x86_avx2(void ** state) { perform_unit_testing_for(state, SIMD_SUPPORTS_AVX2); } void test_crypto_engine_x86_avx(void ** state) { perform_unit_testing_for(state, SIMD_SUPPORTS_AVX); } void test_crypto_engine_x86_sse2(void ** state) { perform_unit_testing_for(state, SIMD_SUPPORTS_SSE2); } void test_crypto_engine_arm_neon(void ** state) { perform_unit_testing_for(state, SIMD_SUPPORTS_NEON); } void test_crypto_engine_ppc_altivec(void ** state) { perform_unit_testing_for(state, SIMD_SUPPORTS_ALTIVEC); } void test_crypto_engine_ppc_power8(void ** state) { perform_unit_testing_for(state, SIMD_SUPPORTS_POWER8); } void test_crypto_engine_generic(void ** state) { perform_unit_testing_for(state, SIMD_SUPPORTS_NONE); } int group_setup(void ** state) { *state = (void *) ((uintptr_t) simd_get_supported_features()); return 0; } int main(int argc, char * argv[]) { (void) argc; (void) argv; const struct CMUnitTest tests[] = { cmocka_unit_test(test_crypto_engine_generic), #if defined(__x86_64__) || defined(__i386__) || defined(_M_IX86) #if defined(__AVX512F__) cmocka_unit_test(test_crypto_engine_x86_avx512f), #endif cmocka_unit_test(test_crypto_engine_x86_avx2), cmocka_unit_test(test_crypto_engine_x86_avx), cmocka_unit_test(test_crypto_engine_x86_sse2), #elif defined(__arm) || defined(__aarch64) || defined(__aarch64__) cmocka_unit_test(test_crypto_engine_arm_neon), #elif defined(__PPC__) || defined(__PPC64__) cmocka_unit_test(test_crypto_engine_ppc_altivec), cmocka_unit_test(test_crypto_engine_ppc_power8), #else /* warning "SIMD not available." */ #endif }; return cmocka_run_group_tests(tests, group_setup, NULL); }
algo/.ansible-lint
skip_list: - yaml - '204' verbosity: 1 warn_list: - no-changed-when - no-handler - fqcn-builtins - var-spacing
algo/.dockerignore
.dockerignore .git .github .gitignore .travis.yml CONTRIBUTING.md Dockerfile README.md config.cfg configs docs .env logo.png tests CHANGELOG.md PULL_REQUEST_TEMPLATE.md Vagrantfile Makefile
algo/algo
#!/usr/bin/env bash set -e if [ -z ${VIRTUAL_ENV+x} ] then ACTIVATE_SCRIPT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/.env/bin/activate" if [ -f "$ACTIVATE_SCRIPT" ] then # shellcheck source=/dev/null source "$ACTIVATE_SCRIPT" else echo "$ACTIVATE_SCRIPT not found. Did you follow documentation to install dependencies?" exit 1 fi fi case "$1" in update-users) PLAYBOOK=users.yml; ARGS=( "${@:2}" -t update-users ) ;; *) PLAYBOOK=main.yml; ARGS=( "${@}" ) ;; esac ansible-playbook ${PLAYBOOK} "${ARGS[@]}"
Shell Script
algo/algo-docker.sh
#!/usr/bin/env bash set -eEo pipefail ALGO_DIR="/algo" DATA_DIR="/data" umask 0077 usage() { retcode="${1:-0}" echo "To run algo from Docker:" echo "" echo "docker run --cap-drop=all -it -v <path to configurations>:"${DATA_DIR}" ghcr.io/trailofbits/algo:latest" echo "" exit ${retcode} } if [ ! -f "${DATA_DIR}"/config.cfg ] ; then echo "Looks like you're not bind-mounting your config.cfg into this container." echo "algo needs a configuration file to run." echo "" usage -1 fi if [ ! -e /dev/console ] ; then echo "Looks like you're trying to run this container without a TTY." echo "If you don't pass `-t`, you can't interact with the algo script." echo "" usage -1 fi # To work around problems with bind-mounting Windows volumes, we need to # copy files out of ${DATA_DIR}, ensure appropriate line endings and permissions, # then copy the algo-generated files into ${DATA_DIR}. tr -d '\r' < "${DATA_DIR}"/config.cfg > "${ALGO_DIR}"/config.cfg test -d "${DATA_DIR}"/configs && rsync -qLktr --delete "${DATA_DIR}"/configs "${ALGO_DIR}"/ "${ALGO_DIR}"/algo "${ALGO_ARGS[@]}" retcode=${?} rsync -qLktr --delete "${ALGO_DIR}"/configs "${DATA_DIR}"/ exit ${retcode}
Shell Script
algo/algo-showenv.sh
#!/usr/bin/env bash # # Print information about Algo's invocation environment to aid in debugging. # This is normally called from Ansible right before a deployment gets underway. # Skip printing this header if we're just testing with no arguments. if [[ $# -gt 0 ]]; then echo "" echo "--> Please include the following block of text when reporting issues:" echo "" fi if [[ ! -f ./algo ]]; then echo "This should be run from the top level Algo directory" fi # Determine the operating system. case "$(uname -s)" in Linux) OS="Linux ($(uname -r) $(uname -v))" if [[ -f /etc/os-release ]]; then # shellcheck disable=SC1091 # I hope this isn't dangerous. . /etc/os-release if [[ ${PRETTY_NAME} ]]; then OS="${PRETTY_NAME}" elif [[ ${NAME} ]]; then OS="${NAME} ${VERSION}" fi fi STAT="stat -c %y" ;; Darwin) OS="$(sw_vers -productName) $(sw_vers -productVersion)" STAT="stat -f %Sm" ;; *) OS="Unknown" ;; esac # Determine if virtualization is being used with Linux. VIRTUALIZED="" if [[ -x $(command -v systemd-detect-virt) ]]; then DETECT_VIRT="$(systemd-detect-virt)" if [[ ${DETECT_VIRT} != "none" ]]; then VIRTUALIZED=" (Virtualized: ${DETECT_VIRT})" fi elif [[ -f /.dockerenv ]]; then VIRTUALIZED=" (Virtualized: docker)" fi echo "Algo running on: ${OS}${VIRTUALIZED}" # Determine the currentness of the Algo software. if [[ -d .git && -x $(command -v git) ]]; then ORIGIN="$(git remote get-url origin)" COMMIT="$(git log --max-count=1 --oneline --no-decorate --no-color)" if [[ ${ORIGIN} == "https://github.com/trailofbits/algo.git" ]]; then SOURCE="clone" else SOURCE="fork" fi echo "Created from git ${SOURCE}. Last commit: ${COMMIT}" elif [[ -f LICENSE && ${STAT} ]]; then CREATED="$(${STAT} LICENSE)" echo "ZIP file created: ${CREATED}" fi # The Python version might be useful to know. if [[ -x ./.env/bin/python3 ]]; then ./.env/bin/python3 --version 2>&1 elif [[ -f ./algo ]]; then echo ".env/bin/python3 not found: has 'python3 -m virtualenv ...' been run?" fi # Just print out all command line arguments, which are expected # to be Ansible variables. if [[ $# -gt 0 ]]; then echo "Runtime variables:" for VALUE in "$@"; do echo " ${VALUE}" done fi exit 0
algo/ansible.cfg
[defaults] inventory = inventory pipelining = True retry_files_enabled = False host_key_checking = False timeout = 60 stdout_callback = default display_skipped_hosts = no force_valid_group_names = ignore [paramiko_connection] record_host_keys = False [ssh_connection] ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o UserKnownHostsFile=/dev/null -o ConnectTimeout=6 -o ConnectionAttempts=30 -o IdentitiesOnly=yes scp_if_ssh = True retries = 30
Markdown
algo/CHANGELOG.md
## 1.2 [(Unreleased)](https://github.com/trailofbits/algo/tree/HEAD) ### Added - New provider CloudStack added [\#1420](https://github.com/trailofbits/algo/pull/1420) - Support for Ubuntu 20.04 [\#1782](https://github.com/trailofbits/algo/pull/1782) - Allow WireGuard to listen on port 53 [\#1594](https://github.com/trailofbits/algo/pull/1594) - Introducing Makefile [\#1553](https://github.com/trailofbits/algo/pull/1553) - Option to unblock SMB and Netbios [\#1558](https://github.com/trailofbits/algo/pull/1558) - Allow OnDemand to be toggled later [\#1557](https://github.com/trailofbits/algo/pull/1557) - New provider Hetzner added [\#1549](https://github.com/trailofbits/algo/pull/1549) - Alternative Ingress IP [\#1605](https://github.com/trailofbits/algo/pull/1605) ### Fixes - WSL private SSH key permissions [\#1584](https://github.com/trailofbits/algo/pull/1584) - Scaleway instance creating issue [\#1549](https://github.com/trailofbits/algo/pull/1549) ### Changed - Discontinue use of the WireGuard PPA [\#1855](https://github.com/trailofbits/algo/pull/1855) - SSH changes [\#1636](https://github.com/trailofbits/algo/pull/1636) - Default port is set to `4160` and can be changed in the config - SSH user for every cloud provider is `algo` - EC2: enable EBS encryption by default [\#1556](https://github.com/trailofbits/algo/pull/1556) - Upgrades [\#1549](https://github.com/trailofbits/algo/pull/1549) - Python 3 - Ansible 2.9 [\#1777](https://github.com/trailofbits/algo/pull/1777) ### Breaking changes - Python virtual environment moved to .env [\#1549](https://github.com/trailofbits/algo/pull/1549) ## 1.1 [(Jul 31, 2019)](https://github.com/trailofbits/algo/releases/tag/v1.1) ### Removed - IKEv2 for Windows is now deleted, use Wireguard [\#1493](https://github.com/trailofbits/algo/issues/1493) ### Added - Tmpfs for key generation [\#145](https://github.com/trailofbits/algo/issues/145) - Randomly generated pre-shared keys for WireGuard [\#1465](https://github.com/trailofbits/algo/pull/1465) ([elreydetoda](https://github.com/elreydetoda)) - Support for Ubuntu 19.04 [\#1405](https://github.com/trailofbits/algo/pull/1405) ([jackivanov](https://github.com/jackivanov)) - AWS support for existing EIP [\#1292](https://github.com/trailofbits/algo/pull/1292) ([statik](https://github.com/statik)) - Script to support cloud-init and local easy deploy [\#1366](https://github.com/trailofbits/algo/pull/1366) ([jackivanov](https://github.com/jackivanov)) - Automatically create cloud firewall rules for installs onto Vultr [\#1400](https://github.com/trailofbits/algo/pull/1400) ([TC1977](https://github.com/TC1977)) - Randomly generated IP address for the local dns resolver [\#1429](https://github.com/trailofbits/algo/pull/1429) ([jackivanov](https://github.com/jackivanov)) - Update users: add server pick-list [\#1441](https://github.com/trailofbits/algo/pull/1441) ([TC1977](https://github.com/TC1977)) - Additional testing [\#213](https://github.com/trailofbits/algo/issues/213) - Add IPv6 support to DNS [\#1425](https://github.com/trailofbits/algo/pull/1425) ([shapiro125](https://github.com/shapiro125)) - Additional p12 with the CA cert included [\#1403](https://github.com/trailofbits/algo/pull/1403) ([jackivanov](https://github.com/jackivanov)) ### Fixed - Fixes error in 10-algo-lo100.network [\#1369](https://github.com/trailofbits/algo/pull/1369) ([adamluk](https://github.com/adamluk)) - Error message is missing for some roles [\#1364](https://github.com/trailofbits/algo/issues/1364) - DNS leak in Linux/Wireguard when LAN gateway/DNS is 172.16.0.1 [\#1422](https://github.com/trailofbits/algo/issues/1422) - Installation error after \#1397 [\#1409](https://github.com/trailofbits/algo/issues/1409) - EC2 encrypted images bug [\#1528](https://github.com/trailofbits/algo/issues/1528) ### Changed - Upgrade Ansible to 2.7.12 [\#1536](https://github.com/trailofbits/algo/pull/1536) - DNSmasq removed, and the DNS adblocking functionality has been moved to the dnscrypt-proxy - Azure: moved to the Standard_B1S image size - Refactoring, Linting and additional tests [\#1397](https://github.com/trailofbits/algo/pull/1397) ([jackivanov](https://github.com/jackivanov)) - Scaleway modules [\#1410](https://github.com/trailofbits/algo/pull/1410) ([jackivanov](https://github.com/jackivanov)) - Use VULTR_API_CONFIG variable if set [\#1374](https://github.com/trailofbits/algo/pull/1374) ([davidemyers](https://github.com/davidemyers)) - Simplify Apple Profile Configuration Template [\#1033](https://github.com/trailofbits/algo/pull/1033) ([faf0](https://github.com/faf0)) - Include roles as separate tasks [\#1365](https://github.com/trailofbits/algo/pull/1365) ([jackivanov](https://github.com/jackivanov)) ## 1.0 [(Mar 19, 2019)](https://github.com/trailofbits/algo/releases/tag/v1.0) ### Added - Tagged releases and changelog [\#724](https://github.com/trailofbits/algo/issues/724) - Add support for custom domain names [\#759](https://github.com/trailofbits/algo/issues/759) ### Fixed - Set the name shown to the user \(client\) to be the server name specified in the install script [\#491](https://github.com/trailofbits/algo/issues/491) - AGPLv3 change [\#1351](https://github.com/trailofbits/algo/pull/1351) - Migrate to python3 [\#1024](https://github.com/trailofbits/algo/issues/1024) - Reorganize the project around ipsec + wireguard [\#1330](https://github.com/trailofbits/algo/issues/1330) - Configuration folder reorganization [\#1330](https://github.com/trailofbits/algo/issues/1330) - Remove WireGuard KeepAlive and include as an option in config [\#1251](https://github.com/trailofbits/algo/issues/1251) - Dnscrypt-proxy no longer works after reboot [\#1356](https://github.com/trailofbits/algo/issues/1356) ## 20 Oct 2018 ### Added - AWS Lightsail ## 7 Sep 2018 ### Changed - Azure: Deployment via Azure Resource Manager ## 27 Aug 2018 ### Changed - Large refactor to support Ansible 2.5. [Details](https://github.com/trailofbits/algo/pull/976) - Add a new cloud provider - Vultr ### Upgrade notes - If any problems encountered follow the [instructions](https://github.com/trailofbits/algo#deploy-the-algo-server) from scratch - You can't update users on your old servers with the new code. Use the old code before this release or rebuild the server from scratch - Update AWS IAM permissions for your user as per [issue](https://github.com/trailofbits/algo/issues/1079#issuecomment-416577599) ## 04 Jun 2018 ### Changed - Switched to [new cipher suite](https://github.com/trailofbits/algo/issues/981) ## 24 May 2018 ### Changed - Switched to Ubuntu 18.04 ### Removed - Lightsail support until they have Ubuntu 18.04 ### Fixed - Scaleway API paginagion ## 30 Apr 2018 ### Added - WireGuard support ### Removed - Android StrongSwan profiles ### Release notes - StrongSwan profiles for Android are deprecated now. Use WireGuard ## 25 Apr 2018 ### Added - DNScrypt-proxy added - Switched to CloudFlare DNS-over-HTTPS by default ## 19 Apr 2018 ### Added - IPv6 in subjectAltName of the certificates. This allows connecting to the Algo instance via the main IPv6 address ### Fixed - IPv6 DNS addresses were not passing to the client ### Release notes - In order to use the IPv6 address as the connection endpoint you need to [reinit](https://github.com/trailofbits/algo/blob/master/config.cfg#L14) the PKI and [reconfigure](https://github.com/trailofbits/algo#configure-the-vpn-clients) your devices with new certificates.
YAML
algo/cloud.yml
--- - name: Provision the server hosts: localhost tags: always become: false vars_files: - config.cfg tasks: - block: - name: Local pre-tasks import_tasks: playbooks/cloud-pre.yml - name: Include a provisioning role include_role: name: "{{ 'local' if algo_provider == 'local' else 'cloud-' + algo_provider }}" - name: Local post-tasks import_tasks: playbooks/cloud-post.yml rescue: - include_tasks: playbooks/rescue.yml
algo/config.cfg
--- # This is the list of users to generate. # Every device must have a unique user. # You can add up to 65,534 new users over the lifetime of an AlgoVPN. # User names with leading 0's or containing only numbers should be escaped in double quotes, e.g. "000dan" or "123". # Email addresses are not allowed. users: - phone - laptop - desktop ### Review these options BEFORE you run Algo, as they are very difficult/impossible to change after the server is deployed. # Change default SSH port for the cloud roles only # It doesn't apply if you deploy to your existing Ubuntu Server ssh_port: 4160 # Deploy StrongSwan to enable IPsec support ipsec_enabled: true # Deploy WireGuard # WireGuard will listen on 51820/UDP. You might need to change to another port # if your network blocks this one. Be aware that 53/UDP (DNS) is blocked on some # mobile data networks. wireguard_enabled: true wireguard_port: 51820 # This feature allows you to configure the Algo server to send outbound traffic # through a different external IP address than the one you are establishing the VPN connection with. # More info https://trailofbits.github.io/algo/cloud-alternative-ingress-ip.html # Available for the following cloud providers: # - DigitalOcean alternative_ingress_ip: false # Reduce the MTU of the VPN tunnel # Some cloud and internet providers use a smaller MTU (Maximum Transmission # Unit) than the normal value of 1500 and if you don't reduce the MTU of your # VPN tunnel some network connections will hang. Algo will attempt to set this # automatically based on your server, but if connections hang you might need to # adjust this yourself. # See: https://github.com/trailofbits/algo/blob/master/docs/troubleshooting.md#various-websites-appear-to-be-offline-through-the-vpn reduce_mtu: 0 # Algo will use the following lists to block ads. You can add new block lists # after deployment by modifying the line starting "BLOCKLIST_URLS=" at: # /usr/local/sbin/adblock.sh # If you load very large blocklists, you may also have to modify resource limits: # /etc/systemd/system/dnsmasq.service.d/100-CustomLimitations.conf adblock_lists: - "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts" # Enable DNS encryption. # If 'false', 'dns_servers' should be specified below. # DNS encryption can not be disabled if DNS adblocking is enabled dns_encryption: true # Block traffic between connected clients. Change this to false to enable # connected clients to reach each other, as well as other computers on the # same LAN as your Algo server (i.e. the "road warrior" setup). In this # case, you may also want to enable SMB/CIFS and NETBIOS traffic below. BetweenClients_DROP: true # Block SMB/CIFS traffic block_smb: true # Block NETBIOS traffic block_netbios: true # Your Algo server will automatically install security updates. Some updates # require a reboot to take effect but your Algo server will not reboot itself # automatically unless you change 'enabled' below from 'false' to 'true', in # which case a reboot will take place if necessary at the time specified (as # HH:MM) in the time zone of your Algo server. The default time zone is UTC. unattended_reboot: enabled: false time: 06:00 ### Advanced users only below this line ### # DNS servers which will be used if 'dns_encryption' is 'true'. Multiple # providers may be specified, but avoid mixing providers that filter results # (like Cisco) with those that don't (like Cloudflare) or you could get # inconsistent results. The list of available public providers can be found # here: # https://github.com/DNSCrypt/dnscrypt-resolvers/blob/master/v2/public-resolvers.md dnscrypt_servers: ipv4: - cloudflare # - google # - <YourCustomServer> # E.g., if using NextDNS, this will be something like NextDNS-abc123. # You must also fill in custom_server_stamps below. You may specify # multiple custom servers. ipv6: - cloudflare-ipv6 custom_server_stamps: # YourCustomServer: 'sdns://...' # DNS servers which will be used if 'dns_encryption' is 'false'. # Fallback resolvers for systemd-resolved # The default is to use Cloudflare. dns_servers: ipv4: - 1.1.1.1 - 1.0.0.1 ipv6: - 2606:4700:4700::1111 - 2606:4700:4700::1001 # Store the PKI in a ram disk. Enabled only if store_pki (retain the PKI) is set to false # Supports on MacOS and Linux only (including Windows Subsystem for Linux) pki_in_tmpfs: true # Set this to 'true' when running './algo update-users' if you want ALL users to get new certs, not just new users. keys_clean_all: false # StrongSwan log level # https://wiki.strongswan.org/projects/strongswan/wiki/LoggerConfiguration strongswan_log_level: 2 # rightsourceip for ipsec # ipv4 strongswan_network: 10.48.0.0/16 # ipv6 strongswan_network_ipv6: '2001:db8:4160::/48' # If you're behind NAT or a firewall and you want to receive incoming connections long after network traffic has gone silent. # This option will keep the "connection" open in the eyes of NAT. # See: https://www.wireguard.com/quickstart/#nat-and-firewall-traversal-persistence wireguard_PersistentKeepalive: 0 # WireGuard network configuration wireguard_network_ipv4: 10.49.0.0/16 wireguard_network_ipv6: 2001:db8:a160::/48 # Randomly generated IP address for the local dns resolver local_service_ip: "{{ '172.16.0.1' | ipmath(1048573 | random(seed=algo_server_name + ansible_fqdn)) }}" local_service_ipv6: "{{ 'fd00::1' | ipmath(1048573 | random(seed=algo_server_name + ansible_fqdn)) }}" # Hide sensitive data no_log: true congrats: common: | "# Congratulations! #" "# Your Algo server is running. #" "# Config files and certificates are in the ./configs/ directory. #" "# Go to https://whoer.net/ after connecting #" "# and ensure that all your traffic passes through the VPN. #" "# Local DNS resolver {{ local_service_ip }}{{ ', ' + local_service_ipv6 if ipv6_support else '' }} #" p12_pass: | "# The p12 and SSH keys password for new users is {{ p12_export_password }} #" ca_key_pass: | "# The CA key password is {{ CA_password|default(omit) }} #" ssh_access: | "# Shell access: ssh -F configs/{{ ansible_ssh_host|default(omit) }}/ssh_config {{ algo_server_name }} #" SSH_keys: comment: algo@ssh private: configs/algo.pem private_tmp: /tmp/algo-ssh.pem public: configs/algo.pem.pub cloud_providers: azure: size: Standard_B1S osDisk: # The storage account type to use for the OS disk. Possible values: # 'Standard_LRS', 'Premium_LRS', 'StandardSSD_LRS', 'UltraSSD_LRS', # 'Premium_ZRS', 'StandardSSD_ZRS', 'PremiumV2_LRS'. type: Standard_LRS image: publisher: Canonical offer: 0001-com-ubuntu-minimal-jammy-daily sku: minimal-22_04-daily-lts version: latest digitalocean: size: s-1vcpu-1gb image: "ubuntu-22-04-x64" ec2: # Change the encrypted flag to "false" to disable AWS volume encryption. encrypted: true # Set use_existing_eip to "true" if you want to use a pre-allocated Elastic IP # Additional prompt will be raised to determine which IP to use use_existing_eip: false size: t2.micro image: name: "ubuntu-jammy-22.04" arch: x86_64 owner: "099720109477" # Change instance_market_type from "on-demand" to "spot" to launch a spot # instance. See deploy-from-ansible.md for spot's additional IAM permission instance_market_type: on-demand gce: size: e2-micro image: ubuntu-2204-lts external_static_ip: false lightsail: size: nano_2_0 image: ubuntu_22_04 scaleway: size: DEV1-S image: Ubuntu 22.04 Jammy Jellyfish arch: x86_64 hetzner: server_type: cx11 image: ubuntu-22.04 openstack: flavor_ram: ">=512" image: Ubuntu-22.04 cloudstack: size: Micro image: Linux Ubuntu 22.04 LTS 64-bit disk: 10 vultr: os: Ubuntu 22.04 LTS x64 size: 1024 MB RAM,25 GB SSD,1.00 TB BW linode: type: g6-nanode-1 image: linode/ubuntu22.04 local: fail_hint: - Sorry, but something went wrong! - Please check the troubleshooting guide. - https://trailofbits.github.io/algo/troubleshooting.html booleans_map: Y: true y: true
Markdown
algo/CONTRIBUTING.md
### Filing New Issues * Check that your issue is not already described in the [FAQ](docs/faq.md), [troubleshooting](docs/troubleshooting.md) docs, or an [existing issue](https://github.com/trailofbits/algo/issues) * Did you remember to install the dependencies for your operating system prior to installing Algo? * We only support modern clients, e.g. macOS 10.11+, iOS 9+, Windows 10+, Ubuntu 17.04+, etc. * Cloud provider support is limited to DO, AWS, GCE, and Azure. Any others are best effort only. * If you need to file a new issue, fill out any relevant fields in the Issue Template. ### Pull Requests * Run [ansible-lint](https://github.com/willthames/ansible-lint) or [shellcheck](https://github.com/koalaman/shellcheck) on any new scripts Thanks!
YAML
algo/deploy_client.yml
--- - name: Configure the client hosts: localhost become: false vars_files: - config.cfg tasks: - name: Add the droplet to an inventory group add_host: name: "{{ client_ip }}" groups: client-host ansible_ssh_user: "{{ 'root' if client_ip == 'localhost' else ssh_user }}" vpn_user: "{{ vpn_user }}" IP_subject_alt_name: "{{ server_ip }}" ansible_python_interpreter: /usr/bin/python3 - name: Configure the client and install required software hosts: client-host gather_facts: false become: true vars_files: - config.cfg - roles/strongswan/defaults/main.yml roles: - role: client
algo/Dockerfile
FROM python:3-alpine ARG VERSION="git" ARG PACKAGES="bash libffi openssh-client openssl rsync tini gcc libffi-dev linux-headers make musl-dev openssl-dev rust cargo" LABEL name="algo" \ version="${VERSION}" \ description="Set up a personal IPsec VPN in the cloud" \ maintainer="Trail of Bits <http://github.com/trailofbits/algo>" RUN apk --no-cache add ${PACKAGES} RUN adduser -D -H -u 19857 algo RUN mkdir -p /algo && mkdir -p /algo/configs WORKDIR /algo COPY requirements.txt . RUN python3 -m pip --no-cache-dir install -U pip && \ python3 -m pip --no-cache-dir install virtualenv && \ python3 -m virtualenv .env && \ source .env/bin/activate && \ python3 -m pip --no-cache-dir install -r requirements.txt COPY . . RUN chmod 0755 /algo/algo-docker.sh # Because of the bind mounting of `configs/`, we need to run as the `root` user # This may break in cases where user namespacing is enabled, so hopefully Docker # sorts out a way to set permissions on bind-mounted volumes (`docker run -v`) # before userns becomes default # Note that not running as root will break if we don't have a matching userid # in the container. The filesystem has also been set up to assume root. USER root CMD [ "/algo/algo-docker.sh" ] ENTRYPOINT [ "/sbin/tini", "--" ]
YAML
algo/input.yml
--- - name: Ask user for the input hosts: localhost tags: always vars: defaults: server_name: algo ondemand_cellular: false ondemand_wifi: false dns_adblocking: false ssh_tunneling: false store_pki: false providers_map: - { name: DigitalOcean, alias: digitalocean } - { name: Amazon Lightsail, alias: lightsail } - { name: Amazon EC2, alias: ec2 } - { name: Microsoft Azure, alias: azure } - { name: Google Compute Engine, alias: gce } - { name: Hetzner Cloud, alias: hetzner } - { name: Vultr, alias: vultr } - { name: Scaleway, alias: scaleway } - { name: OpenStack (DreamCompute optimised), alias: openstack } - { name: CloudStack (Exoscale optimised), alias: cloudstack } - { name: Linode, alias: linode } - { name: Install to existing Ubuntu latest LTS server (for more advanced users), alias: local } vars_files: - config.cfg tasks: - block: - name: Cloud prompt pause: prompt: | What provider would you like to use? {% for p in providers_map %} {{ loop.index }}. {{ p['name'] }} {% endfor %} Enter the number of your desired provider register: _algo_provider when: provider is undefined - name: Set facts based on the input set_fact: algo_provider: "{{ provider | default(providers_map[_algo_provider.user_input|default(omit)|int - 1]['alias']) }}" - name: VPN server name prompt pause: prompt: | Name the vpn server [algo] register: _algo_server_name when: - server_name is undefined - algo_provider != "local" - name: Cellular On Demand prompt pause: prompt: | Do you want macOS/iOS clients to enable "Connect On Demand" when connected to cellular networks? [y/N] register: _ondemand_cellular when: ondemand_cellular is undefined - name: Wi-Fi On Demand prompt pause: prompt: | Do you want macOS/iOS clients to enable "Connect On Demand" when connected to Wi-Fi? [y/N] register: _ondemand_wifi when: ondemand_wifi is undefined - name: Trusted Wi-Fi networks prompt pause: prompt: | List the names of any trusted Wi-Fi networks where macOS/iOS clients should not use "Connect On Demand" (e.g., your home network. Comma-separated value, e.g., HomeNet,OfficeWifi,AlgoWiFi) register: _ondemand_wifi_exclude when: - ondemand_wifi_exclude is undefined - (ondemand_wifi|default(false)|bool) or (booleans_map[_ondemand_wifi.user_input|default(omit)]|default(false)) - name: Retain the PKI prompt pause: prompt: | Do you want to retain the keys (PKI)? (required to add users in the future, but less secure) [y/N] register: _store_pki when: - store_pki is undefined - ipsec_enabled - name: DNS adblocking prompt pause: prompt: | Do you want to enable DNS ad blocking on this VPN server? [y/N] register: _dns_adblocking when: dns_adblocking is undefined - name: SSH tunneling prompt pause: prompt: | Do you want each user to have their own account for SSH tunneling? [y/N] register: _ssh_tunneling when: ssh_tunneling is undefined - name: Set facts based on the input set_fact: algo_server_name: >- {% if server_name is defined %}{% set _server = server_name %} {%- elif _algo_server_name.user_input is defined and _algo_server_name.user_input|length > 0 -%} {%- set _server = _algo_server_name.user_input -%} {%- else %}{% set _server = defaults['server_name'] %}{% endif -%} {{ _server | regex_replace('(?!\.)(\W|_)', '-') }} algo_ondemand_cellular: >- {% if ondemand_cellular is defined %}{{ ondemand_cellular | bool }} {%- elif _ondemand_cellular.user_input is defined %}{{ booleans_map[_ondemand_cellular.user_input] | default(defaults['ondemand_cellular']) }} {%- else %}false{% endif %} algo_ondemand_wifi: >- {% if ondemand_wifi is defined %}{{ ondemand_wifi | bool }} {%- elif _ondemand_wifi.user_input is defined %}{{ booleans_map[_ondemand_wifi.user_input] | default(defaults['ondemand_wifi']) }} {%- else %}false{% endif %} algo_ondemand_wifi_exclude: >- {% if ondemand_wifi_exclude is defined %}{{ ondemand_wifi_exclude | b64encode }} {%- elif _ondemand_wifi_exclude.user_input is defined and _ondemand_wifi_exclude.user_input|length > 0 -%} {{ _ondemand_wifi_exclude.user_input | b64encode }} {%- else %}{{ '_null' | b64encode }}{% endif %} algo_dns_adblocking: >- {% if dns_adblocking is defined %}{{ dns_adblocking | bool }} {%- elif _dns_adblocking.user_input is defined %}{{ booleans_map[_dns_adblocking.user_input] | default(defaults['dns_adblocking']) }} {%- else %}false{% endif %} algo_ssh_tunneling: >- {% if ssh_tunneling is defined %}{{ ssh_tunneling | bool }} {%- elif _ssh_tunneling.user_input is defined %}{{ booleans_map[_ssh_tunneling.user_input] | default(defaults['ssh_tunneling']) }} {%- else %}false{% endif %} algo_store_pki: >- {% if ipsec_enabled %}{%- if store_pki is defined %}{{ store_pki | bool }} {%- elif _store_pki.user_input is defined %}{{ booleans_map[_store_pki.user_input] | default(defaults['store_pki']) }} {%- else %}false{% endif %}{% endif %} rescue: - include_tasks: playbooks/rescue.yml
Shell Script
algo/install.sh
#!/usr/bin/env sh set -ex METHOD="${1:-${METHOD:-cloud}}" ONDEMAND_CELLULAR="${2:-${ONDEMAND_CELLULAR:-false}}" ONDEMAND_WIFI="${3:-${ONDEMAND_WIFI:-false}}" ONDEMAND_WIFI_EXCLUDE="${4:-${ONDEMAND_WIFI_EXCLUDE:-_null}}" STORE_PKI="${5:-${STORE_PKI:-false}}" DNS_ADBLOCKING="${6:-${DNS_ADBLOCKING:-false}}" SSH_TUNNELING="${7:-${SSH_TUNNELING:-false}}" ENDPOINT="${8:-${ENDPOINT:-localhost}}" USERS="${9:-${USERS:-user1}}" REPO_SLUG="${10:-${REPO_SLUG:-trailofbits/algo}}" REPO_BRANCH="${11:-${REPO_BRANCH:-master}}" EXTRA_VARS="${12:-${EXTRA_VARS:-placeholder=null}}" ANSIBLE_EXTRA_ARGS="${13:-${ANSIBLE_EXTRA_ARGS}}" cd /opt/ installRequirements() { export DEBIAN_FRONTEND=noninteractive apt-get update apt-get install \ python3-virtualenv \ jq -y } getAlgo() { [ ! -d "algo" ] && git clone "https://github.com/${REPO_SLUG}" -b "${REPO_BRANCH}" algo cd algo python3 -m virtualenv --python="$(command -v python3)" .env # shellcheck source=/dev/null . .env/bin/activate python3 -m pip install -U pip virtualenv python3 -m pip install -r requirements.txt } publicIpFromInterface() { echo "Couldn't find a valid ipv4 address, using the first IP found on the interfaces as the endpoint." DEFAULT_INTERFACE="$(ip -4 route list match default | grep -Eo "dev .*" | awk '{print $2}')" ENDPOINT=$(ip -4 addr sh dev "$DEFAULT_INTERFACE" | grep -w inet | head -n1 | awk '{print $2}' | grep -oE '\b([0-9]{1,3}\.){3}[0-9]{1,3}\b') export ENDPOINT="${ENDPOINT}" echo "Using ${ENDPOINT} as the endpoint" } publicIpFromMetadata() { if curl -s http://169.254.169.254/metadata/v1/vendor-data | grep DigitalOcean >/dev/null; then ENDPOINT="$(curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/address)" elif test "$(curl -s http://169.254.169.254/latest/meta-data/services/domain)" = "amazonaws.com"; then ENDPOINT="$(curl -s http://169.254.169.254/latest/meta-data/public-ipv4)" elif host -t A -W 10 metadata.google.internal 127.0.0.53 >/dev/null; then ENDPOINT="$(curl -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip")" elif test "$(curl -s -H Metadata:true 'http://169.254.169.254/metadata/instance/compute/publisher/?api-version=2017-04-02&format=text')" = "Canonical"; then ENDPOINT="$(curl -H Metadata:true 'http://169.254.169.254/metadata/instance/network/interface/0/ipv4/ipAddress/0/publicIpAddress?api-version=2017-04-02&format=text')" fi if echo "${ENDPOINT}" | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b"; then export ENDPOINT="${ENDPOINT}" echo "Using ${ENDPOINT} as the endpoint" else publicIpFromInterface fi } deployAlgo() { getAlgo cd /opt/algo # shellcheck source=/dev/null . .env/bin/activate export HOME=/root export ANSIBLE_LOCAL_TEMP=/root/.ansible/tmp export ANSIBLE_REMOTE_TEMP=/root/.ansible/tmp # shellcheck disable=SC2086 ansible-playbook main.yml \ -e provider=local \ -e "ondemand_cellular=${ONDEMAND_CELLULAR}" \ -e "ondemand_wifi=${ONDEMAND_WIFI}" \ -e "ondemand_wifi_exclude=${ONDEMAND_WIFI_EXCLUDE}" \ -e "store_pki=${STORE_PKI}" \ -e "dns_adblocking=${DNS_ADBLOCKING}" \ -e "ssh_tunneling=${SSH_TUNNELING}" \ -e "endpoint=$ENDPOINT" \ -e "users=$(echo "$USERS" | jq -Rc 'split(",")')" \ -e server=localhost \ -e ssh_user=root \ -e "${EXTRA_VARS}" \ --skip-tags debug ${ANSIBLE_EXTRA_ARGS} | tee /var/log/algo.log } if test "$METHOD" = "cloud"; then publicIpFromMetadata fi installRequirements deployAlgo
algo/LICENSE
GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. Developers that use our General Public Licenses protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you legal permission to copy, distribute and/or modify the software. A secondary benefit of defending all users' freedom is that improvements made in alternate versions of the program, if they receive widespread use, become available for other developers to incorporate. Many developers of free software are heartened and encouraged by the resulting cooperation. However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License permits making a modified version and letting the public access it on a server without ever releasing its source code to the public. The GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified source code becomes available to the community. It requires the operator of a network server to provide the source code of the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source code of the modified version. An older license, called the Affero General Public License and published by Affero, was designed to accomplish similar goals. This is a different license, not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this license. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU Affero General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Remote Network Interaction; Use with the GNU General Public License. Notwithstanding any other provision of this License, if you modify the Program, your modified version must prominently offer all users interacting with it remotely through a computer network (if your version supports such interaction) an opportunity to receive the Corresponding Source of your version by providing access to the Corresponding Source from a network server at no charge, through some standard or customary means of facilitating copying of software. This Corresponding Source shall include the Corresponding Source for any work covered by version 3 of the GNU General Public License that is incorporated pursuant to the following paragraph. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the work with which it is combined will remain governed by version 3 of the GNU General Public License. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU Affero General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU Affero General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU Affero General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU Affero General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. <one line to give the program's name and a brief idea of what it does.> Copyright (C) <year> <name of author> This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. Also add information on how to contact you by electronic and paper mail. If your software can interact with users remotely through a computer network, you should also make sure that it provides a way for users to get its source. For example, if your program is a web application, its interface could display a "Source" link that leads users to an archive of the code. There are many ways you could offer source, and different solutions will be better for different programs; see section 13 for the specific requirements. You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>.
YAML
algo/main.yml
--- - hosts: localhost become: false tasks: - name: Playbook dir stat stat: path: "{{ playbook_dir }}" register: _playbook_dir - name: Ensure Ansible is not being run in a world writable directory assert: that: _playbook_dir.stat.mode|int <= 775 msg: > Ansible is being run in a world writable directory ({{ playbook_dir }}), ignoring it as an ansible.cfg source. For more information see https://docs.ansible.com/ansible/devel/reference_appendices/config.html#cfg-in-world-writable-dir - name: Ensure the requirements installed debug: msg: "{{ '' | ipaddr }}" ignore_errors: true no_log: true register: ipaddr - name: Set required ansible version as a fact set_fact: required_ansible_version: "{{ item | regex_replace('^ansible[\\s+]?(?P<op>[=,>,<]+)[\\s+]?(?P<ver>\\d.\\d+(.\\d+)?)$', '{\"op\": \"\\g<op>\",\"ver\"\ : \"\\g<ver>\" }') }}" when: '"ansible" in item' with_items: "{{ lookup('file', 'requirements.txt').splitlines() }}" - name: Just get the list from default pip community.general.pip_package_info: register: pip_package_info - name: Verify Python meets Algo VPN requirements assert: that: (ansible_python.version.major|string + '.' + ansible_python.version.minor|string) is version('3.8', '>=') msg: > Python version is not supported. You must upgrade to at least Python 3.8 to use this version of Algo. See for more details - https://trailofbits.github.io/algo/troubleshooting.html#python-version-is-not-supported - name: Verify Ansible meets Algo VPN requirements assert: that: - pip_package_info.packages.pip.ansible.0.version is version(required_ansible_version.ver, required_ansible_version.op) - not ipaddr.failed msg: > Ansible version is {{ pip_package_info.packages.pip.ansible.0.version }}. You must update the requirements to use this version of Algo. Try to run python3 -m pip install -U -r requirements.txt - name: Include prompts playbook import_playbook: input.yml - name: Include cloud provisioning playbook import_playbook: cloud.yml - name: Include server configuration playbook import_playbook: server.yml
algo/Makefile
## docker-build: Build and tag a docker image .PHONY: docker-build IMAGE := trailofbits/algo TAG := latest DOCKERFILE := Dockerfile CONFIGURATIONS := $(shell pwd) docker-build: docker build \ -t $(IMAGE):$(TAG) \ -f $(DOCKERFILE) \ . ## docker-deploy: Mount config directory and deploy Algo .PHONY: docker-deploy # '--rm' flag removes the container when finished. docker-deploy: docker run \ --cap-drop=all \ --rm \ -it \ -v $(CONFIGURATIONS):/data \ $(IMAGE):$(TAG) ## docker-clean: Remove images and containers. .PHONY: docker-prune docker-prune: docker images \ $(IMAGE) |\ awk '{if (NR>1) print $$3}' |\ xargs docker rmi ## docker-all: Build, Deploy, Prune .PHONY: docker-all docker-all: docker-build docker-deploy docker-prune
Markdown
algo/PULL_REQUEST_TEMPLATE.md
<!--- Provide a general summary of your changes in the Title above --> ## Description <!--- Describe your changes in detail --> ## Motivation and Context <!--- Why is this change required? What problem does it solve? --> <!--- If it fixes an open issue, please link to the issue here. --> ## How Has This Been Tested? <!--- Please describe in detail how you tested your changes. --> <!--- Include details of your testing environment, tests ran to see how --> <!--- your change affects other areas of the code, etc. --> ## Types of changes <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) - Breaking change (fix or feature that would cause existing functionality to not work as expected) ## Checklist: <!--- Go over all the following points, and put an `x` in all the boxes that apply. --> <!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [] I have read the **CONTRIBUTING** document. - [] My code follows the code style of this project. - [] My change requires a change to the documentation. - [] I have updated the documentation accordingly. - [] I have added tests to cover my changes. - [] All new and existing tests passed.
Markdown
algo/README.md
# Algo VPN [![Twitter](https://img.shields.io/twitter/url/https/twitter.com/fold_left.svg?style=social&label=Follow%20%40AlgoVPN)](https://twitter.com/AlgoVPN) [![](https://github.com/trailofbits/algo/workflows/Main/badge.svg?branch=master)](https://github.com/trailofbits/algo/actions) Algo VPN is a set of Ansible scripts that simplify the setup of a personal WireGuard and IPsec VPN. It uses the most secure defaults available and works with common cloud providers. See our [release announcement](https://blog.trailofbits.com/2016/12/12/meet-algo-the-vpn-that-works/) for more information. ## Features * Supports only IKEv2 with strong crypto (AES-GCM, SHA2, and P-256) for iOS, macOS, and Linux * Supports [WireGuard](https://www.wireguard.com/) for all of the above, in addition to Android and Windows 10 * Generates .conf files and QR codes for iOS, macOS, Android, and Windows WireGuard clients * Generates Apple profiles to auto-configure iOS and macOS devices for IPsec - no client software required * Includes a helper script to add and remove users * Blocks ads with a local DNS resolver (optional) * Sets up limited SSH users for tunneling traffic (optional) * Based on current versions of Ubuntu and strongSwan * Installs to DigitalOcean, Amazon Lightsail, Amazon EC2, Vultr, Microsoft Azure, Google Compute Engine, Scaleway, OpenStack, CloudStack, Hetzner Cloud, Linode, or [your own Ubuntu server (for more advanced users)](docs/deploy-to-ubuntu.md) ## Anti-features * Does not support legacy cipher suites or protocols like L2TP, IKEv1, or RSA * Does not install Tor, OpenVPN, or other risky servers * Does not depend on the security of [TLS](https://tools.ietf.org/html/rfc7457) * Does not claim to provide anonymity or censorship avoidance * Does not claim to protect you from the [FSB](https://en.wikipedia.org/wiki/Federal_Security_Service), [MSS](https://en.wikipedia.org/wiki/Ministry_of_State_Security_(China)), [DGSE](https://en.wikipedia.org/wiki/Directorate-General_for_External_Security), or [FSM](https://en.wikipedia.org/wiki/Flying_Spaghetti_Monster) ## Deploy the Algo Server The easiest way to get an Algo server running is to run it on your local system or from [Google Cloud Shell](docs/deploy-from-cloudshell.md) and let it set up a _new_ virtual machine in the cloud for you. 1. **Setup an account on a cloud hosting provider.** Algo supports [DigitalOcean](https://m.do.co/c/4d7f4ff9cfe4) (most user friendly), [Amazon Lightsail](https://aws.amazon.com/lightsail/), [Amazon EC2](https://aws.amazon.com/), [Vultr](https://www.vultr.com/), [Microsoft Azure](https://azure.microsoft.com/), [Google Compute Engine](https://cloud.google.com/compute/), [Scaleway](https://www.scaleway.com/), [DreamCompute](https://www.dreamhost.com/cloud/computing/), [Linode](https://www.linode.com), or other OpenStack-based cloud hosting, [Exoscale](https://www.exoscale.com) or other CloudStack-based cloud hosting, or [Hetzner Cloud](https://www.hetzner.com/). 2. **Get a copy of Algo.** The Algo scripts will be installed on your local system. There are two ways to get a copy: - Download the [ZIP file](https://github.com/trailofbits/algo/archive/master.zip). Unzip the file to create a directory named `algo-master` containing the Algo scripts. - Use `git clone` to create a directory named `algo` containing the Algo scripts: ```bash git clone https://github.com/trailofbits/algo.git ``` 3. **Install Algo's core dependencies.** Algo requires that **Python 3.8 or later** and at least one supporting package are installed on your system. - **macOS:** Catalina (10.15) and higher includes Python 3 as part of the optional Command Line Developer Tools package. From Terminal run: ```bash python3 -m pip install --user --upgrade virtualenv ``` If prompted, install the Command Line Developer Tools and re-run the above command. For macOS versions prior to Catalina, see [Deploy from macOS](docs/deploy-from-macos.md) for information on installing Python 3 . - **Linux:** Recent releases of Ubuntu, Debian, and Fedora come with Python 3 already installed. Make sure your system is up-to-date and install the supporting package(s): * Ubuntu and Debian: ```bash sudo apt install -y --no-install-recommends python3-virtualenv ``` On a Raspberry Pi running Ubuntu also install `libffi-dev` and `libssl-dev`. * Fedora: ```bash sudo dnf install -y python3-virtualenv ``` - **Windows:** Use the Windows Subsystem for Linux (WSL) to create your own copy of Ubuntu running under Windows from which to install and run Algo. See the [Windows documentation](docs/deploy-from-windows.md) for more information. 4. **Install Algo's remaining dependencies.** You'll need to run these commands from the Algo directory each time you download a new copy of Algo. In a Terminal window `cd` into the `algo-master` (ZIP file) or `algo` (`git clone`) directory and run: ```bash python3 -m virtualenv --python="$(command -v python3)" .env && source .env/bin/activate && python3 -m pip install -U pip virtualenv && python3 -m pip install -r requirements.txt ``` On Fedora first run `export TMPDIR=/var/tmp`, then add the option `--system-site-packages` to the first command above (after `python3 -m virtualenv`). On macOS install the C compiler if prompted. 5. **Set your configuration options.** Open the file `config.cfg` in your favorite text editor. Specify the users you wish to create in the `users` list. Create a unique user for each device you plan to connect to your VPN. > Note: [IKEv2 Only] If you want to add or delete users later, you **must** select `yes` at the `Do you want to retain the keys (PKI)?` prompt during the server deployment. You should also review the other options before deployment, as changing your mind about them later [may require you to deploy a brand new server](https://github.com/trailofbits/algo/blob/master/docs/faq.md#i-deployed-an-algo-server-can-you-update-it-with-new-features). 6. **Start the deployment.** Return to your terminal. In the Algo directory, run `./algo` and follow the instructions. There are several optional features available, none of which are required for a fully functional VPN server. These optional features are described in greater detail in [here](docs/deploy-from-ansible.md). That's it! You will get the message below when the server deployment process completes. Take note of the p12 (user certificate) password and the CA key in case you need them later, **they will only be displayed this time**. You can now set up clients to connect to your VPN. Proceed to [Configure the VPN Clients](#configure-the-vpn-clients) below. ``` "# Congratulations! #" "# Your Algo server is running. #" "# Config files and certificates are in the ./configs/ directory. #" "# Go to https://whoer.net/ after connecting #" "# and ensure that all your traffic passes through the VPN. #" "# Local DNS resolver 172.16.0.1 #" "# The p12 and SSH keys password for new users is XXXXXXXX #" "# The CA key password is XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX #" "# Shell access: ssh -F configs/<server_ip>/ssh_config <hostname> #" ``` ## Configure the VPN Clients Certificates and configuration files that users will need are placed in the `configs` directory. Make sure to secure these files since many contain private keys. All files are saved under a subdirectory named with the IP address of your new Algo VPN server. ### Apple Devices WireGuard is used to provide VPN services on Apple devices. Algo generates a WireGuard configuration file, `wireguard/<username>.conf`, and a QR code, `wireguard/<username>.png`, for each user defined in `config.cfg`. On iOS, install the [WireGuard](https://itunes.apple.com/us/app/wireguard/id1441195209?mt=8) app from the iOS App Store. Then, use the WireGuard app to scan the QR code or AirDrop the configuration file to the device. On macOS Mojave or later, install the [WireGuard](https://itunes.apple.com/us/app/wireguard/id1451685025?mt=12) app from the Mac App Store. WireGuard will appear in the menu bar once you run the app. Click on the WireGuard icon, choose **Import tunnel(s) from file...**, then select the appropriate WireGuard configuration file. On either iOS or macOS, you can enable "Connect on Demand" and/or exclude certain trusted Wi-Fi networks (such as your home or work) by editing the tunnel configuration in the WireGuard app. (Algo can't do this automatically for you.) Installing WireGuard is a little more complicated on older version of macOS. See [Using macOS as a Client with WireGuard](docs/client-macos-wireguard.md). If you prefer to use the built-in IPSEC VPN on Apple devices, or need "Connect on Demand" or excluded Wi-Fi networks automatically configured, then see [Using Apple Devices as a Client with IPSEC](docs/client-apple-ipsec.md). ### Android Devices WireGuard is used to provide VPN services on Android. Install the [WireGuard VPN Client](https://play.google.com/store/apps/details?id=com.wireguard.android). Import the corresponding `wireguard/<name>.conf` file to your device, then setup a new connection with it. See the [Android setup instructions](/docs/client-android.md) for more detailed walkthrough. ### Windows WireGuard is used to provide VPN services on Windows. Algo generates a WireGuard configuration file, `wireguard/<username>.conf`, for each user defined in `config.cfg`. Install the [WireGuard VPN Client](https://www.wireguard.com/install/#windows-7-8-81-10-2012-2016-2019). Import the generated `wireguard/<username>.conf` file to your device, then setup a new connection with it. ### Linux WireGuard Clients WireGuard works great with Linux clients. See [this page](docs/client-linux-wireguard.md) for an example of how to configure WireGuard on Ubuntu. ### Linux strongSwan IPsec Clients (e.g., OpenWRT, Ubuntu Server, etc.) Please see [this page](docs/client-linux-ipsec.md). ### OpenWrt Wireguard Clients Please see [this page](docs/client-openwrt-router-wireguard.md). ### Other Devices Depending on the platform, you may need one or multiple of the following files. * ipsec/manual/cacert.pem: CA Certificate * ipsec/manual/<user>.p12: User Certificate and Private Key (in PKCS#12 format) * ipsec/manual/<user>.conf: strongSwan client configuration * ipsec/manual/<user>.secrets: strongSwan client configuration * ipsec/apple/<user>.mobileconfig: Apple Profile * wireguard/<user>.conf: WireGuard configuration profile * wireguard/<user>.png: WireGuard configuration QR code ## Setup an SSH Tunnel If you turned on the optional SSH tunneling role, then local user accounts will be created for each user in `config.cfg` and SSH authorized_key files for them will be in the `configs` directory (user.ssh.pem). SSH user accounts do not have shell access, cannot authenticate with a password, and only have limited tunneling options (e.g., `ssh -N` is required). This ensures that SSH users have the least access required to setup a tunnel and can perform no other actions on the Algo server. Use the example command below to start an SSH tunnel by replacing `<user>` and `<ip>` with your own. Once the tunnel is setup, you can configure a browser or other application to use 127.0.0.1:1080 as a SOCKS proxy to route traffic through the Algo server: ```bash ssh -D 127.0.0.1:1080 -f -q -C -N <user>@algo -i configs/<ip>/ssh-tunnel/<user>.pem -F configs/<ip>/ssh_config ``` ## SSH into Algo Server Your Algo server is configured for key-only SSH access for administrative purposes. Open the Terminal app, `cd` into the `algo-master` directory where you originally downloaded Algo, and then use the command listed on the success message: ``` ssh -F configs/<ip>/ssh_config <hostname> ``` where `<ip>` is the IP address of your Algo server. If you find yourself regularly logging into the server then it will be useful to load your Algo ssh key automatically. Add the following snippet to the bottom of `~/.bash_profile` to add it to your shell environment permanently: ``` ssh-add ~/.ssh/algo > /dev/null 2>&1 ``` Alternatively, you can choose to include the generated configuration for any Algo servers created into your SSH config. Edit the file `~/.ssh/config` to include this directive at the top: ``` Include <algodirectory>/configs/*/ssh_config ``` where `<algodirectory>` is the directory where you cloned Algo. ## Adding or Removing Users _If you chose to save the CA key during the deploy process,_ then Algo's own scripts can easily add and remove users from the VPN server. 1. Update the `users` list in your `config.cfg` 2. Open a terminal, `cd` to the algo directory, and activate the virtual environment with `source .env/bin/activate` 3. Run the command: `./algo update-users` After this process completes, the Algo VPN server will contain only the users listed in the `config.cfg` file. ## Additional Documentation * [FAQ](docs/faq.md) * [Troubleshooting](docs/troubleshooting.md) * How Algo uses [Firewalls](docs/firewalls.md) ### Setup Instructions for Specific Cloud Providers * Configure [Amazon EC2](docs/cloud-amazon-ec2.md) * Configure [Azure](docs/cloud-azure.md) * Configure [DigitalOcean](docs/cloud-do.md) * Configure [Google Cloud Platform](docs/cloud-gce.md) * Configure [Vultr](docs/cloud-vultr.md) * Configure [CloudStack](docs/cloud-cloudstack.md) * Configure [Hetzner Cloud](docs/cloud-hetzner.md) ### Install and Deploy from Common Platforms * Deploy from [macOS](docs/deploy-from-macos.md) * Deploy from [Windows](docs/deploy-from-windows.md) * Deploy from [Google Cloud Shell](docs/deploy-from-cloudshell.md) * Deploy from a [Docker container](docs/deploy-from-docker.md) ### Setup VPN Clients to Connect to the Server * Setup [Android](docs/client-android.md) clients * Setup [Linux](docs/client-linux.md) clients with Ansible * Setup Ubuntu clients to use [WireGuard](docs/client-linux-wireguard.md) * Setup Linux clients to use [IPsec](docs/client-linux-ipsec.md) * Setup Apple devices to use [IPsec](docs/client-apple-ipsec.md) * Setup Macs running macOS 10.13 or older to use [WireGuard](docs/client-macos-wireguard.md) ### Advanced Deployment * Deploy to your own [Ubuntu](docs/deploy-to-ubuntu.md) server, and road warrior setup * Deploy from [Ansible](docs/deploy-from-ansible.md) non-interactively * Deploy onto a [cloud server at time of creation with shell script or cloud-init](docs/deploy-from-script-or-cloud-init-to-localhost.md) * Deploy to an [unsupported cloud provider](docs/deploy-to-unsupported-cloud.md) * Deploy to your own [FreeBSD](docs/deploy-to-freebsd.md) server If you've read all the documentation and have further questions, [create a new discussion](https://github.com/trailofbits/algo/discussions). ## Endorsements > I've been ranting about the sorry state of VPN svcs for so long, probably about > time to give a proper talk on the subject. TL;DR: use Algo. -- [Kenn White](https://twitter.com/kennwhite/status/814166603587788800) > Before picking a VPN provider/app, make sure you do some research > https://research.csiro.au/ng/wp-content/uploads/sites/106/2016/08/paper-1.pdf ... – or consider Algo -- [The Register](https://twitter.com/TheRegister/status/825076303657177088) > Algo is really easy and secure. -- [the grugq](https://twitter.com/thegrugq/status/786249040228786176) > I played around with Algo VPN, a set of scripts that let you set up a VPN in the cloud in very little time, even if you don’t know much about development. I’ve got to say that I was quite impressed with Trail of Bits’ approach. -- [Romain Dillet](https://twitter.com/romaindillet/status/851037243728965632) for [TechCrunch](https://techcrunch.com/2017/04/09/how-i-made-my-own-vpn-server-in-15-minutes/) > If you’re uncomfortable shelling out the cash to an anonymous, random VPN provider, this is the best solution. -- [Thorin Klosowski](https://twitter.com/kingthor) for [Lifehacker](http://lifehacker.com/how-to-set-up-your-own-completely-free-vpn-in-the-cloud-1794302432) ## Support Algo VPN [![Flattr](https://button.flattr.com/flattr-badge-large.png)](https://flattr.com/submit/auto?fid=kxw60j&url=https%3A%2F%2Fgithub.com%2Ftrailofbits%2Falgo) [![PayPal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CYZZD39GXUJ3E) [![Patreon](https://img.shields.io/badge/back_on-patreon-red.svg)](https://www.patreon.com/algovpn) [![Bountysource](https://img.shields.io/bountysource/team/trailofbits/activity.svg)](https://www.bountysource.com/teams/trailofbits) All donations support continued development. Thanks! * We accept donations via [PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CYZZD39GXUJ3E), [Patreon](https://www.patreon.com/algovpn), and [Flattr](https://flattr.com/submit/auto?fid=kxw60j&url=https%3A%2F%2Fgithub.com%2Ftrailofbits%2Falgo). * Use our [referral code](https://m.do.co/c/4d7f4ff9cfe4) when you sign up to Digital Ocean for a $10 credit. * We also accept and appreciate contributions of new code and bugfixes via Github Pull Requests. Algo is licensed and distributed under the AGPLv3. If you want to distribute a closed-source modification or service based on Algo, then please consider <a href="mailto:opensource@trailofbits.com">purchasing an exception</a> . As with the methods above, this will help support continued development.
YAML
algo/server.yml
--- - name: Configure the server and install required software hosts: vpn-host gather_facts: false become: true vars_files: - config.cfg tasks: - block: - name: Wait until the cloud-init completed wait_for: path: /var/lib/cloud/data/result.json delay: 10 timeout: 600 state: present become: false when: cloudinit - block: - name: Ensure the config directory exists file: dest: configs/{{ IP_subject_alt_name }} state: directory mode: "0700" - name: Dump the ssh config copy: dest: configs/{{ IP_subject_alt_name }}/ssh_config mode: "0600" content: | Host {{ IP_subject_alt_name }} {{ algo_server_name }} HostName {{ IP_subject_alt_name }} User {{ ansible_ssh_user }} Port {{ ansible_ssh_port }} IdentityFile {{ SSH_keys.private | realpath }} KeepAlive yes ServerAliveInterval 30 when: inventory_hostname != 'localhost' become: false delegate_to: localhost - import_role: name: common tags: common - import_role: name: dns when: - algo_dns_adblocking or dns_encryption tags: dns - import_role: name: wireguard when: wireguard_enabled tags: wireguard - import_role: name: strongswan when: ipsec_enabled tags: ipsec - import_role: name: ssh_tunneling when: algo_ssh_tunneling tags: ssh_tunneling - block: - name: Dump the configuration copy: dest: configs/{{ IP_subject_alt_name }}/.config.yml content: | server: {{ 'localhost' if inventory_hostname == 'localhost' else inventory_hostname }} server_user: {{ ansible_ssh_user }} ansible_ssh_port: "{{ ansible_ssh_port|default(22) }}" {% if algo_provider != "local" %} ansible_ssh_private_key_file: {{ SSH_keys.private }} {% endif %} algo_provider: {{ algo_provider }} algo_server_name: {{ algo_server_name }} algo_ondemand_cellular: {{ algo_ondemand_cellular }} algo_ondemand_wifi: {{ algo_ondemand_wifi }} algo_ondemand_wifi_exclude: {{ algo_ondemand_wifi_exclude }} algo_dns_adblocking: {{ algo_dns_adblocking }} algo_ssh_tunneling: {{ algo_ssh_tunneling }} algo_store_pki: {{ algo_store_pki }} IP_subject_alt_name: {{ IP_subject_alt_name }} ipsec_enabled: {{ ipsec_enabled }} wireguard_enabled: {{ wireguard_enabled }} {% if tests|default(false)|bool %} ca_password: '{{ CA_password }}' p12_password: '{{ p12_export_password }}' {% endif %} become: false delegate_to: localhost - name: Create a symlink if deploying to localhost file: src: "{{ IP_subject_alt_name }}" dest: configs/localhost state: link force: true when: inventory_hostname == 'localhost' - name: Import tmpfs tasks import_tasks: playbooks/tmpfs/umount.yml become: false delegate_to: localhost vars: facts: "{{ hostvars['localhost'] }}" when: - pki_in_tmpfs - not algo_store_pki - debug: msg: - "{{ congrats.common.split('\n') }}" - " {{ congrats.p12_pass if algo_ssh_tunneling or ipsec_enabled else '' }}" - " {{ congrats.ca_key_pass if algo_store_pki and ipsec_enabled else '' }}" - " {{ congrats.ssh_access if algo_provider != 'local' else ''}}" tags: always rescue: - include_tasks: playbooks/rescue.yml
YAML
algo/users.yml
--- - hosts: localhost gather_facts: false tags: always vars_files: - config.cfg tasks: - block: - name: Get list of installed config files find: paths: configs/ depth: 2 recurse: true hidden: true patterns: .config.yml register: _configs_list - name: Verify servers assert: that: _configs_list.matched > 0 msg: No servers found, nothing to update. - name: Build list of installed servers set_fact: server_list: >- [{% for i in _configs_list.files %} {% set config = lookup('file', i.path)|from_yaml %} '{{ config.server }}' {{ ',' if not loop.last else '' }} {% endfor %}] - name: Server address prompt pause: prompt: | Select the server to update user list below: {% for r in server_list %} {{ loop.index }}. {{ r }} {% endfor %} register: _server when: server is undefined - block: - name: Set facts based on the input set_fact: algo_server: >- {% if server is defined %}{{ server }} {%- elif _server.user_input %}{{ server_list[_server.user_input | int -1 ] }} {%- else %}omit{% endif %} - name: Import host specific variables include_vars: file: configs/{{ algo_server }}/.config.yml - when: ipsec_enabled block: - name: CA password prompt pause: prompt: Enter the password for the private CA key echo: false register: _ca_password when: ca_password is undefined - name: Set facts based on the input set_fact: CA_password: >- {% if ca_password is defined %}{{ ca_password }} {%- elif _ca_password.user_input %}{{ _ca_password.user_input }} {%- else %}omit{% endif %} - name: Local pre-tasks import_tasks: playbooks/cloud-pre.yml become: false - name: Add the server to the vpn-host group add_host: name: "{{ algo_server }}" groups: vpn-host ansible_ssh_user: "{{ server_user|default('root') }}" ansible_connection: "{% if algo_server == 'localhost' %}local{% else %}ssh{% endif %}" ansible_python_interpreter: /usr/bin/python3 CA_password: "{{ CA_password|default(omit) }}" rescue: - include_tasks: playbooks/rescue.yml - name: User management hosts: vpn-host gather_facts: true become: true vars_files: - config.cfg - configs/{{ inventory_hostname }}/.config.yml tasks: - block: - import_role: name: common - import_role: name: wireguard when: wireguard_enabled - import_role: name: strongswan when: ipsec_enabled tags: ipsec - import_role: name: ssh_tunneling when: algo_ssh_tunneling - debug: msg: - "{{ congrats.common.split('\n') }}" - " {{ congrats.p12_pass if algo_ssh_tunneling or ipsec_enabled else '' }}" - " {{ congrats.ca_key_pass if algo_store_pki and ipsec_enabled else '' }}" - " {{ congrats.ssh_access if algo_provider != 'local' else ''}}" tags: always rescue: - include_tasks: playbooks/rescue.yml
algo/Vagrantfile
Vagrant.configure("2") do |config| config.vm.box = "bento/ubuntu-20.04" config.vm.provider "virtualbox" do |v| v.name = "algo-20.04" v.memory = "512" v.cpus = "1" end config.vm.synced_folder "./", "/opt/algo", create: true config.vm.provision "ansible_local" do |ansible| ansible.playbook = "/opt/algo/main.yml" # https://github.com/hashicorp/vagrant/issues/12204 ansible.pip_install_cmd = "sudo apt-get install -y python3-pip python-is-python3 && sudo ln -s -f /usr/bin/pip3 /usr/bin/pip" ansible.install_mode = "pip_args_only" ansible.pip_args = "-r /opt/algo/requirements.txt" ansible.inventory_path = "/opt/algo/inventory" ansible.limit = "local" ansible.verbose = "-vvvv" ansible.extra_vars = { provider: "local", server: "localhost", ssh_user: "", endpoint: "127.0.0.1", ondemand_cellular: true, ondemand_wifi: false, dns_adblocking: true, ssh_tunneling: true, store_pki: true, tests: true, no_log: false } end end
YAML
algo/.github/dependabot.yml
version: 2 updates: # Maintain dependencies for GitHub Actions - package-ecosystem: "github-actions" directory: "/" schedule: interval: "daily" # Maintain dependencies for Python - package-ecosystem: "pip" directory: "/" schedule: interval: "daily"
YAML
algo/.github/FUNDING.yml
# These are supported funding model platforms github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] patreon: algovpn open_collective: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry liberapay: # Replace with a single Liberapay username issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username custom: # Replace with a single custom sponsorship URL
Markdown
algo/.github/ISSUE_TEMPLATE/bug_report.md
--- name: Bug report about: Create a report to help us improve --- **Describe the bug** A clear and concise description of what the bug is. **To Reproduce** Steps to reproduce the behavior: 1. Do this.. 2. Do that.. 3. .. **Expected behavior** A clear and concise description of what you expected to happen. **Additional context** Add any other context about the problem here. **Full log** <!--- Put here the FULL LOG after you run the ./algo script below --> ``` PUT THE OUTPUT HERE ```
Markdown
algo/.github/ISSUE_TEMPLATE/feature_request.md
--- name: Feature request about: Suggest an idea for this project --- **Is your feature request related to a problem? Please describe.** A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] **Describe the solution you'd like** A clear and concise description of what you want to happen. **Describe alternatives you've considered** A clear and concise description of any alternative solutions or features you've considered. **Additional context** Add any other context or screenshots about the feature request here.
YAML
algo/.github/workflows/docker-image.yaml
name: Create and publish a Docker image on: push: branches: ['master'] env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} jobs: build-and-push-image: runs-on: ubuntu-latest permissions: contents: read packages: write steps: - name: Checkout repository uses: actions/checkout@v3 - name: Log in to the Container registry uses: docker/login-action@v2 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@v4 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | # set latest tag for master branch type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }} - name: Build and push Docker image uses: docker/build-push-action@v4 with: context: . push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }}
YAML
algo/.github/workflows/main.yml
name: Main on: [push, pull_request] jobs: lint: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v2.3.2 with: python-version: '3.9' cache: 'pip' - name: Install dependencies env: DEBIAN_FRONTEND: noninteractive run: | sudo apt update -y python -m pip install --upgrade pip pip install -r requirements.txt sudo snap install shellcheck pip install ansible-lint - name: Checks and linters run: | /snap/bin/shellcheck algo install.sh ansible-playbook main.yml --syntax-check ansible-lint -x experimental,package-latest,unnamed-task -v *.yml roles/{local,cloud-*}/*/*.yml || true scripted-deploy: runs-on: ubuntu-20.04 strategy: matrix: UBUNTU_VERSION: ["22.04"] steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v2.3.2 with: python-version: '3.9' cache: 'pip' - name: Install dependencies env: DEBIAN_FRONTEND: noninteractive run: | sudo apt update -y sudo apt install -y \ wireguard \ libxml2-utils \ crudini \ fping \ strongswan \ libstrongswan-standard-plugins \ openresolv python3 -m pip install --upgrade pip python3 -m pip install -r requirements.txt sudo snap refresh lxd sudo lxd init --auto - name: Provision env: DEPLOY: cloud-init UBUNTU_VERSION: ${{ matrix.UBUNTU_VERSION }} REPOSITORY: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name || github.repository }} BRANCH: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref }} run: | ssh-keygen -f ~/.ssh/id_rsa -t rsa -N '' # sed -i "s/^reduce_mtu:\s0$/reduce_mtu: 80/" config.cfg sudo -E ./tests/pre-deploy.sh - name: Deployment run: | set -x until sudo lxc exec algo -- test -f /var/log/cloud-init-output.log; do echo 'Log file not found, Sleep for 3 seconds'; sleep 3; done ( sudo lxc exec algo -- tail -f /var/log/cloud-init-output.log & ) until sudo lxc exec algo -- test -f /var/lib/cloud/data/result.json; do echo 'Cloud init is not finished. Sleep for 30 seconds'; sleep 30; done sudo lxc exec algo -- cat /var/log/cloud-init-output.log sudo lxc exec algo -- test -f /opt/algo/configs/localhost/.config.yml sudo lxc exec algo -- tar zcf /root/algo-configs.tar -C /opt/algo/configs/ . sudo lxc file pull algo/root/algo-configs.tar ./ sudo tar -C ./configs -zxf algo-configs.tar - name: Tests run: | set -x sudo -E bash -x ./tests/wireguard-client.sh sudo env "PATH=$PATH" ./tests/ipsec-client.sh docker-deploy: runs-on: ubuntu-20.04 strategy: matrix: UBUNTU_VERSION: ["22.04"] steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v2.3.2 with: python-version: '3.9' cache: 'pip' - name: Install dependencies env: DEBIAN_FRONTEND: noninteractive run: | set -x sudo apt update -y sudo apt install -y \ wireguard \ libxml2-utils \ crudini \ fping \ strongswan \ libstrongswan-standard-plugins \ openresolv python3 -m pip install --upgrade pip python3 -m pip install -r requirements.txt sudo snap refresh lxd sudo lxd init --auto - name: Provision env: DEPLOY: docker UBUNTU_VERSION: ${{ matrix.UBUNTU_VERSION }} REPOSITORY: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name || github.repository }} BRANCH: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref }} run: | ssh-keygen -f ~/.ssh/id_rsa -t rsa -N '' sed -i "s/^reduce_mtu:\s0$/reduce_mtu: 80/" config.cfg sudo -E ./tests/pre-deploy.sh - name: Deployment env: DEPLOY: docker UBUNTU_VERSION: ${{ matrix.UBUNTU_VERSION }} run: | docker build -t local/algo . ./tests/local-deploy.sh ./tests/update-users.sh - name: Tests run: | set -x sudo bash -x ./tests/wireguard-client.sh sudo env "PATH=$PATH" bash -x ./tests/ipsec-client.sh sudo bash -x ./tests/ssh-tunnel.sh
Markdown
algo/docs/client-android.md
# Android client setup ## Installation via profiles 1. [Install the WireGuard VPN Client](https://play.google.com/store/apps/details?id=com.wireguard.android). 2. Open QR code `configs/<ip_address>/wireguard/<username>.png` and scan it in the WireGuard app
Markdown
algo/docs/client-apple-ipsec.md
# Using the built-in IPSEC VPN on Apple Devices ## Configure IPsec Find the corresponding `mobileconfig` (Apple Profile) for each user and send it to them over AirDrop or other secure means. Apple Configuration Profiles are all-in-one configuration files for iOS and macOS devices. On macOS, double-clicking a profile to install it will fully configure the VPN. On iOS, users are prompted to install the profile as soon as the AirDrop is accepted. ## Enable the VPN On iOS, connect to the VPN by opening **Settings** and clicking the toggle next to "VPN" near the top of the list. If using WireGuard you can also enable the VPN from the WireGuard app. On macOS, connect to the VPN by opening **System Preferences** -> **Network**, finding the Algo VPN in the left column, and clicking "Connect." Check "Show VPN status in menu bar" to easily connect and disconnect from the menu bar. ## Managing "Connect On Demand" If you enabled "Connect On Demand" the VPN will connect automatically whenever it is able. Most Apple users will want to enable "Connect On Demand", but if you do then simply disabling the VPN will not cause it to stay disabled; it will just "Connect On Demand" again. To disable the VPN you'll need to disable "Connect On Demand". On iOS, you can turn off "Connect On Demand" in **Settings** by clicking the (i) next to the entry for your Algo VPN and toggling off "Connect On Demand." On macOS, you can turn off "Connect On Demand" by opening **System Preferences** -> **Network**, finding the Algo VPN in the left column, unchecking the box for "Connect on demand", and clicking Apply.
Markdown
algo/docs/client-linux-ipsec.md
# Linux strongSwan IPsec Clients (e.g., OpenWRT, Ubuntu Server, etc.) Install strongSwan, then copy the included ipsec_user.conf, ipsec_user.secrets, user.crt (user certificate), and user.key (private key) files to your client device. These will require customization based on your exact use case. These files were originally generated with a point-to-point OpenWRT-based VPN in mind. ## Ubuntu Server example 1. `sudo apt-get install strongswan libstrongswan-standard-plugins`: install strongSwan 2. `/etc/ipsec.d/certs`: copy `<name>.crt` from `algo-master/configs/<server_ip>/ipsec/.pki/certs/<name>.crt` 3. `/etc/ipsec.d/private`: copy `<name>.key` from `algo-master/configs/<server_ip>/ipsec/.pki/private/<name>.key` 4. `/etc/ipsec.d/cacerts`: copy `cacert.pem` from `algo-master/configs/<server_ip>/ipsec/manual/cacert.pem` 5. `/etc/ipsec.secrets`: add your `user.key` to the list, e.g. `<server_ip> : ECDSA <name>.key` 6. `/etc/ipsec.conf`: add the connection from `ipsec_user.conf` and ensure `leftcert` matches the `<name>.crt` filename 7. `sudo ipsec restart`: pick up config changes 8. `sudo ipsec up <conn-name>`: start the ipsec tunnel 9. `sudo ipsec down <conn-name>`: shutdown the ipsec tunnel One common use case is to let your server access your local LAN without going through the VPN. Set up a passthrough connection by adding the following to `/etc/ipsec.conf`: conn lan-passthrough leftsubnet=192.168.1.1/24 # Replace with your LAN subnet rightsubnet=192.168.1.1/24 # Replace with your LAN subnet authby=never # No authentication necessary type=pass # passthrough auto=route # no need to ipsec up lan-passthrough To configure the connection to come up at boot time replace `auto=add` with `auto=start`. ## Notes on SELinux If you use a system with SELinux enabled you might need to set appropriate file contexts: ```` semanage fcontext -a -t ipsec_key_file_t "$(pwd)(/.*)?" restorecon -R -v $(pwd) ```` See [this comment](https://github.com/trailofbits/algo/issues/263#issuecomment-328053950).
Markdown
algo/docs/client-linux-wireguard.md
# Using Ubuntu as a Client with WireGuard ## Install WireGuard To connect to your AlgoVPN using [WireGuard](https://www.wireguard.com) from Ubuntu, make sure your system is up-to-date then install WireGuard: ```shell # Update your system: sudo apt update && sudo apt upgrade # If the file /var/run/reboot-required exists then reboot: [ -e /var/run/reboot-required ] && sudo reboot # Install WireGuard: sudo apt install wireguard openresolv ``` For installation on other Linux distributions, see the [Installation](https://www.wireguard.com/install/) page on the WireGuard site. ## Locate the Config File The Algo-generated config files for WireGuard are named `configs/<ip_address>/wireguard/<username>.conf` on the system where you ran `./algo`. One file was generated for each of the users you added to `config.cfg`. Each WireGuard client you connect to your AlgoVPN must use a different config file. Choose one of these files and copy it to your Linux client. ## Configure WireGuard Finally, install the config file on your client as `/etc/wireguard/wg0.conf` and start WireGuard: ```shell # Install the config file to the WireGuard configuration directory on your # Linux client: sudo install -o root -g root -m 600 <username>.conf /etc/wireguard/wg0.conf # Start the WireGuard VPN: sudo systemctl start wg-quick@wg0 # Check that it started properly: sudo systemctl status wg-quick@wg0 # Verify the connection to the AlgoVPN: sudo wg # See that your client is using the IP address of your AlgoVPN: curl ipv4.icanhazip.com # Optionally configure the connection to come up at boot time: sudo systemctl enable wg-quick@wg0 ``` If your Linux distribution does not use `systemd` you can bring up WireGuard with `sudo wg-quick up wg0`. ## Using a DNS Search Domain As of the `v1.0.20200510` release of `wireguard-tools` WireGuard supports setting a DNS search domain. In your `wg0.conf` file a non-numeric entry on the `DNS` line will be used as a search domain. For example this: ``` DNS = 172.27.153.31, fd00::b:991f, mydomain.com ``` will cause your `/etc/resolv.conf` to contain: ``` search mydomain.com nameserver 172.27.153.31 nameserver fd00::b:991f ```
Markdown
algo/docs/client-linux.md
# Linux client setup ## Provision client config After you deploy a server, you can use an included Ansible script to provision Linux clients too! Debian, Ubuntu, CentOS, and Fedora are supported. The playbook is `deploy_client.yml`. ### Required variables * `client_ip` - The IP address of your client machine (You can use `localhost` in order to deploy locally) * `vpn_user` - The username. (Ensure that you have valid certificates and keys in the `configs/SERVER_ip/pki/` directory) * `ssh_user` - The username that we need to use in order to connect to the client machine via SSH (ignore if you are deploying locally) * `server_ip` - The vpn server ip address ### Example ```shell ansible-playbook deploy_client.yml -e 'client_ip=client.com vpn_user=jack server_ip=vpn-server.com ssh_user=root' ``` ### Additional options If the user requires sudo password use the following argument: `--ask-become-pass`. ## OS Specific instructions Some Linux clients may require more specific and details instructions to configure a connection to the deployed Algo VPN, these are documented here. ### Fedora Workstation #### (Gnome) Network Manager install First, install the required plugins. ```` dnf install NetworkManager-strongswan NetworkManager-strongswan-gnome ```` #### (Gnome) Network Manager configuration In this example we'll assume the IP of our Algo VPN server is `1.2.3.4` and the user we created is `user-name`. * Go to *Settings* > *Network* * Add a new Network (`+` bottom left of the window) * Select *IPsec/IKEv2 (strongswan)* * Fill out the options: * Name: your choice, e.g.: *ikev2-1.2.3.4* * Gateway: * Address: IP of the Algo VPN server, e.g: `1.2.3.4` * Certificate: `cacert.pem` found at `/path/to/algo/configs/1.2.3.4/ipsec/.pki/cacert.pem` * Client: * Authentication: *Certificate/Private key* * Certificate: `user-name.crt` found at `/path/to/algo/configs/1.2.3.4/ipsec/.pki/certs/user-name.crt` * Private key: `user-name.key` found at `/path/to/algo/configs/1.2.3.4/ipsec/.pki/private/user-name.key` * Options: * Check *Request an inner IP address*, connection will fail without this option * Optionally check *Enforce UDP encapsulation* * Optionally check *Use IP compression* * For the later 2 options, hover to option in the settings to see a description * Cipher proposal: * Check *Enable custom proposals* * IKE: `aes256gcm16-prfsha512-ecp384` * ESP: `aes256gcm16-ecp384` * Apply and turn the connection on, you should now be connected
Markdown
algo/docs/client-macos-wireguard.md
# MacOS WireGuard Client Setup The WireGuard macOS app is unavailable for older operating systems. Please update your operating system if you can. If you are on a macOS High Sierra (10.13) or earlier, then you can still use WireGuard via their userspace drivers via the process detailed below. ## Install WireGuard Install the wireguard-go userspace driver: ``` brew install wireguard-tools ``` ## Locate the Config File Algo generates a WireGuard configuration file, `wireguard/<username>.conf`, and a QR code, `wireguard/<username>.png`, for each user defined in `config.cfg`. Find the configuration file and copy it to your device if you don't already have it. Note that each client you use to connect to Algo VPN must have a unique WireGuard config. ## Configure WireGuard You'll need to copy the appropriate WireGuard configuration file into a location where the userspace driver can find it. After it is in the right place, start the VPN, and verify connectivity. ``` # Copy the config file to the WireGuard configuration directory on your macOS device mkdir /usr/local/etc/wireguard/ cp <username>.conf /usr/local/etc/wireguard/wg0.conf # Start the WireGuard VPN sudo wg-quick up wg0 # Verify the connection to the Algo VPN wg # See that your client is using the IP address of your Algo VPN: curl ipv4.icanhazip.com ```
Markdown
algo/docs/client-openwrt-router-wireguard.md
# Using Router with OpenWRT as a Client with WireGuard This scenario is useful in case you want to use vpn with devices which has no vpn capability like smart tv, or make vpn connection available via router for multiple devices. This is a tested, working scenario with following environment: - algo installed ubuntu at digitalocean - client side router "TP-Link TL-WR1043ND" with openwrt ver. 21.02.1. [Openwrt Install instructions](https://openwrt.org/toh/tp-link/tl-wr1043nd) - or client side router "TP-Link Archer C20i AC750" with openwrt ver. 21.02.1. [Openwrt install instructions](https://openwrt.org/toh/tp-link/archer_c20i) see compatible device list at https://openwrt.org/toh/start . Theoretically any of the device on list should work ## Router setup Make sure that you have - router with openwrt installed, - router is connected to internet, - router and device in front of router does not have same ip . By default openwrt have 192.168.1.1 if so change it to something like 192.168.2.1 ### Install required packages(WebUI) - Open router web UI (mostly http://192.168.1.1 ) - Login. (by default username: root, password:<empty> - System -> Software, click "Update lists" - Install following packages wireguard-tools, kmod-wireguard, luci-app-wireguard, wireguard, kmod-crypto-sha256, kmod-crypto-sha1, kmod-crypto-md5 - restart router ### Alternative Install required packages(ssh) - Open router web UI (mostly http://192.168.1.1 ) - ssh root@192.168.1.1 - opkg update - opkg install wireguard-tools, kmod-wireguard, luci-app-wireguard, wireguard, kmod-crypto-sha256, kmod-crypto-sha1, kmod-crypto-md5 - reboot ### Create an Interface(WebUI) - Open router web UI - Navigate Network -> Interface - Click "Add new interface" - Give a Name. e.g. `AlgoVpn` - Select Protocol. `Wireguard VPN` - click `Create Interface` - In *General Settings* tab - `Bring up on boot` *checked* - Private key: `Interface -> Private Key` from algo config file - Ip Address: `Interface -> Address` from algo config file - In *Peers* tab - Click add - Name `algo` - Public key: `[Peer]->PublicKey` from algo config file - Preshared key: `[Peer]->PresharedKey` from algo config file - Allowed IPs: 0.0.0.0/0 - Route Allowed IPs: checked - Endpoint Host: `[Peer]->Endpoint` ip from algo config file - Endpoint Port: `[Peer]->Endpoint` port from algo config file - Persistent Keep Alive: `25` - Click Save & Save Apply ### Configure Firewall(WebUI) - Open router web UI - Navigate to Network -> Firewall - Click `Add configuration`: - Name: e.g. ivpn_fw - Input: Reject - Output: Accept - Forward: Reject - Masquerading: Checked - MSS clamping: Checked - Covered networks: Select created VPN interface - Allow forward to destination zones - Unspecified - Allow forward from source zones - lan - Click Save & Save Apply - Reboot router There may be additional configuration required depending on environment like dns configuration. You can also verify the configuration using ssh. /etc/config/network. It should look like ``` config interface 'algo' option proto 'wireguard' list addresses '10.0.0.2/32' option private_key '......' # The private key generated by itself just now config wireguard_wg0 option public_key '......' # Server's public key option route_allowed_ips '1' list allowed_ips '0.0.0.0/0' option endpoint_host '......' # Server's public ip address option endpoint_port '51820' option persistent_keepalive '25' ```
Markdown
algo/docs/cloud-alternative-ingress-ip.md
# Alternative Ingress IP This feature allows you to configure the Algo server to send outbound traffic through a different external IP address than the one you are establishing the VPN connection with. ![cloud-alternative-ingress-ip](/docs/images/cloud-alternative-ingress-ip.png) Additional info might be found in [this issue](https://github.com/trailofbits/algo/issues/1047) #### Caveats ##### Extra charges - DigitalOcean: Floating IPs are free when assigned to a Droplet, but after manually deleting a Droplet you need to also delete the Floating IP or you'll get charged for it. ##### IPv6 Some cloud providers provision a VM with an `/128` address block size. This is the only IPv6 address provided and for outbound and incoming traffic. If the provided address block size is bigger, e.g., `/64`, Algo takes a separate address than the one is assigned to the server to send outbound IPv6 traffic.
Markdown
algo/docs/cloud-amazon-ec2.md
# Amazon EC2 cloud setup ## AWS account creation Creating an Amazon AWS account requires giving Amazon a phone number that can receive a call and has a number pad to enter a PIN challenge displayed in the browser. This phone system prompt occasionally fails to correctly validate input, but try again (request a new PIN in the browser) until you succeed. ### Select an EC2 plan The cheapest EC2 plan you can choose is the "Free Plan" a.k.a. the "AWS Free Tier." It is only available to new AWS customers, it has limits on usage, and it converts to standard pricing after 12 months (the "introductory period"). After you exceed the usage limits, after the 12 month period, or if you are an existing AWS customer, then you will pay standard pay-as-you-go service prices. *Note*: Your Algo instance will not stop working when you hit the bandwidth limit, you will just start accumulating service charges on your AWS account. As of the time of this writing (July 2018), the Free Tier limits include "750 hours of Amazon EC2 Linux t2.micro instance usage" per month, 15 GB of bandwidth (outbound) per month, and 30 GB of cloud storage. Algo will not even use 1% of the storage limit, but you may have to monitor your bandwidth usage or keep an eye out for the email from Amazon when you are about to exceed the Free Tier limits. Additional configurations are documented in the [EC2 section of the deploy from ansible guide](https://github.com/trailofbits/algo/blob/master/docs/deploy-from-ansible.md#amazon-ec2) ### Create an AWS permissions policy In the AWS console, find the policies menu: click Services > IAM > Policies. Click Create Policy. Here, you have the policy editor. Switch to the JSON tab and copy-paste over the existing empty policy with [the minimum required AWS policy needed for Algo deployment](https://github.com/trailofbits/algo/blob/master/docs/deploy-from-ansible.md#minimum-required-iam-permissions-for-deployment). When prompted to name the policy, name it `AlgoVPN_Provisioning`. ![Creating a new permissions policy in the AWS console.](/docs/images/aws-ec2-new-policy.png) ### Set up an AWS user In the AWS console, find the users (“Identity and Access Management”, a.k.a. IAM users) menu: click Services > IAM. Activate multi-factor authentication (MFA) on your root account. The simplest choice is the mobile app "Google Authenticator." A hardware U2F token is ideal (less prone to a phishing attack), but a TOTP authenticator like this is good enough. ![The new user screen in the AWS console.](/docs/images/aws-ec2-new-user.png) Now "Create individual IAM users" and click Add User. Create a user name. I chose “algovpn”. Then click the box next to Programmatic Access. Then click Next. ![The IAM user naming screen in the AWS console.](/docs/images/aws-ec2-new-user-name.png) Next, click “Attach existing policies directly.” Type “Algo” in the search box to filter the policies. Find “AlgoVPN_Provisioning” (the policy you created) and click the checkbox next to that. Click Next when you’re done. ![Attaching a policy to an IAM user in the AWS console.](/docs/images/aws-ec2-attach-policy.png) The user creation confirmation screen should look like this if you've done everything correctly. ![New user creation confirmation screen in the AWS console.](/docs/images/aws-ec2-new-user-confirm.png) On the final screen, click the Download CSV button. This file includes the AWS access keys you’ll need during the Algo set-up process. Click Close, and you’re all set. ![Downloading the credentials for an AWS IAM user.](/docs/images/aws-ec2-new-user-csv.png) ## Using EC2 during Algo setup After you have downloaded Algo and installed its dependencies, the next step is running Algo to provision the VPN server on your AWS account. First you will be asked which server type to setup. You would want to enter "3" to use Amazon EC2. ``` $ ./algo What provider would you like to use? 1. DigitalOcean 2. Amazon Lightsail 3. Amazon EC2 4. Microsoft Azure 5. Google Compute Engine 6. Hetzner Cloud 7. Vultr 8. Scaleway 9. OpenStack (DreamCompute optimised) 10. CloudStack (Exoscale optimised) 11. Linode 12. Install to existing Ubuntu server (for more advanced users) Enter the number of your desired provider : 3 ``` Next you will be asked for the AWS Access Key (Access Key ID) and AWS Secret Key (Secret Access Key) that you received in the CSV file when you setup the account (don't worry if you don't see your text entered in the console; the key input is hidden here by Algo). ``` Enter your aws_access_key (http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html) Note: Make sure to use an IAM user with an acceptable policy attached (see https://github.com/trailofbits/algo/blob/master/docs/deploy-from-ansible.md). [pasted values will not be displayed] [AKIA...]: Enter your aws_secret_key (http://docs.aws.amazon.com/general/latest/gr/managing-aws-access-keys.html) [pasted values will not be displayed] [ABCD...]: ``` You will be prompted for the server name to enter. Feel free to leave this as the default ("algo") if you are not certain how this will affect your setup. Here we chose to call it "algovpn". ``` Name the vpn server: [algo]: algovpn ``` After entering the server name, the script ask which region you wish to setup your new Algo instance in. Enter the number next to name of the region. ``` What region should the server be located in? (https://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region) 1. ap-northeast-1 2. ap-northeast-2 3. ap-south-1 4. ap-southeast-1 5. ap-southeast-2 6. ca-central-1 7. eu-central-1 8. eu-north-1 9. eu-west-1 10. eu-west-2 11. eu-west-3 12. sa-east-1 13. us-east-1 14. us-east-2 15. us-west-1 16. us-west-2 Enter the number of your desired region [13] : ``` You will then be asked the remainder of the standard Algo setup questions. ## Cleanup If you've installed Algo onto EC2 multiple times, your AWS account may become cluttered with unused or deleted resources e.g. instances, VPCs, subnets, etc. This may cause future installs to fail. The easiest way to clean up after you're done with a server is to go to "CloudFormation" from the console and delete the CloudFormation stack associated with that server. Please note that unless you've enabled termination protection on your instance, deleting the stack this way will delete your instance without warning, so be sure you are deleting the correct stack.
Markdown
algo/docs/cloud-azure.md
# Azure cloud setup The easiest way to get started with the Azure CLI is by running it in an Azure Cloud Shell environment through your browser. Here you can find some information from [the official doc](https://docs.microsoft.com/en-us/cli/azure/get-started-with-azure-cli?view=azure-cli-latest). We put the essential commands together for simplest usage. ## Install azure-cli - macOS ([link](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-macos?view=azure-cli-latest)): ```bash $ brew update && brew install azure-cli ``` - Linux (deb-based) ([link](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-apt?view=azure-cli-latest)): ```bash $ sudo apt-get update && sudo apt-get install \ apt-transport-https \ lsb-release \ software-properties-common \ dirmngr -y $ AZ_REPO=$(lsb_release -cs) $ echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" | \ sudo tee /etc/apt/sources.list.d/azure-cli.list $ sudo apt-key --keyring /etc/apt/trusted.gpg.d/Microsoft.gpg adv \ --keyserver packages.microsoft.com \ --recv-keys BC528686B50D79E339D3721CEB3E94ADBE1229CF $ sudo apt-get update $ sudo apt-get install azure-cli ``` - Linux (rpm-based) ([link](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-yum?view=azure-cli-latest)): ```bash $ sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc $ sudo sh -c 'echo -e "[azure-cli]\nname=Azure CLI\nbaseurl=https://packages.microsoft.com/yumrepos/azure-cli\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/azure-cli.repo' $ sudo yum install azure-cli ``` - Windows ([link](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows?view=azure-cli-latest)): For Windows the Azure CLI is installed via an MSI, which gives you access to the CLI through the Windows Command Prompt (CMD) or PowerShell. When installing for Windows Subsystem for Linux (WSL), packages are available for your Linux distribution. [Download the MSI installer](https://aka.ms/installazurecliwindows) If your OS is missing or to get more information see [the official doc](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest) ## Sign in 1. Run the `login` command: ```bash az login ``` If the CLI can open your default browser, it will do so and load a sign-in page. Otherwise, you need to open a browser page and follow the instructions on the command line to enter an authorization code after navigating to https://aka.ms/devicelogin in your browser. 2. Sign in with your account credentials in the browser. There are ways to sign in non-interactively, which are covered in detail in [Sign in with Azure CLI](https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli?view=azure-cli-latest). **Now you are able to deploy an AlgoVPN instance without hassle**
Markdown
algo/docs/cloud-cloudstack.md
### Configuration file Algo scripts will ask you for the API detail. You need to fetch the API credentials and the endpoint from the provider control panel. Example for Exoscale (European cloud provider exposing CloudStack API), visit https://portal.exoscale.com/u/<your@account>/account/profile/api to gather the required information: CloudStack api key and secret. ```bash export CLOUDSTACK_KEY="<your api key>" export CLOUDSTACK_SECRET="<your secret>" export CLOUDSTACK_ENDPOINT="https://api.exoscale.com/compute" ```
Markdown
algo/docs/cloud-do.md
# DigitalOcean cloud setup ## API Token creation First, login into your DigitalOcean account. Select **API** from the titlebar. This will take you to the "Applications & API" page. ![The Applications & API page](/docs/images/do-api.png) On the **Tokens/Keys** tab, select **Generate New Token**. A dialog will pop up. In that dialog, give your new token a name, and make sure **Write** is checked off. Click the **Generate Token** button when you are ready. ![The new token dialog, showing a form requesting a name and confirmation on the scope for the new token.](/docs/images/do-new-token.png) You will be returned to the **Tokens/Keys** tab, and your new key will be shown under the **Personal Access Tokens** header. ![The new token in the listing.](/docs/images/do-view-token.png) Copy or note down the hash that shows below the name you entered, as this will be necessary for the steps below. This value will disappear if you leave this page, and you'll need to regenerate it if you forget it. ## Using DigitalOcean with Algo (interactive) These steps are for those who run Algo using Docker or using the `./algo` command. Choose DigitalOcean as your provider: ``` What provider would you like to use? 1. DigitalOcean 2. Amazon Lightsail 3. Amazon EC2 4. Vultr 5. Microsoft Azure 6. Google Compute Engine 7. Scaleway 8. OpenStack (DreamCompute optimised) 9. Install to existing Ubuntu server (Advanced) Enter the number of your desired provider : 1 ``` Enter a name for your server. Leave this as the default if you are not certain how this will affect your setup: ``` Name the vpn server: [algo]: ``` After several prompts related to Algo features you will be asked for the API Token value. Paste the API Token value you copied when following the steps in [API Token creation](#api-token-creation) (you won't see any output as the key is not echoed by Algo): ``` Enter your API token. The token must have read and write permissions (https://cloud.digitalocean.com/settings/api/tokens): (output is hidden): ``` Finally you will be asked the region in which you wish to setup your new Algo server. This list is dynamic and can change based on availability of resources. Enter the number next to name of the region: ``` What region should the server be located in? 1. ams3 Amsterdam 3 2. blr1 Bangalore 1 3. fra1 Frankfurt 1 4. lon1 London 1 5. nyc1 New York 1 6. nyc3 New York 3 7. sfo2 San Francisco 2 8. sgp1 Singapore 1 9. tor1 Toronto 1 Enter the number of your desired region [6] : 9 ``` ## Using DigitalOcean with Algo (scripted) If you are using Ansible directly to run Algo you will need to pass the API Token as `do_token`. For example: ```shell ansible-playbook main.yml -e "provider=digitalocean server_name=algo ondemand_cellular=true ondemand_wifi=true dns_adblocking=false ssh_tunneling=false store_pki=true region=nyc3 do_token=token" ``` For more, see [Scripted Deployment](deploy-from-ansible.md). ## Using the DigitalOcean firewall with Algo Many cloud providers include the option to configure an external firewall between the Internet and your cloud server. For some providers this is mandatory and Algo will configure it for you, but for DigitalOcean the external firewall is optional. See [AlgoVPN and Firewalls](/docs/firewalls.md) for more information. To configure the DigitalOcean firewall, go to **Networking**, **Firewalls**, and choose **Create Firewall**. Configure your **Inbound Rules** as follows: ![Inbound Rules](/docs/images/do-firewall.png) Leave the **Outbound Rules** at their defaults. Under **Apply to Droplets** enter the tag `Environment:Algo` to apply this firewall to all current and future Algo VPNs you create.
Markdown
algo/docs/cloud-gce.md
# Google Cloud Platform setup * Follow the [`gcloud` installation instructions](https://cloud.google.com/sdk/) * Log into your account using `gcloud init` ### Creating a project The recommendation on GCP is to group resources into **Projects**, so we will create a new project for our VPN server and use a service account restricted to it. ```bash ## Create the project to group the resources ### You might need to change it to have a global unique project id PROJECT_ID=${USER}-algo-vpn BILLING_ID="$(gcloud beta billing accounts list --format="value(ACCOUNT_ID)")" gcloud projects create ${PROJECT_ID} --name algo-vpn --set-as-default gcloud beta billing projects link ${PROJECT_ID} --billing-account ${BILLING_ID} ## Create an account that have access to the VPN gcloud iam service-accounts create algo-vpn --display-name "Algo VPN" gcloud iam service-accounts keys create configs/gce.json \ --iam-account algo-vpn@${PROJECT_ID}.iam.gserviceaccount.com gcloud projects add-iam-policy-binding ${PROJECT_ID} \ --member serviceAccount:algo-vpn@${PROJECT_ID}.iam.gserviceaccount.com \ --role roles/compute.admin gcloud projects add-iam-policy-binding ${PROJECT_ID} \ --member serviceAccount:algo-vpn@${PROJECT_ID}.iam.gserviceaccount.com \ --role roles/iam.serviceAccountUser ## Enable the services gcloud services enable compute.googleapis.com ./algo -e "provider=gce" -e "gce_credentials_file=$(pwd)/configs/gce.json" ``` **Attention:** take care of the `configs/gce.json` file, which contains the credentials to manage your Google Cloud account, including create and delete servers on this project. There are more advanced arguments available for deployment [using ansible](deploy-from-ansible.md).
Markdown
algo/docs/cloud-hetzner.md
## API Token Sign in into the [Hetzner Cloud Console](https://console.hetzner.cloud/) choose a project, go to `Security` → `API Tokens`, and `Generate API Token` with `Read & Write` access. Make sure to copy the token because it won’t be shown to you again. A token is bound to a project. To interact with the API of another project you have to create a new token inside the project.