Beispiel #1
0
    def test_sshHostKey(self):
        fingerprint, keyHash, keyType = sshtools.sshHostKey('localhost')
        self.assertIsInstance(fingerprint, str)
        self.assertIsInstance(keyHash, str)
        self.assertIsInstance(keyType, str)
        if fingerprint.startswith('SHA256'):
            self.assertEqual(len(fingerprint), 50)
            self.assertRegex(fingerprint, r'^SHA256:[a-zA-Z0-9/+]+$')
        else:
            self.assertEqual(len(fingerprint), 47)
            self.assertRegex(fingerprint, r'^[a-fA-F0-9:]+$')

        self.assertIn(keyType, ('ECDSA', 'RSA'))

        hostKey = '/etc/ssh/ssh_host_{}_key.pub'.format(keyType.lower())
        self.assertTrue(os.path.exists(hostKey))
        self.assertEqual(3, len(keyHash.split()))
        try:
            with open(hostKey, 'rt') as f:
                pubKey = f.read().split()[1]
            self.assertEqual(pubKey, keyHash.split()[2])
        except (IOError, IndexError):
            pass
Beispiel #2
0
    def test_sshHostKey(self):
        fingerprint, keyHash, keyType = sshtools.sshHostKey('localhost')
        self.assertIsInstance(fingerprint, str)
        self.assertIsInstance(keyHash, str)
        self.assertIsInstance(keyType, str)
        if fingerprint.startswith('SHA256'):
            self.assertEqual(len(fingerprint), 50)
            self.assertRegex(fingerprint, r'^SHA256:[a-zA-Z0-9/+]+$')
        else:
            self.assertEqual(len(fingerprint), 47)
            self.assertRegex(fingerprint, r'^[a-fA-F0-9:]+$')

        self.assertIn(keyType, ('ECDSA', 'RSA'))

        hostKey = '/etc/ssh/ssh_host_{}_key.pub'.format(keyType.lower())
        self.assertExists(hostKey)
        self.assertEqual(3, len(keyHash.split()))
        try:
            with open(hostKey, 'rt') as f:
                pubKey = f.read().split()[1]
            self.assertEqual(pubKey, keyHash.split()[2])
        except (IOError, IndexError):
            pass