• DER编码


    X.501 Name类型用ASN.1描述如下:
    Name ::=CHOICE{ RDNSequence }
    RDNSequence ::= SEQUENCE OF RelativeDistinguishedNameRelativeDistinguishedName ::= SET OF AttributeValueAssertionAttribute ValueAssertion ::= SEQUENCE{
    AttributeType,
    AttributeValue }
    AttributeType ::= OBJECT IDENTIFIERAttribute Value ::= ANY

    Name类型定义为CHOICE类型,目前只有1个选项RDNSequence。RDNSequence定义为SEQUENCEOF类型,由0个或多个RelativeDistinguishedName组成。RelativeDistinguished-Name定义为SET OF类型,由0个或多个AttributeValueAssertion组成。AttributeValueAssertion定义为SEQUENCE类型,由2个成分组成:1个为AttributeType类型和1个AttributeValue类型。AttributeType定义为OBJECT IDENTIFIER类型。AttributeValue定义为ANY类型,具体内容由AttributeType决定。
    事实上,Name类型可理解为分层或树形结构,即X.500目录树结构。

    2.Name实例

    对于用户Test User 1,其对应的Name类型采用分层结构描述为:
    (root)
    countryName = "CN"
    organization Name= "20181217"
    commonName = "chenshaoqing"

    其中,每层对应一个RelativeDistinguishedName;每个RelativeDistinguishedName 由1个AttributeValueAssertion组成。等号前内容为AttributeType,等号后内容为AttributeValue。
    用户Test User 1包含3个AttributeType: countryName. organizationName,commonName,其OID定义如下:

    attributeType OBJECT IDENTIFIER ::= { joint-iso-ccitt(2) ds(5)4}countryName OBJECT IDENTIFIER:= { attributeType 6 }
    organizationName OBJECT IDENTIFIER::= { attributeType 10 }commonName OBJECT IDENTIFIER::= { attributeType 3 }

    3.DER编码过程

    1. AttributeType编码
    AttributeType为OBJECT IDENTIFIER基本类型,编码规则采用基本类型定长模式。对于标识串,采用低标识编码方式,只需1个字节。OBJECT IDENTIFIER的tag 为Ox06;class选择universal,则位8和位7为0,OBJECT IDENTIFIER为基本类型,则位6为0。因此,标识串=Ox06。
    对于长度串,采用短型编码方式,只需1个字节。
    对于内容串,由3个字节组成。2.5.4.6编码为550406,2.5.4.10编码为5504 0A,2.5.4.3编码为55 04 03。
    具体编码过程如表7-1所示。

    2. AttributeValue编码
    AttributeValue为 PrintableString 基本类型,编码规则采用基本类型定长模式。
    对于标识串,采用低标识编码方式,只需1个字节。PrintableString 的tag 为0x13;class选择universal,则位8和位7为0,OBJECT IDENTIFIER为基本类型,则位6为0。因此,标识串=Ox13。
    对于长度串,采用短型编码方式,只需1个字节。对于内容串,由其ASCII码组成。
    具体编码过程如表7-2所示。

    Attributevalue

    标识串 长度串 内容串
    “CN” 13 02 43 4E
    “20181217” 13 08 32 30 31 38 31 32 31 37
    “chenshaoqing” 13 0C 63 68 65 6E 73 68 61 6F 71 69 6E 67

    3. AttributeValueAssertion编码
    AttributeValueAssertion为 SEQUENCE结构类型,编码规则采用结构类型定长模式。对于标识串,采用低标识编码方式,只需1个字节。SEQUENCE的 tag 为0x10; class

    选择universal,则位8和位7为0,SEQUENCE为结构类型,则位6为1。因此,标识串=Ox30。
    对于长度串,采用短型编码方式,只需1个字节。
    对于内容串,由AttributeType和 AttributeValue的 DER编码值组成。具体编码过程如表7-3所示。

    AttributeValueAssertion

    标识串 长度串 内容串

    countryName="CN"

    30 09

    06 03 55 04 06 

    13 02 43 4E

    organizationName="20181217”

    30 0F

    06 03 55 04 0A

    13 08 32 30 31 38 31 32 31 37

    commonName ="chenshaoqing"

    30 13

    06 03 55 04 03

    13 0C 63 68 65 6E 73 68 61 6F 71 69 6E 67

    4. RelativeDistinguishedName编码
    RelativeDistinguishedName为SET OF结构类型,编码规则采用结构类型定长模式。对于标识串,采用低标识编码方式,只需1个字节。SET OF的tag 为0x11; class选择universal,则位8和位7为0,SET OF 为结构类型,则位6为1。因此,标识串=Ox31。
    对于长度串,采用短型编码方式,只需1个字节。
    对于内容串,由Attribute ValueAssertion的 DER编码值组成。具体编码过程如表7-4所示。

    RelativeDistinguishedName

    标识串 长度串 内容串
    countryName="CN"  31  0B

    30 09

        06 03 55 04 06 

        13 02 43 4E

    organizationName="20181217”  31  11

     30 0F

        06 03 55 04 0A

        13 08 32 30 31 38 31 32 31 37

    commonName ="chenshaoqing"  31  15

     30 13

        06 03 55 04 03

        13 0C 63 68 65 6E 73 68 61 6F 71 69 6E 67

    5. RDNSequence编码
    RDNSequence为SEQUENCE-OF结构类型,编码规则采用结构类型定长模式。对于标识串,采用低标识编码方式,只需1个字节。SEQUENCE OF的 tag 为0x10;class选择universal,则位8和位7为0,SEQUENCE OF为结构类型,则位6为1。因此,标识串=Ox30。
    对于长度串,采用短型编码方式,只需1个字节。
    对于内容串,由3个RelativeDistinguishedName的 DER编码值组成。具体编码过程如表7-5所示。

    RDNSequence

    标识串 长度串 内容串

    countryName ="CN"

    30  37

    31 0B

       30 09

        06 03 55 04 06 

        13 02 43 4E

    31 11

       30 0F

        06 03 55 04 0A

        13 08 32 30 31 38 31 32 31 37

    31 15

       30 13

        06 03 55 04 03

        13 0C 63 68 65 6E 73 68 61 6F 71 69 6E 67

    6.Name编码
    Name为CHOICE类型,其DER编码值与RDNSequence相同。用户Test User 1最终DER编码值如表7-6所示。

    DER编码值

    ASN.1描述

    30 37

       31 0B

         30 09

            06 03 55 04 06 

            13 02 43 4E

       31 11

          30 0F

             06 03 55 04 0A

             13 08 32 30 31 38 31 32 31 37

       31 15

          30 13

             06 03 55 04 03

             13 0C 63 68 65 6E 73 68 61 6F 71 69 6E 67

      

     

    attributeType = countryName

    attributeValue = "CN"
    attributeType = organizationName
    attributeValue = "20181217"
    attributeType = commonName
    attribute Value = "chenshaoqing"

    echo -n -e "x30x37x31x0Bx30x09x06x03x55x04x06x13x02x43x4Ex31x11x30x0Fx06x03x55x04x0Ax13x08x32x30x31x38x31x32x31x37x31x15x30x13x06x03x55x04x03x13x0Cx63x68x65x6Ex73x68x61x6Fx71x69x6Ex67" > 20181217.der

  • 相关阅读:
    【BZOJ 1013】 [JSOI2008]球形空间产生器sphere
    【codeforces 779A】Pupils Redistribution
    【codeforces 779B】Weird Rounding
    【codeforces 779C】Dishonest Sellers
    Residential Gateway System for Home Network Service
    互联网大规模数据分析技术(自主模式)第五章 大数据平台与技术 第10讲 大数据处理平台Hadoop
    大数据系统基础(自主模式) 2.1大数据和云计算关系概述
    设计模式(10) 外观模式(FACADE)
    命令模式(Command Pattern)
    设计模式(三)建造者模式Builder(创建型)
  • 原文地址:https://www.cnblogs.com/cindy123456/p/14904685.html
Copyright © 2020-2023  润新知