真相已经不远了。

首先我们查看函数 d2i_X509, 前已述及,该函数将 ASN1 格式(DER 编码)的 X509 证书内容转换为内部数据格式(X509 结构),其定义如下
X509 *d2i_X509(X509 **a, const unsigned char **in, long len) {
    return (X509 *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, (X509_it()));
}
d2i_X509 在内部调用 ASN1_item_d2i(并传入一个 ASN1_ITEM 结构地址), 后者在内部调用函数 ASN1_item_ex_d2i(将此结构地址透传)

这里出现了一个重要的数据结构 ASN1_ITEM, 它是干什么用的?

我们知道, ASN1 表示的内容是用 TLV 格式编码。对于 X509 证书而言,其内容表示如下
    Certificate  ::=  SEQUENCE  {
        tbsCertificate       TBSCertificate,
        signatureAlgorithm   AlgorithmIdentifier,
        signatureValue       BIT STRING
    }
上面的 Certificate 就是最外层的一个 TLV, 至于其内部的 tbsCertificate 等字段也是一个 TLV, tbsCertificate 的各个属性如版本、序列号等则是由各子 TLV 构成。
一句话,所有大大小小的证书属性(TLV 对)构成了一棵树,下图更好地说明了这点

图中树的各个节点在 OpenSSL 中都有与之一一对应的 ASN1_ITEM
函数 ASN1_item_ex_d2i 根据不同的 ASN1_ITEM 类型,将输入的 ASN1 编码转换为内部(d2i 中的 i)不同的数据格式
ASN1_ITEM 则扮演着类似模板的角色,不同类型的节点(TLV)对应不同的 ASN1_ITEM 模板内容(关键点)

这些 ASN_ITEM 位于代码何处?比如说表示树的根节点的 ASN1_ITEM, 它在哪里定义?
很不幸, OpenSSL 又把它悄悄地隐藏起来了 -- 幸运的是,上一节已经为你扫清了障碍。
它在宏定义对 ASN1_SEQUENCE_ref(X509, x509_cb, CRYPTO_LOCK_X509)/ASN1_SEQUENCE_END_ref(X509, X509) 中(见文件 x_x509.c)

上一节中给出的 make_def.txt 已经包含这个宏了,所以运行脚本 auto_expand_macro.pl 就可以在源文件中看到它的真容。
宏展开后,我们看到,此 ASN1_ITEM 定义为函数 X509_it 中的静态变量(事实上所有 ASN1_ITEM 都是静态变量),其内容是表示证书总信息的模板。

不同的 ASN1_ITEM 节点又如何组成一棵树?我们很容易想到:用指针作为 ASN1_ITEM 的成员,表示父子节点之间的联系。
概念很清楚,但代码实现有一点小问题:父节点中需要多少个指针?父节点不同,子节点个数也不同。
为解决这个问题, OpenSSL 中引入一个中间数据结构 ASN1_TEMPLATE(见 ASN1_ITEM 的成员 templates)。
如果 ASN1_ITEM 节点下面 有成员(作为中间节点),则 templates 描述子节点信息。
如果 ASN1_ITEM 节点下面没有成员(作为叶子节点),则 templates 为空。

下面是 ASN1_ITEM/ASN1_TEMPLATE 的定义

View Code
 1 struct ASN1_ITEM_st {
 2     char itype; // ASN1_ITEM 主类型: PRIMITIVE, SEQUENCE, CHOICE, etc
 3     long utype; // ASN1_ITEM 子类型: 取决于主类型,比如为 PRIMITIVE 时, 2 -- ASN1_INTEGER
 4     const ASN1_TEMPLATE *templates; // itype == SEQUENCE/CHOICE 时表示为中间节点
 5     long tcount;                    // 数组 templates[] 的元素个数
 6     const void *funcs; // 保存辅助信息, 例如 DER 编码相关
 7     long size;         // 对应数据结构大小, X509_it 返回的 ASN1_ITEM: sizeof(X509)
 8     const char *sname; // 对应数据结构名,   X509_it 返回的 ASN1_ITEM: "X509"
 9 };
10 
11 struct ASN1_TEMPLATE {// 一个 ASN1_TEMPLATE 表示上级 ASN1_ITEM 结构的一个成员
12     unsigned long flags; // 表示 [[class] number] EXPLICIT/IMPLICIT 中的 class 和 EXPLICIT/IMPLICIT 和 OPTIONAL 标记
13 /*                           OPTIONAL 可选
14  flags 低 8 位布局            |
15 +-------------------------------+
16 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
17 +-------------------------------+
18   class      |    |    |  |
19 (bit 7/6)    | IMPLICIT|  SET_OF
20             EXPLICIT   |
21                        SEQUENCE_OF
22 */
23     long tag; // 表示 [[class] number] EXPLICIT/IMPLICIT 中的 number, 是否有效取决于成员 flags
24     unsigned long offset; // ASN1_ITEM 中的偏移 offsetof(X509,cert_info) offsetof(X509,sig_alg) offsetof(X509,signature)
25     const char *field_name;         // 成员名称 "cert_info"              "sig_alg"              "signature"
26     ASN1_ITEM_EXP *item;  // 对应的 XXX_it 函数  X509_CINF_it()          X509_ALGOR_it()        ASN1_BIT_STRING_it()
27 }; // 上面三行中的注释为 X509_seq_tt[] 数组(ASN1_ITEM "X509" 的 templates 成员)的元素

两者之间的关系为: ASN1_ITEM 的成员 itype 决定 ASN1_ITEM 节点在树中的位置
如果 ASN1_ITEM.itype == ASN1_ITYPE_NDEF_SEQUENCE 或 ASN1_ITYPE_SEQUENCE, 则是中间节点
此时 ASN1_ITEM 的数组成员有效, 每个数组元素通过函数指针 item 指向子成员的 ASN1_ITEM
也即对于上下级 ASN1_ITEM 节点来说, 它们之间通过 ASN1_TEMPLATE 串起来
对于最终端的叶子节点, 其 itype == ASN1_ITYPE_PRIMITIVE

下面我们给出函数 ASN1_item_ex_d2i 的主干代码(仅考虑被 d2i_X509 调用到的部分)

View Code
 1 // 主要做 2 件事: 1、为数据结构申请内存(如果需要) 2、提取 DER 编码的值赋给数据结构
 2 int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
 3       const ASN1_ITEM *it,
 4       int tag, int aclass, char opt, ASN1_TLC *ctx)
 5 {
 6   switch(it->itype) // 根据 ASN1_ITEM 类型进入对应分支
 7   {
 8     case ASN1_ITYPE_PRIMITIVE: //【叶子节点,对应为最简单的数据结构,比如整数】
 9       if (it->templates)
10       { //【特殊情况下会走到此处】: it->sname: "X509_NAME_INTERNAL/X509_NAME_ENTRIES"
11         return asn1_template_ex_d2i(pval, in, len, // 由 x509_name_ex_d2i 触发调用
12                  it->templates, opt, ctx);
13       }
14       return asn1_d2i_ex_primitive(pval, in, len, it,
15                tag, aclass, opt, ctx); //【将 DER 编码转化为内部的简单数据结构】
16 
17     case ASN1_ITYPE_MSTRING: // d2i_X509() 未调用到
18       return asn1_d2i_ex_primitive(pval, in, len,
19                it, otag, 0, 0, ctx);
20 
21     case ASN1_ITYPE_EXTERN: // it->sname: "X509_NAME"
22       return ef->asn1_ex_d2i(pval, in, len, // 调用函数 x509_name_ex_d2i()
23                it, tag, aclass, opt, ctx);
24 
25     case ASN1_ITYPE_COMPAT: // d2i_X509() 未调用到
26     case ASN1_ITYPE_CHOICE: // d2i_X509() 未调用到
27 
28     case ASN1_ITYPE_NDEF_SEQUENCE:
29     case ASN1_ITYPE_SEQUENCE: //【中间节点,分而治之进行处理】
30       ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst,
31               &p, len, tag, aclass, opt, ctx);
32 
33       if (!*pval && !ASN1_item_ex_new(pval, it))
34       { // 如果数据结构指针为空(对于证书而言为 X509*)
35         // 则分配内存给数据结构: *pval = OPENSSL_malloc(it->size);
36         goto err; //【内部调用 asn1_item_ex_combine_new】
37       }
38 
39       if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it))
40         goto auxerr;
41 
42       // 【对 templates[] 中的各个成员分别进行转换】
43       for (i = 0, tt = it->templates; i < it->tcount; i++, tt++)
44       {
45         seqtt = asn1_do_adb(pval, tt, 1);
46         pseqval = asn1_get_field_ptr(pval, seqtt);
47         asn1_check_eoc(&p, len);
48 
49         ret = asn1_template_ex_d2i(pseqval, &p, len, // 对当前成员进行处理
50                 seqtt, isopt, ctx); // 内部再调用 asn1_template_noexp_d2i
51         // 最终会调用 ASN1_item_ex_d2i 得到子成员的 ASN1_ITEM 节点
52       }
53 
54       /* Save encoding */
55       if (!asn1_enc_save(pval, *in, p - *in, it)) // asn1_enc_save 见后面说明
56         goto auxerr;
57       *in = p;
58       if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it))
59         goto auxerr;
60       return 1;
61 
62     default:
63       return 0;
64   }
65 }

