2 * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL licenses, (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 * https://www.openssl.org/source/license.html
8 * or in the file LICENSE in the source distribution.
14 #include <openssl/opensslconf.h>
15 #include <openssl/err.h>
16 #include <openssl/e_os2.h>
17 #include <openssl/ssl.h>
18 #include <openssl/ssl3.h>
19 #include <openssl/tls1.h>
22 #include "test_main.h"
25 static int test_empty(SSL *s)
27 STACK_OF(SSL_CIPHER) *sk = NULL, *scsv = NULL;
28 const unsigned char bytes[] = {0x00};
30 if (SSL_bytes_to_cipher_list(s, bytes, 0, 0, &sk, &scsv) ||
31 sk != NULL || scsv != NULL)
36 static int test_unsupported(SSL *s)
38 STACK_OF(SSL_CIPHER) *sk, *scsv;
39 /* ECDH-RSA-AES256 (unsupported), ECDHE-ECDSA-AES128, <unassigned> */
40 const unsigned char bytes[] = {0xc0, 0x0f, 0x00, 0x2f, 0x01, 0x00};
42 if (!SSL_bytes_to_cipher_list(s, bytes, sizeof(bytes), 0, &sk, &scsv) ||
43 sk == NULL || sk_SSL_CIPHER_num(sk) != 1 || scsv == NULL ||
44 sk_SSL_CIPHER_num(scsv) != 0)
46 if (strcmp(SSL_CIPHER_get_name(sk_SSL_CIPHER_value(sk, 0)),
50 sk_SSL_CIPHER_free(sk);
51 sk_SSL_CIPHER_free(scsv);
55 static int test_v2(SSL *s)
57 STACK_OF(SSL_CIPHER) *sk, *scsv;
58 /* ECDHE-ECDSA-AES256GCM, SSL2_RC4_1238_WITH_MD5,
59 * ECDHE-ECDSA-CHACHA20-POLY1305 */
60 const unsigned char bytes[] = {0x00, 0x00, 0x35, 0x01, 0x00, 0x80,
63 if (!SSL_bytes_to_cipher_list(s, bytes, sizeof(bytes), 1, &sk, &scsv) ||
64 sk == NULL || sk_SSL_CIPHER_num(sk) != 2 || scsv == NULL ||
65 sk_SSL_CIPHER_num(scsv) != 0)
67 if (strcmp(SSL_CIPHER_get_name(sk_SSL_CIPHER_value(sk, 0)),
69 strcmp(SSL_CIPHER_get_name(sk_SSL_CIPHER_value(sk, 1)),
70 "DHE-RSA-AES128-SHA") != 0)
72 sk_SSL_CIPHER_free(sk);
73 sk_SSL_CIPHER_free(scsv);
77 static int test_v3(SSL *s)
79 STACK_OF(SSL_CIPHER) *sk, *scsv;
80 /* ECDHE-ECDSA-AES256GCM, ECDHE-ECDSA-CHACHAPOLY, DHE-RSA-AES256GCM,
81 * EMPTY-RENEGOTIATION-INFO-SCSV, FALLBACK-SCSV */
82 const unsigned char bytes[] = {0x00, 0x2f, 0x00, 0x33, 0x00, 0x9f, 0x00, 0xff,
85 if (!SSL_bytes_to_cipher_list(s, bytes, sizeof(bytes), 0, &sk, &scsv) ||
86 sk == NULL || sk_SSL_CIPHER_num(sk) != 3 || scsv == NULL ||
87 sk_SSL_CIPHER_num(scsv) != 2)
89 if (strcmp(SSL_CIPHER_get_name(sk_SSL_CIPHER_value(sk, 0)),
91 strcmp(SSL_CIPHER_get_name(sk_SSL_CIPHER_value(sk, 1)),
92 "DHE-RSA-AES128-SHA") != 0 ||
93 strcmp(SSL_CIPHER_get_name(sk_SSL_CIPHER_value(sk, 2)),
94 "DHE-RSA-AES256-GCM-SHA384") != 0 ||
95 strcmp(SSL_CIPHER_get_name(sk_SSL_CIPHER_value(scsv, 0)),
96 "TLS_EMPTY_RENEGOTIATION_INFO_SCSV") != 0 ||
97 strcmp(SSL_CIPHER_get_name(sk_SSL_CIPHER_value(scsv, 1)),
98 "TLS_FALLBACK_SCSV") != 0)
100 sk_SSL_CIPHER_free(sk);
101 sk_SSL_CIPHER_free(scsv);
105 int main(int argc, char **argv)
110 ctx = SSL_CTX_new(TLS_server_method());
112 OPENSSL_assert(s != NULL);
117 if (!test_unsupported(s))