-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
WinCrypt.java
1858 lines (1636 loc) · 65.1 KB
/
WinCrypt.java
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
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
*
* The contents of this file is dual-licensed under 2
* alternative Open Source/Free licenses: LGPL 2.1 or later and
* Apache License 2.0. (starting with JNA version 4.0.0).
*
* You can freely decide which license you want to apply to
* the project.
*
* You may obtain a copy of the LGPL License at:
*
* http://www.gnu.org/licenses/licenses.html
*
* A copy is also included in the downloadable source code package
* containing JNA, in file "LGPL2.1".
*
* You may obtain a copy of the Apache License at:
*
* http://www.apache.org/licenses/
*
* A copy is also included in the downloadable source code package
* containing JNA, in file "AL2.0".
*/
package com.sun.jna.platform.win32;
import com.sun.jna.FromNativeContext;
import com.sun.jna.Memory;
import com.sun.jna.Native;
import com.sun.jna.NativeMapped;
import com.sun.jna.Pointer;
import com.sun.jna.StringArray;
import com.sun.jna.Structure;
import com.sun.jna.Structure.FieldOrder;
import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.win32.W32APITypeMapper;
import com.sun.jna.platform.win32.Guid.GUID;
import com.sun.jna.platform.win32.WTypes.LPSTR;
import com.sun.jna.platform.win32.WinBase.FILETIME;
import com.sun.jna.platform.win32.WinCrypt.DATA_BLOB;
import com.sun.jna.platform.win32.WinNT.HANDLE;
import com.sun.jna.Union;
import com.sun.jna.win32.StdCallLibrary;
/**
* Ported from WinCrypt.h.
* Microsoft Windows SDK 6.0A.
* @author dblock[at]dblock.org
*/
public interface WinCrypt {
/**
* The CryptoAPI CRYPTOAPI_BLOB structure is used for an arbitrary array of bytes.
*/
@FieldOrder({"cbData", "pbData"})
public static class DATA_BLOB extends Structure {
public static class ByReference extends DATA_BLOB implements Structure.ByReference {}
/**
* The count of bytes in the buffer pointed to by pbData.
*/
public int cbData;
/**
* A pointer to a block of data bytes.
*/
public Pointer pbData;
public DATA_BLOB() {
super();
}
public DATA_BLOB(Pointer memory) {
super(memory);
read();
}
public DATA_BLOB(byte [] data) {
super();
if (data.length > 0) {
pbData = new Memory(data.length);
pbData.write(0, data, 0, data.length);
cbData = data.length;
} else {
// We allocate 1 byte memory region because `malloc` may return `NULL` if requested size is 0.
// However, `CryptProtectData` and `CryptUnprotectData` consider `NULL` as invalid data.
// The fact that we allocate 1 byte does not affect the final result because
// we pass the correct size explicitly on `cbData` field.
pbData = new Memory(1);
cbData = 0;
}
}
public DATA_BLOB(String s) {
this(Native.toByteArray(s));
}
/**
* Get byte data.
* @return
* Byte data or null.
*/
public byte[] getData() {
return pbData == null ? null : pbData.getByteArray(0, cbData);
}
}
/**
* The CERT_TRUST_STATUS structure contains trust information about a
* certificate in a certificate chain, summary trust information about a
* simple chain of certificates, or summary information about an array of
* simple chains.
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa377590(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"dwErrorStatus", "dwInfoStatus"})
public static class CERT_TRUST_STATUS extends Structure {
public static class ByReference extends CERT_TRUST_STATUS implements Structure.ByReference {
}
public int dwErrorStatus;
public int dwInfoStatus;
}
/**
* The CTL_ENTRY structure is an element of a certificate trust list (CTL).
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa381487(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"SubjectIdentifier", "cAttribute", "rgAttribute"})
public static class CTL_ENTRY extends Structure {
public static class ByReference extends CTL_ENTRY implements Structure.ByReference {
}
public DATA_BLOB SubjectIdentifier;
public int cAttribute;
public Pointer rgAttribute;
public CRYPT_ATTRIBUTE[] getRgAttribute() {
if (cAttribute == 0) {
return new CRYPT_ATTRIBUTE[0];
} else {
CRYPT_ATTRIBUTE[] result = (CRYPT_ATTRIBUTE[]) Structure.newInstance(
CRYPT_ATTRIBUTE.class,
rgAttribute)
.toArray(cAttribute);
result[0].read();
return result;
}
}
}
/**
* Contains information updated by a certificate revocation list (CRL)
* revocation type handler. The CERT_REVOCATION_CRL_INFO structure is used
* with both base and delta CRLs.
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa377509(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"cbSize", "pBaseCRLContext", "pDeltaCRLContext", "pCrlEntry",
"fDeltaCrlEntry"})
public static class CERT_REVOCATION_CRL_INFO extends Structure {
public static class ByReference extends CERT_REVOCATION_CRL_INFO implements Structure.ByReference {
}
public int cbSize;
public CRL_CONTEXT.ByReference pBaseCRLContext;
public CRL_CONTEXT.ByReference pDeltaCRLContext;
public CRL_ENTRY.ByReference pCrlEntry;
public boolean fDeltaCrlEntry;
public CERT_REVOCATION_CRL_INFO() {
super(W32APITypeMapper.DEFAULT);
}
}
/**
* The CERT_REVOCATION_INFO structure indicates the revocation status of a
* certificate in a CERT_CHAIN_ELEMENT.
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa377519(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"cbSize", "dwRevocationResult", "pszRevocationOid",
"pvOidSpecificInfo", "fHasFreshnessTime", "dwFreshnessTime", "pCrlInfo"})
public static class CERT_REVOCATION_INFO extends Structure {
public static class ByReference extends CERT_REVOCATION_INFO implements Structure.ByReference {
}
public int cbSize;
public int dwRevocationResult;
public String pszRevocationOid;
public Pointer pvOidSpecificInfo;
public boolean fHasFreshnessTime;
public int dwFreshnessTime;
public CERT_REVOCATION_CRL_INFO.ByReference pCrlInfo;
public CERT_REVOCATION_INFO() {
super(W32APITypeMapper.ASCII);
}
}
/**
* The CERT_CHAIN_ELEMENT structure is a single element in a simple
* certificate chain. Each element has a pointer to a certificate context, a
* pointer to a structure that indicates the error status and information
* status of the certificate, and a pointer to a structure that indicates
* the revocation status of the certificate.
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa377183(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"cbSize", "pCertContext", "TrustStatus", "pRevocationInfo",
"pIssuanceUsage", "pApplicationUsage", "pwszExtendedErrorInfo"})
public static class CERT_CHAIN_ELEMENT extends Structure {
public static class ByReference extends CERT_CHAIN_ELEMENT implements Structure.ByReference {
}
public int cbSize;
public CERT_CONTEXT.ByReference pCertContext;
public CERT_TRUST_STATUS TrustStatus;
public CERT_REVOCATION_INFO.ByReference pRevocationInfo;
public CTL_USAGE.ByReference pIssuanceUsage;
public CTL_USAGE.ByReference pApplicationUsage;
public String pwszExtendedErrorInfo;
public CERT_CHAIN_ELEMENT() {
super(W32APITypeMapper.UNICODE);
}
public CERT_CHAIN_ELEMENT(Pointer p) {
super(p, Structure.ALIGN_DEFAULT, W32APITypeMapper.UNICODE);
}
}
/**
* The CTL_INFO structure contains the information stored in a Certificate
* Trust List (CTL).
*
* @see
* <a href="https://msdn.microsoft.com/es-xl/library/windows/desktop/aa381491(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"dwVersion", "SubjectUsage", "ListIdentifier", "SequenceNumber",
"ThisUpdate", "NextUpdate", "SubjectAlgorithm", "cCTLEntry",
"rgCTLEntry", "cExtension", "rgExtension"})
public static class CTL_INFO extends Structure {
public static class ByReference extends CTL_INFO implements Structure.ByReference {
}
public int dwVersion;
public CTL_USAGE SubjectUsage;
public DATA_BLOB ListIdentifier;
public DATA_BLOB SequenceNumber;
public FILETIME ThisUpdate;
public FILETIME NextUpdate;
public CRYPT_ALGORITHM_IDENTIFIER SubjectAlgorithm;
public int cCTLEntry;
public Pointer rgCTLEntry;
public int cExtension;
public Pointer rgExtension;
public CTL_ENTRY[] getRgCTLEntry() {
if (cCTLEntry == 0) {
return new CTL_ENTRY[0];
} else {
CTL_ENTRY[] result = (CTL_ENTRY[]) Structure.newInstance(
CTL_ENTRY.class,
rgCTLEntry)
.toArray(cCTLEntry);
result[0].read();
return result;
}
}
public CERT_EXTENSION[] getRgExtension() {
if (cExtension == 0) {
return new CERT_EXTENSION[0];
} else {
CERT_EXTENSION[] result = (CERT_EXTENSION[]) Structure.newInstance(
CERT_EXTENSION.class,
rgExtension)
.toArray(cExtension);
result[0].read();
return result;
}
}
}
/**
* The CTL_CONTEXT structure contains both the encoded and decoded
* representations of a CTL. It also contains an opened HCRYPTMSG handle to
* the decoded, cryptographically signed message containing the CTL_INFO as
* its inner content.
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa381486(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"dwMsgAndCertEncodingType", "pbCtlEncoded", "cbCtlEncoded",
"pCtlInfo", "hCertStore", "hCryptMsg", "pbCtlContent",
"cbCtlContent"})
public static class CTL_CONTEXT extends Structure {
public static class ByReference extends CTL_CONTEXT implements Structure.ByReference {
}
public int dwMsgAndCertEncodingType;
public Pointer pbCtlEncoded;
public int cbCtlEncoded;
public CTL_INFO.ByReference pCtlInfo;
public HCERTSTORE hCertStore;
public HCRYPTMSG hCryptMsg;
public Pointer pbCtlContent;
public int cbCtlContent;
}
/**
* The CERT_TRUST_LIST_INFO structure that indicates valid usage of a CTL.
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa377585(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"cbSize", "pCtlEntry", "pCtlContext"})
public static class CERT_TRUST_LIST_INFO extends Structure {
public static class ByReference extends CERT_TRUST_LIST_INFO implements Structure.ByReference {
}
public int cbSize;
public CTL_ENTRY.ByReference pCtlEntry;
public CTL_CONTEXT.ByReference pCtlContext;
}
/**
* The CTL_USAGE structure contains an array of object identifiers (OIDs)
* for Certificate Trust List (CTL) extensions. CTL_USAGE structures are
* used in functions that search for CTLs for specific uses.
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa381493(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"cUsageIdentifier", "rgpszUsageIdentifier"})
public static class CTL_USAGE extends Structure {
public static class ByReference extends CTL_USAGE implements Structure.ByReference {
}
public int cUsageIdentifier;
public Pointer rgpszUsageIdentifier;
public CTL_USAGE() {
super();
}
public String[] getRgpszUsageIdentier() {
if (cUsageIdentifier == 0) {
return new String[0];
} else {
return rgpszUsageIdentifier.getStringArray(0, cUsageIdentifier);
}
}
public void setRgpszUsageIdentier(String[] array) {
if (array == null || array.length == 0) {
cUsageIdentifier = 0;
rgpszUsageIdentifier = null;
} else {
cUsageIdentifier = array.length;
rgpszUsageIdentifier = new StringArray(array);
}
}
}
/**
* The CERT_USAGE_MATCH structure provides criteria for identifying issuer
* certificates to be used to build a certificate chain.
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa377593(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"dwType", "Usage"})
public static class CERT_USAGE_MATCH extends Structure {
public static class ByReference extends CERT_USAGE_MATCH implements Structure.ByReference {
}
public int dwType;
public CTL_USAGE Usage;
}
/**
* The CERT_CHAIN_PARA structure establishes the searching and matching
* criteria to be used in building a certificate chain.
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa377186(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"cbSize", "RequestedUsage", "RequestedIssuancePolicy",
"dwUrlRetrievalTimeout", "fCheckRevocationFreshnessTime",
"dwRevocationFreshnessTime", "pftCacheResync", "pStrongSignPara",
"dwStrongSignFlags"})
public static class CERT_CHAIN_PARA extends Structure {
public static class ByReference extends CERT_CHAIN_PARA implements Structure.ByReference {
}
public int cbSize;
public CERT_USAGE_MATCH RequestedUsage;
public CERT_USAGE_MATCH RequestedIssuancePolicy;
public int dwUrlRetrievalTimeout;
public boolean fCheckRevocationFreshnessTime;
public int dwRevocationFreshnessTime;
public FILETIME.ByReference pftCacheResync;
public CERT_STRONG_SIGN_PARA.ByReference pStrongSignPara;
public int dwStrongSignFlags;
public CERT_CHAIN_PARA() {
super(W32APITypeMapper.DEFAULT);
}
}
/**
* Contains parameters used to check for strong signatures on certificates,
* certificate revocation lists (CRLs), online certificate status protocol
* (OCSP) responses, and PKCS #7 messages.
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/hh870262(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"cbSize", "dwInfoChoice", "DUMMYUNIONNAME"})
public static class CERT_STRONG_SIGN_PARA extends Structure {
public static class ByReference extends CERT_CHAIN_PARA implements Structure.ByReference {
}
public int cbSize;
public int dwInfoChoice;
public DUMMYUNION DUMMYUNIONNAME;
public class DUMMYUNION extends Union {
Pointer pvInfo;
CERT_STRONG_SIGN_SERIALIZED_INFO.ByReference pSerializedInfo;
LPSTR pszOID;
}
}
/**
* Contains the signature algorithm/hash algorithm and public key
* algorithm/bit length pairs that can be used for strong signing. This
* structure is used by the CERT_STRONG_SIGN_PARA structure.
*
* @see
* <a href= "https://msdn.microsoft.com/en-us/library/windows/desktop/hh870263(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"dwFlags", "pwszCNGSignHashAlgids", "pwszCNGPubKeyMinBitLengths"})
public static class CERT_STRONG_SIGN_SERIALIZED_INFO extends Structure {
public static class ByReference extends CERT_CHAIN_PARA implements Structure.ByReference {
}
public int dwFlags;
public String pwszCNGSignHashAlgids;
public String pwszCNGPubKeyMinBitLengths;
public CERT_STRONG_SIGN_SERIALIZED_INFO() {
super(W32APITypeMapper.UNICODE);
}
}
/**
* The CERT_CHAIN_POLICY_STATUS structure holds certificate chain status
* information returned by the CertVerifyCertificateChainPolicy function
* when the certificate chains are validated.
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa377188(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"cbSize", "dwError", "lChainIndex", "lElementIndex",
"pvExtraPolicyStatus"})
public static class CERT_CHAIN_POLICY_STATUS extends Structure {
public static class ByReference extends CERT_CHAIN_POLICY_STATUS implements Structure.ByReference {
}
public int cbSize;
public int dwError;
public int lChainIndex;
public int lElementIndex;
public Pointer pvExtraPolicyStatus;
}
/**
* The CERT_SIMPLE_CHAIN structure contains an array of chain elements and a
* summary trust status for the chain that the array represents.
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa377544(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"cbSize", "TrustStatus", "cElement", "rgpElement", "pTrustListInfo",
"fHasRevocationFreshnessTime", "dwRevocationFreshnessTime"})
public static class CERT_SIMPLE_CHAIN extends Structure {
public static class ByReference extends CERT_SIMPLE_CHAIN implements Structure.ByReference {
}
public int cbSize;
public CERT_TRUST_STATUS TrustStatus;
public int cElement;
public Pointer rgpElement;
public CERT_TRUST_LIST_INFO.ByReference pTrustListInfo;
public boolean fHasRevocationFreshnessTime;
public int dwRevocationFreshnessTime;
public CERT_SIMPLE_CHAIN() {
super(W32APITypeMapper.DEFAULT);
}
public CERT_CHAIN_ELEMENT[] getRgpElement() {
CERT_CHAIN_ELEMENT[] elements = new CERT_CHAIN_ELEMENT[cElement];
for (int i = 0; i < elements.length; i++) {
elements[i] = Structure.newInstance(
CERT_CHAIN_ELEMENT.class,
rgpElement.getPointer(i * Native.POINTER_SIZE));
elements[i].read();
}
return elements;
}
}
/**
* The CERT_CHAIN_POLICY_PARA structure contains information used in
* CertVerifyCertificateChainPolicy to establish policy criteria for the
* verification of certificate chains.
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa377187(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"cbSize", "dwFlags", "pvExtraPolicyPara"})
public static class CERT_CHAIN_POLICY_PARA extends Structure {
public static class ByReference extends CERT_CHAIN_POLICY_PARA implements Structure.ByReference {
}
public int cbSize;
public int dwFlags;
public Pointer pvExtraPolicyPara;
}
/**
* The CERT_CHAIN_CONTEXT structure contains an array of simple certificate
* chains and a trust status structure that indicates summary validity data
* on all of the connected simple chains.
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa377182(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"cbSize", "TrustStatus", "cChain", "rgpChain",
"cLowerQualityChainContext", "rgpLowerQualityChainContext",
"fHasRevocationFreshnessTime", "dwRevocationFreshnessTime",
"dwCreateFlags", "ChainId"})
public static class CERT_CHAIN_CONTEXT extends Structure {
public static class ByReference extends CERT_CHAIN_CONTEXT implements Structure.ByReference {
}
public int cbSize;
public CERT_TRUST_STATUS TrustStatus;
public int cChain;
public Pointer rgpChain;
public int cLowerQualityChainContext;
public Pointer rgpLowerQualityChainContext;
public boolean fHasRevocationFreshnessTime;
public int dwRevocationFreshnessTime;
public int dwCreateFlags;
public GUID ChainId;
public CERT_SIMPLE_CHAIN[] getRgpChain() {
CERT_SIMPLE_CHAIN[] elements = new CERT_SIMPLE_CHAIN[cChain];
for (int i = 0; i < elements.length; i++) {
elements[i] = Structure.newInstance(
CERT_SIMPLE_CHAIN.class,
rgpChain.getPointer(i * Native.POINTER_SIZE));
elements[i].read();
}
return elements;
}
public CERT_CHAIN_CONTEXT[] getRgpLowerQualityChainContext() {
CERT_CHAIN_CONTEXT[] elements = new CERT_CHAIN_CONTEXT[cLowerQualityChainContext];
for (int i = 0; i < elements.length; i++) {
elements[i] = Structure.newInstance(
CERT_CHAIN_CONTEXT.class,
rgpLowerQualityChainContext.getPointer(i * Native.POINTER_SIZE));
elements[i].read();
}
return elements;
}
public CERT_CHAIN_CONTEXT() {
super(W32APITypeMapper.DEFAULT);
}
}
/**
* The CERT_CONTEXT structure contains both the encoded and decoded
* representations of a certificate. A certificate context returned by one
* of the functions defined in Wincrypt.h must be freed by calling the
* CertFreeCertificateContext function. The CertDuplicateCertificateContext
* function can be called to make a duplicate copy (which also must be freed
* by calling CertFreeCertificateContext).
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa377189(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"dwCertEncodingType", "pbCertEncoded", "cbCertEncoded",
"pCertInfo", "hCertStore"})
public static class CERT_CONTEXT extends Structure {
public static class ByReference extends CERT_CONTEXT implements Structure.ByReference {
}
public int dwCertEncodingType;
public Pointer pbCertEncoded;
public int cbCertEncoded;
public CERT_INFO.ByReference pCertInfo;
public HCERTSTORE hCertStore;
}
/**
* The CERT_EXTENSION structure contains the extension information for a
* certificate, Certificate Revocation List (CRL) or Certificate Trust List
* (CTL).
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa377195(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"pszObjId", "fCritical", "Value"})
public static class CERT_EXTENSION extends Structure {
public static class ByReference extends CERT_EXTENSION implements Structure.ByReference {
}
public String pszObjId;
public boolean fCritical;
public DATA_BLOB Value;
public CERT_EXTENSION() {
super(W32APITypeMapper.ASCII);
}
}
/**
* The CERT_EXTENSIONS structure contains an array of extensions.
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa377196(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"cExtension", "rgExtension"})
public static class CERT_EXTENSIONS extends Structure {
public static class ByReference extends CERT_EXTENSIONS implements Structure.ByReference {
}
public int cExtension;
public Pointer rgExtension;
public CERT_EXTENSION[] getRgExtension() {
if(cExtension == 0) {
return new CERT_EXTENSION[0];
}
CERT_EXTENSION[] ces = (CERT_EXTENSION[]) Structure
.newInstance(CERT_EXTENSION.class, rgExtension)
.toArray(cExtension);
ces[0].read();
return ces;
}
}
/**
* The CERT_INFO structure contains the information of a certificate.
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa377200(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"dwVersion", "SerialNumber", "SignatureAlgorithm", "Issuer",
"NotBefore", "NotAfter", "Subject", "SubjectPublicKeyInfo",
"IssuerUniqueId", "SubjectUniqueId", "cExtension", "rgExtension"})
public static class CERT_INFO extends Structure {
public static class ByReference extends CERT_INFO implements Structure.ByReference {
}
public int dwVersion;
public DATA_BLOB SerialNumber;
public CRYPT_ALGORITHM_IDENTIFIER SignatureAlgorithm;
public DATA_BLOB Issuer;
public FILETIME NotBefore;
public FILETIME NotAfter;
public DATA_BLOB Subject;
public CERT_PUBLIC_KEY_INFO SubjectPublicKeyInfo;
public CRYPT_BIT_BLOB IssuerUniqueId;
public CRYPT_BIT_BLOB SubjectUniqueId;
public int cExtension;
public Pointer rgExtension;
public CERT_EXTENSION[] getRgExtension() {
if(cExtension == 0) {
return new CERT_EXTENSION[0];
}
CERT_EXTENSION[] ces = (CERT_EXTENSION[]) Structure
.newInstance(CERT_EXTENSION.class, rgExtension)
.toArray(cExtension);
ces[0].read();
return ces;
}
}
/**
* The CERT_PUBLIC_KEY_INFO structure contains a public key and its
* algorithm.
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa377463(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"Algorithm", "PublicKey"})
public static class CERT_PUBLIC_KEY_INFO extends Structure {
public static class ByReference extends CERT_PUBLIC_KEY_INFO implements Structure.ByReference {
}
public CRYPT_ALGORITHM_IDENTIFIER Algorithm;
public CRYPT_BIT_BLOB PublicKey;
}
/**
* The CRL_CONTEXT structure contains both the encoded and decoded
* representations of a certificate revocation list (CRL). CRL contexts
* returned by any CryptoAPI function must be freed by calling the
* CertFreeCRLContext function.
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa379873(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"dwCertEncodingType", "pbCrlEncoded", "cbCrlEncoded",
"pCrlInfo", "hCertStore"})
public static class CRL_CONTEXT extends Structure {
public static class ByReference extends CRL_CONTEXT implements Structure.ByReference {
}
public int dwCertEncodingType;
public Pointer pbCrlEncoded;
public int cbCrlEncoded;
public CRL_INFO.ByReference pCrlInfo;
public HCERTSTORE hCertStore;
}
/**
* The CRL_ENTRY structure contains information about a single revoked
* certificate. It is a member of a CRL_INFO structure.
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa379878(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"SerialNumber", "RevocationDate", "cExtension", "rgExtension"})
public static class CRL_ENTRY extends Structure {
public static class ByReference extends CRL_ENTRY implements Structure.ByReference {
}
public DATA_BLOB SerialNumber;
public FILETIME RevocationDate;
public int cExtension;
public Pointer rgExtension;
public CERT_EXTENSION[] getRgExtension() {
if(cExtension == 0) {
return new CERT_EXTENSION[0];
} else {
CERT_EXTENSION[] result = (CERT_EXTENSION[]) Structure
.newInstance(CERT_EXTENSION.class, rgExtension)
.toArray(cExtension);
result[0].read();
return result;
}
}
}
/**
* The CRL_INFO structure contains the information of a certificate
* revocation list (CRL).
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa379880(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"dwVersion", "SignatureAlgorithm", "Issuer", "ThisUpdate",
"NextUpdate", "cCRLEntry", "rgCRLEntry", "cExtension", "rgExtension"})
public static class CRL_INFO extends Structure {
public static class ByReference extends CRL_INFO implements Structure.ByReference {
}
public int dwVersion;
public CRYPT_ALGORITHM_IDENTIFIER SignatureAlgorithm;
public DATA_BLOB Issuer;
public FILETIME ThisUpdate;
public FILETIME NextUpdate;
public int cCRLEntry;
public Pointer rgCRLEntry;
public int cExtension;
public Pointer rgExtension;
public CRL_ENTRY[] getRgCRLEntry() {
if (cCRLEntry == 0) {
return new CRL_ENTRY[0];
} else {
CRL_ENTRY[] result = (CRL_ENTRY[]) Structure
.newInstance(CRL_ENTRY.class, rgCRLEntry)
.toArray(cCRLEntry);
result[0].read();
return result;
}
}
public CERT_EXTENSION[] getRgExtension() {
if (cExtension == 0) {
return new CERT_EXTENSION[0];
} else {
CERT_EXTENSION[] result = (CERT_EXTENSION[]) Structure
.newInstance(CERT_EXTENSION.class, rgExtension)
.toArray(cExtension);
result[0].read();
return result;
}
}
}
/**
* The CRYPT_ALGORITHM_IDENTIFIER structure specifies an algorithm used to
* encrypt a private key. The structure includes the object identifier (OID)
* of the algorithm and any needed parameters for that algorithm. The
* parameters contained in its CRYPT_OBJID_BLOB are encoded.
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa381133(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"pszObjId", "Parameters"})
public static class CRYPT_ALGORITHM_IDENTIFIER extends Structure {
public static class ByReference extends CRYPT_ALGORITHM_IDENTIFIER implements Structure.ByReference {
}
public String pszObjId;
public DATA_BLOB Parameters;
public CRYPT_ALGORITHM_IDENTIFIER() {
super(W32APITypeMapper.ASCII);
}
}
/**
* The CRYPT_ATTRIBUTE structure specifies an attribute that has one or more
* values.
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa381139(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"pszObjId", "cValue", "rgValue"})
public static class CRYPT_ATTRIBUTE extends Structure {
public static class ByReference extends CRYPT_ATTRIBUTE implements Structure.ByReference {
}
public String pszObjId;
public int cValue;
public DATA_BLOB.ByReference rgValue;
public DATA_BLOB[] getRgValue() {
return (DATA_BLOB[]) rgValue.toArray(cValue);
}
public CRYPT_ATTRIBUTE() {
super(W32APITypeMapper.ASCII);
}
}
/**
* The CRYPT_BIT_BLOB structure contains a set of bits represented by an
* array of bytes.
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa381165(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"cbData", "pbData", "cUnusedBits"})
public static class CRYPT_BIT_BLOB extends Structure {
public static class ByReference extends CRYPT_BIT_BLOB implements Structure.ByReference {
}
public int cbData;
public Pointer pbData;
public int cUnusedBits;
}
/**
* The CRYPT_KEY_PROV_INFO structure contains information about a key
* container within a cryptographic service provider (CSP).
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa381420(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"pwszContainerName", "pwszProvName", "dwProvType", "dwFlags",
"cProvParam", "rgProvParam", "dwKeySpec"})
public static class CRYPT_KEY_PROV_INFO extends Structure {
public static class ByReference extends CRYPT_KEY_PROV_INFO implements Structure.ByReference {
}
public String pwszContainerName;
public String pwszProvName;
public int dwProvType;
public int dwFlags;
public int cProvParam;
public Pointer rgProvParam;
public int dwKeySpec;
public CRYPT_KEY_PROV_INFO() {
super(W32APITypeMapper.UNICODE);
}
public CRYPT_KEY_PROV_PARAM[] getRgProvParam() {
CRYPT_KEY_PROV_PARAM[] elements = new CRYPT_KEY_PROV_PARAM[cProvParam];
for (int i = 0; i < elements.length; i++) {
elements[i] = Structure.newInstance(
CRYPT_KEY_PROV_PARAM.class,
rgProvParam.getPointer(i * Native.POINTER_SIZE));
elements[i].read();
}
return elements;
}
}
/**
* The CRYPT_KEY_PROV_PARAM structure contains information about a key
* container parameter. This structure is used with the CRYPT_KEY_PROV_INFO
* structure.
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa381423(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"dwParam", "pbData", "cbData", "dwFlags"})
public static class CRYPT_KEY_PROV_PARAM extends Structure {
public static class ByReference extends CRYPT_KEY_PROV_PARAM implements Structure.ByReference {
}
public int dwParam;
public Pointer pbData;
public int cbData;
public int dwFlags;
}
/**
* The CRYPT_SIGN_MESSAGE_PARA structure contains information for signing
* messages using a specified signing certificate context.
*
* @see
* <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa381468(v=vs.85).aspx">MSDN</a>
*/
@FieldOrder({"cbSize", "dwMsgEncodingType", "pSigningCert", "HashAlgorithm",
"pvHashAuxInfo", "cMsgCert", "rgpMsgCert", "cMsgCrl",
"rgpMsgCrl", "cAuthAttr", "rgAuthAttr", "cUnauthAttr",
"rgUnauthAttr", "dwFlags", "dwInnerContentType",
"HashEncryptionAlgorithm", "pvHashEncryptionAuxInfo"})
public static class CRYPT_SIGN_MESSAGE_PARA extends Structure {
public static class ByReference extends CRYPT_SIGN_MESSAGE_PARA implements Structure.ByReference {
}
public int cbSize;
public int dwMsgEncodingType;
public CERT_CONTEXT.ByReference pSigningCert;
public CRYPT_ALGORITHM_IDENTIFIER HashAlgorithm;
public Pointer pvHashAuxInfo;
public int cMsgCert;
public Pointer rgpMsgCert = null;
public int cMsgCrl;
public Pointer rgpMsgCrl = null;
public int cAuthAttr;
public Pointer rgAuthAttr = null;
public int cUnauthAttr;
public Pointer rgUnauthAttr = null;
public int dwFlags;
public int dwInnerContentType;
public CRYPT_ALGORITHM_IDENTIFIER HashEncryptionAlgorithm;
public Pointer pvHashEncryptionAuxInfo;
public CERT_CONTEXT[] getRgpMsgCert() {
CERT_CONTEXT[] elements = new CERT_CONTEXT[cMsgCrl];
for (int i = 0; i < elements.length; i++) {
elements[i] = Structure.newInstance(
CERT_CONTEXT.class,
rgpMsgCert.getPointer(i * Native.POINTER_SIZE));
elements[i].read();
}
return elements;
}
public CRL_CONTEXT[] getRgpMsgCrl() {
CRL_CONTEXT[] elements = new CRL_CONTEXT[cMsgCrl];
for (int i = 0; i < elements.length; i++) {
elements[i] = Structure.newInstance(
CRL_CONTEXT.class,
rgpMsgCrl.getPointer(i * Native.POINTER_SIZE));
elements[i].read();
}
return elements;
}
public CRYPT_ATTRIBUTE[] getRgAuthAttr() {
if (cAuthAttr == 0) {