00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 #include <stdio.h>
00060 #include <stdlib.h>
00061 #include <string.h>
00062 #ifdef OPENSSL_NO_STDIO
00063 #define APPS_WIN16
00064 #endif
00065 #include "apps.h"
00066 #include <openssl/err.h>
00067 #include <openssl/ssl.h>
00068
00069 #undef PROG
00070 #define PROG ciphers_main
00071
00072 static const char *ciphers_usage[]={
00073 "usage: ciphers args\n",
00074 " -v - verbose mode, a textual listing of the ciphers in SSLeay\n",
00075 " -ssl2 - SSL2 mode\n",
00076 " -ssl3 - SSL3 mode\n",
00077 " -tls1 - TLS1 mode\n",
00078 NULL
00079 };
00080
00081 int MAIN(int, char **);
00082
00083 int MAIN(int argc, char **argv)
00084 {
00085 int ret=1,i;
00086 int verbose=0;
00087 const char **pp;
00088 const char *p;
00089 int badops=0;
00090 SSL_CTX *ctx=NULL;
00091 SSL *ssl=NULL;
00092 char *ciphers=NULL;
00093 SSL_METHOD *meth=NULL;
00094 STACK_OF(SSL_CIPHER) *sk;
00095 char buf[512];
00096 BIO *STDout=NULL;
00097
00098 #if !defined(OPENSSL_NO_SSL2) && !defined(OPENSSL_NO_SSL3)
00099 meth=SSLv23_server_method();
00100 #elif !defined(OPENSSL_NO_SSL3)
00101 meth=SSLv3_server_method();
00102 #elif !defined(OPENSSL_NO_SSL2)
00103 meth=SSLv2_server_method();
00104 #endif
00105
00106 apps_startup();
00107
00108 if (bio_err == NULL)
00109 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
00110 STDout=BIO_new_fp(stdout,BIO_NOCLOSE);
00111 #ifdef OPENSSL_SYS_VMS
00112 {
00113 BIO *tmpbio = BIO_new(BIO_f_linebuffer());
00114 STDout = BIO_push(tmpbio, STDout);
00115 }
00116 #endif
00117
00118 argc--;
00119 argv++;
00120 while (argc >= 1)
00121 {
00122 if (strcmp(*argv,"-v") == 0)
00123 verbose=1;
00124 #ifndef OPENSSL_NO_SSL2
00125 else if (strcmp(*argv,"-ssl2") == 0)
00126 meth=SSLv2_client_method();
00127 #endif
00128 #ifndef OPENSSL_NO_SSL3
00129 else if (strcmp(*argv,"-ssl3") == 0)
00130 meth=SSLv3_client_method();
00131 #endif
00132 #ifndef OPENSSL_NO_TLS1
00133 else if (strcmp(*argv,"-tls1") == 0)
00134 meth=TLSv1_client_method();
00135 #endif
00136 else if ((strncmp(*argv,"-h",2) == 0) ||
00137 (strcmp(*argv,"-?") == 0))
00138 {
00139 badops=1;
00140 break;
00141 }
00142 else
00143 {
00144 ciphers= *argv;
00145 }
00146 argc--;
00147 argv++;
00148 }
00149
00150 if (badops)
00151 {
00152 for (pp=ciphers_usage; (*pp != NULL); pp++)
00153 BIO_printf(bio_err,"%s",*pp);
00154 goto end;
00155 }
00156
00157 OpenSSL_add_ssl_algorithms();
00158
00159 ctx=SSL_CTX_new(meth);
00160 if (ctx == NULL) goto err;
00161 if (ciphers != NULL) {
00162 if(!SSL_CTX_set_cipher_list(ctx,ciphers)) {
00163 BIO_printf(bio_err, "Error in cipher list\n");
00164 goto err;
00165 }
00166 }
00167 ssl=SSL_new(ctx);
00168 if (ssl == NULL) goto err;
00169
00170
00171 if (!verbose)
00172 {
00173 for (i=0; ; i++)
00174 {
00175 p=SSL_get_cipher_list(ssl,i);
00176 if (p == NULL) break;
00177 if (i != 0) BIO_printf(STDout,":");
00178 BIO_printf(STDout,"%s",p);
00179 }
00180 BIO_printf(STDout,"\n");
00181 }
00182 else
00183 {
00184 sk=SSL_get_ciphers(ssl);
00185
00186 for (i=0; i<sk_SSL_CIPHER_num(sk); i++)
00187 {
00188 BIO_puts(STDout,SSL_CIPHER_description(
00189 sk_SSL_CIPHER_value(sk,i),
00190 buf,sizeof buf));
00191 }
00192 }
00193
00194 ret=0;
00195 if (0)
00196 {
00197 err:
00198 SSL_load_error_strings();
00199 ERR_print_errors(bio_err);
00200 }
00201 end:
00202 if (ctx != NULL) SSL_CTX_free(ctx);
00203 if (ssl != NULL) SSL_free(ssl);
00204 if (STDout != NULL) BIO_free_all(STDout);
00205 apps_shutdown();
00206 OPENSSL_EXIT(ret);
00207 }
00208