Boost Asio和OpenSSL 1.1.0 [英] Boost Asio and OpenSSL 1.1.0

查看:3186
本文介绍了Boost Asio和OpenSSL 1.1.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用一个C ++ IMAP库,以便我可以改进一些肯定生锈的C ++技能。我想让库尽可能便携,这样我可以在操作系统上使用它,如果我感到疯了,甚至在移动设备上。为此,我做了一些研究,并决定使用Boost的Asio库。



我可以让Boost在我的项目中构建和运行。 I event向google.com发送了一个简单的HTTP GET。不幸的是,我需要能够使用TLS进行通信,并且我遇到了尝试使用Asio的SSL功能的问题。



我使用默认设置从源代码构建了Boost和OpenSSL(因此一切都在/ usr / local中)。我也使用CMAKE来构建我的项目。以下是我的CMAKE文件:

  cmake_minimum_required(VERSION 3.2)
项目(IMAP)
$ b b set(CMAKE_CXX_FLAGS$ {CMAKE_CXX_FLAGS} -std = c ++ 11)

消息(警告启动CMAKE ...)
设置(SOURCE_FILES main.cpp)
add_executable(IMAP $ {SOURCE_FILES})

find_package(Boost COMPONENTS system thread regex REQUIRED)
消息(警告Boost_INCLUDE_DIR:$ {Boost_INCLUDE_DIR})
消息Boost_LIBRARIES:$ {Boost_LIBRARIES})
消息(警告Boost_VERSION:$ {Boost_VERSION})
include_directories($ {Boost_INCLUDE_DIR})
target_link_libraries(IMAP $ {Boost_LIBRARIES})

find_package(OpenSSL REQUIRED)
消息(警告OpenSSL_VERSION:$ {OPENSSL_VERSION})
消息(警告OpenSSL_INCLUDE_DIR:$ {OPENSSL_INCLUDE_DIR})
消息OpenSSL_LIBRARIES:$ {OPENSSL_LIBRARIES})
include_directories($ {OPENSSL_INCLUDE_DIR})
target_link_libraries(IMAP $ {OPENSSL_LIBRARIES})

这是我的CMAKE消息的输出:

 警告:启动CMAKE。 .. 
警告:Boost_INCLUDE_DIR:/ usr / local / include
警告: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
警告:Boost_VERSION:106100
警告:OpenSSL_VERSION:1.1.0
警告:OpenSSL_INCLUDE_DIR:/ usr / local / include
警告:OpenSSL_LIBRARIES:/usr/local/lib/libssl.dylib;/usr/local/lib/libcrypto .dylib

当我尝试构建项目时,我收到以下几堆错误:

 在/path/to/my/code/JMail/IMAP/main.cpp:4中包含的文件中:
