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
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
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
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
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']
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']
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}
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}