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>
23 static int test_empty(SSL *s)
25 STACK_OF(SSL_CIPHER) *sk = NULL, *scsv = NULL;
26 const unsigned char bytes[] = {0x00};
28 if (SSL_bytes_to_cipher_list(s, bytes, 0, 0, &sk, &scsv) ||
29 sk != NULL || scsv != NULL)
34 static int test_unsupported(SSL *s)
36 STACK_OF(SSL_CIPHER) *sk, *scsv;
37 /* ECDH-RSA-AES256 (unsupported), ECDHE-ECDSA-AES128, <unassigned> */
38 const unsigned char bytes[] = {0xc0, 0x0f, 0x00, 0x2f, 0x01, 0x00};
40 if (!SSL_bytes_to_cipher_list(s, bytes, sizeof(bytes), 0, &sk, &scsv) ||
41 sk == NULL || sk_SSL_CIPHER_num(sk) != 1 || scsv == NULL ||
42 sk_SSL_CIPHER_num(scsv) != 0)
44 if (strcmp(SSL_CIPHER_get_name(sk_SSL_CIPHER_value(sk, 0)),
48 sk_SSL_CIPHER_free(sk);
49 sk_SSL_CIPHER_free(scsv);
53 static int test_v2(SSL *s)
55 STACK_OF(SSL_CIPHER) *sk, *scsv;
56 /* ECDHE-ECDSA-AES256GCM, SSL2_RC4_1238_WITH_MD5,
57 * ECDHE-ECDSA-CHACHA20-POLY1305 */
58 const unsigned char bytes[] = {0x00, 0x00, 0x35, 0x01, 0x00, 0x80,
61 if (!SSL_bytes_to_cipher_list(s, bytes, sizeof(bytes), 1, &sk, &scsv) ||
62 sk == NULL || sk_SSL_CIPHER_num(sk) != 2 || scsv == NULL ||
63 sk_SSL_CIPHER_num(scsv) != 0)
65 if (strcmp(SSL_CIPHER_get_name(sk_SSL_CIPHER_value(sk, 0)),
67 strcmp(SSL_CIPHER_get_name(sk_SSL_CIPHER_value(sk, 1)),
68 "DHE-RSA-AES128-SHA") != 0)
70 sk_SSL_CIPHER_free(sk);
71 sk_SSL_CIPHER_free(scsv);
75 static int test_v3(SSL *s)
77 STACK_OF(SSL_CIPHER) *sk, *scsv;
78 /* ECDHE-ECDSA-AES256GCM, ECDHE-ECDSA-CHACHAPOLY, DHE-RSA-AES256GCM,
79 * EMPTY-RENEGOTIATION-INFO-SCSV, FALLBACK-SCSV */
80 const unsigned char bytes[] = {0x00, 0x2f, 0x00, 0x33, 0x00, 0x9f, 0x00, 0xff,
83 if (!SSL_bytes_to_cipher_list(s, bytes, sizeof(bytes), 0, &sk, &scsv) ||
84 sk == NULL || sk_SSL_CIPHER_num(sk) != 3 || scsv == NULL ||
85 sk_SSL_CIPHER_num(scsv) != 2)
87 if (strcmp(SSL_CIPHER_get_name(sk_SSL_CIPHER_value(sk, 0)),
89 strcmp(SSL_CIPHER_get_name(sk_SSL_CIPHER_value(sk, 1)),
90 "DHE-RSA-AES128-SHA") != 0 ||
91 strcmp(SSL_CIPHER_get_name(sk_SSL_CIPHER_value(sk, 2)),
92 "DHE-RSA-AES256-GCM-SHA384") != 0 ||
93 strcmp(SSL_CIPHER_get_name(sk_SSL_CIPHER_value(scsv, 0)),
94 "TLS_EMPTY_RENEGOTIATION_INFO_SCSV") != 0 ||
95 strcmp(SSL_CIPHER_get_name(sk_SSL_CIPHER_value(scsv, 1)),
96 "TLS_FALLBACK_SCSV") != 0)
98 sk_SSL_CIPHER_free(sk);
99 sk_SSL_CIPHER_free(scsv);
103 int main(int argc, char **argv)
108 ctx = SSL_CTX_new(TLS_server_method());
110 OPENSSL_assert(s != NULL);
115 if (!test_unsupported(s))