summaryrefslogtreecommitdiffstats
path: root/src/VBox/Runtime/common/crypto/spc-template.h
blob: 510b66a68eeca329919caf6ac6177cf5f43ff5a3 (plain)
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
/* $Id: spc-template.h $ */
/** @file
 * IPRT - Crypto - Microsoft SPC / Authenticode, Code Generator Template.
 */

/*
 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
 *
 * This file is part of VirtualBox base platform packages, as
 * available from https://www.virtualbox.org.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation, in version 3 of the
 * License.
 *
 * This program 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
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <https://www.gnu.org/licenses>.
 *
 * The contents of this file may alternatively be used under the terms
 * of the Common Development and Distribution License Version 1.0
 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
 * in the VirtualBox distribution, in which case the provisions of the
 * CDDL are applicable instead of those of the GPL.
 *
 * You may elect to license modified versions of this file under the
 * terms and conditions of either the GPL or the CDDL or both.
 *
 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
 */

#define RTASN1TMPL_DECL         RTDECL


/*
 * One SPC Serialized Page Hashes V2 Object.
 */
#define RTASN1TMPL_TYPE         RTCRSPCSERIALIZEDPAGEHASHES
#define RTASN1TMPL_EXT_NAME     RTCrSpcSerializedPageHashes
#define RTASN1TMPL_INT_NAME     rtCrSpcSerializedPageHashes
RTASN1TMPL_BEGIN_SETCORE();
RTASN1TMPL_MEMBER(              RawData,               RTASN1OCTETSTRING,           RTAsn1OctetString);
RTASN1TMPL_EXEC_DECODE(         rc = RTCrSpcSerializedPageHashes_UpdateDerivedData(pThis) ) /* no ; */
RTASN1TMPL_EXEC_CLONE(          rc = RTCrSpcSerializedPageHashes_UpdateDerivedData(pThis) ) /* no ; */
RTASN1TMPL_END_SETCORE();
#undef RTASN1TMPL_TYPE
#undef RTASN1TMPL_EXT_NAME
#undef RTASN1TMPL_INT_NAME


/*
 * One SPC Serialized Object Attribute.
 */
#define RTASN1TMPL_TYPE         RTCRSPCSERIALIZEDOBJECTATTRIBUTE
#define RTASN1TMPL_EXT_NAME     RTCrSpcSerializedObjectAttribute
#define RTASN1TMPL_INT_NAME     rtCrSpcSerializedObjectAttribute
RTASN1TMPL_BEGIN_SEQCORE();
RTASN1TMPL_MEMBER(              Type,               RTASN1OBJID,                    RTAsn1ObjId);
RTASN1TMPL_MEMBER_DYN_BEGIN(    Type, RTCRSPCSERIALIZEDOBJECTATTRIBUTETYPE, enmType, Allocation);
RTASN1TMPL_MEMBER_DYN(          u, pPageHashes, V1Hashes,   RTCRSPCSERIALIZEDPAGEHASHES, RTCrSpcSerializedPageHashes, Allocation,
    Type, enmType, RTCRSPCSERIALIZEDOBJECTATTRIBUTETYPE_PAGE_HASHES_V1, RTCRSPC_PE_IMAGE_HASHES_V1_OID);
RTASN1TMPL_MEMBER_DYN(          u, pPageHashes, V2Hashes,   RTCRSPCSERIALIZEDPAGEHASHES, RTCrSpcSerializedPageHashes, Allocation,
    Type, enmType, RTCRSPCSERIALIZEDOBJECTATTRIBUTETYPE_PAGE_HASHES_V2, RTCRSPC_PE_IMAGE_HASHES_V2_OID);
RTASN1TMPL_MEMBER_DYN_DEFAULT(  u, pCore,                   RTASN1CORE, RTAsn1Core, Allocation,
    Type, enmType, RTCRSPCSERIALIZEDOBJECTATTRIBUTETYPE_UNKNOWN);
RTASN1TMPL_MEMBER_DYN_END(      Type, RTCRSPCSERIALIZEDOBJECTATTRIBUTETYPE, enmType, Allocation);
RTASN1TMPL_END_SEQCORE();
#undef RTASN1TMPL_TYPE
#undef RTASN1TMPL_EXT_NAME
#undef RTASN1TMPL_INT_NAME

