Skip to content

Commit

Permalink
Consolitade p11 init
Browse files Browse the repository at this point in the history
  • Loading branch information
qpernil committed Apr 7, 2022
1 parent ac13b3b commit 0c59519
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
15 changes: 12 additions & 3 deletions examples/p11_generate_rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,27 @@ int main(int argc, char *argv[]) {
exit(EXIT_FAILURE);
}

CK_C_GetFunctionList fn;
void *handle = dlopen(argv[1], RTLD_NOW | RTLD_GLOBAL);
assert(handle != NULL);

CK_C_GetFunctionList fn;
*(void **) (&fn) = dlsym(handle, "C_GetFunctionList");
assert(fn != NULL);

CK_FUNCTION_LIST_PTR p11;
CK_FUNCTION_LIST_PTR p11 = NULL;
CK_RV rv = fn(&p11);
assert(rv == CKR_OK);

rv = p11->C_Initialize(NULL_PTR);
char config[256] = {0};
CK_C_INITIALIZE_ARGS initArgs = {0};
const char *connector_url = getenv("DEFAULT_CONNECTOR_URL");
if (connector_url) {
assert(strlen(connector_url) + strlen("connector=") < 256);
sprintf(config, "connector=%s", connector_url);
initArgs.pReserved = (void *) config;
}

rv = p11->C_Initialize(&initArgs);
assert(rv == CKR_OK);

CK_SESSION_HANDLE session;
Expand Down
24 changes: 11 additions & 13 deletions pkcs11/tests/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,25 @@ CK_FUNCTION_LIST_PTR get_function_list(void *handle) {
*(void **) (&fn) = dlsym(handle, "C_GetFunctionList");
assert(fn != NULL);

CK_FUNCTION_LIST_PTR p11;
CK_FUNCTION_LIST_PTR p11 = NULL;
CK_RV rv = fn(&p11);
assert(rv == CKR_OK);

return p11;
}

CK_SESSION_HANDLE open_session(CK_FUNCTION_LIST_PTR p11) {
CK_SESSION_HANDLE session;
CK_C_INITIALIZE_ARGS initArgs;
memset(&initArgs, 0, sizeof(initArgs));

const char *connector_url;
connector_url = getenv("DEFAULT_CONNECTOR_URL");
if (connector_url == NULL) {
connector_url = DEFAULT_CONNECTOR_URL;
CK_SESSION_HANDLE session = 0;
CK_C_INITIALIZE_ARGS initArgs = {0};

char config[256] = {0};
const char *connector_url = getenv("DEFAULT_CONNECTOR_URL");
if (connector_url) {
assert(strlen(connector_url) + strlen("connector=") < 256);
sprintf(config, "connector=%s", connector_url);
initArgs.pReserved = (void *) config;
}
char config[256];
assert(strlen(connector_url) + strlen("connector=") < 256);
sprintf(config, "connector=%s", connector_url);
initArgs.pReserved = (void *) config;

CK_RV rv = p11->C_Initialize(&initArgs);
assert(rv == CKR_OK);

Expand Down

0 comments on commit 0c59519

Please sign in to comment.