2016-05-30 29 views
2

私は現在、C++ IMAPライブラリで作業していますので、錆びたC++スキルを向上させることができます。私はライブラリを可能な限りポータブルにして、OSの中でそれを使うことができるようにしたいと思います。そのために、いくつかの研究を行い、BoostのAsioライブラリを使用することに決めました。Boost AsioとOpenSSL 1.1.0

Boostをビルドして自分のプロジェクトで実行することができました。私のイベントはgoogle.comに簡単なHTTP GETを行った。残念ながら、TLSを使用して通信できる必要があり、AsioのSSL機能を使用しようとする際に問題が発生しました。

私はBoostとOpenSSLの両方をソースからビルドしました。デフォルト設定を使用しています(すべてが/ usr/localにあります)。私はまた私のプロジェクトをビルドするためにCMAKEを使用しています。

In file included from /path/to/my/code/JMail/IMAP/main.cpp:4: 
In file included from /path/to/my/code/JMail/IMAP/IMAPClient.h:6: 
In file included from /path/to/my/code/JMail/IMAP/TLSSocket.h:9: 
In file included from /usr/local/include/boost/asio/ssl.hpp:19: 
In file included from /usr/local/include/boost/asio/ssl/context.hpp:29: 
In file included from /usr/local/include/boost/asio/ssl/detail/openssl_init.hpp:100: 
/usr/local/include/boost/asio/ssl/detail/impl/openssl_init.ipp:43:23: error: expected unqualified-id 
    mutexes_.resize(::CRYPTO_num_locks()); 
        ^
/usr/local/include/openssl/crypto.h:218:41: note: expanded from macro 'CRYPTO_num_locks' 
# define CRYPTO_num_locks()   (0) 
             ^
In file included from /path/to/my/code/JMail/IMAP/main.cpp:4: 
In file included from /path/to/my/code/JMail/IMAP/IMAPClient.h:6: 
In file included from /path/to/my/code/JMail/IMAP/TLSSocket.h:9: 
In file included from /usr/local/include/boost/asio/ssl.hpp:19: 
In file included from /usr/local/include/boost/asio/ssl/context.hpp:29: 
In file included from /usr/local/include/boost/asio/ssl/detail/openssl_init.hpp:100: 
/usr/local/include/boost/asio/ssl/detail/impl/openssl_init.ipp:46:66: error: expected unqualified-id 
    ::CRYPTO_set_locking_callback(&do_init::openssl_locking_func); 
                   ^
/usr/local/include/boost/asio/ssl/detail/impl/openssl_init.ipp:47:56: error: expected unqualified-id 
    ::CRYPTO_set_id_callback(&do_init::openssl_id_func); 
                ^
/usr/local/include/boost/asio/ssl/detail/impl/openssl_init.ipp:64:32: error: expected unqualified-id 
    ::CRYPTO_set_id_callback(0); 
          ^
/usr/local/include/boost/asio/ssl/detail/impl/openssl_init.ipp:65:37: error: expected unqualified-id 
    ::CRYPTO_set_locking_callback(0); 
            ^
/usr/local/include/boost/asio/ssl/detail/impl/openssl_init.ipp:66:7: error: expected unqualified-id 
    ::ERR_free_strings(); 
    ^
/usr/local/include/openssl/err.h:241:29: note: expanded from macro 'ERR_free_strings' 
# define ERR_free_strings() while(0) continue 
          ^
In file included from /path/to/my/code/JMail/IMAP/main.cpp:4: 
In file included from /path/to/my/code/JMail/IMAP/IMAPClient.h:6: 
In file included from /path/to/my/code/JMail/IMAP/TLSSocket.h:9: 
In file included from /usr/local/include/boost/asio/ssl.hpp:19: 
In file included from /usr/local/include/boost/asio/ssl/context.hpp:29: 
In file included from /usr/local/include/boost/asio/ssl/detail/openssl_init.hpp:100: 
/usr/local/include/boost/asio/ssl/detail/impl/openssl_init.ipp:68:7: warning: 'ERR_remove_thread_state' is deprecated [-Wdeprecated-declarations] 
    ::ERR_remove_thread_state(NULL); 
    ^
