异常运行 boost asio ssl 示例 [英] Exception running boost asio ssl example

查看:25
本文介绍了异常运行 boost 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.

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/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

不知道是什么问题:(任何帮助将不胜感激.

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

//生成证书签名请求

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

//用私钥签署证书

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

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

ctx.load_verify_file("server.crt");

那么它应该一切正常!

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

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