SSL_accept() 抛出“无效参数”错误

发布于 2024-09-17 19:40:32 字数 582 浏览 2 评论 0原文

我正在尝试创建一个客户端/服务器程序,但我发现继续处理数量稀少的 OpenSSL 文档有些困难。

我的问题: SSL_accept 在执行以下代码(简化)时抛出“无效参数”:

SSL* ssl = SSL_new(ctx); // ctx is created earlier
SSL_set_fd(ssl, socket); // socket is created earlier as well
BIO * bio = BIO_new(BIO_s_accept());
BIO_set_fd(bio, socket, BIO_NOCLOSE);
SSL_set_bio(ssl, bio, bio);
SSL_accept(ssl); 

我在每次方法调用后检查错误,并且套接字和生物都没有变坏。在我尝试调用 SSL_accept 之前,没有任何迹象表明发生了任何奇怪的情况。我假设 ssl 对象在途中的某个地方被损坏,但我不知道如何〜

编辑 SSL 对象和 BIO 对象为空在调用 SSL_accept() 时。

任何正确方向的指针将不胜感激:D

I'm attempting to create a client/server program, but I'm finding some difficulty continuing with the unfortunately sparse amount of OpenSSL documentation.

My issue:
SSL_accept throws an "Invalid Argument" upon executing the following code (simplified):

SSL* ssl = SSL_new(ctx); // ctx is created earlier
SSL_set_fd(ssl, socket); // socket is created earlier as well
BIO * bio = BIO_new(BIO_s_accept());
BIO_set_fd(bio, socket, BIO_NOCLOSE);
SSL_set_bio(ssl, bio, bio);
SSL_accept(ssl); 

I check errors after each method call, and the neither the socket nor the bio goes bad. There's no indication that anything odd is happening until I attempt calling SSL_accept. I assume that the ssl object was corrupted somewhere along the way, but I don't have a clue as to how~

Edit The SSL object and the BIO object are not null at the point of calling SSL_accept().

Any pointers in the right direction would be greatly appreciated :D

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

智商已欠费 2024-09-24 19:40:33

SSL_set_fd() 旨在作为手动设置 BIO 的便捷替代方法。它会自动创建 BIO 并进行设置 - 所以您需要做的就是:

SSL* ssl = SSL_new(ctx);
SSL_set_fd(ssl, socket);
SSL_accept(ssl); 

SSL_set_fd() is meant as a convenient alternative to manually setting up the BIOs. It automatically creates a BIO and sets it up - so all you need to do is:

SSL* ssl = SSL_new(ctx);
SSL_set_fd(ssl, socket);
SSL_accept(ssl); 
粉红×色少女 2024-09-24 19:40:33

和你一样,我也因缺乏文档而经历了一段困难时期。所以我不能说 set_fd 调用是错误还是正确,但我在没有这些调用的情况下也能正常工作。我成功使用的调用顺序是:

BIO *sbio = BIO_new_socket( socket, BIO_NOCLOSE );
SSL* ssl = SSL_new(ctx); 
SSL_set_bio( ssl, sbio, sbio );
SSL_accept( ssl );

Like you, I have had a difficult time with the dearth of documentation. So I can't say whether or not the set_fd calls are wrong or right, but I got it working without those. The sequence of calls that I have used successfully is:

BIO *sbio = BIO_new_socket( socket, BIO_NOCLOSE );
SSL* ssl = SSL_new(ctx); 
SSL_set_bio( ssl, sbio, sbio );
SSL_accept( ssl );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文