handle.database.deleteKey(appSmackLabel);
}
}
- } catch (const KeyProvider::Exception::PassWordError &e) {
- LogError("Incorrect Password " << e.GetMessage());
- retCode = CKM_API_ERROR_AUTHENTICATION_FAILED;
- } catch (const KeyProvider::Exception::Base &e) {
- LogError("Error in KeyProvider " << e.GetMessage());
- retCode = CKM_API_ERROR_SERVER_ERROR;
} catch (const Exc::Exception &e) {
retCode = e.error();
} catch (const CKM::Exception &e) {
try
{
retCode = changeUserPasswordHelper(user, oldPassword, newPassword);
- } catch (const KeyProvider::Exception::PassWordError &e) {
- LogError("Incorrect Password " << e.GetMessage());
- retCode = CKM_API_ERROR_AUTHENTICATION_FAILED;
- } catch (const KeyProvider::Exception::Base &e) {
- LogError("Error in KeyProvider " << e.GetMessage());
- retCode = CKM_API_ERROR_SERVER_ERROR;
} catch (const Exc::Exception &e) {
retCode = e.error();
} catch (const CKM::Exception &e) {
{
retCode = saveDataHelper(cred, name, label, dataType, binaryData, policy);
}
- } catch (const KeyProvider::Exception::Base &e) {
- LogError("KeyProvider failed with message: " << e.GetMessage());
- retCode = CKM_API_ERROR_SERVER_ERROR;
} catch (const DB::Crypto::Exception::InternalError &e) {
LogError("DB::Crypto failed with message: " << e.GetMessage());
retCode = CKM_API_ERROR_DB_ERROR;
int retCode = CKM_API_ERROR_UNKNOWN;
try {
retCode = saveDataHelper(cred, name, label, pkcs, keyPolicy, certPolicy);
- } catch (const KeyProvider::Exception::Base &e) {
- LogError("KeyProvider failed with message: " << e.GetMessage());
- retCode = CKM_API_ERROR_SERVER_ERROR;
+ } catch (const Exc::Exception &e) {
+ retCode = e.error();
} catch (const DB::Crypto::Exception::InternalError &e) {
LogError("DB::Crypto failed with message: " << e.GetMessage());
retCode = CKM_API_ERROR_DB_ERROR;
try {
retCode = readDataHelper(true, cred, dataType, name, label, password, row);
- } catch (const KeyProvider::Exception::Base &e) {
- LogError("KeyProvider failed with error: " << e.GetMessage());
- retCode = CKM_API_ERROR_SERVER_ERROR;
} catch (const DB::Crypto::Exception::Base &e) {
LogError("DB::Crypto failed with message: " << e.GetMessage());
retCode = CKM_API_ERROR_DB_ERROR;
// prepare response
if(retCode == CKM_API_SUCCESS)
output = PKCS12Serializable(privKey, cert, caChain);
-
- } catch (const KeyProvider::Exception::Base &e) {
- LogError("KeyProvider failed with error: " << e.GetMessage());
- retCode = CKM_API_ERROR_SERVER_ERROR;
} catch (const DB::Crypto::Exception::Base &e) {
LogError("DB::Crypto failed with message: " << e.GetMessage());
retCode = CKM_API_ERROR_DB_ERROR;
if(retCode == CKM_API_SUCCESS) {
signature = m_decider.getStore(row).getKey(row)->sign(cryptoAlg, message);
}
- } catch (const KeyProvider::Exception::Base &e) {
- LogError("KeyProvider failed with message: " << e.GetMessage());
- retCode = CKM_API_ERROR_SERVER_ERROR;
} catch (const DB::Crypto::Exception::Base &e) {
LogError("DB::Crypto failed with message: " << e.GetMessage());
retCode = CKM_API_ERROR_DB_ERROR;
}
} catch (const Exc::Exception &e) {
retCode = e.error();
- } catch (const KeyProvider::Exception::Base &e) {
- LogError("KeyProvider failed with error: " << e.GetMessage());
- retCode = CKM_API_ERROR_SERVER_ERROR;
} catch (const DB::Crypto::Exception::Base &e) {
LogError("DB::Crypto failed with message: " << e.GetMessage());
retCode = CKM_API_ERROR_DB_ERROR;
+#include <exception.h>
#include <key-provider.h>
#include <dpl/log/log.h>
{
// overwrite key
char *ptr = reinterpret_cast<char*>(keyAndInfo);
- for (size_t size = 0; size < sizeof(KeyAndInfo); ++size)
- ptr[size] = 0;
+ memset(ptr, 0, sizeof(KeyAndInfo));
// verification
for (size_t size = 0; size < sizeof(KeyAndInfo); ++size) {
- if (0 != ptr[size]) {
- delete keyAndInfo;
- ThrowMsg(Exception::Base, "KeyAndInfo in KeyAndInfoContainer "
- "was not destroyed!");
+ if (ptr[size]) {
+ LogError("Write momory error! Memory used by key was not owerwritten.");
}
}
delete keyAndInfo;
, m_isInitialized(true)
{
if (!m_isInitialized) {
- ThrowMsg(Exception::InitFailed, "Object not initialized!. Should not happened");
+ ThrowErr(Exc::InternalError, "Object not initialized!. Should not happened");
}
if (domainKEKInWrapForm.size() != sizeof(WrappedKeyAndInfo)) {
LogError("input size:" << domainKEKInWrapForm.size()
<< " Expected: " << sizeof(WrappedKeyAndInfo));
- ThrowMsg(Exception::InputParamError, "buffer doesn't have proper size to store WrappedKeyAndInfo in KeyProvider Constructor");
+ ThrowErr(Exc::InternalError, "buffer doesn't have proper size to store WrappedKeyAndInfo in KeyProvider Constructor");
}
WrappedKeyAndInfoContainer wkmcDKEK = WrappedKeyAndInfoContainer(domainKEKInWrapForm.data());
PKEK1)) {
delete[] concat_user_pass;
- ThrowMsg(Exception::OpensslEngineError, "OPENSSL_ENGINE_ERROR");
+ ThrowErr(Exc::InternalError, "OPENSSL_ENGINE_ERROR");
}
delete[] concat_user_pass;
wkmcDKEK.getWrappedKeyAndInfo().keyInfo.iv,
m_kmcDKEK->getKeyAndInfo().key))) {
- ThrowMsg(Exception::PassWordError, "VerifyDomainKEK failed in KeyProvider Constructor");
+ ThrowErr(Exc::AuthenticationFailed, "VerifyDomainKEK failed in KeyProvider Constructor");
}
m_kmcDKEK->setKeyInfo(&(wkmcDKEK.getWrappedKeyAndInfo().keyInfo));
RawBuffer KeyProvider::getPureDomainKEK()
{
if (!m_isInitialized) {
- ThrowMsg(Exception::InitFailed, "Object not initialized!");
+ ThrowErr(Exc::InternalError, "Object not initialized!");
}
// TODO secure
RawBuffer KeyProvider::getWrappedDomainKEK(const Password &password)
{
if (!m_isInitialized) {
- ThrowMsg(Exception::InitFailed, "Object not initialized!");
+ ThrowErr(Exc::InternalError, "Object not initialized!");
}
WrappedKeyAndInfoContainer wkmcDKEK = WrappedKeyAndInfoContainer();
PKEK1)) {
delete[] concat_user_pass;
- ThrowMsg(Exception::OpensslEngineError, "OPENSSL_ENGINE_ERROR");
+ ThrowErr(Exc::InternalError, "OPENSSL_ENGINE_ERROR");
}
delete[] concat_user_pass;
wkmcDKEK.getWrappedKeyAndInfo().wrappedKey,
wkmcDKEK.getWrappedKeyAndInfo().keyInfo.tag))) {
- ThrowMsg(Exception::InitFailed, "WrapDKEK Failed in KeyProvider::getDomainKEK");
+ ThrowErr(Exc::InternalError, "WrapDKEK Failed in KeyProvider::getDomainKEK");
}
wkmcDKEK.setKeyInfoKeyLength((unsigned int)wrappedKeyLength);
RawBuffer KeyProvider::getPureDEK(const RawBuffer &DEKInWrapForm)
{
if (!m_isInitialized) {
- ThrowMsg(Exception::InitFailed, "Object not initialized!");
+ ThrowErr(Exc::InternalError, "Object not initialized!");
}
if (DEKInWrapForm.size() != sizeof(WrappedKeyAndInfo)){
LogError("input size:" << DEKInWrapForm.size()
<< " Expected: " << sizeof(WrappedKeyAndInfo));
- ThrowMsg(Exception::InputParamError,
+ ThrowErr(Exc::InternalError,
"buffer doesn't have proper size to store "
"WrappedKeyAndInfo in KeyProvider::getPureDEK");
}
MAX_KEY_SIZE,
PKEK2)) {
- ThrowMsg(Exception::OpensslEngineError, "OPENSSL_ENGINE_ERROR");
+ ThrowErr(Exc::InternalError, "OPENSSL_ENGINE_ERROR");
}
if (0 > (keyLength = decryptAes256Gcm(
wkmcDEK.getWrappedKeyAndInfo().keyInfo.iv,
kmcDEK.getKeyAndInfo().key))) {
- ThrowMsg(Exception::UnwrapFailed,
+ ThrowErr(Exc::InternalError,
"UnwrapDEK Failed in KeyProvider::getPureDEK");
}
RawBuffer KeyProvider::generateDEK(const std::string &smackLabel)
{
if (!m_isInitialized) {
- ThrowMsg(Exception::InitFailed,
- "Object not initialized!");
+ ThrowErr(Exc::InternalError, "Object not initialized!");
}
WrappedKeyAndInfoContainer wkmcDEK = WrappedKeyAndInfoContainer();
if (!RAND_bytes(key, m_kmcDKEK->getKeyAndInfo().keyInfo.keyLength) ||
!RAND_bytes(wkmcDEK.getWrappedKeyAndInfo().keyInfo.iv, MAX_IV_SIZE)) {
- ThrowMsg(Exception::OpensslEngineError, "OPENSSL_ENGINE_ERROR");
+ ThrowErr(Exc::InternalError, "OPENSSL_ENGINE_ERROR");
}
if (!PKCS5_PBKDF2_HMAC_SHA1(
MAX_KEY_SIZE,
PKEK2)) {
- ThrowMsg(Exception::OpensslEngineError, "OPENSSL_ENGINE_ERROR");
+ ThrowErr(Exc::InternalError, "OPENSSL_ENGINE_ERROR");
}
int wrappedKeyLength;
wkmcDEK.getWrappedKeyAndInfo().wrappedKey,
wkmcDEK.getWrappedKeyAndInfo().keyInfo.tag))) {
- ThrowMsg(Exception::GenFailed,
- "GenerateDEK Failed in KeyProvider::generateDEK");
+ ThrowErr(Exc::InternalError, "GenerateDEK Failed in KeyProvider::generateDEK");
}
wkmcDEK.setKeyInfoKeyLength((unsigned int)wrappedKeyLength);
if (domainKEKInWrapForm.size() != sizeof(WrappedKeyAndInfo)) {
LogError("input size:" << domainKEKInWrapForm.size()
<< " Expected: " << sizeof(WrappedKeyAndInfo));
- ThrowMsg(Exception::InputParamError,
+ ThrowErr(Exc::InternalError,
"buffer doesn't have proper size to store "
"WrappedKeyAndInfo in KeyProvider::reencrypt");
}
PKEK1)) {
delete[] concat_user_pass;
- ThrowMsg(Exception::OpensslEngineError, "OPENSSL_ENGINE_ERROR");
+ ThrowErr(Exc::InternalError, "OPENSSL_ENGINE_ERROR");
}
delete[] concat_user_pass;
wkmcOldDKEK.getWrappedKeyAndInfo().keyInfo.iv,
kmcDKEK.getKeyAndInfo().key))) {
- ThrowMsg(Exception::PassWordError,
- "Incorrect Old Password ");
+ ThrowErr(Exc::AuthenticationFailed, "Incorrect Old Password ");
}
kmcDKEK.setKeyInfo(&(wkmcOldDKEK.getWrappedKeyAndInfo().keyInfo));
PKEK1)) {
delete[] concat_user_pass;
- ThrowMsg(Exception::OpensslEngineError, "OPENSSL_ENGINE_ERROR");
+ ThrowErr(Exc::InternalError, "OPENSSL_ENGINE_ERROR");
}
delete[] concat_user_pass;
wkmcNewDKEK.getWrappedKeyAndInfo().wrappedKey,
wkmcNewDKEK.getWrappedKeyAndInfo().keyInfo.tag))) {
- ThrowMsg(Exception::UnwrapFailed,
- "UpdateDomainKEK in KeyProvider::reencrypt Failed");
+ ThrowErr(Exc::InternalError, "UpdateDomainKEK in KeyProvider::reencrypt Failed");
}
wkmcNewDKEK.setKeyInfoKeyLength((unsigned int)wrappedKeyLength);
if (!RAND_bytes(wkmcDKEK.getWrappedKeyAndInfo().keyInfo.salt, MAX_SALT_SIZE) ||
!RAND_bytes(key, MAX_KEY_SIZE) ||
!RAND_bytes(wkmcDKEK.getWrappedKeyAndInfo().keyInfo.iv, MAX_IV_SIZE))
- ThrowMsg(Exception::OpensslEngineError, "OPENSSL_ENGINE_ERROR");
+ ThrowErr(Exc::InternalError, "OPENSSL_ENGINE_ERROR");
int wrappedKeyLength;
char *concat_user_pass = NULL;
PKEK1)) {
delete[] concat_user_pass;
- ThrowMsg(Exception::OpensslEngineError, "OPENSSL_ENGINED_ERROR");
+ ThrowErr(Exc::InternalError, "OPENSSL_ENGINED_ERROR");
}
delete[] concat_user_pass;
wkmcDKEK.getWrappedKeyAndInfo().wrappedKey,
wkmcDKEK.getWrappedKeyAndInfo().keyInfo.tag))) {
- ThrowMsg(Exception::GenFailed,
+ ThrowErr(Exc::InternalError,
"GenerateDomainKEK Failed in KeyProvider::generateDomainKEK");
}