Ejemplo n.º 1
0
    def setUp(self):
        self.store = storing.Store(stamp=0.0)

        dirpathBase='/tmp/raet/'

        #main stack
        mainName = "main"
        mainDirpath = os.path.join(dirpathBase, 'road', 'keep', mainName)
        signer = nacling.Signer()
        mainSignKeyHex = signer.keyhex
        privateer = nacling.Privateer()
        mainPriKeyHex = privateer.keyhex


        #other stack
        otherName = "other"
        otherDirpath = os.path.join(dirpathBase, 'road', 'keep', otherName)
        signer = nacling.Signer()
        otherSignKeyHex = signer.keyhex
        privateer = nacling.Privateer()
        otherPriKeyHex = privateer.keyhex


        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)

        local = estating.LocalEstate(eid=0,
                                     name=otherName,
                                     ha=("", raeting.RAET_TEST_PORT),
                                     sigkey=otherSignKeyHex,
                                     prikey=otherPriKeyHex,)

        self.other = stacking.RoadStack(name=otherName,
                                         local=local,
                                         dirpath=otherDirpath,
                                         store=self.store)

        self.timer = StoreTimer(store=self.store, duration=1.0)
Ejemplo n.º 2
0
    def setUp(self):
        self.store = storing.Store(stamp=0.0)
        self.timer = StoreTimer(store=self.store, duration=1.0)

        self.baseDirpath = tempfile.mkdtemp(prefix="raet",
                                            suffix="base",
                                            dir=TEMPDIR)
        stacking.RoadStack.Bk = raeting.bodyKinds.json

        #main stack
        mainName = "main"
        mainDirpath = os.path.join(self.baseDirpath, 'road', 'keep', mainName)
        signer = nacling.Signer()
        mainSignKeyHex = signer.keyhex
        privateer = nacling.Privateer()
        mainPriKeyHex = privateer.keyhex

        #other stack
        otherName = "other"
        otherDirpath = os.path.join(self.baseDirpath, 'road', 'keep',
                                    otherName)
        signer = nacling.Signer()
        otherSignKeyHex = signer.keyhex
        privateer = nacling.Privateer()
        otherPriKeyHex = privateer.keyhex

        keeping.clearAllKeep(mainDirpath)
        keeping.clearAllKeep(otherDirpath)

        self.main = stacking.RoadStack(
            store=self.store,
            name=mainName,
            main=True,
            auto=raeting.autoModes.once,
            sigkey=mainSignKeyHex,
            prikey=mainPriKeyHex,
            dirpath=mainDirpath,
        )

        self.other = stacking.RoadStack(
            store=self.store,
            name=otherName,
            auto=raeting.autoModes.once,
            ha=("", raeting.RAET_TEST_PORT),
            sigkey=otherSignKeyHex,
            prikey=otherPriKeyHex,
            dirpath=otherDirpath,
        )
Ejemplo n.º 3
0
    def createRoadData(self,
                       base,
                       name='',
                       ha=None,
                       main=None,
                       auto=raeting.autoModes.never):
        '''
        name is local estate name (which is stack name property)
        base is the base directory for the keep files
        auto is the auto accept status mode ()
        Creates odict and populates with data to setup road stack

        '''
        data = odict()
        data['name'] = name
        data['ha'] = ha
        data['main'] = main
        data['auto'] = auto
        data['dirpath'] = os.path.join(base, 'road', 'keep', name)
        signer = nacling.Signer()
        data['sighex'] = signer.keyhex
        data['verhex'] = signer.verhex
        privateer = nacling.Privateer()
        data['prihex'] = privateer.keyhex
        data['pubhex'] = privateer.pubhex

        return data
