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
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
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)
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 elif opts.action=='d1': if PITCHFORK and opts.PITCHFORK: ensure_recipient_specified(opts) pitchfork.init() params = pitchfork.start_ecdh(opts.recipient[0]) else: params = dh1_handler() if params: print "[pbp] secret exponent", b85encode(params[0]) print "[pbp] public component", b85encode(params[1]) clearmem(params[0]) # receive ECDH
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 elif opts.action=='ds': ensure_self_specified(opts) ensure_dhparam_specified(opts) ensure_name_specified(opts) sec = mpecdh_start_handler(opts.name, opts.dh_peers, opts.self, opts.infile, opts.outfile, opts.basedir) if sec: print >>sys.stderr, "pushed shared secret, hash", b85encode(nacl.crypto_generichash(sec, outlen=6)) clearmem(sec) sec = None # finish ECDH elif opts.action=='de':
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)