os/ossrv/ssl/tsrc/topenssl/src/engine.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/* apps/engine.c -*- mode: C; c-file-style: "eay" -*- */
sl@0
     2
/* Written by Richard Levitte <richard@levitte.org> for the OpenSSL
sl@0
     3
 * project 2000.
sl@0
     4
 */
sl@0
     5
/* ====================================================================
sl@0
     6
 * Copyright (c) 2000 The OpenSSL Project.  All rights reserved.
sl@0
     7
 *
sl@0
     8
 * Redistribution and use in source and binary forms, with or without
sl@0
     9
 * modification, are permitted provided that the following conditions
sl@0
    10
 * are met:
sl@0
    11
 *
sl@0
    12
 * 1. Redistributions of source code must retain the above copyright
sl@0
    13
 *    notice, this list of conditions and the following disclaimer. 
sl@0
    14
 *
sl@0
    15
 * 2. Redistributions in binary form must reproduce the above copyright
sl@0
    16
 *    notice, this list of conditions and the following disclaimer in
sl@0
    17
 *    the documentation and/or other materials provided with the
sl@0
    18
 *    distribution.
sl@0
    19
 *
sl@0
    20
 * 3. All advertising materials mentioning features or use of this
sl@0
    21
 *    software must display the following acknowledgment:
sl@0
    22
 *    "This product includes software developed by the OpenSSL Project
sl@0
    23
 *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
sl@0
    24
 *
sl@0
    25
 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
sl@0
    26
 *    endorse or promote products derived from this software without
sl@0
    27
 *    prior written permission. For written permission, please contact
sl@0
    28
 *    licensing@OpenSSL.org.
sl@0
    29
 *
sl@0
    30
 * 5. Products derived from this software may not be called "OpenSSL"
sl@0
    31
 *    nor may "OpenSSL" appear in their names without prior written
sl@0
    32
 *    permission of the OpenSSL Project.
sl@0
    33
 *
sl@0
    34
 * 6. Redistributions of any form whatsoever must retain the following
sl@0
    35
 *    acknowledgment:
sl@0
    36
 *    "This product includes software developed by the OpenSSL Project
sl@0
    37
 *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
sl@0
    38
 *
sl@0
    39
 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
sl@0
    40
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
sl@0
    41
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
sl@0
    42
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
sl@0
    43
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
sl@0
    44
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
sl@0
    45
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
sl@0
    46
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
sl@0
    47
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
sl@0
    48
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
sl@0
    49
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
sl@0
    50
 * OF THE POSSIBILITY OF SUCH DAMAGE.
sl@0
    51
 * ====================================================================
sl@0
    52
 *
sl@0
    53
 * This product includes cryptographic software written by Eric Young
sl@0
    54
 * (eay@cryptsoft.com).  This product includes software written by Tim
sl@0
    55
 * Hudson (tjh@cryptsoft.com).
sl@0
    56
 *
sl@0
    57
 */
sl@0
    58
sl@0
    59
#ifndef OPENSSL_NO_ENGINE
sl@0
    60
sl@0
    61
#include <stdio.h>
sl@0
    62
#include <stdlib.h>
sl@0
    63
#include <string.h>
sl@0
    64
#ifdef OPENSSL_NO_STDIO
sl@0
    65
#define APPS_WIN16
sl@0
    66
#endif
sl@0
    67
#include "apps.h"
sl@0
    68
#include <openssl/err.h>
sl@0
    69
#include <openssl/engine.h>
sl@0
    70
#include <openssl/ssl.h>
sl@0
    71
sl@0
    72
sl@0
    73
#undef PROG
sl@0
    74
#define PROG	engine_main
sl@0
    75
sl@0
    76
