i
modified: base_node.py
deleted: commands/__init__.py
deleted: commands/cert-request.proto
deleted: commands/cert_request_pb2.py
deleted: commands/configure-device.proto
deleted: commands/configure_device_pb2.py
deleted: commands/send-pairing-info.proto
deleted: commands/send_pairing_info_pb2.py
deleted: commands/update-capabilities.proto
deleted: commands/update_capabilities_pb2.py
modified: controller.py
modified: end-device.py
diff --git a/controller.py b/controller.py
index 8db4242..64d4119 100644
--- a/controller.py
+++ b/controller.py
@@ -40,37 +40,38 @@
def __init__(self,configFileName):
super(Controller, self).__init__(configFileName=configFileName)
self._responseCount = 0
- self._symmetricKey = "symmetricKeyForBootstrapping"
- self._prefix = "/home/controller/id999"
+ self._symmetricKey = "symmetricKeyForBootstrapping"
+ self._prefix = "/home"
+ self._identity = "/home/controller/id999"
def onInterest(self, prefix, interest, transport, registeredPrefixId):
self._responseCount += 1
- interestName = interest.getName()
+ interestName = interest.getName()
- #for bootstrap interest
- if(interestName.toUri().startswith(self._bootstrapPrefix) and interest.getKeyLocator().getKeyData().toRawStr() == self._symmetricKey):
- dump("Reveived bootstrap interest")
+ #for bootstrap interest
+ if(interestName.toUri().startswith(self._bootstrapPrefix) and interest.getKeyLocator().getKeyData().toRawStr() == self._symmetricKey):
+ dump("Reveived bootstrap interest")
self.onBootstrapInterest(prefix, interest, transport, registeredPrefixId)
- elif ("KEY" in interestName.toUri() and "ID-CERT" in interestName.toUri()):
- dump("Reveived certificate request interest")
- self.onCertificateRequest(prefix, interest, transport, registeredPrefixId)
+ elif ("KEY" in interestName.toUri() and "ID-CERT" in interestName.toUri()):
+ dump("Reveived certificate request interest")
+ self.onCertificateRequest(prefix, interest, transport, registeredPrefixId)
def onBootstrapInterest(self, prefix, interest, transport, registeredPrefixId):
-
- interestName = interest.getName()
- deviceParameters = json.loads(interestName.get(3).getValue().toRawStr())
- deviceNewIdentity = Name("/home")
+
+ interestName = interest.getName()
+ deviceParameters = json.loads(interestName.get(3).getValue().toRawStr())
+ deviceNewIdentity = Name("/home")
- #create new identity for device
+ #create new identity for device
deviceNewIdentity.append(deviceParameters["category"])
deviceNewIdentity.append(deviceParameters["id"])
-
+
#generate content
content = {}
content["deviceNewIdentity"] = deviceNewIdentity.toUri()
- content["controllerIdentity"] = self._prefix
+ content["controllerIdentity"] = self._identity
#get public key of controller
pKeyName = self._identityManager.getDefaultKeyNameForIdentity(self._identityManager.getDefaultIdentity())
@@ -81,106 +82,100 @@
pKeyInfo["keyType"] = pKey.getKeyType()
pKeyInfo["publicKeyDer"] = pKey.getKeyDer().toRawStr()
dump("Sent content : ",content)
-
- #TODO generate signature for data
-
- #generate data package
- data = Data(interestName)
- data.setContent(json.dumps(content,encoding="latin-1"))
- #data.setSignature(signature)
+
+ #TODO generate signature for data
+
+ #generate data package
+ data = Data(interestName)
+ data.setContent(json.dumps(content,encoding="latin-1"))
+ #data.setSignature(signature)
encodedData = data.wireEncode()
transport.send(encodedData.toBuffer())
def onCertificateRequest(self, prefix, interest, transport, registeredPrefixId):
- interestName = interest.getName()
- dump("interest name : ",interestName)
-
- keyName = interestName[:3]
- keyId = interestName.get(4)
- keyName.append(keyId)
- keyInfo = json.loads(interestName.get(5).getValue().toRawStr(),encoding="latin-1")
- keyType = keyInfo['keyType']
- keyDer = Blob().fromRawStr(keyInfo['keyDer'])
+ interestName = interest.getName()
+ dump("interest name : ",interestName)
+
+ keyName = interestName[:3]
+ keyId = interestName.get(4)
+ keyName.append(keyId)
+ keyInfo = json.loads(interestName.get(5).getValue().toRawStr(),encoding="latin-1")
+ keyType = keyInfo['keyType']
+ keyDer = Blob().fromRawStr(keyInfo['keyDer'])
- dump("keyname: ",keyName)
- dump("keyType ",keyInfo['keyType'])
- dump("keyDer string",keyInfo['keyDer'])
- dump("keyDer",keyDer)
+ dump("keyname: ",keyName)
+ dump("keyType ",keyInfo['keyType'])
+ dump("keyDer string",keyInfo['keyDer'])
+ dump("keyDer",keyDer)
- #device and controller are on one mechine, so it needs to be done.
- self._identityManager.setDefaultIdentity(Name(self._prefix))
- try:
- self._identityStorage.addKey(keyName, keyType, keyDer)
- except SecurityException:
- dump("The public key for device already exists ")
+ #device and controller are on one mechine, so it needs to be done.
+ self._identityManager.setDefaultIdentity(Name(self._identity))
+ try:
+ self._identityStorage.addKey(keyName, keyType, keyDer)
+ except SecurityException:
+ dump("The public key for device already exists ")
- signedCertificate = self._identityManager._generateCertificateForKey(keyName)
- self._keyChain.sign(signedCertificate, self._identityManager.getDefaultCertificateName())
- self._identityManager.addCertificate(signedCertificate)
-
-
-
- encodedData = signedCertificate.wireEncode()
+ signedCertificate = self._identityManager._generateCertificateForKey(keyName)
+ self._keyChain.sign(signedCertificate, self._identityManager.getDefaultCertificateName())
+ self._identityManager.addCertificate(signedCertificate)
+
+ encodedData = signedCertificate.wireEncode()
transport.send(encodedData.toBuffer())
-
def onRegisterFailed(self, prefix):
self._responseCount += 1
dump("Register failed for prefix", prefix.toUri())
def beforeLoopStart(self):
- identityName = Name(self._prefix)
-
- defaultIdentityExists = True
- try:
- defaultIdentityName = self._identityManager.getDefaultIdentity()
- except:
- defaultIdentityExists = False
-
+ identityName = Name(self._identity)
+
+ defaultIdentityExists = True
+ try:
+ defaultIdentityName = self._identityManager.getDefaultIdentity()
+ except:
+ defaultIdentityExists = False
+
- #dump(self._identityManager.getDefaultKeyNameForIdentity(self._prefix))
- if not defaultIdentityExists or self._identityManager.getDefaultIdentity() != identityName:
- #make one
- dump("Set default identity: ",identityName)
- #self._identityManager.createIdentityAndCertificate(identityName)
- self._identityStorage.addIdentity(identityName)
- self._identityManager.setDefaultIdentity(identityName)
+ #dump(self._identityManager.getDefaultKeyNameForIdentity(self._identity))
+ if not defaultIdentityExists or self._identityManager.getDefaultIdentity() != identityName:
+ #make one
+ dump("Set default identity: ",identityName)
+ #self._identityManager.createIdentityAndCertificate(identityName)
+ self._identityStorage.addIdentity(identityName)
+ self._identityManager.setDefaultIdentity(identityName)
- try:
- self._identityManager.getDefaultKeyNameForIdentity(identityName)
- except SecurityException:
- newKey = self._identityManager.generateRSAKeyPairAsDefault(Name(self._prefix), isKsk=True)
- newCert = self._identityManager.selfSign(newKey)
- dump("generated new KSK certificate ", newCert)
- self._identityManager.addCertificateAsIdentityDefault(newCert)
+ try:
+ self._identityManager.getDefaultKeyNameForIdentity(identityName)
+ except SecurityException:
+ newKey = self._identityManager.generateRSAKeyPairAsDefault(Name(self._identity), isKsk=True)
+ newCert = self._identityManager.selfSign(newKey)
+ dump("generated new KSK certificate ", newCert)
+ self._identityManager.addCertificateAsIdentityDefault(newCert)
+
+
+ #self.face.registerPrefix(self._prefix, self.onInterest, self.onRegisterFailed)
if __name__ == '__main__':
- # The default Face will connect using a Unix socket, or to "localhost".
- face = Face()
-
- # Use the system default key chain and certificate name to sign commands.
-
controller = Controller("default.conf")
controller.beforeLoopStart()
-
- face.setCommandSigningInfo(controller.getKeyChain(), controller._keyChain.getDefaultCertificateName())
- # Also use the default certificate name to sign data packets.
+ face = Face()
+ face.setCommandSigningInfo(controller._keyChain, controller._keyChain.getDefaultCertificateName())
+ dump("Register prefix : ", controller._prefix)
+ face.registerPrefix(controller._prefix, controller.onInterest, controller.onRegisterFailed)
- prefix = Name("/home/")
- dump("Register prefix", prefix)
-
- face.registerPrefix(prefix, controller.onInterest, controller.onRegisterFailed)
-
-
- while controller._responseCount < 100:
+ while True:
face.processEvents()
# We need to sleep for a few milliseconds so we don't use 100% of the CPU.
time.sleep(0.01)
face.shutdown()
+
+
+
+