OSDN Git Service

f55402567e5bb3a0b97e623aebd4ad59eda1d9bd
[openpts/openpts.git] / src / collector.c
1 /*
2  * This file is part of the OpenPTS project.
3  *
4  * The Initial Developer of the Original Code is International
5  * Business Machines Corporation. Portions created by IBM
6  * Corporation are Copyright (C) 2010 International Business
7  * Machines Corporation. All Rights Reserved.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the Common Public License as published by
11  * IBM Corporation; either version 1 of the License, or (at your option)
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * Common Public License for more details.
18  *
19  * You should have received a copy of the Common Public License
20  * along with this program; if not, a copy can be viewed at
21  * http://www.opensource.org/licenses/cpl1.0.php.
22  */
23
24 /**
25  * \file src/collector.c
26  * \brief TCG IF-M collector functions
27  * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
28  * @date 2011-01-06
29  * cleanup 2011-07-20 SM
30  *
31  * move from ptscd.c 
32  *
33  */
34
35
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <netdb.h>
40 #include <errno.h>
41
42 #include <sys/types.h>
43 #include <sys/socket.h>
44 #include <netinet/in.h>
45 #include <arpa/inet.h>  // inet_ntoa
46 #include <unistd.h>
47
48 #include <signal.h>
49
50 #include <sys/stat.h>
51 #include <fcntl.h>
52
53 #include <openssl/sha.h>
54
55 #include <openpts.h>
56
57
58 /**
59  * print FSM info
60  */
61 void printFsmInfo(OPENPTS_CONTEXT *ctx, char * indent) {
62     int i;
63     OPENPTS_SNAPSHOT *ss;
64
65     printf("%sPCR lv  FSM files\n", indent);
66     printf("%s-----------------------------------------------------\n", indent);
67
68     for (i = 0; i < MAX_PCRNUM; i++) {
69         ss = getSnapshotFromTable(ctx->ss_table, i, 0);
70
71         if (ss != NULL) {
72             if (ss->fsm_behavior != NULL) {
73                 printf("%s%2d  0  ", indent, i);
74                 printf("%s\n", ss->fsm_behavior->uml_file);
75             }
76         }
77
78         /* level 1 */
79         ss = getSnapshotFromTable(ctx->ss_table, i, 1);
80         if (ss != NULL) {
81             if (ss->fsm_behavior != NULL) {
82                 printf("%s%2d  1  ", indent, i);
83                 printf("%s\n", ss->fsm_behavior->uml_file);
84             }
85         }
86     }
87     printf("%s-----------------------------------------------------\n", indent);
88 }
89
90 /**
91  * EV_COLLECTOR_START
92  *
93  *
94  * ./src/iml2text
95  *  154  11 0x00000080 f7412718d74b9292d33dedc9d946aad7afa5c11b [Unknown Event:size=56] 
96  */
97 int extendEvCollectorStart(OPENPTS_CONFIG *conf) {
98     TSS_PCR_EVENT* event;  // /usr/include/tss/tss_structs.h
99     OPENPTS_EVENT_COLLECTOR_START *collector_start;
100     BYTE pcr[SHA1_DIGEST_SIZE];
101     SHA_CTX sha_ctx;
102
103
104     /* malloc eventlog */
105     collector_start = malloc(sizeof(OPENPTS_EVENT_COLLECTOR_START));
106     event = malloc(sizeof(TSS_PCR_EVENT));
107
108     /*fill collector_start */
109     memcpy(&collector_start->pts_version, &conf->pts_version, 4);
110     memcpy(&collector_start->collector_uuid, conf->uuid->uuid, 16);
111     memcpy(&collector_start->manifest_uuid, conf->rm_uuid->uuid, 16);
112
113
114     /* get PCR value*/
115     // memcpy(&collector_start->pcr_value;make
116     readPcr(conf->openpts_pcr_index, pcr);
117     memcpy(&collector_start->pcr_value, pcr, SHA1_DIGEST_SIZE);
118
119
120     /* calc digest */
121     SHA1_Init(&sha_ctx);
122     SHA1_Update(
123         &sha_ctx,
124         collector_start,
125         sizeof(OPENPTS_EVENT_COLLECTOR_START));
126     SHA1_Final(pcr, &sha_ctx);
127
128     /* fill eventlog */
129     // event->versionInfo  // set by TSP?
130     event->ulPcrIndex = conf->openpts_pcr_index;  // set by TSP?
131     event->eventType = EV_COLLECTOR_START;  // openpts_tpm.h
132     event->ulPcrValueLength = SHA1_DIGEST_SIZE;
133     event->rgbPcrValue = pcr;
134     event->ulEventLength = sizeof(OPENPTS_EVENT_COLLECTOR_START);
135     event->rgbEvent = (BYTE *) collector_start;
136
137     /* extend */
138     extendEvent(event);
139
140     /* free */
141     free(collector_start);
142     free(event);
143
144     return PTS_SUCCESS;
145 }
146
147
148
149 /**
150  * initialize ptsc
151  *
152  * 1. generate UUID
153  * 2. generate Sign Key (NA)
154  * 3. get platform information, call dmidecode or BIOS IML? (NA)
155  * 4. generate RM
156  * 
157  *
158  * ./src/ptsc -i -c tests/data/Fedora12/ptscd.conf
159  *
160  * Return
161  *  PTS_SUCCESS
162  *  PTS_INTERNAL_ERROR
163  */
164
165 int init(
166     OPENPTS_CONFIG *conf,
167     int prop_count,
168     OPENPTS_PROPERTY *prop_start,
169     OPENPTS_PROPERTY *prop_end) {
170     int rc = PTS_SUCCESS;
171     OPENPTS_CONTEXT *ctx;
172     int i;
173     int keygen = 1;
174
175     /* ctx for init */
176     ctx = newPtsContext(conf);
177     if (ctx == NULL) {
178         ERROR("no memory\n");
179         return PTS_INTERNAL_ERROR;
180     }
181
182     /* add property */
183     if (prop_count > 0) {
184         ctx->prop_start = prop_start;
185         ctx->prop_end = prop_end;
186         ctx->prop_count = prop_count;
187     }
188
189
190     /* config dir */
191     if (conf->config_dir == NULL) {
192         ERROR("missing config dir, check your config file %s\n", conf->config_file);
193         return PTS_INTERNAL_ERROR;
194     } else {
195         /* check */
196         rc = checkDir(conf->config_dir);
197         if (rc == PTS_SUCCESS) {
198             /* OK */
199         } else {
200             /* Missing */
201             INFO("create new config dir, %s", conf->config_dir);
202             makeDir(conf->config_dir);
203         }
204     }
205     // DEBUG("config dir : %s\n", conf->config_dir);
206
207     /* Generate UUID of this platform */
208     // TODO TODO TODO
209     if (conf->uuid == NULL) {
210         // TODO UUID filename is missing
211         ERROR(" bad conf file\n");
212         return PTS_INTERNAL_ERROR;
213     } else if (conf->uuid->status == OPENPTS_UUID_FILENAME_ONLY) {
214         /* gen new UUID */
215         rc = genOpenptsUuid(conf->uuid);
216         // TODO check rc
217     } else {
218         DEBUG("init() - use given UUID %s (for TEST)\n", conf->uuid->str);
219         keygen = 0;
220     }
221
222     /* Create TPM Sign Key */
223     // TODO we use single sign key for all verifiers
224     //      it depends on the onwer of key, now ptscd is the owner of sign key.
225     //      if verifier take the ownership of sign key, we needs the key for each verifier.
226     //      auth can be transferd by IF-M (DH excnage)
227     if (keygen == 1) {
228         rc = createTssSignKey(
229                 conf->uuid->uuid,
230                 conf->aik_storage_type,
231                 conf->aik_storage_filename,
232                 conf->aik_auth_type,
233                 0,
234                 conf->srk_password_mode);
235         if (rc == 0x0001) {  // 0x0001
236             fprintf(stderr, "createSignKey failed. "
237                             "if you uses well known SRK secret, "
238                             "all zeros (20 bytes of zeros) try -z option\n");
239             rc = PTS_INTERNAL_ERROR;
240             goto free;
241         } else if (rc != PTS_SUCCESS) {
242             fprintf(stderr, "createSignKey failed, rc = 0x%x\n", rc);
243             rc = PTS_INTERNAL_ERROR;
244             goto free;
245         }
246         printf("Sign key  location          : SYSTEM\n");
247     } else {
248         DEBUG("init() - skip key gen for the given UUID\n");
249     }
250
251
252     /* Write UUID file */
253     rc = writeOpenptsUuidFile(conf->uuid, 0);
254     if (rc == PTS_DENIED) {
255         char *str_uuid;
256         PTS_DateTime *time;
257         /* if UUID file exist => exit, admin must delete the UUID file, then init again */
258         /* check existing UUID */
259         rc = readOpenptsUuidFile(conf->uuid);
260         str_uuid = getStringOfUuid(conf->uuid->uuid);
261         time = getDateTimeOfUuid(conf->uuid->uuid);
262
263         fprintf(stderr, "uuid file, '%s' exist, please remove this file if you want to re-intialize the platform\n",
264             conf->uuid->filename);
265         fprintf(stderr, "    existing uuid = %s\n", str_uuid);
266         fprintf(stderr, "    creation date = %d-%d-%d\n",
267             time->year + 1900,
268             time->mon + 1,
269             time->mday);
270         /* free */
271         free(str_uuid);
272         free(time);
273         goto free;
274     } else if (rc != PTS_SUCCESS) {
275         /* internal error */
276         fprintf(stderr, "uuid file, '%s' generation was failed\n", conf->uuid->filename);
277         rc = PTS_INTERNAL_ERROR;
278         goto free;
279     }
280
281     /* print uuid */
282     printf("Generate uuid               : %s \n", conf->uuid->str);
283
284
285
286     /* read FSM */
287     rc = readFsmFromPropFile(ctx, conf->config_file);
288     if (rc != PTS_SUCCESS) {
289         ERROR("read FSM failed\n");
290         rc = PTS_INTERNAL_ERROR;
291         goto free;
292     }
293
294     /* UUID for RM */
295     if (conf->rm_uuid == NULL) {
296         // init/set by readPtsConf
297         ERROR("conf->rm_uuid == NULL\n");
298     } else if (conf->rm_uuid->status == OPENPTS_UUID_FILENAME_ONLY) {
299         rc = genOpenptsUuid(conf->rm_uuid);
300         // TODO
301     } else {
302         DEBUG("init() - use given RM UUID %s\n", conf->rm_uuid->str);
303     }
304
305     /* save to rm_uuid file */
306     rc = writeOpenptsUuidFile(conf->rm_uuid, 0);  // do not overwrite
307     if (rc != PTS_SUCCESS) {
308         ERROR("writeOpenptsUuidFile fail\n");
309     }
310     // TODO check rc
311
312     /* RM set DIR */
313     rc = makeRmSetDir(conf);
314     if (rc != PTS_SUCCESS) {
315         ERROR("mkdir of RM set dir was failed\n");
316         goto free;
317     }
318
319     /* print rm uuid */
320     printf("Generate UUID (for RM)      : %s \n", conf->rm_uuid->str);
321
322     /* read IML to fill the BIOS binary measurement, and translate BHV->BIN FSM */
323
324     /* load current IML using FSMs */
325     if (conf->iml_mode == 0) {  // TODO use def
326 #ifdef CONFIG_NO_TSS
327         ERROR("Build with --without-tss. iml.mode=tss is not supported\n");
328 #else
329         rc = getIml(ctx, 0);
330         rc = getPcr(ctx);
331 #endif
332     } else if (conf->iml_mode == 1) {
333         // TODO change to generic name?  conf->iml_filename[0]  conf->iml_filename[1]
334         /* from  securityfs */
335         /* BIOS IML */
336         rc = readBiosImlFile(
337                 ctx,
338                 conf->bios_iml_filename, conf->iml_endian);
339         if (rc != PTS_SUCCESS) {
340             DEBUG("getBiosImlFile() was failed\n");
341             fprintf(stderr, "Oops! Something is wrong. Please see the reason below\n");
342             printReason(ctx);
343             goto free;
344         }
345
346         /* RUNTIME IML (Linux-IMA) */
347         if (ctx->conf->runtime_iml_filename != NULL) {
348             int count;
349             rc = readImaImlFile(
350                     ctx,
351                     conf->runtime_iml_filename,
352                     conf->runtime_iml_type, 0, &count);  // TODO endian?
353             if (rc != PTS_SUCCESS) {
354                 fprintf(stderr, "read IMA IML, %s was failed\n", conf->runtime_iml_filename);
355                 rc = PTS_INTERNAL_ERROR;
356                 goto free;
357             }
358         }
359     } else {
360         ERROR("unknown IML mode, %d\n", conf->iml_mode);
361     }
362
363     /* get SMBIOS data */
364     // TODO
365
366     /* create Reference Manifest */
367     for (i = 0; i < conf->rm_num; i++) {
368         if (conf->rm_filename[i] != NULL) {
369             rc = writeRm(ctx, conf->rm_filename[i], i);
370             if (rc != PTS_SUCCESS) {
371                 fprintf(stderr, "ERROR, initialization was failed\n");
372                 addReason(ctx,
373                     "[INIT] Failed to create the manifest file, %s",
374                     conf->rm_filename[i]);
375                 printReason(ctx);
376                 rc = PTS_FATAL;
377                 goto free;
378             }
379             printf("level %d Reference Manifest  : %s\n", i, conf->rm_filename[i]);
380         } else {
381             ERROR("missing RM file for level %d\n", i);
382         }
383     }
384     printf("\nptsc is successfully initialized!\n");
385
386  free:
387     /* free */
388     freePtsContext(ctx);
389
390     return rc;
391 }
392
393
394
395 /**
396  *
397  * Selftest
398  * - Find right RM for this boot
399  *
400  * Check RM set by rm_uuid file 
401  *    OK-> OPENPTS_SELFTEST_SUCCESS
402  *    NG -> next
403  * Check RM set by newrm_uuid file 
404  *    OK -> OPENPTS_SELFTEST_RENEWED
405  *    NG -> next
406  * Check RM set by oldrm_uuid file 
407  *    OK -> OPENPTS_SELFTEST_FALLBACK
408  *    NG -> OPENPTS_SELFTEST_FAILED
409  *
410  *
411  * Return
412  *   OPENPTS_SELFTEST_SUCCESS   stable:-)
413  *   OPENPTS_SELFTEST_RENEWED   update/reboot -> success
414  *   OPENPTS_SELFTEST_FALLBACK
415  *   OPENPTS_SELFTEST_FAILED
416  *   PTS_INTERNAL_ERROR         something wrong:-(
417  */
418 int selftest(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OPENPTS_PROPERTY *prop_end) {
419     int rc = PTS_INTERNAL_ERROR;
420     int result;
421     OPENPTS_CONTEXT *ctx;
422     int i;
423     OPENPTS_PROPERTY *prop;
424
425     DEBUG("selftest() start\n");
426
427     /* Step 1 - IR gen */
428
429     /* new */
430     ctx = newPtsContext(conf);
431     if (ctx == NULL) {
432         ERROR("no memory\n");
433         return PTS_INTERNAL_ERROR;
434     }
435
436     /* copy properties */
437     prop = prop_start;
438     for (i = 0; i < prop_count; i++) {
439         if (prop == NULL) {
440             ERROR("prop == NULL\n");
441             return PTS_INTERNAL_ERROR;  // TODO free
442         }
443         addProperty(ctx, prop->name, prop->value);
444         prop = prop->next;
445     }
446
447
448     /* set dummy nonce for IR gen */
449     ctx->nonce->nonce_length = 20;
450     ctx->nonce->nonce = malloc(20);
451     memset(ctx->nonce->nonce, 0x5A, 20);
452     // dummy target uuid
453     ctx->str_uuid = smalloc("SELFTEST");
454
455     /* gen IR */
456     rc = genIr(ctx);  // ir.c
457     if (rc != PTS_SUCCESS) {
458         ERROR("selftest() - genIR failed\n");
459         rc = PTS_INTERNAL_ERROR;
460         goto free;
461     }
462
463     /* free */
464     freePtsContext(ctx);
465
466
467     // DEBUG("selftest() - generate IR file => %s\n", conf->ir_filename);
468     DEBUG("selftest() - generate IR - done\n");
469
470     /* Step 2 - Validate IR */
471
472     /* Keep conf but reset some flags in conf */
473     // conf->aru_count = 0;
474     // conf->enable_aru;
475 #ifdef CONFIG_AUTO_RM_UPDATE
476     conf->update_exist = 0;
477 #endif
478     /* new */
479     ctx = newPtsContext(conf);
480     if (ctx == NULL) {
481         ERROR("no memory\n");
482         return PTS_INTERNAL_ERROR;
483     }
484
485     /* setup RMs */
486     rc = getRmSetDir(conf);
487     if (rc != PTS_SUCCESS) {
488         ERROR("selftest() - getRmSetDir() failed\n");
489         TODO("conf->rm_uuid->filename %s\n", conf->rm_uuid->filename);
490         TODO("conf->rm_uuid->str      %s\n", conf->rm_uuid->str);
491         rc = PTS_INTERNAL_ERROR;
492         goto free;
493     }
494
495     /* load RMs */
496     for (i = 0; i <  conf->rm_num; i++) {
497         rc = readRmFile(ctx, conf->rm_filename[i], i);
498         if (rc < 0) {
499             ERROR("readRmFile fail\n");
500             rc = PTS_INTERNAL_ERROR;
501             goto free;
502         }
503     }
504
505
506     /* verify */
507     DEBUG("selftest() - validate IR - start\n");
508
509     // TODO 2011-01-21 SM just use same conf
510     ctx->target_conf = ctx->conf;
511
512     // Disable Quote
513     // 2011-01-28 SM, If FSM did not covers all PCRs Quote validation will fail?
514     // iml_mode = ctx->conf->iml_mode;
515     // ir_without_quote = ctx->conf->ir_without_quote;
516     // ctx->conf->iml_mode = 1;
517     // ctx->conf->ir_without_quote = 1;
518
519
520
521     result = validateIr(ctx, conf->ir_filename);  /* ir.c */
522
523
524
525     /* check RM integrity status */
526     DEBUG("selftest() - validate IR - done (rc = %d)\n", result);
527     if ((rc != OPENPTS_RESULT_VALID) && (verbose & DEBUG_FLAG)) {
528         printReason(ctx);
529     }
530
531     if (result != OPENPTS_RESULT_VALID) {
532         addReason(ctx, "[SELFTEST] selftest was failed");
533         if ((conf->newrm_uuid != NULL) && (conf->newrm_uuid->uuid != NULL)) {
534             /* New RM exist (for reboot after the update), Try the new RM */
535
536             /* chenge the UUID */  // TODO add exchange func
537             conf->rm_uuid->uuid = conf->newrm_uuid->uuid;
538             conf->rm_uuid->str  = conf->newrm_uuid->str;
539             conf->rm_uuid->time = conf->newrm_uuid->time;
540
541             // del newrm
542             conf->newrm_uuid->uuid = NULL;
543             conf->newrm_uuid->str  = NULL;
544             conf->newrm_uuid->time = NULL;
545
546             // TODO free
547
548             /* try selftest again */
549             DEBUG("selftest again UUID=%s\n", conf->rm_uuid->str);
550             rc = selftest(conf, prop_count, prop_start, prop_end);
551             if (rc == OPENPTS_SELFTEST_SUCCESS) {
552                 /* Update the RM UUID by NEWRM_UUID */
553                 DEBUG("use UUID=%s\n", conf->rm_uuid->str);
554                 /* update rm_uuid */
555                 rc = writeOpenptsUuidFile(conf->rm_uuid, 1);
556                 if (rc != PTS_SUCCESS) {
557                     ERROR("writeOpenptsUuidFile fail\n");
558                 }
559
560                 // TODO check rc
561                 /* delete newrm_uuid */
562                 rc = remove(conf->newrm_uuid->filename);
563                 // TODO check rc
564                 rc = OPENPTS_SELFTEST_RENEWED;
565             } else {
566                 /* fail */
567                 TODO("\n");
568                 addReason(ctx, "[SELFTEST] selftest using both current and new UUID was failed");
569                 printReason(ctx);
570                 rc = OPENPTS_SELFTEST_FAILED;
571             }
572         } else {
573             addReason(ctx, "[SELFTEST] selftest was failed");
574             printReason(ctx);
575             rc = OPENPTS_SELFTEST_FAILED;
576         }
577     } else {
578         /* valid :-) */
579         rc = OPENPTS_SELFTEST_SUCCESS;
580     }
581
582  free:
583     /* free */
584     freePtsContext(ctx);
585
586     return rc;
587 }
588
589
590
591 /**
592  * New RM
593  *
594  * 4. generate RM
595  * 
596  *
597  * ./src/ptsc -i -c tests/data/Fedora12/ptscd.conf
598  *
599  * Return
600  *  PTS_SUCCESS
601  *  PTS_INTERNAL_ERROR
602  */
603
604 int newrm(OPENPTS_CONFIG *conf, int prop_count, OPENPTS_PROPERTY *prop_start, OPENPTS_PROPERTY *prop_end) {
605     int rc = PTS_SUCCESS;
606     OPENPTS_CONTEXT *ctx;
607     int i;
608     OPENPTS_PROPERTY *prop;
609
610     /* ctx for init */
611     ctx = newPtsContext(conf);
612     if (ctx == NULL) {
613         ERROR("no memory\n");
614         return PTS_INTERNAL_ERROR;
615     }
616
617 #if 1
618     /* copy properties */
619     prop = prop_start;
620     for (i = 0; i < prop_count; i++) {
621         if (prop == NULL) {
622             ERROR("prop == NULL\n");
623             return PTS_INTERNAL_ERROR;  // TODO free
624         }
625         addProperty(ctx, prop->name, prop->value);
626         prop = prop->next;
627     }
628 #else
629     /* add property */
630     if (prop_count > 0) {
631         ctx->prop_start = prop_start;
632         ctx->prop_end = prop_end;
633         ctx->prop_count = prop_count;
634     }
635 #endif
636
637     /* read FSM */
638     rc = readFsmFromPropFile(ctx, conf->config_file);
639     if (rc != PTS_SUCCESS) {
640         ERROR("read FSM failed\n");
641         rc = PTS_INTERNAL_ERROR;
642         goto free;
643     }
644
645     /* UUID for RM */
646     if (conf->rm_uuid == NULL) {
647         ERROR("conf->rm_uuid == NULL");
648     } else if (conf->rm_uuid->status == OPENPTS_UUID_FILENAME_ONLY) {
649         rc = genOpenptsUuid(conf->rm_uuid);
650         // TODO
651     } else {
652         DEBUG("init() - use given RM UUID %s\n", conf->rm_uuid->str);
653     }
654
655     /* save/update rm_uuid file */
656     rc = writeOpenptsUuidFile(conf->rm_uuid, 1);  // TODO overwite?
657     if (rc != PTS_SUCCESS) {
658         ERROR("writeOpenptsUuidFile fail\n");
659     }
660
661     /* RM set DIR */
662     rc = makeRmSetDir(conf);
663     if (rc != PTS_SUCCESS) {
664         ERROR("mkdir of RM set dir was failed\n");
665         goto free;
666     }
667
668     /* print rm uuid */
669     printf("Generate UUID (for RM)      : %s \n", conf->rm_uuid->str);
670
671     /* read IML to fill the BIOS binary measurement, and translate BHV->BIN FSM */
672
673     /* load current IML using FSMs */
674     if (conf->iml_mode == 0) {  // TODO use def
675 #ifdef CONFIG_NO_TSS
676         ERROR("Build with --without-tss. iml.mode=tss is not supported\n");
677 #else
678         rc = getIml(ctx, 0);
679         rc = getPcr(ctx);
680 #endif
681     } else if (conf->iml_mode == 1) {
682         // TODO change to generic name?  conf->iml_filename[0]  conf->iml_filename[1]
683         /* from  securityfs */
684         /* BIOS IML */
685         rc = readBiosImlFile(
686                 ctx,
687                 conf->bios_iml_filename, conf->iml_endian);
688         if (rc != PTS_SUCCESS) {
689             DEBUG("getBiosImlFile() was failed\n");
690             fprintf(stderr, "Oops! Something is wrong. Please see the reason below\n");
691             printReason(ctx);
692             goto free;
693         }
694
695         /* RUNTIME IML (Linux-IMA) */
696         if (ctx->conf->runtime_iml_filename != NULL) {
697             int count;
698             rc = readImaImlFile(
699                     ctx,
700                     conf->runtime_iml_filename,
701                     conf->runtime_iml_type, 0, &count);  // TODO endian?
702             if (rc != PTS_SUCCESS) {
703                 fprintf(stderr, "read IMA IML, %s was failed\n", conf->runtime_iml_filename);
704                 rc = PTS_INTERNAL_ERROR;
705                 goto free;
706             }
707         }
708     } else {
709         ERROR("unknown IML mode, %d\n", conf->iml_mode);
710     }
711
712     /* get SMBIOS data */
713     // TODO
714
715     /* create Reference Manifest */
716     for (i = 0; i < conf->rm_num; i++) {
717         if (conf->rm_filename[i] != NULL) {
718             rc = writeRm(ctx, conf->rm_filename[i], i);
719             if (rc != PTS_SUCCESS) {
720                 fprintf(stderr, "write RM, %s was failed\n", conf->rm_filename[i]);
721                 rc = PTS_INTERNAL_ERROR;
722                 goto free;
723             }
724             printf("level %d Reference Manifest  : %s\n", i, conf->rm_filename[i]);
725         } else {
726             ERROR("missing RM file for level %d\n", i);
727         }
728     }
729     // printf("\nptsc is successfully initialized!\n");
730
731  free:
732     /* free */
733     freePtsContext(ctx);
734
735     return rc;
736 }
737
738
739 /**
740  * Print the configuration of PTS collector
741  *
742  * Return
743  *   PTS_SUCCESS
744  */
745 int printCollectorStatus(OPENPTS_CONFIG *conf) {
746     int rc = PTS_SUCCESS;
747     OPENPTS_CONTEXT *ctx;
748
749     ctx = newPtsContext(conf);
750
751     printf("%s version %s \n\n", PACKAGE, VERSION);
752
753     printf("config file                 : %s\n", conf->config_file);
754     /* UUID */
755     printf("UUID                        : %s (%s)\n", ctx->conf->uuid->str, conf->uuid->filename);
756
757     /* IML */
758     if (conf->iml_mode == 0) {
759         printf("IML access mode             : TSS\n");
760     } else if (conf->iml_mode == 1) {
761         printf("IML access                  : SecurityFS\n");
762         printf("  BIOS IML file             : %s\n", conf->bios_iml_filename);
763         printf("  Runtime IML file          : %s\n", conf->runtime_iml_filename);
764         printf("  PCR file                  : %s\n", conf->pcrs_filename);
765     } else {
766         ERROR("unknown IML mode, %d\n", conf->iml_mode);
767     }
768
769     /* Linux IMA mode */
770     switch (conf->runtime_iml_type) {
771     case BINARY_IML_TYPE_IMA_ORIGINAL:
772         printf("  Runtime IML type          : Linux-IMA patch (kernel 2.6.18-2.6.29)\n");
773         break;
774     case BINARY_IML_TYPE_IMA_31:
775         printf("  Runtime IML type          : IMA (kernel 2.6.30-31)\n");
776         break;
777     case BINARY_IML_TYPE_IMA:
778         printf("  Runtime IML type          : IMA (kernel 2.6.32)\n");
779         break;
780     case BINARY_IML_TYPE_IMA_NG:
781         printf("  Runtime IML type          : IMA NG (kernel 2.6.XX)\n");
782         break;
783     case BINARY_IML_TYPE_IMA_NGLONG:
784         printf("  Runtime IML type          : IMA NG LONG (kernel 2.6.XX)\n");
785         break;
786     default:
787         printf("  Runtime IML type          : unknown type 0x%x\n", conf->runtime_iml_type);
788         break;
789     }  // switch
790
791     /* Reference Manifest */
792
793     /* UUID of this platform */
794     printf("RM UUID (current)           : %s\n", conf->rm_uuid->str);
795     printf("RM UUID (for next boot)     : %s\n", conf->newrm_uuid->str);
796
797     /* List RMs */
798     getRmList(conf, conf->config_dir);
799     printf("List of RM set              : %d RM set in config dir\n", conf->rmsets->rmset_num);
800     printRmList(conf, "                             ");
801     printf("Integrity Report            : %s\n", conf->ir_filename);
802
803
804     // TODO remove ctx from readFsmFromPropFile
805     /* Models */
806     rc = readFsmFromPropFile(ctx, conf->config_file);
807     if (rc != PTS_SUCCESS) {
808         ERROR("read FSM failed\n");
809         goto free;
810     }
811
812     printf("Model dir                   : %s\n", conf->model_dir);
813     printf("                              Behavior Models\n");
814     printFsmInfo(ctx, "                              ");
815
816     /* Manifest */
817
818
819     /* Servers */
820
821  free:
822     /* free */
823     freePtsContext(ctx);
824
825     return rc;
826 }
827
828