diff -r d00a24dd3dee src/event/ngx_event_openssl.c
|
a
|
b
|
|
| 374 | 374 | BIO *bio; |
| 375 | 375 | X509 *x509; |
| 376 | 376 | u_long n; |
| 377 | | ngx_str_t *pwd; |
| | 377 | ngx_str_t *pwd, cn, kn; |
| 378 | 378 | ngx_uint_t tries; |
| 379 | 379 | |
| 380 | | if (ngx_conf_full_name(cf->cycle, cert, 1) != NGX_OK) { |
| | 380 | cn = *cert; |
| | 381 | |
| | 382 | if (ngx_conf_full_name(cf->cycle, &cn, 1) != NGX_OK) { |
| 381 | 383 | return NGX_ERROR; |
| 382 | 384 | } |
| 383 | 385 | |
| … |
… |
|
| 387 | 389 | * it here |
| 388 | 390 | */ |
| 389 | 391 | |
| 390 | | bio = BIO_new_file((char *) cert->data, "r"); |
| | 392 | bio = BIO_new_file((char *) cn.data, "r"); |
| 391 | 393 | if (bio == NULL) { |
| 392 | 394 | ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, |
| 393 | | "BIO_new_file(\"%s\") failed", cert->data); |
| | 395 | "BIO_new_file(\"%s\") failed", cn.data); |
| 394 | 396 | return NGX_ERROR; |
| 395 | 397 | } |
| 396 | 398 | |
| 397 | 399 | x509 = PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL); |
| 398 | 400 | if (x509 == NULL) { |
| 399 | 401 | ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, |
| 400 | | "PEM_read_bio_X509_AUX(\"%s\") failed", cert->data); |
| | 402 | "PEM_read_bio_X509_AUX(\"%s\") failed", cn.data); |
| 401 | 403 | BIO_free(bio); |
| 402 | 404 | return NGX_ERROR; |
| 403 | 405 | } |
| 404 | 406 | |
| 405 | 407 | if (SSL_CTX_use_certificate(ssl->ctx, x509) == 0) { |
| 406 | 408 | ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, |
| 407 | | "SSL_CTX_use_certificate(\"%s\") failed", cert->data); |
| | 409 | "SSL_CTX_use_certificate(\"%s\") failed", cn.data); |
| 408 | 410 | X509_free(x509); |
| 409 | 411 | BIO_free(bio); |
| 410 | 412 | return NGX_ERROR; |
| 411 | 413 | } |
| 412 | 414 | |
| 413 | | if (X509_set_ex_data(x509, ngx_ssl_certificate_name_index, cert->data) |
| | 415 | if (X509_set_ex_data(x509, ngx_ssl_certificate_name_index, cn.data) |
| 414 | 416 | == 0) |
| 415 | 417 | { |
| 416 | 418 | ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, "X509_set_ex_data() failed"); |
| … |
… |
|
| 458 | 460 | /* some real error */ |
| 459 | 461 | |
| 460 | 462 | ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, |
| 461 | | "PEM_read_bio_X509(\"%s\") failed", cert->data); |
| | 463 | "PEM_read_bio_X509(\"%s\") failed", cn.data); |
| 462 | 464 | BIO_free(bio); |
| 463 | 465 | return NGX_ERROR; |
| 464 | 466 | } |
| … |
… |
|
| 474 | 476 | if (SSL_CTX_add0_chain_cert(ssl->ctx, x509) == 0) { |
| 475 | 477 | ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, |
| 476 | 478 | "SSL_CTX_add0_chain_cert(\"%s\") failed", |
| 477 | | cert->data); |
| | 479 | cn.data); |
| 478 | 480 | X509_free(x509); |
| 479 | 481 | BIO_free(bio); |
| 480 | 482 | return NGX_ERROR; |
| … |
… |
|
| 484 | 486 | if (SSL_CTX_add_extra_chain_cert(ssl->ctx, x509) == 0) { |
| 485 | 487 | ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, |
| 486 | 488 | "SSL_CTX_add_extra_chain_cert(\"%s\") failed", |
| 487 | | cert->data); |
| | 489 | cn.data); |
| 488 | 490 | X509_free(x509); |
| 489 | 491 | BIO_free(bio); |
| 490 | 492 | return NGX_ERROR; |
| … |
… |
|
| 555 | 557 | #endif |
| 556 | 558 | } |
| 557 | 559 | |
| 558 | | if (ngx_conf_full_name(cf->cycle, key, 1) != NGX_OK) { |
| | 560 | kn = *key; |
| | 561 | |
| | 562 | if (ngx_conf_full_name(cf->cycle, &kn, 1) != NGX_OK) { |
| 559 | 563 | return NGX_ERROR; |
| 560 | 564 | } |
| 561 | 565 | |
| … |
… |
|
| 575 | 579 | |
| 576 | 580 | for ( ;; ) { |
| 577 | 581 | |
| 578 | | if (SSL_CTX_use_PrivateKey_file(ssl->ctx, (char *) key->data, |
| | 582 | if (SSL_CTX_use_PrivateKey_file(ssl->ctx, (char *) kn.data, |
| 579 | 583 | SSL_FILETYPE_PEM) |
| 580 | 584 | != 0) |
| 581 | 585 | { |
| … |
… |
|
| 589 | 593 | } |
| 590 | 594 | |
| 591 | 595 | ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, |
| 592 | | "SSL_CTX_use_PrivateKey_file(\"%s\") failed", key->data); |
| | 596 | "SSL_CTX_use_PrivateKey_file(\"%s\") failed", kn.data); |
| 593 | 597 | return NGX_ERROR; |
| 594 | 598 | } |
| 595 | 599 | |
| … |
… |
|
| 651 | 655 | ngx_ssl_client_certificate(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *cert, |
| 652 | 656 | ngx_int_t depth) |
| 653 | 657 | { |
| | 658 | ngx_str_t cn; |
| | 659 | |
| 654 | 660 | STACK_OF(X509_NAME) *list; |
| 655 | 661 | |
| 656 | 662 | SSL_CTX_set_verify(ssl->ctx, SSL_VERIFY_PEER, ngx_ssl_verify_callback); |
| … |
… |
|
| 661 | 667 | return NGX_OK; |
| 662 | 668 | } |
| 663 | 669 | |
| 664 | | if (ngx_conf_full_name(cf->cycle, cert, 1) != NGX_OK) { |
| | 670 | cn = *cert; |
| | 671 | |
| | 672 | if (ngx_conf_full_name(cf->cycle, &cn, 1) != NGX_OK) { |
| 665 | 673 | return NGX_ERROR; |
| 666 | 674 | } |
| 667 | 675 | |
| 668 | | if (SSL_CTX_load_verify_locations(ssl->ctx, (char *) cert->data, NULL) |
| | 676 | if (SSL_CTX_load_verify_locations(ssl->ctx, (char *) cn.data, NULL) |
| 669 | 677 | == 0) |
| 670 | 678 | { |
| 671 | 679 | ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, |
| 672 | 680 | "SSL_CTX_load_verify_locations(\"%s\") failed", |
| 673 | | cert->data); |
| | 681 | cn.data); |
| 674 | 682 | return NGX_ERROR; |
| 675 | 683 | } |
| 676 | 684 | |
| … |
… |
|
| 681 | 689 | |
| 682 | 690 | ERR_clear_error(); |
| 683 | 691 | |
| 684 | | list = SSL_load_client_CA_file((char *) cert->data); |
| | 692 | list = SSL_load_client_CA_file((char *) cn.data); |
| 685 | 693 | |
| 686 | 694 | if (list == NULL) { |
| 687 | 695 | ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, |
| 688 | | "SSL_load_client_CA_file(\"%s\") failed", cert->data); |
| | 696 | "SSL_load_client_CA_file(\"%s\") failed", cn.data); |
| 689 | 697 | return NGX_ERROR; |
| 690 | 698 | } |
| 691 | 699 | |
| … |
… |
|
| 706 | 714 | ngx_ssl_trusted_certificate(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *cert, |
| 707 | 715 | ngx_int_t depth) |
| 708 | 716 | { |
| | 717 | ngx_str_t cn; |
| | 718 | |
| 709 | 719 | SSL_CTX_set_verify_depth(ssl->ctx, depth); |
| 710 | 720 | |
| 711 | 721 | if (cert->len == 0) { |
| 712 | 722 | return NGX_OK; |
| 713 | 723 | } |
| 714 | 724 | |
| 715 | | if (ngx_conf_full_name(cf->cycle, cert, 1) != NGX_OK) { |
| | 725 | cn = *cert; |
| | 726 | |
| | 727 | if (ngx_conf_full_name(cf->cycle, &cn, 1) != NGX_OK) { |
| 716 | 728 | return NGX_ERROR; |
| 717 | 729 | } |
| 718 | 730 | |
| 719 | | if (SSL_CTX_load_verify_locations(ssl->ctx, (char *) cert->data, NULL) |
| | 731 | if (SSL_CTX_load_verify_locations(ssl->ctx, (char *) cn.data, NULL) |
| 720 | 732 | == 0) |
| 721 | 733 | { |
| 722 | 734 | ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, |
| 723 | 735 | "SSL_CTX_load_verify_locations(\"%s\") failed", |
| 724 | | cert->data); |
| | 736 | cn.data); |
| 725 | 737 | return NGX_ERROR; |
| 726 | 738 | } |
| 727 | 739 | |
| … |
… |
|
| 739 | 751 | ngx_int_t |
| 740 | 752 | ngx_ssl_crl(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *crl) |
| 741 | 753 | { |
| | 754 | ngx_str_t cn; |
| | 755 | |
| 742 | 756 | X509_STORE *store; |
| 743 | 757 | X509_LOOKUP *lookup; |
| 744 | 758 | |
| … |
… |
|
| 746 | 760 | return NGX_OK; |
| 747 | 761 | } |
| 748 | 762 | |
| 749 | | if (ngx_conf_full_name(cf->cycle, crl, 1) != NGX_OK) { |
| | 763 | cn = *crl; |
| | 764 | |
| | 765 | if (ngx_conf_full_name(cf->cycle, &cn, 1) != NGX_OK) { |
| 750 | 766 | return NGX_ERROR; |
| 751 | 767 | } |
| 752 | 768 | |
| … |
… |
|
| 766 | 782 | return NGX_ERROR; |
| 767 | 783 | } |
| 768 | 784 | |
| 769 | | if (X509_LOOKUP_load_file(lookup, (char *) crl->data, X509_FILETYPE_PEM) |
| | 785 | if (X509_LOOKUP_load_file(lookup, (char *) cn.data, X509_FILETYPE_PEM) |
| 770 | 786 | == 0) |
| 771 | 787 | { |
| 772 | 788 | ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, |
| 773 | | "X509_LOOKUP_load_file(\"%s\") failed", crl->data); |
| | 789 | "X509_LOOKUP_load_file(\"%s\") failed", cn.data); |
| 774 | 790 | return NGX_ERROR; |
| 775 | 791 | } |
| 776 | 792 | |
| … |
… |
|
| 896 | 912 | size_t len; |
| 897 | 913 | ssize_t n; |
| 898 | 914 | ngx_fd_t fd; |
| 899 | | ngx_str_t *pwd; |
| | 915 | ngx_str_t *pwd, fn; |
| 900 | 916 | ngx_array_t *passwords; |
| 901 | 917 | ngx_pool_cleanup_t *cln; |
| 902 | 918 | u_char buf[NGX_SSL_PASSWORD_BUFFER_SIZE]; |
| 903 | 919 | |
| 904 | | if (ngx_conf_full_name(cf->cycle, file, 1) != NGX_OK) { |
| | 920 | fn = *file; |
| | 921 | |
| | 922 | if (ngx_conf_full_name(cf->cycle, &fn, 1) != NGX_OK) { |
| 905 | 923 | return NULL; |
| 906 | 924 | } |
| 907 | 925 | |
| … |
… |
|
| 915 | 933 | cln->handler = ngx_ssl_passwords_cleanup; |
| 916 | 934 | cln->data = passwords; |
| 917 | 935 | |
| 918 | | fd = ngx_open_file(file->data, NGX_FILE_RDONLY, NGX_FILE_OPEN, 0); |
| | 936 | fd = ngx_open_file(fn.data, NGX_FILE_RDONLY, NGX_FILE_OPEN, 0); |
| 919 | 937 | if (fd == NGX_INVALID_FILE) { |
| 920 | 938 | ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno, |
| 921 | | ngx_open_file_n " \"%s\" failed", file->data); |
| | 939 | ngx_open_file_n " \"%s\" failed", fn.data); |
| 922 | 940 | return NULL; |
| 923 | 941 | } |
| 924 | 942 | |
| … |
… |
|
| 930 | 948 | |
| 931 | 949 | if (n == -1) { |
| 932 | 950 | ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno, |
| 933 | | ngx_read_fd_n " \"%s\" failed", file->data); |
| | 951 | ngx_read_fd_n " \"%s\" failed", fn.data); |
| 934 | 952 | passwords = NULL; |
| 935 | 953 | goto cleanup; |
| 936 | 954 | } |
| … |
… |
|
| 982 | 1000 | |
| 983 | 1001 | if (len == NGX_SSL_PASSWORD_BUFFER_SIZE) { |
| 984 | 1002 | ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
| 985 | | "too long line in \"%s\"", file->data); |
| | 1003 | "too long line in \"%s\"", fn.data); |
| 986 | 1004 | passwords = NULL; |
| 987 | 1005 | goto cleanup; |
| 988 | 1006 | } |
| … |
… |
|
| 1006 | 1024 | |
| 1007 | 1025 | if (ngx_close_file(fd) == NGX_FILE_ERROR) { |
| 1008 | 1026 | ngx_conf_log_error(NGX_LOG_ALERT, cf, ngx_errno, |
| 1009 | | ngx_close_file_n " \"%s\" failed", file->data); |
| | 1027 | ngx_close_file_n " \"%s\" failed", fn.data); |
| 1010 | 1028 | } |
| 1011 | 1029 | |
| 1012 | 1030 | ngx_memzero(buf, NGX_SSL_PASSWORD_BUFFER_SIZE); |
| … |
… |
|
| 1034 | 1052 | ngx_int_t |
| 1035 | 1053 | ngx_ssl_dhparam(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *file) |
| 1036 | 1054 | { |
| 1037 | | DH *dh; |
| 1038 | | BIO *bio; |
| | 1055 | ngx_str_t fn; |
| | 1056 | DH *dh; |
| | 1057 | BIO *bio; |
| 1039 | 1058 | |
| 1040 | 1059 | if (file->len == 0) { |
| 1041 | 1060 | return NGX_OK; |
| 1042 | 1061 | } |
| 1043 | 1062 | |
| | 1063 | fn = *file; |
| | 1064 | |
| 1044 | 1065 | if (ngx_conf_full_name(cf->cycle, file, 1) != NGX_OK) { |
| 1045 | 1066 | return NGX_ERROR; |
| 1046 | 1067 | } |
| 1047 | 1068 | |
| 1048 | | bio = BIO_new_file((char *) file->data, "r"); |
| | 1069 | bio = BIO_new_file((char *) fn.data, "r"); |
| 1049 | 1070 | if (bio == NULL) { |
| 1050 | 1071 | ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, |
| 1051 | | "BIO_new_file(\"%s\") failed", file->data); |
| | 1072 | "BIO_new_file(\"%s\") failed", fn.data); |
| 1052 | 1073 | return NGX_ERROR; |
| 1053 | 1074 | } |
| 1054 | 1075 | |
| 1055 | 1076 | dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL); |
| 1056 | 1077 | if (dh == NULL) { |
| 1057 | 1078 | ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, |
| 1058 | | "PEM_read_bio_DHparams(\"%s\") failed", file->data); |
| | 1079 | "PEM_read_bio_DHparams(\"%s\") failed", fn.data); |
| 1059 | 1080 | BIO_free(bio); |
| 1060 | 1081 | return NGX_ERROR; |
| 1061 | 1082 | } |
| … |
… |
|
| 2869 | 2890 | u_char buf[80]; |
| 2870 | 2891 | size_t size; |
| 2871 | 2892 | ssize_t n; |
| 2872 | | ngx_str_t *path; |
| | 2893 | ngx_str_t *path, name; |
| 2873 | 2894 | ngx_file_t file; |
| 2874 | 2895 | ngx_uint_t i; |
| 2875 | 2896 | ngx_array_t *keys; |
| … |
… |
|
| 2889 | 2910 | path = paths->elts; |
| 2890 | 2911 | for (i = 0; i < paths->nelts; i++) { |
| 2891 | 2912 | |
| 2892 | | if (ngx_conf_full_name(cf->cycle, &path[i], 1) != NGX_OK) { |
| | 2913 | name = path[i]; |
| | 2914 | |
| | 2915 | if (ngx_conf_full_name(cf->cycle, &name, 1) != NGX_OK) { |
| 2893 | 2916 | return NGX_ERROR; |
| 2894 | 2917 | } |
| 2895 | 2918 | |
| 2896 | 2919 | ngx_memzero(&file, sizeof(ngx_file_t)); |
| 2897 | | file.name = path[i]; |
| | 2920 | file.name = name; |
| 2898 | 2921 | file.log = cf->log; |
| 2899 | 2922 | |
| 2900 | 2923 | file.fd = ngx_open_file(file.name.data, NGX_FILE_RDONLY, 0, 0); |