Esempio n. 1
0
 def test_verifyBadKey(self):
     """
     L{default.verifyHostKey} should return a L{Deferred} which fails with
     L{HostKeyChanged} if the host key is incorrect.
     """
     l = []
     default.verifyHostKey(self.fakeTransport, "4.3.2.1", otherSampleKey,
                           "Again, not required.").addErrback(l.append)
     l[0].trap(HostKeyChanged)
Esempio n. 2
0
 def test_verifyBadKey(self):
     """
     L{default.verifyHostKey} should return a L{Deferred} which fails with
     L{HostKeyChanged} if the host key is incorrect.
     """
     l = []
     default.verifyHostKey(self.fakeTransport, "4.3.2.1", otherSampleKey,
                           "Again, not required.").addErrback(l.append)
     l[0].trap(HostKeyChanged)
Esempio n. 3
0
 def test_verifyOKKey(self):
     """
     L{default.verifyHostKey} should return a L{Deferred} which fires with
     C{1} when passed a host, IP, and key which already match the
     known_hosts file it is supposed to check.
     """
     l = []
     default.verifyHostKey(self.fakeTransport, "4.3.2.1", sampleKey,
                           "I don't care.").addCallback(l.append)
     self.assertEqual([1], l)
Esempio n. 4
0
 def test_verifyOKKey(self):
     """
     L{default.verifyHostKey} should return a L{Deferred} which fires with
     C{1} when passed a host, IP, and key which already match the
     known_hosts file it is supposed to check.
     """
     l = []
     default.verifyHostKey(self.fakeTransport, "4.3.2.1", sampleKey,
                           "I don't care.").addCallback(l.append)
     self.assertEqual([1], l)
Esempio n. 5
0
 def test_verifyBadKey(self):
     """
     L{default.verifyHostKey} should return a L{Deferred} which fails with
     L{HostKeyChanged} if the host key is incorrect.
     """
     d = default.verifyHostKey(self.fakeTransport, "4.3.2.1",
                               otherSampleKey, "Again, not required.")
     return self.assertFailure(d, HostKeyChanged)
Esempio n. 6
0
 def test_noKnownHostsOption(self):
     """
     L{default.verifyHostKey} should find your known_hosts file in
     ~/.ssh/known_hosts if you don't specify one explicitly on the command
     line.
     """
     l = []
     tmpdir = self.mktemp()
     oldHostsOption = self.hostsOption
     hostsNonOption = FilePath(tmpdir).child(".ssh").child("known_hosts")
     hostsNonOption.parent().makedirs()
     FilePath(oldHostsOption).moveTo(hostsNonOption)
     self.replaceHome(tmpdir)
     self.options['known-hosts'] = None
     default.verifyHostKey(self.fakeTransport, "4.3.2.1", sampleKey,
                           "I don't care.").addCallback(l.append)
     self.assertEqual([1], l)
Esempio n. 7
0
 def test_noKnownHostsOption(self):
     """
     L{default.verifyHostKey} should find your known_hosts file in
     ~/.ssh/known_hosts if you don't specify one explicitly on the command
     line.
     """
     l = []
     tmpdir = self.mktemp()
     oldHostsOption = self.hostsOption
     hostsNonOption = FilePath(tmpdir).child(".ssh").child("known_hosts")
     hostsNonOption.parent().makedirs()
     FilePath(oldHostsOption).moveTo(hostsNonOption)
     self.replaceHome(tmpdir)
     self.options['known-hosts'] = None
     default.verifyHostKey(self.fakeTransport, "4.3.2.1", sampleKey,
                           "I don't care.").addCallback(l.append)
     self.assertEqual([1], l)
Esempio n. 8
0
 def test_verifyBadKey(self):
     """
     L{default.verifyHostKey} should return a L{Deferred} which fails with
     L{HostKeyChanged} if the host key is incorrect.
     """
     d = default.verifyHostKey(
         self.fakeTransport, "4.3.2.1", otherSampleKey,
         "Again, not required.")
     return self.assertFailure(d, HostKeyChanged)