/usr/local/include/openssl/err.h:244:25: note: 'ERR_remove_thread_state' has been explicitly marked deprecated here 
DEPRECATEDIN_1_1_0(void ERR_remove_thread_state(void *)) 
         ^
In file included from /path/to/my/code/JMail/IMAP/main.cpp:4: 
In file included from /path/to/my/code/JMail/IMAP/IMAPClient.h:6: 
In file included from /path/to/my/code/JMail/IMAP/TLSSocket.h:9: 
In file included from /usr/local/include/boost/asio/ssl.hpp:19: 
In file included from /usr/local/include/boost/asio/ssl/context.hpp:29: 
In file included from /usr/local/include/boost/asio/ssl/detail/openssl_init.hpp:100: 
/usr/local/include/boost/asio/ssl/detail/impl/openssl_init.ipp:72:7: error: expected unqualified-id 
    ::EVP_cleanup(); 
    ^
/usr/local/include/openssl/evp.h:865:25: note: expanded from macro 'EVP_cleanup' 
# define EVP_cleanup() while(0) continue 
         ^
In file included from /path/to/my/code/JMail/IMAP/main.cpp:4: 
In file included from /path/to/my/code/JMail/IMAP/IMAPClient.h:6: 
In file included from /path/to/my/code/JMail/IMAP/TLSSocket.h:9: 
In file included from /usr/local/include/boost/asio/ssl.hpp:19: 
In file included from /usr/local/include/boost/asio/ssl/context.hpp:29: 
In file included from /usr/local/include/boost/asio/ssl/detail/openssl_init.hpp:100: 
/usr/local/include/boost/asio/ssl/detail/impl/openssl_init.ipp:73:7: error: expected unqualified-id 
    ::CRYPTO_cleanup_all_ex_data(); 
    ^
/usr/local/include/openssl/crypto.h:206:39: note: expanded from macro 'CRYPTO_cleanup_all_ex_data' 
# define CRYPTO_cleanup_all_ex_data() while(0) continue 
            ^
In file included from /path/to/my/code/JMail/IMAP/main.cpp:4: 
In file included from /path/to/my/code/JMail/IMAP/IMAPClient.h:6: 
In file included from /path/to/my/code/JMail/IMAP/TLSSocket.h:9: 
In file included from /usr/local/include/boost/asio/ssl.hpp:19: 
In file included from /usr/local/include/boost/asio/ssl/context.hpp:29: 
In file included from /usr/local/include/boost/asio/ssl/detail/openssl_init.hpp:100: 
/usr/local/include/boost/asio/ssl/detail/impl/openssl_init.ipp:76:7: error: expected unqualified-id 
    ::ENGINE_cleanup(); 
    ^
/usr/local/include/openssl/engine.h:508:27: note: expanded from macro 'ENGINE_cleanup' 
# define ENGINE_cleanup() while(0) continue 
         ^
In file included from /path/to/my/code/JMail/IMAP/main.cpp:4: 
In file included from /path/to/my/code/JMail/IMAP/IMAPClient.h:6: 
In file included from /path/to/my/code/JMail/IMAP/TLSSocket.h:9: 
In file included from /usr/local/include/boost/asio/ssl.hpp:19: 
In file included from /usr/local/include/boost/asio/ssl/context.hpp:29: 
In file included from /usr/local/include/boost/asio/ssl/detail/openssl_init.hpp:100: 
/usr/local/include/boost/asio/ssl/detail/impl/openssl_init.ipp:106:16: error: use of undeclared identifier 'CRYPTO_LOCK' 
    if (mode & CRYPTO_LOCK) 
      ^
In file included from /path/to/my/code/JMail/IMAP/main.cpp:4: 
In file included from /path/to/my/code/JMail/IMAP/IMAPClient.h:6: 
In file included from /path/to/my/code/JMail/IMAP/TLSSocket.h:9: 
In file included from /usr/local/include/boost/asio/ssl.hpp:19: 
In file included from /usr/local/include/boost/asio/ssl/context.hpp:786: 
/usr/local/include/boost/asio/ssl/impl/context.ipp:83:31: error: no member named 'SSLv2_method' in the global namespace 
    handle_ = ::SSL_CTX_new(::SSLv2_method()); 
          ~~^ 
