x_algor.c 分析

相关的变量定义
    
    
    
    
typedef struct X509_algor_st X509_ALGOR;
 
struct X509_algor_st {
ASN1_OBJECT *algorithm;
ASN1_TYPE *parameter;
} /* X509_ALGOR */ ;

x_algor.c 中的宏展开
    
    
    
    
ASN1_SEQUENCE(X509_ALGOR) = {
ASN1_SIMPLE(X509_ALGOR, algorithm, ASN1_OBJECT),
ASN1_OPT(X509_ALGOR, parameter, ASN1_ANY)
} 定义了如下全局变量:
 
static const ASN1_TEMPLATE X509_ALGOR_seq_tt[] = {
{ (0), (0), __builtin_offsetof (X509_ALGOR, algorithm), "algorithm", (&(ASN1_OBJECT_it)) },
{ ((0x1)), (0), __builtin_offsetof (X509_ALGOR, parameter), "parameter", (&(ASN1_ANY_it)) }
} ;
 
ASN1_SEQUENCE_END(X509_ALGOR) 定义了如下全局变量:
const ASN1_ITEM X509_ALGOR_it =
{ 0x1,
16,
X509_ALGOR_seq_tt,
sizeof(X509_ALGOR_seq_tt) / sizeof(ASN1_TEMPLATE),
((void *)0),
sizeof(X509_ALGOR),
"X509_ALGOR" };
 
 
ASN1_ITEM_TEMPLATE(X509_ALGORS) =
ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, algorithms, X509_ALGOR)
定义了如下全局变量:
static const ASN1_TEMPLATE X509_ALGORS_item_tt =
{ ((0x2 << 1)), (0), 0, "algorithms", (&(X509_ALGOR_it)) };
 
ASN1_ITEM_TEMPLATE_END(X509_ALGORS) 定义了如下全局变量:
const ASN1_ITEM X509_ALGORS_it = { 0x0, -1, &X509_ALGORS_item_tt, 0, ((void *)0), 0, "X509_ALGORS" };

可以看出,主要有两种类型的全局变量:ASN1_TEMPLATE和ASN1_ITEM。
两个结构体的定义如下:
    
    
    
    
 
typedef struct ASN1_ITEM_st ASN1_ITEM;
typedef const ASN1_ITEM ASN1_ITEM_EXP;
 
typedef struct ASN1_TEMPLATE_st {
unsigned long flags; //Various flags
long tag; //tag, not used if no tagging
unsigned long offset; //本例中,ASN1_TEMPLATE中定义的某类型结构中某个参数的偏移值,比如X509_ALGOR中algorithm的偏移
const char *field_name; //参数名字
ASN1_ITEM_EXP *item; //本参数指定的ASN1_ITEM全局变量指针,定义中tasn_type.c中 Relevant ASN1_ITEM or ASN1_ADB
}ASN1_TEMPLATE;
 
struct ASN1_ITEM_st {
char itype; //The item type, primitive, SEQUENCE, CHOICEor extern
long utype; //underlying type, ASN1_ITEM的类型,比如SEQUENCE是16,未定义的-1
const ASN1_TEMPLATE *templates; //指明的ASN1_TEMPLATE; If SEQUENCE or CHOICE this contains the contents
long tcount; //ASN1_TEMPLATE模板数组中模板的个数 Number of templates if SEQUENCE or CHOICE
const void *funcs; //functions that handle this type
long size; //该ASN1_ITEM实际结构体的大小,此例中为X509_ALGOR Structure size (usually)
const char *sname; //该ASN1_ITEM的名字,此例中为"X509_ALGOR"
};
     
     
     
     
IMPLEMENT_ASN1_FUNCTIONS(X509_ALGOR) 定义了多个函数
X509_ALGOR *d2i_X509_ALGOR(X509_ALGOR **a, const unsigned char **in, long len)
{
return (X509_ALGOR *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, (&(X509_ALGOR_it)));
}
 
int i2d_X509_ALGOR(X509_ALGOR *a, unsigned char **out)
{
return ASN1_item_i2d((ASN1_VALUE *)a, out, (&(X509_ALGOR_it)));
}
 
X509_ALGOR *X509_ALGOR_new(void)
{
return (X509_ALGOR *)ASN1_item_new((&(X509_ALGOR_it)));
}
void X509_ALGOR_free(X509_ALGOR *a)
{
ASN1_item_free((ASN1_VALUE *)a, (&(X509_ALGOR_it)));
}
IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(X509_ALGORS, X509_ALGORS, X509_ALGORS) 定义了两个函数
X509_ALGORS *d2i_X509_ALGORS(X509_ALGORS **a, const unsigned char **in, long len)
{
return (X509_ALGORS *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, (&(X509_ALGORS_it)));
}
 
