1 /* $OpenBSD: x509.h,v 1.100 2023/04/25 18:57:57 tb Exp $ */ 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 * All rights reserved. 4 * 5 * This package is an SSL implementation written 6 * by Eric Young (eay@cryptsoft.com). 7 * The implementation was written so as to conform with Netscapes SSL. 8 * 9 * This library is free for commercial and non-commercial use as long as 10 * the following conditions are aheared to. The following conditions 11 * apply to all code found in this distribution, be it the RC4, RSA, 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 * included with this distribution is covered by the same copyright terms 14 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15 * 16 * Copyright remains Eric Young's, and as such any Copyright notices in 17 * the code are not to be removed. 18 * If this package is used in a product, Eric Young should be given attribution 19 * as the author of the parts of the library used. 20 * This can be in the form of a textual message at program startup or 21 * in documentation (online or textual) provided with the package. 22 * 23 * Redistribution and use in source and binary forms, with or without 24 * modification, are permitted provided that the following conditions 25 * are met: 26 * 1. Redistributions of source code must retain the copyright 27 * notice, this list of conditions and the following disclaimer. 28 * 2. Redistributions in binary form must reproduce the above copyright 29 * notice, this list of conditions and the following disclaimer in the 30 * documentation and/or other materials provided with the distribution. 31 * 3. All advertising materials mentioning features or use of this software 32 * must display the following acknowledgement: 33 * "This product includes cryptographic software written by 34 * Eric Young (eay@cryptsoft.com)" 35 * The word 'cryptographic' can be left out if the rouines from the library 36 * being used are not cryptographic related :-). 37 * 4. If you include any Windows specific code (or a derivative thereof) from 38 * the apps directory (application code) you must include an acknowledgement: 39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40 * 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 * SUCH DAMAGE. 52 * 53 * The licence and distribution terms for any publically available version or 54 * derivative of this code cannot be changed. i.e. this code cannot simply be 55 * copied and put under another distribution licence 56 * [including the GNU Public Licence.] 57 */ 58 /* ==================================================================== 59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 60 * ECDH support in OpenSSL originally developed by 61 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. 62 */ 63 64 #ifndef HEADER_X509_H 65 #define HEADER_X509_H 66 67 #include <openssl/opensslconf.h> 68 69 #include <openssl/asn1.h> 70 #ifndef OPENSSL_NO_BIO 71 #include <openssl/bio.h> 72 #endif 73 #ifndef OPENSSL_NO_BUFFER 74 #include <openssl/buffer.h> 75 #endif 76 #ifndef OPENSSL_NO_DH 77 #include <openssl/dh.h> 78 #endif 79 #ifndef OPENSSL_NO_DSA 80 #include <openssl/dsa.h> 81 #endif 82 #ifndef OPENSSL_NO_EC 83 #include <openssl/ec.h> 84 #endif 85 #ifndef OPENSSL_NO_ECDSA 86 #include <openssl/ecdsa.h> 87 #endif 88 #ifndef OPENSSL_NO_ECDH 89 #include <openssl/ecdh.h> 90 #endif 91 #ifndef OPENSSL_NO_EVP 92 #include <openssl/evp.h> 93 #endif 94 #ifndef OPENSSL_NO_RSA 95 #include <openssl/rsa.h> 96 #endif 97 #ifndef OPENSSL_NO_SHA 98 #include <openssl/sha.h> 99 #endif 100 #include <openssl/stack.h> 101 #include <openssl/safestack.h> 102 103 #include <openssl/ossl_typ.h> 104 105 #ifdef __cplusplus 106 extern "C" { 107 #endif 108 109 #define X509_FILETYPE_PEM 1 110 #define X509_FILETYPE_ASN1 2 111 #define X509_FILETYPE_DEFAULT 3 112 113 #define X509v3_KU_DIGITAL_SIGNATURE 0x0080 114 #define X509v3_KU_NON_REPUDIATION 0x0040 115 #define X509v3_KU_KEY_ENCIPHERMENT 0x0020 116 #define X509v3_KU_DATA_ENCIPHERMENT 0x0010 117 #define X509v3_KU_KEY_AGREEMENT 0x0008 118 #define X509v3_KU_KEY_CERT_SIGN 0x0004 119 #define X509v3_KU_CRL_SIGN 0x0002 120 #define X509v3_KU_ENCIPHER_ONLY 0x0001 121 #define X509v3_KU_DECIPHER_ONLY 0x8000 122 #define X509v3_KU_UNDEF 0xffff 123 124 struct X509_algor_st { 125 ASN1_OBJECT *algorithm; 126 ASN1_TYPE *parameter; 127 } /* X509_ALGOR */; 128 129 typedef STACK_OF(X509_ALGOR) X509_ALGORS; 130 131 typedef struct X509_val_st { 132 ASN1_TIME *notBefore; 133 ASN1_TIME *notAfter; 134 } X509_VAL; 135 136 typedef struct X509_sig_st X509_SIG; 137 138 typedef struct X509_name_entry_st X509_NAME_ENTRY; 139 140 DECLARE_STACK_OF(X509_NAME_ENTRY) 141 142 DECLARE_STACK_OF(X509_NAME) 143 144 typedef struct X509_extension_st X509_EXTENSION; 145 146 typedef STACK_OF(X509_EXTENSION) X509_EXTENSIONS; 147 148 DECLARE_STACK_OF(X509_EXTENSION) 149 150 typedef struct x509_attributes_st X509_ATTRIBUTE; 151 152 DECLARE_STACK_OF(X509_ATTRIBUTE) 153 154 typedef struct X509_req_info_st X509_REQ_INFO; 155 156 typedef struct X509_req_st X509_REQ; 157 158 typedef struct x509_cert_aux_st X509_CERT_AUX; 159 160 typedef struct x509_cinf_st X509_CINF; 161 162 DECLARE_STACK_OF(X509) 163 164 /* This is used for a table of trust checking functions */ 165 166 typedef struct x509_trust_st { 167 int trust; 168 int flags; 169 int (*check_trust)(struct x509_trust_st *, X509 *, int); 170 char *name; 171 int arg1; 172 void *arg2; 173 } X509_TRUST; 174 175 DECLARE_STACK_OF(X509_TRUST) 176 177 /* standard trust ids */ 178 179 /* OpenSSL changed this to 0 */ 180 #define X509_TRUST_DEFAULT -1 /* Only valid in purpose settings */ 181 182 #define X509_TRUST_COMPAT 1 183 #define X509_TRUST_SSL_CLIENT 2 184 #define X509_TRUST_SSL_SERVER 3 185 #define X509_TRUST_EMAIL 4 186 #define X509_TRUST_OBJECT_SIGN 5 187 #define X509_TRUST_OCSP_SIGN 6 188 #define X509_TRUST_OCSP_REQUEST 7 189 #define X509_TRUST_TSA 8 190 191 /* Keep these up to date! */ 192 #define X509_TRUST_MIN 1 193 #define X509_TRUST_MAX 8 194 195 196 /* trust_flags values */ 197 #define X509_TRUST_DYNAMIC 1 198 #define X509_TRUST_DYNAMIC_NAME 2 199 200 /* check_trust return codes */ 201 202 #define X509_TRUST_TRUSTED 1 203 #define X509_TRUST_REJECTED 2 204 #define X509_TRUST_UNTRUSTED 3 205 206 /* Flags for X509_print_ex() */ 207 208 #define X509_FLAG_COMPAT 0 209 #define X509_FLAG_NO_HEADER 1L 210 #define X509_FLAG_NO_VERSION (1L << 1) 211 #define X509_FLAG_NO_SERIAL (1L << 2) 212 #define X509_FLAG_NO_SIGNAME (1L << 3) 213 #define X509_FLAG_NO_ISSUER (1L << 4) 214 #define X509_FLAG_NO_VALIDITY (1L << 5) 215 #define X509_FLAG_NO_SUBJECT (1L << 6) 216 #define X509_FLAG_NO_PUBKEY (1L << 7) 217 #define X509_FLAG_NO_EXTENSIONS (1L << 8) 218 #define X509_FLAG_NO_SIGDUMP (1L << 9) 219 #define X509_FLAG_NO_AUX (1L << 10) 220 #define X509_FLAG_NO_ATTRIBUTES (1L << 11) 221 222 /* Flags specific to X509_NAME_print_ex() */ 223 224 /* The field separator information */ 225 226 #define XN_FLAG_SEP_MASK (0xf << 16) 227 228 #define XN_FLAG_COMPAT 0 /* Traditional SSLeay: use old X509_NAME_print */ 229 #define XN_FLAG_SEP_COMMA_PLUS (1 << 16) /* RFC2253 ,+ */ 230 #define XN_FLAG_SEP_CPLUS_SPC (2 << 16) /* ,+ spaced: more readable */ 231 #define XN_FLAG_SEP_SPLUS_SPC (3 << 16) /* ;+ spaced */ 232 #define XN_FLAG_SEP_MULTILINE (4 << 16) /* One line per field */ 233 234 #define XN_FLAG_DN_REV (1 << 20) /* Reverse DN order */ 235 236 /* How the field name is shown */ 237 238 #define XN_FLAG_FN_MASK (0x3 << 21) 239 240 #define XN_FLAG_FN_SN 0 /* Object short name */ 241 #define XN_FLAG_FN_LN (1 << 21) /* Object long name */ 242 #define XN_FLAG_FN_OID (2 << 21) /* Always use OIDs */ 243 #define XN_FLAG_FN_NONE (3 << 21) /* No field names */ 244 245 #define XN_FLAG_SPC_EQ (1 << 23) /* Put spaces round '=' */ 246 247 /* This determines if we dump fields we don't recognise: 248 * RFC2253 requires this. 249 */ 250 251 #define XN_FLAG_DUMP_UNKNOWN_FIELDS (1 << 24) 252 253 #define XN_FLAG_FN_ALIGN (1 << 25) /* Align field names to 20 characters */ 254 255 /* Complete set of RFC2253 flags */ 256 257 #define XN_FLAG_RFC2253 (ASN1_STRFLGS_RFC2253 | \ 258 XN_FLAG_SEP_COMMA_PLUS | \ 259 XN_FLAG_DN_REV | \ 260 XN_FLAG_FN_SN | \ 261 XN_FLAG_DUMP_UNKNOWN_FIELDS) 262 263 /* readable oneline form */ 264 265 #define XN_FLAG_ONELINE (ASN1_STRFLGS_RFC2253 | \ 266 ASN1_STRFLGS_ESC_QUOTE | \ 267 XN_FLAG_SEP_CPLUS_SPC | \ 268 XN_FLAG_SPC_EQ | \ 269 XN_FLAG_FN_SN) 270 271 /* readable multiline form */ 272 273 #define XN_FLAG_MULTILINE (ASN1_STRFLGS_ESC_CTRL | \ 274 ASN1_STRFLGS_ESC_MSB | \ 275 XN_FLAG_SEP_MULTILINE | \ 276 XN_FLAG_SPC_EQ | \ 277 XN_FLAG_FN_LN | \ 278 XN_FLAG_FN_ALIGN) 279 280 DECLARE_STACK_OF(X509_REVOKED) 281 282 typedef struct X509_crl_info_st X509_CRL_INFO; 283 284 DECLARE_STACK_OF(X509_CRL) 285 286 typedef struct private_key_st { 287 int version; 288 /* The PKCS#8 data types */ 289 X509_ALGOR *enc_algor; 290 ASN1_OCTET_STRING *enc_pkey; /* encrypted pub key */ 291 292 /* When decrypted, the following will not be NULL */ 293 EVP_PKEY *dec_pkey; 294 295 /* used to encrypt and decrypt */ 296 int key_length; 297 char *key_data; 298 int key_free; /* true if we should auto free key_data */ 299 300 /* expanded version of 'enc_algor' */ 301 EVP_CIPHER_INFO cipher; 302 303 int references; 304 } X509_PKEY; 305 306 #ifndef OPENSSL_NO_EVP 307 typedef struct X509_info_st { 308 X509 *x509; 309 X509_CRL *crl; 310 X509_PKEY *x_pkey; 311 312 EVP_CIPHER_INFO enc_cipher; 313 int enc_len; 314 char *enc_data; 315 316 int references; 317 } X509_INFO; 318 319 DECLARE_STACK_OF(X509_INFO) 320 #endif 321 322 /* The next 2 structures and their 8 routines were sent to me by 323 * Pat Richard <patr@x509.com> and are used to manipulate 324 * Netscapes spki structures - useful if you are writing a CA web page 325 */ 326 typedef struct Netscape_spkac_st { 327 X509_PUBKEY *pubkey; 328 ASN1_IA5STRING *challenge; /* challenge sent in atlas >= PR2 */ 329 } NETSCAPE_SPKAC; 330 331 typedef struct Netscape_spki_st { 332 NETSCAPE_SPKAC *spkac; /* signed public key and challenge */ 333 X509_ALGOR *sig_algor; 334 ASN1_BIT_STRING *signature; 335 } NETSCAPE_SPKI; 336 337 /* Password based encryption structure */ 338 339 typedef struct PBEPARAM_st { 340 ASN1_OCTET_STRING *salt; 341 ASN1_INTEGER *iter; 342 } PBEPARAM; 343 344 /* Password based encryption V2 structures */ 345 346 typedef struct PBE2PARAM_st { 347 X509_ALGOR *keyfunc; 348 X509_ALGOR *encryption; 349 } PBE2PARAM; 350 351 typedef struct PBKDF2PARAM_st { 352 /* Usually OCTET STRING but could be anything */ 353 ASN1_TYPE *salt; 354 ASN1_INTEGER *iter; 355 ASN1_INTEGER *keylength; 356 X509_ALGOR *prf; 357 } PBKDF2PARAM; 358 359 #ifdef __cplusplus 360 } 361 #endif 362 363 #include <openssl/x509_vfy.h> 364 #include <openssl/pkcs7.h> 365 366 #ifdef __cplusplus 367 extern "C" { 368 #endif 369 370 #define X509_extract_key(x) X509_get_pubkey(x) /*****/ 371 #define X509_REQ_extract_key(a) X509_REQ_get_pubkey(a) 372 #define X509_name_cmp(a,b) X509_NAME_cmp((a),(b)) 373 374 int X509_CRL_up_ref(X509_CRL *x); 375 int X509_CRL_get_signature_nid(const X509_CRL *crl); 376 377 int i2d_re_X509_CRL_tbs(X509_CRL *req, unsigned char **pp); 378 379 const STACK_OF(X509_EXTENSION) *X509_CRL_get0_extensions(const X509_CRL *crl); 380 long X509_CRL_get_version(const X509_CRL *crl); 381 const ASN1_TIME *X509_CRL_get0_lastUpdate(const X509_CRL *crl); 382 const ASN1_TIME *X509_CRL_get0_nextUpdate(const X509_CRL *crl); 383 ASN1_TIME *X509_CRL_get_lastUpdate(X509_CRL *crl); 384 ASN1_TIME *X509_CRL_get_nextUpdate(X509_CRL *crl); 385 X509_NAME *X509_CRL_get_issuer(const X509_CRL *crl); 386 STACK_OF(X509_REVOKED) *X509_CRL_get_REVOKED(X509_CRL *crl); 387 void X509_CRL_get0_signature(const X509_CRL *crl, const ASN1_BIT_STRING **psig, 388 const X509_ALGOR **palg); 389 390 const X509_ALGOR *X509_CRL_get0_tbs_sigalg(const X509_CRL *crl); 391 392 int X509_REQ_get_signature_nid(const X509_REQ *req); 393 394 void X509_REQ_get0_signature(const X509_REQ *req, const ASN1_BIT_STRING **psig, 395 const X509_ALGOR **palg); 396 397 void X509_CRL_set_default_method(const X509_CRL_METHOD *meth); 398 X509_CRL_METHOD *X509_CRL_METHOD_new( 399 int (*crl_init)(X509_CRL *crl), 400 int (*crl_free)(X509_CRL *crl), 401 int (*crl_lookup)(X509_CRL *crl, X509_REVOKED **ret, 402 ASN1_INTEGER *ser, X509_NAME *issuer), 403 int (*crl_verify)(X509_CRL *crl, EVP_PKEY *pk)); 404 void X509_CRL_METHOD_free(X509_CRL_METHOD *m); 405 406 void X509_CRL_set_meth_data(X509_CRL *crl, void *dat); 407 void *X509_CRL_get_meth_data(X509_CRL *crl); 408 409 X509_PUBKEY *X509_get_X509_PUBKEY(const X509 *x); 410 411 const char *X509_verify_cert_error_string(long n); 412 413 #ifndef OPENSSL_NO_EVP 414 int X509_verify(X509 *a, EVP_PKEY *r); 415 416 int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r); 417 int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r); 418 int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r); 419 420 NETSCAPE_SPKI * NETSCAPE_SPKI_b64_decode(const char *str, int len); 421 char * NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *x); 422 EVP_PKEY *NETSCAPE_SPKI_get_pubkey(NETSCAPE_SPKI *x); 423 int NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *x, EVP_PKEY *pkey); 424 425 int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki); 426 427 int X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent); 428 int X509_signature_print(BIO *bp, const X509_ALGOR *alg, 429 const ASN1_STRING *sig); 430 431 int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md); 432 int X509_sign_ctx(X509 *x, EVP_MD_CTX *ctx); 433 int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md); 434 int X509_REQ_sign_ctx(X509_REQ *x, EVP_MD_CTX *ctx); 435 int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md); 436 int X509_CRL_sign_ctx(X509_CRL *x, EVP_MD_CTX *ctx); 437 int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md); 438 439 int X509_pubkey_digest(const X509 *data,const EVP_MD *type, 440 unsigned char *md, unsigned int *len); 441 int X509_digest(const X509 *data,const EVP_MD *type, 442 unsigned char *md, unsigned int *len); 443 int X509_CRL_digest(const X509_CRL *data,const EVP_MD *type, 444 unsigned char *md, unsigned int *len); 445 int X509_REQ_digest(const X509_REQ *data,const EVP_MD *type, 446 unsigned char *md, unsigned int *len); 447 int X509_NAME_digest(const X509_NAME *data,const EVP_MD *type, 448 unsigned char *md, unsigned int *len); 449 #endif 450 451 X509 *d2i_X509_fp(FILE *fp, X509 **x509); 452 int i2d_X509_fp(FILE *fp,X509 *x509); 453 X509_CRL *d2i_X509_CRL_fp(FILE *fp,X509_CRL **crl); 454 int i2d_X509_CRL_fp(FILE *fp,X509_CRL *crl); 455 X509_REQ *d2i_X509_REQ_fp(FILE *fp,X509_REQ **req); 456 int i2d_X509_REQ_fp(FILE *fp,X509_REQ *req); 457 #ifndef OPENSSL_NO_RSA 458 RSA *d2i_RSAPrivateKey_fp(FILE *fp,RSA **rsa); 459 int i2d_RSAPrivateKey_fp(FILE *fp,RSA *rsa); 460 RSA *d2i_RSAPublicKey_fp(FILE *fp,RSA **rsa); 461 int i2d_RSAPublicKey_fp(FILE *fp,RSA *rsa); 462 RSA *d2i_RSA_PUBKEY_fp(FILE *fp,RSA **rsa); 463 int i2d_RSA_PUBKEY_fp(FILE *fp,RSA *rsa); 464 #endif 465 #ifndef OPENSSL_NO_DSA 466 DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa); 467 int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa); 468 DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa); 469 int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa); 470 #endif 471 #ifndef OPENSSL_NO_EC 472 EC_KEY *d2i_EC_PUBKEY_fp(FILE *fp, EC_KEY **eckey); 473 int i2d_EC_PUBKEY_fp(FILE *fp, EC_KEY *eckey); 474 EC_KEY *d2i_ECPrivateKey_fp(FILE *fp, EC_KEY **eckey); 475 int i2d_ECPrivateKey_fp(FILE *fp, EC_KEY *eckey); 476 #endif 477 X509_SIG *d2i_PKCS8_fp(FILE *fp,X509_SIG **p8); 478 int i2d_PKCS8_fp(FILE *fp,X509_SIG *p8); 479 PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, 480 PKCS8_PRIV_KEY_INFO **p8inf); 481 int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,PKCS8_PRIV_KEY_INFO *p8inf); 482 int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key); 483 int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey); 484 EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a); 485 int i2d_PUBKEY_fp(FILE *fp, EVP_PKEY *pkey); 486 EVP_PKEY *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a); 487 488 #ifndef OPENSSL_NO_BIO 489 X509 *d2i_X509_bio(BIO *bp,X509 **x509); 490 int i2d_X509_bio(BIO *bp,X509 *x509); 491 X509_CRL *d2i_X509_CRL_bio(BIO *bp,X509_CRL **crl); 492 int i2d_X509_CRL_bio(BIO *bp,X509_CRL *crl); 493 X509_REQ *d2i_X509_REQ_bio(BIO *bp,X509_REQ **req); 494 int i2d_X509_REQ_bio(BIO *bp,X509_REQ *req); 495 #ifndef OPENSSL_NO_RSA 496 RSA *d2i_RSAPrivateKey_bio(BIO *bp,RSA **rsa); 497 int i2d_RSAPrivateKey_bio(BIO *bp,RSA *rsa); 498 RSA *d2i_RSAPublicKey_bio(BIO *bp,RSA **rsa); 499 int i2d_RSAPublicKey_bio(BIO *bp,RSA *rsa); 500 RSA *d2i_RSA_PUBKEY_bio(BIO *bp,RSA **rsa); 501 int i2d_RSA_PUBKEY_bio(BIO *bp,RSA *rsa); 502 #endif 503 #ifndef OPENSSL_NO_DSA 504 DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa); 505 int i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa); 506 DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa); 507 int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa); 508 #endif 509 #ifndef OPENSSL_NO_EC 510 EC_KEY *d2i_EC_PUBKEY_bio(BIO *bp, EC_KEY **eckey); 511 int i2d_EC_PUBKEY_bio(BIO *bp, EC_KEY *eckey); 512 EC_KEY *d2i_ECPrivateKey_bio(BIO *bp, EC_KEY **eckey); 513 int i2d_ECPrivateKey_bio(BIO *bp, EC_KEY *eckey); 514 #endif 515 X509_SIG *d2i_PKCS8_bio(BIO *bp,X509_SIG **p8); 516 int i2d_PKCS8_bio(BIO *bp,X509_SIG *p8); 517 PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, 518 PKCS8_PRIV_KEY_INFO **p8inf); 519 int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,PKCS8_PRIV_KEY_INFO *p8inf); 520 int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key); 521 int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey); 522 EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a); 523 int i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey); 524 EVP_PKEY *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a); 525 #endif 526 527 X509 *X509_dup(X509 *x509); 528 X509_ATTRIBUTE *X509_ATTRIBUTE_dup(X509_ATTRIBUTE *xa); 529 X509_EXTENSION *X509_EXTENSION_dup(X509_EXTENSION *ex); 530 X509_CRL *X509_CRL_dup(X509_CRL *crl); 531 X509_REQ *X509_REQ_dup(X509_REQ *req); 532 X509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn); 533 int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval); 534 void X509_ALGOR_get0(const ASN1_OBJECT **paobj, int *pptype, const void **ppval, 535 const X509_ALGOR *algor); 536 void X509_ALGOR_set_md(X509_ALGOR *alg, const EVP_MD *md); 537 int X509_ALGOR_cmp(const X509_ALGOR *a, const X509_ALGOR *b); 538 539 X509_NAME *X509_NAME_dup(X509_NAME *xn); 540 int X509_NAME_get0_der(X509_NAME *nm, const unsigned char **pder, size_t *pderlen); 541 X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne); 542 543 int X509_cmp_time(const ASN1_TIME *s, time_t *t); 544 int X509_cmp_current_time(const ASN1_TIME *s); 545 ASN1_TIME * X509_time_adj(ASN1_TIME *s, long adj, time_t *t); 546 ASN1_TIME * X509_time_adj_ex(ASN1_TIME *s, 547 int offset_day, long offset_sec, time_t *t); 548 ASN1_TIME * X509_gmtime_adj(ASN1_TIME *s, long adj); 549 550 const char * X509_get_default_cert_area(void ); 551 const char * X509_get_default_cert_dir(void ); 552 const char * X509_get_default_cert_file(void ); 553 const char * X509_get_default_cert_dir_env(void ); 554 const char * X509_get_default_cert_file_env(void ); 555 const char * X509_get_default_private_dir(void ); 556 557 X509_REQ * X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md); 558 X509 * X509_REQ_to_X509(X509_REQ *r, int days,EVP_PKEY *pkey); 559 560 X509_ALGOR *X509_ALGOR_new(void); 561 void X509_ALGOR_free(X509_ALGOR *a); 562 X509_ALGOR *d2i_X509_ALGOR(X509_ALGOR **a, const unsigned char **in, long len); 563 int i2d_X509_ALGOR(X509_ALGOR *a, unsigned char **out); 564 extern const ASN1_ITEM X509_ALGOR_it; 565 X509_ALGORS *d2i_X509_ALGORS(X509_ALGORS **a, const unsigned char **in, long len); 566 int i2d_X509_ALGORS(X509_ALGORS *a, unsigned char **out); 567 extern const ASN1_ITEM X509_ALGORS_it; 568 X509_VAL *X509_VAL_new(void); 569 void X509_VAL_free(X509_VAL *a); 570 X509_VAL *d2i_X509_VAL(X509_VAL **a, const unsigned char **in, long len); 571 int i2d_X509_VAL(X509_VAL *a, unsigned char **out); 572 extern const ASN1_ITEM X509_VAL_it; 573 574 X509_PUBKEY *X509_PUBKEY_new(void); 575 void X509_PUBKEY_free(X509_PUBKEY *a); 576 X509_PUBKEY *d2i_X509_PUBKEY(X509_PUBKEY **a, const unsigned char **in, long len); 577 int i2d_X509_PUBKEY(X509_PUBKEY *a, unsigned char **out); 578 extern const ASN1_ITEM X509_PUBKEY_it; 579 580 int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey); 581 EVP_PKEY * X509_PUBKEY_get(X509_PUBKEY *key); 582 EVP_PKEY * X509_PUBKEY_get0(X509_PUBKEY *key); 583 int X509_get_pubkey_parameters(EVP_PKEY *pkey, 584 STACK_OF(X509) *chain); 585 int i2d_PUBKEY(EVP_PKEY *a,unsigned char **pp); 586 EVP_PKEY * d2i_PUBKEY(EVP_PKEY **a,const unsigned char **pp, 587 long length); 588 #ifndef OPENSSL_NO_RSA 589 int i2d_RSA_PUBKEY(RSA *a,unsigned char **pp); 590 RSA * d2i_RSA_PUBKEY(RSA **a,const unsigned char **pp, 591 long length); 592 #endif 593 #ifndef OPENSSL_NO_DSA 594 int i2d_DSA_PUBKEY(DSA *a,unsigned char **pp); 595 DSA * d2i_DSA_PUBKEY(DSA **a,const unsigned char **pp, 596 long length); 597 #endif 598 #ifndef OPENSSL_NO_EC 599 int i2d_EC_PUBKEY(EC_KEY *a, unsigned char **pp); 600 EC_KEY *d2i_EC_PUBKEY(EC_KEY **a, const unsigned char **pp, 601 long length); 602 #endif 603 604 X509_SIG *X509_SIG_new(void); 605 void X509_SIG_free(X509_SIG *a); 606 X509_SIG *d2i_X509_SIG(X509_SIG **a, const unsigned char **in, long len); 607 int i2d_X509_SIG(X509_SIG *a, unsigned char **out); 608 extern const ASN1_ITEM X509_SIG_it; 609 void X509_SIG_get0(const X509_SIG *sig, const X509_ALGOR **palg, 610 const ASN1_OCTET_STRING **pdigest); 611 void X509_SIG_getm(X509_SIG *sig, X509_ALGOR **palg, 612 ASN1_OCTET_STRING **pdigest); 613 614 X509_REQ_INFO *X509_REQ_INFO_new(void); 615 void X509_REQ_INFO_free(X509_REQ_INFO *a); 616 X509_REQ_INFO *d2i_X509_REQ_INFO(X509_REQ_INFO **a, const unsigned char **in, long len); 617 int i2d_X509_REQ_INFO(X509_REQ_INFO *a, unsigned char **out); 618 extern const ASN1_ITEM X509_REQ_INFO_it; 619 X509_REQ *X509_REQ_new(void); 620 void X509_REQ_free(X509_REQ *a); 621 X509_REQ *d2i_X509_REQ(X509_REQ **a, const unsigned char **in, long len); 622 int i2d_X509_REQ(X509_REQ *a, unsigned char **out); 623 extern const ASN1_ITEM X509_REQ_it; 624 625 X509_ATTRIBUTE *X509_ATTRIBUTE_new(void); 626 void X509_ATTRIBUTE_free(X509_ATTRIBUTE *a); 627 X509_ATTRIBUTE *d2i_X509_ATTRIBUTE(X509_ATTRIBUTE **a, const unsigned char **in, long len); 628 int i2d_X509_ATTRIBUTE(X509_ATTRIBUTE *a, unsigned char **out); 629 extern const ASN1_ITEM X509_ATTRIBUTE_it; 630 X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value); 631 632 X509_EXTENSION *X509_EXTENSION_new(void); 633 void X509_EXTENSION_free(X509_EXTENSION *a); 634 X509_EXTENSION *d2i_X509_EXTENSION(X509_EXTENSION **a, const unsigned char **in, long len); 635 int i2d_X509_EXTENSION(X509_EXTENSION *a, unsigned char **out); 636 extern const ASN1_ITEM X509_EXTENSION_it; 637 X509_EXTENSIONS *d2i_X509_EXTENSIONS(X509_EXTENSIONS **a, const unsigned char **in, long len); 638 int i2d_X509_EXTENSIONS(X509_EXTENSIONS *a, unsigned char **out); 639 extern const ASN1_ITEM X509_EXTENSIONS_it; 640 641 X509_NAME_ENTRY *X509_NAME_ENTRY_new(void); 642 void X509_NAME_ENTRY_free(X509_NAME_ENTRY *a); 643 X509_NAME_ENTRY *d2i_X509_NAME_ENTRY(X509_NAME_ENTRY **a, const unsigned char **in, long len); 644 int i2d_X509_NAME_ENTRY(X509_NAME_ENTRY *a, unsigned char **out); 645 extern const ASN1_ITEM X509_NAME_ENTRY_it; 646 647 X509_NAME *X509_NAME_new(void); 648 void X509_NAME_free(X509_NAME *a); 649 X509_NAME *d2i_X509_NAME(X509_NAME **a, const unsigned char **in, long len); 650 int i2d_X509_NAME(X509_NAME *a, unsigned char **out); 651 extern const ASN1_ITEM X509_NAME_it; 652 653 int X509_NAME_set(X509_NAME **xn, X509_NAME *name); 654 655 X509_CINF *X509_CINF_new(void); 656 void X509_CINF_free(X509_CINF *a); 657 X509_CINF *d2i_X509_CINF(X509_CINF **a, const unsigned char **in, long len); 658 int i2d_X509_CINF(X509_CINF *a, unsigned char **out); 659 extern const ASN1_ITEM X509_CINF_it; 660 661 X509 *X509_new(void); 662 void X509_free(X509 *a); 663 X509 *d2i_X509(X509 **a, const unsigned char **in, long len); 664 int i2d_X509(X509 *a, unsigned char **out); 665 extern const ASN1_ITEM X509_it; 666 X509_CERT_AUX *X509_CERT_AUX_new(void); 667 void X509_CERT_AUX_free(X509_CERT_AUX *a); 668 X509_CERT_AUX *d2i_X509_CERT_AUX(X509_CERT_AUX **a, const unsigned char **in, long len); 669 int i2d_X509_CERT_AUX(X509_CERT_AUX *a, unsigned char **out); 670 extern const ASN1_ITEM X509_CERT_AUX_it; 671 672 int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, 673 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); 674 int X509_set_ex_data(X509 *r, int idx, void *arg); 675 void *X509_get_ex_data(X509 *r, int idx); 676 int i2d_X509_AUX(X509 *a,unsigned char **pp); 677 X509 * d2i_X509_AUX(X509 **a,const unsigned char **pp,long length); 678 679 int i2d_re_X509_tbs(X509 *x, unsigned char **pp); 680 681 void X509_get0_signature(const ASN1_BIT_STRING **psig, 682 const X509_ALGOR **palg, const X509 *x); 683 int X509_get_signature_nid(const X509 *x); 684 685 int X509_alias_set1(X509 *x, const unsigned char *name, int len); 686 int X509_keyid_set1(X509 *x, const unsigned char *id, int len); 687 unsigned char *X509_alias_get0(X509 *x, int *len); 688 unsigned char *X509_keyid_get0(X509 *x, int *len); 689 int (*X509_TRUST_set_default(int (*trust)(int , X509 *, int)))(int, X509 *, int); 690 int X509_TRUST_set(int *t, int trust); 691 int X509_add1_trust_object(X509 *x, const ASN1_OBJECT *obj); 692 int X509_add1_reject_object(X509 *x, const ASN1_OBJECT *obj); 693 void X509_trust_clear(X509 *x); 694 void X509_reject_clear(X509 *x); 695 696 X509_REVOKED *X509_REVOKED_new(void); 697 void X509_REVOKED_free(X509_REVOKED *a); 698 X509_REVOKED *X509_REVOKED_dup(X509_REVOKED *a); 699 X509_REVOKED *d2i_X509_REVOKED(X509_REVOKED **a, const unsigned char **in, long len); 700 int i2d_X509_REVOKED(X509_REVOKED *a, unsigned char **out); 701 extern const ASN1_ITEM X509_REVOKED_it; 702 703 X509_CRL_INFO *X509_CRL_INFO_new(void); 704 void X509_CRL_INFO_free(X509_CRL_INFO *a); 705 X509_CRL_INFO *d2i_X509_CRL_INFO(X509_CRL_INFO **a, const unsigned char **in, long len); 706 int i2d_X509_CRL_INFO(X509_CRL_INFO *a, unsigned char **out); 707 extern const ASN1_ITEM X509_CRL_INFO_it; 708 709 X509_CRL *X509_CRL_new(void); 710 void X509_CRL_free(X509_CRL *a); 711 X509_CRL *d2i_X509_CRL(X509_CRL **a, const unsigned char **in, long len); 712 int i2d_X509_CRL(X509_CRL *a, unsigned char **out); 713 extern const ASN1_ITEM X509_CRL_it; 714 715 int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev); 716 int X509_CRL_get0_by_serial(X509_CRL *crl, 717 X509_REVOKED **ret, ASN1_INTEGER *serial); 718 int X509_CRL_get0_by_cert(X509_CRL *crl, X509_REVOKED **ret, X509 *x); 719 720 X509_PKEY * X509_PKEY_new(void ); 721 void X509_PKEY_free(X509_PKEY *a); 722 723 NETSCAPE_SPKI *NETSCAPE_SPKI_new(void); 724 void NETSCAPE_SPKI_free(NETSCAPE_SPKI *a); 725 NETSCAPE_SPKI *d2i_NETSCAPE_SPKI(NETSCAPE_SPKI **a, const unsigned char **in, long len); 726 int i2d_NETSCAPE_SPKI(NETSCAPE_SPKI *a, unsigned char **out); 727 extern const ASN1_ITEM NETSCAPE_SPKI_it; 728 NETSCAPE_SPKAC *NETSCAPE_SPKAC_new(void); 729 void NETSCAPE_SPKAC_free(NETSCAPE_SPKAC *a); 730 NETSCAPE_SPKAC *d2i_NETSCAPE_SPKAC(NETSCAPE_SPKAC **a, const unsigned char **in, long len); 731 int i2d_NETSCAPE_SPKAC(NETSCAPE_SPKAC *a, unsigned char **out); 732 extern const ASN1_ITEM NETSCAPE_SPKAC_it; 733 734 #ifndef OPENSSL_NO_EVP 735 X509_INFO * X509_INFO_new(void); 736 void X509_INFO_free(X509_INFO *a); 737 char * X509_NAME_oneline(const X509_NAME *a, char *buf, int size); 738 739 int ASN1_item_digest(const ASN1_ITEM *it,const EVP_MD *type,void *data, 740 unsigned char *md,unsigned int *len); 741 742 int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *algor1, 743 ASN1_BIT_STRING *signature,void *data,EVP_PKEY *pkey); 744 745 int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, 746 ASN1_BIT_STRING *signature, 747 void *data, EVP_PKEY *pkey, const EVP_MD *type); 748 int ASN1_item_sign_ctx(const ASN1_ITEM *it, 749 X509_ALGOR *algor1, X509_ALGOR *algor2, 750 ASN1_BIT_STRING *signature, void *asn, EVP_MD_CTX *ctx); 751 #endif 752 753 const STACK_OF(X509_EXTENSION) *X509_get0_extensions(const X509 *x); 754 void X509_get0_uids(const X509 *x, const ASN1_BIT_STRING **piuid, 755 const ASN1_BIT_STRING **psuid); 756 const X509_ALGOR *X509_get0_tbs_sigalg(const X509 *x); 757 int X509_set_version(X509 *x, long version); 758 long X509_get_version(const X509 *x); 759 int X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial); 760 ASN1_INTEGER * X509_get_serialNumber(X509 *x); 761 const ASN1_INTEGER *X509_get0_serialNumber(const X509 *x); 762 int X509_set_issuer_name(X509 *x, X509_NAME *name); 763 X509_NAME * X509_get_issuer_name(const X509 *a); 764 int X509_set_subject_name(X509 *x, X509_NAME *name); 765 X509_NAME * X509_get_subject_name(const X509 *a); 766 int X509_set_notBefore(X509 *x, const ASN1_TIME *tm); 767 int X509_set1_notBefore(X509 *x, const ASN1_TIME *tm); 768 int X509_set_notAfter(X509 *x, const ASN1_TIME *tm); 769 int X509_set1_notAfter(X509 *x, const ASN1_TIME *tm); 770 const ASN1_TIME *X509_get0_notBefore(const X509 *x); 771 ASN1_TIME *X509_getm_notBefore(const X509 *x); 772 const ASN1_TIME *X509_get0_notAfter(const X509 *x); 773 ASN1_TIME *X509_getm_notAfter(const X509 *x); 774 int X509_set_pubkey(X509 *x, EVP_PKEY *pkey); 775 EVP_PKEY * X509_get_pubkey(X509 *x); 776 EVP_PKEY * X509_get0_pubkey(const X509 *x); 777 ASN1_BIT_STRING *X509_get0_pubkey_bitstr(const X509 *x); 778 int X509_certificate_type(const X509 *x, const EVP_PKEY *pubkey); 779 int X509_get_signature_type(const X509 *x); 780 781 #define X509_get_notBefore X509_getm_notBefore 782 #define X509_get_notAfter X509_getm_notAfter 783 784 int X509_REQ_set_version(X509_REQ *x,long version); 785 long X509_REQ_get_version(const X509_REQ *x); 786 int X509_REQ_set_subject_name(X509_REQ *req, X509_NAME *name); 787 X509_NAME *X509_REQ_get_subject_name(const X509_REQ *x); 788 int X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey); 789 EVP_PKEY * X509_REQ_get_pubkey(X509_REQ *req); 790 int i2d_re_X509_REQ_tbs(X509_REQ *req, unsigned char **pp); 791 EVP_PKEY * X509_REQ_get0_pubkey(X509_REQ *req); 792 int X509_REQ_extension_nid(int nid); 793 int * X509_REQ_get_extension_nids(void); 794 void X509_REQ_set_extension_nids(int *nids); 795 STACK_OF(X509_EXTENSION) *X509_REQ_get_extensions(X509_REQ *req); 796 int X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts, 797 int nid); 798 int X509_REQ_add_extensions(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts); 799 int X509_REQ_get_attr_count(const X509_REQ *req); 800 int X509_REQ_get_attr_by_NID(const X509_REQ *req, int nid, 801 int lastpos); 802 int X509_REQ_get_attr_by_OBJ(const X509_REQ *req, const ASN1_OBJECT *obj, 803 int lastpos); 804 X509_ATTRIBUTE *X509_REQ_get_attr(const X509_REQ *req, int loc); 805 X509_ATTRIBUTE *X509_REQ_delete_attr(X509_REQ *req, int loc); 806 int X509_REQ_add1_attr(X509_REQ *req, X509_ATTRIBUTE *attr); 807 int X509_REQ_add1_attr_by_OBJ(X509_REQ *req, 808 const ASN1_OBJECT *obj, int type, 809 const unsigned char *bytes, int len); 810 int X509_REQ_add1_attr_by_NID(X509_REQ *req, 811 int nid, int type, 812 const unsigned char *bytes, int len); 813 int X509_REQ_add1_attr_by_txt(X509_REQ *req, 814 const char *attrname, int type, 815 const unsigned char *bytes, int len); 816 817 int X509_CRL_set_version(X509_CRL *x, long version); 818 int X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name); 819 int X509_CRL_set_lastUpdate(X509_CRL *x, const ASN1_TIME *tm); 820 int X509_CRL_set1_lastUpdate(X509_CRL *x, const ASN1_TIME *tm); 821 int X509_CRL_set_nextUpdate(X509_CRL *x, const ASN1_TIME *tm); 822 int X509_CRL_set1_nextUpdate(X509_CRL *x, const ASN1_TIME *tm); 823 int X509_CRL_sort(X509_CRL *crl); 824 825 const STACK_OF(X509_EXTENSION) *X509_REVOKED_get0_extensions(const X509_REVOKED *x); 826 const ASN1_TIME *X509_REVOKED_get0_revocationDate(const X509_REVOKED *x); 827 const ASN1_INTEGER *X509_REVOKED_get0_serialNumber(const X509_REVOKED *x); 828 int X509_REVOKED_set_revocationDate(X509_REVOKED *r, ASN1_TIME *tm); 829 int X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial); 830 831 int X509_REQ_check_private_key(X509_REQ *x509,EVP_PKEY *pkey); 832 833 int X509_check_private_key(const X509 *x509, const EVP_PKEY *pkey); 834 835 int X509_issuer_and_serial_cmp(const X509 *a, const X509 *b); 836 unsigned long X509_issuer_and_serial_hash(X509 *a); 837 838 int X509_issuer_name_cmp(const X509 *a, const X509 *b); 839 unsigned long X509_issuer_name_hash(X509 *a); 840 841 int X509_subject_name_cmp(const X509 *a, const X509 *b); 842 unsigned long X509_subject_name_hash(X509 *x); 843 844 #ifndef OPENSSL_NO_MD5 845 unsigned long X509_issuer_name_hash_old(X509 *a); 846 unsigned long X509_subject_name_hash_old(X509 *x); 847 #endif 848 849 int X509_cmp(const X509 *a, const X509 *b); 850 int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b); 851 unsigned long X509_NAME_hash(X509_NAME *x); 852 unsigned long X509_NAME_hash_old(X509_NAME *x); 853 854 int X509_CRL_cmp(const X509_CRL *a, const X509_CRL *b); 855 int X509_CRL_match(const X509_CRL *a, const X509_CRL *b); 856 int X509_print_ex_fp(FILE *bp,X509 *x, unsigned long nmflag, unsigned long cflag); 857 int X509_print_fp(FILE *bp,X509 *x); 858 int X509_CRL_print_fp(FILE *bp,X509_CRL *x); 859 int X509_REQ_print_fp(FILE *bp,X509_REQ *req); 860 int X509_NAME_print_ex_fp(FILE *fp, const X509_NAME *nm, int indent, 861 unsigned long flags); 862 863 #ifndef OPENSSL_NO_BIO 864 int X509_NAME_print(BIO *bp, const X509_NAME *name, int obase); 865 int X509_NAME_print_ex(BIO *out, const X509_NAME *nm, int indent, 866 unsigned long flags); 867 int X509_print_ex(BIO *bp,X509 *x, unsigned long nmflag, unsigned long cflag); 868 int X509_print(BIO *bp,X509 *x); 869 int X509_ocspid_print(BIO *bp,X509 *x); 870 int X509_CERT_AUX_print(BIO *bp,X509_CERT_AUX *x, int indent); 871 int X509_CRL_print(BIO *bp,X509_CRL *x); 872 int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflag, unsigned long cflag); 873 int X509_REQ_print(BIO *bp,X509_REQ *req); 874 #endif 875 876 int X509_NAME_entry_count(const X509_NAME *name); 877 int X509_NAME_get_text_by_NID(X509_NAME *name, int nid, 878 char *buf,int len); 879 int X509_NAME_get_text_by_OBJ(X509_NAME *name, 880 const ASN1_OBJECT *obj, char *buf,int len); 881 882 /* NOTE: you should be passing -1, not 0 as lastpos. The functions that use 883 * lastpos, search after that position on. */ 884 int X509_NAME_get_index_by_NID(const X509_NAME *name, int nid, 885 int lastpos); 886 int X509_NAME_get_index_by_OBJ(const X509_NAME *name, 887 const ASN1_OBJECT *obj, int lastpos); 888 X509_NAME_ENTRY *X509_NAME_get_entry(const X509_NAME *name, int loc); 889 X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc); 890 int X509_NAME_add_entry(X509_NAME *name, const X509_NAME_ENTRY *ne, 891 int loc, int set); 892 int X509_NAME_add_entry_by_OBJ(X509_NAME *name, const ASN1_OBJECT *obj, 893 int type, const unsigned char *bytes, int len, int loc, int set); 894 int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type, 895 const unsigned char *bytes, int len, int loc, int set); 896 X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne, 897 const char *field, int type, const unsigned char *bytes, int len); 898 X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid, 899 int type, const unsigned char *bytes, int len); 900 int X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type, 901 const unsigned char *bytes, int len, int loc, int set); 902 X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne, 903 const ASN1_OBJECT *obj, int type, 904 const unsigned char *bytes, int len); 905 int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne, 906 const ASN1_OBJECT *obj); 907 int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type, 908 const unsigned char *bytes, int len); 909 ASN1_OBJECT * X509_NAME_ENTRY_get_object(const X509_NAME_ENTRY *ne); 910 ASN1_STRING * X509_NAME_ENTRY_get_data(const X509_NAME_ENTRY *ne); 911 int X509_NAME_ENTRY_set(const X509_NAME_ENTRY *ne); 912 913 int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x); 914 int X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x, 915 int nid, int lastpos); 916 int X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *x, 917 const ASN1_OBJECT *obj, int lastpos); 918 int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *x, 919 int crit, int lastpos); 920 X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, int loc); 921 X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc); 922 STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x, 923 X509_EXTENSION *ex, int loc); 924 925 int X509_get_ext_count(const X509 *x); 926 int X509_get_ext_by_NID(const X509 *x, int nid, int lastpos); 927 int X509_get_ext_by_OBJ(const X509 *x, const ASN1_OBJECT *obj, 928 int lastpos); 929 int X509_get_ext_by_critical(const X509 *x, int crit, int lastpos); 930 X509_EXTENSION *X509_get_ext(const X509 *x, int loc); 931 X509_EXTENSION *X509_delete_ext(X509 *x, int loc); 932 int X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc); 933 void * X509_get_ext_d2i(const X509 *x, int nid, int *crit, int *idx); 934 int X509_add1_ext_i2d(X509 *x, int nid, void *value, int crit, 935 unsigned long flags); 936 937 int X509_CRL_get_ext_count(const X509_CRL *x); 938 int X509_CRL_get_ext_by_NID(const X509_CRL *x, int nid, 939 int lastpos); 940 int X509_CRL_get_ext_by_OBJ(const X509_CRL *x, 941 const ASN1_OBJECT *obj, int lastpos); 942 int X509_CRL_get_ext_by_critical(const X509_CRL *x, int crit, 943 int lastpos); 944 X509_EXTENSION *X509_CRL_get_ext(const X509_CRL *x, int loc); 945 X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc); 946 int X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc); 947 void * X509_CRL_get_ext_d2i(const X509_CRL *x, int nid, int *crit, 948 int *idx); 949 int X509_CRL_add1_ext_i2d(X509_CRL *x, int nid, void *value, 950 int crit, unsigned long flags); 951 952 int X509_REVOKED_get_ext_count(const X509_REVOKED *x); 953 int X509_REVOKED_get_ext_by_NID(const X509_REVOKED *x, int nid, 954 int lastpos); 955 int X509_REVOKED_get_ext_by_OBJ(const X509_REVOKED *x, 956 const ASN1_OBJECT *obj, int lastpos); 957 int X509_REVOKED_get_ext_by_critical(const X509_REVOKED *x, 958 int crit, int lastpos); 959 X509_EXTENSION *X509_REVOKED_get_ext(const X509_REVOKED *x, int loc); 960 X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc); 961 int X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, 962 int loc); 963 void * X509_REVOKED_get_ext_d2i(const X509_REVOKED *x, int nid, 964 int *crit, int *idx); 965 int X509_REVOKED_add1_ext_i2d(X509_REVOKED *x, int nid, void *value, 966 int crit, unsigned long flags); 967 968 X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex, 969 int nid, int crit, ASN1_OCTET_STRING *data); 970 X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex, 971 const ASN1_OBJECT *obj, int crit, ASN1_OCTET_STRING *data); 972 int X509_EXTENSION_set_object(X509_EXTENSION *ex, 973 const ASN1_OBJECT *obj); 974 int X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit); 975 int X509_EXTENSION_set_data(X509_EXTENSION *ex, 976 ASN1_OCTET_STRING *data); 977 ASN1_OBJECT * X509_EXTENSION_get_object(X509_EXTENSION *ex); 978 ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ne); 979 int X509_EXTENSION_get_critical(const X509_EXTENSION *ex); 980 981 int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x); 982 int X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x, int nid, 983 int lastpos); 984 int X509at_get_attr_by_OBJ(const STACK_OF(X509_ATTRIBUTE) *sk, 985 const ASN1_OBJECT *obj, int lastpos); 986 X509_ATTRIBUTE *X509at_get_attr(const STACK_OF(X509_ATTRIBUTE) *x, int loc); 987 X509_ATTRIBUTE *X509at_delete_attr(STACK_OF(X509_ATTRIBUTE) *x, int loc); 988 STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x, 989 X509_ATTRIBUTE *attr); 990 STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_OBJ(STACK_OF(X509_ATTRIBUTE) **x, 991 const ASN1_OBJECT *obj, int type, 992 const unsigned char *bytes, int len); 993 STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_NID(STACK_OF(X509_ATTRIBUTE) **x, 994 int nid, int type, 995 const unsigned char *bytes, int len); 996 STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_txt(STACK_OF(X509_ATTRIBUTE) **x, 997 const char *attrname, int type, 998 const unsigned char *bytes, int len); 999 void *X509at_get0_data_by_OBJ(STACK_OF(X509_ATTRIBUTE) *x, 1000 const ASN1_OBJECT *obj, int lastpos, int type); 1001 X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid, 1002 int atrtype, const void *data, int len); 1003 X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **attr, 1004 const ASN1_OBJECT *obj, int atrtype, const void *data, int len); 1005 X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_txt(X509_ATTRIBUTE **attr, 1006 const char *atrname, int type, const unsigned char *bytes, int len); 1007 int X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr, const ASN1_OBJECT *obj); 1008 int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, const void *data, int len); 1009 void *X509_ATTRIBUTE_get0_data(X509_ATTRIBUTE *attr, int idx, 1010 int atrtype, void *data); 1011 int X509_ATTRIBUTE_count(const X509_ATTRIBUTE *attr); 1012 ASN1_OBJECT *X509_ATTRIBUTE_get0_object(X509_ATTRIBUTE *attr); 1013 ASN1_TYPE *X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr, int idx); 1014 1015 int EVP_PKEY_get_attr_count(const EVP_PKEY *key); 1016 int EVP_PKEY_get_attr_by_NID(const EVP_PKEY *key, int nid, 1017 int lastpos); 1018 int EVP_PKEY_get_attr_by_OBJ(const EVP_PKEY *key, const ASN1_OBJECT *obj, 1019 int lastpos); 1020 X509_ATTRIBUTE *EVP_PKEY_get_attr(const EVP_PKEY *key, int loc); 1021 X509_ATTRIBUTE *EVP_PKEY_delete_attr(EVP_PKEY *key, int loc); 1022 int EVP_PKEY_add1_attr(EVP_PKEY *key, X509_ATTRIBUTE *attr); 1023 int EVP_PKEY_add1_attr_by_OBJ(EVP_PKEY *key, 1024 const ASN1_OBJECT *obj, int type, 1025 const unsigned char *bytes, int len); 1026 int EVP_PKEY_add1_attr_by_NID(EVP_PKEY *key, 1027 int nid, int type, 1028 const unsigned char *bytes, int len); 1029 int EVP_PKEY_add1_attr_by_txt(EVP_PKEY *key, 1030 const char *attrname, int type, 1031 const unsigned char *bytes, int len); 1032 1033 int X509_verify_cert(X509_STORE_CTX *ctx); 1034 1035 /* lookup a cert from a X509 STACK */ 1036 X509 *X509_find_by_issuer_and_serial(STACK_OF(X509) *sk,X509_NAME *name, 1037 ASN1_INTEGER *serial); 1038 X509 *X509_find_by_subject(STACK_OF(X509) *sk,X509_NAME *name); 1039 1040 PBEPARAM *PBEPARAM_new(void); 1041 void PBEPARAM_free(PBEPARAM *a); 1042 PBEPARAM *d2i_PBEPARAM(PBEPARAM **a, const unsigned char **in, long len); 1043 int i2d_PBEPARAM(PBEPARAM *a, unsigned char **out); 1044 extern const ASN1_ITEM PBEPARAM_it; 1045 PBE2PARAM *PBE2PARAM_new(void); 1046 void PBE2PARAM_free(PBE2PARAM *a); 1047 PBE2PARAM *d2i_PBE2PARAM(PBE2PARAM **a, const unsigned char **in, long len); 1048 int i2d_PBE2PARAM(PBE2PARAM *a, unsigned char **out); 1049 extern const ASN1_ITEM PBE2PARAM_it; 1050 PBKDF2PARAM *PBKDF2PARAM_new(void); 1051 void PBKDF2PARAM_free(PBKDF2PARAM *a); 1052 PBKDF2PARAM *d2i_PBKDF2PARAM(PBKDF2PARAM **a, const unsigned char **in, long len); 1053 int i2d_PBKDF2PARAM(PBKDF2PARAM *a, unsigned char **out); 1054 extern const ASN1_ITEM PBKDF2PARAM_it; 1055 1056 int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter, 1057 const unsigned char *salt, int saltlen); 1058 1059 X509_ALGOR *PKCS5_pbe_set(int alg, int iter, 1060 const unsigned char *salt, int saltlen); 1061 X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter, 1062 unsigned char *salt, int saltlen); 1063 X509_ALGOR *PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter, 1064 unsigned char *salt, int saltlen, 1065 unsigned char *aiv, int prf_nid); 1066 1067 X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen, 1068 int prf_nid, int keylen); 1069 1070 /* PKCS#8 utilities */ 1071 1072 PKCS8_PRIV_KEY_INFO *PKCS8_PRIV_KEY_INFO_new(void); 1073 void PKCS8_PRIV_KEY_INFO_free(PKCS8_PRIV_KEY_INFO *a); 1074 PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO **a, const unsigned char **in, long len); 1075 int i2d_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO *a, unsigned char **out); 1076 extern const ASN1_ITEM PKCS8_PRIV_KEY_INFO_it; 1077 1078 EVP_PKEY *EVP_PKCS82PKEY(const PKCS8_PRIV_KEY_INFO *p8); 1079 PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey); 1080 1081 int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj, int version, 1082 int ptype, void *pval, unsigned char *penc, int penclen); 1083 int PKCS8_pkey_get0(const ASN1_OBJECT **ppkalg, const unsigned char **pk, 1084 int *ppklen, const X509_ALGOR **pa, const PKCS8_PRIV_KEY_INFO *p8); 1085 1086 const STACK_OF(X509_ATTRIBUTE) *PKCS8_pkey_get0_attrs(const PKCS8_PRIV_KEY_INFO *p8); 1087 int PKCS8_pkey_add1_attr_by_NID(PKCS8_PRIV_KEY_INFO *p8, int nid, int type, 1088 const unsigned char *bytes, int len); 1089 1090 int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj, 1091 int ptype, void *pval, 1092 unsigned char *penc, int penclen); 1093 int X509_PUBKEY_get0_param(ASN1_OBJECT **ppkalg, 1094 const unsigned char **pk, int *ppklen, 1095 X509_ALGOR **pa, 1096 X509_PUBKEY *pub); 1097 1098 int X509_check_trust(X509 *x, int id, int flags); 1099 int X509_TRUST_get_count(void); 1100 X509_TRUST * X509_TRUST_get0(int idx); 1101 int X509_TRUST_get_by_id(int id); 1102 int X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int), 1103 const char *name, int arg1, void *arg2); 1104 void X509_TRUST_cleanup(void); 1105 int X509_TRUST_get_flags(const X509_TRUST *xp); 1106 char *X509_TRUST_get0_name(const X509_TRUST *xp); 1107 int X509_TRUST_get_trust(const X509_TRUST *xp); 1108 1109 int X509_up_ref(X509 *x); 1110 STACK_OF(X509) *X509_chain_up_ref(STACK_OF(X509) *chain); 1111 1112 void ERR_load_X509_strings(void); 1113 1114 /* Error codes for the X509 functions. */ 1115 1116 /* Function codes. */ 1117 #define X509_F_ADD_CERT_DIR 100 1118 #define X509_F_BY_FILE_CTRL 101 1119 #define X509_F_CHECK_POLICY 145 1120 #define X509_F_DIR_CTRL 102 1121 #define X509_F_GET_CERT_BY_SUBJECT 103 1122 #define X509_F_NETSCAPE_SPKI_B64_DECODE 129 1123 #define X509_F_NETSCAPE_SPKI_B64_ENCODE 130 1124 #define X509_F_X509AT_ADD1_ATTR 135 1125 #define X509_F_X509V3_ADD_EXT 104 1126 #define X509_F_X509_ATTRIBUTE_CREATE_BY_NID 136 1127 #define X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ 137 1128 #define X509_F_X509_ATTRIBUTE_CREATE_BY_TXT 140 1129 #define X509_F_X509_ATTRIBUTE_GET0_DATA 139 1130 #define X509_F_X509_ATTRIBUTE_SET1_DATA 138 1131 #define X509_F_X509_CHECK_PRIVATE_KEY 128 1132 #define X509_F_X509_CRL_PRINT_FP 147 1133 #define X509_F_X509_EXTENSION_CREATE_BY_NID 108 1134 #define X509_F_X509_EXTENSION_CREATE_BY_OBJ 109 1135 #define X509_F_X509_GET_PUBKEY_PARAMETERS 110 1136 #define X509_F_X509_LOAD_CERT_CRL_FILE 132 1137 #define X509_F_X509_LOAD_CERT_FILE 111 1138 #define X509_F_X509_LOAD_CRL_FILE 112 1139 #define X509_F_X509_NAME_ADD_ENTRY 113 1140 #define X509_F_X509_NAME_ENTRY_CREATE_BY_NID 114 1141 #define X509_F_X509_NAME_ENTRY_CREATE_BY_TXT 131 1142 #define X509_F_X509_NAME_ENTRY_SET_OBJECT 115 1143 #define X509_F_X509_NAME_ONELINE 116 1144 #define X509_F_X509_NAME_PRINT 117 1145 #define X509_F_X509_PRINT_EX_FP 118 1146 #define X509_F_X509_PUBKEY_GET 119 1147 #define X509_F_X509_PUBKEY_SET 120 1148 #define X509_F_X509_REQ_CHECK_PRIVATE_KEY 144 1149 #define X509_F_X509_REQ_PRINT_EX 121 1150 #define X509_F_X509_REQ_PRINT_FP 122 1151 #define X509_F_X509_REQ_TO_X509 123 1152 #define X509_F_X509_STORE_ADD_CERT 124 1153 #define X509_F_X509_STORE_ADD_CRL 125 1154 #define X509_F_X509_STORE_CTX_GET1_ISSUER 146 1155 #define X509_F_X509_STORE_CTX_INIT 143 1156 #define X509_F_X509_STORE_CTX_NEW 142 1157 #define X509_F_X509_STORE_CTX_PURPOSE_INHERIT 134 1158 #define X509_F_X509_TO_X509_REQ 126 1159 #define X509_F_X509_TRUST_ADD 133 1160 #define X509_F_X509_TRUST_SET 141 1161 #define X509_F_X509_VERIFY_CERT 127 1162 1163 /* Reason codes. */ 1164 #define X509_R_BAD_X509_FILETYPE 100 1165 #define X509_R_BASE64_DECODE_ERROR 118 1166 #define X509_R_CANT_CHECK_DH_KEY 114 1167 #define X509_R_CERT_ALREADY_IN_HASH_TABLE 101 1168 #define X509_R_ERR_ASN1_LIB 102 1169 #define X509_R_INVALID_DIRECTORY 113 1170 #define X509_R_INVALID_FIELD_NAME 119 1171 #define X509_R_INVALID_TRUST 123 1172 #define X509_R_INVALID_VERSION 137 1173 #define X509_R_KEY_TYPE_MISMATCH 115 1174 #define X509_R_KEY_VALUES_MISMATCH 116 1175 #define X509_R_LOADING_CERT_DIR 103 1176 #define X509_R_LOADING_DEFAULTS 104 1177 #define X509_R_METHOD_NOT_SUPPORTED 124 1178 #define X509_R_NO_CERTIFICATE_OR_CRL_FOUND 136 1179 #define X509_R_NO_CERT_SET_FOR_US_TO_VERIFY 105 1180 #define X509_R_PUBLIC_KEY_DECODE_ERROR 125 1181 #define X509_R_PUBLIC_KEY_ENCODE_ERROR 126 1182 #define X509_R_SHOULD_RETRY 106 1183 #define X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN 107 1184 #define X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY 108 1185 #define X509_R_UNKNOWN_KEY_TYPE 117 1186 #define X509_R_UNKNOWN_NID 109 1187 #define X509_R_UNKNOWN_PURPOSE_ID 121 1188 #define X509_R_UNKNOWN_TRUST_ID 120 1189 #define X509_R_UNSUPPORTED_ALGORITHM 111 1190 #define X509_R_WRONG_LOOKUP_TYPE 112 1191 #define X509_R_WRONG_TYPE 122 1192 1193 #ifdef __cplusplus 1194 } 1195 #endif 1196 #endif 1197