Пример #1
0
 def test_encrypt_with_multiple_recipients(self):
     # create two keypairs
     pub1, priv1 = utils.keygen(self.name, self.email, self.passphrase)
     pub2, priv2 = utils.keygen(self.name, self.email, self.passphrase)
     # encrypt file for both 
     encrypted = utils.encrypt(self.file, [pub1, pub2])
     # check keypair one can decrypt
     decrypted = utils.decrypt(encrypted, priv1, pub1, self.passphrase)
     self.assertEquals(decrypted, self.message)
     # check keypair two can decrypt
     decrypted = utils.decrypt(encrypted, priv2, pub2, self.passphrase)
     self.assertEquals(decrypted, self.message)
Пример #2
0
 def test_keygen_creates_valid_priv(self):
     pub, priv = utils.keygen(self.name, self.email, self.passphrase)
     priv = base64.b64decode(priv)
     pub = base64.b64decode(pub)
     self.assertTrue(priv.startswith('-----BEGIN PGP MESSAGE-----'))
     self.assertTrue(priv.endswith('-----END PGP MESSAGE-----\n'))
     priv = utils.decrypt(priv, pub, pub, passphrase=self.passphrase)
     self.assertTrue(priv.startswith('-----BEGIN PGP PRIVATE KEY BLOCK-----'))
     self.assertTrue(priv.endswith('-----END PGP PRIVATE KEY BLOCK-----\n'))
Пример #3
0
    def genkey(self):
        self.require_verification()
        with utils.db_session(self.dbmaker) as session:
            user = session.query(User).filter(User.username == self.username).first()

            if form.validate():
                name = form.data["keyname"]
                passphrase = form.data["passphrase"]
                pub, priv = utils.keygen(name, user.email, passphrase)
                keyobj = Key(name, user.id, pub, priv)
                user.keys.append(keyobj)
                session.add(keyobj)
                session.add(user)
                self.request.session.flash(u"successfully generated key %s." % (name,))

        return HTTPFound(location=self.request.route_url("keys"))
Пример #4
0
    def genkey(self):
        self.require_verification()
        form = Form(self.request, schema=forms.GenKeySchema)
        with utils.db_session(self.dbmaker) as session:
            user = session.query(User).filter(User.username==self.username).first()

            if form.validate():
                name = form.data['keyname']
                passphrase = form.data['passphrase']
                pub, priv = utils.keygen(name, user.email, passphrase)
                keyobj = Key(name, user.id, pub, priv)
                user.keys.append(keyobj)
                session.add(keyobj)
                session.add(user)
                self.request.session.flash(u'successfully generated key %s.' % (name, ))

        return HTTPFound(location=self.request.route_url('keys'))
Пример #5
0
 def verify(self):
     email = utils.verify_email(self.token, self.verification_key, self.verification_salt)
     if not email:
         self.request.session.flash(u'Unable to verify your email account')
         return HTTPFound(location=self.request.route_url('home'))
     if 'form.submitted' in self.request.POST:
         if not utils.authenticate_user(form, self.dbmaker):
             self.request.session.flash(u'Failed to verify your account credentials')
             return HTTPFound(location=self.request.route_url('home'))
         headers = remember(self.request, self.username)
         with utils.db_session(self.dbmaker) as session:
             user = session.query(User).filter(User.email==email).first()
             (pub, priv) = utils.keygen(user.name, user.email, form.data['password'])
             user.verified_at = time.time()
             session.add(user)
             self.request.session.flash(u'Account verified!')
             return HTTPFound(location=self.request.route_url('keys'))
     return dict(
         username=self.username,
         token=self.token
     )
Пример #6
0
 def verify(self):
     form = Form(self.request, schema=forms.RegistrationSchema)  # Me add
     email = utils.verify_email(self.token, self.verification_key,
                                self.verification_salt)
     if not email:
         self.request.session.flash(u'Unable to verify your email account')
         return HTTPFound(location=self.request.route_url('home'))
     if 'form.submitted' in self.request.POST:
         if not utils.authenticate_user(form, self.dbmaker):
             self.request.session.flash(
                 u'Failed to verify your account credentials')
             return HTTPFound(location=self.request.route_url('home'))
         headers = remember(self.request, self.username)
         with utils.db_session(self.dbmaker) as session:
             user = session.query(User).filter(User.email == email).first()
             (pub, priv) = utils.keygen(user.name, user.email,
                                        form.data['password'])
             user.verified_at = time.time()
             session.add(user)
             self.request.session.flash(u'Account verified!')
             return HTTPFound(location=self.request.route_url('keys'))
     return dict(username=self.username, token=self.token)
Пример #7
0
 def test_decrypt_creates_valid_msg(self):
     pub, priv = utils.keygen(self.name, self.email, self.passphrase)
     encrypted = utils.encrypt(self.file, pub)
     decrypted = utils.decrypt(encrypted, priv, pub, self.passphrase)
     self.assertEquals(decrypted, self.message)
Пример #8
0
 def test_encrypt_creates_valid_msg(self):
     pub, priv = utils.keygen(self.name, self.email, self.passphrase)
     encrypted = utils.encrypt(self.file, pub)
     self.assertTrue(encrypted.startswith('-----BEGIN PGP MESSAGE-----'))
     self.assertTrue(encrypted.endswith('-----END PGP MESSAGE-----\n'))
Пример #9
0
 def test_keygen_creates_valid_pub(self):
     pub, _ = utils.keygen(self.name, self.email, self.passphrase)
     pub = base64.b64decode(pub)
     self.assertTrue(pub.startswith('-----BEGIN PGP PUBLIC KEY BLOCK-----'))
     self.assertTrue(pub.endswith('-----END PGP PUBLIC KEY BLOCK-----\n'))