Implemented Diffie Hellman Nonce attributes
[strongswan.git] / src / libpts / tcg / tcg_attr.c
1 /*
2 * Copyright (C) 2011 Andreas Steffen, HSR Hochschule fuer Technik Rapperswil
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 */
14
15 #include "tcg_attr.h"
16 #include "tcg/tcg_pts_attr_proto_caps.h"
17 #include "tcg/tcg_pts_attr_dh_nonce_params_req.h"
18 #include "tcg/tcg_pts_attr_dh_nonce_params_resp.h"
19 #include "tcg/tcg_pts_attr_dh_nonce_finish.h"
20 #include "tcg/tcg_pts_attr_meas_algo.h"
21 #include "tcg/tcg_pts_attr_get_tpm_version_info.h"
22 #include "tcg/tcg_pts_attr_tpm_version_info.h"
23 #include "tcg/tcg_pts_attr_get_aik.h"
24 #include "tcg/tcg_pts_attr_aik.h"
25 #include "tcg/tcg_pts_attr_req_funct_comp_evid.h"
26 #include "tcg/tcg_pts_attr_gen_attest_evid.h"
27 #include "tcg/tcg_pts_attr_simple_comp_evid.h"
28 #include "tcg/tcg_pts_attr_simple_evid_final.h"
29 #include "tcg/tcg_pts_attr_req_file_meas.h"
30 #include "tcg/tcg_pts_attr_file_meas.h"
31 #include "tcg/tcg_pts_attr_req_file_meta.h"
32 #include "tcg/tcg_pts_attr_unix_file_meta.h"
33
34 ENUM_BEGIN(tcg_attr_names, TCG_PTS_REQ_FUNCT_COMP_EVID,
35 TCG_PTS_REQ_FUNCT_COMP_EVID,
36 "Request Functional Component Evidence");
37 ENUM_NEXT(tcg_attr_names, TCG_PTS_GEN_ATTEST_EVID,
38 TCG_PTS_GEN_ATTEST_EVID,
39 TCG_PTS_REQ_FUNCT_COMP_EVID,
40 "Generate Attestation Evidence");
41 ENUM_NEXT(tcg_attr_names, TCG_PTS_SIMPLE_COMP_EVID,
42 TCG_PTS_SIMPLE_COMP_EVID,
43 TCG_PTS_GEN_ATTEST_EVID,
44 "Simple Component Evidence");
45 ENUM_NEXT(tcg_attr_names, TCG_PTS_SIMPLE_EVID_FINAL,
46 TCG_PTS_SIMPLE_EVID_FINAL,
47 TCG_PTS_SIMPLE_COMP_EVID,
48 "Simple Evidence Final");
49 ENUM_NEXT(tcg_attr_names, TCG_PTS_VERIFICATION_RESULT,
50 TCG_PTS_VERIFICATION_RESULT,
51 TCG_PTS_SIMPLE_EVID_FINAL,
52 "Verification Result");
53 ENUM_NEXT(tcg_attr_names, TCG_PTS_INTEG_REPORT,
54 TCG_PTS_INTEG_REPORT,
55 TCG_PTS_VERIFICATION_RESULT,
56 "Integrity Report");
57 ENUM_NEXT(tcg_attr_names, TCG_PTS_REQ_FILE_META,
58 TCG_PTS_REQ_FILE_META,
59 TCG_PTS_INTEG_REPORT,
60 "Request File Metadata");
61 ENUM_NEXT(tcg_attr_names, TCG_PTS_WIN_FILE_META,
62 TCG_PTS_WIN_FILE_META,
63 TCG_PTS_REQ_FILE_META,
64 "Windows-Style File Metadata");
65 ENUM_NEXT(tcg_attr_names, TCG_PTS_UNIX_FILE_META,
66 TCG_PTS_UNIX_FILE_META,
67 TCG_PTS_WIN_FILE_META,
68 "Unix-Style File Metadata");
69 ENUM_NEXT(tcg_attr_names, TCG_PTS_REQ_REGISTRY_VALUE,
70 TCG_PTS_REQ_REGISTRY_VALUE,
71 TCG_PTS_UNIX_FILE_META,
72 "Request Registry Value");
73 ENUM_NEXT(tcg_attr_names, TCG_PTS_REGISTRY_VALUE,
74 TCG_PTS_REGISTRY_VALUE,
75 TCG_PTS_REQ_REGISTRY_VALUE,
76 "Registry Value");
77 ENUM_NEXT(tcg_attr_names, TCG_PTS_REQ_FILE_MEAS,
78 TCG_PTS_REQ_FILE_MEAS,
79 TCG_PTS_REGISTRY_VALUE,
80 "Request File Measurement");
81 ENUM_NEXT(tcg_attr_names, TCG_PTS_FILE_MEAS,
82 TCG_PTS_FILE_MEAS,
83 TCG_PTS_REQ_FILE_MEAS,
84 "File Measurement");
85 ENUM_NEXT(tcg_attr_names, TCG_PTS_REQ_INTEG_MEAS_LOG,
86 TCG_PTS_REQ_INTEG_MEAS_LOG,
87 TCG_PTS_FILE_MEAS,
88 "Request Integrity Measurement Log");
89 ENUM_NEXT(tcg_attr_names, TCG_PTS_INTEG_MEAS_LOG,
90 TCG_PTS_INTEG_MEAS_LOG,
91 TCG_PTS_REQ_INTEG_MEAS_LOG,
92 "Integrity Measurement Log");
93 ENUM_NEXT(tcg_attr_names, TCG_PTS_REQ_PROTO_CAPS,
94 TCG_PTS_REQ_PROTO_CAPS,
95 TCG_PTS_INTEG_MEAS_LOG,
96 "Request PTS Protocol Capabilities");
97 ENUM_NEXT(tcg_attr_names, TCG_PTS_PROTO_CAPS,
98 TCG_PTS_PROTO_CAPS,
99 TCG_PTS_REQ_PROTO_CAPS,
100 "PTS Protocol Capabilities");
101 ENUM_NEXT(tcg_attr_names, TCG_PTS_DH_NONCE_PARAMS_REQ,
102 TCG_PTS_DH_NONCE_PARAMS_REQ,
103 TCG_PTS_PROTO_CAPS,
104 "DH Nonce Parameters Request");
105 ENUM_NEXT(tcg_attr_names, TCG_PTS_DH_NONCE_PARAMS_RESP,
106 TCG_PTS_DH_NONCE_PARAMS_RESP,
107 TCG_PTS_DH_NONCE_PARAMS_REQ,
108 "DH Nonce Parameters Response");
109 ENUM_NEXT(tcg_attr_names, TCG_PTS_DH_NONCE_FINISH,
110 TCG_PTS_DH_NONCE_FINISH,
111 TCG_PTS_DH_NONCE_PARAMS_RESP,
112 "DH Nonce Finish");
113 ENUM_NEXT(tcg_attr_names, TCG_PTS_MEAS_ALGO,
114 TCG_PTS_MEAS_ALGO,
115 TCG_PTS_DH_NONCE_FINISH,
116 "PTS Measurement Algorithm Request");
117 ENUM_NEXT(tcg_attr_names, TCG_PTS_MEAS_ALGO_SELECTION,
118 TCG_PTS_MEAS_ALGO_SELECTION,
119 TCG_PTS_MEAS_ALGO,
120 "PTS Measurement Algorithm");
121 ENUM_NEXT(tcg_attr_names, TCG_PTS_GET_TPM_VERSION_INFO,
122 TCG_PTS_GET_TPM_VERSION_INFO,
123 TCG_PTS_MEAS_ALGO_SELECTION,
124 "Get TPM Version Information");
125 ENUM_NEXT(tcg_attr_names, TCG_PTS_TPM_VERSION_INFO,
126 TCG_PTS_TPM_VERSION_INFO,
127 TCG_PTS_GET_TPM_VERSION_INFO,
128 "TPM Version Information");
129 ENUM_NEXT(tcg_attr_names, TCG_PTS_REQ_TEMPL_REF_MANI_SET_META,
130 TCG_PTS_REQ_TEMPL_REF_MANI_SET_META,
131 TCG_PTS_TPM_VERSION_INFO,
132 "Request Template Reference Manifest Set Metadata");
133 ENUM_NEXT(tcg_attr_names, TCG_PTS_TEMPL_REF_MANI_SET_META,
134 TCG_PTS_TEMPL_REF_MANI_SET_META,
135 TCG_PTS_REQ_TEMPL_REF_MANI_SET_META,
136 "Template Reference Manifest Set Metadata");
137 ENUM_NEXT(tcg_attr_names, TCG_PTS_UPDATE_TEMPL_REF_MANI,
138 TCG_PTS_UPDATE_TEMPL_REF_MANI,
139 TCG_PTS_TEMPL_REF_MANI_SET_META,
140 "Update Template Reference Manifest");
141 ENUM_NEXT(tcg_attr_names, TCG_PTS_GET_AIK,
142 TCG_PTS_GET_AIK,
143 TCG_PTS_UPDATE_TEMPL_REF_MANI,
144 "Get Attestation Identity Key");
145 ENUM_NEXT(tcg_attr_names, TCG_PTS_AIK,
146 TCG_PTS_AIK,
147 TCG_PTS_GET_AIK,
148 "Attestation Identity Key");
149 ENUM_END(tcg_attr_names, TCG_PTS_AIK);
150
151 /**
152 * See header
153 */
154 pa_tnc_attr_t* tcg_attr_create_from_data(u_int32_t type, chunk_t value)
155 {
156 switch (type)
157 {
158 case TCG_PTS_REQ_PROTO_CAPS:
159 return tcg_pts_attr_proto_caps_create_from_data(value, TRUE);
160 case TCG_PTS_PROTO_CAPS:
161 return tcg_pts_attr_proto_caps_create_from_data(value, FALSE);
162 case TCG_PTS_DH_NONCE_PARAMS_REQ:
163 return tcg_pts_attr_dh_nonce_params_req_create(value);
164 case TCG_PTS_DH_NONCE_PARAMS_RESP:
165 return tcg_pts_attr_dh_nonce_params_resp_create(value);
166 case TCG_PTS_DH_NONCE_FINISH:
167 return tcg_pts_attr_dh_nonce_finish_create(value);
168 case TCG_PTS_MEAS_ALGO:
169 return tcg_pts_attr_meas_algo_create_from_data(value, FALSE);
170 case TCG_PTS_MEAS_ALGO_SELECTION:
171 return tcg_pts_attr_meas_algo_create_from_data(value, TRUE);
172 case TCG_PTS_GET_TPM_VERSION_INFO:
173 return tcg_pts_attr_get_tpm_version_info_create_from_data(value);
174 case TCG_PTS_TPM_VERSION_INFO:
175 return tcg_pts_attr_tpm_version_info_create_from_data(value);
176 case TCG_PTS_GET_AIK:
177 return tcg_pts_attr_get_aik_create_from_data(value);
178 case TCG_PTS_AIK:
179 return tcg_pts_attr_aik_create_from_data(value);
180 case TCG_PTS_REQ_FUNCT_COMP_EVID:
181 return tcg_pts_attr_req_funct_comp_evid_create_from_data(value);
182 case TCG_PTS_GEN_ATTEST_EVID:
183 return tcg_pts_attr_gen_attest_evid_create_from_data(value);
184 case TCG_PTS_SIMPLE_COMP_EVID:
185 return tcg_pts_attr_simple_comp_evid_create_from_data(value);
186 case TCG_PTS_SIMPLE_EVID_FINAL:
187 return tcg_pts_attr_simple_evid_final_create_from_data(value);
188 case TCG_PTS_REQ_FILE_MEAS:
189 return tcg_pts_attr_req_file_meas_create_from_data(value);
190 case TCG_PTS_FILE_MEAS:
191 return tcg_pts_attr_file_meas_create_from_data(value);
192 case TCG_PTS_REQ_FILE_META:
193 return tcg_pts_attr_req_file_meta_create_from_data(value);
194 case TCG_PTS_UNIX_FILE_META:
195 return tcg_pts_attr_unix_file_meta_create_from_data(value);
196 case TCG_PTS_REQ_TEMPL_REF_MANI_SET_META:
197 case TCG_PTS_TEMPL_REF_MANI_SET_META:
198 case TCG_PTS_UPDATE_TEMPL_REF_MANI:
199 case TCG_PTS_VERIFICATION_RESULT:
200 case TCG_PTS_INTEG_REPORT:
201 case TCG_PTS_WIN_FILE_META:
202 case TCG_PTS_REQ_REGISTRY_VALUE:
203 case TCG_PTS_REGISTRY_VALUE:
204 case TCG_PTS_REQ_INTEG_MEAS_LOG:
205 case TCG_PTS_INTEG_MEAS_LOG:
206 default:
207 return NULL;
208 }
209 }