X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=keyconvert%2Fkeyconvert.py;h=143a8c86e17e327892c01c2b3b9a30ffd19d0b1f;hb=04a3f20dc71bf8b3f96b1e3172623aa346a638a7;hp=af12b1f41a444293ee0f0014bd5841d415725e2e;hpb=9fadbf450732b94a723471b80bfa6e10a710b85c;p=sfa.git diff --git a/keyconvert/keyconvert.py b/keyconvert/keyconvert.py index af12b1f4..143a8c86 100755 --- a/keyconvert/keyconvert.py +++ b/keyconvert/keyconvert.py @@ -4,7 +4,22 @@ import sys import base64 import struct import binascii -from M2Crypto import RSA, DSA +from M2Crypto import RSA, DSA, m2 + + +###### Workaround for bug in m2crypto-0.18 (on Fedora 8) +class RSA_pub_fix(RSA.RSA_pub): + def save_key_bio(self, bio, *args, **kw): + return self.save_pub_key_bio(bio) + +def rsa_new_pub_key(couple): + (e, n)=couple + rsa = m2.rsa_new() + m2.rsa_set_e(rsa, e) + m2.rsa_set_n(rsa, n) + return RSA_pub_fix(rsa, 1) +###### +#rsa_new_pub_key = RSA.new_pub_key def decode_key(fname): @@ -78,7 +93,7 @@ def convert(fin, fout): if key_type == "ssh-rsa": e, n = ret[1:] - rsa = RSA.new_pub_key((e, n)) + rsa = rsa_new_pub_key((e, n)) rsa.save_pem(fout) elif key_type == "ssh-dss": @@ -88,7 +103,7 @@ def convert(fin, fout): dsa.save_pub_key(fout) # FIXME: This is wrong. # M2Crypto doesn't allow us to set the public key parameter - raise(Exception, "DSA keys are not supported yet: M2Crypto doesn't allow us to set the public key parameter") + raise Exception("DSA keys are not supported yet: M2Crypto doesn't allow us to set the public key parameter") if __name__ == "__main__":