Skip to content

Commit

Permalink
This commit contains:-
Browse files Browse the repository at this point in the history
i. Compilation macros (USE_CRYPTOPP_RSA and USE_EDDSA_SINGLE_SIGN) for RSA and EdDSA removed.
ii. The choice of signing algorithm is now based on the value set in 'replicaMsgSigningAlgo' and 'operatorMsgSigningAlgo' config variables.
  • Loading branch information
Pankaj committed Jul 28, 2022
1 parent 3d9a254 commit 9cd5ab7
Show file tree
Hide file tree
Showing 14 changed files with 258 additions and 533 deletions.
7 changes: 0 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ if(NOT DEFINED USE_LOG4CPP)
endif()

option(USE_RELIC "Enable usage of Relic library for BLS threshold signature generation/verification" OFF)
option(USE_CRYPTOPP_RSA "Enable usage of Crypto++ library for RSA/ECDSA signature generation/verification" OFF)
option(USE_EDDSA_SINGLE_SIGN "Enable usage of OpenSSL library for EdDSA signature generation/verification" ON)
option(RUN_APOLLO_TESTS "Enable Apollo tests run" ON)
option(KEEP_APOLLO_LOGS "Retains logs from replicas in separate folder for each test in build/tests/apollo/logs" ON)
option(TXN_SIGNING_ENABLED "Enable External concord client transcattion signing" ON)
Expand Down Expand Up @@ -68,11 +66,6 @@ if(BUILD_COMM_TCP_TLS)
math(EXPR COMM_MODULES "${COMM_MODULES}+1")
endif()

if ((NOT USE_CRYPTOPP_RSA) AND (NOT USE_EDDSA_SINGLE_SIGN))
message(FATAL_ERROR "At least one signature/verification algorithm implementation must be chosen. "
"Choose at least one of the following cmake options: [USE_EDDSA_SINGLE_SIGN, USE_CRYPTOPP_RSA]")
endif()

# UDP module is not part of the CMake configuration, it will be used by default
# if neither of plain TCP or TLS will be chosen
if(${COMM_MODULES} GREATER 1)
Expand Down
25 changes: 18 additions & 7 deletions bftengine/src/preprocessor/tests/preprocessor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using namespace std;
using namespace bft::communication;
using namespace bftEngine;
using namespace preprocessor;
using concord::crypto::signature::SIGN_VERIFY_ALGO;