static const char *engine_usage[]={
sl@0
    77
"usage: engine opts [engine ...]\n",
sl@0
    78
" -v[v[v[v]]] - verbose mode, for each engine, list its 'control commands'\n",
sl@0
    79
"               -vv will additionally display each command's description\n",
sl@0
    80
"               -vvv will also add the input flags for each command\n",
sl@0
    81
"               -vvvv will also show internal input flags\n",
sl@0
    82
" -c          - for each engine, also list the capabilities\n",
sl@0
    83
" -t[t]       - for each engine, check that they are really available\n",
sl@0
    84
"               -tt will display error trace for unavailable engines\n",
sl@0
    85
" -pre <cmd>  - runs command 'cmd' against the ENGINE before any attempts\n",
sl@0
    86
"               to load it (if -t is used)\n",
sl@0
    87
" -post <cmd> - runs command 'cmd' against the ENGINE after loading it\n",
sl@0
    88
"               (only used if -t is also provided)\n",
sl@0
    89
" NB: -pre and -post will be applied to all ENGINEs supplied on the command\n",
sl@0
    90
" line, or all supported ENGINEs if none are specified.\n",
sl@0
    91
" Eg. '-pre \"SO_PATH:/lib/libdriver.so\"' calls command \"SO_PATH\" with\n",
sl@0
    92
" argument \"/lib/libdriver.so\".\n",
sl@0
    93
NULL
sl@0
    94
};
sl@0
    95
sl@0
    96
static void identity(void *ptr)
sl@0
    97
	{
sl@0
    98
	return;
sl@0
    99
	}
sl@0
   100
sl@0
   101
static int append_buf(char **buf, const char *s, int *size, int step)
sl@0
   102
	{
sl@0
   103
	int l = strlen(s);
sl@0
   104
sl@0
   105
	if (*buf == NULL)
sl@0
   106
		{
sl@0
   107
		*size = step;
sl@0
   108
		*buf = OPENSSL_malloc(*size);
sl@0
   109
		if (*buf == NULL)
sl@0
   110
			return 0;
sl@0
   111
		**buf = '\0';
sl@0
   112
		}
sl@0
   113
sl@0
   114
	if (**buf != '\0')
sl@0
   115
		l += 2;		/* ", " */
sl@0
   116
sl@0
   117
	if (strlen(*buf) + strlen(s) >= (unsigned int)*size)
sl@0
   118
		{
sl@0
   119
		*size += step;
sl@0
   120
		*buf = OPENSSL_realloc(*buf, *size);
sl@0
   121
		}
sl@0
   122
sl@0
   123
	if (*buf == NULL)
sl@0
   124
		return 0;
sl@0
   125
sl@0
   126
	if (**buf != '\0')
sl@0
   127
		BUF_strlcat(*buf, ", ", *size);
sl@0
   128
	BUF_strlcat(*buf, s, *size);
sl@0
   129
sl@0
   130
	return 1;
sl@0
   131
	}
sl@0
   132
sl@0
   133
static int util_flags(BIO *bio_out, unsigned int flags, const char *indent)
sl@0
   134
	{
sl@0
   135
	int started = 0, err = 0;
sl@0
   136
	/* Indent before displaying input flags */
sl@0
   137
	BIO_printf(bio_out, "%s%s(input flags): ", indent, indent);
sl@0
   138
	if(flags == 0)
sl@0
   139
		{
sl@0
   140
		BIO_printf(bio_out, "<no flags>\n");
sl@0
   141
		return 1;
sl@0
   142
		}
sl@0
   143
        /* If the object is internal, mark it in a way that shows instead of
sl@0
   144
         * having it part of all the other flags, even if it really is. */
sl@0
   145
	if(flags & ENGINE_CMD_FLAG_INTERNAL)
sl@0
   146
		{
sl@0
   147
		BIO_printf(bio_out, "[Internal] ");
sl@0
   148
		}
sl@0
   149
sl@0
   150
	if(flags & ENGINE_CMD_FLAG_NUMERIC)
sl@0
   151
		{
sl@0
   152
		if(started)
sl@0
   153
			{
sl@0
   154
			BIO_printf(bio_out, "|");
sl@0
   155
			err = 1;
sl@0
   156
			}
sl@0
   157
		BIO_printf(bio_out, "NUMERIC");
sl@0
   158
		started = 1;
sl@0
   159
		}
sl@0
   160
	/* Now we check that no combinations of the mutually exclusive NUMERIC,
sl@0
   161
	 * STRING, and NO_INPUT flags have been used. Future flags that can be
sl@0
   162
	 * OR'd together with these would need to added after these to preserve
sl@0
   163
	 * the testing logic. */
sl@0
   164
	if(flags & ENGINE_CMD_FLAG_STRING)
sl@0
   165
		{
sl@0
   166
		if(started)
sl@0
   167
			{
sl@0
   168
			BIO_printf(bio_out, "|");
sl@0
   169
			err = 1;
sl@0
   170
			}
sl@0
   171
		BIO_printf(bio_out, "STRING");
sl@0
   172
		started = 1;
sl@0
   173
		}
sl@0
   174
	if(flags & ENGINE_CMD_FLAG_NO_INPUT)
sl@0
   175
		{
sl@0
   176
		if(started)
sl@0
   177
			{
sl@0
   178
			BIO_printf(bio_out, "|");
sl@0
   179
			err = 1;
sl@0
   180
			}
sl@0
   181
		BIO_printf(bio_out, "NO_INPUT");
sl@0
   182
		started = 1;
sl@0
   183
		}
sl@0
   184
	/* Check for unknown flags */
sl@0
   185
	flags = flags & ~ENGINE_CMD_FLAG_NUMERIC &
sl@0
   186
			~ENGINE_CMD_FLAG_STRING &
sl@0
   187
			~ENGINE_CMD_FLAG_NO_INPUT &
sl@0
   188
			~ENGINE_CMD_FLAG_INTERNAL;
sl@0
   189
	if(flags)
sl@0
   190
		{
sl@0
   191
		if(started) BIO_printf(bio_out, "|");
sl@0
   192
		BIO_printf(bio_out, "<0x%04X>", flags);
sl@0
   193
		}
sl@0
   194
	if(err)
sl@0
   195
		BIO_printf(bio_out, "  <illegal flags!>");
sl@0
   196
	BIO_printf(bio_out, "\n");
sl@0
   197
	return 1;
sl@0
   198
	}
sl@0
   199
sl@0
   200
static int util_verbose(ENGINE *e, int verbose, BIO *bio_out, const char *indent)
sl@0
   201
	{
sl@0
   202
	static const int line_wrap = 78;
sl@0
   203
	int num;
sl@0
   204
	int ret = 0;
sl@0
   205
	char *name = NULL;
sl@0
   206
	char *desc = NULL;
sl@0
   207
	int flags;
sl@0
   208
	int xpos = 0;
sl@0
   209
	STACK *cmds = NULL;
sl@0
   210
	if(!ENGINE_ctrl(e, ENGINE_CTRL_HAS_CTRL_FUNCTION, 0, NULL, NULL) ||
sl@0
   211
			((num = ENGINE_ctrl(e, ENGINE_CTRL_GET_FIRST_CMD_TYPE,
sl@0
   212
					0, NULL, NULL)) <= 0))
sl@0
   213
		{
sl@0
   214
#if 0
sl@0
   215
		BIO_printf(bio_out, "%s<no control commands>\n", indent);
sl@0
   216
#endif
sl@0
   217
		return 1;
sl@0
   218
		}
sl@0
   219
sl@0
   220
	cmds = sk_new_null();
sl@0
   221
sl@0
   222
	if(!cmds)
sl@0
   223
		goto err;
sl@0
   224
	do {
sl@0
   225
		int len;
sl@0
   226
		/* Get the command input flags */
sl@0
   227
		if((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, num,
sl@0
   228
					NULL, NULL)) < 0)
sl@0
   229
			goto err;
sl@0
   230
                if (!(flags & ENGINE_CMD_FLAG_INTERNAL) || verbose >= 4)
sl@0
   231
                        {
sl@0
   232
                        /* Get the command name */
sl@0
   233
                        if((len = ENGINE_ctrl(e, ENGINE_CTRL_GET_NAME_LEN_FROM_CMD, num,
sl@0
   234
                                NULL, NULL)) <= 0)
sl@0
   235
                                goto err;
sl@0
   236
                        if((name = OPENSSL_malloc(len + 1)) == NULL)
sl@0
   237
                                goto err;
sl@0
   238
                        if(ENGINE_ctrl(e, ENGINE_CTRL_GET_NAME_FROM_CMD, num, name,
sl@0
   239
                                NULL) <= 0)
sl@0
   240
                                goto err;
sl@0
   241
                        /* Get the command description */
sl@0
   242
                        if((len = ENGINE_ctrl(e, ENGINE_CTRL_GET_DESC_LEN_FROM_CMD, num,
sl@0
   243
                                NULL, NULL)) < 0)
sl@0
   244
                                goto err;
sl@0
   245
                        if(len > 0)
sl@0
   246
                                {
sl@0
   247
                                if((desc = OPENSSL_malloc(len + 1)) == NULL)
sl@0
   248
                                        goto err;
sl@0
   249
                                if(ENGINE_ctrl(e, ENGINE_CTRL_GET_DESC_FROM_CMD, num, desc,
sl@0
   250
                                        NULL) <= 0)
sl@0
   251
                                        goto err;
sl@0
   252
                                }
sl@0
   253
                        /* Now decide on the output */
sl@0
   254
                        if(xpos == 0)
sl@0
   255
                                /* Do an indent */
sl@0
   256
                                xpos = BIO_printf(bio_out, indent);
sl@0
   257
                        else
sl@0
   258
                                /* Otherwise prepend a ", " */
sl@0
   259
                                xpos += BIO_printf(bio_out, ", ");
sl@0
   260
                        if(verbose == 1)
sl@0
   261
                                {
sl@0
   262
                                /* We're just listing names, comma-delimited */
sl@0
   263
                                if((xpos > (int)strlen(indent)) &&
sl@0
   264
					(xpos + (int)strlen(name) > line_wrap))
sl@0
   265
                                        {
sl@0
   266
                                        BIO_printf(bio_out, "\n");
sl@0
   267
                                        xpos = BIO_printf(bio_out, indent);
sl@0
   268
                                        }
sl@0
   269
                                xpos += BIO_printf(bio_out, "%s", name);
sl@0
   270
                                }
sl@0
   271
                        else
sl@0
   272
                                {
sl@0
   273
                                /* We're listing names plus descriptions */
sl@0
   274
                                BIO_printf(bio_out, "%s: %s\n", name,
sl@0
   275
                                        (desc == NULL) ? "<no description>" : desc);
sl@0
   276
                                /* ... and sometimes input flags */
sl@0
   277
                                if((verbose >= 3) && !util_flags(bio_out, flags,
sl@0
   278
                                        indent))
sl@0
   279
                                        goto err;
sl@0
   280
                                xpos = 0;
sl@0
   281
                                }
sl@0
   282
                        }
sl@0
   283
		OPENSSL_free(name); name = NULL;
sl@0
   284
		if(desc) { OPENSSL_free(desc); desc = NULL; }
sl@0
   285
		/* Move to the next command */
sl@0
   286
		num = ENGINE_ctrl(e, ENGINE_CTRL_GET_NEXT_CMD_TYPE,
sl@0
   287
					num, NULL, NULL);
sl@0
   288
		} while(num > 0);
sl@0
   289
	if(xpos > 0)
sl@0
   290
		BIO_printf(bio_out, "\n");
sl@0
   291
	ret = 1;
sl@0
   292
err:
sl@0
   293
	if(cmds) sk_pop_free(cmds, identity);
sl@0
   294
	if(name) OPENSSL_free(name);
sl@0
   295
	if(desc) OPENSSL_free(desc);
sl@0
   296
	return ret;
sl@0
   297
	}
sl@0
   298
sl@0
   299