/usr/local/include/boost/asio/ssl/impl/context.ipp:86:31: error: no member named 'SSLv2_client_method' in the global namespace 
    handle_ = ::SSL_CTX_new(::SSLv2_client_method()); 
          ~~^ 
/usr/local/include/boost/asio/ssl/impl/context.ipp:89:31: error: no member named 'SSLv2_server_method' in the global namespace 
    handle_ = ::SSL_CTX_new(::SSLv2_server_method()); 
          ~~^ 
/usr/local/include/boost/asio/ssl/impl/context.ipp:111:31: warning: 'TLSv1_method' is deprecated [-Wdeprecated-declarations] 
    handle_ = ::SSL_CTX_new(::TLSv1_method()); 
          ^
/usr/local/include/openssl/ssl.h:1556:45: note: 'TLSv1_method' has been explicitly marked deprecated here 
DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_method(void)) /* TLSv1.0 */ 
              ^
In file included from /path/to/my/code/JMail/IMAP/main.cpp:4: 
In file included from /path/to/my/code/JMail/IMAP/IMAPClient.h:6: 
In file included from /path/to/my/code/JMail/IMAP/TLSSocket.h:9: 
In file included from /usr/local/include/boost/asio/ssl.hpp:19: 
In file included from /usr/local/include/boost/asio/ssl/context.hpp:786: 
/usr/local/include/boost/asio/ssl/impl/context.ipp:114:31: warning: 'TLSv1_client_method' is deprecated [-Wdeprecated-declarations] 
    handle_ = ::SSL_CTX_new(::TLSv1_client_method()); 
          ^
/usr/local/include/openssl/ssl.h:1558:45: note: 'TLSv1_client_method' has been explicitly marked deprecated here 
DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_client_method(void)) /* TLSv1.0 */ 
              ^
In file included from /path/to/my/code/JMail/IMAP/main.cpp:4: 
In file included from /path/to/my/code/JMail/IMAP/IMAPClient.h:6: 
In file included from /path/to/my/code/JMail/IMAP/TLSSocket.h:9: 
In file included from /usr/local/include/boost/asio/ssl.hpp:19: 
In file included from /usr/local/include/boost/asio/ssl/context.hpp:786: 
/usr/local/include/boost/asio/ssl/impl/context.ipp:117:31: warning: 'TLSv1_server_method' is deprecated [-Wdeprecated-declarations] 
    handle_ = ::SSL_CTX_new(::TLSv1_server_method()); 
          ^
/usr/local/include/openssl/ssl.h:1557:45: note: 'TLSv1_server_method' has been explicitly marked deprecated here 
DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_server_method(void)) /* TLSv1.0 */ 
              ^
In file included from /path/to/my/code/JMail/IMAP/main.cpp:4: 
In file included from /path/to/my/code/JMail/IMAP/IMAPClient.h:6: 
In file included from /path/to/my/code/JMail/IMAP/TLSSocket.h:9: 
In file included from /usr/local/include/boost/asio/ssl.hpp:19: 
In file included from /usr/local/include/boost/asio/ssl/context.hpp:786: 
/usr/local/include/boost/asio/ssl/impl/context.ipp:130:31: warning: 'TLSv1_1_method' is deprecated [-Wdeprecated-declarations] 
    handle_ = ::SSL_CTX_new(::TLSv1_1_method()); 
          ^
/usr/local/include/openssl/ssl.h:1562:45: note: 'TLSv1_1_method' has been explicitly marked deprecated here 
DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_1_method(void)) /* TLSv1.1 */ 
              ^
