Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/crypto/TS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ tm TS::time() const
void TS::verify(const vector<unsigned char> &digest)
{
tm tm = time();
// Full chain validation against the TSA trust store (populated from TSL) is performed
// by TS_RESP_verify_token (PKCS#7 path) and CMS_verify (CMS path) below.
auto store = X509CertStore::createStore(X509CertStore::TSA, tm);
X509CertStore::instance()->activate(cert());
if(d)
Expand Down Expand Up @@ -275,7 +277,7 @@ void TS::verify(const vector<unsigned char> &digest)

auto info = make_unique_ptr<TS_TST_INFO_free>(d2i_TS_TST_INFO_bio(out.get(), nullptr));
if(ASN1_OCTET_STRING *msg = TS_MSG_IMPRINT_get_msg(TS_TST_INFO_get_msg_imprint(info.get()));
std::equal(digest.cbegin(), digest.cend(),
!std::equal(digest.cbegin(), digest.cend(),
ASN1_STRING_get0_data(msg), std::next(ASN1_STRING_get0_data(msg), ASN1_STRING_length(msg))))
THROW_OPENSSLEXCEPTION("Failed to verify TS response.");
}
Expand Down
Binary file added test/data/ASICS-test-match.asics
Binary file not shown.
Binary file added test/data/CMS-imprint-mismatch.asics
Binary file not shown.
20 changes: 20 additions & 0 deletions test/libdigidocpp_boost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,26 @@ BOOST_AUTO_TEST_CASE(OpenValidASiCSContainerWithOtherMeta)
BOOST_CHECK_NO_THROW(ts->validate());
}

BOOST_AUTO_TEST_CASE(OpenCMSTimeStampASiCSContainer)
{
// The token is pkcs7-signedData carrying id-smime-ct-TSTInfo, which d2i_PKCS7
// rejects, so TS falls back to the CMS path where the message imprint is
// compared by hand rather than by TS_RESP_verify_token. The same token over
// matching and forged content pins both directions of that comparison.
auto d = Container::openPtr("ASICS-test-match.asics");
BOOST_CHECK_EQUAL(d->dataFiles().size(), 1U);
BOOST_CHECK_EQUAL(d->signatures().size(), 1U);
BOOST_CHECK_EQUAL(d->mediaType(), ASiCS::TYPE);
BOOST_CHECK_EQUAL(d->dataFiles().front()->fileName(), "valid-bdoc-tm.bdoc");
BOOST_CHECK_NO_THROW(d->signatures().front()->validate());

auto forged = Container::openPtr("CMS-imprint-mismatch.asics");
BOOST_CHECK_EQUAL(forged->dataFiles().size(), 1U);
BOOST_CHECK_EQUAL(forged->signatures().size(), 1U);
BOOST_CHECK_EQUAL(forged->dataFiles().front()->fileName(), "forged-document.txt");
BOOST_CHECK_THROW(forged->signatures().front()->validate(), Exception);
}

BOOST_AUTO_TEST_CASE(OpenInvalidTsASiCSContainer)
{
auto d = Container::openPtr("test-invalidts.asics");
Expand Down
Loading