再对函数 asn1_item_ex_combine_new 着重说明一下,该函数用于给对应的 ASN1_ITEM 分配内存(ASN1_item_ex_new 触发调用)
其实现逻辑以及在构造 ASN1 树的过程中扮演的角色都类似于 ASN1_item_ex_d2i

View Code
 1 static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
 2                 int combine) // d2i_X509 调用的代码中 combine 恒为 0
 3 {
 4   if (!combine) *pval = NULL;
 5   switch(it->itype) // 根据 ASN1_ITEM 类型进入对应分支
 6   {
 7     case ASN1_ITYPE_PRIMITIVE:
 8       if (it->templates)
 9       {
10         if (!ASN1_template_new(pval, it->templates))
11           goto memerr;
12       }
13       else if (!ASN1_primitive_new(pval, it)) //【为基本 ASN1 结构申请内存】
14         goto memerr;
15       break;
16 
17     case ASN1_ITYPE_NDEF_SEQUENCE:
18     case ASN1_ITYPE_SEQUENCE: //【为复杂 ASN1 结构申请内存】
19       if (!combine)
20       {
21         *pval = OPENSSL_malloc(it->size); //【按数据结构大小分配】
22         if (!*pval)
23           goto memerr;
24         memset(*pval, 0, it->size);
25         asn1_do_lock(pval, 0, it);
26         asn1_enc_init(pval, it);
27       }
28       for (i = 0, tt = it->templates; i < it->tcount; tt++, i++)
29       { //【对数据结构的成员,依次申请内存】
30         pseqval = asn1_get_field_ptr(pval, tt);
31         if (!ASN1_template_new(pseqval, tt)) //【内部再度调用 asn1_item_ex_combine_new】
32           goto memerr;
33       }
34       if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it))
35         goto auxerr;
36       break;
37   }
38   return 1;
39   ......
40 }

根据上面的分析,可以得到函数 ASN1_item_ex_d2i 以 ASN1_ITEM "X509" 作为入参的调用路径
ASN1_item_ex_d2i
  ASN1_item_ex_new
    asn1_item_ex_combine_new
      ASN1_template_new -- 内部还可能调用 asn1_item_ex_combine_new
      ASN1_template_new
      ASN1_template_new
  asn1_template_ex_d2i -- 内部还可能调用 ASN1_item_ex_d2i
  asn1_template_ex_d2i
  asn1_template_ex_d2i

上面说明(VC 工程也可验证),以下函数之间相互嵌套调用,其关系之紧密,可谓是“犬牙交错”
ASN1_template_new/asn1_item_ex_combine_new
ASN1_item_ex_d2i/asn1_template_ex_d2i/asn1_template_noexp_d2i

我们深深地体会到:程序对外部用户呈现的功能强大而实用(外表光鲜),内部实现对开发人员来讲,却往往是复杂甚至难懂
在这种复杂的函数嵌套调用过程中,很容易陷入只见树木,不见森林的境地

怎么办?

如果能得到从根 ASN1_ITEM("X509") 节点到所有叶子节点的 d2i 函数运行记录
并且组成动态执行的路径(仔细想来,应该是一个树),那该多好啊
则我们怀疑哪个节点的 d2i 有问题,就直接定位到该节点的运行处,结果将一目了然
对于我们碰到的问题,就是定位并确定序列号的 d2i 过程是否正常

这比一步一步地调试跟踪,来确定具体的问题代码行要方便多了

问题是,这个能做到吗?
我们先给出答案,下面是以函数 ASN1_item_ex_d2i 为根的函数运行树(估且这么称呼)
(调用入口为 d2i_X509 --> ASN1_item_d2i --> ASN1_item_ex_d2i)

View Code
  1 <?xml version="1.0"?>
  2 <func name="ASN1_item_ex_d2i(sname=X509 itype=1 utype=16)">
  3   <func name="ASN1_item_ex_new(sname=X509 itype=1 utype=16)">
  4     <func name="asn1_item_ex_combine_new(sname=X509 itype=1 utype=16 type=NEW)">
  5       <func name="ASN1_template_new(field_name=cert_info flags=0 item=X509_CINF)">
  6         <func name="asn1_item_ex_combine_new(sname=X509_CINF itype=1 utype=16 type=NEW)">
  7           <func name="ASN1_template_new(field_name=version flags=OPT_EXP_CONT_ item=ASN1_INTEGER)"/>
  8           <func name="ASN1_template_new(field_name=serialNumber flags=0 item=ASN1_INTEGER)">
  9             <func name="asn1_item_ex_combine_new(sname=ASN1_INTEGER itype=0 utype=2 type=NEW)">
 10               <func name="ASN1_primitive_new(sname=ASN1_INTEGER itype=0 utype=2)"/>
 11             </func>
 12           </func>
 13           <func name="ASN1_template_new(field_name=signature flags=0 item=X509_ALGOR)">
 14             <func name="asn1_item_ex_combine_new(sname=X509_ALGOR itype=1 utype=16 type=NEW)">
 15               <func name="ASN1_template_new(field_name=algorithm flags=0 item=ASN1_OBJECT)">
 16                 <func name="asn1_item_ex_combine_new(sname=ASN1_OBJECT itype=0 utype=6 type=NEW)">
 17                   <func name="ASN1_primitive_new(sname=ASN1_OBJECT itype=0 utype=6)"/>
 18                 </func>
 19               </func>
 20               <func name="ASN1_template_new(field_name=parameter flags=OPT_ item=ASN1_ANY)"/>
 21             </func>
 22           </func>
 23           <func name="ASN1_template_new(field_name=issuer flags=0 item=X509_NAME)">
 24             <func name="asn1_item_ex_combine_new(sname=X509_NAME itype=4 utype=16 type=NEW)"/>
 25           </func>
 26           <func name="ASN1_template_new(field_name=validity flags=0 item=X509_VAL)">
 27             <func name="asn1_item_ex_combine_new(sname=X509_VAL itype=1 utype=16 type=NEW)">
 28               <func name="ASN1_template_new(field_name=notBefore flags=0 item=ASN1_TIME)">
 29                 <func name="asn1_item_ex_combine_new(sname=ASN1_TIME itype=5 utype=49152 type=NEW)">
 30                   <func name="ASN1_primitive_new(sname=ASN1_TIME itype=5 utype=49152)"/>
 31                 </func>
 32               </func>
 33               <func name="ASN1_template_new(field_name=notAfter flags=0 item=ASN1_TIME)">
 34                 <func name="asn1_item_ex_combine_new(sname=ASN1_TIME itype=5 utype=49152 type=NEW)">
 35                   <func name="ASN1_primitive_new(sname=ASN1_TIME itype=5 utype=49152)"/>
 36                 </func>
 37               </func>
 38             </func>
 39           </func>
 40           <func name="ASN1_template_new(field_name=subject flags=0 item=X509_NAME)">
 41             <func name="asn1_item_ex_combine_new(sname=X509_NAME itype=4 utype=16 type=NEW)"/>
 42           </func>
 43           <func name="ASN1_template_new(field_name=key flags=0 item=X509_PUBKEY)">
 44             <func name="asn1_item_ex_combine_new(sname=X509_PUBKEY itype=1 utype=16 type=NEW)">
 45               <func name="ASN1_template_new(field_name=algor flags=0 item=X509_ALGOR)">
 46                 <func name="asn1_item_ex_combine_new(sname=X509_ALGOR itype=1 utype=16 type=NEW)">
 47                   <func name="ASN1_template_new(field_name=algorithm flags=0 item=ASN1_OBJECT)">
 48                     <func name="asn1_item_ex_combine_new(sname=ASN1_OBJECT itype=0 utype=6 type=NEW)">
 49                       <func name="ASN1_primitive_new(sname=ASN1_OBJECT itype=0 utype=6)"/>
 50                     </func>
 51                   </func>
 52                   <func name="ASN1_template_new(field_name=parameter flags=OPT_ item=ASN1_ANY)"/>
 53                 </func>
 54               </func>
 55               <func name="ASN1_template_new(field_name=public_key flags=0 item=ASN1_BIT_STRING)">
 56                 <func name="asn1_item_ex_combine_new(sname=ASN1_BIT_STRING itype=0 utype=3 type=NEW)">
 57                   <func name="ASN1_primitive_new(sname=ASN1_BIT_STRING itype=0 utype=3)"/>
 58                 </func>
 59               </func>
 60             </func>
 61           </func>
 62           <func name="ASN1_template_new(field_name=issuerUID flags=OPT_IMP_CONT_ item=ASN1_BIT_STRING)"/>
 63           <func name="ASN1_template_new(field_name=subjectUID flags=OPT_IMP_CONT_ item=ASN1_BIT_STRING)"/>
 64           <func name="ASN1_template_new(field_name=extensions flags=OPT_SEQUENCE_EXP_CONT_ item=X509_EXTENSION)"/>
 65         </func>
 66       </func>
 67       <func name="ASN1_template_new(field_name=sig_alg flags=0 item=X509_ALGOR)">
 68         <func name="asn1_item_ex_combine_new(sname=X509_ALGOR itype=1 utype=16 type=NEW)">
 69           <func name="ASN1_template_new(field_name=algorithm flags=0 item=ASN1_OBJECT)">
 70             <func name="asn1_item_ex_combine_new(sname=ASN1_OBJECT itype=0 utype=6 type=NEW)">
 71               <func name="ASN1_primitive_new(sname=ASN1_OBJECT itype=0 utype=6)"/>
 72             </func>
 73           </func>
 74           <func name="ASN1_template_new(field_name=parameter flags=OPT_ item=ASN1_ANY)"/>
 75         </func>
 76       </func>
 77       <func name="ASN1_template_new(field_name=signature flags=0 item=ASN1_BIT_STRING)">
 78         <func name="asn1_item_ex_combine_new(sname=ASN1_BIT_STRING itype=0 utype=3 type=NEW)">
 79           <func name="ASN1_primitive_new(sname=ASN1_BIT_STRING itype=0 utype=3)"/>
 80         </func>
 81       </func>
 82     </func>
 83   </func>
 84   <func name="asn1_template_ex_d2i(field_name=cert_info flags=0 item=X509_CINF)">
 85     <func name="asn1_template_noexp_d2i(field_name=cert_info flags=0 item=X509_CINF)">
 86       <func name="ASN1_item_ex_d2i(sname=X509_CINF itype=1 utype=16)">
 87         <func name="asn1_template_ex_d2i(field_name=version flags=OPT_EXP_CONT_ item=ASN1_INTEGER)">
 88           <func name="asn1_template_noexp_d2i(field_name=version flags=OPT_EXP_CONT_ item=ASN1_INTEGER)">
 89             <func name="ASN1_item_ex_d2i(sname=ASN1_INTEGER itype=0 utype=2)">
 90               <func name="asn1_d2i_ex_primitive(sname=ASN1_INTEGER itype=0 utype=2)">
 91                 <func name="asn1_ex_c2i(sname=ASN1_INTEGER itype=0 utype=2)"/>
 92               </func>
 93             </func>
 94           </func>
 95         </func>
 96         <func name="asn1_template_ex_d2i(field_name=serialNumber flags=0 item=ASN1_INTEGER)">
 97           <func name="asn1_template_noexp_d2i(field_name=serialNumber flags=0 item=ASN1_INTEGER)">
 98             <func name="ASN1_item_ex_d2i(sname=ASN1_INTEGER itype=0 utype=2)">
 99               <func name="asn1_d2i_ex_primitive(sname=ASN1_INTEGER itype=0 utype=2)">