In file included from /path/to/my/code/JMail/IMAP/main.cpp:4: 
In file included from /path/to/my/code/JMail/IMAP/IMAPClient.h:6: 
In file included from /path/to/my/code/JMail/IMAP/TLSSocket.h:9: 
In file included from /usr/local/include/boost/asio/ssl.hpp:19: 
In file included from /usr/local/include/boost/asio/ssl/context.hpp:786: 
/usr/local/include/boost/asio/ssl/impl/context.ipp:133:31: warning: 'TLSv1_1_client_method' is deprecated [-Wdeprecated-declarations] 
    handle_ = ::SSL_CTX_new(::TLSv1_1_client_method()); 
          ^
/usr/local/include/openssl/ssl.h:1564:45: note: 'TLSv1_1_client_method' has been explicitly marked deprecated here 
DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_1_client_method(void)) /* TLSv1.1 */ 
              ^
In file included from /path/to/my/code/JMail/IMAP/main.cpp:4: 
In file included from /path/to/my/code/JMail/IMAP/IMAPClient.h:6: 
In file included from /path/to/my/code/JMail/IMAP/TLSSocket.h:9: 
In file included from /usr/local/include/boost/asio/ssl.hpp:19: 
In file included from /usr/local/include/boost/asio/ssl/context.hpp:786: 
/usr/local/include/boost/asio/ssl/impl/context.ipp:136:31: warning: 'TLSv1_1_server_method' is deprecated [-Wdeprecated-declarations] 
    handle_ = ::SSL_CTX_new(::TLSv1_1_server_method()); 
          ^
/usr/local/include/openssl/ssl.h:1563:45: note: 'TLSv1_1_server_method' has been explicitly marked deprecated here 
DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_1_server_method(void)) /* TLSv1.1 */ 
              ^
In file included from /path/to/my/code/JMail/IMAP/main.cpp:4: 
In file included from /path/to/my/code/JMail/IMAP/IMAPClient.h:6: 
In file included from /path/to/my/code/JMail/IMAP/TLSSocket.h:9: 
In file included from /usr/local/include/boost/asio/ssl.hpp:19: 
In file included from /usr/local/include/boost/asio/ssl/context.hpp:786: 
/usr/local/include/boost/asio/ssl/impl/context.ipp:148:31: warning: 'TLSv1_2_method' is deprecated [-Wdeprecated-declarations] 
    handle_ = ::SSL_CTX_new(::TLSv1_2_method()); 
          ^
/usr/local/include/openssl/ssl.h:1568:45: note: 'TLSv1_2_method' has been explicitly marked deprecated here 
DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_2_method(void)) /* TLSv1.2 */ 
              ^
In file included from /path/to/my/code/JMail/IMAP/main.cpp:4: 
In file included from /path/to/my/code/JMail/IMAP/IMAPClient.h:6: 
In file included from /path/to/my/code/JMail/IMAP/TLSSocket.h:9: 
In file included from /usr/local/include/boost/asio/ssl.hpp:19: 
In file included from /usr/local/include/boost/asio/ssl/context.hpp:786: 
/usr/local/include/boost/asio/ssl/impl/context.ipp:151:31: warning: 'TLSv1_2_client_method' is deprecated [-Wdeprecated-declarations] 
    handle_ = ::SSL_CTX_new(::TLSv1_2_client_method()); 
          ^
/usr/local/include/openssl/ssl.h:1570:45: note: 'TLSv1_2_client_method' has been explicitly marked deprecated here 
DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_2_client_method(void)) /* TLSv1.2 */ 
              ^
In file included from /path/to/my/code/JMail/IMAP/main.cpp:4: 
In file included from /path/to/my/code/JMail/IMAP/IMAPClient.h:6: 
In file included from /path/to/my/code/JMail/IMAP/TLSSocket.h:9: 
In file included from /usr/local/include/boost/asio/ssl.hpp:19: 
In file included from /usr/local/include/boost/asio/ssl/context.hpp:786: 
/usr/local/include/boost/asio/ssl/impl/context.ipp:154:31: warning: 'TLSv1_2_server_method' is deprecated [-Wdeprecated-declarations] 
    handle_ = ::SSL_CTX_new(::TLSv1_2_server_method()); 
          ^
/usr/local/include/openssl/ssl.h:1569:45: note: 'TLSv1_2_server_method' has been explicitly marked deprecated here 
DEPRECATEDIN_1_1_0(__owur const SSL_METHOD *TLSv1_2_server_method(void)) /* TLSv1.2 */ 
              ^
