Skip to content

Commit

Permalink
Review comments addressed - 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Pankaj committed Jul 14, 2022
1 parent c123a73 commit 87f4edd
Show file tree
Hide file tree
Showing 32 changed files with 160 additions and 149 deletions.
6 changes: 3 additions & 3 deletions bftengine/include/bcstatetransfer/SimpleBCStateTransfer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
#include "kvstream.h"
#include "digest.hpp"

using concord::util::digest::BlockDigest;

namespace concord {
namespace storage {
class IDBClient;
Expand Down Expand Up @@ -60,7 +58,9 @@ void computeBlockDigest(const uint64_t blockId,
const uint32_t blockSize,
StateTransferDigest *outDigest);

BlockDigest computeBlockDigest(const uint64_t blockId, const char *block, const uint32_t blockSize);
concord::util::digest::BlockDigest computeBlockDigest(const uint64_t blockId,
const char *block,
const uint32_t blockSize);

// This interface should be implemented by the application/storage layer.
// It is used by the state transfer module.
Expand Down
1 change: 1 addition & 0 deletions bftengine/src/bcstatetransfer/BCStateTran.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ using concord::util::digest::DigestGenerator;

namespace bftEngine {
namespace bcst {
using concord::util::digest::BlockDigest;

void computeBlockDigest(const uint64_t blockId,
const char *block,
Expand Down
4 changes: 3 additions & 1 deletion bftengine/src/bcstatetransfer/BCStateTran.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,9 @@ class BCStateTran : public IStateTransfer {
const uint32_t blockSize,
Digest* outDigest);

static BlockDigest computeDigestOfBlock(const uint64_t blockNum, const char* block, const uint32_t blockSize);
static concord::util::digest::BlockDigest computeDigestOfBlock(const uint64_t blockNum,
const char* block,
const uint32_t blockSize);

protected:
// A wrapper function to get a block from the IAppState and compute its digest.
Expand Down
10 changes: 5 additions & 5 deletions bftengine/src/bftengine/SigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ namespace impl {

using concord::crypto::signature::PrivateKeyClassType;
using concord::crypto::signature::PublicKeyClassType;
using concord::crypto::signature::TransactionSigner;
using concord::crypto::signature::TransactionVerifier;
using concord::crypto::signature::MainReplicaSigner;
using concord::crypto::signature::MainReplicaVerifier;

concord::messages::keys_and_signatures::ClientsPublicKeys clientsPublicKeys_;

Expand Down Expand Up @@ -144,7 +144,7 @@ SigManager::SigManager(PrincipalId myId,
ConcordAssert(publicKeysMapping.size() >= numPublickeys);
if (!mySigPrivateKey.first.empty()) {
const auto signingKey = getByteArrayKeyClass<PrivateKeyClassType>(mySigPrivateKey.first, mySigPrivateKey.second);
mySigner_.reset(new TransactionSigner(signingKey.getBytes()));
mySigner_.reset(new MainReplicaSigner(signingKey.getBytes()));
}
for (const auto& p : publicKeysMapping) {
ConcordAssert(verifiers_.count(p.first) == 0);
Expand All @@ -154,7 +154,7 @@ SigManager::SigManager(PrincipalId myId,
const auto& [key, format] = publickeys[p.second];
if (iter == publicKeyIndexToVerifier.end()) {
const auto verificationKey = getByteArrayKeyClass<PublicKeyClassType>(key, format);
verifiers_[p.first] = std::make_shared<TransactionVerifier>(verificationKey.getBytes());
verifiers_[p.first] = std::make_shared<MainReplicaVerifier>(verificationKey.getBytes());
publicKeyIndexToVerifier[p.second] = verifiers_[p.first];
} else {
verifiers_[p.first] = iter->second;
Expand Down Expand Up @@ -262,7 +262,7 @@ void SigManager::setClientPublicKey(const std::string& key, PrincipalId id, KeyF
try {
std::unique_lock lock(mutex_);
const auto verificationKey = getByteArrayKeyClass<PublicKeyClassType>(key, format);
verifiers_.insert_or_assign(id, std::make_shared<TransactionVerifier>(verificationKey.getBytes()));
verifiers_.insert_or_assign(id, std::make_shared<MainReplicaVerifier>(verificationKey.getBytes()));
} catch (const std::exception& e) {
LOG_ERROR(KEY_EX_LOG, "failed to add a key for client: " << id << " reason: " << e.what());
throw;
Expand Down
26 changes: 13 additions & 13 deletions bftengine/tests/SigManager/SigManager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ std::default_random_engine generator;

using concord::crypto::signature::PrivateKeyClassType;
using concord::crypto::signature::PublicKeyClassType;
using concord::crypto::signature::TransactionSigner;
using concord::crypto::signature::TransactionVerifier;
using concord::crypto::signature::MainReplicaSigner;
using concord::crypto::signature::MainReplicaVerifier;
using concord::crypto::openssl::OpenSSLCryptoImpl;

#ifdef USE_CRYPTOPP_RSA
Expand Down Expand Up @@ -93,8 +93,8 @@ TEST(SignerAndVerifierTest, LoadSignVerifyFromHexKeyPair) {
const auto verificationKey =
getByteArrayKeyClass<PublicKeyClassType>(keyPair.second, KeyFormat::HexaDecimalStrippedFormat);

const auto signer_ = unique_ptr<TransactionSigner>(new TransactionSigner(signingKey.getBytes()));
auto verifier_ = unique_ptr<TransactionVerifier>(new TransactionVerifier(verificationKey.getBytes()));
const auto signer_ = unique_ptr<MainReplicaSigner>(new MainReplicaSigner(signingKey.getBytes()));
auto verifier_ = unique_ptr<MainReplicaVerifier>(new MainReplicaVerifier(verificationKey.getBytes()));

// sign with RSASigner/EdDSASigner
std::string sig;
Expand Down Expand Up @@ -137,8 +137,8 @@ TEST(SignerAndVerifierTest, LoadSignVerifyFromPemfiles) {
const auto signingKey = getByteArrayKeyClass<PrivateKeyClassType>(privKey, KeyFormat::PemFormat);
const auto verificationKey = getByteArrayKeyClass<PublicKeyClassType>(pubkey, KeyFormat::PemFormat);

auto verifier_ = unique_ptr<TransactionVerifier>(new TransactionVerifier(verificationKey.getBytes()));
const auto signer_ = unique_ptr<TransactionSigner>(new TransactionSigner(signingKey.getBytes()));
auto verifier_ = unique_ptr<MainReplicaVerifier>(new MainReplicaVerifier(verificationKey.getBytes()));
const auto signer_ = unique_ptr<MainReplicaSigner>(new MainReplicaSigner(signingKey.getBytes()));

// sign with RSASigner/EdDSASigner
size_t expectedSignerSigLen = signer_->signatureLength();
Expand Down Expand Up @@ -169,7 +169,7 @@ TEST(SigManagerTest, ReplicasOnlyCheckVerify) {
constexpr size_t numReplicas{4};
constexpr PrincipalId myId{0};
string myPrivKey;
unique_ptr<TransactionSigner> signers[numReplicas];
unique_ptr<MainReplicaSigner> signers[numReplicas];
set<pair<PrincipalId, const string>> publicKeysOfReplicas;

generateKeyPairs(numReplicas, ALGO_NAME);
Expand All @@ -186,7 +186,7 @@ TEST(SigManagerTest, ReplicasOnlyCheckVerify) {
continue;
}
const auto signingKey = getByteArrayKeyClass<PrivateKeyClassType>(privKey, KeyFormat::PemFormat);
signers[pid].reset(new TransactionSigner(signingKey.getBytes()));
signers[pid].reset(new MainReplicaSigner(signingKey.getBytes()));
string pubKeyFullPath({string(KEYS_BASE_PATH) + string("/") + to_string(i) + string("/") + PUB_KEY_NAME});
readFile(pubKeyFullPath, pubKey);
publicKeysOfReplicas.insert(make_pair(pid, pubKey));
Expand Down Expand Up @@ -234,7 +234,7 @@ TEST(SigManagerTest, ReplicasOnlyCheckSign) {
constexpr size_t numReplicas{4};
constexpr PrincipalId myId{0};
string myPrivKey, privKey, pubKey, sig;
unique_ptr<TransactionVerifier> verifier;
unique_ptr<MainReplicaVerifier> verifier;
set<pair<PrincipalId, const string>> publicKeysOfReplicas;
char data[RANDOM_DATA_SIZE]{0};
size_t expectedSignerSigLen;
Expand All @@ -250,7 +250,7 @@ TEST(SigManagerTest, ReplicasOnlyCheckSign) {
readFile(pubKeyFullPath, pubKey);

const auto verificationKey = getByteArrayKeyClass<PublicKeyClassType>(pubKey, KeyFormat::PemFormat);
verifier.reset(new TransactionVerifier(verificationKey.getBytes()));
verifier.reset(new MainReplicaVerifier(verificationKey.getBytes()));

// load public key of other replicas, must be done for SigManager ctor
for (size_t i{2}; i <= numReplicas; ++i) {
Expand Down Expand Up @@ -296,7 +296,7 @@ TEST(SigManagerTest, ReplicasAndClientsCheckVerify) {
constexpr PrincipalId myId{0};
string myPrivKey;
size_t i, signerIndex{0};
unique_ptr<TransactionSigner>
unique_ptr<MainReplicaSigner>
signers[numReplicas + numParticipantNodes]; // only external clients and consensus replicas sign

set<pair<PrincipalId, const string>> publicKeysOfReplicas;
Expand All @@ -317,7 +317,7 @@ TEST(SigManagerTest, ReplicasAndClientsCheckVerify) {
continue;
}
const auto signingKey = getByteArrayKeyClass<PrivateKeyClassType>(privKey, KeyFormat::PemFormat);
signers[signerIndex].reset(new TransactionSigner(signingKey.getBytes()));
signers[signerIndex].reset(new MainReplicaSigner(signingKey.getBytes()));

string pubKeyFullPath({string(KEYS_BASE_PATH) + string("/") + to_string(i) + string("/") + PUB_KEY_NAME});
readFile(pubKeyFullPath, pubKey);
Expand All @@ -333,7 +333,7 @@ TEST(SigManagerTest, ReplicasAndClientsCheckVerify) {
string privateKeyFullPath({string(KEYS_BASE_PATH) + string("/") + to_string(i) + string("/") + PRIV_KEY_NAME});
readFile(privateKeyFullPath, privKey);
const auto signingKey = getByteArrayKeyClass<PrivateKeyClassType>(privKey, KeyFormat::PemFormat);
signers[signerIndex].reset(new TransactionSigner(signingKey.getBytes()));
signers[signerIndex].reset(new MainReplicaSigner(signingKey.getBytes()));
string pubKeyFullPath({string(KEYS_BASE_PATH) + string("/") + to_string(i) + string("/") + PUB_KEY_NAME});
set<PrincipalId> principalIds;
for (size_t j{0}; j < numBftClientsInParticipantNodes; ++j) {
Expand Down
4 changes: 2 additions & 2 deletions bftengine/tests/clientsManager/ClientsManager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ using concord::crypto::openssl::OpenSSLCryptoImpl;
#endif

using concord::crypto::signature::PrivateKeyClassType;
using concord::crypto::signature::TransactionSigner;
using concord::crypto::signature::MainReplicaSigner;

// Testing values to be used for certain Concord-BFT configuration that ClientsManager and/or its dependencies may
// reference.
Expand Down Expand Up @@ -240,7 +240,7 @@ static bool verifyClientPublicKeyLoadedToKEM(NodeIdType client_id, const pair<st
}

const auto signingKey = getByteArrayKeyClass<PrivateKeyClassType>(expected_key.first, kKeyFormatForTesting);
TransactionSigner signer(signingKey.getBytes());
MainReplicaSigner signer(signingKey.getBytes());
string signature = signer.sign(kArbitraryMessageForTestingKeyAgreement);
return SigManager::instance()->verifySig(client_id,
kArbitraryMessageForTestingKeyAgreement.data(),
Expand Down
4 changes: 2 additions & 2 deletions client/bftclient/src/bft_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ using namespace bftEngine;
using namespace bftEngine::impl;
using concord::util::crypto::KeyFormat;
using concord::crypto::signature::PrivateKeyClassType;
using concord::crypto::signature::TransactionSigner;
using concord::crypto::signature::MainReplicaSigner;

namespace bft::client {

Expand Down Expand Up @@ -63,7 +63,7 @@ Client::Client(SharedCommPtr comm, const ClientConfig& config, std::shared_ptr<c
throw InvalidPrivateKeyException(file_path, config.secrets_manager_config != std::nullopt);
}
const auto signingKey = getByteArrayKeyClass<PrivateKeyClassType>(key_plaintext.value(), KeyFormat::PemFormat);
transaction_signer_ = std::make_unique<TransactionSigner>(signingKey.getBytes());
transaction_signer_ = std::make_unique<MainReplicaSigner>(signingKey.getBytes());
}
communication_->setReceiver(config_.id.val, &receiver_);
communication_->start();
Expand Down
4 changes: 2 additions & 2 deletions client/bftclient/test/bft_client_api_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ using namespace bftEngine;
using namespace placeholders;
using namespace concord::secretsmanager;
using concord::util::crypto::KeyFormat;
using concord::crypto::signature::TransactionVerifier;
using concord::crypto::signature::MainReplicaVerifier;
using concord::crypto::signature::PublicKeyClassType;
using namespace CryptoPP;

Expand Down Expand Up @@ -189,7 +189,7 @@ TEST_P(ClientApiTestParametrizedFixture, print_received_messages_and_timeout) {
auto pub_key_str = stream.str();

const auto verificationKey = getByteArrayKeyClass<PublicKeyClassType>(pub_key_str, KeyFormat::PemFormat);
transaction_verifier_.reset(new TransactionVerifier(verificationKey.getBytes()));
transaction_verifier_.reset(new MainReplicaVerifier(verificationKey.getBytes()));
}
unique_ptr<FakeCommunication> comm;
if (sign_transaction) {
Expand Down
2 changes: 1 addition & 1 deletion kvbc/include/v4blockchain/detail/blockchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Blockchain {
std::atomic<BlockId> genesis_block_id_{INVALID_BLOCK_ID};
std::shared_ptr<concord::storage::rocksdb::NativeClient> native_client_;
util::ThreadPool thread_pool_{1};
std::optional<std::future<BlockDigest>> future_digest_;
std::optional<std::future<concord::util::digest::BlockDigest>> future_digest_;
};

} // namespace concord::kvbc::v4blockchain::detail
8 changes: 4 additions & 4 deletions kvbc/src/pruning_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ namespace concord::kvbc::pruning {
using concord::util::crypto::KeyFormat;
using concord::crypto::signature::PrivateKeyClassType;
using concord::crypto::signature::PublicKeyClassType;
using concord::crypto::signature::TransactionSigner;
using concord::crypto::signature::TransactionVerifier;
using concord::crypto::signature::MainReplicaSigner;
using concord::crypto::signature::MainReplicaVerifier;

void PruningSigner::sign(concord::messages::LatestPrunableBlock& block) {
std::ostringstream oss;
Expand All @@ -37,14 +37,14 @@ void PruningSigner::sign(concord::messages::LatestPrunableBlock& block) {

PruningSigner::PruningSigner(const std::string& key) {
const auto signingKey = getByteArrayKeyClass<PrivateKeyClassType>(key, KeyFormat::HexaDecimalStrippedFormat);
signer_.reset(new TransactionSigner(signingKey.getBytes()));
signer_.reset(new MainReplicaSigner(signingKey.getBytes()));
}

PruningVerifier::PruningVerifier(const std::set<std::pair<uint16_t, const std::string>>& replicasPublicKeys) {
auto i = 0u;
for (auto& [idx, pkey] : replicasPublicKeys) {
const auto verificationKey = getByteArrayKeyClass<PublicKeyClassType>(pkey, KeyFormat::HexaDecimalStrippedFormat);
replicas_.push_back(Replica{idx, std::make_unique<TransactionVerifier>(verificationKey.getBytes())});
replicas_.push_back(Replica{idx, std::make_unique<MainReplicaVerifier>(verificationKey.getBytes())});
const auto ins_res = replica_ids_.insert(replicas_.back().principal_id);
if (!ins_res.second) {
throw std::runtime_error{"PruningVerifier found duplicate replica principal_id: " +
Expand Down
6 changes: 3 additions & 3 deletions kvbc/tools/db_editor/include/kv_blockchain_db_editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
namespace concord::kvbc::tools::db_editor {

using namespace categorization;
using concord::crypto::signature::TransactionVerifier;
using concord::crypto::signature::MainReplicaVerifier;
using concord::crypto::signature::PublicKeyClassType;

inline const auto kToolName = "kv_blockchain_db_editor"s;
Expand Down Expand Up @@ -370,7 +370,7 @@ struct VerifyBlockRequests {
const auto verificationKey = getByteArrayKeyClass<PublicKeyClassType>(
client_keys.ids_to_keys[req.clientId].key,
(concord::util::crypto::KeyFormat)client_keys.ids_to_keys[req.clientId].format);
auto verifier = std::make_unique<TransactionVerifier>(verificationKey.getBytes());
auto verifier = std::make_unique<MainReplicaVerifier>(verificationKey.getBytes());

if (req.requestPersistencyType == concord::messages::execution_data::EPersistecyType::RAW_ON_CHAIN) {
auto result = verifier->verify(req.request, req.signature);
Expand Down Expand Up @@ -1110,7 +1110,7 @@ struct VerifyDbCheckpoint {
auto key_format = ((format == "hex") ? KeyFormat::HexaDecimalStrippedFormat : KeyFormat::PemFormat);

const auto verificationKey = getByteArrayKeyClass<PublicKeyClassType>(cmd.key, key_format);
replica_keys.emplace(repId, std::make_unique<TransactionVerifier>(verificationKey.getBytes()));
replica_keys.emplace(repId, std::make_unique<MainReplicaVerifier>(verificationKey.getBytes()));
},
*val);
}
Expand Down
4 changes: 2 additions & 2 deletions reconfiguration/src/reconfiguration_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace concord::reconfiguration {
using namespace concord::messages;
using concord::util::crypto::KeyFormat;
using concord::crypto::signature::PublicKeyClassType;
using concord::crypto::signature::TransactionVerifier;
using concord::crypto::signature::MainReplicaVerifier;

bool ReconfigurationHandler::handle(const WedgeCommand& cmd,
uint64_t bft_seq_num,
Expand Down Expand Up @@ -343,7 +343,7 @@ BftReconfigurationHandler::BftReconfigurationHandler() {
verifier_.reset(new ECDSAVerifier(key_str, KeyFormat::PemFormat));
#else
const auto verificationKey = getByteArrayKeyClass<PublicKeyClassType>(key_str, KeyFormat::PemFormat);
verifier_.reset(new TransactionVerifier(verificationKey.getBytes()));
verifier_.reset(new MainReplicaVerifier(verificationKey.getBytes()));
#endif
}

Expand Down
Loading

0 comments on commit 87f4edd

Please sign in to comment.