简体   繁体   English

使用openssl以编程方式查找已协商的TLS版本

[英]Find programmatically using openssl which TLS version was negociated

I'm using openssl in a non web application to commute a socket to TLS (STARTTLS protocol). 我在非Web应用程序中使用openssl将套接字转换为TLS(STARTTLS协议)。 Everything works fine, but I would also like to know which version of TLS among the allowed ones was actually negociated. 一切正常,但是我也想知道实际上已协商了允许的TLS版本。

Is there any way to find this information using openssl API ? 有什么办法可以使用openssl API查找此信息?

Note: with openssl 1.1 and later the information is likely returned by the function SSL_SESSION_get_protocol_version() but I need to also find this information for previous openssl library versions (code in the wild, performing a major update of openssl for mere logging purpose is not an option). 注意:在openssl 1.1及更高版本中,信息可能由函数SSL_SESSION_get_protocol_version()返回,但我还需要查找以前的openssl库版本的信息(在野外代码中,仅出于记录目的而对openssl进行重大更新不是选项)。

You can use SSL_get_version() : 您可以使用SSL_get_version()

SSL_get_version() returns the name of the protocol used for the connection ssl . SSL_get_version()返回用于连接ssl的协议的名称。 It should only be called after the initial handshake has been completed. 仅应在初始握手完成后调用它。 Prior to that the results returned from this function may be unreliable. 在此之前,从该函数返回的结果可能不可靠。

RETURN VALUES 返回值

The following strings can be returned: 可以返回以下字符串:

SSLv2 SSLv2
The connection uses the SSLv2 protocol. 连接使用SSLv2协议。

SSLv3 SSLv3
The connection uses the SSLv3 protocol. 连接使用SSLv3协议。

TLSv1 TLSv1
The connection uses the TLSv1.0 protocol. 连接使用TLSv1.0协议。

TLSv1.1 TLSv1.1
The connection uses the TLSv1.1 protocol. 连接使用TLSv1.1协议。

TLSv1.2 TLSv1.2
The connection uses the TLSv1.2 protocol. 连接使用TLSv1.2协议。

unknown 未知
This indicates an unknown protocol version. 这表示未知的协议版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM