Ejemplo n.º 1
0
 def test_receiver_encrypted(self,unilateral,gpgreceiver):
     # bad encrypt
     id1, id2, enc = unilateral['id'], gpgreceiver, unilateral['enc']
     raw, verified, result1 = id2.decrypt(enc)
     verified2, result2 = id2.verify(enc)
     assert raw and result1 and result2
     assert result1['encrypted'] and not (verified or result1['signed'] or result2['signed'])
     assert not (result1['fingerprints'] or result2['fingerprints'])
     compare_mail(msg,raw)
Ejemplo n.º 2
0
 def test_raw(self,unilateral):
     id1 = unilateral['id']
     assert id1.analyze(msg) == (False,False)
     raw, verified, result1 = id1.decrypt(msg)
     verified2, result2 = id1.verify(msg)
     assert raw and result1 and result2
     assert not result1['encrypted'] and not (verified or result1['signed'] or result2['signed'])
     assert not (result1['fingerprints'] or result2['fingerprints'])
     compare_mail(msg,raw)
Ejemplo n.º 3
0
 def test_receiver_encrypted(self, unilateral, gpgreceiver):
     # bad encrypt
     id1, id2, enc = unilateral['id'], gpgreceiver, unilateral['enc']
     raw, verified, result1 = id2.decrypt(enc)
     verified2, result2 = id2.verify(enc)
     assert raw and result1 and result2
     assert result1['encrypted'] and not (verified or result1['signed']
                                          or result2['signed'])
     assert not (result1['fingerprints'] or result2['fingerprints'])
     compare_mail(msg, raw)
Ejemplo n.º 4
0
 def test_raw(self, unilateral):
     id1 = unilateral['id']
     assert id1.analyze(msg) == (False, False)
     raw, verified, result1 = id1.decrypt(msg)
     verified2, result2 = id1.verify(msg)
     assert raw and result1 and result2
     assert not result1['encrypted'] and not (verified or result1['signed']
                                              or result2['signed'])
     assert not (result1['fingerprints'] or result2['fingerprints'])
     compare_mail(msg, raw)
Ejemplo n.º 5
0
 def encrypt(self,ids,msg,sign,inline):
     id1, id2 = ids['id1'], ids['id2']
     enc,_ = id1.encrypt(msg,sign=sign,inline=inline)
     assert enc and id2.analyze(enc) == (True,None)
     mail, verified, result1 = id2.decrypt(enc)
     verified2, result2 = id2.verify(enc)
     assert mail and verified==verified2 and result1 and result2
     assert result1['encrypted'] and verified==sign and result1['signed']==sign and result2['signed']==sign
     assert result1['fingerprints']==result2['fingerprints']
     compare_mail(mail,msg)
Ejemplo n.º 6
0
 def encrypt(self, ids, msg, sign, inline):
     id1, id2 = ids['id1'], ids['id2']
     enc, _ = id1.encrypt(msg, sign=sign, inline=inline)
     assert enc and id2.analyze(enc) == (True, None)
     mail, verified, result1 = id2.decrypt(enc)
     verified2, result2 = id2.verify(enc)
     assert mail and verified == verified2 and result1 and result2
     assert result1['encrypted'] and verified == sign and result1[
         'signed'] == sign and result2['signed'] == sign
     assert result1['fingerprints'] == result2['fingerprints']
     compare_mail(mail, msg)
Ejemplo n.º 7
0
 def test_receiver_signed(self, unilateral, gpgreceiver):
     # bad sign
     id1, id2, sgn = unilateral['id'], gpgreceiver, unilateral['sgn']
     # receiver does not know sender, cannot verify, but can decrypt
     raw, verified, result1 = id2.decrypt(sgn)
     verified2, result2 = id2.verify(sgn)
     assert raw and result1 and result2
     assert not result1['encrypted'] and not verified
     assert result1['signed'] and result2['signed']
     assert not (result1['fingerprints'] or result2['fingerprints'])
     compare_mail(prot, raw)
Ejemplo n.º 8
0
 def test_receiver_signed(self,unilateral,gpgreceiver):
     # bad sign
     id1, id2, sgn = unilateral['id'], gpgreceiver, unilateral['sgn']
     # receiver does not know sender, cannot verify, but can decrypt
     raw, verified, result1 = id2.decrypt(sgn)
     verified2, result2 = id2.verify(sgn)
     assert raw and result1 and result2
     assert not result1['encrypted'] and not verified
     assert result1['signed'] and result2['signed']
     assert not (result1['fingerprints'] or result2['fingerprints'])
     compare_mail(prot,raw)
Ejemplo n.º 9
0
 def sign(self,ids,msg,inline):
     id1, id2 = ids['id1'], ids['id2']
     prot = protect_mail(msg,linesep='\r\n')
     sgn,_ = id1.sign(msg,inline=inline)
     assert sgn and id2.analyze(sgn) == (False,True)
     mail, verified, result1 = id2.decrypt(sgn)
     verified2, result2 = id2.verify(sgn)
     rawmail, signed = id2.strip_signature(sgn)
     assert mail and verified==verified2
     compare_mail(mail,rawmail)
     assert result1 and result2
     assert not result1['encrypted'] and verified and result1['signed'] and result2['signed']
     assert result1['fingerprints']==result2['fingerprints']
     compare_mail(rawmail,prot)
