/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to mandos

  • Committer: Teddy Hogeborn
  • Date: 2013-10-20 23:27:38 UTC
  • Revision ID: teddy@recompile.se-20131020232738-5gjw6auqqxnp4v7t
* mandos (PGPEngine.password_encode): Bug fix: GnuPG can't handle
                                      really long passphrases - encode
                                      those differently.

Show diffs side-by-side

added added

removed removed

Lines of Context:
172
172
    def password_encode(self, password):
173
173
        # Passphrase can not be empty and can not contain newlines or
174
174
        # NUL bytes.  So we prefix it and hex encode it.
175
 
        return b"mandos" + binascii.hexlify(password)
 
175
        encoded = b"mandos" + binascii.hexlify(password)
 
176
        if len(encoded) > 2048:
 
177
            # GnuPG can't handle long passwords, so encode differently
 
178
            encoded = (b"mandos" + password.replace(b"\\", b"\\\\")
 
179
                       .replace(b"\n", b"\\n")
 
180
                       .replace(b"\0", b"\\x00"))
 
181
        return encoded
176
182
    
177
183
    def encrypt(self, data, password):
178
184
        passphrase = self.password_encode(password)