在包含的文件中从/path/to/my/code/JMail/IMAP/IMAPClient.h:6:
在包含在/path/to/my/code/JMail/IMAP/TLSSocket.h:9的文件中:
在/usr/local/include/boost/asio/ssl.hpp:19中包含的文件中:
在包含在/usr/local/include/boost/asio/ssl/context.hpp:29中的文件中:
在/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:注意:从宏CRYPTO_num_locks扩展
#define CRYPTO_num_locks()(0)
^
在/path/to/my/code/JMail/IMAP/main.cpp:4中包含的文件中:
在包含在/ path /到/ my / code / JMail / IMAP / IMAPClient的文件中.h:6:
在/path/to/my/code/JMail/IMAP/TLSSocket.h:9中包含的文件中:
在包含在/ usr / local / include / boost / asio中的文件中/ssl.hpp:19:
在/usr/local/include/boost/asio/ssl/context.hpp:29中包含的文件中:
在包含在/ 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:错误: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:注意:从宏'ERR_free_strings'扩展
#define ERR_free_strings()while(0)继续
^
在/path/to/my/code/JMail/IMAP/main.cpp:4中包含的文件中:
在从/ path /到/ my / code / JMail / IMAP /IMAPClient.h:6:
在/path/to/my/code/JMail/IMAP/TLSSocket.h:9中包含的文件中:
在包含在/ usr / local / include / boost中的文件中/asio/ssl.hpp:19:
在/usr/local/include/boost/asio/ssl/context.hpp:29中包含的文件中:
在包含在/ 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:注意:'ERR_remove_thread_state'已在此处显式标记为已弃用
DEPRECATEDIN_1_1_0(void ERR_remove_thread_state(void *))
^
在/path/to/my/code/JMail/IMAP/main.cpp:4中包含的文件中:
在从/ path /到/ my / code / JMail中包含的文件中/IMAP/IMAPClient.h:6:
在/path/to/my/code/JMail/IMAP/TLSSocket.h:9中包含的文件中:
在包含在/ usr / local / include中的文件中/boost/asio/ssl.hpp:19:
在/usr/local/include/boost/asio/ssl/context.hpp:29中包含的文件中:
在包含在/ 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:注意:从宏'EVP_cleanup'扩展
#define EVP_cleanup()while(0)continue
^
在/path/to/my/code/JMail/IMAP/main.cpp:4中包含的文件中:
在从/ path /到/ my / code / JMail / IMAP /IMAPClient.h:6:
在/path/to/my/code/JMail/IMAP/TLSSocket.h:9中包含的文件中:
在包含在/ usr / local / include / boost中的文件中/asio/ssl.hpp:19:
在/usr/local/include/boost/asio/ssl/context.hpp:29中包含的文件中:
在包含在/ 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:注意:从宏'CRYPTO_cleanup_all_ex_data'扩展
#define CRYPTO_cleanup_all_ex_data()while(0)continue
^
在/path/to/my/code/JMail/IMAP/main.cpp:4中包含的文件中:
在从/ path /到/ my / code / JMail / IMAP /IMAPClient.h:6:
在/path/to/my/code/JMail/IMAP/TLSSocket.h:9中包含的文件中:
在包含在/ usr / local / include / boost中的文件中/asio/ssl.hpp:19:
在/usr/local/include/boost/asio/ssl/context.hpp:29中包含的文件中:
在包含在/ 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:注意:从宏'ENGINE_cleanup'扩展
#define ENGINE_cleanup()while(0)继续
^
在/path/to/my/code/JMail/IMAP/main.cpp:4中包含的文件中:
在从/ path /到/ my / code / JMail / IMAP /IMAPClient.h:6:
在/path/to/my/code/JMail/IMAP/TLSSocket.h:9中包含的文件中:
在包含在/ usr / local / include / boost中的文件中/asio/ssl.hpp:19:
在/usr/local/include/boost/asio/ssl/context.hpp:29中包含的文件中:
在包含在/ usr / local / include中的文件中/boost/asio/ssl/detail/openssl_init.hpp:100:
/usr/local/include/boost/asio/ssl/detail/impl/openssl_init.ipp:106:16:错误:使用未声明的标识符'CRYPTO_LOCK'
if(mode& CRYPTO_LOCK)
^
在/path/to/my/code/JMail/IMAP/main.cpp:4中包含的文件中:
在/path/to/my/code/JMail/IMAP/IMAPClient.h:6中包含的文件中:
在包含在/path/to/my/code/JMail/IMAP/TLSSocket.h:9中的文件中:
在/usr/local/include/boost/asio/ssl.hpp:19中包含的文件中:
在包含在/usr/local/include/boost/asio/ssl/context.hpp中的文件中: 786:
/usr/local/include/boost/asio/ssl/impl/context.ipp:83:31:错误:在全局命名空间中没有名为SSLv2_method的成员
handle_ = :: SSL_CTX_new (:: SSLv2_method());
~~ ^
/usr/local/include/boost/asio/ssl/impl/context.ipp:86:31:错误:在全局命名空间中没有名为SSLv2_client_method的成员
handle_ = :: SSL_CTX_new(:: SSLv2_client_method());
~~ ^
/usr/local/include/boost/asio/ssl/impl/context.ipp:89:31:错误:在全局命名空间中没有名为SSLv2_server_method的成员
handle_ = :: SSL_CTX_new(:: SSLv2_server_method());
~~ ^
/usr/local/include/boost/asio/ssl/impl/context.ipp:111:31:warning:'TLSv1_method'已弃用[-Wdeprecated-declarations]
handle_ = :: SSL_CTX_new(:: TLSv1_method());
^
/usr/local/include/openssl/ssl.h:1556:45:注意:'TLSv1_method'已在此处显式标记为已弃用
DEPRECATEDIN_1_1_0(__ owur const SSL_METHOD * TLSv1_method ))/ * TLSv1.0 * /
^
在/path/to/my/code/JMail/IMAP/main.cpp:4中包含的文件中:
在包含/路径/到/ my / code / JMail / IMAP / IMAPClient.h:6:
在从/path/to/my/code/JMail/IMAP/TLSSocket.h:9包含的文件中:
文件包含自/usr/local/include/boost/asio/ssl.hpp:19:
在从/usr/local/include/boost/asio/ssl/context.hpp:786包含的文件中:
/usr/local/include/boost/asio/ssl/impl/context.ipp:114:31:warning:'TLSv1_client_method'已弃用[-Wdeprecated-declarations]
handle_ = :: SSL_CTX_new(:: TLSv1_client_method ());
^
/usr/local/include/openssl/ssl.h:1558:45:注意:TLSv1_client_method已在此处显式标记为已弃用
DEPRECATEDIN_1_1_0(__ owur const SSL_METHOD * TLSv1_client_method ))/ * TLSv1.0 * /
^
在/path/to/my/code/JMail/IMAP/main.cpp:4中包含的文件中:
在包含/路径/到/ my / code / JMail / IMAP / IMAPClient.h:6:
在从/path/to/my/code/JMail/IMAP/TLSSocket.h:9包含的文件中:
文件包括在/usr/local/include/boost/asio/ssl.hpp:19中:
包含在/usr/local/include/boost/asio/ssl/context.hpp:786中的文件:
/usr/local/include/boost/asio/ssl/impl/context.ipp:117:31:warning:'TLSv1_server_method'已弃用[-Wdeprecated-declarations]
handle_ = :: SSL_CTX_new(:: TLSv1_server_method ());
^
/usr/local/include/openssl/ssl.h:1557:45:注意:'TLSv1_server_method'已在此处显式标记为已弃用
DEPRECATEDIN_1_1_0(__ owur const SSL_METHOD * TLSv1_server_method ))/ * TLSv1.0 * /
^
在/path/to/my/code/JMail/IMAP/main.cpp:4中包含的文件中:
在包含/路径/到/ my / code / JMail / IMAP / IMAPClient.h:6:
在从/path/to/my/code/JMail/IMAP/TLSSocket.h:9包含的文件中:
文件包括在/usr/local/include/boost/asio/ssl.hpp:19中:
包含在/usr/local/include/boost/asio/ssl/context.hpp:786中的文件:
/usr/local/include/boost/asio/ssl/impl/context.ipp:130:31:warning:'TLSv1_1_method'已弃用[-Wdeprecated-declarations]
handle_ = :: SSL_CTX_new(:: TLSv1_1_method ());
^
/usr/local/include/openssl/ssl.h:1562:45:注意:'TLSv1_1_method'已在此处显式标记为已弃用
DEPRECATEDIN_1_1_0(__ owur const SSL_METHOD * TLSv1_1_method ))/ * TLSv1.1 * /
^
在/path/to/my/code/JMail/IMAP/main.cpp:4:
中包含的文件在包含/路径/到/ my / code / JMail / IMAP / IMAPClient.h:6:
在从/path/to/my/code/JMail/IMAP/TLSSocket.h:9包含的文件中:
文件包括在/usr/local/include/boost/asio/ssl.hpp:19中:
包含在/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'已弃用[-Wdeprecated-declarations]
handle_ = :: SSL_CTX_new(:: TLSv1_1_client_method ());
^
/usr/local/include/openssl/ssl.h:1564:45:注意:'TLSv1_1_client_method'已在此处显式标记为已弃用
DEPRECATEDIN_1_1_0(__ owur const SSL_METHOD * TLSv1_1_client_method ))/ * TLSv1.1 * /
^
在/path/to/my/code/JMail/IMAP/main.cpp:4:
中包含的文件在包含/路径/到/ my / code / JMail / IMAP / IMAPClient.h:6:
在从/path/to/my/code/JMail/IMAP/TLSSocket.h:9包含的文件中:
文件包含自/usr/local/include/boost/asio/ssl.hpp:19:
在从/usr/local/include/boost/asio/ssl/context.hpp:786包含的文件中:
/usr/local/include/boost/asio/ssl/impl/context.ipp:136:31:警告:TLSv1_1_server_method已弃用[-Wdeprecated-declarations]
handle_ = :: SSL_CTX_new(:: TLSv1_1_server_method ());
^
/usr/local/include/openssl/ssl.h:1563:45:注意:'TLSv1_1_server_method'已在此处显式标记为已弃用
DEPRECATEDIN_1_1_0(__ owur const SSL_METHOD * TLSv1_1_server_method(void )/ * TLSv1.1 * /
^
在/path/to/my/code/JMail/IMAP/main.cpp:4:
中包含的文件在包含/路径/到/ my / code / JMail / IMAP / IMAPClient.h:6:
在从/path/to/my/code/JMail/IMAP/TLSSocket.h:9包含的文件中:
文件包含自/usr/local/include/boost/asio/ssl.hpp:19:
在从/usr/local/include/boost/asio/ssl/context.hpp:786包含的文件中:
/usr/local/include/boost/asio/ssl/impl/context.ipp:148:31:警告:TLSv1_2_method已弃用[-Wdeprecated-declarations]
handle_ = :: SSL_CTX_new(:: TLSv1_2_method ());
^
/usr/local/include/openssl/ssl.h:1568:45:注意:'TLSv1_2_method'已在此处显式标记为已弃用
DEPRECATEDIN_1_1_0(__ owur const SSL_METHOD * TLSv1_2_method ))/ * TLSv1.2 * /
^
在/path/to/my/code/JMail/IMAP/main.cpp:4:
中包含的文件在包含/路径/到/ my / code / JMail / IMAP / IMAPClient.h:6:
在从/path/to/my/code/JMail/IMAP/TLSSocket.h:9包含的文件中:
文件包括在/usr/local/include/boost/asio/ssl.hpp:19中:
包含在/usr/local/include/boost/asio/ssl/context.hpp:786中的文件:
/usr/local/include/boost/asio/ssl/impl/context.ipp:151:31:警告:TLSv1_2_client_method已弃用[-Wdeprecated-declarations]
handle_ = :: SSL_CTX_new(:: TLSv1_2_client_method ());
^
/usr/local/include/openssl/ssl.h:1570:45:注意:'TLSv1_2_client_method'已在此处显式标记为已弃用
DEPRECATEDIN_1_1_0(__ owur const SSL_METHOD * TLSv1_2_client_method ))/ * TLSv1.2 * /
^
在/path/to/my/code/JMail/IMAP/main.cpp:4:
中包含的文件在包含/路径/到/ my / code / JMail / IMAP / IMAPClient.h:6:
在从/path/to/my/code/JMail/IMAP/TLSSocket.h:9包含的文件中:
文件包括在/usr/local/include/boost/asio/ssl.hpp:19中:
包含在/usr/local/include/boost/asio/ssl/context.hpp:786中的文件:
/usr/local/include/boost/asio/ssl/impl/context.ipp:154:31:警告:TLSv1_2_server_method已弃用[-Wdeprecated-declarations]
handle_ = :: SSL_CTX_new(:: TLSv1_2_server_method ());
^
/usr/local/include/openssl/ssl.h:1569:45:注意:'TLSv1_2_server_method'已在此处显式标记为已弃用
DEPRECATEDIN_1_1_0(__ owur const SSL_METHOD * TLSv1_2_server_method(void ))/ * TLSv1.2 * /
^
在/path/to/my/code/JMail/IMAP/main.cpp:4:
中包含的文件在包含/路径/到/ my / code / JMail / IMAP / IMAPClient.h:6:
在从/path/to/my/code/JMail/IMAP/TLSSocket.h:9包含的文件中:
文件包括在/usr/local/include/boost/asio/ssl.hpp:19中:
包含在/usr/local/include/boost/asio/ssl/context.hpp:786中的文件:
/usr/local/include/boost/asio/ssl/impl/context.ipp:208:16:错误:成员访问不完全类型'SSL_CTX'(aka'ssl_ctx_st')
if(handle _-> default_passwd_callback_userdata)
^
/usr/local/include/openssl/ossl_typ.h:144:16:注意:'ssl_ctx_st'的前向声明
typedef struct ssl_ctx_st SSL_CTX;
^
从/path/to/my/code/JMail/IMAP/main.cpp:4:
中包含的文件在/ path /到/ my / code / JMail中包含的文件/IMAP/IMAPClient.h:6:
在/path/to/my/code/JMail/IMAP/TLSSocket.h:9中包含的文件中:
在包含在/ usr / local / include中的文件中/boost/asio/ssl.hpp:19:
在/usr/local/include/boost/asio/ssl/context.hpp:786中包含的文件中:
/ usr / local / include / boost /asio/ssl/impl/context.ipp:212:20:error:成员访问不完全类型'SSL_CTX'(aka'ssl_ctx_st')
句柄_-> default_passwd_callback_userdata);
^
/usr/local/include/openssl/ossl_typ.h:144:16:note:正向声明'ssl_ctx_st'
typedef struct ssl_ctx_st SSL_CTX;
^
从/path/to/my/code/JMail/IMAP/main.cpp:4:
中包含的文件在/ path /到/ my / code / JMail中包含的文件/IMAP/IMAPClient.h:6:
在/path/to/my/code/JMail/IMAP/TLSSocket.h:9中包含的文件中:
在包含在/ usr / local / include中的文件中/boost/asio/ssl.hpp:19:
在/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:注意:匹配这个'('
static_cast< detail :: password_callback_base *>(
^
/usr/local/include/boost/asio/ssl/impl/context.ipp:214:14:error:成员访问不完全类型'SSL_CTX'(aka'ssl_ctx_st ')
handle _-> default_passwd_callback_userdata = 0;
^
/usr/local/include/openssl/ossl_typ.h:144:16:note:正向声明为'ssl_ctx_st'
typedef struct ssl_ctx_st SSL_CTX;
^
在/path/to/my/code/JMail/IMAP/main.cpp:4中包含的文件中:
在包含在/ path /到/ my / code / JMail / IMAP / IMAPClient.h:6:
在包含在/path/to/my/code/JMail/IMAP/TLSSocket.h:9中的文件中:
在包括的文件中从/usr/local/include/boost/asio/ssl.hpp:19:
在包含在/usr/local/include/boost/asio/ssl/context.hpp:786的文件中:
/ usr / local / include / boost / asio / ssl / impl / context.ipp:551:18:error:成员访问不完全类型'SSL_CTX'(aka'ssl_ctx_st')
handle _-> default_passwd_callback,
^
/usr/local/include/openssl/ossl_typ.h:144:16:note:前缀声明'ssl_ctx_st'
typedef struct ssl_ctx_st SSL_CTX;
^
从/path/to/my/code/JMail/IMAP/main.cpp:4:
中包含的文件在/ path /到/ my / code / JMail中包含的文件/IMAP/IMAPClient.h:6:
在/path/to/my/code/JMail/IMAP/TLSSocket.h:9中包含的文件中:
在包含在/ usr / local / include中的文件中/boost/asio/ssl.hpp:19:
在/usr/local/include/boost/asio/ssl/context.hpp:786中包含的文件中:
/ usr / local / include / boost /asio/ssl/impl/context.ipp:552:18:error:成员访问不完全类型'SSL_CTX'(aka'ssl_ctx_st')
句柄_-> default_passwd_callback_userdata}};
^
/usr/local/include/openssl/ossl_typ.h:144:16:note:正向声明'ssl_ctx_st'
typedef struct ssl_ctx_st SSL_CTX;
^
致命错误:发出的错误太多,现在停止[-ferror-limit =]
生成了10个警告和20个错误。

