本文整理汇总了Python中pyndn.security.KeyChain.getCertificate方法的典型用法代码示例。如果您正苦于以下问题:Python KeyChain.getCertificate方法的具体用法?Python KeyChain.getCertificate怎么用?Python KeyChain.getCertificate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyndn.security.KeyChain
的用法示例。
在下文中一共展示了KeyChain.getCertificate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Bootstrap
# 需要导入模块: from pyndn.security import KeyChain [as 别名]
# 或者: from pyndn.security.KeyChain import getCertificate [as 别名]
class Bootstrap(object):
"""
Create a Bootstrap object. Bootstrap object provides interface for setting up KeyChain, default certificate name;
(as a producer) requesting publishing authorization from controller; and (as a consumer) keeping track of changes
:param face: the face for communicating with a local / remote forwarder
:type face: ThreadsafeFace
TODO: support Face as well as ThreadsafeFace
"""
def __init__(self, face):
self._defaultIdentity = None
self._defaultCertificateName = None
self._controllerName = None
self._controllerCertificate = None
self._applicationName = ""
self._identityManager = IdentityManager(BasicIdentityStorage(), FilePrivateKeyStorage())
self._policyManager = ConfigPolicyManager()
self._policyManager.config.read("validator \n \
{ \n \
rule \n \
{ \n \
id \"initial rule\" \n \
for data \n \
checker \n \
{ \n \
type hierarchical \n \
} \n \
} \n \
}", "initial-schema")
# keyChain is what we return to the application after successful setup
# TODO: should we separate keyChain from internal KeyChain used to verify trust schemas?
self._keyChain = KeyChain(self._identityManager, self._policyManager)
self._face = face
# setFace for keyChain or else it won't be able to express interests for certs
self._keyChain.setFace(self._face)
self._certificateContentCache = MemoryContentCache(face)
self._trustSchemas = dict()
###############################################
# Initial keyChain and defaultCertificate setup
###############################################
def setupDefaultIdentityAndRoot(self, defaultIdentityOrFileName, signerName = None, onSetupComplete = None, onSetupFailed = None):
"""
Sets up the keyChain, default key name and certificate name according to given
configuration. If successful, this KeyChain and default certificate name will be
returned to the application, which can be passed to instances like Consumer, Discovery, etc
:param defaultIdentityOrFileName: if str, the name of the configuration file; if Name,
the default identity name of this IoT node. The node will use the default keys and
certificate of that identity name.
:type defaultIdentityOrFileName: Name or str
:param signerName: (optional) the expected signing identity of the certificate
:type signerName: Name
:param onSetupComplete: (optional) onSetupComplete(Name, KeyChain) will be called if
set up's successful
:type onSetupComplete: function object
:param onSetupFailed: (optional) onSetupFailed(msg) will be called if setup fails
:type onSetupFailed: function object
"""
def helper(identityName, signerName):
try:
self._defaultIdentity = identityName
self._defaultCertificateName = self._identityManager.getDefaultCertificateNameForIdentity(self._defaultIdentity)
self._defaultKeyName = self._identityManager.getDefaultKeyNameForIdentity(identityName)
except SecurityException:
msg = "Identity " + identityName.toUri() + " in configuration does not exist. Please configure the device with this identity first."
if onSetupFailed:
onSetupFailed(msg)
return
if not self._defaultCertificateName:
msg = "Unable to get default certificate name for identity " + identityName.toUri() + ". Please configure the device with this identity first."
if onSetupFailed:
onSetupFailed(msg)
return
if not self._defaultKeyName:
msg = "Unable to get default key name for identity " + identityName.toUri() + ". Please configure the device with this identity first."
if onSetupFailed:
onSetupFailed(msg)
return
# Note we'll not be able to issue face commands before this point
self._face.setCommandSigningInfo(self._keyChain, self._defaultCertificateName)
# Serve our own certificate
self._certificateContentCache.registerPrefix(Name(self._defaultCertificateName).getPrefix(-1), self.onRegisterFailed)
self._certificateContentCache.add(self._keyChain.getCertificate(self._defaultCertificateName))
actualSignerName = self._keyChain.getCertificate(self._defaultCertificateName).getSignature().getKeyLocator().getKeyName()
if not signerName:
print "Deriving from " + actualSignerName.toUri() + " for controller name"
else:
if signerName and actualSignerName.toUri() != signerName.toUri():
#.........这里部分代码省略.........