def statusRemote(self, remote, verhex, pubhex, main=True): ''' Evaluate acceptance status of remote estate per its keys persist key data differentially based on status ''' status = raeting.ACCEPTANCES[self.saltRaetKey.status( remote.name, remote.eid, pubhex, verhex)] if status != raeting.acceptances.rejected: if (verhex and verhex != remote.verfer.keyhex): remote.verfer = nacling.Verifier(verhex) if (pubhex and pubhex != remote.pubber.keyhex): remote.pubber = nacling.Publican(pubhex) remote.acceptance = status return status
def testEncrypt(self): ''' Test encryption decryption with public private remote local key pairs ''' console.terse("{0}\n".format(self.testEncrypt.__doc__)) priverBob = nacling.Privateer() console.terse("Bob Local Key Pair\n") console.terse("Bob Privateer keyhex = {0}\n".format(priverBob.keyhex)) console.terse("Bob Privateer pubhex = {0}\n".format(priverBob.pubhex)) self.assertEqual(len(priverBob.keyhex), 64) self.assertEqual(len(priverBob.keyraw), 32) self.assertEqual(len(priverBob.pubhex), 64) self.assertEqual(len(priverBob.pubraw), 32) # create from pubhex pubberBob = nacling.Publican(priverBob.pubhex) console.terse("Bob remote public key\n") console.terse("Bob Publican keyhex = {0}\n".format(pubberBob.keyhex)) self.assertEqual(len(pubberBob.keyhex), 64) self.assertEqual(len(pubberBob.keyraw), 32) self.assertEqual(pubberBob.keyhex, priverBob.pubhex) # create from pubraw pubberBob = nacling.Publican(priverBob.pubraw) #console.terse("Bob remote public key\n") #console.terse("Bob Publican keyhex = {0}\n".format(pubberBob.keyhex)) self.assertEqual(len(pubberBob.keyhex), 64) self.assertEqual(len(pubberBob.keyraw), 32) self.assertEqual(pubberBob.keyhex, priverBob.pubhex) # create from key pubberBob = nacling.Publican(pubberBob.key) #console.terse("Bob remote public key\n") #console.terse("Bob Publican keyhex = {0}\n".format(pubberBob.keyhex)) self.assertEqual(len(pubberBob.keyhex), 64) self.assertEqual(len(pubberBob.keyraw), 32) self.assertEqual(pubberBob.keyhex, priverBob.pubhex) priverPam = nacling.Privateer() console.terse("Pam Local Key Pair\n") console.terse("Pam Privateer keyhex = {0}\n".format(priverPam.keyhex)) console.terse("Pam Privateer pubhex = {0}\n".format(priverPam.pubhex)) self.assertEqual(len(priverPam.keyhex), 64) self.assertEqual(len(priverPam.keyraw), 32) self.assertEqual(len(priverPam.pubhex), 64) self.assertEqual(len(priverPam.pubraw), 32) #create from pubhex pubberPam = nacling.Publican(priverPam.pubhex) console.terse("Pam remote public key\n") console.terse("Pam Publican keyhex = {0}\n".format(pubberPam.keyhex)) self.assertEqual(len(pubberPam.keyhex), 64) self.assertEqual(len(pubberPam.keyraw), 32) self.assertEqual(pubberPam.keyhex, priverPam.pubhex) # create from pubraw pubberPam = nacling.Publican(priverPam.pubraw) #console.terse("Pam remote public key\n") #console.terse("Pam Publican keyhex = {0}\n".format(pubberPam.keyhex)) self.assertEqual(len(pubberPam.keyhex), 64) self.assertEqual(len(pubberPam.keyraw), 32) self.assertEqual(pubberPam.keyhex, priverPam.pubhex) # create from key pubberPam = nacling.Publican(pubberPam.key) #console.terse("Pam remote public key\n") #console.terse("Pam Publican keyhex = {0}\n".format(pubberPam.keyhex)) self.assertEqual(len(pubberPam.keyhex), 64) self.assertEqual(len(pubberPam.keyraw), 32) self.assertEqual(pubberPam.keyhex, priverPam.pubhex) console.terse("Encrypted by Bob local private and Pam remote public key pair\n") enmsg = "Hello its me Bob, Did you get my last message Pam?" console.terse("Msg len={0} '{1}'\n".format(len(enmsg), enmsg)) self.assertEqual(len(enmsg), 50) # Pam remote public key, raw cipher nonce cipher, nonce = priverBob.encrypt(enmsg, pubberPam.key) console.terse("Cipher len={0} Nonce len={1}\n".format(len(cipher), len(nonce))) self.assertEqual(len(cipher), 66) self.assertEqual(len(nonce), 24) # Bob public key object console.terse("Decrypted by Pam local private and Bob remote public key pair\n") demsg = priverPam.decrypt(cipher, nonce, pubberBob.key) console.terse("Msg len={0} '{1}'\n".format(len(demsg), demsg)) self.assertEqual(len(demsg), 50) self.assertEqual(demsg, enmsg) # Pam remote public key, hex cipher nonce cipher, nonce = priverBob.encrypt(enmsg, pubberPam.key, enhex=True) console.terse("Cipher len={0} '{1}'\nNonce len={2} '{3}'\n".format( len(cipher), cipher, len(nonce), nonce)) self.assertEqual(len(cipher), 132) self.assertEqual(len(nonce), 48) # Bob public key object #console.terse("Decrypted by Pam local private and Bob remote public key pair\n") demsg = priverPam.decrypt(cipher, nonce, pubberBob.key, dehex=True) #console.terse("Msg len={0} '{1}'\n".format(len(demsg), demsg)) self.assertEqual(len(demsg), 50) self.assertEqual(demsg, enmsg) # Pam remote public keyhex, cipher, nonce = priverBob.encrypt(enmsg, pubberPam.keyhex) #console.terse("Cipher len={0} '{1}'\nNonce len={2} '{3}'\n".format( #len(cipher), cipher, len(nonce), nonce)) self.assertEqual(len(cipher), 66) self.assertEqual(len(nonce), 24) # Bob public keyhex #console.terse("Decrypted by Pam local private and Bob remote public key pair\n") demsg = priverPam.decrypt(cipher, nonce, pubberBob.keyhex) #console.terse("Msg len={0} '{1}'\n".format(len(demsg), demsg)) self.assertEqual(len(demsg), 50) self.assertEqual(demsg, enmsg) # Pam remote public keyraw, cipher, nonce = priverBob.encrypt(enmsg, pubberPam.keyraw) #console.terse("Cipher len={0} '{1}'\nNonce len={2} '{3}'\n".format( #len(cipher), cipher, len(nonce), nonce)) self.assertEqual(len(cipher), 66) self.assertEqual(len(nonce), 24) # Bob public keyraw #console.terse("Decrypted by Pam local private and Bob remote public key pair\n") demsg = priverPam.decrypt(cipher, nonce, pubberBob.keyraw) #console.terse("Msg len={0} '{1}'\n".format(len(demsg), demsg)) self.assertEqual(len(demsg), 50) self.assertEqual(demsg, enmsg)
def setUp(self): self.priverBob = nacling.Privateer() self.pubberBob = nacling.Publican(self.priverBob.pubhex) self.priverPam = nacling.Privateer() self.pubberPam = nacling.Publican(self.priverPam.pubhex)
def setUp(self): self.store = Store(stamp=0.0) self.timer = StoreTimer(store=self.store, duration=1.0) self.dirpathBase = tempfile.mkdtemp(prefix="raet", suffix="base", dir=TEMPDIR) stacking.RoadStack.Bk = raeting.BodyKind.json.value #main stack mainName = "main" mainDirpath = os.path.join(self.dirpathBase, 'road', 'keep', mainName) signer = nacling.Signer() mainSignKeyHex = signer.keyhex mainVerKeyHex = signer.verhex privateer = nacling.Privateer() mainPriKeyHex = privateer.keyhex mainPubKeyHex = privateer.pubhex #other stack otherName = "other" otherDirpath = os.path.join(self.dirpathBase, 'road', 'keep', otherName) signer = nacling.Signer() otherSignKeyHex = signer.keyhex otherVerKeyHex = signer.verhex privateer = nacling.Privateer() otherPriKeyHex = privateer.keyhex otherPubKeyHex = privateer.pubhex keeping.clearAllKeep(mainDirpath) keeping.clearAllKeep(otherDirpath) self.main = stacking.RoadStack(name=mainName, uid=1, sigkey=mainSignKeyHex, prikey=mainPriKeyHex, auto=raeting.AutoMode.once.value, main=True, dirpath=mainDirpath, store=self.store) remote1 = estating.RemoteEstate( stack=self.main, uid=2, name=otherName, ha=("127.0.0.1", raeting.RAET_TEST_PORT), verkey=otherVerKeyHex, pubkey=otherPubKeyHex, ) self.main.addRemote(remote1) self.other = stacking.RoadStack(name=otherName, uid=2, auto=raeting.AutoMode.once.value, ha=("", raeting.RAET_TEST_PORT), sigkey=otherSignKeyHex, prikey=otherPriKeyHex, dirpath=otherDirpath, store=self.store) remote0 = estating.RemoteEstate( stack=self.other, uid=3, name=mainName, ha=('127.0.0.1', raeting.RAET_PORT), verkey=mainVerKeyHex, pubkey=mainPubKeyHex, ) self.other.addRemote(remote0) remote0.publee = nacling.Publican(key=remote1.privee.pubhex) remote1.publee = nacling.Publican(key=remote0.privee.pubhex) stuff = [] for i in range(300): stuff.append(str(i).rjust(4, " ")) self.stuff = ns2b("".join(stuff)) self.data = odict(hk=raeting.HeadKind.raet.value)
def setUp(self): self.store = storing.Store(stamp=0.0) self.timer = StoreTimer(store=self.store, duration=1.0) self.dirpathBase = tempfile.mkdtemp(prefix="raet", suffix="base", dir='/tmp') stacking.RoadStack.Bk = raeting.bodyKinds.json #main stack mainName = "main" mainDirpath = os.path.join(self.dirpathBase, 'road', 'keep', mainName) signer = nacling.Signer() mainSignKeyHex = signer.keyhex mainVerKeyHex = signer.verhex privateer = nacling.Privateer() mainPriKeyHex = privateer.keyhex mainPubKeyHex = privateer.pubhex #other stack otherName = "other" otherDirpath = os.path.join(self.dirpathBase, 'road', 'keep', otherName) signer = nacling.Signer() otherSignKeyHex = signer.keyhex otherVerKeyHex = signer.verhex privateer = nacling.Privateer() otherPriKeyHex = privateer.keyhex otherPubKeyHex = privateer.pubhex keeping.clearAllKeepSafe(mainDirpath) keeping.clearAllKeepSafe(otherDirpath) local = estating.LocalEstate( eid=1, name=mainName, sigkey=mainSignKeyHex, prikey=mainPriKeyHex, ) self.main = stacking.RoadStack(name=mainName, local=local, auto=True, main=True, dirpath=mainDirpath, store=self.store) remote1 = estating.RemoteEstate( stack=self.main, eid=2, name=otherName, ha=("127.0.0.1", raeting.RAET_TEST_PORT), verkey=otherVerKeyHex, pubkey=otherPubKeyHex, period=self.main.period, offset=self.main.offset, ) self.main.addRemote(remote1) local = estating.LocalEstate( eid=2, name=otherName, ha=("", raeting.RAET_TEST_PORT), sigkey=otherSignKeyHex, prikey=otherPriKeyHex, ) self.other = stacking.RoadStack(name=otherName, local=local, dirpath=otherDirpath, store=self.store) remote0 = estating.RemoteEstate( stack=self.other, eid=1, name=mainName, ha=('127.0.0.1', raeting.RAET_PORT), verkey=mainVerKeyHex, pubkey=mainPubKeyHex, period=self.other.period, offset=self.other.offset, ) self.other.addRemote(remote0) remote0.publee = nacling.Publican(key=remote1.privee.pubhex) remote1.publee = nacling.Publican(key=remote0.privee.pubhex) stuff = [] for i in range(300): stuff.append(str(i).rjust(4, " ")) self.stuff = "".join(stuff) self.data = odict(hk=raeting.headKinds.raet)