Ejemplo n.º 1
0
 def test_bad_defkey(self,bilateral):
     # bad sender passphrase, cannot sign
     id1 = GPGMIME(bilateral['gpg1'],default_key=receiver)
     with raises(KeyMissingError): id1.sign(msgrev)
     with raises(KeyMissingError): id1.encrypt(msgrev,sign=True)
     # bad receiver key, cannot decrypt
     enc = bilateral['id2'].encrypt(msgrev,toself=False)[0]
     assert enc and id1.decrypt(enc)[0] is None
Ejemplo n.º 2
0
 def test_bad_defkey(self, bilateral):
     # bad sender passphrase, cannot sign
     id1 = GPGMIME(bilateral['gpg1'], default_key=receiver)
     with raises(KeyMissingError):
         id1.sign(msgrev)
     with raises(KeyMissingError):
         id1.encrypt(msgrev, sign=True)
     # bad receiver key, cannot decrypt
     enc = bilateral['id2'].encrypt(msgrev, toself=False)[0]
     assert enc and id1.decrypt(enc)[0] is None
Ejemplo n.º 3
0
 def test_bad_passphrase(self, bilateral):
     # bad sender passphrase, cannot sign
     id1 = GPGMIME(bilateral['gpg1'], default_key=(sender, 'wrong'))
     assert id1.sign(msg)[0] is None
     assert id1.encrypt(msg, sign=True)[0] is None
     # bad receiver passphrase, cannot decrypt
     enc = bilateral['id2'].encrypt(msgrev)[0]
     assert enc and id1.decrypt(enc)[0] is None
Ejemplo n.º 4
0
 def test_bad_passphrase(self,bilateral):
     # bad sender passphrase, cannot sign
     id1 = GPGMIME(bilateral['gpg1'],default_key=(sender,'wrong'))
     assert id1.sign(msg)[0] is None
     assert id1.encrypt(msg,sign=True)[0] is None
     # bad receiver passphrase, cannot decrypt
     enc = bilateral['id2'].encrypt(msgrev)[0]
     assert enc and id1.decrypt(enc)[0] is None
Ejemplo n.º 5
0
 def test_no_defkey(self, bilateral):
     # missing defkey, cannot sign
     id1 = GPGMIME(bilateral['gpg1'])
     assert id1.sign(msg)[0] is None
     assert id1.encrypt(msg, sign=True)[0] is None
     # no receiver key, cannot decrypt
     enc = bilateral['id2'].encrypt(msgrev)[0]
     assert enc
     mail, valid, result = id1.decrypt(enc)
     assert mail is None and not valid and not result['signed']
Ejemplo n.º 6
0
 def test_no_defkey(self,bilateral):
     # missing defkey, cannot sign
     id1 = GPGMIME(bilateral['gpg1'])
     assert id1.sign(msg)[0] is None
     assert id1.encrypt(msg,sign=True)[0] is None
     # no receiver key, cannot decrypt
     enc = bilateral['id2'].encrypt(msgrev)[0]
     assert enc
     mail, valid, result = id1.decrypt(enc)
     assert mail is None and not valid and not result['signed']
Ejemplo n.º 7
0
def unilateral(request,keys):
    keyring = tmpfname()
    gpg = gnupg.GPG(keyring=keyring,secring=keys['secrings'][0],use_agent=False)
    gpg.import_keys(keys['pubkey1'])
    gpg.import_keys(keys['pubkey2']) # sender knows receiver pubkey
    id = GPGMIME(gpg,default_key=(sender,passphrase))
    sgn = id.sign(msg)[0]
    enc = id.encrypt(msg,toself=False,sign=False)[0]
    def fin():
        import os
        os.unlink(keyring)
    request.addfinalizer(fin)
    return {'id':id,'sgn':sgn,'enc':enc}
Ejemplo n.º 8
0
def unilateral(request, keys):
    keyring = tmpfname()
    gpg = gnupg.GPG(keyring=keyring,
                    secring=keys['secrings'][0],
                    use_agent=False)
    gpg.import_keys(keys['pubkey1'])
    gpg.import_keys(keys['pubkey2'])  # sender knows receiver pubkey
    id = GPGMIME(gpg, default_key=(sender, passphrase))
    sgn = id.sign(msg)[0]
    enc = id.encrypt(msg, toself=False, sign=False)[0]

    def fin():
        import os
        os.unlink(keyring)

    request.addfinalizer(fin)
    return {'id': id, 'sgn': sgn, 'enc': enc}