大网数据广告活动
服务器运维问答

x509 extensions: can the "extnValue" be empty?

· 52CE 我爱测

I'm writing a script that parses x509 certificates. x509 v3 certificates have extensions which are an ASN.1 sequence containing an OID, a critical flag, and an octetString called extnValue . For the basicConstraints extension, th…

问题原文

原帖链接 · pinhead · CC BY-SA 4.0

I'm writing a script that parses x509 certificates. x509 v3 certificates have extensions which are an ASN.1 sequence containing an OID, a critical flag, and an octetString called extnValue.

For the basicConstraints extension, the extnValue is supposed to be another ASN.1 sequence with the details.

I've encountered a certificate that had an empty sequence there instead. Literally the bytes 0x30 0x00 which parse to an ASN.1 sequence of zero length, instead of the expected set of data (boolean for certificate authority and an integer for path length.

The fact that I found a cert in the wild with this quality implies that it is valid, but I was hoping to find a concrete protocol rule about this so my script can handle it correctly instead of throwing an error.

已采纳解答

原帖链接 · bartonjs · CC BY-SA 4.0

extnValue isn't empty, it's 30 00, which is an empty sequence.

https://www.rfc-editor.org/rfc/rfc5280#section-4.2.1.9 says that the encoding of a Basic Constraints extension value is

BasicConstraints ::= SEQUENCE {
    cA                      BOOLEAN DEFAULT FALSE,
    pathLenConstraint       INTEGER (0..MAX) OPTIONAL }

The empty sequence is therefore logically { cA: FALSE, pathLenConstraint: Not Present }.

Because certificates use ASN.1 DER encoding, a DEFAULT value should never be specified, and the text says that pathLenConstraint should never be specified when cA is set to FALSE, so 30 00 is the only valid form for "this certificate does not represent a Certificate Authority".

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-04-25)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。