Exemple #1
0
    def test_chaining(self):
        publickey.Identity('alice', basedir=self.pbp_path, create=True)
        publickey.Identity('bob', basedir=self.pbp_path, create=True)

        msg = self.tmp_dir + '/msg'
        msg2 = self.tmp_dir + '/msg2'
        ct = self.tmp_dir + '/ct'

        sender, receiver = 'alice', 'bob'

        for i in xrange(10):
            with open(msg, 'w') as fd:
                fd.write(str(i) * 1080)

            pbp.chaining_encrypt_handler(infile=msg,
                                         outfile=ct,
                                         recipient=receiver,
                                         self=sender,
                                         basedir=self.pbp_path)
            pbp.chaining_decrypt_handler(infile=ct,
                                         outfile=msg2,
                                         recipient=sender,
                                         self=receiver,
                                         basedir=self.pbp_path)

            with open(msg2, 'r') as fd:
                res = fd.read()
            self.assertEquals(res, str(i) * 1080)

            sender, receiver = receiver, sender
Exemple #2
0
    def test_chaining(self):
        publickey.Identity('alice', basedir=self.pbp_path, create=True)
        publickey.Identity('bob', basedir=self.pbp_path, create=True)

        msg=self.tmp_dir+'/msg'
        msg2=self.tmp_dir+'/msg2'
        ct=self.tmp_dir+'/ct'

        sender, receiver = 'alice', 'bob'

        for i in range(10):
            with open(msg, 'w') as fd:
                fd.write(str(i) * 1080)

            pbp.chaining_encrypt_handler(infile=msg, outfile=ct, recipient=receiver, self=sender, basedir=self.pbp_path)
            pbp.chaining_decrypt_handler(infile=ct, outfile=msg2, recipient=sender, self=receiver, basedir=self.pbp_path)

            with open(msg2, 'r') as fd:
                res = fd.read()
            self.assertEquals(res, str(i)*1080)

            sender,receiver=receiver,sender
Exemple #3
0
    def test_oob_chaining(self):
        # this test is sadly ugly, sorry.

        publickey.Identity('alice', basedir=self.pbp_path, create=True)
        publickey.Identity('bob', basedir=self.pbp_path, create=True)

        msg=self.tmp_dir+'/msg'
        msg2=self.tmp_dir+'/msg2'
        ct=self.tmp_dir+'/ct'
        ct2=self.tmp_dir+'/ct2'
        ct3=self.tmp_dir+'/ct3'
        ct4=self.tmp_dir+'/ct4'
        ct5=self.tmp_dir+'/ct5'

        sender, receiver = 'alice', 'bob'

        # do some proper exchange
        for i in range(5):
            with open(msg, 'w') as fd:
                fd.write(str(i) * 1080)

            pbp.chaining_encrypt_handler(infile=msg, outfile=ct, recipient=receiver, self=sender, basedir=self.pbp_path)
            pbp.chaining_decrypt_handler(infile=ct, outfile=msg2, recipient=sender, self=receiver, basedir=self.pbp_path)

            with open(msg2, 'r') as fd:
                res = fd.read()
            self.assertEquals(res, str(i)*1080)

            sender,receiver=receiver,sender

        with open(msg, 'w') as fd:
            fd.write('a' * 1080)

        pbp.chaining_encrypt_handler(infile=msg, outfile=ct, recipient='alice', self='bob', basedir=self.pbp_path)
        pbp.chaining_decrypt_handler(infile=ct, outfile=msg2, recipient='bob', self='alice', basedir=self.pbp_path)

        with open(msg2, 'r') as fd:
            res = fd.read()
        self.assertEquals(res, 'a'*1080)

        # resend previous message
        pbp.chaining_encrypt_handler(infile=msg, outfile=ct, recipient='alice', self='bob', basedir=self.pbp_path)
        pbp.chaining_decrypt_handler(infile=ct, outfile=msg2, recipient='bob', self='alice', basedir=self.pbp_path)

        with open(msg2, 'r') as fd:
            res = fd.read()
        self.assertEquals(res, 'a'*1080)

        # answer message but mess up order
        # would be nice to have random tests here, instead of the following synthetic
        # b3,a1,b2,b1,a2 - where the letter is the recipent, and the number the order of creation
        # 1st msg
        with open(msg, 'w') as fd: fd.write('b1' * 1080)
        pbp.chaining_encrypt_handler(infile=msg, outfile=ct, recipient='bob', self='alice', basedir=self.pbp_path)
        # 2nd msg
        with open(msg, 'w') as fd: fd.write('b2' * 1080)
        pbp.chaining_encrypt_handler(infile=msg, outfile=ct2, recipient='bob', self='alice', basedir=self.pbp_path)
        # 3rd msg
        with open(msg, 'w') as fd: fd.write('b3' * 1080)
        pbp.chaining_encrypt_handler(infile=msg, outfile=ct3, recipient='bob', self='alice', basedir=self.pbp_path)
        # and 1st message in the other direction at the same time
        with open(msg, 'w') as fd: fd.write('a1' * 1080)
        pbp.chaining_encrypt_handler(infile=msg, outfile=ct4, recipient='alice', self='bob', basedir=self.pbp_path)
        # 2nd message in the other direction at the same time
        with open(msg, 'w') as fd: fd.write('a2' * 1080)
        pbp.chaining_encrypt_handler(infile=msg, outfile=ct5, recipient='alice', self='bob', basedir=self.pbp_path)

        # 3rd msg decrypt
        pbp.chaining_decrypt_handler(infile=ct3, outfile=msg2, recipient='alice', self='bob', basedir=self.pbp_path)
        with open(msg2, 'r') as fd: res = fd.read()
        self.assertEquals(res, 'b3'*1080)

        # other direction decrypt
        pbp.chaining_decrypt_handler(infile=ct4, outfile=msg2, recipient='bob', self='alice', basedir=self.pbp_path)
        with open(msg2, 'r') as fd: res = fd.read()
        self.assertEquals(res, 'a1'*1080)

        # 2nd msg decrypt
        pbp.chaining_decrypt_handler(infile=ct2, outfile=msg2, recipient='alice', self='bob', basedir=self.pbp_path)
        with open(msg2, 'r') as fd: res = fd.read()
        self.assertEquals(res, 'b2'*1080)
        # 1st msg decrypt
        pbp.chaining_decrypt_handler(infile=ct, outfile=msg2, recipient='alice', self='bob', basedir=self.pbp_path)
        with open(msg2, 'r') as fd: res = fd.read()
        self.assertEquals(res, 'b1'*1080)
        # other direction 2nd decrypt
        pbp.chaining_decrypt_handler(infile=ct5, outfile=msg2, recipient='bob', self='alice', basedir=self.pbp_path)
        with open(msg2, 'r') as fd: res = fd.read()
        self.assertEquals(res, 'a2'*1080)
