📄 x509.h
字号:
/* crypto/x509/x509.h *//* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written * by Eric Young (eay@cryptsoft.com). * The implementation was written so as to conform with Netscapes SSL. * * This library is free for commercial and non-commercial use as long as * the following conditions are aheared to. The following conditions * apply to all code found in this distribution, be it the RC4, RSA, * lhash, DES, etc., code; not just the SSL code. The SSL documentation * included with this distribution is covered by the same copyright terms * except that the holder is Tim Hudson (tjh@cryptsoft.com). * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. * If this package is used in a product, Eric Young should be given attribution * as the author of the parts of the library used. * This can be in the form of a textual message at program startup or * in documentation (online or textual) provided with the package. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * "This product includes cryptographic software written by * Eric Young (eay@cryptsoft.com)" * The word 'cryptographic' can be left out if the rouines from the library * being used are not cryptographic related :-). * 4. If you include any Windows specific code (or a derivative thereof) from * the apps directory (application code) you must include an acknowledgement: * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * The licence and distribution terms for any publically available version or * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] */#ifndef HEADER_X509_H#define HEADER_X509_H#ifdef __cplusplusextern "C" {#endif#include "stack.h"#include "asn1.h"#ifndef NO_RSA#include "rsa.h"#else#define RSA long#endif#ifndef NO_DSA#include "dsa.h"#else#define DSA long#endif#ifndef NO_DH#include "dh.h"#else#define DH long#endif#include "evp.h"#define X509_FILETYPE_PEM 1#define X509_FILETYPE_ASN1 2#define X509_FILETYPE_DEFAULT 3#define X509v3_KU_DIGITAL_SIGNATURE 0x0080#define X509v3_KU_NON_REPUDIATION 0x0040#define X509v3_KU_KEY_ENCIPHERMENT 0x0020#define X509v3_KU_DATA_ENCIPHERMENT 0x0010#define X509v3_KU_KEY_AGREEMENT 0x0008#define X509v3_KU_KEY_CERT_SIGN 0x0004#define X509v3_KU_CRL_SIGN 0x0002#define X509v3_KU_ENCIPHER_ONLY 0x0001#define X509v3_KU_DECIPHER_ONLY 0x8000#define X509v3_KU_UNDEF 0xfffftypedef struct X509_objects_st { int nid; int (*a2i)(); int (*i2a)(); } X509_OBJECTS;typedef struct X509_algor_st { ASN1_OBJECT *algorithm; ASN1_TYPE *parameter; } X509_ALGOR;typedef struct X509_val_st { ASN1_UTCTIME *notBefore; ASN1_UTCTIME *notAfter; } X509_VAL;typedef struct X509_pubkey_st { X509_ALGOR *algor; ASN1_BIT_STRING *public_key; struct evp_pkey_st /* EVP_PKEY*/ *pkey; } X509_PUBKEY;typedef struct X509_sig_st { X509_ALGOR *algor; ASN1_OCTET_STRING *digest; } X509_SIG;typedef struct X509_name_entry_st { ASN1_OBJECT *object; ASN1_STRING *value; int set; int size; /* temp variable */ } X509_NAME_ENTRY;/* we always keep X509_NAMEs in 2 forms. */typedef struct X509_name_st { STACK *entries; /* of X509_NAME_ENTRY */ int modified; /* true if 'bytes' needs to be built */#ifdef HEADER_BUFFER_H BUF_MEM *bytes;#else char *bytes;#endif unsigned long hash; /* Keep the hash around for lookups */ } X509_NAME;#define X509_EX_V_NETSCAPE_HACK 0x8000#define X509_EX_V_INIT 0x0001typedef struct X509_extension_st { ASN1_OBJECT *object; short critical; short netscape_hack; ASN1_OCTET_STRING *value; long argl; /* used when decoding */ char *argp; /* used when decoding */ void (*ex_free)(); /* clear argp stuff */ } X509_EXTENSION;/* #if 1 */typedef struct x509_extension_method_st { int nid; int data_type; int pack_type; void (*ex_clear)(); int (*ex_get_bool)(); int (*ex_set_bool)(); int (*ex_get_str)(); int (*ex_set_str)(); char *(*ex_get_struct)(); int (*ex_set_struct)(); int (*a2i)(); int (*i2a)(); } X509_EXTENSION_METHOD;/* #endif */typedef struct X509_req_info_st { ASN1_INTEGER *version; X509_NAME *subject; X509_PUBKEY *pubkey; /* d=2 hl=2 l= 0 cons: cont: 00 */ STACK /* X509_ATTRIBUTE */ *attributes; /* [ 0 ] */ int req_kludge; } X509_REQ_INFO;typedef struct X509_req_st { X509_REQ_INFO *req_info; X509_ALGOR *sig_alg; ASN1_BIT_STRING *signature; int references; } X509_REQ;typedef struct x509_cinf_st { ASN1_INTEGER *version; /* [ 0 ] default of v1 */ ASN1_INTEGER *serialNumber; X509_ALGOR *signature; X509_NAME *issuer; X509_VAL *validity; X509_NAME *subject; X509_PUBKEY *key; ASN1_BIT_STRING *issuerUID; /* [ 1 ] optional in v2 */ ASN1_BIT_STRING *subjectUID; /* [ 2 ] optional in v2 */ STACK /* X509_EXTENSION */ *extensions; /* [ 3 ] optional in v3 */ } X509_CINF;typedef struct x509_st { X509_CINF *cert_info; X509_ALGOR *sig_alg; ASN1_BIT_STRING *signature; int valid; int references; char *name; } X509;typedef struct X509_revoked_st { ASN1_INTEGER *serialNumber; ASN1_UTCTIME *revocationDate; STACK /* optional X509_EXTENSION */ *extensions; int sequence; /* load sequence */ } X509_REVOKED;typedef struct X509_crl_info_st { ASN1_INTEGER *version; X509_ALGOR *sig_alg; X509_NAME *issuer; ASN1_UTCTIME *lastUpdate; ASN1_UTCTIME *nextUpdate; STACK /* X509_REVOKED */ *revoked; STACK /* [0] X509_EXTENSION */ *extensions; } X509_CRL_INFO;typedef struct X509_crl_st { /* actual signature */ X509_CRL_INFO *crl; X509_ALGOR *sig_alg; ASN1_BIT_STRING *signature; int references; } X509_CRL;/* a sequence of these are used */typedef struct x509_attributes_st { ASN1_OBJECT *object; int set; /* 1 for a set, 0 for a single item (which is wrong) */ union { char *ptr;/* 1 */ STACK /* ASN1_TYPE */ *set;/* 0 */ ASN1_TYPE *single; } value; } X509_ATTRIBUTE;typedef struct private_key_st { int version; /* The PKCS#8 data types */ X509_ALGOR *enc_algor; ASN1_OCTET_STRING *enc_pkey; /* encrypted pub key */ /* When decrypted, the following will not be NULL */ EVP_PKEY *dec_pkey; /* used to encrypt and decrypt */ int key_length; char *key_data; int key_free; /* true if we should auto free key_data */ /* expanded version of 'enc_algor' */ EVP_CIPHER_INFO cipher; int references; } X509_PKEY;#ifdef HEADER_ENVELOPE_Htypedef struct X509_info_st { X509 *x509; X509_CRL *crl; X509_PKEY *x_pkey; EVP_CIPHER_INFO enc_cipher; int enc_len; char *enc_data; int references; } X509_INFO;#endif/* The next 2 structures and their 8 routines were sent to me by * Pat Richard <patr@x509.com> and are used to manipulate * Netscapes spki strucutres - usefull if you are writing a CA web page */typedef struct Netscape_spkac_st { X509_PUBKEY *pubkey; ASN1_IA5STRING *challenge; /* challenge sent in atlas >= PR2 */ } NETSCAPE_SPKAC;typedef struct Netscape_spki_st { NETSCAPE_SPKAC *spkac; /* signed public key and challenge */ X509_ALGOR *sig_algor; ASN1_BIT_STRING *signature; } NETSCAPE_SPKI;#ifndef HEADER_BN_H#define BIGNUM char#endiftypedef struct CBCParameter_st { unsigned char iv[8]; } CBC_PARAM;#include "x509_vfy.h"#include "pkcs7.h"#ifdef SSLEAY_MACROS#define X509_verify(a,r) ASN1_verify((int (*)())i2d_X509_CINF,a->sig_alg,\ a->signature,(char *)a->cert_info,r)#define X509_REQ_verify(a,r) ASN1_verify((int (*)())i2d_X509_REQ_INFO, \ a->sig_alg,a->signature,(char *)a->req_info,r)#define X509_CRL_verify(a,r) ASN1_verify((int (*)())i2d_X509_CRL_INFO, \ a->sig_alg, a->signature,(char *)a->crl,r)#define X509_sign(x,pkey,md) \ ASN1_sign((int (*)())i2d_X509_CINF, x->cert_info->signature, \ x->sig_alg, x->signature, (char *)x->cert_info,pkey,md)#define X509_REQ_sign(x,pkey,md) \ ASN1_sign((int (*)())i2d_X509_REQ_INFO,x->sig_alg, NULL, \ x->signature, (char *)x->req_info,pkey,md)#define X509_CRL_sign(x,pkey,md) \ ASN1_sign((int (*)())i2d_X509_CRL_INFO,x->crl->sig_alg,x->sig_alg, \ x->signature, (char *)x->crl,pkey,md)#define NETSCAPE_SPKI_sign(x,pkey,md) \ ASN1_sign((int (*)())i2d_NETSCAPE_SPKAC, x->sig_algor,NULL, \ x->signature, (char *)x->spkac,pkey,md)#define X509_dup(x509) (X509 *)ASN1_dup((int (*)())i2d_X509, \ (char *(*)())d2i_X509,(char *)x509)#define X509_ATTRIBUTE_dup(xa) (X509_ATTRIBUTE *)ASN1_dup(\ (int (*)())i2d_X509_ATTRIBUTE, \ (char *(*)())d2i_X509_ATTRIBUTE,(char *)xa)#define X509_EXTENSION_dup(ex) (X509_EXTENSION *)ASN1_dup( \ (int (*)())i2d_X509_EXTENSION, \ (char *(*)())d2i_X509_EXTENSION,(char *)ex)#define d2i_X509_fp(fp,x509) (X509 *)ASN1_d2i_fp((char *(*)())X509_new, \ (char *(*)())d2i_X509, (fp),(unsigned char **)(x509))#define i2d_X509_fp(fp,x509) ASN1_i2d_fp(i2d_X509,fp,(unsigned char *)x509)#define d2i_X509_bio(bp,x509) (X509 *)ASN1_d2i_bio((char *(*)())X509_new, \ (char *(*)())d2i_X509, (bp),(unsigned char **)(x509))#define i2d_X509_bio(bp,x509) ASN1_i2d_bio(i2d_X509,bp,(unsigned char *)x509)#define X509_CRL_dup(crl) (X509_CRL *)ASN1_dup((int (*)())i2d_X509_CRL, \ (char *(*)())d2i_X509_CRL,(char *)crl)#define d2i_X509_CRL_fp(fp,crl) (X509_CRL *)ASN1_d2i_fp((char *(*)()) \ X509_CRL_new,(char *(*)())d2i_X509_CRL, (fp),\ (unsigned char **)(crl))#define i2d_X509_CRL_fp(fp,crl) ASN1_i2d_fp(i2d_X509_CRL,fp,\ (unsigned char *)crl)#define d2i_X509_CRL_bio(bp,crl) (X509_CRL *)ASN1_d2i_bio((char *(*)()) \ X509_CRL_new,(char *(*)())d2i_X509_CRL, (bp),\ (unsigned char **)(crl))#define i2d_X509_CRL_bio(bp,crl) ASN1_i2d_bio(i2d_X509_CRL,bp,\ (unsigned char *)crl)#define PKCS7_dup(p7) (PKCS7 *)ASN1_dup((int (*)())i2d_PKCS7, \ (char *(*)())d2i_PKCS7,(char *)p7)#define d2i_PKCS7_fp(fp,p7) (PKCS7 *)ASN1_d2i_fp((char *(*)()) \ PKCS7_new,(char *(*)())d2i_PKCS7, (fp),\ (unsigned char **)(p7))#define i2d_PKCS7_fp(fp,p7) ASN1_i2d_fp(i2d_PKCS7,fp,\
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -