forked from arnaudmorin/libgtop11dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcardmod.h
1874 lines (1600 loc) · 65.1 KB
/
cardmod.h
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
//==============================================================;
//
// CARDMOD.H
//
// Abstract:
// This is the header file commonly used for card modules.
//
// This source code is only intended as a supplement to existing Microsoft
// documentation.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
// PURPOSE.
//
// Copyright (C) Microsoft Corporation. All Rights Reserved.
//
//==============================================================;
#ifndef __CARDMOD__H__
#define __CARDMOD__H__
#ifdef WIN32
#include <windows.h>
#include <wincrypt.h>
#pragma warning(push)
#pragma warning(disable:4201)
// Disable error C4201 in public header
// nonstandard extension used : nameless struct/union
#include <winscard.h>
#pragma warning(pop)
#include <specstrings.h>
#include <bcrypt.h>
#else
#ifdef __APPLE__
#include <PCSC/winscard.h>
#include <PCSC/wintypes.h>
#else
#include <winscard.h>
#include <stdint.h>
typedef const wchar_t* LPCWSTR;
#endif
typedef ULONG * ULONG_PTR;
typedef BYTE * PBYTE;
typedef int ALG_ID;
typedef void * PVOID;
typedef size_t SIZE_T;
typedef uint16_t WCHAR;
typedef uint16_t* LPWSTR, *PWSTR;
#define __deref_opt_out_bcount(x)
#define __deref_out_bcount_opt(x)
#define __deref_out_bcount(x)
#define __deref_out_ecount(x)
#define __in
#define IN
#define __in_bcount(x)
#define __in_ecount(x)
#define __in_opt
#define __inout
#define __out
#define OUT
#define __out_bcount_part_opt(x, y)
#define __out_bcount(x)
#define __out_opt
#define WINAPI
#endif
// This value should be passed to
//
// SCardSetCardTypeProviderName
// SCardGetCardTypeProviderName
//
// in order to query and set the Card Specific Module to be used
// for a given card.
#define SCARD_PROVIDER_CARD_MODULE 0x80000001
typedef struct _CARD_DATA CARD_DATA, *PCARD_DATA;
typedef ULONG_PTR CARD_KEY_HANDLE, *PCARD_KEY_HANDLE;
//
// This define can be used as a return value for queries involving
// card data that may be impossible to determine on a given card
// OS, such as the number of available card storage bytes.
//
#define CARD_DATA_VALUE_UNKNOWN ((DWORD) -1)
//
// Well Known Logical Names
//
//
// Logical Directory Names
//
// Second-level logical directories
#define szBASE_CSP_DIR "mscp"
#define szINTERMEDIATE_CERTS_DIR "mscerts"
//
// Logical File Names
//
// When requesting (or otherwise referring to) any logical file, the full path
// must be used, including when referring to well known files. For example,
// to request the wszCONTAINER_MAP_FILE, the provided name will be
// "/mscp/cmapfile".
//
// Well known logical files under Microsoft
#define szCACHE_FILE "cardcf"
#define szCARD_IDENTIFIER_FILE "cardid"
// Well known logical files under CSP
#define szCONTAINER_MAP_FILE "cmapfile"
#define szROOT_STORE_FILE "msroots"
//
// Well known logical files under User Certs
//
// The following prefixes are appended with the container index of the
// associated key. For example, the certificate associated with the
// Key Exchange key in container index 2 will have the name:
// "/mscp/kxc2"
//
#define szUSER_SIGNATURE_CERT_PREFIX "ksc"
#define szUSER_KEYEXCHANGE_CERT_PREFIX "kxc"
#define szUSER_SIGNATURE_PRIVATE_KEY_PREFIX "kss"
#define szUSER_SIGNATURE_PUBLIC_KEY_PREFIX "ksp"
#define szUSER_KEYEXCHANGE_PRIVATE_KEY_PREFIX "kxs"
#define szUSER_KEYEXCHANGE_PUBLIC_KEY_PREFIX "kxp"
//
// Logical Card User Names
//
#define wszCARD_USER_EVERYONE L"anonymous"
#define wszCARD_USER_USER L"user"
#define wszCARD_USER_ADMIN L"admin"
// new ecc key specs
#define AT_ECDSA_P256 3
#define AT_ECDSA_P384 4
#define AT_ECDSA_P521 5
#define AT_ECDHE_P256 6
#define AT_ECDHE_P384 7
#define AT_ECDHE_P521 8
//
// Type: CARD_CACHE_FILE_FORMAT
//
// This struct is used as the file format of the cache file,
// as stored on the card.
//
#define CARD_CACHE_FILE_CURRENT_VERSION 1
typedef struct _CARD_CACHE_FILE_FORMAT
{
BYTE bVersion;
BYTE bPinsFreshness;
WORD wContainersFreshness;
WORD wFilesFreshness;
} CARD_CACHE_FILE_FORMAT, *PCARD_CACHE_FILE_FORMAT;
//
// Type: CONTAINER_MAP_RECORD
//
// This structure describes the format of the Base CSP's container map file,
// stored on the card. This is well-known logical file wszCONTAINER_MAP_FILE.
// The file consists of zero or more of these records.
//
#define MAX_CONTAINER_NAME_LEN 39
// This flag is set in the CONTAINER_MAP_RECORD bFlags member if the
// corresponding container is valid and currently exists on the card.
// If the container is deleted, its bFlags field must be cleared.
#define CONTAINER_MAP_VALID_CONTAINER 1
// This flag is set in the CONTAINER_MAP_RECORD bFlags
// member if the corresponding container is the default container on the card.
#define CONTAINER_MAP_DEFAULT_CONTAINER 2
typedef struct _CONTAINER_MAP_RECORD
{
WCHAR wszGuid [MAX_CONTAINER_NAME_LEN + 1];
BYTE bFlags;
BYTE bReserved;
WORD wSigKeySizeBits;
WORD wKeyExchangeKeySizeBits;
} CONTAINER_MAP_RECORD, *PCONTAINER_MAP_RECORD;
//
// Converts a card filename string from unicode to ansi
//
DWORD
WINAPI
I_CardConvertFileNameToAnsi(
__in PCARD_DATA pCardData,
__in LPWSTR wszUnicodeName,
__out LPSTR *ppszAnsiName);
// Logical Directory Access Conditions
typedef enum
{
InvalidDirAc = 0,
// User Read, Write
UserCreateDeleteDirAc,
// Admin Write
AdminCreateDeleteDirAc
} CARD_DIRECTORY_ACCESS_CONDITION;
// Logical File Access Conditions
typedef enum
{
// Invalid value, chosed to cooincide with common initialization
// of memory
InvalidAc = 0,
// Everyone Read
// User Read, Write
//
// Example: A user certificate file.
EveryoneReadUserWriteAc,
// Everyone None
// User Write, Execute
//
// Example: A private key file.
UserWriteExecuteAc,
// Everyone Read
// Admin Read, Write
//
// Example: The Card Identifier file.
EveryoneReadAdminWriteAc,
// Explicit value to set when it is desired to say that
// it is unknown
UnknownAc,
// Everyone No Access
// User Read Write
//
// Example: A password wallet file.
UserReadWriteAc,
// Everyone/User No Access
// Admin Read Write
//
// Example: Administration data.
AdminReadWriteAc
} CARD_FILE_ACCESS_CONDITION;
//
// Function: CardAcquireContext
//
// Purpose: Initialize the CARD_DATA structure which will be used by
// the CSP to interact with a specific card.
//
typedef DWORD (WINAPI *PFN_CARD_ACQUIRE_CONTEXT)(
__inout PCARD_DATA pCardData,
__in DWORD dwFlags);
DWORD
WINAPI
CardAcquireContext(
__inout PCARD_DATA pCardData,
__in DWORD dwFlags);
//
// Function: CardDeleteContext
//
// Purpose: Free resources consumed by the CARD_DATA structure.
//
typedef DWORD (WINAPI *PFN_CARD_DELETE_CONTEXT)(
__inout PCARD_DATA pCardData);
DWORD
WINAPI
CardDeleteContext(
__inout PCARD_DATA pCardData);
//
// Function: CardQueryCapabilities
//
// Purpose: Query the card module for specific functionality
// provided by this card.
//
#define CARD_CAPABILITIES_CURRENT_VERSION 1
typedef struct _CARD_CAPABILITIES
{
DWORD dwVersion;
BOOL fCertificateCompression;
BOOL fKeyGen;
} CARD_CAPABILITIES, *PCARD_CAPABILITIES;
typedef DWORD (WINAPI *PFN_CARD_QUERY_CAPABILITIES)(
__in PCARD_DATA pCardData,
__inout PCARD_CAPABILITIES pCardCapabilities);
DWORD
WINAPI
CardQueryCapabilities(
__in PCARD_DATA pCardData,
__inout PCARD_CAPABILITIES pCardCapabilities);
// ****************
// PIN SUPPORT
// ****************
//
// There are 8 PINs currently defined in version 6. PIN values 0, 1 and 2 are
// reserved for backwards compatibility, whereas PIN values 3-7 can be used
// as additional PINs to protect key containers.
//
typedef DWORD PIN_ID, *PPIN_ID;
typedef DWORD PIN_SET, *PPIN_SET;
#define MAX_PINS 8
#define ROLE_EVERYONE 0
#define ROLE_USER 1
#define ROLE_ADMIN 2
#define PIN_SET_NONE 0x00
#define PIN_SET_ALL_ROLES 0xFF
#define CREATE_PIN_SET(PinId) (1 << PinId)
#define SET_PIN(PinSet, PinId) PinSet |= CREATE_PIN_SET(PinId)
#define IS_PIN_SET(PinSet, PinId) (0 != (PinSet & CREATE_PIN_SET(PinId)))
#define CLEAR_PIN(PinSet, PinId) PinSet &= ~CREATE_PIN_SET(PinId)
#define PIN_CHANGE_FLAG_UNBLOCK 0x01
#define PIN_CHANGE_FLAG_CHANGEPIN 0x02
#define CP_CACHE_MODE_GLOBAL_CACHE 1
#define CP_CACHE_MODE_SESSION_ONLY 2
#define CP_CACHE_MODE_NO_CACHE 3
#define CARD_AUTHENTICATE_GENERATE_SESSION_PIN 0x10000000
#define CARD_AUTHENTICATE_SESSION_PIN 0x20000000
#define CARD_PIN_STRENGTH_PLAINTEXT 0x1
#define CARD_PIN_STRENGTH_SESSION_PIN 0x2
#define CARD_PIN_SILENT_CONTEXT 0x00000040
typedef enum
{
AlphaNumericPinType = 0, // Regular PIN
ExternalPinType, // Biometric PIN
ChallengeResponsePinType, // Challenge/Response PIN
EmptyPinType // No PIN
} SECRET_TYPE;
typedef enum
{
AuthenticationPin, // Authentication PIN
DigitalSignaturePin, // Digital Signature PIN
EncryptionPin, // Encryption PIN
NonRepudiationPin, // Non Repudiation PIN
AdministratorPin, // Administrator PIN
PrimaryCardPin, // Primary Card PIN
UnblockOnlyPin // Unblock only PIN (PUK)
} SECRET_PURPOSE;
typedef enum
{
PinCacheNormal = 0,
PinCacheTimed,
PinCacheNone,
PinCacheAlwaysPrompt
} PIN_CACHE_POLICY_TYPE;
#define PIN_CACHE_POLICY_CURRENT_VERSION 6
typedef struct _PIN_CACHE_POLICY
{
DWORD dwVersion;
PIN_CACHE_POLICY_TYPE PinCachePolicyType;
DWORD dwPinCachePolicyInfo;
} PIN_CACHE_POLICY, *PPIN_CACHE_POLICY;
#define PIN_INFO_CURRENT_VERSION 6
#define PIN_INFO_REQUIRE_SECURE_ENTRY 1
typedef struct _PIN_INFO
{
DWORD dwVersion;
SECRET_TYPE PinType;
SECRET_PURPOSE PinPurpose;
PIN_SET dwChangePermission;
PIN_SET dwUnblockPermission;
PIN_CACHE_POLICY PinCachePolicy;
DWORD dwFlags;
} PIN_INFO, *PPIN_INFO;
// Gemalto custom !
typedef struct _PIN_INFO_EX
{
IN OUT DWORD dwVersion;
OUT SECRET_TYPE PinType;
OUT SECRET_PURPOSE PinPurpose;
OUT PIN_SET dwChangePermission;
OUT PIN_SET dwUnblockPermission;
OUT PIN_CACHE_POLICY PinCachePolicy;
OUT DWORD dwFlags;
OUT DWORD dwFlagsEx;
} PIN_INFO_EX, *PPIN_INFO_EX;
typedef DWORD (WINAPI *PFN_CARD_GET_CHALLENGE_EX)(
__in PCARD_DATA pCardData,
__in PIN_ID PinId,
__out_bcount(*pcbChallengeData) PBYTE *ppbChallengeData,
__out PDWORD pcbChallengeData,
__in DWORD dwFlags);
DWORD
WINAPI
CardGetChallengeEx(
__in PCARD_DATA pCardData,
__in PIN_ID PinId,
__deref_out_bcount(*pcbChallengeData) PBYTE *ppbChallengeData,
__out PDWORD pcbChallengeData,
__in DWORD dwFlags);
typedef DWORD (WINAPI *PFN_CARD_AUTHENTICATE_EX)(
__in PCARD_DATA pCardData,
__in PIN_ID PinId,
__in DWORD dwFlags,
__in_bcount(cbPinData) PBYTE pbPinData,
__in DWORD cbPinData,
__deref_opt_out_bcount(*pcbSessionPin) PBYTE *ppbSessionPin,
__out_opt PDWORD pcbSessionPin,
__out_opt PDWORD pcAttemptsRemaining);
DWORD
WINAPI
CardAuthenticateEx(
__in PCARD_DATA pCardData,
__in PIN_ID PinId,
__in DWORD dwFlags,
__in_bcount(cbPinData) PBYTE pbPinData,
__in DWORD cbPinData,
__deref_opt_out_bcount(*pcbSessionPin) PBYTE *ppbSessionPin,
__out_opt PDWORD pcbSessionPin,
__out_opt PDWORD pcAttemptsRemaining);
typedef DWORD (WINAPI *PFN_CARD_CHANGE_AUTHENTICATOR_EX)(
__in PCARD_DATA pCardData,
__in DWORD dwFlags,
__in PIN_ID dwAuthenticatingPinId,
__in_bcount(cbAuthenticatingPinData) PBYTE pbAuthenticatingPinData,
__in DWORD cbAuthenticatingPinData,
__in PIN_ID dwTargetPinId,
__in_bcount(cbTargetData) PBYTE pbTargetData,
__in DWORD cbTargetData,
__in DWORD cRetryCount,
__out_opt PDWORD pcAttemptsRemaining);
DWORD
WINAPI
CardChangeAuthenticatorEx(
__in PCARD_DATA pCardData,
__in DWORD dwFlags,
__in PIN_ID dwAuthenticatingPinId,
__in_bcount(cbAuthenticatingPinData) PBYTE pbAuthenticatingPinData,
__in DWORD cbAuthenticatingPinData,
__in PIN_ID dwTargetPinId,
__in_bcount(cbTargetData) PBYTE pbTargetData,
__in DWORD cbTargetData,
__in DWORD cRetryCount,
__out_opt PDWORD pcAttemptsRemaining);
typedef DWORD (WINAPI *PFN_CARD_DEAUTHENTICATE_EX)(
__in PCARD_DATA pCardData,
__in PIN_SET PinId,
__in DWORD dwFlags);
DWORD
WINAPI
CardDeauthenticateEx(
__in PCARD_DATA pCardData,
__in PIN_SET PinId,
__in DWORD dwFlags);
//
// Function: CardDeleteContainer
//
// Purpose: Delete the specified key container.
//
typedef DWORD (WINAPI *PFN_CARD_DELETE_CONTAINER)(
__in PCARD_DATA pCardData,
__in BYTE bContainerIndex,
__in DWORD dwReserved);
DWORD
WINAPI
CardDeleteContainer(
__in PCARD_DATA pCardData,
__in BYTE bContainerIndex,
__in DWORD dwReserved);
//
// Function: CardCreateContainer
//
#define CARD_CREATE_CONTAINER_KEY_GEN 1
#define CARD_CREATE_CONTAINER_KEY_IMPORT 2
typedef DWORD (WINAPI *PFN_CARD_CREATE_CONTAINER)(
__in PCARD_DATA pCardData,
__in BYTE bContainerIndex,
__in DWORD dwFlags,
__in DWORD dwKeySpec,
__in DWORD dwKeySize,
__in PBYTE pbKeyData);
DWORD
WINAPI
CardCreateContainer(
__in PCARD_DATA pCardData,
__in BYTE bContainerIndex,
__in DWORD dwFlags,
__in DWORD dwKeySpec,
__in DWORD dwKeySize,
__in PBYTE pbKeyData);
//
// Function: CardCreateContainerEx
//
typedef DWORD (WINAPI *PFN_CARD_CREATE_CONTAINER_EX)(
__in PCARD_DATA pCardData,
__in BYTE bContainerIndex,
__in DWORD dwFlags,
__in DWORD dwKeySpec,
__in DWORD dwKeySize,
__in PBYTE pbKeyData,
__in PIN_ID PinId);
DWORD
WINAPI
CardCreateContainerEx(
__in PCARD_DATA pCardData,
__in BYTE bContainerIndex,
__in DWORD dwFlags,
__in DWORD dwKeySpec,
__in DWORD dwKeySize,
__in PBYTE pbKeyData,
__in PIN_ID PinId);
//
// Function: CardGetContainerInfo
//
// Purpose: Query for all public information available about
// the named key container. This includes the Signature
// and Key Exchange type public keys, if they exist.
//
// The pbSigPublicKey and pbKeyExPublicKey buffers contain the
// Signature and Key Exchange public keys, respectively, if they
// exist. The format of these buffers is a Crypto
// API PUBLICKEYBLOB -
//
// BLOBHEADER
// RSAPUBKEY
// modulus
//
// In the case of ECC public keys, the pbSigPublicKey will contain
// the ECDSA key and pbKeyExPublicKey will contain the ECDH key if
// they exist. ECC key structure -
//
// BCRYPT_ECCKEY_BLOB
// X coord (big endian)
// Y coord (big endian)
//
#define CONTAINER_INFO_CURRENT_VERSION 1
typedef struct _CONTAINER_INFO
{
DWORD dwVersion;
DWORD dwReserved;
DWORD cbSigPublicKey;
PBYTE pbSigPublicKey;
DWORD cbKeyExPublicKey;
PBYTE pbKeyExPublicKey;
} CONTAINER_INFO, *PCONTAINER_INFO;
typedef DWORD (WINAPI *PFN_CARD_GET_CONTAINER_INFO)(
__in PCARD_DATA pCardData,
__in BYTE bContainerIndex,
__in DWORD dwFlags,
__inout PCONTAINER_INFO pContainerInfo);
DWORD
WINAPI
CardGetContainerInfo(
__in PCARD_DATA pCardData,
__in BYTE bContainerIndex,
__in DWORD dwFlags,
__inout PCONTAINER_INFO pContainerInfo);
//
// Function: CardAuthenticatePin
//
typedef DWORD (WINAPI *PFN_CARD_AUTHENTICATE_PIN)(
__in PCARD_DATA pCardData,
__in LPWSTR pwszUserId,
__in_bcount(cbPin) PBYTE pbPin,
__in DWORD cbPin,
__out_opt PDWORD pcAttemptsRemaining);
DWORD
WINAPI
CardAuthenticatePin(
__in PCARD_DATA pCardData,
__in LPWSTR pwszUserId,
__in_bcount(cbPin) PBYTE pbPin,
__in DWORD cbPin,
__out_opt PDWORD pcAttemptsRemaining);
//
// Function: CardGetChallenge
//
typedef DWORD (WINAPI *PFN_CARD_GET_CHALLENGE)(
__in PCARD_DATA pCardData,
__deref_out_bcount(*pcbChallengeData) PBYTE *ppbChallengeData,
__out PDWORD pcbChallengeData);
DWORD
WINAPI
CardGetChallenge(
__in PCARD_DATA pCardData,
__deref_out_bcount(*pcbChallengeData) PBYTE *ppbChallengeData,
__out PDWORD pcbChallengeData);
//
// Function: CardAuthenticateChallenge
//
typedef DWORD (WINAPI *PFN_CARD_AUTHENTICATE_CHALLENGE)(
__in PCARD_DATA pCardData,
__in_bcount(cbResponseData) PBYTE pbResponseData,
__in DWORD cbResponseData,
__out_opt PDWORD pcAttemptsRemaining);
DWORD
WINAPI
CardAuthenticateChallenge(
__in PCARD_DATA pCardData,
__in_bcount(cbResponseData) PBYTE pbResponseData,
__in DWORD cbResponseData,
__out_opt PDWORD pcAttemptsRemaining);
//
// Function: CardUnblockPin
//
#define CARD_AUTHENTICATE_PIN_CHALLENGE_RESPONSE 1
#define CARD_AUTHENTICATE_PIN_PIN 2
typedef DWORD (WINAPI *PFN_CARD_UNBLOCK_PIN)(
__in PCARD_DATA pCardData,
__in LPWSTR pwszUserId,
__in_bcount(cbAuthenticationData) PBYTE pbAuthenticationData,
__in DWORD cbAuthenticationData,
__in_bcount(cbNewPinData) PBYTE pbNewPinData,
__in DWORD cbNewPinData,
__in DWORD cRetryCount,
__in DWORD dwFlags);
DWORD
WINAPI
CardUnblockPin(
__in PCARD_DATA pCardData,
__in LPWSTR pwszUserId,
__in_bcount(cbAuthenticationData) PBYTE pbAuthenticationData,
__in DWORD cbAuthenticationData,
__in_bcount(cbNewPinData) PBYTE pbNewPinData,
__in DWORD cbNewPinData,
__in DWORD cRetryCount,
__in DWORD dwFlags);
//
// Function: CardChangeAuthenticator
//
typedef DWORD (WINAPI *PFN_CARD_CHANGE_AUTHENTICATOR)(
__in PCARD_DATA pCardData,
__in LPWSTR pwszUserId,
__in_bcount(cbCurrentAuthenticator) PBYTE pbCurrentAuthenticator,
__in DWORD cbCurrentAuthenticator,
__in_bcount(cbNewAuthenticator) PBYTE pbNewAuthenticator,
__in DWORD cbNewAuthenticator,
__in DWORD cRetryCount,
__in DWORD dwFlags,
__out_opt PDWORD pcAttemptsRemaining);
DWORD
WINAPI
CardChangeAuthenticator(
__in PCARD_DATA pCardData,
__in LPWSTR pwszUserId,
__in_bcount(cbCurrentAuthenticator) PBYTE pbCurrentAuthenticator,
__in DWORD cbCurrentAuthenticator,
__in_bcount(cbNewAuthenticator) PBYTE pbNewAuthenticator,
__in DWORD cbNewAuthenticator,
__in DWORD cRetryCount,
__in DWORD dwFlags,
__out_opt PDWORD pcAttemptsRemaining);
//
// Function: CardDeauthenticate
//
// Purpose: De-authenticate the specified logical user name on the card.
//
// This is an optional API. If implemented, this API is used instead
// of SCARD_RESET_CARD by the Base CSP. An example scenario is leaving
// a transaction in which the card has been authenticated (a Pin has been
// successfully presented).
//
// The pwszUserId parameter will point to a valid well-known User Name (see
// above).
//
// The dwFlags parameter is currently unused and will always be zero.
//
// Card modules that choose to not implement this API must set the CARD_DATA
// pfnCardDeauthenticate pointer to NULL.
//
typedef DWORD (WINAPI *PFN_CARD_DEAUTHENTICATE)(
__in PCARD_DATA pCardData,
__in LPWSTR pwszUserId,
__in DWORD dwFlags);
DWORD
WINAPI
CardDeauthenticate(
__in PCARD_DATA pCardData,
__in LPWSTR pwszUserId,
__in DWORD dwFlags);
// Directory Control Group
//
// Function: CardCreateDirectory
//
// Purpose: Register the specified application name on the card, and apply the
// provided access condition.
//
// Return Value:
// ERROR_FILE_EXISTS - directory already exists
//
typedef DWORD (WINAPI *PFN_CARD_CREATE_DIRECTORY)(
__in PCARD_DATA pCardData,
__in LPSTR pszDirectoryName,
__in CARD_DIRECTORY_ACCESS_CONDITION AccessCondition);
DWORD
WINAPI
CardCreateDirectory(
__in PCARD_DATA pCardData,
__in LPSTR pszDirectoryName,
__in CARD_DIRECTORY_ACCESS_CONDITION AccessCondition);
//
// Function: CardDeleteDirectory
//
// Purpose: Unregister the specified application from the card.
//
// Return Value:
// SCARD_E_DIR_NOT_FOUND - directory does not exist
// ERROR_DIR_NOT_EMPTY - the directory is not empty
//
typedef DWORD (WINAPI *PFN_CARD_DELETE_DIRECTORY)(
__in PCARD_DATA pCardData,
__in LPSTR pszDirectoryName);
DWORD
WINAPI
CardDeleteDirectory(
__in PCARD_DATA pCardData,
__in LPSTR pszDirectoryName);
// File Control Group
//
// Function: CardCreateFile
//
typedef DWORD (WINAPI *PFN_CARD_CREATE_FILE)(
__in PCARD_DATA pCardData,
__in_opt LPSTR pszDirectoryName,
__in LPSTR pszFileName,
__in DWORD cbInitialCreationSize,
__in CARD_FILE_ACCESS_CONDITION AccessCondition);
DWORD
WINAPI
CardCreateFile(
__in PCARD_DATA pCardData,
__in_opt LPSTR pszDirectoryName,
__in LPSTR pszFileName,
__in DWORD cbInitialCreationSize,
__in CARD_FILE_ACCESS_CONDITION AccessCondition);
//
// Function: CardReadFile
//
// Purpose: Read the specified file from the card.
//
// The pbData parameter should be allocated
// by the card module and freed by the CSP. The card module
// must set the cbData parameter to the size of the returned buffer.
//
typedef DWORD (WINAPI *PFN_CARD_READ_FILE)(
__in PCARD_DATA pCardData,
__in_opt LPSTR pszDirectoryName,
__in LPSTR pszFileName,
__in DWORD dwFlags,
__deref_out_bcount_opt(*pcbData) PBYTE *ppbData,
__out PDWORD pcbData);
DWORD
WINAPI
CardReadFile(
__in PCARD_DATA pCardData,
__in_opt LPSTR pszDirectoryName,
__in LPSTR pszFileName,
__in DWORD dwFlags,
__deref_out_bcount_opt(*pcbData) PBYTE *ppbData,
__out PDWORD pcbData);
//
// Function: CardWriteFile
//
typedef DWORD (WINAPI *PFN_CARD_WRITE_FILE)(
__in PCARD_DATA pCardData,
__in_opt LPSTR pszDirectoryName,
__in LPSTR pszFileName,
__in DWORD dwFlags,
__in_bcount(cbData) PBYTE pbData,
__in DWORD cbData);
DWORD
WINAPI
CardWriteFile(
__in PCARD_DATA pCardData,
__in_opt LPSTR pszDirectoryName,
__in LPSTR pszFileName,
__in DWORD dwFlags,
__in_bcount(cbData) PBYTE pbData,
__in DWORD cbData);
//
// Function: CardDeleteFile
//
typedef DWORD (WINAPI *PFN_CARD_DELETE_FILE)(
__in PCARD_DATA pCardData,
__in_opt LPSTR pszDirectoryName,
__in LPSTR pszFileName,
__in DWORD dwFlags);
DWORD
WINAPI
CardDeleteFile(
__in PCARD_DATA pCardData,
__in_opt LPSTR pszDirectoryName,
__in LPSTR pszFileName,
__in DWORD dwFlags);
//
// Function: CardEnumFiles
//
// Purpose: Return a multi-string list of the general files
// present on this card. The multi-string is allocated
// by the card module and must be freed by the CSP.
//
// The caller must provide a logical file directory name in the
// pmwszFileNames parameter (see Logical Directory Names, above).
// The logical directory name indicates which group of files will be
// enumerated.
//
// The logical directory name is expected to be a static string, so the
// the card module will not free it. The card module
// will allocate a new buffer in *pmwszFileNames to store the multi-string
// list of enumerated files using pCardData->pfnCspAlloc.
//
// If the function fails for any reason, *pmwszFileNames is set to NULL.
//
typedef DWORD (WINAPI *PFN_CARD_ENUM_FILES)(
__in PCARD_DATA pCardData,
__in_opt LPSTR pszDirectoryName,
__deref_out_ecount(*pdwcbFileName) LPSTR *pmszFileNames,
__out LPDWORD pdwcbFileName,
__in DWORD dwFlags);
DWORD
WINAPI
CardEnumFiles(
__in PCARD_DATA pCardData,
__in_opt LPSTR pszDirectoryName,
__deref_out_ecount(*pdwcbFileName) LPSTR *pmszFileNames,
__out LPDWORD pdwcbFileName,
__in DWORD dwFlags);
//
// Function: CardGetFileInfo
//
#define CARD_FILE_INFO_CURRENT_VERSION 1
typedef struct _CARD_FILE_INFO
{
DWORD dwVersion;
DWORD cbFileSize;
CARD_FILE_ACCESS_CONDITION AccessCondition;
} CARD_FILE_INFO, *PCARD_FILE_INFO;
typedef DWORD (WINAPI *PFN_CARD_GET_FILE_INFO)(
__in PCARD_DATA pCardData,
__in_opt LPSTR pszDirectoryName,
__in LPSTR pszFileName,
__inout PCARD_FILE_INFO pCardFileInfo);
DWORD
WINAPI
CardGetFileInfo(
__in PCARD_DATA pCardData,
__in_opt LPSTR pszDirectoryName,
__in LPSTR pszFileName,
__inout PCARD_FILE_INFO pCardFileInfo);
//
// Function: CardQueryFreeSpace
//
#define CARD_FREE_SPACE_INFO_CURRENT_VERSION 1
typedef struct _CARD_FREE_SPACE_INFO
{
DWORD dwVersion;
DWORD dwBytesAvailable;
DWORD dwKeyContainersAvailable;
DWORD dwMaxKeyContainers;
} CARD_FREE_SPACE_INFO, *PCARD_FREE_SPACE_INFO;
typedef DWORD (WINAPI *PFN_CARD_QUERY_FREE_SPACE)(
__in PCARD_DATA pCardData,
__in DWORD dwFlags,
__inout PCARD_FREE_SPACE_INFO pCardFreeSpaceInfo);
DWORD
WINAPI
CardQueryFreeSpace(
__in PCARD_DATA pCardData,
__in DWORD dwFlags,
__inout PCARD_FREE_SPACE_INFO pCardFreeSpaceInfo);
//
// Function: CardQueryKeySizes
//
#define CARD_KEY_SIZES_CURRENT_VERSION 1
typedef struct _CARD_KEY_SIZES
{
DWORD dwVersion;
DWORD dwMinimumBitlen;
DWORD dwDefaultBitlen;
DWORD dwMaximumBitlen;
DWORD dwIncrementalBitlen;
} CARD_KEY_SIZES, *PCARD_KEY_SIZES;
typedef DWORD (WINAPI *PFN_CARD_QUERY_KEY_SIZES)(
__in PCARD_DATA pCardData,
__in DWORD dwKeySpec,
__in DWORD dwFlags,
__inout PCARD_KEY_SIZES pKeySizes);
DWORD
WINAPI
CardQueryKeySizes(
__in PCARD_DATA pCardData,
__in DWORD dwKeySpec,
__in DWORD dwFlags,
__inout PCARD_KEY_SIZES pKeySizes);
// CARD_RSA_DECRYPT_INFO_VERSION_ONE is provided for pre-v7 certified
// mini-drivers that do not have logic for on-card padding removal.
#define CARD_RSA_KEY_DECRYPT_INFO_VERSION_ONE 1
#define CARD_RSA_KEY_DECRYPT_INFO_VERSION_TWO 2
//