static void util_do_cmds(ENGINE *e, STACK *cmds, BIO *bio_out, const char *indent)
sl@0
   300
	{
sl@0
   301
	int loop, res, num = sk_num(cmds);
sl@0
   302
	if(num < 0)
sl@0
   303
		{
sl@0
   304
		BIO_printf(bio_out, "[Error]: internal stack error\n");
sl@0
   305
		return;
sl@0
   306
		}
sl@0
   307
	for(loop = 0; loop < num; loop++)
sl@0
   308
		{
sl@0
   309
		char buf[256];
sl@0
   310
		const char *cmd, *arg;
sl@0
   311
		cmd = sk_value(cmds, loop);
sl@0
   312
		res = 1; /* assume success */
sl@0
   313
		/* Check if this command has no ":arg" */
sl@0
   314
		if((arg = strstr(cmd, ":")) == NULL)
sl@0
   315
			{
sl@0
   316
			if(!ENGINE_ctrl_cmd_string(e, cmd, NULL, 0))
sl@0
   317
				res = 0;
sl@0
   318
			}
sl@0
   319
		else
sl@0
   320
			{
sl@0
   321
			if((int)(arg - cmd) > 254)
sl@0
   322
				{
sl@0
   323
				BIO_printf(bio_out,"[Error]: command name too long\n");
sl@0
   324
				return;
sl@0
   325
				}
sl@0
   326
			memcpy(buf, cmd, (int)(arg - cmd));
sl@0
   327
			buf[arg-cmd] = '\0';
sl@0
   328
			arg++; /* Move past the ":" */
sl@0
   329
			/* Call the command with the argument */
sl@0
   330
			if(!ENGINE_ctrl_cmd_string(e, buf, arg, 0))
sl@0
   331
				res = 0;
sl@0
   332
			}
sl@0
   333
		if(res)
sl@0
   334
			BIO_printf(bio_out, "[Success]: %s\n", cmd);
sl@0
   335
		else
sl@0
   336
			{
sl@0
   337
			BIO_printf(bio_out, "[Failure]: %s\n", cmd);
sl@0
   338
			ERR_print_errors(bio_out);
sl@0
   339
			}
sl@0
   340
		}
sl@0
   341
	}
sl@0
   342
sl@0
   343
int MAIN(int, char **);
sl@0
   344
sl@0
   345
