Esempio n. 1
0
    def test_14_load_ecdsa_384(self):
        key = ECDSAKey.from_private_key_file(test_path('test_ecdsa_384.key'))
        self.assertEqual('ecdsa-sha2-nistp384', key.get_name())
        exp_ecdsa = b(FINGER_ECDSA_384.split()[1].replace(':', ''))
        my_ecdsa = hexlify(key.get_fingerprint())
        self.assertEqual(exp_ecdsa, my_ecdsa)
        self.assertEqual(PUB_ECDSA_384.split()[1], key.get_base64())
        self.assertEqual(384, key.get_bits())

        s = StringIO()
        key.write_private_key(s)
        self.assertEqual(ECDSA_PRIVATE_OUT_384, s.getvalue())
        s.seek(0)
        key2 = ECDSAKey.from_private_key(s)
        self.assertEqual(key, key2)
Esempio n. 2
0
    def test_2_load_rsa(self):
        key = RSAKey.from_private_key_file(test_path('test_rsa.key'))
        self.assertEqual('ssh-rsa', key.get_name())
        exp_rsa = b(FINGER_RSA.split()[1].replace(':', ''))
        my_rsa = hexlify(key.get_fingerprint())
        self.assertEqual(exp_rsa, my_rsa)
        self.assertEqual(PUB_RSA.split()[1], key.get_base64())
        self.assertEqual(1024, key.get_bits())

        s = StringIO()
        key.write_private_key(s)
        self.assertEqual(RSA_PRIVATE_OUT, s.getvalue())
        s.seek(0)
        key2 = RSAKey.from_private_key(s)
        self.assertEqual(key, key2)
Esempio n. 3
0
    def test_4_load_dss(self):
        key = DSSKey.from_private_key_file(test_path('test_dss.key'))
        self.assertEqual('ssh-dss', key.get_name())
        exp_dss = b(FINGER_DSS.split()[1].replace(':', ''))
        my_dss = hexlify(key.get_fingerprint())
        self.assertEqual(exp_dss, my_dss)
        self.assertEqual(PUB_DSS.split()[1], key.get_base64())
        self.assertEqual(1024, key.get_bits())

        s = StringIO()
        key.write_private_key(s)
        self.assertEqual(DSS_PRIVATE_OUT, s.getvalue())
        s.seek(0)
        key2 = DSSKey.from_private_key(s)
        self.assertEqual(key, key2)
Esempio n. 4
0
    def test_10_load_ecdsa_256(self):
        key = ECDSAKey.from_private_key_file(_support("test_ecdsa_256.key"))
        self.assertEqual("ecdsa-sha2-nistp256", key.get_name())
        exp_ecdsa = b(FINGER_ECDSA_256.split()[1].replace(":", ""))
        my_ecdsa = hexlify(key.get_fingerprint())
        self.assertEqual(exp_ecdsa, my_ecdsa)
        self.assertEqual(PUB_ECDSA_256.split()[1], key.get_base64())
        self.assertEqual(256, key.get_bits())

        s = StringIO()
        key.write_private_key(s)
        self.assertEqual(ECDSA_PRIVATE_OUT_256, s.getvalue())
        s.seek(0)
        key2 = ECDSAKey.from_private_key(s)
        self.assertEqual(key, key2)
Esempio n. 5
0
    def test_18_load_ecdsa_521(self):
        key = ECDSAKey.from_private_key_file(test_path('test_ecdsa_521.key'))
        self.assertEqual('ecdsa-sha2-nistp521', key.get_name())
        exp_ecdsa = b(FINGER_ECDSA_521.split()[1].replace(':', ''))
        my_ecdsa = hexlify(key.get_fingerprint())
        self.assertEqual(exp_ecdsa, my_ecdsa)
        self.assertEqual(PUB_ECDSA_521.split()[1], key.get_base64())
        self.assertEqual(521, key.get_bits())

        s = StringIO()
        key.write_private_key(s)
        # Different versions of OpenSSL (SSLeay versions 0x1000100f and
        # 0x1000207f for instance) use different apparently valid (as far as
        # ssh-keygen is concerned) padding. So we can't check the actual value
        # of the pem encoded key.
        s.seek(0)
        key2 = ECDSAKey.from_private_key(s)
        self.assertEqual(key, key2)
Esempio n. 6
0
    def test_proxycommand_interpolation(self):
        """
        ProxyCommand should perform interpolation on the value
        """
        config = paramiko.util.parse_ssh_config(
            StringIO("""
Host specific
    Port 37
    ProxyCommand host %h port %p lol
Host portonly
    Port 155
Host *
    Port 25
    ProxyCommand host %h port %p
"""))
        for host, val in (
            ('foo.com', "host foo.com port 25"),
            ('specific', "host specific port 37 lol"),
            ('portonly', "host portonly port 155"),
        ):
            self.assertEqual(host_config(host, config)['proxycommand'], val)
Esempio n. 7
0
    def test_11_host_config_test_negation(self):
        test_config_file = """
Host www13.* !*.example.com
    Port 22

Host *.example.com !www13.*
    Port 2222

Host www13.*
    Port 8080

Host *
    Port 3333
    """
        f = StringIO(test_config_file)
        config = paramiko.util.parse_ssh_config(f)
        host = 'www13.example.com'
        self.assertEqual(
            paramiko.util.lookup_ssh_host_config(host, config),
            {'hostname': host, 'port': '8080'}
        )
Esempio n. 8
0
    def test_proxycommand_none_issue_418(self):
        test_config_file = """
Host proxycommand-standard-none
    ProxyCommand None

Host proxycommand-with-equals-none
    ProxyCommand=None
    """
        for host, values in {
                'proxycommand-standard-none': {
                    'hostname': 'proxycommand-standard-none'
                },
                'proxycommand-with-equals-none': {
                    'hostname': 'proxycommand-with-equals-none'
                }
        }.items():

            f = StringIO(test_config_file)
            config = paramiko.util.parse_ssh_config(f)
            self.assertEqual(
                paramiko.util.lookup_ssh_host_config(host, config), values)
Esempio n. 9
0
    def test_host_config_test_proxycommand(self):
        test_config_file = """
Host proxy-with-equal-divisor-and-space
ProxyCommand = foo=bar

Host proxy-with-equal-divisor-and-no-space
ProxyCommand=foo=bar

Host proxy-without-equal-divisor
ProxyCommand foo=bar:%h-%p
    """
        for host, proxycmd in [
            ('proxy-with-equal-divisor-and-space', 'foo=bar'),
            ('proxy-with-equal-divisor-and-no-space', 'foo=bar'),
            ('proxy-without-equal-divisor', 'foo=bar:proxy-without-equal-divisor-22'),
        ]:
            f = StringIO(test_config_file)
            config = paramiko.util.parse_ssh_config(f)
            self.assertEqual(
                paramiko.util.lookup_ssh_host_config(host, config),
                {'hostname': host, 'proxycommand': proxycmd},
            )
Esempio n. 10
0
 def test_parse_config(self):
     global test_config_file
     f = StringIO(test_config_file)
     config = paramiko.util.parse_ssh_config(f)
     self.assertEqual(
         config._config,
         [
             {
                 "host": ["*"],
                 "config": {}
             },
             {
                 "host": ["*"],
                 "config": {
                     "identityfile": ["~/.ssh/id_rsa"],
                     "user": "******",
                 },
             },
             {
                 "host": ["*.example.com"],
                 "config": {
                     "user": "******",
                     "port": "3333"
                 },
             },
             {
                 "host": ["*"],
                 "config": {
                     "crazy": "something dumb"
                 }
             },
             {
                 "host": ["spoo.example.com"],
                 "config": {
                     "crazy": "something else"
                 },
             },
         ],
     )
Esempio n. 11
0
    def test_proxycommand_none_masking(self):
        # Re: https://github.com/paramiko/paramiko/issues/670
        source_config = """
Host specific-host
    ProxyCommand none
Host other-host
    ProxyCommand other-proxy
Host *
    ProxyCommand default-proxy
"""
        config = paramiko.SSHConfig()
        config.parse(StringIO(source_config))
        # When bug is present, the full stripping-out of specific-host's
        # ProxyCommand means it actually appears to pick up the default
        # ProxyCommand value instead, due to cascading. It should (for
        # backwards compatibility reasons in 1.x/2.x) appear completely blank,
        # as if the host had no ProxyCommand whatsoever.
        # Threw another unrelated host in there just for sanity reasons.
        self.assertFalse('proxycommand' in config.lookup('specific-host'))
        self.assertEqual(
            config.lookup('other-host')['proxycommand'], 'other-proxy')
        self.assertEqual(
            config.lookup('some-random-host')['proxycommand'], 'default-proxy')
