Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NTLS允许设置security level和proto version #310

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions ssl/ssl_cert.c
Original file line number Diff line number Diff line change
Expand Up @@ -1080,9 +1080,21 @@ static int ssl_security_default_callback(const SSL *s, const SSL_CTX *ctx,
case SSL_SECOP_VERSION:
if (!SSL_IS_DTLS(s)) {
#ifndef OPENSSL_NO_NTLS
/* NTLS v1.1 not allowed at level 3 */
if (nid == NTLS_VERSION && level >= 3)
return 0;

/*-
yangboyd marked this conversation as resolved.
Show resolved Hide resolved
* NTLS v1.1 not suitable for above level 3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

就把这一行注释留下就行,其他没必要,删除吧

* https://www.openssl.org/docs/man1.1.1/man3/SSL_CTX_set_security_level.html
* level 3: Security level set to 128 bits of security.
* As a result RSA, DSA and DH keys shorter than 3072 bits and ECC
* keys shorter than 256 bits are prohibited. In addition to the
* level 2 exclusions cipher suites not offering forward secrecy are
* prohibited. TLS versions below 1.1 are not permitted.
* Session tickets are disabled.
*/
if (nid == NTLS_VERSION) {
return level > 3 ? 0 : 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我理解level >= 3返回0

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对于NTLS国密协议,level >3返回0; level<=3是适合的,所以返回1. 因为level 3要求ECC密钥至少256位,而国密SSL证书的sm2采用256位密码长度,加密强度等同于3072位RSA证书,所以NTLS1.1满足SSL安全等级level 3的要求。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

当前的TLCP 1.1并不支持前项安全。

}

#endif
/* SSLv3 not allowed at level 2 */
if (nid <= SSL3_VERSION && level >= 2)
Expand Down
4 changes: 4 additions & 0 deletions ssl/statem/statem_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1770,7 +1770,11 @@ int ssl_set_version_bound(int method_version, int version, int *bound)
return 1;
}

#ifndef OPENSSL_NO_NTLS
valid_tls = version >= NTLS1_1_VERSION && version <= TLS_MAX_VERSION_INTERNAL;
#else
valid_tls = version >= SSL3_VERSION && version <= TLS_MAX_VERSION_INTERNAL;
#endif
valid_dtls =
DTLS_VERSION_LE(version, DTLS_MAX_VERSION_INTERNAL) &&
DTLS_VERSION_GE(version, DTLS1_BAD_VER);
Expand Down
4 changes: 4 additions & 0 deletions test/ssl_ntls_api_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,10 @@ static int test_ntls_ssl_set_cert_pkey_api(int i)
if (!TEST_true(ssl != NULL))
goto err;

SSL_CTX_set_security_level(ctx, 2);
SSL_CTX_set_min_proto_version(ctx, NTLS1_1_VERSION);
SSL_CTX_set_max_proto_version(ctx, NTLS1_1_VERSION);

if (!TEST_int_eq(SSL_use_sign_certificate(ssl, sign_cert), 1))
goto err;

Expand Down