-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 #8709)
- Loading branch information
Showing
12 changed files
with
296 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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 <stddef.h> | ||
#include <openssl/crypto.h> | ||
#include "internal/dso_conf.h" | ||
#include "e_os.h" | ||
|
||
const char *OPENSSL_info(int t) | ||
{ | ||
switch (t) { | ||
case OPENSSL_INFO_CONFIG_DIR: | ||
return OPENSSLDIR; | ||
case OPENSSL_INFO_ENGINES_DIR: | ||
return ENGINESDIR; | ||
case OPENSSL_INFO_MODULES_DIR: | ||
return MODULESDIR; | ||
case OPENSSL_INFO_DSO_EXTENSION: | ||
return DSO_EXTENSION; | ||
case OPENSSL_INFO_DIR_FILENAME_SEPARATOR: | ||
#if defined(_WIN32) | ||
return "\\"; | ||
#elif defined(__VMS) | ||
return ""; | ||
#else /* Assume POSIX */ | ||
return "/"; | ||
#endif | ||
case OPENSSL_INFO_LIST_SEPARATOR: | ||
{ | ||
static const char list_sep[] = { LIST_SEPARATOR_CHAR, '\0' }; | ||
return list_sep; | ||
} | ||
default: | ||
break; | ||
} | ||
/* Not an error */ | ||
return NULL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
=pod | ||
|
||
=head1 NAME | ||
|
||
openssl-info, | ||
info - print OpenSSL built-in information | ||
|
||
=head1 SYNOPSIS | ||
|
||
B<openssl info> | ||
[B<-help>] | ||
[B<-configdir> | B<-c>] | ||
[B<-enginesdir> | B<-e>] | ||
[B<-modulesdir> | B<-m>] | ||
[B<-dsoext>] | ||
[B<-dirfilesep>] | ||
[B<-listsep]> | ||
|
||
=head1 DESCRIPTION | ||
|
||
This command is used to print out information about OpenSSL. | ||
The information is written exactly as it is with no extra text, which | ||
makes useful for scripts. | ||
|
||
As a consequence, only one item may be chosen for each run of this | ||
command. | ||
|
||
=head1 OPTIONS | ||
|
||
=over 4 | ||
|
||
=item B<-help> | ||
|
||
Print out a usage message. | ||
|
||
=item B<-configdir>, B<-c> | ||
|
||
Outputs the default directory for OpenSSL configuration files. | ||
|
||
=item B<-enginesdir>, B<-e> | ||
|
||
Outputs the default directory for OpenSSL engine modules. | ||
|
||
=item B<-modulesdir>, B<-m> | ||
|
||
Outputs the default directory for OpenSSL dynamically loadable modules | ||
other than engine modules. | ||
|
||
=item B<-dsoext> | ||
|
||
Outputs the DSO extension OpenSSL uses. | ||
|
||
=item B<-dirnamesep> | ||
|
||
Outputs the separator character between a directory specification and | ||
a file name. | ||
Note that on some operating systems, this is not the same as the | ||
separator between directory elements. | ||
|
||
=item B<-listsep> | ||
|
||
Outputs the OpenSSL list separator character. | ||
This is typically used to construct C<$PATH> (C<%PATH%> on Windows) | ||
style lists. | ||
|
||
=back | ||
|
||
=head1 HISTORY | ||
|
||
The B<openssl info> command was added in OpenSSL 3.0. | ||
|
||
=head1 COPYRIGHT | ||
|
||
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 | ||
L<https://www.openssl.org/source/license.html>. | ||
|
||
=cut |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters