7.9 PickleSignMixin Classes

This is mixed with the application class to sign or modify pickles before sending them to the browser and to undo and check that modification on the return trip. When processing modified pickles returned from the browser the class discards pickles which do not pass the security check.

There is only one mixin supplied for this function; the PickleSignMixin class. Pickle strings are combined with the secret string which was passed to the application constructor as the secret argument. The MD5 sign for the combined string is then prepended to the pickle. On the return trip the MD5 sign is removed compared with the result of the signing process on the pickle returned from the browser. If the two signs are not the same, the pickle is discarded.

The process does not prevent users from seeing the contents of a pickle. Assuming that you keep your secret, to modify the pickle a user must be able to crack the 128 bit MD5 sign.

The mixin has the following interface.

__init__( secret)
When you inherit from the PickleSignMixin class you must call this constructor.

The secret argument is the secret which is used to protect the MD5 sign.

pickle_sign( text)
Generates an MD5 sign for the secret constructor argument and pickle string passed in the text argument. The return string prepends the 16 byte MD5 sign to the string passed in the text argument.

pickle_unsign( text)
Removes the 16 byte MD5 sign prefix and the resigns the remaining string. If the two signs match the unprefixed string is returned. If the signs do not match the method returns an empty string.