2 * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
15 #include <openssl/err.h>
16 #include <openssl/ssl.h>
18 typedef enum OPTION_choice {
19 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
30 OPT_V, OPT_UPPER_V, OPT_S
33 const OPTIONS ciphers_options[] = {
34 OPT_SECTION("General"),
35 {"help", OPT_HELP, '-', "Display this summary"},
37 OPT_SECTION("Output"),
38 {"v", OPT_V, '-', "Verbose listing of the SSL/TLS ciphers"},
39 {"V", OPT_UPPER_V, '-', "Even more verbose"},
40 {"stdname", OPT_STDNAME, '-', "Show standard cipher names"},
41 {"convert", OPT_CONVERT, 's', "Convert standard name into OpenSSL name"},
43 OPT_SECTION("Cipher specification"),
44 {"s", OPT_S, '-', "Only supported ciphers"},
45 #ifndef OPENSSL_NO_SSL3
46 {"ssl3", OPT_SSL3, '-', "Ciphers compatible with SSL3"},
48 #ifndef OPENSSL_NO_TLS1
49 {"tls1", OPT_TLS1, '-', "Ciphers compatible with TLS1"},
51 #ifndef OPENSSL_NO_TLS1_1
52 {"tls1_1", OPT_TLS1_1, '-', "Ciphers compatible with TLS1.1"},
54 #ifndef OPENSSL_NO_TLS1_2
55 {"tls1_2", OPT_TLS1_2, '-', "Ciphers compatible with TLS1.2"},
57 #ifndef OPENSSL_NO_TLS1_3
58 {"tls1_3", OPT_TLS1_3, '-', "Ciphers compatible with TLS1.3"},
60 #ifndef OPENSSL_NO_PSK
61 {"psk", OPT_PSK, '-', "Include ciphersuites requiring PSK"},
63 #ifndef OPENSSL_NO_SRP
64 {"srp", OPT_SRP, '-', "Include ciphersuites requiring SRP"},
66 {"ciphersuites", OPT_CIPHERSUITES, 's',
67 "Configure the TLSv1.3 ciphersuites to use"},
71 #ifndef OPENSSL_NO_PSK
72 static unsigned int dummy_psk(SSL *ssl, const char *hint, char *identity,
73 unsigned int max_identity_len,
75 unsigned int max_psk_len)
80 #ifndef OPENSSL_NO_SRP
81 static char *dummy_srp(SSL *ssl, void *arg)
87 int ciphers_main(int argc, char **argv)
91 STACK_OF(SSL_CIPHER) *sk = NULL;
92 const SSL_METHOD *meth = TLS_server_method();
93 int ret = 1, i, verbose = 0, Verbose = 0, use_supported = 0;
95 #ifndef OPENSSL_NO_PSK
98 #ifndef OPENSSL_NO_SRP
102 char *ciphers = NULL, *prog, *convert = NULL, *ciphersuites = NULL;
105 int min_version = 0, max_version = 0;
107 prog = opt_init(argc, argv, ciphers_options);
108 while ((o = opt_next()) != OPT_EOF) {
113 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
116 opt_help(ciphers_options);
123 verbose = Verbose = 1;
129 stdname = verbose = 1;
135 min_version = SSL3_VERSION;
136 max_version = SSL3_VERSION;
139 min_version = TLS1_VERSION;
140 max_version = TLS1_VERSION;
143 min_version = TLS1_1_VERSION;
144 max_version = TLS1_1_VERSION;
147 min_version = TLS1_2_VERSION;
148 max_version = TLS1_2_VERSION;
151 min_version = TLS1_3_VERSION;
152 max_version = TLS1_3_VERSION;
155 #ifndef OPENSSL_NO_PSK
160 #ifndef OPENSSL_NO_SRP
164 case OPT_CIPHERSUITES:
165 ciphersuites = opt_arg();
170 argc = opt_num_rest();
177 if (convert != NULL) {
178 BIO_printf(bio_out, "OpenSSL cipher name: %s\n",
179 OPENSSL_cipher_name(convert));
183 ctx = SSL_CTX_new(meth);
186 if (SSL_CTX_set_min_proto_version(ctx, min_version) == 0)
188 if (SSL_CTX_set_max_proto_version(ctx, max_version) == 0)
191 #ifndef OPENSSL_NO_PSK
193 SSL_CTX_set_psk_client_callback(ctx, dummy_psk);
195 #ifndef OPENSSL_NO_SRP
197 SSL_CTX_set_srp_client_pwd_callback(ctx, dummy_srp);
200 if (ciphersuites != NULL && !SSL_CTX_set_ciphersuites(ctx, ciphersuites)) {
201 BIO_printf(bio_err, "Error setting TLSv1.3 ciphersuites\n");
205 if (ciphers != NULL) {
206 if (!SSL_CTX_set_cipher_list(ctx, ciphers)) {
207 BIO_printf(bio_err, "Error in cipher list\n");
216 sk = SSL_get1_supported_ciphers(ssl);
218 sk = SSL_get_ciphers(ssl);
221 for (i = 0; i < sk_SSL_CIPHER_num(sk); i++) {
222 const SSL_CIPHER *c = sk_SSL_CIPHER_value(sk, i);
223 p = SSL_CIPHER_get_name(c);
227 BIO_printf(bio_out, ":");
228 BIO_printf(bio_out, "%s", p);
230 BIO_printf(bio_out, "\n");
233 for (i = 0; i < sk_SSL_CIPHER_num(sk); i++) {
236 c = sk_SSL_CIPHER_value(sk, i);
239 unsigned long id = SSL_CIPHER_get_id(c);
240 int id0 = (int)(id >> 24);
241 int id1 = (int)((id >> 16) & 0xffL);
242 int id2 = (int)((id >> 8) & 0xffL);
243 int id3 = (int)(id & 0xffL);
245 if ((id & 0xff000000L) == 0x03000000L)
246 BIO_printf(bio_out, " 0x%02X,0x%02X - ", id2, id3); /* SSL3
249 BIO_printf(bio_out, "0x%02X,0x%02X,0x%02X,0x%02X - ", id0, id1, id2, id3); /* whatever */
252 const char *nm = SSL_CIPHER_standard_name(c);
255 BIO_printf(bio_out, "%-45s - ", nm);
257 BIO_puts(bio_out, SSL_CIPHER_description(c, buf, sizeof(buf)));
264 ERR_print_errors(bio_err);
267 sk_SSL_CIPHER_free(sk);