OLD | NEW |
(Empty) | |
| 1 /* Software-based Mobile Trusted Module (MTM) Emulator |
| 2 * Copyright (C) 2004-2010 Mario Strasser <mast@gmx.net> |
| 3 * |
| 4 * This module is free software; you can redistribute it and/or modify |
| 5 * it under the terms of the GNU General Public License as published |
| 6 * by the Free Software Foundation; either version 2 of the License, |
| 7 * or (at your option) any later version. |
| 8 * |
| 9 * This module is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * $Id$ |
| 15 */ |
| 16 |
| 17 #include "mtm_structures.h" |
| 18 #include "mtm_marshalling.h" |
| 19 #include "mtm_data.h" |
| 20 #include "tpm/tpm_data.h" |
| 21 #include "tpm/tpm_commands.h" |
| 22 |
| 23 static inline TPM_RESULT return_UINT32(UINT32 *respSize, BYTE **resp, UINT32 val
ue) |
| 24 { |
| 25 UINT32 len = *respSize = 4; |
| 26 BYTE *ptr = *resp = tpm_malloc(*respSize); |
| 27 if (ptr == NULL || tpm_marshal_UINT32(&ptr, &len, value)) { |
| 28 tpm_free(*resp); |
| 29 return TPM_FAIL; |
| 30 } |
| 31 return TPM_SUCCESS; |
| 32 } |
| 33 |
| 34 static inline TPM_RESULT return_BOOL(UINT32 *respSize, BYTE **resp, BOOL value) |
| 35 { |
| 36 UINT32 len = *respSize = 1; |
| 37 BYTE *ptr = *resp = tpm_malloc(*respSize); |
| 38 if (ptr == NULL || tpm_marshal_BOOL(&ptr, &len, value)) { |
| 39 tpm_free(*resp); |
| 40 return TPM_FAIL; |
| 41 } |
| 42 return TPM_SUCCESS; |
| 43 } |
| 44 |
| 45 #define return_BYTE return_BOOL |
| 46 |
| 47 static TPM_RESULT cap_ord(UINT32 subCapSize, BYTE *subCap, |
| 48 UINT32 *respSize, BYTE **resp) |
| 49 { |
| 50 TPM_COMMAND_CODE ord; |
| 51 if (tpm_unmarshal_TPM_COMMAND_CODE(&subCap, &subCapSize, &ord)) |
| 52 return TPM_BAD_MODE; |
| 53 switch (ord) { |
| 54 case MTM_ORD_InstallRIM: |
| 55 case MTM_ORD_LoadVerificationKey: |
| 56 case MTM_ORD_LoadVerificationRootKeyDisable: |
| 57 case MTM_ORD_VerifyRIMCert: |
| 58 case MTM_ORD_VerifyRIMCertAndExtend: |
| 59 case MTM_ORD_IncrementBootstrapCounter: |
| 60 case MTM_ORD_SetVerifiedPCRSelection: |
| 61 return return_BOOL(respSize, resp, TRUE); |
| 62 default: |
| 63 return return_BOOL(respSize, resp, FALSE); |
| 64 } |
| 65 } |
| 66 |
| 67 static TPM_RESULT cap_mtm_permanent_data(UINT32 subCapSize, BYTE *subCap, |
| 68 UINT32 *r
espSize, BYTE **resp) |
| 69 { |
| 70 UINT32 subCapVal, len; |
| 71 BYTE* ptr; |
| 72 |
| 73 /* unmarshal subCap */ |
| 74 if (tpm_unmarshal_UINT32(&subCap, &subCapSize, &subCapVal) != 0) |
| 75 return TPM_BAD_PARAMETER; |
| 76 switch (subCapVal) { |
| 77 |
| 78 case 1: |
| 79 return TPM_FAIL; |
| 80 break; |
| 81 |
| 82 case 2: |
| 83 *respSize = len = sizeof_TPM_PCR_SELECTION(mtmData.permanent.data.verified
PCRs); |
| 84 *resp = ptr = tpm_malloc(*respSize); |
| 85 if (*resp == NULL |
| 86 || tpm_marshal_TPM_PCR_SELECTION(&ptr, &len, &mtmData.permanent.data.v
erifiedPCRs)) { |
| 87 tpm_free(*resp); |
| 88 return TPM_FAIL; |
| 89 } |
| 90 |
| 91 case 3: |
| 92 return return_UINT32(respSize, resp, |
| 93 tpmData.permanent.data.counters[MTM_COUNTER_SELECT_BOOTSTRAP].counter); |
| 94 |
| 95 case 4: |
| 96 return return_UINT32(respSize, resp, mtmData.permanent.data.counterRimProt
ectId); |
| 97 |
| 98 case 5: |
| 99 return return_UINT32(respSize, resp, mtmData.permanent.data.counterStorage
ProtectId); |
| 100 |
| 101 case 6: |
| 102 return return_BYTE(respSize, resp, mtmData.permanent.data.specMajor); |
| 103 |
| 104 case 7: |
| 105 return return_BYTE(respSize, resp, mtmData.permanent.data.specMinor); |
| 106 |
| 107 case 8: |
| 108 return return_BYTE(respSize, resp, mtmData.permanent.data.loadVerification
KeyMethods); |
| 109 |
| 110 default: |
| 111 return TPM_BAD_PARAMETER; |
| 112 |
| 113 } |
| 114 return TPM_SUCCESS; |
| 115 } |
| 116 |
| 117 TPM_RESULT MTM_GetCapability(TPM_CAPABILITY_AREA capArea, UINT32 subCapSize, |
| 118 BYTE *subCap, UINT32 *respSize, BYTE **resp) |
| 119 { |
| 120 info("MTM_GetCapability()"); |
| 121 switch (capArea) { |
| 122 |
| 123 case TPM_CAP_ORD: |
| 124 debug("[MTM_CAP_ORD]"); |
| 125 TPM_RESULT res = cap_ord(subCapSize, subCap, respSize, resp); |
| 126 if (res == TPM_SUCCESS && resp[0] == FALSE) { |
| 127 res = TPM_GetCapability(capArea, subCapSize, subCap, respSize, resp); |
| 128 } |
| 129 return res; |
| 130 |
| 131 case TPM_CAP_MTM_PERMANENT_DATA: |
| 132 debug("[TPM_CAP_MTM_PERMANENT_DATA]"); |
| 133 return cap_mtm_permanent_data(subCapSize, subCap, respSize, resp); |
| 134 |
| 135 default: |
| 136 return TPM_GetCapability(capArea, subCapSize, subCap, respSize, resp); |
| 137 |
| 138 } |
| 139 } |
| 140 |
OLD | NEW |