Skip to content

Commit 2298d39

Browse files
committed
provider: Default debug directory to /tmp but make it configurable
The IBMCA provider debug logs were written to the /var/log/ibmca/ directory, but this required that directory to be world-writable, because we don't know under which user an application runs that uses the provider. A world-writable directory under /var has security implications and should be avoided. Change the default log directory to /tmp which is world-writable anyway. Additionally the log directory can now be configured via the 'debug-path' option in the IBMCA provider section of the OpenSSL config file, or via environment variable 'IBMCA_DEBUG_PATH'. Closes: #107 Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
1 parent 67efa9a commit 2298d39

File tree

6 files changed

+59
-14
lines changed

6 files changed

+59
-14
lines changed

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ AM_INIT_AUTOMAKE([foreign])
1010

1111
AC_PATH_PROG([CHMOD], [chmod], [/bin/chmod])
1212

13-
logdir=$localstatedir/log/ibmca
13+
logdir=/tmp
1414
AC_SUBST(logdir)
1515

1616
# Cmdline arguments.

src/provider/Makefile.am

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,3 @@ ACLOCAL_AMFLAGS = -I m4
2525
SUBDIRS = doc
2626

2727
noinst_SCRIPTS = ibmca-provider-opensslconfig
28-
29-
install-data-hook:
30-
$(MKDIR_P) $(DESTDIR)$(logdir)
31-
$(CHMOD) 0777 $(DESTDIR)$(logdir)

src/provider/doc/ibmca-provider.man

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,25 @@ provider if you are on an IBM z15 or later. This would actually make it slower.
9494
.IP "debug = yes | no | stderr"
9595
.RS
9696
Enables debug output for the IBMCA provider. If this option is not specified,
97-
no debuging output is produced. If \fBdebug = stderr\fP is specified,
97+
no debugging output is produced. If \fBdebug = stderr\fP is specified,
9898
debugging messages are printed to stderr. Otherwise the debug output is written
99-
into a trace file in \fB[/usr/local]/var/log/ibmca/trace-<provider-name>.<pid>\fP,
100-
where <provider-name> is the name of the IBMCA provider from the identity
101-
option, and <pid> is the process ID of the current process. You can also
102-
enable debugging by setting the environment variable \fBIBMCA_DEBUG\fP to
103-
\fBon\fP or \fBstderr\fP.
99+
into a trace file in \fB<debug-path>/trace-<provider-name>.<pid>\fP,
100+
where <debug-path> is the path name of a directory to where the debug files are
101+
written (default: \fB/tmp\fP), <provider-name> is the name of the IBMCA provider
102+
from the identity option, and <pid> is the process ID of the current process.
103+
You can also enable debugging by setting the environment variable
104+
\fBIBMCA_DEBUG\fP to \fBon\fP or \fBstderr\fP.
105+
.RE
106+
.PP
107+
.IP "debug-path = /dir/to/debug/directory"
108+
.RS
109+
Sets the directory path to where debug files are written when debug is enabled
110+
via \fBdebug = yes\fP or via environment variable \fBIBMCA_DEBUG=on\fP.
111+
You can also set the debug path by setting the environment variable
112+
\fBIBMCA_DEBUG_PATH\fP to the directory path. It must be ensured that the user
113+
under which the application that uses the IBMCA provider runs has write access
114+
to that directory. If this option is not specified, the default debug path is
115+
\fB/tmp\fP.
104116
.RE
105117
.PP
106118
.IP "fips = yes | no"
@@ -153,8 +165,18 @@ If
153165
.B $IBMCA_DEBUG
154166
is set to \fBstderr\fP debug output to stderr for the IBMCA provider is enabled.
155167
If it is set to \fBon\fP the debug output is written into a trace file in
156-
\fB[/usr/local]/var/log/ibmca/trace-<provider-name>.<pid>\fP, where <pid> is
157-
the process ID of the current process.
168+
\fB<debug-path>/trace-<provider-name>.<pid>\fP, where <debug-path> is the path
169+
name of a directory to where the debug files are written (default: \fB/tmp\fP),
170+
<provider-name> is the name of the IBMCA provider from the identity option,
171+
and <pid> is the process ID of the current process.
172+
.PP
173+
.TP
174+
.BR IBMCA_DEBUG_PATH
175+
Sets the directory path to where debug files are written when debug is enabled
176+
via \fBdebug = yes\fP configuration option or via environment variable
177+
\fBIBMCA_DEBUG=on\fP. It must be ensured that the user under which the
178+
application that uses the IBMCA provider runs has write access to that
179+
directory.
158180
.PP
159181
.SH SEE ALSO
160182
.B provider(1)

