comparison DEPENDENCIES/generic/include/boost/asio/ssl/impl/context.ipp @ 101:c530137014c0

Update Boost headers (1.58.0)
author Chris Cannam
date Mon, 07 Sep 2015 11:12:49 +0100
parents 2665513ce2d3
children
comparison
equal deleted inserted replaced
100:793467b5e61c 101:c530137014c0
1 // 1 //
2 // ssl/impl/context.ipp 2 // ssl/impl/context.ipp
3 // ~~~~~~~~~~~~~~~~~~~~ 3 // ~~~~~~~~~~~~~~~~~~~~
4 // 4 //
5 // Copyright (c) 2005 Voipster / Indrek dot Juhani at voipster dot com 5 // Copyright (c) 2005 Voipster / Indrek dot Juhani at voipster dot com
6 // Copyright (c) 2005-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com) 6 // Copyright (c) 2005-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // 7 //
8 // Distributed under the Boost Software License, Version 1.0. (See accompanying 8 // Distributed under the Boost Software License, Version 1.0. (See accompanying
9 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 9 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10 // 10 //
11 11
65 }; 65 };
66 66
67 context::context(context::method m) 67 context::context(context::method m)
68 : handle_(0) 68 : handle_(0)
69 { 69 {
70 ::ERR_clear_error();
71
70 switch (m) 72 switch (m)
71 { 73 {
72 #if defined(OPENSSL_NO_SSL2) 74 #if defined(OPENSSL_NO_SSL2)
73 case context::sslv2: 75 case context::sslv2:
74 case context::sslv2_client: 76 case context::sslv2_client:
327 } 329 }
328 330
329 boost::system::error_code context::load_verify_file( 331 boost::system::error_code context::load_verify_file(
330 const std::string& filename, boost::system::error_code& ec) 332 const std::string& filename, boost::system::error_code& ec)
331 { 333 {
334 ::ERR_clear_error();
335
332 if (::SSL_CTX_load_verify_locations(handle_, filename.c_str(), 0) != 1) 336 if (::SSL_CTX_load_verify_locations(handle_, filename.c_str(), 0) != 1)
333 { 337 {
334 ec = boost::system::error_code( 338 ec = boost::system::error_code(
335 static_cast<int>(::ERR_get_error()), 339 static_cast<int>(::ERR_get_error()),
336 boost::asio::error::get_ssl_category()); 340 boost::asio::error::get_ssl_category());
384 } 388 }
385 389
386 boost::system::error_code context::set_default_verify_paths( 390 boost::system::error_code context::set_default_verify_paths(
387 boost::system::error_code& ec) 391 boost::system::error_code& ec)
388 { 392 {
393 ::ERR_clear_error();
394
389 if (::SSL_CTX_set_default_verify_paths(handle_) != 1) 395 if (::SSL_CTX_set_default_verify_paths(handle_) != 1)
390 { 396 {
391 ec = boost::system::error_code( 397 ec = boost::system::error_code(
392 static_cast<int>(::ERR_get_error()), 398 static_cast<int>(::ERR_get_error()),
393 boost::asio::error::get_ssl_category()); 399 boost::asio::error::get_ssl_category());
406 } 412 }
407 413
408 boost::system::error_code context::add_verify_path( 414 boost::system::error_code context::add_verify_path(
409 const std::string& path, boost::system::error_code& ec) 415 const std::string& path, boost::system::error_code& ec)
410 { 416 {
417 ::ERR_clear_error();
418
411 if (::SSL_CTX_load_verify_locations(handle_, 0, path.c_str()) != 1) 419 if (::SSL_CTX_load_verify_locations(handle_, 0, path.c_str()) != 1)
412 { 420 {
413 ec = boost::system::error_code( 421 ec = boost::system::error_code(
414 static_cast<int>(::ERR_get_error()), 422 static_cast<int>(::ERR_get_error()),
415 boost::asio::error::get_ssl_category()); 423 boost::asio::error::get_ssl_category());
498 ec = boost::asio::error::invalid_argument; 506 ec = boost::asio::error::invalid_argument;
499 return ec; 507 return ec;
500 } 508 }
501 } 509 }
502 510
511 ::ERR_clear_error();
512
503 if (::SSL_CTX_use_certificate_file(handle_, filename.c_str(), file_type) != 1) 513 if (::SSL_CTX_use_certificate_file(handle_, filename.c_str(), file_type) != 1)
504 { 514 {
505 ec = boost::system::error_code( 515 ec = boost::system::error_code(
506 static_cast<int>(::ERR_get_error()), 516 static_cast<int>(::ERR_get_error()),
507 boost::asio::error::get_ssl_category()); 517 boost::asio::error::get_ssl_category());
590 } 600 }
591 601
592 boost::system::error_code context::use_certificate_chain_file( 602 boost::system::error_code context::use_certificate_chain_file(
593 const std::string& filename, boost::system::error_code& ec) 603 const std::string& filename, boost::system::error_code& ec)
594 { 604 {
605 ::ERR_clear_error();
606
595 if (::SSL_CTX_use_certificate_chain_file(handle_, filename.c_str()) != 1) 607 if (::SSL_CTX_use_certificate_chain_file(handle_, filename.c_str()) != 1)
596 { 608 {
597 ec = boost::system::error_code( 609 ec = boost::system::error_code(
598 static_cast<int>(::ERR_get_error()), 610 static_cast<int>(::ERR_get_error()),
599 boost::asio::error::get_ssl_category()); 611 boost::asio::error::get_ssl_category());
626 { 638 {
627 case context_base::asn1: 639 case context_base::asn1:
628 evp_private_key.p = ::d2i_PrivateKey_bio(bio.p, 0); 640 evp_private_key.p = ::d2i_PrivateKey_bio(bio.p, 0);
629 break; 641 break;
630 case context_base::pem: 642 case context_base::pem:
631 evp_private_key.p = ::PEM_read_bio_PrivateKey(bio.p, 0, 0, 0); 643 evp_private_key.p = ::PEM_read_bio_PrivateKey(
644 bio.p, 0, handle_->default_passwd_callback,
645 handle_->default_passwd_callback_userdata);
632 break; 646 break;
633 default: 647 default:
634 { 648 {
635 ec = boost::asio::error::invalid_argument; 649 ec = boost::asio::error::invalid_argument;
636 return ec; 650 return ec;
683 { 697 {
684 case context_base::asn1: 698 case context_base::asn1:
685 rsa_private_key.p = ::d2i_RSAPrivateKey_bio(bio.p, 0); 699 rsa_private_key.p = ::d2i_RSAPrivateKey_bio(bio.p, 0);
686 break; 700 break;
687 case context_base::pem: 701 case context_base::pem:
688 rsa_private_key.p = ::PEM_read_bio_RSAPrivateKey(bio.p, 0, 0, 0); 702 rsa_private_key.p = ::PEM_read_bio_RSAPrivateKey(
703 bio.p, 0, handle_->default_passwd_callback,
704 handle_->default_passwd_callback_userdata);
689 break; 705 break;
690 default: 706 default:
691 { 707 {
692 ec = boost::asio::error::invalid_argument; 708 ec = boost::asio::error::invalid_argument;
693 return ec; 709 return ec;
728 ec = boost::asio::error::invalid_argument; 744 ec = boost::asio::error::invalid_argument;
729 return ec; 745 return ec;
730 } 746 }
731 } 747 }
732 748
749 ::ERR_clear_error();
750
733 if (::SSL_CTX_use_PrivateKey_file(handle_, filename.c_str(), file_type) != 1) 751 if (::SSL_CTX_use_PrivateKey_file(handle_, filename.c_str(), file_type) != 1)
734 { 752 {
735 ec = boost::system::error_code( 753 ec = boost::system::error_code(
736 static_cast<int>(::ERR_get_error()), 754 static_cast<int>(::ERR_get_error()),
737 boost::asio::error::get_ssl_category()); 755 boost::asio::error::get_ssl_category());
768 ec = boost::asio::error::invalid_argument; 786 ec = boost::asio::error::invalid_argument;
769 return ec; 787 return ec;
770 } 788 }
771 } 789 }
772 790
791 ::ERR_clear_error();
792
773 if (::SSL_CTX_use_RSAPrivateKey_file( 793 if (::SSL_CTX_use_RSAPrivateKey_file(
774 handle_, filename.c_str(), file_type) != 1) 794 handle_, filename.c_str(), file_type) != 1)
775 { 795 {
776 ec = boost::system::error_code( 796 ec = boost::system::error_code(
777 static_cast<int>(::ERR_get_error()), 797 static_cast<int>(::ERR_get_error()),
791 } 811 }
792 812
793 boost::system::error_code context::use_tmp_dh( 813 boost::system::error_code context::use_tmp_dh(
794 const const_buffer& dh, boost::system::error_code& ec) 814 const const_buffer& dh, boost::system::error_code& ec)
795 { 815 {
816 ::ERR_clear_error();
817
796 bio_cleanup bio = { make_buffer_bio(dh) }; 818 bio_cleanup bio = { make_buffer_bio(dh) };
797 if (bio.p) 819 if (bio.p)
798 { 820 {
799 return do_use_tmp_dh(bio.p, ec); 821 return do_use_tmp_dh(bio.p, ec);
800 } 822 }
813 } 835 }
814 836
815 boost::system::error_code context::use_tmp_dh_file( 837 boost::system::error_code context::use_tmp_dh_file(
816 const std::string& filename, boost::system::error_code& ec) 838 const std::string& filename, boost::system::error_code& ec)
817 { 839 {
840 ::ERR_clear_error();
841
818 bio_cleanup bio = { ::BIO_new_file(filename.c_str(), "r") }; 842 bio_cleanup bio = { ::BIO_new_file(filename.c_str(), "r") };
819 if (bio.p) 843 if (bio.p)
820 { 844 {
821 return do_use_tmp_dh(bio.p, ec); 845 return do_use_tmp_dh(bio.p, ec);
822 } 846 }