1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-10 06:47:55 -08:00

Add ssl_cipher_is_permitted(), an internal helper function that

will be used in a few places shortly, e.g. in
ssl_cipher_list_to_bytes().

ok jsing
This commit is contained in:
tb 2019-01-21 10:28:52 +00:00
parent c9e07d34dc
commit a36841cf36
3 changed files with 49 additions and 2 deletions

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.51 2019/01/21 09:10:58 jsing Exp $
# $OpenBSD: Makefile,v 1.52 2019/01/21 10:28:52 tb Exp $
.include <bsd.own.mk>
.ifndef NOMAN
@ -43,6 +43,7 @@ SRCS= \
ssl_both.c \
ssl_cert.c \
ssl_ciph.c \
ssl_ciphers.c \
ssl_clnt.c \
ssl_err.c \
ssl_init.c \

44
lib/libssl/ssl_ciphers.c Normal file
View File

@ -0,0 +1,44 @@
/* $OpenBSD: ssl_ciphers.c,v 1.1 2019/01/21 10:28:52 tb Exp $ */
/*
* Copyright (c) 2019 Theo Buehler <tb@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "ssl_locl.h"
int
ssl_cipher_is_permitted(const SSL_CIPHER *cipher, uint16_t min_ver,
uint16_t max_ver)
{
/* XXX: We only support DTLSv1 which is effectively TLSv1.1 */
if (min_ver == DTLS1_VERSION || max_ver == DTLS1_VERSION)
min_ver = max_ver = TLS1_1_VERSION;
switch(cipher->algorithm_ssl) {
case SSL_SSLV3:
if (min_ver <= TLS1_2_VERSION)
return 1;
break;
case SSL_TLSV1_2:
if (min_ver <= TLS1_2_VERSION && TLS1_2_VERSION <= max_ver)
return 1;
break;
case SSL_TLSV1_3:
if (min_ver <= TLS1_3_VERSION && TLS1_3_VERSION <= max_ver)
return 1;
break;
}
return 0;
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: ssl_locl.h,v 1.227 2019/01/21 06:58:44 jsing Exp $ */
/* $OpenBSD: ssl_locl.h,v 1.228 2019/01/21 10:28:52 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -1052,6 +1052,8 @@ int ssl_version_set_min(const SSL_METHOD *meth, uint16_t ver, uint16_t max_ver,
int ssl_version_set_max(const SSL_METHOD *meth, uint16_t ver, uint16_t min_ver,
uint16_t *out_ver);
uint16_t ssl_max_server_version(SSL *s);
int ssl_cipher_is_permitted(const SSL_CIPHER *cipher, uint16_t min_ver,
uint16_t max_ver);
const SSL_METHOD *dtls1_get_client_method(int ver);
const SSL_METHOD *dtls1_get_server_method(int ver);