X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fjournal%2Ftest-journal-verify.c;h=05400742074e1e1ac122617267892bb2ee9a30fd;hp=4e6c119b6d0ce062556419cf00afb8b003d2b807;hb=faf5077f891aa249270b2a3d9f0104c3eec02da6;hpb=b72631e59c1b9f62bcfaf1ce3f7e72e4a3beee89 diff --git a/src/journal/test-journal-verify.c b/src/journal/test-journal-verify.c index 4e6c119b6..054007420 100644 --- a/src/journal/test-journal-verify.c +++ b/src/journal/test-journal-verify.c @@ -55,7 +55,7 @@ static int raw_verify(const char *fn, const char *verification_key) { JournalFile *f; int r; - r = journal_file_open(fn, O_RDONLY, 0666, true, true, NULL, NULL, NULL, &f); + r = journal_file_open(fn, O_RDONLY, 0666, true, !!verification_key, NULL, NULL, NULL, &f); if (r < 0) return r; @@ -77,6 +77,10 @@ int main(int argc, char *argv[]) { struct stat st; uint64_t p; + /* journal_file_open requires a valid machine id */ + if (access("/etc/machine-id", F_OK) != 0) + return EXIT_TEST_SKIP; + log_set_max_level(LOG_DEBUG); assert_se(mkdtemp(t)); @@ -107,34 +111,36 @@ int main(int argc, char *argv[]) { log_info("Verifying..."); - assert_se(journal_file_open("test.journal", O_RDONLY, 0666, true, true, NULL, NULL, NULL, &f) == 0); - journal_file_print_header(f); + assert_se(journal_file_open("test.journal", O_RDONLY, 0666, true, !!verification_key, NULL, NULL, NULL, &f) == 0); + /* journal_file_print_header(f); */ + journal_file_dump(f); assert_se(journal_file_verify(f, verification_key, &from, &to, &total, true) >= 0); - if (verification_key && journal_file_fss_enabled(f)) { + if (verification_key && JOURNAL_HEADER_SEALED(f->header)) { log_info("=> Validated from %s to %s, %s missing", format_timestamp(a, sizeof(a), from), format_timestamp(b, sizeof(b), to), - format_timespan(c, sizeof(c), total > to ? total - to : 0)); + format_timespan(c, sizeof(c), total > to ? total - to : 0, 0)); } + journal_file_close(f); - log_info("Toggling bits..."); + if (verification_key) { + log_info("Toggling bits..."); - assert_se(stat("test.journal", &st) >= 0); + assert_se(stat("test.journal", &st) >= 0); - for (p = 240*8; p < ((uint64_t) st.st_size * 8); p ++) { - bit_toggle("test.journal", p); + for (p = 38448*8+0; p < ((uint64_t) st.st_size * 8); p ++) { + bit_toggle("test.journal", p); - log_info("[ %llu+%llu]", (unsigned long long) p / 8, (unsigned long long) p % 8); + log_info("[ %"PRIu64"+%"PRIu64"]", p / 8, p % 8); - if (raw_verify("test.journal", verification_key) >= 0) { - log_notice(ANSI_HIGHLIGHT_RED_ON ">>>> %llu (bit %llu) can be toggled without detection." ANSI_HIGHLIGHT_OFF, (unsigned long long) p / 8, (unsigned long long) p % 8); - sleep(1); - } + if (raw_verify("test.journal", verification_key) >= 0) + log_notice(ANSI_HIGHLIGHT_RED_ON ">>>> %"PRIu64" (bit %"PRIu64") can be toggled without detection." ANSI_HIGHLIGHT_OFF, p / 8, p % 8); - bit_toggle("test.journal", p); + bit_toggle("test.journal", p); + } } log_info("Exiting...");