?? engine.c
字號:
/* apps/engine.c -*- mode: C; c-file-style: "eay" -*- *//* Written by Richard Levitte <richard@levitte.org> for the OpenSSL * project 2000. *//* ==================================================================== * Copyright (c) 2000 The OpenSSL Project. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. All advertising materials mentioning features or use of this * software must display the following acknowledgment: * "This product includes software developed by the OpenSSL Project * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" * * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to * endorse or promote products derived from this software without * prior written permission. For written permission, please contact * licensing@OpenSSL.org. * * 5. Products derived from this software may not be called "OpenSSL" * nor may "OpenSSL" appear in their names without prior written * permission of the OpenSSL Project. * * 6. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by the OpenSSL Project * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" * * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * ==================================================================== * * This product includes cryptographic software written by Eric Young * (eay@cryptsoft.com). This product includes software written by Tim * Hudson (tjh@cryptsoft.com). * */#ifndef OPENSSL_NO_ENGINE#include <stdio.h>#include <stdlib.h>#include <string.h>#ifdef OPENSSL_NO_STDIO#define APPS_WIN16#endif#include "apps.h"#include <openssl/err.h>#include <openssl/engine.h>#include <openssl/ssl.h>#undef PROG#define PROG engine_mainstatic const char *engine_usage[]={"usage: engine opts [engine ...]\n"," -v[v[v[v]]] - verbose mode, for each engine, list its 'control commands'\n"," -vv will additionally display each command's description\n"," -vvv will also add the input flags for each command\n"," -vvvv will also show internal input flags\n"," -c - for each engine, also list the capabilities\n"," -t[t] - for each engine, check that they are really available\n"," -tt will display error trace for unavailable engines\n"," -pre <cmd> - runs command 'cmd' against the ENGINE before any attempts\n"," to load it (if -t is used)\n"," -post <cmd> - runs command 'cmd' against the ENGINE after loading it\n"," (only used if -t is also provided)\n"," NB: -pre and -post will be applied to all ENGINEs supplied on the command\n"," line, or all supported ENGINEs if none are specified.\n"," Eg. '-pre \"SO_PATH:/lib/libdriver.so\"' calls command \"SO_PATH\" with\n"," argument \"/lib/libdriver.so\".\n",NULL};static void identity(void *ptr) { return; }static int append_buf(char **buf, const char *s, int *size, int step) { int l = strlen(s); if (*buf == NULL) { *size = step; *buf = OPENSSL_malloc(*size); if (*buf == NULL) return 0; **buf = '\0'; } if (**buf != '\0') l += 2; /* ", " */ if (strlen(*buf) + strlen(s) >= (unsigned int)*size) { *size += step; *buf = OPENSSL_realloc(*buf, *size); } if (*buf == NULL) return 0; if (**buf != '\0') BUF_strlcat(*buf, ", ", *size); BUF_strlcat(*buf, s, *size); return 1; }static int util_flags(BIO *bio_out, unsigned int flags, const char *indent) { int started = 0, err = 0; /* Indent before displaying input flags */ BIO_printf(bio_out, "%s%s(input flags): ", indent, indent); if(flags == 0) { BIO_printf(bio_out, "<no flags>\n"); return 1; } /* If the object is internal, mark it in a way that shows instead of * having it part of all the other flags, even if it really is. */ if(flags & ENGINE_CMD_FLAG_INTERNAL) { BIO_printf(bio_out, "[Internal] "); } if(flags & ENGINE_CMD_FLAG_NUMERIC) { if(started) { BIO_printf(bio_out, "|"); err = 1; } BIO_printf(bio_out, "NUMERIC"); started = 1; } /* Now we check that no combinations of the mutually exclusive NUMERIC, * STRING, and NO_INPUT flags have been used. Future flags that can be * OR'd together with these would need to added after these to preserve * the testing logic. */ if(flags & ENGINE_CMD_FLAG_STRING) { if(started) { BIO_printf(bio_out, "|"); err = 1; } BIO_printf(bio_out, "STRING"); started = 1; } if(flags & ENGINE_CMD_FLAG_NO_INPUT) { if(started) { BIO_printf(bio_out, "|"); err = 1; } BIO_printf(bio_out, "NO_INPUT"); started = 1; } /* Check for unknown flags */ flags = flags & ~ENGINE_CMD_FLAG_NUMERIC & ~ENGINE_CMD_FLAG_STRING & ~ENGINE_CMD_FLAG_NO_INPUT & ~ENGINE_CMD_FLAG_INTERNAL; if(flags) { if(started) BIO_printf(bio_out, "|"); BIO_printf(bio_out, "<0x%04X>", flags); } if(err) BIO_printf(bio_out, " <illegal flags!>"); BIO_printf(bio_out, "\n"); return 1; }static int util_verbose(ENGINE *e, int verbose, BIO *bio_out, const char *indent) { static const int line_wrap = 78; int num; int ret = 0; char *name = NULL; char *desc = NULL; int flags; int xpos = 0; STACK *cmds = NULL; if(!ENGINE_ctrl(e, ENGINE_CTRL_HAS_CTRL_FUNCTION, 0, NULL, NULL) || ((num = ENGINE_ctrl(e, ENGINE_CTRL_GET_FIRST_CMD_TYPE, 0, NULL, NULL)) <= 0)) {#if 0 BIO_printf(bio_out, "%s<no control commands>\n", indent);#endif return 1; } cmds = sk_new_null(); if(!cmds) goto err; do { int len; /* Get the command input flags */ if((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, num, NULL, NULL)) < 0) goto err; if (!(flags & ENGINE_CMD_FLAG_INTERNAL) || verbose >= 4) { /* Get the command name */ if((len = ENGINE_ctrl(e, ENGINE_CTRL_GET_NAME_LEN_FROM_CMD, num, NULL, NULL)) <= 0) goto err; if((name = OPENSSL_malloc(len + 1)) == NULL) goto err; if(ENGINE_ctrl(e, ENGINE_CTRL_GET_NAME_FROM_CMD, num, name, NULL) <= 0) goto err; /* Get the command description */ if((len = ENGINE_ctrl(e, ENGINE_CTRL_GET_DESC_LEN_FROM_CMD, num, NULL, NULL)) < 0) goto err; if(len > 0) { if((desc = OPENSSL_malloc(len + 1)) == NULL) goto err; if(ENGINE_ctrl(e, ENGINE_CTRL_GET_DESC_FROM_CMD, num, desc, NULL) <= 0) goto err; } /* Now decide on the output */ if(xpos == 0) /* Do an indent */ xpos = BIO_printf(bio_out, indent); else /* Otherwise prepend a ", " */ xpos += BIO_printf(bio_out, ", "); if(verbose == 1) { /* We're just listing names, comma-delimited */ if((xpos > (int)strlen(indent)) && (xpos + (int)strlen(name) > line_wrap)) { BIO_printf(bio_out, "\n"); xpos = BIO_printf(bio_out, indent); } xpos += BIO_printf(bio_out, "%s", name); } else { /* We're listing names plus descriptions */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -