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 /* Note that this structure is initialised by PEM_SealInit and cleaned up 143 by PEM_SealFinal (at least for now) */ 144 struct PEM_Encode_Seal_st { 145 EVP_ENCODE_CTX encode; 146 EVP_MD_CTX md; 147 EVP_CIPHER_CTX cipher; 148 } 149 alias PEM_Encode_Seal_st PEM_ENCODE_SEAL_CTX; 150 151 /* enc_type is one off */ 152 enum PEM_TYPE_ENCRYPTED = 10; 153 enum PEM_TYPE_MIC_ONLY = 20; 154 enum PEM_TYPE_MIC_CLEAR = 30; 155 enum PEM_TYPE_CLEAR = 40; 156 157 struct pem_recip_st { 158 char* name; 159 X509_NAME* dn; 160 161 int cipher; 162 int key_enc; 163 /* char iv[8]; unused and wrong size */ 164 } 165 alias pem_recip_st PEM_USER; 166 167 struct pem_ctx_st 168 { 169 int type; /* what type of object */ 170 171 struct proc_type_ { 172 int version_; 173 int mode; 174 } 175 proc_type_ proc_type; 176 177 char* domain; 178 179 struct DEK_info_{ 180 int cipher; 181 /* unused, and wrong size 182 ubyte[8] iv; */ 183 } 184 DEK_info_ DEK_info; 185 186 PEM_USER* originator; 187 188 int num_recipient; 189 PEM_USER** recipient; 190 191 /* XXX(ben): don#t think this is used! 192 STACK* x509_chain; / * certificate chain */ 193 EVP_MD* md; /* signature type */ 194 195 int md_enc; /* is the md encrypted or not? */ 196 int md_len; /* length of md_data */ 197 char* md_data; /* message digest, could be pkey encrypted */ 198 199 EVP_CIPHER* dec; /* date encryption cipher */ 200 int key_len; /* key length */ 201 ubyte* key; /* key */ 202 /* unused, and wrong size 203 ubyte[8] iv; */ 204 205 206 int data_enc; /* is the data encrypted */ 207 int data_len; 208 ubyte* data; 209 } 210 alias pem_ctx_st PEM_CTX; 211 212 /* These macros make the PEM_read/PEM_write functions easier to maintain and 213 * write. Now they are all implemented with either: 214 * IMPLEMENT_PEM_rw(...) or IMPLEMENT_PEM_rw_cb(...) 215 */ 216 217 /+#ifdef OPENSSL_NO_FP_API 218 219 #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/ 220 #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/ 221 #define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) /**/ 222 #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/ 223 #define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) /**/ 224 225 #else 226 227 #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \ 228 type* PEM_read_##name(FILE* fp, type** x, pem_password_cb* cb, void* u)\ 229 { \ 230 return PEM_ASN1_read((d2i_of_void*)d2i_##asn1, str,fp,(void**)x,cb,u); \ 231 } 232 233 #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \ 234 int PEM_write_##name(FILE* fp, type* x) \ 235 { \ 236 return PEM_ASN1_write((i2d_of_void*)i2d_##asn1,str,fp,x,NULL,NULL,0,NULL,NULL); \ 237 } 238 239 #define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) \ 240 int PEM_write_##name(FILE* fp, const(type)* x) \ 241 { \ 242 return PEM_ASN1_write((i2d_of_void*)i2d_##asn1,str,fp,(void*)x,NULL,NULL,0,NULL,NULL); \ 243 } 244 245 #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \ 246 int PEM_write_##name(FILE* fp, type* x, const(EVP_CIPHER)* enc, \ 247 ubyte* kstr, int klen, pem_password_cb* cb, \ 248 void* u) \ 249 { \ 250 return PEM_ASN1_write((i2d_of_void*)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \ 251 } 252 253 #define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \ 254 int PEM_write_##name(FILE* fp, type* x, const(EVP_CIPHER)* enc, \ 255 ubyte* kstr, int klen, pem_password_cb* cb, \ 256 void* u) \ 257 { \ 258 return PEM_ASN1_write((i2d_of_void*)i2d_##asn1,str,fp,x,enc,kstr,klen,cb,u); \ 259 } 260 261 #endif 262 263 #define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ 264 type* PEM_read_bio_##name(BIO* bp, type** x, pem_password_cb* cb, void* u)\ 265 { \ 266 return PEM_ASN1_read_bio((d2i_of_void*)d2i_##asn1, str,bp,(void**)x,cb,u); \ 267 } 268 269 #define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ 270 int PEM_write_bio_##name(BIO* bp, type* x) \ 271 { \ 272 return PEM_ASN1_write_bio((i2d_of_void*)i2d_##asn1,str,bp,x,NULL,NULL,0,NULL,NULL); \ 273 } 274 275 #define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \ 276 int PEM_write_bio_##name(BIO* bp, const(type)* x) \ 277 { \ 278 return PEM_ASN1_write_bio((i2d_of_void*)i2d_##asn1,str,bp,(void*)x,NULL,NULL,0,NULL,NULL); \ 279 } 280 281 #define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ 282 int PEM_write_bio_##name(BIO* bp, type* x, const(EVP_CIPHER)* enc, \ 283 ubyte* kstr, int klen, pem_password_cb* cb, void* u) \ 284 { \ 285 return PEM_ASN1_write_bio((i2d_of_void*)i2d_##asn1,str,bp,x,enc,kstr,klen,cb,u); \ 286 } 287 288 #define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \ 289 int PEM_write_bio_##name(BIO* bp, type* x, const(EVP_CIPHER)* enc, \ 290 ubyte* kstr, int klen, pem_password_cb* cb, void* u) \ 291 { \ 292 return PEM_ASN1_write_bio((i2d_of_void*)i2d_##asn1,str,bp,(void*)x,enc,kstr,klen,cb,u); \ 293 } 294 295 #define IMPLEMENT_PEM_write(name, type, str, asn1) \ 296 IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ 297 IMPLEMENT_PEM_write_fp(name, type, str, asn1) 298 299 #define IMPLEMENT_PEM_write_const(name, type, str, asn1) \ 300 IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \ 301 IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) 302 303 #define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \ 304 IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ 305 IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) 306 307 #define IMPLEMENT_PEM_write_cb_const(name, type, str, asn1) \ 308 IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \ 309 IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) 310 311 #define IMPLEMENT_PEM_read(name, type, str, asn1) \ 312 IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ 313 IMPLEMENT_PEM_read_fp(name, type, str, asn1) 314 315 #define IMPLEMENT_PEM_rw(name, type, str, asn1) \ 316 IMPLEMENT_PEM_read(name, type, str, asn1) \ 317 IMPLEMENT_PEM_write(name, type, str, asn1) 318 319 #define IMPLEMENT_PEM_rw_const(name, type, str, asn1) \ 320 IMPLEMENT_PEM_read(name, type, str, asn1) \ 321 IMPLEMENT_PEM_write_const(name, type, str, asn1) 322 323 #define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \ 324 IMPLEMENT_PEM_read(name, type, str, asn1) \ 325 IMPLEMENT_PEM_write_cb(name, type, str, asn1) 326 +/ 327 328 /* These are the same except they are for the declarations */ 329 330 version (OPENSSL_NO_FP_API) { 331 string DECLARE_PEM_read_fp(string name, string type)() { return ""; } 332 string DECLARE_PEM_read_fp(string name, string type)() { return ""; } 333 string DECLARE_PEM_write_fp(string name, string type)() { return ""; } 334 string DECLARE_PEM_write_fp_const(string name, string type)() { return ""; } 335 string DECLARE_PEM_write_cb_fp(string name, string type)() { return ""; } 336 } else { 337 string DECLARE_PEM_read_fp(string name, string type)() { 338 return type ~ "* PEM_read_" ~ name ~ "(FILE* fp, " ~ type ~ "** x, pem_password_cb* cb, void* u);"; 339 } 340 341 string DECLARE_PEM_write_fp(string name, string type)() { 342 return "int PEM_write_" ~ name ~ "(FILE* fp, " ~ type ~ "* x);"; 343 } 344 345 string DECLARE_PEM_write_fp_const(string name, string type)() { 346 return "int PEM_write_" ~ name ~ "(FILE* fp, const(" ~ type ~ ")* x);"; 347 } 348 349 string DECLARE_PEM_write_cb_fp(string name, string type)() { 350 return "int PEM_write_" ~ name ~ "(FILE* fp, " ~ type ~ "* x, const(EVP_CIPHER)* enc, 351 ubyte* kstr, int klen, pem_password_cb* cb, void* u);"; 352 } 353 354 } 355 356 version (OPENSSL_NO_BIO) { 357 string DECLARE_PEM_read_bio(string name, string type)() { return ""; } 358 string DECLARE_PEM_write_bio(string name, string type)() { return ""; } 359 string DECLARE_PEM_write_bio_const(string name, string type)() { return ""; } 360 string DECLARE_PEM_write_cb_bio(string name, string type)() { return ""; } 361 } else { 362 string DECLARE_PEM_read_bio(string name, string type)() { 363 return type ~ "* PEM_read_bio_" ~ name ~ "(BIO* bp, " ~ type ~ "** x, pem_password_cb* cb, void* u);"; 364 } 365 366 string DECLARE_PEM_write_bio(string name, string type)() { 367 return "int PEM_write_bio_" ~ name ~ "(BIO* bp, " ~ type ~ "* x);"; 368 } 369 370 string DECLARE_PEM_write_bio_const(string name, string type)() { 371 return "int PEM_write_bio_" ~ name ~ "(BIO* bp, const(" ~ type ~ ")* x);"; 372 } 373 374 string DECLARE_PEM_write_cb_bio(string name, string type)() { 375 return "int PEM_write_bio_" ~ name ~ "(BIO* bp, " ~ type ~ "* x, const(EVP_CIPHER)* enc, 376 ubyte* kstr, int klen, pem_password_cb* cb, void* u);"; 377 } 378 } 379 380 string DECLARE_PEM_write(string name, string type)() { 381 return DECLARE_PEM_write_bio!(name, type)() ~ "\n" ~ 382 DECLARE_PEM_write_fp!(name, type)(); 383 } 384 385 string DECLARE_PEM_write_const(string name, string type)() { 386 return DECLARE_PEM_write_bio_const!(name, type)() ~ "\n" ~ 387 DECLARE_PEM_write_fp_const!(name, type)(); 388 } 389 390 string DECLARE_PEM_write_cb(string name, string type)() { 391 return DECLARE_PEM_write_cb_bio!(name, type)() ~ "\n" ~ 392 DECLARE_PEM_write_cb_fp!(name, type)(); 393 } 394 395 string DECLARE_PEM_read(string name, string type)() { 396 return DECLARE_PEM_read_bio!(name, type)() ~ "\n" ~ 397 DECLARE_PEM_read_fp!(name, type)(); 398 } 399 400 string DECLARE_PEM_rw(string name, string type)() { 401 return DECLARE_PEM_read!(name, type)() ~ "\n" ~ 402 DECLARE_PEM_write!(name, type)(); 403 } 404 405 string DECLARE_PEM_rw_const(string name, string type)() { 406 return DECLARE_PEM_read!(name, type)() ~ "\n" ~ 407 DECLARE_PEM_write_const!(name, type)(); 408 } 409 410 string DECLARE_PEM_rw_cb(string name, string type)() { 411 return DECLARE_PEM_read!(name, type)() ~ "\n" ~ 412 DECLARE_PEM_write_cb!(name, type)(); 413 } 414 415 version (all) { 416 /* "userdata": new with OpenSSL 0.9.4 */ 417 alias typeof(*(ExternC!(int function(char* buf, int size, int rwflag, void* userdata))).init) pem_password_cb; 418 } else { 419 /* OpenSSL 0.9.3, 0.9.3a */ 420 alias typeof(*(ExternC!(int function(char* buf, int size, int rwflag))).init) pem_password_cb; 421 } 422 423 int PEM_get_EVP_CIPHER_INFO(char* header, EVP_CIPHER_INFO* cipher); 424 int PEM_do_header (EVP_CIPHER_INFO* cipher, ubyte* data,c_long* len, 425 pem_password_cb* callback,void* u); 426 427 version(OPENSSL_NO_BIO) {} else { 428 int PEM_read_bio(BIO* bp, char** name, char** header, 429 ubyte** data,c_long* len); 430 int PEM_write_bio(BIO* bp,const(char)* name,char* hdr,ubyte* data, 431 c_long len); 432 int PEM_bytes_read_bio(ubyte** pdata, c_long* plen, char** pnm, const(char)* name, BIO* bp, 433 pem_password_cb* cb, void* u); 434 void* PEM_ASN1_read_bio(d2i_of_void* d2i, const(char)* name, BIO* bp, 435 void** x, pem_password_cb* cb, void* u); 436 int PEM_ASN1_write_bio(i2d_of_void* i2d, const(char)* name,BIO* bp, void* x, 437 const(EVP_CIPHER)* enc,ubyte* kstr,int klen, 438 pem_password_cb* cb, void* u); 439 440 STACK_OF!(X509_INFO) * PEM_X509_INFO_read_bio(BIO* bp, STACK_OF!(X509_INFO) *sk, pem_password_cb* cb, void* u); 441 int PEM_X509_INFO_write_bio(BIO* bp,X509_INFO* xi, EVP_CIPHER* enc, 442 ubyte* kstr, int klen, pem_password_cb* cd, void* u); 443 } 444 445 int PEM_read(FILE* fp, char** name, char** header, 446 ubyte** data,c_long* len); 447 int PEM_write(FILE* fp,char* name,char* hdr,ubyte* data,c_long len); 448 void* PEM_ASN1_read(d2i_of_void* d2i, const(char)* name, FILE* fp, void** x, 449 pem_password_cb* cb, void* u); 450 int PEM_ASN1_write(i2d_of_void* i2d,const(char)* name,FILE* fp, 451 void* x,const(EVP_CIPHER)* enc,ubyte* kstr, 452 int klen,pem_password_cb* callback, void* u); 453 STACK_OF!(X509_INFO) * PEM_X509_INFO_read(FILE* fp, STACK_OF!(X509_INFO) *sk, 454 pem_password_cb* cb, void* u); 455 456 int PEM_SealInit(PEM_ENCODE_SEAL_CTX* ctx, EVP_CIPHER* type, 457 EVP_MD* md_type, ubyte** ek, int* ekl, 458 ubyte* iv, EVP_PKEY** pubk, int npubk); 459 void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX* ctx, ubyte* out_, int* outl, 460 ubyte* in_, int inl); 461 int PEM_SealFinal(PEM_ENCODE_SEAL_CTX* ctx, ubyte* sig,int* sigl, 462 ubyte* out_, int* outl, EVP_PKEY* priv); 463 464 void PEM_SignInit(EVP_MD_CTX* ctx, EVP_MD* type); 465 void PEM_SignUpdate(EVP_MD_CTX* ctx,ubyte* d,uint cnt); 466 int PEM_SignFinal(EVP_MD_CTX* ctx, ubyte* sigret, 467 uint* siglen, EVP_PKEY* pkey); 468 469 int PEM_def_callback(char* buf, int num, int w, void* key); 470 void PEM_proc_type(char* buf, int type); 471 void PEM_dek_info(char* buf, const(char)* type, int len, char* str); 472 473 474 public import deimos.openssl.symhacks; 475 476 mixin(DECLARE_PEM_rw!("X509", "X509")()); 477 478 mixin(DECLARE_PEM_rw!("X509_AUX", "X509")()); 479 480 mixin(DECLARE_PEM_rw!("X509_REQ", "X509_REQ")()); 481 mixin(DECLARE_PEM_write!("X509_REQ_NEW", "X509_REQ")()); 482 483 mixin(DECLARE_PEM_rw!("X509_CRL", "X509_CRL")()); 484 485 mixin(DECLARE_PEM_rw!("PKCS7", "PKCS7")()); 486 487 mixin(DECLARE_PEM_rw!("NETSCAPE_CERT_SEQUENCE", "NETSCAPE_CERT_SEQUENCE")()); 488 489 mixin(DECLARE_PEM_rw!("PKCS8", "X509_SIG")()); 490 491 mixin(DECLARE_PEM_rw!("PKCS8_PRIV_KEY_INFO", "PKCS8_PRIV_KEY_INFO")()); 492 493 version(OPENSSL_NO_RSA) {} else { 494 mixin(DECLARE_PEM_rw_cb!("RSAPrivateKey", "RSA")()); 495 496 mixin(DECLARE_PEM_rw_const!("RSAPublicKey", "RSA")()); 497 mixin(DECLARE_PEM_rw!("RSA_PUBKEY", "RSA")()); 498 499 } 500 501 version(OPENSSL_NO_DSA) {} else { 502 mixin(DECLARE_PEM_rw_cb!("DSAPrivateKey", "DSA")()); 503 504 mixin(DECLARE_PEM_rw!("DSA_PUBKEY", "DSA")()); 505 506 mixin(DECLARE_PEM_rw_const!("DSAparams", "DSA")()); 507 508 } 509 510 version(OPENSSL_NO_EC) {} else { 511 mixin(DECLARE_PEM_rw_const!("ECPKParameters", "EC_GROUP")()); 512 mixin(DECLARE_PEM_rw_cb!("ECPrivateKey", "EC_KEY")()); 513 mixin(DECLARE_PEM_rw!("EC_PUBKEY", "EC_KEY")()); 514 } 515 516 version(OPENSSL_NO_DH) {} else { 517 mixin(DECLARE_PEM_rw_const!("DHparams", "DH")()); 518 519 } 520 521 mixin(DECLARE_PEM_rw_cb!("PrivateKey", "EVP_PKEY")()); 522 523 mixin(DECLARE_PEM_rw!("PUBKEY", "EVP_PKEY")()); 524 525 int PEM_write_bio_PKCS8PrivateKey_nid(BIO* bp, EVP_PKEY* x, int nid, 526 char* kstr, int klen, 527 pem_password_cb* cb, void* u); 528 int PEM_write_bio_PKCS8PrivateKey(BIO*, EVP_PKEY*, const(EVP_CIPHER)*, 529 char*, int, pem_password_cb*, void*); 530 int i2d_PKCS8PrivateKey_bio(BIO* bp, EVP_PKEY* x, const(EVP_CIPHER)* enc, 531 char* kstr, int klen, 532 pem_password_cb* cb, void* u); 533 int i2d_PKCS8PrivateKey_nid_bio(BIO* bp, EVP_PKEY* x, int nid, 534 char* kstr, int klen, 535 pem_password_cb* cb, void* u); 536 EVP_PKEY* d2i_PKCS8PrivateKey_bio(BIO* bp, EVP_PKEY** x, pem_password_cb* cb, void* u); 537 538 int i2d_PKCS8PrivateKey_fp(FILE* fp, EVP_PKEY* x, const(EVP_CIPHER)* enc, 539 char* kstr, int klen, 540 pem_password_cb* cb, void* u); 541 int i2d_PKCS8PrivateKey_nid_fp(FILE* fp, EVP_PKEY* x, int nid, 542 char* kstr, int klen, 543 pem_password_cb* cb, void* u); 544 int PEM_write_PKCS8PrivateKey_nid(FILE* fp, EVP_PKEY* x, int nid, 545 char* kstr, int klen, 546 pem_password_cb* cb, void* u); 547 548 EVP_PKEY* d2i_PKCS8PrivateKey_fp(FILE* fp, EVP_PKEY** x, pem_password_cb* cb, void* u); 549 550 int PEM_write_PKCS8PrivateKey(FILE* fp,EVP_PKEY* x,const(EVP_CIPHER)* enc, 551 char* kstr,int klen, pem_password_cb* cd, void* u); 552 553 EVP_PKEY* PEM_read_bio_Parameters(BIO* bp, EVP_PKEY** x); 554 int PEM_write_bio_Parameters(BIO* bp, EVP_PKEY* x); 555 556 557 EVP_PKEY* b2i_PrivateKey(const(ubyte)** in_, c_long length); 558 EVP_PKEY* b2i_PublicKey(const(ubyte)** in_, c_long length); 559 EVP_PKEY* b2i_PrivateKey_bio(BIO* in_); 560 EVP_PKEY* b2i_PublicKey_bio(BIO* in_); 561 int i2b_PrivateKey_bio(BIO* out_, EVP_PKEY* pk); 562 int i2b_PublicKey_bio(BIO* out_, EVP_PKEY* pk); 563 version(OPENSSL_NO_RC4) {} else { 564 EVP_PKEY* b2i_PVK_bio(BIO* in_, pem_password_cb* cb, void* u); 565 int i2b_PVK_bio(BIO* out_, EVP_PKEY* pk, int enclevel, 566 pem_password_cb* cb, void* u); 567 } 568 569 570 /* BEGIN ERROR CODES */ 571 /* The following lines are auto generated by the script mkerr.pl. Any changes 572 * made after this point may be overwritten when the script is next run. 573 */ 574 void ERR_load_PEM_strings(); 575 576 /* Error codes for the PEM functions. */ 577 578 /* Function codes. */ 579 enum PEM_F_B2I_DSS = 127; 580 enum PEM_F_B2I_PVK_BIO = 128; 581 enum PEM_F_B2I_RSA = 129; 582 enum PEM_F_CHECK_BITLEN_DSA = 130; 583 enum PEM_F_CHECK_BITLEN_RSA = 131; 584 enum PEM_F_D2I_PKCS8PRIVATEKEY_BIO = 120; 585 enum PEM_F_D2I_PKCS8PRIVATEKEY_FP = 121; 586 enum PEM_F_DO_B2I = 132; 587 enum PEM_F_DO_B2I_BIO = 133; 588 enum PEM_F_DO_BLOB_HEADER = 134; 589 enum PEM_F_DO_PK8PKEY = 126; 590 enum PEM_F_DO_PK8PKEY_FP = 125; 591 enum PEM_F_DO_PVK_BODY = 135; 592 enum PEM_F_DO_PVK_HEADER = 136; 593 enum PEM_F_I2B_PVK = 137; 594 enum PEM_F_I2B_PVK_BIO = 138; 595 enum PEM_F_LOAD_IV = 101; 596 enum PEM_F_PEM_ASN1_READ = 102; 597 enum PEM_F_PEM_ASN1_READ_BIO = 103; 598 enum PEM_F_PEM_ASN1_WRITE = 104; 599 enum PEM_F_PEM_ASN1_WRITE_BIO = 105; 600 enum PEM_F_PEM_DEF_CALLBACK = 100; 601 enum PEM_F_PEM_DO_HEADER = 106; 602 enum PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY = 118; 603 enum PEM_F_PEM_GET_EVP_CIPHER_INFO = 107; 604 enum PEM_F_PEM_PK8PKEY = 119; 605 enum PEM_F_PEM_READ = 108; 606 enum PEM_F_PEM_READ_BIO = 109; 607 enum PEM_F_PEM_READ_BIO_PARAMETERS = 140; 608 enum PEM_F_PEM_READ_BIO_PRIVATEKEY = 123; 609 enum PEM_F_PEM_READ_PRIVATEKEY = 124; 610 enum PEM_F_PEM_SEALFINAL = 110; 611 enum PEM_F_PEM_SEALINIT = 111; 612 enum PEM_F_PEM_SIGNFINAL = 112; 613 enum PEM_F_PEM_WRITE = 113; 614 enum PEM_F_PEM_WRITE_BIO = 114; 615 enum PEM_F_PEM_WRITE_PRIVATEKEY = 139; 616 enum PEM_F_PEM_X509_INFO_READ = 115; 617 enum PEM_F_PEM_X509_INFO_READ_BIO = 116; 618 enum PEM_F_PEM_X509_INFO_WRITE_BIO = 117; 619 620 /* Reason codes. */ 621 enum PEM_R_BAD_BASE64_DECODE = 100; 622 enum PEM_R_BAD_DECRYPT = 101; 623 enum PEM_R_BAD_END_LINE = 102; 624 enum PEM_R_BAD_IV_CHARS = 103; 625 enum PEM_R_BAD_MAGIC_NUMBER = 116; 626 enum PEM_R_BAD_PASSWORD_READ = 104; 627 enum PEM_R_BAD_VERSION_NUMBER = 117; 628 enum PEM_R_BIO_WRITE_FAILURE = 118; 629 enum PEM_R_CIPHER_IS_NULL = 127; 630 enum PEM_R_ERROR_CONVERTING_PRIVATE_KEY = 115; 631 enum PEM_R_EXPECTING_PRIVATE_KEY_BLOB = 119; 632 enum PEM_R_EXPECTING_PUBLIC_KEY_BLOB = 120; 633 enum PEM_R_INCONSISTENT_HEADER = 121; 634 enum PEM_R_KEYBLOB_HEADER_PARSE_ERROR = 122; 635 enum PEM_R_KEYBLOB_TOO_SHORT = 123; 636 enum PEM_R_NOT_DEK_INFO = 105; 637 enum PEM_R_NOT_ENCRYPTED = 106; 638 enum PEM_R_NOT_PROC_TYPE = 107; 639 enum PEM_R_NO_START_LINE = 108; 640 enum PEM_R_PROBLEMS_GETTING_PASSWORD = 109; 641 enum PEM_R_PUBLIC_KEY_NO_RSA = 110; 642 enum PEM_R_PVK_DATA_TOO_SHORT = 124; 643 enum PEM_R_PVK_TOO_SHORT = 125; 644 enum PEM_R_READ_KEY = 111; 645 enum PEM_R_SHORT_HEADER = 112; 646 enum PEM_R_UNSUPPORTED_CIPHER = 113; 647 enum PEM_R_UNSUPPORTED_ENCRYPTION = 114; 648 enum PEM_R_UNSUPPORTED_KEY_COMPONENTS = 126;