Fixed fatal bug causing deletion of stack-allocated cryptographic keyset: keyset is no longer stack-allocated :P
AsyncKeys destructor now completely deletes keydata
This commit is contained in:
parent
04ef028372
commit
88928ba722
@ -165,7 +165,6 @@ namespace Crypto {
|
|||||||
namespace RSA {
|
namespace RSA {
|
||||||
// -------- RSA START --------
|
// -------- RSA START --------
|
||||||
KeyData* rsa_gen_keys() {
|
KeyData* rsa_gen_keys() {
|
||||||
KeyData* k = new KeyData();
|
|
||||||
|
|
||||||
CryptoPP::InvertibleRSAFunction params;
|
CryptoPP::InvertibleRSAFunction params;
|
||||||
CryptoPP::RandomPool rng;
|
CryptoPP::RandomPool rng;
|
||||||
@ -174,8 +173,8 @@ namespace Crypto {
|
|||||||
rng.IncorporateEntropy((const byte*)&t, sizeof(t) * 8);
|
rng.IncorporateEntropy((const byte*)&t, sizeof(t) * 8);
|
||||||
|
|
||||||
params.GenerateRandomWithKeySize(rng, 3072);
|
params.GenerateRandomWithKeySize(rng, 3072);
|
||||||
k->privKey = CryptoPP::RSA::PrivateKey(params);
|
|
||||||
k->publKey = CryptoPP::RSA::PublicKey(params);
|
KeyData* k = new KeyData{ new CryptoPP::RSA::PrivateKey(params), new CryptoPP::RSA::PublicKey(params) };
|
||||||
return k;
|
return k;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,8 +50,8 @@ namespace Crypto {
|
|||||||
|
|
||||||
namespace RSA {
|
namespace RSA {
|
||||||
struct KeyData {
|
struct KeyData {
|
||||||
CryptoPP::RSA::PrivateKey privKey;
|
CryptoPP::RSA::PrivateKey *privKey;
|
||||||
CryptoPP::RSA::PublicKey publKey;
|
CryptoPP::RSA::PublicKey *publKey;
|
||||||
};
|
};
|
||||||
|
|
||||||
char* serializeKey(CryptoPP::RSA::PublicKey&, ulong_64b* rSize);
|
char* serializeKey(CryptoPP::RSA::PublicKey&, ulong_64b* rSize);
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
namespace IO {
|
namespace IO {
|
||||||
@ -23,9 +24,17 @@ namespace IO {
|
|||||||
done = suppressDelete = true;
|
done = suppressDelete = true;
|
||||||
keys = predef;
|
keys = predef;
|
||||||
}
|
}
|
||||||
AsyncKeys::~AsyncKeys() { if (!suppressDelete) delete keys; }
|
AsyncKeys::~AsyncKeys() {
|
||||||
|
if (!suppressDelete) {
|
||||||
|
delete keys->privKey;
|
||||||
|
delete keys->publKey;
|
||||||
|
delete keys;
|
||||||
|
}
|
||||||
|
}
|
||||||
Crypto::RSA::KeyData* AsyncKeys::get() {
|
Crypto::RSA::KeyData* AsyncKeys::get() {
|
||||||
if (!done) keys = gen.get();
|
if (!done) {
|
||||||
|
keys = gen.get();
|
||||||
|
}
|
||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,7 +284,7 @@ namespace IO {
|
|||||||
delete[] size;
|
delete[] size;
|
||||||
|
|
||||||
p.message = readSparse(sparse, p.size);
|
p.message = readSparse(sparse, p.size);
|
||||||
if (encrypted) p.message = Crypto::full_auto_decrypt(p.message, keyData->get()->privKey, &p.size);
|
if (encrypted) p.message = Crypto::full_auto_decrypt(p.message, *keyData->get()->privKey, &p.size);
|
||||||
|
|
||||||
p.packetUID = p.message[0];
|
p.packetUID = p.message[0];
|
||||||
if (p.packetUID != expectedNextPUID) continue; // Detect packet replay/mismatch
|
if (p.packetUID != expectedNextPUID) continue; // Detect packet replay/mismatch
|
||||||
@ -308,12 +317,12 @@ namespace IO {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ulong_64b size;
|
ulong_64b size;
|
||||||
char* c = Crypto::RSA::serializeKey(keyData->get()->publKey, &size);
|
char* c = Crypto::RSA::serializeKey(*keyData->get()->publKey, &size);
|
||||||
_write(c, size); // This shouldn't be encrypted
|
_write(c, size); // This shouldn't be encrypted
|
||||||
delete[] c;
|
delete[] c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else throw new _exception(); // Incompatible cryptographic requirements!
|
else throw new std::exception(); // Incompatible cryptographic requirements!
|
||||||
}
|
}
|
||||||
if (fm_neg_hasLevel && !fm_neg_hasSize && encrypted && sparse->size() >= sizeof(ulong_64b)) {
|
if (fm_neg_hasLevel && !fm_neg_hasSize && encrypted && sparse->size() >= sizeof(ulong_64b)) {
|
||||||
fm_neg_hasSize = true;
|
fm_neg_hasSize = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user