100                 <func name="asn1_ex_c2i(sname=ASN1_INTEGER itype=0 utype=2)"/>
101               </func>
102             </func>
103           </func>
104         </func>
105         <func name="asn1_template_ex_d2i(field_name=signature flags=0 item=X509_ALGOR)">
106           <func name="asn1_template_noexp_d2i(field_name=signature flags=0 item=X509_ALGOR)">
107             <func name="ASN1_item_ex_d2i(sname=X509_ALGOR itype=1 utype=16)">
108               <func name="asn1_template_ex_d2i(field_name=algorithm flags=0 item=ASN1_OBJECT)">
109                 <func name="asn1_template_noexp_d2i(field_name=algorithm flags=0 item=ASN1_OBJECT)">
110                   <func name="ASN1_item_ex_d2i(sname=ASN1_OBJECT itype=0 utype=6)">
111                     <func name="asn1_d2i_ex_primitive(sname=ASN1_OBJECT itype=0 utype=6)">
112                       <func name="asn1_ex_c2i(sname=ASN1_OBJECT itype=0 utype=6)"/>
113                     </func>
114                   </func>
115                 </func>
116               </func>
117               <func name="asn1_template_ex_d2i(field_name=parameter flags=OPT_ item=ASN1_ANY)">
118                 <func name="asn1_template_noexp_d2i(field_name=parameter flags=OPT_ item=ASN1_ANY)">
119                   <func name="ASN1_item_ex_d2i(sname=ASN1_ANY itype=0 utype=-4)">
120                     <func name="asn1_d2i_ex_primitive(sname=ASN1_ANY itype=0 utype=-4)">
121                       <func name="asn1_ex_c2i(sname=ASN1_ANY itype=0 utype=-4)">
122                         <func name="ASN1_TYPE_new">
123                           <func name="ASN1_item_new(sname=ASN1_ANY itype=0 utype=-4)">
124                             <func name="ASN1_item_ex_new(sname=ASN1_ANY itype=0 utype=-4)">
125                               <func name="asn1_item_ex_combine_new(sname=ASN1_ANY itype=0 utype=-4 type=NEW)">
126                                 <func name="ASN1_primitive_new(sname=ASN1_ANY itype=0 utype=-4)"/>
127                               </func>
128                             </func>
129                           </func>
130                         </func>
131                       </func>
132                     </func>
133                   </func>
134                 </func>
135               </func>
136             </func>
137           </func>
138         </func>
139         <func name="asn1_template_ex_d2i(field_name=issuer flags=0 item=X509_NAME)">
140           <func name="asn1_template_noexp_d2i(field_name=issuer flags=0 item=X509_NAME)">
141             <func name="ASN1_item_ex_d2i(sname=X509_NAME itype=4 utype=16)">
142               <func name="x509_name_ex_d2i(sname=X509_NAME itype=4 utype=16)">
143                 <func name="ASN1_item_ex_d2i(sname=X509_NAME_INTERNAL itype=0 utype=-1)">
144                   <func name="asn1_template_ex_d2i(field_name=Name flags=SEQUENCE_ item=X509_NAME_ENTRIES)">
145                     <func name="asn1_template_noexp_d2i(field_name=Name flags=SEQUENCE_ item=X509_NAME_ENTRIES)">
146                       <func name="ASN1_item_ex_d2i(sname=X509_NAME_ENTRIES itype=0 utype=-1)">
147                         <func name="asn1_template_ex_d2i(field_name=RDNS flags=SET_ item=X509_NAME_ENTRY)">
148                           <func name="asn1_template_noexp_d2i(field_name=RDNS flags=SET_ item=X509_NAME_ENTRY)">
149                             <func name="ASN1_item_ex_d2i(sname=X509_NAME_ENTRY itype=1 utype=16)">
150                               <func name="ASN1_item_ex_new(sname=X509_NAME_ENTRY itype=1 utype=16)">
151                                 <func name="asn1_item_ex_combine_new(sname=X509_NAME_ENTRY itype=1 utype=16 type=NEW)">
152                                   <func name="ASN1_template_new(field_name=object flags=0 item=ASN1_OBJECT)">
153                                     <func name="asn1_item_ex_combine_new(sname=ASN1_OBJECT itype=0 utype=6 type=NEW)">
154                                       <func name="ASN1_primitive_new(sname=ASN1_OBJECT itype=0 utype=6)"/>
155                                     </func>
156                                   </func>
157                                   <func name="ASN1_template_new(field_name=value flags=0 item=ASN1_PRINTABLE)">
158                                     <func name="asn1_item_ex_combine_new(sname=ASN1_PRINTABLE itype=5 utype=81174 type=NEW)">
159                                       <func name="ASN1_primitive_new(sname=ASN1_PRINTABLE itype=5 utype=81174)"/>
160                                     </func>
161                                   </func>
162                                 </func>
163                               </func>
164                               <func name="asn1_template_ex_d2i(field_name=object flags=0 item=ASN1_OBJECT)">
165                                 <func name="asn1_template_noexp_d2i(field_name=object flags=0 item=ASN1_OBJECT)">
166                                   <func name="ASN1_item_ex_d2i(sname=ASN1_OBJECT itype=0 utype=6)">
167                                     <func name="asn1_d2i_ex_primitive(sname=ASN1_OBJECT itype=0 utype=6)">
168                                       <func name="asn1_ex_c2i(sname=ASN1_OBJECT itype=0 utype=6)"/>
169                                     </func>
170                                   </func>
171                                 </func>
172                               </func>
173                               <func name="asn1_template_ex_d2i(field_name=value flags=0 item=ASN1_PRINTABLE)">
174                                 <func name="asn1_template_noexp_d2i(field_name=value flags=0 item=ASN1_PRINTABLE)">
175                                   <func name="ASN1_item_ex_d2i(sname=ASN1_PRINTABLE itype=5 utype=81174)">
176                                     <func name="asn1_d2i_ex_primitive(sname=ASN1_PRINTABLE itype=5 utype=81174)">
177                                       <func name="asn1_ex_c2i(sname=ASN1_PRINTABLE itype=5 utype=81174)"/>
178                                     </func>
179                                   </func>
180                                 </func>
181                               </func>
182                             </func>
183                           </func>
184                         </func>
185                       </func>
186                       <func name="ASN1_item_ex_d2i(sname=X509_NAME_ENTRIES itype=0 utype=-1)">
187                         <func name="asn1_template_ex_d2i(field_name=RDNS flags=SET_ item=X509_NAME_ENTRY)">
188                           <func name="asn1_template_noexp_d2i(field_name=RDNS flags=SET_ item=X509_NAME_ENTRY)">
189                             <func name="ASN1_item_ex_d2i(sname=X509_NAME_ENTRY itype=1 utype=16)">
190                               <func name="ASN1_item_ex_new(sname=X509_NAME_ENTRY itype=1 utype=16)">
191                                 <func name="asn1_item_ex_combine_new(sname=X509_NAME_ENTRY itype=1 utype=16 type=NEW)">
192                                   <func name="ASN1_template_new(field_name=object flags=0 item=ASN1_OBJECT)">
193                                     <func name="asn1_item_ex_combine_new(sname=ASN1_OBJECT itype=0 utype=6 type=NEW)">
194                                       <func name="ASN1_primitive_new(sname=ASN1_OBJECT itype=0 utype=6)"/>
195                                     </func>
196                                   </func>
197                                   <func name="ASN1_template_new(field_name=value flags=0 item=ASN1_PRINTABLE)">
198                                     <func name="asn1_item_ex_combine_new(sname=ASN1_PRINTABLE itype=5 utype=81174 type=NEW)">
199                                       <func name="ASN1_primitive_new(sname=ASN1_PRINTABLE itype=5 utype=81174)"/>
200                                     </func>
201                                   </func>
202                                 </func>
203                               </func>
204                               <func name="asn1_template_ex_d2i(field_name=object flags=0 item=ASN1_OBJECT)">
205                                 <func name="asn1_template_noexp_d2i(field_name=object flags=0 item=ASN1_OBJECT)">
206                                   <func name="ASN1_item_ex_d2i(sname=ASN1_OBJECT itype=0 utype=6)">
207                                     <func name="asn1_d2i_ex_primitive(sname=ASN1_OBJECT itype=0 utype=6)">
208                                       <func name="asn1_ex_c2i(sname=ASN1_OBJECT itype=0 utype=6)"/>
209                                     </func>
210                                   </func>
211                                 </func>
212                               </func>
213                               <func name="asn1_template_ex_d2i(field_name=value flags=0 item=ASN1_PRINTABLE)">
214                                 <func name="asn1_template_noexp_d2i(field_name=value flags=0 item=ASN1_PRINTABLE)">
215                                   <func name="ASN1_item_ex_d2i(sname=ASN1_PRINTABLE itype=5 utype=81174)">
216                                     <func name="asn1_d2i_ex_primitive(sname=ASN1_PRINTABLE itype=5 utype=81174)">
217                                       <func name="asn1_ex_c2i(sname=ASN1_PRINTABLE itype=5 utype=81174)"/>
218                                     </func>
219                                   </func>
220                                 </func>
221                               </func>
222                             </func>
223                           </func>
224                         </func>
225                       </func>
226                       <func name="ASN1_item_ex_d2i(sname=X509_NAME_ENTRIES itype=0 utype=-1)">
227                         <func name="asn1_template_ex_d2i(field_name=RDNS flags=SET_ item=X509_NAME_ENTRY)">
228                           <func name="asn1_template_noexp_d2i(field_name=RDNS flags=SET_ item=X509_NAME_ENTRY)">
229                             <func name="ASN1_item_ex_d2i(sname=X509_NAME_ENTRY itype=1 utype=16)">
230                               <func name="ASN1_item_ex_new(sname=X509_NAME_ENTRY itype=1 utype=16)">
231                                 <func name="asn1_item_ex_combine_new(sname=X509_NAME_ENTRY itype=1 utype=16 type=NEW)">
232                                   <func name="ASN1_template_new(field_name=object flags=0 item=ASN1_OBJECT)">
233                                     <func name="asn1_item_ex_combine_new(sname=ASN1_OBJECT itype=0 utype=6 type=NEW)">
234                                       <func name="ASN1_primitive_new(sname=ASN1_OBJECT itype=0 utype=6)"/>
235                                     </func>
236                                   </func>
237                                   <func name="ASN1_template_new(field_name=value flags=0 item=ASN1_PRINTABLE)">
238                                     <func name="asn1_item_ex_combine_new(sname=ASN1_PRINTABLE itype=5 utype=81174 type=NEW)">
239                                       <func name="ASN1_primitive_new(sname=ASN1_PRINTABLE itype=5 utype=81174)"/>
240                                     </func>
241                                   </func>
242                                 </func>
243                               </func>
244                               <func name="asn1_template_ex_d2i(field_name=object flags=0 item=ASN1_OBJECT)">
245                                 <func name="asn1_template_noexp_d2i(field_name=object flags=0 item=ASN1_OBJECT)">
246                                   <func name="ASN1_item_ex_d2i(sname=ASN1_OBJECT itype=0 utype=6)">
247                                     <func name="asn1_d2i_ex_primitive(sname=ASN1_OBJECT itype=0 utype=6)">
248                                       <func name="asn1_ex_c2i(sname=ASN1_OBJECT itype=0 utype=6)"/>
249                                     </func>
250                                   </func>
251                                 </func>
252                               </func>
253                               <func name="asn1_template_ex_d2i(field_name=value flags=0 item=ASN1_PRINTABLE)">
254                                 <func name="asn1_template_noexp_d2i(field_name=value flags=0 item=ASN1_PRINTABLE)">
255                                   <func name="ASN1_item_ex_d2i(sname=ASN1_PRINTABLE itype=5 utype=81174)">
256                                     <func name="asn1_d2i_ex_primitive(sname=ASN1_PRINTABLE itype=5 utype=81174)">
257                                       <func name="asn1_ex_c2i(sname=ASN1_PRINTABLE itype=5 utype=81174)"/>
258                                     </func>
259                                   </func>
260                                 </func>
261                               </func>
262                             </func>
263                           </func>
264                         </func>
265                       </func>
266                       <func name="ASN1_item_ex_d2i(sname=X509_NAME_ENTRIES itype=0 utype=-1)">
267                         <func name="asn1_template_ex_d2i(field_name=RDNS flags=SET_ item=X509_NAME_ENTRY)">
268                           <func name="asn1_template_noexp_d2i(field_name=RDNS flags=SET_ item=X509_NAME_ENTRY)">
269                             <func name="ASN1_item_ex_d2i(sname=X509_NAME_ENTRY itype=1 utype=16)">
270                               <func name="ASN1_item_ex_new(sname=X509_NAME_ENTRY itype=1 utype=16)">
271                                 <func name="asn1_item_ex_combine_new(sname=X509_NAME_ENTRY itype=1 utype=16 type=NEW)">
272                                   <func name="ASN1_template_new(field_name=object flags=0 item=ASN1_OBJECT)">
273                                     <func name="asn1_item_ex_combine_new(sname=ASN1_OBJECT itype=0 utype=6 type=NEW)">
274                                       <func name="ASN1_primitive_new(sname=ASN1_OBJECT itype=0 utype=6)"/>
275                                     </func>
276                                   </func>
277                                   <func name="ASN1_template_new(field_name=value flags=0 item=ASN1_PRINTABLE)">
278                                     <func name="asn1_item_ex_combine_new(sname=ASN1_PRINTABLE itype=5 utype=81174 type=NEW)">
279                                       <func name="ASN1_primitive_new(sname=ASN1_PRINTABLE itype=5 utype=81174)"/>
280                                     </func>
281                                   </func>
282                                 </func>
283                               </func>
284                               <func name="asn1_template_ex_d2i(field_name=object flags=0 item=ASN1_OBJECT)">
285                                 <func name="asn1_template_noexp_d2i(field_name=object flags=0 item=ASN1_OBJECT)">
286                                   <func name="ASN1_item_ex_d2i(sname=ASN1_OBJECT itype=0 utype=6)">
287                                     <func name="asn1_d2i_ex_primitive(sname=ASN1_OBJECT itype=0 utype=6)">
288                                       <func name="asn1_ex_c2i(sname=ASN1_OBJECT itype=0 utype=6)"/>
289                                     </func>
290                                   </func>
291                                 </func>
292                               </func>
293                               <func name="asn1_template_ex_d2i(field_name=value flags=0 item=ASN1_PRINTABLE)">
294                                 <func name="asn1_template_noexp_d2i(field_name=value flags=0 item=ASN1_PRINTABLE)">
295                                   <func name="ASN1_item_ex_d2i(sname=ASN1_PRINTABLE itype=5 utype=81174)">
296                                     <func name="asn1_d2i_ex_primitive(sname=ASN1_PRINTABLE itype=5 utype=81174)">
297                                       <func name="asn1_ex_c2i(sname=ASN1_PRINTABLE itype=5 utype=81174)"/>
298                                     </func>
299                                   </func>
300                                 </func>
301                               </func>
302                             </func>
303                           </func>
304                         </func>
305                       </func>
306                       <func name="ASN1_item_ex_d2i(sname=X509_NAME_ENTRIES itype=0 utype=-1)">
307                         <func name="asn1_template_ex_d2i(field_name=RDNS flags=SET_ item=X509_NAME_ENTRY)">
308                           <func name="asn1_template_noexp_d2i(field_name=RDNS flags=SET_ item=X509_NAME_ENTRY)">
309                             <func name="ASN1_item_ex_d2i(sname=X509_NAME_ENTRY itype=1 utype=16)">
310                               <func name="ASN1_item_ex_new(sname=X509_NAME_ENTRY itype=1 utype=16)">
311                                 <func name="asn1_item_ex_combine_new(sname=X509_NAME_ENTRY itype=1 utype=16 type=NEW)">
312                                   <func name="ASN1_template_new(field_name=object flags=0 item=ASN1_OBJECT)">
313                                     <func name="asn1_item_ex_combine_new(sname=ASN1_OBJECT itype=0 utype=6 type=NEW)">
314                                       <func name="ASN1_primitive_new(sname=ASN1_OBJECT itype=0 utype=6)"/>
315                                     </func>
316                                   </func>
317                                   <func name="ASN1_template_new(field_name=value flags=0 item=ASN1_PRINTABLE)">
318                                     <func name="asn1_item_ex_combine_new(sname=ASN1_PRINTABLE itype=5 utype=81174 type=NEW)">
319                                       <func name="ASN1_primitive_new(sname=ASN1_PRINTABLE itype=5 utype=81174)"/>
320                                     </func>
321                                   </func>
322                                 </func>
323                               </func>
324                               <func name="asn1_template_ex_d2i(field_name=object flags=0 item=ASN1_OBJECT)">
325                                 <func name="asn1_template_noexp_d2i(field_name=object flags=0 item=ASN1_OBJECT)">
326                                   <func name="ASN1_item_ex_d2i(sname=ASN1_OBJECT itype=0 utype=6)">
327                                     <func name="asn1_d2i_ex_primitive(sname=ASN1_OBJECT itype=0 utype=6)">
328                                       <func name="asn1_ex_c2i(sname=ASN1_OBJECT itype=0 utype=6)"/>
329                                     </func>
330                                   </func>
331                                 </func>
332                               </func>
333                               <func name="asn1_template_ex_d2i(field_name=value flags=0 item=ASN1_PRINTABLE)">
334                                 <func name="asn1_template_noexp_d2i(field_name=value flags=0 item=ASN1_PRINTABLE)">
335                                   <func name="ASN1_item_ex_d2i(sname=ASN1_PRINTABLE itype=5 utype=81174)">
336                                     <func name="asn1_d2i_ex_primitive(sname=ASN1_PRINTABLE itype=5 utype=81174)">
337                                       <func name="asn1_ex_c2i(sname=ASN1_PRINTABLE itype=5 utype=81174)"/>
338                                     </func>
339                                   </func>
340                                 </func>
341                               </func>
342                             </func>
343                           </func>
344                         </func>
345                       </func>
346                     </func>
347                   </func>
348                 </func>
349               </func>
350             </func>
351           </func>
352         </func>
353         <func name="asn1_template_ex_d2i(field_name=validity flags=0 item=X509_VAL)">
354           <func name="asn1_template_noexp_d2i(field_name=validity flags=0 item=X509_VAL)">
355             <func name="ASN1_item_ex_d2i(sname=X509_VAL itype=1 utype=16)">
356               <func name="asn1_template_ex_d2i(field_name=notBefore flags=0 item=ASN1_TIME)">
357                 <func name="asn1_template_noexp_d2i(field_name=notBefore flags=0 item=ASN1_TIME)">
358                   <func name="ASN1_item_ex_d2i(sname=ASN1_TIME itype=5 utype=49152)">
359                     <func name="asn1_d2i_ex_primitive(sname=ASN1_TIME itype=5 utype=49152)">
360                       <func name="asn1_ex_c2i(sname=ASN1_TIME itype=5 utype=49152)"/>
361                     </func>
362                   </func>
363                 </func>
364               </func>
365               <func name="asn1_template_ex_d2i(field_name=notAfter flags=0 item=ASN1_TIME)">
366                 <func name="asn1_template_noexp_d2i(field_name=notAfter flags=0 item=ASN1_TIME)">
367                   <func name="ASN1_item_ex_d2i(sname=ASN1_TIME itype=5 utype=49152)">
368                     <func name="asn1_d2i_ex_primitive(sname=ASN1_TIME itype=5 utype=49152)">
369                       <func name="asn1_ex_c2i(sname=ASN1_TIME itype=5 utype=49152)"/>
370                     </func>
371                   </func>
372                 </func>
373               </func>
374             </func>
375           </func>
376         </func>
377         <func name="asn1_template_ex_d2i(field_name=subject flags=0 item=X509_NAME)">
378           <func name="asn1_template_noexp_d2i(field_name=subject flags=0 item=X509_NAME)">
379             <func name="ASN1_item_ex_d2i(sname=X509_NAME itype=4 utype=16)">
380               <func name="x509_name_ex_d2i(sname=X509_NAME itype=4 utype=16)">
381                 <func name="ASN1_item_ex_d2i(sname=X509_NAME_INTERNAL itype=0 utype=-1)">
382                   <func name="asn1_template_ex_d2i(field_name=Name flags=SEQUENCE_ item=X509_NAME_ENTRIES)">
383                     <func name="asn1_template_noexp_d2i(field_name=Name flags=SEQUENCE_ item=X509_NAME_ENTRIES)">
384                       <func name="ASN1_item_ex_d2i(sname=X509_NAME_ENTRIES itype=0 utype=-1)">
385                         <func name="asn1_template_ex_d2i(field_name=RDNS flags=SET_ item=X509_NAME_ENTRY)">
386                           <func name="asn1_template_noexp_d2i(field_name=RDNS flags=SET_ item=X509_NAME_ENTRY)">
387                             <func name="ASN1_item_ex_d2i(sname=X509_NAME_ENTRY itype=1 utype=16)">
388                               <func name="ASN1_item_ex_new(sname=X509_NAME_ENTRY itype=1 utype=16)">
389                                 <func name="asn1_item_ex_combine_new(sname=X509_NAME_ENTRY itype=1 utype=16 type=NEW)">
390                                   <func name="ASN1_template_new(field_name=object flags=0 item=ASN1_OBJECT)">
391                                     <func name="asn1_item_ex_combine_new(sname=ASN1_OBJECT itype=0 utype=6 type=NEW)">
392                                       <func name="ASN1_primitive_new(sname=ASN1_OBJECT itype=0 utype=6)"/>
393                                     </func>
394                                   </func>
395                                   <func name="ASN1_template_new(field_name=value flags=0 item=ASN1_PRINTABLE)">
396                                     <func name="asn1_item_ex_combine_new(sname=ASN1_PRINTABLE itype=5 utype=81174 type=NEW)">
397                                       <func name="ASN1_primitive_new(sname=ASN1_PRINTABLE itype=5 utype=81174)"/>
398                                     </func>
399                                   </func>
400                                 </func>
401                               </func>
402                               <func name="asn1_template_ex_d2i(field_name=object flags=0 item=ASN1_OBJECT)">
403                                 <func name="asn1_template_noexp_d2i(field_name=object flags=0 item=ASN1_OBJECT)">
404                                   <func name="ASN1_item_ex_d2i(sname=ASN1_OBJECT itype=0 utype=6)">
405                                     <func name="asn1_d2i_ex_primitive(sname=ASN1_OBJECT itype=0 utype=6)">
406                                       <func name="asn1_ex_c2i(sname=ASN1_OBJECT itype=0 utype=6)"/>
407                                     </func>
408                                   </func>
409                                 </func>
410                               </func>
411                               <func name="asn1_template_ex_d2i(field_name=value flags=0 item=ASN1_PRINTABLE)">
412                                 <func name="asn1_template_noexp_d2i(field_name=value flags=0 item=ASN1_PRINTABLE)">
413                                   <func name="ASN1_item_ex_d2i(sname=ASN1_PRINTABLE itype=5 utype=81174)">
414                                     <func name="asn1_d2i_ex_primitive(sname=ASN1_PRINTABLE itype=5 utype=81174)">
415                                       <func name="asn1_ex_c2i(sname=ASN1_PRINTABLE itype=5 utype=81174)"/>
416                                     </func>
417                                   </func>
418                                 </func>
419                               </func>
420                             </func>
421                           </func>
422                         </func>
423                       </func>
424                       <func name="ASN1_item_ex_d2i(sname=X509_NAME_ENTRIES itype=0 utype=-1)">
425                         <func name="asn1_template_ex_d2i(field_name=RDNS flags=SET_ item=X509_NAME_ENTRY)">
426                           <func name="asn1_template_noexp_d2i(field_name=RDNS flags=SET_ item=X509_NAME_ENTRY)">
427                             <func name="ASN1_item_ex_d2i(sname=X509_NAME_ENTRY itype=1 utype=16)">
428                               <func name="ASN1_item_ex_new(sname=X509_NAME_ENTRY itype=1 utype=16)">
429                                 <func name="asn1_item_ex_combine_new(sname=X509_NAME_ENTRY itype=1 utype=16 type=NEW)">
430                                   <func name="ASN1_template_new(field_name=object flags=0 item=ASN1_OBJECT)">
431                                     <func name="asn1_item_ex_combine_new(sname=ASN1_OBJECT itype=0 utype=6 type=NEW)">
432                                       <func name="ASN1_primitive_new(sname=ASN1_OBJECT itype=0 utype=6)"/>
433                                     </func>
434                                   </func>
435                                   <func name="ASN1_template_new(field_name=value flags=0 item=ASN1_PRINTABLE)">
436                                     <func name="asn1_item_ex_combine_new(sname=ASN1_PRINTABLE itype=5 utype=81174 type=NEW)">
437                                       <func name="ASN1_primitive_new(sname=ASN1_PRINTABLE itype=5 utype=81174)"/>
438                                     </func>
439                                   </func>
440                                 </func>
441                               </func>
442                               <func name="asn1_template_ex_d2i(field_name=object flags=0 item=ASN1_OBJECT)">
443                                 <func name="asn1_template_noexp_d2i(field_name=object flags=0 item=ASN1_OBJECT)">
444                                   <func name="ASN1_item_ex_d2i(sname=ASN1_OBJECT itype=0 utype=6)">
445                                     <func name="asn1_d2i_ex_primitive(sname=ASN1_OBJECT itype=0 utype=6)">
446                                       <func name="asn1_ex_c2i(sname=ASN1_OBJECT itype=0 utype=6)"/>
447                                     </func>
448                                   </func>
449                                 </func>
450                               </func>
451                               <func name="asn1_template_ex_d2i(field_name=value flags=0 item=ASN1_PRINTABLE)">
452                                 <func name="asn1_template_noexp_d2i(field_name=value flags=0 item=ASN1_PRINTABLE)">
453                                   <func name="ASN1_item_ex_d2i(sname=ASN1_PRINTABLE itype=5 utype=81174)">
454                                     <func name="asn1_d2i_ex_primitive(sname=ASN1_PRINTABLE itype=5 utype=81174)">
455                                       <func name="asn1_ex_c2i(sname=ASN1_PRINTABLE itype=5 utype=81174)"/>
456                                     </func>
457                                   </func>
458                                 </func>
459                               </func>
460                             </func>
461                           </func>
462                         </func>
463                       </func>
464                       <func name="ASN1_item_ex_d2i(sname=X509_NAME_ENTRIES itype=0 utype=-1)">
465                         <func name="asn1_template_ex_d2i(field_name=RDNS flags=SET_ item=X509_NAME_ENTRY)">
466                           <func name="asn1_template_noexp_d2i(field_name=RDNS flags=SET_ item=X509_NAME_ENTRY)">
467                             <func name="ASN1_item_ex_d2i(sname=X509_NAME_ENTRY itype=1 utype=16)">
468                               <func name="ASN1_item_ex_new(sname=X509_NAME_ENTRY itype=1 utype=16)">
469                                 <func name="asn1_item_ex_combine_new(sname=X509_NAME_ENTRY itype=1 utype=16 type=NEW)">
470                                   <func name="ASN1_template_new(field_name=object flags=0 item=ASN1_OBJECT)">
471                                     <func name="asn1_item_ex_combine_new(sname=ASN1_OBJECT itype=0 utype=6 type=NEW)">
472                                       <func name="ASN1_primitive_new(sname=ASN1_OBJECT itype=0 utype=6)"/>
473                                     </func>
474                                   </func>
475                                   <func name="ASN1_template_new(field_name=value flags=0 item=ASN1_PRINTABLE)">
476                                     <func name="asn1_item_ex_combine_new(sname=ASN1_PRINTABLE itype=5 utype=81174 type=NEW)">
477                                       <func name="ASN1_primitive_new(sname=ASN1_PRINTABLE itype=5 utype=81174)"/>
478                                     </func>
479                                   </func>
480                                 </func>
481                               </func>
482                               <func name="asn1_template_ex_d2i(field_name=object flags=0 item=ASN1_OBJECT)">
483                                 <func name="asn1_template_noexp_d2i(field_name=object flags=0 item=ASN1_OBJECT)">
484                                   <func name="ASN1_item_ex_d2i(sname=ASN1_OBJECT itype=0 utype=6)">
485                                     <func name="asn1_d2i_ex_primitive(sname=ASN1_OBJECT itype=0 utype=6)">
486                                       <func name="asn1_ex_c2i(sname=ASN1_OBJECT itype=0 utype=6)"/>
487                                     </func>
488                                   </func>
489                                 </func>
490                               </func>
491                               <func name="asn1_template_ex_d2i(field_name=value flags=0 item=ASN1_PRINTABLE)">
492                                 <func name="asn1_template_noexp_d2i(field_name=value flags=0 item=ASN1_PRINTABLE)">
493                                   <func name="ASN1_item_ex_d2i(sname=ASN1_PRINTABLE itype=5 utype=81174)">
494                                     <func name="asn1_d2i_ex_primitive(sname=ASN1_PRINTABLE itype=5 utype=81174)">
495                                       <func name="asn1_ex_c2i(sname=ASN1_PRINTABLE itype=5 utype=81174)"/>
496                                     </func>
497                                   </func>
498                                 </func>
499                               </func>
500                             </func>
501                           </func>
502                         </func>
503                       </func>
504                       <func name="ASN1_item_ex_d2i(sname=X509_NAME_ENTRIES itype=0 utype=-1)">
505                         <func name="asn1_template_ex_d2i(field_name=RDNS flags=SET_ item=X509_NAME_ENTRY)">
506                           <func name="asn1_template_noexp_d2i(field_name=RDNS flags=SET_ item=X509_NAME_ENTRY)">
507                             <func name="ASN1_item_ex_d2i(sname=X509_NAME_ENTRY itype=1 utype=16)">
508                               <func name="ASN1_item_ex_new(sname=X509_NAME_ENTRY itype=1 utype=16)">
509                                 <func name="asn1_item_ex_combine_new(sname=X509_NAME_ENTRY itype=1 utype=16 type=NEW)">
510                                   <func name="ASN1_template_new(field_name=object flags=0 item=ASN1_OBJECT)">
511                                     <func name="asn1_item_ex_combine_new(sname=ASN1_OBJECT itype=0 utype=6 type=NEW)">
512                                       <func name="ASN1_primitive_new(sname=ASN1_OBJECT itype=0 utype=6)"/>
513                                     </func>
514                                   </func>
515                                   <func name="ASN1_template_new(field_name=value flags=0 item=ASN1_PRINTABLE)">
516                                     <func name="asn1_item_ex_combine_new(sname=ASN1_PRINTABLE itype=5 utype=81174 type=NEW)">
517                                       <func name="ASN1_primitive_new(sname=ASN1_PRINTABLE itype=5 utype=81174)"/>
518                                     </func>
519                                   </func>
520                                 </func>
521                               </func>
522                               <func name="asn1_template_ex_d2i(field_name=object flags=0 item=ASN1_OBJECT)">
523                                 <func name="asn1_template_noexp_d2i(field_name=object flags=0 item=ASN1_OBJECT)">
524                                   <func name="ASN1_item_ex_d2i(sname=ASN1_OBJECT itype=0 utype=6)">
525                                     <func name="asn1_d2i_ex_primitive(sname=ASN1_OBJECT itype=0 utype=6)">
526                                       <func name="asn1_ex_c2i(sname=ASN1_OBJECT itype=0 utype=6)"/>
527                                     </func>
528                                   </func>
529                                 </func>
530                               </func>
531                               <func name="asn1_template_ex_d2i(field_name=value flags=0 item=ASN1_PRINTABLE)">
532                                 <func name="asn1_template_noexp_d2i(field_name=value flags=0 item=ASN1_PRINTABLE)">
533                                   <func name="ASN1_item_ex_d2i(sname=ASN1_PRINTABLE itype=5 utype=81174)">
534                                     <func name="asn1_d2i_ex_primitive(sname=ASN1_PRINTABLE itype=5 utype=81174)">
535                                       <func name="asn1_ex_c2i(sname=ASN1_PRINTABLE itype=5 utype=81174)"/>
536                                     </func>
537                                   </func>
538                                 </func>
539                               </func>
540                             </func>
541                           </func>
542                         </func>
543                       </func>
544                       <func name="ASN1_item_ex_d2i(sname=X509_NAME_ENTRIES itype=0 utype=-1)">
545                         <func name="asn1_template_ex_d2i(field_name=RDNS flags=SET_ item=X509_NAME_ENTRY)">
546                           <func name="asn1_template_noexp_d2i(field_name=RDNS flags=SET_ item=X509_NAME_ENTRY)">
547                             <func name="ASN1_item_ex_d2i(sname=X509_NAME_ENTRY itype=1 utype=16)">
548                               <func name="ASN1_item_ex_new(sname=X509_NAME_ENTRY itype=1 utype=16)">
549                                 <func name="asn1_item_ex_combine_new(sname=X509_NAME_ENTRY itype=1 utype=16 type=NEW)">
550                                   <func name="ASN1_template_new(field_name=object flags=0 item=ASN1_OBJECT)">
551                                     <func name="asn1_item_ex_combine_new(sname=ASN1_OBJECT itype=0 utype=6 type=NEW)">
552                                       <func name="ASN1_primitive_new(sname=ASN1_OBJECT itype=0 utype=6)"/>
553                                     </func>
554                                   </func>
555                                   <func name="ASN1_template_new(field_name=value flags=0 item=ASN1_PRINTABLE)">
556                                     <func name="asn1_item_ex_combine_new(sname=ASN1_PRINTABLE itype=5 utype=81174 type=NEW)">
557                                       <func name="ASN1_primitive_new(sname=ASN1_PRINTABLE itype=5 utype=81174)"/>
558                                     </func>
559                                   </func>
560                                 </func>
561                               </func>
562                               <func name="asn1_template_ex_d2i(field_name=object flags=0 item=ASN1_OBJECT)">
563                                 <func name="asn1_template_noexp_d2i(field_name=object flags=0 item=ASN1_OBJECT)">
564                                   <func name="ASN1_item_ex_d2i(sname=ASN1_OBJECT itype=0 utype=6)">
565                                     <func name="asn1_d2i_ex_primitive(sname=ASN1_OBJECT itype=0 utype=6)">
566                                       <func name="asn1_ex_c2i(sname=ASN1_OBJECT itype=0 utype=6)"/>
567                                     </func>
568                                   </func>
569                                 </func>
570                               </func>
571                               <func name="asn1_template_ex_d2i(field_name=value flags=0 item=ASN1_PRINTABLE)">
572                                 <func name="asn1_template_noexp_d2i(field_name=value flags=0 item=ASN1_PRINTABLE)">
573                                   <func name="ASN1_item_ex_d2i(sname=ASN1_PRINTABLE itype=5 utype=81174)">
574                                     <func name="asn1_d2i_ex_primitive(sname=ASN1_PRINTABLE itype=5 utype=81174)">
575                                       <func name="asn1_ex_c2i(sname=ASN1_PRINTABLE itype=5 utype=81174)"/>
576                                     </func>
577                                   </func>
578                                 </func>
579                               </func>
580                             </func>
581                           </func>
582                         </func>
583                       </func>
584                     </func>
585                   </func>
586                 </func>
587               </func>
588             </func>
589           </func>
590         </func>
591         <func name="asn1_template_ex_d2i(field_name=key flags=0 item=X509_PUBKEY)">
592           <func name="asn1_template_noexp_d2i(field_name=key flags=0 item=X509_PUBKEY)">
593             <func name="ASN1_item_ex_d2i(sname=X509_PUBKEY itype=1 utype=16)">
594               <func name="asn1_template_ex_d2i(field_name=algor flags=0 item=X509_ALGOR)">
595                 <func name="asn1_template_noexp_d2i(field_name=algor flags=0 item=X509_ALGOR)">
596                   <func name="ASN1_item_ex_d2i(sname=X509_ALGOR itype=1 utype=16)">
597                     <func name="asn1_template_ex_d2i(field_name=algorithm flags=0 item=ASN1_OBJECT)">
598                       <func name="asn1_template_noexp_d2i(field_name=algorithm flags=0 item=ASN1_OBJECT)">
599                         <func name="ASN1_item_ex_d2i(sname=ASN1_OBJECT itype=0 utype=6)">
600                           <func name="asn1_d2i_ex_primitive(sname=ASN1_OBJECT itype=0 utype=6)">
601                             <func name="asn1_ex_c2i(sname=ASN1_OBJECT itype=0 utype=6)"/>
602                           </func>
603                         </func>
604                       </func>
605                     </func>
606                     <func name="asn1_template_ex_d2i(field_name=parameter flags=OPT_ item=ASN1_ANY)">
607                       <func name="asn1_template_noexp_d2i(field_name=parameter flags=OPT_ item=ASN1_ANY)">
608                         <func name="ASN1_item_ex_d2i(sname=ASN1_ANY itype=0 utype=-4)">
609                           <func name="asn1_d2i_ex_primitive(sname=ASN1_ANY itype=0 utype=-4)">
610                             <func name="asn1_ex_c2i(sname=ASN1_ANY itype=0 utype=-4)">
611                               <func name="ASN1_TYPE_new">
612                                 <func name="ASN1_item_new(sname=ASN1_ANY itype=0 utype=-4)">
613                                   <func name="ASN1_item_ex_new(sname=ASN1_ANY itype=0 utype=-4)">
614                                     <func name="asn1_item_ex_combine_new(sname=ASN1_ANY itype=0 utype=-4 type=NEW)">
615                                       <func name="ASN1_primitive_new(sname=ASN1_ANY itype=0 utype=-4)"/>
616                                     </func>
617                                   </func>
618                                 </func>
619                               </func>
620                             </func>
621                           </func>
622                         </func>
623                       </func>
624                     </func>
625                   </func>
626                 </func>
627               </func>
628               <func name="asn1_template_ex_d2i(field_name=public_key flags=0 item=ASN1_BIT_STRING)">
629                 <func name="asn1_template_noexp_d2i(field_name=public_key flags=0 item=ASN1_BIT_STRING)">
630                   <func name="ASN1_item_ex_d2i(sname=ASN1_BIT_STRING itype=0 utype=3)">
631                     <func name="asn1_d2i_ex_primitive(sname=ASN1_BIT_STRING itype=0 utype=3)">
632                       <func name="asn1_ex_c2i(sname=ASN1_BIT_STRING itype=0 utype=3)"/>
633                     </func>
634                   </func>
635                 </func>
636               </func>
637             </func>
638           </func>
639         </func>
640         <func name="asn1_template_ex_d2i(field_name=issuerUID flags=OPT_IMP_CONT_ item=ASN1_BIT_STRING)">
641           <func name="asn1_template_noexp_d2i(field_name=issuerUID flags=OPT_IMP_CONT_ item=ASN1_BIT_STRING)">
642             <func name="ASN1_item_ex_d2i(sname=ASN1_BIT_STRING itype=0 utype=3)">
643               <func name="asn1_d2i_ex_primitive(sname=ASN1_BIT_STRING itype=0 utype=3)"/>
644             </func>
645           </func>
646         </func>
647         <func name="asn1_template_ex_d2i(field_name=subjectUID flags=OPT_IMP_CONT_ item=ASN1_BIT_STRING)">
648           <func name="asn1_template_noexp_d2i(field_name=subjectUID flags=OPT_IMP_CONT_ item=ASN1_BIT_STRING)">
649             <func name="ASN1_item_ex_d2i(sname=ASN1_BIT_STRING itype=0 utype=3)">
650               <func name="asn1_d2i_ex_primitive(sname=ASN1_BIT_STRING itype=0 utype=3)"/>
651             </func>
652           </func>
653         </func>
654         <func name="asn1_template_ex_d2i(field_name=extensions flags=OPT_SEQUENCE_EXP_CONT_ item=X509_EXTENSION)">
655           <func name="asn1_template_noexp_d2i(field_name=extensions flags=OPT_SEQUENCE_EXP_CONT_ item=X509_EXTENSION)">
656             <func name="ASN1_item_ex_d2i(sname=X509_EXTENSION itype=1 utype=16)">
657               <func name="ASN1_item_ex_new(sname=X509_EXTENSION itype=1 utype=16)">
658                 <func name="asn1_item_ex_combine_new(sname=X509_EXTENSION itype=1 utype=16 type=NEW)">
659                   <func name="ASN1_template_new(field_name=object flags=0 item=ASN1_OBJECT)">
660                     <func name="asn1_item_ex_combine_new(sname=ASN1_OBJECT itype=0 utype=6 type=NEW)">
661                       <func name="ASN1_primitive_new(sname=ASN1_OBJECT itype=0 utype=6)"/>
662                     </func>
663                   </func>
664                   <func name="ASN1_template_new(field_name=critical flags=OPT_ item=ASN1_BOOLEAN)"/>
665                   <func name="ASN1_template_new(field_name=value flags=0 item=ASN1_OCTET_STRING)">
666                     <func name="asn1_item_ex_combine_new(sname=ASN1_OCTET_STRING itype=0 utype=4 type=NEW)">
667                       <func name="ASN1_primitive_new(sname=ASN1_OCTET_STRING itype=0 utype=4)"/>
668                     </func>
669                   </func>
670                 </func>
671               </func>
672               <func name="asn1_template_ex_d2i(field_name=object flags=0 item=ASN1_OBJECT)">
673                 <func name="asn1_template_noexp_d2i(field_name=object flags=0 item=ASN1_OBJECT)">
674                   <func name="ASN1_item_ex_d2i(sname=ASN1_OBJECT itype=0 utype=6)">
675                     <func name="asn1_d2i_ex_primitive(sname=ASN1_OBJECT itype=0 utype=6)">
676                       <func name="asn1_ex_c2i(sname=ASN1_OBJECT itype=0 utype=6)"/>
677                     </func>
678                   </func>
679                 </func>
680               </func>
681               <func name="asn1_template_ex_d2i(field_name=critical flags=OPT_ item=ASN1_BOOLEAN)">
682                 <func name="asn1_template_noexp_d2i(field_name=critical flags=OPT_ item=ASN1_BOOLEAN)">
683                   <func name="ASN1_item_ex_d2i(sname=ASN1_BOOLEAN itype=0 utype=1)">
684                     <func name="asn1_d2i_ex_primitive(sname=ASN1_BOOLEAN itype=0 utype=1)"/>
685                   </func>
686                 </func>
687               </func>
688               <func name="asn1_template_ex_d2i(field_name=value flags=0 item=ASN1_OCTET_STRING)">
689                 <func name="asn1_template_noexp_d2i(field_name=value flags=0 item=ASN1_OCTET_STRING)">
690                   <func name="ASN1_item_ex_d2i(sname=ASN1_OCTET_STRING itype=0 utype=4)">
691                     <func name="asn1_d2i_ex_primitive(sname=ASN1_OCTET_STRING itype=0 utype=4)">
692                       <func name="asn1_ex_c2i(sname=ASN1_OCTET_STRING itype=0 utype=4)"/>
693                     </func>
694                   </func>
695                 </func>
696               </func>
697             </func>
698             <func name="ASN1_item_ex_d2i(sname=X509_EXTENSION itype=1 utype=16)">
699               <func name="ASN1_item_ex_new(sname=X509_EXTENSION itype=1 utype=16)">
700                 <func name="asn1_item_ex_combine_new(sname=X509_EXTENSION itype=1 utype=16 type=NEW)">
701                   <func name="ASN1_template_new(field_name=object flags=0 item=ASN1_OBJECT)">
702                     <func name="asn1_item_ex_combine_new(sname=ASN1_OBJECT itype=0 utype=6 type=NEW)">
703                       <func name="ASN1_primitive_new(sname=ASN1_OBJECT itype=0 utype=6)"/>
704                     </func>
705                   </func>
706                   <func name="ASN1_template_new(field_name=critical flags=OPT_ item=ASN1_BOOLEAN)"/>
707                   <func name="ASN1_template_new(field_name=value flags=0 item=ASN1_OCTET_STRING)">
708                     <func name="asn1_item_ex_combine_new(sname=ASN1_OCTET_STRING itype=0 utype=4 type=NEW)">
709                       <func name="ASN1_primitive_new(sname=ASN1_OCTET_STRING itype=0 utype=4)"/>
710                     </func>
711                   </func>
712                 </func>
713               </func>
714               <func name="asn1_template_ex_d2i(field_name=object flags=0 item=ASN1_OBJECT)">
715                 <func name="asn1_template_noexp_d2i(field_name=object flags=0 item=ASN1_OBJECT)">
716                   <func name="ASN1_item_ex_d2i(sname=ASN1_OBJECT itype=0 utype=6)">
717                     <func name="asn1_d2i_ex_primitive(sname=ASN1_OBJECT itype=0 utype=6)">
718                       <func name="asn1_ex_c2i(sname=ASN1_OBJECT itype=0 utype=6)"/>
719                     </func>
720                   </func>
721                 </func>
722               </func>
723               <func name="asn1_template_ex_d2i(field_name=critical flags=OPT_ item=ASN1_BOOLEAN)">
724                 <func name="asn1_template_noexp_d2i(field_name=critical flags=OPT_ item=ASN1_BOOLEAN)">
725                   <func name="ASN1_item_ex_d2i(sname=ASN1_BOOLEAN itype=0 utype=1)">
726                     <func name="asn1_d2i_ex_primitive(sname=ASN1_BOOLEAN itype=0 utype=1)"/>
727                   </func>
728                 </func>
729               </func>
730               <func name="asn1_template_ex_d2i(field_name=value flags=0 item=ASN1_OCTET_STRING)">
731                 <func name="asn1_template_noexp_d2i(field_name=value flags=0 item=ASN1_OCTET_STRING)">
732                   <func name="ASN1_item_ex_d2i(sname=ASN1_OCTET_STRING itype=0 utype=4)">
733                     <func name="asn1_d2i_ex_primitive(sname=ASN1_OCTET_STRING itype=0 utype=4)">
734                       <func name="asn1_ex_c2i(sname=ASN1_OCTET_STRING itype=0 utype=4)"/>
735                     </func>
736                   </func>
737                 </func>
738               </func>
739             </func>
740             <func name="ASN1_item_ex_d2i(sname=X509_EXTENSION itype=1 utype=16)">
741               <func name="ASN1_item_ex_new(sname=X509_EXTENSION itype=1 utype=16)">
742                 <func name="asn1_item_ex_combine_new(sname=X509_EXTENSION itype=1 utype=16 type=NEW)">
743                   <func name="ASN1_template_new(field_name=object flags=0 item=ASN1_OBJECT)">
744                     <func name="asn1_item_ex_combine_new(sname=ASN1_OBJECT itype=0 utype=6 type=NEW)">
745                       <func name="ASN1_primitive_new(sname=ASN1_OBJECT itype=0 utype=6)"/>
746                     </func>
747                   </func>
748                   <func name="ASN1_template_new(field_name=critical flags=OPT_ item=ASN1_BOOLEAN)"/>
749                   <func name="ASN1_template_new(field_name=value flags=0 item=ASN1_OCTET_STRING)">
750                     <func name="asn1_item_ex_combine_new(sname=ASN1_OCTET_STRING itype=0 utype=4 type=NEW)">
751                       <func name="ASN1_primitive_new(sname=ASN1_OCTET_STRING itype=0 utype=4)"/>
752                     </func>
753                   </func>
754                 </func>
755               </func>
756               <func name="asn1_template_ex_d2i(field_name=object flags=0 item=ASN1_OBJECT)">
757                 <func name="asn1_template_noexp_d2i(field_name=object flags=0 item=ASN1_OBJECT)">
758                   <func name="ASN1_item_ex_d2i(sname=ASN1_OBJECT itype=0 utype=6)">
759                     <func name="asn1_d2i_ex_primitive(sname=ASN1_OBJECT itype=0 utype=6)">
760                       <func name="asn1_ex_c2i(sname=ASN1_OBJECT itype=0 utype=6)"/>
761                     </func>
762                   </func>
763                 </func>
764               </func>
765               <func name="asn1_template_ex_d2i(field_name=critical flags=OPT_ item=ASN1_BOOLEAN)">
766                 <func name="asn1_template_noexp_d2i(field_name=critical flags=OPT_ item=ASN1_BOOLEAN)">
767                   <func name="ASN1_item_ex_d2i(sname=ASN1_BOOLEAN itype=0 utype=1)">
768                     <func name="asn1_d2i_ex_primitive(sname=ASN1_BOOLEAN itype=0 utype=1)"/>
769                   </func>
770                 </func>
771               </func>
772               <func name="asn1_template_ex_d2i(field_name=value flags=0 item=ASN1_OCTET_STRING)">
773                 <func name="asn1_template_noexp_d2i(field_name=value flags=0 item=ASN1_OCTET_STRING)">
774                   <func name="ASN1_item_ex_d2i(sname=ASN1_OCTET_STRING itype=0 utype=4)">
775                     <func name="asn1_d2i_ex_primitive(sname=ASN1_OCTET_STRING itype=0 utype=4)">
776                       <func name="asn1_ex_c2i(sname=ASN1_OCTET_STRING itype=0 utype=4)"/>
777                     </func>
778                   </func>
779                 </func>
780               </func>
781             </func>
782           </func>
783         </func>
784       </func>
785     </func>
786   </func>
787   <func name="asn1_template_ex_d2i(field_name=sig_alg flags=0 item=X509_ALGOR)">
788     <func name="asn1_template_noexp_d2i(field_name=sig_alg flags=0 item=X509_ALGOR)">
789       <func name="ASN1_item_ex_d2i(sname=X509_ALGOR itype=1 utype=16)">
790         <func name="asn1_template_ex_d2i(field_name=algorithm flags=0 item=ASN1_OBJECT)">
791           <func name="asn1_template_noexp_d2i(field_name=algorithm flags=0 item=ASN1_OBJECT)">
792             <func name="ASN1_item_ex_d2i(sname=ASN1_OBJECT itype=0 utype=6)">
793               <func name="asn1_d2i_ex_primitive(sname=ASN1_OBJECT itype=0 utype=6)">
794                 <func name="asn1_ex_c2i(sname=ASN1_OBJECT itype=0 utype=6)"/>
795               </func>
796             </func>
797           </func>
798         </func>
799         <func name="asn1_template_ex_d2i(field_name=parameter flags=OPT_ item=ASN1_ANY)">
800           <func name="asn1_template_noexp_d2i(field_name=parameter flags=OPT_ item=ASN1_ANY)">
801             <func name="ASN1_item_ex_d2i(sname=ASN1_ANY itype=0 utype=-4)">
802               <func name="asn1_d2i_ex_primitive(sname=ASN1_ANY itype=0 utype=-4)">
803                 <func name="asn1_ex_c2i(sname=ASN1_ANY itype=0 utype=-4)">
804                   <func name="ASN1_TYPE_new">
805                     <func name="ASN1_item_new(sname=ASN1_ANY itype=0 utype=-4)">
806                       <func name="ASN1_item_ex_new(sname=ASN1_ANY itype=0 utype=-4)">
807                         <func name="asn1_item_ex_combine_new(sname=ASN1_ANY itype=0 utype=-4 type=NEW)">
808                           <func name="ASN1_primitive_new(sname=ASN1_ANY itype=0 utype=-4)"/>
809                         </func>
810                       </func>
811                     </func>
812                   </func>
813                 </func>
814               </func>
815             </func>
816           </func>
817         </func>
818       </func>
819     </func>
820   </func>
821   <func name="asn1_template_ex_d2i(field_name=signature flags=0 item=ASN1_BIT_STRING)">
822     <func name="asn1_template_noexp_d2i(field_name=signature flags=0 item=ASN1_BIT_STRING)">
823       <func name="ASN1_item_ex_d2i(sname=ASN1_BIT_STRING itype=0 utype=3)">
824         <func name="asn1_d2i_ex_primitive(sname=ASN1_BIT_STRING itype=0 utype=3)">
825           <func name="asn1_ex_c2i(sname=ASN1_BIT_STRING itype=0 utype=3)"/>
826         </func>
827       </func>
828     </func>
829   </func>
830 </func>