src/provider/p_ibmca.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <stdio.h>
2020
#include <stdarg.h>
2121
#include <stddef.h>
22+
#include <stdlib.h>
2223
#include <err.h>
2324
#include <strings.h>
2425
#include <string.h>
@@ -58,6 +59,8 @@ struct ibmca_config_item {
5859

5960
static int ibmca_config_debug(struct ibmca_prov_ctx *provctx,
6061
const char *key, const char *value);
62+
static int ibmca_config_debug_path(struct ibmca_prov_ctx *provctx,
63+
const char *key, const char *value);
6164
static int ibmca_config_fips(struct ibmca_prov_ctx *provctx,
6265
const char *key, const char *value);
6366
static int ibmca_config_algorithms(struct ibmca_prov_ctx *provctx,
@@ -70,6 +73,7 @@ static int ibmca_config_openssl_version(struct ibmca_prov_ctx *provctx,
7073
const char *key, const char *value);
7174

7275
static const struct ibmca_config_item config_items[] = {
76+
{ IBMCA_CONF_DEBUG_PATH, ibmca_config_debug_path },
7377
{ IBMCA_CONF_DEBUG, ibmca_config_debug },
7478
{ IBMCA_CONF_FIPS, ibmca_config_fips },
7579
{ IBMCA_CONF_ALGORITHMS, ibmca_config_algorithms },
@@ -881,7 +885,9 @@ static int ibmca_config_debug(struct ibmca_prov_ctx *provctx,
881885
*p = '_';
882886

883887
if (snprintf(debug_file, sizeof(debug_file), "%s/trace-%s.%d",
884-
IBMCA_LOGDIR, prov_name, provctx->debug_pid)
888+
provctx->debug_path != NULL ? provctx->debug_path :
889+
IBMCA_LOGDIR,
890+
prov_name, provctx->debug_pid)
885891
>= (int)sizeof(debug_file)) {
886892
put_error_ctx(provctx, IBMCA_ERR_INTERNAL_ERROR,
887893
"IBMCA_LOGDIR too long: '%s'", IBMCA_LOGDIR);
@@ -904,6 +910,20 @@ static int ibmca_config_debug(struct ibmca_prov_ctx *provctx,
904910
return 1;
905911
}
906912

913+
static int ibmca_config_debug_path(struct ibmca_prov_ctx *provctx,
914+
const char *key, const char *value)
915+
{
916+
/*
917+
* If the debug path is already set (e.g. due to IBMCA_DEBUG_PATH
918+
* environment variable) do not override the setting.
919+
*/
920+
if (provctx->debug_path != NULL)
921+
return 1;
922+
923+
return ibmca_config_const_string(provctx, key, value,
924+
&provctx->debug_path);
925+
}
926+
907927
static int ibmca_config_fips(struct ibmca_prov_ctx *provctx,
908928
const char *key, const char *value)
909929
{
@@ -1302,6 +1322,9 @@ int OSSL_provider_init(const OSSL_CORE_HANDLE *handle,
13021322
ctx->c_free = c_free;
13031323
ctx->ica_adapter = DRIVER_NOT_LOADED;
13041324

1325+
val = secure_getenv(IBMCA_DEBUG_PATH_ENVVAR);
1326+
if (val != NULL)
1327+
ibmca_config_debug_path(ctx, IBMCA_CONF_DEBUG_PATH, val);
13051328
val = getenv(IBMCA_DEBUG_ENVVAR);
13061329
if (val != NULL)
13071330
ibmca_config_debug(ctx, IBMCA_CONF_DEBUG, val);

src/provider/p_ibmca.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727

2828
/* Environment variable name to enable debug */
2929
#define IBMCA_DEBUG_ENVVAR "IBMCA_DEBUG"
30+
#define IBMCA_DEBUG_PATH_ENVVAR "IBMCA_DEBUG_PATH"
3031

3132
/* IBMCA provider configuration key words */
3233
#define IBMCA_CONF_DEBUG "debug"
34+
#define IBMCA_CONF_DEBUG_PATH "debug-path"
3335
#define IBMCA_CONF_ALGORITHMS "algorithms"
3436
#define IBMCA_CONF_FIPS "fips"
3537
#define IBMCA_CONF_FALLBACK_PROPS "fallback-properties"
@@ -64,6 +66,7 @@ struct ibmca_prov_ctx {
6466
OSSL_FUNC_CRYPTO_secure_clear_free_fn *c_secure_clear_free;
6567
OSSL_FUNC_OPENSSL_cleanse_fn *c_cleanse;
6668
bool debug;
69+
const char *debug_path;
6770
FILE *debug_file;
6871
pid_t debug_pid;
6972
pthread_mutex_t debug_mutex;

test/provider/openssl-test.cnf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ identity = ibmca
1616
module = ibmca-provider.so
1717
activate = 1
1818
#debug = yes
19+
#debug-path = /dir/to/debug/directory
1920
#fips=yes
2021
#algorithms = RSA,EC,DH
2122
algorithms = ALL

0 commit comments

Comments
 (0)