summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2019-04-09 14:39:54 +0200
committerRichard Levitte <levitte@openssl.org>2019-04-23 15:51:39 +0200
commit0109e030db9207a47e195b4c3a3b13e9017f0ed2 (patch)
tree835826a1f94de53d09cb15c8752ce428ffdd0b46 /apps
parent47ca8338358b01ef429a3801ce6173f7a0791674 (diff)
Add a way for the application to get OpenSSL configuration data
OpenSSL_version(OPENSSL_DIR) gives you a nicely formatted string for display, but if all you really want is the directory itself, you were forced to parsed the string. This introduces a new function to get diverse configuration data from the library, OPENSSL_info(). This works the same way as OpenSSL_version(), but has its own series of types, currently including: OPENSSL_INFO_CONFIG_DIR returns OPENSSLDIR OPENSSL_INFO_ENGINES_DIR returns ENGINESDIR OPENSSL_INFO_MODULES_DIR returns MODULESDIR OPENSSL_INFO_DSO_EXTENSION returns DSO_EXTENSION OPENSSL_INFO_DIR_FILENAME_SEPARATOR returns directory/filename separator OPENSSL_INFO_LIST_SEPARATOR returns list separator For scripting purposes, this also adds the command 'openssl info'. Reviewed-by: Paul Dale <paul.dale@oracle.com> (Merged from https://github.com/openssl/openssl/pull/8709)
Diffstat (limited to 'apps')
-rw-r--r--apps/build.info3
-rw-r--r--apps/info.c97
-rw-r--r--apps/progs.pl3
3 files changed, 102 insertions, 1 deletions
diff --git a/apps/build.info b/apps/build.info
index ad14038a5d..30847a013d 100644
--- a/apps/build.info
+++ b/apps/build.info
@@ -5,7 +5,8 @@
genpkey.c genrsa.c mac.c nseq.c ocsp.c passwd.c pkcs12.c pkcs7.c
pkcs8.c pkey.c pkeyparam.c pkeyutl.c prime.c rand.c req.c rsa.c
rsautl.c s_client.c s_server.c s_time.c sess_id.c smime.c speed.c
- spkac.c srp.c ts.c verify.c version.c x509.c rehash.c storeutl.c);
+ spkac.c srp.c ts.c verify.c version.c x509.c rehash.c storeutl.c
+ info.c);
our @apps_lib_src =
( qw(apps.c apps_ui.c opt.c fmt.c s_cb.c s_socket.c app_rand.c
bf_prefix.c),
diff --git a/apps/info.c b/apps/info.c
new file mode 100644
index 0000000000..aa019ad19e
--- /dev/null
+++ b/apps/info.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the Apache License 2.0 (the "License"). You may not use
+ * this file except in compliance with the License. You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+#include <openssl/crypto.h>
+#include "apps.h"
+#include "progs.h"
+
+typedef enum OPTION_choice {
+ OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
+ OPT_CONFIGDIR, OPT_ENGINESDIR, OPT_MODULESDIR, OPT_DSOEXT, OPT_DIRNAMESEP,
+ OPT_LISTSEP
+} OPTION_CHOICE;
+
+const OPTIONS info_options[] = {
+ {"help", OPT_HELP, '-', "Display this summary"},
+ {"configdir", OPT_CONFIGDIR, '-', "Default configuration file directory"},
+ {"c", OPT_CONFIGDIR, '-', "Default configuration file directory"},
+ {"enginesdir", OPT_ENGINESDIR, '-', "Default engine module directory"},
+ {"e", OPT_ENGINESDIR, '-', "Default engine module directory"},
+ {"modulesdir", OPT_ENGINESDIR, '-',
+ "Default module directory (other than engine modules)"},
+ {"m", OPT_ENGINESDIR, '-',
+ "Default module directory (other than engine modules)"},
+ {"dsoext", OPT_DSOEXT, '-', "Configured extension for modules"},
+ {"dirnamesep", OPT_DIRNAMESEP, '-', "Directory-filename separator"},
+ {"listsep", OPT_LISTSEP, '-', "List separator character"},
+ {NULL}
+};
+
+int info_main(int argc, char **argv)
+{
+ int ret = 1, dirty = 0, type = 0;
+ char *prog;
+ OPTION_CHOICE o;
+
+ prog = opt_init(argc, argv, info_options);
+ while ((o = opt_next()) != OPT_EOF) {
+ switch (o) {
+ case OPT_EOF:
+ case OPT_ERR:
+opthelp:
+ BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
+ goto end;
+ case OPT_HELP:
+ opt_help(info_options);
+ ret = 0;
+ goto end;
+ case OPT_CONFIGDIR:
+ type = OPENSSL_INFO_CONFIG_DIR;
+ dirty++;
+ break;
+ case OPT_ENGINESDIR:
+ type = OPENSSL_INFO_ENGINES_DIR;
+ dirty++;
+ break;
+ case OPT_MODULESDIR:
+ type = OPENSSL_INFO_MODULES_DIR;
+ dirty++;
+ break;
+ case OPT_DSOEXT:
+ type = OPENSSL_INFO_DSO_EXTENSION;
+ dirty++;
+ break;
+ case OPT_DIRNAMESEP:
+ type = OPENSSL_INFO_DIR_FILENAME_SEPARATOR;
+ dirty++;
+ break;
+ case OPT_LISTSEP:
+ type = OPENSSL_INFO_LIST_SEPARATOR;
+ dirty++;
+ break;
+ }
+ }
+ if (opt_num_rest() != 0) {
+ BIO_printf(bio_err, "%s: Extra parameters given.\n", prog);
+ goto opthelp;
+ }
+ if (dirty > 1) {
+ BIO_printf(bio_err, "%s: Only one item allowed\n", prog);
+ goto opthelp;
+ }
+ if (dirty == 0) {
+ BIO_printf(bio_err, "%s: No items chosen\n", prog);
+ goto opthelp;
+ }
+
+ BIO_printf(bio_out, "%s\n", OPENSSL_info(type));
+ ret = 0;
+ end:
+ return ret;
+}
diff --git a/apps/progs.pl b/apps/progs.pl
index ab1a729fff..3aec7562cf 100644
--- a/apps/progs.pl
+++ b/apps/progs.pl
@@ -51,6 +51,9 @@ print <<"EOF";
* https://www.openssl.org/source/license.html
*/
+#include <openssl/lhash.h>
+#include "opt.h"
+
typedef enum FUNC_TYPE {
FT_none, FT_general, FT_md, FT_cipher, FT_pkey,
FT_md_alg, FT_cipher_alg