Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions sudssigner/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,24 @@ def __init__(self, keyfile, keytype=None, pwd=None, pwdCallback=None,
def load_keyfile(self):
cert = file(self.keyfile, 'rb').read()
self.cert = crypto.load_certificate(crypto.FILETYPE_PEM, cert)
self.privatekey = crypto.load_privatekey(crypto.FILETYPE_PEM, cert)

def handle_keytype(self, keytype):
if keytype is None:
return self.detect_keytype()
elif keytype == "DSA":
return DSA
elif keytype == "RSA":
return RSA
elif any(isinstance(keytype, t) for t in (str, unicode)):
return keytype
else:
raise ValueError('keytype must be a string or None')

def detect_keytype(self):
algo = self.privatekey.type()
cert = file(self.keyfile, 'rb').read()
pwd = (self.pwd or self.pwdCallback)
privatekey = crypto.load_privatekey(crypto.FILETYPE_PEM, cert, pwd)
algo = privatekey.type()
if algo == crypto.TYPE_DSA:
return DSA
if algo == crypto.TYPE_RSA:
Expand Down