X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=apps%2Fsess_id.c;h=41c3b3f4a3ab649ba05ae3580b8ecbdc7bc292d3;hp=03a8f46dfb3355d4310e769e479145a20b9d21c5;hb=ca80756c70ad8f05ccd5d37c01c38641f7da3d3d;hpb=d02b48c63a58ea4367a0e905979f140b7d090f86;ds=inline diff --git a/apps/sess_id.c b/apps/sess_id.c index 03a8f46dfb..41c3b3f4a3 100644 --- a/apps/sess_id.c +++ b/apps/sess_id.c @@ -1,5 +1,5 @@ /* apps/sess_id.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written @@ -60,48 +60,40 @@ #include #include #include "apps.h" -#include "bio.h" -#include "err.h" -#include "x509.h" -#include "pem.h" -#include "ssl.h" +#include +#include +#include +#include +#include #undef PROG #define PROG sess_id_main -#define FORMAT_UNDEF 0 -#define FORMAT_ASN1 1 -#define FORMAT_TEXT 2 -#define FORMAT_PEM 3 - static char *sess_id_usage[]={ -"usage: crl args\n", +"usage: sess_id args\n", "\n", -" -inform arg - input format - default PEM (one of DER, TXT or PEM)\n", +" -inform arg - input format - default PEM (DER or PEM)\n", " -outform arg - output format - default PEM\n", " -in arg - input file - default stdin\n", " -out arg - output file - default stdout\n", " -text - print ssl session id details\n", -" -cert - output certificaet \n", +" -cert - output certificate \n", " -noout - no CRL output\n", +" -context arg - set the session ID context\n", NULL }; -#ifndef NOPROTO static SSL_SESSION *load_sess_id(char *file, int format); -#else -static SSL_SESSION *load_sess_id(); -#endif -int MAIN(argc, argv) -int argc; -char **argv; +int MAIN(int, char **); + +int MAIN(int argc, char **argv) { SSL_SESSION *x=NULL; int ret=1,i,num,badops=0; BIO *out=NULL; int informat,outformat; - char *infile=NULL,*outfile=NULL; + char *infile=NULL,*outfile=NULL,*context=NULL; int cert=0,noout=0,text=0; char **pp; @@ -109,7 +101,7 @@ char **argv; if (bio_err == NULL) if ((bio_err=BIO_new(BIO_s_file())) != NULL) - BIO_set_fp(bio_err,stderr,BIO_NOCLOSE); + BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); informat=FORMAT_PEM; outformat=FORMAT_PEM; @@ -145,6 +137,11 @@ char **argv; cert= ++num; else if (strcmp(*argv,"-noout") == 0) noout= ++num; + else if (strcmp(*argv,"-context") == 0) + { + if(--argc < 1) goto bad; + context=*++argv; + } else { BIO_printf(bio_err,"unknown option %s\n",*argv); @@ -159,7 +156,7 @@ char **argv; { bad: for (pp=sess_id_usage; (*pp != NULL); pp++) - BIO_printf(bio_err,*pp); + BIO_printf(bio_err,"%s",*pp); goto end; } @@ -167,6 +164,17 @@ bad: x=load_sess_id(infile,informat); if (x == NULL) { goto end; } + if(context) + { + x->sid_ctx_length=strlen(context); + if(x->sid_ctx_length > SSL_MAX_SID_CTX_LENGTH) + { + BIO_printf(bio_err,"Context too long\n"); + goto end; + } + memcpy(x->sid_ctx,context,x->sid_ctx_length); + } + #ifdef undef /* just testing for memory leaks :-) */ { @@ -198,7 +206,15 @@ bad: } if (outfile == NULL) + { BIO_set_fp(out,stdout,BIO_NOCLOSE); +#ifdef OPENSSL_SYS_VMS + { + BIO *tmpbio = BIO_new(BIO_f_linebuffer()); + out = BIO_push(tmpbio, out); + } +#endif + } else { if (BIO_write_filename(out,outfile) <= 0) @@ -254,14 +270,13 @@ bad: } ret=0; end: - if (out != NULL) BIO_free(out); + if (out != NULL) BIO_free_all(out); if (x != NULL) SSL_SESSION_free(x); + apps_shutdown(); EXIT(ret); } -static SSL_SESSION *load_sess_id(infile, format) -char *infile; -int format; +static SSL_SESSION *load_sess_id(char *infile, int format) { SSL_SESSION *x=NULL; BIO *in=NULL; @@ -286,7 +301,7 @@ int format; if (format == FORMAT_ASN1) x=d2i_SSL_SESSION_bio(in,NULL); else if (format == FORMAT_PEM) - x=PEM_read_bio_SSL_SESSION(in,NULL,NULL); + x=PEM_read_bio_SSL_SESSION(in,NULL,NULL,NULL); else { BIO_printf(bio_err,"bad input format specified for input crl\n"); goto end;