diff options
author | Jeff Forcier <jeff@bitprophet.org> | 2014-03-05 17:03:37 -0800 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2014-03-05 17:03:37 -0800 |
commit | b2be63ec623b5944f9b84cac8b8f41aeb2b42fb7 (patch) | |
tree | 389e17b0c08cd34872a2e3afbc34860ab44fb3ed /paramiko/rsakey.py | |
parent | bd61c7c0a9a4a2020d0acfb6a01e9ec85bb43b8e (diff) | |
parent | ae078f51d622931954e47e78029a889c4e721a05 (diff) | |
download | paramiko-b2be63ec623b5944f9b84cac8b8f41aeb2b42fb7.tar.gz |
Merge remote-tracking branch 'scottkmaxwell/py3-support-without-py25' into python3
Conflicts:
dev-requirements.txt
paramiko/__init__.py
paramiko/file.py
paramiko/hostkeys.py
paramiko/message.py
paramiko/proxy.py
paramiko/server.py
paramiko/transport.py
paramiko/util.py
paramiko/win_pageant.py
setup.py
Diffstat (limited to 'paramiko/rsakey.py')
-rw-r--r-- | paramiko/rsakey.py | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/paramiko/rsakey.py b/paramiko/rsakey.py index 8c2aae91..06f0085d 100644 --- a/paramiko/rsakey.py +++ b/paramiko/rsakey.py @@ -31,6 +31,8 @@ from paramiko.ber import BER, BERException from paramiko.pkey import PKey from paramiko.ssh_exception import SSHException +SHA1_DIGESTINFO = b'\x30\x21\x30\x09\x06\x05\x2b\x0e\x03\x02\x1a\x05\x00\x04\x14' + class RSAKey (PKey): """ @@ -57,18 +59,21 @@ class RSAKey (PKey): else: if msg is None: raise SSHException('Key object may not be empty') - if msg.get_string() != 'ssh-rsa': + if msg.get_text() != 'ssh-rsa': raise SSHException('Invalid key') self.e = msg.get_mpint() self.n = msg.get_mpint() self.size = util.bit_length(self.n) - def __str__(self): + def asbytes(self): m = Message() m.add_string('ssh-rsa') m.add_mpint(self.e) m.add_mpint(self.n) - return str(m) + return m.asbytes() + + def __str__(self): + return self.asbytes() def __hash__(self): h = hash(self.get_name()) @@ -88,16 +93,16 @@ class RSAKey (PKey): def sign_ssh_data(self, rpool, data): digest = SHA.new(data).digest() rsa = RSA.construct((long(self.n), long(self.e), long(self.d))) - sig = util.deflate_long(rsa.sign(self._pkcs1imify(digest), '')[0], 0) + sig = util.deflate_long(rsa.sign(self._pkcs1imify(digest), bytes())[0], 0) m = Message() m.add_string('ssh-rsa') m.add_string(sig) return m def verify_ssh_sig(self, data, msg): - if msg.get_string() != 'ssh-rsa': + if msg.get_text() != 'ssh-rsa': return False - sig = util.inflate_long(msg.get_string(), True) + sig = util.inflate_long(msg.get_binary(), True) # verify the signature by SHA'ing the data and encrypting it using the # public key. some wackiness ensues where we "pkcs1imify" the 20-byte # hash into a string as long as the RSA key. @@ -116,7 +121,7 @@ class RSAKey (PKey): b.encode(keylist) except BERException: raise SSHException('Unable to create ber encoding of key') - return str(b) + return b.asbytes() def write_private_key_file(self, filename, password=None): self._write_private_key_file('RSA', filename, self._encode_key(), password) @@ -152,10 +157,9 @@ class RSAKey (PKey): turn a 20-byte SHA1 hash into a blob of data as large as the key's N, using PKCS1's \"emsa-pkcs1-v1_5\" encoding. totally bizarre. """ - SHA1_DIGESTINFO = '\x30\x21\x30\x09\x06\x05\x2b\x0e\x03\x02\x1a\x05\x00\x04\x14' size = len(util.deflate_long(self.n, 0)) - filler = '\xff' * (size - len(SHA1_DIGESTINFO) - len(data) - 3) - return '\x00\x01' + filler + '\x00' + SHA1_DIGESTINFO + data + filler = max_byte * (size - len(SHA1_DIGESTINFO) - len(data) - 3) + return zero_byte + one_byte + filler + zero_byte + SHA1_DIGESTINFO + data def _from_private_key_file(self, filename, password): data = self._read_private_key_file('RSA', filename, password) |