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 2012-01-05 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);
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;
93 LOG(LOG_ERR, "null input");
97 len = strlen(message);
98 start = ctx->reason_start;
99 end = ctx->reason_end;
101 reason = (OPENPTS_REASON *) xmalloc(sizeof(OPENPTS_REASON));
102 if (reason == NULL) {
103 LOG(LOG_ERR, "no memory");
106 memset(reason, 0, sizeof(OPENPTS_REASON));
110 /* update the link */
111 ctx->reason_start = reason;
112 ctx->reason_end = reason;
114 ctx->reason_count = 0;
116 /* update the link */
118 ctx->reason_end = reason;
122 reason->message = xmalloc(len +1);
123 if (reason->message == NULL) {
124 LOG(LOG_ERR, "no memory");
128 memcpy(reason->message, message, len);
129 reason->message[len] = 0;
136 * addReason with format
138 #define MAX_REASON_SIZE 2048
139 int addReason(OPENPTS_CONTEXT *ctx, int pcr, const char *format, ...) {
141 char buf[MAX_REASON_SIZE +1]; // TODO size
146 LOG(LOG_ERR, "null input");
150 va_start(list, format);
151 vsnprintf(buf, MAX_REASON_SIZE, format, list);
153 rc = addReason_old(ctx, pcr, (char *)buf);
159 * PCR Usage HINT for each platform.
160 * TODO supply them by Conf.
163 char *reason_pcr_hints[] = {
164 "IBM Partition Firmware Images",
165 "Basic Partition Configuration (e.g. CPUs, memory)",
166 "Third-party Adapter Firmware",
167 "Partition Device Tree",
169 "OS Boot Info (e.g. boot device, or firmware prompt)",
170 NULL, /* PCR6 Unused */
171 NULL, /* PCR7 Unused */
172 NULL, /* PCR8 Unused */
173 NULL, /* PCR9 Unused */
174 "Trusted Execution Database"
176 #else // TPM v1.2, PC Linux, TODO add other type of platform?
177 char *reason_pcr_hints[] = {
178 "CRTM, BIOS and Platform Extensions",
179 "Platform Configuration",
181 "Option ROM Configuration and Data",
182 "IPL Code (usually the MBR)",
183 "IPL Code Configuration and Data (for use by the IPL code)",
184 "State Transition and Wake Events",
185 "Host Platform Manufacturer Control", // v1.1"Reserved for future usage. Do not use.",
186 "OS Kernels (GRUB-IMA)",
187 NULL, /* PCR9 Unused */
188 "Applications (LINUX-IMA)", /* PCR10 */
189 "OpenPTS", /* PCR11 */
190 NULL, /* PCR12 Unused */
191 NULL, /* PCR13 Unused */
192 NULL, /* PCR14 Unused */
193 NULL, /* PCR15 Unused */
195 "Associated with the D-CRTM (Locality 4)", /* PCR17 */
196 "Host Platform defined (locality 3)", /* PCR18 */
197 "Trusted Operating System (locality 2)", /* PCR19 */
198 "Used by Trusted Operating System (locality 1)", /* PCR20 */
199 "Used by Trusted Operating System", /* PCR21 */
200 "Used by Trusted Operating System", /* PCR22 */
201 "Application Support", /* PCR23 */
209 void printReason(OPENPTS_CONTEXT *ctx, int print_pcr_hints) {
210 OPENPTS_REASON *reason;
211 unsigned int i = 0, pcrmask = 0;
215 LOG(LOG_ERR, "null input");
218 reason = ctx->reason_start;
220 while (reason != NULL) {
221 if (reason->pcr >= 0)
222 pcrmask |= 1 << reason->pcr;
223 OUTPUT("%5d %s\n", i, reason->message);
224 reason = reason->next;
227 if (print_pcr_hints) {
228 for (i = 0; i < sizeof(reason_pcr_hints) / sizeof(char *); i++) {
229 if (!(pcrmask & (1 << i)) || reason_pcr_hints[i] == NULL) continue;
230 OUTPUT("PCR%02d corresponds to: %s\n", i, reason_pcr_hints[i]);