]>
git.ipfire.org Git - thirdparty/openssl.git/blob - apps/ciphers.c
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
, OPT_PROV_ENUM
33 const OPTIONS ciphers_options
[] = {
34 {OPT_HELP_STR
, 1, '-', "Usage: %s [options] [cipher]\n"},
36 OPT_SECTION("General"),
37 {"help", OPT_HELP
, '-', "Display this summary"},
39 OPT_SECTION("Output"),
40 {"v", OPT_V
, '-', "Verbose listing of the SSL/TLS ciphers"},
41 {"V", OPT_UPPER_V
, '-', "Even more verbose"},
42 {"stdname", OPT_STDNAME
, '-', "Show standard cipher names"},
43 {"convert", OPT_CONVERT
, 's', "Convert standard name into OpenSSL name"},
45 OPT_SECTION("Cipher specification"),
46 {"s", OPT_S
, '-', "Only supported ciphers"},
47 #ifndef OPENSSL_NO_SSL3
48 {"ssl3", OPT_SSL3
, '-', "Ciphers compatible with SSL3"},
50 #ifndef OPENSSL_NO_TLS1
51 {"tls1", OPT_TLS1
, '-', "Ciphers compatible with TLS1"},
53 #ifndef OPENSSL_NO_TLS1_1
54 {"tls1_1", OPT_TLS1_1
, '-', "Ciphers compatible with TLS1.1"},
56 #ifndef OPENSSL_NO_TLS1_2
57 {"tls1_2", OPT_TLS1_2
, '-', "Ciphers compatible with TLS1.2"},
59 #ifndef OPENSSL_NO_TLS1_3
60 {"tls1_3", OPT_TLS1_3
, '-', "Ciphers compatible with TLS1.3"},
62 #ifndef OPENSSL_NO_PSK
63 {"psk", OPT_PSK
, '-', "Include ciphersuites requiring PSK"},
65 #ifndef OPENSSL_NO_SRP
66 {"srp", OPT_SRP
, '-', "Include ciphersuites requiring SRP"},
68 {"ciphersuites", OPT_CIPHERSUITES
, 's',
69 "Configure the TLSv1.3 ciphersuites to use"},
73 {"cipher", 0, 0, "Cipher string to decode (optional)"},
77 #ifndef OPENSSL_NO_PSK
78 static unsigned int dummy_psk(SSL
*ssl
, const char *hint
, char *identity
,
79 unsigned int max_identity_len
,
81 unsigned int max_psk_len
)
86 #ifndef OPENSSL_NO_SRP
87 static char *dummy_srp(SSL
*ssl
, void *arg
)
93 int ciphers_main(int argc
, char **argv
)
97 STACK_OF(SSL_CIPHER
) *sk
= NULL
;
98 const SSL_METHOD
*meth
= TLS_server_method();
99 int ret
= 1, i
, verbose
= 0, Verbose
= 0, use_supported
= 0;
101 #ifndef OPENSSL_NO_PSK
104 #ifndef OPENSSL_NO_SRP
108 char *ciphers
= NULL
, *prog
, *convert
= NULL
, *ciphersuites
= NULL
;
111 int min_version
= 0, max_version
= 0;
113 prog
= opt_init(argc
, argv
, ciphers_options
);
114 while ((o
= opt_next()) != OPT_EOF
) {
119 BIO_printf(bio_err
, "%s: Use -help for summary.\n", prog
);
122 opt_help(ciphers_options
);
129 verbose
= Verbose
= 1;
135 stdname
= verbose
= 1;
141 min_version
= SSL3_VERSION
;
142 max_version
= SSL3_VERSION
;
145 min_version
= TLS1_VERSION
;
146 max_version
= TLS1_VERSION
;
149 min_version
= TLS1_1_VERSION
;
150 max_version
= TLS1_1_VERSION
;
153 min_version
= TLS1_2_VERSION
;
154 max_version
= TLS1_2_VERSION
;
157 min_version
= TLS1_3_VERSION
;
158 max_version
= TLS1_3_VERSION
;
161 #ifndef OPENSSL_NO_PSK
166 #ifndef OPENSSL_NO_SRP
170 case OPT_CIPHERSUITES
:
171 ciphersuites
= opt_arg();
174 if (!opt_provider(o
))
180 argc
= opt_num_rest();
187 if (convert
!= NULL
) {
188 BIO_printf(bio_out
, "OpenSSL cipher name: %s\n",
189 OPENSSL_cipher_name(convert
));
193 ctx
= SSL_CTX_new(meth
);
196 if (SSL_CTX_set_min_proto_version(ctx
, min_version
) == 0)
198 if (SSL_CTX_set_max_proto_version(ctx
, max_version
) == 0)
201 #ifndef OPENSSL_NO_PSK
203 SSL_CTX_set_psk_client_callback(ctx
, dummy_psk
);
205 #ifndef OPENSSL_NO_SRP
207 SSL_CTX_set_srp_client_pwd_callback(ctx
, dummy_srp
);
210 if (ciphersuites
!= NULL
&& !SSL_CTX_set_ciphersuites(ctx
, ciphersuites
)) {
211 BIO_printf(bio_err
, "Error setting TLSv1.3 ciphersuites\n");
215 if (ciphers
!= NULL
) {
216 if (!SSL_CTX_set_cipher_list(ctx
, ciphers
)) {
217 BIO_printf(bio_err
, "Error in cipher list\n");
226 sk
= SSL_get1_supported_ciphers(ssl
);
228 sk
= SSL_get_ciphers(ssl
);
231 for (i
= 0; i
< sk_SSL_CIPHER_num(sk
); i
++) {
232 const SSL_CIPHER
*c
= sk_SSL_CIPHER_value(sk
, i
);
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
);
249 unsigned long id
= SSL_CIPHER_get_id(c
);
250 int id0
= (int)(id
>> 24);
251 int id1
= (int)((id
>> 16) & 0xffL
);
252 int id2
= (int)((id
>> 8) & 0xffL
);
253 int id3
= (int)(id
& 0xffL
);
255 if ((id
& 0xff000000L
) == 0x03000000L
)
256 BIO_printf(bio_out
, " 0x%02X,0x%02X - ", id2
, id3
); /* SSL3
259 BIO_printf(bio_out
, "0x%02X,0x%02X,0x%02X,0x%02X - ", id0
, id1
, id2
, id3
); /* whatever */
262 const char *nm
= SSL_CIPHER_standard_name(c
);
265 BIO_printf(bio_out
, "%-45s - ", nm
);
267 BIO_puts(bio_out
, SSL_CIPHER_description(c
, buf
, sizeof(buf
)));
274 ERR_print_errors(bio_err
);
277 sk_SSL_CIPHER_free(sk
);