In file included from /path/to/my/code/JMail/IMAP/main.cpp:4: 
In file included from /path/to/my/code/JMail/IMAP/IMAPClient.h:6: 
In file included from /path/to/my/code/JMail/IMAP/TLSSocket.h:9: 
In file included from /usr/local/include/boost/asio/ssl.hpp:19: 
In file included from /usr/local/include/boost/asio/ssl/context.hpp:786: 
/usr/local/include/boost/asio/ssl/impl/context.ipp:208:16: error: member access into incomplete type 'SSL_CTX' (aka 'ssl_ctx_st') 
    if (handle_->default_passwd_callback_userdata) 
      ^
/usr/local/include/openssl/ossl_typ.h:144:16: note: forward declaration of 'ssl_ctx_st' 
typedef struct ssl_ctx_st SSL_CTX; 
      ^
In file included from /path/to/my/code/JMail/IMAP/main.cpp:4: 
In file included from /path/to/my/code/JMail/IMAP/IMAPClient.h:6: 
In file included from /path/to/my/code/JMail/IMAP/TLSSocket.h:9: 
In file included from /usr/local/include/boost/asio/ssl.hpp:19: 
In file included from /usr/local/include/boost/asio/ssl/context.hpp:786: 
/usr/local/include/boost/asio/ssl/impl/context.ipp:212:20: error: member access into incomplete type 'SSL_CTX' (aka 'ssl_ctx_st') 
      handle_->default_passwd_callback_userdata); 
       ^
/usr/local/include/openssl/ossl_typ.h:144:16: note: forward declaration of 'ssl_ctx_st' 
typedef struct ssl_ctx_st SSL_CTX; 
      ^
In file included from /path/to/my/code/JMail/IMAP/main.cpp:4: 
In file included from /path/to/my/code/JMail/IMAP/IMAPClient.h:6: 
In file included from /path/to/my/code/JMail/IMAP/TLSSocket.h:9: 
In file included from /usr/local/include/boost/asio/ssl.hpp:19: 
In file included from /usr/local/include/boost/asio/ssl/context.hpp:786: 
/usr/local/include/boost/asio/ssl/impl/context.ipp:212:22: error: expected ')' 
      handle_->default_passwd_callback_userdata); 
        ^
/usr/local/include/boost/asio/ssl/impl/context.ipp:211:53: note: to match this '(' 
     static_cast<detail::password_callback_base*>(
                ^
/usr/local/include/boost/asio/ssl/impl/context.ipp:214:14: error: member access into incomplete type 'SSL_CTX' (aka 'ssl_ctx_st') 
     handle_->default_passwd_callback_userdata = 0; 
      ^
/usr/local/include/openssl/ossl_typ.h:144:16: note: forward declaration of 'ssl_ctx_st' 
typedef struct ssl_ctx_st SSL_CTX; 
      ^
In file included from /path/to/my/code/JMail/IMAP/main.cpp:4: 
In file included from /path/to/my/code/JMail/IMAP/IMAPClient.h:6: 
In file included from /path/to/my/code/JMail/IMAP/TLSSocket.h:9: 
In file included from /usr/local/include/boost/asio/ssl.hpp:19: 
In file included from /usr/local/include/boost/asio/ssl/context.hpp:786: 
/usr/local/include/boost/asio/ssl/impl/context.ipp:551:18: error: member access into incomplete type 'SSL_CTX' (aka 'ssl_ctx_st') 
      handle_->default_passwd_callback, 
       ^
/usr/local/include/openssl/ossl_typ.h:144:16: note: forward declaration of 'ssl_ctx_st' 
typedef struct ssl_ctx_st SSL_CTX; 
      ^
In file included from /path/to/my/code/JMail/IMAP/main.cpp:4: 
In file included from /path/to/my/code/JMail/IMAP/IMAPClient.h:6: 
In file included from /path/to/my/code/JMail/IMAP/TLSSocket.h:9: 
In file included from /usr/local/include/boost/asio/ssl.hpp:19: 
In file included from /usr/local/include/boost/asio/ssl/context.hpp:786: 
/usr/local/include/boost/asio/ssl/impl/context.ipp:552:18: error: member access into incomplete type 'SSL_CTX' (aka 'ssl_ctx_st') 
      handle_->default_passwd_callback_userdata) }; 
       ^
