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
// ===================================================================
41
#include "vtpm_migrator.h"
42
#include "vtpm_manager.h"
44
TPM_RESULT handle_vtpm_mig_step2(char *server_addr,
47
TPM_RESULT status, cmd_status;
48
buffer_t out_param_buf=NULL_BUF, mig_key_buf=NULL_BUF, empty_buf=NULL_BUF;
50
struct pack_buf_t addr_data32;
52
//===== Get Destination's Public Migration Key ======
53
TPMTRYRETURN( vtpm_migratord_open(server_addr) );
55
TPMTRYRETURN( vtpm_migratord_command(VTPM_MORD_MIG_STEP2,
59
vtpm_migratord_close();
61
TPMTRYRETURN(cmd_status);
63
//===== Load migration key into vtpm_manager ========
65
addr_data32.data = (BYTE *)server_addr;
66
addr_data32.size = strlen(server_addr) + 1; // Include the null
68
TPMTRYRETURN ( buffer_init ( &out_param_buf,
69
sizeof(UINT32) + addr_data32.size +buffer_len(&mig_key_buf),
72
offset = BSG_PackList(out_param_buf.bytes, 1,
73
BSG_TPM_SIZE32_DATA, &addr_data32);
75
memcpy(out_param_buf.bytes + offset , mig_key_buf.bytes, buffer_len(&mig_key_buf) );
77
TPMTRYRETURN ( vtpm_manager_open() );
79
TPMTRYRETURN ( vtpm_manager_command(VTPM_ORD_LOAD_MIG_KEY,
86
TPMTRYRETURN(cmd_status);
93
buffer_free(&mig_key_buf);
94
buffer_free(&out_param_buf);
100
TPM_RESULT handle_vtpm_mig_step3(char *server_addr,
103
TPM_RESULT status, cmd_status;
104
buffer_t out_param_buf=NULL_BUF, state_buf=NULL_BUF, empty_buf=NULL_BUF;
105
struct pack_buf_t addr_data32, name_data32, state_data32;
107
//===== Get vtpm state from vtpm_manager ========
108
addr_data32.data = (BYTE *)server_addr;
109
addr_data32.size = strlen(server_addr) + 1; // Include the null
111
TPMTRYRETURN ( buffer_init ( &out_param_buf,
112
(2 * sizeof(UINT32)) + addr_data32.size,
115
BSG_PackList(out_param_buf.bytes, 2,
116
BSG_TYPE_UINT32, &instance,
117
BSG_TPM_SIZE32_DATA, &addr_data32);
119
TPMTRYRETURN ( vtpm_manager_open() );
121
TPMTRYRETURN ( vtpm_manager_command(VTPM_ORD_MIGRATE_OUT,
126
vtpm_manager_close();
128
TPMTRYRETURN(cmd_status);
130
TPMTRYRETURN( buffer_free( &out_param_buf ) );
132
//===== Send vtpm state to destination ======
133
name_data32.data = (BYTE *)name;
134
name_data32.size = strlen(name) + 1; // Include the null
135
state_data32.data = state_buf.bytes;
136
state_data32.size = buffer_len(&state_buf);
138
TPMTRYRETURN( buffer_init( &out_param_buf,
139
2 * sizeof(UINT32) + name_data32.size + state_data32.size,
142
BSG_PackList(out_param_buf.bytes, 2,
143
BSG_TPM_SIZE32_DATA, &name_data32,
144
BSG_TPM_SIZE32_DATA, &state_data32);
146
TPMTRYRETURN( vtpm_migratord_open(server_addr) );
148
TPMTRYRETURN( vtpm_migratord_command(VTPM_MORD_MIG_STEP3,
152
vtpm_migratord_close();
154
TPMTRYRETURN(cmd_status);
161
buffer_free( &out_param_buf);
162
buffer_free( &state_buf);
163
buffer_free( &empty_buf);
169
// Usage vtpm_migrator addr domain_name instance step
171
int main(int argc, char **argv) {
173
/* variables for processing of command */
174
TPM_RESULT status = TPM_FAIL;
175
char *server_addr, *name;
176
UINT32 instance, step;
179
vtpmlogerror(VTPM_LOG_VTPM, "Usage: vtpm_migrator addr vm_name instance step\n");
180
vtpmlogerror(VTPM_LOG_VTPM, " params given %d\n", argc);
181
status= TPM_BAD_PARAMETER;
185
server_addr = argv[1];
187
instance = atoi( argv[3] );
188
step = atoi( argv[4] );
191
case VTPM_MORD_MIG_STEP2:
192
status = handle_vtpm_mig_step2(server_addr, name, instance);
195
case VTPM_MORD_MIG_STEP3:
196
status = handle_vtpm_mig_step3(server_addr, name, instance);
200
status = TPM_BAD_PARAMETER;