Example #1
0
 def test_saveKeysha256(self):
     """
     L{_saveKey} will generate key fingerprint in
     L{FingerprintFormats.SHA256-BASE64} format if explicitly specified.
     """
     base = FilePath(self.mktemp())
     base.makedirs()
     filename = base.child('id_rsa').path
     key = Key.fromString(privateRSA_openssh)
     _saveKey(key, {'filename': filename, 'pass': '******',
         'format': 'sha256-base64'})
     self.assertEqual(
         self.stdout.getvalue(),
         "Your identification has been saved in %s\n"
         "Your public key has been saved in %s.pub\n"
         "The key fingerprint in <FingerprintFormats=SHA256_BASE64> is:\n"
         "FBTCOoknq0mHy+kpfnY9tDdcAJuWtCpuQMaV3EsvbUI=\n" % (
             filename,
             filename))
     self.assertEqual(
         key.fromString(
             base.child('id_rsa').getContent(), None, 'passphrase'),
         key)
     self.assertEqual(
         Key.fromString(base.child('id_rsa.pub').getContent()),
         key.public())
Example #2
0
 def test_saveKeyECDSA(self):
     """
     L{_saveKey} writes the private and public parts of a key to two
     different files and writes a report of this to standard out.
     Test with ECDSA key.
     """
     base = FilePath(self.mktemp())
     base.makedirs()
     filename = base.child('id_ecdsa').path
     key = Key.fromString(privateECDSA_openssh)
     _saveKey(key, {'filename': filename, 'pass': '******',
         'format': 'md5-hex'})
     self.assertEqual(
         self.stdout.getvalue(),
         "Your identification has been saved in %s\n"
         "Your public key has been saved in %s.pub\n"
         "The key fingerprint in <FingerprintFormats=MD5_HEX> is:\n"
         "1e:ab:83:a6:f2:04:22:99:7c:64:14:d2:ab:fa:f5:16\n" % (
             filename,
             filename))
     self.assertEqual(
         key.fromString(
             base.child('id_ecdsa').getContent(), None, 'passphrase'),
         key)
     self.assertEqual(
         Key.fromString(base.child('id_ecdsa.pub').getContent()),
         key.public())
Example #3
0
 def test_saveKeyEd25519(self):
     """
     L{_saveKey} writes the private and public parts of a key to two
     different files and writes a report of this to standard out.
     Test with Ed25519 key.
     """
     base = FilePath(self.mktemp())
     base.makedirs()
     filename = base.child("id_ed25519").path
     key = Key.fromString(privateEd25519_openssh_new)
     _saveKey(key, {
         "filename": filename,
         "pass": "******",
         "format": "md5-hex"
     })
     self.assertEqual(
         self.stdout.getvalue(),
         "Your identification has been saved in %s\n"
         "Your public key has been saved in %s.pub\n"
         "The key fingerprint in <FingerprintFormats=MD5_HEX> is:\n"
         "ab:ee:c8:ed:e5:01:1b:45:b7:8d:b2:f0:8f:61:1c:14\n" %
         (filename, filename),
     )
     self.assertEqual(
         key.fromString(
             base.child("id_ed25519").getContent(), None, "passphrase"),
         key,
     )
     self.assertEqual(
         Key.fromString(base.child("id_ed25519.pub").getContent()),
         key.public())
 def test_saveKeysha256(self):
     """
     L{_saveKey} will generate key fingerprint in
     L{FingerprintFormats.SHA256-BASE64} format if explicitly specified.
     """
     base = FilePath(self.mktemp())
     base.makedirs()
     filename = base.child('id_rsa').path
     key = Key.fromString(privateRSA_openssh)
     _saveKey(key, {'filename': filename, 'pass': '******',
         'format': 'sha256-base64'})
     self.assertEqual(
         self.stdout.getvalue(),
         "Your identification has been saved in %s\n"
         "Your public key has been saved in %s.pub\n"
         "The key fingerprint in <FingerprintFormats=SHA256_BASE64> is:\n"
         "ryaugIFT0B8ItuszldMEU7q14rG/wj9HkRosMeBWkts=\n" % (
             filename,
             filename))
     self.assertEqual(
         key.fromString(
             base.child('id_rsa').getContent(), None, 'passphrase'),
         key)
     self.assertEqual(
         Key.fromString(base.child('id_rsa.pub').getContent()),
         key.public())
