[34] | 1 | // =================================================================== |
---|
| 2 | // |
---|
| 3 | // Copyright (c) 2005, Intel Corp. |
---|
| 4 | // All rights reserved. |
---|
| 5 | // |
---|
| 6 | // Redistribution and use in source and binary forms, with or without |
---|
| 7 | // modification, are permitted provided that the following conditions |
---|
| 8 | // are met: |
---|
| 9 | // |
---|
| 10 | // * Redistributions of source code must retain the above copyright |
---|
| 11 | // notice, this list of conditions and the following disclaimer. |
---|
| 12 | // * Redistributions in binary form must reproduce the above |
---|
| 13 | // copyright notice, this list of conditions and the following |
---|
| 14 | // disclaimer in the documentation and/or other materials provided |
---|
| 15 | // with the distribution. |
---|
| 16 | // * Neither the name of Intel Corporation nor the names of its |
---|
| 17 | // contributors may be used to endorse or promote products derived |
---|
| 18 | // from this software without specific prior written permission. |
---|
| 19 | // |
---|
| 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
| 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
| 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
---|
| 23 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
---|
| 24 | // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
---|
| 25 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
---|
| 26 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
---|
| 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
| 28 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
---|
| 29 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 30 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
---|
| 31 | // OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | // =================================================================== |
---|
| 33 | // |
---|
| 34 | // vtpmpriv.h |
---|
| 35 | // |
---|
| 36 | // Structures and functions private to the manager |
---|
| 37 | // |
---|
| 38 | // ================================================================== |
---|
| 39 | |
---|
| 40 | #ifndef __VTPMPRIV_H__ |
---|
| 41 | #define __VTPMPRIV_H__ |
---|
| 42 | |
---|
| 43 | #include "vtpm_manager.h" |
---|
| 44 | #include "tcg.h" |
---|
| 45 | #include "tcs.h" |
---|
| 46 | #include "buffer.h" |
---|
| 47 | #include "crypto.h" |
---|
| 48 | #include "vtpm_ipc.h" |
---|
| 49 | |
---|
| 50 | #define VTPM_MANAGER_GEN 2 // This is incremented when the manager's table |
---|
| 51 | // is changed. It's used for backwards compatability |
---|
| 52 | |
---|
| 53 | #define STATE_FILE "/var/vtpm/VTPM" |
---|
| 54 | #define DMI_NVM_FILE "/var/vtpm/vtpm_dm_%d.data" |
---|
| 55 | #define VTPM_CTL_DM 0 |
---|
| 56 | |
---|
| 57 | // ------------------------ Private Structures ----------------------- |
---|
| 58 | typedef struct VTPM_DMI_RESOURCE_T { |
---|
| 59 | // I/O info for Manager to talk to DMI's and controllers |
---|
| 60 | vtpm_ipc_handle_t *tx_vtpm_ipc_h; // TX VTPM Results to DMI |
---|
| 61 | vtpm_ipc_handle_t *rx_vtpm_ipc_h; // RX VTPM Commands from DMI |
---|
| 62 | vtpm_ipc_handle_t *tx_tpm_ipc_h; // TX TPM Commands to DMI |
---|
| 63 | vtpm_ipc_handle_t *rx_tpm_ipc_h; // RX TPM Results from DMI |
---|
| 64 | |
---|
| 65 | #ifndef VTPM_MULTI_VM |
---|
| 66 | pid_t dmi_pid; |
---|
| 67 | #endif |
---|
| 68 | |
---|
| 69 | // Non-persistent Information |
---|
| 70 | bool connected; |
---|
| 71 | UINT32 dmi_domain_id; |
---|
| 72 | TCS_CONTEXT_HANDLE TCSContext; // TCS Handle |
---|
| 73 | char *NVMLocation; // NULL term string indicating location |
---|
| 74 | // of NVM. |
---|
| 75 | // Persistent Information about DMI |
---|
| 76 | UINT32 dmi_id; |
---|
| 77 | BYTE dmi_type; |
---|
| 78 | TPM_DIGEST NVM_measurement; // Equal to the SHA1 of the blob |
---|
| 79 | TPM_DIGEST DMI_measurement; // Correct measurement of the owning DMI |
---|
| 80 | } VTPM_DMI_RESOURCE; |
---|
| 81 | |
---|
| 82 | typedef struct tdVTPM_MIGKEY_LIST { |
---|
| 83 | UINT32 name_size; |
---|
| 84 | BYTE *name; // Name of destination (IP addr, domain name, etc) |
---|
| 85 | CRYPTO_INFO key; |
---|
| 86 | struct tdVTPM_MIGKEY_LIST *next; |
---|
| 87 | } VTPM_MIGKEY_LIST; |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | typedef struct tdVTPM_GLOBALS { |
---|
| 91 | // Non-persistent data |
---|
| 92 | #ifndef VTPM_MULTI_VM |
---|
| 93 | pid_t master_pid; |
---|
| 94 | #endif |
---|
| 95 | |
---|
| 96 | int connected_dmis; // To close guest_rx when no dmis are connected |
---|
| 97 | |
---|
| 98 | struct hashtable *dmi_map; // Table of all DMI's known indexed by persistent instance # |
---|
| 99 | VTPM_MIGKEY_LIST *mig_keys; // Table of migration keys |
---|
| 100 | // Currently keys are loaded at migration time, |
---|
| 101 | // TODO: Make VTPM man store a keys persistently |
---|
| 102 | // and update script to check if key is needed |
---|
| 103 | // before fetching it. |
---|
| 104 | |
---|
| 105 | TCS_CONTEXT_HANDLE manager_tcs_handle; // TCS Handle used by manager |
---|
| 106 | TPM_HANDLE storageKeyHandle; // Key used by persistent store |
---|
| 107 | CRYPTO_INFO storageKey; // For software encryption |
---|
| 108 | CRYPTO_INFO bootKey; // For saving table |
---|
| 109 | TCS_AUTH keyAuth; // OIAP session for storageKey |
---|
| 110 | |
---|
| 111 | // Persistent Data |
---|
| 112 | TPM_AUTHDATA owner_usage_auth; // OwnerAuth of real TPM |
---|
| 113 | buffer_t storageKeyWrap; // Wrapped copy of storageKey |
---|
| 114 | TPM_AUTHDATA srk_usage_auth; |
---|
| 115 | TPM_AUTHDATA storage_key_usage_auth; |
---|
| 116 | |
---|
| 117 | buffer_t bootKeyWrap; // Wrapped copy of boot key |
---|
| 118 | |
---|
| 119 | }VTPM_GLOBALS; |
---|
| 120 | |
---|
| 121 | // --------------------------- Global Values -------------------------- |
---|
| 122 | extern VTPM_GLOBALS *vtpm_globals; // Key info and DMI states |
---|
| 123 | extern const TPM_AUTHDATA SRK_AUTH; // SRK Well Known Auth Value |
---|
| 124 | |
---|
| 125 | // ********************** VTPM Functions ************************* |
---|
| 126 | TPM_RESULT VTPM_Init_Manager(); // Start VTPM Service |
---|
| 127 | void VTPM_Stop_Manager(); // Stop VTPM Service |
---|
| 128 | TPM_RESULT VTPM_Manager_Handler(vtpm_ipc_handle_t *tx_ipc_h, |
---|
| 129 | vtpm_ipc_handle_t *rx_ipc_h, |
---|
| 130 | BOOL fw_tpm, // Should forward TPM cmds |
---|
| 131 | vtpm_ipc_handle_t *fw_tx_ipc_h, |
---|
| 132 | vtpm_ipc_handle_t *fw_rx_ipc_h, |
---|
| 133 | BOOL is_priv, |
---|
| 134 | char *client_name); |
---|
| 135 | |
---|
| 136 | // ********************** Command Handler Prototypes *********************** |
---|
| 137 | |
---|
| 138 | TPM_RESULT VTPM_Handle_Load_NVM( VTPM_DMI_RESOURCE *myDMI, |
---|
| 139 | const buffer_t *inbuf, |
---|
| 140 | buffer_t *outbuf); |
---|
| 141 | |
---|
| 142 | TPM_RESULT VTPM_Handle_Save_NVM( VTPM_DMI_RESOURCE *myDMI, |
---|
| 143 | const buffer_t *inbuf, |
---|
| 144 | buffer_t *outbuf); |
---|
| 145 | |
---|
| 146 | TPM_RESULT VTPM_Handle_TPM_Command( VTPM_DMI_RESOURCE *dmi, |
---|
| 147 | buffer_t *inbuf, |
---|
| 148 | buffer_t *outbuf); |
---|
| 149 | |
---|
| 150 | TPM_RESULT VTPM_Handle_New_DMI(const buffer_t *param_buf); |
---|
| 151 | |
---|
| 152 | TPM_RESULT VTPM_Handle_Close_DMI(const buffer_t *param_buf); |
---|
| 153 | |
---|
| 154 | TPM_RESULT VTPM_Handle_Delete_DMI(const buffer_t *param_buf); |
---|
| 155 | |
---|
| 156 | TPM_RESULT VTPM_Handle_Migrate_In( const buffer_t *param_buf, |
---|
| 157 | buffer_t *result_buf); |
---|
| 158 | |
---|
| 159 | TPM_RESULT VTPM_Handle_Migrate_Out ( const buffer_t *param_buf, |
---|
| 160 | buffer_t *result_buf); |
---|
| 161 | |
---|
| 162 | TPM_RESULT VTPM_Handle_Get_Migration_key( const buffer_t *param_buf, |
---|
| 163 | buffer_t *result_buf); |
---|
| 164 | |
---|
| 165 | TPM_RESULT VTPM_SaveManagerData(void); |
---|
| 166 | TPM_RESULT VTPM_LoadManagerData(void); |
---|
| 167 | |
---|
| 168 | TPM_RESULT VTPM_New_DMI_Extra(VTPM_DMI_RESOURCE *dmi_res, BYTE vm_type, BYTE startup_mode); |
---|
| 169 | |
---|
| 170 | TPM_RESULT VTPM_Close_DMI_Extra(VTPM_DMI_RESOURCE *dmi_res); |
---|
| 171 | |
---|
| 172 | // Helper functions |
---|
| 173 | TPM_RESULT close_dmi(VTPM_DMI_RESOURCE *dmi_res); |
---|
| 174 | TPM_RESULT init_dmi(UINT32 dmi_id, BYTE type, VTPM_DMI_RESOURCE **dmi_res); |
---|
| 175 | |
---|
| 176 | TPM_RESULT envelope_encrypt(const buffer_t *inbuf, |
---|
| 177 | CRYPTO_INFO *asymkey, |
---|
| 178 | buffer_t *sealed_data); |
---|
| 179 | |
---|
| 180 | TPM_RESULT envelope_decrypt(const buffer_t *cipher, |
---|
| 181 | TCS_CONTEXT_HANDLE TCSContext, |
---|
| 182 | TPM_HANDLE keyHandle, |
---|
| 183 | const TPM_AUTHDATA *key_usage_auth, |
---|
| 184 | buffer_t *unsealed_data); |
---|
| 185 | |
---|
| 186 | #endif // __VTPMPRIV_H__ |
---|