Skip to content

Commit fcf6f92

Browse files
achamayouCopilot
andauthored
Debug logging of signature application (#7803)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 1e474cf commit fcf6f92

1 file changed

Lines changed: 33 additions & 2 deletions

File tree

src/node/history.h

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#pragma once
44

55
#include "ccf/crypto/cose_verifier.h"
6+
#include "ccf/ds/x509_time_fmt.h"
67
#include "ccf/pal/locking.h"
78
#include "ccf/service/tables/nodes.h"
89
#include "ccf/service/tables/service.h"
@@ -15,6 +16,7 @@
1516
#include "endian.h"
1617
#include "kv/kv_types.h"
1718
#include "kv/store.h"
19+
#include "node/cose_common.h"
1820
#include "node_signature_verify.h"
1921
#include "service/tables/signatures.h"
2022
#include "tasks/basic_task.h"
@@ -805,8 +807,37 @@ namespace ccf
805807

806808
std::vector<uint8_t> root_hash{
807809
root.h.data(), root.h.data() + root.h.size()};
808-
return cose_verifier_cached(service_info->cert)
809-
->verify_detached(cose_sig.value(), root_hash);
810+
if (!cose_verifier_cached(service_info->cert)
811+
->verify_detached(cose_sig.value(), root_hash))
812+
{
813+
return false;
814+
}
815+
816+
if (ccf::logger::config::ok(LoggerLevel::DEBUG))
817+
{
818+
try
819+
{
820+
auto receipt = ccf::cose::decode_ccf_receipt(
821+
cose_sig.value(), /* recompute_root */ false);
822+
if (receipt.phdr.cwt.iat.has_value())
823+
{
824+
LOG_DEBUG_FMT(
825+
"Verified COSE signature for TxID {}, issued at {}",
826+
receipt.phdr.ccf.txid,
827+
ccf::ds::to_x509_time_string(
828+
std::chrono::system_clock::from_time_t(
829+
receipt.phdr.cwt.iat.value())));
830+
}
831+
}
832+
catch (const std::exception& e)
833+
{
834+
LOG_DEBUG_FMT(
835+
"Failed to decode COSE protected header for debug logging: {}",
836+
e.what());
837+
}
838+
}
839+
840+
return true;
810841
}
811842

812843
std::vector<uint8_t> serialise_tree(size_t to) override

0 commit comments

Comments
 (0)