Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) |
| 2 | * All rights reserved. |
| 3 | * |
| 4 | * This package is an SSL implementation written |
| 5 | * by Eric Young (eay@cryptsoft.com). |
| 6 | * The implementation was written so as to conform with Netscapes SSL. |
| 7 | * |
| 8 | * This library is free for commercial and non-commercial use as long as |
| 9 | * the following conditions are aheared to. The following conditions |
| 10 | * apply to all code found in this distribution, be it the RC4, RSA, |
| 11 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
| 12 | * included with this distribution is covered by the same copyright terms |
| 13 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
| 14 | * |
| 15 | * Copyright remains Eric Young's, and as such any Copyright notices in |
| 16 | * the code are not to be removed. |
| 17 | * If this package is used in a product, Eric Young should be given attribution |
| 18 | * as the author of the parts of the library used. |
| 19 | * This can be in the form of a textual message at program startup or |
| 20 | * in documentation (online or textual) provided with the package. |
| 21 | * |
| 22 | * Redistribution and use in source and binary forms, with or without |
| 23 | * modification, are permitted provided that the following conditions |
| 24 | * are met: |
| 25 | * 1. Redistributions of source code must retain the copyright |
| 26 | * notice, this list of conditions and the following disclaimer. |
| 27 | * 2. Redistributions in binary form must reproduce the above copyright |
| 28 | * notice, this list of conditions and the following disclaimer in the |
| 29 | * documentation and/or other materials provided with the distribution. |
| 30 | * 3. All advertising materials mentioning features or use of this software |
| 31 | * must display the following acknowledgement: |
| 32 | * "This product includes cryptographic software written by |
| 33 | * Eric Young (eay@cryptsoft.com)" |
| 34 | * The word 'cryptographic' can be left out if the rouines from the library |
| 35 | * being used are not cryptographic related :-). |
| 36 | * 4. If you include any Windows specific code (or a derivative thereof) from |
| 37 | * the apps directory (application code) you must include an acknowledgement: |
| 38 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
| 39 | * |
| 40 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
| 41 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 43 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 44 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 45 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 46 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 48 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 49 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 50 | * SUCH DAMAGE. |
| 51 | * |
| 52 | * The licence and distribution terms for any publically available version or |
| 53 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
| 54 | * copied and put under another distribution licence |
| 55 | * [including the GNU Public Licence.] */ |
| 56 | |
| 57 | #ifndef OPENSSL_HEADER_PEM_H |
| 58 | #define OPENSSL_HEADER_PEM_H |
| 59 | |
| 60 | #include <openssl/base64.h> |
| 61 | #include <openssl/bio.h> |
| 62 | #include <openssl/cipher.h> |
| 63 | #include <openssl/digest.h> |
| 64 | #include <openssl/evp.h> |
| 65 | #include <openssl/stack.h> |
| 66 | #include <openssl/x509.h> |
| 67 | |
| 68 | #ifdef __cplusplus |
| 69 | extern "C" { |
| 70 | #endif |
| 71 | |
| 72 | |
| 73 | #define PEM_BUFSIZE 1024 |
| 74 | |
| 75 | #define PEM_OBJ_UNDEF 0 |
| 76 | #define PEM_OBJ_X509 1 |
| 77 | #define PEM_OBJ_X509_REQ 2 |
| 78 | #define PEM_OBJ_CRL 3 |
| 79 | #define PEM_OBJ_SSL_SESSION 4 |
| 80 | #define PEM_OBJ_PRIV_KEY 10 |
| 81 | #define PEM_OBJ_PRIV_RSA 11 |
| 82 | #define PEM_OBJ_PRIV_DSA 12 |
| 83 | #define PEM_OBJ_PRIV_DH 13 |
| 84 | #define PEM_OBJ_PUB_RSA 14 |
| 85 | #define PEM_OBJ_PUB_DSA 15 |
| 86 | #define PEM_OBJ_PUB_DH 16 |
| 87 | #define PEM_OBJ_DHPARAMS 17 |
| 88 | #define PEM_OBJ_DSAPARAMS 18 |
| 89 | #define PEM_OBJ_PRIV_RSA_PUBLIC 19 |
| 90 | #define PEM_OBJ_PRIV_ECDSA 20 |
| 91 | #define PEM_OBJ_PUB_ECDSA 21 |
| 92 | #define PEM_OBJ_ECPARAMETERS 22 |
| 93 | |
| 94 | #define PEM_ERROR 30 |
| 95 | #define PEM_DEK_DES_CBC 40 |
| 96 | #define PEM_DEK_IDEA_CBC 45 |
| 97 | #define PEM_DEK_DES_EDE 50 |
| 98 | #define PEM_DEK_DES_ECB 60 |
| 99 | #define PEM_DEK_RSA 70 |
| 100 | #define PEM_DEK_RSA_MD2 80 |
| 101 | #define PEM_DEK_RSA_MD5 90 |
| 102 | |
| 103 | #define PEM_MD_MD2 NID_md2 |
| 104 | #define PEM_MD_MD5 NID_md5 |
| 105 | #define PEM_MD_SHA NID_sha |
| 106 | #define PEM_MD_MD2_RSA NID_md2WithRSAEncryption |
| 107 | #define PEM_MD_MD5_RSA NID_md5WithRSAEncryption |
| 108 | #define PEM_MD_SHA_RSA NID_sha1WithRSAEncryption |
| 109 | |
| 110 | #define PEM_STRING_X509_OLD "X509 CERTIFICATE" |
| 111 | #define PEM_STRING_X509 "CERTIFICATE" |
| 112 | #define PEM_STRING_X509_PAIR "CERTIFICATE PAIR" |
| 113 | #define PEM_STRING_X509_TRUSTED "TRUSTED CERTIFICATE" |
| 114 | #define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST" |
| 115 | #define PEM_STRING_X509_REQ "CERTIFICATE REQUEST" |
| 116 | #define PEM_STRING_X509_CRL "X509 CRL" |
| 117 | #define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY" |
| 118 | #define PEM_STRING_PUBLIC "PUBLIC KEY" |
| 119 | #define PEM_STRING_RSA "RSA PRIVATE KEY" |
| 120 | #define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY" |
| 121 | #define PEM_STRING_DSA "DSA PRIVATE KEY" |
| 122 | #define PEM_STRING_DSA_PUBLIC "DSA PUBLIC KEY" |
| 123 | #define PEM_STRING_PKCS7 "PKCS7" |
| 124 | #define PEM_STRING_PKCS7_SIGNED "PKCS #7 SIGNED DATA" |
| 125 | #define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY" |
| 126 | #define PEM_STRING_PKCS8INF "PRIVATE KEY" |
| 127 | #define PEM_STRING_DHPARAMS "DH PARAMETERS" |
| 128 | #define PEM_STRING_DHXPARAMS "X9.42 DH PARAMETERS" |
| 129 | #define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS" |
| 130 | #define PEM_STRING_DSAPARAMS "DSA PARAMETERS" |
| 131 | #define PEM_STRING_ECDSA_PUBLIC "ECDSA PUBLIC KEY" |
| 132 | #define PEM_STRING_ECPARAMETERS "EC PARAMETERS" |
| 133 | #define PEM_STRING_ECPRIVATEKEY "EC PRIVATE KEY" |
| 134 | #define PEM_STRING_PARAMETERS "PARAMETERS" |
| 135 | #define PEM_STRING_CMS "CMS" |
| 136 | |
| 137 | /* Note that this structure is initialised by PEM_SealInit and cleaned up |
| 138 | by PEM_SealFinal (at least for now) */ |
| 139 | typedef struct PEM_Encode_Seal_st |
| 140 | { |
| 141 | EVP_ENCODE_CTX encode; |
| 142 | EVP_MD_CTX md; |
| 143 | EVP_CIPHER_CTX cipher; |
| 144 | } PEM_ENCODE_SEAL_CTX; |
| 145 | |
| 146 | /* enc_type is one off */ |
| 147 | #define PEM_TYPE_ENCRYPTED 10 |
| 148 | #define PEM_TYPE_MIC_ONLY 20 |
| 149 | #define PEM_TYPE_MIC_CLEAR 30 |
| 150 | #define PEM_TYPE_CLEAR 40 |
| 151 | |
| 152 | typedef struct pem_recip_st |
| 153 | { |
| 154 | char *name; |
| 155 | X509_NAME *dn; |
| 156 | |
| 157 | int cipher; |
| 158 | int key_enc; |
| 159 | /* char iv[8]; unused and wrong size */ |
| 160 | } PEM_USER; |
| 161 | |
| 162 | typedef struct pem_ctx_st |
| 163 | { |
| 164 | int type; /* what type of object */ |
| 165 | |
| 166 | struct { |
| 167 | int version; |
| 168 | int mode; |
| 169 | } proc_type; |
| 170 | |
| 171 | char *domain; |
| 172 | |
| 173 | struct { |
| 174 | int cipher; |
| 175 | /* unused, and wrong size |
| 176 | unsigned char iv[8]; */ |
| 177 | } DEK_info; |
| 178 | |
| 179 | PEM_USER *originator; |
| 180 | |
| 181 | int num_recipient; |
| 182 | PEM_USER **recipient; |
| 183 | |
| 184 | /* XXX(ben): don#t think this is used! |
| 185 | STACK *x509_chain; / * certificate chain */ |
| 186 | EVP_MD *md; /* signature type */ |
| 187 | |
| 188 | int md_enc; /* is the md encrypted or not? */ |
| 189 | int md_len; /* length of md_data */ |
| 190 | char *md_data; /* message digest, could be pkey encrypted */ |
| 191 | |
| 192 | EVP_CIPHER *dec; /* date encryption cipher */ |
| 193 | int key_len; /* key length */ |
| 194 | unsigned char *key; /* key */ |
| 195 | /* unused, and wrong size |
| 196 | unsigned char iv[8]; */ |
| 197 | |
| 198 | |
| 199 | int data_enc; /* is the data encrypted */ |
| 200 | int data_len; |
| 201 | unsigned char *data; |
| 202 | } PEM_CTX; |
| 203 | |
| 204 | /* These macros make the PEM_read/PEM_write functions easier to maintain and |
| 205 | * write. Now they are all implemented with either: |
| 206 | * IMPLEMENT_PEM_rw(...) or IMPLEMENT_PEM_rw_cb(...) |
| 207 | */ |
| 208 | |
| 209 | #ifdef OPENSSL_NO_FP_API |
| 210 | |
| 211 | #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/ |
| 212 | #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/ |
| 213 | #define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) /**/ |
| 214 | #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/ |
| 215 | #define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) /**/ |
| 216 | |
| 217 | #else |
| 218 | |
| 219 | #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \ |
| 220 | type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\ |
| 221 | { \ |
| 222 | return PEM_ASN1_read((d2i_of_void *)d2i_##asn1, str,fp,(void **)x,cb,u); \ |
| 223 | } |
| 224 | |
| 225 | #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \ |
| 226 | int PEM_write_##name(FILE *fp, type *x) \ |
| 227 | { \ |
| 228 | return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,NULL,NULL,0,NULL,NULL); \ |
| 229 | } |
| 230 | |
| 231 | #define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) \ |
| 232 | int PEM_write_##name(FILE *fp, const type *x) \ |
| 233 | { \ |
| 234 | return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,(void *)x,NULL,NULL,0,NULL,NULL); \ |
| 235 | } |
| 236 | |
| 237 | #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \ |
| 238 | int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ |
| 239 | unsigned char *kstr, int klen, pem_password_cb *cb, \ |
| 240 | void *u) \ |
| 241 | { \ |
| 242 | return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \ |
| 243 | } |
| 244 | |
| 245 | #define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \ |
| 246 | int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ |
| 247 | unsigned char *kstr, int klen, pem_password_cb *cb, \ |
| 248 | void *u) \ |
| 249 | { \ |
| 250 | return PEM_ASN1_write((i2d_of_void *)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \ |
| 251 | } |
| 252 | |
| 253 | #endif |
| 254 | |
| 255 | #define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ |
| 256 | type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\ |
| 257 | { \ |
| 258 | return PEM_ASN1_read_bio((d2i_of_void *)d2i_##asn1, str,bp,(void **)x,cb,u); \ |
| 259 | } |
| 260 | |
| 261 | #define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ |
| 262 | int PEM_write_bio_##name(BIO *bp, type *x) \ |
| 263 | { \ |
| 264 | return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,x,NULL,NULL,0,NULL,NULL); \ |
| 265 | } |
| 266 | |
| 267 | #define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \ |
| 268 | int PEM_write_bio_##name(BIO *bp, const type *x) \ |
| 269 | { \ |
| 270 | return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,(void *)x,NULL,NULL,0,NULL,NULL); \ |
| 271 | } |
| 272 | |
| 273 | #define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ |
| 274 | int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ |
| 275 | unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \ |
| 276 | { \ |
| 277 | return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,x,enc,kstr,klen,cb,u); \ |
| 278 | } |
| 279 | |
| 280 | #define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \ |
| 281 | int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ |
| 282 | unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \ |
| 283 | { \ |
| 284 | return PEM_ASN1_write_bio((i2d_of_void *)i2d_##asn1,str,bp,(void *)x,enc,kstr,klen,cb,u); \ |
| 285 | } |
| 286 | |
| 287 | #define IMPLEMENT_PEM_write(name, type, str, asn1) \ |
| 288 | IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ |
| 289 | IMPLEMENT_PEM_write_fp(name, type, str, asn1) |
| 290 | |
| 291 | #define IMPLEMENT_PEM_write_const(name, type, str, asn1) \ |
| 292 | IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \ |
| 293 | IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) |
| 294 | |
| 295 | #define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \ |
| 296 | IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ |
| 297 | IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) |
| 298 | |
| 299 | #define IMPLEMENT_PEM_write_cb_const(name, type, str, asn1) \ |
| 300 | IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \ |
| 301 | IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) |
| 302 | |
| 303 | #define IMPLEMENT_PEM_read(name, type, str, asn1) \ |
| 304 | IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ |
| 305 | IMPLEMENT_PEM_read_fp(name, type, str, asn1) |
| 306 | |
| 307 | #define IMPLEMENT_PEM_rw(name, type, str, asn1) \ |
| 308 | IMPLEMENT_PEM_read(name, type, str, asn1) \ |
| 309 | IMPLEMENT_PEM_write(name, type, str, asn1) |
| 310 | |
| 311 | #define IMPLEMENT_PEM_rw_const(name, type, str, asn1) \ |
| 312 | IMPLEMENT_PEM_read(name, type, str, asn1) \ |
| 313 | IMPLEMENT_PEM_write_const(name, type, str, asn1) |
| 314 | |
| 315 | #define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \ |
| 316 | IMPLEMENT_PEM_read(name, type, str, asn1) \ |
| 317 | IMPLEMENT_PEM_write_cb(name, type, str, asn1) |
| 318 | |
| 319 | /* These are the same except they are for the declarations */ |
| 320 | |
| 321 | #if defined(OPENSSL_NO_FP_API) |
| 322 | |
| 323 | #define DECLARE_PEM_read_fp(name, type) /**/ |
| 324 | #define DECLARE_PEM_write_fp(name, type) /**/ |
| 325 | #define DECLARE_PEM_write_cb_fp(name, type) /**/ |
| 326 | |
| 327 | #else |
| 328 | |
| 329 | #define DECLARE_PEM_read_fp(name, type) \ |
| 330 | type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u); |
| 331 | |
| 332 | #define DECLARE_PEM_write_fp(name, type) \ |
| 333 | int PEM_write_##name(FILE *fp, type *x); |
| 334 | |
| 335 | #define DECLARE_PEM_write_fp_const(name, type) \ |
| 336 | int PEM_write_##name(FILE *fp, const type *x); |
| 337 | |
| 338 | #define DECLARE_PEM_write_cb_fp(name, type) \ |
| 339 | int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ |
| 340 | unsigned char *kstr, int klen, pem_password_cb *cb, void *u); |
| 341 | |
| 342 | #endif |
| 343 | |
| 344 | #ifndef OPENSSL_NO_BIO |
| 345 | #define DECLARE_PEM_read_bio(name, type) \ |
| 346 | type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u); |
| 347 | |
| 348 | #define DECLARE_PEM_write_bio(name, type) \ |
| 349 | int PEM_write_bio_##name(BIO *bp, type *x); |
| 350 | |
| 351 | #define DECLARE_PEM_write_bio_const(name, type) \ |
| 352 | int PEM_write_bio_##name(BIO *bp, const type *x); |
| 353 | |
| 354 | #define DECLARE_PEM_write_cb_bio(name, type) \ |
| 355 | int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ |
| 356 | unsigned char *kstr, int klen, pem_password_cb *cb, void *u); |
| 357 | |
| 358 | #else |
| 359 | |
| 360 | #define DECLARE_PEM_read_bio(name, type) /**/ |
| 361 | #define DECLARE_PEM_write_bio(name, type) /**/ |
| 362 | #define DECLARE_PEM_write_bio_const(name, type) /**/ |
| 363 | #define DECLARE_PEM_write_cb_bio(name, type) /**/ |
| 364 | |
| 365 | #endif |
| 366 | |
| 367 | #define DECLARE_PEM_write(name, type) \ |
| 368 | DECLARE_PEM_write_bio(name, type) \ |
| 369 | DECLARE_PEM_write_fp(name, type) |
| 370 | |
| 371 | #define DECLARE_PEM_write_const(name, type) \ |
| 372 | DECLARE_PEM_write_bio_const(name, type) \ |
| 373 | DECLARE_PEM_write_fp_const(name, type) |
| 374 | |
| 375 | #define DECLARE_PEM_write_cb(name, type) \ |
| 376 | DECLARE_PEM_write_cb_bio(name, type) \ |
| 377 | DECLARE_PEM_write_cb_fp(name, type) |
| 378 | |
| 379 | #define DECLARE_PEM_read(name, type) \ |
| 380 | DECLARE_PEM_read_bio(name, type) \ |
| 381 | DECLARE_PEM_read_fp(name, type) |
| 382 | |
| 383 | #define DECLARE_PEM_rw(name, type) \ |
| 384 | DECLARE_PEM_read(name, type) \ |
| 385 | DECLARE_PEM_write(name, type) |
| 386 | |
| 387 | #define DECLARE_PEM_rw_const(name, type) \ |
| 388 | DECLARE_PEM_read(name, type) \ |
| 389 | DECLARE_PEM_write_const(name, type) |
| 390 | |
| 391 | #define DECLARE_PEM_rw_cb(name, type) \ |
| 392 | DECLARE_PEM_read(name, type) \ |
| 393 | DECLARE_PEM_write_cb(name, type) |
| 394 | |
| 395 | #if 1 |
| 396 | /* "userdata": new with OpenSSL 0.9.4 */ |
| 397 | typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata); |
| 398 | #else |
| 399 | /* OpenSSL 0.9.3, 0.9.3a */ |
| 400 | typedef int pem_password_cb(char *buf, int size, int rwflag); |
| 401 | #endif |
| 402 | |
| 403 | int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher); |
| 404 | int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len, |
| 405 | pem_password_cb *callback,void *u); |
| 406 | |
| 407 | #ifndef OPENSSL_NO_BIO |
| 408 | int PEM_read_bio(BIO *bp, char **name, char **header, |
| 409 | unsigned char **data,long *len); |
| 410 | int PEM_write_bio(BIO *bp,const char *name, const char *hdr, |
| 411 | const unsigned char *data, long len); |
| 412 | int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char *name, BIO *bp, |
| 413 | pem_password_cb *cb, void *u); |
| 414 | void * PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, |
| 415 | void **x, pem_password_cb *cb, void *u); |
| 416 | int PEM_ASN1_write_bio(i2d_of_void *i2d,const char *name,BIO *bp, void *x, |
| 417 | const EVP_CIPHER *enc,unsigned char *kstr,int klen, |
| 418 | pem_password_cb *cb, void *u); |
| 419 | |
| 420 | STACK_OF(X509_INFO) * PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u); |
| 421 | int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc, |
| 422 | unsigned char *kstr, int klen, pem_password_cb *cd, void *u); |
| 423 | #endif |
| 424 | |
| 425 | int PEM_read(FILE *fp, char **name, char **header, |
| 426 | unsigned char **data,long *len); |
| 427 | int PEM_write(FILE *fp, const char *name, const char *hdr, |
| 428 | const unsigned char *data, long len); |
| 429 | void * PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x, |
| 430 | pem_password_cb *cb, void *u); |
| 431 | int PEM_ASN1_write(i2d_of_void *i2d,const char *name,FILE *fp, |
| 432 | void *x,const EVP_CIPHER *enc,unsigned char *kstr, |
| 433 | int klen,pem_password_cb *callback, void *u); |
| 434 | STACK_OF(X509_INFO) * PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, |
| 435 | pem_password_cb *cb, void *u); |
| 436 | |
| 437 | int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, |
| 438 | EVP_MD *md_type, unsigned char **ek, int *ekl, |
| 439 | unsigned char *iv, EVP_PKEY **pubk, int npubk); |
| 440 | void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl, |
| 441 | unsigned char *in, int inl); |
| 442 | int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig,int *sigl, |
| 443 | unsigned char *out, int *outl, EVP_PKEY *priv); |
| 444 | |
| 445 | void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type); |
| 446 | void PEM_SignUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt); |
| 447 | int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, |
| 448 | unsigned int *siglen, EVP_PKEY *pkey); |
| 449 | |
| 450 | int PEM_def_callback(char *buf, int num, int w, void *key); |
| 451 | void PEM_proc_type(char *buf, int type); |
| 452 | void PEM_dek_info(char *buf, const char *type, int len, char *str); |
| 453 | |
| 454 | |
| 455 | DECLARE_PEM_rw(X509, X509) |
| 456 | |
| 457 | DECLARE_PEM_rw(X509_AUX, X509) |
| 458 | |
| 459 | DECLARE_PEM_rw(X509_CERT_PAIR, X509_CERT_PAIR) |
| 460 | |
| 461 | DECLARE_PEM_rw(X509_REQ, X509_REQ) |
| 462 | DECLARE_PEM_write(X509_REQ_NEW, X509_REQ) |
| 463 | |
| 464 | DECLARE_PEM_rw(X509_CRL, X509_CRL) |
| 465 | |
| 466 | /* DECLARE_PEM_rw(PKCS7, PKCS7) */ |
| 467 | |
| 468 | DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE) |
| 469 | |
| 470 | DECLARE_PEM_rw(PKCS8, X509_SIG) |
| 471 | |
| 472 | DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO) |
| 473 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 474 | DECLARE_PEM_rw_cb(RSAPrivateKey, RSA) |
| 475 | |
| 476 | DECLARE_PEM_rw_const(RSAPublicKey, RSA) |
| 477 | DECLARE_PEM_rw(RSA_PUBKEY, RSA) |
| 478 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 479 | #ifndef OPENSSL_NO_DSA |
| 480 | |
| 481 | DECLARE_PEM_rw_cb(DSAPrivateKey, DSA) |
| 482 | |
| 483 | DECLARE_PEM_rw(DSA_PUBKEY, DSA) |
| 484 | |
| 485 | DECLARE_PEM_rw_const(DSAparams, DSA) |
| 486 | |
| 487 | #endif |
| 488 | |
| 489 | #ifndef OPENSSL_NO_EC |
| 490 | DECLARE_PEM_rw_const(ECPKParameters, EC_GROUP) |
| 491 | DECLARE_PEM_rw_cb(ECPrivateKey, EC_KEY) |
| 492 | DECLARE_PEM_rw(EC_PUBKEY, EC_KEY) |
| 493 | #endif |
| 494 | |
| 495 | #ifndef OPENSSL_NO_DH |
| 496 | |
| 497 | DECLARE_PEM_rw_const(DHparams, DH) |
| 498 | DECLARE_PEM_write_const(DHxparams, DH) |
| 499 | |
| 500 | #endif |
| 501 | |
| 502 | DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY) |
| 503 | |
| 504 | DECLARE_PEM_rw(PUBKEY, EVP_PKEY) |
| 505 | |
| 506 | int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid, |
| 507 | char *kstr, int klen, |
| 508 | pem_password_cb *cb, void *u); |
| 509 | int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *, |
| 510 | char *, int, pem_password_cb *, void *); |
| 511 | int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc, |
| 512 | char *kstr, int klen, |
| 513 | pem_password_cb *cb, void *u); |
| 514 | int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid, |
| 515 | char *kstr, int klen, |
| 516 | pem_password_cb *cb, void *u); |
| 517 | EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u); |
| 518 | |
| 519 | int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc, |
| 520 | char *kstr, int klen, |
| 521 | pem_password_cb *cb, void *u); |
| 522 | int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid, |
| 523 | char *kstr, int klen, |
| 524 | pem_password_cb *cb, void *u); |
| 525 | int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid, |
| 526 | char *kstr, int klen, |
| 527 | pem_password_cb *cb, void *u); |
| 528 | |
| 529 | EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u); |
| 530 | |
| 531 | int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc, |
| 532 | char *kstr,int klen, pem_password_cb *cd, void *u); |
| 533 | |
| 534 | EVP_PKEY *PEM_read_bio_Parameters(BIO *bp, EVP_PKEY **x); |
| 535 | int PEM_write_bio_Parameters(BIO *bp, EVP_PKEY *x); |
| 536 | |
| 537 | |
| 538 | EVP_PKEY *b2i_PrivateKey(const unsigned char **in, long length); |
| 539 | EVP_PKEY *b2i_PublicKey(const unsigned char **in, long length); |
| 540 | EVP_PKEY *b2i_PrivateKey_bio(BIO *in); |
| 541 | EVP_PKEY *b2i_PublicKey_bio(BIO *in); |
| 542 | int i2b_PrivateKey_bio(BIO *out, EVP_PKEY *pk); |
| 543 | int i2b_PublicKey_bio(BIO *out, EVP_PKEY *pk); |
| 544 | #ifndef OPENSSL_NO_RC4 |
| 545 | EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u); |
| 546 | int i2b_PVK_bio(BIO *out, EVP_PKEY *pk, int enclevel, |
| 547 | pem_password_cb *cb, void *u); |
| 548 | #endif |
| 549 | |
| 550 | |
| 551 | void ERR_load_PEM_strings(void); |
| 552 | |
| 553 | |
| 554 | #ifdef __cplusplus |
| 555 | } |
| 556 | #endif |
| 557 | |
| 558 | #define PEM_F_PEM_read_bio_DHparams 100 |
| 559 | #define PEM_F_load_iv 101 |
| 560 | #define PEM_F_PEM_write 102 |
| 561 | #define PEM_F_do_pk8pkey_fp 103 |
| 562 | #define PEM_F_PEM_read_PrivateKey 104 |
| 563 | #define PEM_F_PEM_read_DHparams 105 |
| 564 | #define PEM_F_PEM_ASN1_read_bio 106 |
| 565 | #define PEM_F_PEM_ASN1_read 107 |
| 566 | #define PEM_F_PEM_get_EVP_CIPHER_INFO 108 |
| 567 | #define PEM_F_PEM_X509_INFO_read 109 |
| 568 | #define PEM_F_PEM_read_bio_Parameters 110 |
| 569 | #define PEM_F_PEM_read 111 |
| 570 | #define PEM_F_PEM_X509_INFO_read_bio 112 |
| 571 | #define PEM_F_PEM_X509_INFO_write_bio 113 |
| 572 | #define PEM_F_PEM_ASN1_write 114 |
| 573 | #define PEM_F_d2i_PKCS8PrivateKey_bio 115 |
| 574 | #define PEM_F_d2i_PKCS8PrivateKey_fp 116 |
| 575 | #define PEM_F_PEM_read_bio_PrivateKey 117 |
| 576 | #define PEM_F_PEM_write_PrivateKey 118 |
| 577 | #define PEM_F_PEM_ASN1_write_bio 119 |
| 578 | #define PEM_F_PEM_do_header 120 |
| 579 | #define PEM_F_PEM_write_bio 121 |
| 580 | #define PEM_F_do_pk8pkey 122 |
| 581 | #define PEM_F_PEM_read_bio 123 |
| 582 | #define PEM_R_NO_START_LINE 100 |
| 583 | #define PEM_R_NOT_PROC_TYPE 101 |
| 584 | #define PEM_R_SHORT_HEADER 102 |
| 585 | #define PEM_R_BAD_IV_CHARS 103 |
| 586 | #define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 104 |
| 587 | #define PEM_R_BAD_END_LINE 105 |
| 588 | #define PEM_R_CIPHER_IS_NULL 106 |
| 589 | #define PEM_R_BAD_MAGIC_NUMBER 107 |
| 590 | #define PEM_R_BAD_DECRYPT 108 |
| 591 | #define PEM_R_UNSUPPORTED_ENCRYPTION 109 |
| 592 | #define PEM_R_PVK_DATA_TOO_SHORT 110 |
| 593 | #define PEM_R_PROBLEMS_GETTING_PASSWORD 111 |
| 594 | #define PEM_R_KEYBLOB_HEADER_PARSE_ERROR 112 |
| 595 | #define PEM_R_BIO_WRITE_FAILURE 113 |
| 596 | #define PEM_R_INCONSISTENT_HEADER 114 |
| 597 | #define PEM_R_PUBLIC_KEY_NO_RSA 115 |
| 598 | #define PEM_R_EXPECTING_PUBLIC_KEY_BLOB 116 |
| 599 | #define PEM_R_KEYBLOB_TOO_SHORT 117 |
| 600 | #define PEM_R_BAD_BASE64_DECODE 118 |
| 601 | #define PEM_R_READ_KEY 119 |
| 602 | #define PEM_R_BAD_PASSWORD_READ 120 |
| 603 | #define PEM_R_UNSUPPORTED_KEY_COMPONENTS 121 |
| 604 | #define PEM_R_UNSUPPORTED_CIPHER 122 |
| 605 | #define PEM_R_NOT_ENCRYPTED 123 |
| 606 | #define PEM_R_NOT_DEK_INFO 124 |
| 607 | #define PEM_R_BAD_VERSION_NUMBER 125 |
| 608 | #define PEM_R_EXPECTING_PRIVATE_KEY_BLOB 126 |
| 609 | #define PEM_R_PVK_TOO_SHORT 127 |
| 610 | |
| 611 | #endif /* OPENSSL_HEADER_PEM_H */ |