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/base_node.py b/base_node.py
index 387fce5..ec4b469 100644
--- a/base_node.py
+++ b/base_node.py
@@ -36,11 +36,11 @@
except ImportError:
import trollius as asyncio
-Command = namedtuple('Command', ['suffix', 'function', 'keywords', 'isSigned'])
+#Command = namedtuple('Command', ['suffix', 'function', 'keywords', 'isSigned'])
class BaseNode(object):
"""
- This class contains methods/attributes common to both node and controller.
+ This class contains methods/attributes common to both end device and controller.
"""
def __init__(self,configFileName):
@@ -77,8 +77,8 @@
prefix = ''
for i in range(prefixLen):
prefix += (chr(random.randint(0,0xff)))
- suffix = self.getDeviceSerial().lstrip('0')
- self._instanceSerial = '-'.join([prefix.encode('hex'), suffix])
+
+ self._instanceSerial = prefix.encode('hex')
return self._instanceSerial
##
@@ -87,7 +87,7 @@
def _prepareLogging(self):
self.log = logging.getLogger(str(self.__class__))
self.log.setLevel(logging.DEBUG)
- logFormat = "%(asctime)-15s %(name)-20s %(funcName)-20s (%(levelname)-8s):\n\t%(message)s"
+ logFormat = "%(asctime)-15s %(name)-20s %(funcName)-2s (%(levelname)-2s):\t%(message)s"
self._console = logging.StreamHandler()
self._console.setFormatter(logging.Formatter(logFormat))
self._console.setLevel(logging.INFO)
@@ -121,14 +121,25 @@
def getKeyChain(self):
return self._keyChain
- #def getDefaultCertificateName(self):
- # try:
- # certName = self._identityStorage.getDefaultCertificateNameForIdentity(
- # self._identityManager.getDefaultIdentity())
- # except SecurityException:
- # certName = self._keyChain.getDefaultCertificateName()
-#
- # return certName
+ def getDefaultIdentity(self):
+ try:
+ defaultIdentity = self._identityManager.getDefaultIdentity()
+ except SecurityException:
+ defaultIdentity = ""
+
+ return defaultIdentity
+
+
+ def getDefaultCertificateName(self):
+ #exception - no certficate, return ''
+
+ try:
+ certName = self._identityStorage.getDefaultCertificateNameForIdentity(
+ self._identityManager.getDefaultIdentity())
+ except SecurityException:
+ certName = ""
+
+ return certName
def start(self):
"""
@@ -138,13 +149,16 @@
self.log.info("Starting up")
self.loop = asyncio.get_event_loop()
self.face = ThreadsafeFace(self.loop, '')
- self.face.setCommandSigningInfo(self._keyChain, self.getDefaultCertificateName())
+
self._keyChain.setFace(self.face)
self._isStopped = False
self.face.stopWhen(lambda:self._isStopped)
- self.beforeLoopStart()
+ self.beforeLoopStart()
+
+ self.face.setCommandSigningInfo(self._keyChain, self.getDefaultCertificateName())
+
try:
self.loop.run_forever()
except KeyboardInterrupt:
diff --git a/commands/__init__.py b/commands/__init__.py
deleted file mode 100644
index 3bfc022..0000000
--- a/commands/__init__.py
+++ /dev/null
@@ -1,6 +0,0 @@
-__all__ = ['cert_request_pb2', 'configure_device_pb2', 'send_pairing_info_pb2', 'update_capabilities_pb2']
-
-from cert_request_pb2 import CertificateRequestMessage
-from update_capabilities_pb2 import UpdateCapabilitiesCommandMessage
-from configure_device_pb2 import DeviceConfigurationMessage
-from send_pairing_info_pb2 import DevicePairingInfoMessage
diff --git a/commands/cert-request.proto b/commands/cert-request.proto
deleted file mode 100644
index 6c81dd6..0000000
--- a/commands/cert-request.proto
+++ /dev/null
@@ -1,11 +0,0 @@
-message CertificateRequestMessage {
- message Name {
- repeated bytes components = 8;
- }
- message CertificateRequest {
- required Name keyName = 220;
- required uint32 keyType = 221;
- required bytes keyBits = 222;
- }
- required CertificateRequest command = 223;
-}
diff --git a/commands/cert_request_pb2.py b/commands/cert_request_pb2.py
deleted file mode 100644
index 0bb096d..0000000
--- a/commands/cert_request_pb2.py
+++ /dev/null
@@ -1,138 +0,0 @@
-# Generated by the protocol buffer compiler. DO NOT EDIT!
-
-from google.protobuf import descriptor
-from google.protobuf import message
-from google.protobuf import reflection
-from google.protobuf import descriptor_pb2
-# @@protoc_insertion_point(imports)
-
-
-
-DESCRIPTOR = descriptor.FileDescriptor(
- name='cert-request.proto',
- package='',
- serialized_pb='\n\x12\x63\x65rt-request.proto\"\xe5\x01\n\x19\x43\x65rtificateRequestMessage\x12?\n\x07\x63ommand\x18\xdf\x01 \x02(\x0b\x32-.CertificateRequestMessage.CertificateRequest\x1a\x1a\n\x04Name\x12\x12\n\ncomponents\x18\x08 \x03(\x0c\x1ak\n\x12\x43\x65rtificateRequest\x12\x31\n\x07keyName\x18\xdc\x01 \x02(\x0b\x32\x1f.CertificateRequestMessage.Name\x12\x10\n\x07keyType\x18\xdd\x01 \x02(\r\x12\x10\n\x07keyBits\x18\xde\x01 \x02(\x0c')
-
-
-
-
-_CERTIFICATEREQUESTMESSAGE_NAME = descriptor.Descriptor(
- name='Name',
- full_name='CertificateRequestMessage.Name',
- filename=None,
- file=DESCRIPTOR,
- containing_type=None,
- fields=[
- descriptor.FieldDescriptor(
- name='components', full_name='CertificateRequestMessage.Name.components', index=0,
- number=8, type=12, cpp_type=9, label=3,
- has_default_value=False, default_value=[],
- message_type=None, enum_type=None, containing_type=None,
- is_extension=False, extension_scope=None,
- options=None),
- ],
- extensions=[
- ],
- nested_types=[],
- enum_types=[
- ],
- options=None,
- is_extendable=False,
- extension_ranges=[],
- serialized_start=117,
- serialized_end=143,
-)
-
-_CERTIFICATEREQUESTMESSAGE_CERTIFICATEREQUEST = descriptor.Descriptor(
- name='CertificateRequest',
- full_name='CertificateRequestMessage.CertificateRequest',
- filename=None,
- file=DESCRIPTOR,
- containing_type=None,
- fields=[
- descriptor.FieldDescriptor(
- name='keyName', full_name='CertificateRequestMessage.CertificateRequest.keyName', index=0,
- number=220, type=11, cpp_type=10, label=2,
- has_default_value=False, default_value=None,
- message_type=None, enum_type=None, containing_type=None,
- is_extension=False, extension_scope=None,
- options=None),
- descriptor.FieldDescriptor(
- name='keyType', full_name='CertificateRequestMessage.CertificateRequest.keyType', index=1,
- number=221, type=13, cpp_type=3, label=2,
- has_default_value=False, default_value=0,
- message_type=None, enum_type=None, containing_type=None,
- is_extension=False, extension_scope=None,
- options=None),
- descriptor.FieldDescriptor(
- name='keyBits', full_name='CertificateRequestMessage.CertificateRequest.keyBits', index=2,
- number=222, type=12, cpp_type=9, label=2,
- has_default_value=False, default_value="",
- message_type=None, enum_type=None, containing_type=None,
- is_extension=False, extension_scope=None,
- options=None),
- ],
- extensions=[
- ],
- nested_types=[],
- enum_types=[
- ],
- options=None,
- is_extendable=False,
- extension_ranges=[],
- serialized_start=145,
- serialized_end=252,
-)
-
-_CERTIFICATEREQUESTMESSAGE = descriptor.Descriptor(
- name='CertificateRequestMessage',
- full_name='CertificateRequestMessage',
- filename=None,
- file=DESCRIPTOR,
- containing_type=None,
- fields=[
- descriptor.FieldDescriptor(
- name='command', full_name='CertificateRequestMessage.command', index=0,
- number=223, type=11, cpp_type=10, label=2,
- has_default_value=False, default_value=None,
- message_type=None, enum_type=None, containing_type=None,
- is_extension=False, extension_scope=None,
- options=None),
- ],
- extensions=[
- ],
- nested_types=[_CERTIFICATEREQUESTMESSAGE_NAME, _CERTIFICATEREQUESTMESSAGE_CERTIFICATEREQUEST, ],
- enum_types=[
- ],
- options=None,
- is_extendable=False,
- extension_ranges=[],
- serialized_start=23,
- serialized_end=252,
-)
-
-_CERTIFICATEREQUESTMESSAGE_NAME.containing_type = _CERTIFICATEREQUESTMESSAGE;
-_CERTIFICATEREQUESTMESSAGE_CERTIFICATEREQUEST.fields_by_name['keyName'].message_type = _CERTIFICATEREQUESTMESSAGE_NAME
-_CERTIFICATEREQUESTMESSAGE_CERTIFICATEREQUEST.containing_type = _CERTIFICATEREQUESTMESSAGE;
-_CERTIFICATEREQUESTMESSAGE.fields_by_name['command'].message_type = _CERTIFICATEREQUESTMESSAGE_CERTIFICATEREQUEST
-DESCRIPTOR.message_types_by_name['CertificateRequestMessage'] = _CERTIFICATEREQUESTMESSAGE
-
-class CertificateRequestMessage(message.Message):
- __metaclass__ = reflection.GeneratedProtocolMessageType
-
- class Name(message.Message):
- __metaclass__ = reflection.GeneratedProtocolMessageType
- DESCRIPTOR = _CERTIFICATEREQUESTMESSAGE_NAME
-
- # @@protoc_insertion_point(class_scope:CertificateRequestMessage.Name)
-
- class CertificateRequest(message.Message):
- __metaclass__ = reflection.GeneratedProtocolMessageType
- DESCRIPTOR = _CERTIFICATEREQUESTMESSAGE_CERTIFICATEREQUEST
-
- # @@protoc_insertion_point(class_scope:CertificateRequestMessage.CertificateRequest)
- DESCRIPTOR = _CERTIFICATEREQUESTMESSAGE
-
- # @@protoc_insertion_point(class_scope:CertificateRequestMessage)
-
-# @@protoc_insertion_point(module_scope)
diff --git a/commands/configure-device.proto b/commands/configure-device.proto
deleted file mode 100644
index 1bd38e1..0000000
--- a/commands/configure-device.proto
+++ /dev/null
@@ -1,11 +0,0 @@
-message DeviceConfigurationMessage {
- message Name {
- repeated bytes components = 8;
- }
- message DeviceConfiguration {
- required Name networkPrefix = 224;
- required Name controllerName = 225;
- required Name deviceSuffix = 226;
- }
- required DeviceConfiguration configuration = 227;
-}
diff --git a/commands/configure_device_pb2.py b/commands/configure_device_pb2.py
deleted file mode 100644
index 6a48eec..0000000
--- a/commands/configure_device_pb2.py
+++ /dev/null
@@ -1,140 +0,0 @@
-# Generated by the protocol buffer compiler. DO NOT EDIT!
-
-from google.protobuf import descriptor
-from google.protobuf import message
-from google.protobuf import reflection
-from google.protobuf import descriptor_pb2
-# @@protoc_insertion_point(imports)
-
-
-
-DESCRIPTOR = descriptor.FileDescriptor(
- name='configure-device.proto',
- package='',
- serialized_pb='\n\x16\x63onfigure-device.proto\"\xc7\x02\n\x1a\x44\x65viceConfigurationMessage\x12G\n\rconfiguration\x18\xe3\x01 \x02(\x0b\x32/.DeviceConfigurationMessage.DeviceConfiguration\x1a\x1a\n\x04Name\x12\x12\n\ncomponents\x18\x08 \x03(\x0c\x1a\xc3\x01\n\x13\x44\x65viceConfiguration\x12\x38\n\rnetworkPrefix\x18\xe0\x01 \x02(\x0b\x32 .DeviceConfigurationMessage.Name\x12\x39\n\x0e\x63ontrollerName\x18\xe1\x01 \x02(\x0b\x32 .DeviceConfigurationMessage.Name\x12\x37\n\x0c\x64\x65viceSuffix\x18\xe2\x01 \x02(\x0b\x32 .DeviceConfigurationMessage.Name')
-
-
-
-
-_DEVICECONFIGURATIONMESSAGE_NAME = descriptor.Descriptor(
- name='Name',
- full_name='DeviceConfigurationMessage.Name',
- filename=None,
- file=DESCRIPTOR,
- containing_type=None,
- fields=[
- descriptor.FieldDescriptor(
- name='components', full_name='DeviceConfigurationMessage.Name.components', index=0,
- number=8, type=12, cpp_type=9, label=3,
- has_default_value=False, default_value=[],
- message_type=None, enum_type=None, containing_type=None,
- is_extension=False, extension_scope=None,
- options=None),
- ],
- extensions=[
- ],
- nested_types=[],
- enum_types=[
- ],
- options=None,
- is_extendable=False,
- extension_ranges=[],
- serialized_start=130,
- serialized_end=156,
-)
-
-_DEVICECONFIGURATIONMESSAGE_DEVICECONFIGURATION = descriptor.Descriptor(
- name='DeviceConfiguration',
- full_name='DeviceConfigurationMessage.DeviceConfiguration',
- filename=None,
- file=DESCRIPTOR,
- containing_type=None,
- fields=[
- descriptor.FieldDescriptor(
- name='networkPrefix', full_name='DeviceConfigurationMessage.DeviceConfiguration.networkPrefix', index=0,
- number=224, type=11, cpp_type=10, label=2,
- has_default_value=False, default_value=None,
- message_type=None, enum_type=None, containing_type=None,
- is_extension=False, extension_scope=None,
- options=None),
- descriptor.FieldDescriptor(
- name='controllerName', full_name='DeviceConfigurationMessage.DeviceConfiguration.controllerName', index=1,
- number=225, type=11, cpp_type=10, label=2,
- has_default_value=False, default_value=None,
- message_type=None, enum_type=None, containing_type=None,
- is_extension=False, extension_scope=None,
- options=None),
- descriptor.FieldDescriptor(
- name='deviceSuffix', full_name='DeviceConfigurationMessage.DeviceConfiguration.deviceSuffix', index=2,
- number=226, type=11, cpp_type=10, label=2,
- has_default_value=False, default_value=None,
- message_type=None, enum_type=None, containing_type=None,
- is_extension=False, extension_scope=None,
- options=None),
- ],
- extensions=[
- ],
- nested_types=[],
- enum_types=[
- ],
- options=None,
- is_extendable=False,
- extension_ranges=[],
- serialized_start=159,
- serialized_end=354,
-)
-
-_DEVICECONFIGURATIONMESSAGE = descriptor.Descriptor(
- name='DeviceConfigurationMessage',
- full_name='DeviceConfigurationMessage',
- filename=None,
- file=DESCRIPTOR,
- containing_type=None,
- fields=[
- descriptor.FieldDescriptor(
- name='configuration', full_name='DeviceConfigurationMessage.configuration', index=0,
- number=227, type=11, cpp_type=10, label=2,
- has_default_value=False, default_value=None,
- message_type=None, enum_type=None, containing_type=None,
- is_extension=False, extension_scope=None,
- options=None),
- ],
- extensions=[
- ],
- nested_types=[_DEVICECONFIGURATIONMESSAGE_NAME, _DEVICECONFIGURATIONMESSAGE_DEVICECONFIGURATION, ],
- enum_types=[
- ],
- options=None,
- is_extendable=False,
- extension_ranges=[],
- serialized_start=27,
- serialized_end=354,
-)
-
-_DEVICECONFIGURATIONMESSAGE_NAME.containing_type = _DEVICECONFIGURATIONMESSAGE;
-_DEVICECONFIGURATIONMESSAGE_DEVICECONFIGURATION.fields_by_name['networkPrefix'].message_type = _DEVICECONFIGURATIONMESSAGE_NAME
-_DEVICECONFIGURATIONMESSAGE_DEVICECONFIGURATION.fields_by_name['controllerName'].message_type = _DEVICECONFIGURATIONMESSAGE_NAME
-_DEVICECONFIGURATIONMESSAGE_DEVICECONFIGURATION.fields_by_name['deviceSuffix'].message_type = _DEVICECONFIGURATIONMESSAGE_NAME
-_DEVICECONFIGURATIONMESSAGE_DEVICECONFIGURATION.containing_type = _DEVICECONFIGURATIONMESSAGE;
-_DEVICECONFIGURATIONMESSAGE.fields_by_name['configuration'].message_type = _DEVICECONFIGURATIONMESSAGE_DEVICECONFIGURATION
-DESCRIPTOR.message_types_by_name['DeviceConfigurationMessage'] = _DEVICECONFIGURATIONMESSAGE
-
-class DeviceConfigurationMessage(message.Message):
- __metaclass__ = reflection.GeneratedProtocolMessageType
-
- class Name(message.Message):
- __metaclass__ = reflection.GeneratedProtocolMessageType
- DESCRIPTOR = _DEVICECONFIGURATIONMESSAGE_NAME
-
- # @@protoc_insertion_point(class_scope:DeviceConfigurationMessage.Name)
-
- class DeviceConfiguration(message.Message):
- __metaclass__ = reflection.GeneratedProtocolMessageType
- DESCRIPTOR = _DEVICECONFIGURATIONMESSAGE_DEVICECONFIGURATION
-
- # @@protoc_insertion_point(class_scope:DeviceConfigurationMessage.DeviceConfiguration)
- DESCRIPTOR = _DEVICECONFIGURATIONMESSAGE
-
- # @@protoc_insertion_point(class_scope:DeviceConfigurationMessage)
-
-# @@protoc_insertion_point(module_scope)
diff --git a/commands/send-pairing-info.proto b/commands/send-pairing-info.proto
deleted file mode 100644
index 02649bb..0000000
--- a/commands/send-pairing-info.proto
+++ /dev/null
@@ -1,8 +0,0 @@
-message DevicePairingInfoMessage {
- message DevicePairingInfo {
- required string deviceSerial = 236;
- required bytes devicePin = 237;
- required string deviceSuffix = 238;
-}
- required DevicePairingInfo info = 239;
-}
diff --git a/commands/send_pairing_info_pb2.py b/commands/send_pairing_info_pb2.py
deleted file mode 100644
index aeb0027..0000000
--- a/commands/send_pairing_info_pb2.py
+++ /dev/null
@@ -1,103 +0,0 @@
-# Generated by the protocol buffer compiler. DO NOT EDIT!
-
-from google.protobuf import descriptor
-from google.protobuf import message
-from google.protobuf import reflection
-from google.protobuf import descriptor_pb2
-# @@protoc_insertion_point(imports)
-
-
-
-DESCRIPTOR = descriptor.FileDescriptor(
- name='send-pairing-info.proto',
- package='',
- serialized_pb='\n\x17send-pairing-info.proto\"\xad\x01\n\x18\x44\x65vicePairingInfoMessage\x12:\n\x04info\x18\xee\x01 \x02(\x0b\x32+.DevicePairingInfoMessage.DevicePairingInfo\x1aU\n\x11\x44\x65vicePairingInfo\x12\x15\n\x0c\x64\x65viceSerial\x18\xeb\x01 \x02(\t\x12\x12\n\tdevicePin\x18\xec\x01 \x02(\x0c\x12\x15\n\x0c\x64\x65viceSuffix\x18\xed\x01 \x02(\t')
-
-
-
-
-_DEVICEPAIRINGINFOMESSAGE_DEVICEPAIRINGINFO = descriptor.Descriptor(
- name='DevicePairingInfo',
- full_name='DevicePairingInfoMessage.DevicePairingInfo',
- filename=None,
- file=DESCRIPTOR,
- containing_type=None,
- fields=[
- descriptor.FieldDescriptor(
- name='deviceSerial', full_name='DevicePairingInfoMessage.DevicePairingInfo.deviceSerial', index=0,
- number=235, type=9, cpp_type=9, label=2,
- has_default_value=False, default_value=unicode("", "utf-8"),
- message_type=None, enum_type=None, containing_type=None,
- is_extension=False, extension_scope=None,
- options=None),
- descriptor.FieldDescriptor(
- name='devicePin', full_name='DevicePairingInfoMessage.DevicePairingInfo.devicePin', index=1,
- number=236, type=12, cpp_type=9, label=2,
- has_default_value=False, default_value="",
- message_type=None, enum_type=None, containing_type=None,
- is_extension=False, extension_scope=None,
- options=None),
- descriptor.FieldDescriptor(
- name='deviceSuffix', full_name='DevicePairingInfoMessage.DevicePairingInfo.deviceSuffix', index=2,
- number=237, type=9, cpp_type=9, label=2,
- has_default_value=False, default_value=unicode("", "utf-8"),
- message_type=None, enum_type=None, containing_type=None,
- is_extension=False, extension_scope=None,
- options=None),
- ],
- extensions=[
- ],
- nested_types=[],
- enum_types=[
- ],
- options=None,
- is_extendable=False,
- extension_ranges=[],
- serialized_start=116,
- serialized_end=201,
-)
-
-_DEVICEPAIRINGINFOMESSAGE = descriptor.Descriptor(
- name='DevicePairingInfoMessage',
- full_name='DevicePairingInfoMessage',
- filename=None,
- file=DESCRIPTOR,
- containing_type=None,
- fields=[
- descriptor.FieldDescriptor(
- name='info', full_name='DevicePairingInfoMessage.info', index=0,
- number=238, type=11, cpp_type=10, label=2,
- has_default_value=False, default_value=None,
- message_type=None, enum_type=None, containing_type=None,
- is_extension=False, extension_scope=None,
- options=None),
- ],
- extensions=[
- ],
- nested_types=[_DEVICEPAIRINGINFOMESSAGE_DEVICEPAIRINGINFO, ],
- enum_types=[
- ],
- options=None,
- is_extendable=False,
- extension_ranges=[],
- serialized_start=28,
- serialized_end=201,
-)
-
-_DEVICEPAIRINGINFOMESSAGE_DEVICEPAIRINGINFO.containing_type = _DEVICEPAIRINGINFOMESSAGE;
-_DEVICEPAIRINGINFOMESSAGE.fields_by_name['info'].message_type = _DEVICEPAIRINGINFOMESSAGE_DEVICEPAIRINGINFO
-DESCRIPTOR.message_types_by_name['DevicePairingInfoMessage'] = _DEVICEPAIRINGINFOMESSAGE
-
-class DevicePairingInfoMessage(message.Message):
- __metaclass__ = reflection.GeneratedProtocolMessageType
-
- class DevicePairingInfo(message.Message):
- __metaclass__ = reflection.GeneratedProtocolMessageType
- DESCRIPTOR = _DEVICEPAIRINGINFOMESSAGE_DEVICEPAIRINGINFO
-
- # @@protoc_insertion_point(class_scope:DevicePairingInfoMessage.DevicePairingInfo)
- DESCRIPTOR = _DEVICEPAIRINGINFOMESSAGE
-
- # @@protoc_insertion_point(class_scope:DevicePairingInfoMessage)
-
-# @@protoc_insertion_point(module_scope)
diff --git a/commands/update-capabilities.proto b/commands/update-capabilities.proto
deleted file mode 100644
index f636564..0000000
--- a/commands/update-capabilities.proto
+++ /dev/null
@@ -1,21 +0,0 @@
-message UpdateCapabilitiesCommandMessage {
- message Name {
- repeated bytes components = 8;
- }
-
- message CapabilitiesParameter {
- required string parameterType = 228; // should be a protobuf type
- optional string parameterDesc = 229; // what is this parameter for? (recommended)
- }
-
- message Capability {
- required Name commandPrefix = 230; // the name (after device prefix) of command
- repeated string keywords = 231; // other devices can search for one or more keywords
- // e.g. 'cec', 'motion', 'thermostat'
- repeated CapabilitiesParameter parameterDesc = 232; // list of parameter descriptions
- optional bool needsSignature=233;
- required String deviceSerial=234;
- }
-
- repeated Capability capabilities = 235;
-}
diff --git a/commands/update_capabilities_pb2.py b/commands/update_capabilities_pb2.py
deleted file mode 100644
index 94dc63d..0000000
--- a/commands/update_capabilities_pb2.py
+++ /dev/null
@@ -1,187 +0,0 @@
-# Generated by the protocol buffer compiler. DO NOT EDIT!
-
-from google.protobuf import descriptor
-from google.protobuf import message
-from google.protobuf import reflection
-from google.protobuf import descriptor_pb2
-# @@protoc_insertion_point(imports)
-
-
-
-DESCRIPTOR = descriptor.FileDescriptor(
- name='update-capabilities.proto',
- package='',
- serialized_pb='\n\x19update-capabilities.proto\"\x98\x03\n UpdateCapabilitiesCommandMessage\x12\x43\n\x0c\x63\x61pabilities\x18\xea\x01 \x03(\x0b\x32,.UpdateCapabilitiesCommandMessage.Capability\x1a\x1a\n\x04Name\x12\x12\n\ncomponents\x18\x08 \x03(\x0c\x1aG\n\x15\x43\x61pabilitiesParameter\x12\x16\n\rparameterType\x18\xe4\x01 \x02(\t\x12\x16\n\rparameterDesc\x18\xe5\x01 \x01(\t\x1a\xc9\x01\n\nCapability\x12>\n\rcommandPrefix\x18\xe6\x01 \x02(\x0b\x32&.UpdateCapabilitiesCommandMessage.Name\x12\x11\n\x08keywords\x18\xe7\x01 \x03(\t\x12O\n\rparameterDesc\x18\xe8\x01 \x03(\x0b\x32\x37.UpdateCapabilitiesCommandMessage.CapabilitiesParameter\x12\x17\n\x0eneedsSignature\x18\xe9\x01 \x01(\x08')
-
-
-
-
-_UPDATECAPABILITIESCOMMANDMESSAGE_NAME = descriptor.Descriptor(
- name='Name',
- full_name='UpdateCapabilitiesCommandMessage.Name',
- filename=None,
- file=DESCRIPTOR,
- containing_type=None,
- fields=[
- descriptor.FieldDescriptor(
- name='components', full_name='UpdateCapabilitiesCommandMessage.Name.components', index=0,
- number=8, type=12, cpp_type=9, label=3,
- has_default_value=False, default_value=[],
- message_type=None, enum_type=None, containing_type=None,
- is_extension=False, extension_scope=None,
- options=None),
- ],
- extensions=[
- ],
- nested_types=[],
- enum_types=[
- ],
- options=None,
- is_extendable=False,
- extension_ranges=[],
- serialized_start=135,
- serialized_end=161,
-)
-
-_UPDATECAPABILITIESCOMMANDMESSAGE_CAPABILITIESPARAMETER = descriptor.Descriptor(
- name='CapabilitiesParameter',
- full_name='UpdateCapabilitiesCommandMessage.CapabilitiesParameter',
- filename=None,
- file=DESCRIPTOR,
- containing_type=None,
- fields=[
- descriptor.FieldDescriptor(
- name='parameterType', full_name='UpdateCapabilitiesCommandMessage.CapabilitiesParameter.parameterType', index=0,
- number=228, type=9, cpp_type=9, label=2,
- has_default_value=False, default_value=unicode("", "utf-8"),
- message_type=None, enum_type=None, containing_type=None,
- is_extension=False, extension_scope=None,
- options=None),
- descriptor.FieldDescriptor(
- name='parameterDesc', full_name='UpdateCapabilitiesCommandMessage.CapabilitiesParameter.parameterDesc', index=1,
- number=229, type=9, cpp_type=9, label=1,
- has_default_value=False, default_value=unicode("", "utf-8"),
- message_type=None, enum_type=None, containing_type=None,
- is_extension=False, extension_scope=None,
- options=None),
- ],
- extensions=[
- ],
- nested_types=[],
- enum_types=[
- ],
- options=None,
- is_extendable=False,
- extension_ranges=[],
- serialized_start=163,
- serialized_end=234,
-)
-
-_UPDATECAPABILITIESCOMMANDMESSAGE_CAPABILITY = descriptor.Descriptor(
- name='Capability',
- full_name='UpdateCapabilitiesCommandMessage.Capability',
- filename=None,
- file=DESCRIPTOR,
- containing_type=None,
- fields=[
- descriptor.FieldDescriptor(
- name='commandPrefix', full_name='UpdateCapabilitiesCommandMessage.Capability.commandPrefix', index=0,
- number=230, type=11, cpp_type=10, label=2,
- has_default_value=False, default_value=None,
- message_type=None, enum_type=None, containing_type=None,
- is_extension=False, extension_scope=None,
- options=None),
- descriptor.FieldDescriptor(
- name='keywords', full_name='UpdateCapabilitiesCommandMessage.Capability.keywords', index=1,
- number=231, type=9, cpp_type=9, label=3,
- has_default_value=False, default_value=[],
- message_type=None, enum_type=None, containing_type=None,
- is_extension=False, extension_scope=None,
- options=None),
- descriptor.FieldDescriptor(
- name='parameterDesc', full_name='UpdateCapabilitiesCommandMessage.Capability.parameterDesc', index=2,
- number=232, type=11, cpp_type=10, label=3,
- has_default_value=False, default_value=[],
- message_type=None, enum_type=None, containing_type=None,
- is_extension=False, extension_scope=None,
- options=None),
- descriptor.FieldDescriptor(
- name='needsSignature', full_name='UpdateCapabilitiesCommandMessage.Capability.needsSignature', index=3,
- number=233, type=8, cpp_type=7, label=1,
- has_default_value=False, default_value=False,
- message_type=None, enum_type=None, containing_type=None,
- is_extension=False, extension_scope=None,
- options=None),
- ],
- extensions=[
- ],
- nested_types=[],
- enum_types=[
- ],
- options=None,
- is_extendable=False,
- extension_ranges=[],
- serialized_start=237,
- serialized_end=438,
-)
-
-_UPDATECAPABILITIESCOMMANDMESSAGE = descriptor.Descriptor(
- name='UpdateCapabilitiesCommandMessage',
- full_name='UpdateCapabilitiesCommandMessage',
- filename=None,
- file=DESCRIPTOR,
- containing_type=None,
- fields=[
- descriptor.FieldDescriptor(
- name='capabilities', full_name='UpdateCapabilitiesCommandMessage.capabilities', index=0,
- number=234, type=11, cpp_type=10, label=3,
- has_default_value=False, default_value=[],
- message_type=None, enum_type=None, containing_type=None,
- is_extension=False, extension_scope=None,
- options=None),
- ],
- extensions=[
- ],
- nested_types=[_UPDATECAPABILITIESCOMMANDMESSAGE_NAME, _UPDATECAPABILITIESCOMMANDMESSAGE_CAPABILITIESPARAMETER, _UPDATECAPABILITIESCOMMANDMESSAGE_CAPABILITY, ],
- enum_types=[
- ],
- options=None,
- is_extendable=False,
- extension_ranges=[],
- serialized_start=30,
- serialized_end=438,
-)
-
-_UPDATECAPABILITIESCOMMANDMESSAGE_NAME.containing_type = _UPDATECAPABILITIESCOMMANDMESSAGE;
-_UPDATECAPABILITIESCOMMANDMESSAGE_CAPABILITIESPARAMETER.containing_type = _UPDATECAPABILITIESCOMMANDMESSAGE;
-_UPDATECAPABILITIESCOMMANDMESSAGE_CAPABILITY.fields_by_name['commandPrefix'].message_type = _UPDATECAPABILITIESCOMMANDMESSAGE_NAME
-_UPDATECAPABILITIESCOMMANDMESSAGE_CAPABILITY.fields_by_name['parameterDesc'].message_type = _UPDATECAPABILITIESCOMMANDMESSAGE_CAPABILITIESPARAMETER
-_UPDATECAPABILITIESCOMMANDMESSAGE_CAPABILITY.containing_type = _UPDATECAPABILITIESCOMMANDMESSAGE;
-_UPDATECAPABILITIESCOMMANDMESSAGE.fields_by_name['capabilities'].message_type = _UPDATECAPABILITIESCOMMANDMESSAGE_CAPABILITY
-DESCRIPTOR.message_types_by_name['UpdateCapabilitiesCommandMessage'] = _UPDATECAPABILITIESCOMMANDMESSAGE
-
-class UpdateCapabilitiesCommandMessage(message.Message):
- __metaclass__ = reflection.GeneratedProtocolMessageType
-
- class Name(message.Message):
- __metaclass__ = reflection.GeneratedProtocolMessageType
- DESCRIPTOR = _UPDATECAPABILITIESCOMMANDMESSAGE_NAME
-
- # @@protoc_insertion_point(class_scope:UpdateCapabilitiesCommandMessage.Name)
-
- class CapabilitiesParameter(message.Message):
- __metaclass__ = reflection.GeneratedProtocolMessageType
- DESCRIPTOR = _UPDATECAPABILITIESCOMMANDMESSAGE_CAPABILITIESPARAMETER
-
- # @@protoc_insertion_point(class_scope:UpdateCapabilitiesCommandMessage.CapabilitiesParameter)
-
- class Capability(message.Message):
- __metaclass__ = reflection.GeneratedProtocolMessageType
- DESCRIPTOR = _UPDATECAPABILITIESCOMMANDMESSAGE_CAPABILITY
-
- # @@protoc_insertion_point(class_scope:UpdateCapabilitiesCommandMessage.Capability)
- DESCRIPTOR = _UPDATECAPABILITIESCOMMANDMESSAGE
-
- # @@protoc_insertion_point(class_scope:UpdateCapabilitiesCommandMessage)
-
-# @@protoc_insertion_point(module_scope)
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()
+
+
+
+
diff --git a/end-device.py b/end-device.py
index 0f085e7..fb97a23 100644
--- a/end-device.py
+++ b/end-device.py
@@ -19,14 +19,15 @@
import time
import json
-from pyndn import Name
-from pyndn import Face
-from pyndn import Interest
+from pyndn import Name, Face, Interest, Data, ThreadsafeFace
from pyndn import KeyLocator, KeyLocatorType
from base_node import BaseNode
from pyndn.security.security_exception import SecurityException
from pyndn.util import Blob
-
+try:
+ import asyncio
+except ImportError:
+ import trollius as asyncio
def dump(*list):
result = ""
@@ -35,88 +36,78 @@
print(result)
class Device(BaseNode):
- def __init__(self,configFileName,face):
+ def __init__(self,configFileName):
super(Device, self).__init__(configFileName=configFileName)
- #self.deviceSerial = self.getSerial()
+ self._deviceSerial = self.getSerial()
self._callbackCount = 0
- self._face = face
+ self._symKey = "symmetricKeyForBootstrapping"
+ self._category = "sensors"
+ self._id = "T9273659"
- def onData(self, interest, data):
- self._callbackCount += 1
- dump("Got data packet with name : ", data.getName().toUri())
- # Use join to convert each byte to chr.
- dump(data.getContent().toRawStr())
-
- #haven't checked symmetric key digest yet
- if (data.getName().toUri().startswith(self._bootstrapPrefix)):
- self.onBootstrapData(interest, data)
def expressBootstrapInterest(self):
- symKey = "symmetricKeyForBootstrapping"
- #generate bootstrap name /home/controller/bootstrap/<device-parameters>
- bootstrapName = Name(device._bootstrapPrefix)
+ #generate bootstrap name /home/controller/bootstrap/<device-parameters>
+ bootstrapName = Name(self._bootstrapPrefix)
deviceParameters = {}
- deviceParameters["category"] = "sensors"
- deviceParameters["id"] = "T123456789"
+ deviceParameters["category"] = self._category
+ deviceParameters["id"] = self._deviceSerial
bootstrapName.append(json.dumps(deviceParameters))
bootstrapInterest = Interest(bootstrapName)
-
bootstrapInterest.setInterestLifetimeMilliseconds(5000)
-
bootstrapKeyLocator = KeyLocator()
bootstrapKeyLocator.setType(KeyLocatorType.KEY_LOCATOR_DIGEST)
- bootstrapKeyLocator.setKeyData(symKey)
+ bootstrapKeyLocator.setKeyData(self._symKey)
bootstrapInterest.setKeyLocator(bootstrapKeyLocator)
- dump("Express interest :",bootstrapInterest.toUri())
- self._face.expressInterest(bootstrapInterest, self.onBootstrapData, self.onTimeout)
+ dump("Express bootstrap interest : ",bootstrapInterest.toUri())
+ self.face.expressInterest(bootstrapInterest, self.onBootstrapData, self.onTimeout)
def onBootstrapData(self, interest, data):
- dump("Data received.")
- content = json.loads(data.getContent().toRawStr(), encoding="latin-1")
- deviceNewIdentity = Name(content["deviceNewIdentity"])
- controllerIdentity = Name(content["controllerIdentity"])
- controllerPublicKeyInfo = content["controllerPublicKey"]
+ dump("Bootstrap data received.")
+ content = json.loads(data.getContent().toRawStr(), encoding="latin-1")
+ deviceNewIdentity = Name(content["deviceNewIdentity"])
+ controllerIdentity = Name(content["controllerIdentity"])
+ controllerPublicKeyInfo = content["controllerPublicKey"]
- #set new identity as default and generate default key-pair with KSK Certificate
- self._identityStorage.addIdentity(deviceNewIdentity)
- self._identityManager.setDefaultIdentity(deviceNewIdentity)
- try:
- self._identityManager.getDefaultKeyNameForIdentity(deviceNewIdentity)
- except SecurityException:
- #generate new key-pair and certificate for new identity
- dump("Installed new identity as default\nGenerating new key-pair and self signed certificate...")
- newKey = self._identityManager.generateRSAKeyPairAsDefault(Name(deviceNewIdentity), isKsk=True)
- newCert = self._identityManager.selfSign(newKey)
- self._identityManager.addCertificateAsIdentityDefault(newCert)
-
- #add controller's identity and public key
- keyType = controllerPublicKeyInfo["keyType"]
- keyName = Name(controllerPublicKeyInfo["keyName"])
- keyDer = Blob().fromRawStr(controllerPublicKeyInfo["publicKeyDer"])
- dump("KeyType: ",keyType)
- dump("keyName: ",keyName)
- dump("Controller public key der : ",keyDer)
+ #set new identity as default and generate default key-pair with KSK Certificate
+ self._identityStorage.addIdentity(deviceNewIdentity)
+ self._identityManager.setDefaultIdentity(deviceNewIdentity)
+ try:
+ self._identityManager.getDefaultKeyNameForIdentity(deviceNewIdentity)
+ except SecurityException:
+ #generate new key-pair and certificate for new identity
+ dump("Install new identity as default\nGenerate new key-pair and self signed certificate")
+ newKey = self._identityManager.generateRSAKeyPairAsDefault(Name(deviceNewIdentity), isKsk=True)
+ newCert = self._identityManager.selfSign(newKey)
+ self._identityManager.addCertificateAsIdentityDefault(newCert)
+
+ #add controller's identity and public key
+ keyType = controllerPublicKeyInfo["keyType"]
+ keyName = Name(controllerPublicKeyInfo["keyName"])
+ keyDer = Blob().fromRawStr(controllerPublicKeyInfo["publicKeyDer"])
+ dump("Controller's KeyType: ",keyType)
+ dump("Controller's keyName: ",keyName)
+ dump("Controller public key der : ",keyDer)
- self._identityStorage.addIdentity(controllerIdentity)
- try:
- self._identityStorage.addKey(keyName, keyType, keyDer)
- dump("Controller's identity, key and certificate installled.")
- except SecurityException:
- dump("Controller's identity, key, certificate already exists.")
+ self._identityStorage.addIdentity(controllerIdentity)
+ try:
+ self._identityStorage.addKey(keyName, keyType, keyDer)
+ dump("Controller's identity, key and certificate installled.")
+ except SecurityException:
+ dump("Controller's identity, key, certificate already exists.")
- #express an certificate request interest
- defaultKeyName = self._identityManager.getDefaultKeyNameForIdentity(self._keyChain.getDefaultIdentity() )
- self.requestCertificate(defaultKeyName)
+ #express an certificate request interest
+ defaultKeyName = self._identityManager.getDefaultKeyNameForIdentity(self._keyChain.getDefaultIdentity() )
+ self.requestCertificate(defaultKeyName)
def beforeLoopStart(self):
- pass
-
+ self.expressBootstrapInterest()
+
def onTimeout(self, interest):
self._callbackCount += 1
dump("Time out for interest", interest.getName().toUri())
@@ -125,47 +116,39 @@
"""
We compose a command interest with our public key info so the controller
can sign us a certificate that can be used with other nodes in the network.
- Name format : /home/<device-category>/KEY/<device-id>/<key-id>/<publickey>/ID-CERT/<version-number>
- """
- certificateRequestName = self._keyChain.getDefaultIdentity()
- deviceIdComponent = certificateRequestName.get(-1)
- keyIdComponent = keyIdentity.get(-1)
+ Name format : /home/<device-category>/KEY/<device-id>/<key-id>/<publickey>/ID-CERT/<version-number>
+ """
+ certificateRequestName = self._keyChain.getDefaultIdentity()
+ deviceIdComponent = certificateRequestName.get(-1)
+ keyIdComponent = keyIdentity.get(-1)
- certificateRequestName = certificateRequestName
- certificateRequestName.append("KEY")
- #certificateRequestName.append(deviceIdComponent)
- certificateRequestName.append(keyIdComponent)
+ certificateRequestName = certificateRequestName
+ certificateRequestName.append("KEY")
+ #certificateRequestName.append(deviceIdComponent)
+ certificateRequestName.append(keyIdComponent)
- key = self._identityManager.getPublicKey(keyIdentity)
- keyInfo = {}
- keyInfo["keyType"] = key.getKeyType()
- keyInfo["keyDer"] = key.getKeyDer().toRawStr()
+ key = self._identityManager.getPublicKey(keyIdentity)
+ keyInfo = {}
+ keyInfo["keyType"] = key.getKeyType()
+ keyInfo["keyDer"] = key.getKeyDer().toRawStr()
- certificateRequestName.append(json.dumps(keyInfo, encoding="latin-1"))
+ certificateRequestName.append(json.dumps(keyInfo, encoding="latin-1"))
- certificateRequestName.append("ID-CERT")
-
- dump("Sending certificate request : ",certificateRequestName)
+ certificateRequestName.append("ID-CERT")
+
+ dump("Sending certificate request : ",certificateRequestName)
- self._face.expressInterest(Interest(certificateRequestName), self.onCertificateData, self.onTimeout)
- #TODO use symmetric key to sign
-
+ self.face.expressInterest(Interest(certificateRequestName), self.onCertificateData, self.onTimeout)
+ #TODO use symmetric key to sign
+
def onCertificateData(self, interest, data):
- dump("OnCertificateData : ",data)
-
+ dump("OnCertificateData : ",data)
+
if __name__ == '__main__':
- face = Face("")
- device = Device("default.conf",face)
+ device = Device("default.conf")
+ device.start()
- device.expressBootstrapInterest()
- #device.requestCertificate(device._identityManager.getDefaultKeyNameForIdentity(device._keyChain.getDefaultIdentity() ))
-
- while device._callbackCount < 1000:
- 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()
+