Eneboo - Documentación para desarrolladores
|
00001 /* crypto/pem/pem.h */ 00002 /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 00003 * All rights reserved. 00004 * 00005 * This package is an SSL implementation written 00006 * by Eric Young (eay@cryptsoft.com). 00007 * The implementation was written so as to conform with Netscapes SSL. 00008 * 00009 * This library is free for commercial and non-commercial use as long as 00010 * the following conditions are aheared to. The following conditions 00011 * apply to all code found in this distribution, be it the RC4, RSA, 00012 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 00013 * included with this distribution is covered by the same copyright terms 00014 * except that the holder is Tim Hudson (tjh@cryptsoft.com). 00015 * 00016 * Copyright remains Eric Young's, and as such any Copyright notices in 00017 * the code are not to be removed. 00018 * If this package is used in a product, Eric Young should be given attribution 00019 * as the author of the parts of the library used. 00020 * This can be in the form of a textual message at program startup or 00021 * in documentation (online or textual) provided with the package. 00022 * 00023 * Redistribution and use in source and binary forms, with or without 00024 * modification, are permitted provided that the following conditions 00025 * are met: 00026 * 1. Redistributions of source code must retain the copyright 00027 * notice, this list of conditions and the following disclaimer. 00028 * 2. Redistributions in binary form must reproduce the above copyright 00029 * notice, this list of conditions and the following disclaimer in the 00030 * documentation and/or other materials provided with the distribution. 00031 * 3. All advertising materials mentioning features or use of this software 00032 * must display the following acknowledgement: 00033 * "This product includes cryptographic software written by 00034 * Eric Young (eay@cryptsoft.com)" 00035 * The word 'cryptographic' can be left out if the rouines from the library 00036 * being used are not cryptographic related :-). 00037 * 4. If you include any Windows specific code (or a derivative thereof) from 00038 * the apps directory (application code) you must include an acknowledgement: 00039 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 00040 * 00041 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 00042 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00043 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00044 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 00045 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00046 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00047 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00048 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00049 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00050 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00051 * SUCH DAMAGE. 00052 * 00053 * The licence and distribution terms for any publically available version or 00054 * derivative of this code cannot be changed. i.e. this code cannot simply be 00055 * copied and put under another distribution licence 00056 * [including the GNU Public Licence.] 00057 */ 00058 00059 #ifndef HEADER_PEM_H 00060 #define HEADER_PEM_H 00061 00062 #include <openssl/e_os2.h> 00063 #ifndef OPENSSL_NO_BIO 00064 #include <openssl/bio.h> 00065 #endif 00066 #ifndef OPENSSL_NO_STACK 00067 #include <openssl/stack.h> 00068 #endif 00069 #include <openssl/evp.h> 00070 #include <openssl/x509.h> 00071 #include <openssl/pem2.h> 00072 00073 #ifdef __cplusplus 00074 extern "C" { 00075 #endif 00076 00077 #define PEM_BUFSIZE 1024 00078 00079 #define PEM_OBJ_UNDEF 0 00080 #define PEM_OBJ_X509 1 00081 #define PEM_OBJ_X509_REQ 2 00082 #define PEM_OBJ_CRL 3 00083 #define PEM_OBJ_SSL_SESSION 4 00084 #define PEM_OBJ_PRIV_KEY 10 00085 #define PEM_OBJ_PRIV_RSA 11 00086 #define PEM_OBJ_PRIV_DSA 12 00087 #define PEM_OBJ_PRIV_DH 13 00088 #define PEM_OBJ_PUB_RSA 14 00089 #define PEM_OBJ_PUB_DSA 15 00090 #define PEM_OBJ_PUB_DH 16 00091 #define PEM_OBJ_DHPARAMS 17 00092 #define PEM_OBJ_DSAPARAMS 18 00093 #define PEM_OBJ_PRIV_RSA_PUBLIC 19 00094 #define PEM_OBJ_PRIV_ECDSA 20 00095 #define PEM_OBJ_PUB_ECDSA 21 00096 #define PEM_OBJ_ECPARAMETERS 22 00097 00098 #define PEM_ERROR 30 00099 #define PEM_DEK_DES_CBC 40 00100 #define PEM_DEK_IDEA_CBC 45 00101 #define PEM_DEK_DES_EDE 50 00102 #define PEM_DEK_DES_ECB 60 00103 #define PEM_DEK_RSA 70 00104 #define PEM_DEK_RSA_MD2 80 00105 #define PEM_DEK_RSA_MD5 90 00106 00107 #define PEM_MD_MD2 NID_md2 00108 #define PEM_MD_MD5 NID_md5 00109 #define PEM_MD_SHA NID_sha 00110 #define PEM_MD_MD2_RSA NID_md2WithRSAEncryption 00111 #define PEM_MD_MD5_RSA NID_md5WithRSAEncryption 00112 #define PEM_MD_SHA_RSA NID_sha1WithRSAEncryption 00113 00114 #define PEM_STRING_X509_OLD "X509 CERTIFICATE" 00115 #define PEM_STRING_X509 "CERTIFICATE" 00116 #define PEM_STRING_X509_PAIR "CERTIFICATE PAIR" 00117 #define PEM_STRING_X509_TRUSTED "TRUSTED CERTIFICATE" 00118 #define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST" 00119 #define PEM_STRING_X509_REQ "CERTIFICATE REQUEST" 00120 #define PEM_STRING_X509_CRL "X509 CRL" 00121 #define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY" 00122 #define PEM_STRING_PUBLIC "PUBLIC KEY" 00123 #define PEM_STRING_RSA "RSA PRIVATE KEY" 00124 #define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY" 00125 #define PEM_STRING_DSA "DSA PRIVATE KEY" 00126 #define PEM_STRING_DSA_PUBLIC "DSA PUBLIC KEY" 00127 #define PEM_STRING_PKCS7 "PKCS7" 00128 #define PEM_STRING_PKCS7_SIGNED "PKCS #7 SIGNED DATA" 00129 #define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY" 00130 #define PEM_STRING_PKCS8INF "PRIVATE KEY" 00131 #define PEM_STRING_DHPARAMS "DH PARAMETERS" 00132 #define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS" 00133 #define PEM_STRING_DSAPARAMS "DSA PARAMETERS" 00134 #define PEM_STRING_ECDSA_PUBLIC "ECDSA PUBLIC KEY" 00135 #define PEM_STRING_ECPARAMETERS "EC PARAMETERS" 00136 #define PEM_STRING_ECPRIVATEKEY "EC PRIVATE KEY" 00137 #define PEM_STRING_CMS "CMS" 00138 00139 /* Note that this structure is initialised by PEM_SealInit and cleaned up 00140 by PEM_SealFinal (at least for now) */ 00141 typedef struct PEM_Encode_Seal_st 00142 { 00143 EVP_ENCODE_CTX encode; 00144 EVP_MD_CTX md; 00145 EVP_CIPHER_CTX cipher; 00146 } PEM_ENCODE_SEAL_CTX; 00147 00148 /* enc_type is one off */ 00149 #define PEM_TYPE_ENCRYPTED 10 00150 #define PEM_TYPE_MIC_ONLY 20 00151 #define PEM_TYPE_MIC_CLEAR 30 00152 #define PEM_TYPE_CLEAR 40 00153 00154 typedef struct pem_recip_st 00155 { 00156 char *name; 00157 X509_NAME *dn; 00158 00159 int cipher; 00160 int key_enc; 00161 /* char iv[8]; unused and wrong size */ 00162 } PEM_USER; 00163 00164 typedef struct pem_ctx_st 00165 { 00166 int type; /* what type of object */ 00167 00168 struct { 00169 int version; 00170 int mode; 00171 } proc_type; 00172 00173 char *domain; 00174 00175 struct { 00176 int cipher; 00177 /* unused, and wrong size 00178 unsigned char iv[8]; */ 00179 } DEK_info; 00180 00181 PEM_USER *originator; 00182 00183 int num_recipient; 00184 PEM_USER **recipient; 00185 00186 #ifndef OPENSSL_NO_STACK 00187 STACK *x509_chain; /* certificate chain */ 00188 #else 00189 char *x509_chain; /* certificate chain */ 00190 #endif 00191 EVP_MD *md; /* signature type */ 00192 00193 int md_enc; /* is the md encrypted or not? */ 00194 int md_len; /* length of md_data */ 00195 char *md_data; /* message digest, could be pkey encrypted */ 00196 00197 EVP_CIPHER *dec; /* date encryption cipher */ 00198 int key_len; /* key length */ 00199 unsigned char *key; /* key */ 00200 /* unused, and wrong size 00201 unsigned char iv[8]; */ 00202 00203 00204 int data_enc; /* is the data encrypted */ 00205 int data_len; 00206 unsigned char *data; 00207 } PEM_CTX; 00208 00209 /* These macros make the PEM_read/PEM_write functions easier to maintain and 00210 * write. Now they are all implemented with either: 00211 * IMPLEMENT_PEM_rw(...) or IMPLEMENT_PEM_rw_cb(...) 00212 */ 00213 00214 #ifdef OPENSSL_NO_FP_API 00215 00216 #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) 00217 #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) 00218 #define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) 00219 #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) 00220 #define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) 00221 00222 #else 00223 00224 #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \ 00225 type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\ 00226 { \ 00227 return (type*)PEM_ASN1_read(CHECKED_D2I_OF(type, d2i_##asn1), \ 00228 str, fp, \ 00229 CHECKED_PPTR_OF(type, x), \ 00230 cb, u); \ 00231 } 00232 00233 #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \ 00234 int PEM_write_##name(FILE *fp, type *x) \ 00235 { \ 00236 return PEM_ASN1_write(CHECKED_I2D_OF(type, i2d_##asn1), \ 00237 str, fp, \ 00238 CHECKED_PTR_OF(type, x), \ 00239 NULL, NULL, 0, NULL, NULL); \ 00240 } 00241 00242 #define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) \ 00243 int PEM_write_##name(FILE *fp, const type *x) \ 00244 { \ 00245 return PEM_ASN1_write(CHECKED_I2D_OF(const type, i2d_##asn1), \ 00246 str, fp, \ 00247 CHECKED_PTR_OF(const type, x), \ 00248 NULL, NULL, 0, NULL, NULL); \ 00249 } 00250 00251 #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \ 00252 int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ 00253 unsigned char *kstr, int klen, pem_password_cb *cb, \ 00254 void *u) \ 00255 { \ 00256 return PEM_ASN1_write(CHECKED_I2D_OF(type, i2d_##asn1), \ 00257 str, fp, \ 00258 CHECKED_PTR_OF(type, x), \ 00259 enc, kstr, klen, cb, u); \ 00260 } 00261 00262 #define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \ 00263 int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ 00264 unsigned char *kstr, int klen, pem_password_cb *cb, \ 00265 void *u) \ 00266 { \ 00267 return PEM_ASN1_write(CHECKED_I2D_OF(const type, i2d_##asn1), \ 00268 str, fp, \ 00269 CHECKED_PTR_OF(const type, x), \ 00270 enc, kstr, klen, cb, u); \ 00271 } 00272 00273 #endif 00274 00275 #define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ 00276 type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\ 00277 { \ 00278 return (type*)PEM_ASN1_read_bio(CHECKED_D2I_OF(type, d2i_##asn1), \ 00279 str, bp, \ 00280 CHECKED_PPTR_OF(type, x), \ 00281 cb, u); \ 00282 } 00283 00284 #define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ 00285 int PEM_write_bio_##name(BIO *bp, type *x) \ 00286 { \ 00287 return PEM_ASN1_write_bio(CHECKED_I2D_OF(type, i2d_##asn1), \ 00288 str, bp, \ 00289 CHECKED_PTR_OF(type, x), \ 00290 NULL, NULL, 0, NULL, NULL); \ 00291 } 00292 00293 #define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \ 00294 int PEM_write_bio_##name(BIO *bp, const type *x) \ 00295 { \ 00296 return PEM_ASN1_write_bio(CHECKED_I2D_OF(const type, i2d_##asn1), \ 00297 str, bp, \ 00298 CHECKED_PTR_OF(const type, x), \ 00299 NULL, NULL, 0, NULL, NULL); \ 00300 } 00301 00302 #define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ 00303 int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ 00304 unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \ 00305 { \ 00306 return PEM_ASN1_write_bio(CHECKED_I2D_OF(type, i2d_##asn1), \ 00307 str, bp, \ 00308 CHECKED_PTR_OF(type, x), \ 00309 enc, kstr, klen, cb, u); \ 00310 } 00311 00312 #define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \ 00313 int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ 00314 unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \ 00315 { \ 00316 return PEM_ASN1_write_bio(CHECKED_I2D_OF(const type, i2d_##asn1), \ 00317 str, bp, \ 00318 CHECKED_PTR_OF(const type, x), \ 00319 enc, kstr, klen, cb, u); \ 00320 } 00321 00322 #define IMPLEMENT_PEM_write(name, type, str, asn1) \ 00323 IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ 00324 IMPLEMENT_PEM_write_fp(name, type, str, asn1) 00325 00326 #define IMPLEMENT_PEM_write_const(name, type, str, asn1) \ 00327 IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \ 00328 IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) 00329 00330 #define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \ 00331 IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ 00332 IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) 00333 00334 #define IMPLEMENT_PEM_write_cb_const(name, type, str, asn1) \ 00335 IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \ 00336 IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) 00337 00338 #define IMPLEMENT_PEM_read(name, type, str, asn1) \ 00339 IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ 00340 IMPLEMENT_PEM_read_fp(name, type, str, asn1) 00341 00342 #define IMPLEMENT_PEM_rw(name, type, str, asn1) \ 00343 IMPLEMENT_PEM_read(name, type, str, asn1) \ 00344 IMPLEMENT_PEM_write(name, type, str, asn1) 00345 00346 #define IMPLEMENT_PEM_rw_const(name, type, str, asn1) \ 00347 IMPLEMENT_PEM_read(name, type, str, asn1) \ 00348 IMPLEMENT_PEM_write_const(name, type, str, asn1) 00349 00350 #define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \ 00351 IMPLEMENT_PEM_read(name, type, str, asn1) \ 00352 IMPLEMENT_PEM_write_cb(name, type, str, asn1) 00353 00354 /* These are the same except they are for the declarations */ 00355 00356 #if defined(OPENSSL_SYS_WIN16) || defined(OPENSSL_NO_FP_API) 00357 00358 #define DECLARE_PEM_read_fp(name, type) 00359 #define DECLARE_PEM_write_fp(name, type) 00360 #define DECLARE_PEM_write_fp_const(name, type) 00361 #define DECLARE_PEM_write_cb_fp(name, type) 00362 00363 #else 00364 00365 #define DECLARE_PEM_read_fp(name, type) \ 00366 type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u); 00367 00368 #define DECLARE_PEM_write_fp(name, type) \ 00369 int PEM_write_##name(FILE *fp, type *x); 00370 00371 #define DECLARE_PEM_write_fp_const(name, type) \ 00372 int PEM_write_##name(FILE *fp, const type *x); 00373 00374 #define DECLARE_PEM_write_cb_fp(name, type) \ 00375 int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ 00376 unsigned char *kstr, int klen, pem_password_cb *cb, void *u); 00377 00378 #endif 00379 00380 #ifndef OPENSSL_NO_BIO 00381 #define DECLARE_PEM_read_bio(name, type) \ 00382 type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u); 00383 00384 #define DECLARE_PEM_write_bio(name, type) \ 00385 int PEM_write_bio_##name(BIO *bp, type *x); 00386 00387 #define DECLARE_PEM_write_bio_const(name, type) \ 00388 int PEM_write_bio_##name(BIO *bp, const type *x); 00389 00390 #define DECLARE_PEM_write_cb_bio(name, type) \ 00391 int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ 00392 unsigned char *kstr, int klen, pem_password_cb *cb, void *u); 00393 00394 #else 00395 00396 #define DECLARE_PEM_read_bio(name, type) 00397 #define DECLARE_PEM_write_bio(name, type) 00398 #define DECLARE_PEM_write_bio_const(name, type) 00399 #define DECLARE_PEM_write_cb_bio(name, type) 00400 00401 #endif 00402 00403 #define DECLARE_PEM_write(name, type) \ 00404 DECLARE_PEM_write_bio(name, type) \ 00405 DECLARE_PEM_write_fp(name, type) 00406 00407 #define DECLARE_PEM_write_const(name, type) \ 00408 DECLARE_PEM_write_bio_const(name, type) \ 00409 DECLARE_PEM_write_fp_const(name, type) 00410 00411 #define DECLARE_PEM_write_cb(name, type) \ 00412 DECLARE_PEM_write_cb_bio(name, type) \ 00413 DECLARE_PEM_write_cb_fp(name, type) 00414 00415 #define DECLARE_PEM_read(name, type) \ 00416 DECLARE_PEM_read_bio(name, type) \ 00417 DECLARE_PEM_read_fp(name, type) 00418 00419 #define DECLARE_PEM_rw(name, type) \ 00420 DECLARE_PEM_read(name, type) \ 00421 DECLARE_PEM_write(name, type) 00422 00423 #define DECLARE_PEM_rw_const(name, type) \ 00424 DECLARE_PEM_read(name, type) \ 00425 DECLARE_PEM_write_const(name, type) 00426 00427 #define DECLARE_PEM_rw_cb(name, type) \ 00428 DECLARE_PEM_read(name, type) \ 00429 DECLARE_PEM_write_cb(name, type) 00430 00431 #ifdef SSLEAY_MACROS 00432 00433 #define PEM_write_SSL_SESSION(fp,x) \ 00434 PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \ 00435 PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL) 00436 #define PEM_write_X509(fp,x) \ 00437 PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \ 00438 (char *)x, NULL,NULL,0,NULL,NULL) 00439 #define PEM_write_X509_REQ(fp,x) PEM_ASN1_write( \ 00440 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,(char *)x, \ 00441 NULL,NULL,0,NULL,NULL) 00442 #define PEM_write_X509_CRL(fp,x) \ 00443 PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, \ 00444 fp,(char *)x, NULL,NULL,0,NULL,NULL) 00445 #define PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \ 00446 PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,\ 00447 (char *)x,enc,kstr,klen,cb,u) 00448 #define PEM_write_RSAPublicKey(fp,x) \ 00449 PEM_ASN1_write((int (*)())i2d_RSAPublicKey,\ 00450 PEM_STRING_RSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL,NULL) 00451 #define PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \ 00452 PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,\ 00453 (char *)x,enc,kstr,klen,cb,u) 00454 #define PEM_write_PrivateKey(bp,x,enc,kstr,klen,cb,u) \ 00455 PEM_ASN1_write((int (*)())i2d_PrivateKey,\ 00456 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\ 00457 bp,(char *)x,enc,kstr,klen,cb,u) 00458 #define PEM_write_PKCS7(fp,x) \ 00459 PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, \ 00460 (char *)x, NULL,NULL,0,NULL,NULL) 00461 #define PEM_write_DHparams(fp,x) \ 00462 PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,\ 00463 (char *)x,NULL,NULL,0,NULL,NULL) 00464 00465 #define PEM_write_NETSCAPE_CERT_SEQUENCE(fp,x) \ 00466 PEM_ASN1_write((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \ 00467 PEM_STRING_X509,fp, \ 00468 (char *)x, NULL,NULL,0,NULL,NULL) 00469 00470 #define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \ 00471 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u) 00472 #define PEM_read_X509(fp,x,cb,u) (X509 *)PEM_ASN1_read( \ 00473 (char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb,u) 00474 #define PEM_read_X509_REQ(fp,x,cb,u) (X509_REQ *)PEM_ASN1_read( \ 00475 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,fp,(char **)x,cb,u) 00476 #define PEM_read_X509_CRL(fp,x,cb,u) (X509_CRL *)PEM_ASN1_read( \ 00477 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,fp,(char **)x,cb,u) 00478 #define PEM_read_RSAPrivateKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \ 00479 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,fp,(char **)x,cb,u) 00480 #define PEM_read_RSAPublicKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \ 00481 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb,u) 00482 #define PEM_read_DSAPrivateKey(fp,x,cb,u) (DSA *)PEM_ASN1_read( \ 00483 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,fp,(char **)x,cb,u) 00484 #define PEM_read_PrivateKey(fp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read( \ 00485 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,fp,(char **)x,cb,u) 00486 #define PEM_read_PKCS7(fp,x,cb,u) (PKCS7 *)PEM_ASN1_read( \ 00487 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,fp,(char **)x,cb,u) 00488 #define PEM_read_DHparams(fp,x,cb,u) (DH *)PEM_ASN1_read( \ 00489 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,fp,(char **)x,cb,u) 00490 00491 #define PEM_read_NETSCAPE_CERT_SEQUENCE(fp,x,cb,u) \ 00492 (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read( \ 00493 (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,fp,\ 00494 (char **)x,cb,u) 00495 00496 #define PEM_write_bio_X509(bp,x) \ 00497 PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \ 00498 (char *)x, NULL,NULL,0,NULL,NULL) 00499 #define PEM_write_bio_X509_REQ(bp,x) PEM_ASN1_write_bio( \ 00500 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,bp,(char *)x, \ 00501 NULL,NULL,0,NULL,NULL) 00502 #define PEM_write_bio_X509_CRL(bp,x) \ 00503 PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,\ 00504 bp,(char *)x, NULL,NULL,0,NULL,NULL) 00505 #define PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \ 00506 PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,\ 00507 bp,(char *)x,enc,kstr,klen,cb,u) 00508 #define PEM_write_bio_RSAPublicKey(bp,x) \ 00509 PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, \ 00510 PEM_STRING_RSA_PUBLIC,\ 00511 bp,(char *)x,NULL,NULL,0,NULL,NULL) 00512 #define PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \ 00513 PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,\ 00514 bp,(char *)x,enc,kstr,klen,cb,u) 00515 #define PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb,u) \ 00516 PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,\ 00517 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\ 00518 bp,(char *)x,enc,kstr,klen,cb,u) 00519 #define PEM_write_bio_PKCS7(bp,x) \ 00520 PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, \ 00521 (char *)x, NULL,NULL,0,NULL,NULL) 00522 #define PEM_write_bio_DHparams(bp,x) \ 00523 PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,\ 00524 bp,(char *)x,NULL,NULL,0,NULL,NULL) 00525 #define PEM_write_bio_DSAparams(bp,x) \ 00526 PEM_ASN1_write_bio((int (*)())i2d_DSAparams, \ 00527 PEM_STRING_DSAPARAMS,bp,(char *)x,NULL,NULL,0,NULL,NULL) 00528 00529 #define PEM_write_bio_NETSCAPE_CERT_SEQUENCE(bp,x) \ 00530 PEM_ASN1_write_bio((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \ 00531 PEM_STRING_X509,bp, \ 00532 (char *)x, NULL,NULL,0,NULL,NULL) 00533 00534 #define PEM_read_bio_X509(bp,x,cb,u) (X509 *)PEM_ASN1_read_bio( \ 00535 (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb,u) 00536 #define PEM_read_bio_X509_REQ(bp,x,cb,u) (X509_REQ *)PEM_ASN1_read_bio( \ 00537 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,bp,(char **)x,cb,u) 00538 #define PEM_read_bio_X509_CRL(bp,x,cb,u) (X509_CRL *)PEM_ASN1_read_bio( \ 00539 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,bp,(char **)x,cb,u) 00540 #define PEM_read_bio_RSAPrivateKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \ 00541 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,bp,(char **)x,cb,u) 00542 #define PEM_read_bio_RSAPublicKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \ 00543 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb,u) 00544 #define PEM_read_bio_DSAPrivateKey(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \ 00545 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,bp,(char **)x,cb,u) 00546 #define PEM_read_bio_PrivateKey(bp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read_bio( \ 00547 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,bp,(char **)x,cb,u) 00548 00549 #define PEM_read_bio_PKCS7(bp,x,cb,u) (PKCS7 *)PEM_ASN1_read_bio( \ 00550 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,bp,(char **)x,cb,u) 00551 #define PEM_read_bio_DHparams(bp,x,cb,u) (DH *)PEM_ASN1_read_bio( \ 00552 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,bp,(char **)x,cb,u) 00553 #define PEM_read_bio_DSAparams(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \ 00554 (char *(*)())d2i_DSAparams,PEM_STRING_DSAPARAMS,bp,(char **)x,cb,u) 00555 00556 #define PEM_read_bio_NETSCAPE_CERT_SEQUENCE(bp,x,cb,u) \ 00557 (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read_bio( \ 00558 (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,bp,\ 00559 (char **)x,cb,u) 00560 00561 #endif 00562 00563 #if 1 00564 /* "userdata": new with OpenSSL 0.9.4 */ 00565 typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata); 00566 #else 00567 /* OpenSSL 0.9.3, 0.9.3a */ 00568 typedef int pem_password_cb(char *buf, int size, int rwflag); 00569 #endif 00570 00571 int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher); 00572 int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len, 00573 pem_password_cb *callback,void *u); 00574 00575 #ifndef OPENSSL_NO_BIO 00576 int PEM_read_bio(BIO *bp, char **name, char **header, 00577 unsigned char **data,long *len); 00578 int PEM_write_bio(BIO *bp,const char *name,char *hdr,unsigned char *data, 00579 long len); 00580 int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char *name, BIO *bp, 00581 pem_password_cb *cb, void *u); 00582 void * PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, 00583 void **x, pem_password_cb *cb, void *u); 00584 00585 #define PEM_ASN1_read_bio_of(type,d2i,name,bp,x,cb,u) \ 00586 ((type*)PEM_ASN1_read_bio(CHECKED_D2I_OF(type, d2i), \ 00587 name, bp, \ 00588 CHECKED_PPTR_OF(type, x), \ 00589 cb, u)) 00590 00591 int PEM_ASN1_write_bio(i2d_of_void *i2d,const char *name,BIO *bp,char *x, 00592 const EVP_CIPHER *enc,unsigned char *kstr,int klen, 00593 pem_password_cb *cb, void *u); 00594 00595 #define PEM_ASN1_write_bio_of(type,i2d,name,bp,x,enc,kstr,klen,cb,u) \ 00596 (PEM_ASN1_write_bio(CHECKED_I2D_OF(type, i2d), \ 00597 name, bp, \ 00598 CHECKED_PTR_OF(type, x), \ 00599 enc, kstr, klen, cb, u)) 00600 00601 STACK_OF(X509_INFO) * PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u); 00602 int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc, 00603 unsigned char *kstr, int klen, pem_password_cb *cd, void *u); 00604 #endif 00605 00606 #ifndef OPENSSL_SYS_WIN16 00607 int PEM_read(FILE *fp, char **name, char **header, 00608 unsigned char **data,long *len); 00609 int PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len); 00610 void * PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x, 00611 pem_password_cb *cb, void *u); 00612 int PEM_ASN1_write(i2d_of_void *i2d,const char *name,FILE *fp, 00613 char *x,const EVP_CIPHER *enc,unsigned char *kstr, 00614 int klen,pem_password_cb *callback, void *u); 00615 STACK_OF(X509_INFO) * PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, 00616 pem_password_cb *cb, void *u); 00617 #endif 00618 00619 int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, 00620 EVP_MD *md_type, unsigned char **ek, int *ekl, 00621 unsigned char *iv, EVP_PKEY **pubk, int npubk); 00622 void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl, 00623 unsigned char *in, int inl); 00624 int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig,int *sigl, 00625 unsigned char *out, int *outl, EVP_PKEY *priv); 00626 00627 void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type); 00628 void PEM_SignUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt); 00629 int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, 00630 unsigned int *siglen, EVP_PKEY *pkey); 00631 00632 int PEM_def_callback(char *buf, int num, int w, void *key); 00633 void PEM_proc_type(char *buf, int type); 00634 void PEM_dek_info(char *buf, const char *type, int len, char *str); 00635 00636 #ifndef SSLEAY_MACROS 00637 00638 #include <openssl/symhacks.h> 00639 00640 DECLARE_PEM_rw(X509, X509) 00641 00642 DECLARE_PEM_rw(X509_AUX, X509) 00643 00644 DECLARE_PEM_rw(X509_CERT_PAIR, X509_CERT_PAIR) 00645 00646 DECLARE_PEM_rw(X509_REQ, X509_REQ) 00647 DECLARE_PEM_write(X509_REQ_NEW, X509_REQ) 00648 00649 DECLARE_PEM_rw(X509_CRL, X509_CRL) 00650 00651 DECLARE_PEM_rw(PKCS7, PKCS7) 00652 00653 DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE) 00654 00655 DECLARE_PEM_rw(PKCS8, X509_SIG) 00656 00657 DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO) 00658 00659 #ifndef OPENSSL_NO_RSA 00660 00661 DECLARE_PEM_rw_cb(RSAPrivateKey, RSA) 00662 00663 DECLARE_PEM_rw_const(RSAPublicKey, RSA) 00664 DECLARE_PEM_rw(RSA_PUBKEY, RSA) 00665 00666 #endif 00667 00668 #ifndef OPENSSL_NO_DSA 00669 00670 DECLARE_PEM_rw_cb(DSAPrivateKey, DSA) 00671 00672 DECLARE_PEM_rw(DSA_PUBKEY, DSA) 00673 00674 DECLARE_PEM_rw_const(DSAparams, DSA) 00675 00676 #endif 00677 00678 #ifndef OPENSSL_NO_EC 00679 DECLARE_PEM_rw_const(ECPKParameters, EC_GROUP) 00680 DECLARE_PEM_rw_cb(ECPrivateKey, EC_KEY) 00681 DECLARE_PEM_rw(EC_PUBKEY, EC_KEY) 00682 #endif 00683 00684 #ifndef OPENSSL_NO_DH 00685 00686 DECLARE_PEM_rw_const(DHparams, DH) 00687 00688 #endif 00689 00690 DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY) 00691 00692 DECLARE_PEM_rw(PUBKEY, EVP_PKEY) 00693 00694 int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid, 00695 char *kstr, int klen, 00696 pem_password_cb *cb, void *u); 00697 int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *, 00698 char *, int, pem_password_cb *, void *); 00699 int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc, 00700 char *kstr, int klen, 00701 pem_password_cb *cb, void *u); 00702 int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid, 00703 char *kstr, int klen, 00704 pem_password_cb *cb, void *u); 00705 EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u); 00706 00707 int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc, 00708 char *kstr, int klen, 00709 pem_password_cb *cb, void *u); 00710 int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid, 00711 char *kstr, int klen, 00712 pem_password_cb *cb, void *u); 00713 int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid, 00714 char *kstr, int klen, 00715 pem_password_cb *cb, void *u); 00716 00717 EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u); 00718 00719 int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc, 00720 char *kstr,int klen, pem_password_cb *cd, void *u); 00721 00722 #endif /* SSLEAY_MACROS */ 00723 00724 00725 /* BEGIN ERROR CODES */ 00726 /* The following lines are auto generated by the script mkerr.pl. Any changes 00727 * made after this point may be overwritten when the script is next run. 00728 */ 00729 void ERR_load_PEM_strings(void); 00730 00731 /* Error codes for the PEM functions. */ 00732 00733 /* Function codes. */ 00734 #define PEM_F_D2I_PKCS8PRIVATEKEY_BIO 120 00735 #define PEM_F_D2I_PKCS8PRIVATEKEY_FP 121 00736 #define PEM_F_DO_PK8PKEY 126 00737 #define PEM_F_DO_PK8PKEY_FP 125 00738 #define PEM_F_LOAD_IV 101 00739 #define PEM_F_PEM_ASN1_READ 102 00740 #define PEM_F_PEM_ASN1_READ_BIO 103 00741 #define PEM_F_PEM_ASN1_WRITE 104 00742 #define PEM_F_PEM_ASN1_WRITE_BIO 105 00743 #define PEM_F_PEM_DEF_CALLBACK 100 00744 #define PEM_F_PEM_DO_HEADER 106 00745 #define PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY 118 00746 #define PEM_F_PEM_GET_EVP_CIPHER_INFO 107 00747 #define PEM_F_PEM_PK8PKEY 119 00748 #define PEM_F_PEM_READ 108 00749 #define PEM_F_PEM_READ_BIO 109 00750 #define PEM_F_PEM_READ_BIO_PRIVATEKEY 123 00751 #define PEM_F_PEM_READ_PRIVATEKEY 124 00752 #define PEM_F_PEM_SEALFINAL 110 00753 #define PEM_F_PEM_SEALINIT 111 00754 #define PEM_F_PEM_SIGNFINAL 112 00755 #define PEM_F_PEM_WRITE 113 00756 #define PEM_F_PEM_WRITE_BIO 114 00757 #define PEM_F_PEM_X509_INFO_READ 115 00758 #define PEM_F_PEM_X509_INFO_READ_BIO 116 00759 #define PEM_F_PEM_X509_INFO_WRITE_BIO 117 00760 00761 /* Reason codes. */ 00762 #define PEM_R_BAD_BASE64_DECODE 100 00763 #define PEM_R_BAD_DECRYPT 101 00764 #define PEM_R_BAD_END_LINE 102 00765 #define PEM_R_BAD_IV_CHARS 103 00766 #define PEM_R_BAD_PASSWORD_READ 104 00767 #define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 115 00768 #define PEM_R_NOT_DEK_INFO 105 00769 #define PEM_R_NOT_ENCRYPTED 106 00770 #define PEM_R_NOT_PROC_TYPE 107 00771 #define PEM_R_NO_START_LINE 108 00772 #define PEM_R_PROBLEMS_GETTING_PASSWORD 109 00773 #define PEM_R_PUBLIC_KEY_NO_RSA 110 00774 #define PEM_R_READ_KEY 111 00775 #define PEM_R_SHORT_HEADER 112 00776 #define PEM_R_UNSUPPORTED_CIPHER 113 00777 #define PEM_R_UNSUPPORTED_ENCRYPTION 114 00778 00779 #ifdef __cplusplus 00780 } 00781 #endif 00782 #endif