1 /*
2     libpe - the PE library
3 
4     Copyright (C) 2010 - 2015 libpe authors
5 
6     This file is part of libpe.
7 
8     libpe is free software: you can redistribute it and/or modify
9     it under the terms of the GNU Lesser General Public License as published by
10     the Free Software Foundation, either version 3 of the License, or
11     (at your option) any later version.
12 
13     libpe is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU Lesser General Public License for more details.
17 
18     You should have received a copy of the GNU Lesser General Public License
19     along with libpe.  If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #ifndef LIBPE_DIR_SECURITY_H
23 #define LIBPE_DIR_SECURITY_H
24 
25 #include <inttypes.h>
26 
27 #define ANYSIZE_ARRAY 1
28 
29 // #define WIN_TRUST_MAJOR_REVISION_MASK	0xFFFF0000
30 // #define WIN_TRUST_MINOR_REVISION_MASK	0x0000FFFF
31 // #define WIN_TRUST_REVISION_1_0			0x00010000
32 
33 typedef enum {
34 	// Version 1, legacy version of the Win_Certificate
35 	// structure. It is supported only for purposes of
36 	// verifying legacy Authenticode signatures
37 	WIN_CERT_REVISION_1_0 = 0x0100,
38 	// Version 2 is the current version of the Win_Certificate structure.
39 	WIN_CERT_REVISION_2_0 = 0x0200
40 } CertRevision;
41 
42 typedef enum {
43 	WIN_CERT_TYPE_X509				= 0x0001, // bCertificate contains an X.509 (Certificate)
44 	WIN_CERT_TYPE_PKCS_SIGNED_DATA	= 0x0002, // bCertificate contains a PKCS#7 (SignedData structure)
45 	WIN_CERT_TYPE_RESERVED_1		= 0x0003, // Reserved
46 	WIN_CERT_TYPE_TS_STACK_SIGNED	= 0x0004, // Terminal Server Protocol Stack (Certificate signing)
47 	WIN_CERT_TYPE_EFI_PKCS115		= 0x0EF0,
48 	WIN_CERT_TYPE_EFI_GUID			= 0x0EF1
49 } CertType;
50 
51 #pragma pack(push, 4)
52 
53 // Originally declared in Wintrust.h
54 typedef struct {
55 	// Specified the size, in bytes, of the WIN_CERTIFICATE structure,
56 	// including the data in bCertificate.
57 	uint32_t dwLength;
58 	// Indicates the revision of the structure.
59 	uint16_t wRevision;
60 	// Specifies the type of certificate.
61 	// This member can be one of the following values:
62 	//   Value								Meaning
63 	//   ----------------------------------------------------------------------------------------
64 	//   WIN_CERT_TYPE_X509 				The certificate contains an X.509 Certificate.
65 	//   WIN_CERT_TYPE_PKCS_SIGNED_DATA		The certificate contains a PKCS SignedData structure.
66 	//   WIN_CERT_TYPE_RESERVED_1			Reserved.
67 	//	 WIN_CERT_TYPE_TS_STACK_SIGNED
68 	uint16_t wCertificateType;
69 	// A variable-sized array of bytes that contains the certificate data.
70 	uint8_t bCertificate[ANYSIZE_ARRAY];
71 } WIN_CERTIFICATE;
72 
73 typedef struct {
74 	uint32_t cbData;
75 	uint8_t *pbData;
76 } CRYPT_DATA_BLOB;
77 
78 #pragma pack(pop)
79 
80 #endif
81