Stringify, PrintError> FileSystemFailed;
typedef DefineException<CKM_API_ERROR_AUTHENTICATION_FAILED,
StringifyDebug, PrintDebug> AuthenticationFailed;
+typedef DefineException<CKM_API_ERROR_DB_ERROR,
+ StringifyError, PrintError> DatabaseFailed;
+
+
+struct TransactionFailed : public DatabaseFailed {
+ template<typename... Args>
+ TransactionFailed(const char *path, const char *function, int line, const Args&... args)
+ : DatabaseFailed(path, function, line, args...)
+ {}
+};
} // namespace Exc
} // namespace CKM
}
}
- } catch (const DB::Crypto::Exception::InternalError &e) {
- LogError("DB::Crypto couldn't remove data: " << e.GetMessage());
- retCode = CKM_API_ERROR_DB_ERROR;
- } catch (const DB::Crypto::Exception::TransactionError &e) {
- LogError("DB::Crypto transaction failed with message " << e.GetMessage());
- retCode = CKM_API_ERROR_DB_ERROR;
} catch (const Exc::Exception &e) {
retCode = e.error();
} catch (const CKM::Exception &e) {
{
retCode = saveDataHelper(cred, name, label, binaryData, policy);
}
- } catch (const DB::Crypto::Exception::InternalError &e) {
- LogError("DB::Crypto failed with message: " << e.GetMessage());
- retCode = CKM_API_ERROR_DB_ERROR;
- } catch (const DB::Crypto::Exception::TransactionError &e) {
- LogError("DB::Crypto transaction failed with message " << e.GetMessage());
- retCode = CKM_API_ERROR_DB_ERROR;
} catch (const Exc::Exception &e) {
retCode = e.error();
} catch (const CKM::Exception &e) {
if (retCode == CKM_API_SUCCESS)
key = std::move(obj);
return retCode;
- } catch (const DB::Crypto::Exception::Base &e) {
- LogError("DB::Crypto failed with message: " << e.GetMessage());
- return CKM_API_ERROR_DB_ERROR;
} catch (const Exc::Exception &e) {
return e.error();
} catch (const CKM::Exception &e) {
retCode = saveDataHelper(cred, name, label, pkcs, keyPolicy, certPolicy);
} 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;
- } catch (const DB::Crypto::Exception::TransactionError &e) {
- LogError("DB::Crypto transaction failed with message " << e.GetMessage());
- retCode = CKM_API_ERROR_DB_ERROR;
} catch (const CKM::Exception &e) {
LogError("CKM::Exception: " << e.GetMessage());
retCode = CKM_API_ERROR_SERVER_ERROR;
{
retCode = e.error();
}
- catch (const CKM::Exception &)
+ catch (const CKM::Exception &e)
{
- LogError("Error in deleting row!");
+ LogError("Error: " << e.GetMessage());
retCode = CKM_API_ERROR_DB_ERROR;
}
retCode = readDataHelper(true, cred, dataType, name, label, password, obj, objDataType);
if(retCode == CKM_API_SUCCESS)
row.data = std::move(obj->getBinary());
- } 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 CKM::Exception &e) {
// prepare response
if(retCode == CKM_API_SUCCESS)
output = PKCS12Serializable(privKey, cert, caChain);
- } 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 CKM::Exception &e) {
{
auto &database = m_userDataMap[cred.clientUid].database;
- Try {
+ try {
LabelNameVector tmpVector;
if (dataType.isKey()) {
// list all key types
}
labelNameVector.insert(labelNameVector.end(), tmpVector.begin(), tmpVector.end());
retCode = CKM_API_SUCCESS;
- }
- Catch (CKM::Exception) {
- LogError("Failed to get names");
+ } catch (const CKM::Exception &e) {
+ LogError("Error: " << e.GetMessage());
retCode = CKM_API_ERROR_DB_ERROR;
+ } catch (const Exc::Exception &e) {
+ retCode = e.error();
}
}
return retCode;
policyPublic);
} catch(const Exc::Exception &e) {
retCode = e.error();
- } catch (DB::Crypto::Exception::TransactionError &e) {
- LogDebug("DB::Crypto error: transaction error: " << e.GetMessage());
- retCode = CKM_API_ERROR_DB_ERROR;
- } catch (DB::Crypto::Exception::InternalError &e) {
- LogDebug("DB::Crypto internal error: " << e.GetMessage());
- retCode = CKM_API_ERROR_DB_ERROR;
} catch (const CKM::Exception &e) {
LogError("CKM::Exception: " << e.GetMessage());
retCode = CKM_API_ERROR_SERVER_ERROR;
} catch (std::invalid_argument &e) {
LogDebug("invalid argument error: " << e.what());
retCode = CKM_API_ERROR_INPUT_PARAM;
- } catch (DB::Crypto::Exception::TransactionError &e) {
- LogDebug("DB::Crypto error: transaction error: " << e.GetMessage());
- retCode = CKM_API_ERROR_DB_ERROR;
- } catch (DB::Crypto::Exception::InternalError &e) {
- LogDebug("DB::Crypto internal error: " << e.GetMessage());
- retCode = CKM_API_ERROR_DB_ERROR;
} catch (const CKM::Exception &e) {
LogError("CKM::Exception: " << e.GetMessage());
retCode = CKM_API_ERROR_SERVER_ERROR;
chainRawVector);
} catch (const Exc::Exception &e) {
retCode = e.error();
- } catch (const DB::Crypto::Exception::Base &e) {
- LogError("DB::Crypto failed with message: " << e.GetMessage());
- retCode = CKM_API_ERROR_DB_ERROR;
} catch (const std::exception& e) {
LogError("STD exception " << e.what());
retCode = CKM_API_ERROR_SERVER_ERROR;
trustedCertificates,
useTrustedSystemCertificates,
chainRawVector);
- } 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 std::exception& e) {
if(retCode == CKM_API_SUCCESS) {
signature = obj->sign(cryptoAlg, message);
}
- } 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 CKM::Exception &e) {
LogError("Unknown CKM::Exception: " << e.GetMessage());
retCode = CKM_API_ERROR_SERVER_ERROR;
+ } catch (const std::exception &e) {
+ LogError("STD exception " << e.what());
+ retCode = CKM_API_ERROR_SERVER_ERROR;
}
auto response = MessageBuffer::Serialize(static_cast<int>(LogicCommand::CREATE_SIGNATURE),
}
} catch (const Exc::Exception &e) {
retCode = e.error();
- } catch (const DB::Crypto::Exception::Base &e) {
- LogError("DB::Crypto failed with message: " << e.GetMessage());
- retCode = CKM_API_ERROR_DB_ERROR;
} catch (const CKM::Exception &e) {
LogError("Unknown CKM::Exception: " << e.GetMessage());
retCode = CKM_API_ERROR_SERVER_ERROR;
const PermissionMask permissionMask)
{
int retCode;
- Try {
+ try {
retCode = setPermissionHelper(cred, name, label, accessorLabel, permissionMask);
} catch (const Exc::Exception &e) {
retCode = e.error();
- } Catch (CKM::Exception) {
- LogError("Error in set row!");
+ } catch (const CKM::Exception &e) {
+ LogError("Error: " << e.GetMessage());
retCode = CKM_API_ERROR_DB_ERROR;
}
#include <dpl/db/sql_connection.h>
#include <dpl/log/log.h>
#include <ckm/ckm-error.h>
+#include <exception.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
initDatabase();
m_connection->ExecCommand("VACUUM;");
} Catch(SqlConnection::Exception::ConnectionBroken) {
- LogError("Couldn't connect to database: " << path);
- ReThrow(Crypto::Exception::InternalError);
+ ThrowErr(Exc::DatabaseFailed, "Couldn't connect to database: ", path, _rethrown_exception.GetMessage());
} Catch(SqlConnection::Exception::InvalidArguments) {
- LogError("Couldn't set the key for database");
- ReThrow(Crypto::Exception::InternalError);
+ ThrowErr(Exc::DatabaseFailed, "Couldn't set the key for database. ", _rethrown_exception.GetMessage());
} Catch(SqlConnection::Exception::SyntaxError) {
- LogError("Couldn't initiate the database");
- ReThrow(Crypto::Exception::InternalError);
+ ThrowErr(Exc::DatabaseFailed, "Couldn't initiate the database. ", _rethrown_exception.GetMessage());
} Catch(SqlConnection::Exception::InternalError) {
- LogError("Couldn't create the database");
- ReThrow(Crypto::Exception::InternalError);
+ ThrowErr(Exc::DatabaseFailed, "Couldn't create the database. ", _rethrown_exception.GetMessage());
}
}
ScriptOptional script = getScript(SCRIPT_CREATE_SCHEMA);
if(!script)
{
- std::string errmsg = "Can not create the database schema: no initialization script";
- LogError(errmsg);
- ThrowMsg(Exception::InternalError, errmsg);
+ ThrowErr(Exc::DatabaseFailed, "Can not create the database schema: no initialization script");
}
m_connection->ExecCommand((*script).c_str());
ScriptOptional script = getScript(SCRIPT_DROP_ALL_ITEMS);
if(!script)
{
- std::string errmsg = "Can not clear the database: no clearing script";
- LogError(errmsg);
- ThrowMsg(Exception::InternalError, errmsg);
+ ThrowErr(Exc::DatabaseFailed, "Can not clear the database: no clearing script");
}
m_connection->ExecCommand((*script).c_str());
} Catch(SqlConnection::Exception::InternalError) {
LogError("Couldn't execute insert statement");
}
- ThrowMsg(Crypto::Exception::InternalError,
- "Couldn't check if name and label pair is present");
+ ThrowErr(Exc::DatabaseFailed, "Couldn't check if name and label pair is present");
}
void Crypto::saveRows(const Name &name, const Label &owner, const RowVector &rows)
} Catch(SqlConnection::Exception::InternalError) {
LogError("Couldn't execute insert statement: " << _rethrown_exception.GetMessage());
}
- ThrowMsg(Crypto::Exception::InternalError,
- "Couldn't save Row");
+ ThrowErr(Exc::DatabaseFailed, "Couldn't save Row");
}
void Crypto::saveRow(const Row &row) {
} Catch(SqlConnection::Exception::InternalError) {
LogError("Couldn't execute insert statement");
}
- ThrowMsg(Crypto::Exception::InternalError,
- "Couldn't save Row");
+ ThrowErr(Exc::DatabaseFailed, "Couldn't save Row");
}
void Crypto::updateRow(const Row &row) {
} Catch(SqlConnection::Exception::InternalError) {
LogError("Couldn't execute update statement");
}
- ThrowMsg(Crypto::Exception::InternalError,
- "Couldn't update Row");
+ ThrowErr(Exc::DatabaseFailed, "Couldn't update Row");
}
bool Crypto::deleteRow(
} Catch (SqlConnection::Exception::InternalError) {
LogError("Couldn't execute delete statement");
}
- ThrowMsg(Crypto::Exception::InternalError,
- "Couldn't delete Row for name " << name << " using ownerLabel " << ownerLabel);
+ ThrowErr(Exc::DatabaseFailed,
+ "Couldn't delete Row for name ", name, " using ownerLabel ", ownerLabel);
}
Row Crypto::getRow(
} Catch (SqlConnection::Exception::InternalError) {
LogError("Couldn't execute select statement");
}
- ThrowMsg(Crypto::Exception::InternalError,
- "Couldn't get row of type <" <<
- static_cast<int>(typeRangeStart) << "," <<
- static_cast<int>(typeRangeStop) << ">" <<
- " name " << name << " with owner label " << ownerLabel);
+ ThrowErr(Exc::DatabaseFailed,
+ "Couldn't get row of type <",
+ static_cast<int>(typeRangeStart), ",",
+ static_cast<int>(typeRangeStop), ">",
+ " name ", name, " with owner label ", ownerLabel);
}
void Crypto::getRows(
} Catch (SqlConnection::Exception::InternalError) {
LogError("Couldn't execute select statement");
}
- ThrowMsg(Crypto::Exception::InternalError,
- "Couldn't get row of type <" <<
- static_cast<int>(typeRangeStart) << "," <<
- static_cast<int>(typeRangeStop) << ">" <<
- " name " << name << " with owner label " << ownerLabel);
+ ThrowErr(Exc::DatabaseFailed,
+ "Couldn't get row of type <",
+ static_cast<int>(typeRangeStart), ",",
+ static_cast<int>(typeRangeStop), ">",
+ " name ", name, " with owner label ", ownerLabel);
}
void Crypto::listNames(
} Catch (SqlConnection::Exception::InternalError) {
LogError("Couldn't execute select statement");
}
- ThrowMsg(Crypto::Exception::InternalError,
- "Couldn't list names of type <" <<
- static_cast<int>(typeRangeStart) << "," <<
- static_cast<int>(typeRangeStop) << ">" <<
- " accessible to client label " << smackLabel);
+ ThrowErr(Exc::DatabaseFailed,
+ "Couldn't list names of type <",
+ static_cast<int>(typeRangeStart), ",",
+ static_cast<int>(typeRangeStop), ">",
+ " accessible to client label ", smackLabel);
}
} Catch (SqlConnection::Exception::InternalError) {
LogError("Couldn't execute insert statement");
}
- ThrowMsg(Crypto::Exception::InternalError,
- "Couldn't save key for label " << label);
+ ThrowErr(Exc::DatabaseFailed, "Couldn't save key for label ", label);
}
Crypto::RawBufferOptional Crypto::getKey(const Label& label)
} Catch (SqlConnection::Exception::InternalError) {
LogError("Couldn't execute insert statement");
}
- ThrowMsg(Crypto::Exception::InternalError,
- "Couldn't get key for label " << label);
+ ThrowErr(Exc::DatabaseFailed, "Couldn't get key for label ", label);
}
void Crypto::deleteKey(const Label& label) {
} Catch (SqlConnection::Exception::InternalError) {
LogError("Couldn't execute insert statement");
}
- ThrowMsg(Crypto::Exception::InternalError,
- "Couldn't delete key for label " << label);
+ ThrowErr(Exc::DatabaseFailed, "Couldn't delete key for label ", label);
}
void Crypto::setPermission(
} Catch (SqlConnection::Exception::InternalError) {
LogError("Couldn't execute set statement");
}
- ThrowMsg(Crypto::Exception::InternalError,
- "Couldn't set permissions for name " << name );
+ ThrowErr(Exc::DatabaseFailed, "Couldn't set permissions for name ", name);
}
#include <dpl/db/sql_connection.h>
#include <ckm/ckm-type.h>
+#include <exception.h>
#include <db-row.h>
#include <permission.h>
#include <protocols.h>
public:
typedef boost::optional<Row> RowOptional;
typedef boost::optional<RawBuffer> RawBufferOptional;
- class Exception
- {
- public:
- DECLARE_EXCEPTION_TYPE(CKM::Exception, Base)
- DECLARE_EXCEPTION_TYPE(Base, InternalError)
- DECLARE_EXCEPTION_TYPE(Base, TransactionError)
- DECLARE_EXCEPTION_TYPE(Base, InvalidArgs)
- };
Crypto() :
m_connection(NULL),
m_inUserTransaction(false)
m_db->m_inUserTransaction = true;
m_inTransaction = true;
} Catch (SqlConnection::Exception::InternalError) {
- LogError("sqlite got into infinite busy state");
- ReThrow(Crypto::Exception::TransactionError);
+ ThrowErr(Exc::TransactionFailed, "sqlite got into infinite busy state");
} Catch (SqlConnection::Exception::Base) {
- LogError("Couldn't begin transaction");
- ReThrow(Crypto::Exception::TransactionError);
+ ThrowErr(Exc::TransactionFailed, "Couldn't begin transaction");
}
}
}
m_db->m_inUserTransaction = false;
m_inTransaction = false;
} Catch (SqlConnection::Exception::InternalError) {
- LogError("sqlite got into infinite busy state");
- ReThrow(Crypto::Exception::TransactionError);
+ ThrowErr(Exc::TransactionFailed, "sqlite got into infinite busy state");
} Catch (SqlConnection::Exception::Base) {
- LogError("Couldn't commit transaction");
- ReThrow(Crypto::Exception::TransactionError);
+ ThrowErr(Exc::TransactionFailed, "Couldn't commit transaction");
}
}
}
m_db->m_inUserTransaction = false;
m_inTransaction = false;
} Catch (SqlConnection::Exception::InternalError) {
- LogError("sqlite got into infinite busy state");
- ReThrow(Crypto::Exception::TransactionError);
+ ThrowErr(Exc::TransactionFailed, "sqlite got into infinite busy state");
} Catch (SqlConnection::Exception::Base) {
- LogError("Couldn't rollback transaction");
- ReThrow(Crypto::Exception::TransactionError);
+ ThrowErr(Exc::TransactionFailed, "Couldn't rollback transaction");
}
}
}
m_db->m_connection->RollbackTransaction();
}
} Catch (SqlConnection::Exception::InternalError) {
- LogError("sqlite got into infinite busy state");
- ReThrow(Crypto::Exception::TransactionError);
+ ThrowErr(Exc::TransactionFailed, "sqlite got into infinite busy state");
} Catch (SqlConnection::Exception::Base) {
LogError("Transaction rollback failed!");
}