使用 OpenSSL 将现有的 TCP 套接字转换为 TLS [英] Convert existing TCP socket into TLS using OpenSSL

查看:76
本文介绍了使用 OpenSSL 将现有的 TCP 套接字转换为 TLS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些关于 OpenSSL、TLS 套接字的信息.首先,我想通过 TCP 上的 TLS 与服务器建立连接.一般先创建一个 TCP 套接字,然后使用 TCP 套接字连接到服务器,然后(在通过 TCP 套接字发送或接收任何数据之前)将 TCP 套接字转换为 TLS.

I need some information about OpenSSL, TLS socket. First of i want to made a connection with server through TLS over TCP. Generally first create a TCP socket, then connect to server using the TCP socket, after that convert(before send or receive any data through TCP socket) the TCP socket into TLS.

我的问题是可以按照以下方式吗?

My question is is it possible according to following way?

  1. 创建 TCP 套接字.

  1. Create TCP socket.

使用 TCP 套接字连接服务器.

Connect with server using TCP socket.

通过 TCP 套接字发送和接收一些数据.

Send and receive some data through TCP socket.

然后将 TCP 套接字转换为 TLS.

Then convert the TCP socket into TLS.

注意:我使用的是 OpenSSL.

Note: I am using OpenSSL.

推荐答案

如果服务器必须支持它,那么以给定的方式似乎是可能的.请参阅 SMTP.它以这种方式适用于 SMTP 服务器,其中前几个对话是普通 TCP 然后是 SSL/TLS.您可以使用 BIO_new_socket 将现有套接字绑定到 BIO,然后使用 SSL_set_bio 将此套接字设置为 SSL * 结构.

It seems possible in the given way provided that the server must support it. See SMTP. It works in this way for SMTP server where first few conversation is in plain TCP then over SSL/TLS. You can bind an existing socket to a BIO using BIO_new_socket and then set this socket to SSL * structure using SSL_set_bio.

您可以找到许多 SSL 客户端示例.

You can find many examples of SSL client.

这篇关于使用 OpenSSL 将现有的 TCP 套接字转换为 TLS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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