提高ASIO SSL async_write送我大多胡言乱语 [英] boost asio ssl async_write send me mostly gibberish

查看:347
本文介绍了提高ASIO SSL async_write送我大多胡言乱语的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的非安全套接字转换为SSL,使用boost过程:: ASIO :: SSL

尽管一切工作正常与非SSL,async_write送我主要是胡言乱语。

有趣的是,当我把睡眠(1)每async_write之间,我得到的大多是不错的数据,有一点胡言乱语(类似的东西????? @ ??)

我发送的数据是得到最多的胡言乱语......我完全失去了对这个问题!更快

initSSLConnection:

 的boost ::支持ASIO :: SSL ::中* m_context =新的boost ::支持ASIO :: SSL ::上下文(m_acceptor.io_service(),提振:: ASIO :: SSL ::背景:: sslv23);
 m_context-> set_options(升压:: ASIO :: SSL ::环境:: default_workarounds
                       |提高:: ASIO :: SSL ::环境:: no_sslv2
                       |提高:: ASIO :: SSL ::背景:: single_dh_use);
 m_context-> set_password_callback(的boost ::绑定(安培;服务器:: get_password,这一点));
 m_context-> use_certificate_chain_file(./ ssl_key / cert.pem);
 m_context-> use_private_key_file(./ ssl_key / key.pem,提高:: ASIO :: SSL ::背景:: PEM);

Socket的写:

 而(1){
提高:: ASIO :: async_write(m_socket,
                          提高:: ASIO ::缓​​冲区(ss.str()。c_str(),ss.str()。大小()),
                          提高::绑定(放大器; MyClass的:: done_writing,
                                      shared_from_this())
                          );
}

下面是我得到的时候我不把睡眠(1):

<$p$p><$c$c>`?D`?@?pR???c??_?@?pR??c?@?pR??␌?@???␌?D◆?P0AE0004J0??@?⎻RP0AE0004J0??@?XJ┘?D◆?P0AE0004J0??X?┬±?> ␋┌≤C5700␌??┬±??&GT; ␋┌≤C5700␌?????┐&GT?; ␋┌≤C5700␌?????????┬±??┐?                       ?┴^&GT?; ␋┌≤C5700␌?                                           ?┴^^&GT; ␋┌≤C5700␌?????                                                                      ?┴&GT; ␋┌≤C5700␌·V
          ?? @             ?┴&GT; ␋┌≤C◆????␋┌≤F1DA0?│?ADO14F⎼␋??? @?⎻R
                                                           ? ␋┌≤D9A90?┌?┬±?                                                                              ?┴?┬±?    ?┴??┐?ADO14F⎼␋⎻?? @?⎻R?

 6A7BD600?≠?┌?◆????␋┌≤21ADC?├?

◆????␋┌≤21ADC?├?
◆????␋┌≤21ADC?├??◆????␋┌≤21ADC?├?

这似乎是恩codeD或东西...

我通过这个命令行连接到服务器:

 的OpenSSL的s_client.First -ssl3 -connect 127.0.0.1:4242


解决方案

的问题是,你写交错..

 而(1){
提高:: ASIO :: async_write(m_socket,
                          提高:: ASIO ::缓​​冲区(ss.str()。c_str(),ss.str()。大小()),
                          提高::绑定(放大器; MyClass的:: done_writing,
                                      shared_from_this())
                          );
}

您只能做下 async_write ,一旦第一个完成 - 即在 done_writing 处理程序。这就是为什么你废话,你赚更多的来电......

I'm in the process of converting my non secure socket to ssl, using boost::asio::ssl

While everything was working fine with non-ssl, async_write send me mostly gibberish.

The funny thing is when I put a sleep(1) between every async_write, I get mostly good data, with a little gibberish (something like that "?????@??" )

The faster I send data the most gibberish it gets... I'm completely lost on this problem !

initSSLConnection :

boost::asio::ssl::context *m_context = new boost::asio::ssl::context(m_acceptor.io_service(), boost::asio::ssl::context::sslv23);
 m_context->set_options(boost::asio::ssl::context::default_workarounds
                       | boost::asio::ssl::context::no_sslv2
                       | boost::asio::ssl::context::single_dh_use);
 m_context->set_password_callback(boost::bind(&Server::get_password, this));
 m_context->use_certificate_chain_file("./ssl_key/cert.pem");
 m_context->use_private_key_file("./ssl_key/key.pem", boost::asio::ssl::context::pem);

write on Socket :

while (1) {
boost::asio::async_write(m_socket,                                              
                          boost::asio::buffer(ss.str().c_str(), ss.str().size()),
                          boost::bind(&MyClass::done_writing,                        
                                      shared_from_this())
                          );
}

Here's what I get when I do not put sleep(1) :

`?D`?@?pR???c??_?@?pR??c?@?pR??␌?@???␌?D◆?P0AE0004J0??@?⎻RP0AE0004J0??@?XJ┘?D◆?P0AE0004J0??X?┬±?>   ␋┌≤C5700␌??┬±??>    ␋┌≤C5700␌?????┐?>   ␋┌≤C5700␌?????????┬±??┐?

                       ?┴?^>    ␋┌≤C5700␌??

                                           ?┴?^^>   ␋┌≤C5700␌?????

                                                                      ?┴?>  ␋┌≤C5700␌?V
          ??@

             ?┴?>   ␋┌≤C◆????␋┌≤F1DA0?│?ADO14F⎼␋???@?⎻R
                                                           ?    ␋┌≤D9A90?┌?┬±?

                                                                              ?┴?┬±?

    ?┴??┐?ADO14F⎼␋⎻??@?⎻R?
?
 6A7BD600?≠??┌?◆????␋┌≤21ADC?├???
␉
◆????␋┌≤21ADC?├???
◆????␋┌≤21ADC?├??◆????␋┌≤21ADC?├??

It seems that it is encoded or something...

I connect to the server via this command line :

openssl s_client -ssl3 -connect 127.0.0.1:4242 

解决方案

The problem is that you are interleaving writes..

while (1) {
boost::asio::async_write(m_socket,                                              
                          boost::asio::buffer(ss.str().c_str(), ss.str().size()),
                          boost::bind(&MyClass::done_writing,                        
                                      shared_from_this())
                          );
}

You should only do the next async_write, once the first one completes - i.e. in the done_writing handler. This is why you get crap as you make more calls...

这篇关于提高ASIO SSL async_write送我大多胡言乱语的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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