/usr/local/include/openssl/ossl_typ.h:144:16: note: forward declaration of 'ssl_ctx_st' 
typedef struct ssl_ctx_st SSL_CTX; 
      ^
fatal error: too many errors emitted, stopping now [-ferror-limit=] 
10 warnings and 20 errors generated. 
:私は、エラーの次の山を受けるプロジェクトをビルドしようとすると

Warning:Starting CMAKE... 
Warning:Boost_INCLUDE_DIR: /usr/local/include 
Warning:Boost_LIBRARIES: /usr/local/lib/libboost_system.dylib;/usr/local/lib/libboost_thread.dylib;/usr/local/lib/libboost_regex.dylib;/usr/local/lib/libboost_chrono.dylib;/usr/local/lib/libboost_date_time.dylib;/usr/local/lib/libboost_atomic.dylib 
Warning:Boost_VERSION: 106100 
Warning:OpenSSL_VERSION: 1.1.0 
Warning:OpenSSL_INCLUDE_DIR: /usr/local/include 
Warning:OpenSSL_LIBRARIES: /usr/local/lib/libssl.dylib;/usr/local/lib/libcrypto.dylib 

cmake_minimum_required(VERSION 3.2) 
project(IMAP) 

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 

message(WARNING "Starting CMAKE...") 
set(SOURCE_FILES main.cpp) 
add_executable(IMAP ${SOURCE_FILES}) 

find_package(Boost COMPONENTS system thread regex REQUIRED) 
message(WARNING "Boost_INCLUDE_DIR: ${Boost_INCLUDE_DIR}") 
message(WARNING "Boost_LIBRARIES: ${Boost_LIBRARIES}") 
message(WARNING "Boost_VERSION: ${Boost_VERSION}") 
include_directories(${Boost_INCLUDE_DIR}) 
target_link_libraries(IMAP ${Boost_LIBRARIES}) 

find_package(OpenSSL REQUIRED) 
message(WARNING "OpenSSL_VERSION: ${OPENSSL_VERSION}") 
message(WARNING "OpenSSL_INCLUDE_DIR: ${OPENSSL_INCLUDE_DIR}") 
message(WARNING "OpenSSL_LIBRARIES: ${OPENSSL_LIBRARIES}") 
include_directories(${OPENSSL_INCLUDE_DIR}) 
target_link_libraries(IMAP ${OPENSSL_LIBRARIES}) 

そして、これが私のCMAKEメッセージの出力である:以下は私のCMAKEファイルです

参照されているTLSSocketクラスは、基本的にはBoost Asio SSLの例のラッパーです:

#include <boost/bind.hpp> 
#include <boost/asio.hpp> 
#include <boost/asio/ssl.hpp> 

void TLSSocket::connect() { 
    boost::asio::io_service io_service; 
    boost::asio::ip::tcp::resolver resolver(io_service); 
    boost::asio::ip::tcp::resolver::query query(this->address, this->port); 
    boost::asio::ip::tcp::resolver::iterator iterator = resolver.resolve(query); 
    boost::asio::ssl::context ctx(boost::asio::ssl::context::tlsv1); 
    mSocket = new boost::asio::ssl::stream<boost::asio::ip::tcp::socket>(io_service, ctx); 
    mSocket->set_verify_mode(boost::asio::ssl::verify_peer); 
    mSocket->set_verify_callback(boost::bind(&TLSSocket::on_verify_certificate, this, _1, _2)); 
    boost::asio::async_connect(mSocket->lowest_layer(), iterator, 
     boost::bind(&TLSSocket::on_connect, this, boost::asio::placeholders::error)); 
    io_service.run(); 
} 

void TLSSocket::disconnect() { 
    mSocket->lowest_layer().cancel(); 
} 