Ejemplo n.º 4
0
    def createStack(self, name, port):
        '''
        Create a RoadStack object bound to the specified port on localhost.

        :param name: stack name
        :param port: port to bind to
        :return: the stack
        '''
        dirpath = os.path.join(self.baseDirpath, 'road', 'keep', name)
        signer = nacling.Signer()
        mainSignKeyHex = signer.keyhex
        privateer = nacling.Privateer()
        mainPriKeyHex = privateer.keyhex

        keeping.clearAllKeep(dirpath)

        return stacking.RoadStack(store=self.store,
                                  name=name,
                                  main=True,
                                  auto=raeting.AutoMode.once.value,
                                  ha=("", port),
                                  sigkey=mainSignKeyHex,
                                  prikey=mainPriKeyHex,
                                  dirpath=dirpath,
                                  )
Ejemplo n.º 5
0
    def createRoadData(self, name, base):
        '''
        Creates odict and populates with data to setup road stack
        {
            name: stack name local estate name
            dirpath: dirpath for keep files
            sighex: signing key
            verhex: verify key
            prihex: private key
            pubhex: public key
        }
        '''
        data = odict()
        data['name'] = name
        data['dirpath'] = os.path.join(base, 'road', 'keep', name)
        signer = nacling.Signer()
        data['sighex'] = signer.keyhex
        data['verhex'] = signer.verhex
        privateer = nacling.Privateer()
        data['prihex'] = privateer.keyhex
        data['pubhex'] = privateer.pubhex

        return data
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
 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)
Ejemplo n.º 8
0
    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)
