2 * Copyright 1995-2022 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>
19 typedef enum OPTION_choice {
31 OPT_V, OPT_UPPER_V, OPT_S, OPT_PROV_ENUM
34 const OPTIONS ciphers_options[] = {
35 {OPT_HELP_STR, 1, '-', "Usage: %s [options] [cipher]\n"},
37 OPT_SECTION("General"),
38 {"help", OPT_HELP, '-', "Display this summary"},
40 OPT_SECTION("Output"),
41 {"v", OPT_V, '-', "Verbose listing of the SSL/TLS ciphers"},
42 {"V", OPT_UPPER_V, '-', "Even more verbose"},
43 {"stdname", OPT_STDNAME, '-', "Show standard cipher names"},
44 {"convert", OPT_CONVERT, 's', "Convert standard name into OpenSSL name"},
46 OPT_SECTION("Cipher specification"),
47 {"s", OPT_S, '-', "Only supported ciphers"},
48 #ifndef OPENSSL_NO_SSL3
49 {"ssl3", OPT_SSL3, '-', "Ciphers compatible with SSL3"},
51 #ifndef OPENSSL_NO_TLS1
52 {"tls1", OPT_TLS1, '-', "Ciphers compatible with TLS1"},
54 #ifndef OPENSSL_NO_TLS1_1
55 {"tls1_1", OPT_TLS1_1, '-', "Ciphers compatible with TLS1.1"},
57 #ifndef OPENSSL_NO_TLS1_2
58 {"tls1_2", OPT_TLS1_2, '-', "Ciphers compatible with TLS1.2"},
60 #ifndef OPENSSL_NO_TLS1_3
61 {"tls1_3", OPT_TLS1_3, '-', "Ciphers compatible with TLS1.3"},
63 #ifndef OPENSSL_NO_PSK
64 {"psk", OPT_PSK, '-', "Include ciphersuites requiring PSK"},
66 #ifndef OPENSSL_NO_SRP
67 {"srp", OPT_SRP, '-', "(deprecated) Include ciphersuites requiring SRP"},
69 {"ciphersuites", OPT_CIPHERSUITES, 's',
70 "Configure the TLSv1.3 ciphersuites to use"},
74 {"cipher", 0, 0, "Cipher string to decode (optional)"},
78 #ifndef OPENSSL_NO_PSK
79 static unsigned int dummy_psk(SSL *ssl, const char *hint, char *identity,
80 unsigned int max_identity_len,
82 unsigned int max_psk_len)
88 int ciphers_main(int argc, char **argv)
92 STACK_OF(SSL_CIPHER) *sk = NULL;
93 const SSL_METHOD *meth = TLS_server_method();
94 int ret = 1, i, verbose = 0, Verbose = 0, use_supported = 0;
96 #ifndef OPENSSL_NO_PSK
99 #ifndef OPENSSL_NO_SRP
103 char *ciphers = NULL, *prog, *convert = NULL, *ciphersuites = NULL;
106 int min_version = 0, max_version = 0;
108 prog = opt_init(argc, argv, ciphers_options);
109 while ((o = opt_next()) != OPT_EOF) {
114 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
117 opt_help(ciphers_options);
124 verbose = Verbose = 1;
130 stdname = verbose = 1;
136 min_version = SSL3_VERSION;
137 max_version = SSL3_VERSION;
140 min_version = TLS1_VERSION;
141 max_version = TLS1_VERSION;
144 min_version = TLS1_1_VERSION;
145 max_version = TLS1_1_VERSION;
148 min_version = TLS1_2_VERSION;
149 max_version = TLS1_2_VERSION;
152 min_version = TLS1_3_VERSION;
153 max_version = TLS1_3_VERSION;
156 #ifndef OPENSSL_NO_PSK
161 #ifndef OPENSSL_NO_SRP
165 case OPT_CIPHERSUITES:
166 ciphersuites = opt_arg();
169 if (!opt_provider(o))
175 /* Optional arg is cipher name. */
177 if (opt_num_rest() == 1)
179 else if (!opt_check_rest_arg(NULL))
182 if (convert != NULL) {
183 BIO_printf(bio_out, "OpenSSL cipher name: %s\n",
184 OPENSSL_cipher_name(convert));
189 ctx = SSL_CTX_new_ex(app_get0_libctx(), app_get0_propq(), meth);
192 if (SSL_CTX_set_min_proto_version(ctx, min_version) == 0)
194 if (SSL_CTX_set_max_proto_version(ctx, max_version) == 0)
197 #ifndef OPENSSL_NO_PSK
199 SSL_CTX_set_psk_client_callback(ctx, dummy_psk);
201 #ifndef OPENSSL_NO_SRP
203 set_up_dummy_srp(ctx);
206 if (ciphersuites != NULL && !SSL_CTX_set_ciphersuites(ctx, ciphersuites)) {
207 BIO_printf(bio_err, "Error setting TLSv1.3 ciphersuites\n");
211 if (ciphers != NULL) {
212 if (!SSL_CTX_set_cipher_list(ctx, ciphers)) {
213 BIO_printf(bio_err, "Error in cipher list\n");
222 sk = SSL_get1_supported_ciphers(ssl);
224 sk = SSL_get_ciphers(ssl);
227 for (i = 0; i < sk_SSL_CIPHER_num(sk); i++) {
228 const SSL_CIPHER *c = sk_SSL_CIPHER_value(sk, i);
230 if (!ossl_assert(c != NULL))
233 p = SSL_CIPHER_get_name(c);
237 BIO_printf(bio_out, ":");
238 BIO_printf(bio_out, "%s", p);
240 BIO_printf(bio_out, "\n");
243 for (i = 0; i < sk_SSL_CIPHER_num(sk); i++) {
246 c = sk_SSL_CIPHER_value(sk, i);
248 if (!ossl_assert(c != NULL))
252 unsigned long id = SSL_CIPHER_get_id(c);
253 int id0 = (int)(id >> 24);
254 int id1 = (int)((id >> 16) & 0xffL);
255 int id2 = (int)((id >> 8) & 0xffL);
256 int id3 = (int)(id & 0xffL);
258 if ((id & 0xff000000L) == 0x03000000L)
259 BIO_printf(bio_out, " 0x%02X,0x%02X - ", id2, id3); /* SSL3
262 BIO_printf(bio_out, "0x%02X,0x%02X,0x%02X,0x%02X - ", id0, id1, id2, id3); /* whatever */
265 const char *nm = SSL_CIPHER_standard_name(c);
268 BIO_printf(bio_out, "%-45s - ", nm);
270 BIO_puts(bio_out, SSL_CIPHER_description(c, buf, sizeof(buf)));
277 ERR_print_errors(bio_err);
280 sk_SSL_CIPHER_free(sk);