Esempio n. 12
0
    def test_host_config(self):
        global test_config_file
        f = StringIO(test_config_file)
        config = paramiko.util.parse_ssh_config(f)

        for host, values in {
            'irc.danger.com':   {'crazy': 'something dumb',
                                'user': '******'},
            'irc.example.com':  {'crazy': 'something dumb',
                                'user': '******',
                                'port': '3333'},
            'spoo.example.com': {'crazy': 'something dumb',
                                'user': '******',
                                'port': '3333'}
        }.items():
            values.update(
                hostname=host,
                identityfile=[os.path.expanduser("~/.ssh/id_rsa")]
            )
            self.assertEqual(
                paramiko.util.lookup_ssh_host_config(host, config),
                values
            )
Esempio n. 13
0
    def test_quoted_host_names(self):
        test_config_file = """\
Host "param pam" param "pam"
    Port 1111

Host "param2"
    Port 2222

Host param3 parara
    Port 3333

Host param4 "p a r" "p" "par" para
    Port 4444
"""
        res = {
            'param pam': {'hostname': 'param pam', 'port': '1111'},
            'param': {'hostname': 'param', 'port': '1111'},
            'pam': {'hostname': 'pam', 'port': '1111'},

            'param2': {'hostname': 'param2', 'port': '2222'},

            'param3': {'hostname': 'param3', 'port': '3333'},
            'parara': {'hostname': 'parara', 'port': '3333'},

            'param4': {'hostname': 'param4', 'port': '4444'},
            'p a r': {'hostname': 'p a r', 'port': '4444'},
            'p': {'hostname': 'p', 'port': '4444'},
            'par': {'hostname': 'par', 'port': '4444'},
            'para': {'hostname': 'para', 'port': '4444'},
        }
        f = StringIO(test_config_file)
        config = paramiko.util.parse_ssh_config(f)
        for host, values in res.items():
            self.assertEqual(
                paramiko.util.lookup_ssh_host_config(host, config),
                values
            )
Esempio n. 14
0
    def test_host_config_test_negation(self):
        test_config_file = """
Host www13.* !*.example.com
    Port 22

Host *.example.com !www13.*
    Port 2222

Host www13.*
    Port 8080

Host *
    Port 3333
    """
        f = StringIO(test_config_file)
        config = paramiko.util.parse_ssh_config(f)
        host = "www13.example.com"
        self.assertEqual(
            paramiko.util.lookup_ssh_host_config(host, config),
            {
                "hostname": host,
                "port": "8080"
            },
        )
Esempio n. 15
0
    def test_quoted_host_names(self):
        test_config_file = """\
Host "param pam" param "pam"
    Port 1111

Host "param2"
    Port 2222

Host param3 parara
    Port 3333

Host param4 "p a r" "p" "par" para
    Port 4444
"""
        res = {
            "param pam": {
                "hostname": "param pam",
                "port": "1111"
            },
            "param": {
                "hostname": "param",
                "port": "1111"
            },
            "pam": {
                "hostname": "pam",
                "port": "1111"
            },
            "param2": {
                "hostname": "param2",
                "port": "2222"
            },
            "param3": {
                "hostname": "param3",
                "port": "3333"
            },
            "parara": {
                "hostname": "parara",
                "port": "3333"
            },
            "param4": {
                "hostname": "param4",
                "port": "4444"
            },
            "p a r": {
                "hostname": "p a r",
                "port": "4444"
            },
            "p": {
                "hostname": "p",
                "port": "4444"
            },
            "par": {
                "hostname": "par",
                "port": "4444"
            },
            "para": {
                "hostname": "para",
                "port": "4444"
            },
        }
        f = StringIO(test_config_file)
        config = paramiko.util.parse_ssh_config(f)
        for host, values in res.items():
            self.assertEquals(
                paramiko.util.lookup_ssh_host_config(host, config), values)
Esempio n. 16
0
 def test_get_hostnames(self):
     f = StringIO(test_config_file)
     config = paramiko.util.parse_ssh_config(f)
     self.assertEqual(config.get_hostnames(),
                      {"*", "*.example.com", "spoo.example.com"})
Esempio n. 17
0
 def test_config_dos_crlf_succeeds(self):
     config_file = StringIO("host abcqwerty\r\nHostName 127.0.0.1\r\n")
     config = paramiko.SSHConfig()
     config.parse(config_file)
     self.assertEqual(config.lookup("abcqwerty")["hostname"], "127.0.0.1")
Esempio n. 18
0
 def test_get_hostnames(self):
     f = StringIO(test_config_file)
     config = paramiko.util.parse_ssh_config(f)
     self.assertEqual(config.get_hostnames(),
                      set(['*', '*.example.com', 'spoo.example.com']))