]>
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 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
,
30 OPT_V
, OPT_UPPER_V
, OPT_S
33 const OPTIONS ciphers_options
[] = {
34 {"help", OPT_HELP
, '-', "Display this summary"},
35 {"v", OPT_V
, '-', "Verbose listing of the SSL/TLS ciphers"},
36 {"V", OPT_UPPER_V
, '-', "Even more verbose"},
37 {"s", OPT_S
, '-', "Only supported ciphers"},
38 #ifndef OPENSSL_NO_SSL3
39 {"ssl3", OPT_SSL3
, '-', "SSL3 mode"},
41 #ifndef OPENSSL_NO_TLS1
42 {"tls1", OPT_TLS1
, '-', "TLS1 mode"},
44 #ifndef OPENSSL_NO_TLS1_1
45 {"tls1_1", OPT_TLS1_1
, '-', "TLS1.1 mode"},
47 #ifndef OPENSSL_NO_TLS1_2
48 {"tls1_2", OPT_TLS1_2
, '-', "TLS1.2 mode"},
50 #ifndef OPENSSL_NO_TLS1_3
51 {"tls1_3", OPT_TLS1_3
, '-', "TLS1.3 mode"},
53 {"stdname", OPT_STDNAME
, '-', "Show standard cipher names"},
54 #ifndef OPENSSL_NO_PSK
55 {"psk", OPT_PSK
, '-', "include ciphersuites requiring PSK"},
57 #ifndef OPENSSL_NO_SRP
58 {"srp", OPT_SRP
, '-', "include ciphersuites requiring SRP"},
60 {"convert", OPT_CONVERT
, 's', "Convert standard name into OpenSSL name"},
61 {"ciphersuites", OPT_CIPHERSUITES
, 's',
62 "Configure the TLSv1.3 ciphersuites to use"},
66 #ifndef OPENSSL_NO_PSK
67 static unsigned int dummy_psk(SSL
*ssl
, const char *hint
, char *identity
,
68 unsigned int max_identity_len
,
70 unsigned int max_psk_len
)
75 #ifndef OPENSSL_NO_SRP
76 static char *dummy_srp(SSL
*ssl
, void *arg
)
82 int ciphers_main(int argc
, char **argv
)
86 STACK_OF(SSL_CIPHER
) *sk
= NULL
;
87 const SSL_METHOD
*meth
= TLS_server_method();
88 int ret
= 1, i
, verbose
= 0, Verbose
= 0, use_supported
= 0;
90 #ifndef OPENSSL_NO_PSK
93 #ifndef OPENSSL_NO_SRP
97 char *ciphers
= NULL
, *prog
, *convert
= NULL
, *ciphersuites
= NULL
;
100 int min_version
= 0, max_version
= 0;
102 prog
= opt_init(argc
, argv
, ciphers_options
);
103 while ((o
= opt_next()) != OPT_EOF
) {
108 BIO_printf(bio_err
, "%s: Use -help for summary.\n", prog
);
111 opt_help(ciphers_options
);
118 verbose
= Verbose
= 1;
124 stdname
= verbose
= 1;
130 min_version
= SSL3_VERSION
;
131 max_version
= SSL3_VERSION
;
134 min_version
= TLS1_VERSION
;
135 max_version
= TLS1_VERSION
;
138 min_version
= TLS1_1_VERSION
;
139 max_version
= TLS1_1_VERSION
;
142 min_version
= TLS1_2_VERSION
;
143 max_version
= TLS1_2_VERSION
;
146 min_version
= TLS1_3_VERSION
;
147 max_version
= TLS1_3_VERSION
;
150 #ifndef OPENSSL_NO_PSK
155 #ifndef OPENSSL_NO_SRP
159 case OPT_CIPHERSUITES
:
160 ciphersuites
= opt_arg();
165 argc
= opt_num_rest();
172 if (convert
!= NULL
) {
173 BIO_printf(bio_out
, "OpenSSL cipher name: %s\n",
174 OPENSSL_cipher_name(convert
));
178 ctx
= SSL_CTX_new(meth
);
181 if (SSL_CTX_set_min_proto_version(ctx
, min_version
) == 0)
183 if (SSL_CTX_set_max_proto_version(ctx
, max_version
) == 0)
186 #ifndef OPENSSL_NO_PSK
188 SSL_CTX_set_psk_client_callback(ctx
, dummy_psk
);
190 #ifndef OPENSSL_NO_SRP
192 SSL_CTX_set_srp_client_pwd_callback(ctx
, dummy_srp
);
195 if (ciphersuites
!= NULL
&& !SSL_CTX_set_ciphersuites(ctx
, ciphersuites
)) {
196 BIO_printf(bio_err
, "Error setting TLSv1.3 ciphersuites\n");
200 if (ciphers
!= NULL
) {
201 if (!SSL_CTX_set_cipher_list(ctx
, ciphers
)) {
202 BIO_printf(bio_err
, "Error in cipher list\n");
211 sk
= SSL_get1_supported_ciphers(ssl
);
213 sk
= SSL_get_ciphers(ssl
);
216 for (i
= 0; i
< sk_SSL_CIPHER_num(sk
); i
++) {
217 const SSL_CIPHER
*c
= sk_SSL_CIPHER_value(sk
, i
);
218 p
= SSL_CIPHER_get_name(c
);
222 BIO_printf(bio_out
, ":");
223 BIO_printf(bio_out
, "%s", p
);
225 BIO_printf(bio_out
, "\n");
228 for (i
= 0; i
< sk_SSL_CIPHER_num(sk
); i
++) {
231 c
= sk_SSL_CIPHER_value(sk
, i
);
234 unsigned long id
= SSL_CIPHER_get_id(c
);
235 int id0
= (int)(id
>> 24);
236 int id1
= (int)((id
>> 16) & 0xffL
);
237 int id2
= (int)((id
>> 8) & 0xffL
);
238 int id3
= (int)(id
& 0xffL
);
240 if ((id
& 0xff000000L
) == 0x03000000L
)
241 BIO_printf(bio_out
, " 0x%02X,0x%02X - ", id2
, id3
); /* SSL3
244 BIO_printf(bio_out
, "0x%02X,0x%02X,0x%02X,0x%02X - ", id0
, id1
, id2
, id3
); /* whatever */
247 const char *nm
= SSL_CIPHER_standard_name(c
);
250 BIO_printf(bio_out
, "%s - ", nm
);
252 BIO_puts(bio_out
, SSL_CIPHER_description(c
, buf
, sizeof(buf
)));
259 ERR_print_errors(bio_err
);
262 sk_SSL_CIPHER_free(sk
);