Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion SymCryptProvider/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,5 @@ separate section. This section must be referenced in the symcrypt provider secti
| - | - | - |
| enabled | 0 or 1 to disable or enable keysinuse logging. | 0 |
| max_file_size | Maximum size of the file events are written to. May be written as raw byte size or suffixed with KB/MB/GB | 5KB |
| logging_delay_seconds | Duration in seconds between events being written to the file. Any events that happen in between will be aggregate and logged as one event. | error |
| logging_delay_seconds | Duration in seconds between events being written to the file. Any events that happen in between will be aggregate and logged as one event. | error |
| process_scope | Controls which processes run the KeysInUse logging thread when an application forks. Can be <ul><li>main - only the process that first initialized KeysInUse logs</li><li>child - only forked child processes log</li><li>both - both the main process and forked children log</li></ul> May be overridden at runtime by the `KEYSINUSE_PROCESS_SCOPE` environment variable. | both |
26 changes: 26 additions & 0 deletions SymCryptProvider/src/p_scossl_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ extern "C" {
#define CONF_KEYSINUSE_ENABLED "keysinuse.enabled"
#define CONF_KEYSINUSE_MAX_FILE_SIZE "keysinuse.max_file_size"
#define CONF_KEYSINUSE_LOGGING_DELAY "keysinuse.logging_delay_seconds"
#define CONF_KEYSINUSE_PROCESS_SCOPE "keysinuse.process_scope"

// Cap configured file size at 2GB
#define SCOSSL_MAX_CONFIGURABLE_FILE_SIZE (2l << 30)
Expand Down Expand Up @@ -413,12 +414,15 @@ static void p_scossl_start_keysinuse(_In_ const OSSL_CORE_HANDLE *handle)
const char *confEnabled = NULL;
const char *confMaxFileSize = NULL;
const char *confLoggingDelay = NULL;
const char *confProcessScope = NULL;
const char *envProcessScope = NULL;
const char *envEnabled = NULL;

OSSL_PARAM keysinuseParams[] = {
OSSL_PARAM_utf8_ptr(CONF_KEYSINUSE_ENABLED, &confEnabled, 0),
OSSL_PARAM_utf8_ptr(CONF_KEYSINUSE_MAX_FILE_SIZE, &confMaxFileSize, 0),
OSSL_PARAM_utf8_ptr(CONF_KEYSINUSE_LOGGING_DELAY, &confLoggingDelay, 0),
OSSL_PARAM_utf8_ptr(CONF_KEYSINUSE_PROCESS_SCOPE, &confProcessScope, 0),
OSSL_PARAM_END};

// Config related errors shouldn't surface to caller
Expand Down Expand Up @@ -501,6 +505,28 @@ static void p_scossl_start_keysinuse(_In_ const OSSL_CORE_HANDLE *handle)
p_scossl_keysinuse_set_logging_delay(atol(confLoggingDelay));
}

// Environment overrides config. Config value is alreday fetched core_get_params above
if ((envProcessScope = NCONF_get_string(NULL, NULL, "KEYSINUSE_PROCESS_SCOPE")) != NULL)
{
confProcessScope = envProcessScope;
}

if (confProcessScope != NULL)
{
if (OPENSSL_strcasecmp(confProcessScope, "main") == 0)
{
p_scossl_keysinuse_set_process_scope(KEYSINUSE_PROCESS_SCOPE_MAIN);
}
else if (OPENSSL_strcasecmp(confProcessScope, "child") == 0)
{
p_scossl_keysinuse_set_process_scope(KEYSINUSE_PROCESS_SCOPE_CHILD);
}
else
{
p_scossl_keysinuse_set_process_scope(KEYSINUSE_PROCESS_SCOPE_BOTH);
}
}

p_scossl_keysinuse_init();
}

Expand Down
Loading