/*
 * Set of SPC Serialized Object Attributes.
 */
#define RTASN1TMPL_TYPE         RTCRSPCSERIALIZEDOBJECTATTRIBUTES
#define RTASN1TMPL_EXT_NAME     RTCrSpcSerializedObjectAttributes
#define RTASN1TMPL_INT_NAME     rtCrSpcSerializedObjectAttributes
RTASN1TMPL_SET_OF(RTCRSPCSERIALIZEDOBJECTATTRIBUTE, RTCrSpcSerializedObjectAttribute);
#undef RTASN1TMPL_TYPE
#undef RTASN1TMPL_EXT_NAME
#undef RTASN1TMPL_INT_NAME


/*
 * One SPC Serialized Object.
 */
#define RTASN1TMPL_TYPE         RTCRSPCSERIALIZEDOBJECT
#define RTASN1TMPL_EXT_NAME     RTCrSpcSerializedObject
#define RTASN1TMPL_INT_NAME     rtCrSpcSerializedObject
RTASN1TMPL_BEGIN_SEQCORE();
RTASN1TMPL_MEMBER_EX(           Uuid,               RTASN1OCTETSTRING,              RTAsn1OctetString,
                                RTASN1TMPL_MEMBER_CONSTR_MIN_MAX(Uuid, RTASN1OCTETSTRING, RTAsn1OctetString, 16, 16, RT_NOTHING));
RTASN1TMPL_MEMBER(              SerializedData,     RTASN1OCTETSTRING,              RTAsn1OctetString);
RTASN1TMPL_EXEC_DECODE(         rc = rtCrSpcSerializedObject_DecodeMore(pCursor, fFlags, pThis, pszErrorTag) ) /* no ; */
RTASN1TMPL_END_SEQCORE();
#undef RTASN1TMPL_TYPE
#undef RTASN1TMPL_EXT_NAME
#undef RTASN1TMPL_INT_NAME


/*
 * Choosy SPC strings.
 */
#define RTASN1TMPL_TYPE         RTCRSPCSTRING
#define RTASN1TMPL_EXT_NAME     RTCrSpcString
#define RTASN1TMPL_INT_NAME     rtCrSpcString
RTASN1TMPL_BEGIN_PCHOICE();
RTASN1TMPL_PCHOICE_ITAG_CP(     0, RTCRSPCSTRINGCHOICE_UCS2,     u.pUcs2,   Ucs2,   RTASN1STRING, RTAsn1BmpString);
RTASN1TMPL_PCHOICE_ITAG_CP(     1, RTCRSPCSTRINGCHOICE_ASCII,    u.pAscii,  Ascii,  RTASN1STRING, RTAsn1Ia5String);
RTASN1TMPL_END_PCHOICE();
#undef RTASN1TMPL_TYPE
#undef RTASN1TMPL_EXT_NAME
#undef RTASN1TMPL_INT_NAME


/*
 * SPC Link.
 */
#define RTASN1TMPL_TYPE         RTCRSPCLINK
#define RTASN1TMPL_EXT_NAME     RTCrSpcLink
#define RTASN1TMPL_INT_NAME     rtCrSpcLink
RTASN1TMPL_BEGIN_PCHOICE();
RTASN1TMPL_PCHOICE_ITAG_CP(     0, RTCRSPCLINKCHOICE_URL,     u.pUrl,     Url,      RTASN1STRING,            RTAsn1Ia5String);
RTASN1TMPL_PCHOICE_ITAG(        1, RTCRSPCLINKCHOICE_MONIKER, u.pMoniker, Moniker,  RTCRSPCSERIALIZEDOBJECT, RTCrSpcSerializedObject);
RTASN1TMPL_PCHOICE_XTAG(        2, RTCRSPCLINKCHOICE_FILE,    u.pT2, CtxTag2, File, RTCRSPCSTRING,           RTCrSpcString);
RTASN1TMPL_END_PCHOICE();
#undef RTASN1TMPL_TYPE
#undef RTASN1TMPL_EXT_NAME
#undef RTASN1TMPL_INT_NAME


/*
 * SPC PE Image Data.
 *
 * Note! This is not correctly declared in available specifications. The file
 *       member is tagged.  Seeing the '--#public--' comment in the specs,
 *       one can't only guess that there are other alternatives in that part
 *       of the structure that microsoft does not wish to document.
 */
#define RTASN1TMPL_TYPE         RTCRSPCPEIMAGEDATA
#define RTASN1TMPL_EXT_NAME     RTCrSpcPeImageData
#define RTASN1TMPL_INT_NAME     rtCrSpcPeImageData
RTASN1TMPL_BEGIN_SEQCORE();
/** @todo The flags defaults to includeResources. Could be expressed here rather
 *        than left to the user to deal with. */
RTASN1TMPL_MEMBER_OPT_ITAG_EX(  Flags,              RTASN1BITSTRING, RTAsn1BitString, ASN1_TAG_BIT_STRING, RTASN1TMPL_ITAG_F_UP,
                                RTASN1TMPL_MEMBER_CONSTR_BITSTRING_MIN_MAX(Flags, 0, 3, RT_NOTHING));
RTASN1TMPL_MEMBER_OPT_XTAG_EX(  T0, CtxTag0, File,  RTCRSPCLINK,     RTCrSpcLink, 0, \
                                RTASN1TMPL_MEMBER_CONSTR_PRESENT(T0.File, RTCrSpcLink, RT_NOTHING));
RTASN1TMPL_END_SEQCORE();
#undef RTASN1TMPL_TYPE
#undef RTASN1TMPL_EXT_NAME
#undef RTASN1TMPL_INT_NAME


/*
 * SPC Attribute Type And Optional Value.
 *
 * Note! The value doesn't look very optional in available examples and specs.
 *       The available specs also claim there is an explicit 0 tag around the
 *       data, which isn't there is in signed executables.  Gotta love Microsoft...
 */
#define RTASN1TMPL_TYPE         RTCRSPCATTRIBUTETYPEANDOPTIONALVALUE
#define RTASN1TMPL_EXT_NAME     RTCrSpcAttributeTypeAndOptionalValue
#define RTASN1TMPL_INT_NAME     rtCrSpcAttributeTypeAndOptionalValue
RTASN1TMPL_BEGIN_SEQCORE();
RTASN1TMPL_MEMBER(              Type,               RTASN1OBJID,                    RTAsn1ObjId);
RTASN1TMPL_MEMBER_DYN_BEGIN(    Type, RTCRSPCAAOVTYPE, enmType, Allocation);
RTASN1TMPL_MEMBER_DYN(          uValue, pPeImage, PeImage, RTCRSPCPEIMAGEDATA, RTCrSpcPeImageData, Allocation,
    Type, enmType, RTCRSPCAAOVTYPE_PE_IMAGE_DATA, RTCRSPCPEIMAGEDATA_OID);
RTASN1TMPL_MEMBER_DYN_DEFAULT(  uValue, pCore,             RTASN1CORE,         RTAsn1Core, Allocation,
    Type, enmType, RTCRSPCAAOVTYPE_UNKNOWN);
RTASN1TMPL_MEMBER_DYN_END(      Type, RTCRSPCAAOVTYPE, enmType, Allocation);
RTASN1TMPL_END_SEQCORE();
#undef RTASN1TMPL_TYPE
#undef RTASN1TMPL_EXT_NAME
#undef RTASN1TMPL_INT_NAME


/*
 * SPC Indirect Data Content.
 */
#define RTASN1TMPL_TYPE         RTCRSPCINDIRECTDATACONTENT
#define RTASN1TMPL_EXT_NAME     RTCrSpcIndirectDataContent
#define RTASN1TMPL_INT_NAME     rtCrSpcIndirectDataContent
RTASN1TMPL_BEGIN_SEQCORE();
RTASN1TMPL_MEMBER(              Data,               RTCRSPCATTRIBUTETYPEANDOPTIONALVALUE,  RTCrSpcAttributeTypeAndOptionalValue);
RTASN1TMPL_MEMBER(              DigestInfo,         RTCRPKCS7DIGESTINFO,                   RTCrPkcs7DigestInfo);
RTASN1TMPL_END_SEQCORE();
#undef RTASN1TMPL_TYPE
#undef RTASN1TMPL_EXT_NAME
#undef RTASN1TMPL_INT_NAME