Example #5
0
 def test_saveKeySubtypeV1(self):
     """
     L{_saveKey} can be told to write the new private key file in OpenSSH
     v1 format.
     """
     base = FilePath(self.mktemp())
     base.makedirs()
     filename = base.child('id_rsa').path
     key = Key.fromString(privateRSA_openssh)
     _saveKey(key, {
         'filename': filename, 'pass': '******',
         'format': 'md5-hex', 'private-key-subtype': 'v1',
     })
     self.assertEqual(
         self.stdout.getvalue(),
         "Your identification has been saved in %s\n"
         "Your public key has been saved in %s.pub\n"
         "The key fingerprint in <FingerprintFormats=MD5_HEX> is:\n"
         "85:25:04:32:58:55:96:9f:57:ee:fb:a8:1a:ea:69:da\n" % (
             filename,
             filename))
     privateKeyContent = base.child('id_rsa').getContent()
     self.assertEqual(
         key.fromString(privateKeyContent, None, 'passphrase'), key)
     self.assertTrue(privateKeyContent.startswith(
         b'-----BEGIN OPENSSH PRIVATE KEY-----\n'))
     self.assertEqual(
         Key.fromString(base.child('id_rsa.pub').getContent()),
         key.public())
 def test_saveKeyECDSA(self):
     """
     L{_saveKey} writes the private and public parts of a key to two
     different files and writes a report of this to standard out.
     Test with ECDSA key.
     """
     base = FilePath(self.mktemp())
     base.makedirs()
     filename = base.child('id_ecdsa').path
     key = Key.fromString(privateECDSA_openssh)
     _saveKey(key, {'filename': filename, 'pass': '******',
         'format': 'md5-hex'})
     self.assertEqual(
         self.stdout.getvalue(),
         "Your identification has been saved in %s\n"
         "Your public key has been saved in %s.pub\n"
         "The key fingerprint in <FingerprintFormats=MD5_HEX> is:\n"
         "e2:3b:e8:1c:f8:c9:c7:de:8b:c0:00:68:2e:c9:2c:8a\n" % (
             filename,
             filename))
     self.assertEqual(
         key.fromString(
             base.child('id_ecdsa').getContent(), None, 'passphrase'),
         key)
     self.assertEqual(
         Key.fromString(base.child('id_ecdsa.pub').getContent()),
         key.public())
Example #7
0
 def test_saveKey(self):
     """
     L{_saveKey} writes the private and public parts of a key to two
     different files and writes a report of this to standard out.
     """
     base = FilePath(self.mktemp())
     base.makedirs()
     filename = base.child('id_rsa').path
     key = Key.fromString(privateRSA_openssh)
     _saveKey(key, {'filename': filename, 'pass': '******',
         'format': 'md5-hex'})
     self.assertEqual(
         self.stdout.getvalue(),
         "Your identification has been saved in %s\n"
         "Your public key has been saved in %s.pub\n"
         "The key fingerprint in <FingerprintFormats=MD5_HEX> is:\n"
         "85:25:04:32:58:55:96:9f:57:ee:fb:a8:1a:ea:69:da\n" % (
             filename,
             filename))
     self.assertEqual(
         key.fromString(
             base.child('id_rsa').getContent(), None, 'passphrase'),
         key)
     self.assertEqual(
         Key.fromString(base.child('id_rsa.pub').getContent()),
         key.public())
