[0] 和 [3] 在 ASN1 中如何 wơrk? [英] How does [0] and [3] wơrk in ASN1?

查看:35
本文介绍了[0] 和 [3] 在 ASN1 中如何 wơrk?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在解码 ASN1(在 X.509 中用于 HTTPS 证书).我做得很好,但有件事我找不到并且无法理解文档.

I'm decoding ASN1 (as used in X.509 for HTTPS certificates). I'm doing pretty well, but there is a thing that I just cannot find and understandable documentation for.

在这个 JS ASN1 解析器中,您会看到一个 [0] 和一个[3]SEQUENCE 元素下,数据中的第一个看起来像这样:A0 03 02 01 02 ....我想知道这意味着什么以及如何解码.

In this JS ASN1 parser you see a [0] and a [3] under a SEQUENCE element, the first looking like this in data: A0 03 02 01 02 .... I want to know what this means and how to decode it.

另一个例子是X.509 v3 证书的剖析,在前两个 SEQUENCE 元素之后有一个 [0].

Another example is Anatomy of an X.509 v3 Certificate, there is a [0] right after the first two SEQUENCE elements.

我不明白的是 A0 如何与标签字节的前 2 位是一个类,下一个原始/构造位和其余 5 位应该是标签类型的方案相适应.A0 是 10100000,这意味着标签类型值将为零.

What I don't understand is how A0 fits with the scheme where the first 2 bits of the tag byte are a class, the next a primitive/constructed bit and the remaining 5 are supposed to be the tag type. A0 is 10100000 which means that the tag type value would be zero.

推荐答案

ASN.1 BER 和 DER 使用 ASN.1 TAGS 来明确标识编码流中的某些组件.ASN.1 标签有 4 类:UNIVERSAL、APPLICATION、PRIVATE 和 context-specific.[0] 是上下文特定的标签,因为它前面没有标签类关键字.UNIVERSAL 是为 ASN.1 中的内置类型保留的.大多数情况下,您会看到特定于上下文的标签以消除包含 OPTIONAL 元素的 SEQUENCE 中潜在的歧义.如果您知道自己收到了两个不是可选的物品,一个接一个,您就知道哪个是哪个,即使它们的标签相同.但是,如果第一个是可选的,则两者必须具有不同的标签,否则如果编码中只有一个,您将无法分辨收到的是哪个.

ASN.1 BER and DER use ASN.1 TAGS to unambiguously identify certain components in an encoded stream. There are 4 classes of ASN.1 tags: UNIVERSAL, APPLICATION, PRIVATE, and context-specific. The [0] is a context-specific tag since there is no tag class keword in front of it. UNIVERSAL is reserved for built-in types in ASN.1. Most often you see context specific tags to eliminate potential ambiguity in a SEQUENCE which contains OPTIONAL elements. If you know you are receiving two items that are not optional, one after the other, you know which is which even if their tags are the same. However, if the first one is optional, the two must have different tags, or you would not be able to tell which one you had received if only one was present in the encoding.

今天最常见的是,ASN.1 规范使用AUTOMATIC TAGS";这样您就不必担心消息中的这种消歧,因为 SEQUENCE、SET 和 CHOICE 的组件将自动为每个组件获取以 [0]、[1]、[2] 等开头的上下文特定标签.

Most often today, ASN.1 specification use "AUTOMATIC TAGS" so that you don't have to worry about this kind of disambiguation in messages since components of SEQUENCE, SET and CHOICE will automatically get context specific tags starting with [0], [1], [2], etc. for each component.

您可以在 http://www.oss.com/asn1/resources/books-whitepapers-pubs/asn1-books.html 其中有两本可免费下载的书籍.

You can find more information on ASN.1 tags at http://www.oss.com/asn1/resources/books-whitepapers-pubs/asn1-books.html where two free downloadable books are available.

另一个优秀的资源是http://asn1-playground.oss.com,您可以在那里尝试在线编译器和编码器/解码器中具有不同标签的 ASN.1 规范的变体.您可以在那里看到标签更改对编码的影响.

Another excellent resource is http://asn1-playground.oss.com where you can try variations of ASN.1 specifications with different tags in an online compiler and encoder/decoder. There you can see the effects of tag changes on encodings.

这篇关于[0] 和 [3] 在 ASN1 中如何 wơrk?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