Exemple #4
0
        n = import_handler(infile=opts.infile,
                           basedir=opts.basedir)
        if n:
            print '[pbp] Success: imported public keys for', n
        else:
            print '[pbp] IMPORT FAILED'

    # forward encrypt
    elif opts.action=='e':
        ensure_recipient_specified(opts)
        ensure_only_one_recipient(opts)
        # TODO could try to find out this automatically if non-ambiguous
        ensure_self_specified(opts)
        chaining_encrypt_handler(opts.infile,
                        outfile=opts.outfile,
                        recipient=opts.recipient[0],
                        self=opts.self,
                        basedir=opts.basedir)

    # forward decrypt
    elif opts.action=='E':
        ensure_recipient_specified(opts)
        ensure_only_one_recipient(opts)
        # TODO could try to find out this automatically if non-ambiguous
        ensure_self_specified(opts)
        chaining_decrypt_handler(opts.infile,
                            outfile=opts.outfile,
                            recipient=opts.recipient[0],
                            self=opts.self,
                            basedir=opts.basedir)
    # start ECDH
Exemple #5
0
        n = import_handler(infile=opts.infile,
                           basedir=opts.basedir)
        if n:
            print 'Success: imported public keys for', n
        else:
            print 'import failed'

    # forward encrypt
    elif opts.action=='e':
        ensure_recipient_specified(opts)
        ensure_only_one_recipient(opts)
        # TODO could try to find out this automatically if non-ambiguous
        ensure_self_specified(opts)
        chaining_encrypt_handler(opts.infile,
                        outfile=opts.outfile,
                        recipient=opts.recipient[0],
                        self=opts.self,
                        basedir=opts.basedir)

    # forward decrypt
    elif opts.action=='E':
        ensure_recipient_specified(opts)
        ensure_only_one_recipient(opts)
        # TODO could try to find out this automatically if non-ambiguous
        ensure_self_specified(opts)
        chaining_decrypt_handler(opts.infile,
                            outfile=opts.outfile,
                            recipient=opts.recipient[0],
                            self=opts.self,
                            basedir=opts.basedir)
    # start ECDH
