return KEY_MANAGER_API_SUCCESS;
}
-int Manager::ManagerImpl::requestBinaryDataAliasVector(DBDataType dataType, AliasVector &aliasVector)
+int Manager::ManagerImpl::getBinaryDataAliasVector(DBDataType dataType, AliasVector &aliasVector)
{
return try_catch([&] {
});
}
-int Manager::ManagerImpl::requestKeyAliasVector(AliasVector &aliasVector) {
- return requestBinaryDataAliasVector(DBDataType::KEY_RSA_PUBLIC, aliasVector);
+int Manager::ManagerImpl::getKeyAliasVector(AliasVector &aliasVector) {
+ return getBinaryDataAliasVector(DBDataType::KEY_RSA_PUBLIC, aliasVector);
}
-int Manager::ManagerImpl::requestCertificateAliasVector(AliasVector &aliasVector) {
- return requestBinaryDataAliasVector(DBDataType::CERTIFICATE, aliasVector);
+int Manager::ManagerImpl::getCertificateAliasVector(AliasVector &aliasVector) {
+ return getBinaryDataAliasVector(DBDataType::CERTIFICATE, aliasVector);
}
-int Manager::ManagerImpl::requestDataAliasVector(AliasVector &aliasVector) {
- return requestBinaryDataAliasVector(DBDataType::BINARY_DATA, aliasVector);
+int Manager::ManagerImpl::getDataAliasVector(AliasVector &aliasVector) {
+ return getBinaryDataAliasVector(DBDataType::BINARY_DATA, aliasVector);
}
int Manager::ManagerImpl::createKeyPairRSA(
int saveKey(const Alias &alias, const Key &key, const Policy &policy);
int removeKey(const Alias &alias);
int getKey(const Alias &alias, const std::string &password, Key &key);
- int requestKeyAliasVector(AliasVector &aliasVector);
+ int getKeyAliasVector(AliasVector &aliasVector);
int saveCertificate(const Alias &alias, const Certificate &cert, const Policy &policy);
int removeCertificate(const Alias &alias);
int getCertificate(const Alias &alias, const std::string &password, Certificate &cert);
- int requestCertificateAliasVector(AliasVector &aliasVector);
+ int getCertificateAliasVector(AliasVector &aliasVector);
int saveData(const Alias &alias, const RawBuffer &rawData, const Policy &policy);
int removeData(const Alias &alias);
int getData(const Alias &alias, const std::string &password, RawBuffer &cert);
- int requestDataAliasVector(AliasVector &aliasVector);
+ int getDataAliasVector(AliasVector &aliasVector);
int createKeyPairRSA(
const int size, // size in bits [1024, 2048, 4096]
DBDataType &recvDataType,
RawBuffer &rawData);
- int requestBinaryDataAliasVector(
+ int getBinaryDataAliasVector(
DBDataType sendDataType,
AliasVector &aliasVector);
return m_impl->getData(alias, password, data);
}
-int Manager::requestKeyAliasVector(AliasVector &av) {
- return m_impl->requestKeyAliasVector(av);
+int Manager::getKeyAliasVector(AliasVector &av) {
+ return m_impl->getKeyAliasVector(av);
}
-int Manager::requestCertificateAliasVector(AliasVector &av) {
- return m_impl->requestCertificateAliasVector(av);
+int Manager::getCertificateAliasVector(AliasVector &av) {
+ return m_impl->getCertificateAliasVector(av);
}
-int Manager::requestDataAliasVector(AliasVector &av) {
- return m_impl->requestDataAliasVector(av);
+int Manager::getDataAliasVector(AliasVector &av) {
+ return m_impl->getDataAliasVector(av);
}
int Manager::createKeyPairRSA(
RawBuffer key;
int status = handler.database.getKey(cred.smackLabel, key);
if (KEY_MANAGER_API_ERROR_DB_BAD_REQUEST == status) {
+ LogDebug("No Key in database found. Generating new one for label: " << cred.smackLabel);
key = handler.keyProvider.generateDEK(cred.smackLabel);
- if (KEY_MANAGER_API_SUCCESS != handler.database.saveKey(cred.smackLabel, key))
+ if (KEY_MANAGER_API_SUCCESS != handler.database.saveKey(cred.smackLabel, key)) {
+ LogError("Failed to save key for smack label: " << cred.smackLabel);
return KEY_MANAGER_API_ERROR_DB_ERROR;
+ }
}
key = handler.keyProvider.getPureDEK(key);
handler.crypto.pushKey(cred.smackLabel, key);
try {
retCode = saveDataHelper(cred, dataType, alias, key, policy);
+ LogDebug("SaveDataHelper returned: " << retCode);
} catch (const KeyProvider::Exception::Base &e) {
LogError("KeyProvider failed with message: " << e.GetMessage());
retCode = KEY_MANAGER_API_ERROR_SERVER_ERROR;
DBDataType dataType,
const Alias &alias)
{
- (void)cred;
- (void)alias;
-
int retCode = KEY_MANAGER_API_SUCCESS;
- if (0 == m_userDataMap.count(cred.uid)) {
- retCode = KEY_MANAGER_API_ERROR_DB_LOCKED;
+ if (0 < m_userDataMap.count(cred.uid)) {
+ retCode = m_userDataMap[cred.uid].database.deleteDBRow(alias, cred.smackLabel);
} else {
- // TODO
- auto &handler = m_userDataMap[cred.uid];
- (void)handler;
+ retCode = KEY_MANAGER_API_ERROR_DB_LOCKED;
}
MessageBuffer response;
const std::string &password,
DBRow &row)
{
- (void) dataType;
+ int retCode = KEY_MANAGER_API_SUCCESS;
if (0 == m_userDataMap.count(cred.uid))
return KEY_MANAGER_API_ERROR_DB_LOCKED;
auto &handler = m_userDataMap[cred.uid];
- int retCode = handler.database.getDBRow(alias, cred.smackLabel, dataType, row);
+
+ if (dataType == DBDataType::CERTIFICATE || dataType == DBDataType::BINARY_DATA) {
+ retCode = handler.database.getDBRow(alias, cred.smackLabel, dataType, row);
+ } else if ((static_cast<int>(dataType) >= static_cast<int>(DBDataType::DB_KEY_FIRST))
+ && (static_cast<int>(dataType) <= static_cast<int>(DBDataType::DB_KEY_LAST)))
+ {
+ retCode = handler.database.getKeyDBRow(alias, cred.smackLabel, row);
+ } else {
+ LogError("Unknown type of requested data" << (int)dataType);
+ return KEY_MANAGER_API_ERROR_BAD_REQUEST;
+ }
if (KEY_MANAGER_API_SUCCESS != retCode){
LogDebug("DBCrypto::getDBRow failed with code: " << retCode);
retCode = KEY_MANAGER_API_ERROR_SERVER_ERROR;
}
+ if (KEY_MANAGER_API_SUCCESS != retCode) {
+ row.data.clear();
+ row.dataType = dataType;
+ }
+
MessageBuffer response;
Serialization::Serialize(response, static_cast<int>(LogicCommand::GET));
Serialization::Serialize(response, commandId);
DBDataType dataType)
{
int retCode = KEY_MANAGER_API_SUCCESS;
+ AliasVector aliasVector;
- if (0 == m_userDataMap.count(cred.uid)) {
- retCode = KEY_MANAGER_API_ERROR_DB_LOCKED;
- } else {
+ if (0 < m_userDataMap.count(cred.uid)) {
auto &handler = m_userDataMap[cred.uid];
- // TODO
- (void)handler;
+ if (dataType == DBDataType::CERTIFICATE || dataType == DBDataType::BINARY_DATA) {
+ retCode = handler.database.getAliases(dataType, cred.smackLabel, aliasVector);
+ } else {
+ retCode = handler.database.getKeyAliases(cred.smackLabel, aliasVector);
+ }
+ } else {
+ retCode = KEY_MANAGER_API_ERROR_DB_LOCKED;
}
MessageBuffer response;
Serialization::Serialize(response, commandId);
Serialization::Serialize(response, retCode);
Serialization::Serialize(response, static_cast<int>(dataType));
- Serialization::Serialize(response, AliasVector());
+ Serialization::Serialize(response, aliasVector);
return response.Pop();
}
const Alias &publicKeyAlias,
PolicySerializable policyPrivateKey,
PolicySerializable policyPublicKey)
-{
+{
(void)cred;
(void)size;
(void)privateKeyAlias;