Removed keytype config field in favour of key prefix.

This commit is contained in:
Ravin Perera
2019-10-17 10:18:51 +05:30
parent 0fb9ebf79f
commit da9c5de9d0
4 changed files with 8 additions and 14 deletions

View File

@@ -48,7 +48,7 @@ int rekey()
if (load_config() != 0)
return -1;
crypto::generate_signing_keys(cfg.pubkey, cfg.seckey, cfg.keytype);
crypto::generate_signing_keys(cfg.pubkey, cfg.seckey);
if (binpair_to_hex() != 0)
return -1;
@@ -81,7 +81,7 @@ int create_contract()
//We populate the in-memory struct with default settings and then save it to the file.
crypto::generate_signing_keys(cfg.pubkey, cfg.seckey, cfg.keytype);
crypto::generate_signing_keys(cfg.pubkey, cfg.seckey);
if (binpair_to_hex() != 0)
return -1;
@@ -169,7 +169,6 @@ int load_config()
cfg.pubkeyhex = d["pubkeyhex"].GetString();
cfg.seckeyhex = d["seckeyhex"].GetString();
cfg.keytype = d["keytype"].GetString();
cfg.binary = d["binary"].GetString();
cfg.binargs = d["binargs"].GetString();
cfg.listenip = d["listenip"].GetString();
@@ -210,7 +209,6 @@ int save_config()
d.AddMember("version", rapidjson::StringRef(util::HP_VERSION), allocator);
d.AddMember("pubkeyhex", rapidjson::StringRef(cfg.pubkeyhex.data()), allocator);
d.AddMember("seckeyhex", rapidjson::StringRef(cfg.seckeyhex.data()), allocator);
d.AddMember("keytype", rapidjson::StringRef(cfg.keytype.data()), allocator);
d.AddMember("binary", rapidjson::StringRef(cfg.binary.data()), allocator);
d.AddMember("binargs", rapidjson::StringRef(cfg.binargs.data()), allocator);
d.AddMember("listenip", rapidjson::StringRef(cfg.listenip.data()), allocator);
@@ -386,13 +384,12 @@ int is_schema_valid(rapidjson::Document &d)
const char *cfg_schema =
"{"
"\"type\": \"object\","
"\"required\": [ \"version\", \"pubkeyhex\", \"seckeyhex\", \"keytype\", \"binary\", \"binargs\", \"listenip\""
"\"required\": [ \"version\", \"pubkeyhex\", \"seckeyhex\", \"binary\", \"binargs\", \"listenip\""
", \"peers\", \"unl\", \"peerport\", \"roundtime\", \"pubport\", \"pubmaxsize\", \"pubmaxcpm\" ],"
"\"properties\": {"
"\"version\": { \"type\": \"string\" },"
"\"pubkeyhex\": { \"type\": \"string\" },"
"\"seckeyhex\": { \"type\": \"string\" },"
"\"keytype\": { \"type\": \"string\" },"
"\"binary\": { \"type\": \"string\" },"
"\"binargs\": { \"type\": \"string\" },"
"\"listenip\": { \"type\": \"string\" },"

View File

@@ -35,7 +35,6 @@ struct contract_config
std::string pubkeyhex; // Contract hex public key
std::string seckeyhex; // Contract hex secret key
std::string keytype; // Key generation algorithm used by libsodium
std::string binary; // Full path to the contract binary
std::string binargs; // CLI arguments to pass to the contract binary
std::string listenip; // The IPs to listen on for incoming connections

View File

@@ -21,10 +21,10 @@ int init()
return 0;
}
/**
/**l
* Generates a signing key pair using libsodium and assigns them to the provided strings.
*/
void generate_signing_keys(std::string &pubkey, std::string &seckey, std::string &keytype)
void generate_signing_keys(std::string &pubkey, std::string &seckey)
{
// Generate key pair using libsodium default algorithm.
// Currently using ed25519. So append prefix byte to represent that.
@@ -36,10 +36,8 @@ void generate_signing_keys(std::string &pubkey, std::string &seckey, std::string
seckey[0] = KEYPFX_ed25519;
crypto_sign_keypair(
reinterpret_cast<unsigned char *>(pubkey.data() + 1),
reinterpret_cast<unsigned char *>(seckey.data() + 1));
keytype = crypto_sign_primitive();
reinterpret_cast<unsigned char *>(pubkey.data() + 1), // +1 to skip the prefix byte.
reinterpret_cast<unsigned char *>(seckey.data() + 1)); // +1 to skip the prefix byte.
}
/**

View File

@@ -19,7 +19,7 @@ static size_t PFXD_SECKEY_BYTES = crypto_sign_SECRETKEYBYTES + 1;
int init();
void generate_signing_keys(std::string &pubkey, std::string &seckey, std::string &keytype);
void generate_signing_keys(std::string &pubkey, std::string &seckey);
std::string sign(std::string_view msg, std::string_view seckey);