Esempio n. 1
0
 def test_encode_decode(self):
     from postkasterl.secure import secure_decrypt
     from postkasterl.secure import secure_encrypt
     somestring = 'foo'
     secret = 'secret'
     encrypted = secure_encrypt(somestring, secret)
     self.assertNotEqual(somestring, encrypted)
     self.assertNotEqual(secret, encrypted)
     decrypted = secure_decrypt(encrypted, secret)
     self.assertEqual(somestring, decrypted)
Esempio n. 2
0
def decrypt_string():
    parser.add_argument(
        "-d",
        "--decrypt",
        required=True,
        help="string to decrypt"
    )
    args = parser.parse_args()
    secret = _get_secret(args)
    decrypted = secure_decrypt(args.decrypt, secret)
    print "ENCRYPTED STRING: '{0:s}'".format(args.decrypt)
    print "RAW STRING      : '{0:s}'".format(decrypted)
Esempio n. 3
0
def _handle_form(request, data):
    result = {
        'errors': {},
    }
    # validate form
    if 'name' not in data or not data['name']:
        result['errors']['name'] = "required"
    if 'email' not in data or not data['email']:
        result['errors']['email'] = "required"
    elif not validate_email(data['email'], verify=True):
        result['errors']['email'] = "invalid"
    if result['errors']:
        return result
    if 'recipient' not in data or not data['recipient']:
        raise HTTPForbidden('Not allowed to call w/o recipient.')
    secret = request.registry.settings.get('postkasterl.secret')
    if not secret:
        raise HTTPInternalServerError('No secret configured.')
    try:
        recipient = secure_decrypt(data['recipient'], secret)
    except Exception, e:
        logger.exception(e)
        raise HTTPForbidden('Invalid recipient.')