Main Page | Class List | Directories | File List | Class Members | File Members

ciphers.c

Go to the documentation of this file.
00001 /* apps/ciphers.c */
00002 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
00003  * All rights reserved.
00004  *
00005  * This package is an SSL implementation written
00006  * by Eric Young (eay@cryptsoft.com).
00007  * The implementation was written so as to conform with Netscapes SSL.
00008  * 
00009  * This library is free for commercial and non-commercial use as long as
00010  * the following conditions are aheared to.  The following conditions
00011  * apply to all code found in this distribution, be it the RC4, RSA,
00012  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
00013  * included with this distribution is covered by the same copyright terms
00014  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
00015  * 
00016  * Copyright remains Eric Young's, and as such any Copyright notices in
00017  * the code are not to be removed.
00018  * If this package is used in a product, Eric Young should be given attribution
00019  * as the author of the parts of the library used.
00020  * This can be in the form of a textual message at program startup or
00021  * in documentation (online or textual) provided with the package.
00022  * 
00023  * Redistribution and use in source and binary forms, with or without
00024  * modification, are permitted provided that the following conditions
00025  * are met:
00026  * 1. Redistributions of source code must retain the copyright
00027  *    notice, this list of conditions and the following disclaimer.
00028  * 2. Redistributions in binary form must reproduce the above copyright
00029  *    notice, this list of conditions and the following disclaimer in the
00030  *    documentation and/or other materials provided with the distribution.
00031  * 3. All advertising materials mentioning features or use of this software
00032  *    must display the following acknowledgement:
00033  *    "This product includes cryptographic software written by
00034  *     Eric Young (eay@cryptsoft.com)"
00035  *    The word 'cryptographic' can be left out if the rouines from the library
00036  *    being used are not cryptographic related :-).
00037  * 4. If you include any Windows specific code (or a derivative thereof) from 
00038  *    the apps directory (application code) you must include an acknowledgement:
00039  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
00040  * 
00041  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
00042  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00043  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00044  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
00045  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00046  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00047  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00048  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00049  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00050  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00051  * SUCH DAMAGE.
00052  * 
00053  * The licence and distribution terms for any publically available version or
00054  * derivative of this code cannot be changed.  i.e. this code cannot simply be
00055  * copied and put under another distribution licence
00056  * [including the GNU Public Licence.]
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 

© sourcejam.com 2005-2008