From 83964f59272e7850667d33419e8edd3315fc203d Mon Sep 17 00:00:00 2001 From: Marcin Wielgoszewski Date: Mon, 14 Oct 2013 14:33:35 -0400 Subject: [PATCH] Pass passphrase callback argument to importKey() method `Crypto.PublicKey.RSA.importKey` accepts an optional `passphrase` argument to provide a password to decrypt the encrypted key. --- decrypt-windows-ec2-passwd.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/decrypt-windows-ec2-passwd.py b/decrypt-windows-ec2-passwd.py index 6c7f714..8588fc4 100644 --- a/decrypt-windows-ec2-passwd.py +++ b/decrypt-windows-ec2-passwd.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -import base64, binascii, optparse, sys +import base64, binascii, getpass, optparse, sys from Crypto.PublicKey import RSA @@ -75,10 +75,10 @@ def decryptPassword(rsaKey, password): keyLines = keyFile.readlines() #Import it try: - key = RSA.importKey(keyLines) - except: + key = RSA.importKey(keyLines, passphrase=getpass.getpass('Encrypted Key Password (leave blank if none): ')) + except ValueError: print "Could not import SSH Key (Is it an RSA key? Is it password protected?)" sys.exit(-1) #Decrypt it print "" - print "Password:", decryptPassword(key, options.password) \ No newline at end of file + print "Password:", decryptPassword(key, options.password)