summaryrefslogtreecommitdiff
path: root/src/lib/libc
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/lib/libcrypto/doc/EVP_DigestInit.pod63
-rw-r--r--src/lib/libcrypto/doc/EVP_EncryptInit.pod64
-rw-r--r--src/lib/libcrypto/doc/EVP_PKEY_keygen.pod22
-rw-r--r--src/lib/libcrypto/doc/PEM_read_bio_PrivateKey.pod56
-rw-r--r--src/lib/libcrypto/doc/X509_NAME_get_index_by_NID.pod10
-rw-r--r--src/lib/libcrypto/doc/X509_STORE_CTX_set_verify_cb.pod76
-rw-r--r--src/lib/libcrypto/doc/engine.pod88
7 files changed, 201 insertions, 178 deletions
diff --git a/src/lib/libcrypto/doc/EVP_DigestInit.pod b/src/lib/libcrypto/doc/EVP_DigestInit.pod
index 2ff01b9c7c..f2c1cfdbf0 100644
--- a/src/lib/libcrypto/doc/EVP_DigestInit.pod
+++ b/src/lib/libcrypto/doc/EVP_DigestInit.pod
@@ -215,39 +215,40 @@ digest name passed on the command line.
215 #include <stdio.h> 215 #include <stdio.h>
216 #include <openssl/evp.h> 216 #include <openssl/evp.h>
217 217
218 int
218 main(int argc, char *argv[]) 219 main(int argc, char *argv[])
219 { 220 {
220 EVP_MD_CTX *mdctx; 221 EVP_MD_CTX *mdctx;
221 const EVP_MD *md; 222 const EVP_MD *md;
222 char mess1[] = "Test Message\n"; 223 const char mess1[] = "Test Message\n";
223 char mess2[] = "Hello World\n"; 224 const char mess2[] = "Hello World\n";
224 unsigned char md_value[EVP_MAX_MD_SIZE]; 225 unsigned char md_value[EVP_MAX_MD_SIZE];
225 int md_len, i; 226 int md_len, i;
226 227
227 OpenSSL_add_all_digests(); 228 OpenSSL_add_all_digests();
228 229
229 if(!argv[1]) { 230 if (argc <= 1) {
230 printf("Usage: mdtest digestname\n"); 231 printf("Usage: mdtest digestname\n");
231 exit(1); 232 exit(1);
232 } 233 }
233 234
234 md = EVP_get_digestbyname(argv[1]); 235 md = EVP_get_digestbyname(argv[1]);
235 236 if (md == NULL) {
236 if(!md) { 237 printf("Unknown message digest %s\n", argv[1]);
237 printf("Unknown message digest %s\n", argv[1]); 238 exit(1);
238 exit(1); 239 }
239 } 240
240 241 mdctx = EVP_MD_CTX_create();
241 mdctx = EVP_MD_CTX_create(); 242 EVP_DigestInit_ex(mdctx, md, NULL);
242 EVP_DigestInit_ex(mdctx, md, NULL); 243 EVP_DigestUpdate(mdctx, mess1, strlen(mess1));
243 EVP_DigestUpdate(mdctx, mess1, strlen(mess1)); 244 EVP_DigestUpdate(mdctx, mess2, strlen(mess2));
244 EVP_DigestUpdate(mdctx, mess2, strlen(mess2)); 245 EVP_DigestFinal_ex(mdctx, md_value, &md_len);
245 EVP_DigestFinal_ex(mdctx, md_value, &md_len); 246 EVP_MD_CTX_destroy(mdctx);
246 EVP_MD_CTX_destroy(mdctx); 247
247 248 printf("Digest is: ");
248 printf("Digest is: "); 249 for(i = 0; i < md_len; i++)
249 for(i = 0; i < md_len; i++) printf("%02x", md_value[i]); 250 printf("%02x", md_value[i]);
250 printf("\n"); 251 printf("\n");
251 } 252 }
252 253
253=head1 SEE ALSO 254=head1 SEE ALSO
diff --git a/src/lib/libcrypto/doc/EVP_EncryptInit.pod b/src/lib/libcrypto/doc/EVP_EncryptInit.pod
index a876ac789c..b2211ea6d3 100644
--- a/src/lib/libcrypto/doc/EVP_EncryptInit.pod
+++ b/src/lib/libcrypto/doc/EVP_EncryptInit.pod
@@ -427,46 +427,49 @@ Set the effective key length used in RC2:
427 427
428Encrypt a string using blowfish: 428Encrypt a string using blowfish:
429 429
430 int do_crypt(char *outfile) 430 int
431 { 431 do_crypt(char *outfile)
432 {
432 unsigned char outbuf[1024]; 433 unsigned char outbuf[1024];
433 int outlen, tmplen; 434 int outlen, tmplen;
434 /* Bogus key and IV: we'd normally set these from 435 /*
436 * Bogus key and IV: we'd normally set these from
435 * another source. 437 * another source.
436 */ 438 */
437 unsigned char key[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; 439 unsigned char key[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
438 unsigned char iv[] = {1,2,3,4,5,6,7,8}; 440 unsigned char iv[] = {1,2,3,4,5,6,7,8};
439 char intext[] = "Some Crypto Text"; 441 const char intext[] = "Some Crypto Text";
440 EVP_CIPHER_CTX ctx; 442 EVP_CIPHER_CTX ctx;
441 FILE *out; 443 FILE *out;
442 EVP_CIPHER_CTX_init(&ctx); 444 EVP_CIPHER_CTX_init(&ctx);
443 EVP_EncryptInit_ex(&ctx, EVP_bf_cbc(), NULL, key, iv); 445 EVP_EncryptInit_ex(&ctx, EVP_bf_cbc(), NULL, key, iv);
444 446
445 if(!EVP_EncryptUpdate(&ctx, outbuf, &outlen, intext, strlen(intext))) 447 if (!EVP_EncryptUpdate(&ctx, outbuf, &outlen, intext,
446 { 448 strlen(intext))) {
447 /* Error */ 449 /* Error */
448 return 0; 450 return 0;
449 } 451 }
450 /* Buffer passed to EVP_EncryptFinal() must be after data just 452 /*
453 * Buffer passed to EVP_EncryptFinal() must be after data just
451 * encrypted to avoid overwriting it. 454 * encrypted to avoid overwriting it.
452 */ 455 */
453 if(!EVP_EncryptFinal_ex(&ctx, outbuf + outlen, &tmplen)) 456 if (!EVP_EncryptFinal_ex(&ctx, outbuf + outlen, &tmplen)) {
454 {
455 /* Error */ 457 /* Error */
456 return 0; 458 return 0;
457 } 459 }
458 outlen += tmplen; 460 outlen += tmplen;
459 EVP_CIPHER_CTX_cleanup(&ctx); 461 EVP_CIPHER_CTX_cleanup(&ctx);
460 /* Need binary mode for fopen because encrypted data is 462 /*
463 * Need binary mode for fopen because encrypted data is
461 * binary data. Also cannot use strlen() on it because 464 * binary data. Also cannot use strlen() on it because
462 * it wont be null terminated and may contain embedded 465 * it won't be NUL terminated and may contain embedded
463 * nulls. 466 * NULs.
464 */ 467 */
465 out = fopen(outfile, "wb"); 468 out = fopen(outfile, "wb");
466 fwrite(outbuf, 1, outlen, out); 469 fwrite(outbuf, 1, outlen, out);
467 fclose(out); 470 fclose(out);
468 return 1; 471 return 1;
469 } 472 }
470 473
471The ciphertext from the above example can be decrypted using the B<openssl> 474The ciphertext from the above example can be decrypted using the B<openssl>
472utility with the command line: 475utility with the command line:
@@ -476,16 +479,19 @@ utility with the command line:
476General encryption, decryption function example using FILE I/O and RC2 with an 479General encryption, decryption function example using FILE I/O and RC2 with an
47780 bit key: 48080 bit key:
478 481
479 int do_crypt(FILE *in, FILE *out, int do_encrypt) 482 int
480 { 483 do_crypt(FILE *in, FILE *out, int do_encrypt)
484 {
481 /* Allow enough space in output buffer for additional block */ 485 /* Allow enough space in output buffer for additional block */
482 inbuf[1024], outbuf[1024 + EVP_MAX_BLOCK_LENGTH]; 486 inbuf[1024], outbuf[1024 + EVP_MAX_BLOCK_LENGTH];
483 int inlen, outlen; 487 int inlen, outlen;
484 /* Bogus key and IV: we'd normally set these from 488 /*
489 * Bogus key and IV: we'd normally set these from
485 * another source. 490 * another source.
486 */ 491 */
487 unsigned char key[] = "0123456789"; 492 unsigned char key[] = "0123456789";
488 unsigned char iv[] = "12345678"; 493 unsigned char iv[] = "12345678";
494
489 /* Don't set key or IV because we will modify the parameters */ 495 /* Don't set key or IV because we will modify the parameters */
490 EVP_CIPHER_CTX_init(&ctx); 496 EVP_CIPHER_CTX_init(&ctx);
491 EVP_CipherInit_ex(&ctx, EVP_rc2(), NULL, NULL, NULL, do_encrypt); 497 EVP_CipherInit_ex(&ctx, EVP_rc2(), NULL, NULL, NULL, do_encrypt);
@@ -493,30 +499,28 @@ General encryption, decryption function example using FILE I/O and RC2 with an
493 /* We finished modifying parameters so now we can set key and IV */ 499 /* We finished modifying parameters so now we can set key and IV */
494 EVP_CipherInit_ex(&ctx, NULL, NULL, key, iv, do_encrypt); 500 EVP_CipherInit_ex(&ctx, NULL, NULL, key, iv, do_encrypt);
495 501
496 for(;;) 502 for(;;) {
497 {
498 inlen = fread(inbuf, 1, 1024, in); 503 inlen = fread(inbuf, 1, 1024, in);
499 if(inlen <= 0) break; 504 if (inlen <= 0)
500 if(!EVP_CipherUpdate(&ctx, outbuf, &outlen, inbuf, inlen)) 505 break;
501 { 506 if (!EVP_CipherUpdate(&ctx, outbuf, &outlen, inbuf,
507 inlen)) {
502 /* Error */ 508 /* Error */
503 EVP_CIPHER_CTX_cleanup(&ctx); 509 EVP_CIPHER_CTX_cleanup(&ctx);
504 return 0; 510 return 0;
505 }
506 fwrite(outbuf, 1, outlen, out);
507 } 511 }
508 if(!EVP_CipherFinal_ex(&ctx, outbuf, &outlen)) 512 fwrite(outbuf, 1, outlen, out);
509 { 513 }
514 if (!EVP_CipherFinal_ex(&ctx, outbuf, &outlen)) {
510 /* Error */ 515 /* Error */
511 EVP_CIPHER_CTX_cleanup(&ctx); 516 EVP_CIPHER_CTX_cleanup(&ctx);
512 return 0; 517 return 0;
513 } 518 }
514 fwrite(outbuf, 1, outlen, out); 519 fwrite(outbuf, 1, outlen, out);
515 520
516 EVP_CIPHER_CTX_cleanup(&ctx); 521 EVP_CIPHER_CTX_cleanup(&ctx);
517 return 1; 522 return 1;
518 } 523 }
519
520 524
521=head1 SEE ALSO 525=head1 SEE ALSO
522 526
diff --git a/src/lib/libcrypto/doc/EVP_PKEY_keygen.pod b/src/lib/libcrypto/doc/EVP_PKEY_keygen.pod
index 378fb310ff..05ea04be11 100644
--- a/src/lib/libcrypto/doc/EVP_PKEY_keygen.pod
+++ b/src/lib/libcrypto/doc/EVP_PKEY_keygen.pod
@@ -132,20 +132,26 @@ Example of generation callback for OpenSSL public key implementations:
132 132
133 EVP_PKEY_CTX_set_app_data(ctx, status_bio); 133 EVP_PKEY_CTX_set_app_data(ctx, status_bio);
134 134
135 static int genpkey_cb(EVP_PKEY_CTX *ctx) 135 static int
136 { 136 genpkey_cb(EVP_PKEY_CTX *ctx)
137 char c='*'; 137 {
138 char c = '*';
138 BIO *b = EVP_PKEY_CTX_get_app_data(ctx); 139 BIO *b = EVP_PKEY_CTX_get_app_data(ctx);
139 int p; 140 int p;
141
140 p = EVP_PKEY_CTX_get_keygen_info(ctx, 0); 142 p = EVP_PKEY_CTX_get_keygen_info(ctx, 0);
141 if (p == 0) c='.'; 143 if (p == 0)
142 if (p == 1) c='+'; 144 c='.';
143 if (p == 2) c='*'; 145 if (p == 1)
144 if (p == 3) c='\n'; 146 c='+';
147 if (p == 2)
148 c='*';
149 if (p == 3)
150 c='\n';
145 BIO_write(b,&c,1); 151 BIO_write(b,&c,1);
146 (void)BIO_flush(b); 152 (void)BIO_flush(b);
147 return 1; 153 return 1;
148 } 154 }
149 155
150=head1 SEE ALSO 156=head1 SEE ALSO
151 157
diff --git a/src/lib/libcrypto/doc/PEM_read_bio_PrivateKey.pod b/src/lib/libcrypto/doc/PEM_read_bio_PrivateKey.pod
index 0d9270985a..6d87079a84 100644
--- a/src/lib/libcrypto/doc/PEM_read_bio_PrivateKey.pod
+++ b/src/lib/libcrypto/doc/PEM_read_bio_PrivateKey.pod
@@ -353,71 +353,67 @@ Read a certificate in PEM format from a BIO:
353 353
354 X509 *x; 354 X509 *x;
355 x = PEM_read_bio_X509(bp, NULL, 0, NULL); 355 x = PEM_read_bio_X509(bp, NULL, 0, NULL);
356 if (x == NULL) 356 if (x == NULL) {
357 {
358 /* Error */ 357 /* Error */
359 } 358 }
360 359
361Alternative method: 360Alternative method:
362 361
363 X509 *x = NULL; 362 X509 *x = NULL;
364 if (!PEM_read_bio_X509(bp, &x, 0, NULL)) 363 if (!PEM_read_bio_X509(bp, &x, 0, NULL)) {
365 {
366 /* Error */ 364 /* Error */
367 } 365 }
368 366
369Write a certificate to a BIO: 367Write a certificate to a BIO:
370 368
371 if (!PEM_write_bio_X509(bp, x)) 369 if (!PEM_write_bio_X509(bp, x)) {
372 {
373 /* Error */ 370 /* Error */
374 } 371 }
375 372
376Write an unencrypted private key to a FILE pointer: 373Write an unencrypted private key to a FILE pointer:
377 374
378 if (!PEM_write_PrivateKey(fp, key, NULL, NULL, 0, 0, NULL)) 375 if (!PEM_write_PrivateKey(fp, key, NULL, NULL, 0, 0, NULL)) {
379 {
380 /* Error */ 376 /* Error */
381 } 377 }
382 378
383Write a private key (using traditional format) to a BIO using 379Write a private key (using traditional format) to a BIO using
384triple DES encryption, the pass phrase is prompted for: 380triple DES encryption, the pass phrase is prompted for:
385 381
386 if (!PEM_write_bio_PrivateKey(bp, key, EVP_des_ede3_cbc(), NULL, 0, 0, NULL)) 382 if (!PEM_write_bio_PrivateKey(bp, key, EVP_des_ede3_cbc(),
387 { 383 NULL, 0, 0, NULL)) {
388 /* Error */ 384 /* Error */
389 } 385 }
390 386
391Write a private key (using PKCS#8 format) to a BIO using triple 387Write a private key (using PKCS#8 format) to a BIO using triple
392DES encryption, using the pass phrase "hello": 388DES encryption, using the pass phrase "hello":
393 389
394 if (!PEM_write_bio_PKCS8PrivateKey(bp, key, EVP_des_ede3_cbc(), NULL, 0, 0, "hello")) 390 if (!PEM_write_bio_PKCS8PrivateKey(bp, key, EVP_des_ede3_cbc(),
395 { 391 NULL, 0, 0, "hello")) {
396 /* Error */ 392 /* Error */
397 } 393 }
398 394
399Read a private key from a BIO using the pass phrase "hello": 395Read a private key from a BIO using the pass phrase "hello":
400 396
401 key = PEM_read_bio_PrivateKey(bp, NULL, 0, "hello"); 397 key = PEM_read_bio_PrivateKey(bp, NULL, 0, "hello");
402 if (key == NULL) 398 if (key == NULL) {
403 {
404 /* Error */ 399 /* Error */
405 } 400 }
406 401
407Read a private key from a BIO using a pass phrase callback: 402Read a private key from a BIO using a pass phrase callback:
408 403
409 key = PEM_read_bio_PrivateKey(bp, NULL, pass_cb, "My Private Key"); 404 key = PEM_read_bio_PrivateKey(bp, NULL, pass_cb, "My Private Key");
410 if (key == NULL) 405 if (key == NULL) {
411 {
412 /* Error */ 406 /* Error */
413 } 407 }
414 408
415Skeleton pass phrase callback: 409Skeleton pass phrase callback:
416 410
417 int pass_cb(char *buf, int size, int rwflag, void *u); 411 int
418 { 412 pass_cb(char *buf, int size, int rwflag, void *u)
413 {
419 int len; 414 int len;
420 char *tmp; 415 char *tmp;
416
421 /* We'd probably do something else if 'rwflag' is 1 */ 417 /* We'd probably do something else if 'rwflag' is 1 */
422 printf("Enter pass phrase for \"%s\"\n", u); 418 printf("Enter pass phrase for \"%s\"\n", u);
423 419
@@ -425,12 +421,14 @@ Skeleton pass phrase callback:
425 tmp = "hello"; 421 tmp = "hello";
426 len = strlen(tmp); 422 len = strlen(tmp);
427 423
428 if (len <= 0) return 0; 424 if (len == 0)
425 return 0;
429 /* if too long, truncate */ 426 /* if too long, truncate */
430 if (len > size) len = size; 427 if (len > size)
428 len = size;
431 memcpy(buf, tmp, len); 429 memcpy(buf, tmp, len);
432 return len; 430 return len;
433 } 431 }
434 432
435=head1 NOTES 433=head1 NOTES
436 434
diff --git a/src/lib/libcrypto/doc/X509_NAME_get_index_by_NID.pod b/src/lib/libcrypto/doc/X509_NAME_get_index_by_NID.pod
index 9c694c9867..988fd7bdaf 100644
--- a/src/lib/libcrypto/doc/X509_NAME_get_index_by_NID.pod
+++ b/src/lib/libcrypto/doc/X509_NAME_get_index_by_NID.pod
@@ -66,11 +66,10 @@ Process all entries:
66 int i; 66 int i;
67 X509_NAME_ENTRY *e; 67 X509_NAME_ENTRY *e;
68 68
69 for (i = 0; i < X509_NAME_entry_count(nm); i++) 69 for (i = 0; i < X509_NAME_entry_count(nm); i++) {
70 {
71 e = X509_NAME_get_entry(nm, i); 70 e = X509_NAME_get_entry(nm, i);
72 /* Do something with e */ 71 /* Do something with e */
73 } 72 }
74 73
75Process all commonName entries: 74Process all commonName entries:
76 75
@@ -78,14 +77,13 @@ Process all commonName entries:
78 X509_NAME_ENTRY *e; 77 X509_NAME_ENTRY *e;
79 78
80 loc = -1; 79 loc = -1;
81 for (;;) 80 for (;;) {
82 {
83 lastpos = X509_NAME_get_index_by_NID(nm, NID_commonName, lastpos); 81 lastpos = X509_NAME_get_index_by_NID(nm, NID_commonName, lastpos);
84 if (lastpos == -1) 82 if (lastpos == -1)
85 break; 83 break;
86 e = X509_NAME_get_entry(nm, lastpos); 84 e = X509_NAME_get_entry(nm, lastpos);
87 /* Do something with e */ 85 /* Do something with e */
88 } 86 }
89 87
90=head1 RETURN VALUES 88=head1 RETURN VALUES
91 89
diff --git a/src/lib/libcrypto/doc/X509_STORE_CTX_set_verify_cb.pod b/src/lib/libcrypto/doc/X509_STORE_CTX_set_verify_cb.pod
index 86d988eee0..7dfe430c4c 100644
--- a/src/lib/libcrypto/doc/X509_STORE_CTX_set_verify_cb.pod
+++ b/src/lib/libcrypto/doc/X509_STORE_CTX_set_verify_cb.pod
@@ -59,44 +59,48 @@ X509_STORE_CTX_set_verify_cb() does not return a value.
59 59
60Default callback operation: 60Default callback operation:
61 61
62 int verify_callback(int ok, X509_STORE_CTX *ctx) 62 int
63 { 63 verify_callback(int ok, X509_STORE_CTX *ctx)
64 {
64 return ok; 65 return ok;
65 } 66 }
66 67
67Simple example, suppose a certificate in the chain is expired and we wish 68Simple example, suppose a certificate in the chain is expired and we wish
68to continue after this error: 69to continue after this error:
69 70
70 int verify_callback(int ok, X509_STORE_CTX *ctx) 71 int
71 { 72 verify_callback(int ok, X509_STORE_CTX *ctx)
73 {
72 /* Tolerate certificate expiration */ 74 /* Tolerate certificate expiration */
73 if (X509_STORE_CTX_get_error(ctx) == X509_V_ERR_CERT_HAS_EXPIRED) 75 if (X509_STORE_CTX_get_error(ctx) == X509_V_ERR_CERT_HAS_EXPIRED)
74 return 1; 76 return 1;
75 /* Otherwise don't override */ 77 /* Otherwise don't override */
76 return ok; 78 return ok;
77 } 79 }
78 80
79More complex example, we don't wish to continue after B<any> certificate has 81More complex example, we don't wish to continue after B<any> certificate has
80expired just one specific case: 82expired just one specific case:
81 83
82 int verify_callback(int ok, X509_STORE_CTX *ctx) 84 int
83 { 85 verify_callback(int ok, X509_STORE_CTX *ctx)
86 {
84 int err = X509_STORE_CTX_get_error(ctx); 87 int err = X509_STORE_CTX_get_error(ctx);
85 X509 *err_cert = X509_STORE_CTX_get_current_cert(ctx); 88 X509 *err_cert = X509_STORE_CTX_get_current_cert(ctx);
86 if (err == X509_V_ERR_CERT_HAS_EXPIRED) 89
87 { 90 if (err == X509_V_ERR_CERT_HAS_EXPIRED) {
88 if (check_is_acceptable_expired_cert(err_cert) 91 if (check_is_acceptable_expired_cert(err_cert)
89 return 1; 92 return 1;
90 }
91 return ok;
92 } 93 }
94 return ok;
95 }
93 96
94Full featured logging callback. In this case the B<bio_err> is assumed to be 97Full featured logging callback. In this case the B<bio_err> is assumed to be
95a global logging B<BIO>, an alternative would to store a BIO in B<ctx> using 98a global logging B<BIO>, an alternative would to store a BIO in B<ctx> using
96B<ex_data>. 99B<ex_data>.
97 100
98 int verify_callback(int ok, X509_STORE_CTX *ctx) 101 int
99 { 102 verify_callback(int ok, X509_STORE_CTX *ctx)
103 {
100 X509 *err_cert; 104 X509 *err_cert;
101 int err,depth; 105 int err,depth;
102 106
@@ -105,47 +109,47 @@ B<ex_data>.
105 depth = X509_STORE_CTX_get_error_depth(ctx); 109 depth = X509_STORE_CTX_get_error_depth(ctx);
106 110
107 BIO_printf(bio_err,"depth=%d ",depth); 111 BIO_printf(bio_err,"depth=%d ",depth);
108 if (err_cert) 112 if (err_cert) {
109 { 113 X509_NAME_print_ex(bio_err,
110 X509_NAME_print_ex(bio_err, X509_get_subject_name(err_cert), 114 X509_get_subject_name(err_cert), 0,
111 0, XN_FLAG_ONELINE); 115 XN_FLAG_ONELINE);
112 BIO_puts(bio_err, "\n"); 116 BIO_puts(bio_err, "\n");
113 } 117 } else
114 else
115 BIO_puts(bio_err, "<no cert>\n"); 118 BIO_puts(bio_err, "<no cert>\n");
116 if (!ok) 119 if (!ok)
117 BIO_printf(bio_err,"verify error:num=%d:%s\n",err, 120 BIO_printf(bio_err, "verify error:num=%d:%s\n",
118 X509_verify_cert_error_string(err)); 121 err, X509_verify_cert_error_string(err));
119 switch (err) 122 switch (err) {
120 {
121 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT: 123 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
122 BIO_puts(bio_err,"issuer= "); 124 BIO_puts(bio_err, "issuer= ");
123 X509_NAME_print_ex(bio_err, X509_get_issuer_name(err_cert), 125 X509_NAME_print_ex(bio_err,
124 0, XN_FLAG_ONELINE); 126 X509_get_issuer_name(err_cert), 0,
127 XN_FLAG_ONELINE);
125 BIO_puts(bio_err, "\n"); 128 BIO_puts(bio_err, "\n");
126 break; 129 break;
127 case X509_V_ERR_CERT_NOT_YET_VALID: 130 case X509_V_ERR_CERT_NOT_YET_VALID:
128 case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD: 131 case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
129 BIO_printf(bio_err,"notBefore="); 132 BIO_printf(bio_err, "notBefore=");
130 ASN1_TIME_print(bio_err,X509_get_notBefore(err_cert)); 133 ASN1_TIME_print(bio_err,
131 BIO_printf(bio_err,"\n"); 134 X509_get_notBefore(err_cert));
135 BIO_printf(bio_err, "\n");
132 break; 136 break;
133 case X509_V_ERR_CERT_HAS_EXPIRED: 137 case X509_V_ERR_CERT_HAS_EXPIRED:
134 case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD: 138 case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
135 BIO_printf(bio_err,"notAfter="); 139 BIO_printf(bio_err, "notAfter=");
136 ASN1_TIME_print(bio_err,X509_get_notAfter(err_cert)); 140 ASN1_TIME_print(bio_err, X509_get_notAfter(err_cert));
137 BIO_printf(bio_err,"\n"); 141 BIO_printf(bio_err, "\n");
138 break; 142 break;
139 case X509_V_ERR_NO_EXPLICIT_POLICY: 143 case X509_V_ERR_NO_EXPLICIT_POLICY:
140 policies_print(bio_err, ctx); 144 policies_print(bio_err, ctx);
141 break; 145 break;
142 } 146 }
143 if (err == X509_V_OK && ok == 2) 147 if (err == X509_V_OK && ok == 2)
144 /* print out policies */ 148 /* print out policies */
145 149
146 BIO_printf(bio_err,"verify return:%d\n",ok); 150 BIO_printf(bio_err,"verify return:%d\n",ok);
147 return(ok); 151 return(ok);
148 } 152 }
149 153
150=head1 SEE ALSO 154=head1 SEE ALSO
151 155
diff --git a/src/lib/libcrypto/doc/engine.pod b/src/lib/libcrypto/doc/engine.pod
index 4648af7543..4a6ee59138 100644
--- a/src/lib/libcrypto/doc/engine.pod
+++ b/src/lib/libcrypto/doc/engine.pod
@@ -363,15 +363,15 @@ illustrates how to approach this;
363 const char *engine_id = "ACME"; 363 const char *engine_id = "ACME";
364 ENGINE_load_builtin_engines(); 364 ENGINE_load_builtin_engines();
365 e = ENGINE_by_id(engine_id); 365 e = ENGINE_by_id(engine_id);
366 if(!e) 366 if (!e)
367 /* the engine isn't available */ 367 /* the engine isn't available */
368 return; 368 return;
369 if(!ENGINE_init(e)) { 369 if (!ENGINE_init(e)) {
370 /* the engine couldn't initialise, release 'e' */ 370 /* the engine couldn't initialise, release 'e' */
371 ENGINE_free(e); 371 ENGINE_free(e);
372 return; 372 return;
373 } 373 }
374 if(!ENGINE_set_default_RSA(e)) 374 if (!ENGINE_set_default_RSA(e))
375 /* This should only happen when 'e' can't initialise, but the previous 375 /* This should only happen when 'e' can't initialise, but the previous
376 * statement suggests it did. */ 376 * statement suggests it did. */
377 abort(); 377 abort();
@@ -445,42 +445,54 @@ cases but the name can not. This function should initialise the ENGINE
445and set it as the default for everything except RAND and then return a 445and set it as the default for everything except RAND and then return a
446boolean success or failure. 446boolean success or failure.
447 447
448 int generic_load_engine_fn(const char *engine_id, 448 int
449 const char **pre_cmds, int pre_num, 449 generic_load_engine_fn(const char *engine_id,
450 const char **post_cmds, int post_num) 450 const char **pre_cmds, int pre_num,
451 const char **post_cmds, int post_num)
451 { 452 {
452 ENGINE *e = ENGINE_by_id(engine_id); 453 ENGINE *e = ENGINE_by_id(engine_id);
453 if(!e) return 0; 454
454 while(pre_num--) { 455 if (!e)
455 if(!ENGINE_ctrl_cmd_string(e, pre_cmds[0], pre_cmds[1], 0)) { 456 return 0;
456 fprintf(stderr, "Failed command (%s - %s:%s)\n", engine_id, 457 while (pre_num--) {
457 pre_cmds[0], pre_cmds[1] ? pre_cmds[1] : "(NULL)"); 458 if (!ENGINE_ctrl_cmd_string(e,
458 ENGINE_free(e); 459 pre_cmds[0], pre_cmds[1], 0)) {
459 return 0; 460 fprintf(stderr,
460 } 461 "Failed command (%s - %s:%s)\n",
461 pre_cmds += 2; 462 engine_id, pre_cmds[0],
462 } 463 pre_cmds[1] ? pre_cmds[1] : "(NULL)");
463 if(!ENGINE_init(e)) { 464 ENGINE_free(e);
464 fprintf(stderr, "Failed initialisation\n"); 465 return 0;
465 ENGINE_free(e); 466 }
466 return 0; 467 pre_cmds += 2;
467 } 468 }
468 /* ENGINE_init() returned a functional reference, so free the structural 469 if (!ENGINE_init(e)) {
469 * reference from ENGINE_by_id(). */ 470 fprintf(stderr, "Failed initialisation\n");
470 ENGINE_free(e); 471 ENGINE_free(e);
471 while(post_num--) { 472 return 0;
472 if(!ENGINE_ctrl_cmd_string(e, post_cmds[0], post_cmds[1], 0)) { 473 }
473 fprintf(stderr, "Failed command (%s - %s:%s)\n", engine_id, 474 /*
474 post_cmds[0], post_cmds[1] ? post_cmds[1] : "(NULL)"); 475 * ENGINE_init() returned a functional reference,
475 ENGINE_finish(e); 476 * so free the structural reference from
476 return 0; 477 * ENGINE_by_id().
477 } 478 */
478 post_cmds += 2; 479 ENGINE_free(e);
479 } 480 while (post_num--) {
480 ENGINE_set_default(e, ENGINE_METHOD_ALL & ~ENGINE_METHOD_RAND); 481 if (!ENGINE_ctrl_cmd_string(e,
481 /* Success */ 482 post_cmds[0], post_cmds[1], 0)) {
482 return 1; 483 fprintf(stderr,
483 } 484 "Failed command (%s - %s:%s)\n",
485 engine_id, post_cmds[0],
486 post_cmds[1] ? post_cmds[1] : "(NULL)");
487 ENGINE_finish(e);
488 return 0;
489 }
490 post_cmds += 2;
491 }
492 ENGINE_set_default(e, ENGINE_METHOD_ALL & ~ENGINE_METHOD_RAND);
493 /* Success */
494 return 1;
495}
484 496
485Note that ENGINE_ctrl_cmd_string() accepts a boolean argument that can 497Note that ENGINE_ctrl_cmd_string() accepts a boolean argument that can
486relax the semantics of the function - if set non-zero it will only return 498relax the semantics of the function - if set non-zero it will only return