#define CONV_JSON_CLIENT_IS_HOST "client_is_host"
#define CONV_JSON_CLIENT_CONNECT_TIME "client_connect_time"
#define CONV_JSON_CLIENT_CLIENT_ID "client_id"
+#define CONV_JSON_SECURE_MODE "secure_mode"
#define CONV_JSON_ON_START "onStart"
#define CONV_JSON_ON_CONNECT "onConnect"
INSTALL(TARGETS ${DAEMON} DESTINATION ${BIN_INSTALL_DIR})
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/d2d-conv-manager-iotcon-server.dat DESTINATION
/usr/share/d2d-conv-manager)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../msf_tizen_client/src/ca_crt.pem DESTINATION /usr/share/d2d-conv-manager)
#INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/d2d-conv-manager-iotcon-server.dat DESTINATION
# ${SHARE_INSTALL_PREFIX}/d2d-conv-manager)
_D("SmartView Discovered Service : Name[%s] Version[%s] Type[%s] Id[%s] Uri[%s] ",
serv_name.c_str(), serv_version.c_str(), serv_type.c_str(),
- serv_id.c_str(), serv_uri.c_str() );
+ serv_id.c_str(), serv_uri.c_str());
conv::SmartViewDevice* device_info = new(std::nothrow) conv::SmartViewDevice;
device_info->setId(serv_id);
conv::SmartViewService* conv::SmartviewDiscoveryProvider::convertIntoConvService(Service* smartview_service)
{
- string serv_name, serv_version, serv_type, serv_id, serv_uri;
+ string serv_name, serv_version, serv_type, serv_id, serv_uri, serv_secure;
serv_name = smartview_service->getName();
serv_version = smartview_service->getVersion();
serv_type = smartview_service->getType();
serv_id = smartview_service->getId();
serv_uri = smartview_service->getUri();
+ if ( smartview_service->IsSecureConnectionSupport() )
+ serv_secure = "1";
+ else
+ serv_secure = "0";
- _D("SmartView Discovered Service : Name[%s] Version[%s] Type[%s] Id[%s] Uri[%s] ",
+ _D("SmartView Discovered Service : Name[%s] Version[%s] Type[%s] Id[%s] Uri[%s] Secure[%s]",
serv_name.c_str(), serv_version.c_str(), serv_type.c_str(),
- serv_id.c_str(), serv_uri.c_str() );
+ serv_id.c_str(), serv_uri.c_str(), serv_secure.c_str() );
Json json_serv_info;
json_serv_info.set(CONV_JSON_SERVICE_DATA_PATH, CONV_JSON_SERVICE_DATA_URI, serv_uri);
json_serv_info.set(CONV_JSON_SERVICE_DATA_PATH, CONV_JSON_SERVICE_DATA_NAME, serv_name);
json_serv_info.set(CONV_JSON_SERVICE_DATA_PATH, CONV_JSON_SERVICE_DATA_VERSION, serv_version);
json_serv_info.set(CONV_JSON_SERVICE_DATA_PATH, CONV_JSON_SERVICE_DATA_TYPE, serv_type);
+ json_serv_info.set(CONV_JSON_SERVICE_DATA_PATH, CONV_JSON_SECURE_MODE, serv_secure);
conv::SmartViewService *conv_service = new(std::nothrow) conv::SmartViewService;
conv_service->setType(serv_type);
conv_service->setId(serv_id);
conv_service->setUri(serv_uri);
+ conv_service->setServiceSecureSupport(serv_secure);
conv_service->setServiceInfo(json_serv_info.str());
conv_service->setServiceType(CONV_TYPE_APP_TO_APP_COMMUNICATION);
service_name.c_str(), service_version.c_str(), service_type,
service_id.c_str(), service_uri.c_str());
}
+
+string conv::SmartViewService::getServiceSecureSupport()
+{
+ return service_secure;
+}
+
+void conv::SmartViewService::setServiceSecureSupport(string secure)
+{
+ this->service_secure = secure;
+}
string getUri();
int getServiceType();
string getServiceInfo();
+ string getServiceSecureSupport();
void setName(string name);
void setVersion(string version);
void setUri(string uri);
void setServiceInfo(string serviceInfo);
void setServiceType(int service_type);
+ void setServiceSecureSupport(string secure);
void printInfo();
string service_id;
string service_uri;
string type;
+ string service_secure;
};
}
void conv::AppCommServiceApplication::onError(Error error)
{
_D("onError Called");
+ state = APP_COMM_STATE_NONE;
if ((*requestObj) != NULL) {
_D(RED("publishing_response"));
Json channel;
requestObj->getChannelFromDescription(&channel);
+ Json payload;
+ requestObj->getPayloadFromDescription(&payload);
+
string uri, channelId;
channel.get(NULL, CONV_JSON_URI, &uri);
IF_FAIL_RETURN_TAG(!uri.empty() || svcInfo->isLocal, CONV_ERROR_INVALID_PARAMETER, _E, "uri is empty");
IF_FAIL_RETURN_TAG(!channelId.empty(), CONV_ERROR_INVALID_PARAMETER, _E, "channelId is empty");
+ string secureMode;
+
+ payload.get(NULL, CONV_JSON_SECURE_MODE, &secureMode);
+
AppCommServiceApplication *appInfo = NULL;
for (ApplicationInstanceList::iterator iter = svcInfo->applicationInstanceList.begin(); iter != svcInfo->applicationInstanceList.end(); ++iter) {
appInfo->localService = Service::getLocal();
+ IF_FAIL_RETURN_TAG(secureMode.compare("1") || appInfo->localService.IsSecureConnectionSupport(), CONV_ERROR_INVALID_PARAMETER, _E, "service does not support secure mode");
+
Channel* application = appInfo->localService.createChannel(channelId);
// add listeners
application->addOnAllMessageListener(appInfo);
application->setonPublishListener(appInfo);
+ if ( !secureMode.compare("1") ) {
+ application->setSecurityMode(true);
+ }
+
appInfo->isLocal = true;
appInfo->application = application;
application->connect();
svcInfo->applicationInstanceList.push_back(appInfo);
} else {
_D("COMMUNCATION_START : uri : %s, channel_id : %s", uri.c_str(), channelId.c_str());
+
+ IF_FAIL_RETURN_TAG(secureMode.compare("1") || svcInfo->serviceObj.IsSecureConnectionSupport(), CONV_ERROR_INVALID_PARAMETER, _E, "service does not support secure mode");
+
Application* application = new(std::nothrow) Application(&(svcInfo->serviceObj), uri, channelId);
ASSERT_ALLOC(application);
application->addOnAllMessageListener(appInfo);
application->setonPublishListener(appInfo);
+ if ( !secureMode.compare("1") ) {
+ application->setSecurityMode(true);
+ }
+
appInfo->isLocal = false;
appInfo->application = application;
application->connect();
snprintf(uri, sizeof(uri), "http://%s:8001/api/v2/", address);
+ string isSecure;
+
+ if ( localService.IsSecureConnectionSupport() )
+ isSecure = "1";
+ else
+ isSecure = "0";
+
Json info;
info.set(NULL, CONV_JSON_SERVICE_DATA_URI, uri);
info.set(NULL, CONV_JSON_SERVICE_DATA_TYPE, localService.getType());
info.set(NULL, CONV_JSON_SERVICE_DATA_ID, localService.getId());
info.set(NULL, CONV_JSON_SERVICE_DATA_NAME, localService.getName());
+ info.set(NULL, CONV_JSON_SECURE_MODE, isSecure);
jsonObj->set(NULL, CONV_JSON_DISCOVERY_SERVICE_INFO, info);
g_free(address);
return CONV_ERROR_NONE;
}
-EXTAPI int conv_service_start(conv_service_h handle, conv_channel_h channel_handle, conv_payload_h payload)
+EXTAPI int conv_service_start(conv_service_h handle, conv_channel_h channel_handle, conv_payload_h payload_handle)
{
IF_FAIL_RETURN_TAG(conv::util::is_feature_supported(), CONV_ERROR_NOT_SUPPORTED, _E, "Not supported");
ASSERT_NOT_NULL(handle);
json description;
json channel;
+ json payload;
if ( channel_handle != NULL )
channel = channel_handle->jchannel;
+ if ( payload_handle != NULL)
+ payload = payload_handle->jpayload;
+
json service = handle->jservice;
json device = handle->jdevice;
std::string type = convert_type_to_string(handle->service_type);
description.set(NULL, CONV_JSON_SERVICE, service);
description.set(NULL, CONV_JSON_CHANNEL, channel);
description.set(NULL, CONV_JSON_DEVICE, device);
+ description.set(NULL, CONV_JSON_PAYLOAD, payload);
description.set(NULL, CONV_JSON_TYPE, type);
description.set(NULL, CONV_JSON_IS_LOCAL, handle->is_local);
//LCOV_EXCL_STOP
}
-EXTAPI int conv_service_stop(conv_service_h handle, conv_channel_h channel_handle, conv_payload_h payload)
+EXTAPI int conv_service_stop(conv_service_h handle, conv_channel_h channel_handle, conv_payload_h payload_handle)
{
IF_FAIL_RETURN_TAG(conv::util::is_feature_supported(), CONV_ERROR_NOT_SUPPORTED, _E, "Not supported");
ASSERT_NOT_NULL(handle);
json description;
json channel;
+ json payload;
if ( channel_handle != NULL )
channel = channel_handle->jchannel;
+ if (payload_handle != NULL)
+ payload = payload_handle->jpayload;
+
json service = handle->jservice;
json device = handle->jdevice;
std::string type = convert_type_to_string(handle->service_type);
description.set(NULL, CONV_JSON_SERVICE, service);
description.set(NULL, CONV_JSON_CHANNEL, channel);
description.set(NULL, CONV_JSON_DEVICE, device);
+ description.set(NULL, CONV_JSON_PAYLOAD, payload);
description.set(NULL, CONV_JSON_TYPE, type);
description.set(NULL, CONV_JSON_IS_LOCAL, handle->is_local);
class Clients;
class Channel;
+#define CA_PATH "/usr/share/d2d-conv-manager/ca_crt.pem"
+
class ChannelConnectionHandler {
public:
ChannelConnectionHandler();
class OnErrorListener {
public:
- virtual void onError(/*Error error*/) {}
+ virtual void onError(Error error) {}
+ void onError() {
+ onError(Error::create("Error"));
+ }
};
class OnPublishListener {
void setConnectionTimeout(long timeout);
bool isConnected();
bool isWebSocketOpen();
+ void setSecureSupport(bool support);
+ bool setSecurityMode(bool mode);
bool connect();
void disconnect();
string getChannelUri(map<string, string> *);
void publishMessage(string method, string event, const char *data,
const char *to, unsigned char payload[],
int payload_size, void *user_data);
+ void handleWsiDestroy();
+ void setCommunicated(bool value);
// unsigned char *createBinaryMessage(string json, unsigned char payload[],
// int payload_size);
static void init_json_key_map();
static JsonObject *root_json_object;
string server_ip_address;
int server_port;
+ bool IsSecureSupport = false;
+ bool IsSecureMode = false;
+ bool isCommunicated = false;
};
#endif
typedef std::map<std::string, std::string> map_type;
static Service local_service;
void *result_ptr;
+ bool SecureConnectionSupport = false;
static bool success_get_id;
static string remote_device_id;
string getType();
string getId();
string getVersion();
+ bool IsSecureConnectionSupport();
static string getUniqueId(string address);
static Service getLocal(void);
static void getByURI(string, Result_Base*);
waitForOnReady = false;
install_listener = NULL;
install_result = false;
+ setSecureSupport(se->IsSecureConnectionSupport());
}
Application::Application(Service *se, string Uri, string Id, map<string, string> startargs)
}
}
+void Channel::setSecureSupport(bool support)
+{
+ IsSecureSupport = support;
+}
+
+bool Channel::setSecurityMode(bool mode)
+{
+ if (!IsSecureSupport && mode) {
+ MSF_ERR("not support secure mode");
+ return false;
+ }
+
+ IsSecureMode = mode;
+ MSF_DBG("secure mode is setted to '%d'", mode);
+ return true;
+}
+
bool Channel::connect() { return connect(NULL); }
bool Channel::connect(Result_Base *result1) {
int n;
MSF_DBG("write_socket");
+ ch_p->setCommunicated(true);
+
if (lws_partial_buffered(ch_p->wsi_mirror) == 1) {
MSF_DBG("lws is wrting now. it will retry write.");
lws_callback_on_writable(ch_p->wsi_mirror);
case LWS_CALLBACK_PROTOCOL_DESTROY:
break;
+ case LWS_CALLBACK_WSI_DESTROY:
+ this_ptr->handleWsiDestroy();
+ break;
+
case LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED:
case LWS_CALLBACK_ADD_POLL_FD:
case LWS_CALLBACK_DEL_POLL_FD:
info.extensions = NULL;
info.ssl_cert_filepath = NULL;
info.ssl_private_key_filepath = NULL;
+ if (IsSecureMode) {
+ MSF_DBG("'SecureConnection' is true");
+ info.ssl_ca_filepath = CA_PATH;
+ }
info.gid = -1;
info.uid = -1;
info.options = 0;
string api = getapifromUri(uri);
api.append("channels/").append(ChannelID);
+ if (IsSecureMode) {
+ use_ssl = 1;
+ server_port = 8002;
+ }
+
struct lws_client_connect_info connect_info;
memset(&connect_info, 0, sizeof(lws_client_connect_info));
void ChannelConnectionHandler::setPingTimeout(long t) {
pingTimeout = t;
}
+
+void Channel::handleWsiDestroy()
+{
+ if (!isCommunicated) {
+ was_closed = true;
+ MSF_ERR("wsi destroyed with no communication");
+ if (onErrorListener) {
+ onErrorListener->onError();
+ }
+ }
+}
+
+void Channel::setCommunicated(bool value)
+{
+ isCommunicated = value;
+}
return uri;
}
+bool Service::IsSecureConnectionSupport()
+{
+ return SecureConnectionSupport;
+}
+
void Service::create(char *service_txt)
{
position posvalues;
serviceval.infoURI = json_object_get_string_member(root, "uri");
}
+ Device dev;
if (json_object_has_member(root, "device")) {
+ dev = Device::create(json_object_get_member(root, "device"));
if (ptr != NULL) {
- Device dev = Device::create(json_object_get_member(root, "device"));
(static_cast<Result_Base *>(ptr))->onSuccess(dev);
}
}
+ Service retService = create(serviceval);
+ if ( !dev.getmodel().empty() && atoi(dev.getmodel().substr(0,2).c_str()) >= 16 ) {
+ MSF_DBG("Secure connection support is true");
+ retService.SecureConnectionSupport = true;
+ }
+
if ((Resulturi!= NULL)) {
- Resulturi->onSuccess(create(serviceval));
+ Resulturi->onSuccess(retService);
}
return 0;
Channel *Service::createChannel(string uri)
{
Channel *channel = Channel::create(this, uri);
+ channel->setSecureSupport(SecureConnectionSupport);
return channel;
}
--- /dev/null
+-----BEGIN CERTIFICATE-----
+MIIDhjCCAm6gAwIBAgIJAPm7naJvG91yMA0GCSqGSIb3DQEBCwUAMFcxCzAJBgNV
+BAYTAktSMRUwEwYDVQQKEwxTbWFydFZpZXdTREsxMTAvBgNVBAMTKFNtYXJ0Vmll
+d1NESyBSb290IENlcml0aWZpY2F0ZSBBdXRob3JpdHkwHhcNMTYwNzI5MDUzNDEw
+WhcNMzYwNzI5MDUzNDEwWjBXMQswCQYDVQQGEwJLUjEVMBMGA1UEChMMU21hcnRW
+aWV3U0RLMTEwLwYDVQQDEyhTbWFydFZpZXdTREsgUm9vdCBDZXJpdGlmaWNhdGUg
+QXV0aG9yaXR5MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArtBcclIW
+EuObUkeTn+FW3m6Lm/YpwAOeABCtq6RKnBcq6jzEo3I433cSuVC2DrWGiiYi62Qm
+iAzOHEtkvRctj+jEuK7ZKneKkxQ5261os0RsvWG7fONVb4m0ZRBydykgfu/PLwUB
+MWeiF3PB6w7YCzN1MJzb9EISFlhEcqMxDHgwGWHZYo/CTWtIwBVZ07mhdrCQaV2r
+LLJInA+4Wh9nXRO82qRnqYqFZfV7psIOW4MqfjWqNcKAHWWZ1gKrdZc9fPb2YVK4
+OIlaT3Qq9DOCveeU5T8d3MGEoiFnXt4Lp5656nI7MbkAsPEFFRHFkBK3o8CE1HLp
+sELQa6GBRe8WPQIDAQABo1UwUzASBgNVHRMBAf8ECDAGAQH/AgEAMB0GA1UdDgQW
+BBRQyhCp74M+t2GwCiH3g3Aau0AX7DALBgNVHQ8EBAMCAQYwEQYJYIZIAYb4QgEB
+BAQDAgAHMA0GCSqGSIb3DQEBCwUAA4IBAQAVIEeJo4vGsKPZBoY19hCXZnqB6Qcm
+OnWZzAZ0am8OQHQ4/LbSJ+Vnxh7eFiLtPQwuSHJ1a95ODA7RlNgnpC8ymHsL5Wl5
+UKOq5jOs3Jfa0aG99H9TsFKBysXlsBHfaHX+8/AoZUJDOksNeQigj3n4wCdLEPvt
+UpI9qJEjuzXeKxVhwnDkc/AvOuSGUaPiSeCSxy+xpcyWCANc4uVXtOxJluQvy8aC
+m6l0yG3Ucg09yCIkPzKtzG/kAadDRrTOYi/x4ZECtdamHQxncEnb3D881veLc6+s
+ztEvDx0F77vRtadpeBxNZKivG2kJrymuf47pGIS0FlC5+/5ieV54+1/d
+-----END CERTIFICATE-----
%{_datadir}/license/%{name}
%attr(755,root,root) %{_sysconfdir}/gumd/useradd.d/99_d2d-conv-manager.post
/usr/share/d2d-conv-manager/*.dat
+/usr/share/d2d-conv-manager/ca_crt.pem
%files lib
%manifest lib%{name}.manifest