Example #8
0
 def test_saveKey(self):
     """
     L{_saveKey} writes the private and public parts of a key to two
     different files and writes a report of this to standard out.
     """
     base = FilePath(self.mktemp())
     base.makedirs()
     filename = base.child('id_rsa').path
     key = Key.fromString(privateRSA_openssh)
     _saveKey(
         key.keyObject,
         {'filename': filename, 'pass': '******'})
     self.assertEqual(
         self.stdout.getvalue(),
         "Your identification has been saved in %s\n"
         "Your public key has been saved in %s.pub\n"
         "The key fingerprint is:\n"
         "3d:13:5f:cb:c9:79:8a:93:06:27:65:bc:3d:0b:8f:af\n" % (
             filename,
             filename))
     self.assertEqual(
         key.fromString(
             base.child('id_rsa').getContent(), None, 'passphrase'),
         key)
     self.assertEqual(
         Key.fromString(base.child('id_rsa.pub').getContent()),
         key.public())
 def test_saveKeyEmptyPassphrase(self):
     """
     L{_saveKey} will choose an empty string for the passphrase if
     no-passphrase is C{True}.
     """
     base = FilePath(self.mktemp())
     base.makedirs()
     filename = base.child("id_rsa").path
     key = Key.fromString(privateRSA_openssh)
     _saveKey(key, {"filename": filename, "no-passphrase": True})
     self.assertEqual(key.fromString(base.child("id_rsa").getContent(), None, b""), key)
Example #10
0
 def test_saveKeyEmptyPassphrase(self):
     """
     L{_saveKey} will choose an empty string for the passphrase if
     no-passphrase is C{True}.
     """
     base = FilePath(self.mktemp())
     base.makedirs()
     filename = base.child('id_rsa').path
     key = Key.fromString(privateRSA_openssh)
     _saveKey(key, {'filename': filename, 'no-passphrase': True})
     self.assertEqual(
         key.fromString(base.child('id_rsa').getContent(), None, b''), key)
Example #11
0
 def test_saveKeyBadFingerPrintformat(self):
     """
     L{_saveKey} raises C{keys.BadFingerprintFormat} when unsupported
     formats are requested.
     """
     base = FilePath(self.mktemp())
     base.makedirs()
     filename = base.child('id_rsa').path
     key = Key.fromString(privateRSA_openssh)
     with self.assertRaises(BadFingerPrintFormat) as em:
         _saveKey(key, {'filename': filename, 'pass': '******',
             'format': 'sha-base64'})
     self.assertEqual('Unsupported fingerprint format: sha-base64',
         em.exception.args[0])
 def test_saveKeyBadFingerPrintformat(self):
     """
     L{_saveKey} raises C{keys.BadFingerprintFormat} when unsupported
     formats are requested.
     """
     base = FilePath(self.mktemp())
     base.makedirs()
     filename = base.child('id_rsa').path
     key = Key.fromString(privateRSA_openssh)
     with self.assertRaises(BadFingerPrintFormat) as em:
         _saveKey(key, {'filename': filename, 'pass': '******',
             'format': 'sha-base64'})
     self.assertEqual('Unsupported fingerprint format: sha-base64',
         em.exception.args[0])
 def test_saveKeyECDSAEmptyPassphrase(self):
     """
     L{_saveKey} will choose an empty string for the passphrase if
     no-passphrase is C{True}.
     """
     base = FilePath(self.mktemp())
     base.makedirs()
     filename = base.child('id_ecdsa').path
     key = Key.fromString(privateECDSA_openssh)
     _saveKey(key, {'filename': filename, 'no-passphrase': True,
         'format': 'md5-hex'})
     self.assertEqual(
         key.fromString(
             base.child('id_ecdsa').getContent(), None),
         key)
Example #14
0
 def test_saveKeyEd25519EmptyPassphrase(self):
     """
     L{_saveKey} will choose an empty string for the passphrase if
     no-passphrase is C{True}.
     """
     base = FilePath(self.mktemp())
     base.makedirs()
     filename = base.child("id_ed25519").path
     key = Key.fromString(privateEd25519_openssh_new)
     _saveKey(key, {
         "filename": filename,
         "no-passphrase": True,
         "format": "md5-hex"
     })
     self.assertEqual(
         key.fromString(base.child("id_ed25519").getContent(), None), key)
Example #15
0
    def test_saveKeyNoFilename(self):
        """
        When no path is specified, it will ask for the path used to store the
        key.
        """
        base = FilePath(self.mktemp())
        base.makedirs()
        keyPath = base.child("custom_key").path

        self.patch(__builtin__, "raw_input", lambda _: keyPath)
        key = Key.fromString(privateRSA_openssh)
        _saveKey(key, {"filename": None, "no-passphrase": True})

        persistedKeyContent = base.child("custom_key").getContent()
        persistedKey = key.fromString(persistedKeyContent, None, b"")
        self.assertEqual(key, persistedKey)
