OpenSSL DTLSv1_listen:服务器无法从客户端获取消息

发布于 2024-11-03 08:17:17 字数 1694 浏览 6 评论 0原文

我有一个大问题!我需要你的帮助!请帮我!

我在网上找到了一个DTLS实现的例子,它的名字叫dtls_udp_echo.c。 我在函数中有以下代码来描述服务器的行为:

 memset(&client_addr, 0, sizeof(struct sockaddr_storage));


    /* 创建生物 */

    生物 = BIO_new_dgram(fd, BIO_NOCLOSE);


    /* 设置并激活超时 */

    超时.tv_sec = 5;

    超时.tv_usec = 0;

    BIO_ctrl(bio, BIO_CTRL_DGRAM_SET_RECV_TIMEOUT, 0, &超时);


    ssl = SSL_new(ctx);

    计算<< “ssl 是”<< SSL ;

    printf("ssl 是 \n");

    SSL_set_bio(ssl,bio,bio);

    SSL_set_options(ssl, SSL_OP_COOKIE_EXCHANGE);


    while (DTLSv1_listen(ssl, &client_addr) <= 0){

        //printf("%d\n",DTLSv1_listen(ssl, &client_addr));

    }

    info = (struct pass_info*) malloc (sizeof(struct pass_info));

    memcpy(&info->server_addr, &ser​​ver_addr, sizeof(struct sockaddr_storage));

    memcpy(&info->client_addr, &client_addr, sizeof(struct sockaddr_storage));

    信息->ssl = ssl;

    if (pthread_create( &tid, NULL, connection_handle, info) != 0) {

        perror(“pthread_create”);

        退出(-1);

    }

}

THREAD_cleanup();

我已经创建了客户端,它已向服务器发送了一条消息。使用 TCPDUMP 我可以看到该数据包

60. 250026 IP (tos 0x0, ttl 64, id 59389, offset 0, flags [DF], proto UDP (17), length 104) 127.0.0.1.8001 > 127.0.0.1.8000: UDP, length 76

在哪里:

127.0.0.1 port 8001 - client
127.0.0.1 port 8000 - server 

但服务器似乎是盲目的,它没有将握手发送回客户端。 我相信地址是正确的,因为当我在实验期间更改它们时,客户端无法向服务器发送握手,并且出现错误:

SSL_connect: Connection refused
error:00000000:lib(0):func(0):reason(0)

我的 openSSL 版本是 1.0.0d

谢谢你,朋友,你尝试帮助我!

I have a huge problem! And I need your help! Please help me!

I have found an example of DTLS implementation in the Internet, it is called dtls_udp_echo.c.
And I have the following code in function which describes behavior of server:

    memset(&client_addr, 0, sizeof(struct sockaddr_storage));


    /* Create BIO */

    bio = BIO_new_dgram(fd, BIO_NOCLOSE);


    /* Set and activate timeouts */

    timeout.tv_sec = 5;

    timeout.tv_usec = 0;

    BIO_ctrl(bio, BIO_CTRL_DGRAM_SET_RECV_TIMEOUT, 0, &timeout);


    ssl = SSL_new(ctx);

    cout << "ssl is" << ssl ;

    printf("ssl is \n");

    SSL_set_bio(ssl, bio, bio);

    SSL_set_options(ssl, SSL_OP_COOKIE_EXCHANGE);


    while (DTLSv1_listen(ssl, &client_addr) <= 0){

        //printf("%d\n",DTLSv1_listen(ssl, &client_addr));

    }

    info = (struct pass_info*) malloc (sizeof(struct pass_info));

    memcpy(&info->server_addr, &server_addr, sizeof(struct sockaddr_storage));

    memcpy(&info->client_addr, &client_addr, sizeof(struct sockaddr_storage));

    info->ssl = ssl;

    if (pthread_create( &tid, NULL, connection_handle, info) != 0) {

        perror("pthread_create");

        exit(-1);

    }

}

THREAD_cleanup();

I've created client and it've sent a message to server. Using TCPDUMP I can see that packet

60. 250026 IP (tos 0x0, ttl 64, id 59389, offset 0, flags [DF], proto UDP (17), length 104) 127.0.0.1.8001 > 127.0.0.1.8000: UDP, length 76

where:

127.0.0.1 port 8001 - client
127.0.0.1 port 8000 - server 

But server seems to be blind and it does not sent a handshake back to client.
I believe addresses are correct because when I during experiments changed them client didn't manage to send a handshake to server and there was an error:

SSL_connect: Connection refused
error:00000000:lib(0):func(0):reason(0)

My openSSL's version is 1.0.0d

Thank you, friend for you try to help me!

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

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

发布评论

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

评论(1

冷默言语 2024-11-10 08:17:18

很难确切地说出您的问题是什么,但有一些想法可能会帮助您进行搜索。

设置消息和信息回调,info_cb 和 msg_cb 是您必须提供的函数:

SSL_set_info_callback(ssl, info_cb);
SSL_set_msg_callback(ssl, msg_cb);

DTLSv1_listen 是否返回?在这种情况下,它返回什么?

您还可以调用

SSL_state_string_long(ssl)

That 返回 ssl 当前状态的描述。

如果您使用的是 Windows,则您引用的示例不起作用,因为 Windows 不会按照示例的预期处理绑定到相同地址和端口的多个 UDP 套接字。要解决此问题,请参阅 http://www.net-snmp.org/ wiki/index.php/DTLS_Implementation_Notes

It is hard to say exactly what your problem is, but a couple of ideas that might help you search.

Set message and info callbacks, info_cb and msg_cb are functions you have to provide:

SSL_set_info_callback(ssl, info_cb);
SSL_set_msg_callback(ssl, msg_cb);

Does DTLSv1_listen ever return? In that case, what does it return?

You can also call

SSL_state_string_long(ssl)

That returns a description of the current state of ssl.

If you are on Windows, the examples you refer to doesn't work since Windows does not handle multiple UDP sockets bound to the same address and port as expected by the examples. To work around that, please see http://www.net-snmp.org/wiki/index.php/DTLS_Implementation_Notes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文