int i2d_X509_ALGORS(X509_ALGORS *a, unsigned char **out)
{
return ASN1_item_i2d((ASN1_VALUE *)a, out, (&(X509_ALGORS_it)));
}
IMPLEMENT_ASN1_DUP_FUNCTION(X509_ALGOR) 定义了一个函数
X509_ALGOR * X509_ALGOR_dup(X509_ALGOR *x)
{
return ASN1_item_dup((&(X509_ALGOR_it)), x);
}
下面是一个例子,根据例子通过GDB来 具体跟踪一下这几个函数。
例子如下:
    
    
    
    
#include <string.h>
#include <openssl/x509.h>
int main()
{
FILE *fp;
char *buf,*p;
char data[]={"12345678"},read[1024];
int len;
 
X509_ALGOR *alg=NULL,*alg2=NULL,*alg3=NULL;
/* new 函数 */
alg=X509_ALGOR_new();
/* 构造内容 */
alg->algorithm=OBJ_nid2obj(NID_sha256);
alg->parameter=ASN1_TYPE_new();
ASN1_TYPE_set_octetstring(alg->parameter,data,strlen(data));
/* i2d 函数 */
len=i2d_X509_ALGOR(alg,NULL);
p=buf=malloc(len);
len=i2d_X509_ALGOR(alg,(unsigned char **)&p);
/* 写入文件 */
fp=fopen("alg.cer","wb");
fwrite(buf,1,len,fp);
fclose(fp);
/* 读文件 */
fp=fopen("alg.cer","rb");
len=fread(read,1,1024,fp);
fclose(fp);
p=read;
/* d2i 函数 */
d2i_X509_ALGOR(&alg2,(const unsigned char **)&p,len);
if(alg2==NULL)
{
printf("err\n");
}
/* dup 函数 */
alg3=X509_ALGOR_dup(alg);
/* free 函数 */
X509_ALGOR_free(alg);
if(alg2)
X509_ALGOR_free(alg2);
X509_ALGOR_free(alg3);
free(buf);
return 0;
}
     
    
X509_ALGOR_new:创建一个X509_ALGOR,返回X509_ALGOR类型的对象
    -->ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it):注意,这里返回的是ASN1_VALUE*,入参是ANS1_ITEM*
    ASN1_VALUE的定义中asn1.h中: typedef struct ASN1_VALUE_st ASN1_VALUE;实际找这个ASN_VALUE_st是找不到的,可以看定义处源码上的注释,这里实际是
    C语言的一种特殊用法(c anonymous struct),源码中使用此类型都是强转为其他类型的,这里这个类型就相当于void*。
    入参是一个ASN1_ITEM类型,可以看到这里传进来的是 X509_ALGOR_it;
    -->ASN1_item_ex_new
    -->asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
        //这里入参1是需要返回的创建对象;入参2是X509_ALGOR_it;入参3是0
    具体的栈信息如下:

    
    
    
    
