mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
add controller classes for new db tables crypto_keys and hedera_ids, update model tables for them
This commit is contained in:
parent
71837dbe61
commit
d8766f8d2d
@ -145,4 +145,27 @@ bool KeyPairHedera::verify(const unsigned char* message, size_t messageSize, Mem
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
MemoryBin* KeyPairHedera::getCryptedPrivKey(const Poco::AutoPtr<SecretKeyCryptography> password) const
|
||||||
|
{
|
||||||
|
if (password.isNull()) return nullptr;
|
||||||
|
if (!mPrivateKey) return nullptr;
|
||||||
|
|
||||||
|
MemoryBin* encryptedKey = nullptr;
|
||||||
|
if (SecretKeyCryptography::AUTH_ENCRYPT_OK == password->encrypt(mPrivateKey, &encryptedKey)) {
|
||||||
|
return encryptedKey;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
MemoryBin* KeyPairHedera::getPublicKeyCopy() const
|
||||||
|
{
|
||||||
|
auto mm = MemoryManager::getInstance();
|
||||||
|
auto public_key = mm->getFreeMemory(ed25519_pubkey_SIZE);
|
||||||
|
memcpy(*public_key, mPublicKey, ed25519_pubkey_SIZE);
|
||||||
|
return public_key;
|
||||||
}
|
}
|
||||||
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "sodium.h"
|
#include "sodium.h"
|
||||||
|
#include "SecretKeyCryptography.h"
|
||||||
#include "iroha-ed25519/include/ed25519/ed25519.h"
|
#include "iroha-ed25519/include/ed25519/ed25519.h"
|
||||||
|
|
||||||
class KeyPairHedera : public IKeyPair
|
class KeyPairHedera : public IKeyPair
|
||||||
@ -34,6 +35,7 @@ public:
|
|||||||
bool verify(const unsigned char* message, size_t messageSize, MemoryBin* signature) const;
|
bool verify(const unsigned char* message, size_t messageSize, MemoryBin* signature) const;
|
||||||
|
|
||||||
inline const unsigned char* getPublicKey() const { return mPublicKey; }
|
inline const unsigned char* getPublicKey() const { return mPublicKey; }
|
||||||
|
MemoryBin* getPublicKeyCopy() const;
|
||||||
|
|
||||||
inline bool isTheSame(const KeyPairHedera& b) const {
|
inline bool isTheSame(const KeyPairHedera& b) const {
|
||||||
return 0 == sodium_memcmp(mPublicKey, b.mPublicKey, ed25519_pubkey_SIZE);
|
return 0 == sodium_memcmp(mPublicKey, b.mPublicKey, ed25519_pubkey_SIZE);
|
||||||
@ -60,7 +62,8 @@ public:
|
|||||||
|
|
||||||
inline bool hasPrivateKey() const { return mPrivateKey != nullptr; }
|
inline bool hasPrivateKey() const { return mPrivateKey != nullptr; }
|
||||||
|
|
||||||
|
//! \brief only way to get a private key.. encrypted
|
||||||
|
MemoryBin* getCryptedPrivKey(const Poco::AutoPtr<SecretKeyCryptography> password) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
44
src/cpp/controller/CryptoKey.cpp
Normal file
44
src/cpp/controller/CryptoKey.cpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
|
||||||
|
#include "CryptoKey.h"
|
||||||
|
|
||||||
|
namespace controller {
|
||||||
|
|
||||||
|
CryptoKey::CryptoKey(model::table::CryptoKey* dbModel)
|
||||||
|
{
|
||||||
|
mDBModel = dbModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
CryptoKey::~CryptoKey()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Poco::AutoPtr<CryptoKey> CryptoKey::create(const KeyPairHedera* hederaKeyPair, Poco::AutoPtr<controller::User> user)
|
||||||
|
{
|
||||||
|
auto mm = MemoryManager::getInstance();
|
||||||
|
|
||||||
|
auto encrypted_priv_key = hederaKeyPair->getCryptedPrivKey(user->getPassword());
|
||||||
|
auto public_key = hederaKeyPair->getPublicKeyCopy();
|
||||||
|
|
||||||
|
auto db = new model::table::CryptoKey(encrypted_priv_key, public_key, model::table::KEY_TYPE_ED25519_HEDERA);
|
||||||
|
|
||||||
|
mm->releaseMemory(encrypted_priv_key);
|
||||||
|
mm->releaseMemory(public_key);
|
||||||
|
|
||||||
|
auto cryptoKey = new CryptoKey(db);
|
||||||
|
return Poco::AutoPtr<CryptoKey>(cryptoKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
Poco::AutoPtr<CryptoKey> CryptoKey::load(int id)
|
||||||
|
{
|
||||||
|
auto db = new model::table::CryptoKey();
|
||||||
|
if (1 == db->loadFromDB("id", id)) {
|
||||||
|
auto cryptoKey = new CryptoKey(db);
|
||||||
|
return Poco::AutoPtr<CryptoKey>(cryptoKey);
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
35
src/cpp/controller/CryptoKey.h
Normal file
35
src/cpp/controller/CryptoKey.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#ifndef GRADIDO_LOGIN_SERVER_CONTROLLER_CRYPTO_KEY_INCLUDE
|
||||||
|
#define GRADIDO_LOGIN_SERVER_CONTROLLER_CRYPTO_KEY_INCLUDE
|
||||||
|
|
||||||
|
#include "../model/table/CryptoKey.h"
|
||||||
|
#include "../Crypto/KeyPairHedera.h"
|
||||||
|
|
||||||
|
#include "Poco/SharedPtr.h"
|
||||||
|
|
||||||
|
#include "TableControllerBase.h"
|
||||||
|
#include "User.h"
|
||||||
|
|
||||||
|
namespace controller {
|
||||||
|
class CryptoKey : public TableControllerBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
~CryptoKey();
|
||||||
|
|
||||||
|
static Poco::AutoPtr<CryptoKey> create(const KeyPairHedera* hederaKeyPair, Poco::AutoPtr<controller::User> user);
|
||||||
|
|
||||||
|
//! if returned ptr is NULL, dataset not found
|
||||||
|
static Poco::AutoPtr<CryptoKey> load(int id);
|
||||||
|
|
||||||
|
inline bool deleteFromDB() { return mDBModel->deleteFromDB(); }
|
||||||
|
|
||||||
|
inline Poco::AutoPtr<model::table::CryptoKey> getModel() { return _getModel<model::table::CryptoKey>(); }
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
CryptoKey(model::table::CryptoKey* dbModel);
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //GRADIDO_LOGIN_SERVER_CONTROLLER_CRYPTO_KEY_INCLUDE
|
||||||
32
src/cpp/controller/HederaId.cpp
Normal file
32
src/cpp/controller/HederaId.cpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#include "HederaId.h"
|
||||||
|
|
||||||
|
namespace controller {
|
||||||
|
|
||||||
|
HederaId::HederaId(model::table::HederaId* dbModel)
|
||||||
|
{
|
||||||
|
mDBModel = dbModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
HederaId::~HederaId()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Poco::AutoPtr<HederaId> HederaId::create(Poco::UInt64 shardNum, Poco::UInt64 realmNum, Poco::UInt64 num)
|
||||||
|
{
|
||||||
|
auto db = new model::table::HederaId(shardNum, realmNum, num);
|
||||||
|
|
||||||
|
auto hedera_id = new HederaId(db);
|
||||||
|
return Poco::AutoPtr<HederaId>(hedera_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
Poco::AutoPtr<HederaId> HederaId::load(int id)
|
||||||
|
{
|
||||||
|
auto db = new model::table::HederaId();
|
||||||
|
if (1 == db->loadFromDB("id", id)) {
|
||||||
|
auto cryptoKey = new HederaId(db);
|
||||||
|
return Poco::AutoPtr<HederaId>(cryptoKey);
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
32
src/cpp/controller/HederaId.h
Normal file
32
src/cpp/controller/HederaId.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#ifndef GRADIDO_LOGIN_SERVER_CONTROLLER_HEDERA_ID_INCLUDE
|
||||||
|
#define GRADIDO_LOGIN_SERVER_CONTROLLER_HEDERA_ID_INCLUDE
|
||||||
|
|
||||||
|
#include "../model/table/HederaId.h"
|
||||||
|
|
||||||
|
#include "Poco/SharedPtr.h"
|
||||||
|
|
||||||
|
#include "TableControllerBase.h"
|
||||||
|
|
||||||
|
namespace controller {
|
||||||
|
class HederaId : public TableControllerBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
~HederaId();
|
||||||
|
|
||||||
|
static Poco::AutoPtr<HederaId> create(Poco::UInt64 shardNum, Poco::UInt64 realmNum, Poco::UInt64 num);
|
||||||
|
|
||||||
|
static Poco::AutoPtr<HederaId> load(int id);
|
||||||
|
|
||||||
|
inline bool deleteFromDB() { return mDBModel->deleteFromDB(); }
|
||||||
|
|
||||||
|
inline Poco::AutoPtr<model::table::HederaId> getModel() { return _getModel<model::table::HederaId>(); }
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
HederaId(model::table::HederaId* dbModel);
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //GRADIDO_LOGIN_SERVER_CONTROLLER_HEDERA_ID_INCLUDE
|
||||||
@ -9,6 +9,22 @@ namespace model {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CryptoKey::CryptoKey(MemoryBin* privateKey, MemoryBin* publicKey, KeyType keyType)
|
||||||
|
: mKeyType(keyType)
|
||||||
|
{
|
||||||
|
if (!privateKey) {
|
||||||
|
mPrivateKey = Poco::Nullable<Poco::Data::BLOB>();
|
||||||
|
} else {
|
||||||
|
mPrivateKey = Poco::Nullable<Poco::Data::BLOB>(Poco::Data::BLOB(*privateKey, privateKey->size()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!publicKey) {
|
||||||
|
mPublicKey = Poco::Nullable<Poco::Data::BLOB>();
|
||||||
|
} else {
|
||||||
|
mPublicKey = Poco::Nullable<Poco::Data::BLOB>(Poco::Data::BLOB(*publicKey, publicKey->size()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CryptoKey::~CryptoKey()
|
CryptoKey::~CryptoKey()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@ -8,8 +8,8 @@ namespace model {
|
|||||||
namespace table {
|
namespace table {
|
||||||
|
|
||||||
enum KeyType {
|
enum KeyType {
|
||||||
KEY_TYPE_SODIUM_ED25519 = 0,
|
KEY_TYPE_ED25519_SODIUM = 0,
|
||||||
KEY_TYPE_ED25519_REF10 = 1,
|
KEY_TYPE_ED25519_HEDERA = 1,
|
||||||
KEY_TYPE_COUNT
|
KEY_TYPE_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -17,6 +17,7 @@ namespace model {
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CryptoKey();
|
CryptoKey();
|
||||||
|
CryptoKey(MemoryBin* privateKey, MemoryBin* publicKey, KeyType keyType);
|
||||||
~CryptoKey();
|
~CryptoKey();
|
||||||
|
|
||||||
// generic db operations
|
// generic db operations
|
||||||
|
|||||||
@ -5,6 +5,13 @@ using namespace Poco::Data::Keywords;
|
|||||||
namespace model {
|
namespace model {
|
||||||
namespace table {
|
namespace table {
|
||||||
HederaId::HederaId()
|
HederaId::HederaId()
|
||||||
|
: mShardNum(0), mRealmNum(0), mNum(0)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
HederaId::HederaId(Poco::UInt64 shardNum, Poco::UInt64 realmNum, Poco::UInt64 num)
|
||||||
|
: mShardNum(shardNum), mRealmNum(realmNum), mNum(num)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,6 +11,7 @@ namespace model {
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
HederaId();
|
HederaId();
|
||||||
|
HederaId(Poco::UInt64 shardNum, Poco::UInt64 realmNum, Poco::UInt64 num);
|
||||||
~HederaId();
|
~HederaId();
|
||||||
|
|
||||||
// generic db operations
|
// generic db operations
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user