mbasanta / passlib

Automatically exported from code.google.com/p/passlib
Other
0 stars 0 forks source link

parse_mc3 fails to parse hashes generated by passlib #47

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
from passlib.hash import sha512_crypt
from passlib.utils.handlers import parse_mc3
hash = sha512_crypt.encrypt("password")
print parse_mc3(hash, unicode("$6$"))

What is the expected output?
Tuple with (rounds, salt, checksum)

What do you see instead?
ValueError: invalid literal for int() with base 10: 'rounds=60000'

What version of the product are you using? On what operating system?
Ubuntu 12.10
Python 2.7.3
passlib 1.6.1

Please provide any additional information below.
See 
https://code.google.com/p/passlib/source/browse/passlib/utils/handlers.py#177
The code assumes that the rounds is an integer while passlib generates 
something like "rounds=60000".
I believe it should parse the value from that string.

Original issue reported on code.google.com by alexaho...@gmail.com on 17 Apr 2013 at 1:53

GoogleCodeExporter commented 9 years ago
short answer: it's a feature, not a bug :) 

long answer: 

parse_mc2() and parse_mc3() aren't supposed to be general-purpose hash parsers, 
just internal helper functions to be used when constructing handler classes 
whose hash format happens to use one of two specific grammars.

A handful of hashes (such as bcrypt and sha512_crypt) add their own deviations 
to the grammar handled by parse_mc3(), and I decided it wasn't worth the 
processing time or code complexity to pile all the special cases into 
parse_mc3() -- that it would be better to have it do one thing, and implement a 
separate parser for the hashes that needed it.

That said, your report made me realize I can probably modify parse_mc3() to 
handle sha512_crypt after a fashion, and I'm always looking to remove redundant 
code. So while the behaviour reported is as intended, it probably will inspire 
a change in the next release :)

Original comment by elic@astllc.org on 27 Apr 2013 at 11:14

GoogleCodeExporter commented 9 years ago

Original comment by elic@astllc.org on 7 May 2013 at 4:52