12 alg=X509_ALGOR_new();
(gdb) s
X509_ALGOR_new () at x_algor.c:74
74 IMPLEMENT_ASN1_FUNCTIONS(X509_ALGOR)
(gdb) s
ASN1_item_new (it=0x7ffff7dbed80 <X509_ALGOR_it>) at tasn_new.c:75
75 ASN1_VALUE *ret = NULL;
(gdb) n
76 if (ASN1_item_ex_new(&ret, it) > 0)
(gdb) s
ASN1_item_ex_new (pval=0x7fffffffdfa8, it=0x7ffff7dbed80 <X509_ALGOR_it>) at tasn_new.c:85
85 return asn1_item_ex_combine_new(pval, it, 0);
(gdb) s
asn1_item_ex_combine_new (pval=0x7fffffffdfa8, it=0x7ffff7dbed80 <X509_ALGOR_it>, combine=0) at tasn_new.c:91
91 const ASN1_TEMPLATE *tt = NULL;
(gdb) n
94 const ASN1_AUX *aux = it->funcs;
(gdb)
98 if (aux && aux->asn1_cb)
(gdb)
101 asn1_cb = 0;
(gdb)
104 if (it->sname)
(gdb) n
105 CRYPTO_push_info(it->sname);
(gdb) s
CRYPTO_push_info_ (info=0x7ffff7b73655 "X509_ALGOR", file=0x7ffff7b7408c "tasn_new.c", line=105) at mem_dbg.c:392
392 int ret = 0;
(gdb) n
394 if (is_MemCheck_on()) {
(gdb)
432 return (ret);
(gdb) n
433 }
(gdb)
asn1_item_ex_combine_new (pval=0x7fffffffdfa8, it=0x7ffff7dbed80 <X509_ALGOR_it>, combine=0) at tasn_new.c:108
108 switch (it->itype) {
(gdb)
166 if (asn1_cb) {
(gdb)
178 if (!combine) {
(gdb) p *it
$1 = {itype = 1 '\001', utype = 16, templates = 0x7ffff7dc58a0 <X509_ALGOR_seq_tt>, tcount = 2, funcs = 0x0, size = 16, sname = 0x7ffff7b73655 "X509_ALGOR"}
(gdb) n
179 *pval = OPENSSL_malloc(it->size);
(gdb) n
180 if (!*pval)
(gdb) n
182 memset(*pval, 0, it->size);
(gdb) p it->size
$2 = 16
(gdb) n
183 asn1_do_lock(pval, 0, it);
(gdb) s
asn1_do_lock (pval=0x7fffffffdfa8, op=0, it=0x7ffff7dbed80 <X509_ALGOR_it>) at tasn_utl.c:107
107 if ((it->itype != ASN1_ITYPE_SEQUENCE)
(gdb) n
110 aux = it->funcs;
(gdb) n
111 if (!aux || !(aux->flags & ASN1_AFLG_REFCOUNT))
(gdb) p aux
$3 = (const ASN1_AUX *) 0x0
(gdb) n
112 return 0;
(gdb) n
127 }
(gdb) n
asn1_item_ex_combine_new (pval=0x7fffffffdfa8, it=0x7ffff7dbed80 <X509_ALGOR_it>, combine=0) at tasn_new.c:184
184 asn1_enc_init(pval, it);
(gdb) s
asn1_enc_init (pval=0x7fffffffdfa8, it=0x7ffff7dbed80 <X509_ALGOR_it>) at tasn_utl.c:143
143 enc = asn1_get_enc_ptr(pval, it);
(gdb) s
asn1_get_enc_ptr (pval=0x7fffffffdfa8, it=0x7ffff7dbed80 <X509_ALGOR_it>) at tasn_utl.c:132
132 if (!pval || !*pval)
(gdb) n
134 aux = it->funcs;
(gdb) n
135 if (!aux || !(aux->flags & ASN1_AFLG_ENCODING))
(gdb) n
136 return NULL;
(gdb) n
138 }
(gdb) n
asn1_enc_init (pval=0x7fffffffdfa8, it=0x7ffff7dbed80 <X509_ALGOR_it>) at tasn_utl.c:144
144 if (enc) {
(gdb) n
149 }
(gdb) n
asn1_item_ex_combine_new (pval=0x7fffffffdfa8, it=0x7ffff7dbed80 <X509_ALGOR_it>, combine=0) at tasn_new.c:186
186 for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
(gdb) n
187 pseqval = asn1_get_field_ptr(pval, tt);
(gdb) s
asn1_get_field_ptr (pval=0x7fffffffdfa8, tt=0x7ffff7dc58a0 <X509_ALGOR_seq_tt>) at tasn_utl.c:204
204 if (tt->flags & ASN1_TFLG_COMBINE)
(gdb) n
206 pvaltmp = offset2ptr(*pval, tt->offset);
(gdb) p pval
$4 = (ASN1_VALUE **) 0x7fffffffdfa8
(gdb) n
211 return pvaltmp;
(gdb) p pvaltmp
$5 = (ASN1_VALUE **) 0x603010
(gdb) p *pval
$6 = (ASN1_VALUE *) 0x603010
(gdb) p tt->offset
$7 = 0
(gdb) n
212 }
(gdb) n
asn1_item_ex_combine_new (pval=0x7fffffffdfa8, it=0x7ffff7dbed80 <X509_ALGOR_it>, combine=0) at tasn_new.c:188
188 if (!ASN1_template_new(pseqval, tt))
(gdb) s
ASN1_template_new (pval=0x603010, tt=0x7ffff7dc58a0 <X509_ALGOR_seq_tt>) at tasn_new.c:256
256 const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item);
(gdb) p *tt
$8 = {flags = 0, tag = 0, offset = 0, field_name = 0x7ffff7b73641 "algorithm", item = 0x7ffff7dbf740 <ASN1_OBJECT_it>}
(gdb) p tt->item
$9 = (ASN1_ITEM_EXP *) 0x7ffff7dbf740 <ASN1_OBJECT_it>
(gdb) p *tt->item
$10 = {itype = 0 '\000', utype = 6, templates = 0x0, tcount = 0, funcs = 0x0, size = 0, sname = 0x7ffff7b742c9 "ASN1_OBJECT"}
(gdb) n
258 if (tt->flags & ASN1_TFLG_OPTIONAL) {
(gdb) n
264 if (tt->flags & ASN1_TFLG_ADB_MASK) {
(gdb) n
269 if (tt->field_name)
(gdb) n
270 CRYPTO_push_info(tt->field_name);
(gdb)
273 if (tt->flags & ASN1_TFLG_SK_MASK) {
(gdb)
286 ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE);
(gdb) s
asn1_item_ex_combine_new (pval=0x603010, it=0x7ffff7dbf740 <ASN1_OBJECT_it>, combine=0) at tasn_new.c:91
91 const ASN1_TEMPLATE *tt = NULL;
(gdb) n
94 const ASN1_AUX *aux = it->funcs;
(gdb) n
98 if (aux && aux->asn1_cb)
(gdb)
101 asn1_cb = 0;
(gdb)
104 if (it->sname)
(gdb)
105 CRYPTO_push_info(it->sname);
(gdb)
108 switch (it->itype) {
(gdb)
128 if (it->templates) {
(gdb) p *it
$11 = {itype = 0 '\000', utype = 6, templates = 0x0, tcount = 0, funcs = 0x0, size = 0, sname = 0x7ffff7b742c9 "ASN1_OBJECT"}
(gdb) n
131 } else if (!ASN1_primitive_new(pval, it))
(gdb) s
ASN1_primitive_new (pval=0x603010, it=0x7ffff7dbf740 <ASN1_OBJECT_it>) at tasn_new.c:315
315 if (!it)
(gdb) n
318 if (it->funcs) {
(gdb)
324 if (it->itype == ASN1_ITYPE_MSTRING)
(gdb)
327 utype = it->utype;
(gdb) n
328 switch (utype) {
(gdb) n
330 *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef);
(gdb) s
OBJ_nid2obj (n=0) at obj_dat.c:318
318 if ((n >= 0) && (n < NUM_NID)) {
(gdb) n
319 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) {
(gdb) n
323 return ((ASN1_OBJECT *)&(nid_objs[n]));
(gdb) n
338 }
(gdb) n
ASN1_primitive_new (pval=0x603010, it=0x7ffff7dbf740 <ASN1_OBJECT_it>) at tasn_new.c:331
331 return 1;
(gdb) n
360 }
(gdb)
asn1_item_ex_combine_new (pval=0x603010, it=0x7ffff7dbf740 <ASN1_OBJECT_it>, combine=0) at tasn_new.c:133
133 break;
(gdb)
196 if (it->sname)
(gdb)
197 CRYPTO_pop_info();
(gdb)
199 return 1;
(gdb)
218 }
(gdb)
ASN1_template_new (pval=0x603010, tt=0x7ffff7dc58a0 <X509_ALGOR_seq_tt>) at tasn_new.c:289
289 if (it->sname)
(gdb)
290 CRYPTO_pop_info();
(gdb)
292 return ret;
(gdb)
293 }
(gdb)
asn1_item_ex_combine_new (pval=0x7fffffffdfa8, it=0x7ffff7dbed80 <X509_ALGOR_it>, combine=0) at tasn_new.c:186
186 for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
(gdb)
187 pseqval = asn1_get_field_ptr(pval, tt);
(gdb)
188 if (!ASN1_template_new(pseqval, tt))
(gdb) s
ASN1_template_new (pval=0x603018, tt=0x7ffff7dc58c8 <X509_ALGOR_seq_tt+40>) at tasn_new.c:256
256 const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item);
(gdb) n
258 if (tt->flags & ASN1_TFLG_OPTIONAL) {
(gdb)
259 asn1_template_clear(pval, tt);
(gdb) s
asn1_template_clear (pval=0x603018, tt=0x7ffff7dc58c8 <X509_ALGOR_seq_tt+40>) at tasn_new.c:298
298 if (tt->flags & (ASN1_TFLG_ADB_MASK | ASN1_TFLG_SK_MASK))
(gdb) n
301 asn1_item_clear(pval, ASN1_ITEM_ptr(tt->item));
(gdb) s
asn1_item_clear (pval=0x603018, it=0x7ffff7dbfa00 <ASN1_ANY_it>) at tasn_new.c:224
224 switch (it->itype) {
(gdb) n
235 if (it->templates)
(gdb)
238 asn1_primitive_clear(pval, it);
(gdb) p *it
$12 = {itype = 0 '\000', utype = -4, templates = 0x0, tcount = 0, funcs = 0x0, size = 0, sname = 0x7ffff7b74384 "ASN1_ANY"}
(gdb) s
asn1_primitive_clear (pval=0x603018, it=0x7ffff7dbfa00 <ASN1_ANY_it>) at tasn_new.c:365
365 if (it && it->funcs) {
(gdb) n
373 if (!it || (it->itype == ASN1_ITYPE_MSTRING))
(gdb) n
376 utype = it->utype;
(gdb)
377 if (utype == V_ASN1_BOOLEAN)
(gdb) p utype
$13 = -4
(gdb) n
380 *pval = NULL;
(gdb)
381 }
(gdb)
asn1_item_clear (pval=0x603018, it=0x7ffff7dbfa00 <ASN1_ANY_it>) at tasn_new.c:239
239 break;
(gdb)
252 }
(gdb)
asn1_template_clear (pval=0x603018, tt=0x7ffff7dc58c8 <X509_ALGOR_seq_tt+40>) at tasn_new.c:302
302 }
(gdb) n
ASN1_template_new (pval=0x603018, tt=0x7ffff7dc58c8 <X509_ALGOR_seq_tt+40>) at tasn_new.c:260
260 return 1;
(gdb) n
293 }
(gdb) n
asn1_item_ex_combine_new (pval=0x7fffffffdfa8, it=0x7ffff7dbed80 <X509_ALGOR_it>, combine=0) at tasn_new.c:186
186 for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
(gdb) n
191 if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL))
(gdb) p pseqval
$14 = (ASN1_VALUE **) 0x603018
(gdb) p pval
$15 = (ASN1_VALUE **) 0x7fffffffdfa8
(gdb) p *pval
$16 = (ASN1_VALUE *) 0x603010
(gdb) p asn1_cb
$17 = (ASN1_aux_cb *) 0x0
(gdb) n
193 break;
(gdb) p *(X509_ALGOR*)pval
$18 = {algorithm = 0x603010, parameter = 0x7fffffffdfc0}
(gdb) p *(X509_ALGOR*)pval->parameter
There is no member named parameter.
(gdb) p *((X509_ALGOR*)pval)->parameter)
Junk after end of expression.
(gdb) p *(((X509_ALGOR*)pval)->parameter)
$19 = {type = -7136, value = {ptr = 0x400b0d <main+61> "H\211E\370\277\240\002", boolean = 4197133, asn1_string = 0x400b0d <main+61>, object = 0x400b0d <main+61>,
integer = 0x400b0d <main+61>, enumerated = 0x400b0d <main+61>, bit_string = 0x400b0d <main+61>, octet_string = 0x400b0d <main+61>, printablestring = 0x400b0d <main+61>,
t61string = 0x400b0d <main+61>, ia5string = 0x400b0d <main+61>, generalstring = 0x400b0d <main+61>, bmpstring = 0x400b0d <main+61>, universalstring = 0x400b0d <main+61>,
utctime = 0x400b0d <main+61>, generalizedtime = 0x400b0d <main+61>, visiblestring = 0x400b0d <main+61>, utf8string = 0x400b0d <main+61>, set = 0x400b0d <main+61>,
sequence = 0x400b0d <main+61>, asn1_value = 0x400b0d <main+61>}}
(gdb) n
196 if (it->sname)
(gdb) n
197 CRYPTO_pop_info();
(gdb) n
199 return 1;
(gdb) n
218 }
(gdb) n
ASN1_item_ex_new (pval=0x7fffffffdfa8, it=0x7ffff7dbed80 <X509_ALGOR_it>) at tasn_new.c:86
86 }
(gdb) n
ASN1_item_new (it=0x7ffff7dbed80 <X509_ALGOR_it>) at tasn_new.c:77
77 return ret;
(gdb) n
79 }
(gdb) n
main () at openssl_x_algor_test.c:14
14 alg->algorithm=OBJ_nid2obj(NID_sha256);
(gdb) s
OBJ_nid2obj (n=672) at obj_dat.c:318
318 if ((n >= 0) && (n < NUM_NID)) {
(gdb) n
319 if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) {
(gdb) n
323 return ((ASN1_OBJECT *)&(nid_objs[n]));
(gdb) n
338 }
(gdb) n
main () at openssl_x_algor_test.c:15
15 alg->parameter=ASN1_TYPE_new();
(gdb) p alg->parameter
$20 = (ASN1_TYPE *) 0x0
(gdb) p *alg
$21 = {algorithm = 0x7ffff7db7d40 <nid_objs+26880>, parameter = 0x0}
(gdb) p *alg->algorithm
$22 = {sn = 0x7ffff7b3263f "SHA256", ln = 0x7ffff7b32646 "sha256", nid = 672, length = 9,
data = 0x7ffff7b2e7dc <lvalues+4540> "`\206H\001e\003\004\002\001`\206H\001e\003\004\002\002`\206H\001e\003\004\002\003`\206H\001e\003\004\002\004++\201\004g+g+\001*\206H\316=\001\002\003*\206H\316=\001\002\003\001*\206H\316=\001\002\003\002*\206H\316=\001\002\003\003*\206H\316=\003", flags = 0}
(gdb) s
ASN1_TYPE_new () at tasn_typ.c:118
118 IMPLEMENT_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
(gdb) s
ASN1_item_new (it=0x7ffff7dbfa00 <ASN1_ANY_it>) at tasn_new.c:75
75 ASN1_VALUE *ret = NULL;
(gdb) n
76 if (ASN1_item_ex_new(&ret, it) > 0)
(gdb) s
ASN1_item_ex_new (pval=0x7fffffffdfa8, it=0x7ffff7dbfa00 <ASN1_ANY_it>) at tasn_new.c:85
85 return asn1_item_ex_combine_new(pval, it, 0);
(gdb) s
asn1_item_ex_combine_new (pval=0x7fffffffdfa8, it=0x7ffff7dbfa00 <ASN1_ANY_it>, combine=0) at tasn_new.c:91
91 const ASN1_TEMPLATE *tt = NULL;
(gdb) n
94 const ASN1_AUX *aux = it->funcs;
(gdb) n
98 if (aux && aux->asn1_cb)
(gdb)
101 asn1_cb = 0;
(gdb)
104 if (it->sname)
(gdb)
105 CRYPTO_push_info(it->sname);
(gdb)
108 switch (it->itype) {
(gdb)
128 if (it->templates) {
(gdb)
131 } else if (!ASN1_primitive_new(pval, it))
(gdb) s
ASN1_primitive_new (pval=0x7fffffffdfa8, it=0x7ffff7dbfa00 <ASN1_ANY_it>) at tasn_new.c:315
315 if (!it)
(gdb) p *it
$23 = {itype = 0 '\000', utype = -4, templates = 0x0, tcount = 0, funcs = 0x0, size = 0, sname = 0x7ffff7b74384 "ASN1_ANY"}
(gdb) n
318 if (it->funcs) {
(gdb)
324 if (it->itype == ASN1_ITYPE_MSTRING)
(gdb)
327 utype = it->utype;
(gdb)
328 switch (utype) {
(gdb)
342 typ = OPENSSL_malloc(sizeof(ASN1_TYPE));
(gdb) p utype
$24 = -4
(gdb) n
343 if (!typ)
(gdb) n
345 typ->value.ptr = NULL;
(gdb) n
346 typ->type = -1;
(gdb) n
347 *pval = (ASN1_VALUE *)typ;
(gdb)
348 break;
(gdb)
357 if (*pval)
(gdb)
358 return 1;
(gdb)
360 }
(gdb)
asn1_item_ex_combine_new (pval=0x7fffffffdfa8, it=0x7ffff7dbfa00 <ASN1_ANY_it>, combine=0) at tasn_new.c:133
133 break;
(gdb)
196 if (it->sname)
(gdb)
197 CRYPTO_pop_info();
(gdb)
199 return 1;
(gdb)
218 }
(gdb)
ASN1_item_ex_new (pval=0x7fffffffdfa8, it=0x7ffff7dbfa00 <ASN1_ANY_it>) at tasn_new.c:86
86 }
(gdb)
ASN1_item_new (it=0x7ffff7dbfa00 <ASN1_ANY_it>) at tasn_new.c:77
77 return ret;
(gdb)
79 }
(gdb)
main () at openssl_x_algor_test.c:16
16 ASN1_TYPE_set_octetstring(alg->parameter,data,strlen(data));
(gdb) s
ASN1_TYPE_set_octetstring (a=0x603030, data=0x7fffffffe3e0 "12345678", len=8) at evp_asn1.c:68
68 if ((os = M_ASN1_OCTET_STRING_new()) == NULL)
(gdb) s
ASN1_STRING_type_new (type=4) at asn1_lib.c:412
412 ret = (ASN1_STRING *)OPENSSL_malloc(sizeof(ASN1_STRING));
(gdb) n
413 if (ret == NULL) {
(gdb)
417 ret->length = 0;
(gdb) p *ret
$25 = {length = 0, type = 0, data = 0x0, flags = 0}
(gdb) n
418 ret->type = type;
(gdb)
419 ret->data = NULL;
(gdb) n
420 ret->flags = 0;
(gdb)
421 return (ret);
(gdb)
422 }
(gdb)
ASN1_TYPE_set_octetstring (a=0x603030, data=0x7fffffffe3e0 "12345678", len=8) at evp_asn1.c:70
70 if (!M_ASN1_OCTET_STRING_set(os, data, len)) {
(gdb) s
ASN1_STRING_set (str=0x603050, _data=0x7fffffffe3e0, len=8) at asn1_lib.c:365
365 const char *data = _data;
(gdb)
367 if (len < 0) {
(gdb)
373 if ((str->length < len) || (str->data == NULL)) {
(gdb)
374 c = str->data;
(gdb)
375 if (c == NULL)
(gdb)
376 str->data = OPENSSL_malloc(len + 1);
(gdb) p *str
$26 = {length = 0, type = 4, data = 0x0, flags = 0}
(gdb) n
380 if (str->data == NULL) {
(gdb) n
386 str->length = len;
(gdb) n
387 if (data != NULL) {
(gdb) n
388 memcpy(str->data, data, len);
(gdb) n
390 str->data[len] = '\0';
(gdb) n
392 return (1);
(gdb) n
393 }
(gdb) n
ASN1_TYPE_set_octetstring (a=0x603030, data=0x7fffffffe3e0 "12345678", len=8) at evp_asn1.c:74
74 ASN1_TYPE_set(a, V_ASN1_OCTET_STRING, os);
(gdb) s
ASN1_TYPE_set (a=0x603030, type=4, value=0x603050) at a_type.c:74
74 if (a->value.ptr != NULL) {
(gdb) n
78 a->type = type;
(gdb) nn
Undefined command: "nn". Try "help".
(gdb) n
79 if (type == V_ASN1_BOOLEAN)
(gdb) n
82 a->value.ptr = value;
(gdb) n
83 }
(gdb) n
ASN1_TYPE_set_octetstring (a=0x603030, data=0x7fffffffe3e0 "12345678", len=8) at evp_asn1.c:75
75 return (1);
(gdb) n
76 }
(gdb) n
main () at openssl_x_algor_test.c:18
18 len=i2d_X509_ALGOR(alg,NULL);
(gdb) s
i2d_X509_ALGOR (a=0x603010, out=0x0) at x_algor.c:74
74 IMPLEMENT_ASN1_FUNCTIONS(X509_ALGOR)
(gdb) s
ASN1_item_i2d (val=0x603010, out=0x0, it=0x7ffff7dbed80 <X509_ALGOR_it>) at tasn_enc.c:90
90 return asn1_item_flags_i2d(val, out, it, 0);
(gdb) s
asn1_item_flags_i2d (val=0x603010, out=0x0, it=0x7ffff7dbed80 <X509_ALGOR_it>, flags=0) at tasn_enc.c:103
103 if (out && !*out) {
(gdb) n
118 return ASN1_item_ex_i2d(&val, out, it, -1, flags);
(gdb) s
ASN1_item_ex_i2d (pval=0x7fffffffdf48, out=0x0, it=0x7ffff7dbed80 <X509_ALGOR_it>, tag=-1, aclass=0) at tasn_enc.c:129
129 const ASN1_TEMPLATE *tt = NULL;
(gdb) n
130 unsigned char *p = NULL;
(gdb) n
131 int i, seqcontlen, seqlen, ndef = 1;
(gdb)
134 const ASN1_AUX *aux = it->funcs;
(gdb)
135 ASN1_aux_cb *asn1_cb = 0;
(gdb)
137 if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval)
(gdb) n
140 if (aux && aux->asn1_cb)
(gdb) n
143 switch (it->itype) {
(gdb) n
197 i = asn1_enc_restore(&seqcontlen, out, pval, it);
(gdb) p it->itype
$27 = 1 '\001'
(gdb) p *pval
$28 = (ASN1_VALUE *) 0x603010
(gdb) s
asn1_enc_restore (len=0x7fffffffdeac, out=0x0, pval=0x7fffffffdf48, it=0x7ffff7dbed80 <X509_ALGOR_it>) at tasn_utl.c:188
188 enc = asn1_get_enc_ptr(pval, it);
(gdb) s
asn1_get_enc_ptr (pval=0x7fffffffdf48, it=0x7ffff7dbed80 <X509_ALGOR_it>) at tasn_utl.c:132
132 if (!pval || !*pval)
(gdb) n
134 aux = it->funcs;
(gdb) n
135 if (!aux || !(aux->flags & ASN1_AFLG_ENCODING))
(gdb)
136 return NULL;
(gdb)
138 }
(gdb)
asn1_enc_restore (len=0x7fffffffdeac, out=0x0, pval=0x7fffffffdf48, it=0x7ffff7dbed80 <X509_ALGOR_it>) at tasn_utl.c:189
189 if (!enc || enc->modified)
(gdb) p enc
$29 = (ASN1_ENCODING *) 0x0
(gdb) n
190 return 0;
(gdb) n
198 }
(gdb) n
ASN1_item_ex_i2d (pval=0x7fffffffdf48, out=0x0, it=0x7ffff7dbed80 <X509_ALGOR_it>, tag=-1, aclass=0) at tasn_enc.c:199
199 if (i < 0)
(gdb) n
202 if (i > 0)
(gdb) n
205 seqcontlen = 0;
(gdb) n
207 if (tag == -1) {
(gdb) p tag
$30 = -1
(gdb) n
208 tag = V_ASN1_SEQUENCE;
(gdb) p tag
$31 = -1
(gdb) n
210 aclass = (aclass & ~ASN1_TFLG_TAG_CLASS)
(gdb) n
213 if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))
(gdb) p tag
$32 = 16
(gdb) p aclass
$33 = 0
(gdb) p/x tag
$34 = 0x10
(gdb) p asn1_cb
$35 = (ASN1_aux_cb *) 0x0
(gdb) n
216 for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
(gdb) n
219 seqtt = asn1_do_adb(pval, tt, 1);
(gdb) s
asn1_do_adb (pval=0x7fffffffdf48, tt=0x7ffff7dc58a0 <X509_ALGOR_seq_tt>, nullerr=1) at tasn_utl.c:227
227 if (!(tt->flags & ASN1_TFLG_ADB_MASK))
(gdb) n
228 return tt;
(gdb) n
275 }
(gdb) n
ASN1_item_ex_i2d (pval=0x7fffffffdf48, out=0x0, it=0x7ffff7dbed80 <X509_ALGOR_it>, tag=16, aclass=0) at tasn_enc.c:220
220 if (!seqtt)
(gdb) n
222 pseqval = asn1_get_field_ptr(pval, seqtt);
(gdb) p seqtt
$36 = (const ASN1_TEMPLATE *) 0x7ffff7dc58a0 <X509_ALGOR_seq_tt>
(gdb) n
224 seqcontlen += asn1_template_ex_i2d(pseqval, NULL, seqtt,
(gdb) s
asn1_template_ex_i2d (pval=0x603010, out=0x0, tt=0x7ffff7dc58a0 <X509_ALGOR_seq_tt>, tag=-1, iclass=0) at tasn_enc.c:266
266 flags = tt->flags;
(gdb) n
274 if (flags & ASN1_TFLG_TAG_MASK) {
(gdb) n
282 } else if (tag != -1) {
(gdb)
287 ttag = -1;
(gdb)
288 tclass = 0;
(gdb)
293 iclass &= ~ASN1_TFLG_TAG_CLASS;
(gdb)
301 if ((flags & ASN1_TFLG_NDEF) && (iclass & ASN1_TFLG_NDEF))
(gdb)
304 ndef = 1;
(gdb)
306 if (flags & ASN1_TFLG_SK_MASK) {
(gdb)
375 if (flags & ASN1_TFLG_EXPTAG) {
(gdb)
394 return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item),
(gdb) s
ASN1_item_ex_i2d (pval=0x603010, out=0x0, it=0x7ffff7dbf740 <ASN1_OBJECT_it>, tag=-1, aclass=0) at tasn_enc.c:129
129 const ASN1_TEMPLATE *tt = NULL;
(gdb) n
130 unsigned char *p = NULL;
(gdb)
131 int i, seqcontlen, seqlen, ndef = 1;
(gdb)
134 const ASN1_AUX *aux = it->funcs;
(gdb)
135 ASN1_aux_cb *asn1_cb = 0;
(gdb)
137 if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval)
(gdb)
140 if (aux && aux->asn1_cb)
(gdb)
143 switch (it->itype) {
(gdb)
146 if (it->templates)
(gdb)
149 return asn1_i2d_ex_primitive(pval, out, it, tag, aclass);
(gdb)
254 }
(gdb)
asn1_template_ex_i2d (pval=0x603010, out=0x0, tt=0x7ffff7dc58a0 <X509_ALGOR_seq_tt>, tag=-1, iclass=0) at tasn_enc.c:397
397 }
(gdb)
ASN1_item_ex_i2d (pval=0x7fffffffdf48, out=0x0, it=0x7ffff7dbed80 <X509_ALGOR_it>, tag=16, aclass=0) at tasn_enc.c:216
216 for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
(gdb)
219 seqtt = asn1_do_adb(pval, tt, 1);
(gdb)
220 if (!seqtt)
(gdb)
222 pseqval = asn1_get_field_ptr(pval, seqtt);
(gdb)
224 seqcontlen += asn1_template_ex_i2d(pseqval, NULL, seqtt,
(gdb)
216 for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
(gdb)
228 seqlen = ASN1_object_size(ndef, seqcontlen, tag);
(gdb)
229 if (!out)
(gdb)
230 return seqlen;
(gdb)
254 }
(gdb) p seqlen
$37 = 23
(gdb) n
asn1_item_flags_i2d (val=0x603010, out=0x0, it=0x7ffff7dbed80 <X509_ALGOR_it>, flags=0) at tasn_enc.c:119
119 }
(gdb)
ASN1_item_i2d (val=0x603010, out=0x0, it=0x7ffff7dbed80 <X509_ALGOR_it>) at tasn_enc.c:91
91 }
(gdb)
main () at openssl_x_algor_test.c:19
19 p=buf=malloc(len);
(gdb) n
20 len=i2d_X509_ALGOR(alg,(unsigned char **)&p);
(gdb) n
22 fp=fopen("alg.cer","wb");
(gdb) p p
$38 = 0x6030a7 ""
(gdb) p buf
$39 = 0x603090 "0\025\006\t`\206H\001e\003\004\002\001\004\b12345678"
(gdb) x/23b buf
0x603090: 0x30 0x15 0x06 0x09 0x60 0x86 0x48 0x01
0x603098: 0x65 0x03 0x04 0x02 0x01 0x04 0x08 0x31
0x6030a0: 0x32 0x33 0x34 0x35 0x36 0x37 0x38
(gdb) n
23 fwrite(buf,1,len,fp);
(gdb) n
24 fclose(fp);
(gdb) n
26 fp=fopen("alg.cer","rb");
(gdb) n
27 len=fread(read,1,1024,fp);
(gdb) n
28 fclose(fp);
(gdb) p len
$40 = 23
(gdb) p read
$41 = "0\025\006\t`\206H\001e\003\004\002\001\004\b12345678\000\257O\336\367\377\177\000\000\000\000\000\000\000\000\000\000\030\237\376\367\377\177\000\000\000\220\376\367\377\177\000\000t\267\335\367\377\177\000\000\bMZ\367\377\177\000\000 \264\335\367\377\177\000\000\000\000\000\000\001\000\000\000\236\b\000\000\001\000\000\000\003\000\000\000\000\000\000\000`\342\377\377\377\177\000\000\240\341\377\377\377\177\000\000\001\000\000\000\000\000\000\000\030\237\376\367\377\177\000\000`\345\377\367\377\177\000\000\230\331\377\367\377\177\000\000\257O\336\367\377\177\000\000\000\000\000\000\000\000\000\000\030\237\376\367\377\177\000\000\001\000\000\000\377\177\000\000\000\000\000\000\000\000\000\000\001\000\000\000\377\177\000\000"...
(gdb) x/23b read
0x7fffffffdfe0: 0x30 0x15 0x06 0x09 0x60 0x86 0x48 0x01
0x7fffffffdfe8: 0x65 0x03 0x04 0x02 0x01 0x04 0x08 0x31
0x7fffffffdff0: 0x32 0x33 0x34 0x35 0x36 0x37 0x38
(gdb) n
29 p=read;
(gdb) n
31 d2i_X509_ALGOR(&alg2,(const unsigned char **)&p,len);
(gdb) n
32 if(alg2==NULL)
(gdb) p *alg2
$42 = {algorithm = 0x6030d0, parameter = 0x603120}
(gdb) n
37 alg3=X509_ALGOR_dup(alg);
(gdb) p *alg->algorithm
$43 = {sn = 0x7ffff7b3263f "SHA256", ln = 0x7ffff7b32646 "sha256", nid = 672, length = 9,
data = 0x7ffff7b2e7dc <lvalues+4540> "`\206H\001e\003\004\002\001`\206H\001e\003\004\002\002`\206H\001e\003\004\002\003`\206H\001e\003\004\002\004++\201\004g+g+\001*\206H\316=\001\002\003*\206H\316=\001\002\003\001*\206H\316=\001\002\003\002*\206H\316=\001\002\003\003*\206H\316=\003", flags = 0}
(gdb) p *alg->parameter
$44 = {type = 4, value = {ptr = 0x603050 "\b", boolean = 6303824, asn1_string = 0x603050, object = 0x603050, integer = 0x603050, enumerated = 0x603050, bit_string = 0x603050,
octet_string = 0x603050, printablestring = 0x603050, t61string = 0x603050, ia5string = 0x603050, generalstring = 0x603050, bmpstring = 0x603050, universalstring = 0x603050,
utctime = 0x603050, generalizedtime = 0x603050, visiblestring = 0x603050, utf8string = 0x603050, set = 0x603050, sequence = 0x603050, asn1_value = 0x603050}}
(gdb) n
39 X509_ALGOR_free(alg);
(gdb) p alg3
$45 = (X509_ALGOR *) 0x6031a0
(gdb) p *alg3
$46 = {algorithm = 0x6031c0, parameter = 0x603210}
(gdb) p *alg3->algorithm
$47 = {sn = 0x0, ln = 0x0, nid = 0, length = 9, data = 0x6031f0 "`\206H\001e\003\004\002\001", flags = 9}
(gdb) p *alg3->parameter
$48 = {type = 4, value = {ptr = 0x603230 "\b", boolean = 6304304, asn1_string = 0x603230, object = 0x603230, integer = 0x603230, enumerated = 0x603230, bit_string = 0x603230,
octet_string = 0x603230, printablestring = 0x603230, t61string = 0x603230, ia5string = 0x603230, generalstring = 0x603230, bmpstring = 0x603230, universalstring = 0x603230,
utctime = 0x603230, generalizedtime = 0x603230, visiblestring = 0x603230, utf8string = 0x603230, set = 0x603230, sequence = 0x603230, asn1_value = 0x603230}}
(gdb) n
40 if(alg2)
(gdb) n
41 X509_ALGOR_free(alg2);
(gdb) s
X509_ALGOR_free (a=0x6030b0) at x_algor.c:74
74 IMPLEMENT_ASN1_FUNCTIONS(X509_ALGOR)
(gdb) s
ASN1_item_free (val=0x6030b0, it=0x7ffff7dbed80 <X509_ALGOR_it>) at tasn_fre.c:72
72 asn1_item_combine_free(&val, it, 0);
(gdb) s
asn1_item_combine_free (pval=0x7fffffffdf98, it=0x7ffff7dbed80 <X509_ALGOR_it>, combine=0) at tasn_fre.c:83
83 const ASN1_TEMPLATE *tt = NULL, *seqtt;
(gdb) n
86 const ASN1_AUX *aux = it->funcs;
(gdb) n
89 if (!pval)
(gdb)
91 if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval)
(gdb)
93 if (aux && aux->asn1_cb)
(gdb)
96 asn1_cb = 0;
(gdb)
98 switch (it->itype) {
(gdb)
146 if (asn1_do_lock(pval, -1, it) > 0)
(gdb)
148 if (asn1_cb) {
(gdb)
153 asn1_enc_free(pval, it);
(gdb) s
asn1_enc_free (pval=0x7fffffffdf98, it=0x7ffff7dbed80 <X509_ALGOR_it>) at tasn_utl.c:154
154 enc = asn1_get_enc_ptr(pval, it);
(gdb) n
155 if (enc) {
(gdb)
162 }
(gdb)
asn1_item_combine_free (pval=0x7fffffffdf98, it=0x7ffff7dbed80 <X509_ALGOR_it>, combine=0) at tasn_fre.c:159
159 tt = it->templates + it->tcount - 1;
(gdb)
160 for (i = 0; i < it->tcount; tt--, i++) {
(gdb)
162 seqtt = asn1_do_adb(pval, tt, 0);
(gdb)
163 if (!seqtt)
(gdb)
165 pseqval = asn1_get_field_ptr(pval, seqtt);
(gdb)
166 ASN1_template_free(pseqval, seqtt);
(gdb)
160 for (i = 0; i < it->tcount; tt--, i++) {
(gdb)
162 seqtt = asn1_do_adb(pval, tt, 0);
(gdb)
163 if (!seqtt)
(gdb)
165 pseqval = asn1_get_field_ptr(pval, seqtt);
(gdb)
166 ASN1_template_free(pseqval, seqtt);
(gdb) s
ASN1_template_free (pval=0x6030b0, tt=0x7ffff7dc58a0 <X509_ALGOR_seq_tt>) at tasn_fre.c:181
181 if (tt->flags & ASN1_TFLG_SK_MASK) {
(gdb) n
192 tt->flags & ASN1_TFLG_COMBINE);
(gdb)
191 asn1_item_combine_free(pval, ASN1_ITEM_ptr(tt->item),
(gdb) s
asn1_item_combine_free (pval=0x6030b0, it=0x7ffff7dbf740 <ASN1_OBJECT_it>, combine=0) at tasn_fre.c:83
83 const ASN1_TEMPLATE *tt = NULL, *seqtt;
(gdb) n
86 const ASN1_AUX *aux = it->funcs;
(gdb)
89 if (!pval)
(gdb)
91 if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval)
(gdb)
93 if (aux && aux->asn1_cb)
(gdb)
96 asn1_cb = 0;
(gdb)
98 switch (it->itype) {
(gdb)
101 if (it->templates)
(gdb)
104 ASN1_primitive_free(pval, it);
(gdb)
105 break;
(gdb)
176 }
(gdb)
ASN1_template_free (pval=0x6030b0, tt=0x7ffff7dc58a0 <X509_ALGOR_seq_tt>) at tasn_fre.c:193
193 }
(gdb) n
asn1_item_combine_free (pval=0x7fffffffdf98, it=0x7ffff7dbed80 <X509_ALGOR_it>, combine=0) at tasn_fre.c:160
160 for (i = 0; i < it->tcount; tt--, i++) {
(gdb)
168 if (asn1_cb)
(gdb)
170 if (!combine) {
(gdb)
171 OPENSSL_free(*pval);
(gdb)
172 *pval = NULL;
(gdb)
174 break;
(gdb)
176 }
(gdb)
ASN1_item_free (val=0x0, it=0x7ffff7dbed80 <X509_ALGOR_it>) at tasn_fre.c:73
73 }
(gdb)
main () at openssl_x_algor_test.c:42
42 X509_ALGOR_free(alg3);
(gdb)
43 free(buf);
(gdb) n
44 return 0;
(gdb)
45 }
(gdb)

你可能感兴趣的:(OpenSSL)