引用的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解析器(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\\\
;

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

for(;;){
boost :: array< char,128>缓冲;
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){
尝试{
mSocket-> async_handshake(boost :: asio :: ssl :: stream_base :: handshake_type :: client,
boost :: bind(& TLSSocket :: on_handshake,this,boost :: asio :: placeholder :: error));
} catch(std :: exception ex){
std :: cout< 握手错误:< ex.what()<< \\\
;
}
} else {
std :: cout<< 连接错误:< error.message()<< \\\
;
}
}

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

} else {
std :: cout<< 握手错误:< error.message()<< \\\
;
}
}

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<< 验证< subject_name<< \\\
;

return verified;
}



看起来对我来说,甚至连连接阶段编译,它只是试图使我的main.cpp的.o文件。如果我在我的IDE中打开它抱怨的文件之一,IDE会给我一个语法错误突出显示,但我很遗憾为什么。



把包含在错误的顺序?我的CMAKE文件有问题吗?我是否错误地构建了OpenSSL或Boost?



任何帮助都将不胜感激。我已经工作了这个开关了几个星期,并且花了大部分时间只是让它构建(C ++第1课,我猜:))。

解决方案

这看起来像我一样Boost没有更新使用OpenSSL 1.1.0。在OpenSSL 1.0.2和1.1.0之间已经有一些API更改,它们不是完全源兼容的。我建议你使用1.0.2,直到Boost已更新为使用新的OpenSSL版本(仍然是测试版)。