Ejemplo n.º 9
0
def test():
    '''
    Test keeping.
    '''
    pkiDirpath = os.path.join('/tmp', 'raet', 'keyo', 'master', 'pki')
    if not os.path.exists(pkiDirpath):
        os.makedirs(pkiDirpath)

    acceptedDirpath = os.path.join(pkiDirpath, 'accepted')
    if not os.path.exists(acceptedDirpath):
        os.makedirs(acceptedDirpath)

    pendingDirpath = os.path.join(pkiDirpath, 'pending')
    if not os.path.exists(pendingDirpath):
        os.makedirs(pendingDirpath)

    rejectedDirpath = os.path.join(pkiDirpath, 'rejected')
    if not os.path.exists(rejectedDirpath):
        os.makedirs(rejectedDirpath)

    localFilepath = os.path.join(pkiDirpath, 'local.key')
    if os.path.exists(localFilepath):
        mode = os.stat(localFilepath).st_mode
        print mode
        os.chmod(localFilepath, mode | stat.S_IWUSR | stat.S_IRUSR)
        mode = os.stat(localFilepath).st_mode
        print mode

    cacheDirpath = os.path.join('/tmp/raet', 'cache', 'master')
    if not os.path.exists(cacheDirpath):
        os.makedirs(cacheDirpath)

    sockDirpath = os.path.join('/tmp/raet', 'sock', 'master')
    if not os.path.exists(sockDirpath):
        os.makedirs(sockDirpath)

    opts = dict(
        pki_dir=pkiDirpath,
        sock_dir=sockDirpath,
        cachedir=cacheDirpath,
        open_mode=True,
        auto_accept=True,
        transport='raet',
    )

    masterSafe = salting.SaltSafe(opts=opts)
    print("masterSafe local =\n{0}".format(masterSafe.loadLocalData()))
    print("masterSafe remote =\n{0}".format(masterSafe.loadAllRemoteData()))

    pkiDirpath = os.path.join('/tmp', 'raet', 'keyo', 'minion', 'pki')
    if not os.path.exists(pkiDirpath):
        os.makedirs(pkiDirpath)

    acceptedDirpath = os.path.join(pkiDirpath, 'accepted')
    if not os.path.exists(acceptedDirpath):
        os.makedirs(acceptedDirpath)

    pendingDirpath = os.path.join(pkiDirpath, 'pending')
    if not os.path.exists(pendingDirpath):
        os.makedirs(pendingDirpath)

    rejectedDirpath = os.path.join(pkiDirpath, 'rejected')
    if not os.path.exists(rejectedDirpath):
        os.makedirs(rejectedDirpath)

    localFilepath = os.path.join(pkiDirpath, 'local.key')
    if os.path.exists(localFilepath):
        mode = os.stat(localFilepath).st_mode
        print mode
        os.chmod(localFilepath, mode | stat.S_IWUSR | stat.S_IRUSR)
        mode = os.stat(localFilepath).st_mode
        print mode

    cacheDirpath = os.path.join('/tmp/raet', 'cache', 'minion')
    sockDirpath = os.path.join('/tmp/raet', 'sock', 'minion')

    opts = dict(
        pki_dir=pkiDirpath,
        sock_dir=sockDirpath,
        cachedir=cacheDirpath,
        open_mode=True,
        auto_accept=True,
        transport='raet',
    )

    minionSafe = salting.SaltSafe(opts=opts)
    print("minionSafe local =\n{0}".format(minionSafe.loadLocalData()))
    print("minionSafe remote =\n{0}".format(minionSafe.loadAllRemoteData()))

    masterName = 'master'
    masterDirpath = os.path.join('/tmp', 'raet', 'keep', masterName)
    signer = nacling.Signer()
    masterSignKeyHex = signer.keyhex
    masterVerKeyHex = signer.verhex
    privateer = nacling.Privateer()
    masterPriKeyHex = privateer.keyhex
    masterPubKeyHex = privateer.pubhex

    m1Name = 'minion1'
    m1Dirpath = os.path.join('/tmp', 'raet', 'keep', m1Name)
    signer = nacling.Signer()
    m1SignKeyHex = signer.keyhex
    m1VerKeyHex = signer.verhex
    privateer = nacling.Privateer()
    m1PriKeyHex = privateer.keyhex
    m1PubKeyHex = privateer.pubhex

    m2Name = 'minion2'
    signer = nacling.Signer()
    m2SignKeyHex = signer.keyhex
    m2VerKeyHex = signer.verhex
    privateer = nacling.Privateer()
    m2PriKeyHex = privateer.keyhex
    m2PubKeyHex = privateer.pubhex

    m3Name = 'minion3'
    signer = nacling.Signer()
    m3SignKeyHex = signer.keyhex
    m3VerKeyHex = signer.verhex
    privateer = nacling.Privateer()
    m3PriKeyHex = privateer.keyhex
    m3PubKeyHex = privateer.pubhex

    keeping.clearAllKeepSafe(masterDirpath)
    keeping.clearAllKeepSafe(m1Dirpath)

    #saltsafe = salting.SaltSafe(opts=opts)
    #print saltsafe.loadLocalData()
    #print saltsafe.loadAllRemoteData()

    #master stack
    local = estating.LocalEstate(
        eid=1,
        name=masterName,
        sigkey=masterSignKeyHex,
        prikey=masterPriKeyHex,
    )
    stack0 = stacking.RoadStack(local=local,
                                dirpath=masterDirpath,
                                safe=masterSafe)

    stack0.addRemote(
        estating.RemoteEstate(
            eid=2,
            name=m1Name,
            ha=('127.0.0.1', 7532),
            verkey=m1VerKeyHex,
            pubkey=m1PubKeyHex,
        ))

    stack0.addRemote(
        estating.RemoteEstate(
            eid=3,
            name=m2Name,
            ha=('127.0.0.1', 7533),
            verkey=m2VerKeyHex,
            pubkey=m2PubKeyHex,
        ))

    #minion stack
    local = estating.LocalEstate(
        eid=2,
        name=m1Name,
        ha=("", raeting.RAET_TEST_PORT),
        sigkey=m1SignKeyHex,
        prikey=m1PriKeyHex,
    )
    stack1 = stacking.RoadStack(local=local,
                                dirpath=m1Dirpath,
                                safe=minionSafe)

    stack1.addRemote(
        estating.RemoteEstate(
            eid=1,
            name=masterName,
            ha=('127.0.0.1', 7532),
            verkey=masterVerKeyHex,
            pubkey=masterPubKeyHex,
        ))

    stack1.addRemote(
        estating.RemoteEstate(
            eid=4,
            name=m3Name,
            ha=('127.0.0.1', 7534),
            verkey=m3VerKeyHex,
            pubkey=m3PubKeyHex,
        ))

    #stack0.clearLocal()
    stack0.clearRemoteKeeps()
    #stack1.clearLocal()
    stack1.clearRemoteKeeps()

    stack0.dumpLocal()
    stack0.dumpRemotes()

    stack1.dumpLocal()
    stack1.dumpRemotes()

    print "Road {0}".format(stack0.name)
    print stack0.keep.loadLocalData()
    print stack0.keep.loadAllRemoteData()
    print "Safe {0}".format(stack0.name)
    print stack0.safe.loadLocalData()
    print stack0.safe.loadAllRemoteData()
    print

    print "Road {0}".format(stack1.name)
    print stack1.keep.loadLocalData()
    print stack1.keep.loadAllRemoteData()
    print "Safe {0}".format(stack1.name)
    print stack1.safe.loadLocalData()
    print stack1.safe.loadAllRemoteData()

    stack0.server.close()
    stack1.server.close()

    #master stack
    dirpath = os.path.join('/tmp/raet', 'keep', 'master')
    local = estating.LocalEstate(
        eid=1,
        name='master',
        sigkey=masterSignKeyHex,
        prikey=masterPriKeyHex,
    )
    stack0 = stacking.RoadStack(local=local,
                                dirpath=masterDirpath,
                                safe=masterSafe)

    #minion stack
    dirpath = os.path.join('/tmp/raet', 'keep', 'minion1')
    local = estating.LocalEstate(
        eid=2,
        name='minion1',
        ha=("", raeting.RAET_TEST_PORT),
        sigkey=m1SignKeyHex,
        prikey=m1PriKeyHex,
    )
    stack1 = stacking.RoadStack(local=local,
                                dirpath=m1Dirpath,
                                safe=minionSafe)

    stack0.loadLocal()
    print stack0.local.name, stack0.local.eid, stack0.local.sid, stack0.local.ha, stack0.local.signer, stack0.local.priver
    stack1.loadLocal()
    print stack1.local.name, stack1.local.eid, stack1.local.sid, stack1.local.ha, stack1.local.signer, stack1.local.priver

    stack0.clearLocal()
    stack0.clearRemoteKeeps()
    stack1.clearLocal()
    stack1.clearRemoteKeeps()
