* Add support for ADD, GET, REMOVE commands.
* Rename StorageCommand to LogicCommand.
* Move KeyImpl from client library to common.
Change-Id: Icd86f5dd6f7442565e542d637bf6bda9fd389aa1
XRSA_X931_PADDING
};
+// Internal types
+class KeyImpl;
+
} // namespace CKM
class Key {
public:
- class KeyImpl;
enum class ECType : unsigned int {
prime192v1
// TODO
Key();
Key(const RawData &rawData, KeyType type, const RawData &password = RawData()); // Import key
- Key(const Key &key) = delete;
- Key(Key &&key) = delete;
- Key& operator=(const Key &key) = delete;
- Key& operator=(Key &&key) = delete;
+ Key(const Key &key);
+ Key& operator=(const Key &key);
virtual ~Key(); // This destructor must overwrite memory used by key with some random data.
bool empty() const;
namespace CKM {
-Key::KeyImpl::KeyImpl()
+KeyImpl::KeyImpl()
: m_type(KeyType::KEY_NONE)
{}
-Key::KeyImpl::KeyImpl(const KeyImpl &second)
+KeyImpl::KeyImpl(const KeyImpl &second)
: m_type(second.m_type)
, m_key(second.m_key)
{}
-Key::KeyImpl::KeyImpl(KeyImpl &&second)
+KeyImpl::KeyImpl(KeyImpl &&second)
: m_type(second.m_type)
, m_key(std::move(second.m_key))
{}
-Key::KeyImpl& Key::KeyImpl::operator=(const KeyImpl &second) {
+KeyImpl& KeyImpl::operator=(const KeyImpl &second) {
m_type = second.m_type;
m_key = second.m_key;
return *this;
}
-Key::KeyImpl& Key::KeyImpl::operator=(KeyImpl &&second) {
+KeyImpl& KeyImpl::operator=(KeyImpl &&second) {
m_type = std::move(second.m_type);
m_key = std::move(second.m_key);
return *this;
}
-Key::KeyImpl::KeyImpl(IStream &stream) {
- int type;
- Deserialization::Deserialize(stream, type);
- Deserialization::Deserialize(stream, m_key);
- m_type = static_cast<KeyType>(type);
-}
+//KeyImpl::KeyImpl(IStream &stream) {
+// int type;
+// Deserialization::Deserialize(stream, type);
+// Deserialization::Deserialize(stream, m_key);
+// m_type = static_cast<KeyType>(type);
+//}
-Key::KeyImpl::KeyImpl(const RawData &data, KeyType type, const RawData &password)
+KeyImpl::KeyImpl(const RawData &data, KeyType type, const RawData &password)
: m_type(KeyType::KEY_NONE)
{
int size = 0;
BIO_free_all(bio);
}
-void Key::KeyImpl::Serialize(IStream &stream) const {
- Serialization::Serialize(stream, static_cast<int>(m_type));
- Serialization::Serialize(stream, m_key);
-}
+//void KeyImpl::Serialize(IStream &stream) const {
+// Serialization::Serialize(stream, static_cast<int>(m_type));
+// Serialization::Serialize(stream, m_key);
+//}
-Key::KeyImpl::~KeyImpl(){}
+KeyImpl::~KeyImpl(){}
} // namespace CKM
*/
#pragma once
-#include <dpl/serialization.h>
+//#include <dpl/serialization.h>
#include <ckm/ckm-type.h>
#include <ckm/key-manager.h>
namespace CKM {
-class Key::KeyImpl : public ISerializable {
+class KeyImpl
+// : public ISerializable
+{
public:
KeyImpl();
- KeyImpl(IStream &stream);
+// KeyImpl(IStream &stream);
KeyImpl(const RawData &data, KeyType type, const RawData &password);
KeyImpl(const KeyImpl &);
KeyImpl(KeyImpl &&);
}
bool empty() const {
- return m_key.empty();
+ return (m_type == KeyType::KEY_NONE) || m_key.empty();
}
- void Serialize(IStream &stream) const;
+// void Serialize(IStream &stream) const;
virtual ~KeyImpl();
private:
* @version 1.0
* @brief Key - api implementation.
*/
+#include <ckm/ckm-type.h>
#include <ckm/key-manager.h>
#include <client-key-impl.h>
: m_impl(new KeyImpl(rawData, type, password))
{}
-Key::~Key(){}
+Key::Key(const Key &second) {
+ m_impl = second.m_impl;
+}
+
+Key& Key::operator=(const Key &second) {
+ m_impl = second.m_impl;
+ return *this;
+}
+
+Key::~Key(){
+}
bool Key::empty() const {
- return m_impl->empty();
+ if (m_impl)
+ return m_impl->empty();
+ return true;
}
KeyType Key::getType() const {
- return m_impl->getType();
+ if (m_impl)
+ return m_impl->getType();
+ return KeyType::KEY_NONE;
}
RawData Key::getKey() const {
- return m_impl->getKey();
+ if (m_impl)
+ return m_impl->getKey();
+ return RawData();
}
-Key::KeyImpl* Key::getImpl() const {
- return m_impl.get();
+KeyImpl* Key::getImpl() const {
+ if (m_impl)
+ return m_impl.get();
+ return NULL;
};
* @version 1.0
* @brief Manager implementation.
*/
+#include <dpl/serialization.h>
+
#include <client-manager-impl.h>
-#include <message-buffer.h>
#include <client-common.h>
-#include <dpl/serialization.h>
-#include <protocols.h>
#include <client-key-impl.h>
+#include <message-buffer.h>
+#include <protocols.h>
namespace CKM {
return KEY_MANAGER_API_ERROR_INPUT_PARAM;
MessageBuffer send, recv;
- Serialization::Serialize(send, static_cast<int>(StorageCommand::SAVE));
+ Serialization::Serialize(send, static_cast<int>(LogicCommand::SAVE));
Serialization::Serialize(send, m_counter);
Serialization::Serialize(send, static_cast<int>(toDBDataType(key.getType())));
Serialization::Serialize(send, alias);
- Serialization::Serialize(send, key.getImpl());
+ Serialization::Serialize(send, key.getKey());
Serialization::Serialize(send, PolicySerializable(policy));
int retCode = sendToServer(
return KEY_MANAGER_API_ERROR_INPUT_PARAM;
MessageBuffer send, recv;
- Serialization::Serialize(send, static_cast<int>(StorageCommand::REMOVE));
+ Serialization::Serialize(send, static_cast<int>(LogicCommand::REMOVE));
Serialization::Serialize(send, m_counter);
Serialization::Serialize(send, static_cast<int>(DBDataType::KEY_RSA_PUBLIC));
Serialization::Serialize(send, alias);
});
}
-int Manager::ManagerImpl::getKey(const Alias &alias, const RawData &password, Key &key) {
+int Manager::ManagerImpl::getBinaryData(
+ const Alias &alias,
+ DBDataType sendDataType,
+ const RawData &password,
+ DBDataType &recvDataType,
+ RawData &rawData)
+{
return try_catch([&] {
if (alias.empty())
return KEY_MANAGER_API_ERROR_INPUT_PARAM;
MessageBuffer send, recv;
- Serialization::Serialize(send, static_cast<int>(StorageCommand::GET));
+ Serialization::Serialize(send, static_cast<int>(LogicCommand::GET));
Serialization::Serialize(send, m_counter);
- Serialization::Serialize(send, static_cast<int>(DBDataType::KEY_RSA_PUBLIC));
+ Serialization::Serialize(send, static_cast<int>(sendDataType));
Serialization::Serialize(send, alias);
Serialization::Serialize(send, password);
Deserialization::Deserialize(recv, opType);
Deserialization::Deserialize(recv, retCode);
- if (retCode == KEY_MANAGER_API_SUCCESS)
- Deserialization::Deserialize(recv, *(key.getImpl()));
+ if (retCode == KEY_MANAGER_API_SUCCESS) {
+ int tmpDataType;
+ Deserialization::Deserialize(recv, tmpDataType);
+ Deserialization::Deserialize(recv, rawData);
+ recvDataType = static_cast<DBDataType>(tmpDataType);
+ }
if (counter != m_counter) {
return KEY_MANAGER_API_ERROR_UNKNOWN;
});
}
+int Manager::ManagerImpl::getKey(const Alias &alias, const RawData &password, Key &key) {
+ DBDataType recvDataType;
+ RawData rawData;
+
+ int retCode = getBinaryData(
+ alias,
+ DBDataType::KEY_RSA_PUBLIC,
+ password,
+ recvDataType,
+ rawData);
+
+ if (retCode != KEY_MANAGER_API_SUCCESS)
+ return retCode;
+
+ Key keyParsed(rawData, toKeyType(recvDataType));
+
+ if (keyParsed.empty())
+ return KEY_MANAGER_API_ERROR_BAD_RESPONSE;
+
+ key = keyParsed;
+
+ return KEY_MANAGER_API_SUCCESS;
+}
+
} // namespace CKM
*/
#pragma once
+#include <protocols.h>
+
+#include <ckm/ckm-type.h>
#include <ckm/key-manager.h>
namespace CKM {
int removeKey(const Alias &alias);
int getKey(const Alias &alias, const RawData &password, Key &key);
-private:
+protected:
+ int getBinaryData(
+ const Alias &alias,
+ DBDataType sendDataType,
+ const RawData &password,
+ DBDataType &recvDataType,
+ RawData &rawData);
+
int m_counter;
};
namespace CKM
{
+ struct Credentials {
+ std::string realUser;
+ std::string realSmackLabel;
+ };
+
struct ConnectionInfo {
InterfaceID interfaceID;
MessageBuffer buffer;
+ Credentials credentials;
};
typedef std::map<int, ConnectionInfo> ConnectionInfoMap;
}
}
+KeyType toKeyType(DBDataType dbtype) {
+ switch(dbtype) {
+ case DBDataType::KEY_RSA_PUBLIC: return KeyType::KEY_RSA_PUBLIC;
+ case DBDataType::KEY_RSA_PRIVATE: return KeyType::KEY_RSA_PRIVATE;
+ default:
+ // TODO
+ throw 1;
+ }
+}
+
+PolicySerializable::PolicySerializable()
+{}
+
+
PolicySerializable::PolicySerializable(const Policy &policy)
: Policy(policy)
{}
RESET_USER_PASSWORD
};
-enum class StorageCommand : int {
+enum class LogicCommand : int {
GET,
SAVE,
REMOVE,
};
DBDataType toDBDataType(KeyType key);
+KeyType toKeyType(DBDataType dbDataType);
class IStream;
struct PolicySerializable : public Policy, ISerializable {
+ PolicySerializable();
explicit PolicySerializable(const Policy &);
explicit PolicySerializable(IStream &);
void Serialize(IStream &) const;
return RawBuffer();
}
+RawBuffer CKMLogic::saveData(
+ Credentials &cred,
+ int commandId,
+ DBDataType dataType,
+ const Alias &alias,
+ const RawData &key,
+ const PolicySerializable &policy)
+{
+ (void)cred;
+ (void)commandId;
+ (void)dataType;
+ (void)alias;
+ (void)key;
+ (void)policy;
+ return RawData();
+}
+
+RawBuffer CKMLogic::removeData(
+ Credentials &cred,
+ int commandId,
+ DBDataType dataType,
+ const Alias &alias)
+{
+ (void)cred;
+ (void)commandId;
+ (void)dataType;
+ (void)alias;
+ return RawData();
+}
+
+RawBuffer CKMLogic::getData(
+ Credentials &cred,
+ int commandId,
+ DBDataType dataType,
+ const Alias &alias,
+ const RawData &password)
+{
+ (void)cred;
+ (void)commandId;
+ (void)dataType;
+ (void)alias;
+ (void)password;
+ return RawData();
+}
+
} // namespace CKM
#include <string>
#include <vector>
#include <message-buffer.h>
+#include <protocols.h>
+#include <ckm/ckm-type.h>
+#include <connection-info.h>
namespace CKM {
RawBuffer resetUserPassword(
const std::string &user,
const RawBuffer &newPassword);
+
+ RawBuffer saveData(
+ Credentials &cred,
+ int commandId,
+ DBDataType dataType,
+ const Alias &alias,
+ const RawData &key,
+ const PolicySerializable &policy);
+
+ RawBuffer removeData(
+ Credentials &cred,
+ int commandId,
+ DBDataType dataType,
+ const Alias &alias);
+
+ RawBuffer getData(
+ Credentials &cred,
+ int commandId,
+ DBDataType dataType,
+ const Alias &alias,
+ const RawData &password);
+
private:
};
#include <ckm-service.h>
#include <ckm-logic.h>
+#include <client-key-impl.h>
namespace {
const CKM::InterfaceID SOCKET_ID_CONTROL = 0;
LogDebug("Read event");
auto &info = m_connectionInfoMap[event.connectionID.counter];
info.buffer.Push(event.rawBuffer);
- while(processOne(event.connectionID, info.buffer, info.interfaceID));
+ while(processOne(event.connectionID, info));
}
bool CKMService::processOne(
const ConnectionID &conn,
- MessageBuffer &buffer,
- InterfaceID interfaceID)
+ ConnectionInfo &info)
{
LogDebug ("process One");
RawBuffer response;
Try {
- if (!buffer.Ready())
+ if (!info.buffer.Ready())
return false;
- if (interfaceID == SOCKET_ID_CONTROL)
- response = processControl(buffer);
+ if (info.interfaceID == SOCKET_ID_CONTROL)
+ response = processControl(info.buffer);
else
- response = processStorage(conn, buffer);
+ response = processStorage(info.credentials, info.buffer);
m_serviceManager->Write(conn, response);
}
}
-RawBuffer CKMService::processStorage(const ConnectionID &conn, MessageBuffer &buffer){
- (void)conn;
- (void)buffer;
- return RawBuffer();
+RawBuffer CKMService::processStorage(Credentials &cred, MessageBuffer &buffer){
+ int command;
+ int commandId;
+ int tmpDataType;
+ Alias alias;
+ std::string user;
+ LogicCommand sc;
+
+ Deserialization::Deserialize(buffer, command);
+ Deserialization::Deserialize(buffer, commandId);
+
+ sc = static_cast<LogicCommand>(command);
+
+ switch(sc) {
+ case LogicCommand::SAVE:
+ {
+ RawData rawData;
+ PolicySerializable policy;
+ Deserialization::Deserialize(buffer, tmpDataType);
+ Deserialization::Deserialize(buffer, alias);
+ Deserialization::Deserialize(buffer, rawData);
+ Deserialization::Deserialize(buffer, policy);
+ return m_logic->saveData(
+ cred,
+ commandId,
+ static_cast<DBDataType>(tmpDataType),
+ alias,
+ rawData,
+ policy);
+ }
+ case LogicCommand::REMOVE:
+ {
+ Deserialization::Deserialize(buffer, tmpDataType);
+ Deserialization::Deserialize(buffer, alias);
+ return m_logic->removeData(
+ cred,
+ commandId,
+ static_cast<DBDataType>(tmpDataType),
+ alias);
+ }
+ case LogicCommand::GET:
+ {
+ RawData password;
+ Deserialization::Deserialize(buffer, tmpDataType);
+ Deserialization::Deserialize(buffer, alias);
+ Deserialization::Deserialize(buffer, password);
+ return m_logic->getData(
+ cred,
+ commandId,
+ static_cast<DBDataType>(tmpDataType),
+ alias,
+ password);
+ }
+ default:
+ // TODO
+ throw 1; // broken protocol
+ }
}
private:
bool processOne(
const ConnectionID &conn,
- MessageBuffer &buffer,
- InterfaceID interfaceID);
+ ConnectionInfo &info);
RawBuffer processControl(
MessageBuffer &buffer);
RawBuffer processStorage(
- const ConnectionID &conn,
+ Credentials &cred,
MessageBuffer &buffer);
ConnectionInfoMap m_connectionInfoMap;