TLSSocket::TLSSocket(std::string address, std::string port) { 
    this->address = address; 
    this->port = port; 
    mSocket = nullptr; 
} 

void *TLSSocket::send(IMAPRequest *request) { 
    boost::asio::streambuf requestBuff; 
    std::ostream request_stream(&requestBuff); 
    request_stream << request->getTag() << " " << request->getCommand() << " " << request->getContent() << "\r\n"; 

    boost::asio::write(*mSocket, requestBuff); 

    for (; ;) { 
     boost::array<char, 128> buffer; 
     boost::system::error_code error; 
     size_t len = mSocket->read_some(boost::asio::buffer(buffer), error); 

     if (error == boost::asio::error::eof) 
      break; 
     else if (error) 
      throw boost::system::system_error(error); 

     std::cout.write(buffer.data(), len); 
    } 
} 

void TLSSocket::on_connect(const boost::system::error_code& error){ 
    if(!error) { 
     try { 
      mSocket->async_handshake(boost::asio::ssl::stream_base::handshake_type ::client, 
            boost::bind(&TLSSocket::on_handshake, this, boost::asio::placeholders::error)); 
     } catch (std::exception ex){ 
      std::cout << "Handshaking error: " << ex.what() << "\n"; 
     } 
    } else { 
     std::cout << "Connect error: " << error.message() << "\n"; 
    } 
} 

void TLSSocket::on_handshake(const boost::system::error_code& error){ 
    if(!error){ 

    } else { 
     std::cout << "Handshaking error: " << error.message() << "\n"; 
    } 
} 

bool TLSSocket::on_verify_certificate(bool verified, boost::asio::ssl::verify_context &ctx) { 
    char subject_name[256]; 
    X509* cert = X509_STORE_CTX_get_current_cert(ctx.native_handle()); 
    X509_NAME_oneline(X509_get_subject_name(cert), subject_name, 256); 
    std::cout << "Verifying " << subject_name << "\n"; 

    return verified; 
} 

コンパイルのリンク段階にも達していないように見えます。私のmain.cppに.oファイルを作成しようとしているだけです。私がIDEで不平を言っているファイルの一つを開くと、IDEは私に構文エラーのハイライトを表示しますが、なぜか私は困惑します。

私はインクルードを間違った順序で入れましたか?私のCMAKEファイルに問題はありますか?私はOpenSSLやBoostを間違ってビルドしましたか?

ご協力いただければ幸いです。私はこれを数週間にわたってオン/オフしてきました。その時間の大部分をビルドするだけでした(C++レッスン1、私は推測します:))。

+1

OpenSSLのRTで開く... [問題4547:CRYPTO_num_locks()関数を "#define CRYPTO_num_locks()(0)"に変更するとコンパイルが失敗する](https://rt.openssl.org/Ticket/Display.html) ?id = 4547&user = guest&pass = guest)。このプロジェクトは痛みを緩和することができるかもしれません。バージョニングと代替コードパスに基づいてガーディングを提案するかもしれません。 OpenSSLが後者を示唆している場合は、Boostでバグレポートを開く必要があります。マイナーバージョンのバンプ(1.0.2〜1.1.0)でシンボルが変更されたため、OpenSSLがプログラムを中断することは珍しくありません。彼らのガバナンスはそれを可能にするかもしれませんが、私はポリシー文書を探しませんでした。 – jww

+0

私は1.0.2にロールバックし、すべてが機能しました。ありがとう! –

+0

ブーストバグトラッカーで開く... [問題12238:ブーストがOpenSSL 1.1.0を使用してコンパイルに失敗する](http://svn.boost.org/trac/boost/ticket/12238) – jww

答えて

5

これは、BoostがOpenSSL 1.1.0で動作するように更新されていないようです。 OpenSSL 1.0.2と1.1.0の間には多くのAPIの変更があり、完全なソース互換性がありません。 Boostが新しいOpenSSLバージョン(まだベータ版である)で動作するように更新されるまで、1.0.2を使用することをお勧めします。

+0

これはうまくいった!あなたは私がどれくらいの時間を節約したか分かりません。ありがとう、トン! –

関連する問題