class BasicTestCase(unittest.TestCase): """""" def setUp(self): self.store = storing.Store(stamp=0.0) self.timer = StoreTimer(store=self.store, duration=1.0) self.saltDirpath = tempfile.mkdtemp(prefix="salt", suffix="main", dir='/tmp') pkiDirpath = os.path.join(self.saltDirpath, '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) self.localFilepath = os.path.join(pkiDirpath, 'local.key') if os.path.exists(self.localFilepath): mode = os.stat(self.localFilepath).st_mode os.chmod(self.localFilepath, mode | stat.S_IWUSR | stat.S_IWUSR) self.cacheDirpath = os.path.join(self.saltDirpath, 'cache') self.sockDirpath = os.path.join(self.saltDirpath, 'sock') self.opts = dict( __role='master', id='master', pki_dir=pkiDirpath, sock_dir=self.sockDirpath, cachedir=self.cacheDirpath, open_mode=False, auto_accept=True, transport='raet', ) self.mainKeeper = RaetKey(opts=self.opts) self.baseDirpath = tempfile.mkdtemp(prefix="salt", suffix="base", dir='/tmp') def tearDown(self): if os.path.exists(self.saltDirpath): shutil.rmtree(self.saltDirpath) 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 def testAutoAccept(self): ''' Basic function of RaetKey in auto accept mode ''' console.terse("{0}\n".format(self.testAutoAccept.__doc__)) self.opts['auto_accept'] = True self.assertTrue(self.opts['auto_accept']) self.assertDictEqual(self.mainKeeper.all_keys(), {'accepted': [], 'local': [], 'rejected': [], 'pending': []}) localkeys = self.mainKeeper.read_local() self.assertDictEqual(localkeys, {}) main = self.createRoadData(name='main', base=self.baseDirpath) self.mainKeeper.write_local(main['prihex'], main['sighex']) localkeys = self.mainKeeper.read_local() self.assertDictEqual(localkeys, {'priv': main['prihex'], 'sign': main['sighex']}) allkeys = self.mainKeeper.all_keys() self.assertDictEqual(allkeys, {'accepted': [], 'local': [self.localFilepath], 'rejected': [], 'pending': []}) other1 = self.createRoadData(name='other1', base=self.baseDirpath) other2 = self.createRoadData(name='other2', base=self.baseDirpath) status = self.mainKeeper.status(other1['name'], other1['pubhex'], other1['verhex']) self.assertEqual(status, 'accepted') status = self.mainKeeper.status(other2['name'], other2['pubhex'], other2['verhex']) self.assertEqual(status, 'accepted') allkeys = self.mainKeeper.all_keys() self.assertDictEqual(allkeys, {'accepted': ['other1', 'other2'], 'local': [self.localFilepath], 'pending': [], 'rejected': []} ) remotekeys = self.mainKeeper.read_remote(other1['name']) self.assertDictEqual(remotekeys, { 'minion_id': 'other1', 'pub': other1['pubhex'], 'verify': other1['verhex']} ) remotekeys = self.mainKeeper.read_remote(other2['name']) self.assertDictEqual(remotekeys, { 'minion_id': 'other2', 'pub': other2['pubhex'], 'verify': other2['verhex']} ) listkeys = self.mainKeeper.list_keys() self.assertDictEqual(listkeys, {'accepted': ['other1', 'other2'], 'rejected': [], 'pending': []}) allremotekeys = self.mainKeeper.read_all_remote() self.assertDictEqual(allremotekeys, {'other1': {'verify': other1['verhex'], 'minion_id': 'other1', 'acceptance': 'accepted', 'pub': other1['pubhex'],}, 'other2': {'verify': other2['verhex'], 'minion_id': 'other2', 'acceptance': 'accepted', 'pub': other2['pubhex'],} }) def testManualAccept(self): ''' Basic function of RaetKey in non auto accept mode ''' console.terse("{0}\n".format(self.testAutoAccept.__doc__)) self.opts['auto_accept'] = False self.assertFalse(self.opts['auto_accept']) self.assertDictEqual(self.mainKeeper.all_keys(), {'accepted': [], 'local': [], 'rejected': [], 'pending': []}) localkeys = self.mainKeeper.read_local() self.assertDictEqual(localkeys, {}) main = self.createRoadData(name='main', base=self.baseDirpath) self.mainKeeper.write_local(main['prihex'], main['sighex']) localkeys = self.mainKeeper.read_local() self.assertDictEqual(localkeys, {'priv': main['prihex'], 'sign': main['sighex']}) allkeys = self.mainKeeper.all_keys() self.assertDictEqual(allkeys, {'accepted': [], 'local': [self.localFilepath], 'rejected': [], 'pending': []}) other1 = self.createRoadData(name='other1', base=self.baseDirpath) other2 = self.createRoadData(name='other2', base=self.baseDirpath) status = self.mainKeeper.status(other1['name'], other1['pubhex'], other1['verhex']) self.assertEqual(status, 'pending') status = self.mainKeeper.status(other2['name'], other2['pubhex'], other2['verhex']) self.assertEqual(status, 'pending') allkeys = self.mainKeeper.all_keys() self.assertDictEqual(allkeys, {'accepted': [], 'local': [self.localFilepath], 'pending': ['other1', 'other2'], 'rejected': []} ) remotekeys = self.mainKeeper.read_remote(other1['name']) self.assertDictEqual(remotekeys, {}) remotekeys = self.mainKeeper.read_remote(other2['name']) self.assertDictEqual(remotekeys, {}) listkeys = self.mainKeeper.list_keys() self.assertDictEqual(listkeys, {'accepted': [], 'rejected': [], 'pending': ['other1', 'other2']}) allremotekeys = self.mainKeeper.read_all_remote() self.assertDictEqual(allremotekeys, {'other1': {'verify': other1['verhex'], 'minion_id': 'other1', 'acceptance': 'pending', 'pub': other1['pubhex'],}, 'other2': {'verify': other2['verhex'], 'minion_id': 'other2', 'acceptance': 'pending', 'pub': other2['pubhex'],} }) self.mainKeeper.accept_all() allkeys = self.mainKeeper.all_keys() self.assertDictEqual(allkeys, {'accepted': ['other1', 'other2'], 'local': [self.localFilepath], 'pending': [], 'rejected': []} ) remotekeys = self.mainKeeper.read_remote(other1['name']) self.assertDictEqual(remotekeys, { 'minion_id': 'other1', 'pub': other1['pubhex'], 'verify': other1['verhex']} ) remotekeys = self.mainKeeper.read_remote(other2['name']) self.assertDictEqual(remotekeys, { 'minion_id': 'other2', 'pub': other2['pubhex'], 'verify': other2['verhex']} ) listkeys = self.mainKeeper.list_keys() self.assertDictEqual(listkeys, {'accepted': ['other1', 'other2'], 'rejected': [], 'pending': []}) allremotekeys = self.mainKeeper.read_all_remote() self.assertDictEqual(allremotekeys, {'other1': {'verify': other1['verhex'], 'minion_id': 'other1', 'acceptance': 'accepted', 'pub': other1['pubhex'],}, 'other2': {'verify': other2['verhex'], 'minion_id': 'other2', 'acceptance': 'accepted', 'pub': other2['pubhex'],} }) def testDelete(self): ''' Basic function of RaetKey to delete key ''' console.terse("{0}\n".format(self.testDelete.__doc__)) self.opts['auto_accept'] = True self.assertTrue(self.opts['auto_accept']) self.assertDictEqual(self.mainKeeper.all_keys(), {'accepted': [], 'local': [], 'rejected': [], 'pending': []}) localkeys = self.mainKeeper.read_local() self.assertDictEqual(localkeys, {}) main = self.createRoadData(name='main', base=self.baseDirpath) self.mainKeeper.write_local(main['prihex'], main['sighex']) localkeys = self.mainKeeper.read_local() self.assertDictEqual(localkeys, {'priv': main['prihex'], 'sign': main['sighex']}) allkeys = self.mainKeeper.all_keys() self.assertDictEqual(allkeys, {'accepted': [], 'local': [self.localFilepath], 'rejected': [], 'pending': []}) other1 = self.createRoadData(name='other1', base=self.baseDirpath) other2 = self.createRoadData(name='other2', base=self.baseDirpath) status = self.mainKeeper.status(other1['name'], other1['pubhex'], other1['verhex']) self.assertEqual(status, 'accepted') status = self.mainKeeper.status(other2['name'], other2['pubhex'], other2['verhex']) self.assertEqual(status, 'accepted') allkeys = self.mainKeeper.all_keys() self.assertDictEqual(allkeys, {'accepted': ['other1', 'other2'], 'local': [self.localFilepath], 'pending': [], 'rejected': []} ) remotekeys = self.mainKeeper.read_remote(other1['name']) self.assertDictEqual(remotekeys, { 'minion_id': 'other1', 'pub': other1['pubhex'], 'verify': other1['verhex']} ) remotekeys = self.mainKeeper.read_remote(other2['name']) self.assertDictEqual(remotekeys, { 'minion_id': 'other2', 'pub': other2['pubhex'], 'verify': other2['verhex']} ) listkeys = self.mainKeeper.list_keys() self.assertDictEqual(listkeys, {'accepted': ['other1', 'other2'], 'rejected': [], 'pending': []}) allremotekeys = self.mainKeeper.read_all_remote() self.assertDictEqual(allremotekeys, {'other1': {'verify': other1['verhex'], 'minion_id': 'other1', 'acceptance': 'accepted', 'pub': other1['pubhex']}, 'other2': {'verify': other2['verhex'], 'minion_id': 'other2', 'acceptance': 'accepted', 'pub': other2['pubhex'],} }) self.mainKeeper.delete_key(match=other1['name']) allkeys = self.mainKeeper.all_keys() self.assertDictEqual(allkeys, {'accepted': ['other2'], 'local': [self.localFilepath], 'pending': [], 'rejected': []} ) remotekeys = self.mainKeeper.read_remote(other1['name']) self.assertDictEqual(remotekeys, {} ) remotekeys = self.mainKeeper.read_remote(other2['name']) self.assertDictEqual(remotekeys, { 'minion_id': 'other2', 'pub': other2['pubhex'], 'verify': other2['verhex']} ) listkeys = self.mainKeeper.list_keys() self.assertDictEqual(listkeys, {'accepted': [ 'other2'], 'rejected': [], 'pending': []}) allremotekeys = self.mainKeeper.read_all_remote() self.assertDictEqual(allremotekeys, { 'other2': {'verify': other2['verhex'], 'minion_id': 'other2', 'acceptance': 'accepted', 'pub': other2['pubhex'],} })
class BasicTestCase(unittest.TestCase): """""" def setUp(self): self.store = storing.Store(stamp=0.0) self.timer = StoreTimer(store=self.store, duration=1.0) self.saltDirpath = tempfile.mkdtemp(prefix="salt", suffix="main", dir='/tmp') pkiDirpath = os.path.join(self.saltDirpath, '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) self.localFilepath = os.path.join(pkiDirpath, 'local.key') if os.path.exists(self.localFilepath): mode = os.stat(self.localFilepath).st_mode os.chmod(self.localFilepath, mode | stat.S_IWUSR | stat.S_IWUSR) self.cacheDirpath = os.path.join(self.saltDirpath, 'cache') self.sockDirpath = os.path.join(self.saltDirpath, 'sock') self.opts = dict( pki_dir=pkiDirpath, sock_dir=self.sockDirpath, cachedir=self.cacheDirpath, open_mode=False, auto_accept=True, transport='raet', ) self.mainKeeper = RaetKey(opts=self.opts) self.baseDirpath = tempfile.mkdtemp(prefix="salt", suffix="base", dir='/tmp') def tearDown(self): if os.path.exists(self.saltDirpath): shutil.rmtree(self.saltDirpath) 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 def testAutoAccept(self): ''' Basic function of RaetKey in auto accept mode ''' console.terse("{0}\n".format(self.testAutoAccept.__doc__)) self.opts['auto_accept'] = True self.assertTrue(self.opts['auto_accept']) self.assertDictEqual(self.mainKeeper.all_keys(), { 'accepted': [], 'local': [], 'rejected': [], 'pending': [] }) localkeys = self.mainKeeper.read_local() self.assertDictEqual(localkeys, {}) main = self.createRoadData(name='main', base=self.baseDirpath) self.mainKeeper.write_local(main['prihex'], main['sighex']) localkeys = self.mainKeeper.read_local() self.assertDictEqual(localkeys, { 'priv': main['prihex'], 'sign': main['sighex'] }) allkeys = self.mainKeeper.all_keys() self.assertDictEqual( allkeys, { 'accepted': [], 'local': [self.localFilepath], 'rejected': [], 'pending': [] }) other1 = self.createRoadData(name='other1', base=self.baseDirpath) other2 = self.createRoadData(name='other2', base=self.baseDirpath) status = self.mainKeeper.status(other1['name'], 2, other1['pubhex'], other1['verhex']) self.assertEqual(status, 'accepted') status = self.mainKeeper.status(other2['name'], 3, other2['pubhex'], other2['verhex']) self.assertEqual(status, 'accepted') allkeys = self.mainKeeper.all_keys() self.assertDictEqual( allkeys, { 'accepted': ['other1', 'other2'], 'local': [self.localFilepath], 'pending': [], 'rejected': [] }) remotekeys = self.mainKeeper.read_remote(other1['name']) self.assertDictEqual( remotekeys, { 'device_id': 2, 'minion_id': 'other1', 'pub': other1['pubhex'], 'verify': other1['verhex'] }) remotekeys = self.mainKeeper.read_remote(other2['name']) self.assertDictEqual( remotekeys, { 'device_id': 3, 'minion_id': 'other2', 'pub': other2['pubhex'], 'verify': other2['verhex'] }) listkeys = self.mainKeeper.list_keys() self.assertDictEqual(listkeys, { 'accepted': ['other1', 'other2'], 'rejected': [], 'pending': [] }) allremotekeys = self.mainKeeper.read_all_remote() self.assertDictEqual( allremotekeys, { 2: { 'verify': other1['verhex'], 'minion_id': 'other1', 'acceptance': 'accepted', 'pub': other1['pubhex'], 'device_id': 2 }, 3: { 'verify': other2['verhex'], 'minion_id': 'other2', 'acceptance': 'accepted', 'pub': other2['pubhex'], 'device_id': 3 } }) def testManualAccept(self): ''' Basic function of RaetKey in non auto accept mode ''' console.terse("{0}\n".format(self.testAutoAccept.__doc__)) self.opts['auto_accept'] = False self.assertFalse(self.opts['auto_accept']) self.assertDictEqual(self.mainKeeper.all_keys(), { 'accepted': [], 'local': [], 'rejected': [], 'pending': [] }) localkeys = self.mainKeeper.read_local() self.assertDictEqual(localkeys, {}) main = self.createRoadData(name='main', base=self.baseDirpath) self.mainKeeper.write_local(main['prihex'], main['sighex']) localkeys = self.mainKeeper.read_local() self.assertDictEqual(localkeys, { 'priv': main['prihex'], 'sign': main['sighex'] }) allkeys = self.mainKeeper.all_keys() self.assertDictEqual( allkeys, { 'accepted': [], 'local': [self.localFilepath], 'rejected': [], 'pending': [] }) other1 = self.createRoadData(name='other1', base=self.baseDirpath) other2 = self.createRoadData(name='other2', base=self.baseDirpath) status = self.mainKeeper.status(other1['name'], 2, other1['pubhex'], other1['verhex']) self.assertEqual(status, 'pending') status = self.mainKeeper.status(other2['name'], 3, other2['pubhex'], other2['verhex']) self.assertEqual(status, 'pending') allkeys = self.mainKeeper.all_keys() self.assertDictEqual( allkeys, { 'accepted': [], 'local': [self.localFilepath], 'pending': ['other1', 'other2'], 'rejected': [] }) remotekeys = self.mainKeeper.read_remote(other1['name']) self.assertDictEqual(remotekeys, {}) remotekeys = self.mainKeeper.read_remote(other2['name']) self.assertDictEqual(remotekeys, {}) listkeys = self.mainKeeper.list_keys() self.assertDictEqual(listkeys, { 'accepted': [], 'rejected': [], 'pending': ['other1', 'other2'] }) allremotekeys = self.mainKeeper.read_all_remote() self.assertDictEqual( allremotekeys, { 2: { 'verify': other1['verhex'], 'minion_id': 'other1', 'acceptance': 'pending', 'pub': other1['pubhex'], 'device_id': 2 }, 3: { 'verify': other2['verhex'], 'minion_id': 'other2', 'acceptance': 'pending', 'pub': other2['pubhex'], 'device_id': 3 } }) self.mainKeeper.accept_all() allkeys = self.mainKeeper.all_keys() self.assertDictEqual( allkeys, { 'accepted': ['other1', 'other2'], 'local': [self.localFilepath], 'pending': [], 'rejected': [] }) remotekeys = self.mainKeeper.read_remote(other1['name']) self.assertDictEqual( remotekeys, { 'device_id': 2, 'minion_id': 'other1', 'pub': other1['pubhex'], 'verify': other1['verhex'] }) remotekeys = self.mainKeeper.read_remote(other2['name']) self.assertDictEqual( remotekeys, { 'device_id': 3, 'minion_id': 'other2', 'pub': other2['pubhex'], 'verify': other2['verhex'] }) listkeys = self.mainKeeper.list_keys() self.assertDictEqual(listkeys, { 'accepted': ['other1', 'other2'], 'rejected': [], 'pending': [] }) allremotekeys = self.mainKeeper.read_all_remote() self.assertDictEqual( allremotekeys, { 2: { 'verify': other1['verhex'], 'minion_id': 'other1', 'acceptance': 'accepted', 'pub': other1['pubhex'], 'device_id': 2 }, 3: { 'verify': other2['verhex'], 'minion_id': 'other2', 'acceptance': 'accepted', 'pub': other2['pubhex'], 'device_id': 3 } })
def test(): """ Test keeping. """ pkiDirpath = os.path.join(os.getcwd(), "keyo", "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_IWUSR) cacheDirpath = os.path.join(os.getcwd(), "salt", "cache") sockDirpath = os.path.join("/tmp/raet", "salt", "sock") opts = dict(pki_dir=pkiDirpath, sock_dir=sockDirpath, cachedir=cacheDirpath, open_mode=True, auto_accept=True) masterKeeper = RaetKey(opts=opts) print masterKeeper.all_keys() masterName = "master" masterDirpath = os.path.join(os.getcwd(), "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(os.getcwd(), "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) local = masterKeeper.read_local() print local if not local: masterKeeper.write_local(masterPriKeyHex, masterSignKeyHex) print masterKeeper.read_local() print masterKeeper.all_keys() print masterKeeper.status(m1Name, 2, m1PubKeyHex, m1VerKeyHex) print masterKeeper.status(m2Name, 3, m2PubKeyHex, m2VerKeyHex) print masterKeeper.all_keys() print masterKeeper.read_remote(m1Name) print masterKeeper.read_remote(m2Name) print masterKeeper.list_keys() print masterKeeper.read_all_remote() # master stack estate = estating.LocalEstate(eid=1, name=masterName, sigkey=masterSignKeyHex, prikey=masterPriKeyHex) stack0 = stacking.RoadStack(estate=estate, dirpath=masterDirpath) 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 estate = estating.LocalEstate( eid=2, name=m1Name, ha=("", raeting.RAET_TEST_PORT), sigkey=m1SignKeyHex, prikey=m1PriKeyHex ) stack1 = stacking.RoadStack(estate=estate, dirpath=m1Dirpath) 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.road.loadLocalData() print stack0.road.loadAllRemoteData() print "Safe {0}".format(stack0.name) print stack0.safe.loadLocalData() print stack0.safe.loadAllRemoteData() print print "Road {0}".format(stack1.name) print stack1.road.loadLocalData() print stack1.road.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(os.getcwd(), "keep", "master") estate = estating.LocalEstate(eid=1, name="master", sigkey=masterSignKeyHex, prikey=masterPriKeyHex) stack0 = stacking.RoadStack(estate=estate, dirpath=masterDirpath) # minion stack dirpath = os.path.join(os.getcwd(), "keep", "minion1") estate = estating.LocalEstate( eid=2, name="minion1", ha=("", raeting.RAET_TEST_PORT), sigkey=m1SignKeyHex, prikey=m1PriKeyHex ) stack1 = stacking.RoadStack(estate=estate, dirpath=m1Dirpath) estate0 = stack0.loadLocal() print estate0.name, estate0.eid, estate0.sid, estate0.ha, estate0.signer, estate0.priver estate1 = stack1.loadLocal() print estate1.name, estate1.eid, estate1.sid, estate1.ha, estate1.signer, estate1.priver stack0.clearLocal() stack0.clearRemoteKeeps() stack1.clearLocal() stack1.clearRemoteKeeps()
def test(): ''' Test keeping. ''' pkiDirpath = os.path.join(os.getcwd(), 'keyo', '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_IWUSR) cacheDirpath = os.path.join(os.getcwd(), 'salt', 'cache') sockDirpath = os.path.join('/tmp/raet', 'salt', 'sock') opts = dict( pki_dir=pkiDirpath, sock_dir=sockDirpath, cachedir=cacheDirpath, open_mode=True, auto_accept=True, ) masterKeeper = RaetKey(opts=opts) print masterKeeper.all_keys() masterName = 'master' masterDirpath = os.path.join(os.getcwd(), '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(os.getcwd(), '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.clearAllRoadSafe(masterDirpath) keeping.clearAllRoadSafe(m1Dirpath) local = masterKeeper.read_local() print local if not local: masterKeeper.write_local(masterPriKeyHex, masterSignKeyHex) print masterKeeper.read_local() print masterKeeper.all_keys() print masterKeeper.status(m1Name, 2, m1PubKeyHex, m1VerKeyHex) print masterKeeper.status(m2Name, 3, m2PubKeyHex, m2VerKeyHex) print masterKeeper.all_keys() print masterKeeper.read_remote(m1Name) print masterKeeper.read_remote(m2Name) print masterKeeper.list_keys() print masterKeeper.read_all_remote() #master stack estate = estating.LocalEstate( eid=1, name=masterName, sigkey=masterSignKeyHex, prikey=masterPriKeyHex,) stack0 = stacking.StackUdp(estate=estate, dirpath=masterDirpath) 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 estate = estating.LocalEstate( eid=2, name=m1Name, ha=("", raeting.RAET_TEST_PORT), sigkey=m1SignKeyHex, prikey=m1PriKeyHex,) stack1 = stacking.StackUdp(estate=estate, dirpath=m1Dirpath) 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.clearAllRemote() stack1.clearLocal() stack1.clearAllRemote() stack0.dumpLocal() stack0.dumpAllRemote() stack1.dumpLocal() stack1.dumpAllRemote() print "Road {0}".format(stack0.name) print stack0.road.loadLocalData() print stack0.road.loadAllRemoteData() print "Safe {0}".format(stack0.name) print stack0.safe.loadLocalData() print stack0.safe.loadAllRemoteData() print print "Road {0}".format(stack1.name) print stack1.road.loadLocalData() print stack1.road.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(os.getcwd(), 'keep', 'master') estate = estating.LocalEstate( eid=1, name='master', sigkey=masterSignKeyHex, prikey=masterPriKeyHex,) stack0 = stacking.StackUdp(estate=estate, dirpath=masterDirpath) #minion stack dirpath = os.path.join(os.getcwd(), 'keep', 'minion1') estate = estating.LocalEstate( eid=2, name='minion1', ha=("", raeting.RAET_TEST_PORT), sigkey=m1SignKeyHex, prikey=m1PriKeyHex,) stack1 = stacking.StackUdp(estate=estate, dirpath=m1Dirpath) estate0 = stack0.loadLocal() print estate0.name, estate0.eid, estate0.sid, estate0.ha, estate0.signer, estate0.priver estate1 = stack1.loadLocal() print estate1.name, estate1.eid, estate1.sid, estate1.ha, estate1.signer, estate1.priver stack0.clearLocal() stack0.clearAllRemote() stack1.clearLocal() stack1.clearAllRemote()
def test(): ''' Test keeping. ''' pkiDirpath = os.path.join(os.getcwd(), 'keyo', '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_IWUSR) cacheDirpath = os.path.join(os.getcwd(), 'salt', 'cache') sockDirpath = os.path.join('/tmp/raet', 'salt', 'sock') opts = dict( pki_dir=pkiDirpath, sock_dir=sockDirpath, cachedir=cacheDirpath, open_mode=True, auto_accept=True, ) masterKeeper = RaetKey(opts=opts) print masterKeeper.all_keys() masterName = 'master' masterDirpath = os.path.join(os.getcwd(), '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(os.getcwd(), '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) local = masterKeeper.read_local() print local if not local: masterKeeper.write_local(masterPriKeyHex, masterSignKeyHex) print masterKeeper.read_local() print masterKeeper.all_keys() print masterKeeper.status(m1Name, 2, m1PubKeyHex, m1VerKeyHex) print masterKeeper.status(m2Name, 3, m2PubKeyHex, m2VerKeyHex) print masterKeeper.all_keys() print masterKeeper.read_remote(m1Name) print masterKeeper.read_remote(m2Name) print masterKeeper.list_keys() print masterKeeper.read_all_remote() #master stack estate = estating.LocalEstate( eid=1, name=masterName, sigkey=masterSignKeyHex, prikey=masterPriKeyHex, ) stack0 = stacking.RoadStack(estate=estate, dirpath=masterDirpath) 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 estate = estating.LocalEstate( eid=2, name=m1Name, ha=("", raeting.RAET_TEST_PORT), sigkey=m1SignKeyHex, prikey=m1PriKeyHex, ) stack1 = stacking.RoadStack(estate=estate, dirpath=m1Dirpath) 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.road.loadLocalData() print stack0.road.loadAllRemoteData() print "Safe {0}".format(stack0.name) print stack0.safe.loadLocalData() print stack0.safe.loadAllRemoteData() print print "Road {0}".format(stack1.name) print stack1.road.loadLocalData() print stack1.road.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(os.getcwd(), 'keep', 'master') estate = estating.LocalEstate( eid=1, name='master', sigkey=masterSignKeyHex, prikey=masterPriKeyHex, ) stack0 = stacking.RoadStack(estate=estate, dirpath=masterDirpath) #minion stack dirpath = os.path.join(os.getcwd(), 'keep', 'minion1') estate = estating.LocalEstate( eid=2, name='minion1', ha=("", raeting.RAET_TEST_PORT), sigkey=m1SignKeyHex, prikey=m1PriKeyHex, ) stack1 = stacking.RoadStack(estate=estate, dirpath=m1Dirpath) estate0 = stack0.loadLocal() print estate0.name, estate0.eid, estate0.sid, estate0.ha, estate0.signer, estate0.priver estate1 = stack1.loadLocal() print estate1.name, estate1.eid, estate1.sid, estate1.ha, estate1.signer, estate1.priver stack0.clearLocal() stack0.clearRemoteKeeps() stack1.clearLocal() stack1.clearRemoteKeeps()