1
// ===================================================================
3
// Copyright (c) 2005, Intel Corp.
4
// All rights reserved.
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions
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.
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
// ===================================================================
36
// Structures and functions private to the manager
38
// ==================================================================
40
#ifndef __VTPMPRIV_H__
41
#define __VTPMPRIV_H__
43
#include "vtpm_manager.h"
50
#define VTPM_MANAGER_GEN 2 // This is incremented when the manager's table
51
// is changed. It's used for backwards compatability
53
#define STATE_FILE "/var/vtpm/VTPM"
54
#define DMI_NVM_FILE "/var/vtpm/vtpm_dm_%d.data"
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
69
// Non-persistent Information
72
TCS_CONTEXT_HANDLE TCSContext; // TCS Handle
73
char *NVMLocation; // NULL term string indicating location
75
// Persistent Information about DMI
78
TPM_DIGEST NVM_measurement; // Equal to the SHA1 of the blob
79
TPM_DIGEST DMI_measurement; // Correct measurement of the owning DMI
82
typedef struct tdVTPM_MIGKEY_LIST {
84
BYTE *name; // Name of destination (IP addr, domain name, etc)
86
struct tdVTPM_MIGKEY_LIST *next;
90
typedef struct tdVTPM_GLOBALS {
91
// Non-persistent data
96
int connected_dmis; // To close guest_rx when no dmis are connected
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.
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
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;
117
buffer_t bootKeyWrap; // Wrapped copy of boot key
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
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,
136
// ********************** Command Handler Prototypes ***********************
138
TPM_RESULT VTPM_Handle_Load_NVM( VTPM_DMI_RESOURCE *myDMI,
139
const buffer_t *inbuf,
142
TPM_RESULT VTPM_Handle_Save_NVM( VTPM_DMI_RESOURCE *myDMI,
143
const buffer_t *inbuf,
146
TPM_RESULT VTPM_Handle_TPM_Command( VTPM_DMI_RESOURCE *dmi,
150
TPM_RESULT VTPM_Handle_New_DMI(const buffer_t *param_buf);
152
TPM_RESULT VTPM_Handle_Close_DMI(const buffer_t *param_buf);
154
TPM_RESULT VTPM_Handle_Delete_DMI(const buffer_t *param_buf);
156
TPM_RESULT VTPM_Handle_Migrate_In( const buffer_t *param_buf,
157
buffer_t *result_buf);
159
TPM_RESULT VTPM_Handle_Migrate_Out ( const buffer_t *param_buf,
160
buffer_t *result_buf);
162
TPM_RESULT VTPM_Handle_Get_Migration_key( const buffer_t *param_buf,
163
buffer_t *result_buf);
165
TPM_RESULT VTPM_SaveManagerData(void);
166
TPM_RESULT VTPM_LoadManagerData(void);
168
TPM_RESULT VTPM_New_DMI_Extra(VTPM_DMI_RESOURCE *dmi_res, BYTE vm_type, BYTE startup_mode);
170
TPM_RESULT VTPM_Close_DMI_Extra(VTPM_DMI_RESOURCE *dmi_res);
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);
176
TPM_RESULT envelope_encrypt(const buffer_t *inbuf,
177
CRYPTO_INFO *asymkey,
178
buffer_t *sealed_data);
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);
186
#endif // __VTPMPRIV_H__