Ejemplo n.º 10
0
 def sign(self, ids, msg, inline):
     id1, id2 = ids['id1'], ids['id2']
     prot = protect_mail(msg, linesep='\r\n')
     sgn, _ = id1.sign(msg, inline=inline)
     assert sgn and id2.analyze(sgn) == (False, True)
     mail, verified, result1 = id2.decrypt(sgn)
     verified2, result2 = id2.verify(sgn)
     rawmail, signed = id2.strip_signature(sgn)
     assert mail and verified == verified2
     compare_mail(mail, rawmail)
     assert result1 and result2
     assert not result1['encrypted'] and verified and result1[
         'signed'] and result2['signed']
     assert result1['fingerprints'] == result2['fingerprints']
     compare_mail(rawmail, prot)
Ejemplo n.º 11
0
def test_encrypt(gpgsender, asstr, protect):
    import copy
    inmsg = protect_mail(msgrev,linesep='\r\n') if protect else msgrev
    if asstr: inmsg = inmsg.as_string()
    omsg = copy.deepcopy(inmsg)
    enc, results = gpgsender.encrypt(inmsg,toself=False,sign=False) # we only know sender keys
    assert enc
    compare_mail(omsg,inmsg)
    if protect: enc = protect_mail(enc,linesep='\r\n')
    if asstr: enc = enc.as_string()
    oenc = copy.deepcopy(enc)
    msg2, signed, results = gpgsender.decrypt(enc,strict=True)
    assert not signed and msg2
    compare_mail(oenc,enc)
    if asstr: msg2 = msg2.as_string()
    compare_mail(inmsg,msg2)
Ejemplo n.º 12
0
def test_encrypt(gpgsender, asstr, protect):
    import copy
    inmsg = protect_mail(msgrev, linesep='\r\n') if protect else msgrev
    if asstr: inmsg = inmsg.as_string()
    omsg = copy.deepcopy(inmsg)
    enc, results = gpgsender.encrypt(inmsg, toself=False,
                                     sign=False)  # we only know sender keys
    assert enc
    compare_mail(omsg, inmsg)
    if protect: enc = protect_mail(enc, linesep='\r\n')
    if asstr: enc = enc.as_string()
    oenc = copy.deepcopy(enc)
    msg2, signed, results = gpgsender.decrypt(enc, strict=True)
    assert not signed and msg2
    compare_mail(oenc, enc)
    if asstr: msg2 = msg2.as_string()
    compare_mail(inmsg, msg2)
Ejemplo n.º 13
0
def test_8bit(attachments):
    expect=b'''Content-Type: multipart/mixed; boundary="===============6661726347990728450=="
MIME-Version: 1.0
From: Foo <foo@localhost>
To: Bar <bar@localhost>
Subject: subject
Date: Mon, 02 Feb 2015 12:00:00 +0100

--===============6661726347990728450==
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64

w7xiZXIKMQoy
--===============6661726347990728450==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

uber
--===============6661726347990728450==
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64

w7xiZXIKMQoy
--===============6661726347990728450==
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64

w7xiZXIKMQoy
--===============6661726347990728450==
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable

=C3=BCber
1
2
--===============6661726347990728450==
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit

\xc3\xbcber
1
2
--===============6661726347990728450==
Content-Type: text/plain; charset="iso8859-1"
MIME-Version: 1.0
Content-Transfer-Encoding: base64

/GJlcgoxCjI=
--===============6661726347990728450==
Content-Type: text/plain; charset="iso8859-1"
MIME-Version: 1.0
Content-Transfer-Encoding: base64

/GJlcgoxCjI=
--===============6661726347990728450==
Content-Type: text/plain; charset="iso8859-1"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable

=FCber
1
2
--===============6661726347990728450==
Content-Type: text/plain; charset="iso8859-1"
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

\xfcber
1
2
--===============6661726347990728450==--
'''
    s = u'über\n1\n2'
    msg = create_mail(sender,receiver,'subject',s,attach=attachments,time='Mon, 02 Feb 2015 12:00:00 +0100')
    msg.set_boundary('===============6661726347990728450==')
    out = mail_binary(msg)
    assert out==expect
    prot = protect_mail(out,linesep='\n',sevenbit=False)
    att = prot.get_payload()
    out2 = mail_binary(prot)
    assert out==out2
    compare_mail(msg,prot)