Ejemplo n.º 10
0
def test(preClearMaster=False,
         preClearMinion=False,
         postClearMaster=False,
         postClearMinion=False):
    '''
    initially
    master on port 7530 with eid of 1
    minion on port 7531 with eid of 0
    eventually
    master eid of 1
    minion eid of 2
    '''
    console.reinit(verbosity=console.Wordage.concise)

    #transacting.Joiner.Timeout = 0 # make join go on forever

    store = storing.Store(stamp=0.0)

    #master stack
    masterName = "master"
    signer = nacling.Signer()
    masterSignKeyHex = signer.keyhex
    privateer = nacling.Privateer()
    masterPriKeyHex = privateer.keyhex
    masterDirpath = os.path.join('/tmp/raet/road', 'keep', masterName)

    #minion0 stack
    minionName0 = "minion0"
    signer = nacling.Signer()
    minionSignKeyHex = signer.keyhex
    privateer = nacling.Privateer()
    minionPriKeyHex = privateer.keyhex
    m0Dirpath = os.path.join('/tmp/raet/road', 'keep', minionName0)

    if preClearMaster:
        keeping.clearAllKeepSafe(masterDirpath)
    if preClearMinion:
        keeping.clearAllKeepSafe(m0Dirpath)

    local = estating.LocalEstate(
        eid=1,
        name=masterName,
        sigkey=masterSignKeyHex,
        prikey=masterPriKeyHex,
    )
    stack0 = stacking.RoadStack(name=masterName,
                                local=local,
                                store=store,
                                main=True,
                                dirpath=masterDirpath)

    local = estating.LocalEstate(
        eid=0,
        name=minionName0,
        ha=("", raeting.RAET_TEST_PORT),
        sigkey=minionSignKeyHex,
        prikey=minionPriKeyHex,
    )
    stack1 = stacking.RoadStack(name=minionName0,
                                local=local,
                                store=store,
                                dirpath=m0Dirpath)

    print "\n********* Join Transaction **********"
    stack1.join()
    #timer = StoreTimer(store=store, duration=3.0)
    while stack1.transactions or stack0.transactions:
        stack1.serviceAll()
        stack0.serviceAll()
        if store.stamp >= 0.3:
            for remote in stack0.remotes.values():
                if remote.acceptance == raeting.acceptances.pending:
                    stack0.safe.acceptRemote(remote)
        store.advanceStamp(0.1)

    for remote in stack0.remotes.values():
        print "Remote Estate {0} joined= {1}".format(remote.eid, remote.joined)
    for remote in stack1.remotes.values():
        print "Remote Estate {0} joined= {1}".format(remote.eid, remote.joined)

    print "{0} eid={1}".format(stack0.name, stack0.local.uid)
    print "{0} remotes=\n{1}".format(stack0.name, stack0.remotes)
    print "{0} transactions=\n{1}".format(stack0.name, stack0.transactions)
    print "{0} eid={1}".format(stack1.name, stack1.local.uid)
    print "{0} remotes=\n{1}".format(stack1.name, stack1.remotes)
    print "{0} transactions=\n{1}".format(stack1.name, stack1.transactions)

    print "Road {0}".format(stack0.name)
    print stack0.keep.loadLocalData()
    print stack0.keep.loadAllRemoteData()
    print "Safe {0}".format(stack0.name)
    print stack0.safe.loadLocalData()
    print stack0.safe.loadAllRemoteData()
    print

    print "Road {0}".format(stack1.name)
    print stack1.keep.loadLocalData()
    print stack1.keep.loadAllRemoteData()
    print "Safe {0}".format(stack1.name)
    print stack1.safe.loadLocalData()
    print stack1.safe.loadAllRemoteData()
    print

    print "{0} Stats".format(stack0.name)
    for key, val in stack0.stats.items():
        print "   {0}={1}".format(key, val)
    print
    print "{0} Stats".format(stack1.name)
    for key, val in stack1.stats.items():
        print "   {0}={1}".format(key, val)
    print

    stack0.server.close()
    stack1.server.close()

    if postClearMaster:
        keeping.clearAllKeepSafe(masterDirpath)
    if postClearMinion:
        keeping.clearAllKeepSafe(m0Dirpath)
