我有一个分机,其描述如下:
Extension().setComponentByPosition(0, ObjectIdentifier(2.5.29.19))
.setComponentByPosition(1, Boolean('False'))
.setComponentByPosition(2, Any(hexValue='04023000'))因此,基于id,它是一个BasicConstraints扩展。但是,如果我试图将值解析为扩展本身,则会得到一个错误:
decoder.decode(decoder.decode(e['extnValue'])[0], rfc2459.BasicConstraints())
# PyAsn1Error: Uninitialized component #0 at BasicConstraints()该字符串解码为空序列,因此在法律上它可以是一个BasicConstraints - name length可选/缺失,而ca是默认的,所以没有在DER中编码。
我在这里错过了什么?如何将这个扩展解码为BasicConstraints类?
PS。这个问题看起来类似于一个邮寄名单中的问题,但是我使用的是0.1.8,它应该已经包含了上述的修复
发布于 2015-07-22 06:11:12
由于BasicConstraints是序列导数,其最小可能的序列化是序列标记和零长度。那么它的值可以是空字符串,正如您所建议的那样。事实上,情况就是这样:
>>> derSerialisation, _ = decode(OctetString(hexValue='04023000'))
>>> derSerialisation.prettyPrint()
'0x3000'
>>> constraint, _ = decode(derSerialisation)
>>> constraint.prettyPrint()
'Sequence:\n'ANY值是不透明的(无标记的),但是嵌入式DER序列化本身被编码为八进制字符串。因此,在将其传递给解码器以恢复BasicConstraints之前,请确保从八进制字符串序列化中提取DER内容。
邮件列表错误与此无关--这是在不确定的编码模式下。
更新
它原来是rfc2459.BasicConstraint规范中的一个bug。在准备正式修复/发布时,我可以向pyasn1_modules.rfc2459提供以下猴子补丁:
>>> from pyasn1.type import namedtype
>>> from pyasn1_modules import rfc2459
>>> rfc2459.BasicConstraints.componentType = namedtype.NamedTypes(
... namedtype.DefaultedNamedType(*rfc2459.BasicConstraints.componentType[0]),
... rfc2459.BasicConstraints.componentType[1]
... )它基本上将'cA‘组件标记为默认值。一旦应用,您的序列化可以解码:
>>> s
Any(hexValue='04023000')
>>> basicConstraints, _ = decoder.decode(decoder.decode(s)[0], rfc2459.BasicConstraints())
>>> print(basicConstraints.prettyPrint())
BasicConstraints:
cA='False'再次更新
以上错误已在pyasn1 1-模块0.0.7中修复。
https://stackoverflow.com/questions/31552798
复制相似问题