openssl查询使用情况
我正在尝试在我的应用程序中使用 OpenSSL,并实现安全连接。
起初我尝试:
- create ssl struct
- create socketbio for the tcp socket
- create a sslbio
- set socketbio to SSL strcut
SSL_accept(ssl)
BIO_push(ssl, socketbio)
这会导致握手成功发生,但应用程序数据未正确解密。
然后我稍微调整了一下,将 6 替换为 6
(new) BIO_ctrl(sslbio, SET_SSL, ssl)
,一切正常。
我想知道,以前的方法有什么问题,是什么导致新的方法起作用?
I am trying to use OpenSSL in my application, and achieve a secure connection.
At first I tried:
- create ssl struct
- create socketbio for the tcp socket
- create a sslbio
- set socketbio to SSL strcut
SSL_accept(ssl)
BIO_push(ssl, socketbio)
This cause handshake to happen successfully, but application data wasn't properly decrypted.
Then I tweaked a little, and relaced 6 with
(new) BIO_ctrl(sslbio, SET_SSL, ssl)
and things worked fine.
I Wanted to know, what's wrong with previous approach, and what's causing the new apprach work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果不知道为什么您认为
BIO_push
就是您需要做的一切,就很难回答这个问题。无论如何,您不应该直接调用BIO_ctrl
。您应该使用bio.h
中定义的高级包装器BIO_set_ssl
:该宏设置 BIO 对象的 ssl 成员,如您在
bio_ssl.c 中看到的那样
:此函数中的重要步骤不是
BIO_push
,而是它将BIO_SSL
对象中的 ssl 指针设置为您的活动SSL 上下文,即((BIO_SSL *)b->ptr)->ssl=ssl;
。It's hard to answer the question without knowing why you think
BIO_push
is all you need to do. At any rate, you shouldn't callBIO_ctrl
directly. You should use the high-level wrapperBIO_set_ssl
defined inbio.h
:This macro sets the ssl member of the BIO object as you can see in
bio_ssl.c
:The important step in this function is not the
BIO_push
, but rather is where it sets the ssl pointer in theBIO_SSL
object to your active SSL context, i.e.,((BIO_SSL *)b->ptr)->ssl=ssl;
.