b525d3cbe2fe822fadd9ff6174d93384a78f78c8
[strongswan.git] / src / libpts / pts / pts.h
1 /*
2 * Copyright (C) 2011 Sansar Choinyambuu
3 * HSR Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup pts pts
18 * @{ @ingroup pts
19 */
20
21 #ifndef PTS_H_
22 #define PTS_H_
23
24 typedef struct pts_t pts_t;
25
26 #include "pts_error.h"
27 #include "pts_proto_caps.h"
28 #include "pts_meas_algo.h"
29 #include "pts_file_meas.h"
30 #include "pts_file_meta.h"
31 #include "pts_dh_group.h"
32
33 #include <library.h>
34
35 /**
36 * UTF-8 encoding of the character used to delimiter the filename
37 */
38 #define SOLIDUS_UTF 0x2F
39 #define REVERSE_SOLIDUS_UTF 0x5C
40
41 /**
42 * Lenght of the generated nonce used for calculation of shared secret
43 */
44 #define NONCE_LEN 20
45
46 /**
47 * Class implementing the TCG Platform Trust System (PTS)
48 *
49 */
50 struct pts_t {
51
52 /**
53 * Get PTS Protocol Capabilities
54 *
55 * @return protocol capabilities flags
56 */
57 pts_proto_caps_flag_t (*get_proto_caps)(pts_t *this);
58
59 /**
60 * Set PTS Protocol Capabilities
61 *
62 * @param flags protocol capabilities flags
63 */
64 void (*set_proto_caps)(pts_t *this, pts_proto_caps_flag_t flags);
65
66 /**
67 * Get PTS Measurement Algorithm
68 *
69 * @return measurement algorithm
70 */
71 pts_meas_algorithms_t (*get_meas_algorithm)(pts_t *this);
72
73 /**
74 * Set PTS Measurement Algorithm
75 *
76 * @param algorithm measurement algorithm
77 */
78 void (*set_meas_algorithm)(pts_t *this, pts_meas_algorithms_t algorithm);
79
80 /**
81 * Get PTS Diffie Hellman Group
82 *
83 * @return DH Group
84 */
85 pts_dh_group_t (*get_dh_group)(pts_t *this);
86
87 /**
88 * Set PTS Diffie Hellman Group
89 *
90 * @param dh_group DH Group
91 */
92 void (*set_dh_group)(pts_t *this, pts_dh_group_t dh_group);
93
94 /**
95 * Set PTS Diffie Hellman Object
96 *
97 * @param dh D-H object
98 */
99 bool (*create_dh)(pts_t *this, pts_dh_group_t group);
100
101 /**
102 * Gets Own Diffie Hellman Public Value
103 *
104 * @return D-H Public Value
105 */
106 chunk_t (*get_my_pub_val)(pts_t *this);
107
108 /**
109 * Sets the public value of partner.
110 *
111 * @param value public value of partner
112 */
113 void (*set_other_pub_val) (pts_t *this, chunk_t value);
114
115 /**
116 * Calculates secret assessment value to be used for TPM Quote as an external data
117 *
118 * @param initiator_nonce Initiator nonce (IMV nonce)
119 * @param responder_nonce Responder nonce (IMC nonce)
120 * @param algorithm Hashing algorithm
121 * @return TRUE, FALSE if not both DH public values and
122 * nonces are set
123 */
124 bool (*calculate_secret) (pts_t *this, chunk_t initiator_nonce,
125 chunk_t responder_nonce, pts_meas_algorithms_t algorithm);
126
127 /**
128 * Returns secret assessment value to be used for TPM Quote as an external data
129 *
130 * @return Secret assessment value
131 */
132 chunk_t (*get_secret) (pts_t *this);
133
134 /**
135 * Get Platform and OS Info
136 *
137 * @return platform and OS info
138 */
139 char* (*get_platform_info)(pts_t *this);
140
141 /**
142 * Set Platform and OS Info
143 *
144 * @param info platform and OS info
145 */
146 void (*set_platform_info)(pts_t *this, char *info);
147
148 /**
149 * Get TPM 1.2 Version Info
150 *
151 * @param info chunk containing a TPM_CAP_VERSION_INFO struct
152 * @return TRUE if TPM Version Info available
153 */
154 bool (*get_tpm_version_info)(pts_t *this, chunk_t *info);
155
156 /**
157 * Set TPM 1.2 Version Info
158 *
159 * @param info chunk containing a TPM_CAP_VERSION_INFO struct
160 */
161 void (*set_tpm_version_info)(pts_t *this, chunk_t info);
162
163 /**
164 * Get Attestation Identity Certificate or Public Key
165 *
166 * @return AIK Certificate or Public Key
167 */
168 certificate_t* (*get_aik)(pts_t *this);
169
170 /**
171 * Set Attestation Identity Certificate or Public Key
172 *
173 * @param aik AIK Certificate or Public Key
174 */
175 void (*set_aik)(pts_t *this, certificate_t *aik);
176
177 /**
178 * Check whether path is valid file/directory on filesystem
179 *
180 * @param path Absolute path
181 * @param error_code Output variable for PTS error code
182 * @return TRUE if path is valid or file/directory doesn't exist
183 * or path is invalid
184 * FALSE if local error occurred within stat function
185 */
186 bool (*is_path_valid)(pts_t *this, char *path, pts_error_code_t *error_code);
187
188 /**
189 * Do PTS File Measurements
190 *
191 * @param request_id ID of PTS File Measurement Request
192 * @param pathname Absolute pathname of file to be measured
193 * @param is_directory if TRUE directory contents are measured
194 * @return PTS File Measurements of NULL if FAILED
195 */
196 pts_file_meas_t* (*do_measurements)(pts_t *this, u_int16_t request_id,
197 char *pathname, bool is_directory);
198
199 /**
200 * Obtain file metadata
201 *
202 * @param pathname Absolute pathname of file/directory
203 * @param is_directory if TRUE directory contents are requested
204 * @return PTS File Metadata or NULL if FAILED
205 */
206 pts_file_meta_t* (*get_metadata)(pts_t *this, char *pathname, bool is_directory);
207
208 /**
209 * Destroys a pts_t object.
210 */
211 void (*destroy)(pts_t *this);
212
213 };
214
215 /**
216 * Creates an pts_t object
217 *
218 * @param is_imc TRUE if running on an IMC
219 */
220 pts_t* pts_create(bool is_imc);
221
222 #endif /** PTS_H_ @}*/