Repo for OpenPTS version 0.2.X
修订版 | 12470d822a7130b2968d0dd598ff838c7a244ab3 (tree) |
---|---|
时间 | 2012-01-05 14:40:05 |
作者 | Seiji Munetoh <munetoh@jp.i...> |
Commiter | Seiji Munetoh |
cleanup
@@ -7,11 +7,13 @@ openpts (0.2.6) unstable; urgency=low | ||
7 | 7 | * Locking to ensure only one instance of ptsc and openpts will run at the same time. |
8 | 8 | * Added the doorbell ringer(ptsevt) and the listener (ptsevtd) |
9 | 9 | * Added clear option. e.g. ptsc -e |
10 | - * Improved error handling and messages | |
10 | + * Improved error handling and messages (console and logging) | |
11 | 11 | * Renew validation models (models/*uml), default ptsc.conf |
12 | 12 | * Added UEFI BIOS validation models |
13 | + * Refactoring Infineon v1.2 TPM workaround | |
14 | + * Bug fixes | |
13 | 15 | |
14 | - -- Seiji Munetoh <munetoh@users.sourceforge.jp> Fri, 16 Dec 2011 12:00:00 +0900 | |
16 | + -- Seiji Munetoh <munetoh@users.sourceforge.jp> Thu, 5 Jan 2012 14:40:00 +0900 | |
15 | 17 | |
16 | 18 | openpts (0.2.5.1) unstable; urgency=low |
17 | 19 |
@@ -703,9 +703,9 @@ int writePtsTlv(OPENPTS_CONTEXT *ctx, int fd, int type); | ||
703 | 703 | |
704 | 704 | |
705 | 705 | /* collector.c */ |
706 | -int collector( | |
707 | - OPENPTS_CONFIG *conf, | |
708 | - int forground, int debug, const char* dirname); | |
706 | +//int collector( | |
707 | +// OPENPTS_CONFIG *conf, | |
708 | +// int forground, int debug, const char* dirname); | |
709 | 709 | |
710 | 710 | /* verifier.c */ |
711 | 711 | int verifier( |
@@ -940,6 +940,7 @@ int getRmList(OPENPTS_CONFIG *conf, char * config_dir); | ||
940 | 940 | int purgeRenewedRm(OPENPTS_CONFIG *conf); |
941 | 941 | void printRmList(OPENPTS_CONFIG *conf, char *indent); |
942 | 942 | int getTargetList(OPENPTS_CONFIG *conf, char * config_dir); |
943 | +void printTarget(OPENPTS_TARGET *target_collector, char *indent); | |
943 | 944 | void printTargetList(OPENPTS_CONFIG *conf, char *indent); |
944 | 945 | char *getTargetConfDir(OPENPTS_CONFIG *conf); |
945 | 946 | OPENPTS_TARGET *getTargetCollector(OPENPTS_CONFIG *conf); |
@@ -27,6 +27,7 @@ | ||
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @author David Sherwood <davidshe@uk.ibm.com> |
29 | 29 | * @date 2011-05-05 |
30 | + * cleanup 2012-01-04 | |
30 | 31 | * |
31 | 32 | */ |
32 | 33 |
@@ -113,9 +114,7 @@ writeLog(LOG_DEBUG, "%s:%4d " fmt, __FILE__, __LINE__, ##__VA_ARGS__) | ||
113 | 114 | #define getDebugFlags() (debugBits) |
114 | 115 | #define addDebugFlags(x) (debugBits |= (x)) |
115 | 116 | |
116 | - | |
117 | - | |
118 | - | |
117 | +/* functions */ | |
119 | 118 | void writeLog(int priority, const char *format, ...); |
120 | 119 | void initCatalog(void); |
121 | 120 | void setLogLocation(int ll, char *filename); |
@@ -45,6 +45,7 @@ fsm.c,2446,,OPENPTS_PRINT_FSM_BASE64 | ||
45 | 45 | rm.c,1751,,OPENPTS_RM_CONF_DIR_MISSING |
46 | 46 | log.c,368,,OPENPTS_CANNOT_OPEN_LOGFILE |
47 | 47 | action.c,,,OPENPTS_ACTION_UNKNOWN |
48 | +action.c,,VERBOSE,OPENPTS_ACTION_PROP_CONFLICT | |
48 | 49 | prop.c,,,OPENPTS_PRINT_PROPS |
49 | 50 | policy.c,,,OPENPTS_POLICY_FILE_OPEN_FAILED |
50 | 51 | policy.c,,,OPENPTS_POLICY_MISSING |
@@ -88,6 +89,8 @@ collector.c,,,OPENPTS_INIT_SUCCESS | ||
88 | 89 | collector.c,,,OPENPTS_INIT_FAIL |
89 | 90 | collector.c,,,OPENPTS_COLLECTOR_SELFTEST_FAILED |
90 | 91 | collector.c,,,OPENPTS_COLLECTOR_SELFTEST_FAILED_2 |
92 | +collector.c,,ERROR,OPENPTS_COLLECTOR_SELFTEST_FAILED_3 | |
93 | +collector.c,,ERROR,OPENPTS_COLLECTOR_SELFTEST_FAILED_4 | |
91 | 94 | collector.c,,,OPENPTS_COLLECTOR_FAILED_READ_FSM |
92 | 95 | collector.c,,,OPENPTS_COLLECTOR_MKDIR_RM_SET_FAILED |
93 | 96 | collector.c,,,OPENPTS_NEW_RM_UUID |
@@ -230,11 +233,17 @@ iml2aide.c,,,OPENPTS_IML2AIDE_DATABASE_2 | ||
230 | 233 | iml2aide.c,,,OPENPTS_IML2AIDE_IGN_LIST |
231 | 234 | openpts.c,,,OPENPTS_VERIFY_NEW_UUID_REMOTE |
232 | 235 | tpm_createkey.c,,,OPENPTS_TPM_CREATEKEY_USAGE |
233 | - | |
234 | - | |
235 | - | |
236 | - | |
237 | - | |
238 | - | |
239 | - | |
236 | +verifier.c,,,OPENPTS_VERIFIER_LOCKED | |
237 | +openpts.c,,,OPENPTS_TARGET_MISSING | |
238 | +openpts.c,,,OPENPTS_INIT_ENROLL_FAIL | |
239 | +openpts.c,,,OPENPTS_INIT_VERIFICATION_FAIL | |
240 | +target,,,OPENPTS_PRINT_TARGET_LIST_NULL | |
241 | +target,,,OPENPTS_TARGET_CONFDIR_MISSING | |
242 | +target,,,OPENPTS_TARGET_NULL | |
243 | +ptsc.c,,,OPENPTS_COLLECTOR_NOT_INITIALIZED | |
244 | +ptsc.c,,,OPENPTS_COLLECTOR_CONFIG_FILE | |
245 | +misc.c,,ERROR,OPENPTS_MALLOC_FAIL | |
246 | +misc.c,,ERROR,OPENPTS_ABORT | |
247 | +tboot2iml.c,,OUTPUT,OPENPTS_TBOOT2IML_USAGE | |
248 | +tboot2iml.c,,ERROR,OPENPTS_TBOOT2IML_GRUBPATH_MISSING | |
240 | 249 |
@@ -26,7 +26,7 @@ | ||
26 | 26 | * \brief FSM action |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2010-06-19 |
29 | - * cleanup 2011-07-20 SM | |
29 | + * cleanup 2012-01-05 SM (remains 5 lint errors) | |
30 | 30 | * |
31 | 31 | * FSM Action (UML2 doActivity) |
32 | 32 | * |
@@ -85,9 +85,20 @@ typedef struct { | ||
85 | 85 | */ |
86 | 86 | int resetPCR(OPENPTS_CONTEXT *ctx, char *value) { |
87 | 87 | int rc; |
88 | - int pcr_index = atoi(value); | |
88 | + int pcr_index; | |
89 | 89 | |
90 | - DEBUG_FSM("resetPCR(%d)\n", pcr_index); | |
90 | + /* check */ | |
91 | + if (ctx == NULL) { | |
92 | + LOG(LOG_ERR, "null input"); | |
93 | + return PTS_FATAL; | |
94 | + } | |
95 | + if (value == NULL) { | |
96 | + LOG(LOG_ERR, "null input"); | |
97 | + return PTS_FATAL; | |
98 | + } | |
99 | + pcr_index = atoi(value); | |
100 | + | |
101 | + /* reset */ | |
91 | 102 | rc = resetTpmPcr(&ctx->tpm, pcr_index); |
92 | 103 | if (rc != PTS_SUCCESS) { |
93 | 104 | LOG(LOG_ERR, "reset PCR[%d] was failed, check the model"); |
@@ -97,6 +108,8 @@ int resetPCR(OPENPTS_CONTEXT *ctx, char *value) { | ||
97 | 108 | /* Also, reset the action counter */ |
98 | 109 | ctx->bios_action_count = 0; |
99 | 110 | |
111 | + DEBUG_FSM("resetPCR(%d)\n", pcr_index); | |
112 | + | |
100 | 113 | return PTS_SUCCESS; |
101 | 114 | } |
102 | 115 |
@@ -118,21 +131,25 @@ int addBIOSAction(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) | ||
118 | 131 | |
119 | 132 | /* check */ |
120 | 133 | if (eventWrapper == NULL) { |
121 | - // TODO do not care for dummy EW | |
122 | - DEBUG("null input\n"); // TODO is this OK? | |
123 | - // TODO define RC <-> fsm.c >> INFO:(TODO) fsm.c:986 updateFsm() - rc = 58, call updateFsm() again | |
134 | + // do not care for dummy EW, not a error. | |
135 | + DEBUG("null input"); | |
124 | 136 | return PTS_INTERNAL_ERROR; |
125 | 137 | } |
138 | + if (ctx == NULL) { | |
139 | + LOG(LOG_ERR, "null input"); | |
140 | + return PTS_FATAL; | |
141 | + } | |
126 | 142 | |
127 | 143 | event = eventWrapper->event; |
128 | 144 | if (event == NULL) { |
129 | - LOG(LOG_ERR, "null input\n"); | |
145 | + LOG(LOG_ERR, "null input"); | |
130 | 146 | return PTS_FATAL; |
131 | 147 | } |
132 | 148 | |
133 | 149 | /* value = eventdata */ |
134 | 150 | value = snmalloc((char *)event->rgbEvent, event->ulEventLength); |
135 | 151 | if (value == NULL) { |
152 | + LOG(LOG_ERR, "no memory"); | |
136 | 153 | return PTS_FATAL; |
137 | 154 | } |
138 | 155 |
@@ -141,11 +158,11 @@ int addBIOSAction(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) | ||
141 | 158 | snprintf(name, BUF_SIZE, "bios.pcr.%d.action.%d", event->ulPcrIndex, ctx->bios_action_count); |
142 | 159 | ctx->bios_action_count++; |
143 | 160 | |
161 | + setProperty(ctx, name, value); | |
144 | 162 | |
145 | 163 | DEBUG_FSM("[FSM] addBIOSAction() - '%s' = '%s'\n", name, value); |
146 | 164 | |
147 | - setProperty(ctx, name, value); | |
148 | - | |
165 | + /* free */ | |
149 | 166 | xfree(value); |
150 | 167 | |
151 | 168 | return PTS_SUCCESS; |
@@ -173,21 +190,23 @@ int addBIOSSpecificProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eve | ||
173 | 190 | UINT32 event_id; |
174 | 191 | UINT32 event_length; |
175 | 192 | |
193 | + /* check */ | |
194 | + if (ctx == NULL) { | |
195 | + LOG(LOG_ERR, "null input"); | |
196 | + return PTS_FATAL; | |
197 | + } | |
198 | + | |
176 | 199 | /* event */ |
177 | 200 | if (eventWrapper == NULL) { |
178 | 201 | LOG(LOG_ERR, "addBIOSSpecificProperty- eventWrapper is NULL\n"); |
179 | 202 | return PTS_INTERNAL_ERROR; // -1 |
180 | 203 | } |
181 | 204 | event = eventWrapper->event; |
182 | - | |
183 | 205 | if (event->eventType != 0x06) { |
184 | 206 | LOG(LOG_ERR, "addBIOSSpecificProperty - bad event type 0x%x !- 0x06\n", event->eventType); |
185 | 207 | return PTS_INTERNAL_ERROR; // -1 |
186 | 208 | } |
187 | 209 | |
188 | - // DEBUG("event data size = %d\n", event->ulEventLength); | |
189 | - // printHex("", event->rgbEvent, event->ulEventLength, "\n"); | |
190 | - | |
191 | 210 | /* check EventData */ |
192 | 211 | if (event->ulEventLength == 0) { |
193 | 212 | LOG(LOG_ERR, "addBIOSSpecificProperty - Bad IML, ulEventLength is 0."); |
@@ -198,12 +217,10 @@ int addBIOSSpecificProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eve | ||
198 | 217 | return PTS_FATAL; |
199 | 218 | } |
200 | 219 | |
201 | - | |
220 | + /* event */ | |
202 | 221 | event_id = byte2uint32(&event->rgbEvent[0]); |
203 | 222 | event_length = byte2uint32(&event->rgbEvent[4]); |
204 | 223 | |
205 | - // DEBUG("event data size = %d, id = 0x%x, len %d,\n", event->ulEventLength, event_id, event_length); | |
206 | - | |
207 | 224 | switch (event_id) { |
208 | 225 | case 0x0001: |
209 | 226 | { |
@@ -229,7 +246,6 @@ int addBIOSSpecificProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eve | ||
229 | 246 | } else { |
230 | 247 | setProperty(ctx, "bios.smbios", buf); |
231 | 248 | } |
232 | - // rc = 0; | |
233 | 249 | xfree(buf); |
234 | 250 | } |
235 | 251 | break; |
@@ -239,7 +255,7 @@ int addBIOSSpecificProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eve | ||
239 | 255 | break; |
240 | 256 | } |
241 | 257 | |
242 | - return PTS_SUCCESS; // -1; | |
258 | + return PTS_SUCCESS; | |
243 | 259 | } |
244 | 260 | |
245 | 261 |
@@ -253,16 +269,21 @@ int addBIOSSpecificProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eve | ||
253 | 269 | int validateMBR(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) { |
254 | 270 | TSS_PCR_EVENT *event; |
255 | 271 | |
272 | + /* check */ | |
273 | + if (ctx == NULL) { | |
274 | + LOG(LOG_ERR, "null input"); | |
275 | + return PTS_FATAL; | |
276 | + } | |
256 | 277 | if (eventWrapper == NULL) { |
257 | 278 | LOG(LOG_ERR, "null input"); |
258 | - return PTS_INTERNAL_ERROR; // -1; | |
279 | + return PTS_FATAL; | |
259 | 280 | } |
260 | 281 | |
261 | 282 | event = eventWrapper->event; |
262 | 283 | |
263 | 284 | if (event == NULL) { |
264 | 285 | LOG(LOG_ERR, "event is NULL\n"); |
265 | - return PTS_INTERNAL_ERROR; // -1; | |
286 | + return PTS_FATAL; // -1; | |
266 | 287 | } |
267 | 288 | |
268 | 289 | // TODO |
@@ -287,22 +308,25 @@ int validateMBR(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) { | ||
287 | 308 | int validateEltoritoBootImage(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) { |
288 | 309 | TSS_PCR_EVENT *event; |
289 | 310 | |
290 | - // DEBUG("validateEltoritoBootImage - NA\n"); | |
291 | - | |
311 | + /* check */ | |
312 | + if (ctx == NULL) { | |
313 | + LOG(LOG_ERR, "null input"); | |
314 | + return PTS_FATAL; | |
315 | + } | |
292 | 316 | if (eventWrapper == NULL) { |
293 | 317 | LOG(LOG_ERR, "eventWrapper is NULL\n"); |
294 | - return PTS_INTERNAL_ERROR; // -1; | |
318 | + return PTS_FATAL; | |
295 | 319 | } |
296 | - | |
297 | 320 | event = eventWrapper->event; |
298 | 321 | if (event == NULL) { |
299 | 322 | LOG(LOG_ERR, "event is NULL\n"); |
300 | - return PTS_INTERNAL_ERROR; // -1; | |
323 | + return PTS_FATAL; | |
301 | 324 | } |
302 | 325 | |
326 | + /* set prop */ | |
303 | 327 | setProperty(ctx, "ipl.eltorito.integrity", "unknown"); |
304 | 328 | |
305 | - return PTS_SUCCESS; // -1; | |
329 | + return PTS_SUCCESS; | |
306 | 330 | } |
307 | 331 | |
308 | 332 | /** |
@@ -320,19 +344,19 @@ int setModuleProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrap | ||
320 | 344 | char *buf; |
321 | 345 | int buf_len; |
322 | 346 | |
323 | - // DEBUG("setModuleProperty - NA\n"); | |
324 | - | |
325 | 347 | /* check */ |
348 | + if (ctx == NULL) { | |
349 | + LOG(LOG_ERR, "null input"); | |
350 | + return PTS_FATAL; | |
351 | + } | |
326 | 352 | if (eventWrapper == NULL) { |
327 | 353 | LOG(LOG_ERR, "eventWrapper is NULL\n"); |
328 | - return PTS_INTERNAL_ERROR; // -1; | |
354 | + return PTS_FATAL; | |
329 | 355 | } |
330 | - | |
331 | 356 | event = eventWrapper->event; |
332 | - | |
333 | 357 | if (event == NULL) { |
334 | 358 | LOG(LOG_ERR, "event is NULL\n"); |
335 | - return PTS_INTERNAL_ERROR; // -1; | |
359 | + return PTS_FATAL; | |
336 | 360 | } |
337 | 361 | |
338 | 362 | /* kernel.initrd.digest = PCR => B64 digest */ |
@@ -342,7 +366,7 @@ int setModuleProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrap | ||
342 | 366 | &buf_len); |
343 | 367 | if (buf == NULL) { |
344 | 368 | LOG(LOG_ERR, "encodeBase64 fail"); |
345 | - return PTS_INTERNAL_ERROR; | |
369 | + return PTS_FATAL; | |
346 | 370 | } |
347 | 371 | setProperty(ctx, "kernel.initrd.digest", buf); |
348 | 372 | xfree(buf); |
@@ -355,6 +379,9 @@ int setModuleProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrap | ||
355 | 379 | buf[event->ulEventLength] = 0; |
356 | 380 | setProperty(ctx, "kernel.initrd.filename", buf); |
357 | 381 | xfree(buf); |
382 | + } else { | |
383 | + LOG(LOG_ERR, "no memory"); | |
384 | + return PTS_FATAL; | |
358 | 385 | } |
359 | 386 | |
360 | 387 | return PTS_SUCCESS; // -1; |
@@ -396,19 +423,20 @@ int setLinuxKernelCmdlineAssertion(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPP | ||
396 | 423 | |
397 | 424 | DEBUG_CAL("setLinuxKernelCmdlineAssertion - start\n"); |
398 | 425 | |
399 | - /* input check */ | |
426 | + /* check */ | |
427 | + if (ctx == NULL) { | |
428 | + LOG(LOG_ERR, "null input"); | |
429 | + return PTS_FATAL; | |
430 | + } | |
400 | 431 | if (eventWrapper == NULL) { |
401 | 432 | LOG(LOG_ERR, "eventWrapper is NULL\n"); |
402 | 433 | return PTS_FATAL; |
403 | 434 | } |
404 | - | |
405 | 435 | event = eventWrapper->event; |
406 | - | |
407 | 436 | if (event == NULL) { |
408 | 437 | LOG(LOG_ERR, "event is NULL\n"); |
409 | 438 | return PTS_FATAL; |
410 | 439 | } |
411 | - | |
412 | 440 | if (event->rgbEvent == NULL) { |
413 | 441 | LOG(LOG_ERR, "event->rgbEvent is NULL, BAD IML?\n"); |
414 | 442 | return PTS_FATAL; |
@@ -420,6 +448,10 @@ int setLinuxKernelCmdlineAssertion(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPP | ||
420 | 448 | |
421 | 449 | /* copy(malloc) strings */ |
422 | 450 | cmdline = snmalloc((char *)event->rgbEvent, event->ulEventLength); |
451 | + if (cmdline == NULL) { | |
452 | + LOG(LOG_ERR, "snmalloc() fail"); | |
453 | + return PTS_FATAL; | |
454 | + } | |
423 | 455 | |
424 | 456 | /* first string = kernel filename */ |
425 | 457 | tp = strtok_r(cmdline, " ", &saveptr); |
@@ -443,8 +475,8 @@ int setLinuxKernelCmdlineAssertion(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPP | ||
443 | 475 | "Property %s=%s and %s=%s are conflicted. Drop them from the policy list.", |
444 | 476 | name, prop->value, |
445 | 477 | name, value); |
446 | - VERBOSE(2, // TODO NLS | |
447 | - "Property %s=%s and %s=%s are conflicted. Drop them from the policy list.", | |
478 | + VERBOSE(2, NLS(MS_OPENPTS, OPENPTS_ACTION_PROP_CONFLICT, | |
479 | + "Property %s=%s and %s=%s are conflicted. Drop them from the policy list."), | |
448 | 480 | name, prop->value, |
449 | 481 | name, value); |
450 | 482 | prop->ignore = 1; |
@@ -500,19 +532,23 @@ int validateImaAggregate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventW | ||
500 | 532 | SHA_CTX sha_ctx; |
501 | 533 | BYTE digest[SHA1_DIGEST_SIZE]; |
502 | 534 | |
503 | - // DEBUG("validateImaAggregate - NA\n"); | |
504 | - | |
505 | 535 | /* check */ |
536 | + if (ctx == NULL) { | |
537 | + LOG(LOG_ERR, "null input"); | |
538 | + return PTS_FATAL; | |
539 | + } | |
506 | 540 | if (eventWrapper == NULL) { |
507 | 541 | LOG(LOG_ERR, "null input\n"); |
508 | - return PTS_INTERNAL_ERROR; // -1; | |
542 | + return PTS_FATAL; | |
509 | 543 | } |
510 | - | |
511 | 544 | event = eventWrapper->event; |
512 | - | |
513 | 545 | if (event == NULL) { |
514 | 546 | LOG(LOG_ERR, "event is NULL\n"); |
515 | - return PTS_INTERNAL_ERROR; // -1; | |
547 | + return PTS_FATAL; | |
548 | + } | |
549 | + if (event->rgbEvent == NULL) { | |
550 | + LOG(LOG_ERR, "null input\n"); | |
551 | + return PTS_FATAL; | |
516 | 552 | } |
517 | 553 | |
518 | 554 | /* init SHA1 */ |
@@ -589,18 +625,23 @@ int validateOldImaAggregate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eve | ||
589 | 625 | SHA_CTX sha_ctx; |
590 | 626 | BYTE digest[SHA1_DIGEST_SIZE]; |
591 | 627 | |
592 | - // DEBUG("validateOldImaAggregate - NA\n"); | |
593 | - | |
594 | 628 | /* check */ |
629 | + if (ctx == NULL) { | |
630 | + LOG(LOG_ERR, "null input"); | |
631 | + return PTS_FATAL; | |
632 | + } | |
595 | 633 | if (eventWrapper == NULL) { |
596 | - LOG(LOG_ERR, "eventWrapper is NULL\n"); | |
597 | - return PTS_INTERNAL_ERROR; // -1; | |
634 | + LOG(LOG_ERR, "eventWrapper is NULL"); | |
635 | + return PTS_FATAL; | |
598 | 636 | } |
599 | - | |
600 | 637 | event = eventWrapper->event; |
601 | 638 | if (event == NULL) { |
602 | - LOG(LOG_ERR, "event is NULL\n"); | |
603 | - return PTS_INTERNAL_ERROR; // -1; | |
639 | + LOG(LOG_ERR, "event is NULL"); | |
640 | + return PTS_FATAL; | |
641 | + } | |
642 | + if (event->rgbPcrValue == NULL) { | |
643 | + LOG(LOG_ERR, "null input"); | |
644 | + return PTS_FATAL; | |
604 | 645 | } |
605 | 646 | |
606 | 647 | /* init SHA1 */ |
@@ -636,6 +677,24 @@ int validateOldImaAggregate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eve | ||
636 | 677 | int updateImaProperty(OPENPTS_CONTEXT *ctx, char* name, char* b64digest, char *integrity) { |
637 | 678 | char prop_name[256]; |
638 | 679 | |
680 | + /* check */ | |
681 | + if (ctx == NULL) { | |
682 | + LOG(LOG_ERR, "null input"); | |
683 | + return PTS_FATAL; | |
684 | + } | |
685 | + if (name == NULL) { | |
686 | + LOG(LOG_ERR, "null input"); | |
687 | + return PTS_FATAL; | |
688 | + } | |
689 | + if (b64digest == NULL) { | |
690 | + LOG(LOG_ERR, "null input"); | |
691 | + return PTS_FATAL; | |
692 | + } | |
693 | + if (integrity == NULL) { | |
694 | + LOG(LOG_ERR, "null input"); | |
695 | + return PTS_FATAL; | |
696 | + } | |
697 | + | |
639 | 698 | /* integrity */ |
640 | 699 | snprintf(prop_name, sizeof(prop_name), "ima.%d.integrty", ctx->ima_count); |
641 | 700 | setProperty(ctx, prop_name, integrity); |
@@ -674,6 +733,11 @@ int validateImaMeasurement(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *even | ||
674 | 733 | |
675 | 734 | DEBUG_CAL("validateImaMeasurement - start\n"); |
676 | 735 | |
736 | + /* check */ | |
737 | + if (ctx == NULL) { | |
738 | + LOG(LOG_ERR, "null input"); | |
739 | + return PTS_FATAL; | |
740 | + } | |
677 | 741 | if (eventWrapper == NULL) { |
678 | 742 | /* Just ignore the NULL event */ |
679 | 743 | // TODO(munetoh) Detect LOOP |
@@ -688,6 +752,12 @@ int validateImaMeasurement(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *even | ||
688 | 752 | |
689 | 753 | #ifdef CONFIG_AIDE |
690 | 754 | event = eventWrapper->event; |
755 | + /* check */ | |
756 | + if (event == NULL) { | |
757 | + LOG(LOG_ERR, "null input"); | |
758 | + return PTS_FATAL; | |
759 | + } | |
760 | + | |
691 | 761 | if (ctx->conf->ima_validation_mode == OPENPTS_VALIDATION_MODE_AIDE) { |
692 | 762 | int rc = 0; |
693 | 763 | char *name; |
@@ -801,6 +871,12 @@ int validateImaMeasurementNG(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *ev | ||
801 | 871 | * |
802 | 872 | */ |
803 | 873 | int resetCounter(OPENPTS_CONTEXT *ctx) { |
874 | + /* check */ | |
875 | + if (ctx == NULL) { | |
876 | + LOG(LOG_ERR, "null input"); | |
877 | + return PTS_FATAL; | |
878 | + } | |
879 | + | |
804 | 880 | ctx->count = 0; |
805 | 881 | |
806 | 882 | // DEBUG("[FSM] resetCounter()"); |
@@ -811,6 +887,12 @@ int resetCounter(OPENPTS_CONTEXT *ctx) { | ||
811 | 887 | * |
812 | 888 | */ |
813 | 889 | int incrementCounter(OPENPTS_CONTEXT *ctx) { |
890 | + /* check */ | |
891 | + if (ctx == NULL) { | |
892 | + LOG(LOG_ERR, "null input"); | |
893 | + return PTS_FATAL; | |
894 | + } | |
895 | + | |
814 | 896 | ctx->count += 1; |
815 | 897 | |
816 | 898 | // DEBUG("[FSM] incrementCounter() %d => %d\n", ctx->count -1, ctx->count); |
@@ -899,12 +981,21 @@ int addIntelTxtTbootProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *ev | ||
899 | 981 | |
900 | 982 | DEBUG_FSM("addIntelTxtTbootProperty - start\n"); |
901 | 983 | |
984 | + /* check */ | |
985 | + if (ctx == NULL) { | |
986 | + LOG(LOG_ERR, "null input"); | |
987 | + return PTS_FATAL; | |
988 | + } | |
902 | 989 | /* event */ |
903 | 990 | if (eventWrapper == NULL) { |
904 | 991 | LOG(LOG_ERR, "addBIOSSpecificProperty- eventWrapper is NULL\n"); |
905 | 992 | return -1; |
906 | 993 | } |
907 | 994 | event = eventWrapper->event; |
995 | + if (event == NULL) { | |
996 | + LOG(LOG_ERR, "null input"); | |
997 | + return PTS_FATAL; | |
998 | + } | |
908 | 999 | |
909 | 1000 | switch (event->eventType) { |
910 | 1001 | case EV_TBOOT_SINIT_V6: |
@@ -1029,7 +1120,6 @@ int addIntelTxtTbootProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *ev | ||
1029 | 1120 | // TODO |
1030 | 1121 | ctx->drtm = 1; |
1031 | 1122 | |
1032 | - // setProperty(ctx, "kernel.commandline", "TBD"); | |
1033 | 1123 | return PTS_SUCCESS; |
1034 | 1124 | } |
1035 | 1125 | #endif |
@@ -1042,10 +1132,19 @@ int addIntelTxtTbootProperty(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *ev | ||
1042 | 1132 | int saveCounter(OPENPTS_CONTEXT *ctx, char * name) { |
1043 | 1133 | char buf[128]; // TODO |
1044 | 1134 | |
1135 | + /* check */ | |
1136 | + if (ctx == NULL) { | |
1137 | + LOG(LOG_ERR, "null input"); | |
1138 | + return PTS_FATAL; | |
1139 | + } | |
1140 | + if (name == NULL) { | |
1141 | + LOG(LOG_ERR, "null input"); | |
1142 | + return PTS_FATAL; | |
1143 | + } | |
1144 | + | |
1045 | 1145 | snprintf(buf, sizeof(buf), "%d", ctx->count); |
1046 | 1146 | addProperty(ctx, name, buf); |
1047 | 1147 | |
1048 | - // DEBUG("[FSM] saveCounter() %s = %s\n", name, buf); | |
1049 | 1148 | |
1050 | 1149 | return PTS_SUCCESS; |
1051 | 1150 | } |
@@ -1247,7 +1346,7 @@ int doActivity( | ||
1247 | 1346 | if (eventWrapper == NULL) { |
1248 | 1347 | /* NULL event, skip evaluation */ |
1249 | 1348 | DEBUG_FSM("doActivity - eventWrapper is NULL, skip evaluation\n"); |
1250 | - // return 1; //OPENPTS_FSM_SUCCESS; | |
1349 | + // check again by each func | |
1251 | 1350 | } |
1252 | 1351 | |
1253 | 1352 | /* copy */ |
@@ -26,7 +26,7 @@ | ||
26 | 26 | * \brief AIDE I/F APIs |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2010-06-13 |
29 | - * cleanup 2011-07-06 SM | |
29 | + * cleanup 2012-01-05 SM | |
30 | 30 | * |
31 | 31 | * 1) Integrity check with AIDE |
32 | 32 | * |
@@ -98,7 +98,11 @@ AIDE_METADATA * newAideMetadata() { | ||
98 | 98 | * TODO(munetoh) sep. all and single |
99 | 99 | */ |
100 | 100 | void freeAideMetadata(AIDE_METADATA *md) { |
101 | - if (md == NULL) return; | |
101 | + /* check */ | |
102 | + if (md == NULL) { | |
103 | + LOG(LOG_ERR, "null input"); | |
104 | + return; | |
105 | + } | |
102 | 106 | |
103 | 107 | if (md->next != NULL) { |
104 | 108 | freeAideMetadata(md->next); |
@@ -124,6 +128,16 @@ void freeAideMetadata(AIDE_METADATA *md) { | ||
124 | 128 | int addAideMetadata(AIDE_CONTEXT *ctx, AIDE_METADATA *md) { |
125 | 129 | int rc = 0; |
126 | 130 | |
131 | + /* check */ | |
132 | + if (ctx == NULL) { | |
133 | + LOG(LOG_ERR, "null input"); | |
134 | + return PTS_FATAL; | |
135 | + } | |
136 | + if (md == NULL) { | |
137 | + LOG(LOG_ERR, "null input"); | |
138 | + return PTS_FATAL; | |
139 | + } | |
140 | + | |
127 | 141 | /* update ctx*/ |
128 | 142 | if (ctx->start == NULL) { |
129 | 143 | /* first metadata */ |
@@ -158,10 +172,9 @@ AIDE_CONTEXT * newAideContext() { | ||
158 | 172 | int rc; |
159 | 173 | AIDE_CONTEXT *ctx; |
160 | 174 | |
161 | - // DEBUG("newAideContext()\n"); | |
162 | - | |
163 | 175 | ctx = xmalloc(sizeof(AIDE_CONTEXT)); |
164 | 176 | if (ctx == NULL) { |
177 | + LOG(LOG_ERR, "no memory"); | |
165 | 178 | return NULL; |
166 | 179 | } |
167 | 180 | memset(ctx, 0, sizeof(AIDE_CONTEXT)); |
@@ -179,7 +192,10 @@ AIDE_CONTEXT * newAideContext() { | ||
179 | 192 | ctx->aide_md_table_size = 0; |
180 | 193 | |
181 | 194 | ctx->aide_in_table = xmalloc(sizeof(struct hsearch_data)); |
182 | - // TODO ck null | |
195 | + if (ctx->aide_in_table == NULL) { | |
196 | + LOG(LOG_ERR, "no memory"); | |
197 | + goto error; | |
198 | + } | |
183 | 199 | memset(ctx->aide_in_table, 0, sizeof(struct hsearch_data)); |
184 | 200 | // 4096 full |
185 | 201 | rc = hcreate_r(AIDE_HASH_TABLE_SIZE, ctx->aide_in_table); // hash table for ignore name |
@@ -201,7 +217,9 @@ AIDE_CONTEXT * newAideContext() { | ||
201 | 217 | * |
202 | 218 | */ |
203 | 219 | void freeAideIgnoreList(AIDE_LIST *list) { |
220 | + /* check */ | |
204 | 221 | if (list == NULL) { |
222 | + LOG(LOG_ERR, "null input"); | |
205 | 223 | return; |
206 | 224 | } |
207 | 225 |
@@ -325,6 +343,9 @@ int getAideItemIndex(char *buf) { | ||
325 | 343 | * load AIDE database from file |
326 | 344 | * |
327 | 345 | * filename base64(digest) |
346 | + * Return | |
347 | + * num of meatdata | |
348 | + * -1 ERROR | |
328 | 349 | * |
329 | 350 | * caller |
330 | 351 | * ir.c |
@@ -347,8 +368,17 @@ int loadAideDatabaseFile(AIDE_CONTEXT *ctx, char *filename) { | ||
347 | 368 | int rc; |
348 | 369 | char *sha1_b64_ptr; |
349 | 370 | |
371 | + DEBUG_CAL("loadAideDatabaseFile - start, filename=[%s]\n", filename); | |
350 | 372 | |
351 | - DEBUG("loadAideDatabaseFile - start, filename=[%s]\n", filename); | |
373 | + /* check */ | |
374 | + if (ctx == NULL) { | |
375 | + LOG(LOG_ERR, "null input"); | |
376 | + return -1; | |
377 | + } | |
378 | + if (filename == NULL) { | |
379 | + LOG(LOG_ERR, "null input"); | |
380 | + return -1; | |
381 | + } | |
352 | 382 | |
353 | 383 | fp = gzopen(filename, "r"); |
354 | 384 | if (fp == NULL) { |
@@ -567,7 +597,7 @@ int loadAideDatabaseFile(AIDE_CONTEXT *ctx, char *filename) { | ||
567 | 597 | close: |
568 | 598 | gzclose(fp); |
569 | 599 | DEBUG("loadAideDatabaseFile - has %d entries\n", ctx->metadata_num); |
570 | - DEBUG("loadAideDatabaseFile - done\n"); | |
600 | + DEBUG_CAL("loadAideDatabaseFile - done\n"); | |
571 | 601 | |
572 | 602 | return ctx->metadata_num; |
573 | 603 | } |
@@ -592,16 +622,25 @@ int readAideIgnoreNameFile(AIDE_CONTEXT *ctx, char *filename) { | ||
592 | 622 | ENTRY e; // htable |
593 | 623 | ENTRY *ep; |
594 | 624 | |
595 | - DEBUG("readAideIgnoreNameFile - start, filename=[%s]\n", filename); | |
625 | + DEBUG_CAL("readAideIgnoreNameFile - start, filename=[%s]\n", filename); | |
626 | + | |
627 | + /* check */ | |
628 | + if (ctx == NULL) { | |
629 | + LOG(LOG_ERR, "null input"); | |
630 | + return PTS_FATAL; | |
631 | + } | |
632 | + if (filename == NULL) { | |
633 | + LOG(LOG_ERR, "null input"); | |
634 | + return PTS_FATAL; | |
635 | + } | |
596 | 636 | |
597 | 637 | /* Open file for read */ |
598 | 638 | fp = fopen(filename, "r"); |
599 | 639 | if (fp == NULL) { |
600 | 640 | DEBUG("%s missing\n", filename); |
601 | - return -1; | |
641 | + return PTS_FATAL; | |
602 | 642 | } |
603 | 643 | |
604 | - | |
605 | 644 | /* parse */ |
606 | 645 | while (fgets(line, BUF_SIZE, fp) != NULL) { // read line |
607 | 646 | /* ignore comment, null line */ |
@@ -658,7 +697,7 @@ int readAideIgnoreNameFile(AIDE_CONTEXT *ctx, char *filename) { | ||
658 | 697 | error: |
659 | 698 | fclose(fp); |
660 | 699 | |
661 | - DEBUG("readAideIgnoreNameFile - done, num = %d\n", cnt); | |
700 | + DEBUG_CAL("readAideIgnoreNameFile - done, num = %d\n", cnt); | |
662 | 701 | |
663 | 702 | return rc; |
664 | 703 | } |
@@ -671,9 +710,15 @@ int printAideData(AIDE_CONTEXT *ctx) { | ||
671 | 710 | AIDE_METADATA *md; |
672 | 711 | int i; |
673 | 712 | |
674 | - DEBUG("printAideData - start\n"); | |
713 | + DEBUG_CAL("printAideData - start\n"); | |
675 | 714 | DEBUG("printAideData - num = %d\n", ctx->metadata_num); |
676 | 715 | |
716 | + /* check*/ | |
717 | + if (ctx == NULL) { | |
718 | + LOG(LOG_ERR, "null input"); | |
719 | + return PTS_FATAL; | |
720 | + } | |
721 | + | |
677 | 722 | md = ctx->start; |
678 | 723 | |
679 | 724 | for (i = 0; i < ctx->metadata_num; i++) { |
@@ -695,9 +740,9 @@ int printAideData(AIDE_CONTEXT *ctx) { | ||
695 | 740 | md = md->next; |
696 | 741 | } |
697 | 742 | |
698 | - DEBUG("printAideData - end\n"); | |
743 | + DEBUG_CAL("printAideData - end\n"); | |
699 | 744 | |
700 | - return 0; | |
745 | + return PTS_SUCCESS; | |
701 | 746 | } |
702 | 747 | |
703 | 748 | #if 1 |
@@ -722,6 +767,7 @@ void copyAideMetadata(AIDE_METADATA *dst, AIDE_METADATA *src) { | ||
722 | 767 | } |
723 | 768 | } |
724 | 769 | |
770 | +#if 0 | |
725 | 771 | /** |
726 | 772 | * check AIDE MD vs given MD (SHA1) |
727 | 773 | * |
@@ -759,20 +805,24 @@ int checkFileByAide(AIDE_CONTEXT *ctx, AIDE_METADATA *metadata) { | ||
759 | 805 | DEBUG_FSM("checkFileByAide - MISS\n"); |
760 | 806 | return -2; |
761 | 807 | } |
762 | - | |
808 | +#endif | |
763 | 809 | |
764 | 810 | /** |
765 | 811 | * |
766 | 812 | * return |
767 | 813 | * -1: MISS |
768 | 814 | * 0: HIT |
769 | - * | |
815 | + * -2: ERROR | |
770 | 816 | */ |
771 | 817 | int checkIgnoreList(AIDE_CONTEXT *ctx, char *name) { |
772 | 818 | AIDE_LIST *list; |
773 | 819 | int len; |
774 | 820 | |
775 | 821 | /* check */ |
822 | + if (ctx == NULL) { | |
823 | + LOG(LOG_ERR, "null input"); | |
824 | + return -2; | |
825 | + } | |
776 | 826 | if (name == NULL) { |
777 | 827 | LOG(LOG_ERR, "checkIgnoreList() - name is null\n"); |
778 | 828 | return -2; |
@@ -993,11 +1043,13 @@ AIDE_METADATA *getMetadataFromAideByName(AIDE_CONTEXT *ctx, char *name) { | ||
993 | 1043 | AIDE_METADATA *md; |
994 | 1044 | int i; |
995 | 1045 | |
1046 | + /* check */ | |
996 | 1047 | if (ctx == NULL) { |
1048 | + LOG(LOG_ERR, "null input"); | |
997 | 1049 | return NULL; |
998 | 1050 | } |
999 | - | |
1000 | 1051 | if (name == NULL) { |
1052 | + LOG(LOG_ERR, "null input"); | |
1001 | 1053 | return NULL; |
1002 | 1054 | } |
1003 | 1055 |
@@ -1043,11 +1095,17 @@ int escapeFilename(char **out, char *in) { | ||
1043 | 1095 | int len; |
1044 | 1096 | int i, j; |
1045 | 1097 | |
1098 | + /* check */ | |
1099 | + if (in == NULL) { | |
1100 | + LOG(LOG_ERR, "null input"); | |
1101 | + return -1; | |
1102 | + } | |
1046 | 1103 | len = strlen(in); |
1047 | 1104 | |
1048 | 1105 | /* rough malloc new buffer */ |
1049 | 1106 | buf = xmalloc(len*3); |
1050 | 1107 | if (buf == NULL) { |
1108 | + LOG(LOG_ERR, "no memory"); | |
1051 | 1109 | return -1; |
1052 | 1110 | } |
1053 | 1111 |
@@ -1130,7 +1188,17 @@ int convertImlToAideDbFile(OPENPTS_CONTEXT *ctx, char *filename) { | ||
1130 | 1188 | char *aide_filename = NULL; |
1131 | 1189 | int len; |
1132 | 1190 | |
1133 | - DEBUG("convertImlToAideDbFile %s\n", filename); | |
1191 | + DEBUG_CAL("convertImlToAideDbFile %s\n", filename); | |
1192 | + | |
1193 | + /* check */ | |
1194 | + if (ctx == NULL) { | |
1195 | + LOG(LOG_ERR, "null input"); | |
1196 | + return -1; | |
1197 | + } | |
1198 | + if (filename == NULL) { | |
1199 | + LOG(LOG_ERR, "null input"); | |
1200 | + return -1; | |
1201 | + } | |
1134 | 1202 | |
1135 | 1203 | /* file open for write */ |
1136 | 1204 | fp = gzopen(filename, "wb"); |
@@ -1257,7 +1325,13 @@ int writeReducedAidbDatabase(AIDE_CONTEXT *ctx, char *filename) { | ||
1257 | 1325 | |
1258 | 1326 | DEBUG("writeReducedAidbDatabase %s\n", filename); |
1259 | 1327 | |
1328 | + /* check */ | |
1260 | 1329 | if (ctx == NULL) { |
1330 | + LOG(LOG_ERR, "null input"); | |
1331 | + return -1; | |
1332 | + } | |
1333 | + if (filename == NULL) { | |
1334 | + LOG(LOG_ERR, "null input"); | |
1261 | 1335 | return -1; |
1262 | 1336 | } |
1263 | 1337 |
@@ -1455,21 +1529,16 @@ int verifyBySQLite(AIDE_CONTEXT *ctx, char * key) { | ||
1455 | 1529 | |
1456 | 1530 | sql = sqlite3_mprintf("SELECT * from sample where digest = '%s'", key); |
1457 | 1531 | sqlite3_get_table(ctx->sqlite_db, sql, &result, &row, &col, &err); |
1458 | - // DEBUG("%2d %d %s\n",row,col, md->hash_key); | |
1459 | 1532 | |
1460 | 1533 | if (row >= 1) { |
1461 | 1534 | return OPENPTS_RESULT_VALID; |
1462 | 1535 | } |
1463 | 1536 | |
1464 | - // LOG(LOG_ERR, "row = %d\n",row); | |
1465 | - | |
1466 | 1537 | /* free */ |
1467 | 1538 | sqlite3_free(sql); |
1468 | 1539 | sqlite3_free(err); |
1469 | 1540 | sqlite3_free_table(result); |
1470 | 1541 | |
1471 | - | |
1472 | - | |
1473 | 1542 | return OPENPTS_RESULT_UNKNOWN; |
1474 | 1543 | } |
1475 | 1544 | #endif // CONFIG_SQLITE |
@@ -26,7 +26,7 @@ | ||
26 | 26 | * \brief FSM action for Auto RM Update (ARU) |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2011-01-11 |
29 | - * cleanup 2011-01-22 SM | |
29 | + * cleanup 2012-01-05 SM | |
30 | 30 | * |
31 | 31 | * 2011-02-28 SM |
32 | 32 | * ARU information is stored in conf instead of ctx since this is part of |
@@ -190,7 +190,7 @@ int startUpdate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) { | ||
190 | 190 | int update_type; |
191 | 191 | int data_length; |
192 | 192 | |
193 | - DEBUG("startUpdate() - start\n"); | |
193 | + DEBUG_CAL("startUpdate() - start\n"); | |
194 | 194 | |
195 | 195 | /* check input */ |
196 | 196 | if (ctx == NULL) { |
@@ -237,9 +237,6 @@ int startUpdate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) { | ||
237 | 237 | update = (OPENPTS_UPDATE_CONTEXT *) conf->update; |
238 | 238 | start = (OPENPTS_EVENT_UPDATE_START *) event->rgbEvent; |
239 | 239 | |
240 | - // DEBUG("StartUpdate\n"); | |
241 | - // printHex("UpdateEvent ", (BYTE*) start, sizeof(OPENPTS_EVENT_UPDATE_START), "\n"); | |
242 | - | |
243 | 240 | // Convert the Endian |
244 | 241 | if (ctx->conf->iml_endian != 0) { |
245 | 242 | target_pcr_index = b2l(start->target_pcr_index); |
@@ -276,20 +273,17 @@ int startUpdate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) { | ||
276 | 273 | update->target_pcr_index = target_pcr_index; |
277 | 274 | update->target_snapshot_level = target_snapshot_level; |
278 | 275 | |
279 | - | |
280 | 276 | /* setup OPENPTS_UPDATE_SNAPSHOT */ |
281 | 277 | if (update->snapshot |
282 | 278 | [target_pcr_index] |
283 | 279 | [target_snapshot_level] == NULL) { |
284 | 280 | /* 1st update of this PCR/Level */ |
285 | - // OPENPTS_UPDATE_SNAPSHOT | |
286 | 281 | /* malloc OPENPTS_UPDATE_SNAPSHOT */ |
287 | - // uss = xmalloc(sizeof(OPENPTS_UPDATE_SNAPSHOT)); | |
288 | 282 | uss = newUpdateSnapshot(); |
289 | 283 | if (uss == NULL) { |
290 | - return PTS_INTERNAL_ERROR; | |
284 | + LOG(LOG_ERR, "newUpdateSnapshot() fail"); | |
285 | + return PTS_FATAL; | |
291 | 286 | } |
292 | - // memset(uss, 0, sizeof(OPENPTS_UPDATE_SNAPSHOT)); | |
293 | 287 | } else { |
294 | 288 | /* already exist => replace */ |
295 | 289 | /* free Old SS */ |
@@ -310,7 +304,7 @@ int startUpdate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) { | ||
310 | 304 | [target_snapshot_level] = uss; |
311 | 305 | |
312 | 306 | conf->update_exist = 1; |
313 | - DEBUG("startUpdate() - update exit\n"); | |
307 | + DEBUG_CAL("startUpdate() - update exit\n"); | |
314 | 308 | |
315 | 309 | return PTS_SUCCESS; |
316 | 310 | } |
@@ -319,9 +313,9 @@ int startUpdate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) { | ||
319 | 313 | * doAction - deputyEvent |
320 | 314 | */ |
321 | 315 | int deputyEvent(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) { |
316 | + int rc = PTS_SUCCESS; | |
322 | 317 | TSS_PCR_EVENT *event; |
323 | 318 | OPENPTS_UPDATE_CONTEXT *update; |
324 | - int rc = PTS_SUCCESS; | |
325 | 319 | OPENPTS_CONFIG *conf; |
326 | 320 | OPENPTS_UPDATE_SNAPSHOT *uss; |
327 | 321 |
@@ -394,7 +388,7 @@ int endUpdate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) { | ||
394 | 388 | OPENPTS_EVENT_UPDATE_START *start; |
395 | 389 | int event_num; |
396 | 390 | |
397 | - DEBUG("endUpdate() - start\n"); | |
391 | + DEBUG_CAL("endUpdate() - start\n"); | |
398 | 392 | |
399 | 393 | /* check input */ |
400 | 394 | if (ctx == NULL) { |
@@ -474,7 +468,6 @@ int endUpdate(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) { | ||
474 | 468 | * doAction - updateCollector |
475 | 469 | */ |
476 | 470 | int updateCollector(OPENPTS_CONTEXT *ctx, OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) { |
477 | - // int rc = PTS_SUCCESS; | |
478 | 471 | TSS_PCR_EVENT *event; |
479 | 472 | OPENPTS_EVENT_COLLECTOR_UPDATE *update = NULL; |
480 | 473 | OPENPTS_CONFIG *conf; |
@@ -696,7 +689,6 @@ int updateSnapshot(OPENPTS_CONTEXT *ctx, OPENPTS_UPDATE_SNAPSHOT *uss, int i, in | ||
696 | 689 | |
697 | 690 | /* Move to next level (0->1) */ |
698 | 691 | incActiveSnapshotLevel(ctx->ss_table, target_pcr_index); |
699 | - // goto end; | |
700 | 692 | break; |
701 | 693 | } else if (rc == OPENPTS_FSM_FINISH_WO_HIT) { |
702 | 694 | // TRANSIT, Skip update SS chain |
@@ -705,7 +697,6 @@ int updateSnapshot(OPENPTS_CONTEXT *ctx, OPENPTS_UPDATE_SNAPSHOT *uss, int i, in | ||
705 | 697 | |
706 | 698 | /* Move to next level (0->1) */ |
707 | 699 | incActiveSnapshotLevel(ctx->ss_table, target_pcr_index); |
708 | - // goto end; | |
709 | 700 | break; |
710 | 701 | } else { |
711 | 702 | LOG(LOG_ERR, "updateFsm rc=%d\n", rc); |
@@ -723,12 +714,10 @@ int updateSnapshot(OPENPTS_CONTEXT *ctx, OPENPTS_UPDATE_SNAPSHOT *uss, int i, in | ||
723 | 714 | } |
724 | 715 | |
725 | 716 | ss->event_num++; |
726 | - // update->event_count++; | |
727 | 717 | rc = OPENPTS_FSM_MIGRATE_EVENT; |
728 | 718 | |
729 | 719 | eventWrapper = eventWrapper->next_pcr; |
730 | 720 | count++; |
731 | - // TODO count | |
732 | 721 | } |
733 | 722 | // TODO check count |
734 | 723 | // TODO cut EW <-> event link |
@@ -775,7 +764,16 @@ int extendEvCollectorUpdate(OPENPTS_CONFIG *conf) { | ||
775 | 764 | |
776 | 765 | /* malloc eventlog */ |
777 | 766 | collector_update = xmalloc_assert(sizeof(OPENPTS_EVENT_COLLECTOR_UPDATE)); |
767 | + if (collector_update == NULL) { | |
768 | + LOG(LOG_ERR, "no memory\n"); | |
769 | + return PTS_FATAL; | |
770 | + } | |
778 | 771 | event = xmalloc_assert(sizeof(TSS_PCR_EVENT)); |
772 | + if (event == NULL) { | |
773 | + LOG(LOG_ERR, "no memory\n"); | |
774 | + xfree(collector_update); | |
775 | + return PTS_FATAL; | |
776 | + } | |
779 | 777 | |
780 | 778 | /* fill collector_start */ |
781 | 779 | memcpy(&collector_update->pts_version, &conf->pts_version, 4); |
@@ -1182,7 +1180,7 @@ static int diffFileAgainstCache(char *fileName, int len, BYTE *contents) { | ||
1182 | 1180 | if ( -1 == bytesRead ) { |
1183 | 1181 | LOG(LOG_ERR, "Failed to read from fd %d, errno %d\n", fd, errno); |
1184 | 1182 | break; |
1185 | - } else if ( bytesRead == 0) { | |
1183 | + } else if (bytesRead == 0) { | |
1186 | 1184 | if (totalBytesRead != len) { |
1187 | 1185 | LOG(LOG_ERR, "Finished reading from file prematurely, still expecting data."); |
1188 | 1186 | return PTS_FATAL; |
@@ -1206,7 +1204,7 @@ static int diffFileAgainstCache(char *fileName, int len, BYTE *contents) { | ||
1206 | 1204 | } |
1207 | 1205 | } |
1208 | 1206 | |
1209 | - if ( fd != -1) { | |
1207 | + if (fd != -1) { | |
1210 | 1208 | close(fd); |
1211 | 1209 | } |
1212 | 1210 |
@@ -1582,7 +1580,6 @@ int updateNewRm(OPENPTS_CONTEXT *ctx, char *host, char *conf_dir) { | ||
1582 | 1580 | if (target_conf_filename != NULL) xfree(target_conf_filename); |
1583 | 1581 | if (target_conf != NULL) freePtsConfig(target_conf); |
1584 | 1582 | |
1585 | - // DEBUG("error at verifier\n"); | |
1586 | 1583 | return rc; |
1587 | 1584 | } |
1588 | 1585 |
@@ -26,7 +26,7 @@ | ||
26 | 26 | * \brief Base64 Encode/Decode |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2010-04-01 |
29 | - * cleanup 2011-12-31 SM | |
29 | + * cleanup 2012-01-05 SM | |
30 | 30 | * |
31 | 31 | * http://en.wikipedia.org/wiki/Base64 |
32 | 32 | * |
@@ -101,7 +101,6 @@ int _sizeofBase64Decode(int len) { | ||
101 | 101 | return (len / 4 * 3) + 1; |
102 | 102 | } |
103 | 103 | |
104 | - | |
105 | 104 | /** |
106 | 105 | * Encode BYTE[] to Base64 string |
107 | 106 | * Return |
@@ -141,7 +140,6 @@ int _encodeBase64(char *out, unsigned char * in, int len) { | ||
141 | 140 | } |
142 | 141 | |
143 | 142 | /* Trans */ |
144 | - | |
145 | 143 | while (1) { |
146 | 144 | if ( len >= 3 ) { |
147 | 145 | out[ptr2 ] = transTable[ in[ptr1 ] >>2]; |
@@ -216,7 +214,6 @@ char *encodeBase64(unsigned char * in, int inlen, int *outlen) { | ||
216 | 214 | return out; |
217 | 215 | } |
218 | 216 | |
219 | - | |
220 | 217 | /** |
221 | 218 | * trans (do not check the bad input) |
222 | 219 | */ |
@@ -247,7 +244,7 @@ int _strippedlength(char * in, int len) { | ||
247 | 244 | /* last char */ |
248 | 245 | i = len - 1; |
249 | 246 | |
250 | - while(i > 0) { | |
247 | + while (i > 0) { | |
251 | 248 | if (in[i] == '\n') { |
252 | 249 | /* skip */ |
253 | 250 | skip++; |
@@ -340,7 +337,7 @@ int _decodeBase64(unsigned char *out, char * in, int len) { | ||
340 | 337 | (_b64trans(inbuf[2]) >> 2); |
341 | 338 | out[ptr2+2] = ((_b64trans(inbuf[2])&0x03) << 6) | |
342 | 339 | _b64trans(inbuf[3]); |
343 | - len2 -= 4; // skip chars has been removed in len2 | |
340 | + len2 -= 4; // skip chars has been removed in len2 | |
344 | 341 | ptr1 += 4 + skip; |
345 | 342 | ptr2 += 3; |
346 | 343 | } else if ( inbuf[1] == '=' ) { |
@@ -26,13 +26,12 @@ | ||
26 | 26 | * \brief TCG IF-M collector functions |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2011-01-06 |
29 | - * cleanup 2011-07-20 SM | |
29 | + * cleanup 2012-01-05 SM | |
30 | 30 | * |
31 | 31 | * move from ptscd.c |
32 | 32 | * |
33 | 33 | */ |
34 | 34 | |
35 | - | |
36 | 35 | #include <stdio.h> |
37 | 36 | #include <stdlib.h> |
38 | 37 | #include <string.h> |
@@ -62,6 +61,12 @@ void printFsmInfo(OPENPTS_CONTEXT *ctx, char * indent) { | ||
62 | 61 | int i; |
63 | 62 | OPENPTS_SNAPSHOT *ss; |
64 | 63 | |
64 | + /* check */ | |
65 | + if (ctx == NULL) { | |
66 | + LOG(LOG_ERR, "null input"); | |
67 | + return; | |
68 | + } | |
69 | + | |
65 | 70 | OUTPUT(NLS(MS_OPENPTS, OPENPTS_FSM_INFO_HEADER, "%sPCR lv FSM files\n"), indent); |
66 | 71 | OUTPUT("%s-----------------------------------------------------\n", indent); |
67 | 72 |
@@ -100,23 +105,34 @@ int extendEvCollectorStart(OPENPTS_CONFIG *conf) { | ||
100 | 105 | BYTE pcr[SHA1_DIGEST_SIZE]; |
101 | 106 | SHA_CTX sha_ctx; |
102 | 107 | |
108 | + /* check */ | |
109 | + if (conf == NULL) { | |
110 | + LOG(LOG_ERR, "null input"); | |
111 | + return PTS_FATAL; | |
112 | + } | |
103 | 113 | |
104 | 114 | /* malloc eventlog */ |
105 | 115 | collector_start = xmalloc_assert(sizeof(OPENPTS_EVENT_COLLECTOR_START)); |
116 | + if (collector_start == NULL) { | |
117 | + LOG(LOG_ERR, "no memory"); | |
118 | + return PTS_FATAL; | |
119 | + } | |
106 | 120 | event = xmalloc_assert(sizeof(TSS_PCR_EVENT)); |
121 | + if (event == NULL) { | |
122 | + LOG(LOG_ERR, "no memory"); | |
123 | + xfree(collector_start); | |
124 | + return PTS_FATAL; | |
125 | + } | |
107 | 126 | |
108 | 127 | /*fill collector_start */ |
109 | 128 | memcpy(&collector_start->pts_version, &conf->pts_version, 4); |
110 | 129 | memcpy(&collector_start->collector_uuid, conf->uuid->uuid, 16); |
111 | 130 | memcpy(&collector_start->manifest_uuid, conf->rm_uuid->uuid, 16); |
112 | 131 | |
113 | - | |
114 | 132 | /* get PCR value*/ |
115 | - // memcpy(&collector_start->pcr_value; | |
116 | 133 | readPcr(conf->openpts_pcr_index, pcr); |
117 | 134 | memcpy(&collector_start->pcr_value, pcr, SHA1_DIGEST_SIZE); |
118 | 135 | |
119 | - | |
120 | 136 | /* calc digest */ |
121 | 137 | SHA1_Init(&sha_ctx); |
122 | 138 | SHA1_Update( |
@@ -126,7 +142,6 @@ int extendEvCollectorStart(OPENPTS_CONFIG *conf) { | ||
126 | 142 | SHA1_Final(pcr, &sha_ctx); |
127 | 143 | |
128 | 144 | /* fill eventlog */ |
129 | - // event->versionInfo // set by TSP? | |
130 | 145 | event->ulPcrIndex = conf->openpts_pcr_index; // set by TSP? |
131 | 146 | event->eventType = EV_COLLECTOR_START; // openpts_tpm.h |
132 | 147 | event->ulPcrValueLength = SHA1_DIGEST_SIZE; |
@@ -144,8 +159,6 @@ int extendEvCollectorStart(OPENPTS_CONFIG *conf) { | ||
144 | 159 | return PTS_SUCCESS; |
145 | 160 | } |
146 | 161 | |
147 | - | |
148 | - | |
149 | 162 | /** |
150 | 163 | * initialize ptsc |
151 | 164 | * |
@@ -159,9 +172,9 @@ int extendEvCollectorStart(OPENPTS_CONFIG *conf) { | ||
159 | 172 | * |
160 | 173 | * Return |
161 | 174 | * PTS_SUCCESS |
162 | - * PTS_INTERNAL_ERROR | |
175 | + * OPENPTS_IML_MISSING | |
176 | + * PTS_FATAL | |
163 | 177 | */ |
164 | - | |
165 | 178 | int init( |
166 | 179 | OPENPTS_CONFIG *conf, |
167 | 180 | int prop_count, |
@@ -310,7 +323,7 @@ int init( | ||
310 | 323 | addReason(ctx, -1, |
311 | 324 | "[PTSC-INIT] Couldn't read IML file, %s. Check the ptsc configuration, %s.", |
312 | 325 | conf->runtime_iml_filename, conf->config_file); |
313 | - rc = PTS_INTERNAL_ERROR; | |
326 | + rc = PTS_FATAL; | |
314 | 327 | goto error; |
315 | 328 | } |
316 | 329 | } |
@@ -328,7 +341,7 @@ int init( | ||
328 | 341 | NLS(MS_OPENPTS, OPENPTS_COLLECTOR_MISSING_CONFIG_DIR, |
329 | 342 | "[PTSC-INIT] Configuration directory is not defined. Check the ptsc configuration file, %s"), |
330 | 343 | conf->config_file); |
331 | - rc = PTS_INTERNAL_ERROR; | |
344 | + rc = PTS_FATAL; | |
332 | 345 | goto error; |
333 | 346 | } else { |
334 | 347 | /* check */ |
@@ -371,20 +384,21 @@ int init( | ||
371 | 384 | |
372 | 385 | /* Generate UUID of this platform */ |
373 | 386 | if (conf->uuid == NULL) { |
374 | - // TODO UUID filename is missing | |
387 | + LOG(LOG_ERR, "conf->uuid == NULL"); | |
375 | 388 | addReason(ctx, -1, |
376 | 389 | NLS(MS_OPENPTS, OPENPTS_COLLECTOR_BAD_CONFIG_FILE, |
377 | - "[PTSC-INIT] Bad configuration file, %s"), | |
390 | + "[PTSC-INIT] Bad configuration file, %s. Check 'uuid.file' option"), | |
378 | 391 | conf->config_file); |
379 | - rc = PTS_INTERNAL_ERROR; | |
392 | + rc = PTS_FATAL; | |
380 | 393 | goto error; |
381 | 394 | } else if (conf->uuid->status == OPENPTS_UUID_FILENAME_ONLY) { |
382 | 395 | /* gen new UUID */ |
383 | 396 | rc = genOpenptsUuid(conf->uuid); |
384 | 397 | if (rc != PTS_SUCCESS) { |
398 | + LOG(LOG_ERR, "genOpenptsUuid() fail"); | |
385 | 399 | addReason(ctx, -1, |
386 | 400 | "[PTSC-INIT] Generation of UUID was failed"); |
387 | - rc = PTS_INTERNAL_ERROR; | |
401 | + rc = PTS_FATAL; | |
388 | 402 | goto error; |
389 | 403 | } |
390 | 404 | } else { |
@@ -406,18 +420,19 @@ int init( | ||
406 | 420 | 0, |
407 | 421 | conf->srk_password_mode); |
408 | 422 | if (rc == 0x0001) { // 0x0001 |
423 | + DEBUG("createTssSignKey() failed"); | |
409 | 424 | addReason(ctx, -1, |
410 | 425 | NLS(MS_OPENPTS, OPENPTS_COLLECTOR_SIGN_KEY_FAIL, |
411 | 426 | "[PTSC-INIT] Failed to create the signed key. " |
412 | 427 | "If you are using the well known SRK secret key (all zeroes) " |
413 | 428 | "then please try again with the '-z' option\n")); |
414 | - rc = PTS_INTERNAL_ERROR; | |
429 | + rc = PTS_FATAL; | |
415 | 430 | goto error; |
416 | 431 | } else if (rc != PTS_SUCCESS) { |
417 | - DEBUG("createTssSignKey() failed\n"); | |
432 | + DEBUG("createTssSignKey() failed"); | |
418 | 433 | addReason(ctx, -1, |
419 | 434 | "[PTSC-INIT] Could not create the Key (rc = 0x%x).", rc); |
420 | - rc = PTS_INTERNAL_ERROR; | |
435 | + rc = PTS_FATAL; | |
421 | 436 | goto error; |
422 | 437 | } |
423 | 438 | OUTPUT(NLS(MS_OPENPTS, OPENPTS_INIT_PTSCD, "Sign key location: SYSTEM\n")); |
@@ -431,18 +446,18 @@ int init( | ||
431 | 446 | /* UUID for RM */ |
432 | 447 | if (conf->rm_uuid == NULL) { |
433 | 448 | // init/set by readPtsConf |
434 | - // LOG(LOG_ERR, "conf->rm_uuid == NULL\n"); | |
449 | + LOG(LOG_ERR, "conf->rm_uuid == NULL\n"); | |
435 | 450 | addReason(ctx, -1, |
436 | 451 | "[PTSC-INIT] RM_UUID file is not defined (rm.uuid.file) in the ptsc configulation, %s", |
437 | 452 | conf->config_file); |
438 | - rc = PTS_INTERNAL_ERROR; | |
453 | + rc = PTS_FATAL; | |
439 | 454 | goto error; |
440 | 455 | } else if (conf->rm_uuid->status == OPENPTS_UUID_FILENAME_ONLY) { |
441 | 456 | rc = genOpenptsUuid(conf->rm_uuid); |
442 | 457 | if (rc != PTS_SUCCESS) { |
443 | 458 | addReason(ctx, -1, |
444 | 459 | "[PTSC-INIT] Generation of RM UUID was failed"); |
445 | - rc = PTS_INTERNAL_ERROR; | |
460 | + rc = PTS_FATAL; | |
446 | 461 | goto error; |
447 | 462 | } |
448 | 463 |
@@ -455,7 +470,7 @@ int init( | ||
455 | 470 | if (rc != PTS_SUCCESS) { |
456 | 471 | addReason(ctx, -1, |
457 | 472 | "[PTSC-INIT] Couldn't create Reference Maniferst directory"); |
458 | - rc = PTS_INTERNAL_ERROR; | |
473 | + rc = PTS_FATAL; | |
459 | 474 | goto error; |
460 | 475 | } |
461 | 476 |
@@ -477,7 +492,6 @@ int init( | ||
477 | 492 | addReason(ctx, -1, |
478 | 493 | "[PTSC-INIT] Couldn't create the manifest file, %s", |
479 | 494 | conf->rm_filename[i]); |
480 | - //printReason(ctx, 0); | |
481 | 495 | rc = PTS_FATAL; |
482 | 496 | goto error; |
483 | 497 | } |
@@ -501,7 +515,7 @@ int init( | ||
501 | 515 | addReason(ctx, -1, |
502 | 516 | "[PTSC-INIT] Couldn't write the uuid file, '%s'.\n", |
503 | 517 | conf->uuid->filename); |
504 | - rc = PTS_INTERNAL_ERROR; | |
518 | + rc = PTS_FATAL; | |
505 | 519 | goto error; |
506 | 520 | } |
507 | 521 |
@@ -511,21 +525,21 @@ int init( | ||
511 | 525 | addReason(ctx, -1, |
512 | 526 | "[PTSC-INIT] Couldn't write the UUID file, %s", |
513 | 527 | conf->rm_uuid->filename); |
514 | - rc = PTS_INTERNAL_ERROR; | |
528 | + rc = PTS_FATAL; | |
515 | 529 | goto error; |
516 | 530 | } |
517 | 531 | |
532 | + LOG(LOG_INFO, "ptsc has successfully initialized!\n"); | |
518 | 533 | OUTPUT(NLS(MS_OPENPTS, OPENPTS_INIT_SUCCESS, |
519 | 534 | "\nptsc has successfully initialized!\n\n")); |
520 | - LOG(LOG_INFO, "ptsc has successfully initialized!\n"); | |
521 | 535 | goto free; |
522 | 536 | |
523 | 537 | error: |
524 | 538 | /* initialization was faild */ |
525 | - OUTPUT(NLS(MS_OPENPTS, OPENPTS_INIT_FAIL, | |
539 | + LOG(LOG_INFO, "ptsc initialization was failed\n"); | |
540 | + ERROR(NLS(MS_OPENPTS, OPENPTS_INIT_FAIL, | |
526 | 541 | "ptsc initialization was failed\n\n")); |
527 | 542 | printReason(ctx, 0); |
528 | - LOG(LOG_INFO, "ptsc initialization was failed\n"); | |
529 | 543 | |
530 | 544 | free: |
531 | 545 | /* free */ |
@@ -534,8 +548,6 @@ int init( | ||
534 | 548 | return rc; |
535 | 549 | } |
536 | 550 | |
537 | - | |
538 | - | |
539 | 551 | /** |
540 | 552 | * |
541 | 553 | * Selftest |
@@ -557,7 +569,7 @@ int init( | ||
557 | 569 | * OPENPTS_SELFTEST_RENEWED update/reboot -> success |
558 | 570 | * OPENPTS_SELFTEST_FALLBACK |
559 | 571 | * OPENPTS_SELFTEST_FAILED |
560 | - * PTS_INTERNAL_ERROR something wrong:-( | |
572 | + * PTS_FATAL something wrong:-( | |
561 | 573 | */ |
562 | 574 | int selftest(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OPENPTS_PROPERTY *prop_end) { |
563 | 575 | int rc = PTS_INTERNAL_ERROR; |
@@ -567,22 +579,24 @@ int selftest(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, | ||
567 | 579 | OPENPTS_PROPERTY *prop; |
568 | 580 | char * ir_filename; |
569 | 581 | |
570 | - DEBUG("selftest() start\n"); | |
582 | + DEBUG_CAL("selftest() start\n"); | |
571 | 583 | |
572 | - /* Step 1 - IR gen */ | |
584 | + /* Step 1 - Generate IR --------------------------------------------------*/ | |
573 | 585 | |
574 | - /* new */ | |
586 | + /* new CTX for generation */ | |
575 | 587 | ctx = newPtsContext(conf); |
576 | 588 | if (ctx == NULL) { |
577 | - return PTS_INTERNAL_ERROR; | |
589 | + LOG(LOG_ERR, "newPtsContext() fail. no memory?"); | |
590 | + return PTS_FATAL; | |
578 | 591 | } |
579 | 592 | |
580 | 593 | /* copy properties */ |
581 | 594 | prop = prop_start; |
582 | 595 | for (i = 0; i < prop_count; i++) { |
583 | 596 | if (prop == NULL) { |
584 | - LOG(LOG_ERR, "prop == NULL\n"); | |
585 | - return PTS_INTERNAL_ERROR; // TODO free | |
597 | + LOG(LOG_ERR, "prop == NULL"); | |
598 | + rc = PTS_FATAL; | |
599 | + goto free; | |
586 | 600 | } |
587 | 601 | addProperty(ctx, prop->name, prop->value); |
588 | 602 | prop = prop->next; |
@@ -594,15 +608,25 @@ int selftest(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, | ||
594 | 608 | /* set dummy nonce for IR gen */ |
595 | 609 | ctx->nonce->nonce_length = 20; |
596 | 610 | ctx->nonce->nonce = xmalloc_assert(20); |
611 | + if (ctx->nonce->nonce == NULL) { | |
612 | + LOG(LOG_ERR, "no memory"); | |
613 | + rc = PTS_FATAL; | |
614 | + goto free; | |
615 | + } | |
597 | 616 | memset(ctx->nonce->nonce, 0x5A, 20); |
598 | - // dummy target uuid | |
617 | + /* set dummy target uuid */ | |
599 | 618 | ctx->str_uuid = smalloc("SELFTEST"); |
619 | + if (ctx->str_uuid == NULL) { | |
620 | + LOG(LOG_ERR, "no memory"); | |
621 | + rc = PTS_FATAL; | |
622 | + goto free; | |
623 | + } | |
600 | 624 | |
601 | 625 | /* gen IR */ |
602 | 626 | rc = genIr(ctx, NULL); |
603 | 627 | if (rc != PTS_SUCCESS) { |
604 | 628 | LOG(LOG_ERR, "selftest() - genIR failed\n"); |
605 | - rc = PTS_INTERNAL_ERROR; | |
629 | + rc = PTS_FATAL; | |
606 | 630 | goto free; |
607 | 631 | } |
608 | 632 |
@@ -610,25 +634,27 @@ int selftest(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, | ||
610 | 634 | ir_filename = ctx->ir_filename; |
611 | 635 | ctx->ir_filename = NULL; |
612 | 636 | |
613 | - /* free */ | |
637 | + /* free CTX */ | |
614 | 638 | freePtsContext(ctx); |
639 | + ctx = NULL; | |
615 | 640 | |
616 | - // DEBUG("selftest() - generate IR file => %s\n", conf->ir_filename); | |
617 | - DEBUG("selftest() - generate IR - done\n"); | |
641 | + DEBUG("selftest() - generate IR - done (ir file = %s)\n", ir_filename); | |
618 | 642 | |
619 | - /* Step 2 - Validate IR */ | |
643 | + /* Step 2 - Validate IR --------------------------------------------------*/ | |
620 | 644 | |
621 | 645 | /* Keep conf but reset some flags in conf */ |
622 | - // conf->aru_count = 0; | |
623 | - // conf->enable_aru; | |
624 | 646 | #ifdef CONFIG_AUTO_RM_UPDATE |
647 | + /* clear ARU */ | |
625 | 648 | conf->update_exist = 0; |
626 | 649 | #endif |
627 | - /* new */ | |
650 | + /* new CTX for validation */ | |
628 | 651 | ctx = newPtsContext(conf); |
629 | 652 | if (ctx == NULL) { |
630 | - return PTS_INTERNAL_ERROR; | |
653 | + LOG(LOG_ERR, "newPtsContext() fail. no memory?"); | |
654 | + return PTS_FATAL; | |
631 | 655 | } |
656 | + | |
657 | + /* set generated IR */ | |
632 | 658 | ctx->ir_filename = ir_filename; |
633 | 659 | |
634 | 660 | /* setup RMs */ |
@@ -637,7 +663,7 @@ int selftest(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, | ||
637 | 663 | LOG(LOG_ERR, "selftest() - getRmSetDir() failed\n"); |
638 | 664 | LOG(LOG_TODO, "conf->rm_uuid->filename %s\n", conf->rm_uuid->filename); |
639 | 665 | LOG(LOG_TODO, "conf->rm_uuid->str %s\n", conf->rm_uuid->str); |
640 | - rc = PTS_INTERNAL_ERROR; | |
666 | + rc = PTS_FATAL; | |
641 | 667 | goto free; |
642 | 668 | } |
643 | 669 |
@@ -646,7 +672,7 @@ int selftest(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, | ||
646 | 672 | rc = readRmFile(ctx, conf->rm_filename[i], i); |
647 | 673 | if (rc < 0) { |
648 | 674 | LOG(LOG_ERR, "readRmFile fail\n"); |
649 | - rc = PTS_INTERNAL_ERROR; | |
675 | + rc = PTS_FATAL; | |
650 | 676 | goto free; |
651 | 677 | } |
652 | 678 | } |
@@ -665,21 +691,19 @@ int selftest(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, | ||
665 | 691 | // ctx->conf->iml_mode = 1; |
666 | 692 | // ctx->conf->ir_without_quote = 1; |
667 | 693 | |
668 | - | |
669 | - | |
670 | - //result = validateIr(ctx, conf->ir_filename); /* ir.c */ | |
671 | - // TODO | |
672 | 694 | result = validateIr(ctx); /* ir.c */ |
673 | 695 | |
674 | - | |
675 | 696 | /* check RM integrity status */ |
676 | 697 | DEBUG("selftest() - validate IR - done (rc = %d)\n", result); |
677 | - if ((rc != OPENPTS_RESULT_VALID) && isDebugFlagSet(DEBUG_FLAG)) { | |
698 | + if ((result != OPENPTS_RESULT_VALID) && (getVerbosity() > 0)) { | |
699 | + ERROR(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_SELFTEST_FAILED_4, | |
700 | + "The self test has failed")); | |
678 | 701 | printReason(ctx, 0); |
679 | 702 | } |
680 | 703 | |
681 | 704 | if (result != OPENPTS_RESULT_VALID) { |
682 | - addReason(ctx, -1, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_SELFTEST_FAILED, "[SELFTEST] The self test failed")); | |
705 | + addReason(ctx, -1, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_SELFTEST_FAILED, | |
706 | + "[SELFTEST] The self test failed")); | |
683 | 707 | if ((conf->newrm_uuid != NULL) && (conf->newrm_uuid->uuid != NULL)) { |
684 | 708 | /* New RM exist (for reboot after the update), Try the new RM */ |
685 | 709 |
@@ -705,22 +729,27 @@ int selftest(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, | ||
705 | 729 | rc = writeOpenptsUuidFile(conf->rm_uuid, 1); |
706 | 730 | if (rc != PTS_SUCCESS) { |
707 | 731 | LOG(LOG_ERR, "writeOpenptsUuidFile fail\n"); |
732 | + rc = PTS_FATAL; | |
733 | + goto free; | |
708 | 734 | } |
709 | - | |
710 | - // TODO check rc | |
711 | 735 | /* delete newrm_uuid */ |
712 | 736 | rc = remove(conf->newrm_uuid->filename); |
713 | - // TODO check rc | |
737 | + if (rc != 0) { | |
738 | + LOG(LOG_ERR, "remove(%s) fail\n", conf->newrm_uuid->filename); | |
739 | + rc = PTS_FATAL; | |
740 | + goto free; | |
741 | + } | |
714 | 742 | rc = OPENPTS_SELFTEST_RENEWED; |
715 | 743 | } else { |
716 | 744 | /* fail */ |
717 | - LOG(LOG_ERR, "sleftest fail\n"); | |
745 | + LOG(LOG_ERR, "2nd selftest with NEWRM also fail\n"); | |
718 | 746 | addReason(ctx, -1, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_SELFTEST_FAILED_2, |
719 | 747 | "[SELFTEST] The self test using both current and new UUIDs has failed")); |
720 | 748 | printReason(ctx, 0); |
721 | 749 | rc = OPENPTS_SELFTEST_FAILED; |
722 | 750 | } |
723 | 751 | } else { |
752 | + /* Missing NEWRM */ | |
724 | 753 | printReason(ctx, 0); |
725 | 754 | rc = OPENPTS_SELFTEST_FAILED; |
726 | 755 | } |
@@ -740,11 +769,14 @@ int selftest(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, | ||
740 | 769 | /* free */ |
741 | 770 | freePtsContext(ctx); |
742 | 771 | |
772 | + if (rc == PTS_FATAL) { | |
773 | + ERROR(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_SELFTEST_FAILED_3, | |
774 | + "The self test has failed. See log for details.")); | |
775 | + } | |
776 | + | |
743 | 777 | return rc; |
744 | 778 | } |
745 | 779 | |
746 | - | |
747 | - | |
748 | 780 | /** |
749 | 781 | * New RM |
750 | 782 | * |
@@ -757,7 +789,6 @@ int selftest(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, | ||
757 | 789 | * PTS_SUCCESS |
758 | 790 | * PTS_INTERNAL_ERROR |
759 | 791 | */ |
760 | - | |
761 | 792 | int newrm(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OPENPTS_PROPERTY *prop_end) { |
762 | 793 | int rc = PTS_SUCCESS; |
763 | 794 | OPENPTS_CONTEXT *ctx; |
@@ -767,7 +798,8 @@ int newrm(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OP | ||
767 | 798 | /* ctx for init */ |
768 | 799 | ctx = newPtsContext(conf); |
769 | 800 | if (ctx == NULL) { |
770 | - return PTS_INTERNAL_ERROR; | |
801 | + LOG(LOG_ERR, "newPtsContext() fail. no memory?"); | |
802 | + return PTS_FATAL; | |
771 | 803 | } |
772 | 804 | |
773 | 805 | #if 1 |
@@ -775,8 +807,9 @@ int newrm(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OP | ||
775 | 807 | prop = prop_start; |
776 | 808 | for (i = 0; i < prop_count; i++) { |
777 | 809 | if (prop == NULL) { |
778 | - LOG(LOG_ERR, "prop == NULL\n"); | |
779 | - return PTS_INTERNAL_ERROR; // TODO free | |
810 | + LOG(LOG_ERR, "prop == NULL"); | |
811 | + rc = PTS_FATAL; | |
812 | + goto free; | |
780 | 813 | } |
781 | 814 | addProperty(ctx, prop->name, prop->value); |
782 | 815 | prop = prop->next; |
@@ -797,7 +830,7 @@ int newrm(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OP | ||
797 | 830 | if (rc != PTS_SUCCESS) { |
798 | 831 | ERROR(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_FAILED_READ_FSM, |
799 | 832 | "Failed to read the FSM file.\n")); |
800 | - rc = PTS_INTERNAL_ERROR; | |
833 | + rc = PTS_FATAL; | |
801 | 834 | goto free; |
802 | 835 | } |
803 | 836 |
@@ -806,7 +839,11 @@ int newrm(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OP | ||
806 | 839 | LOG(LOG_ERR, "conf->rm_uuid == NULL"); |
807 | 840 | } else if (conf->rm_uuid->status == OPENPTS_UUID_FILENAME_ONLY) { |
808 | 841 | rc = genOpenptsUuid(conf->rm_uuid); |
809 | - // TODO | |
842 | + if (rc != PTS_SUCCESS) { | |
843 | + LOG(LOG_ERR, "genOpenptsUuid() fail\n"); | |
844 | + rc = PTS_FATAL; | |
845 | + goto free; | |
846 | + } | |
810 | 847 | } else { |
811 | 848 | DEBUG("init() - use given RM UUID %s\n", conf->rm_uuid->str); |
812 | 849 | } |
@@ -814,7 +851,9 @@ int newrm(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OP | ||
814 | 851 | /* save/update rm_uuid file */ |
815 | 852 | rc = writeOpenptsUuidFile(conf->rm_uuid, 1); // TODO overwite? |
816 | 853 | if (rc != PTS_SUCCESS) { |
817 | - LOG(LOG_ERR, "writeOpenptsUuidFile fail\n"); | |
854 | + LOG(LOG_ERR, "writeOpenptsUuidFile() fail\n"); | |
855 | + rc = PTS_FATAL; | |
856 | + goto free; | |
818 | 857 | } |
819 | 858 | |
820 | 859 | /* RM set DIR */ |
@@ -822,6 +861,7 @@ int newrm(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OP | ||
822 | 861 | if (rc != PTS_SUCCESS) { |
823 | 862 | ERROR(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_MKDIR_RM_SET_FAILED, |
824 | 863 | "Failed to create the reference manifest set directory\n")); |
864 | + rc = PTS_FATAL; | |
825 | 865 | goto free; |
826 | 866 | } |
827 | 867 |
@@ -849,6 +889,7 @@ int newrm(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OP | ||
849 | 889 | DEBUG("getBiosImlFile() was failed\n"); |
850 | 890 | LOG(LOG_ERR, "Oops! Something is wrong. Please see the reason below\n"); |
851 | 891 | printReason(ctx, 0); |
892 | + rc = PTS_FATAL; | |
852 | 893 | goto free; |
853 | 894 | } |
854 | 895 |
@@ -861,7 +902,7 @@ int newrm(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OP | ||
861 | 902 | conf->runtime_iml_type, 0, &count); // TODO endian? |
862 | 903 | if (rc != PTS_SUCCESS) { |
863 | 904 | LOG(LOG_ERR, "read IMA IML, %s was failed\n", conf->runtime_iml_filename); |
864 | - rc = PTS_INTERNAL_ERROR; | |
905 | + rc = PTS_FATAL; | |
865 | 906 | goto free; |
866 | 907 | } |
867 | 908 | } |
@@ -878,29 +919,28 @@ int newrm(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OP | ||
878 | 919 | rc = writeRm(ctx, conf->rm_filename[i], i); |
879 | 920 | if (rc != PTS_SUCCESS) { |
880 | 921 | LOG(LOG_ERR, "write RM, %s was failed\n", conf->rm_filename[i]); |
881 | - rc = PTS_INTERNAL_ERROR; | |
922 | + rc = PTS_FATAL; | |
882 | 923 | goto free; |
883 | 924 | } |
884 | 925 | OUTPUT(NLS(MS_OPENPTS, OPENPTS_NEW_RM_RM, "level %d Reference Manifest: %s\n"), i, conf->rm_filename[i]); |
885 | 926 | } else { |
886 | 927 | LOG(LOG_ERR, "missing RM file for level %d\n", i); |
928 | + // continue | |
887 | 929 | } |
888 | 930 | } |
889 | - // OUTPUT("\nptsc is successfully initialized!\n"); | |
890 | 931 | |
891 | 932 | free: |
892 | - | |
893 | - if ( rc == PTS_INTERNAL_ERROR ) { | |
894 | - OUTPUT(NLS(MS_OPENPTS, OPENPTS_NEW_RM_FAILED, "Failed to generate Reference Manifest\n")); | |
895 | - } | |
896 | - | |
897 | 933 | /* free */ |
898 | 934 | freePtsContext(ctx); |
899 | 935 | |
936 | + if ( rc == PTS_FATAL ) { | |
937 | + OUTPUT(NLS(MS_OPENPTS, OPENPTS_NEW_RM_FAILED, | |
938 | + "Failed to generate Reference Manifest. See log for details.\n")); | |
939 | + } | |
940 | + | |
900 | 941 | return rc; |
901 | 942 | } |
902 | 943 | |
903 | - | |
904 | 944 | /** |
905 | 945 | * Print the configuration of PTS collector |
906 | 946 | * |
@@ -973,7 +1013,6 @@ int printCollectorStatus(OPENPTS_CONFIG *conf) { | ||
973 | 1013 | OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_STATUS_LIST_RM, |
974 | 1014 | "List of RM set: %d RM set in config dir\n"), conf->rmsets->rmset_num); |
975 | 1015 | printRmList(conf, " "); |
976 | - // OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_STATUS_IR, "Integrity Report: %s\n"), conf->ir_filename); | |
977 | 1016 | OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_STATUS_IR, "Integrity Report dir: %s\n"), conf->ir_dir); |
978 | 1017 | |
979 | 1018 |
@@ -991,7 +1030,6 @@ int printCollectorStatus(OPENPTS_CONFIG *conf) { | ||
991 | 1030 | |
992 | 1031 | /* Manifest */ |
993 | 1032 | |
994 | - | |
995 | 1033 | /* Servers */ |
996 | 1034 | |
997 | 1035 | free: |
@@ -1023,11 +1061,12 @@ int clear( | ||
1023 | 1061 | return PTS_FATAL; |
1024 | 1062 | } |
1025 | 1063 | |
1064 | + /* msg */ | |
1065 | + VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_CLEAR, | |
1066 | + "Clear PTS collector\n")); | |
1026 | 1067 | |
1027 | - VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_CLEAR, "Clear PTS collector\n")); | |
1028 | - | |
1029 | - /* clear */ | |
1030 | - if (isatty(STDIN_FILENO) && (force == 0) ) { | |
1068 | + /* Ask */ | |
1069 | + if (isatty(STDIN_FILENO) && (force == 0)) { | |
1031 | 1070 | char *lineFeed; |
1032 | 1071 | OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_CLEAR, |
1033 | 1072 | "Clear the PTS collector [y/N]:")); |
@@ -1049,8 +1088,8 @@ int clear( | ||
1049 | 1088 | ansIsNo = !force; |
1050 | 1089 | } |
1051 | 1090 | |
1091 | + /* Yes/No */ | |
1052 | 1092 | if (ansIsYes) { |
1053 | - | |
1054 | 1093 | rc = unlinkDir(conf->config_dir); |
1055 | 1094 | if (rc != PTS_SUCCESS) { |
1056 | 1095 | LOG(LOG_ERR, "unlinkDir(%s) fail", conf->config_dir); |
@@ -1061,6 +1100,5 @@ int clear( | ||
1061 | 1100 | OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_CLEAR_NO_DONE, "keep\n")); |
1062 | 1101 | } |
1063 | 1102 | |
1064 | - | |
1065 | 1103 | return PTS_SUCCESS; |
1066 | 1104 | } |
@@ -27,61 +27,13 @@ | ||
27 | 27 | * |
28 | 28 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
29 | 29 | * @date 2010-08-13 |
30 | - * cleanup 2011-07-06 SM | |
31 | - * | |
30 | + * cleanup 2012-01-04 SM | |
32 | 31 | * |
33 | 32 | * grep strncmp src/conf.c | gawk '{print $3}' |
34 | 33 | * grep strncmp src/conf.c | awk '{print " * " $3}' | sed -e "s/\"//g" -e "s/,//g" |
35 | 34 | * |
36 | - * name default value | |
37 | - * ---------------------------------------------------- | |
38 | - * config.dir | |
39 | - * openpts.pcr.index | |
40 | - * aide | |
41 | - * aide.database.file | |
42 | - * aide.ignorelist.file | |
43 | - * aide.sqlite.file | |
44 | - * autoupdate | |
45 | - * bios.iml.file | |
46 | - * config.dir | |
47 | - * config.dir | |
48 | - * hostname | |
49 | - * ima.validation.mode | |
50 | - * iml.aligned | |
51 | - * iml.endian | |
52 | - * iml.mode | |
53 | - * ir.dir | |
54 | - * ir.file | |
55 | - * ir.quote | |
56 | - * little | |
57 | - * model.dir | |
58 | - * newrm.uuid.file | |
59 | - * oldrm.uuid.file | |
60 | - * openpts.pcr.index | |
61 | - * pcrs.file | |
62 | - * policy.file | |
63 | - * port | |
64 | - * prop.file | |
65 | - * rm.basedir | |
66 | - * rm.num | |
67 | - * rm.uuid.file | |
68 | - * runtime.iml.file | |
69 | - * runtime.iml.type | |
70 | - * securityfs | |
71 | - * selftest | |
72 | - * ssh.mode | |
73 | - * ssh.port | |
74 | - * ssh.username | |
75 | - * strncmp | |
76 | - * strncmp | |
77 | - * target.pubkey | |
78 | - * target.uuid | |
79 | - * uuid.file | |
80 | - * verifier.logging.dir | |
81 | - * ------------------------------------------------------------------------ | |
82 | - * srk.password.mode null/known | |
83 | - * ------------------------------------------------------------------------ | |
84 | - * | |
35 | + * Also update man/man5/ptsc.conf.5 | |
36 | + * | |
85 | 37 | */ |
86 | 38 | |
87 | 39 | #include <stdio.h> |
@@ -90,7 +42,6 @@ | ||
90 | 42 | #include <ctype.h> |
91 | 43 | |
92 | 44 | #include <openpts.h> |
93 | -// #include <log.h> | |
94 | 45 | |
95 | 46 | /** |
96 | 47 | * new Target list |
@@ -109,7 +60,7 @@ OPENPTS_TARGET_LIST *newTargetList(int num) { | ||
109 | 60 | } |
110 | 61 | memset(list, 0, size); |
111 | 62 | |
112 | - list->target_num = num - 1; // set actual number | |
63 | + list->target_num = num - 1; // set actual number | |
113 | 64 | |
114 | 65 | return list; |
115 | 66 | } |
@@ -157,8 +108,6 @@ void freeTargetList(OPENPTS_TARGET_LIST *list) { | ||
157 | 108 | OPENPTS_CONFIG * newPtsConfig() { |
158 | 109 | OPENPTS_CONFIG * conf; |
159 | 110 | |
160 | - // DEBUG("newPtsConfig()\n"); | |
161 | - | |
162 | 111 | /* config */ |
163 | 112 | conf = (OPENPTS_CONFIG *) xmalloc(sizeof(OPENPTS_CONFIG)); |
164 | 113 | if (conf == NULL) { |
@@ -186,7 +135,6 @@ OPENPTS_CONFIG * newPtsConfig() { | ||
186 | 135 | */ |
187 | 136 | int freePtsConfig(OPENPTS_CONFIG * conf) { |
188 | 137 | int i; |
189 | - // DEBUG("freePtsConfig()\n"); | |
190 | 138 | |
191 | 139 | /* check */ |
192 | 140 | if (conf == NULL) { |
@@ -359,7 +307,6 @@ int freePtsConfig(OPENPTS_CONFIG * conf) { | ||
359 | 307 | conf->config_file = NULL; |
360 | 308 | } |
361 | 309 | |
362 | -//<<<<<<< HEAD | |
363 | 310 | #ifdef CONFIG_AUTO_RM_UPDATE |
364 | 311 | if (conf->newRmSet != NULL) { |
365 | 312 | xfree(conf->newRmSet); |
@@ -384,14 +331,11 @@ int freePtsConfig(OPENPTS_CONFIG * conf) { | ||
384 | 331 | if (conf->compIDs[i].VendorID_Value != NULL) xfree(conf->compIDs[i].VendorID_Value); |
385 | 332 | } |
386 | 333 | |
387 | -// xfree(conf); | |
388 | -//======= | |
389 | 334 | if (conf->aik_storage_filename != NULL) { |
390 | 335 | free(conf->aik_storage_filename); |
391 | 336 | } |
392 | 337 | |
393 | 338 | free(conf); |
394 | -//>>>>>>> 042e40b0979f3e44e75200271e4d1282ce08f72c | |
395 | 339 | |
396 | 340 | return PTS_SUCCESS; |
397 | 341 | } |
@@ -435,7 +379,8 @@ static int readPtsConfig_CompID( | ||
435 | 379 | /******************/ |
436 | 380 | |
437 | 381 | if (level >= MAX_RM_NUM) { |
438 | - LOG(LOG_ERR, "readPtsConfig_CompID()- trying to affect a CompID(%s) to a level(%d) greater than MAX_RM_NUM(%d)\n", | |
382 | + LOG(LOG_ERR, | |
383 | + "readPtsConfig_CompID()- trying to affect a CompID(%s) to a level(%d) greater than MAX_RM_NUM(%d)\n", | |
439 | 384 | attributeName, level, MAX_RM_NUM); |
440 | 385 | return PTS_FATAL; |
441 | 386 | } |
@@ -555,12 +500,11 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) { | ||
555 | 500 | |
556 | 501 | /* dir where config file -> config_dir */ |
557 | 502 | if (conf->config_dir != NULL) { |
558 | - // free old one | |
503 | + /* free old one */ | |
559 | 504 | xfree(conf->config_dir); |
560 | 505 | } |
561 | 506 | conf->config_dir = getFullpathDir(filename2); |
562 | 507 | |
563 | - | |
564 | 508 | /* open */ |
565 | 509 | if ((fp = fopen(filename2, "r")) == NULL) { |
566 | 510 | DEBUG("readPtsConfig - File %s open was failed\n", filename2); |
@@ -587,17 +531,14 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) { | ||
587 | 531 | |
588 | 532 | if (line[0] == '#') { |
589 | 533 | // comment -> skip |
590 | - } else if ((eq = strstr(line, "=")) != NULL) { /* name=value line*/ | |
534 | + } else if ((eq = strstr(line, "=")) != NULL) { /* name=value line */ | |
591 | 535 | char *name; |
592 | 536 | char *value; |
593 | 537 | |
594 | 538 | name = line; |
595 | 539 | value = eq + 1; |
596 | - | |
597 | 540 | *eq = 0; |
598 | 541 | |
599 | - // DEBUG("%4d [%s]=[%s]\n",cnt, name, value); | |
600 | - | |
601 | 542 | /* config dir |
602 | 543 | replace the curent setting based on the location of config file |
603 | 544 | to path set by config file. |
@@ -696,7 +637,6 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) { | ||
696 | 637 | conf->iml_endian = 0; |
697 | 638 | #else |
698 | 639 | conf->iml_endian = 2; |
699 | - // DEBUG("convert endian mode\n"); | |
700 | 640 | DEBUG("endian mode : convert\n"); |
701 | 641 | #endif |
702 | 642 | } else { |
@@ -744,7 +684,6 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) { | ||
744 | 684 | // RM config - from 0.2.3 |
745 | 685 | if (!strncmp(name, "rm.basedir", 10)) { |
746 | 686 | if (conf->rm_basedir != NULL) { |
747 | - // DEBUG("realloc conf->rm_basedir"); // TODO realloc happen | |
748 | 687 | xfree(conf->rm_basedir); |
749 | 688 | } |
750 | 689 | conf->rm_basedir = getFullpathName(conf->config_dir, value); |
@@ -752,7 +691,9 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) { | ||
752 | 691 | if (!strncmp(name, "rm.num", 6)) { |
753 | 692 | conf->rm_num = atoi(value); |
754 | 693 | if (conf->rm_num > MAX_RM_NUM) { |
755 | - LOG(LOG_ERR, "RM number rm.num=%d is larger than MAX_RM_NUM=%d - truncking\n", conf->rm_num, MAX_RM_NUM); | |
694 | + LOG(LOG_ERR, | |
695 | + "RM number rm.num=%d is larger than MAX_RM_NUM=%d - truncking\n", | |
696 | + conf->rm_num, MAX_RM_NUM); | |
756 | 697 | conf->rm_num = MAX_RM_NUM; |
757 | 698 | } |
758 | 699 | DEBUG("conf->rm_num : %d\n", conf->rm_num); |
@@ -762,35 +703,25 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) { | ||
762 | 703 | /* Depricated - we use a temporary file in /tmp on collector side */ |
763 | 704 | if (!strncmp(name, "ir.file", 7)) { |
764 | 705 | if (conf->ir_filename != NULL) { |
765 | - // DEBUG("realloc conf->ir_filename"); // TODO realloc happen | |
766 | 706 | xfree(conf->ir_filename); |
767 | 707 | } |
768 | 708 | conf->ir_filename = getFullpathName(conf->config_dir, value); |
769 | 709 | DEBUG("conf->ir_filename : %s\n", conf->ir_filename); |
770 | - // LOG(LOG_ERR, "ir.file is obsolute, please use ir.dir"); /// Collectror TODO | |
771 | 710 | } |
772 | 711 | /* IR dir (collector side) */ |
773 | 712 | if (!strncmp(name, "ir.dir", 6)) { |
774 | 713 | if (conf->ir_dir != NULL) { |
775 | - // DEBUG("realloc conf->ir_filename"); // TODO realloc happen | |
776 | 714 | xfree(conf->ir_dir); |
777 | 715 | } |
778 | 716 | conf->ir_dir = getFullpathName(conf->config_dir, value); |
779 | 717 | DEBUG("conf->ir_dir : %s\n", conf->ir_dir); |
780 | - } // BAD else { | |
781 | - // /* set this to some sensible default value so that ptsc.c doesn't seg fault */ | |
782 | - // conf->ir_dir = smalloc("/tmp"); | |
783 | - //} | |
784 | - | |
718 | + } | |
785 | 719 | if (!strncmp(name, "prop.file", 9)) { |
786 | 720 | if (conf->prop_filename != NULL) { |
787 | - // DEBUG("realloc conf->prop_filename"); // TODO realloc happen | |
788 | 721 | xfree(conf->prop_filename); |
789 | 722 | } |
790 | 723 | conf->prop_filename = getFullpathName(conf->config_dir, value); |
791 | 724 | } |
792 | - | |
793 | - // 20100908 Munetoh -> ifm.c | |
794 | 725 | if (!strncmp(name, "ir.quote", 8)) { |
795 | 726 | if (!strncmp(value, "WITHOUT_QUOTE", 13)) { |
796 | 727 | conf->ir_without_quote = 1; |
@@ -803,6 +734,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) { | ||
803 | 734 | conf->model_dir = getFullpathName(conf->config_dir, value); |
804 | 735 | } |
805 | 736 | |
737 | + /* prop (AIX) */ | |
806 | 738 | if (!strncmp(name, "iml.ipl.maxcount", 16)) { |
807 | 739 | conf->iml_maxcount = atoi(value); |
808 | 740 | DEBUG("conf->iml_maxcount : %d\n", conf->iml_maxcount); |
@@ -816,7 +748,6 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) { | ||
816 | 748 | conf->verifier_logging_dir = getFullpathName(conf->config_dir, value); |
817 | 749 | } |
818 | 750 | |
819 | - | |
820 | 751 | if (!strncmp(name, "policy.file", 11)) { |
821 | 752 | if (conf->policy_filename != NULL) { |
822 | 753 | // DEBUG("realloc conf->policy_filename\n"); // TODO realloc happen |
@@ -825,17 +756,6 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) { | ||
825 | 756 | conf->policy_filename = getFullpathName(conf->config_dir, value); |
826 | 757 | } |
827 | 758 | |
828 | -#if 0 | |
829 | - if (!strncmp(name, "config.dir", 10)) { | |
830 | - if (conf->config_dir != NULL) { | |
831 | - LOG(LOG_TODO, "conf dir %s ->%s\n", conf->config_dir, value); | |
832 | - // | |
833 | - } else { | |
834 | - conf->config_dir = getFullpathName(config_path, value); | |
835 | - } | |
836 | - } | |
837 | -#endif | |
838 | - | |
839 | 759 | /* IMA and AIDE */ |
840 | 760 | if (!strncmp(name, "ima.validation.mode", 19)) { |
841 | 761 | if (!strncmp(value, "aide", 4)) { |
@@ -851,7 +771,6 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) { | ||
851 | 771 | #ifdef CONFIG_AIDE |
852 | 772 | if (!strncmp(name, "aide.database.file", 18)) { |
853 | 773 | if (conf->aide_database_filename != NULL) { |
854 | - // DEBUG("realloc conf->aide_database_filename\n"); // TODO realloc happen | |
855 | 774 | xfree(conf->aide_database_filename); |
856 | 775 | } |
857 | 776 | conf->aide_database_filename = getFullpathName(conf->config_dir, value); |
@@ -863,7 +782,6 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) { | ||
863 | 782 | #endif |
864 | 783 | if (!strncmp(name, "aide.ignorelist.file", 20)) { |
865 | 784 | if (conf->aide_ignorelist_filename != NULL) { |
866 | - // DEBUG("realloc conf->aide_ignorelist_filename\n"); // TODO realloc happen | |
867 | 785 | xfree(conf->aide_ignorelist_filename); |
868 | 786 | } |
869 | 787 | conf->aide_ignorelist_filename = getFullpathName(conf->config_dir, value); |
@@ -913,7 +831,6 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) { | ||
913 | 831 | conf->rm_uuid = newOpenptsUuid(); |
914 | 832 | } |
915 | 833 | if (conf->rm_uuid->filename != NULL) { |
916 | - // DEBUG("realloc conf->rm_uuid->filename"); // TODO realloc happen | |
917 | 834 | xfree(conf->rm_uuid->filename); |
918 | 835 | } |
919 | 836 | conf->rm_uuid->filename = getFullpathName(conf->config_dir, value); |
@@ -921,11 +838,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) { | ||
921 | 838 | rc = readOpenptsUuidFile(conf->rm_uuid); |
922 | 839 | if (rc != PTS_SUCCESS) { |
923 | 840 | /* uuid file is missing */ |
924 | - // TODO gen UUID? | |
925 | - // DEBUG("no UUID file %s\n", conf->uuid->filename); | |
926 | 841 | conf->rm_uuid->status = OPENPTS_UUID_FILENAME_ONLY; |
927 | - } else { | |
928 | - // DEBUG("read UUID from file %s, UUID=%s\n", conf->uuid->filename, conf->uuid->str); | |
929 | 842 | } |
930 | 843 | DEBUG("conf->rm_uuid->str : %s\n", conf->rm_uuid->str); |
931 | 844 | } |
@@ -937,7 +850,6 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) { | ||
937 | 850 | conf->newrm_uuid = newOpenptsUuid(); |
938 | 851 | } |
939 | 852 | if (conf->newrm_uuid->filename != NULL) { |
940 | - // DEBUG("realloc conf->rm_uuid->filename"); // TODO realloc happen | |
941 | 853 | xfree(conf->newrm_uuid->filename); |
942 | 854 | } |
943 | 855 | conf->newrm_uuid->filename = getFullpathName(conf->config_dir, value); |
@@ -945,8 +857,6 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) { | ||
945 | 857 | rc = readOpenptsUuidFile(conf->newrm_uuid); |
946 | 858 | if (rc != PTS_SUCCESS) { |
947 | 859 | /* uuid file is missing */ |
948 | - // TODO gen UUID? | |
949 | - // DEBUG("no UUID file %s\n", conf->uuid->filename); | |
950 | 860 | conf->newrm_uuid->status = OPENPTS_UUID_FILENAME_ONLY; |
951 | 861 | } else { |
952 | 862 | conf->pts_flag[0] |= OPENPTS_FLAG0_NEWRM_EXIST; |
@@ -961,7 +871,6 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) { | ||
961 | 871 | conf->oldrm_uuid = newOpenptsUuid(); |
962 | 872 | } |
963 | 873 | if (conf->oldrm_uuid->filename != NULL) { |
964 | - // DEBUG("realloc conf->oldrm_uuid->filename"); // TODO realloc happen | |
965 | 874 | xfree(conf->oldrm_uuid->filename); |
966 | 875 | } |
967 | 876 | conf->oldrm_uuid->filename = getFullpathName(conf->config_dir, value); |
@@ -969,11 +878,7 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) { | ||
969 | 878 | rc = readOpenptsUuidFile(conf->oldrm_uuid); |
970 | 879 | if (rc != PTS_SUCCESS) { |
971 | 880 | /* uuid file is missing */ |
972 | - // TODO gen UUID? | |
973 | - // DEBUG("no UUID file %s\n", conf->uuid->filename); | |
974 | 881 | conf->oldrm_uuid->status = OPENPTS_UUID_FILENAME_ONLY; |
975 | - } else { | |
976 | - // DEBUG("read UUID from file %s, UUID=%s\n", conf->uuid->filename, conf->uuid->str); | |
977 | 882 | } |
978 | 883 | DEBUG("conf->oldrm_uuid->str : %s\n", conf->oldrm_uuid->str); |
979 | 884 | } |
@@ -981,7 +886,6 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) { | ||
981 | 886 | /* */ |
982 | 887 | if (!strncmp(name, "target.uuid", 11)) { |
983 | 888 | if (conf->target_uuid != NULL) { |
984 | - // DEBUG("realloc conf->target_uuid\n"); // TODO realloc happen | |
985 | 889 | xfree(conf->target_uuid); |
986 | 890 | } |
987 | 891 | conf->target_uuid = getUuidFromString(value); |
@@ -990,7 +894,6 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) { | ||
990 | 894 | } else { |
991 | 895 | // add string too |
992 | 896 | if (conf->str_target_uuid != NULL) { |
993 | - // DEBUG("realloc conf->str_target_uuid\n"); // TODO realloc happen | |
994 | 897 | xfree(conf->str_target_uuid); |
995 | 898 | } |
996 | 899 | conf->str_target_uuid = getStringOfUuid(conf->target_uuid); |
@@ -1035,7 +938,6 @@ int readPtsConfig(OPENPTS_CONFIG *conf, char *filename) { | ||
1035 | 938 | /* hostname */ |
1036 | 939 | if (!strncmp(name, "hostname", 8)) { |
1037 | 940 | if (conf->hostname != NULL) { |
1038 | - // DEBUG("realloc conf->hostname\n"); // TODO realloc happen | |
1039 | 941 | xfree(conf->hostname); |
1040 | 942 | } |
1041 | 943 | conf->hostname = smalloc_assert(value); |
@@ -26,7 +26,7 @@ | ||
26 | 26 | * \brief PTS context |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2010-04-01 |
29 | - * cleanup 2011-07-06 SM | |
29 | + * cleanup 2012-01-05 SM | |
30 | 30 | * |
31 | 31 | * OpenPTS main context |
32 | 32 | * |
@@ -51,6 +51,7 @@ OPENPTS_CONTEXT * newPtsContext(OPENPTS_CONFIG *conf) { | ||
51 | 51 | |
52 | 52 | ctx = (OPENPTS_CONTEXT *) xmalloc(sizeof(OPENPTS_CONTEXT)); |
53 | 53 | if (ctx == NULL) { |
54 | + LOG(LOG_ERR, "no memory"); | |
54 | 55 | return NULL; |
55 | 56 | } |
56 | 57 | memset(ctx, 0, sizeof(OPENPTS_CONTEXT)); |
@@ -64,6 +65,7 @@ OPENPTS_CONTEXT * newPtsContext(OPENPTS_CONFIG *conf) { | ||
64 | 65 | /* IF-M nonce */ |
65 | 66 | ctx->nonce = newNonceContext(); |
66 | 67 | if (ctx->nonce == NULL) { |
68 | + LOG(LOG_ERR, "newNonceContext() fail. no memory"); | |
67 | 69 | goto error; |
68 | 70 | } |
69 | 71 |
@@ -86,9 +88,10 @@ int freePtsContext(OPENPTS_CONTEXT *ctx) { | ||
86 | 88 | int i; |
87 | 89 | DEBUG_CAL("freePtsContext - start\n"); |
88 | 90 | |
91 | + /* check */ | |
89 | 92 | if (ctx == NULL) { |
90 | - DEBUG("freePtsContext - NULL\n"); | |
91 | - return -1; | |
93 | + LOG(LOG_ERR, "null input"); | |
94 | + return PTS_FATAL; | |
92 | 95 | } |
93 | 96 | |
94 | 97 | /* TPM emu - reset */ |
@@ -229,9 +232,7 @@ char * getAlgString(int type) { | ||
229 | 232 | */ |
230 | 233 | int readFsmFromPropFile(OPENPTS_CONTEXT *ctx, char * filename) { |
231 | 234 | int rc = PTS_SUCCESS; |
232 | - OPENPTS_CONFIG *conf; | |
233 | 235 | FILE *fp; |
234 | - | |
235 | 236 | char buf[FSM_BUF_SIZE]; |
236 | 237 | char buf2[FSM_BUF_SIZE]; |
237 | 238 | char *eqp = NULL; |
@@ -239,18 +240,30 @@ int readFsmFromPropFile(OPENPTS_CONTEXT *ctx, char * filename) { | ||
239 | 240 | int level; |
240 | 241 | char *model_filename = NULL; |
241 | 242 | int len; |
242 | - | |
243 | + OPENPTS_CONFIG *conf; | |
243 | 244 | OPENPTS_FSM_CONTEXT *fsm = NULL; |
244 | 245 | OPENPTS_SNAPSHOT *ss = NULL; |
245 | 246 | |
247 | + /* check */ | |
248 | + if (ctx == NULL) { | |
249 | + LOG(LOG_ERR, "null input"); | |
250 | + return PTS_FATAL; | |
251 | + } | |
246 | 252 | conf = ctx->conf; |
253 | + if (conf == NULL) { | |
254 | + LOG(LOG_ERR, "null input"); | |
255 | + return PTS_FATAL; | |
256 | + } | |
257 | + if (filename == NULL) { | |
258 | + LOG(LOG_ERR, "null input"); | |
259 | + return PTS_FATAL; | |
260 | + } | |
247 | 261 | |
248 | 262 | /* new snapshot table */ |
249 | 263 | if (ctx->ss_table == NULL) { |
250 | 264 | ctx->ss_table = newSnapshotTable(); |
251 | 265 | } |
252 | 266 | |
253 | - | |
254 | 267 | /* Open prop file */ |
255 | 268 | if ((fp = fopen(filename, "r")) == NULL) { |
256 | 269 | OUTPUT(NLS(MS_OPENPTS, OPENPTS_CONFIG_MISSING, "Cannot open config file '%s'\n"), filename); |
@@ -285,7 +298,7 @@ int readFsmFromPropFile(OPENPTS_CONTEXT *ctx, char * filename) { | ||
285 | 298 | if (strstr(buf, "platform.model.") != NULL) { |
286 | 299 | LOG(LOG_ERR, "ptsc.conf has old format <=v0.2.3 %s\n", filename); |
287 | 300 | LOG(LOG_ERR, "change platform.model to rm.model.0\n"); |
288 | - OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_BAD_CONFIG_FILE, "Bad configuration file\n")); | |
301 | + OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_BAD_CONFIG_FILE, "Bad configuration file (v0.2.3)\n")); | |
289 | 302 | rc = PTS_FATAL; |
290 | 303 | goto error; |
291 | 304 | } |
@@ -293,7 +306,7 @@ int readFsmFromPropFile(OPENPTS_CONTEXT *ctx, char * filename) { | ||
293 | 306 | if (strstr(buf, "runtime.model.") != NULL) { |
294 | 307 | LOG(LOG_ERR, "ptsc.conf has old format <=v0.2.3 %s\n", filename); |
295 | 308 | LOG(LOG_ERR, "change runtime.model to rm.model.1\n"); |
296 | - OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_BAD_CONFIG_FILE, "Bad configuration file\n")); | |
309 | + OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_BAD_CONFIG_FILE, "Bad configuration file (v0.2.3)\n")); | |
297 | 310 | rc = PTS_FATAL; |
298 | 311 | goto error; |
299 | 312 | } |
@@ -320,7 +333,6 @@ int readFsmFromPropFile(OPENPTS_CONTEXT *ctx, char * filename) { | ||
320 | 333 | "%s/%s", |
321 | 334 | conf->model_dir, model_filename); |
322 | 335 | rc = readUmlModel(fsm, buf2); |
323 | - // TODO(munetoh) cehck rc | |
324 | 336 | if (rc != PTS_SUCCESS) { |
325 | 337 | LOG(LOG_ERR, "addFsmByPropFile - [%s] / [%s] -> [%s] fail rc=%d, pwd = %s\n", |
326 | 338 | conf->model_dir, model_filename, buf2, rc, |
@@ -26,9 +26,9 @@ | ||
26 | 26 | * \brief Finite State Machine |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2010-04-01 |
29 | - * cleanup 2011-01-21 SM | |
30 | - * refactoring 2011-07-20 SM | |
31 | - * | |
29 | + * cleanup 2012-01-05 SM (remains one lint error) | |
30 | + * src/fsm.c:416: Use int16/int64/etc, rather than the C type long [runtime/int] [4] | |
31 | + * | |
32 | 32 | * Input |
33 | 33 | * FSM Model |
34 | 34 | * IML |
@@ -99,7 +99,6 @@ void freeFsmTransitionChain(OPENPTS_FSM_Transition *fsm_trans) { | ||
99 | 99 | * Free OPENPTS_FSM_Subvertex chain |
100 | 100 | */ |
101 | 101 | void freeFsmSubvertexChain(OPENPTS_FSM_Subvertex *fsm_sub) { |
102 | - | |
103 | 102 | /* check */ |
104 | 103 | if (fsm_sub == NULL) { |
105 | 104 | LOG(LOG_ERR, "null input"); |
@@ -119,7 +118,6 @@ void freeFsmSubvertexChain(OPENPTS_FSM_Subvertex *fsm_sub) { | ||
119 | 118 | * free FSM context |
120 | 119 | */ |
121 | 120 | int freeFsmContext(OPENPTS_FSM_CONTEXT *ctx) { |
122 | - | |
123 | 121 | /* check */ |
124 | 122 | if (ctx == NULL) { |
125 | 123 | LOG(LOG_ERR, "null input"); |
@@ -161,7 +159,12 @@ void resetFsmSubvertex(OPENPTS_FSM_CONTEXT *ctx) { | ||
161 | 159 | return; |
162 | 160 | } |
163 | 161 | |
164 | - // fsm_sub=NULL; | |
162 | + /* free subvertex chain */ | |
163 | + if (ctx->fsm_sub != NULL) { | |
164 | + freeFsmSubvertexChain(ctx->fsm_sub); | |
165 | + ctx->fsm_sub = NULL; | |
166 | + } | |
167 | + | |
165 | 168 | ctx->subvertex_num = 0; |
166 | 169 | } |
167 | 170 |
@@ -175,7 +178,12 @@ void resetFsmTransition(OPENPTS_FSM_CONTEXT *ctx) { | ||
175 | 178 | return; |
176 | 179 | } |
177 | 180 | |
178 | - // fsm_trans=NULL; | |
181 | + /* free transition chain */ | |
182 | + if (ctx->fsm_trans != NULL) { | |
183 | + freeFsmTransitionChain(ctx->fsm_trans); | |
184 | + ctx->fsm_trans = NULL; | |
185 | + } | |
186 | + | |
179 | 187 | ctx->transition_num = 0; |
180 | 188 | } |
181 | 189 |
@@ -471,13 +479,11 @@ int getTypeFlag(char * cond, UINT32 *eventtype /* out */) { | ||
471 | 479 | if ((loc[0] == '0') && (loc[1] == 'x')) { // 0x HEX |
472 | 480 | val = strtoll(loc, NULL, 16); |
473 | 481 | *eventtype = (UINT32)val; |
474 | - // DEBUG("strtol [%s] => %X => %X\n", loc,val,*eventtype); | |
475 | 482 | return rc; |
476 | 483 | } |
477 | 484 | } |
478 | 485 | val = strtoll(loc, NULL, 10); |
479 | 486 | *eventtype = (UINT32)val; |
480 | - // DEBUG("strtol [%s] => %X => %X\n", loc,val, *eventtype); | |
481 | 487 | |
482 | 488 | return rc; |
483 | 489 | } |
@@ -628,7 +634,7 @@ int getCounterFlag(char *cond, char *name, char **flag /* out */) { | ||
628 | 634 | |
629 | 635 | loc = skipWhiteSpace(loc, &len); |
630 | 636 | if (isEndOfString(loc)) { |
631 | - goto error; //return -1; | |
637 | + goto error; | |
632 | 638 | } |
633 | 639 | |
634 | 640 | /* operation, "<" ">=" only */ |
@@ -666,12 +672,12 @@ int getCounterFlag(char *cond, char *name, char **flag /* out */) { | ||
666 | 672 | len -=2; |
667 | 673 | } else { |
668 | 674 | LOG(LOG_ERR, "unknown operand [%s]", &loc[0]); |
669 | - goto error; //return -1; | |
675 | + goto error; | |
670 | 676 | } |
671 | 677 | |
672 | 678 | loc = skipWhiteSpace(loc, &len); |
673 | 679 | if (isEndOfString(loc)) { |
674 | - goto error; //return -1; | |
680 | + goto error; | |
675 | 681 | } |
676 | 682 | |
677 | 683 | // TODO check the end, this code only support if counter is the last |
@@ -680,14 +686,14 @@ int getCounterFlag(char *cond, char *name, char **flag /* out */) { | ||
680 | 686 | param_len = loc2 - loc; |
681 | 687 | if (0 == param_len) { |
682 | 688 | /* we haven't moved along the string - no valid parameter found */ |
683 | - goto error; //return -1; | |
689 | + goto error; | |
684 | 690 | } |
685 | 691 | |
686 | 692 | /* DEBUG_FSM("[%d][%s][%s]\n",len, loc, loc2); */ |
687 | 693 | |
688 | 694 | *flag = xmalloc(param_len + 1); |
689 | 695 | if (*flag == NULL) { |
690 | - goto error; //return -1; | |
696 | + goto error; | |
691 | 697 | } |
692 | 698 | memset(*flag, 0, param_len + 1); |
693 | 699 | memcpy(*flag, loc, param_len); |
@@ -788,14 +794,9 @@ int getLastFlag(char * cond) { | ||
788 | 794 | } |
789 | 795 | } |
790 | 796 | |
791 | - // DEBUG("getLastFlag %s #=> %d\n",cond, rc); | |
792 | - | |
793 | 797 | return rc; |
794 | 798 | } |
795 | 799 | |
796 | - | |
797 | - | |
798 | - | |
799 | 800 | /** |
800 | 801 | * add FSM transition |
801 | 802 | * |
@@ -1011,9 +1012,6 @@ int updateFsm( | ||
1011 | 1012 | OPENPTS_PCR_EVENT_WRAPPER *eventWrapper |
1012 | 1013 | ) { |
1013 | 1014 | int rc = OPENPTS_FSM_SUCCESS; |
1014 | - OPENPTS_FSM_Subvertex *curr_state; | |
1015 | - OPENPTS_FSM_Transition *trans; | |
1016 | - TSS_PCR_EVENT *event; | |
1017 | 1015 | int type_check; |
1018 | 1016 | int digest_check; |
1019 | 1017 | int fatal_counter_check; |
@@ -1021,7 +1019,10 @@ int updateFsm( | ||
1021 | 1019 | int dont_care; |
1022 | 1020 | int hit = 0; |
1023 | 1021 | char *hex; |
1022 | + OPENPTS_FSM_Subvertex *curr_state; | |
1023 | + OPENPTS_FSM_Transition *trans; | |
1024 | 1024 | OPENPTS_FSM_Transition *hit_trans = NULL; |
1025 | + TSS_PCR_EVENT *event; | |
1025 | 1026 | |
1026 | 1027 | DEBUG_CAL("updateFsm - start\n"); |
1027 | 1028 |
@@ -1511,12 +1512,10 @@ int updateFsm( | ||
1511 | 1512 | * called from rm.c |
1512 | 1513 | */ |
1513 | 1514 | OPENPTS_FSM_CONTEXT *copyFsm(OPENPTS_FSM_CONTEXT *src_fsm) { |
1514 | - OPENPTS_FSM_CONTEXT * dst_fsm = NULL; | |
1515 | - | |
1515 | + OPENPTS_FSM_CONTEXT *dst_fsm = NULL; | |
1516 | 1516 | OPENPTS_FSM_Subvertex *src_fsm_sub; |
1517 | 1517 | OPENPTS_FSM_Subvertex *dst_fsm_sub = NULL; |
1518 | 1518 | OPENPTS_FSM_Subvertex *dst_fsm_sub_prev = NULL; |
1519 | - | |
1520 | 1519 | OPENPTS_FSM_Transition *src_fsm_trans; |
1521 | 1520 | OPENPTS_FSM_Transition *dst_fsm_trans = NULL; |
1522 | 1521 | OPENPTS_FSM_Transition *dst_fsm_trans_prev = NULL; |
@@ -1664,8 +1663,8 @@ int changeTargetSubvertex( | ||
1664 | 1663 | OPENPTS_FSM_Subvertex *old_sub, // B |
1665 | 1664 | OPENPTS_FSM_Subvertex *new_sub) { // BN |
1666 | 1665 | int rc = 0; |
1667 | - OPENPTS_FSM_Transition *fsm_trans; | |
1668 | 1666 | int count = 0; |
1667 | + OPENPTS_FSM_Transition *fsm_trans; | |
1669 | 1668 | |
1670 | 1669 | /* check */ |
1671 | 1670 | if (fsm_ctx == NULL) { |
@@ -1721,8 +1720,8 @@ int changeTransTargetSubvertex( | ||
1721 | 1720 | OPENPTS_FSM_Subvertex *old_sub, // B |
1722 | 1721 | OPENPTS_FSM_Subvertex *new_sub) { // BN |
1723 | 1722 | int rc = 0; |
1724 | - OPENPTS_FSM_Transition *fsm_trans; | |
1725 | 1723 | int count = 0; |
1724 | + OPENPTS_FSM_Transition *fsm_trans; | |
1726 | 1725 | |
1727 | 1726 | /* check */ |
1728 | 1727 | if (fsm_ctx == NULL) { |
@@ -1813,9 +1812,9 @@ int insertFsmNew( | ||
1813 | 1812 | OPENPTS_FSM_Transition *fsm_trans, // target Trans |
1814 | 1813 | OPENPTS_PCR_EVENT_WRAPPER *eventWrapper) { |
1815 | 1814 | int rc =0; |
1816 | - OPENPTS_FSM_Subvertex *prev_sub; // STRUCT LINK | |
1817 | - OPENPTS_FSM_Subvertex *new_sub; | |
1818 | - OPENPTS_FSM_Subvertex *dst_sub; | |
1815 | + OPENPTS_FSM_Subvertex *prev_sub; // STRUCT LINK | |
1816 | + OPENPTS_FSM_Subvertex *new_sub; | |
1817 | + OPENPTS_FSM_Subvertex *dst_sub; | |
1819 | 1818 | OPENPTS_FSM_Transition *prev_trans; // STRUCT LINK |
1820 | 1819 | OPENPTS_FSM_Transition *new_trans; |
1821 | 1820 | TSS_PCR_EVENT *event; |
@@ -1851,7 +1850,6 @@ int insertFsmNew( | ||
1851 | 1850 | return -1; |
1852 | 1851 | } |
1853 | 1852 | |
1854 | - | |
1855 | 1853 | /* start */ |
1856 | 1854 | if (fsm_trans->source_subvertex == fsm_trans->target_subvertex) { |
1857 | 1855 | /* OK, this is LOOP, */ |
@@ -1862,7 +1860,6 @@ int insertFsmNew( | ||
1862 | 1860 | dst_sub = fsm_trans->target_subvertex; |
1863 | 1861 | |
1864 | 1862 | /* Add new subvertex, BN (->B) */ |
1865 | - | |
1866 | 1863 | new_sub = (OPENPTS_FSM_Subvertex *) |
1867 | 1864 | xmalloc(sizeof(OPENPTS_FSM_Subvertex)); |
1868 | 1865 | if (new_sub == NULL) { |
@@ -2256,6 +2253,7 @@ int writeDotModel(OPENPTS_FSM_CONTEXT *ctx, char * filename) { | ||
2256 | 2253 | return PTS_FATAL; |
2257 | 2254 | } |
2258 | 2255 | |
2256 | + /* check filename, open */ | |
2259 | 2257 | if (filename == NULL) { |
2260 | 2258 | fp = stdout; |
2261 | 2259 | } else { |
@@ -26,7 +26,7 @@ | ||
26 | 26 | * \brief TCG IF-M protocol |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2010-04-01 |
29 | - * cleanup 2011-04-26 SM | |
29 | + * cleanup 2012-01-05 SM | |
30 | 30 | * |
31 | 31 | * 2011-06-20 SM - do not use sendfile() |
32 | 32 | * IF-M did not work with endfile. |
@@ -53,7 +53,6 @@ | ||
53 | 53 | #endif |
54 | 54 | |
55 | 55 | #include <openpts.h> |
56 | -// #include <log.h> | |
57 | 56 | |
58 | 57 | // TODO |
59 | 58 | #define MAX_TLV_MESSAGE_LENGTH 5120000 |
@@ -210,19 +209,12 @@ PTS_IF_M_Attribute *readPtsTlv(int fdin) { | ||
210 | 209 | goto error; |
211 | 210 | } |
212 | 211 | |
213 | - // copy buf to PTS_IF_M_Attribute (NBO) | |
212 | + /* copy buf to PTS_IF_M_Attribute (NBO) */ | |
214 | 213 | memcpy(read_tlv, head, 12); |
215 | - // Convert NBO to Host byte order | |
214 | + /* Convert NBO to Host byte order */ | |
216 | 215 | read_tlv->type = ntohl(read_tlv->type); |
217 | 216 | read_tlv->length = ntohl(read_tlv->length); |
218 | 217 | |
219 | -#if 0 | |
220 | - TODO("IF-M type : 0x%02x%02x%02x%02x (NBO)", | |
221 | - head[4], head[5], head[6], head[7]); | |
222 | - TODO("IF-M length: 0x%02x%02x%02x%02x (NBO) %d", | |
223 | - head[8], head[9], head[10], head[11], read_tlv->length); | |
224 | -#endif | |
225 | - | |
226 | 218 | /* check the length */ |
227 | 219 | if (read_tlv->length > MAX_TLV_MESSAGE_LENGTH) { |
228 | 220 | LOG(LOG_ERR, "read_tlv->length = %d (0x%X)> %d\n", |
@@ -267,7 +259,6 @@ PTS_IF_M_Attribute *readPtsTlv(int fdin) { | ||
267 | 259 | return read_tlv; |
268 | 260 | |
269 | 261 | error: |
270 | - // if (read_msg != NULL) free(read_msg); | |
271 | 262 | if (read_tlv != NULL) { |
272 | 263 | freePtsTlv(read_tlv); |
273 | 264 | } |
@@ -293,10 +284,7 @@ void freePtsTlv(PTS_IF_M_Attribute *tlv) { | ||
293 | 284 | } |
294 | 285 | |
295 | 286 | |
296 | - | |
297 | - | |
298 | - | |
299 | -/* TNC, libtnc */ | |
287 | +/* TNC, libtnc ---------------------------------------------------------------*/ | |
300 | 288 | |
301 | 289 | /** |
302 | 290 | * malloc TLV buffer and fill the header |
@@ -425,8 +413,6 @@ BYTE* getPtsTlvMessage(OPENPTS_CONTEXT *ctx, int type, int *len) { | ||
425 | 413 | break; |
426 | 414 | } |
427 | 415 | |
428 | - | |
429 | - | |
430 | 416 | /* Collector --> Verifier */ |
431 | 417 | case TPM_PUBKEY: |
432 | 418 | { |
@@ -939,6 +925,3 @@ int writePtsTlv(OPENPTS_CONTEXT *ctx, int fdout, int type) { | ||
939 | 925 | |
940 | 926 | return -1; |
941 | 927 | } |
942 | - | |
943 | - | |
944 | - |
@@ -26,7 +26,7 @@ | ||
26 | 26 | * \brief TCG TNC IF-IMC v1.2 R8 |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2010-05-07 |
29 | - * cleanup 2011-12-31 SM | |
29 | + * cleanup 2012-01-05 SM | |
30 | 30 | * |
31 | 31 | * http://www.trustedcomputinggroup.org/resources/tnc_ifimc_specification |
32 | 32 | * http://www.trustedcomputinggroup.org/files/resource_files/8CB977E1-1D09-3519-AD48484530EF6639/TNC_IFIMC_v1_2_r8.pdf |
@@ -72,11 +72,6 @@ static TNC_TNCC_SendMessagePointer sendMessagePtr; | ||
72 | 72 | static OPENPTS_CONFIG *conf = NULL; |
73 | 73 | static OPENPTS_CONTEXT *ctx = NULL; |
74 | 74 | |
75 | -// int verbose = 0; | |
76 | -// int verbose = DEBUG_IFM_FLAG; | |
77 | -// int verbose = DEBUG_FLAG | DEBUG_IFM_FLAG; | |
78 | - | |
79 | - | |
80 | 75 | static TNC_Result sendMessage( |
81 | 76 | /*in*/ TNC_IMCID imcID, |
82 | 77 | /*in*/ TNC_ConnectionID connectionID, |
@@ -26,7 +26,7 @@ | ||
26 | 26 | * \brief Load TCG Integrity Measurement Log (IML) |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2010-04-01 |
29 | - * cleanup 2011-07-06 SM | |
29 | + * cleanup 2012-01-05 SM | |
30 | 30 | * |
31 | 31 | * get IML/PCRS from filesystem |
32 | 32 | * get IML/PCRS vis TSS |
@@ -47,8 +47,8 @@ void printEventWrapper(OPENPTS_PCR_EVENT_WRAPPER *eventWrapper); | ||
47 | 47 | * |
48 | 48 | * TODO use ctx, |
49 | 49 | * TODO reset level1 too |
50 | + * TODO move to snapshot? | |
50 | 51 | */ |
51 | -// TODO move to snapshot? | |
52 | 52 | int resetSnapshot(OPENPTS_SNAPSHOT * snapshots) { |
53 | 53 | int i, j; |
54 | 54 | OPENPTS_SNAPSHOT *ss; |
@@ -81,14 +81,12 @@ int resetSnapshot(OPENPTS_SNAPSHOT * snapshots) { | ||
81 | 81 | xfree(eventWrapper); |
82 | 82 | eventWrapper = eventWrapper_next; |
83 | 83 | } |
84 | - // if (iml[i].eventList != NULL) xfree(iml[i].eventList); | |
85 | 84 | ss->pcrIndex = i; |
86 | 85 | ss->event_num = 0; |
87 | 86 | ss->level = 0; |
88 | 87 | } |
89 | 88 | |
90 | - | |
91 | - return 0; // TODO(munetoh) | |
89 | + return PTS_SUCCESS; | |
92 | 90 | } |
93 | 91 | |
94 | 92 |
@@ -234,11 +232,15 @@ int addEventToSnapshotBhv( | ||
234 | 232 | ss = getSnapshotFromTable(ctx->ss_table, index, 1); |
235 | 233 | if (ss == NULL) { |
236 | 234 | LOG(LOG_ERR, "getSnapshotFromTable(%d,1) is null", index); |
235 | + // ctx->conf->config_file != NULL | |
236 | + LOG(LOG_ERR, "index %d\n", index); | |
237 | + LOG(LOG_ERR, "ctx->conf->config_file %s\n", ctx->conf->config_file); | |
237 | 238 | addReason(ctx, index, NLS(MS_OPENPTS, OPENPTS_IML_SNAPSHOT_MISSING, |
238 | 239 | "[PCR%02d] Snapshot(FSM) is missing for PCR%d. " |
239 | 240 | "Please check the configuration file '%s'"), |
240 | 241 | index, |
241 | - index, ctx->conf->config_file); | |
242 | + index, | |
243 | + ctx->conf->config_file); | |
242 | 244 | ctx->ss_table->error[index] = PTS_INTERNAL_ERROR; |
243 | 245 | return PTS_INTERNAL_ERROR; |
244 | 246 | } |
@@ -253,6 +255,8 @@ int addEventToSnapshotBhv( | ||
253 | 255 | } else { |
254 | 256 | /* FSM is missing */ |
255 | 257 | LOG(LOG_ERR, "getSnapshotFromTable(), FSM is null"); |
258 | + LOG(LOG_ERR, "index %d\n", index); | |
259 | + LOG(LOG_ERR, "ctx->conf->config_file %s\n", ctx->conf->config_file); | |
256 | 260 | addReason(ctx, index, NLS(MS_OPENPTS, OPENPTS_IML_FSM_MISSING, |
257 | 261 | "[RM01-PCR%02d] FSM is missing for PCR%d, Level 1. " |
258 | 262 | "Please check the configuration file '%s'"), |
@@ -433,7 +437,6 @@ int addEventToSnapshotBhv( | ||
433 | 437 | * PTS_INVALID_SNAPSHOT bad event (FSM fail) |
434 | 438 | * PTS_INTERNAL_ERROR else |
435 | 439 | * |
436 | - * | |
437 | 440 | */ |
438 | 441 | int addEventToSnapshotBin( |
439 | 442 | OPENPTS_CONTEXT * ctx, |
@@ -474,7 +477,7 @@ int addEventToSnapshotBin( | ||
474 | 477 | |
475 | 478 | /* check next level (1) */ |
476 | 479 | if (ss == NULL) { |
477 | - LOG(LOG_ERR, "addEventToSnapshotBin() - pcr=%d Level=%d snapshots is missing\n",index, active_level); | |
480 | + LOG(LOG_ERR, "addEventToSnapshotBin() - pcr=%d Level=%d snapshots is missing\n", index, active_level); | |
478 | 481 | addReason(ctx, index, NLS(MS_OPENPTS, OPENPTS_IML_SNAPSHOT_MISSING_3, "[PCR%02d] Snapshot(FSM) is missing"), |
479 | 482 | index); |
480 | 483 | ctx->ss_table->error[index] = PTS_INTERNAL_ERROR; |
@@ -617,7 +620,6 @@ int flashSnapshot( | ||
617 | 620 | OPENPTS_SNAPSHOT *ss; |
618 | 621 | OPENPTS_SNAPSHOT *ss_lv0 = NULL; |
619 | 622 | |
620 | - | |
621 | 623 | DEBUG_CAL("flashSnapshot - start\n"); |
622 | 624 | |
623 | 625 | /* check */ |
@@ -996,21 +998,18 @@ int readBiosImlFile(OPENPTS_CONTEXT * ctx, const char *filename, int mode) { | ||
996 | 998 | int rc = PTS_SUCCESS; |
997 | 999 | int result; |
998 | 1000 | int i = 0; |
1001 | + int endian = 0; | |
1002 | + int aligned = 0; | |
1003 | + int error = 0; | |
999 | 1004 | size_t size; |
1000 | 1005 | FILE *fp = NULL; |
1001 | 1006 | UINT32 pcrIndex; |
1002 | 1007 | UINT32 eventType; |
1003 | 1008 | UINT32 eventLength; |
1004 | - int endian = 0; | |
1005 | - int aligned = 0; | |
1006 | - | |
1007 | 1009 | TSS_PCR_EVENT *event = NULL; |
1008 | 1010 | OPENPTS_PCR_EVENT_WRAPPER *ew_new = NULL; |
1009 | - // OPENPTS_PCR_EVENT_WRAPPER *ew_last = NULL; | |
1010 | - int error = 0; | |
1011 | 1011 | |
1012 | 1012 | DEBUG_CAL("getBiosImlFile - start\n"); |
1013 | - // DEBUG("read BIOS IML, file %s\n", filename); | |
1014 | 1013 | |
1015 | 1014 | /* check */ |
1016 | 1015 | if (ctx == NULL) { |
@@ -26,7 +26,7 @@ | ||
26 | 26 | * \brief convert IML to AIDE DB |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2010-08-24 |
29 | - * cleanup 2011-07-06 SM | |
29 | + * cleanup 2012-01-05 SM | |
30 | 30 | * |
31 | 31 | * create AIDE DB from IML (via securityfs) |
32 | 32 | * |
@@ -24,7 +24,7 @@ | ||
24 | 24 | * \brief Convert binary IML file to plaintext |
25 | 25 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
26 | 26 | * @date 2010-08-25 |
27 | - * cleanup 2011-08-17 SM | |
27 | + * cleanup 2012-01-05 SM | |
28 | 28 | * |
29 | 29 | * show eventlog (get though TSS) |
30 | 30 | * |
@@ -90,7 +90,6 @@ | ||
90 | 90 | #include <openssl/sha.h> |
91 | 91 | |
92 | 92 | #include <openpts.h> |
93 | -// #include <log.h> | |
94 | 93 | |
95 | 94 | #ifdef CONFIG_TBOOT |
96 | 95 | #include <openpts_tboot.h> |
@@ -99,15 +98,9 @@ | ||
99 | 98 | // Local TCSD |
100 | 99 | #define SERVER NULL |
101 | 100 | |
102 | - | |
103 | 101 | // PCR |
104 | 102 | BYTE pcr[24][20]; |
105 | 103 | |
106 | -// Verbose Counter | |
107 | -// 0 no | |
108 | -// -v 1 show event data contents | |
109 | -// -v -v 2 DEBUG | |
110 | - | |
111 | 104 | char *indent = " "; |
112 | 105 | |
113 | 106 | // Check the consistence of IML and PCRs |
@@ -1047,7 +1040,7 @@ void usage(void) { | ||
1047 | 1040 | " -V Verify\n" |
1048 | 1041 | " -D DRTM\n" |
1049 | 1042 | " -E Enable endian conversion (BE->LE or LE->BE)\n" |
1050 | - " -P Show pcrs calculated from the IML" | |
1043 | + " -P Show pcrs calculated from the IML" | |
1051 | 1044 | " -h Show this help message\n" |
1052 | 1045 | "\n")); |
1053 | 1046 | } |
@@ -1296,7 +1289,7 @@ int main(int argc, char *argv[]) { | ||
1296 | 1289 | } |
1297 | 1290 | } |
1298 | 1291 | /* pcrs */ |
1299 | - // PCR-00: 8F BF F3 EC EA 9C 54 C8 D1 C4 2C FE A9 3D 6B F0 1B F3 40 5B | |
1292 | + // PCR-00: 8F BF F3 EC EA 9C 54 C8 D1 C4 2C FE A9 3D 6B F0 1B F3 40 5B | |
1300 | 1293 | if (pcrs == 1) { |
1301 | 1294 | for (i = 0; i < 24; i++) { |
1302 | 1295 | fprintf(fp, "PCR-%02d: ", i); |
@@ -26,7 +26,7 @@ | ||
26 | 26 | * \brief TCG TNC IF-IMV v1.2 R8 |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2010-05-07 |
29 | - * cleanup 2011-08-22 SM | |
29 | + * cleanup 2012-01-05 SM | |
30 | 30 | * |
31 | 31 | * http://www.trustedcomputinggroup.org/resources/tnc_ifimv_specification |
32 | 32 | * http://www.trustedcomputinggroup.org/files/static_page_files/646808C3-1D09-3519-AD2E60765779A42A/TNC_IFIMV_v1_2_r8.pdf |
@@ -51,7 +51,6 @@ | ||
51 | 51 | |
52 | 52 | #include <tncifimv.h> |
53 | 53 | #include <openpts.h> |
54 | -// #include <log.h> | |
55 | 54 | |
56 | 55 | // ifm.c |
57 | 56 | BYTE* getPtsTlvMessage(OPENPTS_CONTEXT *ctx, int type, int *len); |
@@ -64,10 +63,6 @@ static OPENPTS_CONFIG *conf = NULL; | ||
64 | 63 | static OPENPTS_CONTEXT *ctx = NULL; |
65 | 64 | static int result = OPENPTS_RESULT_UNKNOWN; |
66 | 65 | |
67 | -// int verbose = 0; | |
68 | -// int verbose = DEBUG_IFM_FLAG; | |
69 | -// int verbose = DEBUG_FLAG | DEBUG_IFM_FLAG; | |
70 | - | |
71 | 66 | static TNC_Result sendMessage( |
72 | 67 | /*in*/ TNC_IMVID imvID, |
73 | 68 | /*in*/ TNC_ConnectionID connectionID, |
@@ -97,16 +92,6 @@ static TNC_TNCS_SetAttributePointer setAttributePtr; | ||
97 | 92 | static TNC_TNCS_SendMessagePointer sendMessagePtr; |
98 | 93 | |
99 | 94 | |
100 | -/* List of receive message types */ | |
101 | -// static TNC_MessageType messageTypes[] = { | |
102 | -// TNCMESSAGENUM(TNC_VENDORID_TCG, TNC_SUBTYPE_ANY), // generic | |
103 | -// TNCMESSAGENUM(VENDORID, 0), | |
104 | -// TNCMESSAGENUM(VENDORID, 2), | |
105 | -// TNCMESSAGENUM(VENDORID, 4), | |
106 | -// TNCMESSAGENUM(VENDORID, 6), | |
107 | -// TNCMESSAGENUM(VENDORID, 8), | |
108 | -// TNCMESSAGENUM(VENDORID, 10), | |
109 | -// }; | |
110 | 95 | static TNC_MessageType messageTypes[] = { |
111 | 96 | ((TNC_VENDORID_PA_TNC << 8) | TNC_VENDORID_PA_TNC), // TNC generic (Error) |
112 | 97 | // ((TNC_VENDORID_TCG_PEN << 8) | TNC_SUBTYPE_TCG_PTS), // PTS generic |
@@ -114,7 +99,7 @@ static TNC_MessageType messageTypes[] = { | ||
114 | 99 | }; |
115 | 100 | |
116 | 101 | |
117 | -/* IMV Functions */ | |
102 | +/* IMV Functions -------------------------------------------------------------*/ | |
118 | 103 | |
119 | 104 | /** |
120 | 105 | * from IMV spec. |
@@ -26,7 +26,7 @@ | ||
26 | 26 | * \brief Generate Integrity Report from IML |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2010-04-01 |
29 | - * cleanup 2011-07-06 SM | |
29 | + * cleanup 2012-01-05 SM | |
30 | 30 | * |
31 | 31 | * TSS Event Struct -> IR |
32 | 32 | * IML and PCR may not match, since the read them is not an atmic operation |
@@ -44,7 +44,7 @@ | ||
44 | 44 | * |
45 | 45 | * TOCTOU? |
46 | 46 | * |
47 | - * | |
47 | + * TODO refine XML error log | |
48 | 48 | */ |
49 | 49 | |
50 | 50 | #include <sys/stat.h> |
@@ -59,8 +59,8 @@ | ||
59 | 59 | #include <libxml/parser.h> |
60 | 60 | |
61 | 61 | #include <openpts.h> |
62 | -// #include <log.h> | |
63 | 62 | |
63 | +/* XML */ | |
64 | 64 | enum { |
65 | 65 | TEXT_WRITER_START_ELEMENT, |
66 | 66 | TEXT_WRITER_WRITE_ATTR, |
@@ -87,7 +87,7 @@ void displayXmlError(int errorIndex, int rc) { | ||
87 | 87 | |
88 | 88 | /* check */ |
89 | 89 | if (errorIndex >= XML_FUNC_END) { |
90 | - LOG(LOG_ERR, "errorIndex(%d) > XML_FUNC_END(%d)",errorIndex, XML_FUNC_END); | |
90 | + LOG(LOG_ERR, "errorIndex(%d) > XML_FUNC_END(%d)", errorIndex, XML_FUNC_END); | |
91 | 91 | return; |
92 | 92 | } |
93 | 93 |
@@ -114,7 +114,7 @@ int freeAllFsm(OPENPTS_CONTEXT *ctx) { | ||
114 | 114 | } |
115 | 115 | |
116 | 116 | if (ctx->ss_table == NULL) { |
117 | - // DEBUG("resetFsm() - no SS table\n"); | |
117 | + /* no SS table, skip */ | |
118 | 118 | return PTS_SUCCESS; |
119 | 119 | } |
120 | 120 |
@@ -286,7 +286,7 @@ int writeComponentID( | ||
286 | 286 | rc = xmlTextWriterWriteAttribute( |
287 | 287 | writer, |
288 | 288 | BAD_CAST "VersionBuild", |
289 | - BAD_CAST "1250694000000"); // TODO(munetoh) | |
289 | + BAD_CAST "1250694000000"); // TODO(munetoh) | |
290 | 290 | if (rc < 0) { |
291 | 291 | displayXmlError(TEXT_WRITER_WRITE_ATTR, rc); |
292 | 292 | goto error; |
@@ -596,7 +596,6 @@ int writeStuffObjects( | ||
596 | 596 | * @retval PTS_INTERNAL_ERROR |
597 | 597 | * |
598 | 598 | */ |
599 | - | |
600 | 599 | int writePcrHash( |
601 | 600 | xmlTextWriterPtr writer, |
602 | 601 | int pcrIndex, |
@@ -604,7 +603,6 @@ int writePcrHash( | ||
604 | 603 | BYTE * startHash, |
605 | 604 | BYTE * hash, |
606 | 605 | int algtype) { |
607 | - // int rc = PTS_SUCCESS; | |
608 | 606 | char id[256]; // TODO(munetoh) 11+1+1 = 12? |
609 | 607 | int rc; |
610 | 608 |
@@ -953,6 +951,7 @@ int writeQuote( | ||
953 | 951 | /* Start an element named "QuoteData" as child of Report. */ |
954 | 952 | rc = xmlTextWriterStartElement(writer, BAD_CAST "QuoteData"); |
955 | 953 | if (rc < 0) { |
954 | + LOG(LOG_ERR, "xmlX() fail"); | |
956 | 955 | displayXmlError(TEXT_WRITER_START_ELEMENT, rc); |
957 | 956 | return PTS_INTERNAL_ERROR; |
958 | 957 | } |
@@ -960,6 +959,7 @@ int writeQuote( | ||
960 | 959 | /* Add an attribute with name "ID" */ |
961 | 960 | rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "ID", BAD_CAST "TBD"); |
962 | 961 | if (rc < 0) { |
962 | + LOG(LOG_ERR, "xmlX() fail"); | |
963 | 963 | displayXmlError(TEXT_WRITER_WRITE_ATTR, rc); |
964 | 964 | return PTS_INTERNAL_ERROR; |
965 | 965 | } |
@@ -967,6 +967,7 @@ int writeQuote( | ||
967 | 967 | /* Start an element named "Quote" as child of QuoteData. */ |
968 | 968 | rc = xmlTextWriterStartElement(writer, BAD_CAST "Quote"); |
969 | 969 | if (rc < 0) { |
970 | + LOG(LOG_ERR, "xmlX() fail"); | |
970 | 971 | displayXmlError(TEXT_WRITER_START_ELEMENT, rc); |
971 | 972 | return PTS_INTERNAL_ERROR; |
972 | 973 | } |
@@ -974,6 +975,7 @@ int writeQuote( | ||
974 | 975 | /* Start an element named "PcrComposit" as child of Quote. */ |
975 | 976 | rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrComposit"); |
976 | 977 | if (rc < 0) { |
978 | + LOG(LOG_ERR, "xmlX() fail"); | |
977 | 979 | displayXmlError(TEXT_WRITER_START_ELEMENT, rc); |
978 | 980 | return PTS_INTERNAL_ERROR; |
979 | 981 | } |
@@ -1006,6 +1008,7 @@ int writeQuote( | ||
1006 | 1008 | /* Start an element named "PcrSelection" as child of PcrComposit. */ |
1007 | 1009 | rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrSelection"); |
1008 | 1010 | if (rc < 0) { |
1011 | + LOG(LOG_ERR, "xmlX() fail"); | |
1009 | 1012 | displayXmlError(TEXT_WRITER_START_ELEMENT, rc); |
1010 | 1013 | return PTS_INTERNAL_ERROR; |
1011 | 1014 | } |
@@ -1014,6 +1017,7 @@ int writeQuote( | ||
1014 | 1017 | snprintf(tagbuf, sizeof(tagbuf), "%d", size_of_select); |
1015 | 1018 | rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "SizeOfSelect", BAD_CAST tagbuf); |
1016 | 1019 | if (rc < 0) { |
1020 | + LOG(LOG_ERR, "xmlX() fail"); | |
1017 | 1021 | displayXmlError(TEXT_WRITER_WRITE_ATTR, rc); |
1018 | 1022 | return PTS_INTERNAL_ERROR; |
1019 | 1023 | } |
@@ -1029,7 +1033,7 @@ int writeQuote( | ||
1029 | 1033 | } |
1030 | 1034 | rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PcrSelect", BAD_CAST b64buf); |
1031 | 1035 | if (rc < 0) { |
1032 | - // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n"); | |
1036 | + LOG(LOG_ERR, "xmlX() fail"); | |
1033 | 1037 | displayXmlError(TEXT_WRITER_WRITE_ATTR, rc); |
1034 | 1038 | return PTS_INTERNAL_ERROR; |
1035 | 1039 | } |
@@ -1039,7 +1043,7 @@ int writeQuote( | ||
1039 | 1043 | /* Close the element named "PcrSelection". */ |
1040 | 1044 | rc = xmlTextWriterEndElement(writer); |
1041 | 1045 | if (rc < 0) { |
1042 | - // LOG(LOG_ERR, "Error at xmlTextWriterEndElement\n"); | |
1046 | + LOG(LOG_ERR, "xmlX() fail"); | |
1043 | 1047 | displayXmlError(TEXT_WRITER_END_ELEMENT, rc); |
1044 | 1048 | return PTS_INTERNAL_ERROR; |
1045 | 1049 | } |
@@ -1049,6 +1053,7 @@ int writeQuote( | ||
1049 | 1053 | /* Write an element named "ValueSize" as child of PcrComposit */ |
1050 | 1054 | rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ValueSize", "%d", ctx->pcrs->value_size); |
1051 | 1055 | if (rc < 0) { |
1056 | + LOG(LOG_ERR, "xmlX() fail"); | |
1052 | 1057 | displayXmlError(TEXT_WRITER_WRITE_FORMAT_ELEMENT, rc); |
1053 | 1058 | return PTS_INTERNAL_ERROR; |
1054 | 1059 | } |
@@ -1060,6 +1065,7 @@ int writeQuote( | ||
1060 | 1065 | /* Start an element named "PcrValue" as child of PcrComposit. */ |
1061 | 1066 | rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrValue"); |
1062 | 1067 | if (rc < 0) { |
1068 | + LOG(LOG_ERR, "xmlTextWriterStartElement() fail"); | |
1063 | 1069 | displayXmlError(TEXT_WRITER_START_ELEMENT, rc); |
1064 | 1070 | return PTS_INTERNAL_ERROR; |
1065 | 1071 | } |
@@ -1068,6 +1074,7 @@ int writeQuote( | ||
1068 | 1074 | rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PcrNumber", BAD_CAST tagbuf); |
1069 | 1075 | // rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PcrNumber", BAD_CAST "0"); |
1070 | 1076 | if (rc < 0) { |
1077 | + LOG(LOG_ERR, "xmlTextWriterWriteAttribute() fail"); | |
1071 | 1078 | displayXmlError(TEXT_WRITER_WRITE_ATTR, rc); |
1072 | 1079 | return PTS_INTERNAL_ERROR; |
1073 | 1080 | } |
@@ -1079,6 +1086,7 @@ int writeQuote( | ||
1079 | 1086 | 0, |
1080 | 1087 | 20); // TODO add length to OPENPTS_PCRS |
1081 | 1088 | if (rc < 0) { |
1089 | + LOG(LOG_ERR, "xmlTextWriterWriteBase64() fail"); | |
1082 | 1090 | displayXmlError(TEXT_WRITER_WRITE_BASE64, rc); |
1083 | 1091 | return PTS_INTERNAL_ERROR; |
1084 | 1092 | } |
@@ -1086,6 +1094,7 @@ int writeQuote( | ||
1086 | 1094 | /* Close the element named "PcrValue" */ |
1087 | 1095 | rc = xmlTextWriterEndElement(writer); |
1088 | 1096 | if (rc < 0) { |
1097 | + LOG(LOG_ERR, "xmlTextWriterEndElement() fail"); | |
1089 | 1098 | displayXmlError(TEXT_WRITER_END_ELEMENT, rc); |
1090 | 1099 | return PTS_INTERNAL_ERROR; |
1091 | 1100 | } |
@@ -1095,6 +1104,7 @@ int writeQuote( | ||
1095 | 1104 | /* Close the element named "PcrComposit". */ |
1096 | 1105 | rc = xmlTextWriterEndElement(writer); |
1097 | 1106 | if (rc < 0) { |
1107 | + LOG(LOG_ERR, "xmlTextWriterEndElement() fail"); | |
1098 | 1108 | displayXmlError(TEXT_WRITER_END_ELEMENT, rc); |
1099 | 1109 | return PTS_INTERNAL_ERROR; |
1100 | 1110 | } |
@@ -1103,6 +1113,7 @@ int writeQuote( | ||
1103 | 1113 | /* Start an element named "QuoteInfo" as child of Quote. */ |
1104 | 1114 | rc = xmlTextWriterStartElement(writer, BAD_CAST "QuoteInfo"); |
1105 | 1115 | if (rc < 0) { |
1116 | + LOG(LOG_ERR, "xmlTextWriterStartElement() fail"); | |
1106 | 1117 | displayXmlError(TEXT_WRITER_START_ELEMENT, rc); |
1107 | 1118 | return PTS_INTERNAL_ERROR; |
1108 | 1119 | } |
@@ -1111,7 +1122,7 @@ int writeQuote( | ||
1111 | 1122 | snprintf(tagbuf, sizeof(tagbuf), "%d", ctx->validation_data->versionInfo.bMajor); |
1112 | 1123 | rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "VersionMajor", BAD_CAST tagbuf); |
1113 | 1124 | if (rc < 0) { |
1114 | - // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n"); | |
1125 | + LOG(LOG_ERR, "xmlTextWriterWriteAttribute() fail"); | |
1115 | 1126 | displayXmlError(TEXT_WRITER_WRITE_ATTR, rc); |
1116 | 1127 | return PTS_INTERNAL_ERROR; |
1117 | 1128 | } |
@@ -1119,7 +1130,7 @@ int writeQuote( | ||
1119 | 1130 | snprintf(tagbuf, sizeof(tagbuf), "%d", ctx->validation_data->versionInfo.bMinor); |
1120 | 1131 | rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "VersionMinor", BAD_CAST tagbuf); |
1121 | 1132 | if (rc < 0) { |
1122 | - // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n"); | |
1133 | + LOG(LOG_ERR, "xmlX() fail"); | |
1123 | 1134 | displayXmlError(TEXT_WRITER_WRITE_ATTR, rc); |
1124 | 1135 | return PTS_INTERNAL_ERROR; |
1125 | 1136 | } |
@@ -1127,7 +1138,7 @@ int writeQuote( | ||
1127 | 1138 | snprintf(tagbuf, sizeof(tagbuf), "%d", ctx->validation_data->versionInfo.bRevMajor); |
1128 | 1139 | rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "VersionRevMajor", BAD_CAST tagbuf); |
1129 | 1140 | if (rc < 0) { |
1130 | - // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n"); | |
1141 | + LOG(LOG_ERR, "xmlX() fail"); | |
1131 | 1142 | displayXmlError(TEXT_WRITER_WRITE_ATTR, rc); |
1132 | 1143 | return PTS_INTERNAL_ERROR; |
1133 | 1144 | } |
@@ -1136,7 +1147,7 @@ int writeQuote( | ||
1136 | 1147 | snprintf(tagbuf, sizeof(tagbuf), "%d", ctx->validation_data->versionInfo.bRevMinor); |
1137 | 1148 | rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "VersionRevMinor", BAD_CAST tagbuf); |
1138 | 1149 | if (rc < 0) { |
1139 | - // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n"); | |
1150 | + LOG(LOG_ERR, "xmlX() fail"); | |
1140 | 1151 | displayXmlError(TEXT_WRITER_WRITE_ATTR, rc); |
1141 | 1152 | return PTS_INTERNAL_ERROR; |
1142 | 1153 | } |
@@ -1144,7 +1155,7 @@ int writeQuote( | ||
1144 | 1155 | /* Add an attribute with name "Fixed", int */ |
1145 | 1156 | rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "Fixed", BAD_CAST "QUOT"); |
1146 | 1157 | if (rc < 0) { |
1147 | - // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n"); | |
1158 | + LOG(LOG_ERR, "xmlX() fail"); | |
1148 | 1159 | displayXmlError(TEXT_WRITER_WRITE_ATTR, rc); |
1149 | 1160 | return -1; |
1150 | 1161 | } |
@@ -1160,6 +1171,7 @@ int writeQuote( | ||
1160 | 1171 | } |
1161 | 1172 | rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "DigestValue", BAD_CAST b64buf); |
1162 | 1173 | if (rc < 0) { |
1174 | + LOG(LOG_ERR, "xmlX() fail"); | |
1163 | 1175 | displayXmlError(TEXT_WRITER_WRITE_ATTR, rc); |
1164 | 1176 | return PTS_INTERNAL_ERROR; |
1165 | 1177 | } |
@@ -1179,7 +1191,7 @@ int writeQuote( | ||
1179 | 1191 | } |
1180 | 1192 | rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "ExternalData", BAD_CAST b64buf); |
1181 | 1193 | if (rc < 0) { |
1182 | - // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n"); | |
1194 | + LOG(LOG_ERR, "xmlX() fail"); | |
1183 | 1195 | displayXmlError(TEXT_WRITER_WRITE_ATTR, rc); |
1184 | 1196 | return PTS_INTERNAL_ERROR; |
1185 | 1197 | } |
@@ -1189,7 +1201,7 @@ int writeQuote( | ||
1189 | 1201 | /* Close the element named "QuoteInfo". */ |
1190 | 1202 | rc = xmlTextWriterEndElement(writer); |
1191 | 1203 | if (rc < 0) { |
1192 | - // LOG(LOG_ERR, "Error at xmlTextWriterEndElement\n"); | |
1204 | + LOG(LOG_ERR, "xmlX() fail"); | |
1193 | 1205 | displayXmlError(TEXT_WRITER_END_ELEMENT, rc); |
1194 | 1206 | return PTS_INTERNAL_ERROR; |
1195 | 1207 | } |
@@ -1197,7 +1209,7 @@ int writeQuote( | ||
1197 | 1209 | /* Close the element named "Quote". */ |
1198 | 1210 | rc = xmlTextWriterEndElement(writer); |
1199 | 1211 | if (rc < 0) { |
1200 | - // LOG(LOG_ERR, "Error at xmlTextWriterEndElement\n"); | |
1212 | + LOG(LOG_ERR, "xmlX() fail"); | |
1201 | 1213 | displayXmlError(TEXT_WRITER_END_ELEMENT, rc); |
1202 | 1214 | return PTS_INTERNAL_ERROR; |
1203 | 1215 | } |
@@ -1207,6 +1219,7 @@ int writeQuote( | ||
1207 | 1219 | /* Start an element named "TpmSignature" as child of QuoteData. */ |
1208 | 1220 | rc = xmlTextWriterStartElement(writer, BAD_CAST "TpmSignature"); |
1209 | 1221 | if (rc < 0) { |
1222 | + LOG(LOG_ERR, "xmlX() fail"); | |
1210 | 1223 | displayXmlError(TEXT_WRITER_START_ELEMENT, rc); |
1211 | 1224 | return PTS_INTERNAL_ERROR; |
1212 | 1225 | } |
@@ -1216,6 +1229,7 @@ int writeQuote( | ||
1216 | 1229 | /* Start an element named "SignatureMethod" as child of TpmSignature. */ |
1217 | 1230 | rc = xmlTextWriterStartElement(writer, BAD_CAST "SignatureMethod"); |
1218 | 1231 | if (rc < 0) { |
1232 | + LOG(LOG_ERR, "xmlX() fail"); | |
1219 | 1233 | displayXmlError(TEXT_WRITER_START_ELEMENT, rc); |
1220 | 1234 | return PTS_INTERNAL_ERROR; |
1221 | 1235 | } |
@@ -1224,6 +1238,7 @@ int writeQuote( | ||
1224 | 1238 | BAD_CAST "Algorithm", |
1225 | 1239 | BAD_CAST "http://www.w3.org/2000/09/xmldsig#rsa-sha1"); // TODO |
1226 | 1240 | if (rc < 0) { |
1241 | + LOG(LOG_ERR, "xmlX() fail"); | |
1227 | 1242 | displayXmlError(TEXT_WRITER_WRITE_ATTR, rc); |
1228 | 1243 | return PTS_INTERNAL_ERROR; |
1229 | 1244 | } |
@@ -1381,6 +1396,7 @@ int writeQuote2( | ||
1381 | 1396 | snprintf(tagbuf, sizeof(tagbuf), "%d", tag); |
1382 | 1397 | rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "Tag", BAD_CAST tagbuf); |
1383 | 1398 | if (rc < 0) { |
1399 | + LOG(LOG_ERR, "xmlX() fail"); | |
1384 | 1400 | displayXmlError(TEXT_WRITER_WRITE_ATTR, rc); |
1385 | 1401 | return PTS_INTERNAL_ERROR; |
1386 | 1402 | } |
@@ -1388,6 +1404,7 @@ int writeQuote2( | ||
1388 | 1404 | DEBUG("fixed : %s", fixed); |
1389 | 1405 | rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "Fixed", BAD_CAST fixed); |
1390 | 1406 | if (rc < 0) { |
1407 | + LOG(LOG_ERR, "xmlX() fail"); | |
1391 | 1408 | displayXmlError(TEXT_WRITER_WRITE_ATTR, rc); |
1392 | 1409 | return PTS_INTERNAL_ERROR; |
1393 | 1410 | } |
@@ -1403,7 +1420,7 @@ int writeQuote2( | ||
1403 | 1420 | rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "ExternalData", BAD_CAST b64buf); |
1404 | 1421 | free(b64buf); |
1405 | 1422 | if (rc < 0) { |
1406 | - // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n"); | |
1423 | + LOG(LOG_ERR, "xmlX() fail"); | |
1407 | 1424 | displayXmlError(TEXT_WRITER_WRITE_ATTR, rc); |
1408 | 1425 | return PTS_INTERNAL_ERROR; |
1409 | 1426 | } |
@@ -1411,7 +1428,7 @@ int writeQuote2( | ||
1411 | 1428 | /* PcrInfoShort - start */ |
1412 | 1429 | rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrInfoShort"); |
1413 | 1430 | if (rc < 0) { |
1414 | - // LOG(LOG_ERR, "Error at xmlTextWriterStartElement\n"); | |
1431 | + LOG(LOG_ERR, "xmlX() fail"); | |
1415 | 1432 | displayXmlError(TEXT_WRITER_START_ELEMENT, rc); |
1416 | 1433 | return PTS_INTERNAL_ERROR; |
1417 | 1434 | } |
@@ -1419,7 +1436,7 @@ int writeQuote2( | ||
1419 | 1436 | /* PcrSelection - start */ |
1420 | 1437 | rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrSelection"); |
1421 | 1438 | if (rc < 0) { |
1422 | - // LOG(LOG_ERR, "Error at xmlTextWriterStartElement\n"); | |
1439 | + LOG(LOG_ERR, "xmlX() fail"); | |
1423 | 1440 | displayXmlError(TEXT_WRITER_START_ELEMENT, rc); |
1424 | 1441 | return PTS_INTERNAL_ERROR; |
1425 | 1442 | } |
@@ -1427,7 +1444,7 @@ int writeQuote2( | ||
1427 | 1444 | snprintf(tagbuf, sizeof(tagbuf), "%d", size_of_select); |
1428 | 1445 | rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "SizeOfSelect", BAD_CAST tagbuf); |
1429 | 1446 | if (rc < 0) { |
1430 | - // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n"); | |
1447 | + LOG(LOG_ERR, "xmlX() fail"); | |
1431 | 1448 | displayXmlError(TEXT_WRITER_WRITE_ATTR, rc); |
1432 | 1449 | return PTS_INTERNAL_ERROR; |
1433 | 1450 | } |
@@ -1443,12 +1460,14 @@ int writeQuote2( | ||
1443 | 1460 | rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PcrSelect", BAD_CAST b64buf); |
1444 | 1461 | free(b64buf); |
1445 | 1462 | if (rc < 0) { |
1463 | + LOG(LOG_ERR, "xmlX() fail"); | |
1446 | 1464 | displayXmlError(TEXT_WRITER_WRITE_ATTR, rc); |
1447 | 1465 | return PTS_INTERNAL_ERROR; |
1448 | 1466 | } |
1449 | 1467 | /* PcrSelection - end */ |
1450 | 1468 | rc = xmlTextWriterEndElement(writer); |
1451 | 1469 | if (rc < 0) { |
1470 | + LOG(LOG_ERR, "xmlX() fail"); | |
1452 | 1471 | displayXmlError(TEXT_WRITER_END_ELEMENT, rc); |
1453 | 1472 | return PTS_INTERNAL_ERROR; |
1454 | 1473 | } |
@@ -1457,6 +1476,7 @@ int writeQuote2( | ||
1457 | 1476 | /* LocalityAtRelease - element */ |
1458 | 1477 | rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "LocalityAtRelease", "%d", locality); |
1459 | 1478 | if (rc < 0) { |
1479 | + LOG(LOG_ERR, "xmlX() fail"); | |
1460 | 1480 | displayXmlError(TEXT_WRITER_WRITE_FORMAT_ELEMENT, rc); |
1461 | 1481 | return PTS_INTERNAL_ERROR; |
1462 | 1482 | } |
@@ -1473,6 +1493,7 @@ int writeQuote2( | ||
1473 | 1493 | rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "CompositeHash", "%s", b64buf); |
1474 | 1494 | free(b64buf); |
1475 | 1495 | if (rc < 0) { |
1496 | + LOG(LOG_ERR, "xmlX() fail"); | |
1476 | 1497 | displayXmlError(TEXT_WRITER_WRITE_FORMAT_ELEMENT, rc); |
1477 | 1498 | return PTS_INTERNAL_ERROR; |
1478 | 1499 | } |
@@ -1481,7 +1502,7 @@ int writeQuote2( | ||
1481 | 1502 | /* PcrComposite - start */ |
1482 | 1503 | rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrComposit"); |
1483 | 1504 | if (rc < 0) { |
1484 | - // LOG(LOG_ERR, "Error at xmlTextWriterStartElement\n"); | |
1505 | + LOG(LOG_ERR, "xmlX() fail"); | |
1485 | 1506 | displayXmlError(TEXT_WRITER_START_ELEMENT, rc); |
1486 | 1507 | return PTS_INTERNAL_ERROR; |
1487 | 1508 | } |
@@ -1489,7 +1510,7 @@ int writeQuote2( | ||
1489 | 1510 | /* PcrSelection - start */ |
1490 | 1511 | rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrSelection"); |
1491 | 1512 | if (rc < 0) { |
1492 | - // LOG(LOG_ERR, "Error at xmlTextWriterStartElement\n"); | |
1513 | + LOG(LOG_ERR, "xmlX() fail"); | |
1493 | 1514 | displayXmlError(TEXT_WRITER_START_ELEMENT, rc); |
1494 | 1515 | return PTS_INTERNAL_ERROR; |
1495 | 1516 | } |
@@ -1497,7 +1518,7 @@ int writeQuote2( | ||
1497 | 1518 | snprintf(tagbuf, sizeof(tagbuf), "%d", size_of_select); |
1498 | 1519 | rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "SizeOfSelect", BAD_CAST tagbuf); |
1499 | 1520 | if (rc < 0) { |
1500 | - // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n"); | |
1521 | + LOG(LOG_ERR, "xmlX() fail"); | |
1501 | 1522 | displayXmlError(TEXT_WRITER_WRITE_ATTR, rc); |
1502 | 1523 | return PTS_INTERNAL_ERROR; |
1503 | 1524 | } |
@@ -1513,19 +1534,22 @@ int writeQuote2( | ||
1513 | 1534 | rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PcrSelect", BAD_CAST b64buf); |
1514 | 1535 | free(b64buf); |
1515 | 1536 | if (rc < 0) { |
1537 | + LOG(LOG_ERR, "xmlX() fail"); | |
1516 | 1538 | displayXmlError(TEXT_WRITER_WRITE_ATTR, rc); |
1517 | 1539 | return PTS_INTERNAL_ERROR; |
1518 | 1540 | } |
1519 | 1541 | /* PcrSelection - end */ |
1520 | 1542 | rc = xmlTextWriterEndElement(writer); |
1521 | 1543 | if (rc < 0) { |
1544 | + LOG(LOG_ERR, "xmlX() fail"); | |
1522 | 1545 | displayXmlError(TEXT_WRITER_END_ELEMENT, rc); |
1523 | 1546 | return PTS_INTERNAL_ERROR; |
1524 | 1547 | } |
1525 | 1548 | /* ValueSize - element */ |
1526 | 1549 | rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ValueSize", "%d", ctx->pcrs->value_size); |
1527 | 1550 | if (rc < 0) { |
1528 | - displayXmlError(TEXT_WRITER_WRITE_FORMAT_ELEMENT, rc); | |
1551 | + LOG(LOG_ERR, "xmlX() fail"); | |
1552 | + displayXmlError(TEXT_WRITER_WRITE_FORMAT_ELEMENT, rc); | |
1529 | 1553 | return PTS_INTERNAL_ERROR; |
1530 | 1554 | } |
1531 | 1555 | /* PcrValue, loop */ |
@@ -1534,7 +1558,7 @@ int writeQuote2( | ||
1534 | 1558 | /* PcrValue - start */ |
1535 | 1559 | rc = xmlTextWriterStartElement(writer, BAD_CAST "PcrValue"); |
1536 | 1560 | if (rc < 0) { |
1537 | - // LOG(LOG_ERR, "Error at xmlTextWriterStartElement\n"); | |
1561 | + LOG(LOG_ERR, "xmlX() fail"); | |
1538 | 1562 | displayXmlError(TEXT_WRITER_START_ELEMENT, rc); |
1539 | 1563 | return PTS_INTERNAL_ERROR; |
1540 | 1564 | } |
@@ -1542,7 +1566,7 @@ int writeQuote2( | ||
1542 | 1566 | snprintf(tagbuf, sizeof(tagbuf), "%d", i); |
1543 | 1567 | rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "PcrNumber", BAD_CAST tagbuf); |
1544 | 1568 | if (rc < 0) { |
1545 | - // LOG(LOG_ERR, "Error at xmlTextWriterWriteAttribute\n"); | |
1569 | + LOG(LOG_ERR, "xmlX() fail"); | |
1546 | 1570 | displayXmlError(TEXT_WRITER_WRITE_ATTR, rc); |
1547 | 1571 | return PTS_INTERNAL_ERROR; |
1548 | 1572 | } |
@@ -1555,6 +1579,7 @@ int writeQuote2( | ||
1555 | 1579 | 0, |
1556 | 1580 | 20); // TODO add length to OPENPTS_PCRS |
1557 | 1581 | if (rc < 0) { |
1582 | + LOG(LOG_ERR, "xmlX() fail"); | |
1558 | 1583 | displayXmlError(TEXT_WRITER_WRITE_BASE64, rc); |
1559 | 1584 | return PTS_INTERNAL_ERROR; |
1560 | 1585 | } |
@@ -1562,6 +1587,7 @@ int writeQuote2( | ||
1562 | 1587 | /* PcrValue - end */ |
1563 | 1588 | rc = xmlTextWriterEndElement(writer); |
1564 | 1589 | if (rc < 0) { |
1590 | + LOG(LOG_ERR, "xmlX() fail"); | |
1565 | 1591 | displayXmlError(TEXT_WRITER_END_ELEMENT, rc); |
1566 | 1592 | return PTS_INTERNAL_ERROR; |
1567 | 1593 | } |
@@ -1570,6 +1596,7 @@ int writeQuote2( | ||
1570 | 1596 | /* PcrComposite - end */ |
1571 | 1597 | rc = xmlTextWriterEndElement(writer); |
1572 | 1598 | if (rc < 0) { |
1599 | + LOG(LOG_ERR, "xmlX() fail"); | |
1573 | 1600 | displayXmlError(TEXT_WRITER_END_ELEMENT, rc); |
1574 | 1601 | return PTS_INTERNAL_ERROR; |
1575 | 1602 | } |
@@ -1577,6 +1604,7 @@ int writeQuote2( | ||
1577 | 1604 | /* PcrInfoShort - end */ |
1578 | 1605 | rc = xmlTextWriterEndElement(writer); |
1579 | 1606 | if (rc < 0) { |
1607 | + LOG(LOG_ERR, "xmlX() fail"); | |
1580 | 1608 | displayXmlError(TEXT_WRITER_END_ELEMENT, rc); |
1581 | 1609 | return PTS_INTERNAL_ERROR; |
1582 | 1610 | } |
@@ -1584,6 +1612,7 @@ int writeQuote2( | ||
1584 | 1612 | /* QuoteInfo2 - end */ |
1585 | 1613 | rc = xmlTextWriterEndElement(writer); |
1586 | 1614 | if (rc < 0) { |
1615 | + LOG(LOG_ERR, "xmlX() fail"); | |
1587 | 1616 | displayXmlError(TEXT_WRITER_END_ELEMENT, rc); |
1588 | 1617 | return PTS_INTERNAL_ERROR; |
1589 | 1618 | } |
@@ -1591,6 +1620,7 @@ int writeQuote2( | ||
1591 | 1620 | /* Quote2 - end */ |
1592 | 1621 | rc = xmlTextWriterEndElement(writer); |
1593 | 1622 | if (rc < 0) { |
1623 | + LOG(LOG_ERR, "xmlX() fail"); | |
1594 | 1624 | displayXmlError(TEXT_WRITER_END_ELEMENT, rc); |
1595 | 1625 | return PTS_INTERNAL_ERROR; |
1596 | 1626 | } |
@@ -1600,6 +1630,7 @@ int writeQuote2( | ||
1600 | 1630 | /* Start an element named "TpmSignature" as child of QuoteData. */ |
1601 | 1631 | rc = xmlTextWriterStartElement(writer, BAD_CAST "TpmSignature"); |
1602 | 1632 | if (rc < 0) { |
1633 | + LOG(LOG_ERR, "xmlX() fail"); | |
1603 | 1634 | displayXmlError(TEXT_WRITER_START_ELEMENT, rc); |
1604 | 1635 | return PTS_INTERNAL_ERROR; |
1605 | 1636 | } |
@@ -1609,6 +1640,7 @@ int writeQuote2( | ||
1609 | 1640 | /* Start an element named "SignatureMethod" as child of TpmSignature. */ |
1610 | 1641 | rc = xmlTextWriterStartElement(writer, BAD_CAST "SignatureMethod"); |
1611 | 1642 | if (rc < 0) { |
1643 | + LOG(LOG_ERR, "xmlX() fail"); | |
1612 | 1644 | displayXmlError(TEXT_WRITER_START_ELEMENT, rc); |
1613 | 1645 | return PTS_INTERNAL_ERROR; |
1614 | 1646 | } |
@@ -1617,12 +1649,14 @@ int writeQuote2( | ||
1617 | 1649 | BAD_CAST "Algorithm", |
1618 | 1650 | BAD_CAST "http://www.w3.org/2000/09/xmldsig#rsa-sha1"); // TODO |
1619 | 1651 | if (rc < 0) { |
1652 | + LOG(LOG_ERR, "xmlX() fail"); | |
1620 | 1653 | displayXmlError(TEXT_WRITER_WRITE_ATTR, rc); |
1621 | 1654 | return PTS_INTERNAL_ERROR; |
1622 | 1655 | } |
1623 | 1656 | /* Close the element named "SignatureMethod". */ |
1624 | 1657 | rc = xmlTextWriterEndElement(writer); |
1625 | 1658 | if (rc < 0) { |
1659 | + LOG(LOG_ERR, "xmlX() fail"); | |
1626 | 1660 | displayXmlError(TEXT_WRITER_END_ELEMENT, rc); |
1627 | 1661 | return PTS_INTERNAL_ERROR; |
1628 | 1662 | } |
@@ -1632,6 +1666,7 @@ int writeQuote2( | ||
1632 | 1666 | /* Start an element named "SignatureValue" as child of TpmSignature. */ |
1633 | 1667 | rc = xmlTextWriterStartElement(writer, BAD_CAST "SignatureValue"); |
1634 | 1668 | if (rc < 0) { |
1669 | + LOG(LOG_ERR, "xmlX() fail"); | |
1635 | 1670 | displayXmlError(TEXT_WRITER_START_ELEMENT, rc); |
1636 | 1671 | return PTS_INTERNAL_ERROR; |
1637 | 1672 | } |
@@ -1642,12 +1677,14 @@ int writeQuote2( | ||
1642 | 1677 | 0, |
1643 | 1678 | ctx->validation_data->ulValidationDataLength); |
1644 | 1679 | if (rc < 0) { |
1680 | + LOG(LOG_ERR, "xmlX() fail"); | |
1645 | 1681 | displayXmlError(TEXT_WRITER_WRITE_BASE64, rc); |
1646 | 1682 | return PTS_INTERNAL_ERROR; |
1647 | 1683 | } |
1648 | 1684 | /* Close the element named "SignatureValue". */ |
1649 | 1685 | rc = xmlTextWriterEndElement(writer); |
1650 | 1686 | if (rc < 0) { |
1687 | + LOG(LOG_ERR, "xmlX() fail"); | |
1651 | 1688 | displayXmlError(TEXT_WRITER_END_ELEMENT, rc); |
1652 | 1689 | return PTS_INTERNAL_ERROR; |
1653 | 1690 | } |
@@ -1655,6 +1692,7 @@ int writeQuote2( | ||
1655 | 1692 | /* Close the element named "TpmSignature". */ |
1656 | 1693 | rc = xmlTextWriterEndElement(writer); |
1657 | 1694 | if (rc < 0) { |
1695 | + LOG(LOG_ERR, "xmlX() fail"); | |
1658 | 1696 | displayXmlError(TEXT_WRITER_END_ELEMENT, rc); |
1659 | 1697 | return PTS_INTERNAL_ERROR; |
1660 | 1698 | } |
@@ -1662,6 +1700,7 @@ int writeQuote2( | ||
1662 | 1700 | /* Close the element named "QuoteData". */ |
1663 | 1701 | rc = xmlTextWriterEndElement(writer); |
1664 | 1702 | if (rc < 0) { |
1703 | + LOG(LOG_ERR, "xmlX() fail"); | |
1665 | 1704 | displayXmlError(TEXT_WRITER_END_ELEMENT, rc); |
1666 | 1705 | return PTS_INTERNAL_ERROR; |
1667 | 1706 | } |
@@ -1689,8 +1728,8 @@ int writeQuote2( | ||
1689 | 1728 | int writeIr( |
1690 | 1729 | OPENPTS_CONTEXT *ctx, |
1691 | 1730 | const char *filenameDP, // in (set ctx->conf->ir_filename in normal operation) |
1692 | - int *savedFd) // out | |
1693 | -{ | |
1731 | + int *savedFd) { // out | |
1732 | + | |
1694 | 1733 | int rc = PTS_SUCCESS; |
1695 | 1734 | int i; |
1696 | 1735 | int irFd; |
@@ -1778,6 +1817,7 @@ int writeIr( | ||
1778 | 1817 | /* Start the document */ |
1779 | 1818 | rc = xmlTextWriterStartDocument(writer, "1.0", XML_ENCODING, "no"); |
1780 | 1819 | if (rc < 0) { |
1820 | + LOG(LOG_ERR, "xmlX() fail"); | |
1781 | 1821 | displayXmlError(TEXT_WRITER_START_DOC, rc); |
1782 | 1822 | rc = PTS_INTERNAL_ERROR; |
1783 | 1823 | goto freexml; |
@@ -1786,6 +1826,7 @@ int writeIr( | ||
1786 | 1826 | /* Start an element named "Report", the root element of the document. */ |
1787 | 1827 | rc = xmlTextWriterStartElement(writer, BAD_CAST "Report"); |
1788 | 1828 | if (rc < 0) { |
1829 | + LOG(LOG_ERR, "xmlX() fail"); | |
1789 | 1830 | displayXmlError(TEXT_WRITER_START_ELEMENT, rc); |
1790 | 1831 | rc = PTS_INTERNAL_ERROR; |
1791 | 1832 | goto freexml; |
@@ -1799,6 +1840,7 @@ int writeIr( | ||
1799 | 1840 | BAD_CAST "xmlns:core", |
1800 | 1841 | BAD_CAST XMLNS_CORE); |
1801 | 1842 | if (rc < 0) { |
1843 | + LOG(LOG_ERR, "xmlX() fail"); | |
1802 | 1844 | displayXmlError(TEXT_WRITER_WRITE_ATTR, rc); |
1803 | 1845 | rc = PTS_INTERNAL_ERROR; |
1804 | 1846 | goto freexml; |
@@ -1809,6 +1851,7 @@ int writeIr( | ||
1809 | 1851 | BAD_CAST "xmlns:stuff", |
1810 | 1852 | BAD_CAST XMLNS_STUFF); |
1811 | 1853 | if (rc < 0) { |
1854 | + LOG(LOG_ERR, "xmlX() fail"); | |
1812 | 1855 | displayXmlError(TEXT_WRITER_WRITE_ATTR, rc); |
1813 | 1856 | rc = PTS_INTERNAL_ERROR; |
1814 | 1857 | goto freexml; |
@@ -1820,6 +1863,7 @@ int writeIr( | ||
1820 | 1863 | BAD_CAST "xmlns:xsi", |
1821 | 1864 | BAD_CAST "http://www.w3.org/2001/XMLSchema-instance"); |
1822 | 1865 | if (rc < 0) { |
1866 | + LOG(LOG_ERR, "xmlX() fail"); | |
1823 | 1867 | displayXmlError(TEXT_WRITER_WRITE_ATTR, rc); |
1824 | 1868 | rc = PTS_INTERNAL_ERROR; |
1825 | 1869 | goto freexml; |
@@ -1830,6 +1874,7 @@ int writeIr( | ||
1830 | 1874 | BAD_CAST "xmlns", |
1831 | 1875 | BAD_CAST XMLNS_IR); |
1832 | 1876 | if (rc < 0) { |
1877 | + LOG(LOG_ERR, "xmlX() fail"); | |
1833 | 1878 | displayXmlError(TEXT_WRITER_WRITE_ATTR, rc); |
1834 | 1879 | rc = PTS_INTERNAL_ERROR; |
1835 | 1880 | goto freexml; |
@@ -1856,6 +1901,7 @@ int writeIr( | ||
1856 | 1901 | |
1857 | 1902 | rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "ID", BAD_CAST id); |
1858 | 1903 | if (rc < 0) { |
1904 | + LOG(LOG_ERR, "xmlX() fail"); | |
1859 | 1905 | displayXmlError(TEXT_WRITER_WRITE_ATTR, rc); |
1860 | 1906 | rc = PTS_INTERNAL_ERROR; |
1861 | 1907 | goto free; |
@@ -1973,8 +2019,7 @@ int writeIr( | ||
1973 | 2019 | filenameDP = ctx->ir_filename; |
1974 | 2020 | } |
1975 | 2021 | |
1976 | - //filename = ctx->ir_filename; | |
1977 | - DEBUG("Write Integrity Report (IR) : %s\n", filenameDP); //filename); | |
2022 | + DEBUG("Write Integrity Report (IR) : %s\n", filenameDP); | |
1978 | 2023 | |
1979 | 2024 | /* write to file */ |
1980 | 2025 | xmlFreeTextWriter(writer); |
@@ -2872,10 +2917,10 @@ void irCharacters(void* ctx, const xmlChar * ch, int len) { | ||
2872 | 2917 | LOG(LOG_ERR, "null input"); |
2873 | 2918 | return; |
2874 | 2919 | } |
2875 | - //if (ch == NULL) { | |
2876 | - // LOG(LOG_ERR, "null input"); | |
2877 | - // return; | |
2878 | - //} | |
2920 | + if ((len > 0) && (ch == NULL)) { | |
2921 | + LOG(LOG_ERR, "null input"); | |
2922 | + return; | |
2923 | + } | |
2879 | 2924 | |
2880 | 2925 | |
2881 | 2926 | /* copy to buf at ir_ctx, but check length first, ensuring additional space |
@@ -3348,12 +3393,9 @@ int genIrFromTss( | ||
3348 | 3393 | if (ctx->conf->ir_filename != NULL) { |
3349 | 3394 | LOG(LOG_ERR, "Redefining the IR file location %s", ctx->conf->ir_filename); |
3350 | 3395 | } |
3351 | - //ctx->conf->ir_filename = tempnam(NULL, "ir_"); | |
3352 | - //DEBUG("ctx->conf->ir_filename : %s\n", ctx->conf->ir_filename); | |
3353 | 3396 | |
3354 | 3397 | /* save IR (new file in tmp dir) */ |
3355 | 3398 | rc = writeIr(ctx, NULL, savedFd); |
3356 | - // rc = writeIr(ctx, ctx->ir_filename, savedFd); // ir.c | |
3357 | 3399 | if (rc != 0) { |
3358 | 3400 | LOG(LOG_ERR, "fail to write IR, rc = %d\n", rc); |
3359 | 3401 | return PTS_INTERNAL_ERROR; |
@@ -24,7 +24,7 @@ | ||
24 | 24 | * \brief Convert IR file to plaintext (or binary) |
25 | 25 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
26 | 26 | * @date 2010-12-01 |
27 | - * cleanup 2011-01-22 SM | |
27 | + * cleanup 2012-01-05 SM | |
28 | 28 | * |
29 | 29 | * IR(XML) -> SAX -> ctx->snapshot -> print |
30 | 30 | * |
@@ -61,7 +61,6 @@ | ||
61 | 61 | #define SHA1_DIGEST_SIZE 20 |
62 | 62 | BYTE pcr[MAX_PCRNUM][SHA1_DIGEST_SIZE]; |
63 | 63 | |
64 | - | |
65 | 64 | /* Element tag */ |
66 | 65 | #define IR_SAX_STATE_IDOL 0 |
67 | 66 | #define IR_SAX_STATE_PCR_INDEX 1 |
@@ -75,7 +74,6 @@ typedef struct { | ||
75 | 74 | int sax_state; |
76 | 75 | int sax_error; |
77 | 76 | int char_size; |
78 | - // char buf[EVENTDATA_BUF_SIZE]; // TODO(munetoh) fixed buffer | |
79 | 77 | char *buf; /**< buffer for the text element */ |
80 | 78 | /* IML -> FSM */ |
81 | 79 | int event_index; |
@@ -520,7 +518,7 @@ void irEndElement(void * context, const xmlChar * name) { | ||
520 | 518 | DEBUG("ignore QuoteData\n"); |
521 | 519 | } else { |
522 | 520 | /* Else? */ |
523 | - DEBUG("END ELEMENT [%s] ",name); | |
521 | + DEBUG("END ELEMENT [%s] ", name); | |
524 | 522 | } |
525 | 523 | |
526 | 524 | ctx->sax_state = IR_SAX_STATE_IDOL; |
@@ -722,7 +720,3 @@ int main(int argc, char *argv[]) { | ||
722 | 720 | } |
723 | 721 | return rc; |
724 | 722 | } |
725 | - | |
726 | - | |
727 | - | |
728 | - |
@@ -26,8 +26,8 @@ | ||
26 | 26 | * \brief misc functions |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2010-09-08 |
29 | - * cleanup 2011-07-06 SM | |
30 | - * | |
29 | + * cleanup 2012-01-05 SM (remains one lint error) | |
30 | + * src/misc.c:448: If you can, use sizeof(ptr) instead of 3 as the 2nd arg to snprintf. [runtime/printf] [3] | |
31 | 31 | */ |
32 | 32 | |
33 | 33 | #include <stdio.h> |
@@ -66,9 +66,8 @@ void *xmalloc(size_t size) { | ||
66 | 66 | char *result = malloc(size); |
67 | 67 | if (NULL == result) { |
68 | 68 | LOG(LOG_ERR, "Failed to allocate %d bytes of memory\n", size); |
69 | - // if ( size > 0 ) { | |
70 | - // LOG(LOG_ERR, "malloc"); | |
71 | - // } | |
69 | + ERROR(NLS(MS_OPENPTS, OPENPTS_MALLOC_FAIL, | |
70 | + "No memory\n")); | |
72 | 71 | } |
73 | 72 | return result; |
74 | 73 | } |
@@ -78,7 +77,8 @@ void *xmalloc_assert(size_t size) { | ||
78 | 77 | char *result = malloc(size); |
79 | 78 | if (NULL == result) { |
80 | 79 | LOG(LOG_ERR, "Failed to allocate %d bytes of memory\n", size); |
81 | - OUTPUT("About to return NULL pointer - cannot continue\n"); | |
80 | + ERROR(NLS(MS_OPENPTS, OPENPTS_ABORT, | |
81 | + "Abort to return NULL pointer - cannot continue\n")); | |
82 | 82 | exit(1); |
83 | 83 | } |
84 | 84 | return result; |
@@ -133,7 +133,8 @@ char *smalloc_assert(char *str) { | ||
133 | 133 | out = strdup(str); |
134 | 134 | if (NULL == out) { |
135 | 135 | LOG(LOG_ERR, "Failed to duplicate string '%s'\n", str); |
136 | - OUTPUT("About to return NULL pointer - cannot continue\n"); | |
136 | + ERROR(NLS(MS_OPENPTS, OPENPTS_ABORT, | |
137 | + "Abort to return NULL pointer - cannot continue\n")); | |
137 | 138 | exit(1); |
138 | 139 | } |
139 | 140 |
@@ -184,7 +185,6 @@ char *snmalloc(char *str, int len) { | ||
184 | 185 | * @param len |
185 | 186 | */ |
186 | 187 | BYTE *snmalloc2(BYTE *buf, int offset, int len) { |
187 | - | |
188 | 188 | /* check */ |
189 | 189 | if (buf == NULL) { |
190 | 190 | LOG(LOG_ERR, "null input"); |
@@ -216,6 +216,13 @@ BYTE *snmalloc2(BYTE *buf, int offset, int len) { | ||
216 | 216 | * free string buffer |
217 | 217 | */ |
218 | 218 | void sfree(char *str) { |
219 | + /* check */ | |
220 | + if (str == NULL) { | |
221 | + LOG(LOG_ERR, "null input"); | |
222 | + return; | |
223 | + } | |
224 | + | |
225 | + /* free*/ | |
219 | 226 | xfree(str); |
220 | 227 | } |
221 | 228 |
@@ -353,7 +360,7 @@ char *getFullpathDir(char *filename) { | ||
353 | 360 | } |
354 | 361 | } |
355 | 362 | |
356 | - fullpath = xmalloc_assert(i+2); | |
363 | + fullpath = xmalloc_assert(i+2); // check/abort | |
357 | 364 | memcpy(fullpath, filename, i+1); |
358 | 365 | fullpath[i+1] = 0; |
359 | 366 | return fullpath; |
@@ -442,7 +449,7 @@ char *getHexString(BYTE *bin, int size) { | ||
442 | 449 | return NULL; |
443 | 450 | } |
444 | 451 | |
445 | - buf = xmalloc_assert(size * 2 + 1); | |
452 | + buf = xmalloc_assert(size * 2 + 1); // check/abort | |
446 | 453 | ptr = buf; |
447 | 454 | for (i = 0; i < size; i++) { |
448 | 455 | // len = snprintf(ptr, sizeof(ptr), "%02x", bin[i]); |
@@ -26,7 +26,7 @@ | ||
26 | 26 | * \brief calc D-H nonce |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2010-08-19 |
29 | - * cleanup 2011-01-22 SM | |
29 | + * cleanup 2012-01-05 SM | |
30 | 30 | * |
31 | 31 | * PTS IF-M DH-Nonce protocol |
32 | 32 | * |
@@ -233,7 +233,6 @@ int calcExternalDataValue(OPENPTS_NONCE *ctx) { | ||
233 | 233 | SHA_CTX sha_ctx; |
234 | 234 | char c = '1'; |
235 | 235 | |
236 | - // DEBUG("calcExternalDataValue\n"); | |
237 | 236 | /* check */ |
238 | 237 | if (ctx == NULL) { |
239 | 238 | LOG(LOG_ERR, "null input"); |
@@ -279,8 +278,6 @@ int getDhResponce(OPENPTS_NONCE *ctx) { | ||
279 | 278 | PTS_IF_M_DH_Nonce_Parameters_Request *req; |
280 | 279 | PTS_IF_M_DH_Nonce_Parameters_Responce *res; |
281 | 280 | |
282 | - // DEBUG("getDhResponce at Respondor\n"); | |
283 | - | |
284 | 281 | /* check */ |
285 | 282 | if (ctx == NULL) { |
286 | 283 | LOG(LOG_ERR, "null input"); |
@@ -566,10 +563,6 @@ int calcDhFin(OPENPTS_NONCE *ctx) { | ||
566 | 563 | BIGNUM *pub_key; |
567 | 564 | PTS_IF_M_DH_Nonce_Finish *fin; |
568 | 565 | |
569 | - // DEBUG("calcDhFin at Respondor\n"); | |
570 | - // printHex("fin->dh_initiator_nonce :",fin->dh_initiator_nonce,fin->nonce_length,"\n"); | |
571 | - // printHex("fin->dh_initiator_public:",fin->dh_initiator_public,ctx->pubkey_length,"\n"); | |
572 | - | |
573 | 566 | /* check */ |
574 | 567 | if (ctx == NULL) { |
575 | 568 | LOG(LOG_ERR, "null input"); |
@@ -26,12 +26,10 @@ | ||
26 | 26 | * \brief main of openpts command |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2010-07-25 |
29 | - * cleanup 2011-07-20 SM | |
29 | + * cleanup 2012-01-04 SM | |
30 | 30 | * |
31 | 31 | * This is verifier and utility to maintain the collector/verifier |
32 | 32 | * |
33 | - * | |
34 | - * | |
35 | 33 | */ |
36 | 34 | |
37 | 35 | #include <stdio.h> |
@@ -56,7 +54,6 @@ | ||
56 | 54 | // verifier.c |
57 | 55 | void global_lock(int type); |
58 | 56 | int getDefaultConfigfile(OPENPTS_CONFIG *conf); |
59 | -// log.c | |
60 | 57 | |
61 | 58 | /* Well defined return values that can be interpreted by the GUI */ |
62 | 59 | #define RETVAL_OK_TRUSTED 0 |
@@ -68,7 +65,6 @@ int getDefaultConfigfile(OPENPTS_CONFIG *conf); | ||
68 | 65 | #define RETVAL_OK_PENDINGUPDATE 5 |
69 | 66 | #endif |
70 | 67 | |
71 | - | |
72 | 68 | #define LINE "--------------------------------------------------------------------" |
73 | 69 | |
74 | 70 | // TODO |
@@ -115,8 +111,6 @@ void usage(void) { | ||
115 | 111 | |
116 | 112 | #define OPENPTS_LOG_FILENAME "~/.openpts/openpts.log" |
117 | 113 | |
118 | - | |
119 | - | |
120 | 114 | /** |
121 | 115 | * main of "openpts" command |
122 | 116 | * |
@@ -129,7 +123,6 @@ int main(int argc, char *argv[]) { | ||
129 | 123 | int rc = 0; // temporary return code |
130 | 124 | int retVal = -1; // main() actual return value |
131 | 125 | int opt; |
132 | - | |
133 | 126 | OPENPTS_CONFIG *conf = NULL; // conf for openpts |
134 | 127 | OPENPTS_CONTEXT *ctx = NULL; |
135 | 128 | char * config_filename = NULL; |
@@ -153,11 +146,11 @@ int main(int argc, char *argv[]) { | ||
153 | 146 | char *ptsc_path = NULL; |
154 | 147 | char *ptsc_conf = NULL; |
155 | 148 | |
149 | + /* Logging/NLS */ | |
156 | 150 | initCatalog(); |
157 | 151 | setSyslogCommandName("openpts"); |
158 | 152 | |
159 | 153 | /* args */ |
160 | - /* verbose level */ | |
161 | 154 | while ((opt = getopt(argc, argv, "givruDVc:dfuyl:p:P:C:h")) != -1) { |
162 | 155 | switch (opt) { |
163 | 156 | case 'i': |
@@ -180,11 +173,9 @@ int main(int argc, char *argv[]) { | ||
180 | 173 | command = DISPLAY; |
181 | 174 | break; |
182 | 175 | } |
183 | - | |
184 | 176 | OUTPUT(NLS(MS_OPENPTS, OPENPTS_ONE_COMMAND_ONLY, "Only one command may be given at a time.")); |
185 | 177 | usage(); |
186 | 178 | return -1; |
187 | - | |
188 | 179 | case 'V': |
189 | 180 | incVerbosity(); |
190 | 181 | break; |
@@ -239,11 +230,8 @@ int main(int argc, char *argv[]) { | ||
239 | 230 | /* check */ |
240 | 231 | if ((ptsc_path != NULL) && (ptsc_conf != NULL)) { |
241 | 232 | int len; |
242 | - // char ptsc_command[PATH_MAX]; | |
243 | - LOG(LOG_INFO, "ptsc debug mode\n"); | |
244 | - // len = strlen(ptsc_path) + strlen(ptsc_conf) + 13; | |
245 | - // snprintf(ptsc_command, PATH_MAX - 1, "%s -m -v -c %s", ptsc_path, ptsc_conf); | |
246 | 233 | |
234 | + LOG(LOG_INFO, "ptsc debug mode\n"); | |
247 | 235 | len = strlen(ptsc_path) + strlen(ptsc_conf) + 13; |
248 | 236 | ptsc_command = xmalloc(len); |
249 | 237 | snprintf(ptsc_command, len, "%s -m -v -c %s", ptsc_path, ptsc_conf); |
@@ -286,8 +274,7 @@ int main(int argc, char *argv[]) { | ||
286 | 274 | goto out_free; |
287 | 275 | } |
288 | 276 | |
289 | - // setLogLocation(OPENPTS_LOG_CONSOLE, NULL); | |
290 | - | |
277 | + /* verbose msg */ | |
291 | 278 | VERBOSE(2, NLS(MS_OPENPTS, OPENPTS_VERIFIER_CONFIG_FILE, |
292 | 279 | "Config file : %s\n"), conf->config_file); |
293 | 280 | VERBOSE(2, NLS(MS_OPENPTS, OPENPTS_VERIFIER_VERBOSITY, |
@@ -364,17 +351,9 @@ int main(int argc, char *argv[]) { | ||
364 | 351 | /* given target (by hostname) */ |
365 | 352 | /* look up */ |
366 | 353 | if (target_collector != NULL) { |
367 | - // WORK NEEDED: Please use NLS for i18n output | |
368 | - OUTPUT("hostname : %s\n", target_hostname); | |
369 | - OUTPUT("UUID : %s\n", target_collector->str_uuid); | |
370 | - OUTPUT("State : %d\n", target_collector->state); | |
371 | - OUTPUT("Dir : %s\n", target_collector->dir); | |
372 | - OUTPUT("Manifests :\n"); | |
373 | - | |
374 | - getRmList(target_conf, target_conf->config_dir); | |
375 | - printRmList(target_conf, ""); | |
354 | + printTarget(target_collector, ""); | |
376 | 355 | } else { |
377 | - OUTPUT(NLS(MS_OPENPTS, OPENPTS_TARGET_NOT_INITIALIZED, | |
356 | + ERROR(NLS(MS_OPENPTS, OPENPTS_TARGET_NOT_INITIALIZED, | |
378 | 357 | "The target %s is not initialized yet. Please enroll with '%s' first\n\n"), |
379 | 358 | target_hostname, target_hostname); |
380 | 359 | retVal = RETVAL_NOTENROLLED; |
@@ -383,10 +362,12 @@ int main(int argc, char *argv[]) { | ||
383 | 362 | } else { |
384 | 363 | /* all target (simple) */ |
385 | 364 | printTargetList(conf, ""); // target.c |
386 | - goto out_free; // exit | |
365 | + goto out_free; | |
387 | 366 | } |
388 | - } else if ( NULL == target_hostname ) { | |
367 | + } else if (target_hostname == NULL) { | |
389 | 368 | /* Other commands use Remote Access (SSH) */ |
369 | + ERROR(NLS(MS_OPENPTS, OPENPTS_TARGET_MISSING, | |
370 | + "Requires the target hostname\n\n")), | |
390 | 371 | usage(); |
391 | 372 | goto out_free; |
392 | 373 | } |
@@ -470,8 +451,8 @@ int main(int argc, char *argv[]) { | ||
470 | 451 | DEBUG("conf->config_dir %s\n", conf->config_dir); |
471 | 452 | rc = enroll(ctx, target_hostname, ssh_username, ssh_port, conf->config_dir, force); // verifier.c |
472 | 453 | if (rc != 0) { |
473 | - ERROR( // TODO NLS | |
474 | - "enroll was failed, rc = %d\n", rc); | |
454 | + ERROR(NLS(MS_OPENPTS, OPENPTS_INIT_ENROLL_FAIL, | |
455 | + "enroll was failed, rc = %d\n"), rc); | |
475 | 456 | printReason(ctx, print_pcr_hints); |
476 | 457 | retVal = RETVAL_NOTENROLLED; |
477 | 458 | goto out_free; |
@@ -481,8 +462,8 @@ int main(int argc, char *argv[]) { | ||
481 | 462 | rc = verifier(ctx, target_hostname, ssh_username, ssh_port, conf->config_dir, 1); // init |
482 | 463 | if (rc != OPENPTS_RESULT_VALID) { |
483 | 464 | LOG(LOG_ERR, "initial verification was failed, rc = %d\n", rc); |
484 | - ERROR( // TODO NLS | |
485 | - "initial verification was failed, rc = %d\n", rc); | |
465 | + ERROR(NLS(MS_OPENPTS, OPENPTS_INIT_VERIFICATION_FAIL, | |
466 | + "initial verification was failed, rc = %d\n"), rc); | |
486 | 467 | printReason(ctx, print_pcr_hints); |
487 | 468 | retVal = RETVAL_NOTTRUSTED; |
488 | 469 | goto out_free; |
@@ -26,14 +26,13 @@ | ||
26 | 26 | * \brief policy |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2010-06-19 |
29 | - * cleanup 2011-01-22 SM | |
29 | + * cleanup 2012-01-05 SM | |
30 | 30 | * |
31 | 31 | * Security Policy |
32 | 32 | * - load |
33 | 33 | * - verify |
34 | 34 | |
35 | 35 | * |
36 | - * | |
37 | 36 | */ |
38 | 37 | |
39 | 38 |
@@ -42,7 +41,6 @@ | ||
42 | 41 | #include <string.h> |
43 | 42 | |
44 | 43 | #include <openpts.h> |
45 | -// #include <log.h> | |
46 | 44 | |
47 | 45 | /** |
48 | 46 | * Free policy chain |
@@ -71,15 +69,15 @@ int freePolicyChain(OPENPTS_POLICY *pol) { | ||
71 | 69 | * policy number |
72 | 70 | */ |
73 | 71 | int loadPolicyFile(OPENPTS_CONTEXT *ctx, char * filename) { |
74 | - FILE *fp; | |
75 | 72 | char buf[BUF_SIZE]; // SMBIOS |
76 | 73 | char *eq; |
77 | 74 | char *name; |
78 | 75 | char *value; |
79 | 76 | int cnt = 1; |
80 | 77 | int len; |
81 | - OPENPTS_POLICY *pol; | |
82 | 78 | int line = 0; |
79 | + FILE *fp; | |
80 | + OPENPTS_POLICY *pol; | |
83 | 81 | |
84 | 82 | /* check */ |
85 | 83 | if (ctx == NULL) { |
@@ -99,7 +97,6 @@ int loadPolicyFile(OPENPTS_CONTEXT *ctx, char * filename) { | ||
99 | 97 | } |
100 | 98 | |
101 | 99 | /* parse */ |
102 | - | |
103 | 100 | while (fgets(buf, BUF_SIZE, fp) != NULL) { // read line |
104 | 101 | /* ignore comment, null line */ |
105 | 102 | if (buf[0] == '#') { |
@@ -143,7 +140,7 @@ int loadPolicyFile(OPENPTS_CONTEXT *ctx, char * filename) { | ||
143 | 140 | } |
144 | 141 | cnt++; |
145 | 142 | } else { |
146 | - // | |
143 | + // unknown eq | |
147 | 144 | } |
148 | 145 | line++; |
149 | 146 | } |
@@ -243,7 +240,6 @@ int checkPolicy(OPENPTS_CONTEXT *ctx) { | ||
243 | 240 | /** |
244 | 241 | * print policy and properties |
245 | 242 | * |
246 | - * | |
247 | 243 | */ |
248 | 244 | int printPolicy(OPENPTS_CONTEXT *ctx) { |
249 | 245 | OPENPTS_POLICY *pol; |
@@ -308,5 +304,3 @@ int printPolicy(OPENPTS_CONTEXT *ctx) { | ||
308 | 304 | |
309 | 305 | return 0; |
310 | 306 | } |
311 | - | |
312 | - |
@@ -26,7 +26,7 @@ | ||
26 | 26 | * \brief properties |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2010-06-19 |
29 | - * cleanup 2011-01-22 SM | |
29 | + * cleanup 2012-01-05 SM | |
30 | 30 | * |
31 | 31 | * Security Properties |
32 | 32 | * |
@@ -107,7 +107,7 @@ void freeProperty(OPENPTS_PROPERTY *prop) { | ||
107 | 107 | * Free Property Chain |
108 | 108 | */ |
109 | 109 | int freePropertyChain(OPENPTS_PROPERTY *prop) { |
110 | - | |
110 | + /* check */ | |
111 | 111 | if (prop == NULL) { |
112 | 112 | /* end of chain */ |
113 | 113 | return PTS_SUCCESS; |
@@ -164,6 +164,20 @@ int addProperty(OPENPTS_CONTEXT *ctx, char *name, char *value) { | ||
164 | 164 | OPENPTS_PROPERTY *end; |
165 | 165 | OPENPTS_PROPERTY *prop; |
166 | 166 | |
167 | + /* check */ | |
168 | + if (ctx == NULL) { | |
169 | + LOG(LOG_ERR, "null input"); | |
170 | + return PTS_FATAL; | |
171 | + } | |
172 | + if (name == NULL) { | |
173 | + LOG(LOG_ERR, "null input"); | |
174 | + return PTS_FATAL; | |
175 | + } | |
176 | + if (value == NULL) { | |
177 | + LOG(LOG_ERR, "null input"); | |
178 | + return PTS_FATAL; | |
179 | + } | |
180 | + | |
167 | 181 | start = ctx->prop_start; |
168 | 182 | end = ctx->prop_end; |
169 | 183 |
@@ -265,15 +279,15 @@ int setEventProperty(OPENPTS_CONTEXT *ctx, char *name, char *value, OPENPTS_PCR_ | ||
265 | 279 | /* check, missing event */ |
266 | 280 | if (eventWrapper == NULL) { |
267 | 281 | LOG(LOG_ERR, "setEventProperty() - eventWrapper is NULL\n"); |
268 | - return PTS_FATAL; // 0; // PTS_INTERNAL_ERROR; | |
282 | + return PTS_FATAL; | |
269 | 283 | } |
270 | 284 | if (eventWrapper->event == NULL) { |
271 | 285 | LOG(LOG_ERR, "setEventProperty() - event is NULL\n"); |
272 | - return PTS_FATAL; // 0; // PTS_INTERNAL_ERROR; | |
286 | + return PTS_FATAL; | |
273 | 287 | } |
274 | 288 | if (eventWrapper->event->rgbPcrValue == NULL) { |
275 | 289 | LOG(LOG_ERR, "setEventProperty() - rgbPcrValue is NULL\n"); |
276 | - return PTS_FATAL; // 0; // PTS_INTERNAL_ERROR; | |
290 | + return PTS_FATAL; | |
277 | 291 | } |
278 | 292 | |
279 | 293 | buf = encodeBase64( |
@@ -303,18 +317,18 @@ int setEventProperty(OPENPTS_CONTEXT *ctx, char *name, char *value, OPENPTS_PCR_ | ||
303 | 317 | /* check, missing event */ |
304 | 318 | if (eventWrapper == NULL) { |
305 | 319 | LOG(LOG_ERR, "setEventProperty() - eventWrapper is NULL\n"); |
306 | - return PTS_FATAL; // 0; // PTS_INTERNAL_ERROR; | |
320 | + return PTS_FATAL; | |
307 | 321 | } |
308 | 322 | event = eventWrapper->event; |
309 | 323 | if (event == NULL) { |
310 | 324 | LOG(LOG_ERR, "setEventProperty() - event is NULL\n"); |
311 | - return PTS_FATAL; // 0; // PTS_INTERNAL_ERROR; | |
325 | + return PTS_FATAL; | |
312 | 326 | } |
313 | 327 | if (event->ulEventLength > 0) { |
314 | 328 | char * str; |
315 | 329 | if (event->rgbEvent == NULL) { |
316 | 330 | LOG(LOG_ERR, "setEventProperty() - rgbEvent is NULL\n"); |
317 | - return PTS_FATAL; // 0; // PTS_INTERNAL_ERROR; | |
331 | + return PTS_FATAL; | |
318 | 332 | } |
319 | 333 | /* get String */ |
320 | 334 |
@@ -493,7 +507,6 @@ int saveProperties(OPENPTS_CONTEXT *ctx, char * filename) { | ||
493 | 507 | } |
494 | 508 | |
495 | 509 | int addPropertiesFromConfig(OPENPTS_CONFIG *conf, OPENPTS_CONTEXT *ctx) { |
496 | - | |
497 | 510 | /* check */ |
498 | 511 | if (conf == NULL) { |
499 | 512 | LOG(LOG_ERR, "null input"); |
@@ -28,7 +28,7 @@ | ||
28 | 28 | * @author Olivier Valentin <olivier.valentin@us.ibm.com> |
29 | 29 | * @author Alexandre Ratchov <alexandre.ratchov@bull.net> |
30 | 30 | * @date 2010-04-04 |
31 | - * cleanup 2011-07-06 SM | |
31 | + * cleanup 2012-01-04 SM | |
32 | 32 | * |
33 | 33 | */ |
34 | 34 |
@@ -50,8 +50,6 @@ | ||
50 | 50 | #include <sys/stat.h> // chmod |
51 | 51 | |
52 | 52 | #include <openpts.h> |
53 | -// #include <log.h> | |
54 | - | |
55 | 53 | |
56 | 54 | int prop_num = 0; |
57 | 55 | OPENPTS_PROPERTY *start = NULL; |
@@ -64,7 +62,7 @@ OPENPTS_PROPERTY *end = NULL; | ||
64 | 62 | * TODO for multiple conenction, multiple ctxs are required. |
65 | 63 | * TODO disable remote connection |
66 | 64 | */ |
67 | -int collector2(OPENPTS_CONFIG *conf) { | |
65 | +int collector(OPENPTS_CONFIG *conf) { | |
68 | 66 | int rc; |
69 | 67 | int terminate = 0; |
70 | 68 | OPENPTS_CONTEXT *ctx = NULL; |
@@ -83,12 +81,10 @@ int collector2(OPENPTS_CONFIG *conf) { | ||
83 | 81 | DEBUG("collector() - getNewRmSetDir() was failed - never mind\n"); |
84 | 82 | } |
85 | 83 | |
86 | - | |
87 | 84 | LOG(LOG_INFO, "start collector (System UUID=%s, RM UUID = %s)\n", |
88 | 85 | conf->uuid->str, conf->rm_uuid->str); |
89 | 86 | |
90 | 87 | /* Collector <-> Verifier - handshake loop */ |
91 | - | |
92 | 88 | ctx = newPtsContext(conf); |
93 | 89 | |
94 | 90 | addPropertiesFromConfig(conf, ctx); |
@@ -127,7 +123,6 @@ int collector2(OPENPTS_CONFIG *conf) { | ||
127 | 123 | /* C->V responces */ |
128 | 124 | switch (read_tlv->type) { |
129 | 125 | case OPENPTS_CAPABILITIES: |
130 | - // TODO define CAPABILITIES structure | |
131 | 126 | DEBUG("IF-M OPENPTS_CAPABILITIES\n"); |
132 | 127 | /* check the UUID */ |
133 | 128 | if (read_tlv->length != sizeof(OPENPTS_IF_M_Capability)) { // TODO use defined name |
@@ -415,6 +410,8 @@ OPENPTS_PROPERTY *getPropertyFromArg(char *arg) { | ||
415 | 410 | |
416 | 411 | /** |
417 | 412 | * lock ptsc |
413 | + * | |
414 | + * check the log msg | |
418 | 415 | */ |
419 | 416 | void ptsc_lock(void) { |
420 | 417 | int fd, oldmask, oldgrp = 0; |
@@ -442,11 +439,11 @@ void ptsc_lock(void) { | ||
442 | 439 | |
443 | 440 | rc = getgrnam_r(PTSC_GROUP_NAME, &grp, buf, buf_len, &grpent); |
444 | 441 | if (rc != 0) { |
445 | - // TODO | |
442 | + LOG(LOG_ERR, "getgrnam_r() fail"); | |
446 | 443 | exit(1); |
447 | 444 | } |
448 | 445 | if (grpent == NULL) { |
449 | - // TODO | |
446 | + LOG(LOG_ERR, "grpent is null"); | |
450 | 447 | exit(1); |
451 | 448 | } |
452 | 449 | oldgrp = getegid(); |
@@ -495,11 +492,6 @@ static int preparePriv() { | ||
495 | 492 | #endif |
496 | 493 | |
497 | 494 | /* check GID */ |
498 | - // ptsc_grp = getgrnam(PTSC_GROUP_NAME); // TODO use getgrnam_r | |
499 | - // if (ptsc_grp == NULL) { | |
500 | - // LOG(LOG_ERR, "Looking up for group (name=%s) fail", PTSC_GROUP_NAME); | |
501 | - // return PTS_FATAL; | |
502 | - // } | |
503 | 495 | buf_len = sysconf(_SC_GETGR_R_SIZE_MAX); |
504 | 496 | if (buf_len < 0) { |
505 | 497 | buf_len = 4096; |
@@ -527,7 +519,6 @@ static int preparePriv() { | ||
527 | 519 | if (rc < 0) { |
528 | 520 | // TODO do not need for IF-M access (read only) |
529 | 521 | LOG(LOG_INFO, "Switching group (gid=%d) fail. %s\n", grp.gr_gid, strerror(errno)); |
530 | - // TODO 20110927 FAIL | |
531 | 522 | rc = PTS_FATAL; |
532 | 523 | goto free; |
533 | 524 | } |
@@ -539,7 +530,7 @@ static int preparePriv() { | ||
539 | 530 | } |
540 | 531 | #endif |
541 | 532 | |
542 | - /* */ | |
533 | + /* free */ | |
543 | 534 | free: |
544 | 535 | if (buf != NULL) xfree(buf); |
545 | 536 |
@@ -560,11 +551,6 @@ static int chmodDir(char *dirpath, int flag) { | ||
560 | 551 | |
561 | 552 | |
562 | 553 | /* check GID */ |
563 | - // ptsc_grp = getgrnam(PTSC_GROUP_NAME); // TODO use getgrnam_r | |
564 | - // if (ptsc_grp == NULL) { | |
565 | - // LOG(LOG_ERR, "Looking up for group %s", PTSC_GROUP_NAME); | |
566 | - // return PTS_FATAL; | |
567 | - // } | |
568 | 554 | buf_len = sysconf(_SC_GETGR_R_SIZE_MAX); |
569 | 555 | if (buf_len < 0) { |
570 | 556 | buf_len = 4096; |
@@ -636,28 +622,11 @@ int main(int argc, char *argv[]) { | ||
636 | 622 | #ifdef CONFIG_AUTO_RM_UPDATE |
637 | 623 | int remove = 0; |
638 | 624 | #endif |
639 | - // extern int logLocation; | |
640 | - // void setLogLocation(int ll); | |
641 | 625 | |
642 | 626 | /* properties by cmdline */ |
643 | 627 | OPENPTS_PROPERTY *prop; |
644 | 628 | |
645 | -#if 0 | |
646 | - initCatalog(); | |
647 | - | |
648 | - // TODO chgrp | |
649 | - rc = preparePriv(); | |
650 | - if (rc != PTS_SUCCESS) { | |
651 | - LOG(LOG_ERR, "preparePriv fail\n"); | |
652 | - } | |
653 | - | |
654 | - conf = newPtsConfig(); | |
655 | - if (conf == NULL) { | |
656 | - LOG(LOG_ERR, "internal error\n"); // TODO(munetoh) | |
657 | - return -1; | |
658 | - } | |
659 | -#endif | |
660 | - | |
629 | + /* Logging/NLS */ | |
661 | 630 | initCatalog(); |
662 | 631 | setSyslogCommandName("ptsc"); |
663 | 632 |
@@ -695,9 +664,6 @@ int main(int argc, char *argv[]) { | ||
695 | 664 | /* not everything should go to syslog - on some systems |
696 | 665 | this could go to a log file - let default behaviour |
697 | 666 | in log.c decide this */ |
698 | - // setLogLocation(OPENPTS_LOG_SYSLOG, NULL); | |
699 | - // OK setLogLocation(OPENPTS_LOG_CONSOLE, NULL); // OK | |
700 | - // setLogLocation(OPENPTS_LOG_FILE, "/var/log/ptsc.log"); // OK call this before any out | |
701 | 667 | break; |
702 | 668 | case 'c': |
703 | 669 | config_filename = optarg; |
@@ -746,11 +712,10 @@ int main(int argc, char *argv[]) { | ||
746 | 712 | if (command == COMMAND_IFM) { |
747 | 713 | /* Set IF-M log location, syslog or file(for DEBUG) */ |
748 | 714 | setLogLocation(OPENPTS_LOG_SYSLOG, NULL); |
749 | - // setVerbosity(0); // no console out | |
750 | 715 | } else { |
751 | 716 | /* Set logging (location,filename) by ENV */ |
752 | 717 | determineLogLocationByEnv(); |
753 | - //setLogLocation(OPENPTS_LOG_CONSOLE, NULL); | |
718 | + | |
754 | 719 | // TODO chgrp |
755 | 720 | rc = preparePriv(); |
756 | 721 | if (rc != PTS_SUCCESS) { |
@@ -766,7 +731,7 @@ int main(int argc, char *argv[]) { | ||
766 | 731 | |
767 | 732 | /* set the DEBUG level, 1,2,3 */ |
768 | 733 | if (getVerbosity() > 2) { |
769 | - setDebugFlags(DEBUG_FLAG | DEBUG_IFM_FLAG | DEBUG_FSM_FLAG | DEBUG_CAL_FLAG ); | |
734 | + setDebugFlags(DEBUG_FLAG | DEBUG_IFM_FLAG | DEBUG_FSM_FLAG | DEBUG_CAL_FLAG); | |
770 | 735 | } else if (getVerbosity() > 1) { |
771 | 736 | setDebugFlags(DEBUG_FLAG | DEBUG_IFM_FLAG); |
772 | 737 | } else if (getVerbosity() > 0) { |
@@ -781,14 +746,16 @@ int main(int argc, char *argv[]) { | ||
781 | 746 | /* load config, /etc/ptsc.conf */ |
782 | 747 | if (config_filename == NULL) { |
783 | 748 | // this goto stdout and bad with "-m" |
784 | - // VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_CONFIG_FILE, "Config file: %s\n"), PTSC_CONFIG_FILE); | |
749 | + VERBOSE(2, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_CONFIG_FILE, | |
750 | + "Config file: %s\n"), PTSC_CONFIG_FILE); | |
785 | 751 | rc = readPtsConfig(conf, PTSC_CONFIG_FILE); |
786 | 752 | if (rc != PTS_SUCCESS) { |
787 | 753 | DEBUG("readPtsConfig() failed\n"); |
788 | 754 | goto free; |
789 | 755 | } |
790 | 756 | } else { |
791 | - // VERBOSE(1, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_CONFIG_FILE, "Config file: %s\n"), config_filename); | |
757 | + VERBOSE(2, NLS(MS_OPENPTS, OPENPTS_COLLECTOR_CONFIG_FILE, | |
758 | + "Config file: %s\n"), config_filename); | |
792 | 759 | rc = readPtsConfig(conf, config_filename); |
793 | 760 | if (rc != PTS_SUCCESS) { |
794 | 761 | DEBUG("readPtsConfig() failed\n"); |
@@ -804,8 +771,8 @@ int main(int argc, char *argv[]) { | ||
804 | 771 | if (checkFile(conf->uuid->filename) != OPENPTS_FILE_EXISTS) { |
805 | 772 | // missing |
806 | 773 | LOG(LOG_ERR, "ptsc is not initialized yet"); |
807 | - ERROR( // TODO NLS | |
808 | - "ptsc is not initialized yet.\n\n"); | |
774 | + ERROR(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_NOT_INITIALIZED, | |
775 | + "ptsc is not initialized yet.\n\n")); | |
809 | 776 | goto free; |
810 | 777 | } |
811 | 778 | } |
@@ -851,7 +818,7 @@ int main(int argc, char *argv[]) { | ||
851 | 818 | } else { |
852 | 819 | rc = readOpenptsUuidFile(conf->rm_uuid); |
853 | 820 | if (rc != PTS_SUCCESS) { |
854 | - DEBUG("readOpenptsUuidFile(%s) failed\n",conf->rm_uuid->filename); | |
821 | + DEBUG("readOpenptsUuidFile(%s) failed\n", conf->rm_uuid->filename); | |
855 | 822 | OUTPUT(NLS(MS_OPENPTS, OPENPTS_COLLECTOR_FAILED_READ_RM_UUID, |
856 | 823 | "Failed to read the Reference Manifest UUID file '%s':\n" |
857 | 824 | "Please ensure on the target that:\n" |
@@ -914,7 +881,6 @@ int main(int argc, char *argv[]) { | ||
914 | 881 | case COMMAND_AUTO_UPDATE: |
915 | 882 | /* update by command, but HUP is better */ |
916 | 883 | VERBOSE(1, "Updating Reference Manifest\n"); |
917 | - //addDebugFlags(DEBUG_CAL_FLAG); | |
918 | 884 | /* update RMs */ |
919 | 885 | rc = update(conf, prop_num, start, end, remove); |
920 | 886 | if (rc != PTS_SUCCESS) { |
@@ -1034,7 +1000,7 @@ int main(int argc, char *argv[]) { | ||
1034 | 1000 | break; |
1035 | 1001 | case COMMAND_IFM: |
1036 | 1002 | /* run colelctor IF-M */ |
1037 | - rc = collector2(conf); | |
1003 | + rc = collector(conf); | |
1038 | 1004 | break; |
1039 | 1005 | default: |
1040 | 1006 | LOG(LOG_ERR, "bad command\n"); |
@@ -1044,5 +1010,8 @@ int main(int argc, char *argv[]) { | ||
1044 | 1010 | free: |
1045 | 1011 | freePtsConfig(conf); |
1046 | 1012 | |
1013 | + if (rc != PTS_SUCCESS) { | |
1014 | + LOG(LOG_ERR, "ptsc exit. rc = %d", rc); | |
1015 | + } | |
1047 | 1016 | return rc; |
1048 | 1017 | } |
@@ -26,7 +26,7 @@ | ||
26 | 26 | * \brief properties |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2010-11-26 |
29 | - * cleanup 2011-01-22 SM | |
29 | + * cleanup 2012-01-05 SM | |
30 | 30 | * |
31 | 31 | * Reason (Remidiation) of validation fail |
32 | 32 | * |
@@ -56,7 +56,7 @@ void freeReason(OPENPTS_REASON *reason) { | ||
56 | 56 | xfree(reason->message); |
57 | 57 | xfree(reason); |
58 | 58 | |
59 | - return; // PTS_SUCCESS; | |
59 | + return; | |
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -88,16 +88,13 @@ int addReason_old(OPENPTS_CONTEXT *ctx, int pcr, char *message) { | ||
88 | 88 | OPENPTS_REASON *reason; |
89 | 89 | int len; |
90 | 90 | |
91 | - // DEBUG("addReason - [%s]\n", message); | |
92 | - | |
93 | 91 | /* check */ |
94 | 92 | if (ctx == NULL) { |
95 | 93 | LOG(LOG_ERR, "null input"); |
96 | 94 | return PTS_FATAL; |
97 | 95 | } |
98 | 96 | |
99 | - len = strlen(message); | |
100 | - | |
97 | + len = strlen(message); | |
101 | 98 | start = ctx->reason_start; |
102 | 99 | end = ctx->reason_end; |
103 | 100 |
@@ -132,8 +129,6 @@ int addReason_old(OPENPTS_CONTEXT *ctx, int pcr, char *message) { | ||
132 | 129 | reason->message[len] = 0; |
133 | 130 | ctx->reason_count++; |
134 | 131 | |
135 | - // DEBUG("addReason - done %d [%s]\n", ctx->reason_count, reason->message); | |
136 | - | |
137 | 132 | return PTS_SUCCESS; |
138 | 133 | } |
139 | 134 |
@@ -142,10 +137,9 @@ int addReason_old(OPENPTS_CONTEXT *ctx, int pcr, char *message) { | ||
142 | 137 | */ |
143 | 138 | #define MAX_REASON_SIZE 2048 |
144 | 139 | int addReason(OPENPTS_CONTEXT *ctx, int pcr, const char *format, ...) { |
145 | - char buf[MAX_REASON_SIZE +1]; // TODO size | |
146 | 140 | int rc; |
141 | + char buf[MAX_REASON_SIZE +1]; // TODO size | |
147 | 142 | va_list list; |
148 | - va_start(list, format); | |
149 | 143 | |
150 | 144 | /* check */ |
151 | 145 | if (ctx == NULL) { |
@@ -153,6 +147,7 @@ int addReason(OPENPTS_CONTEXT *ctx, int pcr, const char *format, ...) { | ||
153 | 147 | return PTS_FATAL; |
154 | 148 | } |
155 | 149 | |
150 | + va_start(list, format); | |
156 | 151 | vsnprintf(buf, MAX_REASON_SIZE, format, list); |
157 | 152 | |
158 | 153 | rc = addReason_old(ctx, pcr, (char *)buf); |
@@ -178,7 +173,7 @@ char *reason_pcr_hints[] = { | ||
178 | 173 | NULL, /* PCR9 Unused */ |
179 | 174 | "Trusted Execution Database" |
180 | 175 | }; |
181 | -#else // TPM v1.2, PC Linux, TODO add other type of platform? | |
176 | +#else // TPM v1.2, PC Linux, TODO add other type of platform? | |
182 | 177 | char *reason_pcr_hints[] = { |
183 | 178 | "CRTM, BIOS and Platform Extensions", |
184 | 179 | "Platform Configuration", |
@@ -187,7 +182,7 @@ char *reason_pcr_hints[] = { | ||
187 | 182 | "IPL Code (usually the MBR)", |
188 | 183 | "IPL Code Configuration and Data (for use by the IPL code)", |
189 | 184 | "State Transition and Wake Events", |
190 | - "Host Platform Manufacturer Control", // v1.1"Reserved for future usage. Do not use.", | |
185 | + "Host Platform Manufacturer Control", // v1.1"Reserved for future usage. Do not use.", | |
191 | 186 | "OS Kernels (GRUB-IMA)", |
192 | 187 | NULL, /* PCR9 Unused */ |
193 | 188 | "Applications (LINUX-IMA)", /* PCR10 */ |
@@ -236,6 +231,3 @@ void printReason(OPENPTS_CONTEXT *ctx, int print_pcr_hints) { | ||
236 | 231 | } |
237 | 232 | } |
238 | 233 | } |
239 | - | |
240 | - | |
241 | -// TODO add freeReason() |
@@ -26,7 +26,7 @@ | ||
26 | 26 | * \brief Reference Manifest (RM) |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2010-04-01 |
29 | - * cleanup 2011-12-31 SM | |
29 | + * cleanup 2012-01-05 SM | |
30 | 30 | * |
31 | 31 | * IML + Model -> RM |
32 | 32 | * |
@@ -233,7 +233,6 @@ int writeCoreValues(xmlTextWriterPtr writer, | ||
233 | 233 | int algtype, |
234 | 234 | char *id, |
235 | 235 | TSS_PCR_EVENT * event) { |
236 | - | |
237 | 236 | /* check */ |
238 | 237 | if (writer == NULL) { |
239 | 238 | LOG(LOG_ERR, "null input"); |
@@ -479,7 +478,6 @@ int writeAllCoreValues(xmlTextWriterPtr writer, OPENPTS_SNAPSHOT * ss) { | ||
479 | 478 | */ |
480 | 479 | int writeFsmSubvertex(xmlTextWriterPtr writer, |
481 | 480 | OPENPTS_FSM_Subvertex * sub) { |
482 | - | |
483 | 481 | DEBUG_CAL("writeFsmSubvertex - start\n"); |
484 | 482 | |
485 | 483 | /* check */ |
@@ -682,7 +680,6 @@ int writeFsmTransition(xmlTextWriterPtr writer, | ||
682 | 680 | </uml:Model> |
683 | 681 | */ |
684 | 682 | int writeFsmModel(xmlTextWriterPtr writer, OPENPTS_FSM_CONTEXT * fsm) { |
685 | - //int rc =0; | |
686 | 683 | char id[BUF_SIZE]; |
687 | 684 | OPENPTS_FSM_Subvertex *sub; |
688 | 685 | OPENPTS_FSM_Transition *trans; |
@@ -26,7 +26,7 @@ | ||
26 | 26 | * \brief parse SMBIOS info |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2010-08-29 |
29 | - * cleanup 2012-01-03 SM | |
29 | + * cleanup 2012-01-05 SM | |
30 | 30 | * |
31 | 31 | * SMBIOS Info in BIOS IML -> platform properties |
32 | 32 | * |
@@ -53,7 +53,6 @@ | ||
53 | 53 | #include <dirent.h> |
54 | 54 | |
55 | 55 | #include <openpts.h> |
56 | -// #include <log.h> | |
57 | 56 | |
58 | 57 | #define SMBIOS_MAX_SIZE 4096 |
59 | 58 | #define SMBIOS_MAX_HANDLE 0x50 |
@@ -70,17 +69,16 @@ int genSmbiosFileByDmidecode(char * filename) { | ||
70 | 69 | |
71 | 70 | /* must be a root user */ |
72 | 71 | uid = getuid(); |
73 | - // DEBUG("UID %d\n",uid); | |
74 | 72 | if (uid != 0) { |
75 | 73 | DEBUG("must be a root user to run dmidecode\n"); |
76 | - return -2; | |
74 | + return PTS_FATAL; | |
77 | 75 | } |
78 | 76 | |
79 | 77 | /* exec dmidecode */ |
80 | 78 | pid = fork(); |
81 | 79 | if (pid < 0) { |
82 | - LOG(LOG_ERR, "\n"); | |
83 | - return -1; | |
80 | + LOG(LOG_ERR, "fork() fail"); | |
81 | + return PTS_FATAL; | |
84 | 82 | } |
85 | 83 | if (pid == 0) { |
86 | 84 | /* child */ |
@@ -95,17 +93,17 @@ int genSmbiosFileByDmidecode(char * filename) { | ||
95 | 93 | if (WIFEXITED(status)) { |
96 | 94 | /* 1 : OK */ |
97 | 95 | LOG(LOG_TODO, "Exit status %d\n", WEXITSTATUS(status)); |
98 | - return 1; | |
96 | + return PTS_SUCCESS; // 1 | |
99 | 97 | } else if (WIFSIGNALED(status)) { |
100 | 98 | LOG(LOG_ERR, "Signal status %d\n", WIFSIGNALED(status)); |
101 | - return -1; | |
99 | + return PTS_FATAL; | |
102 | 100 | } else { |
103 | 101 | LOG(LOG_ERR, "Bad exit"); |
104 | - return -1; | |
102 | + return PTS_FATAL; | |
105 | 103 | } |
106 | 104 | } |
107 | 105 | |
108 | - return 0; | |
106 | + return PTS_SUCCESS; | |
109 | 107 | } |
110 | 108 | |
111 | 109 |
@@ -123,8 +121,16 @@ int readSmbiosFile(char * filename, BYTE **data, int *len) { | ||
123 | 121 | BYTE *buf; |
124 | 122 | int rc = PTS_SUCCESS; |
125 | 123 | |
126 | - buf = xmalloc(SMBIOS_MAX_SIZE); // TODO check the filesize | |
124 | + /* check */ | |
125 | + if (filename == NULL) { | |
126 | + LOG(LOG_ERR, "null input"); | |
127 | + return PTS_FATAL; | |
128 | + } | |
129 | + | |
130 | + // TODO(munetoh) check the file size | |
131 | + buf = xmalloc(SMBIOS_MAX_SIZE); | |
127 | 132 | if (buf == NULL) { |
133 | + LOG(LOG_ERR, "no memory"); | |
128 | 134 | return PTS_FATAL; |
129 | 135 | } |
130 | 136 |
@@ -134,7 +140,7 @@ int readSmbiosFile(char * filename, BYTE **data, int *len) { | ||
134 | 140 | goto error; |
135 | 141 | } |
136 | 142 | |
137 | - size = fread(buf, 1, SMBIOS_MAX_SIZE, fp); // TODO(munetoh) check the file size | |
143 | + size = fread(buf, 1, SMBIOS_MAX_SIZE, fp); | |
138 | 144 | |
139 | 145 | fclose(fp); |
140 | 146 |
@@ -26,7 +26,7 @@ | ||
26 | 26 | * \brief Functions for snapshot |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2010-11-02 |
29 | - * cleanup 2011-01-20 SM | |
29 | + * cleanup 2012-01-05 SM | |
30 | 30 | * |
31 | 31 | * divided from IML.c |
32 | 32 | * |
@@ -82,7 +82,6 @@ | ||
82 | 82 | #include <openssl/sha.h> |
83 | 83 | |
84 | 84 | #include <openpts.h> |
85 | -// #include <log.h> | |
86 | 85 | |
87 | 86 | /** |
88 | 87 | * New Snapshot |
@@ -94,7 +93,7 @@ | ||
94 | 93 | OPENPTS_SNAPSHOT * newSnapshot() { |
95 | 94 | OPENPTS_SNAPSHOT *ss = NULL; |
96 | 95 | |
97 | - ss = (OPENPTS_SNAPSHOT*) xmalloc(sizeof(OPENPTS_SNAPSHOT)); // leaked | |
96 | + ss = (OPENPTS_SNAPSHOT*) xmalloc(sizeof(OPENPTS_SNAPSHOT)); | |
98 | 97 | if (ss == NULL) { |
99 | 98 | LOG(LOG_ERR, "no memory"); |
100 | 99 | return NULL; |
@@ -109,14 +108,12 @@ OPENPTS_SNAPSHOT * newSnapshot() { | ||
109 | 108 | return ss; |
110 | 109 | } |
111 | 110 | |
112 | - | |
113 | 111 | /** |
114 | 112 | * Free Snapshot |
115 | 113 | * |
116 | 114 | * return 0:success, -1:error |
117 | 115 | */ |
118 | 116 | int freeSnapshot(OPENPTS_SNAPSHOT * ss) { |
119 | - | |
120 | 117 | /* check */ |
121 | 118 | if (ss == NULL) { |
122 | 119 | LOG(LOG_ERR, "null input"); |
@@ -157,7 +154,7 @@ int freeSnapshot(OPENPTS_SNAPSHOT * ss) { | ||
157 | 154 | OPENPTS_SNAPSHOT_TABLE * newSnapshotTable() { |
158 | 155 | OPENPTS_SNAPSHOT_TABLE *sst = NULL; |
159 | 156 | |
160 | - sst = (OPENPTS_SNAPSHOT_TABLE *) xmalloc(sizeof(OPENPTS_SNAPSHOT_TABLE)); // leaked | |
157 | + sst = (OPENPTS_SNAPSHOT_TABLE *) xmalloc(sizeof(OPENPTS_SNAPSHOT_TABLE)); | |
161 | 158 | if (sst == NULL) { |
162 | 159 | LOG(LOG_ERR, "no memory"); |
163 | 160 | return NULL; |
@@ -254,7 +251,7 @@ OPENPTS_SNAPSHOT *getSnapshotFromTable(OPENPTS_SNAPSHOT_TABLE * sst, int pcr_ind | ||
254 | 251 | |
255 | 252 | /* check 2 */ |
256 | 253 | if (sst->snapshot[pcr_index][level] == NULL) { |
257 | - // DEBUG("sst->snapshot[%d][%d] is null", pcr_index, level); | |
254 | + /* Missing SS */ | |
258 | 255 | return NULL; |
259 | 256 | } |
260 | 257 |
@@ -27,7 +27,7 @@ | ||
27 | 27 | * @author Olivier Valentin <olivier.valentin@us.ibm.com> |
28 | 28 | * @author Alexandre Ratchov <alexandre.ratchov@bull.net> |
29 | 29 | * @date 2010-03-31 |
30 | - * cleanup 2011-12-31 SM | |
30 | + * cleanup 2012-01-05 SM | |
31 | 31 | * |
32 | 32 | */ |
33 | 33 |
@@ -67,20 +67,19 @@ pid_t ssh_connect(char *host, char *ssh_username, char *ssh_port, char *key_file | ||
67 | 67 | return -1; |
68 | 68 | } |
69 | 69 | |
70 | - | |
71 | 70 | /* socket */ |
72 | 71 | if (socketpair(AF_UNIX, SOCK_STREAM, 0, socket_pair) == -1) { |
73 | 72 | LOG(LOG_ERR, "socketpair() fail"); |
74 | 73 | goto err; |
75 | 74 | } |
76 | 75 | |
76 | + /* fork */ | |
77 | 77 | if ((pid = fork()) == -1) { |
78 | 78 | LOG(LOG_ERR, "fork() fail"); |
79 | 79 | goto err_close; |
80 | 80 | } |
81 | - | |
82 | 81 | if (pid == 0) { |
83 | - // child process | |
82 | + /* child process */ | |
84 | 83 | char *arguments[16]; |
85 | 84 | int arg_idx = 0; |
86 | 85 | char identity_string[PATH_MAX + /* "IdentityFile " */ 13]; |
@@ -117,13 +116,14 @@ pid_t ssh_connect(char *host, char *ssh_username, char *ssh_port, char *key_file | ||
117 | 116 | arguments[arg_idx++] = host; |
118 | 117 | arguments[arg_idx++] = ptsc_command; |
119 | 118 | #if 0 |
119 | + // TODO | |
120 | 120 | /* Sync verbose level between verifier and collector? */ |
121 | - // { | |
121 | + if (verbose_sync) { | |
122 | 122 | int verboseLevel; |
123 | 123 | for ( verboseLevel = 0; (verboseLevel < getVerbosity()) && (arg_idx < 15); verboseLevel++ ) { |
124 | 124 | arguments[arg_idx++] = "-v"; |
125 | 125 | } |
126 | - // } | |
126 | + } | |
127 | 127 | #endif |
128 | 128 | arguments[arg_idx++] = NULL; |
129 | 129 |
@@ -26,7 +26,7 @@ | ||
26 | 26 | * \brief target(collector) |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2011-06-22 |
29 | - * cleanup 2011-10-07 SM | |
29 | + * cleanup 2012-01-04 SM | |
30 | 30 | * |
31 | 31 | * branch from uuid.c |
32 | 32 | * |
@@ -130,11 +130,8 @@ static int selectUuidDir(const struct dirent *entry) { | ||
130 | 130 | |
131 | 131 | /* skip bad dir name - by length */ |
132 | 132 | len = strlen(entry->d_name); |
133 | - // TODO ("UUID dirname len = %d, %s\n",len, entry->d_name); | |
134 | 133 | if (len != 36) return 0; |
135 | 134 | |
136 | - // TODO not enough?, add test cases for the bad dir name | |
137 | - | |
138 | 135 | /* Dir HIT */ |
139 | 136 | // TODO check the format |
140 | 137 | #ifndef __linux__ |
@@ -187,16 +184,16 @@ int getRmList(OPENPTS_CONFIG *conf, char * config_dir) { | ||
187 | 184 | |
188 | 185 | /* move to config dir */ |
189 | 186 | if ((chdir(conf->config_dir)) != 0) { |
190 | - ERROR( // TODO NLS | |
191 | - "Accessing config directory %s\n", conf->config_dir); | |
187 | + ERROR(NLS(MS_OPENPTS, OPENPTS_TARGET_CONFDIR_MISSING, | |
188 | + "Accessing config directory %s fail\n"), conf->config_dir); | |
192 | 189 | return PTS_INTERNAL_ERROR; |
193 | 190 | } |
194 | 191 | |
195 | 192 | /* scan dirs */ |
196 | 193 | dir_num = scandir(".", &dir_list, &selectUuidDir, NULL); |
197 | 194 | if ( dir_num == -1 ) { |
198 | - ERROR( // TODO NLS | |
199 | - "No target data.\n"); | |
195 | + ERROR(NLS(MS_OPENPTS, OPENPTS_TARGET_NULL, | |
196 | + "No target data.\n")); | |
200 | 197 | return PTS_INTERNAL_ERROR; |
201 | 198 | } |
202 | 199 |
@@ -269,7 +266,6 @@ int getRmList(OPENPTS_CONFIG *conf, char * config_dir) { | ||
269 | 266 | rmset1->dir = tmp_dir; |
270 | 267 | } |
271 | 268 | } |
272 | - // printRmList(conf); | |
273 | 269 | } |
274 | 270 | |
275 | 271 | /* set current_id */ |
@@ -319,8 +315,6 @@ int rmRmsetDir(char * dir) { | ||
319 | 315 | return PTS_FATAL; |
320 | 316 | } |
321 | 317 | |
322 | - | |
323 | - // DEBUG("rm -r %s\n", dir); | |
324 | 318 | snprintf(buf, BUF_SIZE, "rm -r %s\n", dir); |
325 | 319 | rc = system(buf); |
326 | 320 | if (rc < 0) { |
@@ -363,7 +357,6 @@ int purgeRenewedRm(OPENPTS_CONFIG *conf) { | ||
363 | 357 | state = rmset->state; |
364 | 358 | |
365 | 359 | if (state == OPENPTS_RM_STATE_TRASH) { |
366 | - // INFO(NLS(MS_OPENPTS, OPENPTS_PURGE_RENEWED_RM, " purge %s\n"), rmset->str_uuid); | |
367 | 360 | LOG(LOG_INFO, " purge %s\n", rmset->str_uuid); |
368 | 361 | rc = rmRmsetDir(rmset->dir); |
369 | 362 | if (rc != PTS_SUCCESS) { |
@@ -750,6 +743,38 @@ static void printTargetInfo_CompID(OPENPTS_CONTEXT *ctx, FILE *fp, int cnt) { | ||
750 | 743 | } |
751 | 744 | #endif |
752 | 745 | |
746 | +/** | |
747 | + * print one target | |
748 | + */ | |
749 | +void printTarget( | |
750 | + OPENPTS_TARGET *target_collector, | |
751 | + char *indent) { | |
752 | + | |
753 | + OPENPTS_CONFIG *target_conf; | |
754 | + | |
755 | + /* check */ | |
756 | + if (target_collector == NULL) { | |
757 | + LOG(LOG_ERR, "null input"); | |
758 | + return; | |
759 | + } | |
760 | + target_conf = (OPENPTS_CONFIG*)target_collector->target_conf; | |
761 | + if (target_conf == NULL) { | |
762 | + LOG(LOG_ERR, "null input"); | |
763 | + return; | |
764 | + } | |
765 | + | |
766 | + // WORK NEEDED: Please use NLS for i18n output | |
767 | + OUTPUT("%shostname : %s\n", indent, target_conf->hostname); | |
768 | + OUTPUT("%sssh username : %s\n", indent, target_conf->ssh_username); | |
769 | + OUTPUT("%ssh port : %s\n", indent, target_conf->ssh_port); | |
770 | + OUTPUT("%sUUID : %s\n", indent, target_collector->str_uuid); | |
771 | + OUTPUT("%sState : %d\n", indent, target_collector->state); | |
772 | + OUTPUT("%sDir : %s\n", indent, target_collector->dir); | |
773 | + OUTPUT("%sManifests :\n", indent); | |
774 | + | |
775 | + getRmList(target_conf, target_conf->config_dir); | |
776 | + printRmList(target_conf, indent); | |
777 | +} | |
753 | 778 | |
754 | 779 | /** |
755 | 780 | * print target list, target par line |
@@ -775,8 +800,8 @@ void printTargetList(OPENPTS_CONFIG *conf, char *indent) { | ||
775 | 800 | num = conf->target_list->target_num; |
776 | 801 | |
777 | 802 | if (num == 0) { |
778 | - OUTPUT( // TODO NLS | |
779 | - "There is no enrolled target platform.\n"); | |
803 | + OUTPUT(NLS(MS_OPENPTS, OPENPTS_PRINT_TARGET_LIST_NULL, | |
804 | + "There is no enrolled target platform.\n")); | |
780 | 805 | return; |
781 | 806 | } |
782 | 807 |
@@ -26,9 +26,8 @@ | ||
26 | 26 | * \brief create pseudo IML of tboot, standalone tool |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2011-03-28 |
29 | - * cleanup 2011-07-06 SM | |
30 | - * refactoring | |
31 | - * | |
29 | + * cleanup 2012-01-05 SM (remains 33 lint errors, ignore) | |
30 | + * src/tboot2iml.c:184: Tab found; better to use spaces [whitespace/tab] [1] | |
32 | 31 | * |
33 | 32 | * Test |
34 | 33 | * |
@@ -1158,7 +1157,7 @@ int generateEventlog(OPENPTS_TBOOT_CONTEXT *ctx, char *filename) { | ||
1158 | 1157 | |
1159 | 1158 | |
1160 | 1159 | void usage(void) { |
1161 | - OUTPUT( // TODO NLS | |
1160 | + OUTPUT(NLS(MS_OPENPTS, OPENPTS_TBOOT2IML_USAGE, | |
1162 | 1161 | "OpenPTS command\n\n" |
1163 | 1162 | "Usage: tboot2iml [options]\n\n" |
1164 | 1163 | "Options:\n" |
@@ -1168,7 +1167,7 @@ void usage(void) { | ||
1168 | 1167 | " -o filename Output to file (default is STDOUT)\n" |
1169 | 1168 | " -v Verbose message\n" |
1170 | 1169 | " -h Help\n" |
1171 | - "\n"); | |
1170 | + "\n")); | |
1172 | 1171 | } |
1173 | 1172 | |
1174 | 1173 | int main(int argc, char *argv[]) { |
@@ -1209,8 +1208,8 @@ int main(int argc, char *argv[]) { | ||
1209 | 1208 | |
1210 | 1209 | /* check */ |
1211 | 1210 | if ((grub_conf_filename != NULL) && (grub_path == NULL)) { |
1212 | - ERROR( // TODO NLS | |
1213 | - "set the root path used by crub.conf\n"); | |
1211 | + ERROR(NLS(MS_OPENPTS, OPENPTS_TBOOT2IML_GRUBPATH_MISSING, | |
1212 | + "set the root path used by grub.conf\n")); | |
1214 | 1213 | usage(); |
1215 | 1214 | goto close; |
1216 | 1215 | } |
@@ -26,7 +26,7 @@ | ||
26 | 26 | * \brief emulate TPM |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2010-04-01 |
29 | - * cleanup 2011-12-31 SM | |
29 | + * cleanup 2012-01-05 SM | |
30 | 30 | * |
31 | 31 | * Emulate TPM to validate IML and PCR |
32 | 32 | */ |
@@ -46,8 +46,7 @@ | ||
46 | 46 | |
47 | 47 | #include <openpts.h> |
48 | 48 | |
49 | - | |
50 | -/* TPM functions */ | |
49 | +/* TPM functions -------------------------------------------------------------*/ | |
51 | 50 | |
52 | 51 | /** |
53 | 52 | * reset TPM |
@@ -333,5 +332,3 @@ int getTpmPcrValue(OPENPTS_TPM_CONTEXT *tpm, int index, BYTE *digest) { | ||
333 | 332 | |
334 | 333 | return PTS_SUCCESS; |
335 | 334 | } |
336 | - | |
337 | - |
@@ -27,7 +27,7 @@ | ||
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2010-08-18 |
29 | 29 | * refactoring 2011-02-15 SM |
30 | - * cleanup 2012-01-02 SM | |
30 | + * cleanup 2012-01-05 SM | |
31 | 31 | * |
32 | 32 | * Create Sign Key |
33 | 33 | * Create AIK |
@@ -87,8 +87,7 @@ int createTssSignKey( | ||
87 | 87 | char *filename, |
88 | 88 | int auth_type, |
89 | 89 | int force, |
90 | - int srk_password_mode) | |
91 | -{ | |
90 | + int srk_password_mode) { | |
92 | 91 | /* dummy */ |
93 | 92 | return TSS_SUCCESS; |
94 | 93 | } |
@@ -96,8 +95,7 @@ int createTssSignKey( | ||
96 | 95 | int deleteTssKey( |
97 | 96 | PTS_UUID *uuid, |
98 | 97 | int key_storage_type, |
99 | - char *filename) | |
100 | -{ | |
98 | + char *filename) { | |
101 | 99 | /* dummy */ |
102 | 100 | return TSS_SUCCESS; |
103 | 101 | } |
@@ -120,8 +118,7 @@ int getTssPubKey( | ||
120 | 118 | int resetdalock, |
121 | 119 | char *filename, |
122 | 120 | int auth_type, |
123 | - int *pubkey_length, BYTE **pubkey) | |
124 | -{ | |
121 | + int *pubkey_length, BYTE **pubkey) { | |
125 | 122 | /* dummy */ |
126 | 123 | return TSS_SUCCESS; |
127 | 124 | } |
@@ -134,8 +131,7 @@ int quoteTss( | ||
134 | 131 | int auth_type, |
135 | 132 | BYTE *nonce, |
136 | 133 | OPENPTS_PCRS *pcrs, |
137 | - TSS_VALIDATION *validationData) | |
138 | -{ | |
134 | + TSS_VALIDATION *validationData) { | |
139 | 135 | /* dummy */ |
140 | 136 | return TSS_SUCCESS; |
141 | 137 | } |
@@ -148,8 +144,7 @@ int quote2Tss( | ||
148 | 144 | int auth_type, |
149 | 145 | BYTE *nonce, |
150 | 146 | OPENPTS_PCRS *pcrs, |
151 | - TSS_VALIDATION *validationData) | |
152 | -{ | |
147 | + TSS_VALIDATION *validationData) { | |
153 | 148 | /* dummy */ |
154 | 149 | return TSS_SUCCESS; |
155 | 150 | } |
@@ -267,6 +262,7 @@ int getTpmStatus(TSS_FLAG flag, TSS_BOOL *value, int tpm_password_mode) { | ||
267 | 262 | |
268 | 263 | close: |
269 | 264 | /* Close TSS/TPM */ |
265 | + Tspi_Context_FreeMemory(hContext, NULL); | |
270 | 266 | Tspi_Context_Close(hContext); |
271 | 267 | return result; |
272 | 268 | } |
@@ -358,6 +354,7 @@ int setTpmStatus(TSS_FLAG flag, TSS_BOOL value, int tpm_password_mode) { | ||
358 | 354 | |
359 | 355 | close: |
360 | 356 | /* Close TSS/TPM */ |
357 | + Tspi_Context_FreeMemory(hContext, NULL); | |
361 | 358 | Tspi_Context_Close(hContext); |
362 | 359 | return result; |
363 | 360 | } |
@@ -374,7 +371,8 @@ int printTssKeyList(int ps_type) { | ||
374 | 371 | UINT32 ulKeyHierarchySize; |
375 | 372 | TSS_UUID SRK_UUID = TSS_UUID_SRK; |
376 | 373 | int i; |
377 | - TSS_KM_KEYINFO *info = NULL; | |
374 | + TSS_KM_KEYINFO *ppKeyHierarchy = NULL; | |
375 | + TSS_KM_KEYINFO *info; | |
378 | 376 | |
379 | 377 | /* Open TSS */ |
380 | 378 | result = Tspi_Context_Create(&hContext); |
@@ -400,7 +398,7 @@ int printTssKeyList(int ps_type) { | ||
400 | 398 | (UINT32) ps_type, // TSS_PS_TYPE_SYSTEM, |
401 | 399 | &SRK_UUID, |
402 | 400 | &ulKeyHierarchySize, |
403 | - &info); | |
401 | + &ppKeyHierarchy); | |
404 | 402 | if (result == 0x3020) { // TSS_E_PS_KEY_NOTFOUND |
405 | 403 | OUTPUT(NLS(MS_OPENPTS, OPENPTS_TPM_TSS_KEY_NOTFOUND, |
406 | 404 | "The key cannot be found in the persistent storage database.\n")); |
@@ -411,9 +409,9 @@ int printTssKeyList(int ps_type) { | ||
411 | 409 | goto close; |
412 | 410 | } |
413 | 411 | |
412 | + info = ppKeyHierarchy; // save for move | |
414 | 413 | OUTPUT(NLS(MS_OPENPTS, OPENPTS_TPM_TSS_KEY_NUM, "Key number: %d\n"), ulKeyHierarchySize); |
415 | 414 | for (i = 0; i < (int)ulKeyHierarchySize; i++) { |
416 | - //OUTPUT(NLS(MS_OPENPTS, OPENPTS_TPM_TSS_KEY, "Key %d\n"), i); | |
417 | 415 | OUTPUT("id : %d\n", i); |
418 | 416 | OUTPUT("version : %d %d %d %d\n", |
419 | 417 | info->versionInfo.bMajor, |
@@ -435,8 +433,17 @@ int printTssKeyList(int ps_type) { | ||
435 | 433 | info = info + 1; |
436 | 434 | } |
437 | 435 | |
436 | + /* free key info */ | |
437 | + result = Tspi_Context_FreeMemory(hContext, (BYTE *)ppKeyHierarchy); | |
438 | + if (result != TSS_SUCCESS) { | |
439 | + LOG(LOG_ERR, "Tspi_Context_FreeMemory failed rc=0x%x\n", | |
440 | + result); | |
441 | + // 0x313a TSS_E_INVALID_RESOURCE | |
442 | + } | |
443 | + | |
438 | 444 | close: |
439 | 445 | /* Close TSS/TPM */ |
446 | + Tspi_Context_FreeMemory(hContext, NULL); | |
440 | 447 | Tspi_Context_Close(hContext); |
441 | 448 | |
442 | 449 | return result; |
@@ -459,8 +466,9 @@ int createTssSignKey( | ||
459 | 466 | char *filename, |
460 | 467 | int auth_type, |
461 | 468 | int force, |
462 | - int srk_password_mode) | |
463 | -{ | |
469 | + int srk_password_mode) { | |
470 | + int i; | |
471 | + int srk_auth_len = 0; | |
464 | 472 | TSS_RESULT result = 0; |
465 | 473 | TSS_HCONTEXT hContext; |
466 | 474 | TSS_HTPM hTPM; |
@@ -469,12 +477,10 @@ int createTssSignKey( | ||
469 | 477 | TSS_HPOLICY hSRKPolicy; |
470 | 478 | UINT32 srk_auth_mode = TSS_SECRET_MODE_PLAIN; |
471 | 479 | BYTE *srk_auth; |
472 | - int srk_auth_len = 0; | |
473 | 480 | TSS_HKEY hKey; |
474 | 481 | UINT32 keyLength; |
475 | 482 | BYTE *keyBlob; |
476 | 483 | TSS_HPOLICY hKeyPolicy; |
477 | - int i; | |
478 | 484 | TSS_UUID tss_uuid; |
479 | 485 | |
480 | 486 | /* check */ |
@@ -646,8 +652,8 @@ int createTssSignKey( | ||
646 | 652 | FILE *fp; |
647 | 653 | |
648 | 654 | fp = fopen(filename, "w"); |
649 | - if (fp==NULL) { | |
650 | - LOG(LOG_ERR, "file open fail, key blob file is %s",filename); | |
655 | + if (fp == NULL) { | |
656 | + LOG(LOG_ERR, "file open fail, key blob file is %s", filename); | |
651 | 657 | result = TSS_E_KEY_NOT_LOADED; |
652 | 658 | goto close; |
653 | 659 | } |
@@ -690,7 +696,7 @@ int createTssSignKey( | ||
690 | 696 | TSS_HKEY hKey; |
691 | 697 | result = Tspi_Context_UnregisterKey( |
692 | 698 | hContext, |
693 | - (UINT32)key_storage_type, //TSS_PS_TYPE_SYSTEM, | |
699 | + (UINT32)key_storage_type, // TSS_PS_TYPE_SYSTEM, | |
694 | 700 | tss_uuid, |
695 | 701 | &hKey); |
696 | 702 | if (result != TSS_SUCCESS) { |
@@ -718,6 +724,7 @@ int createTssSignKey( | ||
718 | 724 | |
719 | 725 | close: |
720 | 726 | /* Close TSS/TPM */ |
727 | + Tspi_Context_FreeMemory(hContext, NULL); | |
721 | 728 | Tspi_Context_Close(hContext); |
722 | 729 | |
723 | 730 | return result; |
@@ -802,6 +809,7 @@ int deleteTssKey(PTS_UUID *uuid, int key_storage_type, char *filename) { | ||
802 | 809 | |
803 | 810 | close: |
804 | 811 | /* Close TSS/TPM */ |
812 | + Tspi_Context_FreeMemory(hContext, NULL); | |
805 | 813 | Tspi_Context_Close(hContext); |
806 | 814 | |
807 | 815 | return result; |
@@ -823,8 +831,8 @@ int getTssPubKey( | ||
823 | 831 | int resetdalock, |
824 | 832 | char *filename, |
825 | 833 | int auth_type, |
826 | - int *pubkey_length, BYTE **pubkey) | |
827 | -{ | |
834 | + int *pubkey_length, BYTE **pubkey) { | |
835 | + int srk_auth_len = 0; | |
828 | 836 | TSS_RESULT result = 0; |
829 | 837 | TSS_HCONTEXT hContext; |
830 | 838 | TSS_HKEY hKey; |
@@ -835,7 +843,6 @@ int getTssPubKey( | ||
835 | 843 | TSS_UUID SRK_UUID = TSS_UUID_SRK; |
836 | 844 | UINT32 srk_auth_mode = TSS_SECRET_MODE_PLAIN; |
837 | 845 | BYTE *srk_auth; |
838 | - int srk_auth_len = 0; | |
839 | 846 | TSS_HPOLICY hKeyPolicy; |
840 | 847 | |
841 | 848 | /* check */ |
@@ -938,8 +945,8 @@ int getTssPubKey( | ||
938 | 945 | int len; |
939 | 946 | |
940 | 947 | fp = fopen(filename, "r"); |
941 | - if (fp==NULL) { | |
942 | - LOG(LOG_ERR, "file open fail, key blob file is %s",filename); | |
948 | + if (fp == NULL) { | |
949 | + LOG(LOG_ERR, "file open fail, key blob file is %s", filename); | |
943 | 950 | result = TSS_E_KEY_NOT_LOADED; |
944 | 951 | goto close; |
945 | 952 | } |
@@ -962,7 +969,7 @@ int getTssPubKey( | ||
962 | 969 | /* TSS PS*/ |
963 | 970 | result = Tspi_Context_LoadKeyByUUID( |
964 | 971 | hContext, |
965 | - (UINT32)key_storage_type, //TSS_PS_TYPE_SYSTEM, | |
972 | + (UINT32)key_storage_type, // TSS_PS_TYPE_SYSTEM, | |
966 | 973 | tss_uuid, |
967 | 974 | &hKey); |
968 | 975 | if (result == 0x803) { |
@@ -1127,6 +1134,7 @@ int getTpmVersion(TSS_VERSION *version) { | ||
1127 | 1134 | |
1128 | 1135 | /* Close TSS/TPM */ |
1129 | 1136 | close: |
1137 | + Tspi_Context_FreeMemory(hContext, NULL); | |
1130 | 1138 | Tspi_Context_Close(hContext); |
1131 | 1139 | |
1132 | 1140 | return rc; |
@@ -1150,6 +1158,9 @@ int quoteTss( | ||
1150 | 1158 | OPENPTS_PCRS *pcrs, |
1151 | 1159 | /* Output */ |
1152 | 1160 | TSS_VALIDATION *validationData) { |
1161 | + int i; | |
1162 | + int srk_auth_len = 0; | |
1163 | + int pcrSelectCount = 0; | |
1153 | 1164 | TSS_RESULT result; |
1154 | 1165 | TSS_HCONTEXT hContext; |
1155 | 1166 | TSS_HTPM hTPM; |
@@ -1158,22 +1169,17 @@ int quoteTss( | ||
1158 | 1169 | TSS_UUID SRK_UUID = TSS_UUID_SRK; |
1159 | 1170 | UINT32 srk_auth_mode = TSS_SECRET_MODE_PLAIN; |
1160 | 1171 | BYTE *srk_auth = NULL; |
1161 | - int srk_auth_len = 0; | |
1162 | - | |
1163 | 1172 | TSS_HKEY hKey; |
1164 | 1173 | TSS_HPOLICY hKeyPolicy; |
1165 | 1174 | TSS_UUID tss_uuid; |
1166 | 1175 | TSS_HPCRS hPcrComposite; |
1167 | 1176 | TSS_VALIDATION validation_data; // local |
1168 | - int i; | |
1169 | 1177 | UINT32 ulSubCapLength; |
1170 | 1178 | UINT32 rgbSubCap; |
1171 | 1179 | UINT32 pulRespDataLength; |
1172 | 1180 | BYTE *prgbRespData; |
1173 | 1181 | UINT32 pcrnum; |
1174 | 1182 | |
1175 | - int pcrSelectCount = 0; | |
1176 | - | |
1177 | 1183 | /* UUID */ |
1178 | 1184 | memcpy(&tss_uuid, uuid, sizeof(TSS_UUID)); |
1179 | 1185 |
@@ -1319,8 +1325,8 @@ int quoteTss( | ||
1319 | 1325 | int len; |
1320 | 1326 | |
1321 | 1327 | fp = fopen(filename, "r"); |
1322 | - if (fp==NULL) { | |
1323 | - LOG(LOG_ERR, "file open fail, key blob file is %s",filename); | |
1328 | + if (fp == NULL) { | |
1329 | + LOG(LOG_ERR, "file open fail, key blob file is %s", filename); | |
1324 | 1330 | result = TSS_E_KEY_NOT_LOADED; |
1325 | 1331 | goto close; |
1326 | 1332 | } |
@@ -1545,36 +1551,31 @@ int quote2Tss( | ||
1545 | 1551 | /* PCR selection */ |
1546 | 1552 | OPENPTS_PCRS *pcrs, |
1547 | 1553 | /* Output */ |
1548 | - TSS_VALIDATION *validationData) | |
1549 | -{ | |
1554 | + TSS_VALIDATION *validationData) { | |
1555 | + int i; | |
1556 | + int srk_auth_len = 0; | |
1557 | + int pcrSelectCount = 0; | |
1550 | 1558 | TSS_RESULT result; |
1551 | 1559 | TSS_HCONTEXT hContext; |
1552 | 1560 | TSS_HTPM hTPM; |
1553 | 1561 | TSS_HKEY hSRK; |
1554 | 1562 | TSS_HPOLICY hSRKPolicy; |
1555 | 1563 | TSS_UUID SRK_UUID = TSS_UUID_SRK; |
1556 | - | |
1557 | 1564 | UINT32 srk_auth_mode = TSS_SECRET_MODE_PLAIN; |
1558 | 1565 | BYTE *srk_auth; |
1559 | - int srk_auth_len = 0; | |
1560 | - | |
1561 | 1566 | TSS_HKEY hKey; |
1562 | 1567 | TSS_HPOLICY hKeyPolicy; |
1563 | 1568 | TSS_UUID tss_uuid; |
1564 | 1569 | TSS_HPCRS hPcrComposite; |
1565 | 1570 | TSS_VALIDATION validation_data; // local |
1566 | - int i; | |
1567 | 1571 | UINT32 ulSubCapLength; |
1568 | 1572 | UINT32 rgbSubCap; |
1569 | 1573 | UINT32 pulRespDataLength; |
1570 | 1574 | BYTE *prgbRespData; |
1571 | 1575 | UINT32 pcrnum; |
1572 | - | |
1573 | 1576 | UINT32 versionInfoSize; |
1574 | 1577 | BYTE* versionInfo; |
1575 | 1578 | |
1576 | - int pcrSelectCount = 0; | |
1577 | - | |
1578 | 1579 | /* UUID */ |
1579 | 1580 | // uuit_t -> TSS_UUID |
1580 | 1581 | memcpy(&tss_uuid, uuid, sizeof(TSS_UUID)); |
@@ -1664,7 +1665,7 @@ int quote2Tss( | ||
1664 | 1665 | /* Get SRK handles */ |
1665 | 1666 | result = Tspi_Context_LoadKeyByUUID( |
1666 | 1667 | hContext, |
1667 | - TSS_PS_TYPE_SYSTEM, // SRK in PS_SYSTEM | |
1668 | + TSS_PS_TYPE_SYSTEM, // SRK in PS_SYSTEM | |
1668 | 1669 | SRK_UUID, |
1669 | 1670 | &hSRK); |
1670 | 1671 | if (result != TSS_SUCCESS) { |
@@ -1722,8 +1723,8 @@ int quote2Tss( | ||
1722 | 1723 | int len; |
1723 | 1724 | |
1724 | 1725 | fp = fopen(filename, "r"); |
1725 | - if (fp==NULL) { | |
1726 | - LOG(LOG_ERR, "file open fail, key blob file is %s",filename); | |
1726 | + if (fp == NULL) { | |
1727 | + LOG(LOG_ERR, "file open fail, key blob file is %s", filename); | |
1727 | 1728 | result = TSS_E_KEY_NOT_LOADED; |
1728 | 1729 | goto close; |
1729 | 1730 | } |
@@ -1748,7 +1749,7 @@ int quote2Tss( | ||
1748 | 1749 | /* load from TSS's PS */ |
1749 | 1750 | result = Tspi_Context_LoadKeyByUUID( |
1750 | 1751 | hContext, |
1751 | - key_storage_type, // TSS_PS_TYPE_SYSTEM, | |
1752 | + key_storage_type, // TSS_PS_TYPE_SYSTEM, | |
1752 | 1753 | tss_uuid, |
1753 | 1754 | &hKey); |
1754 | 1755 | if (result != TSS_SUCCESS) { |
@@ -2084,6 +2085,7 @@ int extendEvent(TSS_PCR_EVENT* event) { | ||
2084 | 2085 | |
2085 | 2086 | close: |
2086 | 2087 | /* Close TSS/TPM */ |
2088 | + Tspi_Context_FreeMemory(hContext, NULL); | |
2087 | 2089 | Tspi_Context_Close(hContext); |
2088 | 2090 | return result; |
2089 | 2091 | } |
@@ -2138,6 +2140,7 @@ int readPcr(int pcr_index, BYTE *pcr) { | ||
2138 | 2140 | |
2139 | 2141 | close: |
2140 | 2142 | /* Close TSS/TPM */ |
2143 | + Tspi_Context_FreeMemory(hContext, NULL); | |
2141 | 2144 | Tspi_Context_Close(hContext); |
2142 | 2145 | return result; |
2143 | 2146 | } |
@@ -2163,8 +2166,7 @@ int readPcr(int pcr_index, BYTE *pcr) { | ||
2163 | 2166 | */ |
2164 | 2167 | int validateQuoteData( |
2165 | 2168 | OPENPTS_PCRS *pcrs, |
2166 | - TSS_VALIDATION *validationData) | |
2167 | -{ | |
2169 | + TSS_VALIDATION *validationData) { | |
2168 | 2170 | int rc = PTS_VERIFY_FAILED; |
2169 | 2171 | int message_length; |
2170 | 2172 | BYTE *message; |
@@ -2331,18 +2333,17 @@ int validateQuoteData( | ||
2331 | 2333 | */ |
2332 | 2334 | int validatePcrCompositeV11( |
2333 | 2335 | OPENPTS_PCRS *pcrs, |
2334 | - TSS_VALIDATION *validationData) | |
2335 | -{ | |
2336 | + TSS_VALIDATION *validationData) { | |
2336 | 2337 | int rc = PTS_VERIFY_FAILED; |
2337 | 2338 | int i; |
2338 | 2339 | int buf_len; |
2340 | + int count = 0; | |
2341 | + int value_size; | |
2339 | 2342 | BYTE *buf; |
2340 | 2343 | BYTE *ptr; |
2341 | 2344 | SHA_CTX ctx; |
2342 | 2345 | BYTE digest[20]; |
2343 | 2346 | UINT16 mask = 0; |
2344 | - int count = 0; | |
2345 | - int value_size; | |
2346 | 2347 | |
2347 | 2348 | /* check */ |
2348 | 2349 | if (validationData == NULL) { |
@@ -2463,20 +2464,19 @@ int validatePcrCompositeV11( | ||
2463 | 2464 | */ |
2464 | 2465 | int validatePcrCompositeV12( |
2465 | 2466 | OPENPTS_PCRS *pcrs, |
2466 | - TSS_VALIDATION *validationData) | |
2467 | -{ | |
2467 | + TSS_VALIDATION *validationData) { | |
2468 | 2468 | int rc = PTS_VERIFY_FAILED; |
2469 | 2469 | int i; |
2470 | 2470 | int buf_len; |
2471 | + int count = 0; | |
2472 | + int value_size; | |
2473 | + int pcrsel_size; | |
2474 | + int loc = 0; | |
2471 | 2475 | BYTE *buf; |
2472 | 2476 | BYTE *ptr; |
2473 | 2477 | SHA_CTX ctx; |
2474 | 2478 | BYTE digest[20]; |
2475 | 2479 | UINT32 mask = 0; |
2476 | - int count = 0; | |
2477 | - int value_size; | |
2478 | - int pcrsel_size; | |
2479 | - int loc = 0; | |
2480 | 2480 | BYTE *composit_hash; |
2481 | 2481 | |
2482 | 2482 | /* check */ |
@@ -2607,5 +2607,3 @@ int validatePcrCompositeV12( | ||
2607 | 2607 | |
2608 | 2608 | return rc; |
2609 | 2609 | } |
2610 | - | |
2611 | - |
@@ -26,7 +26,7 @@ | ||
26 | 26 | * \brief UML2 State Diagram |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2010-04-01 |
29 | - * cleanup 2011-01-21 SM | |
29 | + * cleanup 2012-01-05 SM | |
30 | 30 | * |
31 | 31 | * UML State Diagram (XMI2.1, Eclipse MDT) -> DOT (Graphviz) Utility |
32 | 32 | */ |
@@ -47,10 +47,8 @@ | ||
47 | 47 | #include <tss/tspi.h> |
48 | 48 | |
49 | 49 | #include <openpts.h> |
50 | -// #include <log.h> | |
51 | 50 | |
52 | 51 | /* |
53 | - | |
54 | 52 | UML |
55 | 53 | <subvertex xmi:type="uml:State" xmi:id="Kk02PKa3" name="CRTM_START" visibility="public"> |
56 | 54 | <doActivity xmi:type="uml:Activity" xmi:id="_OzCawRyrEd6jytZ7WXwL3w" name="resetPCR(0)"/> |
@@ -82,11 +80,16 @@ DOT | ||
82 | 80 | /** |
83 | 81 | * startDocument of SAX parser |
84 | 82 | */ |
85 | -void uml2sax_startDocument(void * fctx) { | |
83 | +void uml2sax_startDocument(void * fctx) { | |
86 | 84 | OPENPTS_FSM_CONTEXT *ctx; |
87 | 85 | |
88 | 86 | DEBUG_CAL("startDocument - start\n"); |
89 | 87 | |
88 | + /* check */ | |
89 | + if (fctx == NULL) { | |
90 | + LOG(LOG_ERR, "null input"); | |
91 | + return; | |
92 | + } | |
90 | 93 | ctx = (OPENPTS_FSM_CONTEXT *)fctx; |
91 | 94 | ctx->error = 0; |
92 | 95 |
@@ -99,9 +102,14 @@ void uml2sax_startDocument(void * fctx) { | ||
99 | 102 | /** |
100 | 103 | * endDocument of SAX parser |
101 | 104 | */ |
102 | -void uml2sax_endDocument(void * fctx) { | |
105 | +void uml2sax_endDocument(void * fctx) { | |
103 | 106 | OPENPTS_FSM_CONTEXT *ctx; |
104 | 107 | |
108 | + /* check */ | |
109 | + if (fctx == NULL) { | |
110 | + LOG(LOG_ERR, "null input"); | |
111 | + return; | |
112 | + } | |
105 | 113 | ctx = (OPENPTS_FSM_CONTEXT *)fctx; |
106 | 114 | |
107 | 115 | /* set start state */ |
@@ -127,14 +135,23 @@ char doActivityName[FSM_BUF_SIZE]; /**< move to ctx */ | ||
127 | 135 | /** |
128 | 136 | * startElement of SAX parser |
129 | 137 | */ |
130 | -void uml2sax_startElement(void* fctx, const xmlChar* name, | |
138 | +void uml2sax_startElement(void* fctx, const xmlChar* name, | |
131 | 139 | const xmlChar** atts) { |
132 | 140 | OPENPTS_FSM_CONTEXT *ctx; |
133 | 141 | int i; |
134 | 142 | char *type; |
135 | 143 | char *value; |
136 | 144 | |
145 | + /* check */ | |
146 | + if (fctx == NULL) { | |
147 | + LOG(LOG_ERR, "null input"); | |
148 | + return; | |
149 | + } | |
137 | 150 | ctx = (OPENPTS_FSM_CONTEXT *)fctx; |
151 | + if (name == NULL) { | |
152 | + LOG(LOG_ERR, "null input"); | |
153 | + return; | |
154 | + } | |
138 | 155 | |
139 | 156 | // DEBUG_SAX("startElement - \n"); |
140 | 157 |
@@ -240,7 +257,16 @@ void uml2sax_startElement(void* fctx, const xmlChar* name, | ||
240 | 257 | void uml2sax_endElement(void * fctx, const xmlChar * name) { |
241 | 258 | OPENPTS_FSM_CONTEXT *ctx; |
242 | 259 | |
260 | + /* check */ | |
261 | + if (fctx == NULL) { | |
262 | + LOG(LOG_ERR, "null input"); | |
263 | + return; | |
264 | + } | |
243 | 265 | ctx = (OPENPTS_FSM_CONTEXT *)fctx; |
266 | + if (name == NULL) { | |
267 | + LOG(LOG_ERR, "null input"); | |
268 | + return; | |
269 | + } | |
244 | 270 | |
245 | 271 | if (!strcmp((char *)name, "subvertex")) { |
246 | 272 | addFsmSubvertex(ctx, subvertexXmiType, subvertexXmiId, subvertexName, doActivityName); |
@@ -268,7 +294,16 @@ void uml2sax_characters(void* fctx, const xmlChar * ch, int len) { | ||
268 | 294 | OPENPTS_FSM_CONTEXT *ctx; |
269 | 295 | char buf[FSM_BUF_SIZE]; |
270 | 296 | |
297 | + /* check */ | |
298 | + if (fctx == NULL) { | |
299 | + LOG(LOG_ERR, "null input"); | |
300 | + return; | |
301 | + } | |
271 | 302 | ctx = (OPENPTS_FSM_CONTEXT *)fctx; |
303 | + if ((len > 0) && (ch == NULL)) { | |
304 | + LOG(LOG_ERR, "null input"); | |
305 | + return; | |
306 | + } | |
272 | 307 | |
273 | 308 | if (len < FSM_BUF_SIZE) { |
274 | 309 | memcpy(buf, ch, len); |
@@ -300,15 +335,23 @@ int readUmlModel(OPENPTS_FSM_CONTEXT * ctx, char *umlfile) { | ||
300 | 335 | xmlSAXHandler sax_handler; |
301 | 336 | int rc; |
302 | 337 | |
338 | + /* check */ | |
339 | + if (ctx == NULL) { | |
340 | + LOG(LOG_ERR, "null input"); | |
341 | + return PTS_FATAL; | |
342 | + } | |
343 | + if (umlfile == NULL) { | |
344 | + LOG(LOG_ERR, "null input"); | |
345 | + return PTS_FATAL; | |
346 | + } | |
347 | + | |
303 | 348 | memset(&sax_handler, 0, sizeof(xmlSAXHandler)); |
304 | 349 | |
305 | 350 | sax_handler.startDocument = uml2sax_startDocument; |
306 | - sax_handler.endDocument = uml2sax_endDocument; | |
307 | - | |
308 | - sax_handler.startElement = uml2sax_startElement; | |
309 | - sax_handler.endElement = uml2sax_endElement; | |
310 | - | |
311 | - sax_handler.characters = uml2sax_characters; | |
351 | + sax_handler.endDocument = uml2sax_endDocument; | |
352 | + sax_handler.startElement = uml2sax_startElement; | |
353 | + sax_handler.endElement = uml2sax_endElement; | |
354 | + sax_handler.characters = uml2sax_characters; | |
312 | 355 | |
313 | 356 | /* read UML */ |
314 | 357 |
@@ -26,6 +26,7 @@ | ||
26 | 26 | * \brief Utility, generate dot file from UML2 state siagram |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2010-04-01 |
29 | + * cleanup 2012-01-05 SM | |
29 | 30 | * |
30 | 31 | * UML State Diagram -> DOT --(graphviz)--> Graph(PNG,JPG etc) |
31 | 32 | * |
@@ -44,17 +45,16 @@ | ||
44 | 45 | #include <fcntl.h> |
45 | 46 | |
46 | 47 | #include <openpts.h> |
47 | -// #include <log.h> | |
48 | 48 | |
49 | 49 | /** |
50 | 50 | * usage |
51 | 51 | */ |
52 | 52 | void usage(void) { |
53 | 53 | OUTPUT(NLS(MS_OPENPTS, OPENPTS_UML2DOT_USAGE, |
54 | - "usage: uml2dot [options] UMLfile \n" | |
55 | - "\t-o output\tset output file (default is stdout)\n" | |
56 | - "\t$ dot -Tpng foo.dot -o foo.png; eog foo.png\n" | |
57 | - "\n")); | |
54 | + "usage: uml2dot [options] UMLfile \n" | |
55 | + "\t-o output\tset output file (default is stdout)\n" | |
56 | + "\t$ dot -Tpng foo.dot -o foo.png; eog foo.png\n" | |
57 | + "\n")); | |
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -67,6 +67,7 @@ int main(int argc, char *argv[]) { | ||
67 | 67 | char *input_filename = NULL; |
68 | 68 | char *output_filename = NULL; |
69 | 69 | |
70 | + /* logging/NLS */ | |
70 | 71 | initCatalog(); |
71 | 72 | |
72 | 73 | while ((c = getopt(argc, argv, "do:h")) != EOF) { |
@@ -89,7 +90,6 @@ int main(int argc, char *argv[]) { | ||
89 | 90 | input_filename = argv[0]; |
90 | 91 | |
91 | 92 | /* Read UML(XML) file */ |
92 | - | |
93 | 93 | if (input_filename == NULL) { |
94 | 94 | ERROR(NLS(MS_OPENPTS, OPENPTS_UML2DOT_MISSING_XML_FILE, "ERROR missing XMLfile\n")); |
95 | 95 | usage(); |
@@ -114,7 +114,6 @@ int main(int argc, char *argv[]) { | ||
114 | 114 | } |
115 | 115 | |
116 | 116 | error: |
117 | - | |
118 | 117 | freeFsmContext(ctx); |
119 | 118 | |
120 | 119 | return rc; |
@@ -26,7 +26,7 @@ | ||
26 | 26 | * \brief UUID wrapper (Generic part, OPENPTS_UUID) |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2010-11-29 |
29 | - * cleanup 2011-10-07 SM | |
29 | + * cleanup 2012-01-05 SM | |
30 | 30 | * |
31 | 31 | * Linux uses libuuid |
32 | 32 | * |
@@ -50,9 +50,6 @@ void uuid_from_string(unsigned_char_t *string_uuid, uuid_t *uuid, | ||
50 | 50 | #endif |
51 | 51 | |
52 | 52 | #include <openpts.h> |
53 | -#include <log.h> | |
54 | - | |
55 | - | |
56 | 53 | |
57 | 54 | #if UUIDSIZE < 16 |
58 | 55 | #error Insufficient space in PTS_UUID |
@@ -218,5 +215,3 @@ PTS_DateTime * getDateTimeOfUuid(PTS_UUID *uuid) { | ||
218 | 215 | |
219 | 216 | return pdt; |
220 | 217 | } |
221 | - | |
222 | - |
@@ -26,7 +26,7 @@ | ||
26 | 26 | * \brief TCG IF-M Verifier |
27 | 27 | * @author Seiji Munetoh <munetoh@users.sourceforge.jp> |
28 | 28 | * @date 2010-04-06 |
29 | - * cleanup 2011-07-20 SM | |
29 | + * cleanup 2012-01-04 SM | |
30 | 30 | * |
31 | 31 | */ |
32 | 32 |
@@ -50,7 +50,6 @@ | ||
50 | 50 | |
51 | 51 | #include <openpts.h> |
52 | 52 | |
53 | - | |
54 | 53 | /** |
55 | 54 | * Lock (POSIX 1003.1) |
56 | 55 | * type: |
@@ -85,17 +84,16 @@ void global_lock(int type) { | ||
85 | 84 | exit(1); |
86 | 85 | } |
87 | 86 | |
88 | - fl.l_start = 0; | |
89 | - fl.l_len = 0; | |
87 | + fl.l_start = 0; | |
88 | + fl.l_len = 0; | |
90 | 89 | fl.l_whence = SEEK_SET; |
91 | - fl.l_type = type; | |
92 | - fl.l_pid = getpid(); | |
93 | - //if (fcntl(fd, F_SETLKW, &fl) < 0) { | |
90 | + fl.l_type = type; | |
91 | + fl.l_pid = getpid(); | |
94 | 92 | if (fcntl(fd, F_SETLK, &fl) < 0) { |
95 | 93 | // get PID of the process holding that lock |
96 | 94 | fcntl(fd, F_GETLK, &fl); |
97 | - ERROR( // TODO NLS | |
98 | - "Openpts configulation is locked by other(pid=%d)\n", fl.l_pid); | |
95 | + ERROR(NLS(MS_OPENPTS, OPENPTS_VERIFIER_LOCKED, | |
96 | + "Openpts configulation is locked by other(pid=%d)\n"), fl.l_pid); | |
99 | 97 | exit(1); |
100 | 98 | } |
101 | 99 | } |
@@ -138,7 +136,7 @@ int getDefaultConfigfile(OPENPTS_CONFIG *conf) { | ||
138 | 136 | rc = mkdir(dirpath, S_IRUSR | S_IWUSR | S_IXUSR); |
139 | 137 | if (rc != 0) { |
140 | 138 | LOG(LOG_ERR, "mkdir on %s failed (errno=%d)", dirpath, errno); |
141 | - rc=PTS_FATAL; | |
139 | + rc = PTS_FATAL; | |
142 | 140 | goto error; |
143 | 141 | } |
144 | 142 | configDirExists = 1; |
@@ -156,7 +154,7 @@ int getDefaultConfigfile(OPENPTS_CONFIG *conf) { | ||
156 | 154 | rc = writeOpenptsUuidFile(conf->uuid, 1); |
157 | 155 | if (rc != PTS_SUCCESS) { |
158 | 156 | LOG(LOG_ERR, "Can't create UUID file, %s", uuid_file); |
159 | - rc=PTS_FATAL; | |
157 | + rc = PTS_FATAL; | |
160 | 158 | goto error; |
161 | 159 | } |
162 | 160 |
@@ -164,7 +162,7 @@ int getDefaultConfigfile(OPENPTS_CONFIG *conf) { | ||
164 | 162 | rc = writeOpenptsConf(conf, conf_file); |
165 | 163 | if (rc != PTS_SUCCESS) { |
166 | 164 | LOG(LOG_ERR, "Can't create config file, %s", conf_file); |
167 | - rc=PTS_FATAL; | |
165 | + rc = PTS_FATAL; | |
168 | 166 | goto error; |
169 | 167 | } |
170 | 168 | } |
@@ -574,8 +572,8 @@ int verifierHandleCapability( | ||
574 | 572 | */ |
575 | 573 | int verifierHandleRimmSet( |
576 | 574 | OPENPTS_CONTEXT *ctx, |
577 | - BYTE *value) | |
578 | -{ | |
575 | + BYTE *value) { | |
576 | + | |
579 | 577 | int rc = PTS_SUCCESS; |
580 | 578 | OPENPTS_CONFIG *target_conf; |
581 | 579 | int i; |
@@ -716,8 +714,7 @@ int writePolicyConf(OPENPTS_CONTEXT *ctx, char *filename) { | ||
716 | 714 | } else if (!strncmp(prop->name, "disable.", 8)) { |
717 | 715 | /* Indicates a disabled tpm quote - SKIP */ |
718 | 716 | } else if (prop->ignore == 1) { |
719 | - ERROR( // TODO NLS | |
720 | - "The property %s is conflicted and excluded from the policy.\n", prop->name); | |
717 | + DEBUG("The property %s is conflicted and excluded from the policy.\n", prop->name); | |
721 | 718 | } else { |
722 | 719 | fprintf(fp, "%s=%s\n", prop->name, prop->value); |
723 | 720 | i++; |
@@ -1469,7 +1466,6 @@ int verifier( | ||
1469 | 1466 | rc = PTS_INTERNAL_ERROR; |
1470 | 1467 | goto close; |
1471 | 1468 | } |
1472 | - // DEBUG("new read_tlv %p\n",read_tlv); | |
1473 | 1469 | |
1474 | 1470 | /* res -> fin */ |
1475 | 1471 | ctx->nonce->res->reserved[0] = read_tlv->value[0]; |