Here are the examples of the python api twisted.conch.ssh.keys.Key.fromString.blob taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
19 Examples
3
Example 1
def test_requestIdentities(self):
"""
Assert that we get all of the keys/comments that we add when we issue a
request for all identities.
"""
d = self.client.requestIdentities()
self.pump.flush()
def _check(keyt):
expected = {}
expected[self.dsaPublic.blob()] = 'a comment'
expected[self.rsaPublic.blob()] = 'another comment'
received = {}
for k in keyt:
received[keys.Key.fromString(k[0], type='blob').blob()] = k[1]
self.assertEquals(expected, received)
return d.addCallback(_check)
3
Example 2
Project: mythbox Source File: test_userauth.py
def requestAvatarId(self, creds):
if creds.blob == keys.Key.fromString(keydata.publicRSA_openssh).blob():
if creds.signature is not None:
obj = keys.Key.fromString(creds.blob)
if obj.verify(creds.signature, creds.sigData):
return creds.username
else:
raise ValidPublicKey()
raise UnauthorizedLogin()
3
Example 3
Project: mythbox Source File: test_userauth.py
def test_successfulPrivateKeyAuthentication(self):
"""
Test that private key authentication completes sucessfully,
"""
blob = keys.Key.fromString(keydata.publicRSA_openssh).blob()
obj = keys.Key.fromString(keydata.privateRSA_openssh)
packet = (NS('foo') + NS('none') + NS('publickey') + '\xff'
+ NS(obj.sshType()) + NS(blob))
self.authServer.transport.sessionID = 'test'
signature = obj.sign(NS('test') + chr(userauth.MSG_USERAUTH_REQUEST)
+ packet)
packet += NS(signature)
d = self.authServer.ssh_USERAUTH_REQUEST(packet)
def check(ignored):
self.assertEquals(self.authServer.transport.packets,
[(userauth.MSG_USERAUTH_SUCCESS, '')])
return d.addCallback(check)
3
Example 4
Project: mythbox Source File: test_userauth.py
def test_verifyValidPrivateKey(self):
"""
Test that verifying a valid private key works.
"""
blob = keys.Key.fromString(keydata.publicRSA_openssh).blob()
packet = (NS('foo') + NS('none') + NS('publickey') + '\x00'
+ NS('ssh-rsa') + NS(blob))
d = self.authServer.ssh_USERAUTH_REQUEST(packet)
def check(ignored):
self.assertEquals(self.authServer.transport.packets,
[(userauth.MSG_USERAUTH_PK_OK, NS('ssh-rsa') + NS(blob))])
return d.addCallback(check)
3
Example 5
Project: mythbox Source File: test_userauth.py
def test_failedPrivateKeyAuthenticationWithoutSignature(self):
"""
Test that private key authentication fails when the public key
is invalid.
"""
blob = keys.Key.fromString(keydata.publicDSA_openssh).blob()
packet = (NS('foo') + NS('none') + NS('publickey') + '\x00'
+ NS('ssh-dsa') + NS(blob))
d = self.authServer.ssh_USERAUTH_REQUEST(packet)
return d.addCallback(self._checkFailed)
3
Example 6
Project: mythbox Source File: test_userauth.py
def test_failedPrivateKeyAuthenticationWithSignature(self):
"""
Test that private key authentication fails when the public key
is invalid.
"""
blob = keys.Key.fromString(keydata.publicRSA_openssh).blob()
obj = keys.Key.fromString(keydata.privateRSA_openssh)
packet = (NS('foo') + NS('none') + NS('publickey') + '\xff'
+ NS('ssh-rsa') + NS(blob) + NS(obj.sign(blob)))
self.authServer.transport.sessionID = 'test'
d = self.authServer.ssh_USERAUTH_REQUEST(packet)
return d.addCallback(self._checkFailed)
3
Example 7
Project: mythbox Source File: test_userauth.py
def test_old_publickey_getPublicKey(self):
"""
Old SSHUserAuthClients returned strings of public key blobs from
getPublicKey(). Test that a Deprecation warning is raised but the key is
verified correctly.
"""
oldAuth = OldClientAuth('foo', FakeTransport.Service())
oldAuth.transport = FakeTransport(None)
oldAuth.transport.sessionID = 'test'
oldAuth.serviceStarted()
oldAuth.transport.packets = []
self.assertWarns(DeprecationWarning, "Returning a string from "
"SSHUserAuthClient.getPublicKey() is deprecated since "
"Twisted 9.0. Return a keys.Key() instead.",
userauth.__file__, oldAuth.tryAuth, 'publickey')
self.assertEquals(oldAuth.transport.packets, [
(userauth.MSG_USERAUTH_REQUEST, NS('foo') + NS('nancy') +
NS('publickey') + '\x00' + NS('ssh-rsa') +
NS(keys.Key.fromString(keydata.publicRSA_openssh).blob()))])
3
Example 8
def test_requestIdentities(self):
"""
Assert that we get all of the keys/comments that we add when we issue a
request for all identities.
"""
d = self.client.requestIdentities()
self.pump.flush()
def _check(keyt):
expected = {}
expected[self.dsaPublic.blob()] = 'a comment'
expected[self.rsaPublic.blob()] = 'another comment'
received = {}
for k in keyt:
received[keys.Key.fromString(k[0], type='blob').blob()] = k[1]
self.assertEqual(expected, received)
return d.addCallback(_check)
3
Example 9
def verifyHostKey(self, key, fp):
keyMatch = key == keys.Key.fromString(publicRSA_openssh).blob()
fingerprintMatch = (
fp == '3d:13:5f:cb:c9:79:8a:93:06:27:65:bc:3d:0b:8f:af')
if keyMatch and fingerprintMatch:
return defer.succeed(1)
return defer.fail(Exception("Key or fingerprint mismatch"))
3
Example 10
Project: SubliminalCollaborator Source File: test_userauth.py
def test_successfulPrivateKeyAuthentication(self):
"""
Test that private key authentication completes sucessfully,
"""
blob = keys.Key.fromString(keydata.publicRSA_openssh).blob()
obj = keys.Key.fromString(keydata.privateRSA_openssh)
packet = (NS('foo') + NS('none') + NS('publickey') + '\xff'
+ NS(obj.sshType()) + NS(blob))
self.authServer.transport.sessionID = 'test'
signature = obj.sign(NS('test') + chr(userauth.MSG_USERAUTH_REQUEST)
+ packet)
packet += NS(signature)
d = self.authServer.ssh_USERAUTH_REQUEST(packet)
def check(ignored):
self.assertEqual(self.authServer.transport.packets,
[(userauth.MSG_USERAUTH_SUCCESS, '')])
return d.addCallback(check)
3
Example 11
Project: SubliminalCollaborator Source File: test_userauth.py
def test_verifyValidPrivateKey(self):
"""
Test that verifying a valid private key works.
"""
blob = keys.Key.fromString(keydata.publicRSA_openssh).blob()
packet = (NS('foo') + NS('none') + NS('publickey') + '\x00'
+ NS('ssh-rsa') + NS(blob))
d = self.authServer.ssh_USERAUTH_REQUEST(packet)
def check(ignored):
self.assertEqual(self.authServer.transport.packets,
[(userauth.MSG_USERAUTH_PK_OK, NS('ssh-rsa') + NS(blob))])
return d.addCallback(check)
3
Example 12
Project: SubliminalCollaborator Source File: test_userauth.py
def test_old_publickey_getPublicKey(self):
"""
Old SSHUserAuthClients returned strings of public key blobs from
getPublicKey(). Test that a Deprecation warning is raised but the key is
verified correctly.
"""
oldAuth = OldClientAuth('foo', FakeTransport.Service())
oldAuth.transport = FakeTransport(None)
oldAuth.transport.sessionID = 'test'
oldAuth.serviceStarted()
oldAuth.transport.packets = []
self.assertWarns(DeprecationWarning, "Returning a string from "
"SSHUserAuthClient.getPublicKey() is deprecated since "
"Twisted 9.0. Return a keys.Key() instead.",
userauth.__file__, oldAuth.tryAuth, 'publickey')
self.assertEqual(oldAuth.transport.packets, [
(userauth.MSG_USERAUTH_REQUEST, NS('foo') + NS('nancy') +
NS('publickey') + '\x00' + NS('ssh-rsa') +
NS(keys.Key.fromString(keydata.publicRSA_openssh).blob()))])
0
Example 13
def __init__(self, userKeys):
self.userKeys = {}
for username, keyData in userKeys.items():
self.userKeys[username] = keys.Key.fromString(data=keyData).blob()
0
Example 14
def checkKey(self, credentials):
unittest.assertEquals(credentials.username, 'testuser', 'bad username')
unittest.assertEquals(credentials.blob, keys.Key.fromString(publicDSA_openssh).blob())
return 1
0
Example 15
def verifyHostKey(self, key, fp):
unittest.assertEquals(key, keys.Key.fromString(publicRSA_openssh).blob())
unittest.assertEquals(fp,'3d:13:5f:cb:c9:79:8a:93:06:27:65:bc:3d:0b:8f:af')
return defer.succeed(1)
0
Example 16
Project: mythbox Source File: test_userauth.py
def getPublicKey(self):
return keys.Key.fromString(keydata.publicRSA_openssh).blob()
0
Example 17
Project: mythbox Source File: test_userauth.py
def test_publickey(self):
"""
Test that the client can authenticate with a public key.
"""
self.authClient.ssh_USERAUTH_FAILURE(NS('publickey') + '\x00')
self.assertEquals(self.authClient.transport.packets[-1],
(userauth.MSG_USERAUTH_REQUEST, NS('foo') + NS('nancy')
+ NS('publickey') + '\x00' + NS('ssh-dss')
+ NS(keys.Key.fromString(
keydata.publicDSA_openssh).blob())))
# that key isn't good
self.authClient.ssh_USERAUTH_FAILURE(NS('publickey') + '\x00')
blob = NS(keys.Key.fromString(keydata.publicRSA_openssh).blob())
self.assertEquals(self.authClient.transport.packets[-1],
(userauth.MSG_USERAUTH_REQUEST, (NS('foo') + NS('nancy')
+ NS('publickey') + '\x00'+ NS('ssh-rsa') + blob)))
self.authClient.ssh_USERAUTH_PK_OK(NS('ssh-rsa')
+ NS(keys.Key.fromString(keydata.publicRSA_openssh).blob()))
sigData = (NS(self.authClient.transport.sessionID)
+ chr(userauth.MSG_USERAUTH_REQUEST) + NS('foo')
+ NS('nancy') + NS('publickey') + '\xff' + NS('ssh-rsa')
+ blob)
obj = keys.Key.fromString(keydata.privateRSA_openssh)
self.assertEquals(self.authClient.transport.packets[-1],
(userauth.MSG_USERAUTH_REQUEST, NS('foo') + NS('nancy')
+ NS('publickey') + '\xff' + NS('ssh-rsa') + blob
+ NS(obj.sign(sigData))))
0
Example 18
def checkKey(self, credentials):
blob = keys.Key.fromString(publicDSA_openssh).blob()
if credentials.username == 'testuser' and credentials.blob == blob:
return True
return False
0
Example 19
Project: SubliminalCollaborator Source File: test_userauth.py
def test_publickey(self):
"""
Test that the client can authenticate with a public key.
"""
self.authClient.ssh_USERAUTH_FAILURE(NS('publickey') + '\x00')
self.assertEqual(self.authClient.transport.packets[-1],
(userauth.MSG_USERAUTH_REQUEST, NS('foo') + NS('nancy')
+ NS('publickey') + '\x00' + NS('ssh-dss')
+ NS(keys.Key.fromString(
keydata.publicDSA_openssh).blob())))
# that key isn't good
self.authClient.ssh_USERAUTH_FAILURE(NS('publickey') + '\x00')
blob = NS(keys.Key.fromString(keydata.publicRSA_openssh).blob())
self.assertEqual(self.authClient.transport.packets[-1],
(userauth.MSG_USERAUTH_REQUEST, (NS('foo') + NS('nancy')
+ NS('publickey') + '\x00'+ NS('ssh-rsa') + blob)))
self.authClient.ssh_USERAUTH_PK_OK(NS('ssh-rsa')
+ NS(keys.Key.fromString(keydata.publicRSA_openssh).blob()))
sigData = (NS(self.authClient.transport.sessionID)
+ chr(userauth.MSG_USERAUTH_REQUEST) + NS('foo')
+ NS('nancy') + NS('publickey') + '\x01' + NS('ssh-rsa')
+ blob)
obj = keys.Key.fromString(keydata.privateRSA_openssh)
self.assertEqual(self.authClient.transport.packets[-1],
(userauth.MSG_USERAUTH_REQUEST, NS('foo') + NS('nancy')
+ NS('publickey') + '\x01' + NS('ssh-rsa') + blob
+ NS(obj.sign(sigData))))