@@ -87,6 +87,13 @@ static const se_owner_epoch_t SIMU_OWNER_EPOCH_MSR = {
87
87
} \
88
88
} while (0 )
89
89
90
+ #define check_config_svn (kr, secs ) do { \
91
+ if (kr->config_svn > secs->config_svn ) { \
92
+ return EGETKEY_INVALID_ISVSVN; \
93
+ } \
94
+ } while (0 )
95
+
96
+ #define KEY_POLICY_KSS (SGX_KEYPOLICY_CONFIGID | SGX_KEYPOLICY_ISVFAMILYID | SGX_KEYPOLICY_ISVEXTPRODID)
90
97
91
98
// The hardware EGETKEY instruction will set ZF on failure.
92
99
//
@@ -112,7 +119,7 @@ static int _EGETKEY(sgx_key_request_t* kr, sgx_key_128bit_t okey)
112
119
GP_ON (!sgx_is_within_enclave (okey, sizeof (sgx_key_128bit_t )));
113
120
114
121
// check reserved bits are not set
115
- GP_ON ((kr->key_policy & ~(SGX_KEYPOLICY_MRENCLAVE | SGX_KEYPOLICY_MRSIGNER)) != 0 );
122
+ GP_ON ((kr->key_policy & ~(SGX_KEYPOLICY_MRENCLAVE | SGX_KEYPOLICY_MRSIGNER | KEY_POLICY_KSS | SGX_KEYPOLICY_NOISVPRODID )) != 0 );
116
123
117
124
// check to see if reserved space in KEYREQUEST are valid
118
125
const uint8_t * u8ptr = (uint8_t *)(&(kr->reserved1 ));
@@ -124,7 +131,13 @@ static int _EGETKEY(sgx_key_request_t* kr, sgx_key_128bit_t okey)
124
131
GP_ON (u8ptr[i] != (uint8_t )0 );
125
132
126
133
secs_t * cur_secs = g_global_data_sim.secs_ptr ;
134
+ isv_ext_id_t * isv_ext_id = reinterpret_cast <isv_ext_id_t *>(cur_secs->reserved4 );
135
+
136
+ GP_ON (!(cur_secs->attributes .flags & SGX_FLAGS_KSS) &&
137
+ ((kr->key_policy & (KEY_POLICY_KSS | SGX_KEYPOLICY_NOISVPRODID)) ||kr->config_svn > 0 ));
138
+
127
139
sgx_attributes_t tmp_attr;
140
+ sgx_misc_select_t tmp_misc;
128
141
derivation_data_t dd;
129
142
130
143
memset (&dd, 0 , sizeof (dd));
@@ -136,6 +149,8 @@ static int _EGETKEY(sgx_key_request_t* kr, sgx_key_128bit_t okey)
136
149
tmp_attr.flags = kr->attribute_mask .flags | SGX_FLAGS_INITTED | SGX_FLAGS_DEBUG;
137
150
tmp_attr.flags &= cur_secs->attributes .flags ;
138
151
tmp_attr.xfrm = kr->attribute_mask .xfrm & cur_secs->attributes .xfrm ;
152
+ // Compute MISCSELECT fields to be included in the key.
153
+ tmp_misc = kr->misc_mask & cur_secs->misc_select ;
139
154
// HW supports CPUSVN to be set as 0.
140
155
// To be consistent with HW behaviour, we replace the cpusvn as DEFAULT_CPUSVN if the input cpusvn is 0.
141
156
if (!memcmp (&kr->cpu_svn , &dd.ddpk .cpu_svn , sizeof (sgx_cpu_svn_t )))
@@ -146,10 +161,12 @@ static int _EGETKEY(sgx_key_request_t* kr, sgx_key_128bit_t okey)
146
161
switch (kr->key_name ) {
147
162
case SGX_KEYSELECT_SEAL:
148
163
check_isv_svn (kr, cur_secs);
164
+ check_config_svn (kr, cur_secs);
149
165
check_cpu_svn (kr);
150
166
151
167
// assemble derivation data
152
168
dd.size = sizeof (dd_seal_key_t );
169
+ dd.ddsk .key_policy = kr->key_policy ;
153
170
if (kr->key_policy & SGX_KEYPOLICY_MRENCLAVE) {
154
171
memcpy (&dd.ddsk .mrenclave , &cur_secs->mr_enclave , sizeof (sgx_measurement_t ));
155
172
}
@@ -158,22 +175,42 @@ static int _EGETKEY(sgx_key_request_t* kr, sgx_key_128bit_t okey)
158
175
memcpy (&dd.ddsk .mrsigner , &cur_secs->mr_signer , sizeof (sgx_measurement_t ));
159
176
}
160
177
178
+ if (kr->key_policy & SGX_KEYPOLICY_ISVFAMILYID) {
179
+ memcpy (&dd.ddsk .isv_family_id , &isv_ext_id->isv_family_id , sizeof (sgx_isvfamily_id_t ));
180
+ }
181
+
182
+ if (kr->key_policy & SGX_KEYPOLICY_ISVEXTPRODID) {
183
+ memcpy (&dd.ddsk .isv_ext_prod_id , &isv_ext_id->isv_ext_prod_id , sizeof (sgx_isvext_prod_id_t ));
184
+ }
185
+
186
+ if (kr->key_policy & SGX_KEYPOLICY_CONFIGID) {
187
+ dd.ddsk .config_svn = kr->config_svn ;
188
+ memcpy (&dd.ddsk .config_id , &cur_secs->config_id , sizeof (sgx_config_id_t ));
189
+ }
190
+
161
191
memcpy (&dd.ddsk .tmp_attr , &tmp_attr, sizeof (sgx_attributes_t ));
162
192
memcpy (&dd.ddsk .attribute_mask , &kr->attribute_mask , sizeof (sgx_attributes_t ));
193
+ dd.ddsk .tmp_misc = tmp_misc;
194
+ dd.ddsk .misc_mask = ~kr->misc_mask ;
163
195
memcpy (dd.ddsk .csr_owner_epoch , SIMU_OWNER_EPOCH_MSR, sizeof (se_owner_epoch_t ));
164
196
memcpy (&dd.ddsk .cpu_svn ,&kr->cpu_svn ,sizeof (sgx_cpu_svn_t ));
165
197
dd.ddsk .isv_svn = kr->isv_svn ;
166
- dd.ddsk .isv_prod_id = cur_secs->isv_prod_id ;
198
+ if (!(kr->key_policy & SGX_KEYPOLICY_NOISVPRODID)) {
199
+ dd.ddsk .isv_prod_id = cur_secs->isv_prod_id ;
200
+ }
167
201
memcpy (&dd.ddsk .key_id , &kr->key_id , sizeof (sgx_key_id_t ));
168
202
break ;
169
203
170
204
case SGX_KEYSELECT_REPORT:
171
205
// assemble derivation data
172
206
dd.size = sizeof (dd_report_key_t );
173
207
memcpy (&dd.ddrk .attributes , &cur_secs->attributes , sizeof (sgx_attributes_t ));
208
+ dd.ddrk .misc_select = cur_secs->misc_select ;
174
209
memcpy (dd.ddrk .csr_owner_epoch , SIMU_OWNER_EPOCH_MSR, sizeof (se_owner_epoch_t ));
175
210
memcpy (&dd.ddrk .cpu_svn ,&(g_global_data_sim.cpusvn_sim ),sizeof (sgx_cpu_svn_t ));
176
211
memcpy (&dd.ddrk .mrenclave , &cur_secs->mr_enclave , sizeof (sgx_measurement_t ));
212
+ dd.ddrk .config_svn = cur_secs->config_svn ;
213
+ memcpy (&dd.ddrk .config_id , &cur_secs->config_id , sizeof (sgx_config_id_t ));
177
214
memcpy (&dd.ddrk .key_id , &kr->key_id , sizeof (sgx_key_id_t ));
178
215
break ;
179
216
@@ -184,16 +221,17 @@ static int _EGETKEY(sgx_key_request_t* kr, sgx_key_128bit_t okey)
184
221
185
222
// assemble derivation data
186
223
dd.size = sizeof (dd_license_key_t );
187
- memcpy (&dd.ddlk .attributes , &cur_secs->attributes , sizeof (sgx_attributes_t ));
224
+ memcpy (&dd.ddlk .tmp_attr , &tmp_attr, sizeof (sgx_attributes_t ));
225
+ dd.ddlk .tmp_misc = tmp_misc;
188
226
memcpy (dd.ddlk .csr_owner_epoch , SIMU_OWNER_EPOCH_MSR, sizeof (se_owner_epoch_t ));
189
227
memcpy (&dd.ddlk .cpu_svn ,&kr->cpu_svn ,sizeof (sgx_cpu_svn_t ));
190
228
dd.ddlk .isv_svn = kr->isv_svn ;
191
229
dd.ddlk .isv_prod_id = cur_secs->isv_prod_id ;
230
+ memcpy (&dd.ddlk .mrsigner , &cur_secs->mr_signer , sizeof (sgx_measurement_t ));
192
231
memcpy (&dd.ddlk .key_id , &kr->key_id , sizeof (sgx_key_id_t ));
193
232
break ;
194
233
195
- case SGX_KEYSELECT_PROVISION: // Pass through. Only key_name differs.
196
- case SGX_KEYSELECT_PROVISION_SEAL:
234
+ case SGX_KEYSELECT_PROVISION:
197
235
check_attr_flag (cur_secs, SGX_FLAGS_PROVISION_KEY);
198
236
check_isv_svn (kr, cur_secs);
199
237
check_cpu_svn (kr);
@@ -202,11 +240,46 @@ static int _EGETKEY(sgx_key_request_t* kr, sgx_key_128bit_t okey)
202
240
dd.size = sizeof (dd_provision_key_t );
203
241
memcpy (&dd.ddpk .tmp_attr , &tmp_attr, sizeof (sgx_attributes_t ));
204
242
memcpy (&dd.ddpk .attribute_mask , &kr->attribute_mask , sizeof (sgx_attributes_t ));
243
+ dd.ddpk .tmp_misc = tmp_misc;
244
+ dd.ddpk .misc_mask = ~kr->misc_mask ;
205
245
memcpy (&dd.ddpk .cpu_svn ,&kr->cpu_svn ,sizeof (sgx_cpu_svn_t ));
206
246
dd.ddpk .isv_svn = kr->isv_svn ;
207
247
dd.ddpk .isv_prod_id = cur_secs->isv_prod_id ;
208
248
memcpy (&dd.ddpk .mrsigner , &cur_secs->mr_signer , sizeof (sgx_measurement_t ));
209
249
break ;
250
+ case SGX_KEYSELECT_PROVISION_SEAL:
251
+ check_attr_flag (cur_secs, SGX_FLAGS_PROVISION_KEY);
252
+ check_isv_svn (kr, cur_secs);
253
+ check_config_svn (kr, cur_secs);
254
+ check_cpu_svn (kr);
255
+
256
+ // assemble derivation data
257
+ dd.size = sizeof (dd_provision_seal_key_t );
258
+ dd.ddpsk .key_policy = kr->key_policy ;
259
+ if (kr->key_policy & SGX_KEYPOLICY_ISVFAMILYID) {
260
+ memcpy (&dd.ddpsk .isv_family_id , &isv_ext_id->isv_family_id , sizeof (sgx_isvfamily_id_t ));
261
+ }
262
+
263
+ if (kr->key_policy & SGX_KEYPOLICY_ISVEXTPRODID) {
264
+ memcpy (&dd.ddpsk .isv_ext_prod_id , &isv_ext_id->isv_ext_prod_id , sizeof (sgx_isvext_prod_id_t ));
265
+ }
266
+
267
+ if (kr->key_policy & SGX_KEYPOLICY_CONFIGID) {
268
+ dd.ddpsk .config_svn = kr->config_svn ;
269
+ memcpy (&dd.ddpsk .config_id , &cur_secs->config_id , sizeof (sgx_config_id_t ));
270
+ }
271
+
272
+ memcpy (&dd.ddpsk .tmp_attr , &tmp_attr, sizeof (sgx_attributes_t ));
273
+ memcpy (&dd.ddpsk .attribute_mask , &kr->attribute_mask , sizeof (sgx_attributes_t ));
274
+ dd.ddpsk .tmp_misc = tmp_misc;
275
+ dd.ddpsk .misc_mask = ~kr->misc_mask ;
276
+ memcpy (&dd.ddpsk .cpu_svn ,&kr->cpu_svn ,sizeof (sgx_cpu_svn_t ));
277
+ dd.ddpsk .isv_svn = kr->isv_svn ;
278
+ if (!(kr->key_policy & SGX_KEYPOLICY_NOISVPRODID)) {
279
+ dd.ddpsk .isv_prod_id = cur_secs->isv_prod_id ;
280
+ }
281
+ memcpy (&dd.ddpsk .mrsigner , &cur_secs->mr_signer , sizeof (sgx_measurement_t ));
282
+ break ;
210
283
211
284
default :
212
285
return EGETKEY_INVALID_KEYNAME;
@@ -241,13 +314,19 @@ static void _EREPORT(const sgx_target_info_t* ti, const sgx_report_data_t* rd, s
241
314
GP_ON (!sgx_is_within_enclave (report, sizeof (sgx_report_t )));
242
315
243
316
secs_t * cur_secs = g_global_data_sim.secs_ptr ;
317
+ isv_ext_id_t * isv_ext_id = reinterpret_cast <isv_ext_id_t *>(cur_secs->reserved4 );
244
318
SE_DECLSPEC_ALIGN (REPORT_ALIGN_SIZE) sgx_report_t tmp_report;
245
319
246
320
// assemble REPORT Data
247
321
memset (&tmp_report, 0 , sizeof (tmp_report));
248
322
memcpy (&tmp_report.body .cpu_svn ,&(g_global_data_sim.cpusvn_sim ),sizeof (sgx_cpu_svn_t ));
323
+ tmp_report.body .misc_select = cur_secs->misc_select ;
249
324
tmp_report.body .isv_prod_id = cur_secs->isv_prod_id ;
250
325
tmp_report.body .isv_svn = cur_secs->isv_svn ;
326
+ tmp_report.body .config_svn = cur_secs->config_svn ;
327
+ memcpy (&tmp_report.body .isv_family_id , &isv_ext_id->isv_family_id , sizeof (sgx_isvfamily_id_t ));
328
+ memcpy (&tmp_report.body .isv_ext_prod_id , &isv_ext_id->isv_ext_prod_id , sizeof (sgx_isvext_prod_id_t ));
329
+ memcpy (&tmp_report.body .config_id , &cur_secs->config_id , sizeof (sgx_config_id_t ));
251
330
memcpy (&tmp_report.body .attributes , &cur_secs->attributes , sizeof (sgx_attributes_t ));
252
331
memcpy (&tmp_report.body .report_data , rd, sizeof (sgx_report_data_t ));
253
332
memcpy (&tmp_report.body .mr_enclave , &cur_secs->mr_enclave , sizeof (sgx_measurement_t ));
@@ -265,6 +344,9 @@ static void _EREPORT(const sgx_target_info_t* ti, const sgx_report_data_t* rd, s
265
344
memcpy (dd.ddrk .csr_owner_epoch , SIMU_OWNER_EPOCH_MSR, sizeof (se_owner_epoch_t ));
266
345
memcpy (&dd.ddrk .cpu_svn ,&(g_global_data_sim.cpusvn_sim ),sizeof (sgx_cpu_svn_t ));
267
346
memcpy (&dd.ddrk .key_id , &tmp_report.key_id , sizeof (sgx_key_id_t ));
347
+ memcpy (&dd.ddrk .config_id , &ti->config_id , sizeof (sgx_config_id_t ));
348
+ dd.ddrk .config_svn = ti->config_svn ;
349
+ dd.ddrk .misc_select = ti->misc_select ;
268
350
269
351
// calculate the derived key
270
352
sgx_key_128bit_t tmp_report_key;
0 commit comments