2 * This file is part of the OpenPTS project.
4 * The Initial Developer of the Original Code is International
5 * Business Machines Corporation. Portions created by IBM
6 * Corporation are Copyright (C) 2010 International Business
7 * Machines Corporation. All Rights Reserved.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the Common Public License as published by
11 * IBM Corporation; either version 1 of the License, or (at your option)
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * Common Public License for more details.
19 * You should have received a copy of the Common Public License
20 * along with this program; if not, a copy can be viewed at
21 * http://www.opensource.org/licenses/cpl1.0.php.
25 * \file src/iml2aide.c
26 * \brief convert IML to AIDE DB
27 * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
29 * cleanup 2012-01-05 SM
31 * create AIDE DB from IML (via securityfs)
33 * ./src/iml2aide -c tests/data/Fedora12/ptscd.conf -i /sys/kernel/security/ima/binary_runtime_measurements -o tests/data/Fedora12/aide.db.gz
34 * zcat tests/data/Fedora12/aide.db.gz | less
36 * Create AIDE DB from IML (via TSS)
38 * time ./src/iml2aide -c tests/data/Fedora12/ptscd.conf -o tests/data/Fedora12/aide.db.gz
39 * IML : 5673 events (TSS)
40 * AIDE DB : 5520 entries (tests/data/Fedora12/aide.db.gz)
46 * Create AIDE DB from IML (via TSS) and refer actual AIDE DB and get the fullpath name if existed.
48 * time src/iml2aide -c tests/data/Fedora12/ptscd.conf -r /var/lib/aide/aide.db.new.gz -o tests/data/Fedora12/aide.db.gz
49 * AIDE DB(ref) : 241826 entries (/var/lib/aide/aide.db.new.gz)
50 * IML : 5681 events (TSS)
51 * AIDE DB : 3986 entries (tests/data/Fedora12/aide.db.gz)
53 * real 1m27.252s << YES VERY SLOW :-(
58 * Create AIDE DB from IML (via TSS) and refer actual AIDE DB and get the fullpath name if existed. also generate ignore list
60 * AIDE DB(ref) : 241826 entries (< /var/lib/aide/aide.db.new.gz)
61 * IML : 5949 events (< TSS)
62 * AIDE DB : 4153 entries (> tests/data/Fedora12/aide.db.gz)
63 * Ignore list : 224 entries (> tests/data/Fedora12/aide.ignore.list)
79 #include <sys/types.h>
80 #include <sys/socket.h>
81 #include <netinet/in.h>
90 * print FSM status (location)
92 void printFsmInfo2(OPENPTS_CONTEXT *ctx) {
98 OUTPUT(NLS(MS_OPENPTS, OPENPTS_IML2AIDE_EVENT,
100 "PCR Level0 Level1\n"));
101 OUTPUT("--------------------------\n");
103 for (i = 0; i < MAX_PCRNUM; i++) {
105 ss = getSnapshotFromTable(ctx->ss_table, i, 0);
107 OUTPUT(" ----- - - ");
110 if (ss->fsm_behavior != NULL) OUTPUT(" O ");
113 if (ss->fsm_binary != NULL) OUTPUT(" O ");
117 ss = getSnapshotFromTable(ctx->ss_table, i, 1);
121 if (ss->fsm_behavior != NULL) OUTPUT(" O ");
124 if (ss->fsm_binary != NULL) OUTPUT(" O ");
131 OUTPUT("---------------------------\n");
132 OUTPUT("level 0 total = %d\n", level0_num);
133 OUTPUT("level 1 total = %d\n", level1_num);
134 OUTPUT("---------------------------\n");
141 OUTPUT(NLS(MS_OPENPTS, OPENPTS_IML2AIDE_USAGE,
142 "OpenPTS command\n\n"
143 "Usage: iml2aide [options]\n\n"
145 " -c filename Set config file\n"
146 " -i filename Set IMA IML file. default, get IML via TSS\n"
147 " -r filename Set AIDE DB file as reference of fullpathname\n"
148 " -o filename Set output file (AIDE DB format, gziped)\n"
149 " -w filename Set output file (Ignore name list, plain text format)\n"
150 " -h Show this help message\n"
157 int main(int argc, char *argv[]) {
159 int ima_type = BINARY_IML_TYPE_IMA;
161 char *ima_filename = NULL;
162 char *aide_filename = NULL;
163 char *config_filename = NULL;
164 char *aideref_filename = NULL;
165 char *ignorelist_filename = NULL;
166 OPENPTS_CONFIG *conf = NULL;
167 OPENPTS_CONTEXT *ctx = NULL;
171 while ((c = getopt(argc, argv, "do:i:c:r:w:h")) != EOF) {
174 setDebugFlags(DEBUG_FLAG);
177 ima_filename = optarg;
180 aide_filename = optarg;
183 aideref_filename = optarg;
186 config_filename = optarg;
189 ignorelist_filename = optarg;
202 if (aide_filename == NULL) {
203 OUTPUT(NLS(MS_OPENPTS, OPENPTS_IML2AIDE_SET_OUTPUT, "Set output file (AIDE DB file)\n\n"));
207 if (config_filename == NULL) {
208 OUTPUT(NLS(MS_OPENPTS, OPENPTS_IML2AIDE_CONFIG, "Set config file\n\n"));
215 conf = newPtsConfig();
217 LOG(LOG_ERR, "Internal Error\n");
221 ctx = newPtsContext(conf);
223 LOG(LOG_ERR, "Internal Error\n");
228 rc = readPtsConfig(ctx->conf, config_filename);
231 rc = readFsmFromPropFile(ctx, config_filename);
232 if (rc != PTS_SUCCESS) {
233 LOG(LOG_ERR, "read FSM failed\n");
238 setEventProperty(ctx, "linux.kernel.digest", "valid", NULL);
239 setEventProperty(ctx, "linux.initrd.digest", "valid", NULL);
240 setEventProperty(ctx, "linux.kernel.cmdline.ima_tcb", "1", NULL);
243 /* AIDE reference DB, pre load */
244 if (aideref_filename != NULL) {
245 ctx->aide_ctx = newAideContext();
247 rc = loadAideDatabaseFile(ctx->aide_ctx, aideref_filename); // ir.c
249 LOG(LOG_ERR, "Internal Error, load AIDE DB() was failed\n");
252 OUTPUT(NLS(MS_OPENPTS, OPENPTS_IML2AIDE_DATABASE,
253 "AIDE Database(ref): %d entries (< %s)\n"), rc, aideref_filename);
256 ctx->conf->ima_validation_mode = OPENPTS_VALIDATION_MODE_AIDE;
257 ctx->conf->aide_database_filename = NULL;
263 if (ima_filename == NULL) {
264 /* IML -> TSS -> Struct */
266 OUTPUT(NLS(MS_OPENPTS, OPENPTS_IML2AIDE_EVENTS,
267 "IML: %d events (< TSS)\n"), rc);
270 /* IML(file) -> Struct */
274 ima_type, 0, &count);
276 if (rc != PTS_SUCCESS) {
277 LOG(LOG_ERR, "Internal Error, raild atr ead IMA's IML\n");
280 OUTPUT(NLS(MS_OPENPTS, OPENPTS_IML2AIDE_EVENTS_2,
281 "IML: %d events (< %s)\n"), rc, ima_filename);
284 LOG(LOG_ERR, "Internal Error\n");
289 if (aideref_filename == NULL) {
290 /* just IML -> AIDE.DB*/
291 rc = convertImlToAideDbFile(ctx, aide_filename);
293 /* IML&AIDE.DB -> AIDE.DB */
294 rc = writeReducedAidbDatabase(ctx->aide_ctx, aide_filename);
297 LOG(LOG_ERR, "Internal Error\n");
301 OUTPUT(NLS(MS_OPENPTS, OPENPTS_IML2AIDE_DATABASE_2,
302 "AIDE Database : %d entries (> %s) \n"), rc, aide_filename);
304 if (ignorelist_filename != NULL) {
305 rc = writeAideIgnoreList(ctx, ignorelist_filename);
306 OUTPUT(NLS(MS_OPENPTS, OPENPTS_IML2AIDE_IGN_LIST,
307 "Ignore list : %d entries (> %s) \n"), rc, ignorelist_filename);