${KEY_MANAGER_CLIENT_ASYNC_SRC_PATH}/service.cpp
${KEY_MANAGER_CLIENT_ASYNC_SRC_PATH}/storage-receiver.cpp
${KEY_MANAGER_CLIENT_ASYNC_SRC_PATH}/ocsp-receiver.cpp
+ ${KEY_MANAGER_CLIENT_ASYNC_SRC_PATH}/encryption-receiver.cpp
${KEY_MANAGER_CLIENT_ASYNC_SRC_PATH}/descriptor-set.cpp
${KEY_MANAGER_CLIENT_CAPI_SRC_PATH}/ckmc-type.cpp
${KEY_MANAGER_CLIENT_CAPI_SRC_PATH}/ckmc-error.cpp
/*
- * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
virtual void ReceivedSetPermission() {}
+ virtual void ReceivedEncrypted(RawBuffer &&) {}
+ virtual void ReceivedDecrypted(RawBuffer &&) {}
+
virtual ~Observer() {}
};
const Label& accessor,
PermissionMask permissionMask);
+ void encrypt(
+ const ObserverPtr& observer,
+ const CryptoAlgorithm& algo,
+ const Alias& keyAlias,
+ const Password& password,
+ const RawBuffer& plain);
+
+ void decrypt(
+ const ObserverPtr& observer,
+ const CryptoAlgorithm& algo,
+ const Alias& keyAlias,
+ const Password& password,
+ const RawBuffer& encrypted);
+
private:
std::unique_ptr<Impl> m_impl;
};
/*
- * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
throw std::invalid_argument("Empty observer");
}
+void ManagerAsync::Impl::crypt(
+ const ObserverPtr& observer,
+ const CryptoAlgorithm& algo,
+ const Alias& keyAlias,
+ const Password& password,
+ const RawBuffer& input,
+ bool encryption)
+{
+ observerCheck(observer);
+ if (input.empty() || keyAlias.empty())
+ return observer->ReceivedError(CKM_API_ERROR_INPUT_PARAM);
+
+ try_catch_async([&] {
+ AliasSupport helper(keyAlias);
+ CryptoAlgorithmSerializable cas(algo);
+ m_counter++;
+
+ auto send = MessageBuffer::Serialize(
+ static_cast<int>(encryption?EncryptionCommand::ENCRYPT:EncryptionCommand::DECRYPT),
+ m_counter,
+ cas,
+ helper.getName(),
+ helper.getLabel(),
+ password,
+ input);
+ thread()->sendMessage(AsyncRequest(observer,
+ SERVICE_SOCKET_ENCRYPTION,
+ send.Pop(),
+ m_counter));
+ }, [&observer](int error){ observer->ReceivedError(error); } );
+}
+
} // namespace CKM
/*
- * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
}, [&observer](int error){ observer->ReceivedError(error); } );
}
+ void crypt(
+ const ObserverPtr& observer,
+ const CryptoAlgorithm& algo,
+ const Alias& keyAlias,
+ const Password& password,
+ const RawBuffer& input,
+ bool encryption);
+
private:
template <typename... Args>
/*
- * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
m_impl->setPermission(observer, alias, accessor, permissionMask);
}
+void ManagerAsync::encrypt(
+ const ObserverPtr& observer,
+ const CryptoAlgorithm& algo,
+ const Alias& keyAlias,
+ const Password& password,
+ const RawBuffer& plain)
+{
+ m_impl->crypt(observer, algo, keyAlias, password, plain, true);
+}
+
+void ManagerAsync::decrypt(
+ const ObserverPtr& observer,
+ const CryptoAlgorithm& algo,
+ const Alias& keyAlias,
+ const Password& password,
+ const RawBuffer& encrypted)
+{
+ m_impl->crypt(observer, algo, keyAlias, password, encrypted, false);
+}
+
} // namespace CKM
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+/*
+ * @file encryption-receiver.cpp
+ * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
+ * @version 1.0
+ */
+
+#include <encryption-receiver.h>
+#include <dpl/log/log.h>
+#include <protocols.h>
+
+namespace CKM {
+
+EncryptionReceiver::EncryptionReceiver(MessageBuffer& buffer, AsyncRequest::Map& requests) :
+ m_buffer(buffer),
+ m_requests(requests)
+{
+}
+
+void EncryptionReceiver::processResponse()
+{
+ int command = 0;
+ int id = 0;
+ int retCode;
+ RawBuffer output;
+ m_buffer.Deserialize(command, id, retCode, output);
+
+ auto it = m_requests.find(id);
+ if (it == m_requests.end()) {
+ LogError("Request with id " << id << " not found!");
+ ThrowMsg(BadResponse, "Request with id " << id << " not found!");
+ }
+
+ // let it throw
+ AsyncRequest req = std::move(m_requests.at(id));
+ m_requests.erase(id);
+
+ switch (static_cast<EncryptionCommand>(command)) {
+ case EncryptionCommand::ENCRYPT:
+ if (retCode == CKM_API_SUCCESS)
+ req.observer->ReceivedEncrypted(std::move(output));
+ else
+ req.observer->ReceivedError(retCode);
+ break;
+ case EncryptionCommand::DECRYPT:
+ if (retCode == CKM_API_SUCCESS)
+ req.observer->ReceivedDecrypted(std::move(output));
+ else
+ req.observer->ReceivedError(retCode);
+ break;
+ default:
+ LogError("Unknown command id: " << command);
+ ThrowMsg(BadResponse, "Unknown command id: " << command);
+ break;
+ }
+}
+
+} /* namespace CKM */
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+/*
+ * @file encryption-receiver.h
+ * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
+ * @version 1.0
+ */
+
+#pragma once
+
+#include <message-buffer.h>
+#include <noncopyable.h>
+#include <async-request.h>
+#include <receiver.h>
+
+namespace CKM {
+
+class EncryptionReceiver : public IReceiver
+{
+public:
+ EncryptionReceiver(MessageBuffer& buffer, AsyncRequest::Map& reqMap);
+ virtual ~EncryptionReceiver() {}
+
+ NONCOPYABLE(EncryptionReceiver);
+
+ void processResponse();
+
+private:
+ MessageBuffer& m_buffer;
+ AsyncRequest::Map& m_requests;
+};
+
+} /* namespace CKM */
{
}
-void OcspReceiver::parseResponse()
+void OcspReceiver::processResponse()
{
int id = 0, retCode = 0, ocspStatus = 0;
m_buffer.Deserialize(id, retCode, ocspStatus);
NONCOPYABLE(OcspReceiver);
- void parseResponse();
+ void processResponse();
private:
MessageBuffer& m_buffer;
public:
DECLARE_EXCEPTION_TYPE(CKM::Exception, BadResponse);
- virtual void parseResponse() = 0;
+ virtual void processResponse() = 0;
virtual ~IReceiver() {};
};
/*
- * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <storage-receiver.h>
#include <ocsp-receiver.h>
+#include <encryption-receiver.h>
#include <protocols.h>
namespace CKM {
receiver.reset(new StorageReceiver(*m_responseBuffer, m_responseMap));
else if (m_interface == SERVICE_SOCKET_OCSP)
receiver.reset(new OcspReceiver(*m_responseBuffer, m_responseMap));
+ else if (m_interface == SERVICE_SOCKET_ENCRYPTION)
+ receiver.reset(new EncryptionReceiver(*m_responseBuffer, m_responseMap));
else {
LogError("Unknown service " << m_interface);
serviceError(CKM_API_ERROR_RECV_FAILED);
return;
}
- receiver->parseResponse();
+ receiver->processResponse();
if (m_responseMap.empty())
watch(m_sendQueue.empty()?0:POLLOUT);
{
}
-void StorageReceiver::parseResponse()
+void StorageReceiver::processResponse()
{
int command = 0, id = 0;
m_buffer.Deserialize(command, id);
NONCOPYABLE(StorageReceiver);
- void parseResponse();
+ void processResponse();
private:
void parseGetCommand();