namespace {

Expand All @@ -53,6 +54,7 @@ const NodeIdType replica_1 = 1;
const NodeIdType replica_2 = 2;
const NodeIdType replica_3 = 3;
const NodeIdType replica_4 = 4;
const NodeIdType replica_5 = 5;
const ViewNum viewNum = 1;
PreProcessorRecorder preProcessorRecorder;
std::shared_ptr<concord::performance::PerformanceManager> sdm = make_shared<concord::performance::PerformanceManager>();
Expand Down Expand Up @@ -155,8 +157,7 @@ class DummyPreProcessor : public PreProcessor {
};

// clang-format off
#ifdef USE_CRYPTOPP_RSA
unordered_map<NodeIdType, string> replicaPrivKeys = {
unordered_map<NodeIdType, string> replicaRSAPrivKeys = {
{replica_0, "308204BA020100300D06092A864886F70D0101010500048204A4308204A00201000282010100C55B8F7979BF24B335017082BF33EE2960E3A0"
"68DCDB45CA3017214BFB3F32649400A2484E2108C7CD07AA7616290667AF7C7A1922C82B51CA01867EED9B60A57F5B6EE33783EC258B234748"
"8B0FA3F99B05CFFBB45F80960669594B58C993D07B94D9A89ED8266D9931EAE70BB5E9063DEA9EFAF744393DCD92F2F5054624AA048C7EE50B"
Expand Down Expand Up @@ -269,7 +270,7 @@ unordered_map<NodeIdType, string> replicaPrivKeys = {
"7088BF0990AB8E232F269B5DBCD446385A66"}
};

unordered_map<NodeIdType, string> replicaPubKeys = {
unordered_map<NodeIdType, string> replicaRSAPubKeys = {
{replica_0, "30820120300D06092A864886F70D01010105000382010D00308201080282010100C55B8F7979BF24B335017082BF33EE2960E3A068DCDB45CA"
"3017214BFB3F32649400A2484E2108C7CD07AA7616290667AF7C7A1922C82B51CA01867EED9B60A57F5B6EE33783EC258B2347488B0FA3F99B"
"05CFFBB45F80960669594B58C993D07B94D9A89ED8266D9931EAE70BB5E9063DEA9EFAF744393DCD92F2F5054624AA048C7EE50BEF374FCDCE"
Expand Down Expand Up @@ -307,25 +308,27 @@ unordered_map<NodeIdType, string> replicaPubKeys = {
"BF2EA16F58773514249B03A4775C6A10561AFC8CF54B551A43FD014F3C5FE12D96AC5F117645E26D125DC7430114FA60577BF7C9AA1224D190"
"B2D8A83B020111"}
};
#elif USE_EDDSA_SINGLE_SIGN
unordered_map<NodeIdType, string> replicaPrivKeys = {

unordered_map<NodeIdType, string> replicaEdDSAPrivKeys = {
{replica_0, "61498efe1764b89357a02e2887d224154006ceacf26269f8695a4af561453eef"},
{replica_1, "247a74ab3620ec6b9f5feab9ee1f86521da3fa2804ad45bb5bf2c5b21ef105bc"},
{replica_2, "fb539bc3d66deda55524d903da26dbec1f4b6abf41ec5db521e617c64eb2c341"},
{replica_3, "55ea66e855b83ec4a02bd8fcce6bb4426ad3db2a842fa2a2a6777f13e40a4717"},
{replica_4, "f2f3d43da68329bfe31419636072e27cfd1a8fff259be4bfada667080eb00556"}
};

unordered_map<NodeIdType, string> replicaPubKeys = {
unordered_map<NodeIdType, string> replicaEdDSAPubKeys = {
{replica_0, "386f4fb049a5d8bb0706d3793096c8f91842ce380dfc342a2001d50dfbc901f4"},
{replica_1, "3f9e7dbde90477c24c1bacf14e073a356c1eca482d352d9cc0b16560a4e7e469"},
{replica_2, "2311c6013ff657844669d8b803b2e1ed33fe06eed445f966a800a8fbb8d790e8"},
{replica_3, "1ba7449655784fc9ce193a7887de1e4d3d35f7c82b802440c4f28bf678a34b34"},
{replica_4, "c426c524c92ad9d0b740f68ee312abf0298051a7e0364a867b940e9693ae6095"}
};
#endif
// clang-format on

unordered_map<NodeIdType, string> replicaPrivKeys;
unordered_map<NodeIdType, string> replicaPubKeys;

void setUpConfiguration_4() {
replicaConfig.replicaId = replica_0;
replicaConfig.numReplicas = numOfReplicas_4;
Expand Down Expand Up @@ -1046,6 +1049,14 @@ TEST(requestPreprocessingState_test, rejectMsgWithInvalidView) {
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
logging::initLogger("logging.properties");

if (replicaConfig.replicaMsgSigningAlgo == SIGN_VERIFY_ALGO::RSA) {
replicaPrivKeys = replicaRSAPrivKeys;
replicaPubKeys = replicaRSAPubKeys;
} else if (replicaConfig.replicaMsgSigningAlgo == SIGN_VERIFY_ALGO::EDDSA) {
replicaPrivKeys = replicaEdDSAPrivKeys;
replicaPubKeys = replicaEdDSAPubKeys;
}
setUpConfiguration_4();
RequestProcessingState::init(numOfRequiredReplies, &preProcessorRecorder);
PreProcessReplyMsg::setPreProcessorHistograms(&preProcessorRecorder);
Expand Down
24 changes: 13 additions & 11 deletions bftengine/tests/SigManager/SigManager_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,9 @@ using concord::crypto::signature::SignerFactory;
using concord::crypto::signature::VerifierFactory;
using concord::crypto::openssl::OpenSSLCryptoImpl;
using bftEngine::ReplicaConfig;
using concord::crypto::signature::SIGN_VERIFY_ALGO;

#ifdef USE_CRYPTOPP_RSA
constexpr char ALGO_NAME[] = "rsa";
#elif USE_EDDSA_SINGLE_SIGN
constexpr char ALGO_NAME[] = "eddsa";
#endif

void generateKeyPairs(size_t count, const char algo[]) {
void generateKeyPairs(size_t count) {
ostringstream cmd;

ASSERT_EQ(0, system(cmd.str().c_str()));
Expand All @@ -57,6 +52,12 @@ void generateKeyPairs(size_t count, const char algo[]) {
cmd.str("");
cmd.clear();

std::string algo;
if (ReplicaConfig::instance().replicaMsgSigningAlgo == SIGN_VERIFY_ALGO::RSA) {
algo = "rsa";
} else if (ReplicaConfig::instance().replicaMsgSigningAlgo == SIGN_VERIFY_ALGO::EDDSA) {
algo = "eddsa";
}
cmd << KEYS_GEN_SCRIPT_PATH << " -n " << count << " -r " << PRIV_KEY_NAME << " -u " << PUB_KEY_NAME << " -o "
<< KEYS_BASE_PARENT_PATH << " -a " << algo;
ASSERT_EQ(0, system(cmd.str().c_str()));
Expand Down Expand Up @@ -126,7 +127,8 @@ TEST(SignerAndVerifierTest, LoadSignVerifyFromPemfiles) {
string privKey, pubkey, sig;
char data[RANDOM_DATA_SIZE]{0};

generateKeyPairs(1, ALGO_NAME);
generateKeyPairs(1);

generateRandomData(data, RANDOM_DATA_SIZE);
readFile(privateKeyFullPath, privKey);
readFile(publicKeyFullPath, pubkey);
Expand Down Expand Up @@ -168,7 +170,7 @@ TEST(SigManagerTest, ReplicasOnlyCheckVerify) {
unique_ptr<ISigner> signers[numReplicas];
set<pair<PrincipalId, const string>> publicKeysOfReplicas;

generateKeyPairs(numReplicas, ALGO_NAME);
generateKeyPairs(numReplicas);

// Load signers to simulate other replicas
for (size_t i{1}; i <= numReplicas; ++i) {
Expand Down Expand Up @@ -235,7 +237,7 @@ TEST(SigManagerTest, ReplicasOnlyCheckSign) {
char data[RANDOM_DATA_SIZE]{0};
size_t expectedSignerSigLen;

generateKeyPairs(numReplicas, ALGO_NAME);
generateKeyPairs(numReplicas);

// Load my private key
string privateKeyFullPath({string(KEYS_BASE_PATH) + string("/") + to_string(1) + string("/") + PRIV_KEY_NAME});
Expand Down Expand Up @@ -298,7 +300,7 @@ TEST(SigManagerTest, ReplicasAndClientsCheckVerify) {
set<pair<const string, set<uint16_t>>> publicKeysOfClients;
unordered_map<PrincipalId, size_t> principalIdToSignerIndex;

generateKeyPairs(numReplicas + numParticipantNodes, ALGO_NAME);
generateKeyPairs(numReplicas + numParticipantNodes);

// Load replica signers to simulate other replicas
PrincipalId currPrincipalId{0};
Expand Down
31 changes: 20 additions & 11 deletions bftengine/tests/messages/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
// file.

#include "helper.hpp"
#include "ReplicaConfig.hpp"

typedef std::pair<uint16_t, std::string> IdToKeyPair;

#ifdef USE_CRYPTOPP_RSA
const char replicaPrivateKey[] =
using concord::crypto::signature::SIGN_VERIFY_ALGO;
using bftEngine::ReplicaConfig;

const std::string replicaRSAPrivateKey = {
"308204BC020100300D06092A864886F70D0101010500048204A6308204A20201000282010100BCC5BEA607F4F52A493AA2F40C2D5482D7CE37"
"DFC526E98131FDC92CE2ECA6035DB307B182EF52CA8471B78A65E445399816AFACB224F4CEA9597D4B6FE5E84030B7AF78A88BA0233263A9F0"
"E2658A6E5BE57923D9093B7D6B70FDBAEC3CDA05C5EDE237674A598F5D607A50C1C528EEAE4B690C90820901A01BF4747C39FE6BD6DA535A9B"
Expand All @@ -36,8 +39,8 @@ const char replicaPrivateKey[] =
"4B1D3F7395D5D435E5D2071AD7AF5CB08758355C8686B890CDA88B798612CEFB57CCA85D5109B5A529ECAB80B79CC685D8836ECD6F7FD67D5F"
"7502818100B33DC57C801E0824CF2C77D6D35EC51E321168DA1DED72238ECF69DF6BD485B19A2A67CFBE87F6819F5872463687295F4091C6D9"
"9AE98AD08EB45931E761D42D9CE941CEF7DF8A493FEAD8EB571BBBA21EF6403151CB25C71A9BB457D3FB058AA34AB4C1AB474C86293A26D428"
"E77960457E2631215FF7B68013877ABCCE4322";
const std::string pubKey = {
"E77960457E2631215FF7B68013877ABCCE4322"};
const std::string replicaRSAPubKey = {
"30820120300D06092A864886F70D01010105000382010D00308201080282010100B"
"CC5BEA607F4F52A493AA2F40C2D5482D7CE37DFC526E981"
"31FDC92CE2ECA6035DB307B182EF52CA8471B78A65E445399816AFACB224F4CEA95"
Expand All @@ -49,19 +52,25 @@ const std::string pubKey = {
"F6605C909F98B6C3F795354BBB988C9695F8A1E27FFC3CE4FFA64B549DD90727634"
"04FBD352C5C1A05FA3D17377E113600B1EDCAEE17687BC4"
"C1AA6F3D020111"};
#elif USE_EDDSA_SINGLE_SIGN
const char replicaPrivateKey[] = {"09a30490ebf6f6685556046f2497fd9c7df4a552998c9a9b6ebec742e8183174"};
const std::string pubKey = {"7363bc5ab96d7f85e71a5ffe0b284405ae38e2e0f032fb3ffe805d9f0e2d117b"};
#endif

const std::vector<std::string> replicasPubKeys = {pubKey, pubKey, pubKey, pubKey, pubKey, pubKey, pubKey};
const std::string replicaEdDSAPrivateKey = {"09a30490ebf6f6685556046f2497fd9c7df4a552998c9a9b6ebec742e8183174"};
const std::string replicaEdDSAPubKey = {"7363bc5ab96d7f85e71a5ffe0b284405ae38e2e0f032fb3ffe805d9f0e2d117b"};

void loadPrivateAndPublicKeys(std::string& myPrivateKey,
std::set<std::pair<uint16_t, const std::string>>& publicKeysOfReplicas,
ReplicaId myId,
size_t numReplicas) {
ConcordAssert(numReplicas <= 7);
myPrivateKey = replicaPrivateKey;

std::string pubKey;
if (ReplicaConfig::instance().replicaMsgSigningAlgo == SIGN_VERIFY_ALGO::RSA) {
myPrivateKey = replicaRSAPrivateKey;
pubKey = replicaRSAPubKey;
} else if (ReplicaConfig::instance().replicaMsgSigningAlgo == SIGN_VERIFY_ALGO::EDDSA) {
myPrivateKey = replicaEdDSAPrivateKey;
pubKey = replicaEdDSAPubKey;
}
const std::vector<std::string> replicasPubKeys{pubKey, pubKey, pubKey, pubKey, pubKey, pubKey, pubKey};

for (size_t i{0}; i < numReplicas; ++i) {
if (i == myId) continue;
publicKeysOfReplicas.insert(IdToKeyPair(i, replicasPubKeys[i].c_str()));
Expand Down
Loading

0 comments on commit 9cd5ab7

Please sign in to comment.