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