From ab25c6fe95ee92fac3187dcd90e0560ccacb084a Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Mon, 28 May 2012 13:19:22 +0200 Subject: Return a byte string if format is set to OpenSSH. RSA.exportKey claims to return a byte string, so really return one. --- lib/Crypto/PublicKey/RSA.py | 6 +++--- lib/Crypto/SelfTest/PublicKey/test_importKey.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/Crypto') diff --git a/lib/Crypto/PublicKey/RSA.py b/lib/Crypto/PublicKey/RSA.py index 99d851d..ec04625 100644 --- a/lib/Crypto/PublicKey/RSA.py +++ b/lib/Crypto/PublicKey/RSA.py @@ -348,9 +348,9 @@ class _RSAobj(pubkey.pubkey): nb = long_to_bytes(self.n) if bord(eb[0]) & 0x80: eb=bchr(0x00)+eb if bord(nb[0]) & 0x80: nb=bchr(0x00)+nb - keyparts = [ 'ssh-rsa', eb, nb ] - keystring = ''.join([ struct.pack(">I",len(kp))+kp for kp in keyparts]) - return 'ssh-rsa '+binascii.b2a_base64(keystring)[:-1] + keyparts = [ b('ssh-rsa'), eb, nb ] + keystring = b('').join([ struct.pack(">I",len(kp))+kp for kp in keyparts]) + return b('ssh-rsa ')+binascii.b2a_base64(keystring)[:-1] # DER format is always used, even in case of PEM, which simply # encodes it into BASE64. diff --git a/lib/Crypto/SelfTest/PublicKey/test_importKey.py b/lib/Crypto/SelfTest/PublicKey/test_importKey.py index f7c1edc..0e41577 100644 --- a/lib/Crypto/SelfTest/PublicKey/test_importKey.py +++ b/lib/Crypto/SelfTest/PublicKey/test_importKey.py @@ -104,7 +104,7 @@ Lr7UkvEtFrRhDDKMtuIIq19FrL4pUIMymPMSLBn3hJLe30Dw48GQM4UCAwEAAQ== -----END PUBLIC KEY-----''' # Obtained using 'ssh-keygen -i -m PKCS8 -f rsaPublicKeyPEM' - rsaPublicKeyOpenSSH = '''ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAQQC/HieQCqCLI1EaXBKBrm2TMSw+/pE/ky6+1JLxLRa0YQwyjLbiCKtfRay+KVCDMpjzEiwZ94SS3t9A8OPBkDOF comment\n''' + rsaPublicKeyOpenSSH = b('''ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAQQC/HieQCqCLI1EaXBKBrm2TMSw+/pE/ky6+1JLxLRa0YQwyjLbiCKtfRay+KVCDMpjzEiwZ94SS3t9A8OPBkDOF comment\n''') # The private key, in PKCS#1 format encoded with DER rsaKeyDER = a2b_hex( -- cgit v1.2.1