1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ssl/tsrc/topenssl/src/ciphers.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,209 @@
1.4 +/* apps/ciphers.c */
1.5 +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
1.6 + * All rights reserved.
1.7 + *
1.8 + * This package is an SSL implementation written
1.9 + * by Eric Young (eay@cryptsoft.com).
1.10 + * The implementation was written so as to conform with Netscapes SSL.
1.11 + *
1.12 + * This library is free for commercial and non-commercial use as long as
1.13 + * the following conditions are aheared to. The following conditions
1.14 + * apply to all code found in this distribution, be it the RC4, RSA,
1.15 + * lhash, DES, etc., code; not just the SSL code. The SSL documentation
1.16 + * included with this distribution is covered by the same copyright terms
1.17 + * except that the holder is Tim Hudson (tjh@cryptsoft.com).
1.18 + *
1.19 + * Copyright remains Eric Young's, and as such any Copyright notices in
1.20 + * the code are not to be removed.
1.21 + * If this package is used in a product, Eric Young should be given attribution
1.22 + * as the author of the parts of the library used.
1.23 + * This can be in the form of a textual message at program startup or
1.24 + * in documentation (online or textual) provided with the package.
1.25 + *
1.26 + * Redistribution and use in source and binary forms, with or without
1.27 + * modification, are permitted provided that the following conditions
1.28 + * are met:
1.29 + * 1. Redistributions of source code must retain the copyright
1.30 + * notice, this list of conditions and the following disclaimer.
1.31 + * 2. Redistributions in binary form must reproduce the above copyright
1.32 + * notice, this list of conditions and the following disclaimer in the
1.33 + * documentation and/or other materials provided with the distribution.
1.34 + * 3. All advertising materials mentioning features or use of this software
1.35 + * must display the following acknowledgement:
1.36 + * "This product includes cryptographic software written by
1.37 + * Eric Young (eay@cryptsoft.com)"
1.38 + * The word 'cryptographic' can be left out if the rouines from the library
1.39 + * being used are not cryptographic related :-).
1.40 + * 4. If you include any Windows specific code (or a derivative thereof) from
1.41 + * the apps directory (application code) you must include an acknowledgement:
1.42 + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
1.43 + *
1.44 + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
1.45 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1.46 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1.47 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1.48 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1.49 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1.50 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1.51 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1.52 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1.53 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1.54 + * SUCH DAMAGE.
1.55 + *
1.56 + * The licence and distribution terms for any publically available version or
1.57 + * derivative of this code cannot be changed. i.e. this code cannot simply be
1.58 + * copied and put under another distribution licence
1.59 + * [including the GNU Public Licence.]
1.60 + */
1.61 +
1.62 +#include <stdio.h>
1.63 +#include <stdlib.h>
1.64 +#include <string.h>
1.65 +#ifdef OPENSSL_NO_STDIO
1.66 +#define APPS_WIN16
1.67 +#endif
1.68 +#include "apps.h"
1.69 +#include <openssl/err.h>
1.70 +#include <openssl/ssl.h>
1.71 +
1.72 +#undef PROG
1.73 +#define PROG ciphers_main
1.74 +
1.75 +static const char *ciphers_usage[]={
1.76 +"usage: ciphers args\n",
1.77 +" -v - verbose mode, a textual listing of the ciphers in SSLeay\n",
1.78 +" -ssl2 - SSL2 mode\n",
1.79 +" -ssl3 - SSL3 mode\n",
1.80 +" -tls1 - TLS1 mode\n",
1.81 +NULL
1.82 +};
1.83 +
1.84 +int MAIN(int, char **);
1.85 +
1.86 +int MAIN(int argc, char **argv)
1.87 + {
1.88 + int ret=1,i;
1.89 + int verbose=0;
1.90 + const char **pp;
1.91 + const char *p;
1.92 + int badops=0;
1.93 + SSL_CTX *ctx=NULL;
1.94 + SSL *ssl=NULL;
1.95 + char *ciphers=NULL;
1.96 + SSL_METHOD *meth=NULL;
1.97 + STACK_OF(SSL_CIPHER) *sk;
1.98 + char buf[512];
1.99 + BIO *STDout=NULL;
1.100 +
1.101 +#if !defined(OPENSSL_NO_SSL2) && !defined(OPENSSL_NO_SSL3)
1.102 + meth=SSLv23_server_method();
1.103 +#elif !defined(OPENSSL_NO_SSL3)
1.104 + meth=SSLv3_server_method();
1.105 +#elif !defined(OPENSSL_NO_SSL2)
1.106 + meth=SSLv2_server_method();
1.107 +#endif
1.108 +
1.109 + apps_startup();
1.110 +
1.111 + if (bio_err == NULL)
1.112 + bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
1.113 + STDout=BIO_new_fp(stdout,BIO_NOCLOSE);
1.114 +
1.115 +#ifdef OPENSSL_SYS_VMS
1.116 + {
1.117 + BIO *tmpbio = BIO_new(BIO_f_linebuffer());
1.118 + STDout = BIO_push(tmpbio, STDout);
1.119 + }
1.120 +#endif
1.121 +
1.122 + argc--;
1.123 + argv++;
1.124 + while (argc >= 1)
1.125 + {
1.126 + if (strcmp(*argv,"-v") == 0)
1.127 + verbose=1;
1.128 +#ifndef OPENSSL_NO_SSL2
1.129 + else if (strcmp(*argv,"-ssl2") == 0)
1.130 + meth=SSLv2_client_method();
1.131 +#endif
1.132 +#ifndef OPENSSL_NO_SSL3
1.133 + else if (strcmp(*argv,"-ssl3") == 0)
1.134 + meth=SSLv3_client_method();
1.135 +#endif
1.136 +#ifndef OPENSSL_NO_TLS1
1.137 + else if (strcmp(*argv,"-tls1") == 0)
1.138 + meth=TLSv1_client_method();
1.139 +#endif
1.140 + else if ((strncmp(*argv,"-h",2) == 0) ||
1.141 + (strcmp(*argv,"-?") == 0))
1.142 + {
1.143 + badops=1;
1.144 + break;
1.145 + }
1.146 + else
1.147 + {
1.148 + ciphers= *argv;
1.149 + }
1.150 + argc--;
1.151 + argv++;
1.152 + }
1.153 +
1.154 + if (badops)
1.155 + {
1.156 + for (pp=ciphers_usage; (*pp != NULL); pp++)
1.157 + BIO_printf(bio_err,"%s",*pp);
1.158 + goto end;
1.159 + }
1.160 +
1.161 + OpenSSL_add_ssl_algorithms();
1.162 +
1.163 + ctx=SSL_CTX_new(meth);
1.164 + if (ctx == NULL) goto err;
1.165 + if (ciphers != NULL) {
1.166 + if(!SSL_CTX_set_cipher_list(ctx,ciphers)) {
1.167 + BIO_printf(bio_err, "Error in cipher list\n");
1.168 + goto err;
1.169 + }
1.170 + }
1.171 + ssl=SSL_new(ctx);
1.172 + if (ssl == NULL) goto err;
1.173 +
1.174 +
1.175 + if (!verbose)
1.176 + {
1.177 + for (i=0; ; i++)
1.178 + {
1.179 + p=SSL_get_cipher_list(ssl,i);
1.180 + if (p == NULL) break;
1.181 + if (i != 0) BIO_printf(STDout,":");
1.182 + BIO_printf(STDout,"%s",p);
1.183 + }
1.184 + BIO_printf(STDout,"\n");
1.185 + }
1.186 + else
1.187 + {
1.188 + sk=SSL_get_ciphers(ssl);
1.189 +
1.190 + for (i=0; i<sk_SSL_CIPHER_num(sk); i++)
1.191 + {
1.192 + BIO_puts(STDout,SSL_CIPHER_description(
1.193 + sk_SSL_CIPHER_value(sk,i),
1.194 + buf,sizeof buf));
1.195 + }
1.196 + }
1.197 +
1.198 + ret=0;
1.199 + if (0)
1.200 + {
1.201 +err:
1.202 + SSL_load_error_strings();
1.203 + ERR_print_errors(bio_err);
1.204 + }
1.205 +end:
1.206 + if (ctx != NULL) SSL_CTX_free(ctx);
1.207 + if (ssl != NULL) SSL_free(ssl);
1.208 + if (STDout != NULL) BIO_free_all(STDout);
1.209 + apps_shutdown();
1.210 + OPENSSL_EXIT(ret);
1.211 + }
1.212 +