// ---------------------------------------------------------------------- TEST(leapsec, ValidateMalformedShort) { const char *cp = leap_shash; int rc = leapsec_validate(stringreader, &cp); TEST_ASSERT_EQUAL(LSVALID_BADFORMAT, rc); }
// ---------------------------------------------------------------------- TEST(leapsec, ValidateNoLeadZero) { const char *cp = leap_gthash; int rc = leapsec_validate(stringreader, &cp); TEST_ASSERT_EQUAL(LSVALID_GOODHASH, rc); }
// ---------------------------------------------------------------------- TEST(leapsec, ValidateBad) { const char *cp = leap_bhash; int rc = leapsec_validate(stringreader, &cp); TEST_ASSERT_EQUAL(LSVALID_BADHASH, rc); }
// ---------------------------------------------------------------------- TEST(leapsec, ValidateNoHash) { const char *cp = leap2; int rc = leapsec_validate(stringreader, &cp); TEST_ASSERT_EQUAL(LSVALID_NOHASH, rc); }
/* load a file from a FILE pointer. Note: If hcheck is true, load * only after successful signature check. The stream must be seekable * or this will fail. */ int/*BOOL*/ leapsec_load_stream( FILE * ifp , const char * fname, int/*BOOL*/ logall) { leap_table_t *pt; int rcheck; if (NULL == fname) fname = "<unknown>"; rcheck = leapsec_validate((leapsec_reader)getc, ifp); if (logall) switch (rcheck) { case LSVALID_GOODHASH: msyslog(LOG_NOTICE, "%s ('%s'): good hash signature", logPrefix, fname); break; case LSVALID_NOHASH: msyslog(LOG_ERR, "%s ('%s'): no hash signature", logPrefix, fname); break; case LSVALID_BADHASH: msyslog(LOG_ERR, "%s ('%s'): signature mismatch", logPrefix, fname); break; case LSVALID_BADFORMAT: msyslog(LOG_ERR, "%s ('%s'): malformed hash signature", logPrefix, fname); break; default: msyslog(LOG_ERR, "%s ('%s'): unknown error code %d", logPrefix, fname, rcheck); break; } if (rcheck < 0) return FALSE; rewind(ifp); pt = leapsec_get_table(TRUE); if (!leapsec_load(pt, (leapsec_reader)getc, ifp, TRUE)) { switch (errno) { case EINVAL: msyslog(LOG_ERR, "%s ('%s'): bad transition time", logPrefix, fname); break; case ERANGE: msyslog(LOG_ERR, "%s ('%s'): times not ascending", logPrefix, fname); break; default: msyslog(LOG_ERR, "%s ('%s'): parsing error", logPrefix, fname); break; } return FALSE; } if (pt->head.size) msyslog(LOG_NOTICE, "%s ('%s'): loaded, expire=%s last=%s ofs=%d", logPrefix, fname, lstostr(&pt->head.expire), lstostr(&pt->info[0].ttime), pt->info[0].taiof); else msyslog(LOG_NOTICE, "%s ('%s'): loaded, expire=%s ofs=%d (no entries after build date)", logPrefix, fname, lstostr(&pt->head.expire), pt->head.base_tai); return leapsec_set_table(pt); }
// ---------------------------------------------------------------------- void test_ValidateMalformed(void) { const char *cp = leap_mhash; int rc = leapsec_validate(stringreader, &cp); TEST_ASSERT_EQUAL(LSVALID_BADFORMAT, rc); }
// ---------------------------------------------------------------------- void test_ValidateGood(void) { const char *cp = leap_ghash; int rc = leapsec_validate(stringreader, &cp); TEST_ASSERT_EQUAL(LSVALID_GOODHASH, rc); }