I am currently working on a C++ IMAP library so that I can improve on some admittedly rusty C++ skills. I would like to make the library as portable as possible so that I can use it across OS's and, if I'm feeling crazy, maybe even on a mobile device. To that end, I've done some research and decided to use Boost's Asio library.

I was able to get Boost to build and run in my project by itself. I event made a simple HTTP GET to google.com. Unfortunately, I need to be able to communicate using TLS and I've run into issues trying to use Asio's SSL functionality.

I built both Boost and OpenSSL from source, using default settings (so everything is in /usr/local). I am also using CMAKE to build my project. Below is my CMAKE file:

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})

And this is the output of my CMAKE messages:

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

When I try to build the project I receive the following pile of errors:

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. 

The TLSSocket class that is being referenced is basically just a wrapper around the Boost Asio SSL example:

#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;
}

It looks to me like it isn't even getting to the linking stage of compilation, it's just trying to make the .o file for my main.cpp. If I open one of the files that it complains about in my IDE, the IDE gives me a syntax error highlight, but I'm stumped as to why.

Did I put the includes in the wrong order? Is there an issue with my CMAKE file? Did I build OpenSSL or Boost incorrectly?

Any help would be appreciated. I've been working on this on and off for a couple of weeks and have spent the majority of that time just getting it to build (C++ Lesson 1, I guess :)).

解决方案

This looks to me like Boost has not been updated to work with OpenSSL 1.1.0. There have been a number of API changes between OpenSSL 1.0.2 and 1.1.0 and they are not fully source compatible. I suggest you use 1.0.2 until Boost has been updated to work with the new OpenSSL version (which is still in beta anyway).

这篇关于Boost Asio和OpenSSL 1.1.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