1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251
|
# Copyright (c) 2016-2025 by Ron Frederick <ronf@timeheart.net> and others.
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License v2.0 which accompanies this
# distribution and is available at:
#
# http://www.eclipse.org/legal/epl-2.0/
#
# This program may also be made available under the following secondary
# licenses when the conditions for such availability set forth in the
# Eclipse Public License v2.0 are satisfied:
#
# GNU General Public License, Version 2.0, or any later versions of
# that license
#
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
#
# Contributors:
# Ron Frederick - initial implementation, API, and documentation
"""Unit tests for AsyncSSH connection authentication"""
import asyncio
import os
import sys
import unittest
from unittest.mock import patch
from cryptography.exceptions import UnsupportedAlgorithm
import asyncssh
from asyncssh.misc import async_context_manager, write_file
from asyncssh.packet import String
from asyncssh.public_key import CERT_TYPE_USER, CERT_TYPE_HOST
from .keysign_stub import create_subprocess_exec_stub
from .server import Server, ServerTestCase
from .util import asynctest, gss_available, patch_getnameinfo
from .util import patch_getnameinfo_error, patch_gss
from .util import make_certificate, nc_available, x509_available
class _FailValidateHostSSHServerConnection(asyncssh.SSHServerConnection):
"""Test error in validating host key signature"""
async def validate_host_based_auth(self, username, key_data, client_host,
client_username, msg, signature):
"""Validate host based authentication for the specified host and user"""
return await super().validate_host_based_auth(username, key_data,
client_host,
client_username,
msg + b'\xff', signature)
class _AsyncGSSServer(asyncssh.SSHServer):
"""Server for testing async GSS authentication"""
# pylint: disable=useless-super-delegation
async def validate_gss_principal(self, username, user_principal,
host_principal):
"""Return whether password is valid for this user"""
return super().validate_gss_principal(username, user_principal,
host_principal)
class _NullServer(Server):
"""Server for testing disabled auth"""
async def begin_auth(self, username):
"""Handle client authentication request"""
return False
async def auth_completed(self):
"""Handle client authentication request"""
class _HostBasedServer(Server):
"""Server for testing host-based authentication"""
def __init__(self, host_key=None, ca_key=None):
super().__init__()
self._host_key = \
asyncssh.read_public_key(host_key) if host_key else None
self._ca_key = \
asyncssh.read_public_key(ca_key) if ca_key else None
def host_based_auth_supported(self):
"""Return whether or not host based authentication is supported"""
return True
def validate_host_public_key(self, client_host, client_addr,
client_port, key):
"""Return whether key is an authorized key for this host"""
# pylint: disable=unused-argument
return key == self._host_key
def validate_host_ca_key(self, client_host, client_addr, client_port, key):
"""Return whether key is an authorized CA key for this host"""
# pylint: disable=unused-argument
return key == self._ca_key
def validate_host_based_user(self, username, client_host, client_username):
"""Return whether remote host and user is authorized for this user"""
# pylint: disable=unused-argument
return client_username == 'user'
class _AsyncHostBasedServer(Server):
"""Server for testing async host-based authentication"""
# pylint: disable=useless-super-delegation
async def validate_host_based_user(self, username, client_host,
client_username):
"""Return whether remote host and user is authorized for this user"""
return super().validate_host_based_user(username, client_host,
client_username)
class _InvalidUsernameClientConnection(asyncssh.connection.SSHClientConnection):
"""Test sending a client username with invalid Unicode to the server"""
async def host_based_auth_requested(self):
"""Return a host key pair, host, and user to authenticate with"""
keypair, host, _ = await super().host_based_auth_requested()
return keypair, host, b'\xff'
class _PublicKeyClient(asyncssh.SSHClient):
"""Test client public key authentication"""
def __init__(self, keylist, delay=0):
self._keylist = keylist
self._delay = delay
async def public_key_auth_requested(self):
"""Return a public key to authenticate with"""
if self._delay:
await asyncio.sleep(self._delay)
return self._keylist.pop(0) if self._keylist else None
class _AsyncPublicKeyClient(_PublicKeyClient):
"""Test async client public key authentication"""
# pylint: disable=useless-super-delegation
async def public_key_auth_requested(self):
"""Return a public key to authenticate with"""
return await super().public_key_auth_requested()
class _PublicKeyServer(Server):
"""Server for testing public key authentication"""
def __init__(self, client_keys=(), authorized_keys=None, delay=0):
super().__init__()
self._client_keys = client_keys
self._authorized_keys = authorized_keys
self._delay = delay
def connection_made(self, conn):
"""Called when a connection is made"""
super().connection_made(conn)
conn.send_auth_banner('auth banner')
async def begin_auth(self, username):
"""Handle client authentication request"""
if self._authorized_keys:
self._conn.set_authorized_keys(self._authorized_keys)
else:
self._client_keys = asyncssh.load_public_keys(self._client_keys)
if self._delay:
await asyncio.sleep(self._delay)
return True
def public_key_auth_supported(self):
"""Return whether or not public key authentication is supported"""
return True
def validate_public_key(self, username, key):
"""Return whether key is an authorized client key for this user"""
return key in self._client_keys
def validate_ca_key(self, username, key):
"""Return whether key is an authorized CA key for this user"""
return key in self._client_keys
class _AsyncPublicKeyServer(_PublicKeyServer):
"""Server for testing async public key authentication"""
# pylint: disable=useless-super-delegation
async def begin_auth(self, username):
"""Handle client authentication request"""
return await super().begin_auth(username)
async def validate_public_key(self, username, key):
"""Return whether key is an authorized client key for this user"""
return super().validate_public_key(username, key)
async def validate_ca_key(self, username, key):
"""Return whether key is an authorized CA key for this user"""
return super().validate_ca_key(username, key)
class _PasswordClient(asyncssh.SSHClient):
"""Test client password authentication"""
def __init__(self, password, old_password, new_password):
self._password = password
self._old_password = old_password
self._new_password = new_password
def password_auth_requested(self):
"""Return a password to authenticate with"""
if self._password:
result = self._password
self._password = None
return result
else:
return None
def password_change_requested(self, prompt, lang):
"""Change the client's password"""
return self._old_password, self._new_password
class _AsyncPasswordClient(_PasswordClient):
"""Test async client password authentication"""
# pylint: disable=useless-super-delegation
async def password_auth_requested(self):
"""Return a password to authenticate with"""
return super().password_auth_requested()
async def password_change_requested(self, prompt, lang):
"""Change the client's password"""
return super().password_change_requested(prompt, lang)
class _PasswordServer(Server):
"""Server for testing password authentication"""
def password_auth_supported(self):
"""Enable password authentication"""
return True
def validate_password(self, username, password):
"""Accept password of pw, trigger password change on oldpw"""
if password == 'oldpw':
raise asyncssh.PasswordChangeRequired('Password change required')
else:
return password == 'pw'
def change_password(self, username, old_password, new_password):
"""Only allow password change from password oldpw"""
return old_password == 'oldpw'
class _AsyncPasswordServer(_PasswordServer):
"""Server for testing async password authentication"""
# pylint: disable=useless-super-delegation
async def validate_password(self, username, password):
"""Return whether password is valid for this user"""
return super().validate_password(username, password)
async def change_password(self, username, old_password, new_password):
"""Handle a request to change a user's password"""
return super().change_password(username, old_password, new_password)
class _KbdintClient(asyncssh.SSHClient):
"""Test keyboard-interactive client auth"""
def __init__(self, responses):
self._responses = responses
def kbdint_auth_requested(self):
"""Return the list of supported keyboard-interactive auth methods"""
return '' if self._responses else None
def kbdint_challenge_received(self, name, instructions, lang, prompts):
"""Return responses to a keyboard-interactive auth challenge"""
# pylint: disable=unused-argument
if not prompts:
return []
elif self._responses:
result = self._responses
self._responses = None
return result
else:
return None
class _AsyncKbdintClient(_KbdintClient):
"""Test keyboard-interactive client auth"""
# pylint: disable=useless-super-delegation
async def kbdint_auth_requested(self):
"""Return the list of supported keyboard-interactive auth methods"""
return super().kbdint_auth_requested()
async def kbdint_challenge_received(self, name, instructions,
lang, prompts):
"""Return responses to a keyboard-interactive auth challenge"""
return super().kbdint_challenge_received(name, instructions,
lang, prompts)
class _KbdintServer(Server):
"""Server for testing keyboard-interactive authentication"""
def __init__(self):
super().__init__()
self._kbdint_round = 0
def kbdint_auth_supported(self):
"""Enable keyboard-interactive authentication"""
return True
def get_kbdint_challenge(self, username, lang, submethods):
"""Return an initial challenge with only instructions"""
return '', 'instructions', '', []
def validate_kbdint_response(self, username, responses):
"""Return a password challenge after the instructions"""
if self._kbdint_round == 0:
if username == 'none':
result = ('', '', '', [])
elif username == 'pw':
result = ('', '', '', [('Password:', False)])
elif username == 'pc':
result = ('', '', '', [('Passcode:', False)])
elif username == 'multi':
result = ('', '', '', [('Prompt1:', True), ('Prompt2', True)])
else:
result = ('', '', '', [('Other Challenge:', False)])
else:
if responses in ([], ['kbdint'], ['1', '2']):
result = True
else:
result = ('', '', '', [('Second Challenge:', True)])
self._kbdint_round += 1
return result
class _AsyncKbdintServer(_KbdintServer):
"""Server for testing async keyboard-interactive authentication"""
# pylint: disable=useless-super-delegation
async def get_kbdint_challenge(self, username, lang, submethods):
"""Return a keyboard-interactive auth challenge"""
return super().get_kbdint_challenge(username, lang, submethods)
async def validate_kbdint_response(self, username, responses):
"""Return whether the keyboard-interactive response is valid
for this user"""
return super().validate_kbdint_response(username, responses)
class _UnknownAuthClientConnection(asyncssh.connection.SSHClientConnection):
"""Test getting back an unknown auth method from the SSH server"""
def try_next_auth(self, *, next_method=False):
"""Attempt client authentication using an unknown method"""
self._auth_methods = [b'unknown'] + self._auth_methods
super().try_next_auth(next_method=next_method)
class _TestNullAuth(ServerTestCase):
"""Unit tests for testing disabled authentication"""
@classmethod
async def start_server(cls):
"""Start an SSH server which supports disabled authentication"""
return await cls.create_server(_NullServer)
@asynctest
async def test_get_server_auth_methods(self):
"""Test getting auth methods from the test server"""
auth_methods = await asyncssh.get_server_auth_methods(
self._server_addr, self._server_port)
self.assertEqual(auth_methods, ['none'])
@asynctest
async def test_disabled_auth(self):
"""Test disabled authentication"""
async with self.connect(username='user'):
pass
@asynctest
async def test_disabled_trivial_auth(self):
"""Test disabling trivial auth with no authentication"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='user', disable_trivial_auth=True)
@unittest.skipUnless(gss_available, 'GSS not available')
@patch_gss
class _TestGSSAuth(ServerTestCase):
"""Unit tests for GSS authentication"""
@unittest.skipIf(sys.platform == 'win32', 'skip GSS store test on Windows')
@classmethod
async def start_server(cls):
"""Start an SSH server which supports GSS authentication"""
return await cls.create_server(_AsyncGSSServer, gss_host='1',
gss_store='a')
@asynctest
async def test_get_server_auth_methods(self):
"""Test getting auth methods from the test server"""
auth_methods = await asyncssh.get_server_auth_methods(
self._server_addr, self._server_port)
self.assertEqual(auth_methods, ['gssapi-with-mic'])
@asynctest
async def test_gss_kex_auth(self):
"""Test GSS key exchange authentication"""
async with self.connect(kex_algs=['gss-gex-sha256'],
username='user', gss_host='1'):
pass
@asynctest
async def test_gss_mic_auth(self):
"""Test GSS MIC authentication"""
async with self.connect(kex_algs=['ecdh-sha2-nistp256'],
username='user', gss_host='1'):
pass
@unittest.skipIf(sys.platform == 'win32', 'skip GSS store test on Windows')
@asynctest
async def test_gss_mic_auth_store(self):
"""Test GSS MIC authentication with GSS store set"""
async with self.connect(kex_algs=['ecdh-sha2-nistp256'],
username='user', gss_host='1', gss_store='a'):
pass
@asynctest
async def test_gss_mic_auth_sign_error(self):
"""Test GSS MIC authentication signing failure"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(kex_algs=['ecdh-sha2-nistp256'],
username='user', gss_host='1,sign_error')
@asynctest
async def test_gss_mic_auth_verify_error(self):
"""Test GSS MIC authentication signature verification failure"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(kex_algs=['ecdh-sha2-nistp256'],
username='user', gss_host='1,verify_error')
@asynctest
async def test_gss_delegate(self):
"""Test GSS credential delegation"""
async with self.connect(username='user', gss_host='1',
gss_delegate_creds=True):
pass
@asynctest
async def test_gss_kex_disabled(self):
"""Test GSS key exchange being disabled"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='user', gss_host=(), gss_kex=False,
preferred_auth='gssapi-keyex')
@asynctest
async def test_gss_auth_disabled(self):
"""Test GSS authentication being disabled"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='user', gss_host=(), gss_auth=False)
@asynctest
async def test_gss_auth_unavailable(self):
"""Test GSS authentication being unavailable"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='user1', gss_host=())
@asynctest
async def test_gss_client_error(self):
"""Test GSS client error"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(gss_host='1,init_error', username='user')
@asynctest
async def test_disabled_trivial_gss_kex_auth(self):
"""Test disabling trivial auth with GSS key exchange authentication"""
async with self.connect(kex_algs=['gss-gex-sha256'],
username='user', gss_host='1',
disable_trivial_auth=True):
pass
@asynctest
async def test_disabled_trivial_gss_mic_auth(self):
"""Test disabling trivial auth with GSS MIC authentication"""
async with self.connect(kex_algs=['ecdh-sha2-nistp256'],
username='user', gss_host='1',
disable_trivial_auth=True):
pass
@unittest.skipUnless(gss_available, 'GSS not available')
@patch_gss
class _TestGSSServerAuthDisabled(ServerTestCase):
"""Unit tests for with GSS key exchange and auth disabled on server"""
@classmethod
async def start_server(cls):
"""Start an SSH server with GSS key exchange and auth disabled"""
return await cls.create_server(gss_host='1', gss_kex=False,
gss_auth=False)
@asynctest
async def test_gss_kex_unavailable(self):
"""Test GSS key exchange being unavailable"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='user', gss_host=(),
preferred_auth='gssapi-keyex')
@asynctest
async def test_gss_auth_unavailable(self):
"""Test GSS authentication being unavailable"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='user', gss_host=(),
preferred_auth='gssapi-with-mic')
@unittest.skipUnless(gss_available, 'GSS not available')
@patch_gss
class _TestGSSServerError(ServerTestCase):
"""Unit tests for GSS server error"""
@classmethod
async def start_server(cls):
"""Start an SSH server which raises an error on GSS authentication"""
return await cls.create_server(gss_host='1,init_error')
@asynctest
async def test_gss_server_error(self):
"""Test GSS error on server"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='user')
@unittest.skipUnless(gss_available, 'GSS not available')
@patch_gss
class _TestGSSFQDN(ServerTestCase):
"""Unit tests for GSS server error"""
@classmethod
async def start_server(cls):
"""Start an SSH server which raises an error on GSS authentication"""
def mock_gethostname():
"""Return a non-fully-qualified hostname"""
return 'host'
def mock_getfqdn():
"""Confirm getfqdn is called on relative hostnames"""
return '1'
with patch('socket.gethostname', mock_gethostname):
with patch('socket.getfqdn', mock_getfqdn):
return await cls.create_server(gss_host=())
@asynctest
async def test_gss_fqdn_lookup(self):
"""Test GSS FQDN lookup"""
async with self.connect(username='user', gss_host=()):
pass
@patch_getnameinfo
class _TestHostBasedAuth(ServerTestCase):
"""Unit tests for host-based authentication"""
@classmethod
async def start_server(cls):
"""Start an SSH server which supports host-based authentication"""
return await cls.create_server(
_HostBasedServer, known_client_hosts='known_hosts')
@asynctest
async def test_get_server_auth_methods(self):
"""Test getting auth methods from the test server"""
auth_methods = await asyncssh.get_server_auth_methods(
self._server_addr, self._server_port, username='user')
self.assertEqual(auth_methods, ['hostbased'])
@unittest.skipUnless(nc_available, 'Netcat not available')
@asynctest
async def test_get_server_auth_methods_no_sockname(self):
"""Test getting auth methods from the test server"""
proxy_command = ('nc', str(self._server_addr), str(self._server_port))
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='user', client_host_keys='skey',
proxy_command=proxy_command)
@asynctest
async def test_client_host_auth(self):
"""Test connecting with host-based authentication"""
async with self.connect(username='user', client_host_keys='skey',
client_username='user'):
pass
@asynctest
async def test_client_host_auth_disabled(self):
"""Test connecting with host-based authentication disabled"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='user', client_host_keys='skey',
client_username='user', host_based_auth=False)
@asynctest
async def test_client_host_key_bytes(self):
"""Test client host key passed in as bytes"""
with open('skey', 'rb') as f:
skey = f.read()
async with self.connect(username='user', client_host_keys=[skey],
client_username='user'):
pass
@asynctest
async def test_client_host_key_sshkey(self):
"""Test client host key passed in as an SSHKey"""
skey = asyncssh.read_private_key('skey')
async with self.connect(username='user', client_host_keys=[skey],
client_username='user'):
pass
@asynctest
async def test_client_host_key_keypairs(self):
"""Test client host keys passed in as a list of SSHKeyPairs"""
keys = asyncssh.load_keypairs('skey')
async with self.connect(username='user', client_host_keys=keys,
client_username='user'):
pass
@asynctest
async def test_client_host_signature_algs(self):
"""Test host based authentication with specific signature algorithms"""
for alg in ('rsa-sha2-256', 'rsa-sha2-512'):
async with self.connect(username='user', client_host_keys='skey',
client_username='user',
signature_algs=[alg]):
pass
@asynctest
async def test_no_server_signature_algs(self):
"""Test a server which doesn't advertise signature algorithms"""
def skip_ext_info(self):
"""Don't send extension information"""
# pylint: disable=unused-argument
return []
with patch('asyncssh.connection.SSHConnection._get_extra_kex_algs',
skip_ext_info):
try:
async with self.connect(username='user',
client_host_keys='skey',
client_username='user'):
pass
except UnsupportedAlgorithm: # pragma: no cover
pass
@asynctest
async def test_untrusted_client_host_key(self):
"""Test untrusted client host key"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='user', client_host_keys='ckey',
client_username='user')
@asynctest
async def test_missing_cert(self):
"""Test missing client host certificate"""
with self.assertRaises(OSError):
await self.connect(username='user',
client_host_keys=[('skey', 'xxx')],
client_username='user')
@asynctest
async def test_invalid_client_host_signature(self):
"""Test invalid client host signature"""
with patch('asyncssh.connection.SSHServerConnection',
_FailValidateHostSSHServerConnection):
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='user', client_host_keys='skey',
client_username='user')
@asynctest
async def test_client_host_trailing_dot(self):
"""Test stripping of trailing dot from client host"""
async with self.connect(username='user', client_host_keys='skey',
client_host='localhost.',
client_username='user'):
pass
@asynctest
async def test_mismatched_client_host(self):
"""Test ignoring of mismatched client host due to canonicalization"""
async with self.connect(username='user', client_host_keys='skey',
client_host='xxx', client_username='user'):
pass
@asynctest
async def test_mismatched_client_username(self):
"""Test mismatched client username"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='user', client_host_keys='skey',
client_username='xxx')
@asynctest
async def test_invalid_client_username(self):
"""Test invalid client username"""
with patch('asyncssh.connection.SSHClientConnection',
_InvalidUsernameClientConnection):
with self.assertRaises(asyncssh.ProtocolError):
await self.connect(username='user', client_host_keys='skey')
@asynctest
async def test_expired_cert(self):
"""Test expired certificate"""
ckey = asyncssh.read_private_key('ckey')
skey = asyncssh.read_private_key('skey')
cert = make_certificate('ssh-rsa-cert-v01@openssh.com',
CERT_TYPE_HOST, ckey, skey, ['localhost'],
valid_before=1)
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='user', client_host_keys=[(ckey, cert)],
client_username='user')
@asynctest
async def test_untrusted_ca(self):
"""Test untrusted CA"""
ckey = asyncssh.read_private_key('ckey')
cert = make_certificate('ssh-rsa-cert-v01@openssh.com',
CERT_TYPE_HOST, ckey, ckey, ['localhost'])
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='user', client_host_keys=[(ckey, cert)],
client_username='user')
@asynctest
async def test_disabled_trivial_client_host_auth(self):
"""Test disabling trivial auth with host-based authentication"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='user', client_host_keys='skey',
client_username='user',
disable_trivial_auth=True)
class _TestHostBasedAuthNoRDNS(ServerTestCase):
"""Unit tests for host-based authentication with no reverse DNS"""
@classmethod
async def start_server(cls):
"""Start an SSH server which supports host-based authentication"""
return await cls.create_server(
_HostBasedServer, known_client_hosts='known_hosts')
@patch_getnameinfo_error
@asynctest
async def test_client_host_auth_no_rdns(self):
"""Test connecting with host-based authentication with no RDNS"""
async with self.connect(username='user', client_host_keys='skey',
client_username='user'):
pass
@patch_getnameinfo
class _TestCallbackHostBasedAuth(ServerTestCase):
"""Unit tests for host-based authentication using callback"""
@classmethod
async def start_server(cls):
"""Start an SSH server which supports host-based authentication"""
def server_factory():
"""Return an SSHServer which can validate the client host key"""
return _HostBasedServer(host_key='skey.pub', ca_key='skey.pub')
return await cls.create_server(server_factory)
@asynctest
async def test_validate_client_host_callback(self):
"""Test using callback to validate client host key"""
async with self.connect(username='user',
client_host_keys=[('skey', None)],
client_username='user'):
pass
@asynctest
async def test_validate_client_host_ca_callback(self):
"""Test using callback to validate client host CA key"""
async with self.connect(username='user', client_host_keys='skey',
client_username='user'):
pass
@asynctest
async def test_untrusted_client_host_callback(self):
"""Test callback to validate client host key returning failure"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='user',
client_host_keys=[('ckey', None)],
client_username='user')
@asynctest
async def test_untrusted_client_host_ca_callback(self):
"""Test callback to validate client host CA key returning failure"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='user', client_host_keys='ckey',
client_username='user')
@patch_getnameinfo
class _TestKeysignHostBasedAuth(ServerTestCase):
"""Unit tests for host-based authentication using ssh-keysign"""
@classmethod
async def start_server(cls):
"""Start an SSH server which supports host-based authentication"""
return await cls.create_server(
_HostBasedServer, known_client_hosts=(['skey_ecdsa.pub'], [], []))
@async_context_manager
async def _connect_keysign(self, client_host_keysign=True,
client_host_keys=None, keysign_dirs=('.',)):
"""Open a connection to test host-based auth using ssh-keysign"""
with patch('asyncio.create_subprocess_exec',
create_subprocess_exec_stub):
with patch('asyncssh.keysign._DEFAULT_KEYSIGN_DIRS', keysign_dirs):
with patch('asyncssh.public_key._DEFAULT_HOST_KEY_DIRS', ['.']):
with patch('asyncssh.public_key._DEFAULT_HOST_KEY_FILES',
['skey_ecdsa', 'xxx']):
return await self.connect(
username='user',
client_host_keysign=client_host_keysign,
client_host_keys=client_host_keys,
client_username='user')
@asynctest
async def test_keysign(self):
"""Test host-based authentication using ssh-keysign"""
async with self._connect_keysign():
pass
@asynctest
async def test_explciit_keysign(self):
"""Test ssh-keysign with an explicit path"""
async with self._connect_keysign(client_host_keysign='.'):
pass
@asynctest
async def test_keysign_explicit_host_keys(self):
"""Test ssh-keysign with explicit host public keys"""
async with self._connect_keysign(client_host_keys='skey_ecdsa.pub'):
pass
@asynctest
async def test_invalid_keysign_response(self):
"""Test invalid ssh-keysign response"""
with patch('asyncssh.keysign.KEYSIGN_VERSION', 0):
with self.assertRaises(asyncssh.PermissionDenied):
await self._connect_keysign()
@asynctest
async def test_keysign_error(self):
"""Test ssh-keysign error response"""
with patch('asyncssh.keysign.KEYSIGN_VERSION', 1):
with self.assertRaises(asyncssh.PermissionDenied):
await self._connect_keysign()
@asynctest
async def test_invalid_keysign_version(self):
"""Test invalid version in ssh-keysign request"""
with patch('asyncssh.keysign.KEYSIGN_VERSION', 99):
with self.assertRaises(asyncssh.PermissionDenied):
await self._connect_keysign()
@asynctest
async def test_keysign_not_found(self):
"""Test ssh-keysign executable not being found"""
with self.assertRaises(ValueError):
await self._connect_keysign(keysign_dirs=())
@asynctest
async def test_explicit_keysign_not_found(self):
"""Test explicit ssh-keysign executable not being found"""
with self.assertRaises(ValueError):
await self._connect_keysign(client_host_keysign='xxx')
@asynctest
async def test_keysign_dir_not_present(self):
"""Test ssh-keysign executable not in a keysign dir"""
with self.assertRaises(ValueError):
await self._connect_keysign(keysign_dirs=('xxx',))
@patch_getnameinfo
class _TestHostBasedAsyncServerAuth(_TestHostBasedAuth):
"""Unit tests for host-based authentication with async server callbacks"""
@classmethod
async def start_server(cls):
"""Start an SSH server which supports async host-based auth"""
return await cls.create_server(_AsyncHostBasedServer,
known_client_hosts='known_hosts',
trust_client_host=True)
@asynctest
async def test_mismatched_client_host(self):
"""Test mismatch of trusted client host"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='user', client_host_keys='skey',
client_host='xxx', client_username='user')
@patch_getnameinfo
class _TestLimitedHostBasedSignatureAlgs(ServerTestCase):
"""Unit tests for limited host key signature algorithms"""
@classmethod
async def start_server(cls):
"""Start an SSH server which supports host-based authentication"""
return await cls.create_server(
_HostBasedServer, known_client_hosts='known_hosts',
signature_algs=['ssh-rsa', 'rsa-sha2-512'])
@asynctest
async def test_mismatched_host_signature_algs(self):
"""Test mismatched host key signature algorithms"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='ckey', client_host_keys='skey',
client_username='user',
signature_algs=['rsa-sha2-256'])
@asynctest
async def test_host_signature_alg_fallback(self):
"""Test fall back to default host key signature algorithm"""
try:
async with self.connect(username='ckey', client_host_keys='skey',
client_username='user',
signature_algs=['rsa-sha2-256', 'ssh-rsa']):
pass
except UnsupportedAlgorithm: # pragma: no cover
pass
class _TestPublicKeyAuth(ServerTestCase):
"""Unit tests for public key authentication"""
@classmethod
async def start_server(cls):
"""Start an SSH server which supports public key authentication"""
return await cls.create_server(
_PublicKeyServer, authorized_client_keys='authorized_keys')
@async_context_manager
async def _connect_publickey(self, keylist, test_async=False):
"""Open a connection to test public key auth"""
def client_factory():
"""Return an SSHClient to use to do public key auth"""
cls = _AsyncPublicKeyClient if test_async else _PublicKeyClient
return cls(keylist)
conn, _ = await self.create_connection(client_factory, username='ckey',
client_keys=None)
return conn
@asynctest
async def test_get_server_auth_methods(self):
"""Test getting auth methods from the test server"""
auth_methods = await asyncssh.get_server_auth_methods(
self._server_addr, self._server_port)
self.assertEqual(auth_methods, ['publickey'])
@asynctest
async def test_encrypted_client_key(self):
"""Test public key auth with encrypted client key"""
async with self.connect(username='ckey', client_keys='ckey_encrypted',
passphrase='passphrase'):
pass
@asynctest
async def test_encrypted_client_key_callable(self):
"""Test public key auth with callable passphrase"""
def _passphrase(filename):
self.assertEqual(filename, 'ckey_encrypted')
return 'passphrase'
async with self.connect(username='ckey', client_keys='ckey_encrypted',
passphrase=_passphrase):
pass
@asynctest
async def test_encrypted_client_key_awaitable(self):
"""Test public key auth with awaitable passphrase"""
async def _passphrase(filename):
self.assertEqual(filename, 'ckey_encrypted')
return 'passphrase'
async with self.connect(username='ckey', client_keys='ckey_encrypted',
passphrase=_passphrase):
pass
@asynctest
async def test_encrypted_client_key_list_callable(self):
"""Test public key auth with callable passphrase"""
def _passphrase(filename):
self.assertEqual(filename, 'ckey_encrypted')
return 'passphrase'
async with self.connect(username='ckey',
client_keys=['ckey_encrypted'],
passphrase=_passphrase):
pass
@asynctest
async def test_encrypted_client_key_list_awaitable(self):
"""Test public key auth with awaitable passphrase"""
async def _passphrase(filename):
self.assertEqual(filename, 'ckey_encrypted')
return 'passphrase'
async with self.connect(username='ckey',
client_keys=['ckey_encrypted'],
passphrase=_passphrase):
pass
@asynctest
async def test_encrypted_client_key_bad_passphrase(self):
"""Test wrong passphrase for encrypted client key"""
with self.assertRaises(asyncssh.KeyEncryptionError):
await self.connect(username='ckey', client_keys='ckey_encrypted',
passphrase='xxx')
@asynctest
async def test_encrypted_client_key_missing_passphrase(self):
"""Test missing passphrase for encrypted client key"""
with self.assertRaises(asyncssh.KeyImportError):
await self.connect(username='ckey', client_keys='ckey_encrypted')
@asynctest
async def test_client_certs(self):
"""Test trusted client certificate via client_certs"""
async with self.connect(username='ckey', client_keys='ckey',
client_certs='ckey-cert.pub'):
pass
@asynctest
async def test_agent_auth(self):
"""Test connecting with ssh-agent authentication"""
if not self.agent_available(): # pragma: no cover
self.skipTest('ssh-agent not available')
async with self.connect(username='ckey'):
pass
@asynctest
async def test_agent_identities(self):
"""Test connecting with ssh-agent auth with specific identities"""
if not self.agent_available(): # pragma: no cover
self.skipTest('ssh-agent not available')
ckey = asyncssh.read_private_key('ckey')
ckey.write_private_key('ckey.pem', 'pkcs8-pem')
ckey_cert = asyncssh.read_certificate('ckey-cert.pub')
ckey_ecdsa = asyncssh.read_public_key('ckey_ecdsa.pub')
for pubkey in ('ckey-cert.pub', 'ckey_ecdsa.pub', 'ckey.pem',
ckey_cert, ckey_ecdsa, ckey_ecdsa.public_data):
async with self.connect(username='ckey', agent_identities=pubkey):
pass
@asynctest
async def test_agent_identities_config(self):
"""Test connecting with ssh-agent auth and IdentitiesOnly config"""
if not self.agent_available(): # pragma: no cover
self.skipTest('ssh-agent not available')
write_file('ckey_err', b'')
write_file('config', 'IdentitiesOnly True\n'
'IdentityFile ckey-cert.pub\n'
'IdentityFile ckey_ecdsa.pub\n'
'IdentityFile ckey_err\n', 'w')
async with self.connect(username='ckey', config='config'):
pass
@asynctest
async def test_agent_identities_config_default_keys(self):
"""Test connecting with ssh-agent auth and default IdentitiesOnly"""
if not self.agent_available(): # pragma: no cover
self.skipTest('ssh-agent not available')
write_file('config', 'IdentitiesOnly True\n', 'w')
async with self.connect(username='ckey', config='config'):
pass
@asynctest
async def test_agent_signature_algs(self):
"""Test ssh-agent keys with specific signature algorithms"""
if not self.agent_available(): # pragma: no cover
self.skipTest('ssh-agent not available')
for alg in ('rsa-sha2-256', 'rsa-sha2-512'):
async with self.connect(username='ckey', signature_algs=[alg]):
pass
@asynctest
async def test_agent_auth_failure(self):
"""Test failure connecting with ssh-agent authentication"""
if not self.agent_available(): # pragma: no cover
self.skipTest('ssh-agent not available')
with patch.dict(os.environ, HOME='xxx'):
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='ckey', agent_path='xxx',
known_hosts='.ssh/known_hosts')
@asynctest
async def test_agent_auth_unset(self):
"""Test connecting with no local keys and no ssh-agent configured"""
with patch.dict(os.environ, HOME='xxx', USERPROFILE='xxx',
SSH_AUTH_SOCK=''):
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='ckey',
known_hosts='.ssh/known_hosts')
@asynctest
async def test_public_key_auth(self):
"""Test connecting with public key authentication"""
async with self.connect(username='ckey', client_keys='ckey'):
pass
@asynctest
async def test_public_key_auth_disabled(self):
"""Test connecting with public key authentication disabled"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='ckey', client_keys='ckey',
public_key_auth=False)
@asynctest
async def test_public_key_auth_not_preferred(self):
"""Test public key authentication not being in preferred auth list"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='ckey', client_keys='ckey',
preferred_auth='password')
@asynctest
async def test_public_key_signature_algs(self):
"""Test public key authentication with specific signature algorithms"""
for alg in ('rsa-sha2-256', 'rsa-sha2-512'):
async with self.connect(username='ckey', agent_path=None,
client_keys='ckey', signature_algs=[alg]):
pass
@asynctest
async def test_no_server_signature_algs(self):
"""Test a server which doesn't advertise signature algorithms"""
def skip_ext_info(self):
"""Don't send extension information"""
# pylint: disable=unused-argument
return []
with patch('asyncssh.connection.SSHConnection._get_extra_kex_algs',
skip_ext_info):
try:
async with self.connect(username='ckey', client_keys='ckey',
agent_path=None):
pass
except UnsupportedAlgorithm: # pragma: no cover
pass
@asynctest
async def test_default_public_key_auth(self):
"""Test connecting with default public key authentication"""
async with self.connect(username='ckey', agent_path=None):
pass
@asynctest
async def test_invalid_default_key(self):
"""Test connecting with invalid default client key"""
key_path = os.path.join('.ssh', 'id_dsa')
with open(key_path, 'w') as f:
f.write('-----XXX-----')
with self.assertRaises(asyncssh.KeyImportError):
await self.connect(username='ckey', agent_path=None)
os.remove(key_path)
@asynctest
async def test_client_key_bytes(self):
"""Test client key passed in as bytes"""
with open('ckey', 'rb') as f:
ckey = f.read()
async with self.connect(username='ckey', client_keys=[ckey]):
pass
@asynctest
async def test_client_key_sshkey(self):
"""Test client key passed in as an SSHKey"""
ckey = asyncssh.read_private_key('ckey')
async with self.connect(username='ckey', client_keys=[ckey]):
pass
@asynctest
async def test_client_key_keypairs(self):
"""Test client keys passed in as a list of SSHKeyPairs"""
keys = asyncssh.load_keypairs('ckey')
async with self.connect(username='ckey', client_keys=keys):
pass
@asynctest
async def test_client_key_agent_keypairs(self):
"""Test client keys passed in as a list of SSHAgentKeyPairs"""
if not self.agent_available(): # pragma: no cover
self.skipTest('ssh-agent not available')
async with asyncssh.connect_agent() as agent:
for key in await agent.get_keys():
async with self.connect(username='ckey', client_keys=[key]):
pass
@asynctest
async def test_keypair_with_replaced_cert(self):
"""Test connecting with a keypair with replaced cert"""
ckey = asyncssh.load_keypairs(['ckey'])[0]
async with self.connect(username='ckey',
client_keys=[(ckey, 'ckey-cert.pub')]):
pass
@asynctest
async def test_agent_keypair_with_replaced_cert(self):
"""Test connecting with an agent key with replaced cert"""
if not self.agent_available(): # pragma: no cover
self.skipTest('ssh-agent not available')
async with asyncssh.connect_agent() as agent:
ckey = (await agent.get_keys())[2]
async with self.connect(username='ckey',
client_keys=[(ckey, 'ckey-cert.pub')]):
pass
@asynctest
async def test_untrusted_client_key(self):
"""Test untrusted client key"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='ckey', client_keys='skey',
agent_path=None)
@asynctest
async def test_missing_cert(self):
"""Test missing client certificate"""
with self.assertRaises(OSError):
await self.connect(username='ckey', client_keys=[('ckey', 'xxx')])
@asynctest
async def test_expired_cert(self):
"""Test expired certificate"""
ckey = asyncssh.read_private_key('ckey')
skey = asyncssh.read_private_key('skey')
cert = make_certificate('ssh-rsa-cert-v01@openssh.com',
CERT_TYPE_USER, skey, ckey, ['ckey'],
valid_before=1)
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='ckey', client_keys=[(skey, cert)],
agent_path=None)
@asynctest
async def test_allowed_address(self):
"""Test allowed address in certificate"""
ckey = asyncssh.read_private_key('ckey')
skey = asyncssh.read_private_key('skey')
cert = make_certificate('ssh-rsa-cert-v01@openssh.com',
CERT_TYPE_USER, skey, ckey, ['ckey'],
options={'source-address':
String('0.0.0.0/0,::/0')})
async with self.connect(username='ckey', client_keys=[(skey, cert)]):
pass
@asynctest
async def test_disallowed_address(self):
"""Test disallowed address in certificate"""
ckey = asyncssh.read_private_key('ckey')
skey = asyncssh.read_private_key('skey')
cert = make_certificate('ssh-rsa-cert-v01@openssh.com',
CERT_TYPE_USER, skey, ckey, ['ckey'],
options={'source-address': String('0.0.0.0')})
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='ckey', client_keys=[(skey, cert)],
agent_path=None)
@asynctest
async def test_untrusted_ca(self):
"""Test untrusted CA"""
skey = asyncssh.read_private_key('skey')
cert = make_certificate('ssh-rsa-cert-v01@openssh.com',
CERT_TYPE_USER, skey, skey, ['skey'])
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='ckey', client_keys=[(skey, cert)],
agent_path=None)
@asynctest
async def test_mismatched_ca(self):
"""Test mismatched CA"""
ckey = asyncssh.read_private_key('ckey')
skey = asyncssh.read_private_key('skey')
cert = make_certificate('ssh-rsa-cert-v01@openssh.com',
CERT_TYPE_USER, skey, skey, ['skey'])
with self.assertRaises(ValueError):
await self.connect(username='ckey', client_keys=[(ckey, cert)])
@asynctest
async def test_callback(self):
"""Test connecting with public key authentication using callback"""
async with self._connect_publickey(['ckey'], test_async=True):
pass
@asynctest
async def test_callback_sshkeypair(self):
"""Test client key passed in as an SSHKeyPair by callback"""
if not self.agent_available(): # pragma: no cover
self.skipTest('ssh-agent not available')
async with asyncssh.connect_agent() as agent:
keylist = await agent.get_keys()
async with self._connect_publickey(keylist):
pass
@asynctest
async def test_callback_untrusted_client_key(self):
"""Test failure connecting with public key authentication callback"""
with self.assertRaises(asyncssh.PermissionDenied):
await self._connect_publickey(['skey'])
@asynctest
async def test_unknown_auth(self):
"""Test server returning an unknown auth method before public key"""
with patch('asyncssh.connection.SSHClientConnection',
_UnknownAuthClientConnection):
async with self.connect(username='ckey', client_keys='ckey',
agent_path=None):
pass
@asynctest
async def test_disabled_trivial_public_key_auth(self):
"""Test disabling trivial auth with public key authentication"""
async with self.connect(username='ckey', agent_path=None,
disable_trivial_auth=True):
pass
class _TestPublicKeyAsyncServerAuth(_TestPublicKeyAuth):
"""Unit tests for public key authentication with async server callbacks"""
@classmethod
async def start_server(cls):
"""Start an SSH server which supports async public key auth"""
def server_factory():
"""Return an SSH server which trusts specific client keys"""
return _AsyncPublicKeyServer(client_keys=['ckey.pub',
'ckey_ecdsa.pub'])
return await cls.create_server(server_factory)
class _TestLimitedPublicKeySignatureAlgs(ServerTestCase):
"""Unit tests for limited public key signature algorithms"""
@classmethod
async def start_server(cls):
"""Start an SSH server which supports public key authentication"""
return await cls.create_server(
_PublicKeyServer, authorized_client_keys='authorized_keys',
signature_algs=['ssh-rsa', 'rsa-sha2-512'])
@asynctest
async def test_mismatched_client_signature_algs(self):
"""Test mismatched client key signature algorithms"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='ckey', client_keys='ckey',
signature_algs=['rsa-sha2-256'])
class _TestSetAuthorizedKeys(ServerTestCase):
"""Unit tests for public key authentication with set_authorized_keys"""
@classmethod
async def start_server(cls):
"""Start an SSH server which supports public key authentication"""
def server_factory():
"""Return an SSH server which calls set_authorized_keys"""
return _PublicKeyServer(authorized_keys='authorized_keys')
return await cls.create_server(server_factory)
@asynctest
async def test_set_authorized_keys(self):
"""Test set_authorized_keys method on server"""
async with self.connect(username='ckey', client_keys='ckey'):
pass
@asynctest
async def test_cert_principals(self):
"""Test certificate principals check"""
ckey = asyncssh.read_private_key('ckey')
cert = make_certificate('ssh-rsa-cert-v01@openssh.com',
CERT_TYPE_USER, ckey, ckey, ['ckey'])
async with self.connect(username='ckey', client_keys=[(ckey, cert)]):
pass
class _TestPreloadedAuthorizedKeys(ServerTestCase):
"""Unit tests for authentication with pre-loaded authorized keys"""
@classmethod
async def start_server(cls):
"""Start an SSH server which supports public key authentication"""
def server_factory():
"""Return an SSH server which calls set_authorized_keys"""
authorized_keys = asyncssh.read_authorized_keys('authorized_keys')
return _PublicKeyServer(authorized_keys=authorized_keys)
return await cls.create_server(server_factory)
@asynctest
async def test_pre_loaded_authorized_keys(self):
"""Test pre-loaded authorized keys file"""
async with self.connect(username='ckey', client_keys='ckey'):
pass
class _TestPreloadedAuthorizedKeysFileList(ServerTestCase):
"""Unit tests with pre-loaded authorized keys file list"""
@classmethod
async def start_server(cls):
"""Start an SSH server which supports public key authentication"""
def server_factory():
"""Return an SSH server which calls set_authorized_keys"""
authorized_keys = asyncssh.read_authorized_keys(['authorized_keys'])
return _PublicKeyServer(authorized_keys=authorized_keys)
return await cls.create_server(server_factory)
@asynctest
async def test_pre_loaded_authorized_keys(self):
"""Test pre-loaded authorized keys file list"""
async with self.connect(username='ckey', client_keys='ckey'):
pass
@unittest.skipUnless(x509_available, 'X.509 not available')
class _TestX509Auth(ServerTestCase):
"""Unit tests for X.509 certificate authentication"""
@classmethod
async def start_server(cls):
"""Start an SSH server which supports public key authentication"""
return await cls.create_server(
_PublicKeyServer, authorized_client_keys='authorized_keys_x509')
@asynctest
async def test_x509_self(self):
"""Test connecting with X.509 self-signed certificate"""
async with self.connect(username='ckey',
client_keys=['ckey_x509_self']):
pass
@asynctest
async def test_x509_chain(self):
"""Test connecting with X.509 certificate chain"""
async with self.connect(username='ckey',
client_keys=['ckey_x509_chain']):
pass
@asynctest
async def test_keypair_with_x509_cert(self):
"""Test connecting with a keypair with replaced X.509 cert"""
ckey = asyncssh.load_keypairs(['ckey'])[0]
async with self.connect(username='ckey',
client_keys=[(ckey, 'ckey_x509_chain')]):
pass
@asynctest
async def test_agent_keypair_with_x509_cert(self):
"""Test connecting with an agent key with replaced X.509 cert"""
if not self.agent_available(): # pragma: no cover
self.skipTest('ssh-agent not available')
async with asyncssh.connect_agent() as agent:
ckey = (await agent.get_keys())[2]
async with self.connect(username='ckey',
client_keys=[(ckey, 'ckey_x509_chain')]):
pass
@asynctest
async def test_x509_incomplete_chain(self):
"""Test connecting with incomplete X.509 certificate chain"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='ckey',
client_keys=[('ckey_x509_chain',
'ckey_x509_partial.pem')])
@asynctest
async def test_x509_untrusted_cert(self):
"""Test connecting with untrusted X.509 certificate chain"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='ckey', client_keys=['skey_x509_chain'])
@asynctest
async def test_disabled_trivial_x509_auth(self):
"""Test disabling trivial auth with X.509 certificate authentication"""
async with self.connect(username='ckey',
client_keys=['ckey_x509_self'],
disable_trivial_auth=True):
pass
@unittest.skipUnless(x509_available, 'X.509 not available')
class _TestX509AuthDisabled(ServerTestCase):
"""Unit tests for disabled X.509 certificate authentication"""
@classmethod
async def start_server(cls):
"""Start an SSH server which doesn't support X.509 authentication"""
return await cls.create_server(
_PublicKeyServer, x509_trusted_certs=None,
authorized_client_keys='authorized_keys')
@asynctest
async def test_failed_x509_auth(self):
"""Test connect failure with X.509 certificate"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='ckey', client_keys=['ckey_x509_self'],
signature_algs=['x509v3-ssh-rsa'])
@asynctest
async def test_non_x509(self):
"""Test connecting without an X.509 certificate"""
async with self.connect(username='ckey', client_keys=['ckey']):
pass
@unittest.skipUnless(x509_available, 'X.509 not available')
class _TestX509Subject(ServerTestCase):
"""Unit tests for X.509 certificate authentication by subject name"""
@classmethod
async def start_server(cls):
"""Start an SSH server which supports public key authentication"""
authorized_keys = asyncssh.import_authorized_keys(
'x509v3-ssh-rsa subject=OU=name\n')
return await cls.create_server(
_PublicKeyServer, authorized_client_keys=authorized_keys,
x509_trusted_certs=['ckey_x509_self.pub'])
@asynctest
async def test_x509_subject(self):
"""Test authenticating X.509 certificate by subject name"""
async with self.connect(username='ckey',
client_keys=['ckey_x509_self']):
pass
@unittest.skipUnless(x509_available, 'X.509 not available')
class _TestX509Untrusted(ServerTestCase):
"""Unit tests for X.509 authentication with no trusted certificates"""
@classmethod
async def start_server(cls):
"""Start an SSH server which supports public key authentication"""
return await cls.create_server(_PublicKeyServer,
authorized_client_keys=None)
@asynctest
async def test_x509_untrusted(self):
"""Test untrusted X.509 self-signed certificate"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='ckey', client_keys=['ckey_x509_self'])
@unittest.skipUnless(x509_available, 'X.509 not available')
class _TestX509Disabled(ServerTestCase):
"""Unit tests for X.509 authentication with server support disabled"""
@classmethod
async def start_server(cls):
"""Start an SSH server with X.509 authentication disabled"""
return await cls.create_server(_PublicKeyServer, x509_purposes=None)
@asynctest
async def test_x509_disabled(self):
"""Test X.509 client certificate with server support disabled"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='ckey', client_keys='skey_x509_self')
class _TestPasswordAuth(ServerTestCase):
"""Unit tests for password authentication"""
@classmethod
async def start_server(cls):
"""Start an SSH server which supports password authentication"""
return await cls.create_server(_PasswordServer)
@asynctest
async def test_get_server_auth_methods(self):
"""Test getting auth methods from the test server"""
auth_methods = await asyncssh.get_server_auth_methods(
self._server_addr, self._server_port, username='pw')
self.assertEqual(auth_methods, ['keyboard-interactive', 'password'])
@async_context_manager
async def _connect_password(self, username, password, old_password='',
new_password='', disable_trivial_auth=False,
test_async=False):
"""Open a connection to test password authentication"""
def client_factory():
"""Return an SSHClient to use to do password change"""
cls = _AsyncPasswordClient if test_async else _PasswordClient
return cls(password, old_password, new_password)
conn, _ = await self.create_connection(
client_factory, username=username, client_keys=None,
disable_trivial_auth=disable_trivial_auth)
return conn
@asynctest
async def test_password_auth(self):
"""Test connecting with password authentication"""
async with self.connect(username='pw', password='pw', client_keys=None):
pass
@asynctest
async def test_password_auth_callable(self):
"""Test connecting with a callable for password authentication"""
async with self.connect(username='pw', password=lambda: 'pw',
client_keys=None):
pass
@asynctest
async def test_password_auth_async_callable(self):
"""Test connecting with an async callable for password authentication"""
async def get_password():
return 'pw'
async with self.connect(username='pw', password=get_password,
client_keys=None):
pass
@asynctest
async def test_password_auth_awaitable(self):
"""Test connecting with an awaitable for password authentication"""
async def get_password():
return 'pw'
async with self.connect(username='pw', password=get_password(),
client_keys=None):
pass
@asynctest
async def test_password_auth_disabled(self):
"""Test connecting with password authentication disabled"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='pw', password='kbdint',
password_auth=False, preferred_auth='password')
@asynctest
async def test_password_auth_failure(self):
"""Test _failure connecting with password authentication"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='pw', password='badpw',
client_keys=None)
@asynctest
async def test_password_auth_callback(self):
"""Test connecting with password authentication callback"""
async with self._connect_password('pw', 'pw', test_async=True):
pass
@asynctest
async def test_password_auth_callback_failure(self):
"""Test failure connecting with password authentication callback"""
with self.assertRaises(asyncssh.PermissionDenied):
await self._connect_password('pw', 'badpw')
@asynctest
async def test_password_change(self):
"""Test password change"""
async with self._connect_password('pw', 'oldpw', 'oldpw', 'pw',
test_async=True):
pass
@asynctest
async def test_password_change_failure(self):
"""Test failure of password change"""
with self.assertRaises(asyncssh.PermissionDenied):
await self._connect_password('pw', 'oldpw', 'badpw', 'pw')
@asynctest
async def test_disabled_trivial_password_auth(self):
"""Test disabling trivial auth with password authentication"""
async with self.connect(username='pw', password='pw',
client_keys=None, disable_trivial_auth=True):
pass
@asynctest
async def test_disabled_trivial_password_change(self):
"""Test disabling trivial aith with password change"""
async with self._connect_password('pw', 'oldpw', 'oldpw', 'pw',
disable_trivial_auth=True):
pass
class _TestPasswordAsyncServerAuth(_TestPasswordAuth):
"""Unit tests for password authentication with async server callbacks"""
@classmethod
async def start_server(cls):
"""Start an SSH server which supports async password authentication"""
return await cls.create_server(_AsyncPasswordServer)
class _TestKbdintAuth(ServerTestCase):
"""Unit tests for keyboard-interactive authentication"""
@classmethod
async def start_server(cls):
"""Start an SSH server which supports keyboard-interactive auth"""
return await cls.create_server(_KbdintServer)
@asynctest
async def test_get_server_auth_methods(self):
"""Test getting auth methods from the test server"""
auth_methods = await asyncssh.get_server_auth_methods(
self._server_addr, self._server_port, username='none')
self.assertEqual(auth_methods, ['keyboard-interactive'])
@async_context_manager
async def _connect_kbdint(self, username, responses, test_async=False):
"""Open a connection to test keyboard-interactive auth"""
def client_factory():
"""Return an SSHClient to use to do keyboard-interactive auth"""
cls = _AsyncKbdintClient if test_async else _KbdintClient
return cls(responses)
conn, _ = await self.create_connection(client_factory,
username=username,
client_keys=None)
return conn
@asynctest
async def test_kbdint_auth_no_prompts(self):
"""Test keyboard-interactive authentication with no prompts"""
async with self.connect(username='none', password='kbdint',
client_keys=None):
pass
@asynctest
async def test_kbdint_auth_password(self):
"""Test keyboard-interactive authentication via password"""
async with self.connect(username='pw', password='kbdint',
client_keys=None):
pass
@asynctest
async def test_kbdint_auth_passcode(self):
"""Test keyboard-interactive authentication via passcode"""
async with self.connect(username='pc', password='kbdint',
client_keys=None):
pass
@asynctest
async def test_kbdint_auth_not_password(self):
"""Test keyboard-interactive authentication other than password"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='kbdint', password='kbdint',
client_keys=None)
@asynctest
async def test_kbdint_auth_multi_not_password(self):
"""Test keyboard-interactive authentication with multiple prompts"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='multi', password='kbdint',
client_keys=None)
@asynctest
async def test_kbdint_auth_disabled(self):
"""Test connecting with keyboard-interactive authentication disabled"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='pw', password='kbdint',
kbdint_auth=False)
@asynctest
async def test_kbdint_auth_failure(self):
"""Test failure connecting with keyboard-interactive authentication"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='kbdint', password='badpw',
client_keys=None)
@asynctest
async def test_kbdint_auth_callback(self):
"""Test keyboard-interactive auth callback"""
async with self._connect_kbdint('kbdint', ['kbdint'], test_async=True):
pass
@asynctest
async def test_kbdint_auth_callback_multi(self):
"""Test keyboard-interactive auth callback with multiple challenges"""
async with self._connect_kbdint('multi', ['1', '2'], test_async=True):
pass
@asynctest
async def test_kbdint_auth_callback_failure(self):
"""Test failure connecting with keyboard-interactive auth callback"""
with self.assertRaises(asyncssh.PermissionDenied):
await self._connect_kbdint('kbdint', ['badpw'])
@asynctest
async def test_disabled_trivial_kbdint_auth(self):
"""Test disabled trivial auth with keyboard-interactive auth"""
async with self.connect(username='pw', password='kbdint',
client_keys=None, disable_trivial_auth=True):
pass
@asynctest
async def test_disabled_trivial_kbdint_no_prompts(self):
"""Test disabled trivial with with no keyboard-interactive prompts"""
with self.assertRaises(asyncssh.PermissionDenied):
await self.connect(username='none', password='kbdint',
client_keys=None, disable_trivial_auth=True)
class _TestKbdintAsyncServerAuth(_TestKbdintAuth):
"""Unit tests for keyboard-interactive auth with async server callbacks"""
@classmethod
async def start_server(cls):
"""Start an SSH server which supports async kbd-int auth"""
return await cls.create_server(_AsyncKbdintServer)
class _TestKbdintPasswordServerAuth(ServerTestCase):
"""Unit tests for keyboard-interactive auth with server password auth"""
@classmethod
async def start_server(cls):
"""Start an SSH server which supports server password auth"""
return await cls.create_server(_PasswordServer)
@async_context_manager
async def _connect_kbdint(self, username, responses):
"""Open a connection to test keyboard-interactive auth"""
def client_factory():
"""Return an SSHClient to use to do keyboard-interactive auth"""
return _KbdintClient(responses)
conn, _ = await self.create_connection(client_factory,
username=username,
client_keys=None)
return conn
@asynctest
async def test_kbdint_password_auth(self):
"""Test keyboard-interactive server password authentication"""
async with self._connect_kbdint('pw', ['pw']):
pass
@asynctest
async def test_kbdint_password_auth_multiple_responses(self):
"""Test multiple responses to server password authentication"""
with self.assertRaises(asyncssh.PermissionDenied):
await self._connect_kbdint('pw', ['xxx', 'yyy'])
@asynctest
async def test_kbdint_password_change(self):
"""Test keyboard-interactive server password change"""
with self.assertRaises(asyncssh.PermissionDenied):
await self._connect_kbdint('pw', ['oldpw'])
class _TestClientLoginTimeout(ServerTestCase):
"""Unit test for client login timeout"""
@classmethod
async def start_server(cls):
"""Start an SSH server which supports public key authentication"""
def server_factory():
"""Return an SSHServer that delays before starting auth"""
return _PublicKeyServer(delay=2)
return await cls.create_server(
server_factory, authorized_client_keys='authorized_keys')
@asynctest
async def test_client_login_timeout_exceeded(self):
"""Test client login timeout exceeded"""
with self.assertRaises(asyncssh.ConnectionLost):
await self.connect(username='ckey', client_keys='ckey',
login_timeout=1)
@asynctest
async def test_client_login_timeout_exceeded_string(self):
"""Test client login timeout exceeded with string value"""
with self.assertRaises(asyncssh.ConnectionLost):
await self.connect(username='ckey', client_keys='ckey',
login_timeout='0m1s')
@asynctest
async def test_invalid_client_login_timeout(self):
"""Test invalid client login timeout"""
with self.assertRaises(ValueError):
await self.connect(login_timeout=-1)
class _TestServerLoginTimeoutExceeded(ServerTestCase):
"""Unit test for server login timeout"""
@classmethod
async def start_server(cls):
"""Start an SSH server with a 1 second login timeout"""
return await cls.create_server(
_PublicKeyServer, authorized_client_keys='authorized_keys',
login_timeout=1)
@asynctest
async def test_server_login_timeout_exceeded(self):
"""Test server_login timeout exceeded"""
def client_factory():
"""Return an SSHClient that delays before providing a key"""
return _PublicKeyClient(['ckey'], 2)
with self.assertRaises(asyncssh.ConnectionLost):
await self.create_connection(client_factory, username='ckey',
client_keys=None)
class _TestServerLoginTimeoutDisabled(ServerTestCase):
"""Unit test for disabled server login timeout"""
@classmethod
async def start_server(cls):
"""Start an SSH server with no login timeout"""
return await cls.create_server(
_PublicKeyServer, authorized_client_keys='authorized_keys',
login_timeout=None)
@asynctest
async def test_server_login_timeout_disabled(self):
"""Test with login timeout disabled"""
async with self.connect(username='ckey', client_keys='ckey'):
pass
|