def __init__(self, configFileName): self.appConfigFileName = configFileName self.loadConfigFile() self.initLog() self.handle = pyccn.CCN() self.getApplicationKey() self.iFlex_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # we really need one of these per sender (pubkey) self.state = NameCrypto.new_state() self.cryptoKey = NameCrypto.generate_application_key(self.cfg.fixtureKey, self.cfg.appName) #self.symmKey = Key.Key().generateRSA(512) #self.symmKey = self.symmKey.generateRSA() # list of sender public keys self.senders = [] # list of sender states self.states = [] self.send = False self.count = 0 self.avgTime = 0 self.startTime =0 self.endTime =0 self.badPacket = 0 self.goodPacket = 0
def __init__(self, configFileName): self.appConfigFileName = configFileName self.loadConfigFile() self.handle = CCN.CCN() self.getApplicationKey() #nameCrypto self.state = NameCrypto.new_state() self.cryptoKey = NameCrypto.generate_application_key(self.cfg.fixtureKey, self.cfg.appName)
def sendSignedInterest(self,command): self.count = self.count +1 time.sleep(self.cfg.refreshInterval) fullURI = self.cfg.appPrefix + command print fullURI i = Interest.Interest() #self.state = NameCrypto.new_state() #build keyLocator to append to interest for NameCrypto on upcall keyLoc = Key.KeyLocator(self.key) keyLocStr = _pyccn.dump_charbuf(keyLoc.ccn_data) nameAndKeyLoc = Name.Name(str(fullURI)) #print("there are "+str(len(nameAndKeyLoc))+" components") nameAndKeyLoc += keyLocStr #print("there are "+str(len(nameAndKeyLoc))+" components after adding keyLocStr") #symmetric authName = NameCrypto.authenticate_command(self.state, nameAndKeyLoc, self.cfg.appName, self.cryptoKey) #asymmetric #authName = NameCrypto.authenticate_command_sig(self.state, nameAndKeyLoc, self.cfg.appName, self.key) #print authName.components co = self.handle.expressInterest(authName,self)
def sendSignedInterest(self,command): self.count = self.count +1 #time.sleep(self.cfg.refreshInterval) fullURI = self.cfg.appPrefix + command #print fullURI i = Interest() #self.state = NameCrypto.new_state() #build keyLocator to append to interest for NameCrypto on upcall keyLoc = pyccn.KeyLocator(self.key) keyLocStr = pyccn._pyccn.dump_charbuf(keyLoc.ccn_data) nameAndKeyLoc = Name(str(fullURI)) #print("there are "+str(len(nameAndKeyLoc))+" components") nameAndKeyLoc = nameAndKeyLoc.append(keyLocStr) #print("there are "+str(len(nameAndKeyLoc))+" components after adding keyLocStr") #symmetric #authName = NameCrypto.authenticate_command(self.state, nameAndKeyLoc, self.cfg.appName, self.cryptoKey) #asymmetric authName = NameCrypto.authenticate_command_sig(self.state, nameAndKeyLoc, self.cfg.appName, self.key) #print authName.components self.handle.setInterestFilter(Name(authName), self) #trace(str(time.time()),str(authName),"expressed") # time sent tS = time.time() self.log.info(str((tS-self.startTime))+",INTEREST_EXPRESSED, , "+ str(authName)) co = self.handle.expressInterest(authName,self) self.handle.run(0)
def sendSignedInterest(self,command): fullURI = self.cfg.appPrefix + command print fullURI i = Interest() self.state = NameCrypto.new_state() #build keyLocator to append to interest for NameCrypto on upcall # keyLoc = pyccn.KeyLocator(self.key) keyLocStr = pyccn._pyccn.dump_charbuf(keyLoc.ccn_data) nameAndKeyLoc = Name(str(fullURI)) #print("there are "+str(len(nameAndKeyLoc))+" components") nameAndKeyLoc = nameAndKeyLoc.append(keyLocStr) #print("there are "+str(len(nameAndKeyLoc))+" components after adding keyLocStr") authName = NameCrypto.authenticate_command(self.state, nameAndKeyLoc, self.cfg.appName, self.cryptoKey) #print authName.components # send interest # for just expressing co = self.handle.expressInterest(authName,self)
def sendSignedInterest(self,command): fullURI = self.cfg.appPrefix + command print fullURI i = Interest.Interest() #build keyLocator to append to interest for NameCrypto on upcall keyLoc = Key.KeyLocator(self.key) keyLocStr = _pyccn.dump_charbuf(keyLoc.ccn_data) nameAndKeyLoc = Name.Name(str(fullURI)) #print("there are "+str(len(nameAndKeyLoc))+" components") nameAndKeyLoc += keyLocStr #print("there are "+str(len(nameAndKeyLoc))+" components after adding keyLocStr") authName = NameCrypto.authenticate_command(self.state, nameAndKeyLoc, self.cfg.appName, self.cryptoKey) #print authName.components co = self.handle.get(authName,i,500) if not not co: #if co is not empty, print result for debugging print("interest "+str(co.content))
def sendSignedInterest(self,command): fullURI = self.cfg.appPrefix + command #print fullURI i = Interest() #build keyLocator to append to interest for NameCrypto on upcall keyLoc = pyccn.KeyLocator(self.key) keyLocStr = _pyccn.dump_charbuf(keyLoc.ccn_data) nameAndKeyLoc = Name(str(fullURI)) #print("there are "+str(len(nameAndKeyLoc))+" components") nameAndKeyLoc += keyLocStr #print("there are "+str(len(nameAndKeyLoc))+" components after adding keyLocStr") t0 = time() authName = NameCrypto.authenticate_command(self.state, nameAndKeyLoc, self.cfg.appName, self.cryptoKey) t1 = time() #print "elapsed sign", t1-t0 #print authName.components t0 = time() co = self.handle.expressInterest(authName,self) t1 = time()
from pyccn import NameCrypto, CCN, Name handle = CCN.CCN() key = handle.getDefaultKey() del handle fixture_key ="1234" app_name="lightingController" name = Name.Name(["name"]) app_key = NameCrypto.generate_application_key(fixture_key, app_name) sender_state = NameCrypto.new_state() receiver_state = NameCrypto.new_state() auth_name1 = NameCrypto.authenticate_command(sender_state, name, app_name, app_key) print("ccnx:" + str(auth_name1)) auth_name2 = NameCrypto.authenticate_command_sig(sender_state, name, app_name, key) print("ccnx:" + str(auth_name2)) result = NameCrypto.verify_command(receiver_state, auth_name1, 10000, fixture_key=fixture_key, pub_key=key) print(result) result = NameCrypto.verify_command(receiver_state, auth_name2, 10000, fixture_key=fixture_key, pub_key=key) print(result)
import pyccn from pyccn import Name, NameCrypto, Key, KeyLocator, CCN window = -1 # Test symmetric authentication state = NameCrypto.new_state() secret = '1234567812345678' app_name = 'cuerda' app_key = NameCrypto.generate_application_key(secret, app_name) name = Name('/ndn/ucla.edu/apps/cuerda') auth_name = NameCrypto.authenticate_command(state, name, app_name, app_key) print auth_name state2 = NameCrypto.new_state() ret = NameCrypto.verify_command(state2, auth_name, window, fixture_key=secret) print ret assert(ret == True) name_from_js = Name( '/ndn/ucla.edu/apps/cuerda/%40%96%1CQ%00%06cuerdaQk%8A%13%00%07%B8%90%00%00%00%03%00%00%00%00%BB%14%FCHl%A5%F6%5D%18%1EIs%9E%91t%5El%C1y%3F%BAA%A7%02Y%EC%804%23%A4%D4t' ) state3 = NameCrypto.new_state()
def upcall(self, kind, info): tR = time.time() #print self.appCfg.appName +" upcall..." if kind != pyccn.UPCALL_INTEREST: return pyccn.RESULT_OK #ignore timeouts if kind == pyccn.UPCALL_INTEREST_TIMED_OUT: return pyccn.RESULT_OK #print "received interest "+str(info.Interest.name) #print info.Interest.name.components #print "interest has "+str(len(info.Interest.name))+" components" self.state = NameCrypto.new_state() # verify interest n = info.Interest.name ### if we know the key ### use the state for it ### if it's a new key ### and we trust it ### make a state for it ### and use that state #meanwhile, until this is implemented... restart controller if use with a new sender/app self.send = False #symmetric #result = NameCrypto.verify_command(self.state, n, self.cfg.window, fixture_key=self.cfg.fixtureKey) # keyLoc only needs parsing for asymmetric keyLocStr2 = n[-2] #print "\n ncrypt: "+ keyLocStr2 + "\n" #try: capsule = pyccn._pyccn.new_charbuf('KeyLocator_ccn_data', keyLocStr2) keyLoc2 = pyccn._pyccn.KeyLocator_obj_from_ccn(capsule) #asymmetric result = NameCrypto.verify_command(self.state, n, self.cfg.window, pub_key=keyLoc2.key) self.state = NameCrypto.new_state() content = result self.log.info(str(time.time()-self.startTime)+",NC_VERIFY,"+str(content)+","+str(info.Interest.name)) if(result == True): #print "Verify "+str(result) #content = "Verify True" self.send = True self.goodPacket=self.goodPacket+1 self.state = NameCrypto.new_state() else: self.badPacket=self.badPacket+1 self.send = False #if (result == -2): #content = "Verify False : "+str(result) # content = "-2=NC Verification Fail" #print "Verify False : "+ str(result)+" for "+str(info.Interest.name) #print("-2 verification fail") ''' else: # we don't care about duplicates right now if (result != -4): #content = "Verify False : "+str(result) #print "Verify False : "+ str(result)+" for "+str(info.Interest.name) # nor do we care about bad authenticators either print("-4 expired command") if (result == -2): #content = "Verify False : "+str(result) #print "Verify False : "+ str(result)+" for "+str(info.Interest.name) print("-2 verification fail") ''' # if verified, send interest #if self.send: # parse command & send to correct driver/IP # must ignore right now, still get too many false / 'outside window' self.parseAndSendToLight(info.Interest.name) # return content object # (ideally based on success/fail - yet that's not implicitly supported by current kinet # so perhaps we put a self-verification of new driver state process here # meanwhile just return 'ok' tS = time.time() if (content>0): #if (self.send): #if(content): self.handle.put(self.makeDefaultContent(info.Interest.name, content)) # send the prepared data self.log.info(str(tS-self.startTime)+",CONTENT_PUT,"+str(content)+","+str(info.Interest.name)) #print("published content object at "+str(info.Interest.name)+"\n") t1 = time.time() self.count = self.count+1 self.avgTime = ((t1-tR) + (self.avgTime / self.count)) #print str(self.avgTime) +" at "+str(self.count) # self.handle.setRunTimeout(-1) # finish run() return pyccn.RESULT_INTEREST_CONSUMED