diff options
author | miod <> | 2014-07-10 14:14:04 +0000 |
---|---|---|
committer | miod <> | 2014-07-10 14:14:04 +0000 |
commit | 3ff93b65bfbf4da2c2e0cf6b752387131854fd98 (patch) | |
tree | ebb859fccda290f491c480e68ac91088c2cf7b19 /src | |
parent | f8e6fe02fc43958d79cf9326eebabf8ef8d3ae34 (diff) | |
download | openbsd-3ff93b65bfbf4da2c2e0cf6b752387131854fd98.tar.gz openbsd-3ff93b65bfbf4da2c2e0cf6b752387131854fd98.tar.bz2 openbsd-3ff93b65bfbf4da2c2e0cf6b752387131854fd98.zip |
Try and fix the horrible coding style of the example code snippets.
Diffstat (limited to 'src')
19 files changed, 445 insertions, 398 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 | ||
428 | Encrypt a string using blowfish: | 428 | Encrypt 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 | ||
471 | The ciphertext from the above example can be decrypted using the B<openssl> | 474 | The ciphertext from the above example can be decrypted using the B<openssl> |
472 | utility with the command line: | 475 | utility with the command line: |
@@ -476,16 +479,19 @@ utility with the command line: | |||
476 | General encryption, decryption function example using FILE I/O and RC2 with an | 479 | General encryption, decryption function example using FILE I/O and RC2 with an |
477 | 80 bit key: | 480 | 80 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 | ||
361 | Alternative method: | 360 | Alternative 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 | ||
369 | Write a certificate to a BIO: | 367 | Write 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 | ||
376 | Write an unencrypted private key to a FILE pointer: | 373 | Write 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 | ||
383 | Write a private key (using traditional format) to a BIO using | 379 | Write a private key (using traditional format) to a BIO using |
384 | triple DES encryption, the pass phrase is prompted for: | 380 | triple 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 | ||
391 | Write a private key (using PKCS#8 format) to a BIO using triple | 387 | Write a private key (using PKCS#8 format) to a BIO using triple |
392 | DES encryption, using the pass phrase "hello": | 388 | DES 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 | ||
399 | Read a private key from a BIO using the pass phrase "hello": | 395 | Read 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 | ||
407 | Read a private key from a BIO using a pass phrase callback: | 402 | Read 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 | ||
415 | Skeleton pass phrase callback: | 409 | Skeleton 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 | ||
75 | Process all commonName entries: | 74 | Process 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 | ||
60 | Default callback operation: | 60 | Default 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 | ||
67 | Simple example, suppose a certificate in the chain is expired and we wish | 68 | Simple example, suppose a certificate in the chain is expired and we wish |
68 | to continue after this error: | 69 | to 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 | ||
79 | More complex example, we don't wish to continue after B<any> certificate has | 81 | More complex example, we don't wish to continue after B<any> certificate has |
80 | expired just one specific case: | 82 | expired 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 | ||
94 | Full featured logging callback. In this case the B<bio_err> is assumed to be | 97 | Full featured logging callback. In this case the B<bio_err> is assumed to be |
95 | a global logging B<BIO>, an alternative would to store a BIO in B<ctx> using | 98 | a global logging B<BIO>, an alternative would to store a BIO in B<ctx> using |
96 | B<ex_data>. | 99 | B<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 | |||
445 | and set it as the default for everything except RAND and then return a | 445 | and set it as the default for everything except RAND and then return a |
446 | boolean success or failure. | 446 | boolean 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 | ||
485 | Note that ENGINE_ctrl_cmd_string() accepts a boolean argument that can | 497 | Note that ENGINE_ctrl_cmd_string() accepts a boolean argument that can |
486 | relax the semantics of the function - if set non-zero it will only return | 498 | relax the semantics of the function - if set non-zero it will only return |
diff --git a/src/lib/libssl/src/doc/crypto/BIO_f_md.pod b/src/lib/libssl/src/doc/crypto/BIO_f_md.pod index cb83fb0993..37041d9206 100644 --- a/src/lib/libssl/src/doc/crypto/BIO_f_md.pod +++ b/src/lib/libssl/src/doc/crypto/BIO_f_md.pod | |||
@@ -78,11 +78,12 @@ digest BIO and passes the string "Hello World" through it. Error | |||
78 | checking has been omitted for clarity. | 78 | checking has been omitted for clarity. |
79 | 79 | ||
80 | BIO *bio, *mdtmp; | 80 | BIO *bio, *mdtmp; |
81 | char message[] = "Hello World"; | 81 | const char message[] = "Hello World"; |
82 | bio = BIO_new(BIO_s_null()); | 82 | bio = BIO_new(BIO_s_null()); |
83 | mdtmp = BIO_new(BIO_f_md()); | 83 | mdtmp = BIO_new(BIO_f_md()); |
84 | BIO_set_md(mdtmp, EVP_sha1()); | 84 | BIO_set_md(mdtmp, EVP_sha1()); |
85 | /* For BIO_push() we want to append the sink BIO and keep a note of | 85 | /* |
86 | * For BIO_push() we want to append the sink BIO and keep a note of | ||
86 | * the start of the chain. | 87 | * the start of the chain. |
87 | */ | 88 | */ |
88 | bio = BIO_push(mdtmp, bio); | 89 | bio = BIO_push(mdtmp, bio); |
@@ -97,6 +98,7 @@ The next example digests data by reading through a chain instead: | |||
97 | BIO *bio, *mdtmp; | 98 | BIO *bio, *mdtmp; |
98 | char buf[1024]; | 99 | char buf[1024]; |
99 | int rdlen; | 100 | int rdlen; |
101 | |||
100 | bio = BIO_new_file(file, "rb"); | 102 | bio = BIO_new_file(file, "rb"); |
101 | mdtmp = BIO_new(BIO_f_md()); | 103 | mdtmp = BIO_new(BIO_f_md()); |
102 | BIO_set_md(mdtmp, EVP_sha1()); | 104 | BIO_set_md(mdtmp, EVP_sha1()); |
@@ -105,9 +107,9 @@ The next example digests data by reading through a chain instead: | |||
105 | BIO_set_md(mdtmp, EVP_md5()); | 107 | BIO_set_md(mdtmp, EVP_md5()); |
106 | bio = BIO_push(mdtmp, bio); | 108 | bio = BIO_push(mdtmp, bio); |
107 | do { | 109 | do { |
108 | rdlen = BIO_read(bio, buf, sizeof(buf)); | 110 | rdlen = BIO_read(bio, buf, sizeof(buf)); |
109 | /* Might want to do something with the data here */ | 111 | /* Might want to do something with the data here */ |
110 | } while(rdlen > 0); | 112 | } while (rdlen > 0); |
111 | 113 | ||
112 | This next example retrieves the message digests from a BIO chain and | 114 | This next example retrieves the message digests from a BIO chain and |
113 | outputs them. This could be used with the examples above. | 115 | outputs them. This could be used with the examples above. |
@@ -116,19 +118,21 @@ outputs them. This could be used with the examples above. | |||
116 | unsigned char mdbuf[EVP_MAX_MD_SIZE]; | 118 | unsigned char mdbuf[EVP_MAX_MD_SIZE]; |
117 | int mdlen; | 119 | int mdlen; |
118 | int i; | 120 | int i; |
121 | |||
119 | mdtmp = bio; /* Assume bio has previously been set up */ | 122 | mdtmp = bio; /* Assume bio has previously been set up */ |
120 | do { | 123 | do { |
121 | EVP_MD *md; | 124 | EVP_MD *md; |
122 | mdtmp = BIO_find_type(mdtmp, BIO_TYPE_MD); | 125 | mdtmp = BIO_find_type(mdtmp, BIO_TYPE_MD); |
123 | if(!mdtmp) break; | 126 | if (!mdtmp) |
127 | break; | ||
124 | BIO_get_md(mdtmp, &md); | 128 | BIO_get_md(mdtmp, &md); |
125 | printf("%s digest", OBJ_nid2sn(EVP_MD_type(md))); | 129 | printf("%s digest", OBJ_nid2sn(EVP_MD_type(md))); |
126 | mdlen = BIO_gets(mdtmp, mdbuf, EVP_MAX_MD_SIZE); | 130 | mdlen = BIO_gets(mdtmp, mdbuf, EVP_MAX_MD_SIZE); |
127 | for(i = 0; i < mdlen; i++) printf(":%02X", mdbuf[i]); | 131 | for(i = 0; i < mdlen; i++) |
132 | printf(":%02X", mdbuf[i]); | ||
128 | printf("\n"); | 133 | printf("\n"); |
129 | mdtmp = BIO_next(mdtmp); | 134 | mdtmp = BIO_next(mdtmp); |
130 | } while(mdtmp); | 135 | } while(mdtmp); |
131 | |||
132 | BIO_free_all(bio); | 136 | BIO_free_all(bio); |
133 | 137 | ||
134 | =head1 BUGS | 138 | =head1 BUGS |
diff --git a/src/lib/libssl/src/doc/crypto/BIO_find_type.pod b/src/lib/libssl/src/doc/crypto/BIO_find_type.pod index 40eedb8a86..03200a1b6b 100644 --- a/src/lib/libssl/src/doc/crypto/BIO_find_type.pod +++ b/src/lib/libssl/src/doc/crypto/BIO_find_type.pod | |||
@@ -86,9 +86,10 @@ Traverse a chain looking for digest BIOs: | |||
86 | 86 | ||
87 | do { | 87 | do { |
88 | btmp = BIO_find_type(btmp, BIO_TYPE_MD); | 88 | btmp = BIO_find_type(btmp, BIO_TYPE_MD); |
89 | if(btmp == NULL) break; /* Not found */ | 89 | if (btmp == NULL) |
90 | break; /* Not found */ | ||
90 | /* btmp is a digest BIO, do something with it ...*/ | 91 | /* btmp is a digest BIO, do something with it ...*/ |
91 | ... | 92 | ... |
92 | 93 | ||
93 | btmp = BIO_next(btmp); | 94 | btmp = BIO_next(btmp); |
94 | } while(btmp); | 95 | } while(btmp); |
diff --git a/src/lib/libssl/src/doc/crypto/BIO_s_accept.pod b/src/lib/libssl/src/doc/crypto/BIO_s_accept.pod index 058bda1409..935d464748 100644 --- a/src/lib/libssl/src/doc/crypto/BIO_s_accept.pod +++ b/src/lib/libssl/src/doc/crypto/BIO_s_accept.pod | |||
@@ -151,14 +151,14 @@ down each and finally closes both down. | |||
151 | abio = BIO_new_accept("4444"); | 151 | abio = BIO_new_accept("4444"); |
152 | 152 | ||
153 | /* First call to BIO_accept() sets up accept BIO */ | 153 | /* First call to BIO_accept() sets up accept BIO */ |
154 | if(BIO_do_accept(abio) <= 0) { | 154 | if (BIO_do_accept(abio) <= 0) { |
155 | fprintf(stderr, "Error setting up accept\n"); | 155 | fprintf(stderr, "Error setting up accept\n"); |
156 | ERR_print_errors_fp(stderr); | 156 | ERR_print_errors_fp(stderr); |
157 | exit(0); | 157 | exit(0); |
158 | } | 158 | } |
159 | 159 | ||
160 | /* Wait for incoming connection */ | 160 | /* Wait for incoming connection */ |
161 | if(BIO_do_accept(abio) <= 0) { | 161 | if (BIO_do_accept(abio) <= 0) { |
162 | fprintf(stderr, "Error accepting connection\n"); | 162 | fprintf(stderr, "Error accepting connection\n"); |
163 | ERR_print_errors_fp(stderr); | 163 | ERR_print_errors_fp(stderr); |
164 | exit(0); | 164 | exit(0); |
@@ -169,7 +169,7 @@ down each and finally closes both down. | |||
169 | BIO_puts(cbio, "Connection 1: Sending out Data on initial connection\n"); | 169 | BIO_puts(cbio, "Connection 1: Sending out Data on initial connection\n"); |
170 | fprintf(stderr, "Sent out data on connection 1\n"); | 170 | fprintf(stderr, "Sent out data on connection 1\n"); |
171 | /* Wait for another connection */ | 171 | /* Wait for another connection */ |
172 | if(BIO_do_accept(abio) <= 0) { | 172 | if (BIO_do_accept(abio) <= 0) { |
173 | fprintf(stderr, "Error accepting connection\n"); | 173 | fprintf(stderr, "Error accepting connection\n"); |
174 | ERR_print_errors_fp(stderr); | 174 | ERR_print_errors_fp(stderr); |
175 | exit(0); | 175 | exit(0); |
diff --git a/src/lib/libssl/src/doc/crypto/BIO_s_connect.pod b/src/lib/libssl/src/doc/crypto/BIO_s_connect.pod index 92f37d05ff..7cad0e3f0f 100644 --- a/src/lib/libssl/src/doc/crypto/BIO_s_connect.pod +++ b/src/lib/libssl/src/doc/crypto/BIO_s_connect.pod | |||
@@ -169,18 +169,20 @@ to retrieve a page and copy the result to standard output. | |||
169 | BIO *cbio, *out; | 169 | BIO *cbio, *out; |
170 | int len; | 170 | int len; |
171 | char tmpbuf[1024]; | 171 | char tmpbuf[1024]; |
172 | |||
172 | ERR_load_crypto_strings(); | 173 | ERR_load_crypto_strings(); |
173 | cbio = BIO_new_connect("localhost:http"); | 174 | cbio = BIO_new_connect("localhost:http"); |
174 | out = BIO_new_fp(stdout, BIO_NOCLOSE); | 175 | out = BIO_new_fp(stdout, BIO_NOCLOSE); |
175 | if(BIO_do_connect(cbio) <= 0) { | 176 | if (BIO_do_connect(cbio) <= 0) { |
176 | fprintf(stderr, "Error connecting to server\n"); | 177 | fprintf(stderr, "Error connecting to server\n"); |
177 | ERR_print_errors_fp(stderr); | 178 | ERR_print_errors_fp(stderr); |
178 | /* whatever ... */ | 179 | /* whatever ... */ |
179 | } | 180 | } |
180 | BIO_puts(cbio, "GET / HTTP/1.0\n\n"); | 181 | BIO_puts(cbio, "GET / HTTP/1.0\n\n"); |
181 | for(;;) { | 182 | for(;;) { |
182 | len = BIO_read(cbio, tmpbuf, 1024); | 183 | len = BIO_read(cbio, tmpbuf, 1024); |
183 | if(len <= 0) break; | 184 | if (len <= 0) |
185 | break; | ||
184 | BIO_write(out, tmpbuf, len); | 186 | BIO_write(out, tmpbuf, len); |
185 | } | 187 | } |
186 | BIO_free(cbio); | 188 | BIO_free(cbio); |
diff --git a/src/lib/libssl/src/doc/crypto/EVP_DigestInit.pod b/src/lib/libssl/src/doc/crypto/EVP_DigestInit.pod index 2ff01b9c7c..f2c1cfdbf0 100644 --- a/src/lib/libssl/src/doc/crypto/EVP_DigestInit.pod +++ b/src/lib/libssl/src/doc/crypto/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/libssl/src/doc/crypto/EVP_EncryptInit.pod b/src/lib/libssl/src/doc/crypto/EVP_EncryptInit.pod index a876ac789c..b2211ea6d3 100644 --- a/src/lib/libssl/src/doc/crypto/EVP_EncryptInit.pod +++ b/src/lib/libssl/src/doc/crypto/EVP_EncryptInit.pod | |||
@@ -427,46 +427,49 @@ Set the effective key length used in RC2: | |||
427 | 427 | ||
428 | Encrypt a string using blowfish: | 428 | Encrypt 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 | ||
471 | The ciphertext from the above example can be decrypted using the B<openssl> | 474 | The ciphertext from the above example can be decrypted using the B<openssl> |
472 | utility with the command line: | 475 | utility with the command line: |
@@ -476,16 +479,19 @@ utility with the command line: | |||
476 | General encryption, decryption function example using FILE I/O and RC2 with an | 479 | General encryption, decryption function example using FILE I/O and RC2 with an |
477 | 80 bit key: | 480 | 80 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/libssl/src/doc/crypto/EVP_PKEY_keygen.pod b/src/lib/libssl/src/doc/crypto/EVP_PKEY_keygen.pod index 378fb310ff..05ea04be11 100644 --- a/src/lib/libssl/src/doc/crypto/EVP_PKEY_keygen.pod +++ b/src/lib/libssl/src/doc/crypto/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/libssl/src/doc/crypto/PEM_read_bio_PrivateKey.pod b/src/lib/libssl/src/doc/crypto/PEM_read_bio_PrivateKey.pod index 0d9270985a..6d87079a84 100644 --- a/src/lib/libssl/src/doc/crypto/PEM_read_bio_PrivateKey.pod +++ b/src/lib/libssl/src/doc/crypto/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 | ||
361 | Alternative method: | 360 | Alternative 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 | ||
369 | Write a certificate to a BIO: | 367 | Write 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 | ||
376 | Write an unencrypted private key to a FILE pointer: | 373 | Write 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 | ||
383 | Write a private key (using traditional format) to a BIO using | 379 | Write a private key (using traditional format) to a BIO using |
384 | triple DES encryption, the pass phrase is prompted for: | 380 | triple 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 | ||
391 | Write a private key (using PKCS#8 format) to a BIO using triple | 387 | Write a private key (using PKCS#8 format) to a BIO using triple |
392 | DES encryption, using the pass phrase "hello": | 388 | DES 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 | ||
399 | Read a private key from a BIO using the pass phrase "hello": | 395 | Read 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 | ||
407 | Read a private key from a BIO using a pass phrase callback: | 402 | Read 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 | ||
415 | Skeleton pass phrase callback: | 409 | Skeleton 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/libssl/src/doc/crypto/X509_NAME_get_index_by_NID.pod b/src/lib/libssl/src/doc/crypto/X509_NAME_get_index_by_NID.pod index 9c694c9867..988fd7bdaf 100644 --- a/src/lib/libssl/src/doc/crypto/X509_NAME_get_index_by_NID.pod +++ b/src/lib/libssl/src/doc/crypto/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 | ||
75 | Process all commonName entries: | 74 | Process 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/libssl/src/doc/crypto/X509_STORE_CTX_set_verify_cb.pod b/src/lib/libssl/src/doc/crypto/X509_STORE_CTX_set_verify_cb.pod index 86d988eee0..7dfe430c4c 100644 --- a/src/lib/libssl/src/doc/crypto/X509_STORE_CTX_set_verify_cb.pod +++ b/src/lib/libssl/src/doc/crypto/X509_STORE_CTX_set_verify_cb.pod | |||
@@ -59,44 +59,48 @@ X509_STORE_CTX_set_verify_cb() does not return a value. | |||
59 | 59 | ||
60 | Default callback operation: | 60 | Default 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 | ||
67 | Simple example, suppose a certificate in the chain is expired and we wish | 68 | Simple example, suppose a certificate in the chain is expired and we wish |
68 | to continue after this error: | 69 | to 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 | ||
79 | More complex example, we don't wish to continue after B<any> certificate has | 81 | More complex example, we don't wish to continue after B<any> certificate has |
80 | expired just one specific case: | 82 | expired 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 | ||
94 | Full featured logging callback. In this case the B<bio_err> is assumed to be | 97 | Full featured logging callback. In this case the B<bio_err> is assumed to be |
95 | a global logging B<BIO>, an alternative would to store a BIO in B<ctx> using | 98 | a global logging B<BIO>, an alternative would to store a BIO in B<ctx> using |
96 | B<ex_data>. | 99 | B<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/libssl/src/doc/crypto/ecdsa.pod b/src/lib/libssl/src/doc/crypto/ecdsa.pod index 92c3f4fa04..f54966df33 100644 --- a/src/lib/libssl/src/doc/crypto/ecdsa.pod +++ b/src/lib/libssl/src/doc/crypto/ecdsa.pod | |||
@@ -129,39 +129,37 @@ named curve secp192k1. | |||
129 | First step: create a EC_KEY object (note: this part is B<not> ECDSA | 129 | First step: create a EC_KEY object (note: this part is B<not> ECDSA |
130 | specific) | 130 | specific) |
131 | 131 | ||
132 | int ret; | 132 | int ret; |
133 | ECDSA_SIG *sig; | 133 | ECDSA_SIG *sig; |
134 | EC_KEY *eckey; | 134 | EC_KEY *eckey; |
135 | |||
135 | eckey = EC_KEY_new_by_curve_name(NID_secp192k1); | 136 | eckey = EC_KEY_new_by_curve_name(NID_secp192k1); |
136 | if (eckey == NULL) | 137 | if (eckey == NULL) { |
137 | { | ||
138 | /* error */ | 138 | /* error */ |
139 | } | 139 | } |
140 | if (!EC_KEY_generate_key(eckey)) | 140 | if (!EC_KEY_generate_key(eckey)) { |
141 | { | ||
142 | /* error */ | 141 | /* error */ |
143 | } | 142 | } |
144 | 143 | ||
145 | Second step: compute the ECDSA signature of a SHA-1 hash value | 144 | Second step: compute the ECDSA signature of a SHA-1 hash value |
146 | using B<ECDSA_do_sign> | 145 | using B<ECDSA_do_sign> |
147 | 146 | ||
148 | sig = ECDSA_do_sign(digest, 20, eckey); | 147 | sig = ECDSA_do_sign(digest, 20, eckey); |
149 | if (sig == NULL) | 148 | if (sig == NULL) { |
150 | { | ||
151 | /* error */ | 149 | /* error */ |
152 | } | 150 | } |
153 | 151 | ||
154 | or using B<ECDSA_sign> | 152 | or using B<ECDSA_sign> |
155 | 153 | ||
156 | unsigned char *buffer, *pp; | 154 | unsigned char *buffer, *pp; |
157 | int buf_len; | 155 | int buf_len; |
156 | |||
158 | buf_len = ECDSA_size(eckey); | 157 | buf_len = ECDSA_size(eckey); |
159 | buffer = OPENSSL_malloc(buf_len); | 158 | buffer = OPENSSL_malloc(buf_len); |
160 | pp = buffer; | 159 | pp = buffer; |
161 | if (!ECDSA_sign(0, dgst, dgstlen, pp, &buf_len, eckey); | 160 | if (!ECDSA_sign(0, dgst, dgstlen, pp, &buf_len, eckey) { |
162 | { | ||
163 | /* error */ | 161 | /* error */ |
164 | } | 162 | } |
165 | 163 | ||
166 | Third step: verify the created ECDSA signature using B<ECDSA_do_verify> | 164 | Third step: verify the created ECDSA signature using B<ECDSA_do_verify> |
167 | 165 | ||
@@ -173,18 +171,14 @@ or using B<ECDSA_verify> | |||
173 | 171 | ||
174 | and finally evaluate the return value: | 172 | and finally evaluate the return value: |
175 | 173 | ||
176 | if (ret == -1) | 174 | if (ret == -1) { |
177 | { | ||
178 | /* error */ | 175 | /* error */ |
179 | } | 176 | } else if (ret == 0) { |
180 | else if (ret == 0) | ||
181 | { | ||
182 | /* incorrect signature */ | 177 | /* incorrect signature */ |
183 | } | 178 | } else { |
184 | else /* ret == 1 */ | 179 | /* ret == 1 */ |
185 | { | ||
186 | /* signature ok */ | 180 | /* signature ok */ |
187 | } | 181 | } |
188 | 182 | ||
189 | =head1 CONFORMING TO | 183 | =head1 CONFORMING TO |
190 | 184 | ||
diff --git a/src/lib/libssl/src/doc/crypto/engine.pod b/src/lib/libssl/src/doc/crypto/engine.pod index 4648af7543..4a6ee59138 100644 --- a/src/lib/libssl/src/doc/crypto/engine.pod +++ b/src/lib/libssl/src/doc/crypto/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 | |||
445 | and set it as the default for everything except RAND and then return a | 445 | and set it as the default for everything except RAND and then return a |
446 | boolean success or failure. | 446 | boolean 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 | ||
485 | Note that ENGINE_ctrl_cmd_string() accepts a boolean argument that can | 497 | Note that ENGINE_ctrl_cmd_string() accepts a boolean argument that can |
486 | relax the semantics of the function - if set non-zero it will only return | 498 | relax the semantics of the function - if set non-zero it will only return |