* \brief properties
* @author Seiji Munetoh <munetoh@users.sourceforge.jp>
* @date 2010-11-26
- * cleanup 2011-01-22 SM
+ * cleanup 2012-01-05 SM
*
* Reason (Remidiation) of validation fail
*
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <stdarg.h> /* va_ */
-
+#include <stdarg.h> /* va_ */
#include <openpts.h>
void freeReason(OPENPTS_REASON *reason) {
/* check */
if (reason == NULL) {
+ LOG(LOG_ERR, "null input");
return;
}
- free(reason->message);
- free(reason);
+ /* free */
+ xfree(reason->message);
+ xfree(reason);
- return; // PTS_SUCCESS;
+ return;
}
/**
* Free Reason Chain
*/
int freeReasonChain(OPENPTS_REASON *reason) {
+ /* check */
if (reason == NULL) {
- return PTS_INTERNAL_ERROR;
+ LOG(LOG_ERR, "null input");
+ return PTS_FATAL;
}
+ /* chain */
if (reason->next != NULL) {
freeReasonChain(reason->next);
}
/**
* add reason
*/
-int addReason_old(OPENPTS_CONTEXT *ctx, char *message) {
+int addReason_old(OPENPTS_CONTEXT *ctx, int pcr, char *message) {
OPENPTS_REASON *start;
OPENPTS_REASON *end;
OPENPTS_REASON *reason;
int len;
- // DEBUG("addReason - [%s]\n", message);
-
- len = strlen(message);
+ /* check */
+ if (ctx == NULL) {
+ LOG(LOG_ERR, "null input");
+ return PTS_FATAL;
+ }
+ len = strlen(message);
start = ctx->reason_start;
end = ctx->reason_end;
- reason = (OPENPTS_REASON *) malloc(sizeof(OPENPTS_REASON));
+ reason = (OPENPTS_REASON *) xmalloc(sizeof(OPENPTS_REASON));
if (reason == NULL) {
- ERROR("");
- return -1;
+ LOG(LOG_ERR, "no memory");
+ return PTS_FATAL;
}
memset(reason, 0, sizeof(OPENPTS_REASON));
ctx->reason_end = reason;
reason->next = NULL;
}
-
- reason->message = malloc(len +1);
+ reason->pcr = pcr;
+ reason->message = xmalloc(len +1);
+ if (reason->message == NULL) {
+ LOG(LOG_ERR, "no memory");
+ xfree(reason);
+ return PTS_FATAL;
+ }
memcpy(reason->message, message, len);
reason->message[len] = 0;
ctx->reason_count++;
- // DEBUG("addReason - done %d [%s]\n", ctx->reason_count, reason->message);
-
- return 0;
+ return PTS_SUCCESS;
}
/**
* addReason with format
*/
#define MAX_REASON_SIZE 2048
-int addReason(OPENPTS_CONTEXT *ctx, const char *format, ...) {
- char buf[MAX_REASON_SIZE +1]; // TODO size
+int addReason(OPENPTS_CONTEXT *ctx, int pcr, const char *format, ...) {
int rc;
+ char buf[MAX_REASON_SIZE +1]; // TODO size
va_list list;
- va_start(list, format);
+ /* check */
+ if (ctx == NULL) {
+ LOG(LOG_ERR, "null input");
+ return PTS_FATAL;
+ }
+ va_start(list, format);
vsnprintf(buf, MAX_REASON_SIZE, format, list);
- // DEBUG("buf %s\n", buf);
-
- va_end(list);
- rc = addReason_old(ctx, (char *)buf);
+ rc = addReason_old(ctx, pcr, (char *)buf);
return rc;
}
+/**
+ * PCR Usage HINT for each platform.
+ * TODO supply them by Conf.
+ */
+#ifdef AIX_TARGET
+char *reason_pcr_hints[] = {
+ "IBM Partition Firmware Images",
+ "Basic Partition Configuration (e.g. CPUs, memory)",
+ "Third-party Adapter Firmware",
+ "Partition Device Tree",
+ "OS Boot Image",
+ "OS Boot Info (e.g. boot device, or firmware prompt)",
+ NULL, /* PCR6 Unused */
+ NULL, /* PCR7 Unused */
+ NULL, /* PCR8 Unused */
+ NULL, /* PCR9 Unused */
+ "Trusted Execution Database"
+};
+#else // TPM v1.2, PC Linux, TODO add other type of platform?
+char *reason_pcr_hints[] = {
+ "CRTM, BIOS and Platform Extensions",
+ "Platform Configuration",
+ "Option ROM Code",
+ "Option ROM Configuration and Data",
+ "IPL Code (usually the MBR)",
+ "IPL Code Configuration and Data (for use by the IPL code)",
+ "State Transition and Wake Events",
+ "Host Platform Manufacturer Control", // v1.1"Reserved for future usage. Do not use.",
+ "OS Kernels (GRUB-IMA)",
+ NULL, /* PCR9 Unused */
+ "Applications (LINUX-IMA)", /* PCR10 */
+ "OpenPTS", /* PCR11 */
+ NULL, /* PCR12 Unused */
+ NULL, /* PCR13 Unused */
+ NULL, /* PCR14 Unused */
+ NULL, /* PCR15 Unused */
+ "Debug", /* PCR16 */
+ "Associated with the D-CRTM (Locality 4)", /* PCR17 */
+ "Host Platform defined (locality 3)", /* PCR18 */
+ "Trusted Operating System (locality 2)", /* PCR19 */
+ "Used by Trusted Operating System (locality 1)", /* PCR20 */
+ "Used by Trusted Operating System", /* PCR21 */
+ "Used by Trusted Operating System", /* PCR22 */
+ "Application Support", /* PCR23 */
+};
+#endif
/**
* print Reason
*
*/
-void printReason(OPENPTS_CONTEXT *ctx) {
+void printReason(OPENPTS_CONTEXT *ctx, int print_pcr_hints) {
OPENPTS_REASON *reason;
- int i = 0;
+ unsigned int i = 0, pcrmask = 0;
+
+ /* check */
+ if (ctx == NULL) {
+ LOG(LOG_ERR, "null input");
+ return;
+ }
reason = ctx->reason_start;
- printf("Reasons\n");
while (reason != NULL) {
- printf("%5d %s\n", i, reason->message);
+ if (reason->pcr >= 0)
+ pcrmask |= 1 << reason->pcr;
+ OUTPUT("%5d %s\n", i, reason->message);
reason = reason->next;
i++;
}
+ if (print_pcr_hints) {
+ for (i = 0; i < sizeof(reason_pcr_hints) / sizeof(char *); i++) {
+ if (!(pcrmask & (1 << i)) || reason_pcr_hints[i] == NULL) continue;
+ OUTPUT("PCR%02d corresponds to: %s\n", i, reason_pcr_hints[i]);
+ }
+ }
}
-
-
-// TODO add freeReason()