int MAIN(int argc, char **argv)
sl@0
   346
	{
sl@0
   347
	int ret=1,i;
sl@0
   348
	const char **pp;
sl@0
   349
	int verbose=0, list_cap=0, test_avail=0, test_avail_noise = 0;
sl@0
   350
	ENGINE *e;
sl@0
   351
	STACK *engines = sk_new_null();
sl@0
   352
	STACK *pre_cmds = sk_new_null();
sl@0
   353
	STACK *post_cmds = sk_new_null();
sl@0
   354
	int badops=1;
sl@0
   355
	BIO *bio_out=NULL;
sl@0
   356
	const char *indent = "     ";
sl@0
   357
sl@0
   358
	apps_startup();
sl@0
   359
	SSL_load_error_strings();
sl@0
   360
sl@0
   361
	if (bio_err == NULL)
sl@0
   362
		bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
sl@0
   363
sl@0
   364
	if (!load_config(bio_err, NULL))
sl@0
   365
		goto end;
sl@0
   366
	bio_out=BIO_new_fp(stdout,BIO_NOCLOSE);
sl@0
   367
sl@0
   368
#ifdef OPENSSL_SYS_VMS
sl@0
   369
	{
sl@0
   370
	BIO *tmpbio = BIO_new(BIO_f_linebuffer());
sl@0
   371
	bio_out = BIO_push(tmpbio, bio_out);
sl@0
   372
	}
sl@0
   373
#endif
sl@0
   374
sl@0
   375
	argc--;
sl@0
   376
	argv++;
sl@0
   377
	while (argc >= 1)
sl@0
   378
		{
sl@0
   379
		if (strncmp(*argv,"-v",2) == 0)
sl@0
   380
			{
sl@0
   381
			if(strspn(*argv + 1, "v") < strlen(*argv + 1))
sl@0
   382
				goto skip_arg_loop;
sl@0
   383
			if((verbose=strlen(*argv + 1)) > 4)
sl@0
   384
				goto skip_arg_loop;
sl@0
   385
			}
sl@0
   386
		else if (strcmp(*argv,"-c") == 0)
sl@0
   387
			list_cap=1;
sl@0
   388
		else if (strncmp(*argv,"-t",2) == 0)
sl@0
   389
			{
sl@0
   390
			test_avail=1;
sl@0
   391
			if(strspn(*argv + 1, "t") < strlen(*argv + 1))
sl@0
   392
				goto skip_arg_loop;
sl@0
   393
			if((test_avail_noise = strlen(*argv + 1) - 1) > 1)
sl@0
   394
				goto skip_arg_loop;
sl@0
   395
			}
sl@0
   396
		else if (strcmp(*argv,"-pre") == 0)
sl@0
   397
			{
sl@0
   398
			argc--; argv++;
sl@0
   399
			if (argc == 0)
sl@0
   400
				goto skip_arg_loop;
sl@0
   401
			sk_push(pre_cmds,*argv);
sl@0
   402
			}
sl@0
   403
		else if (strcmp(*argv,"-post") == 0)
sl@0
   404
			{
sl@0
   405
			argc--; argv++;
sl@0
   406
			if (argc == 0)
sl@0
   407
				goto skip_arg_loop;
sl@0
   408
			sk_push(post_cmds,*argv);
sl@0
   409
			}
sl@0
   410
		else if ((strncmp(*argv,"-h",2) == 0) ||
sl@0
   411
				(strcmp(*argv,"-?") == 0))
sl@0
   412
			goto skip_arg_loop;
sl@0
   413
		else
sl@0
   414
			sk_push(engines,*argv);
sl@0
   415
		argc--;
sl@0
   416
		argv++;
sl@0
   417
		}
sl@0
   418
	/* Looks like everything went OK */
sl@0
   419
	badops = 0;
sl@0
   420
skip_arg_loop:
sl@0
   421
sl@0
   422
	if (badops)
sl@0
   423
		{
sl@0
   424
		for (pp=engine_usage; (*pp != NULL); pp++)
sl@0
   425
			BIO_printf(bio_err,"%s",*pp);
sl@0
   426
		goto end;
sl@0
   427
		}
sl@0
   428
sl@0
   429
	if (sk_num(engines) == 0)
sl@0
   430
		{
sl@0
   431
		for(e = ENGINE_get_first(); e != NULL; e = ENGINE_get_next(e))
sl@0
   432
			{
sl@0
   433
			sk_push(engines,(char *)ENGINE_get_id(e));
sl@0
   434
			}
sl@0
   435
		}
sl@0
   436
sl@0
   437
	for (i=0; i<sk_num(engines); i++)
sl@0
   438
		{
sl@0
   439
		const char *id = sk_value(engines,i);
sl@0
   440
		if ((e = ENGINE_by_id(id)) != NULL)
sl@0
   441
			{
sl@0
   442
			const char *name = ENGINE_get_name(e);
sl@0
   443
			/* Do "id" first, then "name". Easier to auto-parse. */
sl@0
   444
			BIO_printf(bio_out, "(%s) %s\n", id, name);
sl@0
   445
			util_do_cmds(e, pre_cmds, bio_out, indent);
sl@0
   446
			if (strcmp(ENGINE_get_id(e), id) != 0)
sl@0
   447
				{
sl@0
   448
				BIO_printf(bio_out, "Loaded: (%s) %s\n",
sl@0
   449
					ENGINE_get_id(e), ENGINE_get_name(e));
sl@0
   450
				}
sl@0
   451
			if (list_cap)
sl@0
   452
				{
sl@0
   453
				int cap_size = 256;
sl@0
   454
				char *cap_buf = NULL;
sl@0
   455
				int k,n;
sl@0
   456
				const int *nids;
sl@0
   457
				ENGINE_CIPHERS_PTR fn_c;
sl@0
   458
				ENGINE_DIGESTS_PTR fn_d;
sl@0
   459
sl@0
   460
				if (ENGINE_get_RSA(e) != NULL
sl@0
   461
					&& !append_buf(&cap_buf, "RSA",
sl@0
   462
						&cap_size, 256))
sl@0
   463
					goto end;
sl@0
   464
				if (ENGINE_get_DSA(e) != NULL
sl@0
   465
					&& !append_buf(&cap_buf, "DSA",
sl@0
   466
						&cap_size, 256))
sl@0
   467
					goto end;
sl@0
   468
				if (ENGINE_get_DH(e) != NULL
sl@0
   469
					&& !append_buf(&cap_buf, "DH",
sl@0
   470
						&cap_size, 256))
sl@0
   471
					goto end;
sl@0
   472
				if (ENGINE_get_RAND(e) != NULL
sl@0
   473
					&& !append_buf(&cap_buf, "RAND",
sl@0
   474
						&cap_size, 256))
sl@0
   475
					goto end;
sl@0
   476
sl@0
   477
				fn_c = ENGINE_get_ciphers(e);
sl@0
   478
				if(!fn_c) goto skip_ciphers;
sl@0
   479
				n = fn_c(e, NULL, &nids, 0);
sl@0
   480
				for(k=0 ; k < n ; ++k)
sl@0
   481
					if(!append_buf(&cap_buf,
sl@0
   482
						       OBJ_nid2sn(nids[k]),
sl@0
   483
						       &cap_size, 256))
sl@0
   484
						goto end;
sl@0
   485
sl@0
   486
skip_ciphers:
sl@0
   487
				fn_d = ENGINE_get_digests(e);
sl@0
   488
				if(!fn_d) goto skip_digests;
sl@0
   489
				n = fn_d(e, NULL, &nids, 0);
sl@0
   490
				for(k=0 ; k < n ; ++k)
sl@0
   491
					if(!append_buf(&cap_buf,
sl@0
   492
						       OBJ_nid2sn(nids[k]),
sl@0
   493
						       &cap_size, 256))
sl@0
   494
						goto end;
sl@0
   495
sl@0
   496
skip_digests:
sl@0
   497
				if (cap_buf && (*cap_buf != '\0'))
sl@0
   498
					BIO_printf(bio_out, " [%s]\n", cap_buf);
sl@0
   499
sl@0
   500
				OPENSSL_free(cap_buf);
sl@0
   501
				}
sl@0
   502
			if(test_avail)
sl@0
   503
				{
sl@0
   504
				BIO_printf(bio_out, "%s", indent);
sl@0
   505
				if (ENGINE_init(e))
sl@0
   506
					{
sl@0
   507
					BIO_printf(bio_out, "[ available ]\n");
sl@0
   508
					util_do_cmds(e, post_cmds, bio_out, indent);
sl@0
   509
					ENGINE_finish(e);
sl@0
   510
					}
sl@0
   511
				else
sl@0
   512
					{
sl@0
   513
					BIO_printf(bio_out, "[ unavailable ]\n");
sl@0
   514
					if(test_avail_noise)
sl@0
   515
					ERR_print_errors_fp(stdout);
sl@0
   516
					ERR_clear_error();
sl@0
   517
					}
sl@0
   518
				}
sl@0
   519
			if((verbose > 0) && !util_verbose(e, verbose, bio_out, indent))
sl@0
   520
				goto end;
sl@0
   521
			ENGINE_free(e);
sl@0
   522
			}
sl@0
   523
		else
sl@0
   524
			ERR_print_errors(bio_err);
sl@0
   525
		}
sl@0
   526
sl@0
   527
	ret=0;
sl@0
   528
end:
sl@0
   529
sl@0
   530
	ERR_print_errors(bio_err);
sl@0
   531
	sk_pop_free(engines, identity);
sl@0
   532
	sk_pop_free(pre_cmds, identity);
sl@0
   533
	sk_pop_free(post_cmds, identity);
sl@0
   534
	if (bio_out != NULL) BIO_free_all(bio_out);
sl@0
   535
	apps_shutdown();
sl@0
   536
	OPENSSL_EXIT(ret);
sl@0
   537
	}
sl@0
   538
#else
sl@0
   539
sl@0
   540
# if PEDANTIC
sl@0
   541
static void *dummy=&dummy;
sl@0
   542
# endif
sl@0
   543
sl@0
   544
#endif