2 * Copyright (C) 2011-2012 Sansar Choinyambuu
3 * Copyright (C) 2011-2014 Andreas Steffen
4 * HSR Hochschule fuer Technik Rapperswil
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 #include "imv_attestation_build.h"
18 #include "imv_attestation_state.h"
20 #include <tcg/pts/tcg_pts_attr_dh_nonce_params_req.h>
21 #include <tcg/pts/tcg_pts_attr_dh_nonce_finish.h>
22 #include <tcg/pts/tcg_pts_attr_get_tpm_version_info.h>
23 #include <tcg/pts/tcg_pts_attr_get_aik.h>
24 #include <tcg/pts/tcg_pts_attr_req_func_comp_evid.h>
25 #include <tcg/pts/tcg_pts_attr_gen_attest_evid.h>
27 #include <utils/debug.h>
29 bool imv_attestation_build(imv_msg_t
*out_msg
, imv_state_t
*state
,
30 pts_dh_group_t supported_dh_groups
,
31 pts_database_t
*pts_db
)
33 imv_attestation_state_t
*attestation_state
;
34 imv_attestation_handshake_state_t handshake_state
;
36 pa_tnc_attr_t
*attr
= NULL
;
38 attestation_state
= (imv_attestation_state_t
*)state
;
39 handshake_state
= attestation_state
->get_handshake_state(attestation_state
);
40 pts
= attestation_state
->get_pts(attestation_state
);
42 switch (handshake_state
)
44 case IMV_ATTESTATION_STATE_NONCE_REQ
:
48 /* Send DH nonce parameters request attribute */
49 min_nonce_len
= lib
->settings
->get_int(lib
->settings
,
50 "libimcv.plugins.imv-attestation.min_nonce_len", 0);
51 attr
= tcg_pts_attr_dh_nonce_params_req_create(min_nonce_len
,
53 attr
->set_noskip_flag(attr
, TRUE
);
54 out_msg
->add_attribute(out_msg
, attr
);
56 attestation_state
->set_handshake_state(attestation_state
,
57 IMV_ATTESTATION_STATE_TPM_INIT
);
60 case IMV_ATTESTATION_STATE_TPM_INIT
:
62 pts_meas_algorithms_t selected_algorithm
;
63 chunk_t initiator_value
, initiator_nonce
;
65 /* Send DH nonce finish attribute */
66 selected_algorithm
= pts
->get_meas_algorithm(pts
);
67 pts
->get_my_public_value(pts
, &initiator_value
, &initiator_nonce
);
68 attr
= tcg_pts_attr_dh_nonce_finish_create(selected_algorithm
,
69 initiator_value
, initiator_nonce
);
70 attr
->set_noskip_flag(attr
, TRUE
);
71 out_msg
->add_attribute(out_msg
, attr
);
73 /* Send Get TPM Version attribute */
74 attr
= tcg_pts_attr_get_tpm_version_info_create();
75 attr
->set_noskip_flag(attr
, TRUE
);
76 out_msg
->add_attribute(out_msg
, attr
);
78 /* Send Get AIK attribute */
79 attr
= tcg_pts_attr_get_aik_create();
80 attr
->set_noskip_flag(attr
, TRUE
);
81 out_msg
->add_attribute(out_msg
, attr
);
83 attestation_state
->set_handshake_state(attestation_state
,
84 IMV_ATTESTATION_STATE_COMP_EVID
);
87 case IMV_ATTESTATION_STATE_COMP_EVID
:
89 tcg_pts_attr_req_func_comp_evid_t
*attr_cast
;
90 enumerator_t
*enumerator
;
91 pts_comp_func_name_t
*name
;
96 bool first_component
= TRUE
;
98 attestation_state
->set_handshake_state(attestation_state
,
99 IMV_ATTESTATION_STATE_END
);
101 if (!pts
->get_aik_keyid(pts
, &keyid
))
103 DBG1(DBG_IMV
, "retrieval of AIK keyid failed");
108 DBG1(DBG_IMV
, "pts database not available");
111 if (pts_db
->check_aik_keyid(pts_db
, keyid
, &kid
) != SUCCESS
)
115 enumerator
= attestation_state
->create_component_enumerator(
117 while (enumerator
->enumerate(enumerator
, &flags
, &depth
, &name
))
121 attr
= tcg_pts_attr_req_func_comp_evid_create();
122 attr
->set_noskip_flag(attr
, TRUE
);
123 first_component
= FALSE
;
124 DBG2(DBG_IMV
, "evidence request by");
126 name
->log(name
, " ");
128 /* TODO check flags against negotiated_caps */
129 attr_cast
= (tcg_pts_attr_req_func_comp_evid_t
*)attr
;
130 attr_cast
->add_component(attr_cast
, flags
, depth
, name
);
132 enumerator
->destroy(enumerator
);
136 /* Send Request Functional Component Evidence attribute */
137 out_msg
->add_attribute(out_msg
, attr
);
139 /* Send Generate Attestation Evidence attribute */
140 attr
= tcg_pts_attr_gen_attest_evid_create();
141 attr
->set_noskip_flag(attr
, TRUE
);
142 out_msg
->add_attribute(out_msg
, attr
);
144 attestation_state
->set_handshake_state(attestation_state
,
145 IMV_ATTESTATION_STATE_EVID_FINAL
);
149 case IMV_ATTESTATION_STATE_EVID_FINAL
:
150 if (attestation_state
->components_finalized(attestation_state
))
152 attestation_state
->set_handshake_state(attestation_state
,
153 IMV_ATTESTATION_STATE_END
);