diff options
Diffstat (limited to 'src/lib/libcrypto/pem')
| -rw-r--r-- | src/lib/libcrypto/pem/pem.h | 612 | ||||
| -rw-r--r-- | src/lib/libcrypto/pem/pem2.h | 8 | ||||
| -rw-r--r-- | src/lib/libcrypto/pem/pem_all.c | 480 | ||||
| -rw-r--r-- | src/lib/libcrypto/pem/pem_err.c | 129 | ||||
| -rw-r--r-- | src/lib/libcrypto/pem/pem_info.c | 99 | ||||
| -rw-r--r-- | src/lib/libcrypto/pem/pem_lib.c | 329 | ||||
| -rw-r--r-- | src/lib/libcrypto/pem/pem_seal.c | 84 | ||||
| -rw-r--r-- | src/lib/libcrypto/pem/pem_sign.c | 33 |
8 files changed, 796 insertions, 978 deletions
diff --git a/src/lib/libcrypto/pem/pem.h b/src/lib/libcrypto/pem/pem.h index 55fbaeffe2..3785fca77d 100644 --- a/src/lib/libcrypto/pem/pem.h +++ b/src/lib/libcrypto/pem/pem.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* crypto/pem/pem.org */ | 1 | /* crypto/pem/pem.h */ |
| 2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -56,23 +56,25 @@ | |||
| 56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
| 57 | */ | 57 | */ |
| 58 | 58 | ||
| 59 | /* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING | ||
| 60 | * | ||
| 61 | * Always modify pem.org since pem.h is automatically generated from | ||
| 62 | * it during SSLeay configuration. | ||
| 63 | * | ||
| 64 | * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING | ||
| 65 | */ | ||
| 66 | |||
| 67 | #ifndef HEADER_PEM_H | 59 | #ifndef HEADER_PEM_H |
| 68 | #define HEADER_PEM_H | 60 | #define HEADER_PEM_H |
| 69 | 61 | ||
| 62 | #ifndef OPENSSL_NO_BIO | ||
| 63 | #include <openssl/bio.h> | ||
| 64 | #endif | ||
| 65 | #ifndef OPENSSL_NO_STACK | ||
| 66 | #include <openssl/stack.h> | ||
| 67 | #endif | ||
| 68 | #include <openssl/evp.h> | ||
| 69 | #include <openssl/x509.h> | ||
| 70 | #include <openssl/pem2.h> | ||
| 71 | #include <openssl/e_os2.h> | ||
| 72 | |||
| 70 | #ifdef __cplusplus | 73 | #ifdef __cplusplus |
| 71 | extern "C" { | 74 | extern "C" { |
| 72 | #endif | 75 | #endif |
| 73 | 76 | ||
| 74 | #include "evp.h" | 77 | #define PEM_BUFSIZE 1024 |
| 75 | #include "x509.h" | ||
| 76 | 78 | ||
| 77 | #define PEM_OBJ_UNDEF 0 | 79 | #define PEM_OBJ_UNDEF 0 |
| 78 | #define PEM_OBJ_X509 1 | 80 | #define PEM_OBJ_X509 1 |
| @@ -108,49 +110,25 @@ extern "C" { | |||
| 108 | 110 | ||
| 109 | #define PEM_STRING_X509_OLD "X509 CERTIFICATE" | 111 | #define PEM_STRING_X509_OLD "X509 CERTIFICATE" |
| 110 | #define PEM_STRING_X509 "CERTIFICATE" | 112 | #define PEM_STRING_X509 "CERTIFICATE" |
| 113 | #define PEM_STRING_X509_TRUSTED "TRUSTED CERTIFICATE" | ||
| 111 | #define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST" | 114 | #define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST" |
| 112 | #define PEM_STRING_X509_REQ "CERTIFICATE REQUEST" | 115 | #define PEM_STRING_X509_REQ "CERTIFICATE REQUEST" |
| 113 | #define PEM_STRING_X509_CRL "X509 CRL" | 116 | #define PEM_STRING_X509_CRL "X509 CRL" |
| 114 | #define PEM_STRING_EVP_PKEY "PRIVATE KEY" | 117 | #define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY" |
| 118 | #define PEM_STRING_PUBLIC "PUBLIC KEY" | ||
| 115 | #define PEM_STRING_RSA "RSA PRIVATE KEY" | 119 | #define PEM_STRING_RSA "RSA PRIVATE KEY" |
| 116 | #define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY" | 120 | #define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY" |
| 117 | #define PEM_STRING_DSA "DSA PRIVATE KEY" | 121 | #define PEM_STRING_DSA "DSA PRIVATE KEY" |
| 122 | #define PEM_STRING_DSA_PUBLIC "DSA PUBLIC KEY" | ||
| 118 | #define PEM_STRING_PKCS7 "PKCS7" | 123 | #define PEM_STRING_PKCS7 "PKCS7" |
| 124 | #define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY" | ||
| 125 | #define PEM_STRING_PKCS8INF "PRIVATE KEY" | ||
| 119 | #define PEM_STRING_DHPARAMS "DH PARAMETERS" | 126 | #define PEM_STRING_DHPARAMS "DH PARAMETERS" |
| 120 | #define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS" | 127 | #define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS" |
| 121 | #define PEM_STRING_DSAPARAMS "DSA PARAMETERS" | 128 | #define PEM_STRING_DSAPARAMS "DSA PARAMETERS" |
| 122 | 129 | ||
| 123 | #ifndef HEADER_ENVELOPE_H | 130 | /* Note that this structure is initialised by PEM_SealInit and cleaned up |
| 124 | 131 | by PEM_SealFinal (at least for now) */ | |
| 125 | #define EVP_ENCODE_CTX_SIZE 96 | ||
| 126 | #define EVP_MD_SIZE 60 | ||
| 127 | #define EVP_MD_CTX_SIZE 152 | ||
| 128 | #define EVP_CIPHER_SIZE 40 | ||
| 129 | #define EVP_CIPHER_CTX_SIZE 4212 | ||
| 130 | #define EVP_MAX_MD_SIZE 20 | ||
| 131 | |||
| 132 | typedef struct evp_encode_ctx_st | ||
| 133 | { | ||
| 134 | char data[EVP_ENCODE_CTX_SIZE]; | ||
| 135 | } EVP_ENCODE_CTX; | ||
| 136 | |||
| 137 | typedef struct env_md_ctx_st | ||
| 138 | { | ||
| 139 | char data[EVP_MD_CTX_SIZE]; | ||
| 140 | } EVP_MD_CTX; | ||
| 141 | |||
| 142 | typedef struct evp_cipher_st | ||
| 143 | { | ||
| 144 | char data[EVP_CIPHER_SIZE]; | ||
| 145 | } EVP_CIPHER; | ||
| 146 | |||
| 147 | typedef struct evp_cipher_ctx_st | ||
| 148 | { | ||
| 149 | char data[EVP_CIPHER_CTX_SIZE]; | ||
| 150 | } EVP_CIPHER_CTX; | ||
| 151 | #endif | ||
| 152 | |||
| 153 | |||
| 154 | typedef struct PEM_Encode_Seal_st | 132 | typedef struct PEM_Encode_Seal_st |
| 155 | { | 133 | { |
| 156 | EVP_ENCODE_CTX encode; | 134 | EVP_ENCODE_CTX encode; |
| @@ -195,7 +173,7 @@ typedef struct pem_ctx_st | |||
| 195 | int num_recipient; | 173 | int num_recipient; |
| 196 | PEM_USER **recipient; | 174 | PEM_USER **recipient; |
| 197 | 175 | ||
| 198 | #ifdef HEADER_STACK_H | 176 | #ifndef OPENSSL_NO_STACK |
| 199 | STACK *x509_chain; /* certificate chain */ | 177 | STACK *x509_chain; /* certificate chain */ |
| 200 | #else | 178 | #else |
| 201 | char *x509_chain; /* certificate chain */ | 179 | char *x509_chain; /* certificate chain */ |
| @@ -217,151 +195,324 @@ typedef struct pem_ctx_st | |||
| 217 | unsigned char *data; | 195 | unsigned char *data; |
| 218 | } PEM_CTX; | 196 | } PEM_CTX; |
| 219 | 197 | ||
| 198 | /* These macros make the PEM_read/PEM_write functions easier to maintain and | ||
| 199 | * write. Now they are all implemented with either: | ||
| 200 | * IMPLEMENT_PEM_rw(...) or IMPLEMENT_PEM_rw_cb(...) | ||
| 201 | */ | ||
| 202 | |||
| 203 | #ifdef OPENSSL_NO_FP_API | ||
| 204 | |||
| 205 | #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/ | ||
| 206 | #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/ | ||
| 207 | #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/ | ||
| 208 | |||
| 209 | #else | ||
| 210 | |||
| 211 | #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \ | ||
| 212 | type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\ | ||
| 213 | { \ | ||
| 214 | return((type *)PEM_ASN1_read((char *(*)())d2i_##asn1, str,fp,(char **)x,\ | ||
| 215 | cb,u)); \ | ||
| 216 | } \ | ||
| 217 | |||
| 218 | #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \ | ||
| 219 | int PEM_write_##name(FILE *fp, type *x) \ | ||
| 220 | { \ | ||
| 221 | return(PEM_ASN1_write((int (*)())i2d_##asn1,str,fp, (char *)x, \ | ||
| 222 | NULL,NULL,0,NULL,NULL)); \ | ||
| 223 | } | ||
| 224 | |||
| 225 | #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \ | ||
| 226 | int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ | ||
| 227 | unsigned char *kstr, int klen, pem_password_cb *cb, \ | ||
| 228 | void *u) \ | ||
| 229 | { \ | ||
| 230 | return(PEM_ASN1_write((int (*)())i2d_##asn1,str,fp, \ | ||
| 231 | (char *)x,enc,kstr,klen,cb,u)); \ | ||
| 232 | } | ||
| 233 | |||
| 234 | #endif | ||
| 235 | |||
| 236 | #define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ | ||
| 237 | type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\ | ||
| 238 | { \ | ||
| 239 | return((type *)PEM_ASN1_read_bio((char *(*)())d2i_##asn1, str,bp,\ | ||
| 240 | (char **)x,cb,u)); \ | ||
| 241 | } | ||
| 242 | |||
| 243 | #define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ | ||
| 244 | int PEM_write_bio_##name(BIO *bp, type *x) \ | ||
| 245 | { \ | ||
| 246 | return(PEM_ASN1_write_bio((int (*)())i2d_##asn1,str,bp, (char *)x, \ | ||
| 247 | NULL,NULL,0,NULL,NULL)); \ | ||
| 248 | } | ||
| 249 | |||
| 250 | #define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ | ||
| 251 | int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ | ||
| 252 | unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \ | ||
| 253 | { \ | ||
| 254 | return(PEM_ASN1_write_bio((int (*)())i2d_##asn1,str,bp, \ | ||
| 255 | (char *)x,enc,kstr,klen,cb,u)); \ | ||
| 256 | } | ||
| 257 | |||
| 258 | #define IMPLEMENT_PEM_write(name, type, str, asn1) \ | ||
| 259 | IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ | ||
| 260 | IMPLEMENT_PEM_write_fp(name, type, str, asn1) | ||
| 261 | |||
| 262 | #define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \ | ||
| 263 | IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ | ||
| 264 | IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) | ||
| 265 | |||
| 266 | #define IMPLEMENT_PEM_read(name, type, str, asn1) \ | ||
| 267 | IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ | ||
| 268 | IMPLEMENT_PEM_read_fp(name, type, str, asn1) | ||
| 269 | |||
| 270 | #define IMPLEMENT_PEM_rw(name, type, str, asn1) \ | ||
| 271 | IMPLEMENT_PEM_read(name, type, str, asn1) \ | ||
| 272 | IMPLEMENT_PEM_write(name, type, str, asn1) | ||
| 273 | |||
| 274 | #define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \ | ||
| 275 | IMPLEMENT_PEM_read(name, type, str, asn1) \ | ||
| 276 | IMPLEMENT_PEM_write_cb(name, type, str, asn1) | ||
| 277 | |||
| 278 | /* These are the same except they are for the declarations */ | ||
| 279 | |||
| 280 | #if defined(OPENSSL_SYS_WIN16) || defined(OPENSSL_NO_FP_API) | ||
| 281 | |||
| 282 | #define DECLARE_PEM_read_fp(name, type) /**/ | ||
| 283 | #define DECLARE_PEM_write_fp(name, type) /**/ | ||
| 284 | #define DECLARE_PEM_write_cb_fp(name, type) /**/ | ||
| 285 | |||
| 286 | #else | ||
| 287 | |||
| 288 | #define DECLARE_PEM_read_fp(name, type) \ | ||
| 289 | type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u); | ||
| 290 | |||
| 291 | #define DECLARE_PEM_write_fp(name, type) \ | ||
| 292 | int PEM_write_##name(FILE *fp, type *x); | ||
| 293 | |||
| 294 | #define DECLARE_PEM_write_cb_fp(name, type) \ | ||
| 295 | int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ | ||
| 296 | unsigned char *kstr, int klen, pem_password_cb *cb, void *u); | ||
| 297 | |||
| 298 | #endif | ||
| 299 | |||
| 300 | #ifndef OPENSSL_NO_BIO | ||
| 301 | #define DECLARE_PEM_read_bio(name, type) \ | ||
| 302 | type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u); | ||
| 303 | |||
| 304 | #define DECLARE_PEM_write_bio(name, type) \ | ||
| 305 | int PEM_write_bio_##name(BIO *bp, type *x); | ||
| 306 | |||
| 307 | #define DECLARE_PEM_write_cb_bio(name, type) \ | ||
| 308 | int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ | ||
| 309 | unsigned char *kstr, int klen, pem_password_cb *cb, void *u); | ||
| 310 | |||
| 311 | #else | ||
| 312 | |||
| 313 | #define DECLARE_PEM_read_bio(name, type) /**/ | ||
| 314 | #define DECLARE_PEM_write_bio(name, type) /**/ | ||
| 315 | #define DECLARE_PEM_write_cb_bio(name, type) /**/ | ||
| 316 | |||
| 317 | #endif | ||
| 318 | |||
| 319 | #define DECLARE_PEM_write(name, type) \ | ||
| 320 | DECLARE_PEM_write_bio(name, type) \ | ||
| 321 | DECLARE_PEM_write_fp(name, type) | ||
| 322 | |||
| 323 | #define DECLARE_PEM_write_cb(name, type) \ | ||
| 324 | DECLARE_PEM_write_cb_bio(name, type) \ | ||
| 325 | DECLARE_PEM_write_cb_fp(name, type) | ||
| 326 | |||
| 327 | #define DECLARE_PEM_read(name, type) \ | ||
| 328 | DECLARE_PEM_read_bio(name, type) \ | ||
| 329 | DECLARE_PEM_read_fp(name, type) | ||
| 330 | |||
| 331 | #define DECLARE_PEM_rw(name, type) \ | ||
| 332 | DECLARE_PEM_read(name, type) \ | ||
| 333 | DECLARE_PEM_write(name, type) | ||
| 334 | |||
| 335 | #define DECLARE_PEM_rw_cb(name, type) \ | ||
| 336 | DECLARE_PEM_read(name, type) \ | ||
| 337 | DECLARE_PEM_write_cb(name, type) | ||
| 338 | |||
| 220 | #ifdef SSLEAY_MACROS | 339 | #ifdef SSLEAY_MACROS |
| 221 | 340 | ||
| 222 | #define PEM_write_SSL_SESSION(fp,x) \ | 341 | #define PEM_write_SSL_SESSION(fp,x) \ |
| 223 | PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \ | 342 | PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \ |
| 224 | PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL) | 343 | PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL) |
| 225 | #define PEM_write_X509(fp,x) \ | 344 | #define PEM_write_X509(fp,x) \ |
| 226 | PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \ | 345 | PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \ |
| 227 | (char *)x, NULL,NULL,0,NULL) | 346 | (char *)x, NULL,NULL,0,NULL,NULL) |
| 228 | #define PEM_write_X509_REQ(fp,x) PEM_ASN1_write( \ | 347 | #define PEM_write_X509_REQ(fp,x) PEM_ASN1_write( \ |
| 229 | (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,(char *)x, \ | 348 | (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,(char *)x, \ |
| 230 | NULL,NULL,0,NULL) | 349 | NULL,NULL,0,NULL,NULL) |
| 231 | #define PEM_write_X509_CRL(fp,x) \ | 350 | #define PEM_write_X509_CRL(fp,x) \ |
| 232 | PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, \ | 351 | PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, \ |
| 233 | fp,(char *)x, NULL,NULL,0,NULL) | 352 | fp,(char *)x, NULL,NULL,0,NULL,NULL) |
| 234 | #define PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb) \ | 353 | #define PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \ |
| 235 | PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,\ | 354 | PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,\ |
| 236 | (char *)x,enc,kstr,klen,cb) | 355 | (char *)x,enc,kstr,klen,cb,u) |
| 237 | #define PEM_write_RSAPublicKey(fp,x) \ | 356 | #define PEM_write_RSAPublicKey(fp,x) \ |
| 238 | PEM_ASN1_write((int (*)())i2d_RSAPublicKey,\ | 357 | PEM_ASN1_write((int (*)())i2d_RSAPublicKey,\ |
| 239 | PEM_STRING_RSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL) | 358 | PEM_STRING_RSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL,NULL) |
| 240 | #define PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb) \ | 359 | #define PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \ |
| 241 | PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,\ | 360 | PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,\ |
| 242 | (char *)x,enc,kstr,klen,cb) | 361 | (char *)x,enc,kstr,klen,cb,u) |
| 243 | #define PEM_write_PrivateKey(bp,x,enc,kstr,klen,cb) \ | 362 | #define PEM_write_PrivateKey(bp,x,enc,kstr,klen,cb,u) \ |
| 244 | PEM_ASN1_write((int (*)())i2d_PrivateKey,\ | 363 | PEM_ASN1_write((int (*)())i2d_PrivateKey,\ |
| 245 | (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\ | 364 | (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\ |
| 246 | bp,(char *)x,enc,kstr,klen,cb) | 365 | bp,(char *)x,enc,kstr,klen,cb,u) |
| 247 | #define PEM_write_PKCS7(fp,x) \ | 366 | #define PEM_write_PKCS7(fp,x) \ |
| 248 | PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, \ | 367 | PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, \ |
| 249 | (char *)x, NULL,NULL,0,NULL) | 368 | (char *)x, NULL,NULL,0,NULL,NULL) |
| 250 | #define PEM_write_DHparams(fp,x) \ | 369 | #define PEM_write_DHparams(fp,x) \ |
| 251 | PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,\ | 370 | PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,\ |
| 252 | (char *)x,NULL,NULL,0,NULL) | 371 | (char *)x,NULL,NULL,0,NULL,NULL) |
| 253 | 372 | ||
| 254 | #define PEM_read_SSL_SESSION(fp,x,cb) (SSL_SESSION *)PEM_ASN1_read( \ | 373 | #define PEM_write_NETSCAPE_CERT_SEQUENCE(fp,x) \ |
| 255 | (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb) | 374 | PEM_ASN1_write((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \ |
| 256 | #define PEM_read_X509(fp,x,cb) (X509 *)PEM_ASN1_read( \ | 375 | PEM_STRING_X509,fp, \ |
| 257 | (char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb) | 376 | (char *)x, NULL,NULL,0,NULL,NULL) |
| 258 | #define PEM_read_X509_REQ(fp,x,cb) (X509_REQ *)PEM_ASN1_read( \ | 377 | |
| 259 | (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,fp,(char **)x,cb) | 378 | #define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \ |
| 260 | #define PEM_read_X509_CRL(fp,x,cb) (X509_CRL *)PEM_ASN1_read( \ | 379 | (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u) |
| 261 | (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,fp,(char **)x,cb) | 380 | #define PEM_read_X509(fp,x,cb,u) (X509 *)PEM_ASN1_read( \ |
| 262 | #define PEM_read_RSAPrivateKey(fp,x,cb) (RSA *)PEM_ASN1_read( \ | 381 | (char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb,u) |
| 263 | (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,fp,(char **)x,cb) | 382 | #define PEM_read_X509_REQ(fp,x,cb,u) (X509_REQ *)PEM_ASN1_read( \ |
| 264 | #define PEM_read_RSAPublicKey(fp,x,cb) (RSA *)PEM_ASN1_read( \ | 383 | (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,fp,(char **)x,cb,u) |
| 265 | (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb) | 384 | #define PEM_read_X509_CRL(fp,x,cb,u) (X509_CRL *)PEM_ASN1_read( \ |
| 266 | #define PEM_read_DSAPrivateKey(fp,x,cb) (DSA *)PEM_ASN1_read( \ | 385 | (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,fp,(char **)x,cb,u) |
| 267 | (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,fp,(char **)x,cb) | 386 | #define PEM_read_RSAPrivateKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \ |
| 268 | #define PEM_read_PrivateKey(fp,x,cb) (EVP_PKEY *)PEM_ASN1_read( \ | 387 | (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,fp,(char **)x,cb,u) |
| 269 | (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,fp,(char **)x,cb) | 388 | #define PEM_read_RSAPublicKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \ |
| 270 | #define PEM_read_PKCS7(fp,x,cb) (PKCS7 *)PEM_ASN1_read( \ | 389 | (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb,u) |
| 271 | (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,fp,(char **)x,cb) | 390 | #define PEM_read_DSAPrivateKey(fp,x,cb,u) (DSA *)PEM_ASN1_read( \ |
| 272 | #define PEM_read_DHparams(fp,x,cb) (DH *)PEM_ASN1_read( \ | 391 | (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,fp,(char **)x,cb,u) |
| 273 | (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,fp,(char **)x,cb) | 392 | #define PEM_read_PrivateKey(fp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read( \ |
| 393 | (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,fp,(char **)x,cb,u) | ||
| 394 | #define PEM_read_PKCS7(fp,x,cb,u) (PKCS7 *)PEM_ASN1_read( \ | ||
| 395 | (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,fp,(char **)x,cb,u) | ||
| 396 | #define PEM_read_DHparams(fp,x,cb,u) (DH *)PEM_ASN1_read( \ | ||
| 397 | (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,fp,(char **)x,cb,u) | ||
| 398 | |||
| 399 | #define PEM_read_NETSCAPE_CERT_SEQUENCE(fp,x,cb,u) \ | ||
| 400 | (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read( \ | ||
| 401 | (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,fp,\ | ||
| 402 | (char **)x,cb,u) | ||
| 274 | 403 | ||
| 275 | #define PEM_write_bio_SSL_SESSION(bp,x) \ | 404 | #define PEM_write_bio_SSL_SESSION(bp,x) \ |
| 276 | PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \ | 405 | PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \ |
| 277 | PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL) | 406 | PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL,NULL) |
| 278 | #define PEM_write_bio_X509(bp,x) \ | 407 | #define PEM_write_bio_X509(bp,x) \ |
| 279 | PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \ | 408 | PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \ |
| 280 | (char *)x, NULL,NULL,0,NULL) | 409 | (char *)x, NULL,NULL,0,NULL,NULL) |
| 281 | #define PEM_write_bio_X509_REQ(bp,x) PEM_ASN1_write_bio( \ | 410 | #define PEM_write_bio_X509_REQ(bp,x) PEM_ASN1_write_bio( \ |
| 282 | (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,bp,(char *)x, \ | 411 | (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,bp,(char *)x, \ |
| 283 | NULL,NULL,0,NULL) | 412 | NULL,NULL,0,NULL,NULL) |
| 284 | #define PEM_write_bio_X509_CRL(bp,x) \ | 413 | #define PEM_write_bio_X509_CRL(bp,x) \ |
| 285 | PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,\ | 414 | PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,\ |
| 286 | bp,(char *)x, NULL,NULL,0,NULL) | 415 | bp,(char *)x, NULL,NULL,0,NULL,NULL) |
| 287 | #define PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb) \ | 416 | #define PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \ |
| 288 | PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,\ | 417 | PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,\ |
| 289 | bp,(char *)x,enc,kstr,klen,cb) | 418 | bp,(char *)x,enc,kstr,klen,cb,u) |
| 290 | #define PEM_write_bio_RSAPublicKey(bp,x) \ | 419 | #define PEM_write_bio_RSAPublicKey(bp,x) \ |
| 291 | PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, \ | 420 | PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, \ |
| 292 | PEM_STRING_RSA_PUBLIC,\ | 421 | PEM_STRING_RSA_PUBLIC,\ |
| 293 | bp,(char *)x,NULL,NULL,0,NULL) | 422 | bp,(char *)x,NULL,NULL,0,NULL,NULL) |
| 294 | #define PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb) \ | 423 | #define PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \ |
| 295 | PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,\ | 424 | PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,\ |
| 296 | bp,(char *)x,enc,kstr,klen,cb) | 425 | bp,(char *)x,enc,kstr,klen,cb,u) |
| 297 | #define PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb) \ | 426 | #define PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb,u) \ |
| 298 | PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,\ | 427 | PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,\ |
| 299 | (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\ | 428 | (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\ |
| 300 | bp,(char *)x,enc,kstr,klen,cb) | 429 | bp,(char *)x,enc,kstr,klen,cb,u) |
| 301 | #define PEM_write_bio_PKCS7(bp,x) \ | 430 | #define PEM_write_bio_PKCS7(bp,x) \ |
| 302 | PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, \ | 431 | PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, \ |
| 303 | (char *)x, NULL,NULL,0,NULL) | 432 | (char *)x, NULL,NULL,0,NULL,NULL) |
| 304 | #define PEM_write_bio_DHparams(bp,x) \ | 433 | #define PEM_write_bio_DHparams(bp,x) \ |
| 305 | PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,\ | 434 | PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,\ |
| 306 | bp,(char *)x,NULL,NULL,0,NULL) | 435 | bp,(char *)x,NULL,NULL,0,NULL,NULL) |
| 307 | #define PEM_write_bio_DSAparams(bp,x) \ | 436 | #define PEM_write_bio_DSAparams(bp,x) \ |
| 308 | PEM_ASN1_write_bio((int (*)())i2d_DSAparams, \ | 437 | PEM_ASN1_write_bio((int (*)())i2d_DSAparams, \ |
| 309 | PEM_STRING_DSAPARAMS,bp,(char *)x,NULL,NULL,0,NULL) | 438 | PEM_STRING_DSAPARAMS,bp,(char *)x,NULL,NULL,0,NULL,NULL) |
| 310 | 439 | ||
| 311 | #define PEM_read_bio_SSL_SESSION(bp,x,cb) (SSL_SESSION *)PEM_ASN1_read_bio( \ | 440 | #define PEM_write_bio_NETSCAPE_CERT_SEQUENCE(bp,x) \ |
| 312 | (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb) | 441 | PEM_ASN1_write_bio((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \ |
| 313 | #define PEM_read_bio_X509(bp,x,cb) (X509 *)PEM_ASN1_read_bio( \ | 442 | PEM_STRING_X509,bp, \ |
| 314 | (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb) | 443 | (char *)x, NULL,NULL,0,NULL,NULL) |
| 315 | #define PEM_read_bio_X509_REQ(bp,x,cb) (X509_REQ *)PEM_ASN1_read_bio( \ | 444 | |
| 316 | (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,bp,(char **)x,cb) | 445 | #define PEM_read_bio_SSL_SESSION(bp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read_bio( \ |
| 317 | #define PEM_read_bio_X509_CRL(bp,x,cb) (X509_CRL *)PEM_ASN1_read_bio( \ | 446 | (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb,u) |
| 318 | (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,bp,(char **)x,cb) | 447 | #define PEM_read_bio_X509(bp,x,cb,u) (X509 *)PEM_ASN1_read_bio( \ |
| 319 | #define PEM_read_bio_RSAPrivateKey(bp,x,cb) (RSA *)PEM_ASN1_read_bio( \ | 448 | (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb,u) |
| 320 | (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,bp,(char **)x,cb) | 449 | #define PEM_read_bio_X509_REQ(bp,x,cb,u) (X509_REQ *)PEM_ASN1_read_bio( \ |
| 321 | #define PEM_read_bio_RSAPublicKey(bp,x,cb) (RSA *)PEM_ASN1_read_bio( \ | 450 | (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,bp,(char **)x,cb,u) |
| 322 | (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb) | 451 | #define PEM_read_bio_X509_CRL(bp,x,cb,u) (X509_CRL *)PEM_ASN1_read_bio( \ |
| 323 | #define PEM_read_bio_DSAPrivateKey(bp,x,cb) (DSA *)PEM_ASN1_read_bio( \ | 452 | (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,bp,(char **)x,cb,u) |
| 324 | (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,bp,(char **)x,cb) | 453 | #define PEM_read_bio_RSAPrivateKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \ |
| 325 | #define PEM_read_bio_PrivateKey(bp,x,cb) (EVP_PKEY *)PEM_ASN1_read_bio( \ | 454 | (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,bp,(char **)x,cb,u) |
| 326 | (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,bp,(char **)x,cb) | 455 | #define PEM_read_bio_RSAPublicKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \ |
| 327 | 456 | (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb,u) | |
| 328 | #define PEM_read_bio_PKCS7(bp,x,cb) (PKCS7 *)PEM_ASN1_read_bio( \ | 457 | #define PEM_read_bio_DSAPrivateKey(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \ |
| 329 | (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,bp,(char **)x,cb) | 458 | (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,bp,(char **)x,cb,u) |
| 330 | #define PEM_read_bio_DHparams(bp,x,cb) (DH *)PEM_ASN1_read_bio( \ | 459 | #define PEM_read_bio_PrivateKey(bp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read_bio( \ |
| 331 | (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,bp,(char **)x,cb) | 460 | (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,bp,(char **)x,cb,u) |
| 332 | #define PEM_read_bio_DSAparams(bp,x,cb) (DSA *)PEM_ASN1_read_bio( \ | 461 | |
| 333 | (char *(*)())d2i_DSAparams,PEM_STRING_DSAPARAMS,bp,(char **)x,cb) | 462 | #define PEM_read_bio_PKCS7(bp,x,cb,u) (PKCS7 *)PEM_ASN1_read_bio( \ |
| 463 | (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,bp,(char **)x,cb,u) | ||
| 464 | #define PEM_read_bio_DHparams(bp,x,cb,u) (DH *)PEM_ASN1_read_bio( \ | ||
| 465 | (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,bp,(char **)x,cb,u) | ||
| 466 | #define PEM_read_bio_DSAparams(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \ | ||
| 467 | (char *(*)())d2i_DSAparams,PEM_STRING_DSAPARAMS,bp,(char **)x,cb,u) | ||
| 468 | |||
| 469 | #define PEM_read_bio_NETSCAPE_CERT_SEQUENCE(bp,x,cb,u) \ | ||
| 470 | (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read_bio( \ | ||
| 471 | (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,bp,\ | ||
| 472 | (char **)x,cb,u) | ||
| 334 | 473 | ||
| 335 | #endif | 474 | #endif |
| 336 | 475 | ||
| 337 | #ifndef NOPROTO | 476 | #if 1 |
| 477 | /* "userdata": new with OpenSSL 0.9.4 */ | ||
| 478 | typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata); | ||
| 479 | #else | ||
| 480 | /* OpenSSL 0.9.3, 0.9.3a */ | ||
| 481 | typedef int pem_password_cb(char *buf, int size, int rwflag); | ||
| 482 | #endif | ||
| 483 | |||
| 338 | int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher); | 484 | int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher); |
| 339 | int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len, | 485 | int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len, |
| 340 | int (*callback)()); | 486 | pem_password_cb *callback,void *u); |
| 341 | 487 | ||
| 342 | #ifdef HEADER_BIO_H | 488 | #ifndef OPENSSL_NO_BIO |
| 343 | int PEM_read_bio(BIO *bp, char **name, char **header, | 489 | int PEM_read_bio(BIO *bp, char **name, char **header, |
| 344 | unsigned char **data,long *len); | 490 | unsigned char **data,long *len); |
| 345 | int PEM_write_bio(BIO *bp,char *name,char *hdr,unsigned char *data, | 491 | int PEM_write_bio(BIO *bp,const char *name,char *hdr,unsigned char *data, |
| 346 | long len); | 492 | long len); |
| 347 | char * PEM_ASN1_read_bio(char *(*d2i)(),char *name,BIO *bp,char **x, | 493 | int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char *name, BIO *bp, |
| 348 | int (*cb)()); | 494 | pem_password_cb *cb, void *u); |
| 349 | int PEM_ASN1_write_bio(int (*i2d)(),char *name,BIO *bp,char *x, | 495 | char * PEM_ASN1_read_bio(char *(*d2i)(),const char *name,BIO *bp,char **x, |
| 350 | EVP_CIPHER *enc,unsigned char *kstr,int klen,int (*callback)()); | 496 | pem_password_cb *cb, void *u); |
| 351 | STACK * PEM_X509_INFO_read_bio(BIO *bp, STACK *sk, int (*cb)()); | 497 | int PEM_ASN1_write_bio(int (*i2d)(),const char *name,BIO *bp,char *x, |
| 498 | const EVP_CIPHER *enc,unsigned char *kstr,int klen, | ||
| 499 | pem_password_cb *cb, void *u); | ||
| 500 | STACK_OF(X509_INFO) * PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u); | ||
| 352 | int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc, | 501 | int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc, |
| 353 | unsigned char *kstr, int klen, int (*cb)()); | 502 | unsigned char *kstr, int klen, pem_password_cb *cd, void *u); |
| 354 | #endif | 503 | #endif |
| 355 | 504 | ||
| 356 | #ifndef WIN16 | 505 | #ifndef OPENSSL_SYS_WIN16 |
| 357 | int PEM_read(FILE *fp, char **name, char **header, | 506 | int PEM_read(FILE *fp, char **name, char **header, |
| 358 | unsigned char **data,long *len); | 507 | unsigned char **data,long *len); |
| 359 | int PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len); | 508 | int PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len); |
| 360 | char * PEM_ASN1_read(char *(*d2i)(),char *name,FILE *fp,char **x, | 509 | char * PEM_ASN1_read(char *(*d2i)(),const char *name,FILE *fp,char **x, |
| 361 | int (*cb)()); | 510 | pem_password_cb *cb, void *u); |
| 362 | int PEM_ASN1_write(int (*i2d)(),char *name,FILE *fp,char *x, | 511 | int PEM_ASN1_write(int (*i2d)(),const char *name,FILE *fp,char *x, |
| 363 | EVP_CIPHER *enc,unsigned char *kstr,int klen,int (*callback)()); | 512 | const EVP_CIPHER *enc,unsigned char *kstr,int klen, |
| 364 | STACK * PEM_X509_INFO_read(FILE *fp, STACK *sk, int (*cb)()); | 513 | pem_password_cb *callback, void *u); |
| 514 | STACK_OF(X509_INFO) * PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, | ||
| 515 | pem_password_cb *cb, void *u); | ||
| 365 | #endif | 516 | #endif |
| 366 | 517 | ||
| 367 | int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, | 518 | int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, |
| @@ -377,148 +528,102 @@ void PEM_SignUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt); | |||
| 377 | int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, | 528 | int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, |
| 378 | unsigned int *siglen, EVP_PKEY *pkey); | 529 | unsigned int *siglen, EVP_PKEY *pkey); |
| 379 | 530 | ||
| 380 | void ERR_load_PEM_strings(void); | 531 | int PEM_def_callback(char *buf, int num, int w, void *key); |
| 381 | |||
| 382 | void PEM_proc_type(char *buf, int type); | 532 | void PEM_proc_type(char *buf, int type); |
| 383 | void PEM_dek_info(char *buf, char *type, int len, char *str); | 533 | void PEM_dek_info(char *buf, const char *type, int len, char *str); |
| 384 | 534 | ||
| 385 | #ifndef SSLEAY_MACROS | 535 | #ifndef SSLEAY_MACROS |
| 386 | 536 | ||
| 387 | #ifndef WIN16 | 537 | #include <openssl/symhacks.h> |
| 388 | X509 *PEM_read_X509(FILE *fp,X509 **x,int (*cb)()); | 538 | |
| 389 | X509_REQ *PEM_read_X509_REQ(FILE *fp,X509_REQ **x,int (*cb)()); | 539 | DECLARE_PEM_rw(X509, X509) |
| 390 | X509_CRL *PEM_read_X509_CRL(FILE *fp,X509_CRL **x,int (*cb)()); | 540 | |
| 391 | RSA *PEM_read_RSAPrivateKey(FILE *fp,RSA **x,int (*cb)()); | 541 | DECLARE_PEM_rw(X509_AUX, X509) |
| 392 | RSA *PEM_read_RSAPublicKey(FILE *fp,RSA **x,int (*cb)()); | 542 | |
| 393 | DSA *PEM_read_DSAPrivateKey(FILE *fp,DSA **x,int (*cb)()); | 543 | DECLARE_PEM_rw(X509_REQ, X509_REQ) |
| 394 | EVP_PKEY *PEM_read_PrivateKey(FILE *fp,EVP_PKEY **x,int (*cb)()); | 544 | DECLARE_PEM_write(X509_REQ_NEW, X509_REQ) |
| 395 | PKCS7 *PEM_read_PKCS7(FILE *fp,PKCS7 **x,int (*cb)()); | 545 | |
| 396 | DH *PEM_read_DHparams(FILE *fp,DH **x,int (*cb)()); | 546 | DECLARE_PEM_rw(X509_CRL, X509_CRL) |
| 397 | DSA *PEM_read_DSAparams(FILE *fp,DSA **x,int (*cb)()); | 547 | |
| 398 | int PEM_write_X509(FILE *fp,X509 *x); | 548 | DECLARE_PEM_rw(PKCS7, PKCS7) |
| 399 | int PEM_write_X509_REQ(FILE *fp,X509_REQ *x); | 549 | |
| 400 | int PEM_write_X509_CRL(FILE *fp,X509_CRL *x); | 550 | DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE) |
| 401 | int PEM_write_RSAPrivateKey(FILE *fp,RSA *x,EVP_CIPHER *enc,unsigned char *kstr, | 551 | |
| 402 | int klen,int (*cb)()); | 552 | DECLARE_PEM_rw(PKCS8, X509_SIG) |
| 403 | int PEM_write_RSAPublicKey(FILE *fp,RSA *x); | 553 | |
| 404 | int PEM_write_DSAPrivateKey(FILE *fp,DSA *x,EVP_CIPHER *enc,unsigned char *kstr, | 554 | DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO) |
| 405 | int klen,int (*cb)()); | 555 | |
| 406 | int PEM_write_PrivateKey(FILE *fp,EVP_PKEY *x,EVP_CIPHER *enc, | 556 | #ifndef OPENSSL_NO_RSA |
| 407 | unsigned char *kstr,int klen,int (*cb)()); | 557 | |
| 408 | int PEM_write_PKCS7(FILE *fp,PKCS7 *x); | 558 | DECLARE_PEM_rw_cb(RSAPrivateKey, RSA) |
| 409 | int PEM_write_DHparams(FILE *fp,DH *x); | 559 | |
| 410 | int PEM_write_DSAparams(FILE *fp,DSA *x); | 560 | DECLARE_PEM_rw(RSAPublicKey, RSA) |
| 411 | #endif | 561 | DECLARE_PEM_rw(RSA_PUBKEY, RSA) |
| 412 | 562 | ||
| 413 | #ifdef HEADER_BIO_H | ||
| 414 | X509 *PEM_read_bio_X509(BIO *bp,X509 **x,int (*cb)()); | ||
| 415 | X509_REQ *PEM_read_bio_X509_REQ(BIO *bp,X509_REQ **x,int (*cb)()); | ||
| 416 | X509_CRL *PEM_read_bio_X509_CRL(BIO *bp,X509_CRL **x,int (*cb)()); | ||
| 417 | RSA *PEM_read_bio_RSAPrivateKey(BIO *bp,RSA **x,int (*cb)()); | ||
| 418 | RSA *PEM_read_bio_RSAPublicKey(BIO *bp,RSA **x,int (*cb)()); | ||
| 419 | DSA *PEM_read_bio_DSAPrivateKey(BIO *bp,DSA **x,int (*cb)()); | ||
| 420 | EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp,EVP_PKEY **x,int (*cb)()); | ||
| 421 | PKCS7 *PEM_read_bio_PKCS7(BIO *bp,PKCS7 **x,int (*cb)()); | ||
| 422 | DH *PEM_read_bio_DHparams(BIO *bp,DH **x,int (*cb)()); | ||
| 423 | DSA *PEM_read_bio_DSAparams(BIO *bp,DSA **x,int (*cb)()); | ||
| 424 | int PEM_write_bio_X509(BIO *bp,X509 *x); | ||
| 425 | int PEM_write_bio_X509_REQ(BIO *bp,X509_REQ *x); | ||
| 426 | int PEM_write_bio_X509_CRL(BIO *bp,X509_CRL *x); | ||
| 427 | int PEM_write_bio_RSAPrivateKey(BIO *fp,RSA *x,EVP_CIPHER *enc, | ||
| 428 | unsigned char *kstr,int klen,int (*cb)()); | ||
| 429 | int PEM_write_bio_RSAPublicKey(BIO *fp,RSA *x); | ||
| 430 | int PEM_write_bio_DSAPrivateKey(BIO *fp,DSA *x,EVP_CIPHER *enc, | ||
| 431 | unsigned char *kstr,int klen,int (*cb)()); | ||
| 432 | int PEM_write_bio_PrivateKey(BIO *fp,EVP_PKEY *x,EVP_CIPHER *enc, | ||
| 433 | unsigned char *kstr,int klen,int (*cb)()); | ||
| 434 | int PEM_write_bio_PKCS7(BIO *bp,PKCS7 *x); | ||
| 435 | int PEM_write_bio_DHparams(BIO *bp,DH *x); | ||
| 436 | int PEM_write_bio_DSAparams(BIO *bp,DSA *x); | ||
| 437 | #endif | 563 | #endif |
| 438 | 564 | ||
| 439 | #endif /* SSLEAY_MACROS */ | 565 | #ifndef OPENSSL_NO_DSA |
| 440 | 566 | ||
| 567 | DECLARE_PEM_rw_cb(DSAPrivateKey, DSA) | ||
| 441 | 568 | ||
| 442 | #else | 569 | DECLARE_PEM_rw(DSA_PUBKEY, DSA) |
| 570 | |||
| 571 | DECLARE_PEM_rw(DSAparams, DSA) | ||
| 443 | 572 | ||
| 444 | int PEM_get_EVP_CIPHER_INFO(); | ||
| 445 | int PEM_do_header(); | ||
| 446 | int PEM_read_bio(); | ||
| 447 | int PEM_write_bio(); | ||
| 448 | #ifndef WIN16 | ||
| 449 | int PEM_read(); | ||
| 450 | int PEM_write(); | ||
| 451 | STACK * PEM_X509_INFO_read(); | ||
| 452 | char * PEM_ASN1_read(); | ||
| 453 | int PEM_ASN1_write(); | ||
| 454 | #endif | 573 | #endif |
| 455 | STACK * PEM_X509_INFO_read_bio(); | ||
| 456 | int PEM_X509_INFO_write_bio(); | ||
| 457 | char * PEM_ASN1_read_bio(); | ||
| 458 | int PEM_ASN1_write_bio(); | ||
| 459 | int PEM_SealInit(); | ||
| 460 | void PEM_SealUpdate(); | ||
| 461 | int PEM_SealFinal(); | ||
| 462 | int PEM_SignFinal(); | ||
| 463 | 574 | ||
| 464 | void ERR_load_PEM_strings(); | 575 | #ifndef OPENSSL_NO_DH |
| 465 | 576 | ||
| 466 | void PEM_proc_type(); | 577 | DECLARE_PEM_rw(DHparams, DH) |
| 467 | void PEM_dek_info(); | ||
| 468 | 578 | ||
| 469 | #ifndef SSLEAY_MACROS | ||
| 470 | #ifndef WIN16 | ||
| 471 | X509 *PEM_read_X509(); | ||
| 472 | X509_REQ *PEM_read_X509_REQ(); | ||
| 473 | X509_CRL *PEM_read_X509_CRL(); | ||
| 474 | RSA *PEM_read_RSAPrivateKey(); | ||
| 475 | RSA *PEM_read_RSAPublicKey(); | ||
| 476 | DSA *PEM_read_DSAPrivateKey(); | ||
| 477 | EVP_PKEY *PEM_read_PrivateKey(); | ||
| 478 | PKCS7 *PEM_read_PKCS7(); | ||
| 479 | DH *PEM_read_DHparams(); | ||
| 480 | DSA *PEM_read_DSAparams(); | ||
| 481 | int PEM_write_X509(); | ||
| 482 | int PEM_write_X509_REQ(); | ||
| 483 | int PEM_write_X509_CRL(); | ||
| 484 | int PEM_write_RSAPrivateKey(); | ||
| 485 | int PEM_write_RSAPublicKey(); | ||
| 486 | int PEM_write_DSAPrivateKey(); | ||
| 487 | int PEM_write_PrivateKey(); | ||
| 488 | int PEM_write_PKCS7(); | ||
| 489 | int PEM_write_DHparams(); | ||
| 490 | int PEM_write_DSAparams(); | ||
| 491 | #endif | 579 | #endif |
| 492 | 580 | ||
| 493 | X509 *PEM_read_bio_X509(); | 581 | DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY) |
| 494 | X509_REQ *PEM_read_bio_X509_REQ(); | 582 | |
| 495 | X509_CRL *PEM_read_bio_X509_CRL(); | 583 | DECLARE_PEM_rw(PUBKEY, EVP_PKEY) |
| 496 | RSA *PEM_read_bio_RSAPrivateKey(); | 584 | |
| 497 | RSA *PEM_read_bio_RSAPublicKey(); | 585 | int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid, |
| 498 | DSA *PEM_read_bio_DSAPrivateKey(); | 586 | char *kstr, int klen, |
| 499 | EVP_PKEY *PEM_read_bio_PrivateKey(); | 587 | pem_password_cb *cb, void *u); |
| 500 | PKCS7 *PEM_read_bio_PKCS7(); | 588 | int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *, |
| 501 | DH *PEM_read_bio_DHparams(); | 589 | char *, int, pem_password_cb *, void *); |
| 502 | DSA *PEM_read_bio_DSAparams(); | 590 | int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc, |
| 503 | int PEM_write_bio_X509(); | 591 | char *kstr, int klen, |
| 504 | int PEM_write_bio_X509_REQ(); | 592 | pem_password_cb *cb, void *u); |
| 505 | int PEM_write_bio_X509_CRL(); | 593 | int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid, |
| 506 | int PEM_write_bio_RSAPrivateKey(); | 594 | char *kstr, int klen, |
| 507 | int PEM_write_bio_RSAPublicKey(); | 595 | pem_password_cb *cb, void *u); |
| 508 | int PEM_write_bio_DSAPrivateKey(); | 596 | EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u); |
| 509 | int PEM_write_bio_PrivateKey(); | 597 | |
| 510 | int PEM_write_bio_PKCS7(); | 598 | int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc, |
| 511 | int PEM_write_bio_DHparams(); | 599 | char *kstr, int klen, |
| 512 | int PEM_write_bio_DSAparams(); | 600 | pem_password_cb *cb, void *u); |
| 601 | int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid, | ||
| 602 | char *kstr, int klen, | ||
| 603 | pem_password_cb *cb, void *u); | ||
| 604 | int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid, | ||
| 605 | char *kstr, int klen, | ||
| 606 | pem_password_cb *cb, void *u); | ||
| 607 | |||
| 608 | EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u); | ||
| 609 | |||
| 610 | int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc, | ||
| 611 | char *kstr,int klen, pem_password_cb *cd, void *u); | ||
| 513 | 612 | ||
| 514 | #endif /* SSLEAY_MACROS */ | 613 | #endif /* SSLEAY_MACROS */ |
| 515 | 614 | ||
| 516 | #endif | ||
| 517 | 615 | ||
| 518 | /* BEGIN ERROR CODES */ | 616 | /* BEGIN ERROR CODES */ |
| 617 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
| 618 | * made after this point may be overwritten when the script is next run. | ||
| 619 | */ | ||
| 620 | void ERR_load_PEM_strings(void); | ||
| 621 | |||
| 519 | /* Error codes for the PEM functions. */ | 622 | /* Error codes for the PEM functions. */ |
| 520 | 623 | ||
| 521 | /* Function codes. */ | 624 | /* Function codes. */ |
| 625 | #define PEM_F_D2I_PKCS8PRIVATEKEY_BIO 120 | ||
| 626 | #define PEM_F_D2I_PKCS8PRIVATEKEY_FP 121 | ||
| 522 | #define PEM_F_DEF_CALLBACK 100 | 627 | #define PEM_F_DEF_CALLBACK 100 |
| 523 | #define PEM_F_LOAD_IV 101 | 628 | #define PEM_F_LOAD_IV 101 |
| 524 | #define PEM_F_PEM_ASN1_READ 102 | 629 | #define PEM_F_PEM_ASN1_READ 102 |
| @@ -526,6 +631,8 @@ int PEM_write_bio_DSAparams(); | |||
| 526 | #define PEM_F_PEM_ASN1_WRITE 104 | 631 | #define PEM_F_PEM_ASN1_WRITE 104 |
| 527 | #define PEM_F_PEM_ASN1_WRITE_BIO 105 | 632 | #define PEM_F_PEM_ASN1_WRITE_BIO 105 |
| 528 | #define PEM_F_PEM_DO_HEADER 106 | 633 | #define PEM_F_PEM_DO_HEADER 106 |
| 634 | #define PEM_F_PEM_F_DO_PK8KEY_FP 122 | ||
| 635 | #define PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY 118 | ||
| 529 | #define PEM_F_PEM_GET_EVP_CIPHER_INFO 107 | 636 | #define PEM_F_PEM_GET_EVP_CIPHER_INFO 107 |
| 530 | #define PEM_F_PEM_READ 108 | 637 | #define PEM_F_PEM_READ 108 |
| 531 | #define PEM_F_PEM_READ_BIO 109 | 638 | #define PEM_F_PEM_READ_BIO 109 |
| @@ -534,6 +641,7 @@ int PEM_write_bio_DSAparams(); | |||
| 534 | #define PEM_F_PEM_SIGNFINAL 112 | 641 | #define PEM_F_PEM_SIGNFINAL 112 |
| 535 | #define PEM_F_PEM_WRITE 113 | 642 | #define PEM_F_PEM_WRITE 113 |
| 536 | #define PEM_F_PEM_WRITE_BIO 114 | 643 | #define PEM_F_PEM_WRITE_BIO 114 |
| 644 | #define PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY 119 | ||
| 537 | #define PEM_F_PEM_X509_INFO_READ 115 | 645 | #define PEM_F_PEM_X509_INFO_READ 115 |
| 538 | #define PEM_F_PEM_X509_INFO_READ_BIO 116 | 646 | #define PEM_F_PEM_X509_INFO_READ_BIO 116 |
| 539 | #define PEM_F_PEM_X509_INFO_WRITE_BIO 117 | 647 | #define PEM_F_PEM_X509_INFO_WRITE_BIO 117 |
| @@ -544,6 +652,7 @@ int PEM_write_bio_DSAparams(); | |||
| 544 | #define PEM_R_BAD_END_LINE 102 | 652 | #define PEM_R_BAD_END_LINE 102 |
| 545 | #define PEM_R_BAD_IV_CHARS 103 | 653 | #define PEM_R_BAD_IV_CHARS 103 |
| 546 | #define PEM_R_BAD_PASSWORD_READ 104 | 654 | #define PEM_R_BAD_PASSWORD_READ 104 |
| 655 | #define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 115 | ||
| 547 | #define PEM_R_NOT_DEK_INFO 105 | 656 | #define PEM_R_NOT_DEK_INFO 105 |
| 548 | #define PEM_R_NOT_ENCRYPTED 106 | 657 | #define PEM_R_NOT_ENCRYPTED 106 |
| 549 | #define PEM_R_NOT_PROC_TYPE 107 | 658 | #define PEM_R_NOT_PROC_TYPE 107 |
| @@ -554,9 +663,8 @@ int PEM_write_bio_DSAparams(); | |||
| 554 | #define PEM_R_SHORT_HEADER 112 | 663 | #define PEM_R_SHORT_HEADER 112 |
| 555 | #define PEM_R_UNSUPPORTED_CIPHER 113 | 664 | #define PEM_R_UNSUPPORTED_CIPHER 113 |
| 556 | #define PEM_R_UNSUPPORTED_ENCRYPTION 114 | 665 | #define PEM_R_UNSUPPORTED_ENCRYPTION 114 |
| 557 | 666 | ||
| 558 | #ifdef __cplusplus | 667 | #ifdef __cplusplus |
| 559 | } | 668 | } |
| 560 | #endif | 669 | #endif |
| 561 | #endif | 670 | #endif |
| 562 | |||
diff --git a/src/lib/libcrypto/pem/pem2.h b/src/lib/libcrypto/pem/pem2.h index 4a016aacd2..4e484bcd82 100644 --- a/src/lib/libcrypto/pem/pem2.h +++ b/src/lib/libcrypto/pem/pem2.h | |||
| @@ -57,4 +57,12 @@ | |||
| 57 | * Ben 30 Jan 1999. | 57 | * Ben 30 Jan 1999. |
| 58 | */ | 58 | */ |
| 59 | 59 | ||
| 60 | #ifdef __cplusplus | ||
| 61 | extern "C" { | ||
| 62 | #endif | ||
| 63 | |||
| 60 | void ERR_load_PEM_strings(void); | 64 | void ERR_load_PEM_strings(void); |
| 65 | |||
| 66 | #ifdef __cplusplus | ||
| 67 | } | ||
| 68 | #endif | ||
diff --git a/src/lib/libcrypto/pem/pem_all.c b/src/lib/libcrypto/pem/pem_all.c index d1cda7aabe..e72b7134ce 100644 --- a/src/lib/libcrypto/pem/pem_all.c +++ b/src/lib/libcrypto/pem/pem_all.c | |||
| @@ -59,430 +59,138 @@ | |||
| 59 | #include <stdio.h> | 59 | #include <stdio.h> |
| 60 | #undef SSLEAY_MACROS | 60 | #undef SSLEAY_MACROS |
| 61 | #include "cryptlib.h" | 61 | #include "cryptlib.h" |
| 62 | #include "bio.h" | 62 | #include <openssl/bio.h> |
| 63 | #include "evp.h" | 63 | #include <openssl/evp.h> |
| 64 | #include "x509.h" | 64 | #include <openssl/x509.h> |
| 65 | #include "pkcs7.h" | 65 | #include <openssl/pkcs7.h> |
| 66 | #include "pem.h" | 66 | #include <openssl/pem.h> |
| 67 | |||
| 68 | #ifndef NO_FP_API | ||
| 69 | /* The X509 functions */ | ||
| 70 | X509 *PEM_read_X509(fp,x,cb) | ||
| 71 | FILE *fp; | ||
| 72 | X509 **x; | ||
| 73 | int (*cb)(); | ||
| 74 | { | ||
| 75 | return((X509 *)PEM_ASN1_read((char *(*)())d2i_X509, | ||
| 76 | PEM_STRING_X509,fp,(char **)x,cb)); | ||
| 77 | } | ||
| 78 | #endif | ||
| 79 | |||
| 80 | X509 *PEM_read_bio_X509(bp,x,cb) | ||
| 81 | BIO *bp; | ||
| 82 | X509 **x; | ||
| 83 | int (*cb)(); | ||
| 84 | { | ||
| 85 | return((X509 *)PEM_ASN1_read_bio((char *(*)())d2i_X509, | ||
| 86 | PEM_STRING_X509,bp,(char **)x,cb)); | ||
| 87 | } | ||
| 88 | 67 | ||
| 89 | #ifndef NO_FP_API | 68 | #ifndef OPENSSL_NO_RSA |
| 90 | int PEM_write_X509(fp,x) | 69 | static RSA *pkey_get_rsa(EVP_PKEY *key, RSA **rsa); |
| 91 | FILE *fp; | ||
| 92 | X509 *x; | ||
| 93 | { | ||
| 94 | return(PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, | ||
| 95 | (char *)x, NULL,NULL,0,NULL)); | ||
| 96 | } | ||
| 97 | #endif | 70 | #endif |
| 98 | 71 | #ifndef OPENSSL_NO_DSA | |
| 99 | int PEM_write_bio_X509(bp,x) | 72 | static DSA *pkey_get_dsa(EVP_PKEY *key, DSA **dsa); |
| 100 | BIO *bp; | ||
| 101 | X509 *x; | ||
| 102 | { | ||
| 103 | return(PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, | ||
| 104 | (char *)x, NULL,NULL,0,NULL)); | ||
| 105 | } | ||
| 106 | |||
| 107 | #ifndef NO_FP_API | ||
| 108 | /* The X509_REQ functions */ | ||
| 109 | X509_REQ *PEM_read_X509_REQ(fp,x,cb) | ||
| 110 | FILE *fp; | ||
| 111 | X509_REQ **x; | ||
| 112 | int (*cb)(); | ||
| 113 | { | ||
| 114 | return((X509_REQ *)PEM_ASN1_read((char *(*)())d2i_X509_REQ, | ||
| 115 | PEM_STRING_X509_REQ,fp,(char **)x,cb)); | ||
| 116 | } | ||
| 117 | #endif | 73 | #endif |
| 118 | 74 | ||
| 119 | X509_REQ *PEM_read_bio_X509_REQ(bp,x,cb) | 75 | IMPLEMENT_PEM_rw(X509_REQ, X509_REQ, PEM_STRING_X509_REQ, X509_REQ) |
| 120 | BIO *bp; | ||
| 121 | X509_REQ **x; | ||
| 122 | int (*cb)(); | ||
| 123 | { | ||
| 124 | return((X509_REQ *)PEM_ASN1_read_bio((char *(*)())d2i_X509_REQ, | ||
| 125 | PEM_STRING_X509_REQ,bp,(char **)x,cb)); | ||
| 126 | } | ||
| 127 | 76 | ||
| 128 | #ifndef NO_FP_API | 77 | IMPLEMENT_PEM_write(X509_REQ_NEW, X509_REQ, PEM_STRING_X509_REQ_OLD, X509_REQ) |
| 129 | int PEM_write_X509_REQ(fp,x) | ||
| 130 | FILE *fp; | ||
| 131 | X509_REQ *x; | ||
| 132 | { | ||
| 133 | return(PEM_ASN1_write((int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp, | ||
| 134 | (char *)x, NULL,NULL,0,NULL)); | ||
| 135 | } | ||
| 136 | #endif | ||
| 137 | 78 | ||
| 138 | int PEM_write_bio_X509_REQ(bp,x) | 79 | IMPLEMENT_PEM_rw(X509_CRL, X509_CRL, PEM_STRING_X509_CRL, X509_CRL) |
| 139 | BIO *bp; | ||
| 140 | X509_REQ *x; | ||
| 141 | { | ||
| 142 | return(PEM_ASN1_write_bio((int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ, | ||
| 143 | bp,(char *)x, NULL,NULL,0,NULL)); | ||
| 144 | } | ||
| 145 | 80 | ||
| 146 | #ifndef NO_FP_API | 81 | IMPLEMENT_PEM_rw(PKCS7, PKCS7, PEM_STRING_PKCS7, PKCS7) |
| 147 | /* The X509_CRL functions */ | ||
| 148 | X509_CRL *PEM_read_X509_CRL(fp,x,cb) | ||
| 149 | FILE *fp; | ||
| 150 | X509_CRL **x; | ||
| 151 | int (*cb)(); | ||
| 152 | { | ||
| 153 | return((X509_CRL *)PEM_ASN1_read((char *(*)())d2i_X509_CRL, | ||
| 154 | PEM_STRING_X509_CRL,fp,(char **)x,cb)); | ||
| 155 | } | ||
| 156 | #endif | ||
| 157 | 82 | ||
| 158 | X509_CRL *PEM_read_bio_X509_CRL(bp,x,cb) | 83 | IMPLEMENT_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE, |
| 159 | BIO *bp; | 84 | PEM_STRING_X509, NETSCAPE_CERT_SEQUENCE) |
| 160 | X509_CRL **x; | ||
| 161 | int (*cb)(); | ||
| 162 | { | ||
| 163 | return((X509_CRL *)PEM_ASN1_read_bio((char *(*)())d2i_X509_CRL, | ||
| 164 | PEM_STRING_X509_CRL,bp,(char **)x,cb)); | ||
| 165 | } | ||
| 166 | 85 | ||
| 167 | #ifndef NO_FP_API | ||
| 168 | int PEM_write_X509_CRL(fp,x) | ||
| 169 | FILE *fp; | ||
| 170 | X509_CRL *x; | ||
| 171 | { | ||
| 172 | return(PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,fp, | ||
| 173 | (char *)x, NULL,NULL,0,NULL)); | ||
| 174 | } | ||
| 175 | #endif | ||
| 176 | |||
| 177 | int PEM_write_bio_X509_CRL(bp,x) | ||
| 178 | BIO *bp; | ||
| 179 | X509_CRL *x; | ||
| 180 | { | ||
| 181 | return(PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, | ||
| 182 | bp,(char *)x, NULL,NULL,0,NULL)); | ||
| 183 | } | ||
| 184 | 86 | ||
| 185 | #ifndef NO_RSA | 87 | #ifndef OPENSSL_NO_RSA |
| 186 | #ifndef NO_FP_API | ||
| 187 | /* The RSAPrivateKey functions */ | ||
| 188 | RSA *PEM_read_RSAPrivateKey(fp,x,cb) | ||
| 189 | FILE *fp; | ||
| 190 | RSA **x; | ||
| 191 | int (*cb)(); | ||
| 192 | { | ||
| 193 | return((RSA *)PEM_ASN1_read((char *(*)())d2i_RSAPrivateKey, | ||
| 194 | PEM_STRING_RSA,fp,(char **)x,cb)); | ||
| 195 | } | ||
| 196 | |||
| 197 | RSA *PEM_read_RSAPublicKey(fp,x,cb) | ||
| 198 | FILE *fp; | ||
| 199 | RSA **x; | ||
| 200 | int (*cb)(); | ||
| 201 | { | ||
| 202 | return((RSA *)PEM_ASN1_read((char *(*)())d2i_RSAPublicKey, | ||
| 203 | PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb)); | ||
| 204 | } | ||
| 205 | #endif | ||
| 206 | 88 | ||
| 207 | RSA *PEM_read_bio_RSAPrivateKey(bp,x,cb) | 89 | /* We treat RSA or DSA private keys as a special case. |
| 208 | BIO *bp; | 90 | * |
| 209 | RSA **x; | 91 | * For private keys we read in an EVP_PKEY structure with |
| 210 | int (*cb)(); | 92 | * PEM_read_bio_PrivateKey() and extract the relevant private |
| 211 | { | 93 | * key: this means can handle "traditional" and PKCS#8 formats |
| 212 | return((RSA *)PEM_ASN1_read_bio((char *(*)())d2i_RSAPrivateKey, | 94 | * transparently. |
| 213 | PEM_STRING_RSA,bp,(char **)x,cb)); | 95 | */ |
| 214 | } | ||
| 215 | 96 | ||
| 216 | RSA *PEM_read_bio_RSAPublicKey(bp,x,cb) | 97 | static RSA *pkey_get_rsa(EVP_PKEY *key, RSA **rsa) |
| 217 | BIO *bp; | 98 | { |
| 218 | RSA **x; | 99 | RSA *rtmp; |
| 219 | int (*cb)(); | 100 | if(!key) return NULL; |
| 220 | { | 101 | rtmp = EVP_PKEY_get1_RSA(key); |
| 221 | return((RSA *)PEM_ASN1_read_bio((char *(*)())d2i_RSAPublicKey, | 102 | EVP_PKEY_free(key); |
| 222 | PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb)); | 103 | if(!rtmp) return NULL; |
| 104 | if(rsa) { | ||
| 105 | RSA_free(*rsa); | ||
| 106 | *rsa = rtmp; | ||
| 223 | } | 107 | } |
| 108 | return rtmp; | ||
| 109 | } | ||
| 224 | 110 | ||
| 225 | #ifndef NO_FP_API | 111 | RSA *PEM_read_bio_RSAPrivateKey(BIO *bp, RSA **rsa, pem_password_cb *cb, |
| 226 | int PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb) | 112 | void *u) |
| 227 | FILE *fp; | 113 | { |
| 228 | RSA *x; | 114 | EVP_PKEY *pktmp; |
| 229 | EVP_CIPHER *enc; | 115 | pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u); |
| 230 | unsigned char *kstr; | 116 | return pkey_get_rsa(pktmp, rsa); |
| 231 | int klen; | 117 | } |
| 232 | int (*cb)(); | ||
| 233 | { | ||
| 234 | return(PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp, | ||
| 235 | (char *)x,enc,kstr,klen,cb)); | ||
| 236 | } | ||
| 237 | 118 | ||
| 238 | int PEM_write_RSAPublicKey(fp,x) | 119 | #ifndef OPENSSL_NO_FP_API |
| 239 | FILE *fp; | ||
| 240 | RSA *x; | ||
| 241 | { | ||
| 242 | return(PEM_ASN1_write((int (*)())i2d_RSAPublicKey, | ||
| 243 | PEM_STRING_RSA_PUBLIC,fp, | ||
| 244 | (char *)x,NULL,NULL,0,NULL)); | ||
| 245 | } | ||
| 246 | #endif | ||
| 247 | 120 | ||
| 248 | int PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb) | 121 | RSA *PEM_read_RSAPrivateKey(FILE *fp, RSA **rsa, pem_password_cb *cb, |
| 249 | BIO *bp; | 122 | void *u) |
| 250 | RSA *x; | 123 | { |
| 251 | EVP_CIPHER *enc; | 124 | EVP_PKEY *pktmp; |
| 252 | unsigned char *kstr; | 125 | pktmp = PEM_read_PrivateKey(fp, NULL, cb, u); |
| 253 | int klen; | 126 | return pkey_get_rsa(pktmp, rsa); |
| 254 | int (*cb)(); | 127 | } |
| 255 | { | ||
| 256 | return(PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA, | ||
| 257 | bp,(char *)x,enc,kstr,klen,cb)); | ||
| 258 | } | ||
| 259 | 128 | ||
| 260 | int PEM_write_bio_RSAPublicKey(bp,x) | ||
| 261 | BIO *bp; | ||
| 262 | RSA *x; | ||
| 263 | { | ||
| 264 | return(PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, | ||
| 265 | PEM_STRING_RSA_PUBLIC, | ||
| 266 | bp,(char *)x,NULL,NULL,0,NULL)); | ||
| 267 | } | ||
| 268 | #endif /* !NO_RSA */ | ||
| 269 | |||
| 270 | #ifndef NO_DSA | ||
| 271 | #ifndef NO_FP_API | ||
| 272 | /* The DSAPrivateKey functions */ | ||
| 273 | DSA *PEM_read_DSAPrivateKey(fp,x,cb) | ||
| 274 | FILE *fp; | ||
| 275 | DSA **x; | ||
| 276 | int (*cb)(); | ||
| 277 | { | ||
| 278 | return((DSA *)PEM_ASN1_read((char *(*)())d2i_DSAPrivateKey, | ||
| 279 | PEM_STRING_DSA,fp,(char **)x,cb)); | ||
| 280 | } | ||
| 281 | #endif | 129 | #endif |
| 282 | 130 | ||
| 283 | DSA *PEM_read_bio_DSAPrivateKey(bp,x,cb) | 131 | IMPLEMENT_PEM_write_cb(RSAPrivateKey, RSA, PEM_STRING_RSA, RSAPrivateKey) |
| 284 | BIO *bp; | 132 | IMPLEMENT_PEM_rw(RSAPublicKey, RSA, PEM_STRING_RSA_PUBLIC, RSAPublicKey) |
| 285 | DSA **x; | 133 | IMPLEMENT_PEM_rw(RSA_PUBKEY, RSA, PEM_STRING_PUBLIC, RSA_PUBKEY) |
| 286 | int (*cb)(); | ||
| 287 | { | ||
| 288 | return((DSA *)PEM_ASN1_read_bio((char *(*)())d2i_DSAPrivateKey, | ||
| 289 | PEM_STRING_DSA,bp,(char **)x,cb)); | ||
| 290 | } | ||
| 291 | |||
| 292 | #ifndef NO_FP_API | ||
| 293 | int PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb) | ||
| 294 | FILE *fp; | ||
| 295 | DSA *x; | ||
| 296 | EVP_CIPHER *enc; | ||
| 297 | unsigned char *kstr; | ||
| 298 | int klen; | ||
| 299 | int (*cb)(); | ||
| 300 | { | ||
| 301 | return(PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp, | ||
| 302 | (char *)x,enc,kstr,klen,cb)); | ||
| 303 | } | ||
| 304 | #endif | ||
| 305 | 134 | ||
| 306 | int PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb) | ||
| 307 | BIO *bp; | ||
| 308 | DSA *x; | ||
| 309 | EVP_CIPHER *enc; | ||
| 310 | unsigned char *kstr; | ||
| 311 | int klen; | ||
| 312 | int (*cb)(); | ||
| 313 | { | ||
| 314 | return(PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA, | ||
| 315 | bp,(char *)x,enc,kstr,klen,cb)); | ||
| 316 | } | ||
| 317 | #endif | 135 | #endif |
| 318 | 136 | ||
| 319 | #ifndef NO_FP_API | 137 | #ifndef OPENSSL_NO_DSA |
| 320 | /* The PrivateKey functions */ | ||
| 321 | EVP_PKEY *PEM_read_PrivateKey(fp,x,cb) | ||
| 322 | FILE *fp; | ||
| 323 | EVP_PKEY **x; | ||
| 324 | int (*cb)(); | ||
| 325 | { | ||
| 326 | return((EVP_PKEY *)PEM_ASN1_read((char *(*)())d2i_PrivateKey, | ||
| 327 | PEM_STRING_EVP_PKEY,fp,(char **)x,cb)); | ||
| 328 | } | ||
| 329 | #endif | ||
| 330 | 138 | ||
| 331 | EVP_PKEY *PEM_read_bio_PrivateKey(bp,x,cb) | 139 | static DSA *pkey_get_dsa(EVP_PKEY *key, DSA **dsa) |
| 332 | BIO *bp; | 140 | { |
| 333 | EVP_PKEY **x; | 141 | DSA *dtmp; |
| 334 | int (*cb)(); | 142 | if(!key) return NULL; |
| 335 | { | 143 | dtmp = EVP_PKEY_get1_DSA(key); |
| 336 | return((EVP_PKEY *)PEM_ASN1_read_bio((char *(*)())d2i_PrivateKey, | 144 | EVP_PKEY_free(key); |
| 337 | PEM_STRING_EVP_PKEY,bp,(char **)x,cb)); | 145 | if(!dtmp) return NULL; |
| 146 | if(dsa) { | ||
| 147 | DSA_free(*dsa); | ||
| 148 | *dsa = dtmp; | ||
| 338 | } | 149 | } |
| 150 | return dtmp; | ||
| 151 | } | ||
| 339 | 152 | ||
| 340 | #ifndef NO_FP_API | 153 | DSA *PEM_read_bio_DSAPrivateKey(BIO *bp, DSA **dsa, pem_password_cb *cb, |
| 341 | int PEM_write_PrivateKey(fp,x,enc,kstr,klen,cb) | 154 | void *u) |
| 342 | FILE *fp; | 155 | { |
| 343 | EVP_PKEY *x; | 156 | EVP_PKEY *pktmp; |
| 344 | EVP_CIPHER *enc; | 157 | pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u); |
| 345 | unsigned char *kstr; | 158 | return pkey_get_dsa(pktmp, dsa); |
| 346 | int klen; | 159 | } |
| 347 | int (*cb)(); | ||
| 348 | { | ||
| 349 | return(PEM_ASN1_write((int (*)())i2d_PrivateKey, | ||
| 350 | ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA), | ||
| 351 | fp,(char *)x,enc,kstr,klen,cb)); | ||
| 352 | } | ||
| 353 | #endif | ||
| 354 | 160 | ||
| 355 | int PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb) | 161 | IMPLEMENT_PEM_write_cb(DSAPrivateKey, DSA, PEM_STRING_DSA, DSAPrivateKey) |
| 356 | BIO *bp; | 162 | IMPLEMENT_PEM_rw(DSA_PUBKEY, DSA, PEM_STRING_PUBLIC, DSA_PUBKEY) |
| 357 | EVP_PKEY *x; | ||
| 358 | EVP_CIPHER *enc; | ||
| 359 | unsigned char *kstr; | ||
| 360 | int klen; | ||
| 361 | int (*cb)(); | ||
| 362 | { | ||
| 363 | return(PEM_ASN1_write_bio((int (*)())i2d_PrivateKey, | ||
| 364 | ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA), | ||
| 365 | bp,(char *)x,enc,kstr,klen,cb)); | ||
| 366 | } | ||
| 367 | 163 | ||
| 368 | #ifndef NO_FP_API | 164 | #ifndef OPENSSL_NO_FP_API |
| 369 | /* The PKCS7 functions */ | ||
| 370 | PKCS7 *PEM_read_PKCS7(fp,x,cb) | ||
| 371 | FILE *fp; | ||
| 372 | PKCS7 **x; | ||
| 373 | int (*cb)(); | ||
| 374 | { | ||
| 375 | return((PKCS7 *)PEM_ASN1_read((char *(*)())d2i_PKCS7, | ||
| 376 | PEM_STRING_PKCS7,fp,(char **)x,cb)); | ||
| 377 | } | ||
| 378 | #endif | ||
| 379 | 165 | ||
| 380 | PKCS7 *PEM_read_bio_PKCS7(bp,x,cb) | 166 | DSA *PEM_read_DSAPrivateKey(FILE *fp, DSA **dsa, pem_password_cb *cb, |
| 381 | BIO *bp; | 167 | void *u) |
| 382 | PKCS7 **x; | 168 | { |
| 383 | int (*cb)(); | 169 | EVP_PKEY *pktmp; |
| 384 | { | 170 | pktmp = PEM_read_PrivateKey(fp, NULL, cb, u); |
| 385 | return((PKCS7 *)PEM_ASN1_read_bio((char *(*)())d2i_PKCS7, | 171 | return pkey_get_dsa(pktmp, dsa); |
| 386 | PEM_STRING_PKCS7,bp,(char **)x,cb)); | 172 | } |
| 387 | } | ||
| 388 | 173 | ||
| 389 | #ifndef NO_FP_API | ||
| 390 | int PEM_write_PKCS7(fp,x) | ||
| 391 | FILE *fp; | ||
| 392 | PKCS7 *x; | ||
| 393 | { | ||
| 394 | return(PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, | ||
| 395 | (char *)x, NULL,NULL,0,NULL)); | ||
| 396 | } | ||
| 397 | #endif | 174 | #endif |
| 398 | 175 | ||
| 399 | int PEM_write_bio_PKCS7(bp,x) | 176 | IMPLEMENT_PEM_rw(DSAparams, DSA, PEM_STRING_DSAPARAMS, DSAparams) |
| 400 | BIO *bp; | ||
| 401 | PKCS7 *x; | ||
| 402 | { | ||
| 403 | return(PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, | ||
| 404 | (char *)x, NULL,NULL,0,NULL)); | ||
| 405 | } | ||
| 406 | 177 | ||
| 407 | #ifndef NO_DH | ||
| 408 | #ifndef NO_FP_API | ||
| 409 | /* The DHparams functions */ | ||
| 410 | DH *PEM_read_DHparams(fp,x,cb) | ||
| 411 | FILE *fp; | ||
| 412 | DH **x; | ||
| 413 | int (*cb)(); | ||
| 414 | { | ||
| 415 | return((DH *)PEM_ASN1_read((char *(*)())d2i_DHparams, | ||
| 416 | PEM_STRING_DHPARAMS,fp,(char **)x,cb)); | ||
| 417 | } | ||
| 418 | #endif | 178 | #endif |
| 419 | 179 | ||
| 420 | DH *PEM_read_bio_DHparams(bp,x,cb) | 180 | #ifndef OPENSSL_NO_DH |
| 421 | BIO *bp; | ||
| 422 | DH **x; | ||
| 423 | int (*cb)(); | ||
| 424 | { | ||
| 425 | return((DH *)PEM_ASN1_read_bio((char *(*)())d2i_DHparams, | ||
| 426 | PEM_STRING_DHPARAMS,bp,(char **)x,cb)); | ||
| 427 | } | ||
| 428 | 181 | ||
| 429 | #ifndef NO_FP_API | 182 | IMPLEMENT_PEM_rw(DHparams, DH, PEM_STRING_DHPARAMS, DHparams) |
| 430 | int PEM_write_DHparams(fp,x) | ||
| 431 | FILE *fp; | ||
| 432 | DH *x; | ||
| 433 | { | ||
| 434 | return(PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp, | ||
| 435 | (char *)x, NULL,NULL,0,NULL)); | ||
| 436 | } | ||
| 437 | #endif | ||
| 438 | 183 | ||
| 439 | int PEM_write_bio_DHparams(bp,x) | ||
| 440 | BIO *bp; | ||
| 441 | DH *x; | ||
| 442 | { | ||
| 443 | return(PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS, | ||
| 444 | bp,(char *)x, NULL,NULL,0,NULL)); | ||
| 445 | } | ||
| 446 | #endif | 184 | #endif |
| 447 | 185 | ||
| 448 | #ifndef NO_DSA | ||
| 449 | #ifndef NO_FP_API | ||
| 450 | /* The DSAparams functions */ | ||
| 451 | DSA *PEM_read_DSAparams(fp,x,cb) | ||
| 452 | FILE *fp; | ||
| 453 | DSA **x; | ||
| 454 | int (*cb)(); | ||
| 455 | { | ||
| 456 | return((DSA *)PEM_ASN1_read((char *(*)())d2i_DSAparams, | ||
| 457 | PEM_STRING_DSAPARAMS,fp,(char **)x,cb)); | ||
| 458 | } | ||
| 459 | #endif | ||
| 460 | 186 | ||
| 461 | DSA *PEM_read_bio_DSAparams(bp,x,cb) | 187 | /* The PrivateKey case is not that straightforward. |
| 462 | BIO *bp; | 188 | * IMPLEMENT_PEM_rw_cb(PrivateKey, EVP_PKEY, PEM_STRING_EVP_PKEY, PrivateKey) |
| 463 | DSA **x; | 189 | * does not work, RSA and DSA keys have specific strings. |
| 464 | int (*cb)(); | 190 | * (When reading, parameter PEM_STRING_EVP_PKEY is a wildcard for anything |
| 465 | { | 191 | * appropriate.) |
| 466 | return((DSA *)PEM_ASN1_read_bio((char *(*)())d2i_DSAparams, | 192 | */ |
| 467 | PEM_STRING_DSAPARAMS,bp,(char **)x,cb)); | 193 | IMPLEMENT_PEM_write_cb(PrivateKey, EVP_PKEY, ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA), PrivateKey) |
| 468 | } | ||
| 469 | |||
| 470 | #ifndef NO_FP_API | ||
| 471 | int PEM_write_DSAparams(fp,x) | ||
| 472 | FILE *fp; | ||
| 473 | DSA *x; | ||
| 474 | { | ||
| 475 | return(PEM_ASN1_write((int (*)())i2d_DSAparams,PEM_STRING_DSAPARAMS,fp, | ||
| 476 | (char *)x, NULL,NULL,0,NULL)); | ||
| 477 | } | ||
| 478 | #endif | ||
| 479 | 194 | ||
| 480 | int PEM_write_bio_DSAparams(bp,x) | 195 | IMPLEMENT_PEM_rw(PUBKEY, EVP_PKEY, PEM_STRING_PUBLIC, PUBKEY) |
| 481 | BIO *bp; | ||
| 482 | DSA *x; | ||
| 483 | { | ||
| 484 | return(PEM_ASN1_write_bio((int (*)())i2d_DSAparams,PEM_STRING_DSAPARAMS, | ||
| 485 | bp,(char *)x, NULL,NULL,0,NULL)); | ||
| 486 | } | ||
| 487 | #endif | ||
| 488 | 196 | ||
diff --git a/src/lib/libcrypto/pem/pem_err.c b/src/lib/libcrypto/pem/pem_err.c index e17fcdb540..3b39b84d66 100644 --- a/src/lib/libcrypto/pem/pem_err.c +++ b/src/lib/libcrypto/pem/pem_err.c | |||
| @@ -1,68 +1,73 @@ | |||
| 1 | /* lib/pem/pem_err.c */ | 1 | /* crypto/pem/pem_err.c */ |
| 2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) | 2 | /* ==================================================================== |
| 3 | * All rights reserved. | 3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. |
| 4 | * | 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 | 5 | * Redistribution and use in source and binary forms, with or without |
| 24 | * modification, are permitted provided that the following conditions | 6 | * modification, are permitted provided that the following conditions |
| 25 | * are met: | 7 | * are met: |
| 26 | * 1. Redistributions of source code must retain the copyright | 8 | * |
| 27 | * notice, this list of conditions and the following disclaimer. | 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
| 29 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in |
| 30 | * documentation and/or other materials provided with the distribution. | 14 | * the documentation and/or other materials provided with the |
| 31 | * 3. All advertising materials mentioning features or use of this software | 15 | * distribution. |
| 32 | * must display the following acknowledgement: | 16 | * |
| 33 | * "This product includes cryptographic software written by | 17 | * 3. All advertising materials mentioning features or use of this |
| 34 | * Eric Young (eay@cryptsoft.com)" | 18 | * software must display the following acknowledgment: |
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | 19 | * "This product includes software developed by the OpenSSL Project |
| 36 | * being used are not cryptographic related :-). | 20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" |
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 21 | * |
| 38 | * the apps directory (application code) you must include an acknowledgement: | 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to |
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 23 | * endorse or promote products derived from this software without |
| 40 | * | 24 | * prior written permission. For written permission, please contact |
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 25 | * openssl-core@OpenSSL.org. |
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 26 | * |
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 27 | * 5. Products derived from this software may not be called "OpenSSL" |
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | 28 | * nor may "OpenSSL" appear in their names without prior written |
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 29 | * permission of the OpenSSL Project. |
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 30 | * |
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 31 | * 6. Redistributions of any form whatsoever must retain the following |
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 32 | * acknowledgment: |
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 33 | * "This product includes software developed by the OpenSSL Project |
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" |
| 51 | * SUCH DAMAGE. | 35 | * |
| 52 | * | 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY |
| 53 | * The licence and distribution terms for any publically available version or | 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 55 | * copied and put under another distribution licence | 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR |
| 56 | * [including the GNU Public Licence.] | 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | * This product includes cryptographic software written by Eric Young | ||
| 51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 52 | * Hudson (tjh@cryptsoft.com). | ||
| 53 | * | ||
| 57 | */ | 54 | */ |
| 55 | |||
| 56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
| 57 | * made to it will be overwritten when the script next updates this file, | ||
| 58 | * only reason strings will be preserved. | ||
| 59 | */ | ||
| 60 | |||
| 58 | #include <stdio.h> | 61 | #include <stdio.h> |
| 59 | #include "err.h" | 62 | #include <openssl/err.h> |
| 60 | #include "pem.h" | 63 | #include <openssl/pem.h> |
| 61 | 64 | ||
| 62 | /* BEGIN ERROR CODES */ | 65 | /* BEGIN ERROR CODES */ |
| 63 | #ifndef NO_ERR | 66 | #ifndef OPENSSL_NO_ERR |
| 64 | static ERR_STRING_DATA PEM_str_functs[]= | 67 | static ERR_STRING_DATA PEM_str_functs[]= |
| 65 | { | 68 | { |
| 69 | {ERR_PACK(0,PEM_F_D2I_PKCS8PRIVATEKEY_BIO,0), "d2i_PKCS8PrivateKey_bio"}, | ||
| 70 | {ERR_PACK(0,PEM_F_D2I_PKCS8PRIVATEKEY_FP,0), "d2i_PKCS8PrivateKey_fp"}, | ||
| 66 | {ERR_PACK(0,PEM_F_DEF_CALLBACK,0), "DEF_CALLBACK"}, | 71 | {ERR_PACK(0,PEM_F_DEF_CALLBACK,0), "DEF_CALLBACK"}, |
| 67 | {ERR_PACK(0,PEM_F_LOAD_IV,0), "LOAD_IV"}, | 72 | {ERR_PACK(0,PEM_F_LOAD_IV,0), "LOAD_IV"}, |
| 68 | {ERR_PACK(0,PEM_F_PEM_ASN1_READ,0), "PEM_ASN1_read"}, | 73 | {ERR_PACK(0,PEM_F_PEM_ASN1_READ,0), "PEM_ASN1_read"}, |
| @@ -70,6 +75,8 @@ static ERR_STRING_DATA PEM_str_functs[]= | |||
| 70 | {ERR_PACK(0,PEM_F_PEM_ASN1_WRITE,0), "PEM_ASN1_write"}, | 75 | {ERR_PACK(0,PEM_F_PEM_ASN1_WRITE,0), "PEM_ASN1_write"}, |
| 71 | {ERR_PACK(0,PEM_F_PEM_ASN1_WRITE_BIO,0), "PEM_ASN1_write_bio"}, | 76 | {ERR_PACK(0,PEM_F_PEM_ASN1_WRITE_BIO,0), "PEM_ASN1_write_bio"}, |
| 72 | {ERR_PACK(0,PEM_F_PEM_DO_HEADER,0), "PEM_do_header"}, | 77 | {ERR_PACK(0,PEM_F_PEM_DO_HEADER,0), "PEM_do_header"}, |
| 78 | {ERR_PACK(0,PEM_F_PEM_F_DO_PK8KEY_FP,0), "PEM_F_DO_PK8KEY_FP"}, | ||
| 79 | {ERR_PACK(0,PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY,0), "PEM_F_PEM_WRITE_PKCS8PRIVATEKEY"}, | ||
| 73 | {ERR_PACK(0,PEM_F_PEM_GET_EVP_CIPHER_INFO,0), "PEM_get_EVP_CIPHER_INFO"}, | 80 | {ERR_PACK(0,PEM_F_PEM_GET_EVP_CIPHER_INFO,0), "PEM_get_EVP_CIPHER_INFO"}, |
| 74 | {ERR_PACK(0,PEM_F_PEM_READ,0), "PEM_read"}, | 81 | {ERR_PACK(0,PEM_F_PEM_READ,0), "PEM_read"}, |
| 75 | {ERR_PACK(0,PEM_F_PEM_READ_BIO,0), "PEM_read_bio"}, | 82 | {ERR_PACK(0,PEM_F_PEM_READ_BIO,0), "PEM_read_bio"}, |
| @@ -78,10 +85,11 @@ static ERR_STRING_DATA PEM_str_functs[]= | |||
| 78 | {ERR_PACK(0,PEM_F_PEM_SIGNFINAL,0), "PEM_SignFinal"}, | 85 | {ERR_PACK(0,PEM_F_PEM_SIGNFINAL,0), "PEM_SignFinal"}, |
| 79 | {ERR_PACK(0,PEM_F_PEM_WRITE,0), "PEM_write"}, | 86 | {ERR_PACK(0,PEM_F_PEM_WRITE,0), "PEM_write"}, |
| 80 | {ERR_PACK(0,PEM_F_PEM_WRITE_BIO,0), "PEM_write_bio"}, | 87 | {ERR_PACK(0,PEM_F_PEM_WRITE_BIO,0), "PEM_write_bio"}, |
| 88 | {ERR_PACK(0,PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY,0), "PEM_write_bio_PKCS8PrivateKey"}, | ||
| 81 | {ERR_PACK(0,PEM_F_PEM_X509_INFO_READ,0), "PEM_X509_INFO_read"}, | 89 | {ERR_PACK(0,PEM_F_PEM_X509_INFO_READ,0), "PEM_X509_INFO_read"}, |
| 82 | {ERR_PACK(0,PEM_F_PEM_X509_INFO_READ_BIO,0), "PEM_X509_INFO_read_bio"}, | 90 | {ERR_PACK(0,PEM_F_PEM_X509_INFO_READ_BIO,0), "PEM_X509_INFO_read_bio"}, |
| 83 | {ERR_PACK(0,PEM_F_PEM_X509_INFO_WRITE_BIO,0), "PEM_X509_INFO_write_bio"}, | 91 | {ERR_PACK(0,PEM_F_PEM_X509_INFO_WRITE_BIO,0), "PEM_X509_INFO_write_bio"}, |
| 84 | {0,NULL}, | 92 | {0,NULL} |
| 85 | }; | 93 | }; |
| 86 | 94 | ||
| 87 | static ERR_STRING_DATA PEM_str_reasons[]= | 95 | static ERR_STRING_DATA PEM_str_reasons[]= |
| @@ -91,6 +99,7 @@ static ERR_STRING_DATA PEM_str_reasons[]= | |||
| 91 | {PEM_R_BAD_END_LINE ,"bad end line"}, | 99 | {PEM_R_BAD_END_LINE ,"bad end line"}, |
| 92 | {PEM_R_BAD_IV_CHARS ,"bad iv chars"}, | 100 | {PEM_R_BAD_IV_CHARS ,"bad iv chars"}, |
| 93 | {PEM_R_BAD_PASSWORD_READ ,"bad password read"}, | 101 | {PEM_R_BAD_PASSWORD_READ ,"bad password read"}, |
| 102 | {PEM_R_ERROR_CONVERTING_PRIVATE_KEY ,"error converting private key"}, | ||
| 94 | {PEM_R_NOT_DEK_INFO ,"not dek info"}, | 103 | {PEM_R_NOT_DEK_INFO ,"not dek info"}, |
| 95 | {PEM_R_NOT_ENCRYPTED ,"not encrypted"}, | 104 | {PEM_R_NOT_ENCRYPTED ,"not encrypted"}, |
| 96 | {PEM_R_NOT_PROC_TYPE ,"not proc type"}, | 105 | {PEM_R_NOT_PROC_TYPE ,"not proc type"}, |
| @@ -101,19 +110,19 @@ static ERR_STRING_DATA PEM_str_reasons[]= | |||
| 101 | {PEM_R_SHORT_HEADER ,"short header"}, | 110 | {PEM_R_SHORT_HEADER ,"short header"}, |
| 102 | {PEM_R_UNSUPPORTED_CIPHER ,"unsupported cipher"}, | 111 | {PEM_R_UNSUPPORTED_CIPHER ,"unsupported cipher"}, |
| 103 | {PEM_R_UNSUPPORTED_ENCRYPTION ,"unsupported encryption"}, | 112 | {PEM_R_UNSUPPORTED_ENCRYPTION ,"unsupported encryption"}, |
| 104 | {0,NULL}, | 113 | {0,NULL} |
| 105 | }; | 114 | }; |
| 106 | 115 | ||
| 107 | #endif | 116 | #endif |
| 108 | 117 | ||
| 109 | void ERR_load_PEM_strings() | 118 | void ERR_load_PEM_strings(void) |
| 110 | { | 119 | { |
| 111 | static int init=1; | 120 | static int init=1; |
| 112 | 121 | ||
| 113 | if (init); | 122 | if (init) |
| 114 | {; | 123 | { |
| 115 | init=0; | 124 | init=0; |
| 116 | #ifndef NO_ERR | 125 | #ifndef OPENSSL_NO_ERR |
| 117 | ERR_load_strings(ERR_LIB_PEM,PEM_str_functs); | 126 | ERR_load_strings(ERR_LIB_PEM,PEM_str_functs); |
| 118 | ERR_load_strings(ERR_LIB_PEM,PEM_str_reasons); | 127 | ERR_load_strings(ERR_LIB_PEM,PEM_str_reasons); |
| 119 | #endif | 128 | #endif |
diff --git a/src/lib/libcrypto/pem/pem_info.c b/src/lib/libcrypto/pem/pem_info.c index 4b69833b62..9a6dffb45c 100644 --- a/src/lib/libcrypto/pem/pem_info.c +++ b/src/lib/libcrypto/pem/pem_info.c | |||
| @@ -58,20 +58,17 @@ | |||
| 58 | 58 | ||
| 59 | #include <stdio.h> | 59 | #include <stdio.h> |
| 60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
| 61 | #include "buffer.h" | 61 | #include <openssl/buffer.h> |
| 62 | #include "objects.h" | 62 | #include <openssl/objects.h> |
| 63 | #include "evp.h" | 63 | #include <openssl/evp.h> |
| 64 | #include "x509.h" | 64 | #include <openssl/x509.h> |
| 65 | #include "pem.h" | 65 | #include <openssl/pem.h> |
| 66 | 66 | ||
| 67 | #ifndef NO_FP_API | 67 | #ifndef OPENSSL_NO_FP_API |
| 68 | STACK *PEM_X509_INFO_read(fp,sk,cb) | 68 | STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u) |
| 69 | FILE *fp; | ||
| 70 | STACK *sk; | ||
| 71 | int (*cb)(); | ||
| 72 | { | 69 | { |
| 73 | BIO *b; | 70 | BIO *b; |
| 74 | STACK *ret; | 71 | STACK_OF(X509_INFO) *ret; |
| 75 | 72 | ||
| 76 | if ((b=BIO_new(BIO_s_file())) == NULL) | 73 | if ((b=BIO_new(BIO_s_file())) == NULL) |
| 77 | { | 74 | { |
| @@ -79,29 +76,26 @@ int (*cb)(); | |||
| 79 | return(0); | 76 | return(0); |
| 80 | } | 77 | } |
| 81 | BIO_set_fp(b,fp,BIO_NOCLOSE); | 78 | BIO_set_fp(b,fp,BIO_NOCLOSE); |
| 82 | ret=PEM_X509_INFO_read_bio(b,sk,cb); | 79 | ret=PEM_X509_INFO_read_bio(b,sk,cb,u); |
| 83 | BIO_free(b); | 80 | BIO_free(b); |
| 84 | return(ret); | 81 | return(ret); |
| 85 | } | 82 | } |
| 86 | #endif | 83 | #endif |
| 87 | 84 | ||
| 88 | STACK *PEM_X509_INFO_read_bio(bp,sk,cb) | 85 | STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u) |
| 89 | BIO *bp; | ||
| 90 | STACK *sk; | ||
| 91 | int (*cb)(); | ||
| 92 | { | 86 | { |
| 93 | X509_INFO *xi=NULL; | 87 | X509_INFO *xi=NULL; |
| 94 | char *name=NULL,*header=NULL,**pp; | 88 | char *name=NULL,*header=NULL,**pp; |
| 95 | unsigned char *data=NULL,*p; | 89 | unsigned char *data=NULL,*p; |
| 96 | long len,error=0; | 90 | long len,error=0; |
| 97 | int ok=0; | 91 | int ok=0; |
| 98 | STACK *ret=NULL; | 92 | STACK_OF(X509_INFO) *ret=NULL; |
| 99 | unsigned int i,raw; | 93 | unsigned int i,raw; |
| 100 | char *(*d2i)(); | 94 | char *(*d2i)(); |
| 101 | 95 | ||
| 102 | if (sk == NULL) | 96 | if (sk == NULL) |
| 103 | { | 97 | { |
| 104 | if ((ret=sk_new_null()) == NULL) | 98 | if ((ret=sk_X509_INFO_new_null()) == NULL) |
| 105 | { | 99 | { |
| 106 | PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_MALLOC_FAILURE); | 100 | PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_MALLOC_FAILURE); |
| 107 | goto err; | 101 | goto err; |
| @@ -117,7 +111,7 @@ int (*cb)(); | |||
| 117 | i=PEM_read_bio(bp,&name,&header,&data,&len); | 111 | i=PEM_read_bio(bp,&name,&header,&data,&len); |
| 118 | if (i == 0) | 112 | if (i == 0) |
| 119 | { | 113 | { |
| 120 | error=ERR_GET_REASON(ERR_peek_error()); | 114 | error=ERR_GET_REASON(ERR_peek_last_error()); |
| 121 | if (error == PEM_R_NO_START_LINE) | 115 | if (error == PEM_R_NO_START_LINE) |
| 122 | { | 116 | { |
| 123 | ERR_clear_error(); | 117 | ERR_clear_error(); |
| @@ -132,7 +126,18 @@ start: | |||
| 132 | d2i=(char *(*)())d2i_X509; | 126 | d2i=(char *(*)())d2i_X509; |
| 133 | if (xi->x509 != NULL) | 127 | if (xi->x509 != NULL) |
| 134 | { | 128 | { |
| 135 | if (!sk_push(ret,(char *)xi)) goto err; | 129 | if (!sk_X509_INFO_push(ret,xi)) goto err; |
| 130 | if ((xi=X509_INFO_new()) == NULL) goto err; | ||
| 131 | goto start; | ||
| 132 | } | ||
| 133 | pp=(char **)&(xi->x509); | ||
| 134 | } | ||
| 135 | else if ((strcmp(name,PEM_STRING_X509_TRUSTED) == 0)) | ||
| 136 | { | ||
| 137 | d2i=(char *(*)())d2i_X509_AUX; | ||
| 138 | if (xi->x509 != NULL) | ||
| 139 | { | ||
| 140 | if (!sk_X509_INFO_push(ret,xi)) goto err; | ||
| 136 | if ((xi=X509_INFO_new()) == NULL) goto err; | 141 | if ((xi=X509_INFO_new()) == NULL) goto err; |
| 137 | goto start; | 142 | goto start; |
| 138 | } | 143 | } |
| @@ -143,20 +148,20 @@ start: | |||
| 143 | d2i=(char *(*)())d2i_X509_CRL; | 148 | d2i=(char *(*)())d2i_X509_CRL; |
| 144 | if (xi->crl != NULL) | 149 | if (xi->crl != NULL) |
| 145 | { | 150 | { |
| 146 | if (!sk_push(ret,(char *)xi)) goto err; | 151 | if (!sk_X509_INFO_push(ret,xi)) goto err; |
| 147 | if ((xi=X509_INFO_new()) == NULL) goto err; | 152 | if ((xi=X509_INFO_new()) == NULL) goto err; |
| 148 | goto start; | 153 | goto start; |
| 149 | } | 154 | } |
| 150 | pp=(char **)&(xi->crl); | 155 | pp=(char **)&(xi->crl); |
| 151 | } | 156 | } |
| 152 | else | 157 | else |
| 153 | #ifndef NO_RSA | 158 | #ifndef OPENSSL_NO_RSA |
| 154 | if (strcmp(name,PEM_STRING_RSA) == 0) | 159 | if (strcmp(name,PEM_STRING_RSA) == 0) |
| 155 | { | 160 | { |
| 156 | d2i=(char *(*)())d2i_RSAPrivateKey; | 161 | d2i=(char *(*)())d2i_RSAPrivateKey; |
| 157 | if (xi->x_pkey != NULL) | 162 | if (xi->x_pkey != NULL) |
| 158 | { | 163 | { |
| 159 | if (!sk_push(ret,(char *)xi)) goto err; | 164 | if (!sk_X509_INFO_push(ret,xi)) goto err; |
| 160 | if ((xi=X509_INFO_new()) == NULL) goto err; | 165 | if ((xi=X509_INFO_new()) == NULL) goto err; |
| 161 | goto start; | 166 | goto start; |
| 162 | } | 167 | } |
| @@ -174,13 +179,13 @@ start: | |||
| 174 | } | 179 | } |
| 175 | else | 180 | else |
| 176 | #endif | 181 | #endif |
| 177 | #ifndef NO_DSA | 182 | #ifndef OPENSSL_NO_DSA |
| 178 | if (strcmp(name,PEM_STRING_DSA) == 0) | 183 | if (strcmp(name,PEM_STRING_DSA) == 0) |
| 179 | { | 184 | { |
| 180 | d2i=(char *(*)())d2i_DSAPrivateKey; | 185 | d2i=(char *(*)())d2i_DSAPrivateKey; |
| 181 | if (xi->x_pkey != NULL) | 186 | if (xi->x_pkey != NULL) |
| 182 | { | 187 | { |
| 183 | if (!sk_push(ret,(char *)xi)) goto err; | 188 | if (!sk_X509_INFO_push(ret,xi)) goto err; |
| 184 | if ((xi=X509_INFO_new()) == NULL) goto err; | 189 | if ((xi=X509_INFO_new()) == NULL) goto err; |
| 185 | goto start; | 190 | goto start; |
| 186 | } | 191 | } |
| @@ -211,7 +216,7 @@ start: | |||
| 211 | 216 | ||
| 212 | if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) | 217 | if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) |
| 213 | goto err; | 218 | goto err; |
| 214 | if (!PEM_do_header(&cipher,data,&len,cb)) | 219 | if (!PEM_do_header(&cipher,data,&len,cb,u)) |
| 215 | goto err; | 220 | goto err; |
| 216 | p=data; | 221 | p=data; |
| 217 | if (d2i(pp,&p,len) == NULL) | 222 | if (d2i(pp,&p,len) == NULL) |
| @@ -232,9 +237,9 @@ start: | |||
| 232 | else { | 237 | else { |
| 233 | /* unknown */ | 238 | /* unknown */ |
| 234 | } | 239 | } |
| 235 | if (name != NULL) Free(name); | 240 | if (name != NULL) OPENSSL_free(name); |
| 236 | if (header != NULL) Free(header); | 241 | if (header != NULL) OPENSSL_free(header); |
| 237 | if (data != NULL) Free(data); | 242 | if (data != NULL) OPENSSL_free(data); |
| 238 | name=NULL; | 243 | name=NULL; |
| 239 | header=NULL; | 244 | header=NULL; |
| 240 | data=NULL; | 245 | data=NULL; |
| @@ -246,7 +251,7 @@ start: | |||
| 246 | if ((xi->x509 != NULL) || (xi->crl != NULL) || | 251 | if ((xi->x509 != NULL) || (xi->crl != NULL) || |
| 247 | (xi->x_pkey != NULL) || (xi->enc_data != NULL)) | 252 | (xi->x_pkey != NULL) || (xi->enc_data != NULL)) |
| 248 | { | 253 | { |
| 249 | if (!sk_push(ret,(char *)xi)) goto err; | 254 | if (!sk_X509_INFO_push(ret,xi)) goto err; |
| 250 | xi=NULL; | 255 | xi=NULL; |
| 251 | } | 256 | } |
| 252 | ok=1; | 257 | ok=1; |
| @@ -254,36 +259,30 @@ err: | |||
| 254 | if (xi != NULL) X509_INFO_free(xi); | 259 | if (xi != NULL) X509_INFO_free(xi); |
| 255 | if (!ok) | 260 | if (!ok) |
| 256 | { | 261 | { |
| 257 | for (i=0; ((int)i)<sk_num(ret); i++) | 262 | for (i=0; ((int)i)<sk_X509_INFO_num(ret); i++) |
| 258 | { | 263 | { |
| 259 | xi=(X509_INFO *)sk_value(ret,i); | 264 | xi=sk_X509_INFO_value(ret,i); |
| 260 | X509_INFO_free(xi); | 265 | X509_INFO_free(xi); |
| 261 | } | 266 | } |
| 262 | if (ret != sk) sk_free(ret); | 267 | if (ret != sk) sk_X509_INFO_free(ret); |
| 263 | ret=NULL; | 268 | ret=NULL; |
| 264 | } | 269 | } |
| 265 | 270 | ||
| 266 | if (name != NULL) Free(name); | 271 | if (name != NULL) OPENSSL_free(name); |
| 267 | if (header != NULL) Free(header); | 272 | if (header != NULL) OPENSSL_free(header); |
| 268 | if (data != NULL) Free(data); | 273 | if (data != NULL) OPENSSL_free(data); |
| 269 | return(ret); | 274 | return(ret); |
| 270 | } | 275 | } |
| 271 | 276 | ||
| 272 | 277 | ||
| 273 | /* A TJH addition */ | 278 | /* A TJH addition */ |
| 274 | int PEM_X509_INFO_write_bio(bp,xi,enc,kstr,klen,cb) | 279 | int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc, |
| 275 | BIO *bp; | 280 | unsigned char *kstr, int klen, pem_password_cb *cb, void *u) |
| 276 | X509_INFO *xi; | ||
| 277 | EVP_CIPHER *enc; | ||
| 278 | unsigned char *kstr; | ||
| 279 | int klen; | ||
| 280 | int (*cb)(); | ||
| 281 | { | 281 | { |
| 282 | EVP_CIPHER_CTX ctx; | 282 | EVP_CIPHER_CTX ctx; |
| 283 | int i,ret=0; | 283 | int i,ret=0; |
| 284 | unsigned char *data=NULL; | 284 | unsigned char *data=NULL; |
| 285 | char *objstr=NULL; | 285 | const char *objstr=NULL; |
| 286 | #define PEM_BUFSIZE 1024 | ||
| 287 | char buf[PEM_BUFSIZE]; | 286 | char buf[PEM_BUFSIZE]; |
| 288 | unsigned char *iv=NULL; | 287 | unsigned char *iv=NULL; |
| 289 | 288 | ||
| @@ -306,7 +305,7 @@ int (*cb)(); | |||
| 306 | { | 305 | { |
| 307 | if ( (xi->enc_data!=NULL) && (xi->enc_len>0) ) | 306 | if ( (xi->enc_data!=NULL) && (xi->enc_len>0) ) |
| 308 | { | 307 | { |
| 309 | /* copy from wierdo names into more normal things */ | 308 | /* copy from weirdo names into more normal things */ |
| 310 | iv=xi->enc_cipher.iv; | 309 | iv=xi->enc_cipher.iv; |
| 311 | data=(unsigned char *)xi->enc_data; | 310 | data=(unsigned char *)xi->enc_data; |
| 312 | i=xi->enc_len; | 311 | i=xi->enc_len; |
| @@ -327,7 +326,7 @@ int (*cb)(); | |||
| 327 | /* create the right magic header stuff */ | 326 | /* create the right magic header stuff */ |
| 328 | buf[0]='\0'; | 327 | buf[0]='\0'; |
| 329 | PEM_proc_type(buf,PEM_TYPE_ENCRYPTED); | 328 | PEM_proc_type(buf,PEM_TYPE_ENCRYPTED); |
| 330 | PEM_dek_info(buf,objstr,8,(char *)iv); | 329 | PEM_dek_info(buf,objstr,enc->iv_len,(char *)iv); |
| 331 | 330 | ||
| 332 | /* use the normal code to write things out */ | 331 | /* use the normal code to write things out */ |
| 333 | i=PEM_write_bio(bp,PEM_STRING_RSA,buf,data,i); | 332 | i=PEM_write_bio(bp,PEM_STRING_RSA,buf,data,i); |
| @@ -336,18 +335,18 @@ int (*cb)(); | |||
| 336 | else | 335 | else |
| 337 | { | 336 | { |
| 338 | /* Add DSA/DH */ | 337 | /* Add DSA/DH */ |
| 339 | #ifndef NO_RSA | 338 | #ifndef OPENSSL_NO_RSA |
| 340 | /* normal optionally encrypted stuff */ | 339 | /* normal optionally encrypted stuff */ |
| 341 | if (PEM_write_bio_RSAPrivateKey(bp, | 340 | if (PEM_write_bio_RSAPrivateKey(bp, |
| 342 | xi->x_pkey->dec_pkey->pkey.rsa, | 341 | xi->x_pkey->dec_pkey->pkey.rsa, |
| 343 | enc,kstr,klen,cb)<=0) | 342 | enc,kstr,klen,cb,u)<=0) |
| 344 | goto err; | 343 | goto err; |
| 345 | #endif | 344 | #endif |
| 346 | } | 345 | } |
| 347 | } | 346 | } |
| 348 | 347 | ||
| 349 | /* if we have a certificate then write it out now */ | 348 | /* if we have a certificate then write it out now */ |
| 350 | if ((xi->x509 != NULL) || (PEM_write_bio_X509(bp,xi->x509) <= 0)) | 349 | if ((xi->x509 != NULL) && (PEM_write_bio_X509(bp,xi->x509) <= 0)) |
| 351 | goto err; | 350 | goto err; |
| 352 | 351 | ||
| 353 | /* we are ignoring anything else that is loaded into the X509_INFO | 352 | /* we are ignoring anything else that is loaded into the X509_INFO |
diff --git a/src/lib/libcrypto/pem/pem_lib.c b/src/lib/libcrypto/pem/pem_lib.c index 7a2c0ad83b..18b751a91a 100644 --- a/src/lib/libcrypto/pem/pem_lib.c +++ b/src/lib/libcrypto/pem/pem_lib.c | |||
| @@ -58,45 +58,40 @@ | |||
| 58 | 58 | ||
| 59 | #include <stdio.h> | 59 | #include <stdio.h> |
| 60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
| 61 | #include "buffer.h" | 61 | #include <openssl/buffer.h> |
| 62 | #include "objects.h" | 62 | #include <openssl/objects.h> |
| 63 | #include "evp.h" | 63 | #include <openssl/evp.h> |
| 64 | #include "rand.h" | 64 | #include <openssl/rand.h> |
| 65 | #include "x509.h" | 65 | #include <openssl/x509.h> |
| 66 | #include "pem.h" | 66 | #include <openssl/pem.h> |
| 67 | #ifndef NO_DES | 67 | #include <openssl/pkcs12.h> |
| 68 | #include "des.h" | 68 | #ifndef OPENSSL_NO_DES |
| 69 | #include <openssl/des.h> | ||
| 69 | #endif | 70 | #endif |
| 70 | 71 | ||
| 71 | char *PEM_version="PEM part of SSLeay 0.9.0b 29-Jun-1998"; | 72 | const char *PEM_version="PEM" OPENSSL_VERSION_PTEXT; |
| 72 | 73 | ||
| 73 | #define MIN_LENGTH 4 | 74 | #define MIN_LENGTH 4 |
| 74 | 75 | ||
| 75 | /* PEMerr(PEM_F_PEM_WRITE_BIO,ERR_R_MALLOC_FAILURE); | ||
| 76 | * PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); | ||
| 77 | */ | ||
| 78 | |||
| 79 | #ifndef NOPROTO | ||
| 80 | static int def_callback(char *buf, int num, int w); | ||
| 81 | static int load_iv(unsigned char **fromp,unsigned char *to, int num); | 76 | static int load_iv(unsigned char **fromp,unsigned char *to, int num); |
| 82 | #else | 77 | static int check_pem(const char *nm, const char *name); |
| 83 | static int def_callback(); | ||
| 84 | static int load_iv(); | ||
| 85 | #endif | ||
| 86 | 78 | ||
| 87 | static int def_callback(buf, num, w) | 79 | int PEM_def_callback(char *buf, int num, int w, void *key) |
| 88 | char *buf; | ||
| 89 | int num; | ||
| 90 | int w; | ||
| 91 | { | 80 | { |
| 92 | #ifdef NO_FP_API | 81 | #ifdef OPENSSL_NO_FP_API |
| 93 | /* We should not ever call the default callback routine from | 82 | /* We should not ever call the default callback routine from |
| 94 | * windows. */ | 83 | * windows. */ |
| 95 | PEMerr(PEM_F_DEF_CALLBACK,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | 84 | PEMerr(PEM_F_DEF_CALLBACK,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); |
| 96 | return(-1); | 85 | return(-1); |
| 97 | #else | 86 | #else |
| 98 | int i,j; | 87 | int i,j; |
| 99 | char *prompt; | 88 | const char *prompt; |
| 89 | if(key) { | ||
| 90 | i=strlen(key); | ||
| 91 | i=(i > num)?num:i; | ||
| 92 | memcpy(buf,key,i); | ||
| 93 | return(i); | ||
| 94 | } | ||
| 100 | 95 | ||
| 101 | prompt=EVP_get_pw_prompt(); | 96 | prompt=EVP_get_pw_prompt(); |
| 102 | if (prompt == NULL) | 97 | if (prompt == NULL) |
| @@ -123,11 +118,9 @@ int w; | |||
| 123 | #endif | 118 | #endif |
| 124 | } | 119 | } |
| 125 | 120 | ||
| 126 | void PEM_proc_type(buf, type) | 121 | void PEM_proc_type(char *buf, int type) |
| 127 | char *buf; | ||
| 128 | int type; | ||
| 129 | { | 122 | { |
| 130 | char *str; | 123 | const char *str; |
| 131 | 124 | ||
| 132 | if (type == PEM_TYPE_ENCRYPTED) | 125 | if (type == PEM_TYPE_ENCRYPTED) |
| 133 | str="ENCRYPTED"; | 126 | str="ENCRYPTED"; |
| @@ -143,11 +136,7 @@ int type; | |||
| 143 | strcat(buf,"\n"); | 136 | strcat(buf,"\n"); |
| 144 | } | 137 | } |
| 145 | 138 | ||
| 146 | void PEM_dek_info(buf, type, len, str) | 139 | void PEM_dek_info(char *buf, const char *type, int len, char *str) |
| 147 | char *buf; | ||
| 148 | char *type; | ||
| 149 | int len; | ||
| 150 | char *str; | ||
| 151 | { | 140 | { |
| 152 | static unsigned char map[17]="0123456789ABCDEF"; | 141 | static unsigned char map[17]="0123456789ABCDEF"; |
| 153 | long i; | 142 | long i; |
| @@ -166,13 +155,9 @@ char *str; | |||
| 166 | buf[j+i*2+1]='\0'; | 155 | buf[j+i*2+1]='\0'; |
| 167 | } | 156 | } |
| 168 | 157 | ||
| 169 | #ifndef NO_FP_API | 158 | #ifndef OPENSSL_NO_FP_API |
| 170 | char *PEM_ASN1_read(d2i,name,fp, x, cb) | 159 | char *PEM_ASN1_read(char *(*d2i)(), const char *name, FILE *fp, char **x, |
| 171 | char *(*d2i)(); | 160 | pem_password_cb *cb, void *u) |
| 172 | char *name; | ||
| 173 | FILE *fp; | ||
| 174 | char **x; | ||
| 175 | int (*cb)(); | ||
| 176 | { | 161 | { |
| 177 | BIO *b; | 162 | BIO *b; |
| 178 | char *ret; | 163 | char *ret; |
| @@ -183,74 +168,97 @@ int (*cb)(); | |||
| 183 | return(0); | 168 | return(0); |
| 184 | } | 169 | } |
| 185 | BIO_set_fp(b,fp,BIO_NOCLOSE); | 170 | BIO_set_fp(b,fp,BIO_NOCLOSE); |
| 186 | ret=PEM_ASN1_read_bio(d2i,name,b,x,cb); | 171 | ret=PEM_ASN1_read_bio(d2i,name,b,x,cb,u); |
| 187 | BIO_free(b); | 172 | BIO_free(b); |
| 188 | return(ret); | 173 | return(ret); |
| 189 | } | 174 | } |
| 190 | #endif | 175 | #endif |
| 191 | 176 | ||
| 192 | char *PEM_ASN1_read_bio(d2i,name,bp, x, cb) | 177 | static int check_pem(const char *nm, const char *name) |
| 193 | char *(*d2i)(); | 178 | { |
| 194 | char *name; | 179 | /* Normal matching nm and name */ |
| 195 | BIO *bp; | 180 | if (!strcmp(nm,name)) return 1; |
| 196 | char **x; | 181 | |
| 197 | int (*cb)(); | 182 | /* Make PEM_STRING_EVP_PKEY match any private key */ |
| 183 | |||
| 184 | if(!strcmp(nm,PEM_STRING_PKCS8) && | ||
| 185 | !strcmp(name,PEM_STRING_EVP_PKEY)) return 1; | ||
| 186 | |||
| 187 | if(!strcmp(nm,PEM_STRING_PKCS8INF) && | ||
| 188 | !strcmp(name,PEM_STRING_EVP_PKEY)) return 1; | ||
| 189 | |||
| 190 | if(!strcmp(nm,PEM_STRING_RSA) && | ||
| 191 | !strcmp(name,PEM_STRING_EVP_PKEY)) return 1; | ||
| 192 | |||
| 193 | if(!strcmp(nm,PEM_STRING_DSA) && | ||
| 194 | !strcmp(name,PEM_STRING_EVP_PKEY)) return 1; | ||
| 195 | |||
| 196 | /* Permit older strings */ | ||
| 197 | |||
| 198 | if(!strcmp(nm,PEM_STRING_X509_OLD) && | ||
| 199 | !strcmp(name,PEM_STRING_X509)) return 1; | ||
| 200 | |||
| 201 | if(!strcmp(nm,PEM_STRING_X509_REQ_OLD) && | ||
| 202 | !strcmp(name,PEM_STRING_X509_REQ)) return 1; | ||
| 203 | |||
| 204 | /* Allow normal certs to be read as trusted certs */ | ||
| 205 | if(!strcmp(nm,PEM_STRING_X509) && | ||
| 206 | !strcmp(name,PEM_STRING_X509_TRUSTED)) return 1; | ||
| 207 | |||
| 208 | if(!strcmp(nm,PEM_STRING_X509_OLD) && | ||
| 209 | !strcmp(name,PEM_STRING_X509_TRUSTED)) return 1; | ||
| 210 | |||
| 211 | /* Some CAs use PKCS#7 with CERTIFICATE headers */ | ||
| 212 | if(!strcmp(nm, PEM_STRING_X509) && | ||
| 213 | !strcmp(name, PEM_STRING_PKCS7)) return 1; | ||
| 214 | |||
| 215 | return 0; | ||
| 216 | } | ||
| 217 | |||
| 218 | int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char *name, BIO *bp, | ||
| 219 | pem_password_cb *cb, void *u) | ||
| 198 | { | 220 | { |
| 199 | EVP_CIPHER_INFO cipher; | 221 | EVP_CIPHER_INFO cipher; |
| 200 | char *nm=NULL,*header=NULL; | 222 | char *nm=NULL,*header=NULL; |
| 201 | unsigned char *p=NULL,*data=NULL; | 223 | unsigned char *data=NULL; |
| 202 | long len; | 224 | long len; |
| 203 | char *ret=NULL; | 225 | int ret = 0; |
| 204 | 226 | ||
| 205 | for (;;) | 227 | for (;;) |
| 206 | { | 228 | { |
| 207 | if (!PEM_read_bio(bp,&nm,&header,&data,&len)) return(NULL); | 229 | if (!PEM_read_bio(bp,&nm,&header,&data,&len)) { |
| 208 | if ( (strcmp(nm,name) == 0) || | 230 | if(ERR_GET_REASON(ERR_peek_error()) == |
| 209 | ((strcmp(nm,PEM_STRING_RSA) == 0) && | 231 | PEM_R_NO_START_LINE) |
| 210 | (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) || | 232 | ERR_add_error_data(2, "Expecting: ", name); |
| 211 | ((strcmp(nm,PEM_STRING_DSA) == 0) && | 233 | return 0; |
| 212 | (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) || | ||
| 213 | ((strcmp(nm,PEM_STRING_X509_OLD) == 0) && | ||
| 214 | (strcmp(name,PEM_STRING_X509) == 0)) || | ||
| 215 | ((strcmp(nm,PEM_STRING_X509_REQ_OLD) == 0) && | ||
| 216 | (strcmp(name,PEM_STRING_X509_REQ) == 0)) | ||
| 217 | ) | ||
| 218 | break; | ||
| 219 | Free(nm); | ||
| 220 | Free(header); | ||
| 221 | Free(data); | ||
| 222 | } | 234 | } |
| 223 | if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) goto err; | 235 | if(check_pem(nm, name)) break; |
| 224 | if (!PEM_do_header(&cipher,data,&len,cb)) goto err; | 236 | OPENSSL_free(nm); |
| 225 | p=data; | 237 | OPENSSL_free(header); |
| 226 | if (strcmp(name,PEM_STRING_EVP_PKEY) == 0) | 238 | OPENSSL_free(data); |
| 227 | { | ||
| 228 | if (strcmp(nm,PEM_STRING_RSA) == 0) | ||
| 229 | ret=d2i(EVP_PKEY_RSA,x,&p,len); | ||
| 230 | else if (strcmp(nm,PEM_STRING_DSA) == 0) | ||
| 231 | ret=d2i(EVP_PKEY_DSA,x,&p,len); | ||
| 232 | } | 239 | } |
| 233 | else | 240 | if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) goto err; |
| 234 | ret=d2i(x,&p,len); | 241 | if (!PEM_do_header(&cipher,data,&len,cb,u)) goto err; |
| 235 | if (ret == NULL) | 242 | |
| 236 | PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB); | 243 | *pdata = data; |
| 244 | *plen = len; | ||
| 245 | |||
| 246 | if (pnm) | ||
| 247 | *pnm = nm; | ||
| 248 | |||
| 249 | ret = 1; | ||
| 250 | |||
| 237 | err: | 251 | err: |
| 238 | Free(nm); | 252 | if (!pnm) OPENSSL_free(nm); |
| 239 | Free(header); | 253 | OPENSSL_free(header); |
| 240 | Free(data); | 254 | if (!ret) OPENSSL_free(data); |
| 241 | return(ret); | 255 | return ret; |
| 242 | } | 256 | } |
| 243 | 257 | ||
| 244 | #ifndef NO_FP_API | 258 | #ifndef OPENSSL_NO_FP_API |
| 245 | int PEM_ASN1_write(i2d,name,fp, x, enc, kstr, klen, callback) | 259 | int PEM_ASN1_write(int (*i2d)(), const char *name, FILE *fp, char *x, |
| 246 | int (*i2d)(); | 260 | const EVP_CIPHER *enc, unsigned char *kstr, int klen, |
| 247 | char *name; | 261 | pem_password_cb *callback, void *u) |
| 248 | FILE *fp; | ||
| 249 | char *x; | ||
| 250 | EVP_CIPHER *enc; | ||
| 251 | unsigned char *kstr; | ||
| 252 | int klen; | ||
| 253 | int (*callback)(); | ||
| 254 | { | 262 | { |
| 255 | BIO *b; | 263 | BIO *b; |
| 256 | int ret; | 264 | int ret; |
| @@ -261,27 +269,20 @@ int (*callback)(); | |||
| 261 | return(0); | 269 | return(0); |
| 262 | } | 270 | } |
| 263 | BIO_set_fp(b,fp,BIO_NOCLOSE); | 271 | BIO_set_fp(b,fp,BIO_NOCLOSE); |
| 264 | ret=PEM_ASN1_write_bio(i2d,name,b,x,enc,kstr,klen,callback); | 272 | ret=PEM_ASN1_write_bio(i2d,name,b,x,enc,kstr,klen,callback,u); |
| 265 | BIO_free(b); | 273 | BIO_free(b); |
| 266 | return(ret); | 274 | return(ret); |
| 267 | } | 275 | } |
| 268 | #endif | 276 | #endif |
| 269 | 277 | ||
| 270 | int PEM_ASN1_write_bio(i2d,name,bp, x, enc, kstr, klen, callback) | 278 | int PEM_ASN1_write_bio(int (*i2d)(), const char *name, BIO *bp, char *x, |
| 271 | int (*i2d)(); | 279 | const EVP_CIPHER *enc, unsigned char *kstr, int klen, |
| 272 | char *name; | 280 | pem_password_cb *callback, void *u) |
| 273 | BIO *bp; | ||
| 274 | char *x; | ||
| 275 | EVP_CIPHER *enc; | ||
| 276 | unsigned char *kstr; | ||
| 277 | int klen; | ||
| 278 | int (*callback)(); | ||
| 279 | { | 281 | { |
| 280 | EVP_CIPHER_CTX ctx; | 282 | EVP_CIPHER_CTX ctx; |
| 281 | int dsize=0,i,j,ret=0; | 283 | int dsize=0,i,j,ret=0; |
| 282 | unsigned char *p,*data=NULL; | 284 | unsigned char *p,*data=NULL; |
| 283 | char *objstr=NULL; | 285 | const char *objstr=NULL; |
| 284 | #define PEM_BUFSIZE 1024 | ||
| 285 | char buf[PEM_BUFSIZE]; | 286 | char buf[PEM_BUFSIZE]; |
| 286 | unsigned char key[EVP_MAX_KEY_LENGTH]; | 287 | unsigned char key[EVP_MAX_KEY_LENGTH]; |
| 287 | unsigned char iv[EVP_MAX_IV_LENGTH]; | 288 | unsigned char iv[EVP_MAX_IV_LENGTH]; |
| @@ -303,7 +304,7 @@ int (*callback)(); | |||
| 303 | goto err; | 304 | goto err; |
| 304 | } | 305 | } |
| 305 | /* dzise + 8 bytes are needed */ | 306 | /* dzise + 8 bytes are needed */ |
| 306 | data=(unsigned char *)Malloc((unsigned int)dsize+20); | 307 | data=(unsigned char *)OPENSSL_malloc((unsigned int)dsize+20); |
| 307 | if (data == NULL) | 308 | if (data == NULL) |
| 308 | { | 309 | { |
| 309 | PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,ERR_R_MALLOC_FAILURE); | 310 | PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,ERR_R_MALLOC_FAILURE); |
| @@ -317,18 +318,23 @@ int (*callback)(); | |||
| 317 | if (kstr == NULL) | 318 | if (kstr == NULL) |
| 318 | { | 319 | { |
| 319 | if (callback == NULL) | 320 | if (callback == NULL) |
| 320 | klen=def_callback(buf,PEM_BUFSIZE,1); | 321 | klen=PEM_def_callback(buf,PEM_BUFSIZE,1,u); |
| 321 | else | 322 | else |
| 322 | klen=(*callback)(buf,PEM_BUFSIZE,1); | 323 | klen=(*callback)(buf,PEM_BUFSIZE,1,u); |
| 323 | if (klen <= 0) | 324 | if (klen <= 0) |
| 324 | { | 325 | { |
| 325 | PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,PEM_R_READ_KEY); | 326 | PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,PEM_R_READ_KEY); |
| 326 | goto err; | 327 | goto err; |
| 327 | } | 328 | } |
| 329 | #ifdef CHARSET_EBCDIC | ||
| 330 | /* Convert the pass phrase from EBCDIC */ | ||
| 331 | ebcdic2ascii(buf, buf, klen); | ||
| 332 | #endif | ||
| 328 | kstr=(unsigned char *)buf; | 333 | kstr=(unsigned char *)buf; |
| 329 | } | 334 | } |
| 330 | RAND_seed(data,i);/* put in the RSA key. */ | 335 | RAND_add(data,i,0);/* put in the RSA key. */ |
| 331 | RAND_bytes(iv,8); /* Generate a salt */ | 336 | if (RAND_pseudo_bytes(iv,enc->iv_len) < 0) /* Generate a salt */ |
| 337 | goto err; | ||
| 332 | /* The 'iv' is used as the iv and as a salt. It is | 338 | /* The 'iv' is used as the iv and as a salt. It is |
| 333 | * NOT taken from the BytesToKey function */ | 339 | * NOT taken from the BytesToKey function */ |
| 334 | EVP_BytesToKey(enc,EVP_md5(),iv,kstr,klen,1,key,NULL); | 340 | EVP_BytesToKey(enc,EVP_md5(),iv,kstr,klen,1,key,NULL); |
| @@ -337,12 +343,14 @@ int (*callback)(); | |||
| 337 | 343 | ||
| 338 | buf[0]='\0'; | 344 | buf[0]='\0'; |
| 339 | PEM_proc_type(buf,PEM_TYPE_ENCRYPTED); | 345 | PEM_proc_type(buf,PEM_TYPE_ENCRYPTED); |
| 340 | PEM_dek_info(buf,objstr,8,(char *)iv); | 346 | PEM_dek_info(buf,objstr,enc->iv_len,(char *)iv); |
| 341 | /* k=strlen(buf); */ | 347 | /* k=strlen(buf); */ |
| 342 | 348 | ||
| 343 | EVP_EncryptInit(&ctx,enc,key,iv); | 349 | EVP_CIPHER_CTX_init(&ctx); |
| 350 | EVP_EncryptInit_ex(&ctx,enc,NULL,key,iv); | ||
| 344 | EVP_EncryptUpdate(&ctx,data,&j,data,i); | 351 | EVP_EncryptUpdate(&ctx,data,&j,data,i); |
| 345 | EVP_EncryptFinal(&ctx,&(data[j]),&i); | 352 | EVP_EncryptFinal_ex(&ctx,&(data[j]),&i); |
| 353 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
| 346 | i+=j; | 354 | i+=j; |
| 347 | ret=1; | 355 | ret=1; |
| 348 | } | 356 | } |
| @@ -359,15 +367,12 @@ err: | |||
| 359 | memset((char *)&ctx,0,sizeof(ctx)); | 367 | memset((char *)&ctx,0,sizeof(ctx)); |
| 360 | memset(buf,0,PEM_BUFSIZE); | 368 | memset(buf,0,PEM_BUFSIZE); |
| 361 | memset(data,0,(unsigned int)dsize); | 369 | memset(data,0,(unsigned int)dsize); |
| 362 | Free(data); | 370 | OPENSSL_free(data); |
| 363 | return(ret); | 371 | return(ret); |
| 364 | } | 372 | } |
| 365 | 373 | ||
| 366 | int PEM_do_header(cipher, data, plen, callback) | 374 | int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *plen, |
| 367 | EVP_CIPHER_INFO *cipher; | 375 | pem_password_cb *callback,void *u) |
| 368 | unsigned char *data; | ||
| 369 | long *plen; | ||
| 370 | int (*callback)(); | ||
| 371 | { | 376 | { |
| 372 | int i,j,o,klen; | 377 | int i,j,o,klen; |
| 373 | long len; | 378 | long len; |
| @@ -379,21 +384,27 @@ int (*callback)(); | |||
| 379 | 384 | ||
| 380 | if (cipher->cipher == NULL) return(1); | 385 | if (cipher->cipher == NULL) return(1); |
| 381 | if (callback == NULL) | 386 | if (callback == NULL) |
| 382 | klen=def_callback(buf,PEM_BUFSIZE,0); | 387 | klen=PEM_def_callback(buf,PEM_BUFSIZE,0,u); |
| 383 | else | 388 | else |
| 384 | klen=callback(buf,PEM_BUFSIZE,0); | 389 | klen=callback(buf,PEM_BUFSIZE,0,u); |
| 385 | if (klen <= 0) | 390 | if (klen <= 0) |
| 386 | { | 391 | { |
| 387 | PEMerr(PEM_F_PEM_DO_HEADER,PEM_R_BAD_PASSWORD_READ); | 392 | PEMerr(PEM_F_PEM_DO_HEADER,PEM_R_BAD_PASSWORD_READ); |
| 388 | return(0); | 393 | return(0); |
| 389 | } | 394 | } |
| 395 | #ifdef CHARSET_EBCDIC | ||
| 396 | /* Convert the pass phrase from EBCDIC */ | ||
| 397 | ebcdic2ascii(buf, buf, klen); | ||
| 398 | #endif | ||
| 399 | |||
| 390 | EVP_BytesToKey(cipher->cipher,EVP_md5(),&(cipher->iv[0]), | 400 | EVP_BytesToKey(cipher->cipher,EVP_md5(),&(cipher->iv[0]), |
| 391 | (unsigned char *)buf,klen,1,key,NULL); | 401 | (unsigned char *)buf,klen,1,key,NULL); |
| 392 | 402 | ||
| 393 | j=(int)len; | 403 | j=(int)len; |
| 394 | EVP_DecryptInit(&ctx,cipher->cipher,key,&(cipher->iv[0])); | 404 | EVP_CIPHER_CTX_init(&ctx); |
| 405 | EVP_DecryptInit_ex(&ctx,cipher->cipher,NULL, key,&(cipher->iv[0])); | ||
| 395 | EVP_DecryptUpdate(&ctx,data,&i,data,j); | 406 | EVP_DecryptUpdate(&ctx,data,&i,data,j); |
| 396 | o=EVP_DecryptFinal(&ctx,&(data[i]),&j); | 407 | o=EVP_DecryptFinal_ex(&ctx,&(data[i]),&j); |
| 397 | EVP_CIPHER_CTX_cleanup(&ctx); | 408 | EVP_CIPHER_CTX_cleanup(&ctx); |
| 398 | memset((char *)buf,0,sizeof(buf)); | 409 | memset((char *)buf,0,sizeof(buf)); |
| 399 | memset((char *)key,0,sizeof(key)); | 410 | memset((char *)key,0,sizeof(key)); |
| @@ -407,12 +418,10 @@ int (*callback)(); | |||
| 407 | return(1); | 418 | return(1); |
| 408 | } | 419 | } |
| 409 | 420 | ||
| 410 | int PEM_get_EVP_CIPHER_INFO(header,cipher) | 421 | int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher) |
| 411 | char *header; | ||
| 412 | EVP_CIPHER_INFO *cipher; | ||
| 413 | { | 422 | { |
| 414 | int o; | 423 | int o; |
| 415 | EVP_CIPHER *enc=NULL; | 424 | const EVP_CIPHER *enc=NULL; |
| 416 | char *p,c; | 425 | char *p,c; |
| 417 | 426 | ||
| 418 | cipher->cipher=NULL; | 427 | cipher->cipher=NULL; |
| @@ -438,9 +447,15 @@ EVP_CIPHER_INFO *cipher; | |||
| 438 | for (;;) | 447 | for (;;) |
| 439 | { | 448 | { |
| 440 | c= *header; | 449 | c= *header; |
| 450 | #ifndef CHARSET_EBCDIC | ||
| 441 | if (!( ((c >= 'A') && (c <= 'Z')) || (c == '-') || | 451 | if (!( ((c >= 'A') && (c <= 'Z')) || (c == '-') || |
| 442 | ((c >= '0') && (c <= '9')))) | 452 | ((c >= '0') && (c <= '9')))) |
| 443 | break; | 453 | break; |
| 454 | #else | ||
| 455 | if (!( isupper(c) || (c == '-') || | ||
| 456 | isdigit(c))) | ||
| 457 | break; | ||
| 458 | #endif | ||
| 444 | header++; | 459 | header++; |
| 445 | } | 460 | } |
| 446 | *header='\0'; | 461 | *header='\0'; |
| @@ -454,14 +469,12 @@ EVP_CIPHER_INFO *cipher; | |||
| 454 | PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_UNSUPPORTED_ENCRYPTION); | 469 | PEMerr(PEM_F_PEM_GET_EVP_CIPHER_INFO,PEM_R_UNSUPPORTED_ENCRYPTION); |
| 455 | return(0); | 470 | return(0); |
| 456 | } | 471 | } |
| 457 | if (!load_iv((unsigned char **)&header,&(cipher->iv[0]),8)) return(0); | 472 | if (!load_iv((unsigned char **)&header,&(cipher->iv[0]),enc->iv_len)) return(0); |
| 458 | 473 | ||
| 459 | return(1); | 474 | return(1); |
| 460 | } | 475 | } |
| 461 | 476 | ||
| 462 | static int load_iv(fromp,to,num) | 477 | static int load_iv(unsigned char **fromp, unsigned char *to, int num) |
| 463 | unsigned char **fromp,*to; | ||
| 464 | int num; | ||
| 465 | { | 478 | { |
| 466 | int v,i; | 479 | int v,i; |
| 467 | unsigned char *from; | 480 | unsigned char *from; |
| @@ -490,13 +503,9 @@ int num; | |||
| 490 | return(1); | 503 | return(1); |
| 491 | } | 504 | } |
| 492 | 505 | ||
| 493 | #ifndef NO_FP_API | 506 | #ifndef OPENSSL_NO_FP_API |
| 494 | int PEM_write(fp, name, header, data,len) | 507 | int PEM_write(FILE *fp, char *name, char *header, unsigned char *data, |
| 495 | FILE *fp; | 508 | long len) |
| 496 | char *name; | ||
| 497 | char *header; | ||
| 498 | unsigned char *data; | ||
| 499 | long len; | ||
| 500 | { | 509 | { |
| 501 | BIO *b; | 510 | BIO *b; |
| 502 | int ret; | 511 | int ret; |
| @@ -513,12 +522,8 @@ long len; | |||
| 513 | } | 522 | } |
| 514 | #endif | 523 | #endif |
| 515 | 524 | ||
| 516 | int PEM_write_bio(bp, name, header, data,len) | 525 | int PEM_write_bio(BIO *bp, const char *name, char *header, unsigned char *data, |
| 517 | BIO *bp; | 526 | long len) |
| 518 | char *name; | ||
| 519 | char *header; | ||
| 520 | unsigned char *data; | ||
| 521 | long len; | ||
| 522 | { | 527 | { |
| 523 | int nlen,n,i,j,outl; | 528 | int nlen,n,i,j,outl; |
| 524 | unsigned char *buf; | 529 | unsigned char *buf; |
| @@ -541,7 +546,7 @@ long len; | |||
| 541 | goto err; | 546 | goto err; |
| 542 | } | 547 | } |
| 543 | 548 | ||
| 544 | buf=(unsigned char *)Malloc(PEM_BUFSIZE*8); | 549 | buf=(unsigned char *)OPENSSL_malloc(PEM_BUFSIZE*8); |
| 545 | if (buf == NULL) | 550 | if (buf == NULL) |
| 546 | { | 551 | { |
| 547 | reason=ERR_R_MALLOC_FAILURE; | 552 | reason=ERR_R_MALLOC_FAILURE; |
| @@ -561,7 +566,7 @@ long len; | |||
| 561 | } | 566 | } |
| 562 | EVP_EncodeFinal(&ctx,buf,&outl); | 567 | EVP_EncodeFinal(&ctx,buf,&outl); |
| 563 | if ((outl > 0) && (BIO_write(bp,(char *)buf,outl) != outl)) goto err; | 568 | if ((outl > 0) && (BIO_write(bp,(char *)buf,outl) != outl)) goto err; |
| 564 | Free(buf); | 569 | OPENSSL_free(buf); |
| 565 | if ( (BIO_write(bp,"-----END ",9) != 9) || | 570 | if ( (BIO_write(bp,"-----END ",9) != 9) || |
| 566 | (BIO_write(bp,name,nlen) != nlen) || | 571 | (BIO_write(bp,name,nlen) != nlen) || |
| 567 | (BIO_write(bp,"-----\n",6) != 6)) | 572 | (BIO_write(bp,"-----\n",6) != 6)) |
| @@ -572,13 +577,9 @@ err: | |||
| 572 | return(0); | 577 | return(0); |
| 573 | } | 578 | } |
| 574 | 579 | ||
| 575 | #ifndef NO_FP_API | 580 | #ifndef OPENSSL_NO_FP_API |
| 576 | int PEM_read(fp, name, header, data,len) | 581 | int PEM_read(FILE *fp, char **name, char **header, unsigned char **data, |
| 577 | FILE *fp; | 582 | long *len) |
| 578 | char **name; | ||
| 579 | char **header; | ||
| 580 | unsigned char **data; | ||
| 581 | long *len; | ||
| 582 | { | 583 | { |
| 583 | BIO *b; | 584 | BIO *b; |
| 584 | int ret; | 585 | int ret; |
| @@ -595,12 +596,8 @@ long *len; | |||
| 595 | } | 596 | } |
| 596 | #endif | 597 | #endif |
| 597 | 598 | ||
| 598 | int PEM_read_bio(bp, name, header, data, len) | 599 | int PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data, |
| 599 | BIO *bp; | 600 | long *len) |
| 600 | char **name; | ||
| 601 | char **header; | ||
| 602 | unsigned char **data; | ||
| 603 | long *len; | ||
| 604 | { | 601 | { |
| 605 | EVP_ENCODE_CTX ctx; | 602 | EVP_ENCODE_CTX ctx; |
| 606 | int end=0,i,k,bl=0,hl=0,nohead=0; | 603 | int end=0,i,k,bl=0,hl=0,nohead=0; |
| @@ -643,7 +640,7 @@ long *len; | |||
| 643 | PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); | 640 | PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); |
| 644 | goto err; | 641 | goto err; |
| 645 | } | 642 | } |
| 646 | strncpy(nameB->data,&(buf[11]),(unsigned int)i-6); | 643 | memcpy(nameB->data,&(buf[11]),i-6); |
| 647 | nameB->data[i-6]='\0'; | 644 | nameB->data[i-6]='\0'; |
| 648 | break; | 645 | break; |
| 649 | } | 646 | } |
| @@ -668,7 +665,7 @@ long *len; | |||
| 668 | nohead=1; | 665 | nohead=1; |
| 669 | break; | 666 | break; |
| 670 | } | 667 | } |
| 671 | strncpy(&(headerB->data[hl]),buf,(unsigned int)i); | 668 | memcpy(&(headerB->data[hl]),buf,i); |
| 672 | headerB->data[hl+i]='\0'; | 669 | headerB->data[hl+i]='\0'; |
| 673 | hl+=i; | 670 | hl+=i; |
| 674 | } | 671 | } |
| @@ -696,7 +693,7 @@ long *len; | |||
| 696 | PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); | 693 | PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); |
| 697 | goto err; | 694 | goto err; |
| 698 | } | 695 | } |
| 699 | strncpy(&(dataB->data[bl]),buf,(unsigned int)i); | 696 | memcpy(&(dataB->data[bl]),buf,i); |
| 700 | dataB->data[bl+i]='\0'; | 697 | dataB->data[bl+i]='\0'; |
| 701 | bl+=i; | 698 | bl+=i; |
| 702 | if (end) | 699 | if (end) |
| @@ -721,7 +718,7 @@ long *len; | |||
| 721 | } | 718 | } |
| 722 | i=strlen(nameB->data); | 719 | i=strlen(nameB->data); |
| 723 | if ( (strncmp(buf,"-----END ",9) != 0) || | 720 | if ( (strncmp(buf,"-----END ",9) != 0) || |
| 724 | (strncmp(nameB->data,&(buf[9]),(unsigned int)i) != 0) || | 721 | (strncmp(nameB->data,&(buf[9]),i) != 0) || |
| 725 | (strncmp(&(buf[9+i]),"-----\n",6) != 0)) | 722 | (strncmp(&(buf[9+i]),"-----\n",6) != 0)) |
| 726 | { | 723 | { |
| 727 | PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_END_LINE); | 724 | PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_END_LINE); |
| @@ -750,9 +747,9 @@ long *len; | |||
| 750 | *header=headerB->data; | 747 | *header=headerB->data; |
| 751 | *data=(unsigned char *)dataB->data; | 748 | *data=(unsigned char *)dataB->data; |
| 752 | *len=bl; | 749 | *len=bl; |
| 753 | Free(nameB); | 750 | OPENSSL_free(nameB); |
| 754 | Free(headerB); | 751 | OPENSSL_free(headerB); |
| 755 | Free(dataB); | 752 | OPENSSL_free(dataB); |
| 756 | return(1); | 753 | return(1); |
| 757 | err: | 754 | err: |
| 758 | BUF_MEM_free(nameB); | 755 | BUF_MEM_free(nameB); |
diff --git a/src/lib/libcrypto/pem/pem_seal.c b/src/lib/libcrypto/pem/pem_seal.c index b4b36df453..ae463a301d 100644 --- a/src/lib/libcrypto/pem/pem_seal.c +++ b/src/lib/libcrypto/pem/pem_seal.c | |||
| @@ -56,23 +56,18 @@ | |||
| 56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
| 57 | */ | 57 | */ |
| 58 | 58 | ||
| 59 | #ifndef OPENSSL_NO_RSA | ||
| 59 | #include <stdio.h> | 60 | #include <stdio.h> |
| 60 | #include "cryptlib.h" | 61 | #include "cryptlib.h" |
| 61 | #include "evp.h" | 62 | #include <openssl/evp.h> |
| 62 | #include "rand.h" | 63 | #include <openssl/rand.h> |
| 63 | #include "objects.h" | 64 | #include <openssl/objects.h> |
| 64 | #include "x509.h" | 65 | #include <openssl/x509.h> |
| 65 | #include "pem.h" | 66 | #include <openssl/pem.h> |
| 66 | 67 | ||
| 67 | int PEM_SealInit(ctx,type,md_type,ek,ekl,iv,pubk,npubk) | 68 | int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type, |
| 68 | PEM_ENCODE_SEAL_CTX *ctx; | 69 | unsigned char **ek, int *ekl, unsigned char *iv, EVP_PKEY **pubk, |
| 69 | EVP_CIPHER *type; | 70 | int npubk) |
| 70 | EVP_MD *md_type; | ||
| 71 | unsigned char **ek; | ||
| 72 | int *ekl; | ||
| 73 | unsigned char *iv; | ||
| 74 | EVP_PKEY **pubk; | ||
| 75 | int npubk; | ||
| 76 | { | 71 | { |
| 77 | unsigned char key[EVP_MAX_KEY_LENGTH]; | 72 | unsigned char key[EVP_MAX_KEY_LENGTH]; |
| 78 | int ret= -1; | 73 | int ret= -1; |
| @@ -89,17 +84,20 @@ int npubk; | |||
| 89 | j=RSA_size(pubk[i]->pkey.rsa); | 84 | j=RSA_size(pubk[i]->pkey.rsa); |
| 90 | if (j > max) max=j; | 85 | if (j > max) max=j; |
| 91 | } | 86 | } |
| 92 | s=(char *)Malloc(max*2); | 87 | s=(char *)OPENSSL_malloc(max*2); |
| 93 | if (s == NULL) | 88 | if (s == NULL) |
| 94 | { | 89 | { |
| 95 | PEMerr(PEM_F_PEM_SEALINIT,ERR_R_MALLOC_FAILURE); | 90 | PEMerr(PEM_F_PEM_SEALINIT,ERR_R_MALLOC_FAILURE); |
| 96 | goto err; | 91 | goto err; |
| 97 | } | 92 | } |
| 98 | 93 | ||
| 99 | EVP_EncodeInit(&(ctx->encode)); | 94 | EVP_EncodeInit(&ctx->encode); |
| 100 | EVP_SignInit(&(ctx->md),md_type); | 95 | |
| 96 | EVP_MD_CTX_init(&ctx->md); | ||
| 97 | EVP_SignInit(&ctx->md,md_type); | ||
| 101 | 98 | ||
| 102 | ret=EVP_SealInit(&(ctx->cipher),type,ek,ekl,iv,pubk,npubk); | 99 | EVP_CIPHER_CTX_init(&ctx->cipher); |
| 100 | ret=EVP_SealInit(&ctx->cipher,type,ek,ekl,iv,pubk,npubk); | ||
| 103 | if (!ret) goto err; | 101 | if (!ret) goto err; |
| 104 | 102 | ||
| 105 | /* base64 encode the keys */ | 103 | /* base64 encode the keys */ |
| @@ -113,23 +111,19 @@ int npubk; | |||
| 113 | 111 | ||
| 114 | ret=npubk; | 112 | ret=npubk; |
| 115 | err: | 113 | err: |
| 116 | if (s != NULL) Free(s); | 114 | if (s != NULL) OPENSSL_free(s); |
| 117 | memset(key,0,EVP_MAX_KEY_LENGTH); | 115 | memset(key,0,EVP_MAX_KEY_LENGTH); |
| 118 | return(ret); | 116 | return(ret); |
| 119 | } | 117 | } |
| 120 | 118 | ||
| 121 | void PEM_SealUpdate(ctx,out,outl,in,inl) | 119 | void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl, |
| 122 | PEM_ENCODE_SEAL_CTX *ctx; | 120 | unsigned char *in, int inl) |
| 123 | unsigned char *out; | ||
| 124 | int *outl; | ||
| 125 | unsigned char *in; | ||
| 126 | int inl; | ||
| 127 | { | 121 | { |
| 128 | unsigned char buffer[1600]; | 122 | unsigned char buffer[1600]; |
| 129 | int i,j; | 123 | int i,j; |
| 130 | 124 | ||
| 131 | *outl=0; | 125 | *outl=0; |
| 132 | EVP_SignUpdate(&(ctx->md),in,inl); | 126 | EVP_SignUpdate(&ctx->md,in,inl); |
| 133 | for (;;) | 127 | for (;;) |
| 134 | { | 128 | { |
| 135 | if (inl <= 0) break; | 129 | if (inl <= 0) break; |
| @@ -137,8 +131,8 @@ int inl; | |||
| 137 | i=1200; | 131 | i=1200; |
| 138 | else | 132 | else |
| 139 | i=inl; | 133 | i=inl; |
| 140 | EVP_EncryptUpdate(&(ctx->cipher),buffer,&j,in,i); | 134 | EVP_EncryptUpdate(&ctx->cipher,buffer,&j,in,i); |
| 141 | EVP_EncodeUpdate(&(ctx->encode),out,&j,buffer,j); | 135 | EVP_EncodeUpdate(&ctx->encode,out,&j,buffer,j); |
| 142 | *outl+=j; | 136 | *outl+=j; |
| 143 | out+=j; | 137 | out+=j; |
| 144 | in+=i; | 138 | in+=i; |
| @@ -146,13 +140,8 @@ int inl; | |||
| 146 | } | 140 | } |
| 147 | } | 141 | } |
| 148 | 142 | ||
| 149 | int PEM_SealFinal(ctx,sig,sigl,out,outl,priv) | 143 | int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig, int *sigl, |
| 150 | PEM_ENCODE_SEAL_CTX *ctx; | 144 | unsigned char *out, int *outl, EVP_PKEY *priv) |
| 151 | unsigned char *sig; | ||
| 152 | int *sigl; | ||
| 153 | unsigned char *out; | ||
| 154 | int *outl; | ||
| 155 | EVP_PKEY *priv; | ||
| 156 | { | 145 | { |
| 157 | unsigned char *s=NULL; | 146 | unsigned char *s=NULL; |
| 158 | int ret=0,j; | 147 | int ret=0,j; |
| @@ -165,27 +154,34 @@ EVP_PKEY *priv; | |||
| 165 | } | 154 | } |
| 166 | i=RSA_size(priv->pkey.rsa); | 155 | i=RSA_size(priv->pkey.rsa); |
| 167 | if (i < 100) i=100; | 156 | if (i < 100) i=100; |
| 168 | s=(unsigned char *)Malloc(i*2); | 157 | s=(unsigned char *)OPENSSL_malloc(i*2); |
| 169 | if (s == NULL) | 158 | if (s == NULL) |
| 170 | { | 159 | { |
| 171 | PEMerr(PEM_F_PEM_SEALFINAL,ERR_R_MALLOC_FAILURE); | 160 | PEMerr(PEM_F_PEM_SEALFINAL,ERR_R_MALLOC_FAILURE); |
| 172 | goto err; | 161 | goto err; |
| 173 | } | 162 | } |
| 174 | 163 | ||
| 175 | EVP_EncryptFinal(&(ctx->cipher),s,(int *)&i); | 164 | EVP_EncryptFinal_ex(&ctx->cipher,s,(int *)&i); |
| 176 | EVP_EncodeUpdate(&(ctx->encode),out,&j,s,i); | 165 | EVP_EncodeUpdate(&ctx->encode,out,&j,s,i); |
| 177 | *outl=j; | 166 | *outl=j; |
| 178 | out+=j; | 167 | out+=j; |
| 179 | EVP_EncodeFinal(&(ctx->encode),out,&j); | 168 | EVP_EncodeFinal(&ctx->encode,out,&j); |
| 180 | *outl+=j; | 169 | *outl+=j; |
| 181 | 170 | ||
| 182 | if (!EVP_SignFinal(&(ctx->md),s,&i,priv)) goto err; | 171 | if (!EVP_SignFinal(&ctx->md,s,&i,priv)) goto err; |
| 183 | *sigl=EVP_EncodeBlock(sig,s,i); | 172 | *sigl=EVP_EncodeBlock(sig,s,i); |
| 184 | 173 | ||
| 185 | ret=1; | 174 | ret=1; |
| 186 | err: | 175 | err: |
| 187 | memset((char *)&(ctx->md),0,sizeof(ctx->md)); | 176 | EVP_MD_CTX_cleanup(&ctx->md); |
| 188 | memset((char *)&(ctx->cipher),0,sizeof(ctx->cipher)); | 177 | EVP_CIPHER_CTX_cleanup(&ctx->cipher); |
| 189 | if (s != NULL) Free(s); | 178 | if (s != NULL) OPENSSL_free(s); |
| 190 | return(ret); | 179 | return(ret); |
| 191 | } | 180 | } |
| 181 | #else /* !OPENSSL_NO_RSA */ | ||
| 182 | |||
| 183 | # if PEDANTIC | ||
| 184 | static void *dummy=&dummy; | ||
| 185 | # endif | ||
| 186 | |||
| 187 | #endif | ||
diff --git a/src/lib/libcrypto/pem/pem_sign.c b/src/lib/libcrypto/pem/pem_sign.c index d56f9f9e14..c3b9808cb2 100644 --- a/src/lib/libcrypto/pem/pem_sign.c +++ b/src/lib/libcrypto/pem/pem_sign.c | |||
| @@ -58,38 +58,31 @@ | |||
| 58 | 58 | ||
| 59 | #include <stdio.h> | 59 | #include <stdio.h> |
| 60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
| 61 | #include "rand.h" | 61 | #include <openssl/rand.h> |
| 62 | #include "evp.h" | 62 | #include <openssl/evp.h> |
| 63 | #include "objects.h" | 63 | #include <openssl/objects.h> |
| 64 | #include "x509.h" | 64 | #include <openssl/x509.h> |
| 65 | #include "pem.h" | 65 | #include <openssl/pem.h> |
| 66 | 66 | ||
| 67 | void PEM_SignInit(ctx,type) | 67 | void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type) |
| 68 | EVP_MD_CTX *ctx; | ||
| 69 | EVP_MD *type; | ||
| 70 | { | 68 | { |
| 71 | EVP_DigestInit(ctx,type); | 69 | EVP_DigestInit_ex(ctx, type, NULL); |
| 72 | } | 70 | } |
| 73 | 71 | ||
| 74 | void PEM_SignUpdate(ctx,data,count) | 72 | void PEM_SignUpdate(EVP_MD_CTX *ctx, unsigned char *data, |
| 75 | EVP_MD_CTX *ctx; | 73 | unsigned int count) |
| 76 | unsigned char *data; | ||
| 77 | unsigned int count; | ||
| 78 | { | 74 | { |
| 79 | EVP_DigestUpdate(ctx,data,count); | 75 | EVP_DigestUpdate(ctx,data,count); |
| 80 | } | 76 | } |
| 81 | 77 | ||
| 82 | int PEM_SignFinal(ctx,sigret,siglen,pkey) | 78 | int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen, |
| 83 | EVP_MD_CTX *ctx; | 79 | EVP_PKEY *pkey) |
| 84 | unsigned char *sigret; | ||
| 85 | unsigned int *siglen; | ||
| 86 | EVP_PKEY *pkey; | ||
| 87 | { | 80 | { |
| 88 | unsigned char *m; | 81 | unsigned char *m; |
| 89 | int i,ret=0; | 82 | int i,ret=0; |
| 90 | unsigned int m_len; | 83 | unsigned int m_len; |
| 91 | 84 | ||
| 92 | m=(unsigned char *)Malloc(EVP_PKEY_size(pkey)+2); | 85 | m=(unsigned char *)OPENSSL_malloc(EVP_PKEY_size(pkey)+2); |
| 93 | if (m == NULL) | 86 | if (m == NULL) |
| 94 | { | 87 | { |
| 95 | PEMerr(PEM_F_PEM_SIGNFINAL,ERR_R_MALLOC_FAILURE); | 88 | PEMerr(PEM_F_PEM_SIGNFINAL,ERR_R_MALLOC_FAILURE); |
| @@ -103,7 +96,7 @@ EVP_PKEY *pkey; | |||
| 103 | ret=1; | 96 | ret=1; |
| 104 | err: | 97 | err: |
| 105 | /* ctx has been zeroed by EVP_SignFinal() */ | 98 | /* ctx has been zeroed by EVP_SignFinal() */ |
| 106 | if (m != NULL) Free(m); | 99 | if (m != NULL) OPENSSL_free(m); |
| 107 | return(ret); | 100 | return(ret); |
| 108 | } | 101 | } |
| 109 | 102 | ||
