-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmyproxy-pkcs11.c
149 lines (132 loc) · 3.9 KB
/
myproxy-pkcs11.c
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
140
141
142
143
144
145
146
147
148
149
#include "gpkcs11_locl.h"
struct gpkcs11_soft_token_t gpkcs11_soft_token;
#define MYPROXY_MODULE_VERSION "1.0"
CK_RV
C_Initialize(CK_VOID_PTR a)
{
CK_C_INITIALIZE_ARGS_PTR args = a;
gpkcs11_log("Initialize\n");
int i;
CK_RV ret;
if (a != NULL_PTR) {
gpkcs11_log("\tCreateMutex:\t%p\n", args->CreateMutex);
gpkcs11_log("\tDestroyMutext\t%p\n", args->DestroyMutex);
gpkcs11_log("\tLockMutext\t%p\n", args->LockMutex);
gpkcs11_log("\tUnlockMutext\t%p\n", args->UnlockMutex);
gpkcs11_log("\tFlags\t%04x\n", (unsigned int)args->flags);
}
ret = gpkcs11_init_token(MYPROXY_MODULE_VERSION, "MyProxy repository", &gpkcs11_soft_token);
if (ret)
return ret;
gpkcs11_soft_token.myproxy_server = getenv("MYPROXY_SERVER");
if (gpkcs11_soft_token.myproxy_server == NULL) {
gpkcs11_log("MYPROXY_SERVER not set in the environment, exiting.\n");
return CKR_GENERAL_ERROR;
}
gpkcs11_soft_token.myproxy_user = getenv("LOGNAME");
/* XXX add some fallbacks */
return CKR_OK;
}
CK_RV
C_Login(CK_SESSION_HANDLE hSession, CK_USER_TYPE userType, CK_UTF8CHAR_PTR pPin, CK_ULONG ulPinLen)
{
char *pin = NULL;
int i;
char *creds = NULL;
CK_RV ret;
gpkcs11_log("Login\n");
if (gpkcs11_verify_session_handle(hSession, NULL) != CKR_OK)
gpkcs11_app_error("session not open");
ret = get_myproxy_creds(gpkcs11_soft_token.myproxy_server, gpkcs11_soft_token.myproxy_user, pin, &creds);
if (ret)
goto end;
ret = gpkcs11_add_credentials(gpkcs11_soft_token.myproxy_user, creds,
creds, gpkcs11_soft_token.myproxy_user, 0);
if (ret)
goto end;
gpkcs11_soft_token.flags.login_done = 1;
ret = CKR_OK;
end:
if (pin)
free(pin);
if (creds)
free(creds);
return ret;
}
static CK_RV
func_not_supported(void)
{
gpkcs11_log("function not supported\n");
return CKR_FUNCTION_NOT_SUPPORTED;
}
CK_FUNCTION_LIST funcs = {
{2, 11},
C_Initialize,
C_Finalize,
C_GetInfo,
C_GetFunctionList,
C_GetSlotList,
C_GetSlotInfo,
C_GetTokenInfo,
C_GetMechanismList,
C_GetMechanismInfo,
C_InitToken,
(void *)func_not_supported, /* C_InitPIN */
(void *)func_not_supported, /* C_SetPIN */
C_OpenSession,
C_CloseSession,
C_CloseAllSessions,
C_GetSessionInfo,
(void *)func_not_supported, /* C_GetOperationState */
(void *)func_not_supported, /* C_SetOperationState */
C_Login,
C_Logout,
(void *)func_not_supported, /* C_CreateObject */
(void *)func_not_supported, /* C_CopyObject */
(void *)func_not_supported, /* C_DestroyObject */
(void *)func_not_supported, /* C_GetObjectSize */
C_GetAttributeValue,
(void *)func_not_supported, /* C_SetAttributeValue */
C_FindObjectsInit,
C_FindObjects,
C_FindObjectsFinal,
C_EncryptInit,
C_Encrypt,
C_EncryptUpdate,
C_EncryptFinal,
C_DecryptInit,
C_Decrypt,
C_DecryptUpdate,
C_DecryptFinal,
C_DigestInit,
(void *)func_not_supported, /* C_Digest */
(void *)func_not_supported, /* C_DigestUpdate */
(void *)func_not_supported, /* C_DigestKey */
(void *)func_not_supported, /* C_DigestFinal */
C_SignInit,
C_Sign,
C_SignUpdate,
C_SignFinal,
(void *)func_not_supported, /* C_SignRecoverInit */
(void *)func_not_supported, /* C_SignRecover */
C_VerifyInit,
C_Verify,
C_VerifyUpdate,
C_VerifyFinal,
(void *)func_not_supported, /* C_VerifyRecoverInit */
(void *)func_not_supported, /* C_VerifyRecover */
(void *)func_not_supported, /* C_DigestEncryptUpdate */
(void *)func_not_supported, /* C_DecryptDigestUpdate */
(void *)func_not_supported, /* C_SignEncryptUpdate */
(void *)func_not_supported, /* C_DecryptVerifyUpdate */
(void *)func_not_supported, /* C_GenerateKey */
(void *)func_not_supported, /* C_GenerateKeyPair */
(void *)func_not_supported, /* C_WrapKey */
(void *)func_not_supported, /* C_UnwrapKey */
(void *)func_not_supported, /* C_DeriveKey */
(void *)func_not_supported, /* C_SeedRandom */
C_GenerateRandom,
(void *)func_not_supported, /* C_GetFunctionStatus */
(void *)func_not_supported, /* C_CancelFunction */
(void *)func_not_supported /* C_WaitForSlotEvent */
};