1 
2 /*
3  * Licensed Materials - Property of IBM
4  *
5  * trousers - An open source TCG Software Stack
6  *
7  * (C) Copyright International Business Machines Corp. 2004-2007
8  *
9  */
10 
11 
12 #include <stdlib.h>
13 #include <stdio.h>
14 #include <string.h>
15 #include <time.h>
16 #include <errno.h>
17 
18 #include "trousers/tss.h"
19 #include "trousers/trousers.h"
20 #include "trousers_types.h"
21 #include "trousers_types.h"
22 #include "spi_utils.h"
23 #include "capabilities.h"
24 #include "tsplog.h"
25 #include "obj.h"
26 #include "tsp_audit.h"
27 
28 
29 TSS_RESULT
Tspi_SetAttribUint32(TSS_HOBJECT hObject,TSS_FLAG attribFlag,TSS_FLAG subFlag,UINT32 ulAttrib)30 Tspi_SetAttribUint32(TSS_HOBJECT hObject,	/* in */
31 		     TSS_FLAG attribFlag,	/* in */
32 		     TSS_FLAG subFlag,		/* in */
33 		     UINT32 ulAttrib)		/* in */
34 {
35 	TSS_RESULT result;
36 
37 	if (obj_is_rsakey(hObject)) {
38 #ifdef TSS_BUILD_RSAKEY_LIST
39 		if (attribFlag == TSS_TSPATTRIB_KEY_REGISTER) {
40 			if (subFlag)
41 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
42 
43 			if (ulAttrib == TSS_TSPATTRIB_KEYREGISTER_USER)
44 				result = obj_rsakey_set_pstype(hObject, TSS_PS_TYPE_USER);
45 			else if (ulAttrib == TSS_TSPATTRIB_KEYREGISTER_SYSTEM)
46 				result = obj_rsakey_set_pstype(hObject, TSS_PS_TYPE_SYSTEM);
47 			else if (ulAttrib == TSS_TSPATTRIB_KEYREGISTER_NO)
48 				result = obj_rsakey_set_pstype(hObject, TSS_PS_TYPE_NO);
49 			else
50 				return TSPERR(TSS_E_INVALID_ATTRIB_DATA);
51 		} else if (attribFlag == TSS_TSPATTRIB_KEY_INFO) {
52 			switch (subFlag) {
53 				case TSS_TSPATTRIB_KEYINFO_USAGE:
54 					result = obj_rsakey_set_usage(hObject, ulAttrib);
55 					break;
56 				case TSS_TSPATTRIB_KEYINFO_MIGRATABLE:
57 					if (ulAttrib != TRUE && ulAttrib != FALSE)
58 						return TSPERR(TSS_E_INVALID_ATTRIB_DATA);
59 
60 					result = obj_rsakey_set_migratable(hObject, ulAttrib);
61 					break;
62 				case TSS_TSPATTRIB_KEYINFO_REDIRECTED:
63 					if (ulAttrib != TRUE && ulAttrib != FALSE)
64 						return TSPERR(TSS_E_INVALID_ATTRIB_DATA);
65 
66 					result = obj_rsakey_set_redirected(hObject, ulAttrib);
67 					break;
68 				case TSS_TSPATTRIB_KEYINFO_VOLATILE:
69 					if (ulAttrib != TRUE && ulAttrib != FALSE)
70 						return TSPERR(TSS_E_INVALID_ATTRIB_DATA);
71 
72 					result = obj_rsakey_set_volatile(hObject, ulAttrib);
73 					break;
74 				case TSS_TSPATTRIB_KEYINFO_AUTHUSAGE:
75 					/* fall through */
76 				case TSS_TSPATTRIB_KEYINFO_AUTHDATAUSAGE:
77 					if (ulAttrib != TRUE && ulAttrib != FALSE)
78 						return TSPERR(TSS_E_INVALID_ATTRIB_DATA);
79 
80 					result = obj_rsakey_set_authdata_usage(hObject, ulAttrib);
81 					break;
82 				case TSS_TSPATTRIB_KEYINFO_ALGORITHM:
83 					result = obj_rsakey_set_alg(hObject, ulAttrib);
84 					break;
85 				case TSS_TSPATTRIB_KEYINFO_ENCSCHEME:
86 					if (ulAttrib != TSS_ES_NONE &&
87 					    ulAttrib != TSS_ES_RSAESPKCSV15 &&
88 					    ulAttrib != TSS_ES_RSAESOAEP_SHA1_MGF1)
89 						return TSPERR(TSS_E_INVALID_ATTRIB_DATA);
90 
91 					result = obj_rsakey_set_es(hObject, ulAttrib);
92 					break;
93 				case TSS_TSPATTRIB_KEYINFO_SIGSCHEME:
94 					if (ulAttrib != TSS_SS_NONE &&
95 					    ulAttrib != TSS_SS_RSASSAPKCS1V15_SHA1 &&
96 					    ulAttrib != TSS_SS_RSASSAPKCS1V15_DER  &&
97 					    ulAttrib !=	TSS_SS_RSASSAPKCS1V15_INFO)
98 						return TSPERR(TSS_E_INVALID_ATTRIB_DATA);
99 
100 					result = obj_rsakey_set_ss(hObject, ulAttrib);
101 					break;
102 				case TSS_TSPATTRIB_KEYINFO_KEYFLAGS:
103 					result = obj_rsakey_set_flags(hObject, ulAttrib);
104 					break;
105 				case TSS_TSPATTRIB_KEYINFO_SIZE:
106 					result = obj_rsakey_set_size(hObject, ulAttrib);
107 					break;
108 				default:
109 					return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
110 			}
111 		} else if (attribFlag == TSS_TSPATTRIB_RSAKEY_INFO) {
112 			if (subFlag == TSS_TSPATTRIB_KEYINFO_RSA_PRIMES) {
113 				result = obj_rsakey_set_num_primes(hObject, ulAttrib);
114 			} else
115 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
116 		} else
117 			return TSPERR(TSS_E_INVALID_ATTRIB_FLAG);
118 #endif
119 #ifdef TSS_BUILD_NV
120 	} else if (obj_is_nvstore(hObject)) {
121 		switch (attribFlag) {
122 			case TSS_TSPATTRIB_NV_INDEX:
123 				if ((result = obj_nvstore_set_index(hObject, ulAttrib)))
124 					return result;
125 				break;
126 			case TSS_TSPATTRIB_NV_DATASIZE:
127 				if ((result = obj_nvstore_set_datasize(hObject, ulAttrib)))
128 					return result;
129 				break;
130 			case TSS_TSPATTRIB_NV_PERMISSIONS:
131 				if ((result = obj_nvstore_set_permission(hObject, ulAttrib)))
132 					return result;
133 				break;
134 			default:
135 				return TSPERR(TSS_E_INVALID_ATTRIB_FLAG);
136 				break;
137 		}
138 #endif
139 	} else if (obj_is_policy(hObject)) {
140 		switch (attribFlag) {
141 			case TSS_TSPATTRIB_POLICY_CALLBACK_HMAC:
142 			case TSS_TSPATTRIB_POLICY_CALLBACK_XOR_ENC:
143 			case TSS_TSPATTRIB_POLICY_CALLBACK_TAKEOWNERSHIP:
144 			case TSS_TSPATTRIB_POLICY_CALLBACK_CHANGEAUTHASYM:
145 				result = obj_policy_set_cb11(hObject, attribFlag,
146 							     subFlag, ulAttrib);
147 				break;
148 			case TSS_TSPATTRIB_POLICY_SECRET_LIFETIME:
149 				if (subFlag == TSS_TSPATTRIB_POLICYSECRET_LIFETIME_ALWAYS ||
150 				    subFlag == TSS_TSPATTRIB_POLICYSECRET_LIFETIME_COUNTER ||
151 				    subFlag == TSS_TSPATTRIB_POLICYSECRET_LIFETIME_TIMER) {
152 					result = obj_policy_set_lifetime(hObject, subFlag,
153 									 ulAttrib);
154 				} else {
155 					result = TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
156 				}
157 				break;
158 			case TSS_TSPATTRIB_SECRET_HASH_MODE:
159 				result = obj_policy_set_hash_mode(hObject, ulAttrib);
160 				break;
161 #ifdef TSS_BUILD_DELEGATION
162 			case TSS_TSPATTRIB_POLICY_DELEGATION_INFO:
163 				switch (subFlag) {
164 				case TSS_TSPATTRIB_POLDEL_TYPE:
165 					switch (ulAttrib) {
166 					case TSS_DELEGATIONTYPE_NONE:
167 					case TSS_DELEGATIONTYPE_OWNER:
168 					case TSS_DELEGATIONTYPE_KEY:
169 						result = obj_policy_set_delegation_type(hObject,
170 											ulAttrib);
171 						break;
172 					default:
173 						result = TSPERR(TSS_E_INVALID_ATTRIB_DATA);
174 					}
175 					break;
176 				case TSS_TSPATTRIB_POLDEL_INDEX:
177 					result = obj_policy_set_delegation_index(hObject, ulAttrib);
178 					break;
179 				case TSS_TSPATTRIB_POLDEL_PER1:
180 					result = obj_policy_set_delegation_per1(hObject, ulAttrib);
181 					break;
182 				case TSS_TSPATTRIB_POLDEL_PER2:
183 					result = obj_policy_set_delegation_per2(hObject, ulAttrib);
184 					break;
185 				default:
186 					result = TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
187 				}
188 				break;
189 #endif
190 			default:
191 				return TSPERR(TSS_E_INVALID_ATTRIB_FLAG);
192 				break;
193 		}
194 	} else if (obj_is_context(hObject)) {
195 		switch (attribFlag) {
196 			case TSS_TSPATTRIB_CONTEXT_SILENT_MODE:
197 				if (ulAttrib == TSS_TSPATTRIB_CONTEXT_NOT_SILENT)
198 					result = obj_context_set_mode(hObject, ulAttrib);
199 				else if (ulAttrib == TSS_TSPATTRIB_CONTEXT_SILENT) {
200 					if (obj_context_has_popups(hObject))
201 						return TSPERR(TSS_E_SILENT_CONTEXT);
202 					result = obj_context_set_mode(hObject, ulAttrib);
203 				} else
204 					return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
205 				break;
206 #ifdef TSS_BUILD_TRANSPORT
207 			case TSS_TSPATTRIB_CONTEXT_TRANSPORT:
208 				if (subFlag == TSS_TSPATTRIB_CONTEXTTRANS_CONTROL) {
209 					if (ulAttrib != TSS_TSPATTRIB_DISABLE_TRANSPORT &&
210 					    ulAttrib != TSS_TSPATTRIB_ENABLE_TRANSPORT)
211 						return TSPERR(TSS_E_INVALID_ATTRIB_DATA);
212 
213 					result = obj_context_transport_set_control(hObject,
214 										   ulAttrib);
215 				} else if (subFlag == TSS_TSPATTRIB_CONTEXTTRANS_MODE) {
216 					switch (ulAttrib) {
217 						case TSS_TSPATTRIB_TRANSPORT_NO_DEFAULT_ENCRYPTION:
218 						case TSS_TSPATTRIB_TRANSPORT_DEFAULT_ENCRYPTION:
219 						case TSS_TSPATTRIB_TRANSPORT_AUTHENTIC_CHANNEL:
220 						case TSS_TSPATTRIB_TRANSPORT_EXCLUSIVE:
221 						case TSS_TSPATTRIB_TRANSPORT_STATIC_AUTH:
222 							break;
223 						default:
224 							return TSPERR(TSS_E_INVALID_ATTRIB_DATA);
225 					}
226 
227 					result = obj_context_transport_set_mode(hObject, ulAttrib);
228 				} else
229 					return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
230 
231 				break;
232 #endif
233 			case TSS_TSPATTRIB_SECRET_HASH_MODE:
234 				result = obj_context_set_hash_mode(hObject, ulAttrib);
235 				break;
236 			default:
237 				return TSPERR(TSS_E_INVALID_ATTRIB_FLAG);
238 				break;
239 		}
240 	} else if (obj_is_tpm(hObject)) {
241 		switch (attribFlag) {
242 			case TSS_TSPATTRIB_TPM_CALLBACK_COLLATEIDENTITY:
243 			case TSS_TSPATTRIB_TPM_CALLBACK_ACTIVATEIDENTITY:
244 				if ((result = obj_tpm_set_cb11(hObject, attribFlag, subFlag,
245 							       ulAttrib)))
246 					return result;
247 				break;
248 #ifdef TSS_BUILD_AUDIT
249 			case TSS_TSPATTRIB_TPM_ORDINAL_AUDIT_STATUS:
250 				result = __tspi_audit_set_ordinal_audit_status(hObject, attribFlag,
251 									subFlag, ulAttrib);
252 				break;
253 #endif
254 			default:
255 				result = TSPERR(TSS_E_INVALID_ATTRIB_FLAG);
256 				break;
257 		}
258 #ifdef TSS_BUILD_SEALX
259 	} else if (obj_is_encdata(hObject)) {
260 		if (attribFlag != TSS_TSPATTRIB_ENCDATA_SEAL)
261 			return TSPERR(TSS_E_INVALID_ATTRIB_FLAG);
262 		if (subFlag == TSS_TSPATTRIB_ENCDATASEAL_PROTECT_MODE) {
263 			if (ulAttrib != TSS_TSPATTRIB_ENCDATASEAL_NO_PROTECT &&
264 			    ulAttrib != TSS_TSPATTRIB_ENCDATASEAL_PROTECT)
265 				return TSPERR(TSS_E_INVALID_ATTRIB_DATA);
266 
267 			result = obj_encdata_set_seal_protect_mode(hObject, ulAttrib);
268 		} else
269 			return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
270 #endif
271 #ifdef TSS_BUILD_DELEGATION
272 	} else if (obj_is_delfamily(hObject)) {
273 		switch (attribFlag) {
274 		case TSS_TSPATTRIB_DELFAMILY_STATE:
275 			switch (subFlag) {
276 			case TSS_TSPATTRIB_DELFAMILYSTATE_LOCKED:
277 				result = obj_delfamily_set_locked(hObject, (TSS_BOOL)ulAttrib, TRUE);
278 				break;
279 			case TSS_TSPATTRIB_DELFAMILYSTATE_ENABLED:
280 				result = obj_delfamily_set_enabled(hObject, (TSS_BOOL)ulAttrib, TRUE);
281 				break;
282 			default:
283 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
284 			}
285 			break;
286 		default:
287 			return TSPERR(TSS_E_INVALID_ATTRIB_FLAG);
288 		}
289 #endif
290 	} else {
291 		if (obj_is_hash(hObject) || obj_is_pcrs(hObject))
292 			result = TSPERR(TSS_E_BAD_PARAMETER);
293 		else
294 			result = TSPERR(TSS_E_INVALID_HANDLE);
295 	}
296 
297 	return result;
298 }
299 
300 TSS_RESULT
Tspi_GetAttribUint32(TSS_HOBJECT hObject,TSS_FLAG attribFlag,TSS_FLAG subFlag,UINT32 * pulAttrib)301 Tspi_GetAttribUint32(TSS_HOBJECT hObject,	/* in */
302 		     TSS_FLAG attribFlag,	/* in */
303 		     TSS_FLAG subFlag,		/* in */
304 		     UINT32 * pulAttrib)	/* out */
305 {
306 	UINT32 attrib;
307 	TSS_RESULT result = TSS_SUCCESS;
308 
309 	if (pulAttrib == NULL)
310 		return TSPERR(TSS_E_BAD_PARAMETER);
311 
312 	if (obj_is_rsakey(hObject)) {
313 #ifdef TSS_BUILD_RSAKEY_LIST
314 		if (attribFlag == TSS_TSPATTRIB_KEY_REGISTER) {
315 			if (subFlag != 0)
316 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
317 
318 			if ((result = obj_rsakey_get_pstype(hObject, &attrib)))
319 				return result;
320 
321 			if (attrib == TSS_PS_TYPE_USER)
322 				*pulAttrib = TSS_TSPATTRIB_KEYREGISTER_USER;
323 			else if (attrib == TSS_PS_TYPE_SYSTEM)
324 				*pulAttrib = TSS_TSPATTRIB_KEYREGISTER_SYSTEM;
325 			else
326 				*pulAttrib = TSS_TSPATTRIB_KEYREGISTER_NO;
327 		} else if (attribFlag == TSS_TSPATTRIB_KEY_INFO) {
328 			switch (subFlag) {
329 			case TSS_TSPATTRIB_KEYINFO_USAGE:
330 				if ((result = obj_rsakey_get_usage(hObject, pulAttrib)))
331 					return result;
332 				break;
333 			case TSS_TSPATTRIB_KEYINFO_MIGRATABLE:
334 				*pulAttrib = obj_rsakey_is_migratable(hObject);
335 				break;
336 			case TSS_TSPATTRIB_KEYINFO_REDIRECTED:
337 				*pulAttrib = obj_rsakey_is_redirected(hObject);
338 				break;
339 			case TSS_TSPATTRIB_KEYINFO_VOLATILE:
340 				*pulAttrib = obj_rsakey_is_volatile(hObject);
341 				break;
342 			case TSS_TSPATTRIB_KEYINFO_AUTHUSAGE:
343 				/* fall through */
344 			case TSS_TSPATTRIB_KEYINFO_AUTHDATAUSAGE:
345 				if ((result = obj_rsakey_get_authdata_usage(hObject, pulAttrib)))
346 					return result;
347 				break;
348 			case TSS_TSPATTRIB_KEYINFO_ALGORITHM:
349 				if ((result = obj_rsakey_get_alg(hObject, pulAttrib)))
350 					return result;
351 				break;
352 			case TSS_TSPATTRIB_KEYINFO_ENCSCHEME:
353 				if ((result = obj_rsakey_get_es(hObject, pulAttrib)))
354 					return result;
355 				break;
356 			case TSS_TSPATTRIB_KEYINFO_SIGSCHEME:
357 				if ((result = obj_rsakey_get_ss(hObject, pulAttrib)))
358 					return result;
359 				break;
360 			case TSS_TSPATTRIB_KEYINFO_KEYFLAGS:
361 				if ((result = obj_rsakey_get_flags(hObject, pulAttrib)))
362 					return result;
363 				break;
364 			case TSS_TSPATTRIB_KEYINFO_SIZE:
365 				if ((result = obj_rsakey_get_size(hObject, pulAttrib)))
366 					return result;
367 				break;
368 #ifdef TSS_BUILD_CMK
369 			case TSS_TSPATTRIB_KEYINFO_CMK:
370 				*pulAttrib = obj_rsakey_is_cmk(hObject);
371 				break;
372 #endif
373 			default:
374 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
375 			}
376 		} else if (attribFlag == TSS_TSPATTRIB_RSAKEY_INFO) {
377 			if (subFlag == TSS_TSPATTRIB_KEYINFO_RSA_KEYSIZE) {
378 				if ((result = obj_rsakey_get_size(hObject, pulAttrib)))
379 					return result;
380 			} else if (subFlag == TSS_TSPATTRIB_KEYINFO_RSA_PRIMES) {
381 				if ((result = obj_rsakey_get_num_primes(hObject, pulAttrib)))
382 					return result;
383 			} else {
384 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
385 			}
386 		} else if (attribFlag == TSS_TSPATTRIB_KEY_PCR_LONG) {
387 			if (subFlag == TSS_TSPATTRIB_KEYPCRLONG_LOCALITY_ATCREATION ||
388 			    subFlag == TSS_TSPATTRIB_KEYPCRLONG_LOCALITY_ATRELEASE) {
389 				result = obj_rsakey_get_pcr_locality(hObject, subFlag, pulAttrib);
390 			} else
391 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
392 		} else
393 			return TSPERR(TSS_E_INVALID_ATTRIB_FLAG);
394 #endif
395 #ifdef TSS_BUILD_NV
396 	} else if (obj_is_nvstore(hObject)) {
397 		switch (attribFlag) {
398 			case TSS_TSPATTRIB_NV_INDEX:
399 				if ((result = obj_nvstore_get_index(hObject, pulAttrib)))
400 					return result;
401 				break;
402 			case TSS_TSPATTRIB_NV_DATASIZE:
403 				if ((result = obj_nvstore_get_datasize(hObject, pulAttrib)))
404 					return result;
405 				break;
406 			case TSS_TSPATTRIB_NV_PERMISSIONS:
407 				if ((result = obj_nvstore_get_permission(hObject, pulAttrib)))
408 					return result;
409 				break;
410 			case TSS_TSPATTRIB_NV_STATE:
411 				switch (subFlag) {
412 					case TSS_TSPATTRIB_NVSTATE_READSTCLEAR:
413 						if ((result =
414 						     obj_nvstore_get_state_readstclear(hObject,
415 										       pulAttrib)))
416 							return result;
417 						break;
418 					case TSS_TSPATTRIB_NVSTATE_WRITEDEFINE:
419 						if ((result =
420 						     obj_nvstore_get_state_writedefine(hObject,
421 										       pulAttrib)))
422 							return result;
423 						break;
424 					case TSS_TSPATTRIB_NVSTATE_WRITESTCLEAR:
425 						if ((result =
426 						     obj_nvstore_get_state_writestclear(hObject,
427 											pulAttrib)))
428 							return result;
429 						break;
430 					default:
431 						return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
432 					}
433 				break;
434 			case TSS_TSPATTRIB_NV_PCR:
435 				switch (subFlag) {
436 					case TSS_TSPATTRIB_NVPCR_READLOCALITYATRELEASE:
437 						if ((result =
438 						     obj_nvstore_get_readlocalityatrelease(hObject,
439 										   pulAttrib)))
440 							return result;
441 						break;
442 					case TSS_TSPATTRIB_NVPCR_WRITELOCALITYATRELEASE:
443 						if ((result =
444 						     obj_nvstore_get_writelocalityatrelease(hObject,
445 										    pulAttrib)))
446 							return result;
447 						break;
448 					default:
449 						return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
450 					}
451 				break;
452 			case TSS_TSPATTRIB_KEYCONTROL_OWNEREVICT:
453 				if ((result = obj_rsakey_get_ownerevict(hObject, pulAttrib)))
454 					return result;
455 				break;
456 			default:
457 				return TSPERR(TSS_E_INVALID_ATTRIB_FLAG);
458 		}
459 #endif
460 	} else if (obj_is_policy(hObject)) {
461 		switch (attribFlag) {
462 			case TSS_TSPATTRIB_POLICY_CALLBACK_HMAC:
463 			case TSS_TSPATTRIB_POLICY_CALLBACK_XOR_ENC:
464 			case TSS_TSPATTRIB_POLICY_CALLBACK_TAKEOWNERSHIP:
465 			case TSS_TSPATTRIB_POLICY_CALLBACK_CHANGEAUTHASYM:
466 				if ((result = obj_policy_get_cb11(hObject, attribFlag, pulAttrib)))
467 					return result;
468 				break;
469 			case TSS_TSPATTRIB_POLICY_SECRET_LIFETIME:
470 				if ((result = obj_policy_get_lifetime(hObject, &attrib)))
471 					return result;
472 
473 				if (subFlag == TSS_TSPATTRIB_POLICYSECRET_LIFETIME_ALWAYS) {
474 					if (attrib == TSS_TSPATTRIB_POLICYSECRET_LIFETIME_ALWAYS)
475 						*pulAttrib = TRUE;
476 					else
477 						*pulAttrib = FALSE;
478 				} else if (subFlag == TSS_TSPATTRIB_POLICYSECRET_LIFETIME_COUNTER) {
479 					if (attrib != TSS_TSPATTRIB_POLICYSECRET_LIFETIME_COUNTER)
480 						return TSPERR(TSS_E_BAD_PARAMETER);
481 					if ((result = obj_policy_get_counter(hObject, pulAttrib)))
482 						return result;
483 				} else if (subFlag == TSS_TSPATTRIB_POLICYSECRET_LIFETIME_TIMER) {
484 					if ((result =
485 					    obj_policy_get_secs_until_expired(hObject, pulAttrib)))
486 						return result;
487 				} else
488 					return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
489 				break;
490 			case TSS_TSPATTRIB_SECRET_HASH_MODE:
491 				if (subFlag == TSS_TSPATTRIB_SECRET_HASH_MODE_POPUP)
492 					result = obj_policy_get_hash_mode(hObject, pulAttrib);
493 				else
494 					return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
495 				break;
496 #ifdef TSS_BUILD_DELEGATION
497 			case TSS_TSPATTRIB_POLICY_DELEGATION_INFO:
498 				switch (subFlag) {
499 				case TSS_TSPATTRIB_POLDEL_TYPE:
500 					result = obj_policy_get_delegation_type(hObject,
501 							pulAttrib);
502 					break;
503 				case TSS_TSPATTRIB_POLDEL_INDEX:
504 					result = obj_policy_get_delegation_index(hObject,
505 							pulAttrib);
506 					break;
507 				case TSS_TSPATTRIB_POLDEL_PER1:
508 					result = obj_policy_get_delegation_per1(hObject,
509 							pulAttrib);
510 					break;
511 				case TSS_TSPATTRIB_POLDEL_PER2:
512 					result = obj_policy_get_delegation_per2(hObject,
513 							pulAttrib);
514 					break;
515 				case TSS_TSPATTRIB_POLDEL_LABEL:
516 					result = obj_policy_get_delegation_label(hObject,
517 							(BYTE *)pulAttrib);
518 					break;
519 				case TSS_TSPATTRIB_POLDEL_FAMILYID:
520 					result = obj_policy_get_delegation_familyid(hObject,
521 							pulAttrib);
522 					break;
523 				case TSS_TSPATTRIB_POLDEL_VERCOUNT:
524 					result = obj_policy_get_delegation_vercount(hObject,
525 							pulAttrib);
526 					break;
527 				default:
528 					result = TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
529 				}
530 				break;
531 			case TSS_TSPATTRIB_POLICY_DELEGATION_PCR:
532 				switch (subFlag) {
533 				case TSS_TSPATTRIB_POLDELPCR_LOCALITY:
534 					result = obj_policy_get_delegation_pcr_locality(hObject,
535 							pulAttrib);
536 					break;
537 				default:
538 					result = TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
539 				}
540 				break;
541 #endif
542 			default:
543 				return TSPERR(TSS_E_INVALID_ATTRIB_FLAG);
544 				break;
545 		}
546 	} else if (obj_is_context(hObject)) {
547 		switch (attribFlag) {
548 			case TSS_TSPATTRIB_CONTEXT_SILENT_MODE:
549 				if ((result = obj_context_get_mode(hObject, pulAttrib)))
550 					return result;
551 				break;
552 			case TSS_TSPATTRIB_SECRET_HASH_MODE:
553 				if (subFlag == TSS_TSPATTRIB_SECRET_HASH_MODE_POPUP)
554 					result = obj_context_get_hash_mode(hObject, pulAttrib);
555 				else
556 					return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
557 				break;
558 #ifdef TSS_BUILD_TRANSPORT
559 			case TSS_TSPATTRIB_CONTEXT_TRANSPORT:
560 				if (subFlag == TSS_TSPATTRIB_DISABLE_TRANSPORT ||
561 				    subFlag == TSS_TSPATTRIB_ENABLE_TRANSPORT) {
562 					result = obj_context_transport_get_control(hObject, subFlag,
563 										   pulAttrib);
564 				} else if (
565 					subFlag == TSS_TSPATTRIB_TRANSPORT_NO_DEFAULT_ENCRYPTION ||
566 					subFlag == TSS_TSPATTRIB_TRANSPORT_DEFAULT_ENCRYPTION ||
567 					subFlag == TSS_TSPATTRIB_TRANSPORT_AUTHENTIC_CHANNEL ||
568 					subFlag == TSS_TSPATTRIB_TRANSPORT_EXCLUSIVE ||
569 					subFlag == TSS_TSPATTRIB_TRANSPORT_STATIC_AUTH) {
570 					result = obj_context_transport_get_mode(hObject, subFlag,
571 										pulAttrib);
572 				} else
573 					return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
574 				break;
575 #endif
576 			default:
577 				return TSPERR(TSS_E_INVALID_ATTRIB_FLAG);
578 				break;
579 		}
580 	} else if (obj_is_tpm(hObject)) {
581 		switch (attribFlag) {
582 			case TSS_TSPATTRIB_TPM_CALLBACK_COLLATEIDENTITY:
583 			case TSS_TSPATTRIB_TPM_CALLBACK_ACTIVATEIDENTITY:
584 				if ((result = obj_tpm_get_cb11(hObject, attribFlag, pulAttrib)))
585 					return result;
586 				break;
587 			default:
588 				result = TSPERR(TSS_E_INVALID_ATTRIB_FLAG);
589 				break;
590 		}
591 	} else if (obj_is_encdata(hObject)) {
592 #ifdef TSS_BUILD_SEALX
593 		if (attribFlag == TSS_TSPATTRIB_ENCDATA_SEAL) {
594 			if (subFlag == TSS_TSPATTRIB_ENCDATASEAL_PROTECT_MODE)
595 				result = obj_encdata_get_seal_protect_mode(hObject, pulAttrib);
596 			else
597 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
598 		} else if (attribFlag == TSS_TSPATTRIB_ENCDATA_PCR_LONG) {
599 			if (subFlag == TSS_TSPATTRIB_ENCDATAPCRLONG_LOCALITY_ATCREATION ||
600 			    subFlag == TSS_TSPATTRIB_ENCDATAPCRLONG_LOCALITY_ATRELEASE) {
601 				result = obj_encdata_get_pcr_locality(hObject, subFlag, pulAttrib);
602 			} else
603 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
604 		} else
605 			return TSPERR(TSS_E_INVALID_ATTRIB_FLAG);
606 #endif
607 #ifdef TSS_BUILD_DELEGATION
608 	} else if (obj_is_delfamily(hObject)) {
609 		switch (attribFlag) {
610 		case TSS_TSPATTRIB_DELFAMILY_STATE:
611 			switch (subFlag) {
612 			case TSS_TSPATTRIB_DELFAMILYSTATE_LOCKED:
613 				result = obj_delfamily_get_locked(hObject, (TSS_BOOL *)pulAttrib);
614 				break;
615 			case TSS_TSPATTRIB_DELFAMILYSTATE_ENABLED:
616 				result = obj_delfamily_get_enabled(hObject, (TSS_BOOL *)pulAttrib);
617 				break;
618 			default:
619 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
620 			}
621 			break;
622 		case TSS_TSPATTRIB_DELFAMILY_INFO:
623 			switch (subFlag) {
624 			case TSS_TSPATTRIB_DELFAMILYINFO_LABEL:
625 				result = obj_delfamily_get_label(hObject, (BYTE *)pulAttrib);
626 				break;
627 			case TSS_TSPATTRIB_DELFAMILYINFO_VERCOUNT:
628 				result = obj_delfamily_get_vercount(hObject, pulAttrib);
629 				break;
630 			case TSS_TSPATTRIB_DELFAMILYINFO_FAMILYID:
631 				result = obj_delfamily_get_familyid(hObject, pulAttrib);
632 				break;
633 			default:
634 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
635 			}
636 			break;
637 		default:
638 			return TSPERR(TSS_E_INVALID_ATTRIB_FLAG);
639 		}
640 #endif
641 	} else {
642 		if (obj_is_hash(hObject) || obj_is_pcrs(hObject))
643 			result = TSPERR(TSS_E_BAD_PARAMETER);
644 		else
645 			result = TSPERR(TSS_E_INVALID_HANDLE);
646 	}
647 
648 	return result;
649 }
650 
651 TSS_RESULT
Tspi_SetAttribData(TSS_HOBJECT hObject,TSS_FLAG attribFlag,TSS_FLAG subFlag,UINT32 ulAttribDataSize,BYTE * rgbAttribData)652 Tspi_SetAttribData(TSS_HOBJECT hObject,		/* in */
653 		   TSS_FLAG attribFlag,		/* in */
654 		   TSS_FLAG subFlag,		/* in */
655 		   UINT32 ulAttribDataSize,	/* in */
656 		   BYTE * rgbAttribData)	/* in */
657 {
658 	TSS_RESULT result;
659 	BYTE *string = NULL;
660 
661 	if (obj_is_rsakey(hObject)) {
662 #ifdef TSS_BUILD_RSAKEY_LIST
663 		if (attribFlag == TSS_TSPATTRIB_KEY_BLOB) {
664 			if (subFlag == TSS_TSPATTRIB_KEYBLOB_BLOB) {
665 				/* A TPM_KEY(12) structure, in blob form */
666 				result = obj_rsakey_set_tcpakey(hObject, ulAttribDataSize,
667 								rgbAttribData);
668 				if (result == TSS_SUCCESS)
669 					result = obj_rsakey_set_tcs_handle(hObject, 0);
670 			} else if (subFlag == TSS_TSPATTRIB_KEYBLOB_PUBLIC_KEY) {
671 				/* A TCPA_PUBKEY structure, in blob form */
672 				result = obj_rsakey_set_pubkey(hObject, FALSE, rgbAttribData);
673 			} else if (subFlag == TSS_TSPATTRIB_KEYBLOB_PRIVATE_KEY) {
674 				/* A blob, either encrypted or unencrypted */
675 				result = obj_rsakey_set_privkey(hObject, FALSE, ulAttribDataSize,
676 								rgbAttribData);
677 			} else {
678 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
679 			}
680 		} else if (attribFlag == TSS_TSPATTRIB_RSAKEY_INFO) {
681 			if (subFlag == TSS_TSPATTRIB_KEYINFO_RSA_EXPONENT) {
682 				result = obj_rsakey_set_exponent(hObject, ulAttribDataSize,
683 								 rgbAttribData);
684 			} else if (subFlag == TSS_TSPATTRIB_KEYINFO_RSA_MODULUS) {
685 				result = obj_rsakey_set_modulus(hObject, ulAttribDataSize,
686 								rgbAttribData);
687 			} else {
688 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
689 			}
690 #ifdef TSS_BUILD_CMK
691 		} else if (attribFlag == TSS_TSPATTRIB_KEY_CMKINFO) {
692 			if (subFlag == TSS_TSPATTRIB_KEYINFO_CMK_MA_APPROVAL) {
693 				result = obj_rsakey_set_msa_approval(hObject, ulAttribDataSize,
694 						rgbAttribData);
695 			} else if (subFlag == TSS_TSPATTRIB_KEYINFO_CMK_MA_DIGEST) {
696 				result = obj_rsakey_set_msa_digest(hObject, ulAttribDataSize,
697 						rgbAttribData);
698 			} else {
699 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
700 			}
701 #endif
702 		} else {
703 			return TSPERR(TSS_E_INVALID_ATTRIB_FLAG);
704 		}
705 #endif
706 	} else if (obj_is_encdata(hObject)) {
707 #ifdef TSS_BUILD_ENCDATA_LIST
708 		if (attribFlag != TSS_TSPATTRIB_ENCDATA_BLOB)
709 			return TSPERR(TSS_E_INVALID_ATTRIB_FLAG);
710 		if (subFlag != TSS_TSPATTRIB_ENCDATABLOB_BLOB)
711 			return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
712 
713 		result = obj_encdata_set_data(hObject, ulAttribDataSize, rgbAttribData);
714 #endif
715 	} else if (obj_is_policy(hObject)) {
716 		switch (attribFlag) {
717 			case TSS_TSPATTRIB_POLICY_POPUPSTRING:
718 				if ((string = Trspi_UNICODE_To_Native(rgbAttribData,
719 								      NULL)) == NULL)
720 					return TSPERR(TSS_E_INTERNAL_ERROR);
721 
722 				result = obj_policy_set_string(hObject,
723 							       ulAttribDataSize,
724 							       string);
725 				break;
726 			case TSS_TSPATTRIB_POLICY_CALLBACK_HMAC:
727 			case TSS_TSPATTRIB_POLICY_CALLBACK_XOR_ENC:
728 			case TSS_TSPATTRIB_POLICY_CALLBACK_TAKEOWNERSHIP:
729 			case TSS_TSPATTRIB_POLICY_CALLBACK_CHANGEAUTHASYM:
730 #ifdef TSS_BUILD_SEALX
731 			case TSS_TSPATTRIB_POLICY_CALLBACK_SEALX_MASK:
732 #endif
733 				result = obj_policy_set_cb12(hObject, attribFlag,
734 							     rgbAttribData);
735 				break;
736 #ifdef TSS_BUILD_DELEGATION
737 			case TSS_TSPATTRIB_POLICY_DELEGATION_INFO:
738 				switch (subFlag) {
739 				case TSS_TSPATTRIB_POLDEL_OWNERBLOB:
740 					result = obj_policy_set_delegation_blob(hObject,
741 							TSS_DELEGATIONTYPE_OWNER,
742 							ulAttribDataSize, rgbAttribData);
743 					break;
744 				case TSS_TSPATTRIB_POLDEL_KEYBLOB:
745 					result = obj_policy_set_delegation_blob(hObject,
746 							TSS_DELEGATIONTYPE_KEY,
747 							ulAttribDataSize, rgbAttribData);
748 					break;
749 				default:
750 					result = TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
751 				}
752 				break;
753 #endif
754 			default:
755 				return TSPERR(TSS_E_INVALID_ATTRIB_FLAG);
756 				break;
757 		}
758 	} else if (obj_is_hash(hObject)) {
759 #ifdef TSS_BUILD_HASH_LIST
760 		if (attribFlag != TSS_TSPATTRIB_HASH_IDENTIFIER)
761 			return TSPERR(TSS_E_INVALID_ATTRIB_FLAG);
762 
763 		if (subFlag != 0)
764 			return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
765 
766 		result = obj_hash_set_value(hObject, ulAttribDataSize, rgbAttribData);
767 #endif
768 	} else if (obj_is_tpm(hObject)) {
769 		switch (attribFlag) {
770 			case TSS_TSPATTRIB_TPM_CALLBACK_COLLATEIDENTITY:
771 			case TSS_TSPATTRIB_TPM_CALLBACK_ACTIVATEIDENTITY:
772 				result = obj_tpm_set_cb12(hObject, attribFlag,
773 							  rgbAttribData);
774 				break;
775 			case TSS_TSPATTRIB_TPM_CREDENTIAL:
776 				if (subFlag == TSS_TPMATTRIB_EKCERT ||
777 				    subFlag == TSS_TPMATTRIB_TPM_CC ||
778 				    subFlag == TSS_TPMATTRIB_PLATFORMCERT ||
779 				    subFlag == TSS_TPMATTRIB_PLATFORM_CC) {
780 					result = obj_tpm_set_cred(hObject, subFlag,
781 								  ulAttribDataSize, rgbAttribData);
782 				} else {
783 					return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
784 				}
785 				break;
786 			default:
787 				return TSPERR(TSS_E_INVALID_ATTRIB_FLAG);
788 				break;
789 		}
790 	} else if (obj_is_migdata(hObject)) {
791 #ifdef TSS_BUILD_CMK
792 		switch (attribFlag) {
793 		case TSS_MIGATTRIB_MIGRATIONBLOB:
794 			switch (subFlag) {
795 			case TSS_MIGATTRIB_MIG_MSALIST_PUBKEY_BLOB:
796 			case TSS_MIGATTRIB_MIG_AUTHORITY_PUBKEY_BLOB:
797 			case TSS_MIGATTRIB_MIG_DESTINATION_PUBKEY_BLOB:
798 			case TSS_MIGATTRIB_MIG_SOURCE_PUBKEY_BLOB:
799 				result = obj_migdata_set_migrationblob(hObject, subFlag,
800 						ulAttribDataSize, rgbAttribData);
801 				break;
802 			default:
803 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
804 			}
805 			break;
806 		case TSS_MIGATTRIB_MIGRATIONTICKET:
807 			if (subFlag != 0)
808 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
809 			result = obj_migdata_set_ticket_blob(hObject, ulAttribDataSize, rgbAttribData);
810 			break;
811 		case TSS_MIGATTRIB_AUTHORITY_DATA:
812 			switch (subFlag) {
813 			case TSS_MIGATTRIB_AUTHORITY_DIGEST:
814 			case TSS_MIGATTRIB_AUTHORITY_APPROVAL_HMAC:
815 			case TSS_MIGATTRIB_AUTHORITY_MSALIST:
816 				result = obj_migdata_set_authoritydata(hObject, subFlag,
817 						ulAttribDataSize, rgbAttribData);
818 				break;
819 			default:
820 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
821 			}
822 			break;
823 		case TSS_MIGATTRIB_MIG_AUTH_DATA:
824 			switch (subFlag) {
825 			case TSS_MIGATTRIB_MIG_AUTH_AUTHORITY_DIGEST:
826 			case TSS_MIGATTRIB_MIG_AUTH_DESTINATION_DIGEST:
827 			case TSS_MIGATTRIB_MIG_AUTH_SOURCE_DIGEST:
828 				result = obj_migdata_set_migauthdata(hObject, subFlag,
829 						ulAttribDataSize, rgbAttribData);
830 				break;
831 			default:
832 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
833 			}
834 			break;
835 		case TSS_MIGATTRIB_TICKET_DATA:
836 			switch (subFlag) {
837 			case TSS_MIGATTRIB_TICKET_SIG_DIGEST:
838 			case TSS_MIGATTRIB_TICKET_SIG_VALUE:
839 			case TSS_MIGATTRIB_TICKET_SIG_TICKET:
840 			case TSS_MIGATTRIB_TICKET_RESTRICT_TICKET:
841 				result = obj_migdata_set_ticketdata(hObject, subFlag,
842 						ulAttribDataSize, rgbAttribData);
843 				break;
844 			default:
845 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
846 			}
847 			break;
848 		default:
849 			return TSPERR(TSS_E_INVALID_ATTRIB_FLAG);
850 			break;
851 		}
852 #endif
853 	} else {
854 		if (obj_is_pcrs(hObject) || obj_is_context(hObject))
855 			result = TSPERR(TSS_E_BAD_PARAMETER);
856 #ifdef TSS_BUILD_NV
857 		else if (obj_is_nvstore(hObject))
858 			result = TSPERR(TSS_E_BAD_PARAMETER);
859 #endif
860 		else
861 			result = TSPERR(TSS_E_INVALID_HANDLE);
862 	}
863 
864 	return result;
865 }
866 
867 TSS_RESULT
Tspi_GetAttribData(TSS_HOBJECT hObject,TSS_FLAG attribFlag,TSS_FLAG subFlag,UINT32 * pulAttribDataSize,BYTE ** prgbAttribData)868 Tspi_GetAttribData(TSS_HOBJECT hObject,		/* in */
869 		   TSS_FLAG attribFlag,		/* in */
870 		   TSS_FLAG subFlag,		/* in */
871 		   UINT32 * pulAttribDataSize,	/* out */
872 		   BYTE ** prgbAttribData)	/* out */
873 {
874 	TSS_RESULT result;
875 
876 	if (pulAttribDataSize == NULL || prgbAttribData == NULL)
877 		return TSPERR(TSS_E_BAD_PARAMETER);
878 
879 	if (obj_is_rsakey(hObject)) {
880 #ifdef TSS_BUILD_RSAKEY_LIST
881 		if (attribFlag == TSS_TSPATTRIB_KEY_BLOB) {
882 			if (subFlag == TSS_TSPATTRIB_KEYBLOB_BLOB) {
883 				/* A TPM_KEY(12) structure, in blob form */
884 				result = obj_rsakey_get_blob(hObject, pulAttribDataSize,
885 							     prgbAttribData);
886 			} else if (subFlag == TSS_TSPATTRIB_KEYBLOB_PRIVATE_KEY) {
887 				/* A blob, either encrypted or unencrypted */
888 				result = obj_rsakey_get_priv_blob(hObject, pulAttribDataSize,
889 								  prgbAttribData);
890 			} else if (subFlag == TSS_TSPATTRIB_KEYBLOB_PUBLIC_KEY) {
891 				/* A TCPA_PUBKEY structure, in blob form */
892 				result = obj_rsakey_get_pub_blob(hObject, pulAttribDataSize,
893 								 prgbAttribData);
894 			} else {
895 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
896 			}
897 		} else if (attribFlag == TSS_TSPATTRIB_KEY_INFO) {
898 			if (subFlag != TSS_TSPATTRIB_KEYINFO_VERSION)
899 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
900 
901 			result = obj_rsakey_get_version(hObject, pulAttribDataSize,
902 							prgbAttribData);
903 		} else if (attribFlag == TSS_TSPATTRIB_RSAKEY_INFO) {
904 			if (subFlag == TSS_TSPATTRIB_KEYINFO_RSA_EXPONENT) {
905 				result = obj_rsakey_get_exponent(hObject, pulAttribDataSize,
906 								 prgbAttribData);
907 			} else if (subFlag == TSS_TSPATTRIB_KEYINFO_RSA_MODULUS) {
908 				result = obj_rsakey_get_modulus(hObject, pulAttribDataSize,
909 								prgbAttribData);
910 			} else
911 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
912 		} else if (attribFlag == TSS_TSPATTRIB_KEY_UUID) {
913 			if (subFlag)
914 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
915 
916 			result = obj_rsakey_get_uuid(hObject, pulAttribDataSize, prgbAttribData);
917 		} else if (attribFlag == TSS_TSPATTRIB_KEY_PCR) {
918 			if (subFlag == TSS_TSPATTRIB_KEYPCR_DIGEST_ATCREATION ||
919 			    subFlag == TSS_TSPATTRIB_KEYPCR_DIGEST_ATRELEASE) {
920 				result = obj_rsakey_get_pcr_digest(hObject, TSS_PCRS_STRUCT_INFO,
921 								   subFlag, pulAttribDataSize,
922 								   prgbAttribData);
923 			} else if (subFlag == TSS_TSPATTRIB_KEYPCR_SELECTION) {
924 				result = obj_rsakey_get_pcr_selection(hObject, TSS_PCRS_STRUCT_INFO,
925 								      subFlag, pulAttribDataSize,
926 								      prgbAttribData);
927 			} else
928 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
929 		} else if (attribFlag == TSS_TSPATTRIB_KEY_PCR_LONG) {
930 			if (subFlag == TSS_TSPATTRIB_KEYPCRLONG_DIGEST_ATCREATION ||
931 			    subFlag == TSS_TSPATTRIB_KEYPCRLONG_DIGEST_ATRELEASE) {
932 				result = obj_rsakey_get_pcr_digest(hObject,
933 								   TSS_PCRS_STRUCT_INFO_LONG,
934 								   subFlag, pulAttribDataSize,
935 								   prgbAttribData);
936 			} else if (subFlag == TSS_TSPATTRIB_KEYPCRLONG_CREATION_SELECTION ||
937 			           subFlag == TSS_TSPATTRIB_KEYPCRLONG_RELEASE_SELECTION) {
938 				result = obj_rsakey_get_pcr_selection(hObject,
939 								      TSS_PCRS_STRUCT_INFO_LONG,
940 								      subFlag, pulAttribDataSize,
941 								      prgbAttribData);
942 			} else
943 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
944 #ifdef TSS_BUILD_CMK
945 		} else if (attribFlag == TSS_TSPATTRIB_KEY_CMKINFO) {
946 			if (subFlag == TSS_TSPATTRIB_KEYINFO_CMK_MA_APPROVAL) {
947 				result = obj_rsakey_get_msa_approval(hObject, pulAttribDataSize,
948 						prgbAttribData);
949 			} else if (subFlag == TSS_TSPATTRIB_KEYINFO_CMK_MA_DIGEST) {
950 				result = obj_rsakey_get_msa_digest(hObject, pulAttribDataSize,
951 						prgbAttribData);
952 			} else {
953 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
954 			}
955 #endif
956 		} else
957 			return TSPERR(TSS_E_INVALID_ATTRIB_FLAG);
958 #endif
959 #ifdef TSS_BUILD_NV
960 	} else if (obj_is_nvstore(hObject)) {
961 		if (attribFlag == TSS_TSPATTRIB_NV_PCR) {
962 			switch (subFlag) {
963 				case TSS_TSPATTRIB_NVPCR_READDIGESTATRELEASE:
964 					if ((result = obj_nvstore_get_readdigestatrelease(hObject,
965 									pulAttribDataSize,
966 									prgbAttribData)))
967 							return result;
968 					break;
969 				case TSS_TSPATTRIB_NVPCR_READPCRSELECTION:
970 					if ((result = obj_nvstore_get_readpcrselection(
971 									hObject,
972 									pulAttribDataSize,
973 									prgbAttribData)))
974 						return result;
975 					break;
976 				case TSS_TSPATTRIB_NVPCR_WRITEDIGESTATRELEASE:
977 					if ((result = obj_nvstore_get_writedigestatrelease(hObject,
978 									pulAttribDataSize,
979 									prgbAttribData)))
980 						return result;
981 					break;
982 				case TSS_TSPATTRIB_NVPCR_WRITEPCRSELECTION:
983 					if ((result = obj_nvstore_get_writepcrselection(hObject,
984 									pulAttribDataSize,
985 									prgbAttribData)))
986 						return result;
987 					break;
988 				default:
989 					return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
990 			}
991 		} else
992 			return TSPERR(TSS_E_INVALID_ATTRIB_FLAG);
993 #endif
994 	} else if (obj_is_encdata(hObject)) {
995 #ifdef TSS_BUILD_ENCDATA_LIST
996 		if (attribFlag == TSS_TSPATTRIB_ENCDATA_BLOB) {
997 			if (subFlag != TSS_TSPATTRIB_ENCDATABLOB_BLOB)
998 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
999 
1000 			result = obj_encdata_get_data(hObject, pulAttribDataSize, prgbAttribData);
1001 		} else if (attribFlag == TSS_TSPATTRIB_ENCDATA_PCR) {
1002 			if (subFlag == TSS_TSPATTRIB_ENCDATAPCR_DIGEST_ATCREATION ||
1003 			    subFlag == TSS_TSPATTRIB_ENCDATAPCR_DIGEST_RELEASE) {
1004 				result = obj_encdata_get_pcr_digest(hObject, TSS_PCRS_STRUCT_INFO,
1005 								    subFlag, pulAttribDataSize,
1006 								    prgbAttribData);
1007 			} else if (subFlag == TSS_TSPATTRIB_ENCDATAPCR_SELECTION) {
1008 				result = obj_encdata_get_pcr_selection(hObject,
1009 								       TSS_PCRS_STRUCT_INFO,
1010 								       subFlag, pulAttribDataSize,
1011 								       prgbAttribData);
1012 			} else {
1013 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
1014 			}
1015 		} else if (attribFlag == TSS_TSPATTRIB_ENCDATA_PCR_LONG) {
1016 			if (subFlag == TSS_TSPATTRIB_ENCDATAPCRLONG_CREATION_SELECTION ||
1017 			    subFlag == TSS_TSPATTRIB_ENCDATAPCRLONG_RELEASE_SELECTION) {
1018 				result = obj_encdata_get_pcr_selection(hObject,
1019 								       TSS_PCRS_STRUCT_INFO_LONG,
1020 								       subFlag, pulAttribDataSize,
1021 								       prgbAttribData);
1022 			} else if (subFlag == TSS_TSPATTRIB_ENCDATAPCRLONG_DIGEST_ATCREATION ||
1023 				   subFlag == TSS_TSPATTRIB_ENCDATAPCRLONG_DIGEST_ATRELEASE) {
1024 				result = obj_encdata_get_pcr_digest(hObject,
1025 								    TSS_PCRS_STRUCT_INFO_LONG,
1026 								    subFlag, pulAttribDataSize,
1027 								    prgbAttribData);
1028 			} else {
1029 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
1030 			}
1031 		} else {
1032 			return TSPERR(TSS_E_INVALID_ATTRIB_FLAG);
1033 		}
1034 #endif
1035 	} else if (obj_is_context(hObject)) {
1036 		if (attribFlag != TSS_TSPATTRIB_CONTEXT_MACHINE_NAME)
1037 			return TSPERR(TSS_E_INVALID_ATTRIB_FLAG);
1038 
1039 		if ((result = obj_context_get_machine_name_attrib(hObject,
1040 								  pulAttribDataSize,
1041 								  prgbAttribData)))
1042 			return result;
1043 	} else if (obj_is_policy(hObject)) {
1044 		switch (attribFlag) {
1045 			case TSS_TSPATTRIB_POLICY_CALLBACK_HMAC:
1046 			case TSS_TSPATTRIB_POLICY_CALLBACK_XOR_ENC:
1047 			case TSS_TSPATTRIB_POLICY_CALLBACK_TAKEOWNERSHIP:
1048 			case TSS_TSPATTRIB_POLICY_CALLBACK_CHANGEAUTHASYM:
1049 #ifdef TSS_BUILD_SEALX
1050 			case TSS_TSPATTRIB_POLICY_CALLBACK_SEALX_MASK:
1051 #endif
1052 				result = obj_policy_get_cb12(hObject, attribFlag,
1053 							     pulAttribDataSize, prgbAttribData);
1054 				break;
1055 			case TSS_TSPATTRIB_POLICY_POPUPSTRING:
1056 				if ((result = obj_policy_get_string(hObject, pulAttribDataSize,
1057 								    prgbAttribData)))
1058 					return result;
1059 				break;
1060 #ifdef TSS_BUILD_DELEGATION
1061 			case TSS_TSPATTRIB_POLICY_DELEGATION_INFO:
1062 				switch (subFlag) {
1063 				case TSS_TSPATTRIB_POLDEL_OWNERBLOB:
1064 					result = obj_policy_get_delegation_blob(hObject,
1065 							TSS_DELEGATIONTYPE_OWNER,
1066 							pulAttribDataSize, prgbAttribData);
1067 					break;
1068 				case TSS_TSPATTRIB_POLDEL_KEYBLOB:
1069 					result = obj_policy_get_delegation_blob(hObject,
1070 							TSS_DELEGATIONTYPE_KEY,
1071 							pulAttribDataSize, prgbAttribData);
1072 					break;
1073 				default:
1074 					return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
1075 				}
1076 				break;
1077 			case TSS_TSPATTRIB_POLICY_DELEGATION_PCR:
1078 				switch (subFlag) {
1079 				case TSS_TSPATTRIB_POLDELPCR_DIGESTATRELEASE:
1080 					result = obj_policy_get_delegation_pcr_digest(hObject,
1081 							pulAttribDataSize, prgbAttribData);
1082 					break;
1083 				case TSS_TSPATTRIB_POLDELPCR_SELECTION:
1084 					result = obj_policy_get_delegation_pcr_selection(hObject,
1085 							pulAttribDataSize, prgbAttribData);
1086 					break;
1087 				default:
1088 					return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
1089 				}
1090 				break;
1091 #endif
1092 			default:
1093 				result = TSPERR(TSS_E_INVALID_ATTRIB_FLAG);
1094 				break;
1095 		}
1096 	} else if (obj_is_tpm(hObject)) {
1097 		switch (attribFlag) {
1098 			case TSS_TSPATTRIB_TPM_CALLBACK_COLLATEIDENTITY:
1099 			case TSS_TSPATTRIB_TPM_CALLBACK_ACTIVATEIDENTITY:
1100 				result = obj_tpm_get_cb12(hObject, attribFlag,
1101 							  pulAttribDataSize, prgbAttribData);
1102 				break;
1103 			default:
1104 				return TSPERR(TSS_E_INVALID_ATTRIB_FLAG);
1105 				break;
1106 		}
1107 	} else if (obj_is_migdata(hObject)) {
1108 #ifdef TSS_BUILD_CMK
1109 		switch (attribFlag) {
1110 		case TSS_MIGATTRIB_MIGRATIONBLOB:
1111 			switch (subFlag) {
1112 			case TSS_MIGATTRIB_MIG_XOR_BLOB:
1113 				result = obj_migdata_get_migrationblob(hObject, subFlag,
1114 						pulAttribDataSize, prgbAttribData);
1115 				break;
1116 			default:
1117 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
1118 			}
1119 			break;
1120 		case TSS_MIGATTRIB_AUTHORITY_DATA:
1121 			switch (subFlag) {
1122 			case TSS_MIGATTRIB_AUTHORITY_DIGEST:
1123 			case TSS_MIGATTRIB_AUTHORITY_APPROVAL_HMAC:
1124 			case TSS_MIGATTRIB_AUTHORITY_MSALIST:
1125 				result = obj_migdata_get_authoritydata(hObject, subFlag,
1126 						pulAttribDataSize, prgbAttribData);
1127 				break;
1128 			default:
1129 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
1130 			}
1131 			break;
1132 		case TSS_MIGATTRIB_MIG_AUTH_DATA:
1133 			switch (subFlag) {
1134 			case TSS_MIGATTRIB_MIG_AUTH_AUTHORITY_DIGEST:
1135 			case TSS_MIGATTRIB_MIG_AUTH_DESTINATION_DIGEST:
1136 			case TSS_MIGATTRIB_MIG_AUTH_SOURCE_DIGEST:
1137 				result = obj_migdata_get_migauthdata(hObject, subFlag,
1138 						pulAttribDataSize, prgbAttribData);
1139 				break;
1140 			default:
1141 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
1142 			}
1143 			break;
1144 		case TSS_MIGATTRIB_TICKET_DATA:
1145 			switch (subFlag) {
1146 			case TSS_MIGATTRIB_TICKET_SIG_TICKET:
1147 				result = obj_migdata_get_ticketdata(hObject, subFlag,
1148 						pulAttribDataSize, prgbAttribData);
1149 				break;
1150 			default:
1151 				return TSPERR(TSS_E_INVALID_ATTRIB_SUBFLAG);
1152 			}
1153 			break;
1154 		default:
1155 			return TSPERR(TSS_E_INVALID_ATTRIB_FLAG);
1156 			break;
1157 		}
1158 #endif
1159 	} else {
1160 		if (obj_is_hash(hObject) || obj_is_pcrs(hObject))
1161 			result = TSPERR(TSS_E_BAD_PARAMETER);
1162 		else
1163 			result = TSPERR(TSS_E_INVALID_HANDLE);
1164 	}
1165 
1166 	return result;
1167 }
1168 
1169