* \brief Generate Integrity Report from IML
* @author Seiji Munetoh <munetoh@users.sourceforge.jp>
* @date 2010-04-01
- * cleanup 2011-07-06 SM
+ * cleanup 2012-01-05 SM
*
* TSS Event Struct -> IR
* IML and PCR may not match, since the read them is not an atmic operation
*
* TOCTOU?
*
- *
+ * TODO refine XML error log
*/
#include <sys/stat.h>
#include <libxml/parser.h>
#include <openpts.h>
-// #include <log.h>
+/* XML */
enum {
TEXT_WRITER_START_ELEMENT,
TEXT_WRITER_WRITE_ATTR,
"xmlTextWriterEndDocument",
};
- ERROR("XML function '%s' returned '%d'\n", xmlFuncStrings[errorIndex], rc);
+ /* check */
+ if (errorIndex >= XML_FUNC_END) {
+ LOG(LOG_ERR, "errorIndex(%d) > XML_FUNC_END(%d)", errorIndex, XML_FUNC_END);
+ return;
+ }
+
+ /* log */
+ LOG(LOG_ERR, "XML function '%s' returned '%d'\n", xmlFuncStrings[errorIndex], rc);
}
/**
DEBUG_CAL("resetFsm\n");
+ /* check */
+ if (ctx == NULL) {
+ LOG(LOG_ERR, "null input");
+ return PTS_FATAL;
+ }
+
if (ctx->ss_table == NULL) {
- // DEBUG("resetFsm() - no SS table\n");
+ /* no SS table, skip */
return PTS_SUCCESS;
}
ctx = (OPENPTS_IR_CONTEXT *) xmalloc(sizeof(OPENPTS_IR_CONTEXT));
if (ctx == NULL) {
+ LOG(LOG_ERR, "no memory");
return NULL;
}
memset(ctx, 0, sizeof(OPENPTS_IR_CONTEXT));
ctx->buf = xmalloc(EVENTDATA_BUF_SIZE);
if (ctx->buf == NULL) {
+ LOG(LOG_ERR, "no memory");
xfree(ctx);
return NULL;
}
*
*/
void freeIrContext(OPENPTS_IR_CONTEXT *ctx) {
+ /* check */
if (ctx == NULL) {
+ LOG(LOG_ERR, "null input");
return;
}
+ /* free */
if (ctx->buf != NULL) {
xfree(ctx->buf);
}
int rc = PTS_INTERNAL_ERROR;
char id[256];
+ /* check */
+ if (cid == NULL) {
+ LOG(LOG_ERR, "null input");
+ return PTS_FATAL;
+ }
+
/* get strings */
BYTE *simpleName = snmalloc2(cid->dataBlock.dataBlock,
cid->simpleName.offset,
/* element "core:ComponentID" */
rc = xmlTextWriterStartElement(writer, BAD_CAST "core:ComponentID");
if (rc < 0) {
- displayXmlError(TEXT_WRITER_START_ELEMENT, rc); // TODO(munetoh) SYSLOG
+ displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
goto error;
}
rc = xmlTextWriterWriteAttribute(
writer,
BAD_CAST "Id",
- BAD_CAST id); // TODO(munetoh)
+ BAD_CAST id);
if (rc < 0) {
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
goto error;
rc = xmlTextWriterWriteAttribute(
writer,
BAD_CAST "ModelSystemClass",
- BAD_CAST "745749J"); // TODO(munetoh)
+ BAD_CAST "TBD"); // TODO(munetoh)
if (rc < 0) {
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
goto error;
rc = xmlTextWriterWriteAttribute(
writer,
BAD_CAST "SimpleName",
- BAD_CAST simpleName); // "745749J 6DET58WW (3.08 )");
+ BAD_CAST simpleName);
if (rc < 0) {
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
goto error;
rc = xmlTextWriterWriteAttribute(
writer,
BAD_CAST "VersionBuild",
- BAD_CAST "1250694000000");
+ BAD_CAST "1250694000000"); // TODO(munetoh)
if (rc < 0) {
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
goto error;
rc = xmlTextWriterWriteAttribute(
writer,
BAD_CAST "VersionString",
- BAD_CAST versionString); // "6DET58WW (3.08 )");
+ BAD_CAST versionString);
if (rc < 0) {
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
goto error;
rc = xmlTextWriterWriteAttribute(
writer,
BAD_CAST "Name",
- BAD_CAST vendor); // "LENOVO");
+ BAD_CAST vendor);
if (rc < 0) {
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
goto error;
/* element "core:TcgVendorId" */
rc = xmlTextWriterWriteFormatElement(
writer,
- BAD_CAST "core:TcgVendorId", "%s", "DEMO");
+ BAD_CAST "core:TcgVendorId", "%s", "DEMO"); // TODO(munetoh)
if (rc < 0) {
displayXmlError(TEXT_WRITER_WRITE_FORMAT_ELEMENT, rc);
goto error;
char id[256]; // TODO(munetoh)
int rc;
- ASSERT(NULL != event, "writeStuffObjects, event == NULL\n");
+ /* check */
+ if (event == NULL) {
+ LOG(LOG_ERR, "null input");
+ return PTS_FATAL;
+ }
+ /* ID */
snprintf(id, sizeof(id), "PCR_%d_LV%d_%d_%d_EVENT",
event->ulPcrIndex, ss_level, event->eventType, eventindex);
goto error;
}
} else {
- // printf("SM DEBUG no eventdata\n");
+ // no eventdata
}
/* Close the element named "stuff:Objects". */
return PTS_SUCCESS;
error:
- ERROR("writeStuffObjects() XML ERROR\n");
+ LOG(LOG_ERR, "writeStuffObjects() XML ERROR\n");
return PTS_INTERNAL_ERROR;
}
* @retval PTS_INTERNAL_ERROR
*
*/
-
int writePcrHash(
xmlTextWriterPtr writer,
int pcrIndex,
BYTE * startHash,
BYTE * hash,
int algtype) {
- // int rc = PTS_SUCCESS;
char id[256]; // TODO(munetoh) 11+1+1 = 12?
int rc;
DEBUG_CAL("writePcrHash - PCR[%d] level %d \n", pcrIndex, ss_level);
+ /* check */
+ if (startHash == NULL) {
+ LOG(LOG_ERR, "null input");
+ return PTS_FATAL;
+ }
+ if (hash == NULL) {
+ LOG(LOG_ERR, "null input");
+ return PTS_FATAL;
+ }
+
+ /* ID */
snprintf(id, sizeof(id), "PCR_%d_LV%d_HASH", pcrIndex, ss_level);
/* Start an element named "eventdata" as child of "PcrHash". */
/* Write a text */
rc = xmlTextWriterWriteBase64(writer, (const char *) hash, 0, 20);
if (rc < 0) {
- // printf("SM DEBUG ERROR digest len %d \n", 20);
displayXmlError(TEXT_WRITER_WRITE_BASE64, rc);
goto error;
}
char *str_ir_uuid;
char id[256]; // TODO 3 + UUID = 3 + 36 = 39
int level;
+ OPENPTS_PCR_EVENT_WRAPPER *eventWrapper;
+ /* check */
+ if (tpm == NULL) {
+ LOG(LOG_ERR, "null input");
+ return PTS_FATAL;
+ }
+ if (cid == NULL) {
+ LOG(LOG_ERR, "null input");
+ return PTS_FATAL;
+ }
+ if (ss == NULL) {
+ LOG(LOG_ERR, "null input");
+ return PTS_FATAL;
+ }
level = ss->level;
- OPENPTS_PCR_EVENT_WRAPPER *eventWrapper;
/* reset PCR */
// FSM resetPCR(n) exist
if (ss->reset_pcr == 1) {
- TODO("reset PCR[%d]\n", index);
+ LOG(LOG_TODO, "reset PCR[%d]\n", index);
resetTpmPcr(tpm, index);
}
/* new UUID */
ir_uuid = newUuid();
if (ir_uuid == NULL) {
- ERROR("UUID \n");
+ LOG(LOG_ERR, "UUID \n");
rc = PTS_INTERNAL_ERROR;
goto error;
}
str_ir_uuid = getStringOfUuid(ir_uuid);
if (str_ir_uuid == NULL) {
- ERROR("UUID \n");
+ LOG(LOG_ERR, "UUID \n");
rc = PTS_INTERNAL_ERROR;
xfree(ir_uuid);
goto error;
eventWrapper = ss->start;
if (eventWrapper == NULL) {
- ERROR("writeSnapshot- eventWrapper is NULL\n");
- rc = PTS_INTERNAL_ERROR;
+ LOG(LOG_ERR, "writeSnapshot- eventWrapper is NULL\n");
+ rc = PTS_FATAL;
goto free;
}
/* set curr PCR value */
rc = getTpmPcrValue(tpm, index, ss->curr_pcr);
- // TODO(munetoh) check with TSS/PCR value
+ if (rc != PTS_SUCCESS) {
+ LOG(LOG_ERR, "getTpmPcrValue() fail");
+ rc = PTS_INTERNAL_ERROR;
+ goto free;
+ }
/* check with TPM value if this is the last snapshot */
- // TODO(munetoh) copt level0 tpm_pcr to level1
+ // TODO(munetoh) copy level0 tpm_pcr to level1
/* add PcrHash element */
rc = writePcrHash(writer, index, level, ss->start_pcr, ss->curr_pcr, ALGTYPE_SHA1);
- // NG rc = writePcrHash(writer, index, level, ss->start_pcr, ss->tpm_pcr, ALGTYPE_SHA1);
+ if (rc != PTS_SUCCESS) {
+ LOG(LOG_ERR, "writePcrHash() fail");
+ rc = PTS_INTERNAL_ERROR;
+ goto free;
+ }
/* Close the element named "SnapshotCollection". */
rc = xmlTextWriterEndElement(writer);
BYTE select_byte[3]; // TODO TPM1.2, 24PCRs => 3 bytes
char tagbuf[128];
+ /* check */
+ if (ctx == NULL) {
+ LOG(LOG_ERR, "null input");
+ return PTS_FATAL;
+ }
if (ctx->pcrs == NULL) {
- TODO("writeQuote - OPENPTS_PCRS is NULL, SKIP QuoteData\n");
- return PTS_INTERNAL_ERROR;
+ LOG(LOG_TODO, "writeQuote - OPENPTS_PCRS is NULL, SKIP QuoteData\n");
+ return PTS_FATAL;
}
if (ctx->validation_data == NULL) {
- TODO("writeQuote - TSS_VALIDATION is NULL, SKIP QuoteData\n");
- return PTS_INTERNAL_ERROR;
+ LOG(LOG_TODO, "writeQuote - TSS_VALIDATION is NULL, SKIP QuoteData\n");
+ return PTS_FATAL;
}
/* Start an element named "QuoteData" as child of Report. */
rc = xmlTextWriterStartElement(writer, BAD_CAST "QuoteData");
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
/* Add an attribute with name "ID" */
rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "ID", BAD_CAST "TBD");
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
return PTS_INTERNAL_ERROR;
}
/* Start an element named "Quote" as child of QuoteData. */
rc = xmlTextWriterStartElement(writer, BAD_CAST "Quote");
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
/* Start an element named "PcrComposit" as child of Quote. */
rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrComposit");
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
select_byte[2] = select_int & 0xFF;
} else {
// TODO
- ERROR(" PCR NUM != 24\n");
+ LOG(LOG_ERR, " PCR NUM != 24\n");
}
/* Start an element named "PcrSelection" as child of PcrComposit. */
rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrSelection");
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
snprintf(tagbuf, sizeof(tagbuf), "%d", size_of_select);
rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "SizeOfSelect", BAD_CAST tagbuf);
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
return PTS_INTERNAL_ERROR;
}
size_of_select,
&b64buf_len);
if (b64buf == NULL) {
- ERROR("encodeBase64 fail"); // TODO ERROR => displayXmlError
+ LOG(LOG_ERR, "encodeBase64 fail"); // TODO ERROR => displayXmlError
return PTS_INTERNAL_ERROR;
}
rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PcrSelect", BAD_CAST b64buf);
if (rc < 0) {
- // ERROR("Error at xmlTextWriterWriteAttribute\n");
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
return PTS_INTERNAL_ERROR;
}
/* Close the element named "PcrSelection". */
rc = xmlTextWriterEndElement(writer);
if (rc < 0) {
- // ERROR("Error at xmlTextWriterEndElement\n");
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
/* Write an element named "ValueSize" as child of PcrComposit */
rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ValueSize", "%d", ctx->pcrs->value_size);
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_FORMAT_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
/* Start an element named "PcrValue" as child of PcrComposit. */
rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrValue");
if (rc < 0) {
+ LOG(LOG_ERR, "xmlTextWriterStartElement() fail");
displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PcrNumber", BAD_CAST tagbuf);
// rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PcrNumber", BAD_CAST "0");
if (rc < 0) {
+ LOG(LOG_ERR, "xmlTextWriterWriteAttribute() fail");
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
return PTS_INTERNAL_ERROR;
}
0,
20); // TODO add length to OPENPTS_PCRS
if (rc < 0) {
+ LOG(LOG_ERR, "xmlTextWriterWriteBase64() fail");
displayXmlError(TEXT_WRITER_WRITE_BASE64, rc);
return PTS_INTERNAL_ERROR;
}
/* Close the element named "PcrValue" */
rc = xmlTextWriterEndElement(writer);
if (rc < 0) {
+ LOG(LOG_ERR, "xmlTextWriterEndElement() fail");
displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
/* Close the element named "PcrComposit". */
rc = xmlTextWriterEndElement(writer);
if (rc < 0) {
+ LOG(LOG_ERR, "xmlTextWriterEndElement() fail");
displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
/* Start an element named "QuoteInfo" as child of Quote. */
rc = xmlTextWriterStartElement(writer, BAD_CAST "QuoteInfo");
if (rc < 0) {
+ LOG(LOG_ERR, "xmlTextWriterStartElement() fail");
displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
snprintf(tagbuf, sizeof(tagbuf), "%d", ctx->validation_data->versionInfo.bMajor);
rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "VersionMajor", BAD_CAST tagbuf);
if (rc < 0) {
- // ERROR("Error at xmlTextWriterWriteAttribute\n");
+ LOG(LOG_ERR, "xmlTextWriterWriteAttribute() fail");
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
return PTS_INTERNAL_ERROR;
}
snprintf(tagbuf, sizeof(tagbuf), "%d", ctx->validation_data->versionInfo.bMinor);
rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "VersionMinor", BAD_CAST tagbuf);
if (rc < 0) {
- // ERROR("Error at xmlTextWriterWriteAttribute\n");
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
return PTS_INTERNAL_ERROR;
}
snprintf(tagbuf, sizeof(tagbuf), "%d", ctx->validation_data->versionInfo.bRevMajor);
rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "VersionRevMajor", BAD_CAST tagbuf);
if (rc < 0) {
- // ERROR("Error at xmlTextWriterWriteAttribute\n");
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
return PTS_INTERNAL_ERROR;
}
snprintf(tagbuf, sizeof(tagbuf), "%d", ctx->validation_data->versionInfo.bRevMinor);
rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "VersionRevMinor", BAD_CAST tagbuf);
if (rc < 0) {
- // ERROR("Error at xmlTextWriterWriteAttribute\n");
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
return PTS_INTERNAL_ERROR;
}
/* Add an attribute with name "Fixed", int */
rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "Fixed", BAD_CAST "QUOT");
if (rc < 0) {
- // ERROR("Error at xmlTextWriterWriteAttribute\n");
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
return -1;
}
20,
&b64buf_len); // ctx->validation_data->ulDataLength);
if (b64buf == NULL) {
- ERROR("encodeBase64() fail");
+ LOG(LOG_ERR, "encodeBase64() fail");
return PTS_INTERNAL_ERROR;
}
rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "DigestValue", BAD_CAST b64buf);
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
return PTS_INTERNAL_ERROR;
}
ctx->validation_data->ulExternalDataLength,
&b64buf_len);
if (b64buf == NULL) {
- ERROR("encodeBase64() fail");
+ LOG(LOG_ERR, "encodeBase64() fail");
return PTS_INTERNAL_ERROR;
}
rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "ExternalData", BAD_CAST b64buf);
if (rc < 0) {
- // ERROR("Error at xmlTextWriterWriteAttribute\n");
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
return PTS_INTERNAL_ERROR;
}
/* Close the element named "QuoteInfo". */
rc = xmlTextWriterEndElement(writer);
if (rc < 0) {
- // ERROR("Error at xmlTextWriterEndElement\n");
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
/* Close the element named "Quote". */
rc = xmlTextWriterEndElement(writer);
if (rc < 0) {
- // ERROR("Error at xmlTextWriterEndElement\n");
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
/* Start an element named "TpmSignature" as child of QuoteData. */
rc = xmlTextWriterStartElement(writer, BAD_CAST "TpmSignature");
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
/* Start an element named "SignatureMethod" as child of TpmSignature. */
rc = xmlTextWriterStartElement(writer, BAD_CAST "SignatureMethod");
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
BAD_CAST "Algorithm",
BAD_CAST "http://www.w3.org/2000/09/xmldsig#rsa-sha1"); // TODO
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
return PTS_INTERNAL_ERROR;
}
BYTE *composite_hash;
char tagbuf[128]; // Quote tag
+ /* check */
+ if (ctx == NULL) {
+ LOG(LOG_ERR, "null input");
+ return PTS_FATAL;
+ }
if (ctx->pcrs == NULL) {
- TODO("writeQuote2 - OPENPTS_PCRS is NULL, SKIP QuoteData\n");
- return PTS_INTERNAL_ERROR;
+ LOG(LOG_TODO, "writeQuote2 - OPENPTS_PCRS is NULL, SKIP QuoteData\n");
+ return PTS_FATAL;
}
if (ctx->validation_data == NULL) {
- TODO("writeQuote2 - TSS_VALIDATION is NULL, SKIP QuoteData\n");
- return PTS_INTERNAL_ERROR;
+ LOG(LOG_TODO, "writeQuote2 - TSS_VALIDATION is NULL, SKIP QuoteData\n");
+ return PTS_FATAL;
}
/* Quote2 - tag [0:1] */
snprintf(tagbuf, sizeof(tagbuf), "%d", tag);
rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "Tag", BAD_CAST tagbuf);
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
return PTS_INTERNAL_ERROR;
}
DEBUG("fixed : %s", fixed);
rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "Fixed", BAD_CAST fixed);
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
return PTS_INTERNAL_ERROR;
}
ctx->validation_data->ulExternalDataLength,
&b64buf_len);
if (b64buf == NULL) {
- ERROR("encodeBase64 fail");
+ LOG(LOG_ERR, "encodeBase64 fail");
return PTS_INTERNAL_ERROR;
}
rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "ExternalData", BAD_CAST b64buf);
free(b64buf);
if (rc < 0) {
- // ERROR("Error at xmlTextWriterWriteAttribute\n");
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
return PTS_INTERNAL_ERROR;
}
/* PcrInfoShort - start */
rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrInfoShort");
if (rc < 0) {
- // ERROR("Error at xmlTextWriterStartElement\n");
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
/* PcrSelection - start */
rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrSelection");
if (rc < 0) {
- // ERROR("Error at xmlTextWriterStartElement\n");
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
snprintf(tagbuf, sizeof(tagbuf), "%d", size_of_select);
rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "SizeOfSelect", BAD_CAST tagbuf);
if (rc < 0) {
- // ERROR("Error at xmlTextWriterWriteAttribute\n");
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
return PTS_INTERNAL_ERROR;
}
size_of_select,
&b64buf_len);
if (b64buf == NULL) {
- ERROR("encodeBase64 fail");
+ LOG(LOG_ERR, "encodeBase64 fail");
return PTS_INTERNAL_ERROR;
}
rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PcrSelect", BAD_CAST b64buf);
free(b64buf);
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
return PTS_INTERNAL_ERROR;
}
/* PcrSelection - end */
rc = xmlTextWriterEndElement(writer);
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
/* LocalityAtRelease - element */
rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "LocalityAtRelease", "%d", locality);
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_FORMAT_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
20,
&b64buf_len);
if (b64buf == NULL) {
- ERROR("encodeBase64 fail");
+ LOG(LOG_ERR, "encodeBase64 fail");
return PTS_INTERNAL_ERROR;
}
rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "CompositeHash", "%s", b64buf);
free(b64buf);
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_FORMAT_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
/* PcrComposite - start */
rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrComposit");
if (rc < 0) {
- // ERROR("Error at xmlTextWriterStartElement\n");
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
/* PcrSelection - start */
rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrSelection");
if (rc < 0) {
- // ERROR("Error at xmlTextWriterStartElement\n");
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
snprintf(tagbuf, sizeof(tagbuf), "%d", size_of_select);
rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "SizeOfSelect", BAD_CAST tagbuf);
if (rc < 0) {
- // ERROR("Error at xmlTextWriterWriteAttribute\n");
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
return PTS_INTERNAL_ERROR;
}
size_of_select,
&b64buf_len);
if (b64buf == NULL) {
- ERROR("encodeBase64 fail");
+ LOG(LOG_ERR, "encodeBase64 fail");
return PTS_INTERNAL_ERROR;
}
rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PcrSelect", BAD_CAST b64buf);
free(b64buf);
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
return PTS_INTERNAL_ERROR;
}
/* PcrSelection - end */
rc = xmlTextWriterEndElement(writer);
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
/* ValueSize - element */
rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ValueSize", "%d", ctx->pcrs->value_size);
if (rc < 0) {
- displayXmlError(TEXT_WRITER_WRITE_FORMAT_ELEMENT, rc);
+ LOG(LOG_ERR, "xmlX() fail");
+ displayXmlError(TEXT_WRITER_WRITE_FORMAT_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
/* PcrValue, loop */
/* PcrValue - start */
rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrValue");
if (rc < 0) {
- // ERROR("Error at xmlTextWriterStartElement\n");
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
snprintf(tagbuf, sizeof(tagbuf), "%d", i);
rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PcrNumber", BAD_CAST tagbuf);
if (rc < 0) {
- // ERROR("Error at xmlTextWriterWriteAttribute\n");
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
return PTS_INTERNAL_ERROR;
}
0,
20); // TODO add length to OPENPTS_PCRS
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_BASE64, rc);
return PTS_INTERNAL_ERROR;
}
/* PcrValue - end */
rc = xmlTextWriterEndElement(writer);
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
/* PcrComposite - end */
rc = xmlTextWriterEndElement(writer);
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
/* PcrInfoShort - end */
rc = xmlTextWriterEndElement(writer);
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
-
-
-
/* QuoteInfo2 - end */
rc = xmlTextWriterEndElement(writer);
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
/* Quote2 - end */
rc = xmlTextWriterEndElement(writer);
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
/* Start an element named "TpmSignature" as child of QuoteData. */
rc = xmlTextWriterStartElement(writer, BAD_CAST "TpmSignature");
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
/* Start an element named "SignatureMethod" as child of TpmSignature. */
rc = xmlTextWriterStartElement(writer, BAD_CAST "SignatureMethod");
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
BAD_CAST "Algorithm",
BAD_CAST "http://www.w3.org/2000/09/xmldsig#rsa-sha1"); // TODO
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
return PTS_INTERNAL_ERROR;
}
/* Close the element named "SignatureMethod". */
rc = xmlTextWriterEndElement(writer);
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
/* Start an element named "SignatureValue" as child of TpmSignature. */
rc = xmlTextWriterStartElement(writer, BAD_CAST "SignatureValue");
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
0,
ctx->validation_data->ulValidationDataLength);
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_BASE64, rc);
return PTS_INTERNAL_ERROR;
}
/* Close the element named "SignatureValue". */
rc = xmlTextWriterEndElement(writer);
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
/* Close the element named "TpmSignature". */
rc = xmlTextWriterEndElement(writer);
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
/* Close the element named "QuoteData". */
rc = xmlTextWriterEndElement(writer);
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_END_ELEMENT, rc);
return PTS_INTERNAL_ERROR;
}
*
*/
// TODO remove file
-int writeIr(OPENPTS_CONTEXT *ctx, const char *filenameDP, int *savedFd) {
-//int writeIr(OPENPTS_CONTEXT *ctx, int *savedFd) {
+int writeIr(
+ OPENPTS_CONTEXT *ctx,
+ const char *filenameDP, // in (set ctx->conf->ir_filename in normal operation)
+ int *savedFd) { // out
+
int rc = PTS_SUCCESS;
int i;
int irFd;
int lengthOfIrFile;
xmlTextWriterPtr writer;
xmlBufferPtr xmlbuf;
- // FILE *fp;
PTS_ComponentId cid;
OPENPTS_TPM_CONTEXT tpm; // to calc snapshot PCR
PTS_UUID *ir_uuid;
char *str_ir_uuid;
char *filename = NULL;
- // char filename[256]; // TODO UUID_UUID.xml
PTS_Byte smbios[12] = { 0x4A, 0x4A, 0x4A, 0x4A, 0x4A,
0x4A, 0x4A, 0x4A, 0x4A, 0x4A,
/* check */
if (ctx == NULL) {
- ERROR("ctx == NULL");
+ LOG(LOG_ERR, "null input");
return PTS_FATAL;
}
- //if (filename == NULL) {
- // ERROR("filename == NULL");
- // return PTS_FATAL;
- //}
+
// TODO(munetoh) dummy data
cid.vendor.offset = 0;
/* Create a new XML buffer */
xmlbuf = xmlBufferCreate();
if (xmlbuf == NULL) {
- ERROR("creating the xml buffer fail\n");
+ LOG(LOG_ERR, "creating the xml buffer fail\n");
rc = PTS_INTERNAL_ERROR;
goto error;
}
/* Create a new XmlWriter for memory */
writer = xmlNewTextWriterMemory(xmlbuf, 0);
if (writer == NULL) {
- ERROR("creating the xml writer fail\n");
+ LOG(LOG_ERR, "creating the xml writer fail\n");
rc = PTS_INTERNAL_ERROR;
goto freexml;
}
/* Start the document */
rc = xmlTextWriterStartDocument(writer, "1.0", XML_ENCODING, "no");
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_START_DOC, rc);
rc = PTS_INTERNAL_ERROR;
goto freexml;
/* Start an element named "Report", the root element of the document. */
rc = xmlTextWriterStartElement(writer, BAD_CAST "Report");
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_START_ELEMENT, rc);
rc = PTS_INTERNAL_ERROR;
goto freexml;
}
-
-
DEBUG_CAL("genIr - uuid done\n");
/* Add an attribute of Schemas */
BAD_CAST "xmlns:core",
BAD_CAST XMLNS_CORE);
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
rc = PTS_INTERNAL_ERROR;
goto freexml;
BAD_CAST "xmlns:stuff",
BAD_CAST XMLNS_STUFF);
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
rc = PTS_INTERNAL_ERROR;
goto freexml;
BAD_CAST "xmlns:xsi",
BAD_CAST "http://www.w3.org/2001/XMLSchema-instance");
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
rc = PTS_INTERNAL_ERROR;
goto freexml;
BAD_CAST "xmlns",
BAD_CAST XMLNS_IR);
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
rc = PTS_INTERNAL_ERROR;
goto freexml;
/* generate UUID */
ir_uuid = newUuid();
if (ir_uuid == NULL) {
- ERROR("fail UUID generation\n");
+ LOG(LOG_ERR, "fail UUID generation\n");
rc = PTS_INTERNAL_ERROR;
goto freexml;
}
str_ir_uuid = getStringOfUuid(ir_uuid);
if (str_ir_uuid == NULL) {
- ERROR("fail UUID generation\n");
+ LOG(LOG_ERR, "fail UUID generation\n");
rc = PTS_INTERNAL_ERROR;
xfree(ir_uuid);
goto freexml;
rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "ID", BAD_CAST id);
if (rc < 0) {
+ LOG(LOG_ERR, "xmlX() fail");
displayXmlError(TEXT_WRITER_WRITE_ATTR, rc);
rc = PTS_INTERNAL_ERROR;
goto free;
/* Quote*/
if (ctx->conf->iml_mode == 0) {
if (ctx->conf->ir_without_quote == 1) {
- TODO("skip TPM_Quote\n");
+ LOG(LOG_TODO, "skip TPM_Quote\n");
} else {
if (ctx->conf->tpm_quote_type == 1) {
/* Quote */
rc = writeQuote(writer, ctx);
if (rc < 0) {
- ERROR("writeIr - writeQuote() rc = %d\n", rc);
+ LOG(LOG_ERR, "writeIr - writeQuote() rc = %d\n", rc);
rc = PTS_INTERNAL_ERROR;
goto free;
}
/* Quote2 */
rc = writeQuote2(writer, ctx);
if (rc < 0) {
- ERROR("writeIr - writeQuote2() rc = %d\n", rc);
+ LOG(LOG_ERR, "writeIr - writeQuote2() rc = %d\n", rc);
rc = PTS_INTERNAL_ERROR;
goto free;
}
if (ss != NULL) {
if (ss->event_num > 0) {
// level 0
- // printf("DEBUG add level %d snapshot for PCR%d\n",ss->level, i);
- // ERROR("writeIr PCR[%d] LV0 num=%d\n", i,ss->event_num);
+ // LOG(LOG_ERR, "writeIr PCR[%d] LV0 num=%d\n", i,ss->event_num);
writeSnapshot(writer, &tpm, &cid, i, ss);
}
}
ss = getSnapshotFromTable(ctx->ss_table, i, 1);
if (ss != NULL) {
if (ss->event_num > 0) {
- // ERROR("writeIr PCR[%d] LV1 num=%d\n", i,ss->event_num);
+ // LOG(LOG_ERR, "writeIr PCR[%d] LV1 num=%d\n", i,ss->event_num);
// writeSnapshot(writer, &tpm, &cid, i, ss);
if (i == OPENPTS_PCR_INDEX) {
DEBUG("genIr - Not writing snapshot for OPENPTS_PCR_INDEX (%d)\n",
rc = xmlTextWriterFlush(writer);
if (rc < 0) {
- // ERROR("writeRm: Error at xmlTextWriterFlush\n");
+ // LOG(LOG_ERR, "writeRm: Error at xmlTextWriterFlush\n");
displayXmlError(TEXT_WRITER_FLUSH, rc);
rc = PTS_INTERNAL_ERROR;
goto free;
/* Close all elements */
rc = xmlTextWriterEndDocument(writer);
if (rc < 0) {
- ERROR("testXmlwriterMemory: Error at xmlTextWriterEndDocument\n");
+ LOG(LOG_ERR, "testXmlwriterMemory: Error at xmlTextWriterEndDocument\n");
rc = PTS_INTERNAL_ERROR;
goto free;
}
-#if 0
- /* set IR file */
- if (filename != NULL) {
- /* use given filename */
- ctx->conf->ir_filename = smalloc((char *)file);
- } else {
- /* use default filename */
- if (ctx->conf->ir_filename != NULL) {
- free(ctx->conf->ir_filename);
- }
- if (ctx->conf->ir_dir == NULL) {
- ERROR("Set ir.dir at ptsc.conf. \n");
- ctx->conf->ir_dir = smalloc("/tmp/.ptsc");
- }
- snprintf(filename, sizeof(filename), "%s_%s.xml",
- ctx->str_uuid,
- str_ir_uuid);
- ctx->conf->ir_filename = getFullpathName(ctx->conf->ir_dir, filename);
- }
-#endif
- if (ctx->ir_filename != NULL) {
+
+ /* check filename */
+ if (filenameDP != NULL) {
/* use given filename for the Unit Test*/
- // filename = smalloc(ctx->conf->ir_filename); filename = ctx->conf->ir_filename;
} else {
+ /* create new IR filename, save to ctx->ir_filename */
char buf[1024];
/* use default filename */
if (ctx->conf->ir_dir == NULL) {
- ERROR("Set ir.dir in %s.\n", ctx->conf->config_file);
+ LOG(LOG_ERR, "Set ir.dir in %s.\n", ctx->conf->config_file);
ctx->conf->ir_dir = smalloc("/tmp/.ptsc");
}
snprintf(buf, sizeof(buf), "%s_%s.xml",
str_ir_uuid);
ctx->ir_filename = getFullpathName(ctx->conf->ir_dir, buf);
+ filenameDP = ctx->ir_filename;
}
- filename = ctx->ir_filename;
- DEBUG("Write Integrity Report (IR) : %s\n", filename);
+ DEBUG("Write Integrity Report (IR) : %s\n", filenameDP);
/* write to file */
xmlFreeTextWriter(writer);
-#if 0
- fp = fopen(ctx->conf->ir_filename, "w");
- if (fp == NULL) {
- ERROR("testXmlwriterMemory: Error at fopen, %s\n", ctx->conf->ir_filename);
- rc = PTS_INTERNAL_ERROR;
- goto free;
- }
-
- fprintf(fp, "%s", (const char *) xmlbuf->content);
-
- rc = PTS_SUCCESS; // 0
-
- fclose(fp);
-#endif
-
- irFd = open(filename, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR);
+ irFd = open(filenameDP, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR);
if (-1 == irFd) {
- ERROR("Failed to open ir file '%s' for writing, errno = %d\n", filename, errno);
+ LOG(LOG_ERR, "Failed to open ir file '%s' for writing, errno = %d\n", filename, errno);
rc = PTS_INTERNAL_ERROR;
goto free;
}
This is most useful during verification when running "ptsc -m". Anyway,
serious hackers probably wouldn't be deterred by this ... */
if (NULL != savedFd &&
- -1 == unlink(filename)) {
- ERROR("Failed to unlink file '%s', errno = %d\n", filename, errno);
+ -1 == unlink(filenameDP)) {
+ LOG(LOG_ERR, "Failed to unlink file '%s', errno = %d\n", filename, errno);
}
lengthOfIrFile = xmlbuf->use;
{
int writeRc = write(irFd, xmlbuf->content, lengthOfIrFile);
if ( lengthOfIrFile != writeRc ) {
- ERROR("Failed to write contents to IR file - rc %d, errno %d\n", writeRc, errno);
+ LOG(LOG_ERR, "Failed to write contents to IR file - rc %d, errno %d\n", writeRc, errno);
rc = PTS_INTERNAL_ERROR;
close(irFd);
} else {
free:
xfree(ir_uuid);
xfree(str_ir_uuid);
- //if (filename != NULL) xfree(filename);
freexml:
xmlBufferFree(xmlbuf);
error:
-
-
DEBUG_CAL("writeIr - done\n");
return rc;
OPENPTS_CONTEXT * pctx = (OPENPTS_CONTEXT *)ctx;
OPENPTS_IR_CONTEXT * ir_ctx = pctx->ir_ctx;
+ /* check */
+ if (ctx == NULL) {
+ LOG(LOG_ERR, "null input");
+ return;
+ }
+
ir_ctx->sax_error = 0;
ir_ctx->event_index = 0;
* SAX parser
*/
void irEndDocument(void * ctx) {
- // printf("END DOC \n");
+ /* check */
+ if (ctx == NULL) {
+ LOG(LOG_ERR, "null input");
+ return;
+ }
}
/* This prevents real world buffer over-run attacks using malformed IRs
wrongly into presenting a valid attestation of a compromised system. */
static int getPcrIndexFromIR(char *value) {
unsigned int index = atoi(value);
+
+ /* check */
+ if (value == NULL) {
+ LOG(LOG_ERR, "null input");
+ return -1;
+ }
+
+ index = atoi(value);
if ( index > MAX_PCRNUM ) {
return -1;
} else {
* SAX parser - Start of Element
*/
void irStartElement(void* ctx, const xmlChar* name, const xmlChar** atts) {
- OPENPTS_CONTEXT * pctx = (OPENPTS_CONTEXT *)ctx;
- OPENPTS_IR_CONTEXT * ir_ctx = pctx->ir_ctx;
- TSS_VALIDATION *validation_data = pctx->validation_data;
- OPENPTS_PCRS *pcrs = pctx->pcrs;
+ OPENPTS_CONTEXT * pctx;
+ OPENPTS_IR_CONTEXT * ir_ctx;
+ TSS_VALIDATION *validation_data;
+ OPENPTS_PCRS *pcrs;
BYTE *b64buf = NULL;
int b64buf_len;
int i;
char *type;
char *value;
+ /* check */
+ if (ctx == NULL) {
+ LOG(LOG_ERR, "null input");
+ return;
+ }
+ pctx = (OPENPTS_CONTEXT *)ctx;
+ ir_ctx = pctx->ir_ctx;
+ if (ir_ctx == NULL) {
+ LOG(LOG_ERR, "null input");
+ return;
+ }
+ pcrs = pctx->pcrs;
+ if (pcrs == NULL) {
+ LOG(LOG_ERR, "null input");
+ return;
+ }
+ if (name == NULL) {
+ LOG(LOG_ERR, "null input");
+ return;
+ }
+ validation_data = pctx->validation_data; // ckeck later
+
+ /* IR */
ir_ctx->char_size = 0;
if (!strcmp((char *)name, "Report")) {
//
} else if (!strcmp((char *)name, "pcrindex")) {
/* stuff:Hash -> PCR value (base64) */
- // printf("START ELEMENT [%s] <<<< HASH HASH \n",name);
+ // DEBUG("START ELEMENT [%s] <<<< HASH HASH \n",name);
// ir_ctx->sax_state = IR_SAX_STATE_PCR_INDEX;
} else if (!strcmp((char *)name, "eventtype")) {
- // printf("START ELEMENT [%s] <<<< HASH HASH \n",name);
+ // DEBUG("START ELEMENT [%s] <<<< HASH HASH \n",name);
// ir_ctx->sax_state = IR_SAX_STATE_EVENT_TYPE;
} else if (!strcmp((char *)name, "stuff:Hash")) {
- // printf("START ELEMENT [%s] <<<< DIGEST \n",name);
+ // DEBUG("START ELEMENT [%s] <<<< DIGEST \n",name);
// ir_ctx->sax_state = IR_SAX_STATE_DIGEST;
} else if (!strcmp((char *)name, "eventdata")) {
- // printf("START ELEMENT [%s] <<<< EVENT_DATA\n",name);
+ // DEBUG("START ELEMENT [%s] <<<< EVENT_DATA\n",name);
// ir_ctx->sax_state = IR_SAX_STATE_EVENT_DATA;
} else if (!strcmp((char *)name, "PcrHash")) {
- // printf("START ELEMENT [%s] <<<< EVENT_DATA\n",name);
+ // DEBUG("START ELEMENT [%s] <<<< EVENT_DATA\n",name);
// ir_ctx->sax_state = IR_SAX_STATE_PCR;
/* get Number =pcrindex) attribute ( */
if (atts != NULL) {
for (i = 0;(atts[i] != NULL);i++) {
type = (char *)atts[i++];
- // printf(", %s='", type);
if (atts[i] != NULL) {
value= (char *)atts[i];
- // printf("%s'", value);
if (!strcmp(type, "Number")) {
ir_ctx->pcr_index = getPcrIndexFromIR(value);
}
if (atts != NULL) {
for (i = 0;(atts[i] != NULL);i++) {
type = (char *)atts[i++];
- // printf(", %s='", type);
if (atts[i] != NULL) {
value= (char *)atts[i];
- // printf("%s'", value);
if (!strcmp(type, "SizeOfSelect")) {
/* TPM1.2 - 24 PCRS -> 3 */
pcrs->pcr_select_size = atoi(value);
if (!strcmp(type, "PcrSelect")) {
/* used later */
if (b64buf != NULL) {
- ERROR("bad memory management");
+ LOG(LOG_ERR, "bad memory management");
free(b64buf);
}
b64buf = (BYTE *) decodeBase64(
// attr_cnt++;
// DEBUG("PcrSelect = 0x%02x %02x %02x \n", buf[0],buf[1],buf[2]);
if (b64buf == NULL) {
- ERROR("Failed to decode base64 string\n");
+ LOG(LOG_ERR, "Failed to decode base64 string\n");
ir_ctx->sax_error++;
pcrs->pcr_select_size = 0;
} else {
if (b64buf != NULL) {
memcpy(pcrs->pcr_select_byte, b64buf, pcrs->pcr_select_size);
} else {
- ERROR("pcr_select_byte is missing");
+ LOG(LOG_ERR, "pcr_select_byte is missing");
}
} else {
- ERROR("no memory\n");
+ LOG(LOG_ERR, "no memory\n");
}
} else {
/* BAD IR */
- ERROR("BAD IR SizeOfSelect or PcrSelect are missing\n");
+ LOG(LOG_ERR, "BAD IR SizeOfSelect or PcrSelect are missing\n");
}
/* free Base64 buffer */
if (b64buf != NULL) {
if (atts != NULL) {
for (i = 0;(atts[i] != NULL);i++) {
type = (char *)atts[i++];
- // printf(", %s='", type);
if (atts[i] != NULL) {
value= (char *)atts[i];
- // printf("%s'", value);
if (!strcmp(type, "PcrNumber")) {
ir_ctx->pcr_index = getPcrIndexFromIR(value);
}
for (i = 0;(atts[i] != NULL);i++) {
type = (char *)atts[i++];
+ if (validation_data == NULL) {
+ LOG(LOG_ERR, "validation_data == NULL");
+ return;
+ }
if (validation_data->rgbData == NULL) {
// TODO 1.2 only
validation_data->ulDataLength = 48;
validation_data->rgbData = xmalloc_assert(48);
}
- // printf(", %s='", type);
if (atts[i] != NULL) {
value= (char *)atts[i];
- // printf("%s'", value);
if (!strcmp(type, "VersionMajor")) {
validation_data->versionInfo.bMajor = atoi(value);
validation_data->rgbData[0] = atoi(value);
strlen(value),
&b64buf_len);
if (b64buf == NULL) {
- ERROR("decodeBase64 fail");
+ LOG(LOG_ERR, "decodeBase64 fail");
ir_ctx->sax_error++;
return; // TODO return?
}
if (b64buf_len == 20) {
memcpy(&validation_data->rgbData[8], b64buf, 20);
} else {
- ERROR("size of decodeBase64 out is not 20 but %d", b64buf_len);
+ LOG(LOG_ERR, "size of decodeBase64 out is not 20 but %d", b64buf_len);
ir_ctx->sax_error++;
return; // TODO
}
strlen(value),
&b64buf_len);
if (b64buf == NULL) {
- ERROR("decodeBase64 fail");
+ LOG(LOG_ERR, "decodeBase64 fail");
ir_ctx->sax_error++;
return; // TODO
}
// memcpy(validation_data->rgbExternalData, buf, rc);
memcpy(&validation_data->rgbData[28], b64buf, 20);
} else {
- ERROR("Failed to decode base64 string, len = %d not 20\n", b64buf_len);
+ LOG(LOG_ERR, "Failed to decode base64 string, len = %d not 20\n", b64buf_len);
ir_ctx->sax_error++;
return; // TODO
}
for (i = 0;(atts[i] != NULL);i++) {
type = (char *)atts[i++];
+ if (validation_data == NULL) {
+ LOG(LOG_ERR, "validation_data == NULL");
+ return;
+ }
if (validation_data->rgbData == NULL) {
// TODO 1.2 only
validation_data->ulDataLength = 52;
validation_data->rgbData = xmalloc_assert(52);
}
- // printf(", %s='", type);
if (atts[i] != NULL) {
value= (char *)atts[i];
- // printf("%s'", value);
if (!strcmp(type, "Tag")) {
int tag = atoi(value);
validation_data->rgbData[0] = (tag >> 8) & 0xFF;
strlen(value),
&b64buf_len);
if (b64buf == NULL) {
- ERROR("decodeBase64 fail");
+ LOG(LOG_ERR, "decodeBase64 fail");
ir_ctx->sax_error++;
return;
}
// memcpy(validation_data->rgbExternalData, b64buf, rc);
memcpy(&validation_data->rgbData[6], b64buf, 20);
} else {
- ERROR("Failed to decode base64 string, len = %d not 20\n", b64buf_len);
+ LOG(LOG_ERR, "Failed to decode base64 string, len = %d not 20\n", b64buf_len);
ir_ctx->sax_error++;
return; // TODO
}
} else if (!strcmp((char *)name, "SignatureMethod")) {
// TODO check alg
} else if (!strcmp((char *)name, "SignatureValue")) {
- // DONE TODO("get value(base64)\n");
+ // DONE LOG(LOG_TODO, "get value(base64)\n");
} else if (!strcmp((char *)name, "KeyInfo")) {
// TODO
} else if (!strcmp((char *)name, "KeyValue")) {
- // DONE TODO("get value(base64)\n");
+ // DONE LOG(LOG_TODO, "get value(base64)\n");
} else { /* Else? */
- ERROR("START ELEMENT [%s] \n", name);
+ LOG(LOG_ERR, "START ELEMENT [%s] \n", name);
ir_ctx->sax_state = IR_SAX_STATE_IDOL;
}
}
* SAX parser - End of Element
*/
void irEndElement(void * ctx, const xmlChar * name) {
- OPENPTS_CONTEXT * pctx = (OPENPTS_CONTEXT *)ctx;
- OPENPTS_IR_CONTEXT * ir_ctx = pctx->ir_ctx;
- TSS_VALIDATION *validation_data = pctx->validation_data;
- OPENPTS_PCRS *pcrs = pctx->pcrs;
+ OPENPTS_CONTEXT * pctx;
+ OPENPTS_IR_CONTEXT * ir_ctx;
+ TSS_VALIDATION *validation_data;
+ OPENPTS_PCRS *pcrs;
int rc;
BYTE *b64buf = NULL;
int b64buf_len;
+ /* check */
+ if (ctx == NULL) {
+ LOG(LOG_ERR, "null input");
+ return;
+ }
+ pctx = (OPENPTS_CONTEXT *)ctx;
+ ir_ctx = pctx->ir_ctx;
+ if (ir_ctx == NULL) {
+ LOG(LOG_ERR, "null input");
+ return;
+ }
+ pcrs = pctx->pcrs;
+ if (pcrs == NULL) {
+ LOG(LOG_ERR, "null input");
+ return;
+ }
+ if (name == NULL) {
+ LOG(LOG_ERR, "null input");
+ return;
+ }
+ validation_data = pctx->validation_data; // ckeck later
+
+ /* END ELEMENT */
if (!strcmp((char *)name, "stuff:Objects")) {
int extend = 0;
int pcr_index = -1;
/* set the event structure */
if (ir_ctx->event == NULL) {
- ERROR("internal error\n");
+ LOG(LOG_ERR, "internal error\n");
ir_ctx->ew_new->event = NULL;
ir_ctx->sax_error++;
} else {
/* map to the snapshot, push FSM */
rc = addEventToSnapshotBin(pctx, ir_ctx->ew_new); // iml.c
if (rc != PTS_SUCCESS) {
- // ERROR("validateIr:irStartElement - addEventToSnapshotBin rc = %d\n", rc);
+ // LOG(LOG_ERR, "validateIr:irStartElement - addEventToSnapshotBin rc = %d\n", rc);
ir_ctx->integrity = OPENPTS_RESULT_INVALID;
return;
}
DEBUG_FSM("irEndElement() -- SS has validation error\n");
ir_ctx->fsm_error_count++;
} else if (rc != PTS_SUCCESS) {
- ERROR("SnapshotCollection -> FSM flash was fail\n");
+ LOG(LOG_ERR, "SnapshotCollection -> FSM flash was fail\n");
ir_ctx->sax_error++;
return;
}
ir_ctx->char_size,
&b64buf_len);
if (ir_ctx->event->rgbPcrValue == NULL) {
- ERROR("decodeBase64 fail");
+ LOG(LOG_ERR, "decodeBase64 fail");
ir_ctx->sax_error++;
return; // TODO
} else {
ir_ctx->char_size,
&b64buf_len);
if (ir_ctx->event->rgbEvent == NULL) {
- ERROR("decodeBase64 fail");
+ LOG(LOG_ERR, "decodeBase64 fail");
ir_ctx->sax_error++;
return; // TODO
} else {
ir_ctx->char_size,
&b64buf_len);
if (b64buf == NULL) {
- ERROR("decodeBase64 fail");
+ LOG(LOG_ERR, "decodeBase64 fail");
ir_ctx->sax_error++;
return; // TODO
}
if (b64buf_len > MAX_DIGEST_SIZE) {
- ERROR("decodeBase64 out is too latge, %d > %d",
+ LOG(LOG_ERR, "decodeBase64 out is too latge, %d > %d",
b64buf_len, MAX_DIGEST_SIZE);
ir_ctx->sax_error++;
return; // TODO
free(b64buf);
/* Check with PCR in TPM */
rc = checkTpmPcr2(&pctx->tpm, ir_ctx->pcr_index, ir_ctx->pcr);
- if (rc != 0) {
- ERROR("ERROR PCR[%d] != IML\n", ir_ctx->pcr_index);
+ if (rc != PTS_SUCCESS) {
+ LOG(LOG_ERR, "ERROR PCR[%d] != IML\n", ir_ctx->pcr_index);
ir_ctx->sax_error = 1;
// verbose = DEBUG_FLAG | DEBUG_TPM_FLAG; // switch DEBUG MODE
if (isDebugFlagSet(DEBUG_FLAG)) {
if (pctx->conf->iml_mode == 0) {
if (pcrs == NULL) {
/* malloc OPENPTS_PCRS */
- // ERROR("PCR is not intialized - No QuoteData element\n");
+ // LOG(LOG_ERR, "PCR is not intialized - No QuoteData element\n");
pcrs = xmalloc(sizeof(OPENPTS_PCRS));
if (pcrs == NULL) {
- ERROR("no memory\n");
+ LOG(LOG_ERR, "no memory\n");
return;
}
memset(pcrs, 0, sizeof(OPENPTS_PCRS));
}
} else if (!strcmp((char *)name, "LocalityAtRelease")) {
// TODO
+ if (validation_data == NULL) {
+ LOG(LOG_ERR, "validation_data == NULL");
+ return;
+ }
validation_data->rgbData[31] = atoi(ir_ctx->buf);
} else if (!strcmp((char *)name, "CompositeHash")) {
// DEBUG("CompositeHash %s", ir_ctx->buf);
+ if (validation_data == NULL) {
+ LOG(LOG_ERR, "validation_data == NULL");
+ return;
+ }
b64buf = decodeBase64(
(char *)ir_ctx->buf,
ir_ctx->char_size,
&b64buf_len);
if (b64buf == NULL) {
- ERROR("decodeBase64 fail");
+ LOG(LOG_ERR, "decodeBase64 fail");
ir_ctx->sax_error++;
return;
}
ir_ctx->char_size,
&b64buf_len);
if (b64buf == NULL) {
- ERROR("decodeBase64 fail");
+ LOG(LOG_ERR, "decodeBase64 fail");
ir_ctx->sax_error++;
return;
}
if (b64buf_len < SHA1_DIGEST_SIZE) {
- ERROR("decodeBase64 outout is too small, %d < %d", b64buf_len, SHA1_DIGEST_SIZE);
+ LOG(LOG_ERR, "decodeBase64 outout is too small, %d < %d", b64buf_len, SHA1_DIGEST_SIZE);
ir_ctx->sax_error++;
return;
}
if (b64buf_len > MAX_DIGEST_SIZE) {
- ERROR("decodeBase64 outout is too large, %d < %d", b64buf_len, MAX_DIGEST_SIZE);
+ LOG(LOG_ERR, "decodeBase64 outout is too large, %d < %d", b64buf_len, MAX_DIGEST_SIZE);
ir_ctx->sax_error++;
return;
}
} else if (!strcmp((char *)name, "QuoteInfo2")) {
/* pcr select => validation_data */
if (pcrs->pcr_select_byte == NULL) {
- ERROR("pcrs->pcr_select_byte is null");
+ LOG(LOG_ERR, "pcrs->pcr_select_byte is null");
} else {
+ if (validation_data == NULL) {
+ LOG(LOG_ERR, "validation_data == NULL");
+ return;
+ }
validation_data->rgbData[26] = 0;
validation_data->rgbData[27] = pcrs->pcr_select_size;
validation_data->rgbData[28] = pcrs->pcr_select_byte[0];
} else if (!strcmp((char *)name, "SignatureValue")) {
ir_ctx->buf[ir_ctx->char_size] = 0;
if (ir_ctx->char_size > IR_SAX_BUFFER_SIZE) { // TODO check buf size
- ERROR("buf is small %d \n", ir_ctx->char_size);
+ LOG(LOG_ERR, "buf is small %d \n", ir_ctx->char_size);
ir_ctx->sax_error++;
} else {
+ if (validation_data == NULL) {
+ LOG(LOG_ERR, "validation_data == NULL");
+ return;
+ }
if (validation_data->rgbValidationData != NULL) {
xfree(validation_data->rgbValidationData);
}
ir_ctx->char_size,
&b64buf_len);
if (validation_data->rgbValidationData == NULL) {
- ERROR("decodeBase64 fail");
+ LOG(LOG_ERR, "decodeBase64 fail");
ir_ctx->sax_error++;
return; // TODO
}
} else if (!strcmp((char *)name, "KeyValue")) {
ir_ctx->buf[ir_ctx->char_size] = 0;
if (ir_ctx->char_size > IR_SAX_BUFFER_SIZE) { // TODO check buf size
- ERROR("buf is small %d \n", ir_ctx->char_size);
+ LOG(LOG_ERR, "buf is small %d \n", ir_ctx->char_size);
} else {
pcrs->pubkey = decodeBase64(
(char *)ir_ctx->buf,
ir_ctx->char_size,
&b64buf_len);
if (pcrs->pubkey == NULL) {
- ERROR("decodeBase64 fail");
+ LOG(LOG_ERR, "decodeBase64 fail");
ir_ctx->sax_error++;
return;
}
/* Validate QuoteData */
if ( ir_ctx->sax_error > 0 ) {
- ERROR("Unable to validate quote data due to %d SAX parse errors\n", ir_ctx->sax_error);
+ LOG(LOG_ERR, "Unable to validate quote data due to %d SAX parse errors\n", ir_ctx->sax_error);
} else {
rc = validateQuoteData(pcrs, validation_data);
// DEBUG("validateQuoteData = %d\n", rc);
if (rc != PTS_SUCCESS) {
- ERROR("---------------------------------------------------------------------------\n");
- ERROR("BAD QUOTE DATA!!! BAD QUOTE DATA!!! BAD QUOTE DATA!!! BAD QUOTE DATA!!!\n");
- ERROR("---------------------------------------------------------------------------\n");
+ LOG(LOG_ERR, "---------------------------------------------------------------------------\n");
+ LOG(LOG_ERR, "BAD QUOTE DATA!!! BAD QUOTE DATA!!! BAD QUOTE DATA!!! BAD QUOTE DATA!!!\n");
+ LOG(LOG_ERR, "---------------------------------------------------------------------------\n");
addProperty(pctx, "tpm.quote.signature", "invalid");
// TODO set error
ir_ctx->bad_quote = 1;
} else {
#if 0
- TODO("---------------------------------------------------------------------------\n");
- TODO("GOOD QUOTE DATA!!! GOOD QUOTE DATA!!! GOOD QUOTE DATA!!! GOOD QUOTE DATA!!!\n");
- TODO("---------------------------------------------------------------------------\n");
+ LOG(LOG_TODO, "---------------------------------------------------------------------------\n");
+ LOG(LOG_TODO, "GOOD QUOTE DATA!!! GOOD QUOTE DATA!!! GOOD QUOTE DATA!!! GOOD QUOTE DATA!!!\n");
+ LOG(LOG_TODO, "---------------------------------------------------------------------------\n");
#endif
addProperty(pctx, "tpm.quote.signature", "valid");
}
pctx->conf->ir_without_quote = 0;
} else {
/* Else? */
- // printf("END ELEMENT [%s] ",name);
}
ir_ctx->sax_state = IR_SAX_STATE_IDOL;
*
*/
void irCharacters(void* ctx, const xmlChar * ch, int len) {
- OPENPTS_CONTEXT * pctx = (OPENPTS_CONTEXT *)ctx;
- OPENPTS_IR_CONTEXT * ir_ctx = pctx->ir_ctx;
+ OPENPTS_CONTEXT * pctx;
+ OPENPTS_IR_CONTEXT * ir_ctx;
+
+ /* check */
+ if (ctx == NULL) {
+ LOG(LOG_ERR, "null input");
+ return;
+ }
+ pctx = (OPENPTS_CONTEXT *)ctx;
+ ir_ctx = pctx->ir_ctx;
+ if (ir_ctx == NULL) {
+ LOG(LOG_ERR, "null input");
+ return;
+ }
+ if ((len > 0) && (ch == NULL)) {
+ LOG(LOG_ERR, "null input");
+ return;
+ }
+
/* copy to buf at ir_ctx, but check length first, ensuring additional space
for NULL terminator */
if ((ir_ctx->char_size + len + 1) > EVENTDATA_BUF_SIZE) {
- ERROR("Buffer for EVENTDATA is too small, %d + %d > %d\n", ir_ctx->char_size, len, EVENTDATA_BUF_SIZE);
+ LOG(LOG_ERR, "Buffer for EVENTDATA is too small, %d + %d > %d\n", ir_ctx->char_size, len, EVENTDATA_BUF_SIZE);
return;
}
memcpy(&ir_ctx->buf[ir_ctx->char_size], ch, len);
DEBUG("validateIr - start\n");
/* check */
- ASSERT(NULL != ctx, "ctx == NULL\n");
- ASSERT(NULL != ctx->target_conf, "ctx->target_conf == NULL\n");
- ASSERT(NULL != ctx->ir_filename, "ctx->ir_filename == NULL\n");
-
+ if (ctx == NULL) {
+ LOG(LOG_ERR, "null input");
+ return PTS_FATAL;
+ }
+ if (ctx->target_conf == NULL) {
+ LOG(LOG_ERR, "null input");
+ return PTS_FATAL;
+ }
+ if (ctx->ir_filename == NULL) {
+ LOG(LOG_ERR, "null input");
+ return PTS_FATAL;
+ }
conf = ctx->target_conf;
+ if (conf == NULL) {
+ LOG(LOG_ERR, "null input");
+ return PTS_FATAL;
+ }
/* new */
if (ctx->pcrs == NULL) {
// DEBUG("loadSQLiteDatabaseFile %s\n", ctx->conf->aide_sqlite_filename);
rc = loadSQLiteDatabaseFile(ctx->aide_ctx, conf->aide_sqlite_filename);
if (rc != PTS_SUCCESS) {
- ERROR("loadSQLiteDatabaseFile fail\n");
+ LOG(LOG_ERR, "loadSQLiteDatabaseFile fail\n");
rc = PTS_FATAL;
goto free;
}
#endif
} else {
// pre loaded (see iml2aide.c)
- TODO("AIDE DB pre loaded\n");
+ LOG(LOG_TODO, "AIDE DB pre loaded\n");
}
if (ctx->conf->aide_ignorelist_filename != NULL) {
}
// DEBUG("validatePcrComposite, ctx->conf->ir_without_quote %d\n", ctx->conf->ir_without_quote);
- // ERROR("conf->pubkey_length %d\n",conf->pubkey_length);
+ // LOG(LOG_ERR, "conf->pubkey_length %d\n",conf->pubkey_length);
/* validate PCR values by QuoteData */
if ((conf->iml_mode == 0) && (conf->ir_without_quote == 0)) {
addProperty(ctx, "tpm.quote.pcrs", "invalid");
}
} else {
- ERROR("PUBKEY is missing\n");
+ LOG(LOG_ERR, "PUBKEY is missing\n");
addProperty(ctx, "tpm.quote.pcrs", "unknown");
}
} else {
* @retval PTS_SUCCESS
* @retval PTS_INTERNAL_ERROR
*/
-int genIrFromSecurityfs(OPENPTS_CONTEXT *ctx, int *savedFd) {
+int genIrFromSecurityfs(
+ OPENPTS_CONTEXT *ctx,
+ int *savedFd /* out*/ ) {
int rc;
/* get IML via securityfs */
DEBUG("TPM Quote not work with config option iml.mode=securityfs\n");
#endif
+ /* check */
+ if (ctx == NULL) {
+ LOG(LOG_ERR, "null input");
+ return PTS_FATAL;
+ }
+
/* reset TPM emu */
resetTpm(&ctx->tpm, ctx->drtm);
/* setup FSM */
rc = readFsmFromPropFile(ctx, ctx->conf->config_file);
if (rc != PTS_SUCCESS) {
- ERROR("readFsmFromPropFile %s failed\n", ctx->conf->config_file);
+ LOG(LOG_ERR, "readFsmFromPropFile %s failed\n", ctx->conf->config_file);
return PTS_INTERNAL_ERROR;
}
/* read BIOS IML */
rc = readBiosImlFile(ctx, ctx->conf->bios_iml_filename, ctx->conf->iml_endian);
if (rc != PTS_SUCCESS) {
- ERROR("fail to load BIOS IML, rc = %d\n", rc);
+ LOG(LOG_ERR, "fail to load BIOS IML, rc = %d\n", rc);
return PTS_INTERNAL_ERROR;
}
rc = readImaImlFile(ctx, ctx->conf->runtime_iml_filename,
ctx->conf->runtime_iml_type, 0, &count); // TODO endian?
if (rc != PTS_SUCCESS) {
- ERROR("fail to load IMA IML, rc = %d\n", rc);
+ LOG(LOG_ERR, "fail to load IMA IML, rc = %d\n", rc);
return PTS_INTERNAL_ERROR;
}
}
/* read PCRS */
rc = getPcrBySysfsFile(ctx, ctx->conf->pcrs_filename);
if (rc < 0) {
- ERROR("fail to load PCR, rc = %d -- (pcr file is missing)\n", rc);
- TODO("Get or Create PCR file for this testcase\n");
+ LOG(LOG_ERR, "fail to load PCR, rc = %d -- (pcr file is missing)\n", rc);
+ LOG(LOG_TODO, "Get or Create PCR file for this testcase\n");
// return -1;
}
// do not use tempnum,
// if (ctx->conf->ir_filename != NULL) {
- // ERROR("Redefining the IR file location %s", ctx->conf->ir_filename);
+ // LOG(LOG_ERR, "Redefining the IR file location %s", ctx->conf->ir_filename);
// }
// ctx->conf->ir_filename = tempnam(NULL, "ir_");
- /* save IR */
- rc = writeIr(ctx, ctx->conf->ir_filename, savedFd);
+ /* save IR (new file in tmp dir) */
+ rc = writeIr(ctx, NULL, savedFd);
+ // rc = writeIr(ctx, ctx->ir_filename, savedFd);
if (rc != 0) {
- ERROR("fail to write IR, rc = %d\n", rc);
+ LOG(LOG_ERR, "fail to write IR, rc = %d\n", rc);
return PTS_INTERNAL_ERROR;
}
* @retval PTS_SUCCESS
* @retval PTS_INTERNAL_ERROR
*/
-int genIrFromTss(OPENPTS_CONTEXT *ctx, int *savedFd) {
+int genIrFromTss(
+ OPENPTS_CONTEXT *ctx,
+ int *savedFd /* out */ ) {
int rc;
+ /* check */
+ if (ctx == NULL) {
+ LOG(LOG_ERR, "null input");
+ return PTS_FATAL;
+ }
+
/* get IML via securityfs */
/* reset TPM emu */
// pcrSelect is set at PCR with FSM
rc = readFsmFromPropFile(ctx, ctx->conf->config_file); // fsm.c
if (rc != PTS_SUCCESS) {
- ERROR("read FSM failed\n");
+ LOG(LOG_ERR, "read FSM failed\n");
return PTS_INTERNAL_ERROR;
}
/* copy */
ctx->validation_data->rgbExternalData = malloc(ctx->nonce->nonce_length);
if (ctx->validation_data->rgbExternalData == NULL) {
- ERROR("no memory");
+ LOG(LOG_ERR, "no memory");
return PTS_FATAL;
}
memcpy(
ctx->nonce->nonce,
ctx->nonce->nonce_length);
} else {
- ERROR("genIrFromTss - nonce is missing, DH-nonce? \n");
+ LOG(LOG_ERR, "genIrFromTss - nonce is missing, DH-nonce? \n");
ctx->validation_data->ulExternalDataLength = 0;
ctx->validation_data->rgbExternalData = NULL;
}
if (ctx->conf->ir_without_quote == 1) {
- TODO("skip TPM_Quote\n");
+ LOG(LOG_TODO, "skip TPM_Quote\n");
} else {
/* TPM Quote or TPM Quote2 */
if (ctx->conf->tpm_quote_type == 1) {
ctx->validation_data); // tss.c
}
if (rc != 0) {
- ERROR("quoteTss fail, rc = 0x%04d\n", rc);
+ LOG(LOG_ERR, "quoteTss fail, rc = 0x%04d\n", rc);
return PTS_INTERNAL_ERROR;
}
}
/* set PCR to snapshot */
rc = setPcrsToSnapshot(ctx, ctx->pcrs); // TODO
if (rc < 0) {
- ERROR("fail to load PCR, rc = %d\n", rc);
+ LOG(LOG_ERR, "fail to load PCR, rc = %d\n", rc);
return PTS_INTERNAL_ERROR;
}
/* get BIOS/IMA IML */
rc = getIml(ctx, 0);
if (rc < 0) {
- ERROR("fail to load BIOS IML, rc = %d\n", rc);
+ LOG(LOG_ERR, "fail to load BIOS IML, rc = %d\n", rc);
return PTS_INTERNAL_ERROR;
}
if (ctx->conf->ir_filename != NULL) {
- ERROR("Redefining the IR file location %s", ctx->conf->ir_filename);
+ LOG(LOG_ERR, "Redefining the IR file location %s", ctx->conf->ir_filename);
}
- //ctx->conf->ir_filename = tempnam(NULL, "ir_");
- //DEBUG("ctx->conf->ir_filename : %s\n", ctx->conf->ir_filename);
- /* save IR */
- rc = writeIr(ctx, ctx->conf->ir_filename, savedFd); // ir.c
+ /* save IR (new file in tmp dir) */
+ rc = writeIr(ctx, NULL, savedFd);
if (rc != 0) {
- ERROR("fail to write IR, rc = %d\n", rc);
+ LOG(LOG_ERR, "fail to write IR, rc = %d\n", rc);
return PTS_INTERNAL_ERROR;
}
* @retval PTS_SUCCESS
* @retval PTS_INTERNAL_ERROR
*/
-int genIr(OPENPTS_CONTEXT *ctx, int *savedFd) {
+int genIr(
+ OPENPTS_CONTEXT *ctx,
+ int *savedFd /* out */) {
int rc = PTS_INTERNAL_ERROR;
+
+ /* check */
+ if (ctx == NULL) {
+ LOG(LOG_ERR, "null input");
+ return PTS_FATAL;
+ }
+
+
+ /* gen */
if (ctx->conf->iml_mode == 1) {
rc = genIrFromSecurityfs(ctx, savedFd);
if (rc != PTS_SUCCESS) {
- ERROR("writePtsTlvToSock - gen IR failed\n");
+ LOG(LOG_ERR, "writePtsTlvToSock - gen IR failed\n");
return rc;
}
} else {
#ifdef CONFIG_NO_TSS
- TODO("OpenPTS was build with --without-tss and config option iml.mode=tssand, skip IR gen.\n");
+ LOG(LOG_TODO, "OpenPTS was build with --without-tss and config option iml.mode=tssand, skip IR gen.\n");
#else
// DEBUG("get IML/PCR via TSS is not ready\n");
rc = genIrFromTss(ctx, savedFd);
if (rc != PTS_SUCCESS) {
- ERROR("gen IR failed\n");
+ LOG(LOG_ERR, "gen IR failed\n");
return rc;
}
#endif