Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate p11 init #227

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
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
18 changes: 5 additions & 13 deletions common/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,21 @@
#include <winsock.h>
#endif

#ifdef __linux__
#define ANSI_RED "\x1b[31m"
#define ANSI_GREEN "\x1b[32m"
#define ANSI_YELLOW "\x1b[33m"
#define ANSI_BLUE "\x1b[34m"
#define ANSI_MAGENTA "\x1b[35m"
#define ANSI_CYAN "\x1b[36m"
#define ANSI_RESET "\x1b[0m"
#else
#define ANSI_RED ""
#define ANSI_GREEN ""
#define ANSI_YELLOW ""
#define ANSI_BLUE ""
#define ANSI_MAGENTA ""
#define ANSI_CYAN ""
#define ANSI_RESET ""
#endif

#define __FILENAME__ \
(strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)

#ifdef _MSVC
#define localtime_r(a, b) localtime_s(b, a)
#define __FILENAME__ \
(strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#else
#define __FILENAME__ \
(strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
#endif

#define D(var, file, col, who, lev, ...) \
Expand Down
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
Loading