def _getID(self): """ Returns a tuple: private key, public key, nodeID, private group ID, and public group ID from config. If these values don't exist in conf file, they are generated and added. """ # get the keys and IDs from the config file. # If these values don't exist, generate a pub/priv key pair, nodeID, # and groupIDs. if not self.configParser.has_section("identification"): self.configParser.add_section("identification") try: privkey = FludRSA.importPrivateKey( eval(self.configParser.get("identification","Kr"))) except: pubkey, privkey = FludCrypto.generateKeys() else: try: pubkey = FludRSA.importPublicKey( eval(self.configParser.get("identification","Ku"))) except: pubkey = privkey.publickey() try: nodeID = self.configParser.get("identification","nodeID") except: #nodeID = FludCrypto.hashstring(str(pubkey.exportPublicKey())) nodeID = pubkey.id() try: privgroupID = self.configParser.get("identification", "groupIDr")[:64] except: privgroupID = 'fludtest' # default groupID hardcoded try: pubgroupID = self.configParser.get("identification","groupIDu") except: pubgroupID = FludCrypto.hashstring(str(pubkey.exportPublicKey()) +privgroupID) # write the settings back out to config object self.configParser.set("identification","Kr",privkey.exportPrivateKey()) self.configParser.set("identification","Ku",pubkey.exportPublicKey()) self.configParser.set("identification","nodeID",nodeID) self.configParser.set("identification","groupIDr",privgroupID) self.configParser.set("identification","groupIDu",pubgroupID) # return the values return privkey, pubkey, nodeID, privgroupID, pubgroupID
def testVERIFY(nKu, fname, fkey, mkey, node, host, port, newmeta): """ Test sendVerify """ # newmeta, if True, will generate new metadata to be stored during verify if newmeta: thismkey = mkey+fake_mkey_offset else: thismkey = mkey print "starting testVERIFY (%s) %s.%s" % (newmeta, fname, thismkey) fd = os.open(fname, os.O_RDONLY) fsize = os.fstat(fd)[stat.ST_SIZE] length = 20 offset = random.randrange(fsize-length) os.lseek(fd, offset, 0) data = os.read(fd, length) os.close(fd) hash = FludCrypto.hashstring(data) deferred = node.client.sendVerify(fkey, offset, length, host, port, nKu, (thismkey, StringIO(metadatablock))) deferred.addCallback(checkVERIFY, nKu, fname, fkey, mkey, node, host, port, hash, newmeta) deferred.addErrback(testerror, "failed at testVERIFY (%s)" % newmeta, node) return deferred