def test(): ''' Test packeting. ''' data = odict(hk=1, bk=raeting.bodyKinds.json) body = odict(msg='Hello Raet World', extra='what is this') packet0 = packeting.TxPacket( embody=body, data=data, ) print packet0.body.data packet0.pack() print packet0.packed stuff = [] for i in range(300): stuff.append(str(i).rjust(4, " ")) stuff = "".join(stuff) data.update(bk=raeting.bodyKinds.raw) packet0 = packeting.TxPacket( embody=stuff, data=data, ) packet0.pack() print packet0.packed rejoin = [] if packet0.segmented: for index, segment in packet0.segments.items(): print index, segment.packed rejoin.append(segment.body.packed) rejoin = "".join(rejoin) print stuff == rejoin signer = nacling.Signer() masterSignKeyHex = signer.keyhex masterVerKeyHex = signer.verhex privateer = nacling.Privateer() masterPriKeyHex = privateer.keyhex masterPubKeyHex = privateer.pubhex signer = nacling.Signer() minionSignKeyHex = signer.keyhex minionVerKeyHex = signer.verhex privateer = nacling.Privateer() minionPriKeyHex = privateer.keyhex minionPubKeyHex = privateer.pubhex #master stack device = devicing.LocalDevice(did=1, signkey=masterSignKeyHex, prikey=masterPriKeyHex) stack0 = stacking.StackUdp(device=device) remote1 = devicing.RemoteDevice( did=2, verkey=minionVerKeyHex, pubkey=minionPubKeyHex, ) stack0.addRemoteDevice(remote1) #minion stack device = devicing.LocalDevice( did=2, ha=("", raeting.RAET_TEST_PORT), signkey=minionSignKeyHex, prikey=minionPriKeyHex, ) stack1 = stacking.StackUdp(device=device) remote0 = devicing.RemoteDevice( did=1, ha=('127.0.0.1', raeting.RAET_PORT), verkey=masterVerKeyHex, pubkey=masterPubKeyHex, ) stack1.addRemoteDevice(remote0) remote0.publee = nacling.Publican(key=remote1.privee.pubhex) remote1.publee = nacling.Publican(key=remote0.privee.pubhex) data.update(sd=1, dd=2, bk=raeting.bodyKinds.raw, fk=raeting.footKinds.nacl) packet0 = packeting.TxPacket( stack=stack0, embody=stuff, data=data, ) packet0.pack() print packet0.packed rejoin = [] if packet0.segmented: for index, segment in packet0.segments.items(): print index, segment.packed rejoin.append(segment.coat.packed) rejoin = "".join(rejoin) print stuff == rejoin segmentage = None if packet0.segmented: for segment in packet0.segments.values(): packet = packeting.RxPacket(stack=stack1, packed=segment.packed) packet.parseOuter() if packet.segmentive: if not segmentage: segmentage = packeting.RxPacket(stack=packet.stack, data=packet.data) segmentage.parseSegment(packet) if segmentage.desegmentable(): segmentage.desegmentize() break if segmentage: if not stack1.parseInner(segmentage): print "*******BAD SEGMENTAGE********" return print segmentage.body.packed print segmentage.body.data print segmentage.body.packed == packet0.body.packed body = odict(stuff=stuff) print body data.update(sd=1, dd=2, bk=raeting.bodyKinds.json, fk=raeting.footKinds.nacl) packet0 = packeting.TxPacket( stack=stack0, embody=body, data=data, ) packet0.pack() print packet0.packed segmentage = None if packet0.segmented: for segment in packet0.segments.values(): packet = packeting.RxPacket(stack=stack1, packed=segment.packed) packet.parseOuter() if packet.segmentive: if not segmentage: segmentage = packeting.RxPacket(stack=packet.stack, data=packet.data) segmentage.parseSegment(packet) if segmentage.desegmentable(): segmentage.desegmentize() break if segmentage: if not stack1.parseInner(segmentage): print "*******BAD SEGMENTAGE********" return print segmentage.body.packed print segmentage.body.data print segmentage.body.packed == packet0.body.packed body = odict(stuff=stuff) print body data.update(sd=1, dd=2, bk=raeting.bodyKinds.json, ck=raeting.coatKinds.nacl, fk=raeting.footKinds.nacl) packet0 = packeting.TxPacket( stack=stack0, embody=body, data=data, ) packet0.pack() print "Body" print packet0.body.size, packet0.body.packed print "Coat" print packet0.coat.size, packet0.coat.packed print "Head" print packet0.head.size, packet0.head.packed print "Foot" print packet0.foot.size, packet0.foot.packed print "Packet" print packet0.size, packet0.packed segmentage = None if packet0.segmented: for segment in packet0.segments.values(): packet = packeting.RxPacket(stack=stack1, packed=segment.packed) packet.parseOuter() if packet.segmentive: if not segmentage: segmentage = packeting.RxPacket(stack=packet.stack, data=packet.data) segmentage.parseSegment(packet) if segmentage.desegmentable(): segmentage.desegmentize() break if segmentage: if not stack1.parseInner(segmentage): print "*******BAD SEGMENTAGE********" print segmentage.body.packed print segmentage.body.data print segmentage.body.packed == packet0.body.packed
def test(bk=raeting.bodyKinds.json): ''' Test packeting. ''' data = odict(hk=1, bk=bk) body = odict(msg='Hello Raet World', extra='what is this') packet0 = packeting.TxPacket( embody=body, data=data, ) print packet0.body.data packet0.pack() print packet0.packed packet1 = packeting.RxPacket(packed=packet0.packed) packet1.parse() print packet1.data print packet1.body.data stuff = [] for i in range(300): stuff.append(str(i).rjust(4, " ")) stuff = "".join(stuff) data.update(bk=raeting.bodyKinds.raw) packet0 = packeting.TxPacket( embody=stuff, data=data, ) packet0.pack() print packet0.packed packet1 = packeting.RxPacket(packed=packet0.packed) packet1.parse() print packet1.data print packet1.body.data rejoin = [] if packet0.segmented: for index, segment in packet0.segments.items(): print index, segment.packed rejoin.append(segment.body.packed) rejoin = "".join(rejoin) print stuff == rejoin #master stack masterName = "master" signer = nacling.Signer() masterSignKeyHex = signer.keyhex masterVerKeyHex = signer.verhex privateer = nacling.Privateer() masterPriKeyHex = privateer.keyhex masterPubKeyHex = privateer.pubhex dirpathMaster = os.path.join(os.getcwd(), 'keep', masterName) #minion stack minionName = "minion" signer = nacling.Signer() minionSignKeyHex = signer.keyhex minionVerKeyHex = signer.verhex privateer = nacling.Privateer() minionPriKeyHex = privateer.keyhex minionPubKeyHex = privateer.pubhex dirpathMinion = os.path.join(os.getcwd(), 'keep', minionName) keeping.clearAllRoadSafe(dirpathMaster) keeping.clearAllRoadSafe(dirpathMinion) estate = estating.LocalEstate(eid=1, name=masterName, sigkey=masterSignKeyHex, prikey=masterPriKeyHex) stack0 = stacking.StackUdp(estate=estate, main=True, dirpath=dirpathMaster) remote1 = estating.RemoteEstate( eid=2, name=minionName, ha=("127.0.0.1", raeting.RAET_TEST_PORT), verkey=minionVerKeyHex, pubkey=minionPubKeyHex, ) stack0.addRemoteEstate(remote1) estate = estating.LocalEstate( eid=2, name=minionName, ha=("", raeting.RAET_TEST_PORT), sigkey=minionSignKeyHex, prikey=minionPriKeyHex, ) stack1 = stacking.StackUdp(estate=estate) remote0 = estating.RemoteEstate( eid=1, name=masterName, ha=('127.0.0.1', raeting.RAET_PORT), verkey=masterVerKeyHex, pubkey=masterPubKeyHex, ) stack1.addRemoteEstate(remote0) remote0.publee = nacling.Publican(key=remote1.privee.pubhex) remote1.publee = nacling.Publican(key=remote0.privee.pubhex) print "\n___________Raw Body Test" data.update(se=1, de=2, bk=raeting.bodyKinds.raw, fk=raeting.footKinds.nacl) packet0 = packeting.TxPacket( stack=stack0, embody=stuff, data=data, ) packet0.pack() print packet0.packed #not signed if segmented each segment is signed rejoin = [] if packet0.segmented: for index, segment in packet0.segments.items(): print index, segment.packed rejoin.append(segment.coat.packed) rejoin = "".join(rejoin) print stuff == rejoin segmentage = None if packet0.segmented: for segment in packet0.segments.values(): packet = packeting.RxPacket(stack=stack1, packed=segment.packed) packet.parseOuter() if packet.segmentive: if not segmentage: segmentage = packeting.RxPacket(stack=packet.stack, data=packet.data) segmentage.parseSegment(packet) if segmentage.desegmentable(): segmentage.desegmentize() break if segmentage: if not stack1.parseInner(segmentage): print "*******BAD SEGMENTAGE********" return print segmentage.body.packed print segmentage.body.data print segmentage.body.packed == packet0.body.packed body = odict(stuff=stuff) print body print "\n_____________ Packed Body Test" data.update(se=1, de=2, bk=bk, fk=raeting.footKinds.nacl) packet0 = packeting.TxPacket( stack=stack0, embody=body, data=data, ) packet0.pack() print packet0.packed segmentage = None if packet0.segmented: for segment in packet0.segments.values(): packet = packeting.RxPacket(stack=stack1, packed=segment.packed) packet.parseOuter() if packet.segmentive: if not segmentage: segmentage = packeting.RxPacket(stack=packet.stack, data=packet.data) segmentage.parseSegment(packet) if segmentage.desegmentable(): segmentage.desegmentize() break if segmentage: if not stack1.parseInner(segmentage): print "*******BAD SEGMENTAGE********" return print segmentage.body.packed print segmentage.body.data print segmentage.body.packed == packet0.body.packed body = odict(stuff=stuff) print body print "\n___________ Encrypted Coat Test " data.update(se=1, de=2, bk=raeting.bodyKinds.json, ck=raeting.coatKinds.nacl, fk=raeting.footKinds.nacl) packet0 = packeting.TxPacket( stack=stack0, embody=body, data=data, ) packet0.pack() print "Body" print packet0.body.size, packet0.body.packed print "Coat" print packet0.coat.size, packet0.coat.packed print "Head" print packet0.head.size, packet0.head.packed print "Foot" print packet0.foot.size, packet0.foot.packed print "Packet" print packet0.size, packet0.packed segmentage = None if packet0.segmented: for segment in packet0.segments.values(): packet = packeting.RxPacket(stack=stack1, packed=segment.packed) packet.parseOuter() if packet.segmentive: if not segmentage: segmentage = packeting.RxPacket(stack=packet.stack, data=packet.data) segmentage.parseSegment(packet) if segmentage.desegmentable(): segmentage.desegmentize() break if segmentage: if not stack1.parseInner(segmentage): print "*******BAD SEGMENTAGE********" print segmentage.body.packed print segmentage.body.data print segmentage.body.packed == packet0.body.packed
def test(): print "Bob Signer" signerBob = nacling.Signer() print len(signerBob.keyhex), signerBob.keyhex print len(signerBob.keyraw), signerBob.keyraw print len(signerBob.verhex), signerBob.verhex print len(signerBob.verraw), signerBob.verraw print "Pam Verifier" verferPam = nacling.Verifier(signerBob.verhex) print len(verferPam.keyhex), verferPam.keyhex print len(verferPam.keyraw), verferPam.keyraw print "Signed by Bod" msg = "Hello This is Bob, how are you Pam?" print len(msg), msg signature = signerBob.signature(msg) print len(signature), signature print "Verified by Pam" verified = verferPam.verify(signature, msg) print verified print "Pam Verifier" verferPam = nacling.Verifier(signerBob.verraw) print len(verferPam.keyhex), verferPam.keyhex print len(verferPam.keyraw), verferPam.keyraw print "Signed by Bod" msg = "Hello This is Bob, how are you Pam?" print len(msg), msg signature = signerBob.signature(msg) print len(signature), signature print "Verified by Pam" verified = verferPam.verify(signature, msg) print verified print "Bob Privateer" priverBob = nacling.Privateer() print len(priverBob.keyhex), priverBob.keyhex print len(priverBob.keyraw), priverBob.keyraw print len(priverBob.pubhex), priverBob.pubhex print len(priverBob.pubraw), priverBob.pubraw print "Bob Publican" pubberBob = nacling.Publican(priverBob.pubhex) print len(pubberBob.keyhex), pubberBob.keyhex print len(pubberBob.keyraw), pubberBob.keyraw print "Pam Privateer" priverPam = nacling.Privateer() print len(priverPam.keyhex), priverPam.keyhex print len(priverPam.keyraw), priverPam.keyraw print len(priverPam.pubhex), priverPam.pubhex print len(priverPam.pubraw), priverPam.pubraw print "Pam Publican" pubberPam = nacling.Publican(priverPam.pubhex) print len(pubberPam.keyhex), pubberPam.keyhex print len(pubberPam.keyraw), pubberPam.keyraw print "Encrypted by Bob private Pam public key object" msg = "Hello its me Bob, Did you get my last message Alice?" print len(msg), msg cipher, nonce = priverBob.encrypt(msg, pubberPam.key) print "cipher" print len(cipher), cipher print "nonce" print len(nonce), nonce print "Decrypted by Pam private Bob public key object" msg = priverPam.decrypt(cipher, nonce, pubberBob.key) print len(msg), msg cipher, nonce = priverBob.encrypt(msg, pubberPam.keyhex) print "cipher" print len(cipher), cipher print "nonce" print len(nonce), nonce print "Decrypted by Pam private Bob public keyhex " msg = priverPam.decrypt(cipher, nonce, pubberBob.keyhex) print len(msg), msg cipher, nonce = priverBob.encrypt(msg, pubberPam.keyraw) print "cipher" print len(cipher), cipher print "nonce" print len(nonce), nonce print "Decrypted by Pam private Bob public keyraw" msg = priverPam.decrypt(cipher, nonce, pubberBob.keyraw) print len(msg), msg print "Encrypted by Bob private Pam public key aw" msg = "Hello its me Bob, Did you get my last message Alice?" print len(msg), msg cipher, nonce = priverBob.encrypt(msg, pubberPam.keyraw) print "cipher" print len(cipher), cipher print "nonce" print len(nonce), nonce print "Decrypted by Pam private Bob public keyraw" msg = priverPam.decrypt(cipher, nonce, pubberBob.keyraw) print len(msg), msg print "Blank" msg = "".rjust(64, '\x00') print len(msg), msg cipher, nonce = priverBob.encrypt(msg, pubberPam.keyhex) print "cipher" print len(cipher), cipher print "nonce" print len(nonce), nonce print "Cookie" fmt = '<32sLL32s' msg = struct.pack(fmt, pubberPam.keyraw, 45000, 63000, pubberBob.keyraw) print "Packed" print len(msg), msg cipher, nonce = priverBob.encrypt(msg, pubberPam.keyhex) print "cipher" print len(cipher), cipher print "nonce" print len(nonce), nonce print "Cookie again" fmt = '<32sLL32s' msg = struct.pack(fmt, pubberPam.keyraw, 1, 2, pubberBob.keyraw) print "Packed" print len(msg), msg cipher, nonce = priverBob.encrypt(msg, pubberPam.keyhex) print "cipher" print len(cipher), cipher print "nonce" print len(nonce), nonce print "Cookie Good" fmt = '<32sLL24s' cookie = priverBob.nonce() msg = struct.pack(fmt, pubberPam.keyraw, 1, 2, cookie) print "Packed" print len(msg), msg cipher, nonce = priverBob.encrypt(msg, pubberPam.keyhex) print "cipher" print len(cipher), cipher print "nonce" print len(nonce), nonce print "Initiate" msg = priverBob.keyraw vcipher, vnonce = priverBob.encrypt(msg, pubberPam.key) print "vcipher" print len(vcipher), vcipher print "vnonce" print len(nonce), nonce fqdn = "10.0.2.30".ljust(128, ' ') print "fqdn" print len(fqdn), fqdn fmt = '<32s48s24s128s' stuff = struct.pack(fmt, priverBob.keyraw, vcipher, vnonce, fqdn) print "stuff" print len(stuff), stuff cipher, nonce = priverBob.encrypt(stuff, pubberPam.keyhex) print "cipher" print len(cipher), cipher print "nonce" print len(nonce), nonce
def test(hk=raeting.headKinds.json, bk=raeting.bodyKinds.json): ''' Test packeting. ''' data = odict(hk=hk, bk=bk) body = odict(msg='Hello Raet World', extra='what is this') packet0 = packeting.TxPacket( embody=body, data=data, ) print packet0.body.data packet0.pack() print packet0.packed packet1 = packeting.RxPacket(packed=packet0.packed) packet1.parse() print packet1.data print packet1.body.data stuff = [] for i in range(300): stuff.append(str(i).rjust(4, " ")) stuff = "".join(stuff) data.update(bk=raeting.bodyKinds.raw) packet0 = packeting.TxPacket( embody=stuff, data=data, ) try: packet0.pack() except raeting.PacketError as ex: print ex print "Need to use tray" tray0 = packeting.TxTray(data=data, body=stuff) tray0.pack() print tray0.packed print tray0.packets tray1 = packeting.RxTray() for packet in tray0.packets: tray1.parse(packet) print tray1.data print tray1.body print stuff == tray1.body #master stack masterName = "master" signer = nacling.Signer() masterSignKeyHex = signer.keyhex masterVerKeyHex = signer.verhex privateer = nacling.Privateer() masterPriKeyHex = privateer.keyhex masterPubKeyHex = privateer.pubhex dirpathMaster = os.path.join(os.getcwd(), 'keep', masterName) #minion stack minionName = "minion" signer = nacling.Signer() minionSignKeyHex = signer.keyhex minionVerKeyHex = signer.verhex privateer = nacling.Privateer() minionPriKeyHex = privateer.keyhex minionPubKeyHex = privateer.pubhex dirpathMinion = os.path.join(os.getcwd(), 'keep', minionName) keeping.clearAllKeepSafe(dirpathMaster) keeping.clearAllKeepSafe(dirpathMinion) estate = estating.LocalEstate(eid=1, name=masterName, sigkey=masterSignKeyHex, prikey=masterPriKeyHex) stack0 = stacking.RoadStack(estate=estate, main=True, dirpath=dirpathMaster) remote1 = estating.RemoteEstate( eid=2, name=minionName, ha=("127.0.0.1", raeting.RAET_TEST_PORT), verkey=minionVerKeyHex, pubkey=minionPubKeyHex, ) stack0.addRemote(remote1) estate = estating.LocalEstate( eid=2, name=minionName, ha=("", raeting.RAET_TEST_PORT), sigkey=minionSignKeyHex, prikey=minionPriKeyHex, ) stack1 = stacking.RoadStack(estate=estate) remote0 = estating.RemoteEstate( eid=1, name=masterName, ha=('127.0.0.1', raeting.RAET_PORT), verkey=masterVerKeyHex, pubkey=masterPubKeyHex, ) stack1.addRemote(remote0) remote0.publee = nacling.Publican(key=remote1.privee.pubhex) remote1.publee = nacling.Publican(key=remote0.privee.pubhex) print "\n___________Raw Body Test" data.update(se=1, de=2, bk=raeting.bodyKinds.raw, fk=raeting.footKinds.nacl) tray0 = packeting.TxTray(stack=stack0, data=data, body=stuff) tray0.pack() print tray0.packed print tray0.packets tray1 = packeting.RxTray(stack=stack1) for packet in tray0.packets: tray1.parse(packet) print tray1.data print tray1.body print stuff == tray1.body print "\n_____________ Packed Body Test" body = odict(stuff=stuff) print body data.update(se=1, de=2, bk=bk, fk=raeting.footKinds.nacl) tray0 = packeting.TxTray(stack=stack0, data=data, body=body) tray0.pack() print tray0.packed print tray0.packets tray1 = packeting.RxTray(stack=stack1) for packet in tray0.packets: tray1.parse(packet) print tray1.data print tray1.body print body == tray1.body print "\n___________ Encrypted Coat Test " body = odict(stuff=stuff) print body data.update(se=1, de=2, bk=raeting.bodyKinds.json, ck=raeting.coatKinds.nacl, fk=raeting.footKinds.nacl) tray0 = packeting.TxTray(stack=stack0, data=data, body=body) tray0.pack() print tray0.packed print tray0.packets tray1 = packeting.RxTray(stack=stack1) for packet in tray0.packets: tray1.parse(packet) print tray1.data print tray1.body print body == tray1.body stack0.server.close() stack1.server.close()