From ff3f974b0236684659e35fdee65a168a2859e912 Mon Sep 17 00:00:00 2001 From: Allu2 Date: Wed, 17 Aug 2016 10:33:47 +0300 Subject: [PATCH 1/2] Allow importing password protected pem files CryptoDome supports password protected pem files, simply adding and passing keyword argument passphrase fixes this. --- src/jwkest/jwk.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/jwkest/jwk.py b/src/jwkest/jwk.py index 222f1ee..e89ef2f 100644 --- a/src/jwkest/jwk.py +++ b/src/jwkest/jwk.py @@ -87,18 +87,18 @@ def sha512_digest(msg): # ============================================================================= -def import_rsa_key_from_file(filename): - return RSA.importKey(open(filename, 'r').read()) +def import_rsa_key_from_file(filename, passphrase=None): + return RSA.importKey(open(filename, 'r').read(), passphrase=passphrase) -def import_rsa_key(key): +def import_rsa_key(key, passphrase=None): """ Extract an RSA key from a PEM-encoded certificate :param key: RSA key encoded in standard form :return: RSA key instance """ - return importKey(key) + return importKey(key, passphrase=passphrase) def der2rsa(der): From 77ad5968c0feb6daf5dec0a6083e8e49e95353e2 Mon Sep 17 00:00:00 2001 From: Allu2 Date: Wed, 17 Aug 2016 11:14:19 +0300 Subject: [PATCH 2/2] Upatated documentation to match code Updated documentation to match code after adding the password parameter --- src/jwkest/jwk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jwkest/jwk.py b/src/jwkest/jwk.py index e89ef2f..6c79b2a 100644 --- a/src/jwkest/jwk.py +++ b/src/jwkest/jwk.py @@ -94,8 +94,8 @@ def import_rsa_key_from_file(filename, passphrase=None): def import_rsa_key(key, passphrase=None): """ Extract an RSA key from a PEM-encoded certificate - :param key: RSA key encoded in standard form + :param passphrase: Password to open the certificate (Optional) :return: RSA key instance """ return importKey(key, passphrase=passphrase)