运行 boost asio ssl 示例时出现异常
我正在尝试从 boost::asio 运行 SSL 示例,但在运行它们时出现“无效参数”异常。我在 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
不确定问题是什么:( 任何帮助将不胜感激。
谢谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
好的,对于将来发现此问题的任何人,您需要创建证书并对其进行适当的签名。
以下是 Linux 的命令:
//生成私钥
//生成证书签名请求
//使用私钥签署证书
//删除密码要求(例如需要)
//生成 dhparam 文件
完成后,您需要更改 server.cpp 和 client.cpp 中的文件名。
server.cpp
client.cpp
那么它应该一切正常!
OK, for anyone finding this in the future, you need to create your certificates and sign them appropriately.
Here are the commands for linux:
//Generate a private key
//Generate Certificate signing request
//Sign certificate with private key
//Remove password requirement (needed for example)
//Generate dhparam file
Once you've done that, you need to change the filenames in server.cpp and client.cpp.
server.cpp
client.cpp
Then it should all work!
使用 strace 再次执行测试以查看哪个系统调用获得 EINVAL,作为奖励,您将看到失败调用的参数。这可能是安全上下文设置失败的一部分,除非您拥有示例中的正确文件和数据:
您收到
EPERM
因为您试图绑定到特权 TCP 端口(其值为小于 1024)。这就是./server 10000
无法获取EPERM
的原因。Execute the tests again with strace to see which syscall gets the
EINVAL
, as a bonus you'll get to see the args for the failing call. It's likely part of the security context setup that's failing, unless you have the right files and data from the example:You were getting
EPERM
because you were trying to bind to a privileged TCP port (one whose value is less than 1024). That's why./server 10000
does not getEPERM
.当遵循 @Shootfast 的答案时,出现错误:“错误的 SSL 配置:use_certificate_chain_file:ee 密钥太小”
更改第一个行:
至:
为我修好了。
之后,我收到错误:“错误的 SSL 配置:use_private_key_file:无起始行”,原因和解决方案如下所述:解决方案< /a> (这或多或少是@Shootfast 答案。)
When following the answer of @Shootfast an error appered: 'bad SSL configuration: use_certificate_chain_file: ee key too small'
Changing the first line:
to:
fixed it for me.
After that I got the error: 'bad SSL configuration: use_private_key_file: no start line' the reason and solution to this is explained here: solution (It is more or less the reason for the last command of @Shootfast answer.)
对于未来的读者;对于遇到连接问题的人(例如客户端意外关闭):请确保在客户端 ssl 套接字上设置主机名:
For future readers; and for people running into connection problems (e.g. unexpected close on client): make sure to set the host name on the client ssl socket: