forked from arnaudmorin/libgtop11dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Log.cpp
2402 lines (2062 loc) · 46.5 KB
/
Log.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* PKCS#11 library for .Net smart cards
* Copyright (C) 2007-2009 Gemalto <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <string.h>
#include <stdio.h>
#include "Log.hpp"
#ifdef WIN32
#include <Windows.h>
clock_t Log::m_clockStart;
#else
timeval Log::m_clockStart;
#endif
bool Log::s_bEnableLog = false;
const unsigned char T_BOOL = 0;
#define T_BYTES 1
#define T_LONG 2
#define T_KEY_TYPE 3
#define T_CERTIFICATE_TYPE 4
#define T_CLASS 5
#define T_DATE 6
#define T_KEY_GEN_MECHANISM 7
#define T_UNKNOWN 8
//std::string Log::s_stLogFilePath = "/tmp";
//std::string Log::s_stLogFile = "/tmp/Gemalto.NET.PKCS11.log";
char Log::s_LogFilePath[ 512 ] = "";
void Log::setLogPath( const std::string& stPath ) {
std::string s = stPath + std::string( "/Gemalto.NET.PKCS11.log" );
#ifdef _WIN32
char szExePath[512] = {0};
char* ptr;
GetModuleFileName(NULL, szExePath, 512);
ptr = &szExePath[strlen(szExePath) - 1];
while ( (ptr != &szExePath[0]) && ((*ptr != '\\') && (*ptr != '/')))
{
ptr--;
}
if (ptr != &szExePath[0])
{
ptr++;
s = stPath + std::string( "/Gemalto.NET.PKCS11." ) + ptr;
// Add process ID
sprintf(szExePath, "-%d.log", GetCurrentProcessId());
s += szExePath;
}
#endif
memset( s_LogFilePath, 0, sizeof( s_LogFilePath ) );
if( s.length( ) < sizeof( s_LogFilePath ) ) {
memcpy( s_LogFilePath, s.c_str( ), s.length( ) );
} else {
char szDefaultPath[ ] = "/tmp/Gemalto.NET.PKCS11.log";
memcpy( s_LogFilePath, szDefaultPath, sizeof( szDefaultPath ) );
}
}
/* Log a message into the log file
*/
void Log::log( const char * format, ... )
{
if( !Log::s_bEnableLog ) {
return;
}
/*
if( Log::s_stLogFile.empty( ) ) {
return;
}*/
try {
va_list args;
// Try to open the file
FILE* pLog = fopen( s_LogFilePath, "a" ); /*s_stLogFile.c_str( )*/
if( pLog ) {
// Write the message to the log file
va_start( args, format );
vfprintf( pLog, format, args );
va_end( args );
fprintf(pLog, "\n");
// Close the file
fclose( pLog );
}
#ifndef WIN32
// Write the message to stderr stream
va_start( args, format );
vfprintf( stderr, format, args );
va_end( args );
fprintf( stderr, "\n");
#else
// Get the size of the buffer necessary to write the message
// The size must be extended to include the '\n' and the '\0' characters.
va_start( args, format );
size_t len = _vscprintf( format, args );
va_end( args );
// Allocate the buffer for the message
char *buffer = new char[ len + 2 ];
memset( buffer, '\0', len + 2 );
// Write the message into the buffer.
va_start( args, format );
vsprintf_s( buffer, len + 1, format, args );
va_end( args );
buffer[ len ] = '\n';
// Write the message to the console
OutputDebugString( buffer );
// Release the buffer
delete[] buffer;
#endif
va_end( args );
} catch( ... ) { }
}
/*
*/
void Log::begin( const char* a_pMethod )
{
#ifdef _WIN32
char szDateTimeUTC[260];
SYSTEMTIME stNow;
GetSystemTime(&stNow);
sprintf(szDateTimeUTC,"%04d-%02d-%02d %02d:%02d:%02d.%d(UTC)",
stNow.wYear,stNow.wMonth,stNow.wDay,stNow.wHour,stNow.wMinute,stNow.wSecond,stNow.wMilliseconds);
log( "%s - <BEGIN> [TID=0x%.8X] [%s]", a_pMethod, GetCurrentThreadId(), szDateTimeUTC);
#else
log( "%s - <BEGIN>", a_pMethod);
#endif
}
/*
*/
void Log::end( const char* a_pMethod )
{
#ifdef _WIN32
char szDateTimeUTC[260];
SYSTEMTIME stNow;
GetSystemTime(&stNow);
sprintf(szDateTimeUTC,"%04d-%02d-%02d %02d:%02d:%02d.%d(UTC)",
stNow.wYear,stNow.wMonth,stNow.wDay,stNow.wHour,stNow.wMinute,stNow.wSecond,stNow.wMilliseconds);
log( "%s - <END> [TID=0x%.8X] [%s]\n", a_pMethod, GetCurrentThreadId(), szDateTimeUTC);
#else
log( "%s - <END>\n", a_pMethod);
#endif
}
/*
*/
void Log::in( const char* a_pMethod )
{
log( "%s - [IN]", a_pMethod );
}
/*
*/
void Log::out( const char* a_pMethod )
{
log( "%s - [OUT]", a_pMethod );
}
/*
*/
void Log::error( const char* a_pMethod, const char* a_pError )
{
log( "%s - ## Error ## %s", a_pMethod, a_pError );
}
/*
*/
void Log::logCK_UTF8CHAR_PTR( const char* a_pName, const unsigned char* a_pBuffer, const std::size_t& a_Size )
{
if( !s_bEnableLog ) {
return;
}
if( a_pBuffer ) {
std::string s = "";
toString( a_pBuffer, a_Size, s );
log( "%s - <%#02x> - size <%ld> - buffer <%s>", a_pName, a_pBuffer, a_Size, s.c_str( ) );
} else {
log( "%s - NULL_PTR", a_pName );
}
}
/*
*/
void Log::logCK_MECHANISM_INFO_PTR( const char* a_pMethod, CK_MECHANISM_INFO_PTR pInfo )
{
if( !s_bEnableLog ) {
return;
}
if( pInfo ) {
std::string flags = "";
CK_FLAGS f = pInfo->flags;
mechanismFlagsToString( f, flags );
log( "%s - CK_MECHANISM_INFO - ulMinKeySize <%#02x> - ulMaxKeySize <%#02x> - flags <%s>", a_pMethod, pInfo->ulMinKeySize, pInfo->ulMaxKeySize, flags.c_str( ) );
}
else
{
log( "%s - CK_MECHANISM_INFO - NULL_PTR", a_pMethod );
}
}
/*
*/
void Log::logCK_INFO( const char* a_pMethod, const CK_INFO_PTR pInfo )
{
if( !s_bEnableLog ) {
return;
}
if( pInfo )
{
std::string s = "";
CK_INFOToString( pInfo, s );
log( "%s - CK_INFO <%s>", a_pMethod, s.c_str( ) );
}
else
{
log( "%s - CK_INFO <NULL_PTR>", a_pMethod );
}
}
/*
*/
void Log::logCK_RV( const char* a_pMethod, const CK_RV& rv )
{
if( !s_bEnableLog ) {
return;
}
if( CKR_OK == rv )
{
log( "%s - [RV] <0x00> (CKR_OK)", a_pMethod );
}
else
{
std::string s = "";
CK_RVToString( rv, s );
log( "%s - [RV] <%#02x> (%s)", a_pMethod, rv, s.c_str( ) );
}
}
/*
*/
void Log::logCK_C_INITIALIZE_ARGS_PTR( const char* a_pMethod, CK_C_INITIALIZE_ARGS_PTR a_pArgs )
{
if( !s_bEnableLog ) {
return;
}
if( a_pArgs )
{
//log( a_pMethod, "pInitArgs->CreateMutex <%#02x>", a_pArgs.CreateMutex );
log( "%s - CK_C_INITIALIZE_ARGS - DestroyMutex <%#02x> - LockMutex <%#02x> - UnlockMutex <%#02x> - flags <%#02x> - pReserved <%#02x>",
a_pMethod, a_pArgs->DestroyMutex, a_pArgs->LockMutex, a_pArgs->UnlockMutex, a_pArgs->flags, a_pArgs->pReserved );
}
else
{
log( "%s - CK_C_INITIALIZE_ARGS - CreateMutex <NULL_PTR> - DestroyMutex <NULL_PTR> - LockMutex <NULL_PTR> - UnlockMutex <NULL_PTR> - flags <NULL_PTR> - pReserved <NULL_PTR>", a_pMethod );
}
}
/*
*/
void Log::logCK_SLOT_ID_PTR( const char* a_pMethod, CK_SLOT_ID_PTR pSlotList, CK_ULONG_PTR pulCount )
{
if( !s_bEnableLog ) {
return;
}
if( NULL_PTR == pSlotList )
{
log( "%s - CK_SLOT_ID_PTR - pulCount <%#02x> (%ld) - pSlotList <NULL_PTR>", a_pMethod, pulCount, ( NULL_PTR != pulCount ) ? *pulCount : 0 );
}
else
{
std::string sList = "";
if( NULL_PTR != pulCount )
{
for( size_t i = 0 ; i < (size_t)*pulCount ; i++ )
{
std::string s = "";
toString( (unsigned long) pSlotList[ i ], s );
sList += s;
if( i != (size_t)( *pulCount - 1 ) )
{
sList += ", " ;
}
}
}
log( "%s - CK_SLOT_ID_PTR - pulCount <%#02x> (%ld) - pSlotList <%#02x> (%s)", a_pMethod, pulCount, ( NULL_PTR != pulCount ) ? *pulCount : 0, pSlotList, sList.c_str( ) );
}
}
/*
*/
void Log::logCK_SLOT_INFO_PTR( const char* a_pMethod, CK_SLOT_INFO_PTR pInfo )
{
if( !s_bEnableLog ) {
return;
}
if( pInfo )
{
std::string slotDescription = "";
toString( pInfo->slotDescription, 64, slotDescription );
std::string manufacturerID = "";
toString( pInfo->manufacturerID, 32, manufacturerID );
std::string flags = "";
CK_FLAGS f = pInfo->flags;
slotFlagsToString( f, flags );
std::string hardwareVersion = "";
CK_VERSIONToString( &(pInfo->hardwareVersion), hardwareVersion );
std::string firmwareVersion = "";
CK_VERSIONToString( &(pInfo->firmwareVersion), firmwareVersion );
log( "%s - CK_SLOT_INFO_PTR - slotDescription <%s> - manufacturerID <%s> - flags <%s> - hardwareVersion <%s> - firmwareVersion <%s>",
a_pMethod, slotDescription.c_str( ), manufacturerID.c_str( ), flags.c_str( ), hardwareVersion.c_str( ), firmwareVersion.c_str( ) );
}
else
{
log( "%s - CK_SLOT_INFO_PTR - NULL_PTR", a_pMethod );
}
}
/*
*/
void Log::logCK_TOKEN_INFO_PTR( const char* a_pMethod, CK_TOKEN_INFO_PTR pInfo )
{
if( !s_bEnableLog ) {
return;
}
if( pInfo )
{
std::string label = "";
toString( pInfo->label, 32, label );
std::string manufacturerID = "";
toString( pInfo->manufacturerID, 32, manufacturerID );
std::string model = "";
toString( pInfo->model, 16, model );
std::string serialNumber = "";
toString( pInfo->serialNumber, 16, serialNumber );
std::string hardwareVersion = "";
CK_VERSIONToString( &(pInfo->hardwareVersion), hardwareVersion );
std::string firmwareVersion = "";
CK_VERSIONToString( &(pInfo->firmwareVersion), firmwareVersion );
std::string utcTime = "";
toString( pInfo->utcTime, 16, utcTime );
log( "%s - CK_TOKEN_INFO_PTR - <%#02x> - label <%s> - manufacturerID <%s> - model <%s> - serialNumber <%s> - flags <%#02x> - ulMaxSessionCount <%#02x> - ulSessionCount <%#02x> - \
ulMaxRwSessionCount <%#02x> - ulRwSessionCount <%#02x> - ulMaxPinLen <%#02x> - ulMinPinLen <%#02x> - ulTotalPublicMemory <%#02x> - \
ulFreePublicMemory <%#02x> - ulTotalPrivateMemory <%#02x> - ulFreePrivateMemory <%#02x> - hardwareVersion <%s> - \
firmwareVersion <%s> - utcTime <%s>",
a_pMethod,
pInfo,
label.c_str( ),
manufacturerID.c_str( ),
model.c_str( ),
serialNumber.c_str( ),
pInfo->flags,
pInfo->ulMaxSessionCount,
pInfo->ulSessionCount,
pInfo->ulMaxRwSessionCount,
pInfo->ulRwSessionCount,
pInfo->ulMaxPinLen,
pInfo->ulMinPinLen,
pInfo->ulTotalPublicMemory,
pInfo->ulFreePublicMemory,
pInfo->ulTotalPrivateMemory,
pInfo->ulFreePrivateMemory,
hardwareVersion.c_str( ),
firmwareVersion.c_str( ),
utcTime.c_str( ) );
}
else
{
log( "%s - CK_TOKEN_INFO_PTR - <NULL_PTR>", a_pMethod );
}
}
/*
*/
void Log::logCK_MECHANISM_TYPE( const char* a_pMethod, CK_MECHANISM_TYPE_PTR pMechanismList, CK_ULONG_PTR pulCount )
{
if( !s_bEnableLog ) {
return;
}
std::string s = "";
if( pMechanismList && pulCount )
{
CK_MECHANISM_TYPEToString( pMechanismList, *pulCount, s );
}
log( "%s - CK_MECHANISM_TYPE_PTR - pulCount <%#02x> (%ld) - pMechanismList <%#02x> (%s)", a_pMethod, pulCount, ( ( NULL_PTR != pulCount ) ? *pulCount : 0 ), pMechanismList, s.c_str( ) );
}
/*
*/
void Log::logCK_MECHANISM_TYPE( const char* a_pMethod, CK_MECHANISM_TYPE & ulMechanism )
{
if( !s_bEnableLog ) {
return;
}
std::string s = "";
CK_MECHANISM_TYPEToString( ulMechanism, s );
log( "%s - CK_MECHANISM_TYPE <%s>", a_pMethod, s.c_str( ) );
}
/*
*/
void Log::logSessionFlags( const char* a_pMethod, CK_FLAGS & flags )
{
if( !s_bEnableLog ) {
return;
}
std::string s = "";
sessionFlagsToString( flags, s );
log( "%s - CK_FLAGS <%s>", a_pMethod, s.c_str( ) );
}
/*
*/
void Log::logCK_SESSION_INFO_PTR( const char* a_pMethod, CK_SESSION_INFO_PTR pInfo )
{
if( !s_bEnableLog ) {
return;
}
if( pInfo )
{
std::string s = "";
CK_SESSION_INFOToString( pInfo, s );
log( "%s - CK_SESSION_INFO <%#02x> (%s)", a_pMethod, pInfo, s.c_str( ) );
}
else
{
log( "%s - CK_SESSION_INFO <NULL_PTR>", a_pMethod );
}
}
/*
*/
void Log::logCK_USER_TYPE( const char* a_pMethod, CK_USER_TYPE &userType )
{
if( !s_bEnableLog ) {
return;
}
std::string s = "";
CK_USER_TYPEToString( userType, s );
log( "%s - CK_USER_TYPE <%s>", a_pMethod, s.c_str( ) );
}
/*
*/
void Log::logCK_MECHANISM_PTR( const char* a_pMethod, CK_MECHANISM_PTR pMechanism )
{
if( !s_bEnableLog ) {
return;
}
std::string s = "";
CK_MECHANISMToString( pMechanism, s );
log( "%s - CK_MECHANISM_PTR <%s>", a_pMethod, s.c_str( ) );
}
/*
*/
void Log::logCK_ATTRIBUTE_PTR( const char* a_pMethod, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG& ulCount )
{
if( !s_bEnableLog ) {
return;
}
log( "%s - pTemplate <%#02x> - ulCount <%ld>", a_pMethod, pTemplate, ulCount );
if( pTemplate )
{
for( size_t i = 0; i < (size_t)ulCount; i++ )
{
CK_ATTRIBUTE a = pTemplate[ i ];
std::string attribute = "";
CK_ATTRIBUTEToString( &a, attribute );
log( "%s - Attribute #%d - %s", a_pMethod, i, attribute.c_str( ) );
}
}
}
/*
*/
void Log::CK_MECHANISMToString( CK_MECHANISM_PTR m, std::string &result )
{
if( !s_bEnableLog ) {
return;
}
if( NULL_PTR == m )
{
return;
}
std::string mechanismType = "";
CK_MECHANISM_TYPE t = m->mechanism;
CK_MECHANISM_TYPEToString( t, mechanismType );
std::string mechanismParam = "";
toString( (const unsigned char*)m->pParameter, m->ulParameterLen, mechanismParam );
toString( result,
"Type <%s> - Parameter <%s> - ParameterLen <%#02x>",
mechanismType.c_str( ),
mechanismParam.c_str( ),
m->ulParameterLen );
}
/*
*/
void Log::CK_ATTRIBUTEToString( const CK_ATTRIBUTE_PTR a, std::string &result )
{
if( !s_bEnableLog ) {
return;
}
if( NULL_PTR == a )
{
return;
}
std::string t = "";
int type = T_UNKNOWN;
CK_ATTRIBUTE_TYPEToString( a->type, t, type );
if( ( (CK_ULONG)(-1) ) == a->ulValueLen )
{
toString( result, "Type <%s> - Length <-1> - Value <UNKNOWN>", t.c_str( ) );
return;
}
std::string v = "";
if( NULL_PTR == a->pValue )
{
v = "null";
}
else
{
switch( type )
{
case T_BOOL:
toString( ((CK_BBOOL*)a->pValue)[0], v );
break;
case T_BYTES:
toString( (CK_BYTE_PTR) a->pValue, a->ulValueLen, v );
break;
case T_LONG:
toString( ((CK_ULONG*)a->pValue)[0], v );
break;
case T_KEY_TYPE:
CK_KEY_TYPEToString( ((CK_KEY_TYPE *)a->pValue)[0], v );
break;
case T_CERTIFICATE_TYPE:
CK_CERTIFICATE_TYPEToString( ((CK_CERTIFICATE_TYPE *)a->pValue)[0], v );
break;
case T_CLASS:
CK_OBJECT_CLASSToString( ((CK_OBJECT_CLASS *)a->pValue)[0], v );
break;
case T_DATE:
CK_DATEToString( (CK_DATE*) a->pValue, v );
break;
case T_KEY_GEN_MECHANISM:
CK_MECHANISM_TYPEToString( ((CK_MECHANISM_TYPE *)a->pValue)[0], v );
break;
default:
v = "UNPREDICTABLE VALUE";
}
}
toString( result, "Type <%s> - Length <%#02x> - Value <%s>", t.c_str( ), a->ulValueLen, v.c_str( ) );
}
/*
*/
void Log::CK_ATTRIBUTE_TYPEToString( const CK_ATTRIBUTE_TYPE& a, std::string &t, int& type )
{
if( !s_bEnableLog ) {
return;
}
switch( a )
{
case CKA_CLASS:
t = "CKA_CLASS";
type = T_CLASS;
break;
case CKA_TOKEN:
t = "CKA_TOKEN";
type = T_BOOL;
break;
case CKA_PRIVATE:
t = "CKA_PRIVATE";
type = T_BOOL;
break;
case CKA_LABEL:
t = "CKA_LABEL";
type = T_BYTES;
break;
case CKA_APPLICATION:
t = "CKA_APPLICATION";
type = T_BYTES;
break;
case CKA_VALUE:
t = "CKA_VALUE";
type = T_BYTES;
break;
case CKA_CERTIFICATE_TYPE:
t = "CKA_CERTIFICATE_TYPE";
type = T_CERTIFICATE_TYPE;
break;
case CKA_ISSUER:
t = "CKA_ISSUER";
type = T_BYTES;
break;
case CKA_SERIAL_NUMBER:
t = "CKA_SERIAL_NUMBER";
type = T_BYTES;
break;
case CKA_KEY_TYPE:
t = "CKA_KEY_TYPE";
type = T_KEY_TYPE;
break;
case CKA_SUBJECT:
t = "CKA_SUBJECT";
type = T_BYTES;
break;
case CKA_ID:
t = "CKA_ID";
type = T_BYTES;
break;
case CKA_SENSITIVE:
t = "CKA_SENSITIVE";
type = T_BOOL;
break;
case CKA_ENCRYPT:
t = "CKA_ENCRYPT";
type = T_BOOL;
break;
case CKA_DECRYPT:
t = "CKA_DECRYPT";
type = T_BOOL;
break;
case CKA_WRAP:
t = "CKA_WRAP";
type = T_BOOL;
break;
case CKA_UNWRAP:
t = "CKA_UNWRAP";
type = T_BOOL;
break;
case CKA_SIGN:
t = "CKA_SIGN";
type = T_BOOL;
break;
case CKA_SIGN_RECOVER:
t = "CKA_SIGN_RECOVER";
type = T_BOOL;
break;
case CKA_VERIFY:
t = "CKA_VERIFY";
type = T_BOOL;
break;
case CKA_VERIFY_RECOVER:
t = "CKA_VERIFY_RECOVER";
type = T_BOOL;
break;
case CKA_DERIVE:
t = "CKA_DERIVE";
type = T_BOOL;
break;
case CKA_START_DATE:
t = "CKA_START_DATE";
type = T_DATE;
break;
case CKA_END_DATE:
t = "CKA_END_DATE";
type = T_DATE;
break;
case CKA_MODULUS:
t = "CKA_MODULUS";
type = T_BYTES;
break;
case CKA_MODULUS_BITS:
t = "CKA_MODULUS_BITS";
type = T_LONG;
break;
case CKA_PUBLIC_EXPONENT:
t = "CKA_PUBLIC_EXPONENT";
type = T_BYTES;
break;
case CKA_PRIVATE_EXPONENT:
t = "CKA_PRIVATE_EXPONENT";
type = T_BYTES;
break;
case CKA_PRIME_1:
t = "CKA_PRIME_1";
type = T_BYTES;
break;
case CKA_PRIME_2:
t = "CKA_PRIME_2";
type = T_BYTES;
break;
case CKA_EXPONENT_1:
t = "CKA_EXPONENT_1";
type = T_BYTES;
break;
case CKA_EXPONENT_2:
t = "CKA_EXPONENT_2";
type = T_BYTES;
break;
case CKA_COEFFICIENT:
t = "CKA_COEFFICIENT";
type = T_BYTES;
break;
case CKA_PRIME:
t = "CKA_PRIME";
type = T_BYTES;
break;
case CKA_SUBPRIME:
t = "CKA_SUBPRIME";
type = T_BYTES;
break;
case CKA_BASE:
t = "CKA_BASE";
type = T_BYTES;
break;
case CKA_VALUE_BITS:
t = "CKA_VALUE_BITS";
type = T_BYTES;
break;
case CKA_VALUE_LEN:
t = "CKA_VALUE_LEN";
type = T_LONG;
break;
case CKA_EXTRACTABLE:
t = "CKA_EXTRACTABLE";
type = T_BOOL;
break;
case CKA_LOCAL:
t = "CKA_LOCAL";
type = T_BOOL;
break;
case CKA_NEVER_EXTRACTABLE:
t = "CKA_NEVER_EXTRACTABLE";
type = T_BOOL;
break;
case CKA_ALWAYS_SENSITIVE:
t = "CKA_ALWAYS_SENSITIVE";
type = T_BOOL;
break;
case CKA_MODIFIABLE:
t = "CKA_MODIFIABLE";
type = T_BOOL;
break;
case CKA_ECDSA_PARAMS:
t = "CKA_ECDSA_PARAMS";
type = T_BYTES;
break;
case CKA_EC_POINT:
t = "CKA_EC_POINT";
type = T_BYTES;
break;
case CKA_VENDOR_DEFINED:
t = "CKA_VENDOR_DEFINED";
type = T_BYTES;
break;
//case CKA_KEY_GEN_MECHANISM:
// t = "CKA_KEY_GEN_MECHANISM";
// type = T_KEY_GEN_MECHANISM;
// break;
default:
toString( t, "UNKNOWN TYPE <%#02x>", a );
type = T_UNKNOWN;
}
}
/*
*/
void Log::CK_DATEToString( const CK_DATE* t, std::string &result )
{
if( !s_bEnableLog ) {
return;
}
if( NULL_PTR == t )
{
return;
}
std::string year = "";
toString( t->year, 4, year );
std::string month = "";
toString( t->month, 2, month );
std::string day = "";
toString( t->day, 2, day );
result = "Year <" + year + "> - Month <" + month + "> - Day <" + day + ">";
}
/*
*/
void Log::CK_OBJECT_CLASSToString( const CK_OBJECT_CLASS& t, std::string &result )
{
if( !s_bEnableLog ) {
return;
}
switch( t )
{
case CKO_DATA:
result = "CKO_DATA";
break;
case CKO_CERTIFICATE:
result = "CKO_CERTIFICATE";
break;
case CKO_PUBLIC_KEY:
result = "CKO_PUBLIC_KEY";
break;
case CKO_PRIVATE_KEY:
result = "CKO_PRIVATE_KEY";
break;
case CKO_SECRET_KEY:
result = "CKO_SECRET_KEY";
break;
case CKO_VENDOR_DEFINED:
result = "CKO_VENDOR_DEFINED";
break;
default: