/******************************************************************
*
- * Copyright 2017 - 2020 Samsung Electronics All Rights Reserved.
+ * Copyright 2017 - 2021 Samsung Electronics All Rights Reserved.
*
* Author: Jaroslaw Pelczar <j.pelczar@samsung.com>
*
#include "dcm_server.h"
#include "log.h"
+#define DCM_DEFAULT_PRIVILEGE "http://tizen.org/privilege/devicecertificate"
+
dcm_session::dcm_session(boost::asio::io_service& io_service,
const std::shared_ptr<dcm_server>& server,
std::shared_ptr<so_resolver> soResolver,
void dcm_session::start()
{
- int handle = fSocket.native_handle();
LOGD("Accepted connection with socket " << fSocket.native_handle());
- if(verify_privileges(handle)) {
- do_receive();
- } else {
- LOGE("Client privilege check failure. Disconnect");
- }
+ do_receive();
}
void dcm_session::do_receive() noexcept
return std::string("Can't translate error");
}
-bool dcm_session::verify_privileges(int handle)
+bool dcm_session::verify_privileges(int handle, const char* privilege_to_check)
{
int ret = 0;
char* tmp_str;
LOGD("Got new session from " << pid << " with user " << user.get() <<
", client ID " << client.get() << " and session ID " << client_session.get());
- ret = cynara_check(fCynaraInstance, client.get(), client_session.get(), user.get(),
- "http://tizen.org/privilege/devicecertificate");
+ ret = cynara_check(fCynaraInstance, client.get(), client_session.get(), user.get(), privilege_to_check);
if(ret != CYNARA_API_ACCESS_ALLOWED) {
- LOGE("Application access denied for " << pid << " - " << cynara_error_to_string(ret));
+ LOGE("Application access denied for " << pid << ", privilege: " <<
+ privilege_to_check << ", error: - " << cynara_error_to_string(ret));
return false;
}
- LOGD("Access granted for " << pid);
+ LOGD("Access granted for " << pid << " with privilege " << privilege_to_check);
return true;
}
{
LOGD("Associate context");
+ if(!verify_privileges(fSocket.native_handle(), DCM_DEFAULT_PRIVILEGE)) {
+ LOGE("Client privilege check failure. Disconnect");
+ return;
+ }
+
ResponseMessage msg;
auto* contextResponse = msg.mutable_associate_context();
{
LOGD("Request certificate chain");
+ if(!verify_privileges(fSocket.native_handle(), DCM_DEFAULT_PRIVILEGE)) {
+ LOGE("Client privilege check failure. Disconnect");
+ return;
+ }
+
ResponseMessage msg;
auto* certificateResponse = msg.mutable_request_chain();
{
LOGD("Request data signing");
+ if(!verify_privileges(fSocket.native_handle(), DCM_DEFAULT_PRIVILEGE)) {
+ LOGE("Client privilege check failure. Disconnect");
+ return;
+ }
+
ResponseMessage msg;
auto* signingResponse = msg.mutable_sign_data();
signingResponse->set_result(error);
reply(msg);
-}
+}
\ No newline at end of file
/******************************************************************
*
- * Copyright 2017 - 2020 Samsung Electronics All Rights Reserved.
+ * Copyright 2017 - 2021 Samsung Electronics All Rights Reserved.
*
* Author: Jaroslaw Pelczar <j.pelczar@samsung.com>
*
void decode_message() noexcept;
void reply(const ResponseMessage& resp) noexcept;
- bool verify_privileges(int handle);
+ bool verify_privileges(int handle, const char* privilege_to_check);
void handle_context_association(const AssociateKeyContext& message);
void handle_cert_chain(const RequestCertificateChain& message);