2 * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (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,
29 OPT_V, OPT_UPPER_V, OPT_S
32 const OPTIONS ciphers_options[] = {
33 {"help", OPT_HELP, '-', "Display this summary"},
34 {"v", OPT_V, '-', "Verbose listing of the SSL/TLS ciphers"},
35 {"V", OPT_UPPER_V, '-', "Even more verbose"},
36 {"s", OPT_S, '-', "Only supported ciphers"},
37 #ifndef OPENSSL_NO_SSL3
38 {"ssl3", OPT_SSL3, '-', "SSL3 mode"},
40 #ifndef OPENSSL_NO_TLS1
41 {"tls1", OPT_TLS1, '-', "TLS1 mode"},
43 #ifndef OPENSSL_NO_TLS1_1
44 {"tls1_1", OPT_TLS1_1, '-', "TLS1.1 mode"},
46 #ifndef OPENSSL_NO_TLS1_2
47 {"tls1_2", OPT_TLS1_2, '-', "TLS1.2 mode"},
49 #ifndef OPENSSL_NO_TLS1_3
50 {"tls1_3", OPT_TLS1_3, '-', "TLS1.3 mode"},
52 {"stdname", OPT_STDNAME, '-', "Show standard cipher names"},
53 #ifndef OPENSSL_NO_PSK
54 {"psk", OPT_PSK, '-', "include ciphersuites requiring PSK"},
56 #ifndef OPENSSL_NO_SRP
57 {"srp", OPT_SRP, '-', "include ciphersuites requiring SRP"},
59 {"convert", OPT_CONVERT, 's', "Convert standard name into OpenSSL name"},
63 #ifndef OPENSSL_NO_PSK
64 static unsigned int dummy_psk(SSL *ssl, const char *hint, char *identity,
65 unsigned int max_identity_len,
67 unsigned int max_psk_len)
72 #ifndef OPENSSL_NO_SRP
73 static char *dummy_srp(SSL *ssl, void *arg)
79 int ciphers_main(int argc, char **argv)
83 STACK_OF(SSL_CIPHER) *sk = NULL;
84 const SSL_METHOD *meth = TLS_server_method();
85 int ret = 1, i, verbose = 0, Verbose = 0, use_supported = 0;
87 #ifndef OPENSSL_NO_PSK
90 #ifndef OPENSSL_NO_SRP
94 char *ciphers = NULL, *prog, *convert = NULL;
97 int min_version = 0, max_version = 0;
99 prog = opt_init(argc, argv, ciphers_options);
100 while ((o = opt_next()) != OPT_EOF) {
105 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
108 opt_help(ciphers_options);
115 verbose = Verbose = 1;
121 stdname = verbose = 1;
127 min_version = SSL3_VERSION;
128 max_version = SSL3_VERSION;
131 min_version = TLS1_VERSION;
132 max_version = TLS1_VERSION;
135 min_version = TLS1_1_VERSION;
136 max_version = TLS1_1_VERSION;
139 min_version = TLS1_2_VERSION;
140 max_version = TLS1_2_VERSION;
143 min_version = TLS1_3_VERSION;
144 max_version = TLS1_3_VERSION;
147 #ifndef OPENSSL_NO_PSK
152 #ifndef OPENSSL_NO_SRP
159 argc = opt_num_rest();
166 if (convert != NULL) {
167 BIO_printf(bio_out, "OpenSSL cipher name: %s\n",
168 OPENSSL_cipher_name(convert));
172 ctx = SSL_CTX_new(meth);
175 if (SSL_CTX_set_min_proto_version(ctx, min_version) == 0)
177 if (SSL_CTX_set_max_proto_version(ctx, max_version) == 0)
180 #ifndef OPENSSL_NO_PSK
182 SSL_CTX_set_psk_client_callback(ctx, dummy_psk);
184 #ifndef OPENSSL_NO_SRP
186 SSL_CTX_set_srp_client_pwd_callback(ctx, dummy_srp);
188 if (ciphers != NULL) {
189 if (!SSL_CTX_set_cipher_list(ctx, ciphers)) {
190 BIO_printf(bio_err, "Error in cipher list\n");
199 sk = SSL_get1_supported_ciphers(ssl);
201 sk = SSL_get_ciphers(ssl);
204 for (i = 0; i < sk_SSL_CIPHER_num(sk); i++) {
205 const SSL_CIPHER *c = sk_SSL_CIPHER_value(sk, i);
206 p = SSL_CIPHER_get_name(c);
210 BIO_printf(bio_out, ":");
211 BIO_printf(bio_out, "%s", p);
213 BIO_printf(bio_out, "\n");
216 for (i = 0; i < sk_SSL_CIPHER_num(sk); i++) {
219 c = sk_SSL_CIPHER_value(sk, i);
222 unsigned long id = SSL_CIPHER_get_id(c);
223 int id0 = (int)(id >> 24);
224 int id1 = (int)((id >> 16) & 0xffL);
225 int id2 = (int)((id >> 8) & 0xffL);
226 int id3 = (int)(id & 0xffL);
228 if ((id & 0xff000000L) == 0x03000000L)
229 BIO_printf(bio_out, " 0x%02X,0x%02X - ", id2, id3); /* SSL3
232 BIO_printf(bio_out, "0x%02X,0x%02X,0x%02X,0x%02X - ", id0, id1, id2, id3); /* whatever */
235 const char *nm = SSL_CIPHER_standard_name(c);
238 BIO_printf(bio_out, "%s - ", nm);
240 BIO_puts(bio_out, SSL_CIPHER_description(c, buf, sizeof(buf)));
247 ERR_print_errors(bio_err);
250 sk_SSL_CIPHER_free(sk);