Friday, March 05, 2010

March Madness Challenge - Day 5

For tonight's March madness I will be demonstrating a variation on the theme of storing your private key locally. This program will up the ante and store your username and password as a QRCode. This way only a few machines can compromise your accounts when you take a picture of your username/password for decryption. Inspired by the following super high security tech technology: SafeBerg Technology

A bit of preparation is required. I'm using the python library huBarcode. You will need to run some flavor of "git clone git://github.com/hudora/huBarcode.git" followed by python setup.py install. Last option: sudo easy_install huBarcode

This code would have worked brilliantly if not for this error:
IOError: [Errno 2] No such file or directory: '/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/huBarcode-0.56p5-py2.4.egg/qrcode/qrcode_data/qrv1_0.dat'

And here is the code:



#
# Turn a username/password into a QRCode
#
#
import getopt
import sys
import getpass
import qrcode

#Describe usage
def usage():
print "-h, --help\n -v, --verbose\n -u, --username\n -p, --password\n -f, --filename\n"

def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "h:u:pvf:", ["help", "username=", "password", "filename"])
except getopt.GetoptError, err:
#print help information and exit:
print str(err) # will print something like "option -a not recognized"
usage()
sys.exit(2)
username = None
password = None
verbose = False
filename = "default.png"

for o, a in opts:
if o == "-v":
verbose = True
elif o in ("-h", "--help"):
usage()
sys.exit()
elif o in ("-u", "--username"):
username = a
if verbose:
print "username: " + username
elif o in ("-p", "--password"):
password = getpass.getpass("Enter password: ")
if verbose:
print "password: " + password
elif o in ("-f", "--filename"):
filename = a;
if verbose:
print "filename: " + filename
else:
assert False, "unhandled option"
if username is None:
print "-u, --username was not given"
usage()
sys.exit(2)
if password is None:
print "-p, --password was not given"
usage()
sys.exit(2)


encoder = qrcode.QRCodeEncoder( username + "\n" + password)
print encoder.get_ascii()
encoder.save(filename, 3)

if __name__ == "__main__":
main()

No comments: