运行异常升压ASIO例如SSL [英] Exception running boost asio ssl example

查看:170
本文介绍了运行异常升压ASIO例如SSL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行自boost :: ASIO的SSL例子,我得到一个无效参数的例外,当我运行它们。我在Linux x86_64的。

I'm trying to run the SSL examples from boost::asio and I'm getting an "Invalid argument" exception when I run them. I'm on Linux x86_64.

<一个href=\"http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/example/ssl/client.cpp\">http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/example/ssl/client.cpp

<一个href=\"http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/example/ssl/server.cpp\">http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/example/ssl/server.cpp

与编译:

g++ server.cpp -o server -lboost_system -lssl
g++ client.cpp -o client -lboost_system -lssl

样运行:

$ ./server 
Usage: server <port>
$ ./server 10000
Exception: Invalid argument
$ ./server 1000
Exception: Permission denied
$ sudo ./server 1000
Exception: Invalid argument

不知道是什么问题:(
任何帮助将大大AP preciated。

Not sure what the problem is :( Any help would be greatly appreciated.

谢谢!

推荐答案

确定,任何人在将来发现这一点,你需要创建你的证书和适当的签字。
下面是命令对于Linux:

OK, for anyone finding this in the future, you need to create your certificates and sign them appropriately. Here are the commands for linux:

//生成私钥

openssl genrsa -des3 -out server.key 1024

//生成证书签名请求

//Generate Certificate signing request

openssl req -new -key server.key -out server.csr

//使用私钥证书登录

//Sign certificate with private key

openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt

//删除密码要求(需要为例)

//Remove password requirement (needed for example)

cp server.key server.key.secure
openssl rsa -in server.key.secure -out server.key

//生成dhparam文件

//Generate dhparam file

openssl dhparam -out dh512.pem 512

一旦你做到了这一点,您需要更改文件名中server.cpp和client.cpp。

Once you've done that, you need to change the filenames in server.cpp and client.cpp.

server.cpp

server.cpp

context_.use_certificate_chain_file("server.crt"); 
context_.use_private_key_file("server.key", boost::asio::ssl::context::pem);
context_.use_tmp_dh_file("dh512.pem");

client.cpp

client.cpp

ctx.load_verify_file("server.crt");

那么它应该所有的工作!

Then it should all work!

这篇关于运行异常升压ASIO例如SSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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