Ejemplo n.º 11
0
    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)
Ejemplo n.º 12
0
def test(preClearMaster=True,
         preClearMinion=True,
         postClearMaster=True,
         postClearMinion=True):
    '''
    initially
    master on port 7530 with eid of 1
    minion on port 7531 with eid of 0
    eventually
    master eid of 1
    minion eid of 2
    '''
    console.reinit(verbosity=console.Wordage.concise)

    store = storing.Store(stamp=0.0)

    #master stack
    masterName = "master"
    signer = nacling.Signer()
    masterSignKeyHex = signer.keyhex
    privateer = nacling.Privateer()
    masterPriKeyHex = privateer.keyhex
    masterDirpath = os.path.join('/tmp/raet/road', 'keep', masterName)

    #minion0 stack
    minionName0 = "minion0"
    signer = nacling.Signer()
    minionSignKeyHex = signer.keyhex
    privateer = nacling.Privateer()
    minionPriKeyHex = privateer.keyhex
    m0Dirpath = os.path.join('/tmp/raet/road', 'keep', minionName0)

    if preClearMaster:
        keeping.clearAllKeepSafe(masterDirpath)
    if preClearMinion:
        keeping.clearAllKeepSafe(m0Dirpath)

    local = estating.LocalEstate(
        eid=1,
        name=masterName,
        sigkey=masterSignKeyHex,
        prikey=masterPriKeyHex,
    )
    stack0 = stacking.RoadStack(name=masterName,
                                local=local,
                                auto=True,
                                store=store,
                                main=True,
                                dirpath=masterDirpath)

    local = estating.LocalEstate(
        eid=0,
        name=minionName0,
        ha=("", raeting.RAET_TEST_PORT),
        sigkey=minionSignKeyHex,
        prikey=minionPriKeyHex,
    )
    stack1 = stacking.RoadStack(name=minionName0,
                                local=local,
                                store=store,
                                dirpath=m0Dirpath)

    print "\n********* Join Forever Transaction **********"
    #transacting.Joiner.Timeout = 0 # make join go on forever
    stack1.join(timeout=0.0)  # make join go on forever
    timer = StoreTimer(store=store, duration=30.0)
    while (stack1.transactions or stack0.transactions) and not timer.expired:
        stack1.serviceAll()
        if timer.elapsed > 20.0:
            stack0.serviceAll()
        store.advanceStamp(0.1)

    for remote in stack0.remotes.values():
        print "{0} Remote Estate {1} joined= {2}".format(
            stack0.name, remote.eid, remote.joined)
    for remote in stack1.remotes.values():
        print "{0} Remote Estate {1} joined= {2}".format(
            stack1.name, remote.eid, remote.joined)

    print "{0} Stats".format(stack0.name)
    for key, val in stack0.stats.items():
        print "   {0}={1}".format(key, val)
    print
    print "{0} Stats".format(stack1.name)
    for key, val in stack1.stats.items():
        print "   {0}={1}".format(key, val)
    print

    print "\n********* Join Default Timeout Transaction **********"
    stack1.join(timeout=None)
    timer.restart()
    while (stack1.transactions or stack0.transactions) and not timer.expired:
        stack1.serviceAll()
        if timer.elapsed > 20.0:
            stack0.serviceAll()
        store.advanceStamp(0.1)

    for remote in stack0.remotes.values():
        print "{0} Remote Estate {1} joined= {2}".format(
            stack0.name, remote.eid, remote.joined)
    for remote in stack1.remotes.values():
        print "{0} Remote Estate {1} joined= {2}".format(
            stack1.name, remote.eid, remote.joined)
    print "{0} Stats".format(stack0.name)
    for key, val in stack0.stats.items():
        print "   {0}={1}".format(key, val)
    print
    print "{0} Stats".format(stack1.name)
    for key, val in stack1.stats.items():
        print "   {0}={1}".format(key, val)
    print

    for uid in stack0.remotes:
        stack0.removeRemote(uid)
    for uid in stack1.remotes:
        stack1.removeRemote(uid)

    if postClearMaster:
        keeping.clearAllKeepSafe(masterDirpath)
    if postClearMinion:
        keeping.clearAllKeepSafe(m0Dirpath)

    print "Road {0}".format(stack0.name)
    print stack0.keep.loadLocalData()
    print stack0.keep.loadAllRemoteData()
    print "Safe {0}".format(stack0.name)
    print stack0.safe.loadLocalData()
    print stack0.safe.loadAllRemoteData()
    print

    print "Road {0}".format(stack1.name)
    print stack1.keep.loadLocalData()
    print stack1.keep.loadAllRemoteData()
    print "Safe {0}".format(stack1.name)
    print stack1.safe.loadLocalData()
    print stack1.safe.loadAllRemoteData()
    print

    print "\n********* Join Default Timeout Transaction After Clear Keeps **********"
    stack1.join(timeout=None)
    timer.restart()
    while (stack1.transactions or stack0.transactions) and not timer.expired:
        stack1.serviceAll()
        if timer.elapsed > 20.0:
            stack0.serviceAll()
        store.advanceStamp(0.1)

    for remote in stack0.remotes.values():
        print "{0} Remote Estate {1} joined= {2}".format(
            stack0.name, remote.eid, remote.joined)
    for remote in stack1.remotes.values():
        print "{0} Remote Estate {1} joined= {2}".format(
            stack1.name, remote.eid, remote.joined)

    print "{0} Stats".format(stack0.name)
    for key, val in stack0.stats.items():
        print "   {0}={1}".format(key, val)
    print
    print "{0} Stats".format(stack1.name)
    for key, val in stack1.stats.items():
        print "   {0}={1}".format(key, val)
    print

    print "\n********* Join Forever Timeout Transaction After Clear Keeps**********"
    stack1.join(timeout=0.0)
    timer.restart()
    while (stack1.transactions or stack0.transactions) and not timer.expired:
        stack1.serviceAll()
        if timer.elapsed > 20.0:
            stack0.serviceAll()
        store.advanceStamp(0.1)

    for remote in stack0.remotes.values():
        print "{0} Remote Estate {1} joined= {2}".format(
            stack0.name, remote.eid, remote.joined)
    for remote in stack1.remotes.values():
        print "{0} Remote Estate {1} joined= {2}".format(
            stack1.name, remote.eid, remote.joined)

    print "{0} Stats".format(stack0.name)
    for key, val in stack0.stats.items():
        print "   {0}={1}".format(key, val)
    print
    print "{0} Stats".format(stack1.name)
    for key, val in stack1.stats.items():
        print "   {0}={1}".format(key, val)
    print

    stack0.server.close()
    stack1.server.close()

    if postClearMaster:
        keeping.clearAllKeepSafe(masterDirpath)
    if postClearMinion:
        keeping.clearAllKeepSafe(m0Dirpath)
