Check-in [3eb54f93b1]
Overview
Comment:Added softokn3 wrapper module
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:3eb54f93b1fec6bf225cf0eb43bfda91652764f4
User & Date: rkeene on 2019-08-08 16:52:55
Other Links: manifest | tags
Context
2019-08-09
01:34
Fixed padding conditions Leaf check-in: b63163f527 user: rkeene tags: trunk
2019-08-08
16:52
Added softokn3 wrapper module check-in: 3eb54f93b1 user: rkeene tags: trunk
2019-06-12
22:41
More testing of the Tcl implementation of the SSH agent check-in: 24e37c4dab user: rkeene tags: trunk
Changes

Modified build/tcl/Makefile from [04cbb3e324] to [ef0ac61411].

1
2
3
4
5
6



7
8

9
10
11
12
all: ssh-agent-noasync.js

ssh-agent-noasync.js: ../chrome/ssh-agent.js
	cc -Dawait='' -Dasync='' -nostdinc -C -E -x c ../chrome/ssh-agent.js -o - | grep -v '^# ' > ssh-agent-noasync.js.new
	mv ssh-agent-noasync.js.new ssh-agent-noasync.js




clean:
	rm -f ssh-agent-noasync.js.new ssh-agent-noasync.js


distclean: clean

.PHONY: all clean distclean



|


>
>
>


>




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
all: ssh-agent-noasync.js

ssh-agent-noasync.js: ../chrome/ssh-agent.js
	$(CC) -Dawait='' -Dasync='' -nostdinc -C -E -x c ../chrome/ssh-agent.js -o - | grep -v '^# ' > ssh-agent-noasync.js.new
	mv ssh-agent-noasync.js.new ssh-agent-noasync.js

softokn3-pkcs11.so: softokn3-pkcs11.c
	$(CC) -fPIC -Wall -shared -o softokn3-pkcs11.so softokn3-pkcs11.c

clean:
	rm -f ssh-agent-noasync.js.new ssh-agent-noasync.js
	rm -f softokn3-pkcs11.so

distclean: clean

.PHONY: all clean distclean

Added build/tcl/softokn3-pkcs11.c version [4e157658f4].























































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>

#include <stdio.h>

/*
 * Create minimal PKCS#11 module interface needed to wrap
 */
#define CK_DEFINE_FUNCTION(type, func) type func

#define CKR_GENERAL_ERROR 0x00000005
#define CKR_OK            0x00000000

typedef void (*CK_CREATEMUTEX)();
typedef void (*CK_DESTROYMUTEX)();
typedef void (*CK_LOCKMUTEX)();
typedef void (*CK_UNLOCKMUTEX)();
typedef unsigned long CK_FLAGS;
typedef unsigned long CK_RV;
typedef void * CK_VOID_PTR;

typedef struct CK_C_INITIALIZE_ARGS {
	CK_CREATEMUTEX CreateMutex;
	CK_DESTROYMUTEX DestroyMutex;
	CK_LOCKMUTEX LockMutex;
	CK_UNLOCKMUTEX UnlockMutex;
	CK_FLAGS flags;
	CK_VOID_PTR pReserved;
} CK_C_INITIALIZE_ARGS;

typedef struct {
	unsigned char major;
	unsigned char minor;
} CK_VERSION;

typedef struct {
	CK_VERSION version;
	CK_RV (*C_Initialize)(CK_VOID_PTR);
	CK_RV (*C_Finalize)(CK_VOID_PTR);
} CK_FUNCTION_LIST;

typedef CK_FUNCTION_LIST* CK_FUNCTION_LIST_PTR;
typedef CK_FUNCTION_LIST** CK_FUNCTION_LIST_PTR_PTR;

/*
 * This is the size of the full PKCS#11 function list structure
 * (CK_FUNCTION_LIST).  We only actually care about wrapping the
 * initialization function, so we have to compute the full size
 *
 * Size is sizeOf(ourFunctionListStruct) + (numberOfFunctions-2 * functionPointerSize)
 */
#define SIZE_OF_PKCS11_FUNCTION_LIST (sizeof(CK_FUNCTION_LIST) + (67 * sizeof(void *)))

/*
 * Real C_Initialize() function for this module
 */
static CK_RV (*Real_C_Initialize)(CK_VOID_PTR) = NULL;

static CK_DEFINE_FUNCTION(CK_RV, Proxy_C_Initialize)(CK_VOID_PTR pInitArgs) {
	char nssConfig[1024];
	char *nssDBDir = NULL;
	CK_C_INITIALIZE_ARGS *InitArgs = NULL;

	InitArgs = pInitArgs;

	if (InitArgs == NULL) {
		InitArgs = malloc(sizeof(*InitArgs));

		InitArgs->CreateMutex = NULL;
		InitArgs->DestroyMutex = NULL;
		InitArgs->LockMutex = NULL;
		InitArgs->UnlockMutex = NULL;
		InitArgs->flags = 0;
		InitArgs->pReserved = NULL;
	}

	if (InitArgs->pReserved == NULL) {
		nssDBDir = getenv("SOFTOKN3_NSS_DIR");

		if (nssDBDir) {
			snprintf(nssConfig, sizeof(nssConfig),
			         "configdir='%s' certPrefix='' keyPrefix='' secmod='secmod.db' flags=readOnly",
				 nssDBDir
			);

			InitArgs->pReserved = (void *) nssConfig;
		}
	}

	if (Real_C_Initialize == NULL) {
		return(CKR_GENERAL_ERROR);
	}

	return(Real_C_Initialize(InitArgs));
}

CK_DEFINE_FUNCTION(CK_RV, C_GetFunctionList)(CK_FUNCTION_LIST_PTR_PTR ppFunctionList) {
	CK_RV (*Real_C_GetFunctionList)(CK_FUNCTION_LIST_PTR_PTR);
	CK_FUNCTION_LIST_PTR copyFunctionList;
	void *handle;
	CK_RV retval;
	char *module;

	module = getenv("SOFTOKN3_MODULE");
	if (!module) {
		module = "/usr/lib64/libsoftokn3.so";
	}

	/* handle = dlmopen(LM_ID_NEWLM, module, RTLD_NOW | RTLD_LOCAL); */
	handle = dlopen(module, RTLD_NOW | RTLD_LOCAL);
	if (handle == NULL) {
		fprintf(stderr, "Unable to open \"%s\": %s\n", module, dlerror());

		return(CKR_GENERAL_ERROR);
	}

	Real_C_GetFunctionList = dlsym(handle, "C_GetFunctionList");

	if (Real_C_GetFunctionList == NULL) {
		return(CKR_GENERAL_ERROR);
	}

	retval = Real_C_GetFunctionList(ppFunctionList);

	if (retval != CKR_OK) {
		return(retval);
	}

        copyFunctionList = malloc(SIZE_OF_PKCS11_FUNCTION_LIST);
        memcpy(copyFunctionList, *ppFunctionList, SIZE_OF_PKCS11_FUNCTION_LIST);
        *ppFunctionList = copyFunctionList;

	Real_C_Initialize = (*ppFunctionList)->C_Initialize;
	(*ppFunctionList)->C_Initialize = Proxy_C_Initialize;

	return(retval);
}