ronys / pypwsafe

A pure-Python library that can read and write Password Safe v3 files, originally by Paulson McIntyre
http://pwsafe.org
Other
66 stars 23 forks source link

Better Handling Of Unicode Strings In PWSafe Setters #8

Closed gpmidi closed 11 years ago

gpmidi commented 11 years ago

Currently the various database-level setters off of PWSafe3 will sliently accept string inputs that are Unicode. Later parts of PyPWSafe will error out when they try to seralize these strings.

For example: [2013-02-04 00:47:23,812: DEBUG/MainProcess] Adding hmac data u'some random unicode string' from 'DBNameHeader' ... [2013-02-04 00:47:23,814: DEBUG/MainProcess] Adding hmac data 'Y\xf0-5&\xaaA\x9c\x91m\xfc\x10l\xba\x88\x0f' from 'UUIDHeader' [2013-02-04 00:47:23,835: ERROR/MainProcess] Task psafefe.psafe.tasks.write.newSafe[3479fca0-4728-4b4a-a63e-d3b6c88342c6] raised exception: UnicodeDecodeError('ascii', 'Y\xf0-5&\xaaA\x9c\x91m\xfc\x10l\xba\x88\x0f', 1, 2, 'ordinal not in range(128)') Traceback (most recent call last): ... File ".../pypwsafe-web/src/psafefe/psafe/tasks/write.py", line 72, in newSafe pypwsafe.save() File ".../pypwsafe/src/pypwsafe/__init__.py", line 258, in save self.serialiaze() File ".../pypwsafe/src/pypwsafe/__init__.py", line 277, in serialiaze self.hmac = self.current_hmac() File ".../pypwsafe/src/pypwsafe/__init__.py", line 453, in current_hmac data += i.hmac_data() UnicodeDecodeError: 'ascii' codec can't decode byte 0xf0 in position 1: ordinal not in range(128)

gpmidi commented 11 years ago

I'm working on fixing this.

ronys commented 11 years ago

Fine. Formally, PasswordSafe supports UTF-8 Unicode encoding.

gpmidi commented 11 years ago

The problem is really that PyPWSafe uses regular strings for handling the binary data. Normally this works fine, but when a mix of Unicode strings and regular strings are used to set fields, then internally PyPWSafe starts using Unicode strings for some of the binary data. The best solution to this will be pretty simple - I'll convert all of the internal handling to Unicode. Although I need to double check that I'm going about this the right way (at least as far as text vs binary string handling is concerned in Python).

gpmidi commented 11 years ago

I think I have this fixed for records and DB headers as of fd3ea670fd77c1a9a1c746615b0d7f0d15fbfdb0.