说明:
0、与 Linux 的 strace 相比,树的结构不仅可以表示函数运行的先后顺序(从上到下),更重要的是可以表示函数间的调用关系
1、被调用函数比调用函数缩进一层显示,处于同一层次的函数则平行显示
2、函数后跟入参说明,用于区分
3、以 XML 格式存放,可以方便折叠显示
4、目前只显示我们关注的 d2i 系列函数

那怎么用呢?

我们看到上面的第 100 行(asn1_ex_c2i)正是序列号转换的代码,见下面一段运行记录
<func name="asn1_template_ex_d2i(field_name=serialNumber flags=0 item=ASN1_INTEGER)">
  <func name="asn1_template_noexp_d2i(field_name=serialNumber flags=0 item=ASN1_INTEGER)">
    <func name="ASN1_item_ex_d2i(sname=ASN1_INTEGER itype=0 utype=2)">
      <func name="asn1_d2i_ex_primitive(sname=ASN1_INTEGER itype=0 utype=2)">
        <func name="asn1_ex_c2i(sname=ASN1_INTEGER itype=0 utype=2)"/>
直接将断点设在函数 asn1_ex_c2i 的入口(注意要等 d2i_X509 运行到再设断点)
并设置断点命中次数为 2 -- asn1_ex_c2i 第 2 次运行时进行 serialNumber 的转换
则中断后,就可以直接进入现场排查了,经过跟踪,我们最终发现了错误的原因

欲知是哪个函数出了问题?请见下回分解