I am trying to create cert for Elasticsearch Searchguard. One requirement is that the cert must include oid:1.2.3.4.5.5
in SANs. I am using GO to generate that cert. After some trial and error I have figured out that if I use []byte{0x88, 0x05, 0x2A, 0x03, 0x04, 0x05, 0x05}
as Raw ASN.1 bytes, this turns into oid:1.2.3.4.5.5
in SANs . I want to understand how these bytes represent the value oid:1.2.3.4.5.5
. I have read this, but I am still confused. Can you help me understand how this []byte represents oid:1.2.3.4.5.5
?
如何解析DER字节?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- dsa1234569 2017-12-21 02:56关注
Mostly dupe How does ASN.1 encode an object identifier?
The encoding of the (X.509=PKIX) SAN extension's value is defined in rfc5280 as:
SubjectAltName ::= GeneralNames GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName GeneralName ::= CHOICE { // tags implicit otherName [0] AnotherName, rfc822Name [1] IA5String, dNSName [2] IA5String, x400Address [3] ORAddress, directoryName [4] Name, ediPartyName [5] EDIPartyName, uniformResourceIdentifier [6] IA5String, iPAddress [7] OCTET STRING, registeredID [8] OBJECT IDENTIFIER }
For this CHOICE, your first octet 0x88 is the tag value for context-specific #8 (meaning registeredID), and your second octet 0x05 is the length of the value, which is encoded as 0x2A 0x03 0x04 0x05 0x05. Since this value is an object identifier, to decode it look at the section on encoding under OBJECT IDENTIFIER in the Kaliski document:
BER encoding. Primitive. Contents octets are as follows, where value1, ..., valuen denote the integer values of the components in the complete object identifier:
The first octet has value 40 * value1 + value2. (This is unambiguous, since value1 is limited to values 0, 1, and 2; value2 is limited to the range 0 to 39 when value1 is 0 or 1; and, according to X.208, n is always at least 2.)
The following octets, if any, encode value3, ..., valuen. Each value is encoded base 128, most significant digit first, with as few digits as possible, and the most significant bit of each octet except the last in the value's encoding set to "1."
The first value octet 0x2A is decimal 42 and 42 = 40 * 1 + 2, so the first two components of the OID are 1 and 2. All of the remaining octets do not have their most-significant bit set so they each encode one component: 3 4 5 5. The OID consisting of the components 1 2 3 4 5 5 is in the usual shorthand notation 1.2.3.4.5.5 (but there are other equivalent notations as shown in Kaliski).
Incidentally, that OID is invalid because it would have to be under the member-body of the country with ISO3166 numeric code 3 and there is no such country.
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 PointNet++的onnx模型只能使用一次
- ¥20 西南科技大学数字信号处理
- ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
- ¥30 STM32 INMP441无法读取数据
- ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
- ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
- ¥15 用visualstudio2022创建vue项目后无法启动
- ¥15 x趋于0时tanx-sinx极限可以拆开算吗
- ¥500 把面具戴到人脸上,请大家贡献智慧,别用大模型回答,大模型的答案没啥用
- ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。