Giter Club home page Giter Club logo

pypwsafe's Introduction

Introduction

A pure-Python library that can read and write Password Safe v3 files. It includes full support for almost all current Password Safe v3 database headers and record headers.

History

The library was initially written by Paulson McIntyre for Symantec in 2009. It was later released by Symantec under the GPLv2 in 2011. Changes and updates have been made since by Paulson McIntyre (GpMidi), Evan Deaubl (evandeaubl), and Sean Perry (shaleh). Rony Shapiro maintains the project page and acts as gate keeper for new patches.

Known Issues

  1. Lack of documentation
  2. Unit tests are out-of-date
  3. There MAY be an issue with the order that NonDefaultPrefsHeader serializes preferences for HMAC validation in pypwsafe. Although the library validates HMACs fine at the moment, so who knows.
  4. The version of python-mcrypt for Windows isn't compatible with this library. As a result, the pypwsafe library doesn't work in Windows. If anyone is able to get around this, please notify us. The library has not been tried under Cygwin.

Dependencies

  1. python-mcrypt
  2. hashlib OR pycrypto

Install Instructions

RHEL/CentOS

  1. Install libmcrypt and it's dev package along with the Python dev package[1]: yum install libmcrypt-devel libmcrypt python-devel These packages are needed by the installer for python-mcrypt
  2. Install the standard Linux development tools. For RHEL/CentOS 5 and 6, yum groupinstall 'Development tools' can be used if your YUM repos have group information.
  3. Use Pip or easy install to install python-mcrypt, hashlib, and pycrypto
  4. Run the setup script python setup.py install
  5. Test that the module loads python -c "import pypwsafe"

Note 1: This package requires Python 2.6, so on EL5 systems python26 and python26-devel are required.

Windows

Windows is not currently supported due to issues with python-mcrypt. A pure-Python Twofish implementation will allow future support, if a bit slower than a C-based implementation.

Development Setup Instructions

FIXME: Fill this in

FAQ

Why mcrypt and not use PyCrypto?

The pyCrypto library doesn't support TwoFish, which is a newer cipher based on Blowfish. Twofish is required to encrypt/decrypt Password Safe v3 files.

Where can I find details on the Password Safe file format?

The format spec is kept in the Password Safe project's SVN repo. Go to the password safe code base and check in /pwsafe/pwsafe/docs/formatV3.txt. As of today, it can be found here

TODO

  1. Add support for using a pure-python TwoFish algorithm if mcrypt doesn't work. http://code.google.com/p/python-keysafe/source/browse/crypto/twofish.py http://www.bjrn.se/code/twofishpy.txt
  2. Need to update against the latest version of the official psafe format v3 doc.
  3. Change IV on every save.
  4. Make locking 'with' compatible.

pypwsafe's People

Contributors

gpmidi avatar evandeaubl avatar nhjm449 avatar pmcintyresfdc avatar

Stargazers

Sean Perry avatar  avatar Lionel D. Hummel avatar

Watchers

 avatar  avatar

Forkers

kellen random832

pypwsafe's Issues

PWSafe3.close() throws an exception when the password file was not existing before

If the psafe file does not exist and the file is newly created the close() method does not work as expected:
>>> s = new_safe("/Pwsafe_Venv/safetests/test.psafe3", "abcdefgh")
>>> s.save()
>>> s.close()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Pwsafe_Venv/local/lib/python2.7/site-packages/pypwsafe/__init__.py", line 478, in close
    self.fl.close()
AttributeError: 'NoneType' object has no attribute 'close

If the file already exists close() works fine:
>>> s = new_safe("/Pwsafe_Venv/safetests/test.psafe3", "abcdefgh")
>>> s.save()
>>> s.close()

The problem might be that self.fl attribute does not exist if the PWSafe3 object is initialized on the fly and not read from the filesystem.
Maybe this method isn't even needed as self.fl is closed in __init__ anyway and never used again or the code from __del__ could be copied to this function to avoid the exception.

Not recognized / duplicate version headers

