/src/nss/lib/softoken/fipstokn.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
2 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | | /* |
5 | | * This file implements PKCS 11 on top of our existing security modules |
6 | | * |
7 | | * For more information about PKCS 11 See PKCS 11 Token Inteface Standard. |
8 | | * This implementation has two slots: |
9 | | * slot 1 is our generic crypto support. It does not require login |
10 | | * (unless you've enabled FIPS). It supports Public Key ops, and all they |
11 | | * bulk ciphers and hashes. It can also support Private Key ops for imported |
12 | | * Private keys. It does not have any token storage. |
13 | | * slot 2 is our private key support. It requires a login before use. It |
14 | | * can store Private Keys and Certs as token objects. Currently only private |
15 | | * keys and their associated Certificates are saved on the token. |
16 | | * |
17 | | * In this implementation, session objects are only visible to the session |
18 | | * that created or generated them. |
19 | | */ |
20 | | #include "seccomon.h" |
21 | | #include "softoken.h" |
22 | | #include "lowkeyi.h" |
23 | | #include "pkcs11.h" |
24 | | #include "pkcs11i.h" |
25 | | #include "prenv.h" |
26 | | #include "prprf.h" |
27 | | |
28 | | #include <ctype.h> |
29 | | |
30 | | #ifdef XP_UNIX |
31 | | #define NSS_AUDIT_WITH_SYSLOG 1 |
32 | | #include <syslog.h> |
33 | | #include <unistd.h> |
34 | | #endif |
35 | | |
36 | | #ifdef LINUX |
37 | | #include <pthread.h> |
38 | | #include <dlfcn.h> |
39 | 0 | #define LIBAUDIT_NAME "libaudit.so.1" |
40 | | #ifndef AUDIT_CRYPTO_TEST_USER |
41 | 0 | #define AUDIT_CRYPTO_TEST_USER 2400 /* Crypto test results */ |
42 | 0 | #define AUDIT_CRYPTO_PARAM_CHANGE_USER 2401 /* Crypto attribute change */ |
43 | 0 | #define AUDIT_CRYPTO_LOGIN 2402 /* Logged in as crypto officer */ |
44 | 0 | #define AUDIT_CRYPTO_LOGOUT 2403 /* Logged out from crypto */ |
45 | 0 | #define AUDIT_CRYPTO_KEY_USER 2404 /* Create,delete,negotiate */ |
46 | 0 | #define AUDIT_CRYPTO_FAILURE_USER 2405 /* Fail decrypt,encrypt,randomize */ |
47 | | #endif |
48 | | static void *libaudit_handle; |
49 | | static int (*audit_open_func)(void); |
50 | | static void (*audit_close_func)(int fd); |
51 | | static int (*audit_log_user_message_func)(int audit_fd, int type, |
52 | | const char *message, const char *hostname, const char *addr, |
53 | | const char *tty, int result); |
54 | | static int (*audit_send_user_message_func)(int fd, int type, |
55 | | const char *message); |
56 | | |
57 | | static pthread_once_t libaudit_once_control = PTHREAD_ONCE_INIT; |
58 | | |
59 | | static void |
60 | | libaudit_init(void) |
61 | 0 | { |
62 | 0 | libaudit_handle = dlopen(LIBAUDIT_NAME, RTLD_LAZY); |
63 | 0 | if (!libaudit_handle) { |
64 | 0 | return; |
65 | 0 | } |
66 | 0 | audit_open_func = dlsym(libaudit_handle, "audit_open"); |
67 | 0 | audit_close_func = dlsym(libaudit_handle, "audit_close"); |
68 | | /* |
69 | | * audit_send_user_message is the older function. |
70 | | * audit_log_user_message, if available, is preferred. |
71 | | */ |
72 | 0 | audit_log_user_message_func = dlsym(libaudit_handle, |
73 | 0 | "audit_log_user_message"); |
74 | 0 | if (!audit_log_user_message_func) { |
75 | 0 | audit_send_user_message_func = dlsym(libaudit_handle, |
76 | 0 | "audit_send_user_message"); |
77 | 0 | } |
78 | 0 | if (!audit_open_func || !audit_close_func || |
79 | 0 | (!audit_log_user_message_func && !audit_send_user_message_func)) { |
80 | 0 | dlclose(libaudit_handle); |
81 | 0 | libaudit_handle = NULL; |
82 | 0 | audit_open_func = NULL; |
83 | 0 | audit_close_func = NULL; |
84 | 0 | audit_log_user_message_func = NULL; |
85 | 0 | audit_send_user_message_func = NULL; |
86 | 0 | } |
87 | 0 | } |
88 | | #endif /* LINUX */ |
89 | | |
90 | | /* |
91 | | * ******************** Password Utilities ******************************* |
92 | | */ |
93 | | static PRBool isLoggedIn = PR_FALSE; |
94 | | static PRBool isLevel2 = PR_TRUE; |
95 | | PRBool sftk_fatalError = PR_FALSE; |
96 | | |
97 | | /* |
98 | | * This function returns |
99 | | * - CKR_PIN_INVALID if the password/PIN is not a legal UTF8 string |
100 | | * - CKR_PIN_LEN_RANGE if the password/PIN is too short or does not |
101 | | * consist of characters from three or more character classes. |
102 | | * - CKR_OK otherwise |
103 | | * |
104 | | * The minimum password/PIN length is FIPS_MIN_PIN Unicode characters. |
105 | | * We define five character classes: digits (0-9), ASCII lowercase letters, |
106 | | * ASCII uppercase letters, ASCII non-alphanumeric characters (such as |
107 | | * space and punctuation marks), and non-ASCII characters. If an ASCII |
108 | | * uppercase letter is the first character of the password/PIN, the |
109 | | * uppercase letter is not counted toward its character class. Similarly, |
110 | | * if a digit is the last character of the password/PIN, the digit is not |
111 | | * counted toward its character class. |
112 | | * |
113 | | * Although NSC_SetPIN and NSC_InitPIN already do the maximum and minimum |
114 | | * password/PIN length checks, they check the length in bytes as opposed |
115 | | * to characters. To meet the minimum password/PIN guessing probability |
116 | | * requirements in FIPS 140-2, we need to check the length in characters. |
117 | | */ |
118 | | static CK_RV |
119 | | sftk_newPinCheck(CK_CHAR_PTR pPin, CK_ULONG ulPinLen) |
120 | 0 | { |
121 | 0 | unsigned int i; |
122 | 0 | int nchar = 0; /* number of characters */ |
123 | 0 | int ntrail = 0; /* number of trailing bytes to follow */ |
124 | 0 | int ndigit = 0; /* number of decimal digits */ |
125 | 0 | int nlower = 0; /* number of ASCII lowercase letters */ |
126 | 0 | int nupper = 0; /* number of ASCII uppercase letters */ |
127 | 0 | int nnonalnum = 0; /* number of ASCII non-alphanumeric characters */ |
128 | 0 | int nnonascii = 0; /* number of non-ASCII characters */ |
129 | 0 | int nclass; /* number of character classes */ |
130 | |
|
131 | 0 | for (i = 0; i < ulPinLen; i++) { |
132 | 0 | unsigned int byte = pPin[i]; |
133 | |
|
134 | 0 | if (ntrail) { |
135 | 0 | if ((byte & 0xc0) != 0x80) { |
136 | | /* illegal */ |
137 | 0 | nchar = -1; |
138 | 0 | break; |
139 | 0 | } |
140 | 0 | if (--ntrail == 0) { |
141 | 0 | nchar++; |
142 | 0 | nnonascii++; |
143 | 0 | } |
144 | 0 | continue; |
145 | 0 | } |
146 | 0 | if ((byte & 0x80) == 0x00) { |
147 | | /* single-byte (ASCII) character */ |
148 | 0 | nchar++; |
149 | 0 | if (isdigit(byte)) { |
150 | 0 | if (i < ulPinLen - 1) { |
151 | 0 | ndigit++; |
152 | 0 | } |
153 | 0 | } else if (islower(byte)) { |
154 | 0 | nlower++; |
155 | 0 | } else if (isupper(byte)) { |
156 | 0 | if (i > 0) { |
157 | 0 | nupper++; |
158 | 0 | } |
159 | 0 | } else { |
160 | 0 | nnonalnum++; |
161 | 0 | } |
162 | 0 | } else if ((byte & 0xe0) == 0xc0) { |
163 | | /* leading byte of two-byte character */ |
164 | 0 | ntrail = 1; |
165 | 0 | } else if ((byte & 0xf0) == 0xe0) { |
166 | | /* leading byte of three-byte character */ |
167 | 0 | ntrail = 2; |
168 | 0 | } else if ((byte & 0xf8) == 0xf0) { |
169 | | /* leading byte of four-byte character */ |
170 | 0 | ntrail = 3; |
171 | 0 | } else { |
172 | | /* illegal */ |
173 | 0 | nchar = -1; |
174 | 0 | break; |
175 | 0 | } |
176 | 0 | } |
177 | 0 | if (nchar == -1) { |
178 | | /* illegal UTF8 string */ |
179 | 0 | return CKR_PIN_INVALID; |
180 | 0 | } |
181 | 0 | if (nchar < FIPS_MIN_PIN) { |
182 | 0 | return CKR_PIN_LEN_RANGE; |
183 | 0 | } |
184 | 0 | nclass = (ndigit != 0) + (nlower != 0) + (nupper != 0) + |
185 | 0 | (nnonalnum != 0) + (nnonascii != 0); |
186 | 0 | if (nclass < 3) { |
187 | 0 | return CKR_PIN_LEN_RANGE; |
188 | 0 | } |
189 | 0 | return CKR_OK; |
190 | 0 | } |
191 | | |
192 | | /* FIPS required checks before any useful cryptographic services */ |
193 | | static CK_RV |
194 | | sftk_fipsCheck(void) |
195 | 0 | { |
196 | 0 | if (sftk_fatalError) |
197 | 0 | return CKR_DEVICE_ERROR; |
198 | 0 | if (isLevel2 && !isLoggedIn) |
199 | 0 | return CKR_USER_NOT_LOGGED_IN; |
200 | 0 | return CKR_OK; |
201 | 0 | } |
202 | | |
203 | | #define SFTK_FIPSCHECK() \ |
204 | 0 | CK_RV rv; \ |
205 | 0 | if ((rv = sftk_fipsCheck()) != CKR_OK) \ |
206 | 0 | return rv; |
207 | | |
208 | | #define SFTK_FIPSFATALCHECK() \ |
209 | 0 | if (sftk_fatalError) \ |
210 | 0 | return CKR_DEVICE_ERROR; |
211 | | |
212 | | /* grab an attribute out of a raw template */ |
213 | | void * |
214 | | fc_getAttribute(CK_ATTRIBUTE_PTR pTemplate, |
215 | | CK_ULONG ulCount, CK_ATTRIBUTE_TYPE type) |
216 | 0 | { |
217 | 0 | int i; |
218 | |
|
219 | 0 | for (i = 0; i < (int)ulCount; i++) { |
220 | 0 | if (pTemplate[i].type == type) { |
221 | 0 | return pTemplate[i].pValue; |
222 | 0 | } |
223 | 0 | } |
224 | 0 | return NULL; |
225 | 0 | } |
226 | | |
227 | | #define __PASTE(x, y) x##y |
228 | | |
229 | | /* ------------- forward declare all the NSC_ functions ------------- */ |
230 | | #undef CK_NEED_ARG_LIST |
231 | | #undef CK_PKCS11_FUNCTION_INFO |
232 | | |
233 | | #define CK_PKCS11_3_0 1 |
234 | | |
235 | | #define CK_PKCS11_FUNCTION_INFO(name) CK_RV __PASTE(NS, name) |
236 | | #define CK_NEED_ARG_LIST 1 |
237 | | |
238 | | #include "pkcs11f.h" |
239 | | |
240 | | /* ------------- forward declare all the FIPS functions ------------- */ |
241 | | #undef CK_NEED_ARG_LIST |
242 | | #undef CK_PKCS11_FUNCTION_INFO |
243 | | |
244 | | #define CK_PKCS11_FUNCTION_INFO(name) CK_RV __PASTE(F, name) |
245 | | #define CK_NEED_ARG_LIST 1 |
246 | | |
247 | | #include "pkcs11f.h" |
248 | | |
249 | | /* ------------- build the CK_CRYPTO_TABLE ------------------------- */ |
250 | | static CK_FUNCTION_LIST_3_0 sftk_fipsTable = { |
251 | | { 3, 0 }, |
252 | | |
253 | | #undef CK_NEED_ARG_LIST |
254 | | #undef CK_PKCS11_FUNCTION_INFO |
255 | | |
256 | | #define CK_PKCS11_FUNCTION_INFO(name) \ |
257 | | __PASTE(F, name) \ |
258 | | , |
259 | | |
260 | | #include "pkcs11f.h" |
261 | | |
262 | | }; |
263 | | |
264 | | /* forward declaration of special GetInfo functions */ |
265 | | CK_RV FC_GetInfoV2(CK_INFO_PTR pInfo); |
266 | | CK_RV NSC_GetInfoV2(CK_INFO_PTR pInfo); |
267 | | CK_RV FC_GetMechanismInfoV2(CK_SLOT_ID slotID, CK_MECHANISM_TYPE type, |
268 | | CK_MECHANISM_INFO_PTR pInfo); |
269 | | CK_RV NSC_GetMechanismInfoV2(CK_SLOT_ID slotID, CK_MECHANISM_TYPE type, |
270 | | CK_MECHANISM_INFO_PTR pInfo); |
271 | | |
272 | | static CK_FUNCTION_LIST sftk_fipsTable_v2 = { |
273 | | { 2, 40 }, |
274 | | |
275 | | #undef CK_PKCS11_3_0 |
276 | | #define CK_PKCS11_2_0_ONLY 1 |
277 | | #undef CK_NEED_ARG_LIST |
278 | | #undef CK_PKCS11_FUNCTION_INFO |
279 | | #define C_GetInfo C_GetInfoV2 |
280 | | #define C_GetMechanismInfo C_GetMechanismInfoV2 |
281 | | |
282 | | #define CK_PKCS11_FUNCTION_INFO(name) \ |
283 | | __PASTE(F, name) \ |
284 | | , |
285 | | |
286 | | #include "pkcs11f.h" |
287 | | |
288 | | }; |
289 | | |
290 | | #undef C_GetInfo |
291 | | #undef C_GetMechanismInfo |
292 | | #undef CK_NEED_ARG_LIST |
293 | | #undef CK_PKCS11_FUNCTION_INFO |
294 | | #undef CK_PKCS11_2_0_ONLY |
295 | | |
296 | | #undef __PASTE |
297 | | |
298 | | /* |
299 | | * Array is orderd by default first |
300 | | */ |
301 | | static CK_INTERFACE fips_interfaces[] = { |
302 | | { (CK_UTF8CHAR_PTR) "PKCS 11", &sftk_fipsTable, NSS_INTERFACE_FLAGS }, |
303 | | { (CK_UTF8CHAR_PTR) "PKCS 11", &sftk_fipsTable_v2, NSS_INTERFACE_FLAGS }, |
304 | | { (CK_UTF8CHAR_PTR) "Vendor NSS Module Interface", &sftk_module_funcList, NSS_INTERFACE_FLAGS }, |
305 | | { (CK_UTF8CHAR_PTR) "Vendor NSS FIPS Interface", &sftk_fips_funcList, NSS_INTERFACE_FLAGS } |
306 | | }; |
307 | | /* must match the count of interfaces in fips_interfaces above*/ |
308 | 0 | #define FIPS_INTERFACE_COUNT 4 |
309 | | |
310 | | /* CKO_NOT_A_KEY can be any object class that's not a key object. */ |
311 | 0 | #define CKO_NOT_A_KEY CKO_DATA |
312 | | |
313 | | #define SFTK_IS_KEY_OBJECT(objClass) \ |
314 | 0 | (((objClass) == CKO_PUBLIC_KEY) || \ |
315 | 0 | ((objClass) == CKO_PRIVATE_KEY) || \ |
316 | 0 | ((objClass) == CKO_SECRET_KEY)) |
317 | | |
318 | | #define SFTK_IS_NONPUBLIC_KEY_OBJECT(objClass) \ |
319 | 0 | (((objClass) == CKO_PRIVATE_KEY) || ((objClass) == CKO_SECRET_KEY)) |
320 | | |
321 | | static CK_RV |
322 | | sftk_get_object_class_and_fipsCheck(CK_SESSION_HANDLE hSession, |
323 | | CK_OBJECT_HANDLE hObject, CK_OBJECT_CLASS *pObjClass) |
324 | 0 | { |
325 | 0 | CK_RV rv; |
326 | 0 | CK_ATTRIBUTE class; |
327 | 0 | class.type = CKA_CLASS; |
328 | 0 | class.pValue = pObjClass; |
329 | 0 | class.ulValueLen = sizeof(*pObjClass); |
330 | 0 | rv = NSC_GetAttributeValue(hSession, hObject, &class, 1); |
331 | 0 | if ((rv == CKR_OK) && SFTK_IS_NONPUBLIC_KEY_OBJECT(*pObjClass)) { |
332 | 0 | rv = sftk_fipsCheck(); |
333 | 0 | } |
334 | 0 | return rv; |
335 | 0 | } |
336 | | |
337 | | #ifdef LINUX |
338 | | |
339 | | int |
340 | | sftk_mapLinuxAuditType(NSSAuditSeverity severity, NSSAuditType auditType) |
341 | 0 | { |
342 | 0 | switch (auditType) { |
343 | 0 | case NSS_AUDIT_ACCESS_KEY: |
344 | 0 | case NSS_AUDIT_CHANGE_KEY: |
345 | 0 | case NSS_AUDIT_COPY_KEY: |
346 | 0 | case NSS_AUDIT_DERIVE_KEY: |
347 | 0 | case NSS_AUDIT_DESTROY_KEY: |
348 | 0 | case NSS_AUDIT_DIGEST_KEY: |
349 | 0 | case NSS_AUDIT_GENERATE_KEY: |
350 | 0 | case NSS_AUDIT_LOAD_KEY: |
351 | 0 | case NSS_AUDIT_UNWRAP_KEY: |
352 | 0 | case NSS_AUDIT_WRAP_KEY: |
353 | 0 | return AUDIT_CRYPTO_KEY_USER; |
354 | 0 | case NSS_AUDIT_CRYPT: |
355 | 0 | return (severity == NSS_AUDIT_ERROR) ? AUDIT_CRYPTO_FAILURE_USER : AUDIT_CRYPTO_KEY_USER; |
356 | 0 | case NSS_AUDIT_FIPS_STATE: |
357 | 0 | case NSS_AUDIT_INIT_PIN: |
358 | 0 | case NSS_AUDIT_INIT_TOKEN: |
359 | 0 | case NSS_AUDIT_SET_PIN: |
360 | 0 | return AUDIT_CRYPTO_PARAM_CHANGE_USER; |
361 | 0 | case NSS_AUDIT_SELF_TEST: |
362 | 0 | return AUDIT_CRYPTO_TEST_USER; |
363 | 0 | case NSS_AUDIT_LOGIN: |
364 | 0 | return AUDIT_CRYPTO_LOGIN; |
365 | 0 | case NSS_AUDIT_LOGOUT: |
366 | 0 | return AUDIT_CRYPTO_LOGOUT; |
367 | | /* we skip the fault case here so we can get compiler |
368 | | * warnings if new 'NSSAuditType's are added without |
369 | | * added them to this list, defaults fall through */ |
370 | 0 | } |
371 | | /* default */ |
372 | 0 | return AUDIT_CRYPTO_PARAM_CHANGE_USER; |
373 | 0 | } |
374 | | #endif |
375 | | |
376 | | /********************************************************************** |
377 | | * |
378 | | * FIPS 140 auditable event logging |
379 | | * |
380 | | **********************************************************************/ |
381 | | |
382 | | PRBool sftk_audit_enabled = PR_FALSE; |
383 | | |
384 | | /* |
385 | | * Each audit record must have the following information: |
386 | | * - Date and time of the event |
387 | | * - Type of event |
388 | | * - user (subject) identity |
389 | | * - outcome (success or failure) of the event |
390 | | * - process ID |
391 | | * - name (ID) of the object |
392 | | * - for changes to data (except for authentication data and CSPs), the new |
393 | | * and old values of the data |
394 | | * - for authentication attempts, the origin of the attempt (e.g., terminal |
395 | | * identifier) |
396 | | * - for assuming a role, the type of role, and the location of the request |
397 | | */ |
398 | | void |
399 | | sftk_LogAuditMessage(NSSAuditSeverity severity, NSSAuditType auditType, |
400 | | const char *msg) |
401 | 0 | { |
402 | 0 | #ifdef NSS_AUDIT_WITH_SYSLOG |
403 | 0 | int level; |
404 | |
|
405 | 0 | switch (severity) { |
406 | 0 | case NSS_AUDIT_ERROR: |
407 | 0 | level = LOG_ERR; |
408 | 0 | break; |
409 | 0 | case NSS_AUDIT_WARNING: |
410 | 0 | level = LOG_WARNING; |
411 | 0 | break; |
412 | 0 | default: |
413 | 0 | level = LOG_INFO; |
414 | 0 | break; |
415 | 0 | } |
416 | | /* timestamp is provided by syslog in the message header */ |
417 | 0 | syslog(level | LOG_USER /* facility */, |
418 | 0 | "NSS " SOFTOKEN_LIB_NAME "[pid=%d uid=%d]: %s", |
419 | 0 | (int)getpid(), (int)getuid(), msg); |
420 | 0 | #ifdef LINUX |
421 | 0 | if (pthread_once(&libaudit_once_control, libaudit_init) != 0) { |
422 | 0 | return; |
423 | 0 | } |
424 | 0 | if (libaudit_handle) { |
425 | 0 | int audit_fd; |
426 | 0 | int linuxAuditType; |
427 | 0 | int result = (severity != NSS_AUDIT_ERROR); /* 1=success; 0=failed */ |
428 | 0 | char *message = PR_smprintf("NSS " SOFTOKEN_LIB_NAME ": %s", msg); |
429 | 0 | if (!message) { |
430 | 0 | return; |
431 | 0 | } |
432 | 0 | audit_fd = audit_open_func(); |
433 | 0 | if (audit_fd < 0) { |
434 | 0 | PR_smprintf_free(message); |
435 | 0 | return; |
436 | 0 | } |
437 | 0 | linuxAuditType = sftk_mapLinuxAuditType(severity, auditType); |
438 | 0 | if (audit_log_user_message_func) { |
439 | 0 | audit_log_user_message_func(audit_fd, linuxAuditType, message, |
440 | 0 | NULL, NULL, NULL, result); |
441 | 0 | } else { |
442 | 0 | audit_send_user_message_func(audit_fd, linuxAuditType, message); |
443 | 0 | } |
444 | 0 | audit_close_func(audit_fd); |
445 | 0 | PR_smprintf_free(message); |
446 | 0 | } |
447 | 0 | #endif /* LINUX */ |
448 | | #else |
449 | | /* do nothing */ |
450 | | #endif |
451 | 0 | } |
452 | | |
453 | | /********************************************************************** |
454 | | * |
455 | | * Start of PKCS 11 functions |
456 | | * |
457 | | **********************************************************************/ |
458 | | /* return the function list */ |
459 | | CK_RV |
460 | | FC_GetFunctionList(CK_FUNCTION_LIST_PTR *pFunctionList) |
461 | 0 | { |
462 | |
|
463 | 0 | CHECK_FORK(); |
464 | |
|
465 | 0 | *pFunctionList = &sftk_fipsTable_v2; |
466 | 0 | return CKR_OK; |
467 | 0 | } |
468 | | |
469 | | CK_RV |
470 | | FC_GetInterfaceList(CK_INTERFACE_PTR interfaces, CK_ULONG_PTR pulCount) |
471 | 0 | { |
472 | 0 | CK_ULONG count = *pulCount; |
473 | 0 | *pulCount = FIPS_INTERFACE_COUNT; |
474 | 0 | if (interfaces == NULL) { |
475 | 0 | return CKR_OK; |
476 | 0 | } |
477 | 0 | if (count < FIPS_INTERFACE_COUNT) { |
478 | 0 | return CKR_BUFFER_TOO_SMALL; |
479 | 0 | } |
480 | 0 | PORT_Memcpy(interfaces, fips_interfaces, sizeof(fips_interfaces)); |
481 | 0 | return CKR_OK; |
482 | 0 | } |
483 | | |
484 | | /* |
485 | | * Get the requested interface, use the fips_interfaces array so we can |
486 | | * easily add new interfaces as they occur. |
487 | | */ |
488 | | CK_RV |
489 | | FC_GetInterface(CK_UTF8CHAR_PTR pInterfaceName, CK_VERSION_PTR pVersion, |
490 | | CK_INTERFACE_PTR_PTR ppInterface, CK_FLAGS flags) |
491 | 0 | { |
492 | 0 | int i; |
493 | 0 | for (i = 0; i < FIPS_INTERFACE_COUNT; i++) { |
494 | 0 | CK_INTERFACE_PTR interface = &fips_interfaces[i]; |
495 | 0 | if (pInterfaceName && PORT_Strcmp((char *)pInterfaceName, (char *)interface->pInterfaceName) != 0) { |
496 | 0 | continue; |
497 | 0 | } |
498 | 0 | if (pVersion && PORT_Memcmp(pVersion, (CK_VERSION *)interface->pFunctionList, sizeof(CK_VERSION)) != 0) { |
499 | 0 | continue; |
500 | 0 | } |
501 | 0 | if (flags & ((interface->flags & flags) != flags)) { |
502 | 0 | continue; |
503 | 0 | } |
504 | 0 | *ppInterface = interface; |
505 | 0 | return CKR_OK; |
506 | 0 | } |
507 | 0 | return CKR_ARGUMENTS_BAD; |
508 | 0 | } |
509 | | |
510 | | /* sigh global so pkcs11 can read it */ |
511 | | PRBool nsf_init = PR_FALSE; |
512 | | |
513 | | void |
514 | | fc_log_init_error(CK_RV crv) |
515 | 0 | { |
516 | 0 | if (sftk_audit_enabled) { |
517 | 0 | char msg[128]; |
518 | 0 | PR_snprintf(msg, sizeof msg, |
519 | 0 | "C_Initialize()=0x%08lX " |
520 | 0 | "power-up self-tests failed", |
521 | 0 | (PRUint32)crv); |
522 | 0 | sftk_LogAuditMessage(NSS_AUDIT_ERROR, NSS_AUDIT_SELF_TEST, msg); |
523 | 0 | } |
524 | 0 | } |
525 | | |
526 | | /* FC_Initialize initializes the PKCS #11 library. */ |
527 | | CK_RV |
528 | | FC_Initialize(CK_VOID_PTR pReserved) |
529 | 0 | { |
530 | 0 | const char *envp; |
531 | 0 | CK_RV crv; |
532 | 0 | PRBool rerun; |
533 | |
|
534 | 0 | if ((envp = PR_GetEnv("NSS_ENABLE_AUDIT")) != NULL) { |
535 | 0 | sftk_audit_enabled = (atoi(envp) == 1); |
536 | 0 | } |
537 | | |
538 | | /* if we have the forcePOST flag on, rerun the integrity checks */ |
539 | | /* we need to know this before we fully parse the arguments in |
540 | | * nsc_CommonInitialize, so read it now */ |
541 | 0 | rerun = sftk_RawArgHasFlag("flags", "forcePost", pReserved); |
542 | | |
543 | | /* At this point we should have already done post and integrity checks. |
544 | | * if we haven't, it probably means the FIPS product has not been installed |
545 | | * or the tests failed. Don't let an application try to enter FIPS mode. This |
546 | | * also forces the tests to be rerun if forcePOST is set. */ |
547 | 0 | crv = sftk_FIPSEntryOK(rerun); |
548 | 0 | if (crv != CKR_OK) { |
549 | 0 | sftk_fatalError = PR_TRUE; |
550 | 0 | fc_log_init_error(crv); |
551 | 0 | return crv; |
552 | 0 | } |
553 | | |
554 | 0 | sftk_ForkReset(pReserved, &crv); |
555 | |
|
556 | 0 | if (nsf_init) { |
557 | 0 | return CKR_CRYPTOKI_ALREADY_INITIALIZED; |
558 | 0 | } |
559 | | |
560 | 0 | crv = nsc_CommonInitialize(pReserved, PR_TRUE); |
561 | | |
562 | | /* not an 'else' rv can be set by either SFTK_LowInit or SFTK_SlotInit*/ |
563 | 0 | if (crv != CKR_OK) { |
564 | 0 | sftk_fatalError = PR_TRUE; |
565 | 0 | return crv; |
566 | 0 | } |
567 | | |
568 | 0 | sftk_fatalError = PR_FALSE; /* any error has been reset */ |
569 | 0 | nsf_init = PR_TRUE; |
570 | 0 | isLevel2 = PR_TRUE; /* assume level 2 unless we learn otherwise */ |
571 | |
|
572 | 0 | return CKR_OK; |
573 | 0 | } |
574 | | |
575 | | /*FC_Finalize indicates that an application is done with the PKCS #11 library.*/ |
576 | | CK_RV |
577 | | FC_Finalize(CK_VOID_PTR pReserved) |
578 | 0 | { |
579 | 0 | CK_RV crv; |
580 | |
|
581 | 0 | if (sftk_ForkReset(pReserved, &crv)) { |
582 | 0 | return crv; |
583 | 0 | } |
584 | | |
585 | 0 | if (!nsf_init) { |
586 | 0 | return CKR_OK; |
587 | 0 | } |
588 | | |
589 | 0 | crv = nsc_CommonFinalize(pReserved, PR_TRUE); |
590 | |
|
591 | 0 | nsf_init = (PRBool) !(crv == CKR_OK); |
592 | 0 | return crv; |
593 | 0 | } |
594 | | |
595 | | /* FC_GetInfo returns general information about PKCS #11. */ |
596 | | CK_RV |
597 | | FC_GetInfo(CK_INFO_PTR pInfo) |
598 | 0 | { |
599 | 0 | CHECK_FORK(); |
600 | |
|
601 | 0 | return NSC_GetInfo(pInfo); |
602 | 0 | } |
603 | | |
604 | | /* FC_GetInfo returns general information about PKCS #11. */ |
605 | | CK_RV |
606 | | FC_GetInfoV2(CK_INFO_PTR pInfo) |
607 | 0 | { |
608 | 0 | CHECK_FORK(); |
609 | |
|
610 | 0 | return NSC_GetInfoV2(pInfo); |
611 | 0 | } |
612 | | |
613 | | /* FC_GetSlotList obtains a list of slots in the system. */ |
614 | | CK_RV |
615 | | FC_GetSlotList(CK_BBOOL tokenPresent, |
616 | | CK_SLOT_ID_PTR pSlotList, CK_ULONG_PTR pulCount) |
617 | 0 | { |
618 | 0 | CHECK_FORK(); |
619 | |
|
620 | 0 | return nsc_CommonGetSlotList(tokenPresent, pSlotList, pulCount, |
621 | 0 | NSC_FIPS_MODULE); |
622 | 0 | } |
623 | | |
624 | | /* FC_GetSlotInfo obtains information about a particular slot in the system. */ |
625 | | CK_RV |
626 | | FC_GetSlotInfo(CK_SLOT_ID slotID, CK_SLOT_INFO_PTR pInfo) |
627 | 0 | { |
628 | 0 | CHECK_FORK(); |
629 | |
|
630 | 0 | return NSC_GetSlotInfo(slotID, pInfo); |
631 | 0 | } |
632 | | |
633 | | /*FC_GetTokenInfo obtains information about a particular token in the system.*/ |
634 | | CK_RV |
635 | | FC_GetTokenInfo(CK_SLOT_ID slotID, CK_TOKEN_INFO_PTR pInfo) |
636 | 0 | { |
637 | 0 | CK_RV crv; |
638 | |
|
639 | 0 | CHECK_FORK(); |
640 | |
|
641 | 0 | crv = NSC_GetTokenInfo(slotID, pInfo); |
642 | 0 | if (crv == CKR_OK) { |
643 | | /* use the global database to figure out if we are running in |
644 | | * FIPS 140 Level 1 or Level 2 */ |
645 | 0 | if (slotID == FIPS_SLOT_ID && |
646 | 0 | (pInfo->flags & CKF_LOGIN_REQUIRED) == 0) { |
647 | 0 | isLevel2 = PR_FALSE; |
648 | 0 | } |
649 | 0 | } |
650 | 0 | return crv; |
651 | 0 | } |
652 | | |
653 | | /*FC_GetMechanismList obtains a list of mechanism types supported by a token.*/ |
654 | | CK_RV |
655 | | FC_GetMechanismList(CK_SLOT_ID slotID, |
656 | | CK_MECHANISM_TYPE_PTR pMechanismList, CK_ULONG_PTR pusCount) |
657 | 0 | { |
658 | 0 | CHECK_FORK(); |
659 | |
|
660 | 0 | SFTK_FIPSFATALCHECK(); |
661 | 0 | if (sftk_isFIPS(slotID)) { |
662 | 0 | slotID = NETSCAPE_SLOT_ID; |
663 | 0 | } |
664 | | /* FIPS Slots support all functions */ |
665 | 0 | return NSC_GetMechanismList(slotID, pMechanismList, pusCount); |
666 | 0 | } |
667 | | |
668 | | /* FC_GetMechanismInfo obtains information about a particular mechanism |
669 | | * possibly supported by a token. */ |
670 | | CK_RV |
671 | | FC_GetMechanismInfo(CK_SLOT_ID slotID, CK_MECHANISM_TYPE type, |
672 | | CK_MECHANISM_INFO_PTR pInfo) |
673 | 0 | { |
674 | 0 | CHECK_FORK(); |
675 | |
|
676 | 0 | SFTK_FIPSFATALCHECK(); |
677 | 0 | if (sftk_isFIPS(slotID)) { |
678 | 0 | slotID = NETSCAPE_SLOT_ID; |
679 | 0 | } |
680 | | /* FIPS Slots support all functions */ |
681 | 0 | return NSC_GetMechanismInfo(slotID, type, pInfo); |
682 | 0 | } |
683 | | |
684 | | /* FC_GetMechanismInfoV2 same as FC_GetMechanismInfo except the Message |
685 | | * flags have been stripped out */ |
686 | | CK_RV |
687 | | FC_GetMechanismInfoV2(CK_SLOT_ID slotID, CK_MECHANISM_TYPE type, |
688 | | CK_MECHANISM_INFO_PTR pInfo) |
689 | 0 | { |
690 | 0 | CHECK_FORK(); |
691 | |
|
692 | 0 | SFTK_FIPSFATALCHECK(); |
693 | 0 | if (sftk_isFIPS(slotID)) { |
694 | 0 | slotID = NETSCAPE_SLOT_ID; |
695 | 0 | } |
696 | | /* FIPS Slots support all functions */ |
697 | 0 | return NSC_GetMechanismInfoV2(slotID, type, pInfo); |
698 | 0 | } |
699 | | |
700 | | /* FC_InitToken initializes a token. */ |
701 | | CK_RV |
702 | | FC_InitToken(CK_SLOT_ID slotID, CK_CHAR_PTR pPin, |
703 | | CK_ULONG usPinLen, CK_CHAR_PTR pLabel) |
704 | 0 | { |
705 | 0 | CK_RV crv; |
706 | |
|
707 | 0 | CHECK_FORK(); |
708 | |
|
709 | 0 | crv = NSC_InitToken(slotID, pPin, usPinLen, pLabel); |
710 | 0 | if (sftk_audit_enabled) { |
711 | 0 | char msg[128]; |
712 | 0 | NSSAuditSeverity severity = (crv == CKR_OK) ? NSS_AUDIT_INFO : NSS_AUDIT_ERROR; |
713 | | /* pLabel points to a 32-byte label, which is not null-terminated */ |
714 | 0 | PR_snprintf(msg, sizeof msg, |
715 | 0 | "C_InitToken(slotID=%lu, pLabel=\"%.32s\")=0x%08lX", |
716 | 0 | (PRUint32)slotID, pLabel, (PRUint32)crv); |
717 | 0 | sftk_LogAuditMessage(severity, NSS_AUDIT_INIT_TOKEN, msg); |
718 | 0 | } |
719 | 0 | return crv; |
720 | 0 | } |
721 | | |
722 | | /* FC_InitPIN initializes the normal user's PIN. */ |
723 | | CK_RV |
724 | | FC_InitPIN(CK_SESSION_HANDLE hSession, |
725 | | CK_CHAR_PTR pPin, CK_ULONG ulPinLen) |
726 | 0 | { |
727 | 0 | CK_RV rv; |
728 | |
|
729 | 0 | CHECK_FORK(); |
730 | |
|
731 | 0 | if (sftk_fatalError) |
732 | 0 | return CKR_DEVICE_ERROR; |
733 | | /* NSC_InitPIN will only work once per database. We can either initialize |
734 | | * it to level1 (pin len == 0) or level2. If we initialize to level 2, then |
735 | | * we need to make sure the pin meets FIPS requirements */ |
736 | 0 | if ((ulPinLen == 0) || ((rv = sftk_newPinCheck(pPin, ulPinLen)) == CKR_OK)) { |
737 | 0 | rv = NSC_InitPIN(hSession, pPin, ulPinLen); |
738 | 0 | if ((rv == CKR_OK) && |
739 | 0 | (sftk_SlotIDFromSessionHandle(hSession) == FIPS_SLOT_ID)) { |
740 | 0 | isLevel2 = (ulPinLen > 0) ? PR_TRUE : PR_FALSE; |
741 | 0 | } |
742 | 0 | } |
743 | 0 | if (sftk_audit_enabled) { |
744 | 0 | char msg[128]; |
745 | 0 | NSSAuditSeverity severity = (rv == CKR_OK) ? NSS_AUDIT_INFO : NSS_AUDIT_ERROR; |
746 | 0 | PR_snprintf(msg, sizeof msg, |
747 | 0 | "C_InitPIN(hSession=0x%08lX)=0x%08lX", |
748 | 0 | (PRUint32)hSession, (PRUint32)rv); |
749 | 0 | sftk_LogAuditMessage(severity, NSS_AUDIT_INIT_PIN, msg); |
750 | 0 | } |
751 | 0 | return rv; |
752 | 0 | } |
753 | | |
754 | | /* FC_SetPIN modifies the PIN of user that is currently logged in. */ |
755 | | /* NOTE: This is only valid for the PRIVATE_KEY_SLOT */ |
756 | | CK_RV |
757 | | FC_SetPIN(CK_SESSION_HANDLE hSession, CK_CHAR_PTR pOldPin, |
758 | | CK_ULONG usOldLen, CK_CHAR_PTR pNewPin, CK_ULONG usNewLen) |
759 | 0 | { |
760 | 0 | CK_RV rv; |
761 | |
|
762 | 0 | CHECK_FORK(); |
763 | |
|
764 | 0 | rv = sftk_fipsCheck(); |
765 | 0 | if (rv != CKR_OK) { |
766 | 0 | goto loser; |
767 | 0 | } |
768 | | |
769 | 0 | if (isLevel2 || usNewLen > 0) { |
770 | 0 | rv = sftk_newPinCheck(pNewPin, usNewLen); |
771 | 0 | if (rv != CKR_OK) { |
772 | 0 | goto loser; |
773 | 0 | } |
774 | 0 | rv = NSC_SetPIN(hSession, pOldPin, usOldLen, pNewPin, usNewLen); |
775 | 0 | if (rv != CKR_OK) { |
776 | 0 | goto loser; |
777 | 0 | } |
778 | 0 | if (sftk_SlotIDFromSessionHandle(hSession) == FIPS_SLOT_ID) { |
779 | | /* if we set the password in level1 we now go |
780 | | * to level2. NOTE: we don't allow the user to |
781 | | * go from level2 to level1 */ |
782 | 0 | isLevel2 = PR_TRUE; |
783 | 0 | } |
784 | 0 | } else { |
785 | | /* here both old and new passwords are empty, but we need to |
786 | | * call NSC_SetPIN to force rekey the database entries */ |
787 | 0 | PORT_Assert(usNewLen == 0); |
788 | 0 | rv = NSC_SetPIN(hSession, pOldPin, usOldLen, pNewPin, usNewLen); |
789 | 0 | if (rv != CKR_OK) { |
790 | 0 | goto loser; |
791 | 0 | } |
792 | 0 | } |
793 | | |
794 | 0 | loser: |
795 | 0 | if (sftk_audit_enabled) { |
796 | 0 | char msg[128]; |
797 | 0 | NSSAuditSeverity severity = (rv == CKR_OK) ? NSS_AUDIT_INFO : NSS_AUDIT_ERROR; |
798 | 0 | PR_snprintf(msg, sizeof msg, |
799 | 0 | "C_SetPIN(hSession=0x%08lX)=0x%08lX", |
800 | 0 | (PRUint32)hSession, (PRUint32)rv); |
801 | 0 | sftk_LogAuditMessage(severity, NSS_AUDIT_SET_PIN, msg); |
802 | 0 | } |
803 | 0 | return rv; |
804 | 0 | } |
805 | | |
806 | | /* FC_OpenSession opens a session between an application and a token. */ |
807 | | CK_RV |
808 | | FC_OpenSession(CK_SLOT_ID slotID, CK_FLAGS flags, |
809 | | CK_VOID_PTR pApplication, CK_NOTIFY Notify, CK_SESSION_HANDLE_PTR phSession) |
810 | 0 | { |
811 | 0 | SFTK_FIPSFATALCHECK(); |
812 | |
|
813 | 0 | CHECK_FORK(); |
814 | |
|
815 | 0 | return NSC_OpenSession(slotID, flags, pApplication, Notify, phSession); |
816 | 0 | } |
817 | | |
818 | | /* FC_CloseSession closes a session between an application and a token. */ |
819 | | CK_RV |
820 | | FC_CloseSession(CK_SESSION_HANDLE hSession) |
821 | 0 | { |
822 | 0 | CHECK_FORK(); |
823 | |
|
824 | 0 | return NSC_CloseSession(hSession); |
825 | 0 | } |
826 | | |
827 | | /* FC_CloseAllSessions closes all sessions with a token. */ |
828 | | CK_RV |
829 | | FC_CloseAllSessions(CK_SLOT_ID slotID) |
830 | 0 | { |
831 | |
|
832 | 0 | CHECK_FORK(); |
833 | |
|
834 | 0 | return NSC_CloseAllSessions(slotID); |
835 | 0 | } |
836 | | |
837 | | CK_RV |
838 | | FC_SessionCancel(CK_SESSION_HANDLE hSession, CK_FLAGS flags) |
839 | 0 | { |
840 | 0 | SFTK_FIPSFATALCHECK(); |
841 | |
|
842 | 0 | CHECK_FORK(); |
843 | |
|
844 | 0 | return NSC_SessionCancel(hSession, flags); |
845 | 0 | } |
846 | | |
847 | | /* FC_GetSessionInfo obtains information about the session. */ |
848 | | CK_RV |
849 | | FC_GetSessionInfo(CK_SESSION_HANDLE hSession, |
850 | | CK_SESSION_INFO_PTR pInfo) |
851 | 0 | { |
852 | 0 | CK_RV rv; |
853 | 0 | SFTK_FIPSFATALCHECK(); |
854 | |
|
855 | 0 | CHECK_FORK(); |
856 | |
|
857 | 0 | rv = NSC_GetSessionInfo(hSession, pInfo); |
858 | 0 | if (rv == CKR_OK) { |
859 | | /* handle the case where the auxilary slot doesn't require login. |
860 | | * piggy back on the main token's login state */ |
861 | 0 | if (isLoggedIn && |
862 | 0 | ((pInfo->state == CKS_RO_PUBLIC_SESSION) || |
863 | 0 | (pInfo->state == CKS_RW_PUBLIC_SESSION))) { |
864 | 0 | CK_RV crv; |
865 | 0 | CK_TOKEN_INFO tInfo; |
866 | 0 | crv = NSC_GetTokenInfo(sftk_SlotIDFromSessionHandle(hSession), |
867 | 0 | &tInfo); |
868 | | /* if the token doesn't login, use our global login state */ |
869 | 0 | if ((crv == CKR_OK) && ((tInfo.flags & CKF_LOGIN_REQUIRED) == 0)) { |
870 | 0 | if (pInfo->state == CKS_RO_PUBLIC_SESSION) { |
871 | 0 | pInfo->state = CKS_RO_USER_FUNCTIONS; |
872 | 0 | } else { |
873 | 0 | pInfo->state = CKS_RW_USER_FUNCTIONS; |
874 | 0 | } |
875 | 0 | } |
876 | 0 | } |
877 | 0 | } |
878 | 0 | return rv; |
879 | 0 | } |
880 | | |
881 | | /* FC_Login logs a user into a token. */ |
882 | | CK_RV |
883 | | FC_Login(CK_SESSION_HANDLE hSession, CK_USER_TYPE userType, |
884 | | CK_CHAR_PTR pPin, CK_ULONG usPinLen) |
885 | 0 | { |
886 | 0 | CK_RV rv; |
887 | 0 | PRBool successful; |
888 | 0 | if (sftk_fatalError) |
889 | 0 | return CKR_DEVICE_ERROR; |
890 | 0 | rv = NSC_Login(hSession, userType, pPin, usPinLen); |
891 | 0 | successful = (rv == CKR_OK) || (rv == CKR_USER_ALREADY_LOGGED_IN); |
892 | 0 | if (successful) |
893 | 0 | isLoggedIn = PR_TRUE; |
894 | 0 | if (sftk_audit_enabled) { |
895 | 0 | char msg[128]; |
896 | 0 | NSSAuditSeverity severity; |
897 | 0 | severity = successful ? NSS_AUDIT_INFO : NSS_AUDIT_ERROR; |
898 | 0 | PR_snprintf(msg, sizeof msg, |
899 | 0 | "C_Login(hSession=0x%08lX, userType=%lu)=0x%08lX", |
900 | 0 | (PRUint32)hSession, (PRUint32)userType, (PRUint32)rv); |
901 | 0 | sftk_LogAuditMessage(severity, NSS_AUDIT_LOGIN, msg); |
902 | 0 | } |
903 | 0 | return rv; |
904 | 0 | } |
905 | | |
906 | | CK_RV |
907 | | FC_LoginUser(CK_SESSION_HANDLE hSession, CK_USER_TYPE userType, |
908 | | CK_CHAR_PTR pPin, CK_ULONG ulPinLen, CK_UTF8CHAR_PTR pUsername, |
909 | | CK_ULONG ulUsernameLen) |
910 | 0 | { |
911 | 0 | CK_RV rv; |
912 | 0 | PRBool successful; |
913 | 0 | if (sftk_fatalError) |
914 | 0 | return CKR_DEVICE_ERROR; |
915 | 0 | rv = NSC_LoginUser(hSession, userType, pPin, ulPinLen, |
916 | 0 | pUsername, ulUsernameLen); |
917 | 0 | successful = (rv == CKR_OK) || (rv == CKR_USER_ALREADY_LOGGED_IN); |
918 | 0 | if (successful) |
919 | 0 | isLoggedIn = PR_TRUE; |
920 | 0 | if (sftk_audit_enabled) { |
921 | 0 | char msg[128]; |
922 | 0 | char user[61]; |
923 | 0 | int len = PR_MIN(ulUsernameLen, sizeof(user) - 1); |
924 | 0 | PORT_Memcpy(user, pUsername, len); |
925 | 0 | user[len] = 0; |
926 | 0 | NSSAuditSeverity severity; |
927 | 0 | severity = successful ? NSS_AUDIT_INFO : NSS_AUDIT_ERROR; |
928 | 0 | PR_snprintf(msg, sizeof msg, |
929 | 0 | "C_LoginUser(hSession=0x%08lX, userType=%lu username=%s)=0x%08lX", |
930 | 0 | (PRUint32)hSession, (PRUint32)userType, user, (PRUint32)rv); |
931 | 0 | sftk_LogAuditMessage(severity, NSS_AUDIT_LOGIN, msg); |
932 | 0 | } |
933 | 0 | return rv; |
934 | 0 | } |
935 | | |
936 | | /* FC_Logout logs a user out from a token. */ |
937 | | CK_RV |
938 | | FC_Logout(CK_SESSION_HANDLE hSession) |
939 | 0 | { |
940 | 0 | CK_RV rv; |
941 | |
|
942 | 0 | CHECK_FORK(); |
943 | |
|
944 | 0 | if ((rv = sftk_fipsCheck()) == CKR_OK) { |
945 | 0 | rv = NSC_Logout(hSession); |
946 | 0 | isLoggedIn = PR_FALSE; |
947 | 0 | } |
948 | 0 | if (sftk_audit_enabled) { |
949 | 0 | char msg[128]; |
950 | 0 | NSSAuditSeverity severity = (rv == CKR_OK) ? NSS_AUDIT_INFO : NSS_AUDIT_ERROR; |
951 | 0 | PR_snprintf(msg, sizeof msg, |
952 | 0 | "C_Logout(hSession=0x%08lX)=0x%08lX", |
953 | 0 | (PRUint32)hSession, (PRUint32)rv); |
954 | 0 | sftk_LogAuditMessage(severity, NSS_AUDIT_LOGOUT, msg); |
955 | 0 | } |
956 | 0 | return rv; |
957 | 0 | } |
958 | | |
959 | | /* FC_CreateObject creates a new object. */ |
960 | | CK_RV |
961 | | FC_CreateObject(CK_SESSION_HANDLE hSession, |
962 | | CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount, |
963 | | CK_OBJECT_HANDLE_PTR phObject) |
964 | 0 | { |
965 | 0 | CK_OBJECT_CLASS *classptr; |
966 | 0 | CK_RV rv = CKR_OK; |
967 | |
|
968 | 0 | CHECK_FORK(); |
969 | |
|
970 | 0 | classptr = (CK_OBJECT_CLASS *)fc_getAttribute(pTemplate, ulCount, CKA_CLASS); |
971 | 0 | if (classptr == NULL) |
972 | 0 | return CKR_TEMPLATE_INCOMPLETE; |
973 | | |
974 | 0 | if (*classptr == CKO_NSS_NEWSLOT || *classptr == CKO_NSS_DELSLOT) { |
975 | 0 | if (sftk_fatalError) |
976 | 0 | return CKR_DEVICE_ERROR; |
977 | 0 | } else { |
978 | 0 | rv = sftk_fipsCheck(); |
979 | 0 | if (rv != CKR_OK) |
980 | 0 | return rv; |
981 | 0 | } |
982 | | |
983 | | /* FIPS can't create keys from raw key material */ |
984 | 0 | if (SFTK_IS_NONPUBLIC_KEY_OBJECT(*classptr)) { |
985 | 0 | rv = CKR_ATTRIBUTE_VALUE_INVALID; |
986 | 0 | } else { |
987 | 0 | rv = NSC_CreateObject(hSession, pTemplate, ulCount, phObject); |
988 | 0 | } |
989 | 0 | if (sftk_audit_enabled && SFTK_IS_KEY_OBJECT(*classptr)) { |
990 | 0 | sftk_AuditCreateObject(hSession, pTemplate, ulCount, phObject, rv); |
991 | 0 | } |
992 | 0 | return rv; |
993 | 0 | } |
994 | | |
995 | | /* FC_CopyObject copies an object, creating a new object for the copy. */ |
996 | | CK_RV |
997 | | FC_CopyObject(CK_SESSION_HANDLE hSession, |
998 | | CK_OBJECT_HANDLE hObject, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount, |
999 | | CK_OBJECT_HANDLE_PTR phNewObject) |
1000 | 0 | { |
1001 | 0 | CK_RV rv; |
1002 | 0 | CK_OBJECT_CLASS objClass = CKO_NOT_A_KEY; |
1003 | |
|
1004 | 0 | CHECK_FORK(); |
1005 | |
|
1006 | 0 | SFTK_FIPSFATALCHECK(); |
1007 | 0 | rv = sftk_get_object_class_and_fipsCheck(hSession, hObject, &objClass); |
1008 | 0 | if (rv == CKR_OK) { |
1009 | 0 | rv = NSC_CopyObject(hSession, hObject, pTemplate, ulCount, phNewObject); |
1010 | 0 | } |
1011 | 0 | if (sftk_audit_enabled && SFTK_IS_KEY_OBJECT(objClass)) { |
1012 | 0 | sftk_AuditCopyObject(hSession, |
1013 | 0 | hObject, pTemplate, ulCount, phNewObject, rv); |
1014 | 0 | } |
1015 | 0 | return rv; |
1016 | 0 | } |
1017 | | |
1018 | | /* FC_DestroyObject destroys an object. */ |
1019 | | CK_RV |
1020 | | FC_DestroyObject(CK_SESSION_HANDLE hSession, |
1021 | | CK_OBJECT_HANDLE hObject) |
1022 | 0 | { |
1023 | 0 | CK_RV rv; |
1024 | 0 | CK_OBJECT_CLASS objClass = CKO_NOT_A_KEY; |
1025 | |
|
1026 | 0 | CHECK_FORK(); |
1027 | |
|
1028 | 0 | SFTK_FIPSFATALCHECK(); |
1029 | 0 | rv = sftk_get_object_class_and_fipsCheck(hSession, hObject, &objClass); |
1030 | 0 | if (rv == CKR_OK) { |
1031 | 0 | rv = NSC_DestroyObject(hSession, hObject); |
1032 | 0 | } |
1033 | 0 | if (sftk_audit_enabled && SFTK_IS_KEY_OBJECT(objClass)) { |
1034 | 0 | sftk_AuditDestroyObject(hSession, hObject, rv); |
1035 | 0 | } |
1036 | 0 | return rv; |
1037 | 0 | } |
1038 | | |
1039 | | /* FC_GetObjectSize gets the size of an object in bytes. */ |
1040 | | CK_RV |
1041 | | FC_GetObjectSize(CK_SESSION_HANDLE hSession, |
1042 | | CK_OBJECT_HANDLE hObject, CK_ULONG_PTR pulSize) |
1043 | 0 | { |
1044 | 0 | CK_RV rv; |
1045 | 0 | CK_OBJECT_CLASS objClass = CKO_NOT_A_KEY; |
1046 | |
|
1047 | 0 | CHECK_FORK(); |
1048 | |
|
1049 | 0 | SFTK_FIPSFATALCHECK(); |
1050 | 0 | rv = sftk_get_object_class_and_fipsCheck(hSession, hObject, &objClass); |
1051 | 0 | if (rv == CKR_OK) { |
1052 | 0 | rv = NSC_GetObjectSize(hSession, hObject, pulSize); |
1053 | 0 | } |
1054 | 0 | if (sftk_audit_enabled && SFTK_IS_KEY_OBJECT(objClass)) { |
1055 | 0 | sftk_AuditGetObjectSize(hSession, hObject, pulSize, rv); |
1056 | 0 | } |
1057 | 0 | return rv; |
1058 | 0 | } |
1059 | | |
1060 | | /* FC_GetAttributeValue obtains the value of one or more object attributes. */ |
1061 | | CK_RV |
1062 | | FC_GetAttributeValue(CK_SESSION_HANDLE hSession, |
1063 | | CK_OBJECT_HANDLE hObject, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount) |
1064 | 0 | { |
1065 | 0 | CK_RV rv; |
1066 | 0 | CK_OBJECT_CLASS objClass = CKO_NOT_A_KEY; |
1067 | |
|
1068 | 0 | CHECK_FORK(); |
1069 | |
|
1070 | 0 | SFTK_FIPSFATALCHECK(); |
1071 | 0 | rv = sftk_get_object_class_and_fipsCheck(hSession, hObject, &objClass); |
1072 | 0 | if (rv == CKR_OK) { |
1073 | 0 | rv = NSC_GetAttributeValue(hSession, hObject, pTemplate, ulCount); |
1074 | 0 | } |
1075 | 0 | if (sftk_audit_enabled && SFTK_IS_KEY_OBJECT(objClass)) { |
1076 | 0 | sftk_AuditGetAttributeValue(hSession, hObject, pTemplate, ulCount, rv); |
1077 | 0 | } |
1078 | 0 | return rv; |
1079 | 0 | } |
1080 | | |
1081 | | /* FC_SetAttributeValue modifies the value of one or more object attributes */ |
1082 | | CK_RV |
1083 | | FC_SetAttributeValue(CK_SESSION_HANDLE hSession, |
1084 | | CK_OBJECT_HANDLE hObject, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount) |
1085 | 0 | { |
1086 | 0 | CK_RV rv; |
1087 | 0 | CK_OBJECT_CLASS objClass = CKO_NOT_A_KEY; |
1088 | |
|
1089 | 0 | CHECK_FORK(); |
1090 | |
|
1091 | 0 | SFTK_FIPSFATALCHECK(); |
1092 | 0 | rv = sftk_get_object_class_and_fipsCheck(hSession, hObject, &objClass); |
1093 | 0 | if (rv == CKR_OK) { |
1094 | 0 | rv = NSC_SetAttributeValue(hSession, hObject, pTemplate, ulCount); |
1095 | 0 | } |
1096 | 0 | if (sftk_audit_enabled && SFTK_IS_KEY_OBJECT(objClass)) { |
1097 | 0 | sftk_AuditSetAttributeValue(hSession, hObject, pTemplate, ulCount, rv); |
1098 | 0 | } |
1099 | 0 | return rv; |
1100 | 0 | } |
1101 | | |
1102 | | /* FC_FindObjectsInit initializes a search for token and session objects |
1103 | | * that match a template. */ |
1104 | | CK_RV |
1105 | | FC_FindObjectsInit(CK_SESSION_HANDLE hSession, |
1106 | | CK_ATTRIBUTE_PTR pTemplate, CK_ULONG usCount) |
1107 | 0 | { |
1108 | | /* let publically readable object be found */ |
1109 | 0 | unsigned int i; |
1110 | 0 | CK_RV rv; |
1111 | 0 | PRBool needLogin = PR_FALSE; |
1112 | |
|
1113 | 0 | CHECK_FORK(); |
1114 | |
|
1115 | 0 | SFTK_FIPSFATALCHECK(); |
1116 | |
|
1117 | 0 | for (i = 0; i < usCount; i++) { |
1118 | 0 | CK_OBJECT_CLASS class; |
1119 | 0 | if (pTemplate[i].type != CKA_CLASS) { |
1120 | 0 | continue; |
1121 | 0 | } |
1122 | 0 | if (pTemplate[i].ulValueLen != sizeof(CK_OBJECT_CLASS)) { |
1123 | 0 | continue; |
1124 | 0 | } |
1125 | 0 | if (pTemplate[i].pValue == NULL) { |
1126 | 0 | continue; |
1127 | 0 | } |
1128 | 0 | class = *(CK_OBJECT_CLASS *)pTemplate[i].pValue; |
1129 | 0 | if ((class == CKO_PRIVATE_KEY) || (class == CKO_SECRET_KEY)) { |
1130 | 0 | needLogin = PR_TRUE; |
1131 | 0 | break; |
1132 | 0 | } |
1133 | 0 | } |
1134 | 0 | if (needLogin) { |
1135 | 0 | if ((rv = sftk_fipsCheck()) != CKR_OK) |
1136 | 0 | return rv; |
1137 | 0 | } |
1138 | 0 | return NSC_FindObjectsInit(hSession, pTemplate, usCount); |
1139 | 0 | } |
1140 | | |
1141 | | /* FC_FindObjects continues a search for token and session objects |
1142 | | * that match a template, obtaining additional object handles. */ |
1143 | | CK_RV |
1144 | | FC_FindObjects(CK_SESSION_HANDLE hSession, |
1145 | | CK_OBJECT_HANDLE_PTR phObject, CK_ULONG usMaxObjectCount, |
1146 | | CK_ULONG_PTR pusObjectCount) |
1147 | 0 | { |
1148 | 0 | CHECK_FORK(); |
1149 | | |
1150 | | /* let publically readable object be found */ |
1151 | 0 | SFTK_FIPSFATALCHECK(); |
1152 | 0 | return NSC_FindObjects(hSession, phObject, usMaxObjectCount, |
1153 | 0 | pusObjectCount); |
1154 | 0 | } |
1155 | | |
1156 | | /* |
1157 | | ************** Crypto Functions: Encrypt ************************ |
1158 | | */ |
1159 | | |
1160 | | /* FC_EncryptInit initializes an encryption operation. */ |
1161 | | CK_RV |
1162 | | FC_EncryptInit(CK_SESSION_HANDLE hSession, |
1163 | | CK_MECHANISM_PTR pMechanism, CK_OBJECT_HANDLE hKey) |
1164 | 0 | { |
1165 | 0 | SFTK_FIPSCHECK(); |
1166 | 0 | CHECK_FORK(); |
1167 | |
|
1168 | 0 | rv = NSC_EncryptInit(hSession, pMechanism, hKey); |
1169 | 0 | if (sftk_audit_enabled) { |
1170 | 0 | sftk_AuditCryptInit("Encrypt", hSession, pMechanism, hKey, rv); |
1171 | 0 | } |
1172 | 0 | return rv; |
1173 | 0 | } |
1174 | | |
1175 | | /* FC_Encrypt encrypts single-part data. */ |
1176 | | CK_RV |
1177 | | FC_Encrypt(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, |
1178 | | CK_ULONG usDataLen, CK_BYTE_PTR pEncryptedData, |
1179 | | CK_ULONG_PTR pusEncryptedDataLen) |
1180 | 0 | { |
1181 | 0 | SFTK_FIPSCHECK(); |
1182 | 0 | CHECK_FORK(); |
1183 | |
|
1184 | 0 | return NSC_Encrypt(hSession, pData, usDataLen, pEncryptedData, |
1185 | 0 | pusEncryptedDataLen); |
1186 | 0 | } |
1187 | | |
1188 | | /* FC_EncryptUpdate continues a multiple-part encryption operation. */ |
1189 | | CK_RV |
1190 | | FC_EncryptUpdate(CK_SESSION_HANDLE hSession, |
1191 | | CK_BYTE_PTR pPart, CK_ULONG usPartLen, CK_BYTE_PTR pEncryptedPart, |
1192 | | CK_ULONG_PTR pusEncryptedPartLen) |
1193 | 0 | { |
1194 | 0 | SFTK_FIPSCHECK(); |
1195 | 0 | CHECK_FORK(); |
1196 | |
|
1197 | 0 | return NSC_EncryptUpdate(hSession, pPart, usPartLen, pEncryptedPart, |
1198 | 0 | pusEncryptedPartLen); |
1199 | 0 | } |
1200 | | |
1201 | | /* FC_EncryptFinal finishes a multiple-part encryption operation. */ |
1202 | | CK_RV |
1203 | | FC_EncryptFinal(CK_SESSION_HANDLE hSession, |
1204 | | CK_BYTE_PTR pLastEncryptedPart, CK_ULONG_PTR pusLastEncryptedPartLen) |
1205 | 0 | { |
1206 | 0 | SFTK_FIPSCHECK(); |
1207 | 0 | CHECK_FORK(); |
1208 | |
|
1209 | 0 | return NSC_EncryptFinal(hSession, pLastEncryptedPart, |
1210 | 0 | pusLastEncryptedPartLen); |
1211 | 0 | } |
1212 | | |
1213 | | /* |
1214 | | ************** Crypto Functions: Decrypt ************************ |
1215 | | */ |
1216 | | |
1217 | | /* FC_DecryptInit initializes a decryption operation. */ |
1218 | | CK_RV |
1219 | | FC_DecryptInit(CK_SESSION_HANDLE hSession, |
1220 | | CK_MECHANISM_PTR pMechanism, CK_OBJECT_HANDLE hKey) |
1221 | 0 | { |
1222 | 0 | SFTK_FIPSCHECK(); |
1223 | 0 | CHECK_FORK(); |
1224 | |
|
1225 | 0 | rv = NSC_DecryptInit(hSession, pMechanism, hKey); |
1226 | 0 | if (sftk_audit_enabled) { |
1227 | 0 | sftk_AuditCryptInit("Decrypt", hSession, pMechanism, hKey, rv); |
1228 | 0 | } |
1229 | 0 | return rv; |
1230 | 0 | } |
1231 | | |
1232 | | /* FC_Decrypt decrypts encrypted data in a single part. */ |
1233 | | CK_RV |
1234 | | FC_Decrypt(CK_SESSION_HANDLE hSession, |
1235 | | CK_BYTE_PTR pEncryptedData, CK_ULONG usEncryptedDataLen, CK_BYTE_PTR pData, |
1236 | | CK_ULONG_PTR pusDataLen) |
1237 | 0 | { |
1238 | 0 | SFTK_FIPSCHECK(); |
1239 | 0 | CHECK_FORK(); |
1240 | |
|
1241 | 0 | return NSC_Decrypt(hSession, pEncryptedData, usEncryptedDataLen, pData, |
1242 | 0 | pusDataLen); |
1243 | 0 | } |
1244 | | |
1245 | | /* FC_DecryptUpdate continues a multiple-part decryption operation. */ |
1246 | | CK_RV |
1247 | | FC_DecryptUpdate(CK_SESSION_HANDLE hSession, |
1248 | | CK_BYTE_PTR pEncryptedPart, CK_ULONG usEncryptedPartLen, |
1249 | | CK_BYTE_PTR pPart, CK_ULONG_PTR pusPartLen) |
1250 | 0 | { |
1251 | 0 | SFTK_FIPSCHECK(); |
1252 | 0 | CHECK_FORK(); |
1253 | |
|
1254 | 0 | return NSC_DecryptUpdate(hSession, pEncryptedPart, usEncryptedPartLen, |
1255 | 0 | pPart, pusPartLen); |
1256 | 0 | } |
1257 | | |
1258 | | /* FC_DecryptFinal finishes a multiple-part decryption operation. */ |
1259 | | CK_RV |
1260 | | FC_DecryptFinal(CK_SESSION_HANDLE hSession, |
1261 | | CK_BYTE_PTR pLastPart, CK_ULONG_PTR pusLastPartLen) |
1262 | 0 | { |
1263 | 0 | SFTK_FIPSCHECK(); |
1264 | 0 | CHECK_FORK(); |
1265 | |
|
1266 | 0 | return NSC_DecryptFinal(hSession, pLastPart, pusLastPartLen); |
1267 | 0 | } |
1268 | | |
1269 | | /* |
1270 | | ************** Crypto Functions: Digest (HASH) ************************ |
1271 | | */ |
1272 | | |
1273 | | /* FC_DigestInit initializes a message-digesting operation. */ |
1274 | | CK_RV |
1275 | | FC_DigestInit(CK_SESSION_HANDLE hSession, |
1276 | | CK_MECHANISM_PTR pMechanism) |
1277 | 0 | { |
1278 | 0 | SFTK_FIPSFATALCHECK(); |
1279 | 0 | CHECK_FORK(); |
1280 | |
|
1281 | 0 | return NSC_DigestInit(hSession, pMechanism); |
1282 | 0 | } |
1283 | | |
1284 | | /* FC_Digest digests data in a single part. */ |
1285 | | CK_RV |
1286 | | FC_Digest(CK_SESSION_HANDLE hSession, |
1287 | | CK_BYTE_PTR pData, CK_ULONG usDataLen, CK_BYTE_PTR pDigest, |
1288 | | CK_ULONG_PTR pusDigestLen) |
1289 | 0 | { |
1290 | 0 | SFTK_FIPSFATALCHECK(); |
1291 | 0 | CHECK_FORK(); |
1292 | |
|
1293 | 0 | return NSC_Digest(hSession, pData, usDataLen, pDigest, pusDigestLen); |
1294 | 0 | } |
1295 | | |
1296 | | /* FC_DigestUpdate continues a multiple-part message-digesting operation. */ |
1297 | | CK_RV |
1298 | | FC_DigestUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, |
1299 | | CK_ULONG usPartLen) |
1300 | 0 | { |
1301 | 0 | SFTK_FIPSFATALCHECK(); |
1302 | 0 | CHECK_FORK(); |
1303 | |
|
1304 | 0 | return NSC_DigestUpdate(hSession, pPart, usPartLen); |
1305 | 0 | } |
1306 | | |
1307 | | /* FC_DigestFinal finishes a multiple-part message-digesting operation. */ |
1308 | | CK_RV |
1309 | | FC_DigestFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pDigest, |
1310 | | CK_ULONG_PTR pusDigestLen) |
1311 | 0 | { |
1312 | 0 | SFTK_FIPSFATALCHECK(); |
1313 | 0 | CHECK_FORK(); |
1314 | |
|
1315 | 0 | return NSC_DigestFinal(hSession, pDigest, pusDigestLen); |
1316 | 0 | } |
1317 | | |
1318 | | /* |
1319 | | ************** Crypto Functions: Sign ************************ |
1320 | | */ |
1321 | | |
1322 | | /* FC_SignInit initializes a signature (private key encryption) operation, |
1323 | | * where the signature is (will be) an appendix to the data, |
1324 | | * and plaintext cannot be recovered from the signature */ |
1325 | | CK_RV |
1326 | | FC_SignInit(CK_SESSION_HANDLE hSession, |
1327 | | CK_MECHANISM_PTR pMechanism, CK_OBJECT_HANDLE hKey) |
1328 | 0 | { |
1329 | 0 | SFTK_FIPSCHECK(); |
1330 | 0 | CHECK_FORK(); |
1331 | |
|
1332 | 0 | rv = NSC_SignInit(hSession, pMechanism, hKey); |
1333 | 0 | if (sftk_audit_enabled) { |
1334 | 0 | sftk_AuditCryptInit("Sign", hSession, pMechanism, hKey, rv); |
1335 | 0 | } |
1336 | 0 | return rv; |
1337 | 0 | } |
1338 | | |
1339 | | /* FC_Sign signs (encrypts with private key) data in a single part, |
1340 | | * where the signature is (will be) an appendix to the data, |
1341 | | * and plaintext cannot be recovered from the signature */ |
1342 | | CK_RV |
1343 | | FC_Sign(CK_SESSION_HANDLE hSession, |
1344 | | CK_BYTE_PTR pData, CK_ULONG usDataLen, CK_BYTE_PTR pSignature, |
1345 | | CK_ULONG_PTR pusSignatureLen) |
1346 | 0 | { |
1347 | 0 | SFTK_FIPSCHECK(); |
1348 | 0 | CHECK_FORK(); |
1349 | |
|
1350 | 0 | return NSC_Sign(hSession, pData, usDataLen, pSignature, pusSignatureLen); |
1351 | 0 | } |
1352 | | |
1353 | | /* FC_SignUpdate continues a multiple-part signature operation, |
1354 | | * where the signature is (will be) an appendix to the data, |
1355 | | * and plaintext cannot be recovered from the signature */ |
1356 | | CK_RV |
1357 | | FC_SignUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, |
1358 | | CK_ULONG usPartLen) |
1359 | 0 | { |
1360 | 0 | SFTK_FIPSCHECK(); |
1361 | 0 | CHECK_FORK(); |
1362 | |
|
1363 | 0 | return NSC_SignUpdate(hSession, pPart, usPartLen); |
1364 | 0 | } |
1365 | | |
1366 | | /* FC_SignFinal finishes a multiple-part signature operation, |
1367 | | * returning the signature. */ |
1368 | | CK_RV |
1369 | | FC_SignFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSignature, |
1370 | | CK_ULONG_PTR pusSignatureLen) |
1371 | 0 | { |
1372 | 0 | SFTK_FIPSCHECK(); |
1373 | 0 | CHECK_FORK(); |
1374 | |
|
1375 | 0 | return NSC_SignFinal(hSession, pSignature, pusSignatureLen); |
1376 | 0 | } |
1377 | | |
1378 | | /* |
1379 | | ************** Crypto Functions: Sign Recover ************************ |
1380 | | */ |
1381 | | /* FC_SignRecoverInit initializes a signature operation, |
1382 | | * where the (digest) data can be recovered from the signature. |
1383 | | * E.g. encryption with the user's private key */ |
1384 | | CK_RV |
1385 | | FC_SignRecoverInit(CK_SESSION_HANDLE hSession, |
1386 | | CK_MECHANISM_PTR pMechanism, CK_OBJECT_HANDLE hKey) |
1387 | 0 | { |
1388 | 0 | SFTK_FIPSCHECK(); |
1389 | 0 | CHECK_FORK(); |
1390 | |
|
1391 | 0 | rv = NSC_SignRecoverInit(hSession, pMechanism, hKey); |
1392 | 0 | if (sftk_audit_enabled) { |
1393 | 0 | sftk_AuditCryptInit("SignRecover", hSession, pMechanism, hKey, rv); |
1394 | 0 | } |
1395 | 0 | return rv; |
1396 | 0 | } |
1397 | | |
1398 | | /* FC_SignRecover signs data in a single operation |
1399 | | * where the (digest) data can be recovered from the signature. |
1400 | | * E.g. encryption with the user's private key */ |
1401 | | CK_RV |
1402 | | FC_SignRecover(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, |
1403 | | CK_ULONG usDataLen, CK_BYTE_PTR pSignature, CK_ULONG_PTR pusSignatureLen) |
1404 | 0 | { |
1405 | 0 | SFTK_FIPSCHECK(); |
1406 | 0 | CHECK_FORK(); |
1407 | |
|
1408 | 0 | return NSC_SignRecover(hSession, pData, usDataLen, pSignature, pusSignatureLen); |
1409 | 0 | } |
1410 | | |
1411 | | /* |
1412 | | ************** Crypto Functions: verify ************************ |
1413 | | */ |
1414 | | |
1415 | | /* FC_VerifyInit initializes a verification operation, |
1416 | | * where the signature is an appendix to the data, |
1417 | | * and plaintext cannot be recovered from the signature (e.g. DSA) */ |
1418 | | CK_RV |
1419 | | FC_VerifyInit(CK_SESSION_HANDLE hSession, |
1420 | | CK_MECHANISM_PTR pMechanism, CK_OBJECT_HANDLE hKey) |
1421 | 0 | { |
1422 | 0 | SFTK_FIPSCHECK(); |
1423 | 0 | CHECK_FORK(); |
1424 | |
|
1425 | 0 | rv = NSC_VerifyInit(hSession, pMechanism, hKey); |
1426 | 0 | if (sftk_audit_enabled) { |
1427 | 0 | sftk_AuditCryptInit("Verify", hSession, pMechanism, hKey, rv); |
1428 | 0 | } |
1429 | 0 | return rv; |
1430 | 0 | } |
1431 | | |
1432 | | /* FC_Verify verifies a signature in a single-part operation, |
1433 | | * where the signature is an appendix to the data, |
1434 | | * and plaintext cannot be recovered from the signature */ |
1435 | | CK_RV |
1436 | | FC_Verify(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, |
1437 | | CK_ULONG usDataLen, CK_BYTE_PTR pSignature, CK_ULONG usSignatureLen) |
1438 | 0 | { |
1439 | | /* make sure we're legal */ |
1440 | 0 | SFTK_FIPSCHECK(); |
1441 | 0 | CHECK_FORK(); |
1442 | |
|
1443 | 0 | return NSC_Verify(hSession, pData, usDataLen, pSignature, usSignatureLen); |
1444 | 0 | } |
1445 | | |
1446 | | /* FC_VerifyUpdate continues a multiple-part verification operation, |
1447 | | * where the signature is an appendix to the data, |
1448 | | * and plaintext cannot be recovered from the signature */ |
1449 | | CK_RV |
1450 | | FC_VerifyUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, |
1451 | | CK_ULONG usPartLen) |
1452 | 0 | { |
1453 | 0 | SFTK_FIPSCHECK(); |
1454 | 0 | CHECK_FORK(); |
1455 | |
|
1456 | 0 | return NSC_VerifyUpdate(hSession, pPart, usPartLen); |
1457 | 0 | } |
1458 | | |
1459 | | /* FC_VerifyFinal finishes a multiple-part verification operation, |
1460 | | * checking the signature. */ |
1461 | | CK_RV |
1462 | | FC_VerifyFinal(CK_SESSION_HANDLE hSession, |
1463 | | CK_BYTE_PTR pSignature, CK_ULONG usSignatureLen) |
1464 | 0 | { |
1465 | 0 | SFTK_FIPSCHECK(); |
1466 | 0 | CHECK_FORK(); |
1467 | |
|
1468 | 0 | return NSC_VerifyFinal(hSession, pSignature, usSignatureLen); |
1469 | 0 | } |
1470 | | |
1471 | | /* |
1472 | | ************** Crypto Functions: Verify Recover ************************ |
1473 | | */ |
1474 | | |
1475 | | /* FC_VerifyRecoverInit initializes a signature verification operation, |
1476 | | * where the data is recovered from the signature. |
1477 | | * E.g. Decryption with the user's public key */ |
1478 | | CK_RV |
1479 | | FC_VerifyRecoverInit(CK_SESSION_HANDLE hSession, |
1480 | | CK_MECHANISM_PTR pMechanism, CK_OBJECT_HANDLE hKey) |
1481 | 0 | { |
1482 | 0 | SFTK_FIPSCHECK(); |
1483 | 0 | CHECK_FORK(); |
1484 | |
|
1485 | 0 | rv = NSC_VerifyRecoverInit(hSession, pMechanism, hKey); |
1486 | 0 | if (sftk_audit_enabled) { |
1487 | 0 | sftk_AuditCryptInit("VerifyRecover", hSession, pMechanism, hKey, rv); |
1488 | 0 | } |
1489 | 0 | return rv; |
1490 | 0 | } |
1491 | | |
1492 | | /* FC_VerifyRecover verifies a signature in a single-part operation, |
1493 | | * where the data is recovered from the signature. |
1494 | | * E.g. Decryption with the user's public key */ |
1495 | | CK_RV |
1496 | | FC_VerifyRecover(CK_SESSION_HANDLE hSession, |
1497 | | CK_BYTE_PTR pSignature, CK_ULONG usSignatureLen, |
1498 | | CK_BYTE_PTR pData, CK_ULONG_PTR pusDataLen) |
1499 | 0 | { |
1500 | 0 | SFTK_FIPSCHECK(); |
1501 | 0 | CHECK_FORK(); |
1502 | |
|
1503 | 0 | return NSC_VerifyRecover(hSession, pSignature, usSignatureLen, pData, |
1504 | 0 | pusDataLen); |
1505 | 0 | } |
1506 | | |
1507 | | /* |
1508 | | **************************** Key Functions: ************************ |
1509 | | */ |
1510 | | |
1511 | | /* FC_GenerateKey generates a secret key, creating a new key object. */ |
1512 | | CK_RV |
1513 | | FC_GenerateKey(CK_SESSION_HANDLE hSession, |
1514 | | CK_MECHANISM_PTR pMechanism, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount, |
1515 | | CK_OBJECT_HANDLE_PTR phKey) |
1516 | 0 | { |
1517 | 0 | CK_BBOOL *boolptr; |
1518 | |
|
1519 | 0 | SFTK_FIPSCHECK(); |
1520 | 0 | CHECK_FORK(); |
1521 | | |
1522 | | /* all secret keys must be sensitive, if the upper level code tries to say |
1523 | | * otherwise, reject it. */ |
1524 | 0 | boolptr = (CK_BBOOL *)fc_getAttribute(pTemplate, ulCount, CKA_SENSITIVE); |
1525 | 0 | if (boolptr != NULL) { |
1526 | 0 | if (!(*boolptr)) { |
1527 | 0 | return CKR_ATTRIBUTE_VALUE_INVALID; |
1528 | 0 | } |
1529 | 0 | } |
1530 | | |
1531 | 0 | rv = NSC_GenerateKey(hSession, pMechanism, pTemplate, ulCount, phKey); |
1532 | 0 | if (sftk_audit_enabled) { |
1533 | 0 | sftk_AuditGenerateKey(hSession, pMechanism, pTemplate, ulCount, phKey, rv); |
1534 | 0 | } |
1535 | 0 | return rv; |
1536 | 0 | } |
1537 | | |
1538 | | /* FC_GenerateKeyPair generates a public-key/private-key pair, |
1539 | | * creating new key objects. */ |
1540 | | CK_RV |
1541 | | FC_GenerateKeyPair(CK_SESSION_HANDLE hSession, |
1542 | | CK_MECHANISM_PTR pMechanism, CK_ATTRIBUTE_PTR pPublicKeyTemplate, |
1543 | | CK_ULONG usPublicKeyAttributeCount, CK_ATTRIBUTE_PTR pPrivateKeyTemplate, |
1544 | | CK_ULONG usPrivateKeyAttributeCount, CK_OBJECT_HANDLE_PTR phPublicKey, |
1545 | | CK_OBJECT_HANDLE_PTR phPrivateKey) |
1546 | 0 | { |
1547 | 0 | CK_BBOOL *boolptr; |
1548 | 0 | CK_RV crv; |
1549 | |
|
1550 | 0 | SFTK_FIPSCHECK(); |
1551 | 0 | CHECK_FORK(); |
1552 | | |
1553 | | /* all private keys must be sensitive, if the upper level code tries to say |
1554 | | * otherwise, reject it. */ |
1555 | 0 | boolptr = (CK_BBOOL *)fc_getAttribute(pPrivateKeyTemplate, |
1556 | 0 | usPrivateKeyAttributeCount, CKA_SENSITIVE); |
1557 | 0 | if (boolptr != NULL) { |
1558 | 0 | if (!(*boolptr)) { |
1559 | 0 | return CKR_ATTRIBUTE_VALUE_INVALID; |
1560 | 0 | } |
1561 | 0 | } |
1562 | 0 | crv = NSC_GenerateKeyPair(hSession, pMechanism, pPublicKeyTemplate, |
1563 | 0 | usPublicKeyAttributeCount, pPrivateKeyTemplate, |
1564 | 0 | usPrivateKeyAttributeCount, phPublicKey, phPrivateKey); |
1565 | 0 | if (crv == CKR_GENERAL_ERROR) { |
1566 | | /* pairwise consistency check failed. */ |
1567 | 0 | sftk_fatalError = PR_TRUE; |
1568 | 0 | } |
1569 | 0 | if (sftk_audit_enabled) { |
1570 | 0 | sftk_AuditGenerateKeyPair(hSession, pMechanism, pPublicKeyTemplate, |
1571 | 0 | usPublicKeyAttributeCount, pPrivateKeyTemplate, |
1572 | 0 | usPrivateKeyAttributeCount, phPublicKey, phPrivateKey, crv); |
1573 | 0 | } |
1574 | 0 | return crv; |
1575 | 0 | } |
1576 | | |
1577 | | /* FC_WrapKey wraps (i.e., encrypts) a key. */ |
1578 | | CK_RV |
1579 | | FC_WrapKey(CK_SESSION_HANDLE hSession, |
1580 | | CK_MECHANISM_PTR pMechanism, CK_OBJECT_HANDLE hWrappingKey, |
1581 | | CK_OBJECT_HANDLE hKey, CK_BYTE_PTR pWrappedKey, |
1582 | | CK_ULONG_PTR pulWrappedKeyLen) |
1583 | 0 | { |
1584 | 0 | SFTK_FIPSCHECK(); |
1585 | 0 | CHECK_FORK(); |
1586 | |
|
1587 | 0 | rv = NSC_WrapKey(hSession, pMechanism, hWrappingKey, hKey, pWrappedKey, |
1588 | 0 | pulWrappedKeyLen); |
1589 | 0 | if (sftk_audit_enabled) { |
1590 | 0 | sftk_AuditWrapKey(hSession, pMechanism, hWrappingKey, hKey, pWrappedKey, |
1591 | 0 | pulWrappedKeyLen, rv); |
1592 | 0 | } |
1593 | 0 | return rv; |
1594 | 0 | } |
1595 | | |
1596 | | /* FC_UnwrapKey unwraps (decrypts) a wrapped key, creating a new key object. */ |
1597 | | CK_RV |
1598 | | FC_UnwrapKey(CK_SESSION_HANDLE hSession, |
1599 | | CK_MECHANISM_PTR pMechanism, CK_OBJECT_HANDLE hUnwrappingKey, |
1600 | | CK_BYTE_PTR pWrappedKey, CK_ULONG ulWrappedKeyLen, |
1601 | | CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulAttributeCount, |
1602 | | CK_OBJECT_HANDLE_PTR phKey) |
1603 | 0 | { |
1604 | 0 | CK_BBOOL *boolptr; |
1605 | |
|
1606 | 0 | SFTK_FIPSCHECK(); |
1607 | 0 | CHECK_FORK(); |
1608 | | |
1609 | | /* all secret keys must be sensitive, if the upper level code tries to say |
1610 | | * otherwise, reject it. */ |
1611 | 0 | boolptr = (CK_BBOOL *)fc_getAttribute(pTemplate, |
1612 | 0 | ulAttributeCount, CKA_SENSITIVE); |
1613 | 0 | if (boolptr != NULL) { |
1614 | 0 | if (!(*boolptr)) { |
1615 | 0 | return CKR_ATTRIBUTE_VALUE_INVALID; |
1616 | 0 | } |
1617 | 0 | } |
1618 | 0 | rv = NSC_UnwrapKey(hSession, pMechanism, hUnwrappingKey, pWrappedKey, |
1619 | 0 | ulWrappedKeyLen, pTemplate, ulAttributeCount, phKey); |
1620 | 0 | if (sftk_audit_enabled) { |
1621 | 0 | sftk_AuditUnwrapKey(hSession, pMechanism, hUnwrappingKey, pWrappedKey, |
1622 | 0 | ulWrappedKeyLen, pTemplate, ulAttributeCount, phKey, rv); |
1623 | 0 | } |
1624 | 0 | return rv; |
1625 | 0 | } |
1626 | | |
1627 | | /* FC_DeriveKey derives a key from a base key, creating a new key object. */ |
1628 | | CK_RV |
1629 | | FC_DeriveKey(CK_SESSION_HANDLE hSession, |
1630 | | CK_MECHANISM_PTR pMechanism, CK_OBJECT_HANDLE hBaseKey, |
1631 | | CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulAttributeCount, |
1632 | | CK_OBJECT_HANDLE_PTR phKey) |
1633 | 0 | { |
1634 | 0 | CK_BBOOL *boolptr; |
1635 | |
|
1636 | 0 | SFTK_FIPSCHECK(); |
1637 | 0 | CHECK_FORK(); |
1638 | | |
1639 | | /* all secret keys must be sensitive, if the upper level code tries to say |
1640 | | * otherwise, reject it. */ |
1641 | 0 | boolptr = (CK_BBOOL *)fc_getAttribute(pTemplate, |
1642 | 0 | ulAttributeCount, CKA_SENSITIVE); |
1643 | 0 | if (boolptr != NULL) { |
1644 | 0 | if (!(*boolptr)) { |
1645 | 0 | return CKR_ATTRIBUTE_VALUE_INVALID; |
1646 | 0 | } |
1647 | 0 | } |
1648 | 0 | rv = NSC_DeriveKey(hSession, pMechanism, hBaseKey, pTemplate, |
1649 | 0 | ulAttributeCount, phKey); |
1650 | 0 | if (sftk_audit_enabled) { |
1651 | 0 | sftk_AuditDeriveKey(hSession, pMechanism, hBaseKey, pTemplate, |
1652 | 0 | ulAttributeCount, phKey, rv); |
1653 | 0 | } |
1654 | 0 | return rv; |
1655 | 0 | } |
1656 | | |
1657 | | /* |
1658 | | **************************** Radom Functions: ************************ |
1659 | | */ |
1660 | | |
1661 | | /* FC_SeedRandom mixes additional seed material into the token's random number |
1662 | | * generator. */ |
1663 | | CK_RV |
1664 | | FC_SeedRandom(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSeed, |
1665 | | CK_ULONG usSeedLen) |
1666 | 0 | { |
1667 | 0 | CK_RV crv; |
1668 | |
|
1669 | 0 | SFTK_FIPSFATALCHECK(); |
1670 | 0 | CHECK_FORK(); |
1671 | |
|
1672 | 0 | crv = NSC_SeedRandom(hSession, pSeed, usSeedLen); |
1673 | 0 | if (crv != CKR_OK) { |
1674 | 0 | sftk_fatalError = PR_TRUE; |
1675 | 0 | } |
1676 | 0 | return crv; |
1677 | 0 | } |
1678 | | |
1679 | | /* FC_GenerateRandom generates random data. */ |
1680 | | CK_RV |
1681 | | FC_GenerateRandom(CK_SESSION_HANDLE hSession, |
1682 | | CK_BYTE_PTR pRandomData, CK_ULONG ulRandomLen) |
1683 | 0 | { |
1684 | 0 | CK_RV crv; |
1685 | |
|
1686 | 0 | CHECK_FORK(); |
1687 | |
|
1688 | 0 | SFTK_FIPSFATALCHECK(); |
1689 | 0 | crv = NSC_GenerateRandom(hSession, pRandomData, ulRandomLen); |
1690 | 0 | if (crv != CKR_OK) { |
1691 | 0 | sftk_fatalError = PR_TRUE; |
1692 | 0 | if (sftk_audit_enabled) { |
1693 | 0 | char msg[128]; |
1694 | 0 | PR_snprintf(msg, sizeof msg, |
1695 | 0 | "C_GenerateRandom(hSession=0x%08lX, pRandomData=%p, " |
1696 | 0 | "ulRandomLen=%lu)=0x%08lX " |
1697 | 0 | "self-test: continuous RNG test failed", |
1698 | 0 | (PRUint32)hSession, pRandomData, |
1699 | 0 | (PRUint32)ulRandomLen, (PRUint32)crv); |
1700 | 0 | sftk_LogAuditMessage(NSS_AUDIT_ERROR, NSS_AUDIT_SELF_TEST, msg); |
1701 | 0 | } |
1702 | 0 | } |
1703 | 0 | return crv; |
1704 | 0 | } |
1705 | | |
1706 | | /* FC_GetFunctionStatus obtains an updated status of a function running |
1707 | | * in parallel with an application. */ |
1708 | | CK_RV |
1709 | | FC_GetFunctionStatus(CK_SESSION_HANDLE hSession) |
1710 | 0 | { |
1711 | 0 | SFTK_FIPSCHECK(); |
1712 | 0 | CHECK_FORK(); |
1713 | |
|
1714 | 0 | return NSC_GetFunctionStatus(hSession); |
1715 | 0 | } |
1716 | | |
1717 | | /* FC_CancelFunction cancels a function running in parallel */ |
1718 | | CK_RV |
1719 | | FC_CancelFunction(CK_SESSION_HANDLE hSession) |
1720 | 0 | { |
1721 | 0 | SFTK_FIPSCHECK(); |
1722 | 0 | CHECK_FORK(); |
1723 | |
|
1724 | 0 | return NSC_CancelFunction(hSession); |
1725 | 0 | } |
1726 | | |
1727 | | /* |
1728 | | **************************** Version 1.1 Functions: ************************ |
1729 | | */ |
1730 | | |
1731 | | /* FC_GetOperationState saves the state of the cryptographic |
1732 | | *operation in a session. */ |
1733 | | CK_RV |
1734 | | FC_GetOperationState(CK_SESSION_HANDLE hSession, |
1735 | | CK_BYTE_PTR pOperationState, CK_ULONG_PTR pulOperationStateLen) |
1736 | 0 | { |
1737 | 0 | SFTK_FIPSFATALCHECK(); |
1738 | 0 | CHECK_FORK(); |
1739 | |
|
1740 | 0 | return NSC_GetOperationState(hSession, pOperationState, pulOperationStateLen); |
1741 | 0 | } |
1742 | | |
1743 | | /* FC_SetOperationState restores the state of the cryptographic operation |
1744 | | * in a session. */ |
1745 | | CK_RV |
1746 | | FC_SetOperationState(CK_SESSION_HANDLE hSession, |
1747 | | CK_BYTE_PTR pOperationState, CK_ULONG ulOperationStateLen, |
1748 | | CK_OBJECT_HANDLE hEncryptionKey, CK_OBJECT_HANDLE hAuthenticationKey) |
1749 | 0 | { |
1750 | 0 | SFTK_FIPSFATALCHECK(); |
1751 | 0 | CHECK_FORK(); |
1752 | |
|
1753 | 0 | return NSC_SetOperationState(hSession, pOperationState, ulOperationStateLen, |
1754 | 0 | hEncryptionKey, hAuthenticationKey); |
1755 | 0 | } |
1756 | | |
1757 | | /* FC_FindObjectsFinal finishes a search for token and session objects. */ |
1758 | | CK_RV |
1759 | | FC_FindObjectsFinal(CK_SESSION_HANDLE hSession) |
1760 | 0 | { |
1761 | | /* let publically readable object be found */ |
1762 | 0 | SFTK_FIPSFATALCHECK(); |
1763 | 0 | CHECK_FORK(); |
1764 | |
|
1765 | 0 | return NSC_FindObjectsFinal(hSession); |
1766 | 0 | } |
1767 | | |
1768 | | /* Dual-function cryptographic operations */ |
1769 | | |
1770 | | /* FC_DigestEncryptUpdate continues a multiple-part digesting and encryption |
1771 | | * operation. */ |
1772 | | CK_RV |
1773 | | FC_DigestEncryptUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, |
1774 | | CK_ULONG ulPartLen, CK_BYTE_PTR pEncryptedPart, |
1775 | | CK_ULONG_PTR pulEncryptedPartLen) |
1776 | 0 | { |
1777 | 0 | SFTK_FIPSCHECK(); |
1778 | 0 | CHECK_FORK(); |
1779 | |
|
1780 | 0 | return NSC_DigestEncryptUpdate(hSession, pPart, ulPartLen, pEncryptedPart, |
1781 | 0 | pulEncryptedPartLen); |
1782 | 0 | } |
1783 | | |
1784 | | /* FC_DecryptDigestUpdate continues a multiple-part decryption and digesting |
1785 | | * operation. */ |
1786 | | CK_RV |
1787 | | FC_DecryptDigestUpdate(CK_SESSION_HANDLE hSession, |
1788 | | CK_BYTE_PTR pEncryptedPart, CK_ULONG ulEncryptedPartLen, |
1789 | | CK_BYTE_PTR pPart, CK_ULONG_PTR pulPartLen) |
1790 | 0 | { |
1791 | 0 | SFTK_FIPSCHECK(); |
1792 | 0 | CHECK_FORK(); |
1793 | |
|
1794 | 0 | return NSC_DecryptDigestUpdate(hSession, pEncryptedPart, ulEncryptedPartLen, |
1795 | 0 | pPart, pulPartLen); |
1796 | 0 | } |
1797 | | |
1798 | | /* FC_SignEncryptUpdate continues a multiple-part signing and encryption |
1799 | | * operation. */ |
1800 | | CK_RV |
1801 | | FC_SignEncryptUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, |
1802 | | CK_ULONG ulPartLen, CK_BYTE_PTR pEncryptedPart, |
1803 | | CK_ULONG_PTR pulEncryptedPartLen) |
1804 | 0 | { |
1805 | 0 | SFTK_FIPSCHECK(); |
1806 | 0 | CHECK_FORK(); |
1807 | |
|
1808 | 0 | return NSC_SignEncryptUpdate(hSession, pPart, ulPartLen, pEncryptedPart, |
1809 | 0 | pulEncryptedPartLen); |
1810 | 0 | } |
1811 | | |
1812 | | /* FC_DecryptVerifyUpdate continues a multiple-part decryption and verify |
1813 | | * operation. */ |
1814 | | CK_RV |
1815 | | FC_DecryptVerifyUpdate(CK_SESSION_HANDLE hSession, |
1816 | | CK_BYTE_PTR pEncryptedData, CK_ULONG ulEncryptedDataLen, |
1817 | | CK_BYTE_PTR pData, CK_ULONG_PTR pulDataLen) |
1818 | 0 | { |
1819 | 0 | SFTK_FIPSCHECK(); |
1820 | 0 | CHECK_FORK(); |
1821 | |
|
1822 | 0 | return NSC_DecryptVerifyUpdate(hSession, pEncryptedData, ulEncryptedDataLen, |
1823 | 0 | pData, pulDataLen); |
1824 | 0 | } |
1825 | | |
1826 | | /* FC_DigestKey continues a multi-part message-digesting operation, |
1827 | | * by digesting the value of a secret key as part of the data already digested. |
1828 | | */ |
1829 | | CK_RV |
1830 | | FC_DigestKey(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hKey) |
1831 | 0 | { |
1832 | 0 | SFTK_FIPSCHECK(); |
1833 | 0 | CHECK_FORK(); |
1834 | |
|
1835 | 0 | rv = NSC_DigestKey(hSession, hKey); |
1836 | 0 | if (sftk_audit_enabled) { |
1837 | 0 | sftk_AuditDigestKey(hSession, hKey, rv); |
1838 | 0 | } |
1839 | 0 | return rv; |
1840 | 0 | } |
1841 | | |
1842 | | CK_RV |
1843 | | FC_WaitForSlotEvent(CK_FLAGS flags, CK_SLOT_ID_PTR pSlot, |
1844 | | CK_VOID_PTR pReserved) |
1845 | 0 | { |
1846 | 0 | CHECK_FORK(); |
1847 | |
|
1848 | 0 | return NSC_WaitForSlotEvent(flags, pSlot, pReserved); |
1849 | 0 | } |
1850 | | |
1851 | | CK_RV |
1852 | | FC_MessageEncryptInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, |
1853 | | CK_OBJECT_HANDLE hKey) |
1854 | 0 | { |
1855 | 0 | SFTK_FIPSCHECK(); |
1856 | 0 | CHECK_FORK(); |
1857 | |
|
1858 | 0 | rv = NSC_MessageEncryptInit(hSession, pMechanism, hKey); |
1859 | 0 | if (sftk_audit_enabled) { |
1860 | 0 | sftk_AuditCryptInit("MessageEncrypt", hSession, pMechanism, hKey, rv); |
1861 | 0 | } |
1862 | 0 | return rv; |
1863 | 0 | } |
1864 | | |
1865 | | CK_RV |
1866 | | FC_EncryptMessage(CK_SESSION_HANDLE hSession, CK_VOID_PTR pParameter, |
1867 | | CK_ULONG ulParameterLen, CK_BYTE_PTR pAssociatedData, |
1868 | | CK_ULONG ulAssociatedDataLen, CK_BYTE_PTR pPlaintext, |
1869 | | CK_ULONG ulPlaintextLen, CK_BYTE_PTR pCiphertext, |
1870 | | CK_ULONG_PTR pulCiphertextLen) |
1871 | 0 | { |
1872 | 0 | SFTK_FIPSCHECK(); |
1873 | 0 | CHECK_FORK(); |
1874 | 0 | return NSC_EncryptMessage(hSession, pParameter, ulParameterLen, |
1875 | 0 | pAssociatedData, ulAssociatedDataLen, |
1876 | 0 | pPlaintext, ulPlaintextLen, pCiphertext, |
1877 | 0 | pulCiphertextLen); |
1878 | 0 | } |
1879 | | |
1880 | | CK_RV |
1881 | | FC_EncryptMessageBegin(CK_SESSION_HANDLE hSession, CK_VOID_PTR pParameter, |
1882 | | CK_ULONG ulParameterLen, CK_BYTE_PTR pAssociatedData, |
1883 | | CK_ULONG ulAssociatedDataLen) |
1884 | 0 | { |
1885 | 0 | SFTK_FIPSCHECK(); |
1886 | 0 | CHECK_FORK(); |
1887 | 0 | return NSC_EncryptMessageBegin(hSession, pParameter, ulParameterLen, |
1888 | 0 | pAssociatedData, ulAssociatedDataLen); |
1889 | 0 | } |
1890 | | |
1891 | | CK_RV |
1892 | | FC_EncryptMessageNext(CK_SESSION_HANDLE hSession, CK_VOID_PTR pParameter, |
1893 | | CK_ULONG ulParameterLen, CK_BYTE_PTR pPlaintextPart, |
1894 | | CK_ULONG ulPlaintextPartLen, CK_BYTE_PTR pCiphertextPart, |
1895 | | CK_ULONG_PTR pulCiphertextPartLen, CK_FLAGS flags) |
1896 | 0 | { |
1897 | 0 | SFTK_FIPSCHECK(); |
1898 | 0 | CHECK_FORK(); |
1899 | 0 | return NSC_EncryptMessageNext(hSession, pParameter, ulParameterLen, |
1900 | 0 | pPlaintextPart, ulPlaintextPartLen, |
1901 | 0 | pCiphertextPart, pulCiphertextPartLen, flags); |
1902 | 0 | } |
1903 | | |
1904 | | CK_RV |
1905 | | FC_MessageEncryptFinal(CK_SESSION_HANDLE hSession) |
1906 | 0 | { |
1907 | 0 | SFTK_FIPSCHECK(); |
1908 | 0 | CHECK_FORK(); |
1909 | 0 | return NSC_MessageEncryptFinal(hSession); |
1910 | 0 | } |
1911 | | |
1912 | | CK_RV |
1913 | | FC_MessageDecryptInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, |
1914 | | CK_OBJECT_HANDLE hKey) |
1915 | 0 | { |
1916 | 0 | SFTK_FIPSCHECK(); |
1917 | 0 | CHECK_FORK(); |
1918 | |
|
1919 | 0 | rv = NSC_MessageDecryptInit(hSession, pMechanism, hKey); |
1920 | 0 | if (sftk_audit_enabled) { |
1921 | 0 | sftk_AuditCryptInit("MessageDecrypt", hSession, pMechanism, hKey, rv); |
1922 | 0 | } |
1923 | 0 | return rv; |
1924 | 0 | } |
1925 | | |
1926 | | CK_RV |
1927 | | FC_DecryptMessage(CK_SESSION_HANDLE hSession, CK_VOID_PTR pParameter, |
1928 | | CK_ULONG ulParameterLen, CK_BYTE_PTR pAssociatedData, |
1929 | | CK_ULONG ulAssociatedDataLen, CK_BYTE_PTR pCiphertext, |
1930 | | CK_ULONG ulCiphertextLen, CK_BYTE_PTR pPlaintext, |
1931 | | CK_ULONG_PTR pulPlaintextLen) |
1932 | 0 | { |
1933 | 0 | SFTK_FIPSCHECK(); |
1934 | 0 | CHECK_FORK(); |
1935 | 0 | return NSC_DecryptMessage(hSession, pParameter, ulParameterLen, |
1936 | 0 | pAssociatedData, ulAssociatedDataLen, |
1937 | 0 | pCiphertext, ulCiphertextLen, pPlaintext, |
1938 | 0 | pulPlaintextLen); |
1939 | 0 | } |
1940 | | |
1941 | | CK_RV |
1942 | | FC_DecryptMessageBegin(CK_SESSION_HANDLE hSession, CK_VOID_PTR pParameter, |
1943 | | CK_ULONG ulParameterLen, CK_BYTE_PTR pAssociatedData, |
1944 | | CK_ULONG ulAssociatedDataLen) |
1945 | 0 | { |
1946 | 0 | SFTK_FIPSCHECK(); |
1947 | 0 | CHECK_FORK(); |
1948 | 0 | return NSC_DecryptMessageBegin(hSession, pParameter, ulParameterLen, |
1949 | 0 | pAssociatedData, ulAssociatedDataLen); |
1950 | 0 | } |
1951 | | |
1952 | | CK_RV |
1953 | | FC_DecryptMessageNext(CK_SESSION_HANDLE hSession, CK_VOID_PTR pParameter, |
1954 | | CK_ULONG ulParameterLen, CK_BYTE_PTR pCiphertextPart, |
1955 | | CK_ULONG ulCiphertextPartLen, CK_BYTE_PTR pPlaintextPart, |
1956 | | CK_ULONG_PTR pulPlaintextPartLen, CK_FLAGS flags) |
1957 | 0 | { |
1958 | 0 | SFTK_FIPSCHECK(); |
1959 | 0 | CHECK_FORK(); |
1960 | 0 | return NSC_DecryptMessageNext(hSession, pParameter, ulParameterLen, |
1961 | 0 | pCiphertextPart, ulCiphertextPartLen, |
1962 | 0 | pPlaintextPart, pulPlaintextPartLen, flags); |
1963 | 0 | } |
1964 | | |
1965 | | CK_RV |
1966 | | FC_MessageDecryptFinal(CK_SESSION_HANDLE hSession) |
1967 | 0 | { |
1968 | 0 | SFTK_FIPSCHECK(); |
1969 | 0 | CHECK_FORK(); |
1970 | 0 | return NSC_MessageDecryptFinal(hSession); |
1971 | 0 | } |
1972 | | |
1973 | | CK_RV |
1974 | | FC_MessageSignInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, |
1975 | | CK_OBJECT_HANDLE hKey) |
1976 | 0 | { |
1977 | 0 | SFTK_FIPSCHECK(); |
1978 | 0 | CHECK_FORK(); |
1979 | |
|
1980 | 0 | rv = NSC_MessageSignInit(hSession, pMechanism, hKey); |
1981 | 0 | if (sftk_audit_enabled) { |
1982 | 0 | sftk_AuditCryptInit("MessageSign", hSession, pMechanism, hKey, rv); |
1983 | 0 | } |
1984 | 0 | return rv; |
1985 | 0 | } |
1986 | | |
1987 | | CK_RV |
1988 | | FC_SignMessage(CK_SESSION_HANDLE hSession, CK_VOID_PTR pParameter, |
1989 | | CK_ULONG ulParameterLen, CK_BYTE_PTR pData, CK_ULONG ulDataLen, |
1990 | | CK_BYTE_PTR pSignature, CK_ULONG_PTR pulSignatureLen) |
1991 | 0 | { |
1992 | 0 | SFTK_FIPSCHECK(); |
1993 | 0 | CHECK_FORK(); |
1994 | 0 | return NSC_SignMessage(hSession, pParameter, ulParameterLen, pData, |
1995 | 0 | ulDataLen, pSignature, pulSignatureLen); |
1996 | 0 | } |
1997 | | |
1998 | | CK_RV |
1999 | | FC_SignMessageBegin(CK_SESSION_HANDLE hSession, CK_VOID_PTR pParameter, |
2000 | | CK_ULONG ulParameterLen) |
2001 | 0 | { |
2002 | 0 | SFTK_FIPSCHECK(); |
2003 | 0 | CHECK_FORK(); |
2004 | 0 | return NSC_SignMessageBegin(hSession, pParameter, ulParameterLen); |
2005 | 0 | } |
2006 | | |
2007 | | CK_RV |
2008 | | FC_SignMessageNext(CK_SESSION_HANDLE hSession, CK_VOID_PTR pParameter, |
2009 | | CK_ULONG ulParameterLen, CK_BYTE_PTR pData, |
2010 | | CK_ULONG ulDataLen, CK_BYTE_PTR pSignature, |
2011 | | CK_ULONG_PTR pulSignatureLen) |
2012 | 0 | { |
2013 | 0 | SFTK_FIPSCHECK(); |
2014 | 0 | CHECK_FORK(); |
2015 | 0 | return NSC_SignMessageNext(hSession, pParameter, ulParameterLen, pData, |
2016 | 0 | ulDataLen, pSignature, pulSignatureLen); |
2017 | 0 | } |
2018 | | |
2019 | | CK_RV |
2020 | | FC_MessageSignFinal(CK_SESSION_HANDLE hSession) |
2021 | 0 | { |
2022 | 0 | SFTK_FIPSCHECK(); |
2023 | 0 | CHECK_FORK(); |
2024 | 0 | return NSC_MessageSignFinal(hSession); |
2025 | 0 | } |
2026 | | |
2027 | | CK_RV |
2028 | | FC_MessageVerifyInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, |
2029 | | CK_OBJECT_HANDLE hKey) |
2030 | 0 | { |
2031 | 0 | SFTK_FIPSCHECK(); |
2032 | 0 | CHECK_FORK(); |
2033 | |
|
2034 | 0 | rv = NSC_MessageVerifyInit(hSession, pMechanism, hKey); |
2035 | 0 | if (sftk_audit_enabled) { |
2036 | 0 | sftk_AuditCryptInit("MessageVerify", hSession, pMechanism, hKey, rv); |
2037 | 0 | } |
2038 | 0 | return rv; |
2039 | 0 | } |
2040 | | |
2041 | | CK_RV |
2042 | | FC_VerifyMessage(CK_SESSION_HANDLE hSession, CK_VOID_PTR pParameter, |
2043 | | CK_ULONG ulParameterLen, CK_BYTE_PTR pData, |
2044 | | CK_ULONG ulDataLen, CK_BYTE_PTR pSignature, |
2045 | | CK_ULONG ulSignatureLen) |
2046 | 0 | { |
2047 | 0 | SFTK_FIPSCHECK(); |
2048 | 0 | CHECK_FORK(); |
2049 | 0 | return NSC_VerifyMessage(hSession, pParameter, ulParameterLen, pData, |
2050 | 0 | ulDataLen, pSignature, ulSignatureLen); |
2051 | 0 | } |
2052 | | |
2053 | | CK_RV |
2054 | | FC_VerifyMessageBegin(CK_SESSION_HANDLE hSession, CK_VOID_PTR pParameter, |
2055 | | CK_ULONG ulParameterLen) |
2056 | 0 | { |
2057 | 0 | SFTK_FIPSCHECK(); |
2058 | 0 | CHECK_FORK(); |
2059 | 0 | return NSC_VerifyMessageBegin(hSession, pParameter, ulParameterLen); |
2060 | 0 | } |
2061 | | |
2062 | | CK_RV |
2063 | | FC_VerifyMessageNext(CK_SESSION_HANDLE hSession, CK_VOID_PTR pParameter, |
2064 | | CK_ULONG ulParameterLen, CK_BYTE_PTR pData, |
2065 | | CK_ULONG ulDataLen, CK_BYTE_PTR pSignature, |
2066 | | CK_ULONG ulSignatureLen) |
2067 | 0 | { |
2068 | 0 | SFTK_FIPSCHECK(); |
2069 | 0 | CHECK_FORK(); |
2070 | 0 | return NSC_VerifyMessageNext(hSession, pParameter, ulParameterLen, |
2071 | 0 | pData, ulDataLen, pSignature, ulSignatureLen); |
2072 | 0 | } |
2073 | | |
2074 | | CK_RV |
2075 | | FC_MessageVerifyFinal(CK_SESSION_HANDLE hSession) |
2076 | 0 | { |
2077 | 0 | SFTK_FIPSCHECK(); |
2078 | 0 | CHECK_FORK(); |
2079 | 0 | return NSC_MessageVerifyFinal(hSession); |
2080 | 0 | } |