Ejemplo n.º 13
0
    def testJoinentVacuousAcceptNewKeys(self):
        '''
        Test joinent accept vacuous join with an updated keys (D5)
        '''
        console.terse("{0}\n".format(
            self.testJoinentVacuousAcceptNewKeys.__doc__))

        # Status: Accepted (auto accept keys)
        # Mode: Never, Once, Always
        alpha, beta = self.bootstrapJoinedRemotes()
        # Mutable: Yes
        alpha.mutable = True

        # Vacuous: Yes
        betaRemote = beta.addRemote(
            estating.RemoteEstate(
                stack=beta,
                fuid=0,  # vacuous join
                sid=0,  # always 0 for join
                ha=alpha.local.ha))

        # Ephemeral: No Name (the name is known)
        alphaRemote = estating.RemoteEstate(stack=alpha,
                                            fuid=betaRemote.nuid,
                                            ha=beta.local.ha,
                                            name=beta.name,
                                            verkey=beta.local.signer.verhex,
                                            pubkey=beta.local.priver.pubhex)
        alpha.addRemote(alphaRemote)

        # Name: Old
        # Main: Either
        # Appl: Either
        # RHA:  Either
        # Nuid: Computed
        # Fuid: Either
        # Leid: 0
        # Reid: Either
        # Role: Old
        # Keys: New
        beta.local.signer = nacling.Signer()
        beta.local.priver = nacling.Privateer()
        # Sameness: Not sameall
        keep = self.copyData(alphaRemote)

        # Test
        self.join(beta, alpha, deid=betaRemote.nuid)

        # Action: Accept, Dump
        for stack in [alpha, beta]:
            self.assertEqual(len(stack.transactions), 0)
            self.assertEqual(len(stack.remotes), 1)
            self.assertEqual(len(stack.nameRemotes), 1)
            for remote in stack.remotes.values():
                self.assertIs(remote.joined, True)
                self.assertIs(remote.allowed, None)
                self.assertIs(remote.alived, None)
        self.assertIs(beta.mutable, None)
        self.assertIs(alpha.mutable, True)
        self.assertIs(self.sameAll(alphaRemote, keep), False)
        self.assertIs(self.sameRoleKeys(alphaRemote, keep), False)
        self.assertEqual(alphaRemote.verfer.keyhex, beta.local.signer.verhex)
        self.assertEqual(alphaRemote.pubber.keyhex, beta.local.priver.pubhex)
        self.assertEqual(alphaRemote.acceptance, raeting.acceptances.accepted)
        self.assertEqual(betaRemote.acceptance, raeting.acceptances.accepted)

        # Keys: New
        beta.local.priver = nacling.Privateer()
        betaRemote.fuid = 0
        betaRemote.sid = 0

        for stack in [alpha, beta]:
            stack.server.close()
            stack.clearAllKeeps()