So open a Python shell and create a new database (file does not exists so far).
Version header looks pretty normal after creation.
==========================================================================
(Pwsafe_Venv)$ python
Python 2.7.3 (default, Aug  1 2012, 05:14:39) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from psafe_actions import *
No handlers could be found for logger "psafe.lib.record"
>>> s = new_safe("/home/test/psafe/test01.psafe3", "abcdefgh")
>>> pp(s.headers)
[VersionHeader(0,2,'\x00\x00'),
 LastSaveUserHeader(7,6,'test'),
 LastSaveHostHeader(8,7,'testmachine'),
 LastSaveHeader(4,4,'\xf0\x9c\x11Q'),
 LastSaveAppHeader(6,8,'pypwsafe'),
 UUIDHeader(1,16,'\xec\x01\xbc\xfb\x82{E\xed\xa3\xfbH~\x90\x004\xc2'),
 EOFHeader(255,0,'')]
==========================================================================

Now if we close the Python shell, open a new one and reopen the database the version header is not recognized as version header any more.
So this means that calling setVersion adds a new header...
Okay call it and save the file and close the shell.
==========================================================================
(Pwsafe_Venv)$ python
Python 2.7.3 (default, Aug  1 2012, 05:14:39) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from psafe_actions import *
No handlers could be found for logger "psafe.lib.record"
>>> s = get_safe("/home/test/psafe/test01.psafe3", "abcdefgh")
>>> pp(s.headers)
[Header(0,2,'\x00\x00'),
 LastSaveUserHeader(7,6,'test'),
 LastSaveHostHeader(8,7,'testmachine'),
 LastSaveHeader(4,4,'\xf0\x9c\x11Q'),
 LastSaveAppHeader(6,8,'pypwsafe'),
 UUIDHeader(1,16,'\xec\x01\xbc\xfb\x82{E\xed\xa3\xfbH~\x90\x004\xc2'),
 EOFHeader(255,0,'')]
>>> s.setVersion(0x0300)
>>> s.save()
==========================================================================

After opening the shell again now we have two unrecognized version headers.
Okay set the version header and save.
==========================================================================
(Pwsafe_Venv)$ python
Python 2.7.3 (default, Aug  1 2012, 05:14:39) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from psafe_actions import *
No handlers could be found for logger "psafe.lib.record"
>>> s = get_safe("/home/test/psafe/test01.psafe3", "abcdefgh")
>>> s.setVersion(0x0300)
>>> pp(s.headers)
[VersionHeader(0,2,'\x00\x03'),
 Header(0,2,'\x00\x03'),
 Header(0,2,'\x00\x00'),
 LastSaveUserHeader(7,6,'test'),
 LastSaveHostHeader(8,7,'testmachine'),
 LastSaveHeader(4,4,'\x9a\x9d\x11Q'),
 LastSaveAppHeader(6,8,'pypwsafe'),
 UUIDHeader(1,16,'\xeeW\x18\xe0\x87\xf9I}\x88\x855\x88\r\xec`h'),
 EOFHeader(255,0,'')]
>>> s.save()
==========================================================================

Now if we reopen the file there are three unrecognized version headers.
==========================================================================
(Pwsafe_Venv)$ python
Python 2.7.3 (default, Aug  1 2012, 05:14:39) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from psafe_actions import *
No handlers could be found for logger "psafe.lib.record"
>>> s = get_safe("/home/test/psafe/test01.psafe3", "abcdefgh")
>>> pp(s.headers)
[Header(0,2,'\x00\x03'),
 Header(0,2,'\x00\x03'),
 Header(0,2,'\x00\x00'),
 LastSaveUserHeader(7,6,'test'),
 LastSaveHostHeader(8,7,'testmachine'),
 LastSaveHeader(4,4,'\x9a\x9d\x11Q'),
 LastSaveAppHeader(6,8,'pypwsafe'),
 UUIDHeader(1,16,'\xeeW\x18\xe0\x87\xf9I}\x88\x855\x88\r\xec`h'),
 EOFHeader(255,0,'')]
==========================================================================

If you look at the type of Header(0,2,'\x00\x03') it is 0 so it is definitely the version header:
Version                     0x00        2 bytes       Y              [1]

Validate All DB Headers Against Latest formatV3.txt

Go through all of the DB headers in the official v3 format doc and validate that they are fully supported. Also check the change history for the past year for the v3 format doc and validate that all changes are accounted for.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.