Skip to content

Commit 04d24fb

Browse files
flichtenheldcron2
authored andcommitted
ssl_openssl: Use uint16_t internally for TLS versions
libressl changed the API for the involved functions. Since uint16_t is a true subset of int it should be safe to switch to that for all OpenSSL variants. One trivial drive-by fix in unrelated code to be able to enable -Wconversion fully for the file. This just adds a cast where the comment says we intend a cast. Change-Id: I9ea87531afb553f789289787403900a4758b8e1c Signed-off-by: Frank Lichtenheld <[email protected]> Acked-by: MaxF <[email protected]> Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1212 Message-Id: <[email protected]> URL: https://sourceforge.net/p/openvpn/mailman/message/59238230/ Signed-off-by: Gert Doering <[email protected]>
1 parent b2d5d71 commit 04d24fb

File tree

1 file changed

+7
-25
lines changed

1 file changed

+7
-25
lines changed

src/openvpn/ssl_openssl.c

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ tls_version_max(void)
235235
}
236236

237237
/** Convert internal version number to openssl version number */
238-
static int
239-
openssl_tls_version(int ver)
238+
static uint16_t
239+
openssl_tls_version(unsigned int ver)
240240
{
241241
if (ver == TLS_VER_1_0)
242242
{
@@ -272,23 +272,18 @@ openssl_tls_version(int ver)
272272
return 0;
273273
}
274274

275-
#if defined(__GNUC__) || defined(__clang__)
276-
#pragma GCC diagnostic push
277-
#pragma GCC diagnostic ignored "-Wconversion"
278-
#endif
279-
280275
static bool
281276
tls_ctx_set_tls_versions(struct tls_root_ctx *ctx, unsigned int ssl_flags)
282277
{
283-
int tls_ver_min =
278+
uint16_t tls_ver_min =
284279
openssl_tls_version((ssl_flags >> SSLF_TLS_VERSION_MIN_SHIFT) & SSLF_TLS_VERSION_MIN_MASK);
285-
int tls_ver_max =
280+
uint16_t tls_ver_max =
286281
openssl_tls_version((ssl_flags >> SSLF_TLS_VERSION_MAX_SHIFT) & SSLF_TLS_VERSION_MAX_MASK);
287282

288283
if (!tls_ver_min)
289284
{
290285
/* Enforce at least TLS 1.0 */
291-
int cur_min = SSL_CTX_get_min_proto_version(ctx->ctx);
286+
uint16_t cur_min = (uint16_t)SSL_CTX_get_min_proto_version(ctx->ctx);
292287
tls_ver_min = cur_min < TLS1_VERSION ? TLS1_VERSION : cur_min;
293288
}
294289

@@ -387,7 +382,7 @@ convert_tls_list_to_openssl(char *openssl_ciphers, size_t len, const char *ciphe
387382
/* %.*s format specifier expects length of type int, so guarantee */
388383
/* that length is small enough and cast to int. */
389384
msg(D_LOW, "No valid translation found for TLS cipher '%.*s'",
390-
constrain_int(current_cipher_len, 0, 256), current_cipher);
385+
constrain_int((int)current_cipher_len, 0, 256), current_cipher);
391386
}
392387
else
393388
{
@@ -429,10 +424,6 @@ convert_tls_list_to_openssl(char *openssl_ciphers, size_t len, const char *ciphe
429424
}
430425
}
431426

432-
#if defined(__GNUC__) || defined(__clang__)
433-
#pragma GCC diagnostic pop
434-
#endif
435-
436427
void
437428
tls_ctx_restrict_ciphers(struct tls_root_ctx *ctx, const char *ciphers)
438429
{
@@ -2522,11 +2513,6 @@ print_details(struct key_state_ssl *ks_ssl, const char *prefix)
25222513
msg(D_HANDSHAKE, "%s%s%s%s%s", s1, s2, s3, s4, s5);
25232514
}
25242515

2525-
#if defined(__GNUC__) || defined(__clang__)
2526-
#pragma GCC diagnostic push
2527-
#pragma GCC diagnostic ignored "-Wconversion"
2528-
#endif
2529-
25302516
void
25312517
show_available_tls_ciphers_list(const char *cipher_list, const char *tls_cert_profile, bool tls13)
25322518
{
@@ -2541,7 +2527,7 @@ show_available_tls_ciphers_list(const char *cipher_list, const char *tls_cert_pr
25412527
#if defined(TLS1_3_VERSION)
25422528
if (tls13)
25432529
{
2544-
SSL_CTX_set_min_proto_version(tls_ctx.ctx, openssl_tls_version(TLS_VER_1_3));
2530+
SSL_CTX_set_min_proto_version(tls_ctx.ctx, TLS1_3_VERSION);
25452531
tls_ctx_restrict_ciphers_tls13(&tls_ctx, cipher_list);
25462532
}
25472533
else
@@ -2594,10 +2580,6 @@ show_available_tls_ciphers_list(const char *cipher_list, const char *tls_cert_pr
25942580
SSL_CTX_free(tls_ctx.ctx);
25952581
}
25962582

2597-
#if defined(__GNUC__) || defined(__clang__)
2598-
#pragma GCC diagnostic pop
2599-
#endif
2600-
26012583
/*
26022584
* Show the Elliptic curves that are available for us to use
26032585
* in the OpenSSL library.

0 commit comments

Comments
 (0)