2 * This file is part of the OpenPTS project.
4 * The Initial Developer of the Original Code is International
5 * Business Machines Corporation. Portions created by IBM
6 * Corporation are Copyright (C) 2010 International Business
7 * Machines Corporation. All Rights Reserved.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the Common Public License as published by
11 * IBM Corporation; either version 1 of the License, or (at your option)
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * Common Public License for more details.
19 * You should have received a copy of the Common Public License
20 * along with this program; if not, a copy can be viewed at
21 * http://www.opensource.org/licenses/cpl1.0.php.
27 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
29 * cleanup 2011-01-22 SM
31 * Reason (Remidiation) of validation fail
34 * Fail at Policy check
41 #include <stdarg.h> /* va_ */
48 void freeReason(OPENPTS_REASON *reason) {
51 LOG(LOG_ERR, "null input");
56 xfree(reason->message);
59 return; // PTS_SUCCESS;
65 int freeReasonChain(OPENPTS_REASON *reason) {
68 LOG(LOG_ERR, "null input");
73 if (reason->next != NULL) {
74 freeReasonChain(reason->next);
85 int addReason_old(OPENPTS_CONTEXT *ctx, int pcr, char *message) {
86 OPENPTS_REASON *start;
88 OPENPTS_REASON *reason;
91 // DEBUG("addReason - [%s]\n", message);
95 LOG(LOG_ERR, "null input");
99 len = strlen(message);
101 start = ctx->reason_start;
102 end = ctx->reason_end;
104 reason = (OPENPTS_REASON *) xmalloc(sizeof(OPENPTS_REASON));
105 if (reason == NULL) {
106 LOG(LOG_ERR, "no memory");
109 memset(reason, 0, sizeof(OPENPTS_REASON));
113 /* update the link */
114 ctx->reason_start = reason;
115 ctx->reason_end = reason;
117 ctx->reason_count = 0;
119 /* update the link */
121 ctx->reason_end = reason;
125 reason->message = xmalloc(len +1);
126 if (reason->message == NULL) {
127 LOG(LOG_ERR, "no memory");
131 memcpy(reason->message, message, len);
132 reason->message[len] = 0;
135 // DEBUG("addReason - done %d [%s]\n", ctx->reason_count, reason->message);
141 * addReason with format
143 #define MAX_REASON_SIZE 2048
144 int addReason(OPENPTS_CONTEXT *ctx, int pcr, const char *format, ...) {
145 char buf[MAX_REASON_SIZE +1]; // TODO size
148 va_start(list, format);
152 LOG(LOG_ERR, "null input");
156 vsnprintf(buf, MAX_REASON_SIZE, format, list);
158 rc = addReason_old(ctx, pcr, (char *)buf);
164 * PCR Usage HINT for each platform.
165 * TODO supply them by Conf.
168 char *reason_pcr_hints[] = {
169 "IBM Partition Firmware Images",
170 "Basic Partition Configuration (e.g. CPUs, memory)",
171 "Third-party Adapter Firmware",
172 "Partition Device Tree",
174 "OS Boot Info (e.g. boot device, or firmware prompt)",
175 NULL, /* PCR6 Unused */
176 NULL, /* PCR7 Unused */
177 NULL, /* PCR8 Unused */
178 NULL, /* PCR9 Unused */
179 "Trusted Execution Database"
181 #else // TPM v1.2, PC Linux, TODO add other type of platform?
182 char *reason_pcr_hints[] = {
183 "CRTM, BIOS and Platform Extensions",
184 "Platform Configuration",
186 "Option ROM Configuration and Data",
187 "IPL Code (usually the MBR)",
188 "IPL Code Configuration and Data (for use by the IPL code)",
189 "State Transition and Wake Events",
190 "Host Platform Manufacturer Control", // v1.1"Reserved for future usage. Do not use.",
191 "OS Kernels (GRUB-IMA)",
192 NULL, /* PCR9 Unused */
193 "Applications (LINUX-IMA)", /* PCR10 */
194 "OpenPTS", /* PCR11 */
195 NULL, /* PCR12 Unused */
196 NULL, /* PCR13 Unused */
197 NULL, /* PCR14 Unused */
198 NULL, /* PCR15 Unused */
200 "Associated with the D-CRTM (Locality 4)", /* PCR17 */
201 "Host Platform defined (locality 3)", /* PCR18 */
202 "Trusted Operating System (locality 2)", /* PCR19 */
203 "Used by Trusted Operating System (locality 1)", /* PCR20 */
204 "Used by Trusted Operating System", /* PCR21 */
205 "Used by Trusted Operating System", /* PCR22 */
206 "Application Support", /* PCR23 */
214 void printReason(OPENPTS_CONTEXT *ctx, int print_pcr_hints) {
215 OPENPTS_REASON *reason;
216 unsigned int i = 0, pcrmask = 0;
220 LOG(LOG_ERR, "null input");
223 reason = ctx->reason_start;
225 while (reason != NULL) {
226 if (reason->pcr >= 0)
227 pcrmask |= 1 << reason->pcr;
228 OUTPUT("%5d %s\n", i, reason->message);
229 reason = reason->next;
232 if (print_pcr_hints) {
233 for (i = 0; i < sizeof(reason_pcr_hints) / sizeof(char *); i++) {
234 if (!(pcrmask & (1 << i)) || reason_pcr_hints[i] == NULL) continue;
235 OUTPUT("PCR%02d corresponds to: %s\n", i, reason_pcr_hints[i]);
241 // TODO add freeReason()