ia64/xen-unstable

changeset 8499:d186157615d6

This patch adds TPM_Seal support to the VTSP. On measured platforms
this can be use to better protect secrets in the VTPM System

Signed-off-by: Vinnie Scarlata <vincent.r.scarlata@intel.com>
author kaf24@firebug.cl.cam.ac.uk
date Wed Jan 04 11:37:41 2006 +0100 (2006-01-04)
parents f22ea989389d
children e0a0ebad0535
files tools/vtpm_manager/manager/vtsp.c tools/vtpm_manager/manager/vtsp.h tools/vtpm_manager/tcs/tcs.c
line diff
     1.1 --- a/tools/vtpm_manager/manager/vtsp.c	Tue Jan 03 19:06:14 2006 +0100
     1.2 +++ b/tools/vtpm_manager/manager/vtsp.c	Wed Jan 04 11:37:41 2006 +0100
     1.3 @@ -144,7 +144,10 @@ TPM_RESULT VerifyAuth( /*[IN]*/ const BY
     1.4    if (memcmp (&hm, &(auth->HMAC), sizeof(TPM_DIGEST)) == 0)  // 0 indicates equality
     1.5      return (TPM_SUCCESS);
     1.6    else {
     1.7 -    VTSP_OIAP( hContext, auth);
     1.8 +    // If specified, reconnect the OIAP session.
     1.9 +    // NOTE: This only works for TCS's that never have a 0 context. 
    1.10 +    if (hContext) 
    1.11 +      VTSP_OIAP( hContext, auth);
    1.12      return (TPM_AUTHFAIL);
    1.13    }
    1.14  }
    1.15 @@ -157,6 +160,10 @@ TPM_RESULT VTSP_OIAP(const TCS_CONTEXT_H
    1.16    TPMTRYRETURN( TCSP_OIAP(hContext,
    1.17  			  &auth->AuthHandle,
    1.18  			  &auth->NonceEven) );
    1.19 +
    1.20 +  memset(&auth->HMAC, 0, sizeof(TPM_DIGEST));
    1.21 +  auth->fContinueAuthSession = FALSE;
    1.22 +
    1.23    goto egress;
    1.24    
    1.25   abort_egress:
    1.26 @@ -195,6 +202,9 @@ TPM_RESULT VTSP_OSAP(const TCS_CONTEXT_H
    1.27  		 BSG_TPM_NONCE, &nonceOddOSAP);
    1.28    
    1.29    Crypto_HMAC(sharedSecretText, sizeof(sharedSecretText), (BYTE *) usageAuth, TPM_DIGEST_SIZE, (BYTE *) sharedSecret);       
    1.30 +
    1.31 +  memset(&auth->HMAC, 0, sizeof(TPM_DIGEST));
    1.32 +  auth->fContinueAuthSession = FALSE;
    1.33      
    1.34    goto egress;
    1.35    
    1.36 @@ -288,9 +298,6 @@ TPM_RESULT VTSP_TakeOwnership(   const T
    1.37    
    1.38    struct pack_buf_t srkText;
    1.39    
    1.40 -  // GenerateAuth new nonceOdd    
    1.41 -  Crypto_GetRandom(&auth->NonceOdd, sizeof(TPM_NONCE) );
    1.42 -  
    1.43    //These values are accurate for an enc(AuthData).
    1.44    struct pack_buf_t encOwnerAuth, encSrkAuth;
    1.45    
    1.46 @@ -383,9 +390,6 @@ TPM_RESULT VTSP_DisablePubekRead( const 
    1.47    BYTE *paramText;        // Digest to make Auth.
    1.48    UINT32 paramTextSize;
    1.49      
    1.50 -  // Generate HMAC   
    1.51 -  Crypto_GetRandom(&auth->NonceOdd, sizeof(TPM_NONCE) );
    1.52 -  
    1.53    paramText = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
    1.54    
    1.55    paramTextSize = BSG_PackList(paramText, 1,
    1.56 @@ -504,9 +508,6 @@ TPM_RESULT VTSP_CreateWrapKey(  const TC
    1.57    newKeyText.data = flatKey;
    1.58    newKeyText.size = flatKeySize;
    1.59    
    1.60 -  // GenerateAuth new nonceOdd    
    1.61 -  Crypto_GetRandom(&auth->NonceOdd, sizeof(TPM_NONCE) );
    1.62 -  
    1.63    // Generate HMAC
    1.64    paramText = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
    1.65    
    1.66 @@ -587,9 +588,6 @@ TPM_RESULT VTSP_LoadKey(const TCS_CONTEX
    1.67      // Generate Extra TCS Parameters
    1.68      TPM_HANDLE phKeyHMAC;
    1.69    
    1.70 -    // Generate HMAC
    1.71 -    Crypto_GetRandom(&auth->NonceOdd, sizeof(TPM_NONCE) );
    1.72 -  
    1.73      paramText = (BYTE *) malloc(sizeof(BYTE) *  TCPA_MAX_BUFFER_LENGTH);
    1.74    
    1.75      paramTextSize = BSG_PackList(paramText, 1,
    1.76 @@ -676,9 +674,6 @@ TPM_RESULT VTSP_Unbind( const TCS_CONTEX
    1.77    BYTE *clear_data_text;
    1.78    UINT32 clear_data_size;
    1.79    
    1.80 -  // Generate HMAC   
    1.81 -  Crypto_GetRandom(&auth->NonceOdd, sizeof(TPM_NONCE) );
    1.82 -  
    1.83    struct pack_buf_t bound_data32 = {bound_data->size, bound_data->bytes};
    1.84    
    1.85    paramText = (BYTE *) malloc(sizeof(BYTE) * TCPA_MAX_BUFFER_LENGTH);
    1.86 @@ -787,6 +782,196 @@ TPM_RESULT VTSP_Bind(   CRYPTO_INFO *cry
    1.87    return TPM_SUCCESS;
    1.88  }
    1.89  
    1.90 +TPM_RESULT VTSP_Seal(const TCS_CONTEXT_HANDLE    hContext,
    1.91 +                     const TPM_KEY_HANDLE        keyHandle,
    1.92 +                     const TPM_AUTHDATA          *sealDataAuth,
    1.93 +                     const TPM_PCR_COMPOSITE     *pcrComp,
    1.94 +                     const buffer_t              *inData,
    1.95 +                     TPM_STORED_DATA             *sealedData,                                   
    1.96 +                     const TPM_SECRET            *osapSharedSecret,
    1.97 +                     TCS_AUTH                    *auth) {
    1.98 +
    1.99 +  TPM_RESULT status = TPM_SUCCESS;
   1.100 +  TPM_COMMAND_CODE command = TPM_ORD_Seal;
   1.101 +
   1.102 +  BYTE *paramText;        // Digest to make Auth.
   1.103 +  UINT32 paramTextSize;
   1.104 +
   1.105 +  // Generate PCR_Info Struct from Comp
   1.106 +  TPM_PCR_INFO pcrInfo;
   1.107 +  UINT32 pcrInfoSize, flatpcrSize;
   1.108 +  BYTE flatpcr[3 +                          // PCR_Select = 3 1 byte banks
   1.109 +               sizeof(UINT16) +             //              2 byte UINT16
   1.110 +               sizeof(UINT32) +             // PCR_Comp   = 4 byte UINT32
   1.111 +               24 * sizeof(TPM_PCRVALUE) ]; //              up to 24 PCRs
   1.112 +
   1.113 +  if (pcrComp != NULL) {
   1.114 +      //printf("\n\tBinding to PCRs: ");
   1.115 +      //for(int i = 0 ; i < pcrComp->select.sizeOfSelect ; i++)
   1.116 +      //printf("%2.2x", pcrComp->select.pcrSelect[i]);
   1.117 +
   1.118 +      memcpy(&pcrInfo.pcrSelection, &pcrComp->select, sizeof(TPM_PCR_SELECTION));
   1.119 +
   1.120 +      flatpcrSize = BSG_Pack(BSG_TPM_PCR_COMPOSITE, (BYTE *) pcrComp, flatpcr);
   1.121 +      Crypto_SHA1Full((BYTE *) flatpcr, flatpcrSize, (BYTE *) &(pcrInfo.digestAtRelease));
   1.122 +      memset(&(pcrInfo.digestAtCreation), 0, sizeof(TPM_DIGEST));
   1.123 +      pcrInfoSize = BSG_Pack(BSG_TPM_PCR_INFO, (BYTE *) &pcrInfo, flatpcr);
   1.124 +  } else {
   1.125 +      //printf("\n\tBinding to no PCRS.");
   1.126 +      pcrInfoSize = 0;
   1.127 +  }
   1.128 +
   1.129 +  // Calculate encUsageAuth
   1.130 +  BYTE XORbuffer[sizeof(TPM_SECRET) + sizeof(TPM_NONCE)];
   1.131 +  UINT32 XORbufferSize = sizeof(XORbuffer);
   1.132 +  TPM_DIGEST XORKey;
   1.133 +  TPM_ENCAUTH encAuth;
   1.134 +
   1.135 +  BSG_PackList( XORbuffer, 2,
   1.136 +                BSG_TPM_SECRET, osapSharedSecret,
   1.137 +                BSG_TPM_NONCE, &auth->NonceEven );
   1.138 +
   1.139 +  Crypto_SHA1Full(XORbuffer, XORbufferSize, (BYTE *) &XORKey);
   1.140 +
   1.141 +  int i;
   1.142 +  for (i=0; i < TPM_DIGEST_SIZE; i++)
   1.143 +    ((BYTE *) &encAuth)[i] = ((BYTE *) &XORKey)[i] ^ ((BYTE *) sealDataAuth)[i];
   1.144 +
   1.145 +  // Generate Extra TCS Parameters
   1.146 +  UINT32 inDataSize = buffer_len(inData);
   1.147 +  struct pack_buf_t inData_pack = {inDataSize, inData->bytes};
   1.148 +  struct pack_buf_t pcrInfo_pack = {pcrInfoSize, flatpcr};
   1.149 +
   1.150 +  UINT32 sealedDataSize;
   1.151 +  BYTE *flatSealedData=NULL;
   1.152 +
   1.153 +  paramText = (BYTE *) malloc(sizeof(BYTE) *  TCPA_MAX_BUFFER_LENGTH);
   1.154 +
   1.155 +  paramTextSize = BSG_PackList(paramText, 4,
   1.156 +                               BSG_TPM_COMMAND_CODE, &command,
   1.157 +                               BSG_TPM_ENCAUTH, &encAuth,
   1.158 +                               BSG_TPM_SIZE32_DATA, &pcrInfo_pack,
   1.159 +                               BSG_TPM_SIZE32_DATA, &inData_pack);
   1.160 +
   1.161 +  TPMTRYRETURN( GenerateAuth( paramText, paramTextSize,
   1.162 +                              osapSharedSecret, auth) );
   1.163 +
   1.164 +  // Call TCS
   1.165 +  TPMTRYRETURN( TCSP_Seal( hContext,
   1.166 +                           keyHandle,
   1.167 +                           encAuth,
   1.168 +                           pcrInfoSize,
   1.169 +                           flatpcr,
   1.170 +                           inDataSize,
   1.171 +                           inData->bytes,
   1.172 +                           auth,
   1.173 +                           &sealedDataSize,
   1.174 +                           &flatSealedData) );
   1.175 +
   1.176 +  // Unpack/return key structure
   1.177 +  BSG_Unpack( BSG_TPM_STORED_DATA, flatSealedData, sealedData );
   1.178 +
   1.179 +  paramTextSize = BSG_PackList(paramText, 3,
   1.180 +                               BSG_TPM_RESULT, &status,
   1.181 +                               BSG_TPM_COMMAND_CODE, &command,
   1.182 +                               BSG_TPM_STORED_DATA, sealedData);
   1.183 +
   1.184 +  TPMTRYRETURN( VerifyAuth( paramText, paramTextSize,
   1.185 +                            osapSharedSecret, auth,
   1.186 +                            0) );
   1.187 +
   1.188 +
   1.189 +  goto egress;
   1.190 +
   1.191 + abort_egress:
   1.192 + egress:
   1.193 +
   1.194 +  if (flatSealedData)
   1.195 +    TCS_FreeMemory( hContext, flatSealedData);
   1.196 +
   1.197 +  free(paramText);
   1.198 +  return status;
   1.199 +}
   1.200 +
   1.201 +
   1.202 +TPM_RESULT VTSP_Unseal(const TCS_CONTEXT_HANDLE    hContext,
   1.203 +                       const TPM_KEY_HANDLE        keyHandle,
   1.204 +                       const TPM_STORED_DATA       *sealedData,
   1.205 +                       const TPM_AUTHDATA          *key_usage_auth,
   1.206 +                       const TPM_AUTHDATA          *data_usage_auth,
   1.207 +                       buffer_t                    *outData,
   1.208 +                       TCS_AUTH                    *auth,
   1.209 +                       TCS_AUTH                    *dataAuth) {
   1.210 +
   1.211 +  TPM_RESULT status = TPM_SUCCESS;
   1.212 +  TPM_COMMAND_CODE command = TPM_ORD_Unseal;
   1.213 +
   1.214 +  BYTE *paramText;        // Digest to make Auth.
   1.215 +  UINT32 paramTextSize;
   1.216 +
   1.217 +  // Generate Extra TCS Parameters
   1.218 +  UINT32 sealDataSize, clearDataSize;
   1.219 +  BYTE *flatSealedData= (BYTE *) malloc(sizeof(TPM_VERSION) +
   1.220 +                                        2 * sizeof(UINT32) +
   1.221 +                                        sealedData->sealInfoSize +
   1.222 +                                        sealedData->encDataSize),
   1.223 +       *clearData=NULL;
   1.224 +
   1.225 +  sealDataSize = BSG_Pack(BSG_TPM_STORED_DATA, sealedData, flatSealedData );
   1.226 +
   1.227 +  paramText = (BYTE *) malloc(sizeof(BYTE) *  TCPA_MAX_BUFFER_LENGTH);
   1.228 +
   1.229 +  paramTextSize = BSG_PackList(paramText, 2,
   1.230 +                               BSG_TPM_COMMAND_CODE, &command,
   1.231 +                               BSG_TPM_STORED_DATA, sealedData);
   1.232 +
   1.233 +  TPMTRYRETURN( GenerateAuth( paramText, paramTextSize,
   1.234 +                              key_usage_auth, auth) );
   1.235 +
   1.236 +  TPMTRYRETURN( GenerateAuth( paramText, paramTextSize,
   1.237 +                              data_usage_auth, dataAuth) );
   1.238 +  // Call TCS
   1.239 +  TPMTRYRETURN( TCSP_Unseal(  hContext,
   1.240 +                              keyHandle,
   1.241 +                              sealDataSize,
   1.242 +                              flatSealedData,
   1.243 +                              auth,
   1.244 +                              dataAuth,
   1.245 +                              &clearDataSize,
   1.246 +                              &clearData) );
   1.247 +
   1.248 +  // Verify Auth
   1.249 +  struct pack_buf_t clearData_pack = {clearDataSize, clearData};
   1.250 +
   1.251 +  paramTextSize = BSG_PackList(paramText, 3,
   1.252 +                               BSG_TPM_RESULT, &status,
   1.253 +                               BSG_TPM_COMMAND_CODE, &command,
   1.254 +                               BSG_TPM_SIZE32_DATA, &clearData_pack);
   1.255 +
   1.256 +  TPMTRYRETURN( VerifyAuth( paramText, paramTextSize,
   1.257 +                            key_usage_auth, auth,
   1.258 +                            hContext) );
   1.259 +
   1.260 +  TPMTRYRETURN( VerifyAuth( paramText, paramTextSize,
   1.261 +                            data_usage_auth, dataAuth,
   1.262 +                            hContext) );
   1.263 +
   1.264 +  // Unpack/return key structure
   1.265 +  TPMTRYRETURN( buffer_init(outData, clearDataSize, clearData) );
   1.266 +
   1.267 +  goto egress;
   1.268 +
   1.269 + abort_egress:
   1.270 + egress:
   1.271 +
   1.272 +  if (flatSealedData)
   1.273 +    TCS_FreeMemory( hContext, clearData);
   1.274 +
   1.275 +  free(paramText);
   1.276 +  return status;
   1.277 +}
   1.278 +
   1.279 +
   1.280  // Function Reaches into unsupported TCS command, beware.
   1.281  TPM_RESULT VTSP_RawTransmit(const TCS_CONTEXT_HANDLE    hContext,
   1.282                              const buffer_t *inbuf,
     2.1 --- a/tools/vtpm_manager/manager/vtsp.h	Tue Jan 03 19:06:14 2006 +0100
     2.2 +++ b/tools/vtpm_manager/manager/vtsp.h	Wed Jan 04 11:37:41 2006 +0100
     2.3 @@ -100,4 +100,22 @@ TPM_RESULT VTSP_Bind(   CRYPTO_INFO *cry
     2.4              const buffer_t *inData, 
     2.5              buffer_t *outData);
     2.6                          
     2.7 +TPM_RESULT VTSP_Seal(const TCS_CONTEXT_HANDLE    hContext,
     2.8 +                     const TPM_KEY_HANDLE        keyHandle,
     2.9 +                     const TPM_AUTHDATA          *sealDataAuth,
    2.10 +                     const TPM_PCR_COMPOSITE     *pcrComp,
    2.11 +                     const buffer_t              *inData,
    2.12 +                     TPM_STORED_DATA             *sealedData,                                   
    2.13 +                     const TPM_SECRET            *osapSharedSecret,
    2.14 +                     TCS_AUTH                    *auth);
    2.15 +
    2.16 +TPM_RESULT VTSP_Unseal(const TCS_CONTEXT_HANDLE    hContext,
    2.17 +                       const TPM_KEY_HANDLE        keyHandle,
    2.18 +                       const TPM_STORED_DATA       *sealedData,
    2.19 +                       const TPM_AUTHDATA          *key_usage_auth,
    2.20 +                       const TPM_AUTHDATA          *data_usage_auth,
    2.21 +                       buffer_t                    *outData,
    2.22 +                       TCS_AUTH                    *auth,
    2.23 +                       TCS_AUTH                    *dataAuth);
    2.24 +
    2.25  #endif //_VTSP_H_
     3.1 --- a/tools/vtpm_manager/tcs/tcs.c	Tue Jan 03 19:06:14 2006 +0100
     3.2 +++ b/tools/vtpm_manager/tcs/tcs.c	Wed Jan 04 11:37:41 2006 +0100
     3.3 @@ -636,7 +636,7 @@ TPM_RESULT TCSP_Seal(   TCS_CONTEXT_HAND
     3.4    TDDL_UINT32  OutLength = TCPA_MAX_BUFFER_LENGTH;
     3.5    
     3.6    // check input params
     3.7 -  if (inData == NULL || pubAuth == NULL || SealedDataSize == NULL || *SealedData == NULL)
     3.8 +  if (inData == NULL || pubAuth == NULL || SealedDataSize == NULL || SealedData == NULL)
     3.9      return TPM_BAD_PARAMETER;
    3.10    
    3.11    // Convert Byte Input parameter in the input byte stream InBuf