我想为我的项目使用 openSSL 1.1.1 设置和运行带有 TLS 1.2 的 SSL 客户端和服务器。
我对 openSSL 有一些疑问和/或要求:
最佳答案
what is the right way to select TLS 1.2 as version? Currently I am using TLS_client_method(). the other methods seem to be deprecated. Is there a specific API for choosing particular version?
TLS_client_method()
是正确的使用方法。要指定不使用低于 TLSv1.2 的版本,您应该这样做:SSL_CTX_set_min_proto_version(ctx, TLS1_2_VERSION);
在哪里 ctx
是你的SSL_CTX
目的。如果您还想防止使用高于 TLSv1.2 的任何内容,请执行以下操作:
SSL_CTX_set_max_proto_version(ctx, TLS1_2_VERSION);
有关这些调用的信息,请参阅此页面:https://www.openssl.org/docs/man1.1.1/man3/SSL_CTX_set_min_proto_version.html
I need to run an SSL clinet with following handshake extensions.
- ec_point_formats with "uncompressed" as value
- supported_groups with list of "secp521r","secp384r1","secp256r1","secp224r1","secp192r1","secp160r1","ffdhe2048"
如果您指定了您选择的 PSK 密码套件,则不会使用这些扩展,因此 OpenSSL 不会发送它们(假设您已如上所述限制了最大 TLS 协议(protocol)版本,并且仅配置了该密码套件)。这样做是没有意义的。即使支持,OpenSSL 1.1.1 也不支持“ffdhe2048”。它确实支持所有其他人。
- encrypt_then_mac with value 0
不确定您所说的“值为 0”是什么意思,因为此扩展名始终为空且没有任何值(value)。我假设你的意思是长度为 0。这个扩展是默认发送的,所以你不需要做任何事情。
- server_name
您应该调用:
SSL_set_tlsext_host_name(ssl, "hostname of the server");
在哪里 ssl
是你的SSL
对象,并将“服务器的主机名”替换为服务器的真实主机名。有关此调用的信息,请参阅此页面:
https://www.openssl.org/docs/man1.1.1/man3/SSL_set_tlsext_host_name.html
- extended_master_secret without any value and length set to 0
默认情况下会发送此扩展程序,因此您无需执行任何操作。
I need to run an SSL server with following handshake extensions
- encrypt_then_mac with value 0
- extended_master_secret without any value and length set to 0
如果客户端发送了它们,那么服务器将默认回显它们。你不需要做任何事情。
Apart from above header extension fields I want to disable everything else. How to accomplish that?
OpenSSL 客户端将另外发送
session_ticket
扩大。它是无害的,但如果你真的想禁用它,你可以这样做:SSL_CTX_set_options(ctx, SSL_OP_NO_TICKET);
有关详细信息,请参阅此页面:https://www.openssl.org/docs/man1.1.1/man3/SSL_CTX_set_options.html
OpenSSL 服务器将另外发送“重新协商”扩展。你不能禁用它(事实上你不能)。忽略它。它无害。
From client I want to provide only "TLS_PSK_WITH_AES_128_CBC_SHA256" cipher suite as option.
这是密码套件的官方 IANA 名称。 OpenSSL 将其称为“PSK-AES128-CBC-SHA256”。
像这样在客户端和服务器上配置它:
SSL_CTX_set_cipher_list(ctx, "PSK-AES128-CBC-SHA256");
有关详细信息,请参阅此页面:https://www.openssl.org/docs/man1.1.1/man3/SSL_CTX_set_cipher_list.html
此外,您将需要提供 PSK 回调来告诉 OpenSSL 您要使用的 PSK 是什么。
在客户端上,您需要调用
SSL_CTX_set_psk_client_callback()
.在服务器上,您必须调用 SSL_CTX_set_psk_server_callback()
.有关详细信息,请参阅这些页面:
https://www.openssl.org/docs/man1.1.1/man3/SSL_CTX_set_psk_client_callback.html
https://www.openssl.org/docs/man1.1.1/man3/SSL_CTX_set_psk_server_callback.html
TLSv1.3 密码套件仍将自动发送,除非您如上所述另外将最大 TLS 协议(protocol)版本限制为 TLSv1.2。最后,您还将看到一个名为“TLS_EMPTY_RENEGOTIATION_INFO_SCSV”的密码套件正在发送。这实际上根本不是真正的密码套件。它总是被发送并且不能被抑制。它永远不会被谈判并且是无害的。忽略它。
Is client certificate and key files (pem) necessary for successful connection establishment and communication when PSK cipher is used?
不。
Is there any example or open source client-server implementation with PSK authentication?
你可以看看 s_client 和 s_server 是怎么做的:
https://github.com/openssl/openssl/blob/OpenSSL_1_1_1-stable/apps/s_client.c
https://github.com/openssl/openssl/blob/OpenSSL_1_1_1-stable/apps/s_server.c
关于ssl - openSSL 1.1.1 API 疑点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67921680/