mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-11 23:49:38 -05:00
fixed wrong size check
This commit is contained in:
parent
aef993de55
commit
5418483934
@ -50,8 +50,10 @@ std::string publicKeyFromPrivate(std::string const &priv)
|
||||
* https://geti2p.net/spec/common-structures#keysandcert
|
||||
* https://geti2p.net/spec/common-structures#certificate
|
||||
*/
|
||||
if (priv.empty() || priv.length() < 884) // base64 ( = 663 bytes = KeyCert + priv Keys)
|
||||
if (priv.length() < privKeyMinLenth_b64) {
|
||||
RS_WARN("key to short!");
|
||||
return std::string();
|
||||
}
|
||||
|
||||
// creat a copy to work on, need to convert it to standard base64
|
||||
auto priv_copy(priv);
|
||||
@ -163,8 +165,10 @@ std::string publicKeyFromPrivate(std::string const &priv)
|
||||
|
||||
bool getKeyTypes(const std::string &key, std::string &signingKey, std::string &cryptoKey)
|
||||
{
|
||||
if (key.length() < 522) // base64 (391 bytes = 384 bytes + 7 bytes = KeysAndCert + Certificate)
|
||||
if (key.length() < pubKeyMinLenth_b64) {
|
||||
RS_WARN("key to short!");
|
||||
return false;
|
||||
}
|
||||
|
||||
// creat a copy to work on, need to convert it to standard base64
|
||||
auto key_copy(key);
|
||||
|
@ -186,6 +186,39 @@ static const std::array<std::pair<uint16_t, uint16_t>, 12> signingKeyLengths {
|
||||
/*SigningKeyType::RedDSA_SHA512_Ed25519 */ std::make_pair<uint16_t, uint16_t>( 32, 32),
|
||||
};
|
||||
|
||||
/*
|
||||
* Key length infos:
|
||||
*
|
||||
* BOB private key
|
||||
* len b64: 884
|
||||
* len pln: 663
|
||||
*
|
||||
* BOB public key / destination
|
||||
* len b64: 516
|
||||
* len pln: 387
|
||||
*
|
||||
* SAMv3 private key
|
||||
* len b64: 908
|
||||
* len pln: 679
|
||||
*
|
||||
* SAMv3 public key
|
||||
* len b64: 516
|
||||
* len pln: 387
|
||||
*
|
||||
* Example:
|
||||
* in bytes, public key only
|
||||
* 384 (Key) + 3 (Null certificate) = 387 bytes
|
||||
* 384 (Key) + 7 (key certificate) = 391 bytes
|
||||
*
|
||||
* in bytes public + private key
|
||||
* 384 (Key) + 3 (Null certificate) + 256 (ElGamal) + 20 (DSA_SHA1) = 663 bytes
|
||||
* 384 (Key) + 7 (key certificate) + 256 (ElGamal) + 32 (EdDSA_SHA512_Ed25519) = 679 bytes
|
||||
*/
|
||||
constexpr size_t pubKeyMinLenth_b64 = 516;
|
||||
constexpr size_t pubKeyMinLenth_bin = 387;
|
||||
constexpr size_t privKeyMinLenth_b64 = 884;
|
||||
constexpr size_t privKeyMinLenth_bin = 663;
|
||||
|
||||
/**
|
||||
* @brief makeOption Creates the string "lhs=rhs" used by BOB and SAM. Converts rhs
|
||||
* @param lhs option to set
|
||||
|
Loading…
Reference in New Issue
Block a user