
I Wear Pants
Now with Stuff and Things!
A blog by Peter Fein.
Follow @wearpants
The views expressed here do not represent my past, present or future employers, collectives, family, nation-state or houseplants. They are mine alone. Who's else would they be?
Introducing Petapass
March 27, 2011 at 12:41 PM | Tags: password, python, gui, pygtk, release, security, petapassThis post was import from an earlier version of this blog. Original here.
A few weeks ago, I wrote about a scheme for better passwords. Building on that idea, I'm pleased to announce Petapass, a stateless password generator. The name is a play on my first name as well as the very large number of passwords you can create.
The traditional approach to password management is to store passwords in an encrypted file (various password managers use this approach). Petapass instead implements a stateless password management scheme - all the necessary state resides in your head. It hashes a master password and a per-login descriptive token to generate unique 10-character passwords. The token is merely something you will remember when you need to log in (such as "myblog"). Portable across OSes, nothing to steal, lose or synchronize. I like to think of it as RESTful password management.
Petapass implements a simple GUI. It provides a "daemon mode", where it will remember your master password for a configurable timeout. After entering the token, the generated password is copied to the clipboard, allowing you to easily paste it to a login form or ssh prompt. Binding the command to show the window to a global hotkey makes Petapass unobtrusive and easy to use.Full details at PYPI. Linux only for now - a windows version should be trivial, while OS X requires a Cocoa GUI.
Note: I couldn't get the window to always raise to the foreground the way I wanted - if you've got PyGTK skills and a few minutes, please ping me.
Better Passwords in Under 200 Characters
February 08, 2011 at 11:15 AM | Tags: python, oneliner, security, password, hashThis post was import from an earlier version of this blog. Original here.
Good password security is a pain in the neck. Done properly, it requires a different password for every site. Good passwords are basically impossible to remember - simply subsituting a few numbers or symbols l337-speak style isn't enough (in other words, tw1tt3r will fool no one). The traditional approach is to use a well-guarded text file (hard to secure) or password manager, such as OS X's Keychain, Gnome's Keyring or Firefox's Master Password (hard to synchronize across machines/platforms).
The solution? Hashed passwords. Remember a single master password, hash it with a per-site identifier and... that's it. The idea's not new, and there are several browser based implementations (including one I can't find right now but had you type (but not submit) your master password into login forms to be replaced by Javascript - which should send you running). Most use MD5 or SHA-1 (both with known weakness). I just can't feel great about doing this in my browser using some random dude's JS implementation of crypto, so I whipped up this one liner:
python -c "import hashlib,getpass,hmac,os;os.popen('xclip -selection c','w').write(hmac.new(getpass.getpass('Password: '),raw_input('Token: '),hashlib.sha256).digest().encode('base64')[:10])"
192 characters, including overly verbose prompts. It takes a master password and a token - a mnemonic you'll associate with the site where you use the generated password. Runs a SHA-256 HMAC, base-64 encodes it and sticks the first ten characters in your clipboard. Done. As the saying goes, "Don't invent your own crypto", so I'd love feedback on whether this contains any errors.
There's definitely room for featurification here: the app could store the master password in memory, allowing you to enter multiple tokens. A prettier GUI and cross-platform support would be nice too. There's also no way to guarrantee that the generated password contains a letter or symbol (some sites require this). But good enough for now.
After writing this, I found a commandline version using openssl/bash. Shrug.
OS X version:
python -c "import hashlib,getpass,hmac,os;os.popen('pbcopy','w').write(hmac.new(getpass.getpass('Password: '),raw_input('Token: '),hashlib.sha256).digest().encode('base64')[:10])"
These comments were imported from an earlier version of this blog.
For this use case, the collision weaknesses in MD5 aren't really a factor. See Brett Cannon's explanation at http://code.google.com/p/oplop/wiki/HowItWorks.
The problem I have with this is that I don't want to have to remember all those tokens. I used to use a similar scheme and always used a site's domain name as the token, which has obvious problems if the master password is compromised.
Currently, I use KeePassX, since it's cross platform (Linux, Mac, and Windows) and can generate passwords according to different rules (length, certain character sets, etc).
I haven't worked out the sync issue yet. I've been thinking that I could put the key database in version control, but I'm not sure how secure that would be if someone should happen to get a hold of the database. Given that you can set a master password *and* require a key file to unlock the database, maybe it would be OK.
What about LastPass? They securely encrypt the passwordfile and store it for you. You can even have a walkthrough to see how that works. Also has cross-browser support.
supergenpass does the same thing for the web, minus the need for a bash terminal (it's just a bookmarklet) http://supergenpass.com/
Otherwise, LastPass and KeePass are simpler solutions.
I use 1Password and love it. Until someone comes out with a better universal solution for this stuff (bank-issued cellphone/hardware token + PIN/pass + ubiquitous three-legged online auth), I'm in the "one basket and guard the basket" approach. A nice feature of 1Password is that it also lets me store CC numbers and other useful information that I want to have in electronic format on my computer. It also has support for folders and tags, so I can separate my work-related logins from personal sites and services.
I use the SuperGenPass. I like the ability to run it from any computer with a browser (including on a phone) and they also have something similar to your implementation for Android, for example.
One thing you could improve would be to take the token from the clipboard, so the workflow could become: select the domain name of the web site, hit a hotkey bound to this script, a xmessage or ssh-ask-pass clone pops up to ask for the master password and the result is put back into the clipboard.
(SuperGenPass goes even further - you can just enter your master password into the web form, hit a hotkey or click a bookmarklet and the master password will be replaced with the site-specific password instantly)
These comments were imported from an earlier version of this blog.
Jeff Barea 2011/03/27 19:56:41 -0700
I like the concept. One thing I've noticed is by introducing third party programs it makes it less secure than would seem.
Mostly talking about the clipboard copying. A whole host of other security issues, but some of them are simply out of anyone's control really.
ncoghlan_dev 2011/03/27 20:23:36 -0700
I believe Brett Cannon did something along these lines with OpLop (only web based). I've never quite seen the point of stateless generators: yes, it provides substantially improved resistance to dictionary attacks against the sites themselves, but it doesn't help much with remembering your tokens for rarely used sites.
And if you decide to save the tokens somewhere... you're back to needing an encrypted password store. And once you're using one of those *anyway* why not just generate the passwords directly and not bother with the tokens?
None 2011/03/28 08:49:41 -0700
Peter Fein said...
@ncoghlan: yeah, it's similar to OpLop (which does have Python implementation btw). Doing this in a browser at all feels risky, and doing it on a third party webpage is *insane* - you're implicitly trusting all of the code loaded by Oplop every time you use it. While I might trust Brett, I'm relying on his & google's security.
As for remembering tokens, that doesn't seem to be a problem in practice - the tokens themselves don't need to be hard to guess - the domain name (perhaps without TLD) is fine: http://updates.oplop.mobi/2010/12/tips-and-tricks-for-using-oplop.html
@Jeff Barea: The clipboard aspect could be improved (by being eliminated entirely). It's particularly a problem when you're using a clipboard history manager, like parcellite. Perhaps I can add another command to "paste" directly to the current X11 window. See this bug: http://hg.wearpants.org/petapass/issue/7/avoid-use-of-clipboard-entirely
Eric 2011/03/28 13:21:09 -0700
I keep wishing that something like this would work for me, but the passwords I'm required to create are full of incompatible restrictions. Some sites are restricted to ten characters, others require at least twelve. Some sites prohibit special characters, others require them. I use an encrypted password store partly to avoid manipulating the result of such a stateless system to fit the need.