本文整理汇总了Python中pyndn.security.KeyChain.getDefaultCertificateName方法的典型用法代码示例。如果您正苦于以下问题:Python KeyChain.getDefaultCertificateName方法的具体用法?Python KeyChain.getDefaultCertificateName怎么用?Python KeyChain.getDefaultCertificateName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyndn.security.KeyChain
的用法示例。
在下文中一共展示了KeyChain.getDefaultCertificateName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Producer
# 需要导入模块: from pyndn.security import KeyChain [as 别名]
# 或者: from pyndn.security.KeyChain import getDefaultCertificateName [as 别名]
class Producer(object):
def __init__(self, delay=None):
self.delay = delay
self.nDataServed = 0
self.isDone = False
def run(self, prefix):
self.keyChain = KeyChain()
self.consoleThread = ConsoleThread()
self.consoleThread.start()
# The default Face will connect using a Unix socket
face = Face()
prefix = Name(prefix)
# Use the system default key chain and certificate name to sign commands.
face.setCommandSigningInfo(self.keyChain, self.keyChain.getDefaultCertificateName())
# Also use the default certificate name to sign data packets.
face.registerPrefix(prefix, self.onInterest, self.onRegisterFailed)
print "Registering prefix", prefix.toUri()
while not self.isDone:
face.processEvents()
time.sleep(0.01)
def onInterest(self, prefix, interest, transport, registeredPrefixId):
global stopServing
if stopServing:
print "refusing to serve " + interest.getName().toUri()
self.consoleThread.join()
print "join'd thread"
return
if self.delay is not None:
time.sleep(self.delay)
interestName = interest.getName()
data = Data(interestName)
data.setContent("Hello " + interestName.toUri())
data.getMetaInfo().setFreshnessPeriod(3600 * 1000)
self.keyChain.sign(data, self.keyChain.getDefaultCertificateName())
transport.send(data.wireEncode().toBuffer())
self.nDataServed += 1
print "Replied to: %s (#%d)" % (interestName.toUri(), self.nDataServed)
def onRegisterFailed(self, prefix):
print "Register failed for prefix", prefix.toUri()
示例2: main
# 需要导入模块: from pyndn.security import KeyChain [as 别名]
# 或者: from pyndn.security.KeyChain import getDefaultCertificateName [as 别名]
def main():
"""
Call requestInsert and register a prefix so that ProduceSegments will answer
interests from the repo to send the data packets. This assumes that repo-ng
is already running (e.g. `sudo ndn-repo-ng`).
"""
repoCommandPrefix = Name("/example/repo/1")
repoDataPrefix = Name("/example/data/1")
nowMilliseconds = int(time.time() * 1000.0)
fetchPrefix = Name(repoDataPrefix).append("testinsert").appendVersion(nowMilliseconds)
# 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.
keyChain = KeyChain()
face.setCommandSigningInfo(keyChain, keyChain.getDefaultCertificateName())
# Register the prefix and send the repo insert command at the same time.
startBlockId = 0
endBlockId = 1
enabled = [True]
def onFinished():
dump("All data was inserted.")
enabled[0] = False
produceSegments = ProduceSegments(
keyChain, keyChain.getDefaultCertificateName(), startBlockId, endBlockId,
onFinished)
dump("Register prefix", fetchPrefix.toUri())
def onRegisterFailed(prefix):
dump("Register failed for prefix", prefix.toUri())
enabled[0] = False
face.registerPrefix(
fetchPrefix, produceSegments.onInterest, onRegisterFailed)
def onInsertStarted():
dump("Insert started for", fetchPrefix.toUri())
def onFailed():
enabled[0] = False
requestInsert(
face, repoCommandPrefix, fetchPrefix, onInsertStarted, onFailed,
startBlockId, endBlockId)
# Run until all the data is sent.
while enabled[0]:
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()
示例3: status_put
# 需要导入模块: from pyndn.security import KeyChain [as 别名]
# 或者: from pyndn.security.KeyChain import getDefaultCertificateName [as 别名]
def status_put(name, data):
# Use the system default key chain and certificate name to sign commands.
keyChain = KeyChain()
face.setCommandSigningInfo(keyChain, keyChain.getDefaultCertificateName())
# Also use the default certificate name to sign data packets.
echo = Echo(keyChain, keyChain.getDefaultCertificateName(), data)
prefix = Name(name)
dump("Register prefix", prefix.toUri())
logging.debug('Register prefix ' + prefix.toUri())
face.registerPrefix(prefix, echo.onInterest, echo.onRegisterFailed)
face.processEvents()
示例4: main
# 需要导入模块: from pyndn.security import KeyChain [as 别名]
# 或者: from pyndn.security.KeyChain import getDefaultCertificateName [as 别名]
def main():
"""
Call startRepoWatch and register a prefix so that SendSegments will answer
interests from the repo to send data packets for the watched prefix. When
all the data is sent (or an error), call stopRepoWatch. This assumes that
repo-ng is already running (e.g. `sudo ndn-repo-ng`).
"""
repoCommandPrefix = Name("/example/repo/1")
repoDataPrefix = Name("/example/data/1")
nowMilliseconds = int(time.time() * 1000.0)
watchPrefix = Name(repoDataPrefix).append("testwatch").appendVersion(
nowMilliseconds)
# 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.
keyChain = KeyChain()
face.setCommandSigningInfo(keyChain, keyChain.getDefaultCertificateName())
# Register the prefix and start the repo watch at the same time.
enabled = [True]
def onFinishedSending():
stopRepoWatchAndQuit(face, repoCommandPrefix, watchPrefix, enabled)
sendSegments = SendSegments(
keyChain, keyChain.getDefaultCertificateName(), onFinishedSending)
def onRegisterFailed(prefix):
dump("Register failed for prefix", prefix.toUri())
enabled[0] = False
dump("Register prefix", watchPrefix.toUri())
face.registerPrefix(watchPrefix, sendSegments.onInterest, onRegisterFailed)
def onRepoWatchStarted():
dump("Watch started for", watchPrefix.toUri())
def onStartFailed():
dump("startRepoWatch failed.")
stopRepoWatchAndQuit(face, repoCommandPrefix, watchPrefix, enabled)
startRepoWatch(
face, repoCommandPrefix, watchPrefix, onRepoWatchStarted, onStartFailed)
# Run until someone sets enabled[0] = False.
enabled[0] = True
while enabled[0]:
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()
示例5: Producer
# 需要导入模块: from pyndn.security import KeyChain [as 别名]
# 或者: from pyndn.security.KeyChain import getDefaultCertificateName [as 别名]
class Producer(object):
def __init__(self):
self.keyChain = KeyChain()
self.isDone = False
def run(self, namespace):
# Create a connection to the local forwarder over a Unix socket
face = Face()
prefix = Name(namespace)
# Use the system default key chain and certificate name to sign commands.
face.setCommandSigningInfo(self.keyChain, \
self.keyChain.getDefaultCertificateName())
# Also use the default certificate name to sign Data packets.
face.registerPrefix(prefix, self.onInterest, self.onRegisterFailed)
print "Registering prefix", prefix.toUri()
# Run the event loop forever. Use a short sleep to
# prevent the Producer from using 100% of the CPU.
while not self.isDone:
face.processEvents()
time.sleep(0.01)
def onInterest(self, prefix, interest, transport, registeredPrefixId):
interestName = interest.getName()
data = Data(interestName)
data.setContent("Hello, " + interestName.toUri())
hourMilliseconds = 3600 * 1000
data.getMetaInfo().setFreshnessPeriod(hourMilliseconds)
self.keyChain.sign(data, self.keyChain.getDefaultCertificateName())
transport.send(data.wireEncode().toBuffer())
print "Replied to: %s" % interestName.toUri()
def onRegisterFailed(self, prefix):
print "Register failed for prefix", prefix.toUri()
self.isDone = True
示例6: ThreadsafeFaceWrapper
# 需要导入模块: from pyndn.security import KeyChain [as 别名]
# 或者: from pyndn.security.KeyChain import getDefaultCertificateName [as 别名]
class ThreadsafeFaceWrapper(object):
def __init__(self):
self._loop = asyncio.get_event_loop()
self._face = ThreadsafeFace(self._loop, "")
self._keyChain = KeyChain()
self._certificateName = self._keyChain.getDefaultCertificateName()
self._face.setCommandSigningInfo(self._keyChain, self._certificateName)
def startProcessing(self):
try:
self._loop.run_forever()
finally:
self.stop()
def stopProcessing(self):
self._loop.close()
self._face.shutdown()
self._face = None
sys.exit(1)
def getFace(self):
return self._face
def getLoop(self):
return self._loop
示例7: main
# 需要导入模块: from pyndn.security import KeyChain [as 别名]
# 或者: from pyndn.security.KeyChain import getDefaultCertificateName [as 别名]
def main():
# The default Face will connect using a Unix socket, or to "localhost".
face = Face()
keyChain = KeyChain()
face.setCommandSigningInfo(keyChain, keyChain.getDefaultCertificateName())
dataPrefix = "/home/test1/data"
repoDataPrefix = "/home/test1/data"
# Set up repo-ng, register prefix for repo-ng's fetch prefix
# Per configuration file in /usr/local/etc/ndn/repo-ng.conf
# memCache is not used for now; repo is hoping that the piece of data in question is still being held at nfd
#memCache = MemoryContentCache(face, 100000)
#memCache.registerPrefix(Name(repoDataPrefix), onRegisterFailed, onDataNotFound)
counter = Counter(face, repoDataPrefix)
interest = Interest(Name(dataPrefix))
interest.setChildSelector(1)
interest.setInterestLifetimeMilliseconds(defaultInterestLifetime)
face.expressInterest(interest, counter.onData, counter.onTimeout)
while True:
face.processEvents()
# We need to sleep for a few milliseconds so we don't use 100% of the CPU.
time.sleep(1)
face.shutdown()
示例8: onSetupFailed
# 需要导入模块: from pyndn.security import KeyChain [as 别名]
# 或者: from pyndn.security.KeyChain import getDefaultCertificateName [as 别名]
def onSetupFailed(msg):
print(msg)
print("In this test, try start publishing with default keychain certificate anyway")
keyChain = KeyChain()
try:
defaultCertificateName = keyChain.getDefaultCertificateName()
startProducers(defaultCertificateName, keyChain)
except SecurityException as e:
print str(e)
示例9: main
# 需要导入模块: from pyndn.security import KeyChain [as 别名]
# 或者: from pyndn.security.KeyChain import getDefaultCertificateName [as 别名]
def main():
# Silence the warning from Interest wire encode.
Interest.setDefaultCanBePrefix(True)
interest = Interest()
interest.wireDecode(TlvInterest)
dump("Interest:")
dumpInterest(interest)
# Set the name again to clear the cached encoding so we encode again.
interest.setName(interest.getName())
encoding = interest.wireEncode()
dump("")
dump("Re-encoded interest", encoding.toHex())
reDecodedInterest = Interest()
reDecodedInterest.wireDecode(encoding)
dump("Re-decoded Interest:")
dumpInterest(reDecodedInterest)
freshInterest = (Interest(Name("/ndn/abc"))
.setMustBeFresh(False)
.setMinSuffixComponents(4)
.setMaxSuffixComponents(6)
.setInterestLifetimeMilliseconds(30000)
.setChildSelector(1)
.setMustBeFresh(True))
freshInterest.getKeyLocator().setType(KeyLocatorType.KEY_LOCATOR_DIGEST)
freshInterest.getKeyLocator().setKeyData(bytearray(
[0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F]))
freshInterest.getExclude().appendComponent(Name("abc")[0]).appendAny()
freshInterest.getForwardingHint().add(1, Name("/A"))
dump(freshInterest.toUri())
# Set up the KeyChain.
keyChain = KeyChain("pib-memory:", "tpm-memory:")
keyChain.importSafeBag(SafeBag
(Name("/testname/KEY/123"),
Blob(DEFAULT_RSA_PRIVATE_KEY_DER, False),
Blob(DEFAULT_RSA_PUBLIC_KEY_DER, False)))
validator = Validator(ValidationPolicyFromPib(keyChain.getPib()))
# Make a Face just so that we can sign the interest.
face = Face("localhost")
face.setCommandSigningInfo(keyChain, keyChain.getDefaultCertificateName())
face.makeCommandInterest(freshInterest)
reDecodedFreshInterest = Interest()
reDecodedFreshInterest.wireDecode(freshInterest.wireEncode())
dump("")
dump("Re-decoded fresh Interest:")
dumpInterest(reDecodedFreshInterest)
validator.validate(
reDecodedFreshInterest, makeSuccessCallback("Freshly-signed Interest"),
makeFailureCallback("Freshly-signed Interest"))
示例10: main
# 需要导入模块: from pyndn.security import KeyChain [as 别名]
# 或者: from pyndn.security.KeyChain import getDefaultCertificateName [as 别名]
def 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.
keyChain = KeyChain()
face.setCommandSigningInfo(keyChain, keyChain.getDefaultCertificateName())
# Also use the default certificate name to sign data packets.
echo = Echo(keyChain, keyChain.getDefaultCertificateName())
prefix = Name("/testecho")
dump("Register prefix", prefix.toUri())
face.registerPrefix(prefix, echo.onInterest, echo.onRegisterFailed)
while echo._responseCount < 1:
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()
示例11: start
# 需要导入模块: from pyndn.security import KeyChain [as 别名]
# 或者: from pyndn.security.KeyChain import getDefaultCertificateName [as 别名]
def start(self):
self.isStopped = False
self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(self.loop)
self.face = ThreadsafeFace(self.loop, '')
k = KeyChain()
self.face.setCommandSigningInfo(k, k.getDefaultCertificateName())
self.face.stopWhen(lambda:self.isStopped)
try:
self.loop.run_until_complete(self.sendNextInsertRequest())
finally:
self.face.shutdown()
示例12: main
# 需要导入模块: from pyndn.security import KeyChain [as 别名]
# 或者: from pyndn.security.KeyChain import getDefaultCertificateName [as 别名]
def main():
# Params parsing
parser = argparse.ArgumentParser(description='bms gateway node to Parse or follow Cascade Datahub log and publish to MiniNdn.')
parser.add_argument('filename', help='datahub log file')
parser.add_argument('-f', dest='follow', action='store_true', help='follow (tail -f) the log file')
parser.add_argument('--namespace', default='/ndn/edu/ucla/remap/bms', help='root of ndn name, no trailing slash')
args = parser.parse_args()
# Setup logging
logger = Logger()
logger.prepareLogging()
# Face, KeyChain, memoryContentCache and asio event loop initialization
loop = asyncio.get_event_loop()
face = ThreadsafeFace(loop, "128.97.98.7")
keyChain = KeyChain(IdentityManager(BasicIdentityStorage(), FilePrivateKeyStorage()))
# For the gateway publisher, we create one identity for it to sign nfd command interests
#certificateName = keyChain.createIdentityAndCertificate(Name("/ndn/bms/gateway-publisher"))
face.setCommandSigningInfo(keyChain, keyChain.getDefaultCertificateName())
print "Using certificate name " + keyChain.getDefaultCertificateName().toUri()
cache = MemoryContentCache(face)
dataPublisher = DataPublisher(face, keyChain, loop, cache, args.namespace)
cache.registerPrefix(Name(args.namespace), dataPublisher.onRegisterFailed, dataPublisher.onDataNotFound)
# Parse csv to decide the mapping between sensor JSON -> <NDN name, data type>
dataPublisher.populateSensorNDNDictFromCSV('bms-sensor-data-types-sanitized.csv')
loop.call_later(dataPublisher._restartInterval, dataPublisher.checkAlive)
if args.follow:
#asyncio.async(loop.run_in_executor(executor, followfile, args.filename, args.namespace, cache))
loop.run_until_complete(dataPublisher.followfile(args.filename))
else:
loop.run_until_complete(dataPublisher.readfile(args.filename))
loop.run_forever()
face.shutdown()
示例13: main
# 需要导入模块: from pyndn.security import KeyChain [as 别名]
# 或者: from pyndn.security.KeyChain import getDefaultCertificateName [as 别名]
def main():
loop = asyncio.get_event_loop()
face = ThreadsafeFace(loop, "localhost")
keyChain = KeyChain()
face.setCommandSigningInfo(keyChain, keyChain.getDefaultCertificateName())
# TODO: NFD hack: uncomment once NFD forwarding fixed
# discoveree = Discoveree(loop, face, keyChain)
# TODO: NFD hack: remove once NFD forwarding fixed
discoveree = LocalDiscoveree(loop, face, keyChain)
cecTv = CecTv(loop, face, keyChain, discoveree)
loop.run_forever()
face.shutdown()
示例14: main
# 需要导入模块: from pyndn.security import KeyChain [as 别名]
# 或者: from pyndn.security.KeyChain import getDefaultCertificateName [as 别名]
def main():
face = Face()
# Use the system default key chain and certificate name to sign commands.
keyChain = KeyChain()
certificateName = keyChain.getDefaultCertificateName()
face.setCommandSigningInfo(keyChain, certificateName)
test = DiscoveryTest(face, keyChain, certificateName)
test.start()
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()
示例15: start
# 需要导入模块: from pyndn.security import KeyChain [as 别名]
# 或者: from pyndn.security.KeyChain import getDefaultCertificateName [as 别名]
def start(self):
self.isStopped = False
self.loop = asyncio.get_event_loop()
self.face = ThreadsafeFace(self.loop, '')
self.keyFace = ThreadsafeFace(self.loop, 'borges.metwi.ucla.edu')
self.face.stopWhen(lambda:self.isStopped)
self.keyFace.stopWhen(lambda:self.isStopped)
k = KeyChain()
self.face.setCommandSigningInfo(k, k.getDefaultCertificateName())
try:
self.loop.run_until_complete(self.parseDataRequest())
except (EOFError, KeyboardInterrupt):
pass
finally:
self.face.shutdown()