def __init__(self, name, key): self.name = name self.key = key kl = ndn.KeyLocator(key) self.signed_info = ndn.SignedInfo(key_locator=kl, key_digest=key.publicKeyID)
def prepareContent(self, content, key): # create a new data packet co = ndn.ContentObject() # since they want us to use versions and segments append those to our name co.name = self.name.appendVersion().appendSegment(0) # place the content co.content = content si = co.signedInfo # key used to sign data (required by ndnx) si.publisherPublicKeyDigest = key.publicKeyID # how to obtain the key (required by ndn); here we attach the # key to the data (not too secure), we could also provide name # of the key under which it is stored in DER format si.keyLocator = ndn.KeyLocator(key) # data type (not needed, since DATA is the default) si.type = ndn.CONTENT_DATA # number of the last segment (0 - i.e. this is the only # segment) si.finalBlockID = ndn.Name.num2seg(0) # signing the packet co.sign(key) return co
def __init__(self, prefix, nick=getpass.getuser()): self.handle = ndn.Face() self.flow = FlowController(prefix, self.handle) #XXX: temporary, until we allow fetching key from key storage self.key = self.handle.getDefaultKey() self.keylocator = ndn.KeyLocator(self.key) self.prefix = ndn.Name(prefix) self.members_uri = self.prefix + "members" member_name = self.members_uri.appendKeyID( fix_digest(self.key.publicKeyID)) self.member_message = self.publish(member_name, nick) self.flow.put(self.member_message)
def publish(name, content): key = ndn.Face.getDefaultKey() keylocator = ndn.KeyLocator(key) # Name co_name = ndn.Name(name).appendSegment(0) # SignedInfo si = ndn.SignedInfo() si.type = ndn.CONTENT_DATA si.finalBlockID = ndn.Name.num2seg(0) si.publisherPublicKeyDigest = key.publicKeyID si.keyLocator = keylocator # ContentObject co = ndn.ContentObject() co.content = content co.name = co_name co.signedInfo = si co.sign(key) return co
def key_locator(self): return ndn.KeyLocator(self.name)