~ubuntu-branches/ubuntu/hardy/opencryptoki/hardy

« back to all changes in this revision

Viewing changes to testcases/driver/sess_mgmt.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2008-01-24 14:22:58 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080124142258-i0nmjvqoy6wxe8x1
Tags: 2.2.5+dfsg-1ubuntu1
* Merge from debian unstable
* debian/libopencryptoki0.install, debian/libopencryptoki-dev.install: 
  - removed /usr/lib/opencryptoki/stdll/*, it's empty now
 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// File: sess_mgmt.c
2
 
//
3
 
 
4
 
#include <windows.h>
5
 
 
6
 
#include <stdio.h>
7
 
#include <stdlib.h>
8
 
#include <string.h>
9
 
#include <memory.h>
10
 
 
11
 
#include "pkcs11types.h"
12
 
#include "regress.h"
13
 
 
14
 
 
15
 
//
16
 
//
17
 
void dump_session_info( CK_SESSION_INFO *info )
18
 
{
19
 
   printf("   CK_SESSION_INFO:\n");
20
 
   printf("      slotID:         %ld\n", info->slotID );
21
 
   printf("      state:          ");
22
 
   switch (info->state) {
23
 
      case CKS_RO_PUBLIC_SESSION:   printf("CKS_RO_PUBLIC_SESSION\n");
24
 
                                    break;
25
 
      case CKS_RW_PUBLIC_SESSION:   printf("CKS_RW_PUBLIC_SESSION\n");
26
 
                                    break;
27
 
      case CKS_RO_USER_FUNCTIONS:   printf("CKS_RO_USER_FUNCTIONS\n");
28
 
                                    break;
29
 
      case CKS_RW_USER_FUNCTIONS:   printf("CKS_RW_USER_FUNCTIONS\n");
30
 
                                    break;
31
 
      case CKS_RW_SO_FUNCTIONS:     printf("CKS_RW_SO_FUNCTIONS\n");
32
 
                                    break;
33
 
   }
34
 
   printf("      flags:          %p\n",    (void *)info->flags );
35
 
   printf("      ulDeviceError:  %ld\n",    info->ulDeviceError );
36
 
}
37
 
 
38
 
 
39
 
 
40
 
//
41
 
//
42
 
int do_OpenSession( void )
43
 
{
44
 
   CK_SLOT_ID        slot_id;
45
 
   CK_FLAGS          flags;
46
 
   CK_SESSION_HANDLE handle;
47
 
   CK_RV             rc;
48
 
 
49
 
   printf("do_OpenSession...\n");
50
 
 
51
 
   slot_id = SLOT_ID;
52
 
   flags   = CKF_SERIAL_SESSION;   // read-only session
53
 
 
54
 
   rc = funcs->C_OpenSession( slot_id, flags, NULL, NULL, &handle );
55
 
   if (rc != CKR_OK) {
56
 
      show_error("   C_OpenSession #1", rc );
57
 
      return FALSE;
58
 
   }
59
 
 
60
 
   rc = funcs->C_CloseSession( handle );
61
 
   if (rc != CKR_OK) {
62
 
      show_error("   C_CloseSession #1", rc );
63
 
      return FALSE;
64
 
   }
65
 
 
66
 
   printf("Looks okay...\n");
67
 
 
68
 
   return TRUE;
69
 
}
70
 
 
71
 
 
72
 
//
73
 
//
74
 
int do_OpenSession2( void )
75
 
{
76
 
   CK_SLOT_ID        slot_id;
77
 
   CK_FLAGS          flags;
78
 
   CK_SESSION_HANDLE h1, h2;
79
 
   CK_RV             rc;
80
 
 
81
 
   printf("do_OpenSession2...\n");
82
 
 
83
 
   slot_id = SLOT_ID;
84
 
   flags   = CKF_SERIAL_SESSION;   // read-only session
85
 
 
86
 
   rc = funcs->C_OpenSession( slot_id, flags, NULL, NULL, &h1 );
87
 
   if (rc != CKR_OK) {
88
 
      show_error("   C_OpenSession #1", rc );
89
 
      return FALSE;
90
 
   }
91
 
 
92
 
   flags = CKF_SERIAL_SESSION | CKF_RW_SESSION;
93
 
   rc = funcs->C_OpenSession( slot_id, flags, NULL, NULL, &h2 );
94
 
   if (rc != CKR_OK) {
95
 
      show_error("   C_OpenSession #2", rc );
96
 
      return FALSE;
97
 
   }
98
 
 
99
 
   rc = funcs->C_CloseSession( h1 );
100
 
   if (rc != CKR_OK) {
101
 
      show_error("   C_CloseSession #1", rc );
102
 
      return FALSE;
103
 
   }
104
 
 
105
 
   rc = funcs->C_CloseSession( h2 );
106
 
   if (rc != CKR_OK) {
107
 
      show_error("   C_CloseSession #2", rc );
108
 
      return FALSE;
109
 
   }
110
 
 
111
 
   printf("Looks okay...\n");
112
 
 
113
 
   return TRUE;
114
 
}
115
 
 
116
 
 
117
 
//
118
 
//
119
 
int do_CloseAllSessions( void )
120
 
{
121
 
   CK_SLOT_ID        slot_id;
122
 
   CK_FLAGS          flags;
123
 
   CK_SESSION_HANDLE h1, h2, h3;
124
 
   CK_RV             rc;
125
 
 
126
 
   printf("do_CloseAllSessions...\n");
127
 
 
128
 
   slot_id = SLOT_ID;
129
 
   flags   = CKF_SERIAL_SESSION;   // read-only session
130
 
 
131
 
   rc = funcs->C_OpenSession( slot_id, flags, NULL, NULL, &h1 );
132
 
   if (rc != CKR_OK) {
133
 
      show_error("   C_OpenSession #1", rc );
134
 
      return FALSE;
135
 
   }
136
 
 
137
 
   flags = CKF_SERIAL_SESSION | CKF_RW_SESSION;
138
 
   rc = funcs->C_OpenSession( slot_id, flags, NULL, NULL, &h2 );
139
 
   if (rc != CKR_OK) {
140
 
      show_error("   C_OpenSession #2", rc );
141
 
      return FALSE;
142
 
   }
143
 
 
144
 
   flags = CKF_SERIAL_SESSION | CKF_RW_SESSION;
145
 
   rc = funcs->C_OpenSession( slot_id, flags, NULL, NULL, &h3 );
146
 
   if (rc != CKR_OK) {
147
 
      show_error("   C_OpenSession #3", rc );
148
 
      return FALSE;
149
 
   }
150
 
 
151
 
   rc = funcs->C_CloseAllSessions( slot_id );
152
 
   if (rc != CKR_OK) {
153
 
      show_error("   C_CloseAllSessions", rc );
154
 
      return FALSE;
155
 
   }
156
 
 
157
 
   printf("Looks okay...\n");
158
 
 
159
 
   return TRUE;
160
 
}
161
 
 
162
 
 
163
 
//
164
 
//
165
 
int do_GetSessionInfo( void )
166
 
{
167
 
   CK_SLOT_ID        slot_id;
168
 
   CK_FLAGS          flags;
169
 
   CK_SESSION_HANDLE h1, h2, h3;
170
 
   CK_SESSION_INFO   info;
171
 
   CK_RV             rc;
172
 
 
173
 
   printf("do_GetSessionInfo...\n");
174
 
 
175
 
   slot_id = SLOT_ID;
176
 
   flags   = CKF_SERIAL_SESSION;   // read-only session
177
 
 
178
 
   rc = funcs->C_OpenSession( slot_id, flags, NULL, NULL, &h1 );
179
 
   if (rc != CKR_OK) {
180
 
      show_error("   C_OpenSession #1", rc );
181
 
      return FALSE;
182
 
   }
183
 
 
184
 
   flags = CKF_SERIAL_SESSION | CKF_RW_SESSION;
185
 
   rc = funcs->C_OpenSession( slot_id, flags, NULL, NULL, &h2 );
186
 
   if (rc != CKR_OK) {
187
 
      show_error("   C_OpenSession #2", rc );
188
 
      return FALSE;
189
 
   }
190
 
 
191
 
   flags = CKF_SERIAL_SESSION | CKF_RW_SESSION;
192
 
   rc = funcs->C_OpenSession( slot_id, flags, NULL, NULL, &h3 );
193
 
   if (rc != CKR_OK) {
194
 
      show_error("   C_OpenSession #3", rc );
195
 
      return FALSE;
196
 
   }
197
 
 
198
 
   rc = funcs->C_GetSessionInfo( h1, &info );
199
 
   if (rc != CKR_OK) {
200
 
      show_error("   C_GetSessionInfo #1", rc );
201
 
      return FALSE;
202
 
   }
203
 
 
204
 
   dump_session_info( &info );
205
 
 
206
 
   rc = funcs->C_GetSessionInfo( h2, &info );
207
 
   if (rc != CKR_OK) {
208
 
      show_error("   C_GetSessionInfo #2", rc );
209
 
      return FALSE;
210
 
   }
211
 
 
212
 
   dump_session_info( &info );
213
 
 
214
 
   rc = funcs->C_GetSessionInfo( h2, &info );
215
 
   if (rc != CKR_OK) {
216
 
      show_error("   C_GetSessionInfo #3", rc );
217
 
      return FALSE;
218
 
   }
219
 
 
220
 
   dump_session_info( &info );
221
 
 
222
 
   rc = funcs->C_CloseAllSessions( slot_id );
223
 
   if (rc != CKR_OK) {
224
 
      show_error("   C_CloseAllSessions", rc );
225
 
      return FALSE;
226
 
   }
227
 
 
228
 
   printf("Looks okay...\n");
229
 
 
230
 
   return TRUE;
231
 
}
232
 
 
233
 
 
234
 
 
235
 
// This is a messy function but it does alot of tests:
236
 
//
237
 
//  1) Create 1 RO session and 2 RW sessions
238
 
//  2) Log the USER into session #1.  Verify that all 3 become USER sessions.
239
 
//  3) Try to login again, this time to session #2.  Verify that it fails
240
 
//  4) Logout session #1
241
 
//  5) Try to logout from session #2.  Verify that this fails.
242
 
//  6) Try to log the SO into session #1.  Verify that it fails (RO session exists)
243
 
//  7) Try to log the SO into session #2.  Verify that it fails (RO session exists)
244
 
//  8) Close all sessions
245
 
//  9) Creaate 2 RW sessions
246
 
//  A) Log the SO into one.  Verify that both are now SO sessions.
247
 
//  B) Create a 3rd RW session.  Verify that it immediately becomes an SO session
248
 
//  C) Try to create a RO session.  Verify that it fails (SO session exists)
249
 
//  D) Close all sessions and return
250
 
//
251
 
int do_LoginLogout( void )
252
 
{
253
 
   CK_SLOT_ID        slot_id;
254
 
   CK_FLAGS          flags;
255
 
   CK_SESSION_HANDLE h1, h2, h3, h4;
256
 
   CK_SESSION_INFO   info;
257
 
   CK_RV             rc;
258
 
   CK_BYTE           user_pin[PKCS11_MAX_PIN_LEN];
259
 
   CK_ULONG          user_pin_len;
260
 
   CK_BYTE           so_pin[PKCS11_MAX_PIN_LEN];
261
 
   CK_ULONG          so_pin_len;
262
 
 
263
 
   printf("do_LoginLogout...\n");
264
 
 
265
 
   if (get_user_pin(user_pin))
266
 
           return CKR_FUNCTION_FAILED;
267
 
   user_pin_len = (CK_ULONG)strlen((char *)user_pin);
268
 
 
269
 
   if (get_so_pin(so_pin))
270
 
           return CKR_FUNCTION_FAILED;
271
 
   so_pin_len = (CK_ULONG)strlen((char *)so_pin);
272
 
 
273
 
   slot_id = SLOT_ID;
274
 
   flags   = CKF_SERIAL_SESSION;   // read-only session
275
 
 
276
 
   //
277
 
   // create 3 sessions.  1 RO, two RW
278
 
   //
279
 
   rc = funcs->C_OpenSession( slot_id, flags, NULL, NULL, &h1 );
280
 
   if (rc != CKR_OK) {
281
 
      show_error("   C_OpenSession #1", rc );
282
 
      return FALSE;
283
 
   }
284
 
 
285
 
   flags = CKF_SERIAL_SESSION | CKF_RW_SESSION;
286
 
   rc = funcs->C_OpenSession( slot_id, flags, NULL, NULL, &h2 );
287
 
   if (rc != CKR_OK) {
288
 
      show_error("   C_OpenSession #2", rc );
289
 
      return FALSE;
290
 
   }
291
 
 
292
 
   flags = CKF_SERIAL_SESSION | CKF_RW_SESSION;
293
 
   rc = funcs->C_OpenSession( slot_id, flags, NULL, NULL, &h3 );
294
 
   if (rc != CKR_OK) {
295
 
      show_error("   C_OpenSession #3", rc );
296
 
      return FALSE;
297
 
   }
298
 
 
299
 
   //
300
 
   // log the first session in.  all sessions should become USER sessions
301
 
   //
302
 
   rc = funcs->C_Login( h1, CKU_USER, user_pin, user_pin_len );
303
 
   if (rc != CKR_OK) {
304
 
      show_error("   C_Login #1", rc );
305
 
      return FALSE;
306
 
   }
307
 
 
308
 
   rc = funcs->C_GetSessionInfo( h1, &info );
309
 
   if (rc != CKR_OK) {
310
 
      show_error("   C_GetSessionInfo #1", rc );
311
 
      return FALSE;
312
 
   }
313
 
 
314
 
   dump_session_info( &info );
315
 
 
316
 
   rc = funcs->C_GetSessionInfo( h2, &info );
317
 
   if (rc != CKR_OK) {
318
 
      show_error("   C_GetSessionInfo #2", rc );
319
 
      return FALSE;
320
 
   }
321
 
 
322
 
   dump_session_info( &info );
323
 
 
324
 
   rc = funcs->C_GetSessionInfo( h2, &info );
325
 
   if (rc != CKR_OK) {
326
 
      show_error("   C_GetSessionInfo #3", rc );
327
 
      return FALSE;
328
 
   }
329
 
 
330
 
   dump_session_info( &info );
331
 
 
332
 
 
333
 
   //
334
 
   // now, try to log in session #2.  this should fail (already logged in)
335
 
   //
336
 
   rc = funcs->C_Login( h2, CKU_USER, user_pin, user_pin_len );
337
 
   if (rc != CKR_USER_ALREADY_LOGGED_IN) {
338
 
      show_error("   C_Login #2", rc );
339
 
      printf("   Expected CKR_USER_ALREADY_LOGGED_IN\n");
340
 
      return FALSE;
341
 
   }
342
 
 
343
 
   //
344
 
   // now, try to logout twice
345
 
   //
346
 
   rc = funcs->C_Logout( h1 );
347
 
   if (rc != CKR_OK) {
348
 
      show_error("   C_Logout #1", rc );
349
 
      return FALSE;
350
 
   }
351
 
 
352
 
   rc = funcs->C_Logout( h2 );
353
 
   if (rc != CKR_USER_NOT_LOGGED_IN) {
354
 
      show_error("   C_Logout #2", rc );
355
 
      printf("   Expected CKR_USER_NOT_LOGGED_IN\n");
356
 
      return FALSE;
357
 
   }
358
 
 
359
 
   //
360
 
   // now, try to log the SO in.  this should fail since H1 is a RO session
361
 
   //
362
 
   rc = funcs->C_Login( h1, CKU_SO, so_pin, so_pin_len );
363
 
   if (rc != CKR_SESSION_READ_ONLY_EXISTS) {
364
 
      show_error("   C_Login #4", rc );
365
 
      printf("   Expected CKR_SESSION_READ_ONLY_EXISTS\n");
366
 
      return FALSE;
367
 
   }
368
 
 
369
 
   rc = funcs->C_Login( h2, CKU_SO, so_pin, so_pin_len );
370
 
   if (rc != CKR_SESSION_READ_ONLY_EXISTS) {
371
 
      show_error("   C_Login #5", rc );
372
 
      printf("   Expected CKR_SESSION_READ_ONLY_EXISTS\n");
373
 
      return FALSE;
374
 
   }
375
 
 
376
 
   //
377
 
   // log completely out
378
 
   //
379
 
 
380
 
   rc = funcs->C_CloseAllSessions( slot_id );
381
 
   if (rc != CKR_OK) {
382
 
      show_error("   C_CloseAllSessions #1", rc );
383
 
      return FALSE;
384
 
   }
385
 
 
386
 
   //
387
 
   // now, start two RW sessions
388
 
   //
389
 
   flags = CKF_SERIAL_SESSION | CKF_RW_SESSION;
390
 
   rc = funcs->C_OpenSession( slot_id, flags, NULL, NULL, &h1 );
391
 
   if (rc != CKR_OK) {
392
 
      show_error("   C_OpenSession #4", rc );
393
 
      return FALSE;
394
 
   }
395
 
 
396
 
   flags = CKF_SERIAL_SESSION | CKF_RW_SESSION;
397
 
   rc = funcs->C_OpenSession( slot_id, flags, NULL, NULL, &h2 );
398
 
   if (rc != CKR_OK) {
399
 
      show_error("   C_OpenSession #5", rc );
400
 
      return FALSE;
401
 
   }
402
 
 
403
 
   //
404
 
   // now, try to log the SO in.  this should work
405
 
   //
406
 
   rc = funcs->C_Login( h1, CKU_SO, so_pin, so_pin_len );
407
 
   if (rc != CKR_OK) {
408
 
      show_error("   C_Login #6", rc );
409
 
      return FALSE;
410
 
   }
411
 
 
412
 
   rc = funcs->C_GetSessionInfo( h1, &info );
413
 
   if (rc != CKR_OK) {
414
 
      show_error("   C_GetSessionInfo #4", rc );
415
 
      return FALSE;
416
 
   }
417
 
 
418
 
   dump_session_info( &info );
419
 
 
420
 
   rc = funcs->C_GetSessionInfo( h2, &info );
421
 
   if (rc != CKR_OK) {
422
 
      show_error("   C_GetSessionInfo #5", rc );
423
 
      return FALSE;
424
 
   }
425
 
 
426
 
   dump_session_info( &info );
427
 
 
428
 
   //
429
 
   // now, create a 3rd RW session.  verify that it is automatically an SO session
430
 
   //
431
 
   flags = CKF_SERIAL_SESSION | CKF_RW_SESSION;
432
 
   rc = funcs->C_OpenSession( slot_id, flags, NULL, NULL, &h3 );
433
 
   if (rc != CKR_OK) {
434
 
      show_error("   C_OpenSession #6", rc );
435
 
      return FALSE;
436
 
   }
437
 
 
438
 
   rc = funcs->C_GetSessionInfo( h3, &info );
439
 
   if (rc != CKR_OK) {
440
 
      show_error("   C_GetSessionInfo #6", rc );
441
 
      return FALSE;
442
 
   }
443
 
 
444
 
   dump_session_info( &info );
445
 
 
446
 
   //
447
 
   // now, try to create a 4th session.  RO this time.  Should fail
448
 
   //
449
 
   flags = CKF_SERIAL_SESSION;
450
 
   rc = funcs->C_OpenSession( slot_id, flags, NULL, NULL, &h4 );
451
 
   if (rc != CKR_SESSION_READ_WRITE_SO_EXISTS) {
452
 
      show_error("   C_OpenSession #6", rc );
453
 
      printf("   Expected CKR_SESSION_READ_WRITE_SO_EXISTS\n");
454
 
      return FALSE;
455
 
   }
456
 
 
457
 
 
458
 
   //
459
 
   // we're done...close all sessions
460
 
   //
461
 
   rc = funcs->C_CloseAllSessions( slot_id );
462
 
   if (rc != CKR_OK) {
463
 
      show_error("   C_CloseAllSessions #2:  %d", rc );
464
 
      return FALSE;
465
 
   }
466
 
 
467
 
 
468
 
   printf("Looks okay...\n");
469
 
 
470
 
   return TRUE;
471
 
}
472
 
 
473
 
 
474
 
//
475
 
//
476
 
int do_OperationState1( void )
477
 
{
478
 
   CK_SLOT_ID          slot_id;
479
 
   CK_SESSION_HANDLE   session1, session2;
480
 
   CK_FLAGS            flags;
481
 
   CK_BYTE             user_pin[PKCS11_MAX_PIN_LEN];
482
 
   CK_ULONG            user_pin_len;
483
 
   CK_RV               rc;
484
 
 
485
 
   CK_BYTE       original[1024];
486
 
   CK_BYTE       crypt1  [1024];
487
 
   CK_BYTE       crypt2  [1024];
488
 
   CK_BYTE       trash1  [8];
489
 
   CK_BYTE       trash2  [8];
490
 
 
491
 
   CK_BYTE      *op_state = NULL;
492
 
   CK_ULONG      op_state_len;
493
 
 
494
 
   CK_ULONG      orig_len, crypt1_len, crypt2_len, trash1_len, trash2_len;
495
 
   CK_ULONG      i;
496
 
 
497
 
   CK_MECHANISM     mech;
498
 
   CK_OBJECT_HANDLE h_key;
499
 
 
500
 
 
501
 
   printf("do_OperationState1...\n");
502
 
   slot_id = SLOT_ID;
503
 
 
504
 
   //
505
 
   // here's the goal:
506
 
   //
507
 
   //  All the hash values should be the same
508
 
   //    1) session #1 starts a multi-part encryption
509
 
   //    2) save session #1 operation state
510
 
   //    3) session #1 passes garbage to encrypt update
511
 
   //    4) session #2's operation state is set to what we saved
512
 
   //    5) sessoin #2 finishes the encryption operation
513
 
   //
514
 
   //  Session #2's results should be the same as the single-part version
515
 
   //
516
 
 
517
 
   // create two USER RW sessions
518
 
   //
519
 
   flags = CKF_SERIAL_SESSION | CKF_RW_SESSION;
520
 
   rc = funcs->C_OpenSession( slot_id, flags, NULL, NULL, &session1 );
521
 
   if (rc != CKR_OK) {
522
 
      show_error("   C_OpenSession #1", rc );
523
 
      return FALSE;
524
 
   }
525
 
 
526
 
   rc = funcs->C_OpenSession( slot_id, flags, NULL, NULL, &session2 );
527
 
   if (rc != CKR_OK) {
528
 
      show_error("   C_OpenSession #2", rc );
529
 
      return FALSE;
530
 
   }
531
 
 
532
 
   if (get_user_pin(user_pin))
533
 
           return CKR_FUNCTION_FAILED;
534
 
   user_pin_len = (CK_ULONG)strlen((char *)user_pin);
535
 
 
536
 
   rc = funcs->C_Login( session1, CKU_USER, user_pin, user_pin_len );
537
 
   if (rc != CKR_OK) {
538
 
      show_error("   C_Login #1", rc );
539
 
      return FALSE;
540
 
   }
541
 
 
542
 
   orig_len = sizeof(original);
543
 
   for (i=0; i < orig_len; i++)
544
 
      original[i] = i % 255;
545
 
 
546
 
   trash1_len = sizeof(trash1);
547
 
   memcpy( trash1, "asdflkjasdlkjadslkj", trash1_len );
548
 
 
549
 
 
550
 
   // first generate a DES key
551
 
   //
552
 
   mech.mechanism      = CKM_DES_KEY_GEN;
553
 
   mech.ulParameterLen = 0;
554
 
   mech.pParameter     = NULL;
555
 
 
556
 
   rc = funcs->C_GenerateKey( session1, &mech, NULL, 0, &h_key );
557
 
   if (rc != CKR_OK) {
558
 
      show_error("   C_GenerateKey #1", rc );
559
 
      return FALSE;
560
 
   }
561
 
 
562
 
   // now encrypt the original data all at once using CBC
563
 
   //
564
 
   mech.mechanism = CKM_DES_CBC;
565
 
   mech.ulParameterLen = 8;
566
 
   mech.pParameter     = "asdfqwer";
567
 
 
568
 
   rc = funcs->C_EncryptInit( session1, &mech, h_key );
569
 
   if (rc != CKR_OK) {
570
 
      show_error("   C_EncryptInit #1", rc );
571
 
      return FALSE;
572
 
   }
573
 
 
574
 
   crypt1_len = sizeof(crypt1);
575
 
   rc = funcs->C_Encrypt( session1, original, orig_len, crypt1, &crypt1_len );
576
 
   if (rc != CKR_OK) {
577
 
      show_error("   C_Encrypt #1", rc );
578
 
      return FALSE;
579
 
   }
580
 
 
581
 
 
582
 
   // now, begin encrypting multipart
583
 
   //
584
 
   rc = funcs->C_EncryptInit( session1, &mech, h_key );
585
 
   if (rc != CKR_OK) {
586
 
      show_error("   C_EncryptInit #2", rc );
587
 
      return FALSE;
588
 
   }
589
 
 
590
 
   crypt2_len = sizeof(crypt2);
591
 
   rc = funcs->C_EncryptUpdate( session1, original,  orig_len / 2,
592
 
                                         crypt2,   &crypt2_len );
593
 
   if (rc != CKR_OK) {
594
 
      show_error("   C_EncryptUpdate #1", rc );
595
 
      return FALSE;
596
 
   }
597
 
 
598
 
   // save session #1's operation state
599
 
   //
600
 
   rc = funcs->C_GetOperationState( session1, NULL, &op_state_len );
601
 
   if (rc != CKR_OK) {
602
 
      show_error("   C_GetOperationState #1", rc );
603
 
      return FALSE;
604
 
   }
605
 
 
606
 
   op_state = (CK_BYTE *)malloc(op_state_len);
607
 
   if (!op_state) {
608
 
      show_error("   HOST MEMORY ERROR", CKR_HOST_MEMORY );
609
 
      return FALSE;
610
 
   }
611
 
 
612
 
   rc = funcs->C_GetOperationState( session1, op_state, &op_state_len );
613
 
   if (rc != CKR_OK) {
614
 
      show_error("   C_GetOperationState #1", rc );
615
 
      return FALSE;
616
 
   }
617
 
 
618
 
   // now, encrypt some garbage.  this will affect the CBC even if
619
 
   // we throw the encrypted garbage away
620
 
   //
621
 
   trash2_len = sizeof(trash2);
622
 
   rc = funcs->C_EncryptUpdate( session1, trash1,  trash1_len,
623
 
                                          trash2, &trash2_len );
624
 
   if (rc != CKR_OK) {
625
 
      show_error("   C_EncryptUpdate #2", rc );
626
 
      return FALSE;
627
 
   }
628
 
 
629
 
   // restore session #1's operation state that we just saved back
630
 
   // into session #2 and continue with the encryption
631
 
   //
632
 
   rc = funcs->C_SetOperationState( session2, op_state, op_state_len,
633
 
                                    h_key, 0 );
634
 
   if (rc != CKR_OK) {
635
 
      show_error("   C_SetOperationState #1", rc );
636
 
      return FALSE;
637
 
   }
638
 
 
639
 
   free( op_state );
640
 
 
641
 
   // now, encrypt the rest of the original data
642
 
   //
643
 
   i = crypt2_len;
644
 
   crypt2_len = sizeof(crypt2) - crypt2_len;
645
 
   rc = funcs->C_EncryptUpdate( session2,
646
 
                                original + orig_len/2,  orig_len/2,
647
 
                                crypt2 + i,            &crypt2_len );
648
 
   if (rc != CKR_OK) {
649
 
      show_error("   C_EncryptUpdate #3", rc );
650
 
      return FALSE;
651
 
   }
652
 
 
653
 
   crypt2_len += i;
654
 
 
655
 
   trash2_len = sizeof(trash2);
656
 
   rc = funcs->C_EncryptFinal( session2, trash2, &trash2_len );
657
 
   if (rc != CKR_OK) {
658
 
      show_error("   C_EncryptFinal #1", rc );
659
 
      return FALSE;
660
 
   }
661
 
 
662
 
   if (crypt2_len != crypt1_len) {
663
 
      printf("   ERROR:  Lengths don't match\n");
664
 
      return FALSE;
665
 
   }
666
 
 
667
 
   if (memcmp(crypt1, crypt2, crypt1_len) != 0) {
668
 
      printf("   ERROR:  crypt1 != crypt2\n");
669
 
      return FALSE;
670
 
   }
671
 
 
672
 
   rc = funcs->C_CloseSession( session1 );
673
 
   if (rc != CKR_OK) {
674
 
      show_error("   C_CloseSession #1", rc );
675
 
      return FALSE;
676
 
   }
677
 
 
678
 
   rc = funcs->C_CloseSession( session2 );
679
 
   if (rc != CKR_OK) {
680
 
      show_error("   C_CloseSession #2", rc );
681
 
      return FALSE;
682
 
   }
683
 
 
684
 
   printf("Looks okay...\n");
685
 
   return TRUE;
686
 
}
687
 
 
688
 
 
689
 
//
690
 
//
691
 
int do_OperationState2( void )
692
 
{
693
 
   CK_SLOT_ID          slot_id;
694
 
   CK_SESSION_HANDLE   session1, session2, session3;
695
 
   CK_FLAGS            flags;
696
 
   CK_BYTE             user_pin[PKCS11_MAX_PIN_LEN];
697
 
   CK_ULONG            user_pin_len;
698
 
   CK_RV               rc;
699
 
 
700
 
   CK_BYTE     original[1024];
701
 
   CK_BYTE     digest1[16];
702
 
   CK_BYTE     digest2[16];
703
 
   CK_BYTE     digest3[16];
704
 
 
705
 
   CK_ULONG    orig_len;
706
 
   CK_ULONG    digest1_len, digest2_len, digest3_len;
707
 
 
708
 
   CK_BYTE    *op_state1 = NULL;
709
 
   CK_BYTE    *op_state2 = NULL;
710
 
   CK_ULONG    op_state1_len;
711
 
   CK_ULONG    op_state2_len;
712
 
 
713
 
   CK_ULONG    i;
714
 
 
715
 
   CK_MECHANISM   mech;
716
 
 
717
 
 
718
 
   printf("do_OperationState2...\n");
719
 
   slot_id = SLOT_ID;
720
 
 
721
 
   //
722
 
   // here's the goal:
723
 
   //  1) session #1 digests the first 499 bytes
724
 
   //  2) session #2 digests the first 27 bytes
725
 
   //  3) session #3 digests the whole thing
726
 
   //  3) we save both operation states
727
 
   //  4) we set the operation states to the 'other' session thereby
728
 
   //     switching sessions.  Session #2 picks up where session #1 was
729
 
   //     saved, session #1 picks up where session #2 was saved.
730
 
   //  5) session #1 digests the final (1024 - 27) bytes
731
 
   //  6) session #2 digests the final (1024 - 499) bytes
732
 
   //
733
 
   //  All the hash values should be the same
734
 
   //
735
 
 
736
 
   // create three USER RW sessions
737
 
   //
738
 
   flags = CKF_SERIAL_SESSION | CKF_RW_SESSION;
739
 
   rc = funcs->C_OpenSession( slot_id, flags, NULL, NULL, &session1 );
740
 
   if (rc != CKR_OK) {
741
 
      show_error("   C_OpenSession #1", rc );
742
 
      return FALSE;
743
 
   }
744
 
 
745
 
   rc = funcs->C_OpenSession( slot_id, flags, NULL, NULL, &session2 );
746
 
   if (rc != CKR_OK) {
747
 
      show_error("   C_OpenSession #2", rc );
748
 
      return FALSE;
749
 
   }
750
 
 
751
 
   rc = funcs->C_OpenSession( slot_id, flags, NULL, NULL, &session3 );
752
 
   if (rc != CKR_OK) {
753
 
      show_error("   C_OpenSession #3", rc );
754
 
      return FALSE;
755
 
   }
756
 
 
757
 
   if (get_user_pin(user_pin))
758
 
           return CKR_FUNCTION_FAILED;
759
 
   user_pin_len = (CK_ULONG)strlen((char *)user_pin);
760
 
 
761
 
   rc = funcs->C_Login( session1, CKU_USER, user_pin, user_pin_len );
762
 
   if (rc != CKR_OK) {
763
 
      show_error("   C_Login #1", rc );
764
 
      return FALSE;
765
 
   }
766
 
 
767
 
   orig_len = sizeof(original);
768
 
   for (i=0; i < orig_len; i++)
769
 
      original[i] = i % 255;
770
 
 
771
 
   mech.mechanism      = CKM_MD5;
772
 
   mech.pParameter     = NULL;
773
 
   mech.ulParameterLen = 0;
774
 
 
775
 
   rc = funcs->C_DigestInit( session1, &mech );
776
 
   if (rc != CKR_OK) {
777
 
      show_error("   C_DigestInit #1", rc );
778
 
      return FALSE;
779
 
   }
780
 
 
781
 
   rc = funcs->C_DigestInit( session2, &mech );
782
 
   if (rc != CKR_OK) {
783
 
      show_error("   C_DigestInit #2", rc );
784
 
      return FALSE;
785
 
   }
786
 
 
787
 
   rc = funcs->C_DigestInit( session3, &mech );
788
 
   if (rc != CKR_OK) {
789
 
      show_error("   C_DigestInit #3", rc );
790
 
      return FALSE;
791
 
   }
792
 
 
793
 
   rc = funcs->C_DigestUpdate( session1, original, 499 );
794
 
   if (rc != CKR_OK) {
795
 
      show_error("   C_DigestUpdate #1", rc );
796
 
      return FALSE;
797
 
   }
798
 
 
799
 
   rc = funcs->C_DigestUpdate( session2, original, 27 );
800
 
   if (rc != CKR_OK) {
801
 
      show_error("   C_DigestUpdate #2", rc );
802
 
      return FALSE;
803
 
   }
804
 
 
805
 
   orig_len = sizeof(original);
806
 
   digest3_len = sizeof(digest3);
807
 
   rc = funcs->C_Digest( session3, original,  orig_len,
808
 
                                   digest3,  &digest3_len );
809
 
   if (rc != CKR_OK) {
810
 
      show_error("   C_Digest #1", rc );
811
 
      return FALSE;
812
 
   }
813
 
 
814
 
   // save the operation states of sessions 1 and 2
815
 
   //
816
 
   rc = funcs->C_GetOperationState( session1, NULL, &op_state1_len );
817
 
   if (rc != CKR_OK) {
818
 
      show_error("   C_GetOperationState #1", rc );
819
 
      return FALSE;
820
 
   }
821
 
   op_state1 = (CK_BYTE *)malloc(op_state1_len);
822
 
   if (!op_state1) {
823
 
      show_error("   HOST MEMORY ERROR", CKR_HOST_MEMORY );
824
 
      return FALSE;
825
 
   }
826
 
   rc = funcs->C_GetOperationState( session1, op_state1, &op_state1_len );
827
 
   if (rc != CKR_OK) {
828
 
      show_error("   C_GetOperationState #2", rc );
829
 
      return FALSE;
830
 
   }
831
 
 
832
 
   rc = funcs->C_GetOperationState( session2, NULL, &op_state2_len );
833
 
   if (rc != CKR_OK) {
834
 
      show_error("   C_GetOperationState #3", rc );
835
 
      return FALSE;
836
 
   }
837
 
   op_state2 = (CK_BYTE *)malloc(op_state2_len);
838
 
   if (!op_state2) {
839
 
      show_error("   HOST MEMORY ERROR", CKR_HOST_MEMORY );
840
 
      return FALSE;
841
 
   }
842
 
   rc = funcs->C_GetOperationState( session2, op_state2, &op_state2_len );
843
 
   if (rc != CKR_OK) {
844
 
      show_error("   C_GetOperationState #4", rc );
845
 
      return FALSE;
846
 
   }
847
 
 
848
 
   // switch the states
849
 
   //
850
 
   rc = funcs->C_SetOperationState( session1, op_state2, op_state2_len,
851
 
                                    0, 0 );
852
 
   if (rc != CKR_OK) {
853
 
      show_error("   C_SetOperationState #2", rc );
854
 
      return FALSE;
855
 
   }
856
 
 
857
 
   rc = funcs->C_SetOperationState( session2, op_state1, op_state1_len,
858
 
                                    0, 0 );
859
 
   if (rc != CKR_OK) {
860
 
      show_error("   C_SetOperationState #3", rc );
861
 
      return FALSE;
862
 
   }
863
 
 
864
 
   // now, finish the digest operations
865
 
   //
866
 
   rc = funcs->C_DigestUpdate( session2, original+499, (orig_len - 499) );
867
 
   if (rc != CKR_OK) {
868
 
      show_error("   C_DigestUpdate #3", rc );
869
 
      return FALSE;
870
 
   }
871
 
 
872
 
   rc = funcs->C_DigestUpdate( session1, original+27, orig_len - 27 );
873
 
   if (rc != CKR_OK) {
874
 
      show_error("   C_DigestUpdate #4", rc );
875
 
      return FALSE;
876
 
   }
877
 
 
878
 
   digest1_len = sizeof(digest1);
879
 
   rc = funcs->C_DigestFinal( session1, digest1, &digest1_len );
880
 
   if (rc != CKR_OK) {
881
 
      show_error("   C_DigestFinal #1", rc );
882
 
      return FALSE;
883
 
   }
884
 
 
885
 
   digest2_len = sizeof(digest2);
886
 
   rc = funcs->C_DigestFinal( session2, digest2, &digest2_len );
887
 
   if (rc != CKR_OK) {
888
 
      show_error("   C_DigestFinal #2", rc );
889
 
      return FALSE;
890
 
   }
891
 
 
892
 
   if (digest1_len != digest2_len || digest1_len != digest3_len) {
893
 
      printf("   ERROR:  digested lengths don't match\n");
894
 
      return FALSE;
895
 
   }
896
 
 
897
 
   if (memcmp(digest1, digest2, digest1_len) != 0) {
898
 
      printf("   ERROR:  digest1 != digest2\n");
899
 
      return FALSE;
900
 
   }
901
 
 
902
 
   if (memcmp(digest1, digest3, digest1_len) != 0) {
903
 
      printf("   ERROR:  digest1 != digest3\n");
904
 
      return FALSE;
905
 
   }
906
 
 
907
 
   rc = funcs->C_CloseSession( session1 );
908
 
   if (rc != CKR_OK) {
909
 
      show_error("   C_CloseSession #3", rc );
910
 
      return FALSE;
911
 
   }
912
 
   rc = funcs->C_CloseSession( session2 );
913
 
   if (rc != CKR_OK) {
914
 
      show_error("   C_CloseSession #4", rc );
915
 
      return FALSE;
916
 
   }
917
 
   rc = funcs->C_CloseSession( session3 );
918
 
   if (rc != CKR_OK) {
919
 
      show_error("   C_CloseSession #5", rc );
920
 
      return FALSE;
921
 
   }
922
 
 
923
 
   printf("Looks okay...\n");
924
 
   return TRUE;
925
 
}
926
 
 
927
 
 
928
 
//
929
 
//
930
 
int do_OperationState3( void )
931
 
{
932
 
   CK_SLOT_ID          slot_id;
933
 
   CK_SESSION_HANDLE   session1, session2, session3;
934
 
   CK_FLAGS            flags;
935
 
   CK_BYTE             user_pin[PKCS11_MAX_PIN_LEN];
936
 
   CK_ULONG            user_pin_len;
937
 
   CK_RV               rc;
938
 
 
939
 
   CK_BYTE     original[1024];
940
 
   CK_BYTE     digest1[16];
941
 
   CK_BYTE     digest2[16];
942
 
   CK_BYTE     digest3[16];
943
 
   CK_BYTE     junk[1024];
944
 
 
945
 
   CK_ULONG    orig_len, junk_len;
946
 
   CK_ULONG    digest1_len, digest2_len, digest3_len;
947
 
 
948
 
   CK_BYTE    *op_state2 = NULL;
949
 
   CK_ULONG    op_state2_len;
950
 
 
951
 
   CK_ULONG    i;
952
 
 
953
 
   CK_MECHANISM      mech1, mech2;
954
 
   CK_OBJECT_HANDLE  key;
955
 
 
956
 
 
957
 
   printf("do_OperationState3...\n");
958
 
   slot_id = SLOT_ID;
959
 
 
960
 
   //
961
 
   // here's the goal:
962
 
   //  1) session #1 starts a multi-part encrypt
963
 
   //  2) session #2 starts a multi-part digest
964
 
   //  3) session #3 digests the whole thing
965
 
   //  4) assign session #2's operating state to session #1
966
 
   //  5) session #1 tries C_EncryptUpdate.  Should fail.
967
 
   //  6) session #1 finishes the multi-part digest
968
 
   //  7) session #2 finishes the multi-part digest
969
 
   //
970
 
   //  All the hash values should be the same
971
 
   //
972
 
 
973
 
   // create three USER RW sessions
974
 
   //
975
 
   flags = CKF_SERIAL_SESSION | CKF_RW_SESSION;
976
 
   rc = funcs->C_OpenSession( slot_id, flags, NULL, NULL, &session1 );
977
 
   if (rc != CKR_OK) {
978
 
      show_error("   C_OpenSession #1", rc );
979
 
      return FALSE;
980
 
   }
981
 
 
982
 
   rc = funcs->C_OpenSession( slot_id, flags, NULL, NULL, &session2 );
983
 
   if (rc != CKR_OK) {
984
 
      show_error("   C_OpenSession #2", rc );
985
 
      return FALSE;
986
 
   }
987
 
 
988
 
   rc = funcs->C_OpenSession( slot_id, flags, NULL, NULL, &session3 );
989
 
   if (rc != CKR_OK) {
990
 
      show_error("   C_OpenSession #3", rc );
991
 
      return FALSE;
992
 
   }
993
 
 
994
 
   if (get_user_pin(user_pin))
995
 
           return CKR_FUNCTION_FAILED;
996
 
   user_pin_len = (CK_ULONG)strlen((char *)user_pin);
997
 
 
998
 
   rc = funcs->C_Login( session1, CKU_USER, user_pin, user_pin_len );
999
 
   if (rc != CKR_OK) {
1000
 
      show_error("   C_Login #1", rc );
1001
 
      return FALSE;
1002
 
   }
1003
 
 
1004
 
   orig_len = sizeof(original);
1005
 
   for (i=0; i < orig_len; i++)
1006
 
      original[i] = i % 255;
1007
 
 
1008
 
 
1009
 
   mech1.mechanism      = CKM_DES_KEY_GEN;
1010
 
   mech1.pParameter     = NULL;
1011
 
   mech1.ulParameterLen = 0;
1012
 
 
1013
 
   rc = funcs->C_GenerateKey( session1, &mech1, NULL, 0, &key );
1014
 
   if (rc != CKR_OK) {
1015
 
      show_error("   C_GenerateKey #1", rc );
1016
 
      return FALSE;
1017
 
   }
1018
 
 
1019
 
 
1020
 
   mech1.mechanism      = CKM_DES_ECB;
1021
 
   mech1.pParameter     = NULL;
1022
 
   mech1.ulParameterLen = 0;
1023
 
 
1024
 
   rc = funcs->C_EncryptInit( session1, &mech1, key );
1025
 
   if (rc != CKR_OK) {
1026
 
      show_error("   C_EncryptInit #1", rc );
1027
 
      return FALSE;
1028
 
   }
1029
 
 
1030
 
   mech2.mechanism      = CKM_MD5;
1031
 
   mech2.pParameter     = NULL;
1032
 
   mech2.ulParameterLen = 0;
1033
 
 
1034
 
   rc = funcs->C_DigestInit( session2, &mech2 );
1035
 
   if (rc != CKR_OK) {
1036
 
      show_error("   C_DigestInit #1", rc );
1037
 
      return FALSE;
1038
 
   }
1039
 
 
1040
 
   rc = funcs->C_DigestInit( session3, &mech2 );
1041
 
   if (rc != CKR_OK) {
1042
 
      show_error("   C_DigestInit #2", rc );
1043
 
      return FALSE;
1044
 
   }
1045
 
 
1046
 
   rc = funcs->C_DigestUpdate( session2, original, 499 );
1047
 
   if (rc != CKR_OK) {
1048
 
      show_error("   C_DigestUpdate #1", rc );
1049
 
      return FALSE;
1050
 
   }
1051
 
 
1052
 
   orig_len = sizeof(original);
1053
 
   digest3_len = sizeof(digest3);
1054
 
   rc = funcs->C_Digest( session3, original,  orig_len,
1055
 
                                   digest3,  &digest3_len );
1056
 
   if (rc != CKR_OK) {
1057
 
      show_error("   C_Digest #1", rc );
1058
 
      return FALSE;
1059
 
   }
1060
 
 
1061
 
 
1062
 
   rc = funcs->C_GetOperationState( session2, NULL, &op_state2_len );
1063
 
   if (rc != CKR_OK) {
1064
 
      show_error("   C_GetOperationState #1", rc );
1065
 
      return FALSE;
1066
 
   }
1067
 
   op_state2 = (CK_BYTE *)malloc(op_state2_len);
1068
 
   if (!op_state2) {
1069
 
      show_error("   HOST MEMORY ERROR #1", CKR_HOST_MEMORY );
1070
 
      return FALSE;
1071
 
   }
1072
 
   rc = funcs->C_GetOperationState( session2, op_state2, &op_state2_len );
1073
 
   if (rc != CKR_OK) {
1074
 
      show_error("   C_GetOperationState #2", rc );
1075
 
      return FALSE;
1076
 
   }
1077
 
 
1078
 
   rc = funcs->C_SetOperationState( session1, op_state2, op_state2_len, 0, 0 );
1079
 
   if (rc != CKR_OK) {
1080
 
      show_error("   C_SetOperationState #1", rc );
1081
 
      return FALSE;
1082
 
   }
1083
 
 
1084
 
   // session #1 should not be set to do digest not encryption
1085
 
   //
1086
 
   junk_len = sizeof(junk);
1087
 
   rc = funcs->C_EncryptUpdate( session1, original, 499, junk, &junk_len );
1088
 
   if (rc != CKR_OPERATION_NOT_INITIALIZED) {
1089
 
      show_error("   C_EncryptUpdate #1", rc );
1090
 
      printf("   Expected CKR_OPERATION_NOT_INITIALIZED\n" );
1091
 
      return FALSE;
1092
 
   }
1093
 
 
1094
 
 
1095
 
   // now, finish the digest operations
1096
 
   //
1097
 
   rc = funcs->C_DigestUpdate( session1, original+499, (orig_len - 499) );
1098
 
   if (rc != CKR_OK) {
1099
 
      show_error("   C_DigestUpdate #2", rc );
1100
 
      return FALSE;
1101
 
   }
1102
 
 
1103
 
   rc = funcs->C_DigestUpdate( session2, original+499, (orig_len - 499) );
1104
 
   if (rc != CKR_OK) {
1105
 
      show_error("   C_DigestUpdate #3", rc );
1106
 
      return FALSE;
1107
 
   }
1108
 
 
1109
 
 
1110
 
   digest1_len = sizeof(digest1);
1111
 
   rc = funcs->C_DigestFinal( session1, digest1, &digest1_len );
1112
 
   if (rc != CKR_OK) {
1113
 
      show_error("   C_DigestFinal #1", rc );
1114
 
      return FALSE;
1115
 
   }
1116
 
 
1117
 
   digest2_len = sizeof(digest2);
1118
 
   rc = funcs->C_DigestFinal( session2, digest2, &digest2_len );
1119
 
   if (rc != CKR_OK) {
1120
 
      show_error("   C_DigestFinal #2", rc );
1121
 
      return FALSE;
1122
 
   }
1123
 
 
1124
 
   if (digest1_len != digest2_len || digest1_len != digest3_len) {
1125
 
      printf("   ERROR:  digested lengths don't match\n");
1126
 
      return FALSE;
1127
 
   }
1128
 
 
1129
 
   if (memcmp(digest1, digest2, digest1_len) != 0) {
1130
 
      printf("   ERROR:  digest1 != digest2\n");
1131
 
      return FALSE;
1132
 
   }
1133
 
 
1134
 
   if (memcmp(digest1, digest3, digest1_len) != 0) {
1135
 
      printf("   ERROR:  digest1 != digest3\n");
1136
 
      return FALSE;
1137
 
   }
1138
 
 
1139
 
   rc = funcs->C_CloseSession( session1 );
1140
 
   if (rc != CKR_OK) {
1141
 
      show_error("   C_CloseSession #3", rc );
1142
 
      return FALSE;
1143
 
   }
1144
 
   rc = funcs->C_CloseSession( session2 );
1145
 
   if (rc != CKR_OK) {
1146
 
      show_error("   C_CloseSession #4", rc );
1147
 
      return FALSE;
1148
 
   }
1149
 
   rc = funcs->C_CloseSession( session3 );
1150
 
   if (rc != CKR_OK) {
1151
 
      show_error("   C_CloseSession #5", rc );
1152
 
      return FALSE;
1153
 
   }
1154
 
 
1155
 
   printf("Looks okay...\n");
1156
 
   return TRUE;
1157
 
}
1158
 
 
1159
 
 
1160
 
int sess_mgmt_functions()
1161
 
{
1162
 
   SYSTEMTIME  t1, t2;
1163
 
   int         rc;
1164
 
 
1165
 
 
1166
 
   GetSystemTime(&t1);
1167
 
   rc = do_OpenSession();
1168
 
   if (!rc)
1169
 
      return FALSE;
1170
 
   GetSystemTime(&t2);
1171
 
   process_time( t1, t2 );
1172
 
 
1173
 
 
1174
 
   GetSystemTime(&t1);
1175
 
   rc = do_OpenSession2();
1176
 
   if (!rc)
1177
 
      return FALSE;
1178
 
   GetSystemTime(&t2);
1179
 
   process_time( t1, t2 );
1180
 
 
1181
 
 
1182
 
   GetSystemTime(&t1);
1183
 
   rc = do_CloseAllSessions();
1184
 
   if (!rc)
1185
 
      return FALSE;
1186
 
   GetSystemTime(&t2);
1187
 
   process_time( t1, t2 );
1188
 
 
1189
 
   GetSystemTime(&t1);
1190
 
   rc = do_GetSessionInfo();
1191
 
   if (!rc)
1192
 
      return FALSE;
1193
 
   GetSystemTime(&t2);
1194
 
   process_time( t1, t2 );
1195
 
 
1196
 
 
1197
 
   GetSystemTime(&t1);
1198
 
   rc = do_LoginLogout();
1199
 
   if (!rc)
1200
 
      return FALSE;
1201
 
   GetSystemTime(&t2);
1202
 
   process_time( t1, t2 );
1203
 
 
1204
 
 
1205
 
   GetSystemTime(&t1);
1206
 
   rc = do_OperationState1();
1207
 
   if (!rc)
1208
 
      return FALSE;
1209
 
   GetSystemTime(&t2);
1210
 
   process_time( t1, t2 );
1211
 
 
1212
 
 
1213
 
   GetSystemTime(&t1);
1214
 
   rc = do_OperationState2();
1215
 
   if (!rc)
1216
 
      return FALSE;
1217
 
   GetSystemTime(&t2);
1218
 
   process_time( t1, t2 );
1219
 
 
1220
 
 
1221
 
   GetSystemTime(&t1);
1222
 
   rc = do_OperationState3();
1223
 
   if (!rc)
1224
 
      return FALSE;
1225
 
   GetSystemTime(&t2);
1226
 
   process_time( t1, t2 );
1227
 
 
1228
 
   return TRUE;
1229
 
}