Exemple #6
0
    def test_oob_chaining(self):
        # this test is sadly ugly, sorry.

        publickey.Identity('alice', basedir=self.pbp_path, create=True)
        publickey.Identity('bob', basedir=self.pbp_path, create=True)

        msg = self.tmp_dir + '/msg'
        msg2 = self.tmp_dir + '/msg2'
        ct = self.tmp_dir + '/ct'
        ct2 = self.tmp_dir + '/ct2'
        ct3 = self.tmp_dir + '/ct3'
        ct4 = self.tmp_dir + '/ct4'
        ct5 = self.tmp_dir + '/ct5'

        sender, receiver = 'alice', 'bob'

        # do some proper exchange
        for i in xrange(5):
            with open(msg, 'w') as fd:
                fd.write(str(i) * 1080)

            pbp.chaining_encrypt_handler(infile=msg,
                                         outfile=ct,
                                         recipient=receiver,
                                         self=sender,
                                         basedir=self.pbp_path)
            pbp.chaining_decrypt_handler(infile=ct,
                                         outfile=msg2,
                                         recipient=sender,
                                         self=receiver,
                                         basedir=self.pbp_path)

            with open(msg2, 'r') as fd:
                res = fd.read()
            self.assertEquals(res, str(i) * 1080)

            sender, receiver = receiver, sender

        with open(msg, 'w') as fd:
            fd.write('a' * 1080)

        pbp.chaining_encrypt_handler(infile=msg,
                                     outfile=ct,
                                     recipient='alice',
                                     self='bob',
                                     basedir=self.pbp_path)
        pbp.chaining_decrypt_handler(infile=ct,
                                     outfile=msg2,
                                     recipient='bob',
                                     self='alice',
                                     basedir=self.pbp_path)

        with open(msg2, 'r') as fd:
            res = fd.read()
        self.assertEquals(res, 'a' * 1080)

        # resend previous message
        pbp.chaining_encrypt_handler(infile=msg,
                                     outfile=ct,
                                     recipient='alice',
                                     self='bob',
                                     basedir=self.pbp_path)
        pbp.chaining_decrypt_handler(infile=ct,
                                     outfile=msg2,
                                     recipient='bob',
                                     self='alice',
                                     basedir=self.pbp_path)

        with open(msg2, 'r') as fd:
            res = fd.read()
        self.assertEquals(res, 'a' * 1080)

        # answer message but mess up order
        # would be nice to have random tests here, instead of the following synthetic
        # b3,a1,b2,b1,a2 - where the letter is the recipent, and the number the order of creation
        # 1st msg
        with open(msg, 'w') as fd:
            fd.write('b1' * 1080)
        pbp.chaining_encrypt_handler(infile=msg,
                                     outfile=ct,
                                     recipient='bob',
                                     self='alice',
                                     basedir=self.pbp_path)
        # 2nd msg
        with open(msg, 'w') as fd:
            fd.write('b2' * 1080)
        pbp.chaining_encrypt_handler(infile=msg,
                                     outfile=ct2,
                                     recipient='bob',
                                     self='alice',
                                     basedir=self.pbp_path)
        # 3rd msg
        with open(msg, 'w') as fd:
            fd.write('b3' * 1080)
        pbp.chaining_encrypt_handler(infile=msg,
                                     outfile=ct3,
                                     recipient='bob',
                                     self='alice',
                                     basedir=self.pbp_path)
        # and 1st message in the other direction at the same time
        with open(msg, 'w') as fd:
            fd.write('a1' * 1080)
        pbp.chaining_encrypt_handler(infile=msg,
                                     outfile=ct4,
                                     recipient='alice',
                                     self='bob',
                                     basedir=self.pbp_path)
        # 2nd message in the other direction at the same time
        with open(msg, 'w') as fd:
            fd.write('a2' * 1080)
        pbp.chaining_encrypt_handler(infile=msg,
                                     outfile=ct5,
                                     recipient='alice',
                                     self='bob',
                                     basedir=self.pbp_path)

        # 3rd msg decrypt
        pbp.chaining_decrypt_handler(infile=ct3,
                                     outfile=msg2,
                                     recipient='alice',
                                     self='bob',
                                     basedir=self.pbp_path)
        with open(msg2, 'r') as fd:
            res = fd.read()
        self.assertEquals(res, 'b3' * 1080)

        # other direction decrypt
        pbp.chaining_decrypt_handler(infile=ct4,
                                     outfile=msg2,
                                     recipient='bob',
                                     self='alice',
                                     basedir=self.pbp_path)
        with open(msg2, 'r') as fd:
            res = fd.read()
        self.assertEquals(res, 'a1' * 1080)

        # 2nd msg decrypt
        pbp.chaining_decrypt_handler(infile=ct2,
                                     outfile=msg2,
                                     recipient='alice',
                                     self='bob',
                                     basedir=self.pbp_path)
        with open(msg2, 'r') as fd:
            res = fd.read()
        self.assertEquals(res, 'b2' * 1080)
        # 1st msg decrypt
        pbp.chaining_decrypt_handler(infile=ct,
                                     outfile=msg2,
                                     recipient='alice',
                                     self='bob',
                                     basedir=self.pbp_path)
        with open(msg2, 'r') as fd:
            res = fd.read()
        self.assertEquals(res, 'b1' * 1080)
        # other direction 2nd decrypt
        pbp.chaining_decrypt_handler(infile=ct5,
                                     outfile=msg2,
                                     recipient='bob',
                                     self='alice',
                                     basedir=self.pbp_path)
        with open(msg2, 'r') as fd:
            res = fd.read()
        self.assertEquals(res, 'a2' * 1080)