Esempio n. 9
0
 def test_verifyHostButNotIP(self):
     """
     L{default.verifyHostKey} should return a L{Deferred} which fires with
     C{1} when passed a host which matches with an IP is not present in its
     known_hosts file, and should also warn the user that it has added the
     IP address.
     """
     l = []
     default.verifyHostKey(self.fakeTransport, "8.7.6.5", sampleKey,
                           "Fingerprint not required.").addCallback(l.append)
     self.assertEqual(
         ["Warning: Permanently added the RSA host key for IP address "
         "'8.7.6.5' to the list of known hosts."],
         self.fakeFile.outchunks)
     self.assertEqual([1], l)
     knownHostsFile = KnownHostsFile.fromPath(FilePath(self.hostsOption))
     self.assertEqual(True, knownHostsFile.hasHostKey("8.7.6.5",
                                          Key.fromString(sampleKey)))
Esempio n. 10
0
 def test_verifyQuestion(self):
     """
     L{default.verifyHostKey} should return a L{Default} which fires with
     C{0} when passed a unknown host that the user refuses to acknowledge.
     """
     self.fakeTransport.factory.options['host'] = 'fake.example.com'
     l = []
     self.fakeFile.inlines.append("no")
     default.verifyHostKey(self.fakeTransport, "9.8.7.6", otherSampleKey,
                           "No fingerprint!").addErrback(l.append)
     self.assertEqual([
             "The authenticity of host 'fake.example.com (9.8.7.6)' "
             "can't be established.\n"
             "RSA key fingerprint is "
             "57:a1:c2:a1:07:a0:2b:f4:ce:b5:e5:b7:ae:cc:e1:99.\n"
             "Are you sure you want to continue connecting (yes/no)? "],
                      self.fakeFile.outchunks)
     l[0].trap(UserRejectedKey)
Esempio n. 11
0
 def test_verifyQuestion(self):
     """
     L{default.verifyHostKey} should return a L{Default} which fires with
     C{0} when passed a unknown host that the user refuses to acknowledge.
     """
     self.fakeTransport.factory.options['host'] = 'fake.example.com'
     l = []
     self.fakeFile.inlines.append("no")
     default.verifyHostKey(self.fakeTransport, "9.8.7.6", otherSampleKey,
                           "No fingerprint!").addErrback(l.append)
     self.assertEqual([
         "The authenticity of host 'fake.example.com (9.8.7.6)' "
         "can't be established.\n"
         "RSA key fingerprint is "
         "57:a1:c2:a1:07:a0:2b:f4:ce:b5:e5:b7:ae:cc:e1:99.\n"
         "Are you sure you want to continue connecting (yes/no)? "
     ], self.fakeFile.outchunks)
     l[0].trap(UserRejectedKey)
Esempio n. 12
0
 def test_verifyQuestion(self):
     """
     L{default.verifyHostKey} should return a L{Default} which fires with
     C{0} when passed an unknown host that the user refuses to acknowledge.
     """
     self.fakeTransport.factory.options['host'] = b'fake.example.com'
     self.fakeFile.inlines.append(b"no")
     d = default.verifyHostKey(self.fakeTransport, b"9.8.7.6",
                               otherSampleKey, b"No fingerprint!")
     self.assertEqual([
         b"The authenticity of host 'fake.example.com (9.8.7.6)' "
         b"can't be established.\n"
         b"RSA key fingerprint is "
         b"SHA256:vD0YydsNIUYJa7yLZl3tIL8h0vZvQ8G+HPG7JLmQV0s=.\n"
         b"Are you sure you want to continue connecting (yes/no)? "
     ], self.fakeFile.outchunks)
     return self.assertFailure(d, UserRejectedKey)
Esempio n. 13
0
 def test_verifyQuestion(self):
     """
     L{default.verifyHostKey} should return a L{Default} which fires with
     C{0} when passed an unknown host that the user refuses to acknowledge.
     """
     self.fakeTransport.factory.options['host'] = b'fake.example.com'
     self.fakeFile.inlines.append(b"no")
     d = default.verifyHostKey(
         self.fakeTransport, b"9.8.7.6", otherSampleKey,
         b"No fingerprint!")
     self.assertEqual(
         [b"The authenticity of host 'fake.example.com (9.8.7.6)' "
          b"can't be established.\n"
          b"RSA key fingerprint is "
          b"SHA256:vD0YydsNIUYJa7yLZl3tIL8h0vZvQ8G+HPG7JLmQV0s=.\n"
          b"Are you sure you want to continue connecting (yes/no)? "],
          self.fakeFile.outchunks)
     return self.assertFailure(d, UserRejectedKey)