Ejemplo n.º 14
0
def test_sign(gpgsender, inline, attach, asstr, protect):
    # protect = use protected CRLF message
    import copy
    if inline and attach: return

    if attach:  # with attachment
        nmsg, pmsg = protect_mail(msgatt, linesep='\n'), protatt
        inmsg = protatt if protect else nmsg
    else:
        inmsg = prot if protect else msg
        nmsg, pmsg = msg, prot
    if asstr:
        inmsg, nmsg, pmsg = inmsg.as_string(), nmsg.as_string(
        ), pmsg.as_string()
    omsg = copy.deepcopy(inmsg)
    sgn, result = gpgsender.sign(inmsg, inline=inline, verify=True)
    assert sgn
    compare_mail(omsg, inmsg)  # unmodified
    if inline:
        assert not sgn.is_multipart()
        body = gpgsender.without_signature(sgn.get_payload())
        if not asstr: assert body == pmsg.get_payload()
    if asstr: sgn = sgn.as_string()
    if protect: sgn = protect_mail(sgn, linesep='\r\n')
    osgn = copy.deepcopy(sgn)
    assert gpgsender.verify(sgn, strict=True)[0]
    compare_mail(osgn, sgn)  # unmodified
    msg2, signed, results = gpgsender.decrypt(sgn, strict=True)
    assert signed and msg2
    compare_mail(osgn, sgn)  # unmodified
    if asstr: msg2 = msg2.as_string()
    compare_mail(pmsg, msg2)

    assert gpgsender.verify(sgn, strict=False)[0]
    compare_mail(osgn, sgn)  # unmodified
    msg2, signed, results = gpgsender.decrypt(sgn, strict=False)
    assert signed and msg2
    compare_mail(osgn, sgn)  # unmodified
    if asstr: msg2 = msg2.as_string()
    compare_mail(pmsg, msg2)

    nsgn = protect_mail(sgn, linesep='\n')  # use LF message as input
    if asstr: nsgn = nsgn.as_string()
    compare_mail(osgn, sgn)  # unmodified
    onsgn = copy.deepcopy(nsgn)
    msg2, signed, results = gpgsender.decrypt(nsgn, strict=True)
    assert signed == bool(
        inline) and msg2  # sgn was modified, should fail for detached
    compare_mail(onsgn, nsgn)  # unmodified
    if asstr: msg2 = msg2.as_string()
    compare_mail(nmsg, msg2)

    msg2, signed, results = gpgsender.decrypt(nsgn, strict=False)
    assert signed and msg2
    compare_mail(onsgn, nsgn)
    if asstr: msg2 = msg2.as_string()
    if inline:
        compare_mail(nmsg, msg2)
    else:
        compare_mail(pmsg, msg2)
Ejemplo n.º 15
0
def test_sign(gpgsender,inline,attach,asstr,protect):
    # protect = use protected CRLF message
    import copy
    if inline and attach: return

    if attach: # with attachment
        nmsg, pmsg = protect_mail(msgatt,linesep='\n'), protatt
        inmsg = protatt if protect else nmsg
    else:
        inmsg = prot if protect else msg
        nmsg, pmsg = msg, prot
    if asstr: inmsg, nmsg, pmsg = inmsg.as_string(), nmsg.as_string(), pmsg.as_string()
    omsg = copy.deepcopy(inmsg)
    sgn, result = gpgsender.sign(inmsg,inline=inline,verify=True)
    assert sgn
    compare_mail(omsg,inmsg) # unmodified
    if inline:
        assert not sgn.is_multipart()
        body = gpgsender.without_signature(sgn.get_payload())
        if not asstr: assert body==pmsg.get_payload()
    if asstr: sgn = sgn.as_string()
    if protect: sgn = protect_mail(sgn,linesep='\r\n')
    osgn = copy.deepcopy(sgn)
    assert gpgsender.verify(sgn,strict=True)[0]
    compare_mail(osgn,sgn) # unmodified
    msg2, signed, results = gpgsender.decrypt(sgn,strict=True)
    assert signed and msg2
    compare_mail(osgn,sgn) # unmodified
    if asstr: msg2 = msg2.as_string()
    compare_mail(pmsg,msg2)

    assert gpgsender.verify(sgn,strict=False)[0]
    compare_mail(osgn,sgn) # unmodified
    msg2, signed, results = gpgsender.decrypt(sgn,strict=False)
    assert signed and msg2
    compare_mail(osgn,sgn) # unmodified
    if asstr: msg2 = msg2.as_string()
    compare_mail(pmsg,msg2)

    nsgn = protect_mail(sgn,linesep='\n') # use LF message as input
    if asstr: nsgn = nsgn.as_string()
    compare_mail(osgn,sgn) # unmodified
    onsgn = copy.deepcopy(nsgn)
    msg2, signed, results = gpgsender.decrypt(nsgn,strict=True)
    assert signed==bool(inline) and msg2 # sgn was modified, should fail for detached
    compare_mail(onsgn,nsgn) # unmodified
    if asstr: msg2 = msg2.as_string()
    compare_mail(nmsg,msg2)

    msg2, signed, results = gpgsender.decrypt(nsgn,strict=False)
    assert signed and msg2
    compare_mail(onsgn,nsgn)
    if asstr: msg2 = msg2.as_string()
    if inline:
        compare_mail(nmsg,msg2)
    else:
        compare_mail(pmsg,msg2)