Example #16
0
    def test_saveKeyNoFilename(self):
        """
        When no path is specified, it will ask for the path used to store the
        key.
        """
        base = FilePath(self.mktemp())
        base.makedirs()
        keyPath = base.child('custom_key').path

        self.patch(__builtin__, 'raw_input', lambda _: keyPath)
        key = Key.fromString(privateRSA_openssh)
        _saveKey(key, {'filename': None, 'no-passphrase': True})

        persistedKeyContent = base.child('custom_key').getContent()
        persistedKey = key.fromString(persistedKeyContent, None, b'')
        self.assertEqual(key, persistedKey)
    def test_saveKeyNoFilename(self):
        """
        When no path is specified, it will ask for the path used to store the
        key.
        """
        base = FilePath(self.mktemp())
        base.makedirs()
        keyPath = base.child('custom_key').path

        import twisted.conch.scripts.ckeygen
        self.patch(twisted.conch.scripts.ckeygen, 'raw_input', lambda _: keyPath)
        key = Key.fromString(privateRSA_openssh)
        _saveKey(key, {'filename': None, 'no-passphrase': True,
            'format': 'md5-hex'})

        persistedKeyContent = base.child('custom_key').getContent()
        persistedKey = key.fromString(persistedKeyContent, None, b'')
        self.assertEqual(key, persistedKey)
Example #18
0
 def test_saveKeyEmptyPassphrase(self):
     """
     L{_saveKey} will choose an empty string for the passphrase if
     no-passphrase is C{True}.
     """
     base = FilePath(self.mktemp())
     base.makedirs()
     filename = base.child('id_rsa').path
     key = Key.fromString(privateRSA_openssh)
     _saveKey(
         key.keyObject,
         {'filename': filename, 'no-passphrase': True},
         'rsa',
         )
     self.assertEqual(
         key.fromString(
             base.child('id_rsa').getContent(), None, b''),
         key)
Example #19
0
 def test_saveKeyBadFingerPrintformat(self):
     """
     L{_saveKey} raises C{keys.BadFingerprintFormat} when unsupported
     formats are requested.
     """
     base = FilePath(self.mktemp())
     base.makedirs()
     filename = base.child("id_rsa").path
     key = Key.fromString(privateRSA_openssh)
     with self.assertRaises(BadFingerPrintFormat) as em:
         _saveKey(
             key,
             {
                 "filename": filename,
                 "pass": "******",
                 "format": "sha-base64"
             },
         )
     self.assertEqual("Unsupported fingerprint format: sha-base64",
                      em.exception.args[0])
Example #20
0
    def test_saveKeyNoFilename(self):
        """
        When no path is specified, it will ask for the path used to store the
        key.
        """
        base = FilePath(self.mktemp())
        base.makedirs()
        keyPath = base.child('custom_key').path

        self.patch(__builtin__, 'raw_input', lambda _: keyPath)
        key = Key.fromString(privateRSA_openssh)
        _saveKey(
            key.keyObject,
            {'filename': None, 'no-passphrase': True},
            'rsa',
            )

        persistedKeyContent = base.child('custom_key').getContent()
        persistedKey = key.fromString(persistedKeyContent, None, b'')
        self.assertEqual(key, persistedKey)
Example #21
0
    def test_saveKeyNoFilename(self):
        """
        When no path is specified, it will ask for the path used to store the
        key.
        """
        base = FilePath(self.mktemp())
        base.makedirs()
        keyPath = base.child("custom_key").path

        import twisted.conch.scripts.ckeygen

        self.patch(twisted.conch.scripts.ckeygen, "_inputSaveFile",
                   lambda _: keyPath)
        key = Key.fromString(privateRSA_openssh)
        _saveKey(key, {
            "filename": None,
            "no-passphrase": True,
            "format": "md5-hex"
        })

        persistedKeyContent = base.child("custom_key").getContent()
        persistedKey = key.fromString(persistedKeyContent, None, b"")
        self.assertEqual(key, persistedKey)