📄 openssl.txt
字号:
X509V3_set_ctx_test(ctx)This macro is used to set the 'ctx' structure to a 'test' value: this is toallow the syntax of an extension (or configuration file) to be tested.X509V3_set_ctx_nodb(ctx)This macro is used when no configuration database is present.void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash);This function is used to set the configuration database when it is an LHASHstructure: typically a configuration file.The following functions are used to access a configuration database: theyshould only be used in RAW extensions.char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section);This function returns the value of the parameter "name" in "section", or NULLif there has been an error.void X509V3_string_free(X509V3_CTX *ctx, char *str);This function frees up the string returned by the above function.STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section);This function returns a whole section as a STACK_OF(CONF_VALUE) .void X509V3_section_free( X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section);This function frees up the STACK returned by the above function.Note: it is possible to use the extension code with a custom configurationdatabase. To do this the "db_meth" element of the X509V3_CTX structure shouldbe set to an X509V3_CTX_METHOD structure. This structure contains the followingfunction pointers:char * (*get_string)(void *db, char *section, char *value);STACK_OF(CONF_VALUE) * (*get_section)(void *db, char *section);void (*free_string)(void *db, char * string);void (*free_section)(void *db, STACK_OF(CONF_VALUE) *section);these will be called and passed the 'db' element in the X509V3_CTX structureto access the database. If a given function is not implemented or not requiredit can be set to NULL.5. String helper functions.There are several "i2s" and "s2i" functions that convert structures to andfrom ASCII strings. In all the "i2s" cases the returned string should befreed using Free() after use. Since some of these are part of other extensioncode they may take a 'method' parameter. Unless otherwise stated it can besafely set to NULL.char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *oct);This returns a hex string from an ASN1_OCTET_STRING.char * i2s_ASN1_INTEGER(X509V3_EXT_METHOD *meth, ASN1_INTEGER *aint);char * i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *meth, ASN1_ENUMERATED *aint);These return a string decimal representations of an ASN1_INTEGER and anASN1_ENUMERATED type, respectively.ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str);This converts an ASCII hex string to an ASN1_OCTET_STRING.ASN1_INTEGER * s2i_ASN1_INTEGER(X509V3_EXT_METHOD *meth, char *value);This converts a decimal ASCII string into an ASN1_INTEGER.6. Multi valued extension helper functions.The following functions can be used to manipulate STACKs of CONF_VALUEstructures, as used by multi valued extensions.int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool);This function expects a boolean value in 'value' and sets 'asn1_bool' toit. That is it sets it to 0 for FALSE or 0xff for TRUE. The followingstrings are acceptable: "TRUE", "true", "Y", "y", "YES", "yes", "FALSE""false", "N", "n", "NO" or "no".int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint);This accepts a decimal integer of arbitrary length and sets an ASN1_INTEGER.int X509V3_add_value(const char *name, const char *value, STACK_OF(CONF_VALUE) **extlist);This simply adds a string name and value pair.int X509V3_add_value_uchar(const char *name, const unsigned char *value, STACK_OF(CONF_VALUE) **extlist);The same as above but for an unsigned character value.int X509V3_add_value_bool(const char *name, int asn1_bool, STACK_OF(CONF_VALUE) **extlist);This adds either "TRUE" or "FALSE" depending on the value of 'asn1_bool'int X509V3_add_value_bool_nf(char *name, int asn1_bool, STACK_OF(CONF_VALUE) **extlist);This is the same as above except it adds nothing if asn1_bool is FALSE.int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint, STACK_OF(CONF_VALUE) **extlist);This function adds the value of the ASN1_INTEGER in decimal form.7. Other helper functions.<to be added>ADDING CUSTOM EXTENSIONS.Currently there are three types of supported extensions. String extensions are simple strings where the value is placed directly in theextensions, and the string returned is printed out.Multi value extensions are passed a STACK_OF(CONF_VALUE) name and value pairsor return a STACK_OF(CONF_VALUE).Raw extensions are just passed a BIO or a value and it is the extensionsresponsibility to handle all the necessary printing.There are two ways to add an extension. One is simply as an alias to an alreadyexisting extension. An alias is an extension that is identical in ASN1 structureto an existing extension but has a different OBJECT IDENTIFIER. This can bedone by calling:int X509V3_EXT_add_alias(int nid_to, int nid_from);'nid_to' is the new extension NID and 'nid_from' is the already existingextension NID.Alternatively an extension can be written from scratch. This involves writingthe ASN1 code to encode and decode the extension and functions to print out andgenerate the extension from strings. The relevant functions are then placed ina X509V3_EXT_METHOD structure and int X509V3_EXT_add(X509V3_EXT_METHOD *ext);called.The X509V3_EXT_METHOD structure is described below.strut {int ext_nid;int ext_flags;X509V3_EXT_NEW ext_new;X509V3_EXT_FREE ext_free;X509V3_EXT_D2I d2i;X509V3_EXT_I2D i2d;X509V3_EXT_I2S i2s;X509V3_EXT_S2I s2i;X509V3_EXT_I2V i2v;X509V3_EXT_V2I v2i;X509V3_EXT_R2I r2i;X509V3_EXT_I2R i2r;void *usr_data;};The elements have the following meanings.ext_nid is the NID of the object identifier of the extension.ext_flags is set of flags. Currently the only external flag is X509V3_EXT_MULTILINE which means a multi valued extensions should be printed on separate lines.usr_data is an extension specific pointer to any relevant data. This allows extensions to share identical code but have different uses. An example of this is the bit string extension which uses usr_data to contain a list of the bit names.All the remaining elements are function pointers.ext_new is a pointer to a function that allocates memory for the extension ASN1 structure: for example ASN1_OBJECT_new().ext_free is a pointer to a function that free up memory of the extension ASN1 structure: for example ASN1_OBJECT_free().d2i is the standard ASN1 function that converts a DER buffer into the internal ASN1 structure: for example d2i_ASN1_IA5STRING().i2d is the standard ASN1 function that converts the internal structure into the DER representation: for example i2d_ASN1_IA5STRING().The remaining functions are depend on the type of extension. One i2X andone X2i should be set and the rest set to NULL. The types set do not needto match up, for example the extension could be set using the multi valuedv2i function and printed out using the raw i2r.All functions have the X509V3_EXT_METHOD passed to them in the 'method'parameter and an X509V3_CTX structure. Extension code can then access theparent structure via the 'method' parameter to for example make use of the valueof usr_data. If the code needs to use detail relating to the request it canuse the 'ctx' parameter.A note should be given here about the 'flags' member of the 'ctx' parameter.If it has the value CTX_TEST then the configuration syntax is being checkedand no actual certificate or CRL exists. Therefore any attempt in the configfile to access such information should silently succeed. If the syntax is OKthen it should simply return a (possibly bogus) extension, otherwise itshould return NULL.char *i2s(struct v3_ext_method *method, void *ext);This function takes the internal structure in the ext parameter and returnsa Malloc'ed string representing its value.void * s2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);This function takes the string representation in the ext parameter and returnsan allocated internal structure: ext_free() will be used on this internalstructure after use.i2v and v2i handle a STACK_OF(CONF_VALUE):typedef struct{ char *section; char *name; char *value;} CONF_VALUE;Only the name and value members are currently used.STACK_OF(CONF_VALUE) * i2v(struct v3_ext_method *method, void *ext);This function is passed the internal structure in the ext parameter andreturns a STACK of CONF_VALUE structures. The values of name, value,section and the structure itself will be freed up with Free after use.Several helper functions are available to add values to this STACK.void * v2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx, STACK_OF(CONF_VALUE) *values);This function takes a STACK_OF(CONF_VALUE) structures and should set thevalues of the external structure. This typically uses the name element todetermine which structure element to set and the value element to determinewhat to set it to. Several helper functions are available for thispurpose (see above).int i2r(struct v3_ext_method *method, void *ext, BIO *out, int indent);This function is passed the internal extension structure in the ext parameterand sends out a human readable version of the extension to out. The 'indent'parameter should be noted to determine the necessary amount of indentationneeded on the output.void * r2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);This is just passed the string representation of the extension. It is intendedto be used for more elaborate extensions where the standard single and multivalued options are insufficient. They can use the 'ctx' parameter to parse theconfiguration database themselves. See the context functions section for detailsof how to do this.Note: although this type takes the same parameters as the "r2s" function thereis a subtle difference. Whereas an "r2i" function can access a configurationdatabase an "s2i" function MUST NOT. This is so the internal code can safelyassume that an "s2i" function will work without a configuration database.============================================================================== PKCS#12 Library==============================================================================This section describes the internal PKCS#12 support. There are very fewdifferences between the old external library and the new internal code atpresent. This may well change because the external library will not be updatedmuch in future.This version now includes a couple of high level PKCS#12 functions whichgenerally "do the right thing" and should make it much easier to handle PKCS#12structures.HIGH LEVEL FUNCTIONS.For most applications you only need concern yourself with the high levelfunctions. They can parse and generate simple PKCS#12 files as produced byNetscape and MSIE or indeed any compliant PKCS#12 file containing a singleprivate key and certificate pair.1. Initialisation and cleanup.No special initialisation is needed for the internal PKCS#12 library: the standard SSLeay_add_all_algorithms() is sufficient. If you do not wish toadd all algorithms (you should at least add SHA1 though) then you can manuallyinitialise the PKCS#12 library with:PKCS12_PBE_add();The memory allocated by the PKCS#12 library is freed up when EVP_cleanup() iscalled or it can be directly freed with:EVP_PBE_cleanup();after this call (or EVP_cleanup() ) no more PKCS#12 library functions shouldbe called.2. I/O functions.i2d_PKCS12_bio(bp, p12)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -