Home | History | Annotate | Line # | Download | only in tcs
      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
      8  *
      9  */
     10 
     11 
     12 #include <stdlib.h>
     13 #include <stdio.h>
     14 #include <string.h>
     15 #include <inttypes.h>
     16 
     17 #include "trousers/tss.h"
     18 #include "trousers_types.h"
     19 #include "tcs_tsp.h"
     20 #include "tcsps.h"
     21 #include "tcs_utils.h"
     22 #include "tcs_int_literals.h"
     23 #include "capabilities.h"
     24 #include "tcslog.h"
     25 #include "req_mgr.h"
     26 #include "tcsd_wrap.h"
     27 #include "tcsd.h"
     28 
     29 TSS_RESULT
     30 TCSP_DirWriteAuth_Internal(TCS_CONTEXT_HANDLE hContext,	/* in */
     31 			   TCPA_DIRINDEX dirIndex,	/* in */
     32 			   TCPA_DIRVALUE newContents,	/* in */
     33 			   TPM_AUTH * ownerAuth)	/* in, out */
     34 {
     35 	UINT64 offset = 0;
     36 	UINT32 paramSize;
     37 	TSS_RESULT result;
     38 	BYTE txBlob[TSS_TPM_TXBLOB_SIZE];
     39 
     40 	LogDebug("Entering dirwriteauth");
     41 	if ((result = ctx_verify_context(hContext)))
     42 		goto done;
     43 
     44 	if ((result = auth_mgr_check(hContext, &ownerAuth->AuthHandle)))
     45 		goto done;
     46 
     47 	if (dirIndex > tpm_metrics.num_dirs) {
     48 		result = TCSERR(TSS_E_BAD_PARAMETER);
     49 		goto done;
     50 	}
     51 
     52 	if ((result = tpm_rqu_build(TPM_ORD_DirWriteAuth, &offset, txBlob, dirIndex,
     53 				    TPM_DIGEST_SIZE, newContents.digest, ownerAuth, NULL)))
     54 		goto done;
     55 
     56 	if ((result = req_mgr_submit_req(txBlob)))
     57 		goto done;
     58 
     59 	result = UnloadBlob_Header(txBlob, &paramSize);
     60 
     61 	if (!result) {
     62 		result = tpm_rsp_parse(TPM_ORD_DirWriteAuth, txBlob, paramSize, ownerAuth);
     63 	}
     64 	LogResult("DirWriteAuth", result);
     65 done:
     66 	auth_mgr_release_auth(ownerAuth, NULL, hContext);
     67 	return result;
     68 }
     69 
     70 TSS_RESULT
     71 TCSP_DirRead_Internal(TCS_CONTEXT_HANDLE hContext,	/* in */
     72 		      TCPA_DIRINDEX dirIndex,	/* in */
     73 		      TCPA_DIRVALUE * dirValue)	/* out */
     74 {
     75 	UINT64 offset = 0;
     76 	UINT32 paramSize;
     77 	TSS_RESULT result;
     78 	BYTE txBlob[TSS_TPM_TXBLOB_SIZE];
     79 
     80 	LogDebug("Entering DirRead");
     81 	if ((result = ctx_verify_context(hContext)))
     82 		return result;
     83 
     84 	if (dirValue == NULL)
     85 		return TCSERR(TSS_E_BAD_PARAMETER);
     86 
     87 	if (dirIndex > tpm_metrics.num_dirs)
     88 		return TCSERR(TSS_E_BAD_PARAMETER);
     89 
     90 	if ((result = tpm_rqu_build(TPM_ORD_DirRead, &offset, txBlob, dirIndex, NULL)))
     91 		return result;
     92 
     93 	if ((result = req_mgr_submit_req(txBlob)))
     94 		return result;
     95 
     96 	result = UnloadBlob_Header(txBlob, &paramSize);
     97 	if (!result) {
     98 		result = tpm_rsp_parse(TPM_ORD_DirRead, txBlob, paramSize, NULL, dirValue->digest);
     99 	}
    100 	LogResult("DirRead", result);
    101 	return result;
    102 }
    103 
    104