1)  X509_TRUST

该结构定义在crypto/x509v3/x509v3.h中,如下:

typedef struct x509_trust_st

{

              int trust;

              int flags;

              int (*check_trust)(struct x509_trust_st *, X509 *, int);

              char *name;

              int arg1;

              void *arg2;

} X509_TRUST;

信任检查数据结构,本结构用来检查数字证书是否是受信任的,其主要的函数实现在x509/x509_trs.c中。其主要项为回调函数check_trust,该函数用于判断证书是受信任的。

Opensslx509_trs.c中维护了两个表,标准表和扩展表,用于判断特定NID的信任情况。如下:

标准表:

static X509_TRUST trstandard[] = {

{X509_TRUST_COMPAT, 0, trust_compat, "compatible", 0, NULL},

{X509_TRUST_SSL_CLIENT, 0, trust_1oidany, "SSL Client", NID_client_auth, NULL},

{X509_TRUST_SSL_SERVER, 0, trust_1oidany, "SSL Server", NID_server_auth, NULL},

{X509_TRUST_EMAIL, 0, trust_1oidany, "S/MIME email", NID_email_protect, NULL},

{X509_TRUST_OBJECT_SIGN, 0, trust_1oidany, "Object Signer", NID_code_sign, NULL},

{X509_TRUST_OCSP_SIGN, 0, trust_1oid, "OCSP responder", NID_OCSP_sign, NULL},

{X509_TRUST_OCSP_REQUEST, 0, trust_1oid, "OCSP request", NID_ad_OCSP, NULL}

};

扩展表:

static STACK_OF(X509_TRUST) *trtable = NULL;

扩展表通过X509_TRUST_add函数来添加。当用户需要对某个NID做判断时,查找这两个表,然后通过check_trust得到结果。

2X509_CERT_AUX

该结构定义在x509.h中,如下:

typedef struct x509_cert_aux_st

{

       STACK_OF(ASN1_OBJECT) *trust;   

       STACK_OF(ASN1_OBJECT) *reject; 

       ASN1_UTF8STRING *alias;

       ASN1_OCTET_STRING *keyid; 

       STACK_OF(X509_ALGOR) *other;

} X509_CERT_AUX;

       该结构是X509的一项,用于决定一个证书是否受信任。trust堆栈中存放了受信任的ASN1_OBJECTreject堆栈中存放了应该拒绝的ASN1_OBJECTtrust堆栈通过X509_add1_trust_object函数来存放一个可信的ASN1_OBJECTreject堆栈通过X509_add1_reject_object来存放一个应该拒绝的ASN1_OBJECT。这两个堆栈在x509/x509_trs.cobj_trust函数中使用。obj_trust函数是默认的check_trust函数。

       上述两个结构在证书验证中的作用如下:

Ø         X509结构中构造X509_CERT_AUX

Ø         调用X509_add1_trust_objectX509_add1_reject_object,将受信任和要拒绝的ASN1_OBJECT添加到X509_CERT_AUX的两个堆栈中;

验证证书时,如果要验证某个ASN1_OBJECT是否受信任,查表找到相应的check_trust,进行计算。如果对应的项在标准表trstandard中,除了X509_TRUST_COMPAT(检查证书用途)都会调用obj_trust函数。