From 776bf4358fd00627eb7e907db34a61b69247ef61 Mon Sep 17 00:00:00 2001 From: jkjo92 Date: Mon, 13 Feb 2017 19:55:12 +0900 Subject: [PATCH 01/16] apply 4.0 tool chain build error Change-Id: I726c4ca9e30b71d9cd03ad2000e849c484abe52a Signed-off-by: jkjo92 --- common/AsmHelper.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) mode change 100644 => 100755 common/AsmHelper.h diff --git a/common/AsmHelper.h b/common/AsmHelper.h old mode 100644 new mode 100755 index 5850666..2b61584 --- a/common/AsmHelper.h +++ b/common/AsmHelper.h @@ -67,15 +67,15 @@ #define LOG_TAG "org.tizen.fido.asm" #ifndef _ERR -#define _ERR(fmt, args...) LOGE("[%s:%d] "fmt"\n", __func__, __LINE__, ##args) +#define _ERR(fmt, args...) LOGE("[%s:%d] " fmt"\n", __func__, __LINE__, ##args) #endif #ifndef _DBG -#define _DBG(fmt, args...) LOGD("[%s:%d] "fmt"\n", __func__, __LINE__, ##args) +#define _DBG(fmt, args...) LOGD("[%s:%d] " fmt"\n", __func__, __LINE__, ##args) #endif #ifndef _INFO -#define _INFO(fmt, args...) LOGI("[%s:%d] "fmt"\n", __func__, __LINE__, ##args) +#define _INFO(fmt, args...) LOGI("[%s:%d] " fmt"\n", __func__, __LINE__, ##args) #endif #ifndef _BEGIN -- 2.7.4 From 54326a8373c70b49b3f122365295b82ee4b2bf1b Mon Sep 17 00:00:00 2001 From: Manasij Sur Roy Date: Tue, 21 Mar 2017 14:35:07 +0530 Subject: [PATCH 02/16] Auth-FW based FIDO Authenticator implementation Change-Id: Id408afb6a2a4c2036bea095150871e11f798e901 Signed-off-by: Manasij Sur Roy --- CMakeLists.txt | 4 +- common/AsmHelper.h | 6 +-- packaging/fido-asm.spec | 54 ++++++++++----------- server/auth_discovery/src/AuthManager.cpp | 42 ++++++++-------- silent_auth/CMakeLists.txt | 4 ++ silent_auth/instructions.txt | 34 +++++++++++++ silent_auth/silent_auth_entry.cpp | 81 ++++++++++++++++++++++++++++++- test/RADemoTV/.cproject | 24 ++++----- test/RADemoTV/.project | 6 +++ test/RADemoTV/.sign/.manifest.tmp | 4 +- test/RADemoTV/.sign/author-signature.xml | 8 +-- test/RADemoTV/.sign/signature1.xml | 10 ++-- 12 files changed, 199 insertions(+), 78 deletions(-) create mode 100644 silent_auth/instructions.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 1cdee6f..1aabe10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,9 +13,9 @@ ADD_SUBDIRECTORY(ui) ADD_SUBDIRECTORY(roaming_agent) ADD_SUBDIRECTORY(common/dbus_interfaces) ADD_SUBDIRECTORY(bt_roaming_agent) -ADD_SUBDIRECTORY(ble_roaming_agent) +##ADD_SUBDIRECTORY(ble_roaming_agent) ADD_DEPENDENCIES(fido-asm fido-asm-dbus) ADD_DEPENDENCIES(fido-bt-ragent-service fido-asm-dbus) -ADD_DEPENDENCIES(fido-ble-ragent-service fido-asm-dbus) +##ADD_DEPENDENCIES(fido-ble-ragent-service fido-asm-dbus) ADD_DEPENDENCIES(fido-roaming-agent-service fido-asm-dbus) ADD_DEPENDENCIES(asmui fido-asm-dbus) diff --git a/common/AsmHelper.h b/common/AsmHelper.h index 5850666..2b61584 100644 --- a/common/AsmHelper.h +++ b/common/AsmHelper.h @@ -67,15 +67,15 @@ #define LOG_TAG "org.tizen.fido.asm" #ifndef _ERR -#define _ERR(fmt, args...) LOGE("[%s:%d] "fmt"\n", __func__, __LINE__, ##args) +#define _ERR(fmt, args...) LOGE("[%s:%d] " fmt"\n", __func__, __LINE__, ##args) #endif #ifndef _DBG -#define _DBG(fmt, args...) LOGD("[%s:%d] "fmt"\n", __func__, __LINE__, ##args) +#define _DBG(fmt, args...) LOGD("[%s:%d] " fmt"\n", __func__, __LINE__, ##args) #endif #ifndef _INFO -#define _INFO(fmt, args...) LOGI("[%s:%d] "fmt"\n", __func__, __LINE__, ##args) +#define _INFO(fmt, args...) LOGI("[%s:%d] " fmt"\n", __func__, __LINE__, ##args) #endif #ifndef _BEGIN diff --git a/packaging/fido-asm.spec b/packaging/fido-asm.spec index 2868296..83ef1df 100644 --- a/packaging/fido-asm.spec +++ b/packaging/fido-asm.spec @@ -10,7 +10,7 @@ Source1: org.tizen.fido-asm.service Source2: org.tizen.fido-asm.conf Source3: fido-asm.service Source4: fido-roaming-agent.service -Source5: fido-ble-roaming-agent.service +##Source5: fido-ble-roaming-agent.service Source6: fido-bt-roaming-agent.service BuildRequires: cmake @@ -95,10 +95,6 @@ install -m 0644 %SOURCE4 %{buildroot}%{_unitdir}/fido-roaming-agent.service %install_service multi-user.target.wants fido-roaming-agent.service mkdir -p %{buildroot}%{_unitdir}/multi-user.target.wants -install -m 0644 %SOURCE5 %{buildroot}%{_unitdir}/fido-ble-roaming-agent.service -%install_service multi-user.target.wants fido-ble-roaming-agent.service - -mkdir -p %{buildroot}%{_unitdir}/multi-user.target.wants install -m 0644 %SOURCE6 %{buildroot}%{_unitdir}/fido-bt-roaming-agent.service %install_service multi-user.target.wants fido-bt-roaming-agent.service @@ -242,6 +238,8 @@ BuildRequires: pkgconfig(json-glib-1.0) BuildRequires: pkgconfig(glib-2.0) >= 2.26 BuildRequires: pkgconfig(gio-unix-2.0) BuildRequires: pkgconfig(capi-network-connection) +BuildRequires: pkgconfig(syspopup-caller) +BuildRequires: pkgconfig(buxton2) %description -n fido_silent FIDO Silent Authenticator @@ -300,29 +298,29 @@ chsmack -a '_' /opt/data/fido-ra/*.dat ################################################################################# # FIDO BLE Roaming Agent ################################################################################# -%package -n fido_ble_roaming_agent -Summary: FIDO BLE Roaming Agent -Group: Account - -BuildRequires: cmake -BuildRequires: pkgconfig(capi-appfw-application) -BuildRequires: pkgconfig(dlog) -BuildRequires: pkgconfig(bundle) -BuildRequires: pkgconfig(json-glib-1.0) -BuildRequires: pkgconfig(glib-2.0) >= 2.26 -BuildRequires: pkgconfig(gio-unix-2.0) -BuildRequires: pkgconfig(capi-network-connection) -BuildRequires: pkgconfig(capi-network-bluetooth) - - -%description -n fido_ble_roaming_agent -FIDO BT Roaming Agent GATT Server - -%files -n fido_ble_roaming_agent -%manifest fido-ble-ragent.manifest -%{_bindir}/fido-ble-ragent-service -%{_unitdir}/fido-ble-roaming-agent.service -%{_unitdir}/multi-user.target.wants/fido-ble-roaming-agent.service +##%package -n fido_ble_roaming_agent +##Summary: FIDO BLE Roaming Agent +##Group: Account + +##BuildRequires: cmake +##BuildRequires: pkgconfig(capi-appfw-application) +##BuildRequires: pkgconfig(dlog) +##BuildRequires: pkgconfig(bundle) +##BuildRequires: pkgconfig(json-glib-1.0) +##BuildRequires: pkgconfig(glib-2.0) >= 2.26 +##BuildRequires: pkgconfig(gio-unix-2.0) +##BuildRequires: pkgconfig(capi-network-connection) +##BuildRequires: pkgconfig(capi-network-bluetooth) + + +##%description -n fido_ble_roaming_agent +##FIDO BT Roaming Agent GATT Server + +##%files -n fido_ble_roaming_agent +##%manifest fido-ble-ragent.manifest +##%{_bindir}/fido-ble-ragent-service +##%{_unitdir}/fido-ble-roaming-agent.service +##%{_unitdir}/multi-user.target.wants/fido-ble-roaming-agent.service ################################################################################# # FIDO BT Roaming Agent diff --git a/server/auth_discovery/src/AuthManager.cpp b/server/auth_discovery/src/AuthManager.cpp index 5402cfd..adfb8cb 100644 --- a/server/auth_discovery/src/AuthManager.cpp +++ b/server/auth_discovery/src/AuthManager.cpp @@ -38,27 +38,27 @@ AuthManager::initProviders(void) __providerList.push_back(badPro); - if (RoamingUtil::isRASupported() == true) { - IADProvider *radPro = new IotADProvider(); - int retRa = radPro->init(); - if (retRa == 0) { - _INFO("Roaming Provider=[%p]", radPro); - __providerList.push_back(radPro); - } else { - _INFO("RA not supported"); - delete radPro; - } - } - - IADProvider *blePro = new BleAdProvider(); - int retBle = blePro->init(); - if (retBle == 0) { - _INFO("BLE Provider=[%p]", blePro); - __providerList.push_back(blePro); - } else { - _INFO("BLE Provider not supported"); - delete blePro; - } +// if (RoamingUtil::isRASupported() == true) { +// IADProvider *radPro = new IotADProvider(); +// int retRa = radPro->init(); +// if (retRa == 0) { +// _INFO("Roaming Provider=[%p]", radPro); +// __providerList.push_back(radPro); +// } else { +// _INFO("RA not supported"); +// delete radPro; +// } +// } + +// IADProvider *blePro = new BleAdProvider(); +// int retBle = blePro->init(); +// if (retBle == 0) { +// _INFO("BLE Provider=[%p]", blePro); +// __providerList.push_back(blePro); +// } else { +// _INFO("BLE Provider not supported"); +// delete blePro; +// } IADProvider *btPro = new BtAdProvider(); int retBt = btPro->init(); diff --git a/silent_auth/CMakeLists.txt b/silent_auth/CMakeLists.txt index 4021531..37e7a06 100644 --- a/silent_auth/CMakeLists.txt +++ b/silent_auth/CMakeLists.txt @@ -29,6 +29,10 @@ pkg_check_modules(SILENT_AUTH_PKGS REQUIRED capi-network-connection aul libtzplatform-config + syspopup-caller + capi-appfw-application + capi-appfw-app-manager + buxton2 ) FOREACH(flag ${SILENT_AUTH_PKGS_CFLAGS}) diff --git a/silent_auth/instructions.txt b/silent_auth/instructions.txt new file mode 100644 index 0000000..1bc48bb --- /dev/null +++ b/silent_auth/instructions.txt @@ -0,0 +1,34 @@ +======================================================================== +FIDO Authenticator Plugin based on Auth-FW +======================================================================== +This is a FIDO Authenticator which utilizes Tizen Device PIN using "auth-fw". +This utilizes fido-syspopup for PIN UI. + +Instructions for TM1, Bound Use Case: + +Setup:- +1. Build fido-asm and fido-syspopup +2. Uninstall dummyasm +3. Install fido-asm, fido_silent_auth using rpm -ivh --force command. +4. Install fido-syspopup as globalapp: + - rpm -ivh --force --nodeps /home/org.tizen.fido-syspopup-1.0-1.armv7l.rpm + - tpk-backend -y org.tizen.fido-syspopup --preload +5. (Once per device only) Add org.tizen.fido-syspopup into auth-fw client whitelist + - echo "User::Pkg::org.tizen.fido-syspopup" >> /etc/auth-fw/client-whitelist +6. Install rademotv from IDE +If IDE does not recognize TM1 then: +sdb push org.example.rademotv-1.0.0-arm.tpk /opt/usr/home/owner/apps_rw/tmp +sdb shell tpk-backend -i /opt/usr/home/owner/apps_rw/tmp/org.example.rademotv-1.0.0-arm.tpk +sdb shell tpk-backend -i /opt/usr/home/owner/apps_rw/tmp/org.example.rademotv-1.0.0-arm.tpk --preload + +6. Reboot + +Test:- +1. Launch RADemoTV. +2. Register New user. +3. Enter any name. +4. PIN UI will be launched, enter 2 digit PIN, confirm the same again. +(If the device already has PIN setup previously via Settings, then instead of setting new PIN you must enter the +previous PIN) +5. Registration completes. +6. For Authenticate: Enter PIN to verify. diff --git a/silent_auth/silent_auth_entry.cpp b/silent_auth/silent_auth_entry.cpp index 4235647..5d04721 100644 --- a/silent_auth/silent_auth_entry.cpp +++ b/silent_auth/silent_auth_entry.cpp @@ -21,6 +21,12 @@ #include #include #include +#include +#include +#include +#include +#include + #include "silent_auth_entry.h" #include "GetInfoReqTlvEncoder.h" @@ -78,6 +84,9 @@ static int __sign_counter = 1; #define AUTH_EXTENSION_RESPONSE_SUCCESS "success" #define AUTH_EXTENSION_RESPONSE_SUCCESS_LEN 128 +#define PWD_VERIFY_STATUS_TS_KEY "LOCK_PWD_VERIFY_STATUS_TS_KEY" +#define PWD_VERIFY_STATUS_KEY "LOCK_PWD_VERIFY_STATUS_KEY" + #ifdef JSON_BUILDER static void __add_string_to_json_object(JsonBuilder *json_obj, const char *key, const char *val) @@ -1118,6 +1127,9 @@ fido_auth_plugin_is_enrolled(const char *args) return true; } +#define TS_KEY "ts" +#define TS_VAL_TEST "test" + EXPORT_API int fido_auth_plugin_enroll(const char *args) { @@ -1129,8 +1141,75 @@ fido_auth_plugin_enroll(const char *args) EXPORT_API int fido_auth_plugin_verify(const char *cmd, const char *fch, char **verif_token) { + time_t ts = time(0); + _INFO(""); - /*TODO: user verification*/ + bundle *b = NULL; + b = bundle_create(); + char ts_str[1024] = {0, }; + snprintf(ts_str, 1024 - 1, "%lld", (long long)ts); + bundle_add(b, TS_KEY, ts_str); + _INFO("[%s]", ts_str); + + int ret = syspopup_launch((char *)"fido-syspopup", b); + if (ret != 0) { + _ERR("syspopup_launch Error = [%d]", ret); + return -1; + } + + /*buxton watch*/ + struct buxton_client *cli; + struct buxton_layer *layer; + + int r = buxton_open(&cli, NULL, NULL); + if (r) { + _ERR("buxton_open=[%d]", r); + return -1; + } + + layer = buxton_create_layer("system"); + + /*long long int poll_count = 0;*/ + + while (1) { + usleep(1000); + buxton_value *val_ts = NULL; + r = buxton_get_value_sync(cli, layer, PWD_VERIFY_STATUS_TS_KEY, &val_ts); + if (r == -1) { + _ERR("buxton_get_value_sync=[%d]", r); + return -1; + } + if (val_ts != NULL) { + char *val_ts_str = NULL; + buxton_value_get_string(val_ts, (const char **)&val_ts_str); + if (val_ts_str != NULL) { + /*poll_count++;*/ + /*if ((poll_count % 50) == 0) + _INFO("[%s][%s]", val_ts_str, ts_str);*/ + + if (strcmp(val_ts_str, ts_str) == 0) { + _INFO("Received matching ts"); + buxton_value *val_bool = NULL; + r = buxton_get_value_sync(cli, layer, PWD_VERIFY_STATUS_KEY, &val_bool); + _INFO("buxton_get_value_sync=[%d]", r); + if (val_bool != NULL) { + int val_verifiy = false; + buxton_value_get_boolean(val_bool, &val_verifiy); + _INFO("val_verifiy=[%d]", val_verifiy); + if (val_verifiy != 0) + return 0; + else + return -1; + } else { + _ERR(""); + return -1; + } + } + } + } + + } + _ERR("Out of while!!"); return 0; } diff --git a/test/RADemoTV/.cproject b/test/RADemoTV/.cproject index ebc8598..20b7d24 100644 --- a/test/RADemoTV/.cproject +++ b/test/RADemoTV/.cproject @@ -322,10 +322,10 @@ - - - - @@ -437,10 +437,10 @@ - - - - @@ -552,7 +552,7 @@ - diff --git a/test/RADemoTV/.project b/test/RADemoTV/.project index 46db98f..57fe641 100644 --- a/test/RADemoTV/.project +++ b/test/RADemoTV/.project @@ -6,6 +6,11 @@ + org.tizen.nativecore.apichecker.apicheckerbuilder + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder @@ -22,6 +27,7 @@ org.eclipse.cdt.core.ccnature org.eclipse.cdt.managedbuilder.core.managedBuildNature org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + org.tizen.nativecore.apichecker.apicheckernature diff --git a/test/RADemoTV/.sign/.manifest.tmp b/test/RADemoTV/.sign/.manifest.tmp index 0e0ccde..6453fc3 100644 --- a/test/RADemoTV/.sign/.manifest.tmp +++ b/test/RADemoTV/.sign/.manifest.tmp @@ -26,8 +26,8 @@ res/offline_auth_req.json__DEL__oZb4hdBo7gfvHQp3Phmi7OrQvOTkYebs+cj0CUB55wQ= res/offline_dereg_req.json__DEL__ls9i8E/7YfyG+yCzw/XQC8as8ooSZNM8ItkTCvG3AQ0= res/offline_reg_req.json__DEL__rdOHCvLX1D/a4sN49GMCPTDj4spKyHjgXrcTvDmtHmI= res/ui-controls.edc__DEL__yT6Ox68AGW/HIfljsxpDJ0/42qHiF0sSTOPCj0hDChM= -res/ui-controls.edj__DEL__zY+RgwVhayMhI8gOpkbxqIKV8/Sqe8uUkf/hn4wUZcQ= +res/ui-controls.edj__DEL__nf2E5KtcXKvxS/HUTnR60HxwBrU7JMxbEM3lfwxCn/8= shared/res/fido.png__DEL__9DwesXg1NEg1AEHfbtrY6C9YwJoypEr2v6hOyWHW6i8= shared/res/rademotv.png__DEL__1d0oEZHqPn+QzNzGIHwj9ODby6x9ggFs9uOsav6jPNs= tizen-manifest.xml__DEL__hf3BnDDOp8ZyVZbapG4QNDJtBWqH8Qa24aJD4/kN4dY= -author-signature.xml__DEL__7K9ckaGz1GQydrpk8zkpnZw1mh7PkeJZQ41FJxuRd3Q= +author-signature.xml__DEL__y4enTiLoUZO3luwmsmV3hK5i2fohhohsYOxM6GGripk= diff --git a/test/RADemoTV/.sign/author-signature.xml b/test/RADemoTV/.sign/author-signature.xml index 845390e..035e5a0 100644 --- a/test/RADemoTV/.sign/author-signature.xml +++ b/test/RADemoTV/.sign/author-signature.xml @@ -116,7 +116,7 @@ -zY+RgwVhayMhI8gOpkbxqIKV8/Sqe8uUkf/hn4wUZcQ= +nf2E5KtcXKvxS/HUTnR60HxwBrU7JMxbEM3lfwxCn/8= @@ -139,9 +139,9 @@ -o9X1remP0l3i/1LdxaKEtQungByfq6filBpnmxprmlrLGlbJ8NvlYwLGbiESY21gHajumW4Zyn// -c/iy8VFQOX04y9Nk2cxLO2Ut3RjUIakHyk32y+KgoBlRZAusGD1EQ/zu0noLLbiSzZcFhe96NO+d -b74qVqwdHfy9tYxkyao= +MlYR5rz7dFxkEYZtkZj4l+iSZh4dZSlxSvZVriY1s1D07Jbzm016xmcv15KQq6GrP6mW67P9mVNv +QoW+I4F/7jnTl/5ofa03oI5cB18AT3Mr/AX0fKM/JHBxnutpjK2MdNj6VANv7bZ/9H64tTOeZQHr +HLJH0TwfmAVwPBkXDU0= diff --git a/test/RADemoTV/.sign/signature1.xml b/test/RADemoTV/.sign/signature1.xml index 6a21c0d..cdd3b09 100644 --- a/test/RADemoTV/.sign/signature1.xml +++ b/test/RADemoTV/.sign/signature1.xml @@ -4,7 +4,7 @@ -7K9ckaGz1GQydrpk8zkpnZw1mh7PkeJZQ41FJxuRd3Q= +y4enTiLoUZO3luwmsmV3hK5i2fohhohsYOxM6GGripk= @@ -120,7 +120,7 @@ -zY+RgwVhayMhI8gOpkbxqIKV8/Sqe8uUkf/hn4wUZcQ= +nf2E5KtcXKvxS/HUTnR60HxwBrU7JMxbEM3lfwxCn/8= @@ -143,9 +143,9 @@ -G9pc7RO8mSwrw7f796Ngr1qU37WS3jRv9g8Sm5ugLxsJ23F6D3glkBRwiDvpTMc0/y/JtzINzCgs -ArloFO39fWP8kEKHcTkkVPXGED3D7jl3eVIYcIcgLD0iFsHFFzBHKRVIrZORmQIt9J3F6Ul8q9rQ -IwXK4ORO1aTjOqP6lgM= +HApMDDq7LO1eI07Iw5VjSAaM73WeFAtQeW8KQi3e5SyHCbUWoKTDSFwHA/Y2+91iqJnC/3KN2ksy +S8CwCOBAMx5kWSr+01qiQIv5J0tV3T0/PFN/rMwXGX4SaImwYJ+g/Xdwns4gZCaTISZBqQPi25NM +QDcoZ3vdFA/uFzmSIVw= -- 2.7.4 From 55cdee10e9453a7e956e17872801a2111fd2412c Mon Sep 17 00:00:00 2001 From: Manasij Sur Roy Date: Thu, 30 Mar 2017 15:21:30 +0530 Subject: [PATCH 03/16] Fix for Roaming mode Authentication Change-Id: Ia24440083427ed5d96c024dce2baf76a81dff761 Signed-off-by: Manasij Sur Roy --- server/auth_discovery/src/BAuthStub.cpp | 23 ++++++++++++ server/auth_discovery/src/RoamingUtil.cpp | 1 + server/states/src/AuthenticateState.cpp | 61 ++++++++++++++++++++++++++++++- server/states/src/DeregState.cpp | 4 ++ silent_auth/instructions.txt | 3 +- 5 files changed, 88 insertions(+), 4 deletions(-) diff --git a/server/auth_discovery/src/BAuthStub.cpp b/server/auth_discovery/src/BAuthStub.cpp index acd527d..229382d 100644 --- a/server/auth_discovery/src/BAuthStub.cpp +++ b/server/auth_discovery/src/BAuthStub.cpp @@ -27,26 +27,35 @@ BAuthStub::getInfo(void) RET_IF_FAIL(__pluginHandle->process != NULL, NULL); RET_IF_FAIL(__pluginHandle->process->process != NULL, NULL); + _INFO(""); + TlvEncodable encodableReq; encodableReq.setEncoder(EID_UAFV1_GETINFO_REQ); + _INFO(""); TlvEncodable encodableResp; encodableResp.setEncoder(EID_UAFV1_GETINFO_RESP); + _INFO(""); Buffer *authReq = encodableReq.encode(); unsigned char *authRespRaw = NULL; + _INFO(""); __pluginHandle->process->process(authReq->data, &authRespRaw); + _INFO(""); __cachedData = encodableResp.decode(authRespRaw); /*Map AuthIndex*/ /*TODO: Find Device ID logic used by IoTCon*/ + _INFO(""); if (__cachedData->authList != NULL) { + _INFO(""); GList *authListIter = g_list_first(__cachedData->authList); while (authListIter != NULL) { + _INFO(""); AuthenticatorInfo *authInfo = (AuthenticatorInfo*)(authListIter->data); /*TODO: Find Device ID logic used by IoTCon*/ _INFO("Before calling getMappedIndex"); @@ -56,14 +65,17 @@ BAuthStub::getInfo(void) _INFO("After calling getMappedIndex"); authInfo->__devId = strdup(AsmCrypto::getDeviceId().c_str()); + _INFO(""); authInfo->__isUserEnrolled = isEnrolled(); authInfo->__isRoamingAuthenticator = false; + _INFO(""); authListIter = authListIter->next; } } + _INFO(""); /*Fill-up additional data*/ __cachedData->attach_hint = ATTACHMENT_HINT_INTERNAL; /*__cachedData->attach_hint = __pluginHandle->conn->attach_hint();*/ @@ -71,6 +83,17 @@ BAuthStub::getInfo(void) /*__cachedData->description = __pluginHandle->conn->description();*/ } + /*Resetting fields altered during last RA operation*/ + else if (__cachedData->authList != NULL) { + _INFO(""); + GList *authListIter = g_list_first(__cachedData->authList); + while (authListIter != NULL) { + AuthenticatorInfo *authInfo = (AuthenticatorInfo*)(authListIter->data); + authInfo->__isRoamingAuthenticator = false; + authListIter = authListIter->next; + } + } + _INFO("Returning __cachedData"); return __cachedData; } diff --git a/server/auth_discovery/src/RoamingUtil.cpp b/server/auth_discovery/src/RoamingUtil.cpp index 94e0227..8633d9c 100644 --- a/server/auth_discovery/src/RoamingUtil.cpp +++ b/server/auth_discovery/src/RoamingUtil.cpp @@ -166,6 +166,7 @@ RoamingUtil::createAuthReq(const char *tlvB64) default: /*Rest are not supported for Roaming operations*/ + /*https://fidoalliance.org/specs/fido-uaf-v1.0-ps-20141208/fido-uaf-asm-api-v1.0-ps-20141208.html#access-control-for-asm-apis*/ _ERR(""); delete asmReq; return NULL; diff --git a/server/states/src/AuthenticateState.cpp b/server/states/src/AuthenticateState.cpp index 1170927..cd95e1b 100644 --- a/server/states/src/AuthenticateState.cpp +++ b/server/states/src/AuthenticateState.cpp @@ -364,8 +364,65 @@ AuthenticateState::handle(IAuthStub *stub, AsmRequest *asmReq, const char *str, signAuthReq->khHList = storedKhList; _INFO("Matched khlist count =[%d]", g_list_length(signAuthReq->khHList)); } else { - signAuthReq->khHList = NULL; - _ERR("NO Matched khlist"); + _ERR("NO Matched khlist, trying with direct keyid"); + + /*Temp fix to not use b64 encode of keyid*/ + + + IStorageParcel *searchParcel = new AsmStorageParcel(); + std::string appIdStr(signAuthReq->appId); + searchParcel->setString(STR_PROP_APP_ID, appIdStr); + + GList *storedKhList = NULL; + GList *recvdKhListIter = g_list_first(signAuthReq->khHList); + + while (recvdKhListIter != NULL) { + + char *recvKh = (char*)(recvdKhListIter->data); + /*unsigned char *recvKhDec = AsmCrypto::ToBase64Url((unsigned char*)recvKh, strlen(recvKh));*/ + if (recvKh != NULL) { + + std::string kIdStr((char*)recvKh); + searchParcel->setString(STR_PROP_KEY_ID, kIdStr); + _INFO("search=[%s][%s]", appIdStr.c_str(), kIdStr.c_str()); + + std::vector *searchRes = AsmStorage::getInstance()->searchData(searchParcel); + if (searchRes != NULL) { + + int recFound = searchRes->size(); + _INFO("Records found in database corresponding to appId = [%d]", recFound); + if (recFound <= 0) { + _INFO("No key registered for this app"); + } + + std::vector::iterator searchResIter = searchRes->begin(); + + for (; searchResIter != searchRes->end(); ++searchResIter) { + + IStorageParcel *parcel = *searchResIter; + char *kh = NULL; + int res = parcel->getString(STR_PROP_KEY_HANDLE, &kh); + + if (res == 0) { + _INFO("Length of b64 encoded keyHandle : [%d]", strlen(kh)); + storedKhList = g_list_append(storedKhList, kh); + } + } + } + } + + recvdKhListIter = recvdKhListIter->next; + } + + if (storedKhList == NULL) { + _ERR("No matching keyid found"); + return -1; + } + + storedKhList = g_list_first(storedKhList); + signAuthReq->khHList = storedKhList; + _INFO("Matched khlist count =[%d]", g_list_length(signAuthReq->khHList)); + } } diff --git a/server/states/src/DeregState.cpp b/server/states/src/DeregState.cpp index fcf5b48..88ffdd6 100644 --- a/server/states/src/DeregState.cpp +++ b/server/states/src/DeregState.cpp @@ -118,6 +118,10 @@ DeregState::handle(IAuthStub *authStub, AsmRequest *asmReq, const char *str, cha if(deleteRecord == -1) return -1; + /*Temp fix: try to delete b64enc keyid too*/ + _INFO("About to delete non-b64-enc too=[%s][%s]", deRegAuthReq->appId, deRegAuthReq->keyId); + deleteRecord = deleteAsmRecord(deRegAuthReq->appId, deRegAuthReq->keyId); + DeregResp *stubResp = authStub->processDeregister(deRegAuthReq); RET_IF_FAIL(stubResp != NULL, -1); diff --git a/silent_auth/instructions.txt b/silent_auth/instructions.txt index 1bc48bb..4b19393 100644 --- a/silent_auth/instructions.txt +++ b/silent_auth/instructions.txt @@ -17,9 +17,8 @@ Setup:- - echo "User::Pkg::org.tizen.fido-syspopup" >> /etc/auth-fw/client-whitelist 6. Install rademotv from IDE If IDE does not recognize TM1 then: -sdb push org.example.rademotv-1.0.0-arm.tpk /opt/usr/home/owner/apps_rw/tmp +sdb push org.example.rademotv-1.0.0-arm.tpk /opt/usr/home/owner/apps_rw/tmp/ sdb shell tpk-backend -i /opt/usr/home/owner/apps_rw/tmp/org.example.rademotv-1.0.0-arm.tpk -sdb shell tpk-backend -i /opt/usr/home/owner/apps_rw/tmp/org.example.rademotv-1.0.0-arm.tpk --preload 6. Reboot -- 2.7.4 From c3ef20d436a6d80bb313e40e4e3ed2149ff56ee3 Mon Sep 17 00:00:00 2001 From: Manasij Sur Roy Date: Thu, 20 Apr 2017 15:45:37 +0530 Subject: [PATCH 04/16] Fixed SVACE issues Change-Id: Ibc8e09939f74e23d46fb383cedf357b68d3ddccb Signed-off-by: Manasij Sur Roy --- bt_roaming_agent/src/bt_server.c | 7 ++++--- roaming_agent/src/iotcon_handler.c | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/bt_roaming_agent/src/bt_server.c b/bt_roaming_agent/src/bt_server.c index 7603002..ce0ed1a 100644 --- a/bt_roaming_agent/src/bt_server.c +++ b/bt_roaming_agent/src/bt_server.c @@ -143,6 +143,9 @@ __bt_send_data(int sock_fd, char *data) int ret = bt_socket_send_data(sock_fd, full_data, full_data_len); _INFO("bt_socket_send_data=[%d]", ret); + SAFE_DELETE(data); + SAFE_DELETE(full_data); + return 0; } @@ -162,9 +165,6 @@ __receive_finished(bt_server_t *server) server->expected_len = 0; server->rem_len = 0; - char *fullDataString = (char*)calloc(server->client_req_len + 1, sizeof(char)); - memcpy(fullDataString, server->client_req, server->client_req_len); - _INFO("bluetooth Total pack length = [%d]", server->client_req_len); /*Call ASM dbus and receive the response*/ @@ -331,6 +331,7 @@ __bt_sock_data_received_cb(bt_socket_received_data_s* data, void* user_data) sscanf(d_len_str, "%d", &d_len); _INFO("Data Len frame=[%d]", d_len); + SAFE_DELETE(d_len_str); server->expected_len = d_len; diff --git a/roaming_agent/src/iotcon_handler.c b/roaming_agent/src/iotcon_handler.c index 3dc8bad..1703d64 100644 --- a/roaming_agent/src/iotcon_handler.c +++ b/roaming_agent/src/iotcon_handler.c @@ -242,7 +242,7 @@ _create_ra_representation(ra_resource_s *ra, char *tlvRespB64) /*TODO:Call Mobile ASM with the incoming query (Base64 decoded TLV)*/ //char tlv_b64_dec[5000] = {0,}; //snprintf(tlv_b64_dec, 4999, "%s", ASM_GET_INFO_RESP); - iotcon_attributes_add_str(state, RA_QUERY_KEY_RESPONSE, tlvRespB64); + ret = iotcon_attributes_add_str(state, RA_QUERY_KEY_RESPONSE, tlvRespB64); if (IOTCON_ERROR_NONE != ret) { iotcon_attributes_destroy(state); iotcon_representation_destroy(repr); -- 2.7.4 From 62bd2e943900381761bbd91d5d0aaa4f8811c359 Mon Sep 17 00:00:00 2001 From: Manasij Sur Roy Date: Mon, 8 May 2017 12:14:48 +0530 Subject: [PATCH 05/16] SVACE issue fix for 4.0 Change-Id: Ie6e5c2eff19b7ca3e5ad7dea97b92d85eb039336 Signed-off-by: Manasij Sur Roy --- common/AsmHelper.h | 1 + common/cryptoutil/inc/asmcrypto.h | 10 +- common/cryptoutil/src/AsmCrypto.cpp | 267 +++------------------ common/datatypes/src/AsmRegRequest.cpp | 2 +- common/datatypes/src/AsmRequest.cpp | 4 +- common/datatypes/src/AsmResponse.cpp | 4 +- common/uafv1tlvutil/inc/TlvData.h | 2 +- common/uafv1tlvutil/src/AttBasicFullTlvEncoder.cpp | 29 ++- common/uafv1tlvutil/src/AttBasicSurrTlvEncoder.cpp | 28 ++- .../src/AuthAssertionInfoTlvEncoder.cpp | 3 + .../src/AuthCountersInfoTlvEncoder.cpp | 3 + common/uafv1tlvutil/src/BufferTlvEncoder.cpp | 2 + common/uafv1tlvutil/src/DeRegReqTlvEncoder.cpp | 27 ++- common/uafv1tlvutil/src/DeRegRespTlvEncoder.cpp | 18 +- common/uafv1tlvutil/src/GetInfoReqTlvEncoder.cpp | 14 +- common/uafv1tlvutil/src/GetInfoRespTlvEncoder.cpp | 40 ++- common/uafv1tlvutil/src/IntTlvEncoder.cpp | 2 + .../src/RegAssertionInfoTlvEncoder.cpp | 2 + .../src/RegAuthAssertionTlvEncoder.cpp | 41 +++- .../uafv1tlvutil/src/RegCountersInfoTlvEncoder.cpp | 2 + common/uafv1tlvutil/src/RegReqTlvEncoder.cpp | 33 ++- common/uafv1tlvutil/src/RegRespTlvEncoder.cpp | 35 ++- .../src/SignAuthAssertionTlvEncoder.cpp | 29 ++- common/uafv1tlvutil/src/SignReqTlvEncoder.cpp | 28 ++- common/uafv1tlvutil/src/SignRespTlvEncoder.cpp | 67 +++++- common/uafv1tlvutil/src/SignedDataTlvEncoder.cpp | 27 ++- common/uafv1tlvutil/src/StringTlvEncoder.cpp | 1 + common/uafv1tlvutil/src/Tlv.cpp | 5 + common/uafv1tlvutil/src/Uafv1KrdTlvEncoder.cpp | 26 +- common/uiutil/src/AcUiAdaptor.cpp | 4 +- common/uiutil/src/PinAuthUiAdaptor.cpp | 6 +- common/uiutil/src/TCUiAdaptor.cpp | 4 +- server/auth_discovery/src/BAuthStub.cpp | 56 ++++- server/auth_discovery/src/BleAdProvider.cpp | 4 +- server/auth_discovery/src/BleCon.cpp | 5 +- server/auth_discovery/src/BtADProvider.cpp | 6 + server/auth_discovery/src/BtCon.cpp | 18 +- server/auth_discovery/src/IoTCon.cpp | 16 +- server/auth_discovery/src/IotADProvider.cpp | 5 +- server/auth_discovery/src/RAuthStub.cpp | 3 + server/auth_discovery/src/RoamingUtil.cpp | 5 + server/ops/src/AsmOp.cpp | 4 +- server/ops/src/GetInfoOp.cpp | 38 +-- server/src/AsmStorage.cpp | 11 +- server/src/ClientListener.cpp | 19 +- server/states/src/AuthenticateState.cpp | 8 +- server/states/src/GetRegsState.cpp | 7 +- server/states/src/RegisterState.cpp | 28 ++- server/states/src/TCState.cpp | 2 +- server/states/src/VerifyState.cpp | 2 +- silent_auth/silent_auth_entry.cpp | 86 +++++-- 51 files changed, 715 insertions(+), 374 deletions(-) diff --git a/common/AsmHelper.h b/common/AsmHelper.h index 2b61584..c44f577 100755 --- a/common/AsmHelper.h +++ b/common/AsmHelper.h @@ -20,6 +20,7 @@ #include #include +#include #define RET_IF_FAIL_VOID(cond) do {\ if (!(cond)){\ diff --git a/common/cryptoutil/inc/asmcrypto.h b/common/cryptoutil/inc/asmcrypto.h index 90fff27..edb6b0b 100644 --- a/common/cryptoutil/inc/asmcrypto.h +++ b/common/cryptoutil/inc/asmcrypto.h @@ -39,23 +39,17 @@ public: static int aesDecrypt(const unsigned char *ciphertext, int ciphertext_len, const unsigned char *key, const unsigned char *iv, unsigned char *plaintext); static int createRSAKeyPair(int ksz, char **pubkey, int *pubkey_len, char **prikey, int *prikey_len); - static int createSha256Digest(const unsigned char *ip, int ip_len, char **op); static unsigned char* readDer(const char *der_file_name, int *len); - static unsigned char *signRSA(const unsigned char *m, unsigned char *pri_key); /*Caller must call AuthenrStub::Hash on this*/ static std::string getKHAccessToken(std::string appId, bool isBound); - static int signWithRSAPSSMGF1(const char *message, int m_len, - const char *privKeyFile, const char *pwd, - unsigned char **signature, int *sig_len); - static int digestSignRSAPSSMGF1(const char *message, int m_len, const char *privKeyFile, const char *pwd, unsigned char **signature, int *sig_len); static std::string getDeviceId(void); - static char* getAppId(char *appIdPubKey); + static char* getAppId(const char *appIdPubKey); static unsigned char* fidoSignWithKey(const unsigned char *msg, int msg_len, const unsigned char *private_key, int priv_key_len, @@ -65,6 +59,8 @@ public: const char *pwd, int *sig_len); static std::string getAsmToken(void); + + static int genRandomInt(void); private: static int onPkgList(pkgmgrinfo_pkginfo_h handle, void *user_data); diff --git a/common/cryptoutil/src/AsmCrypto.cpp b/common/cryptoutil/src/AsmCrypto.cpp index 32d7dee..c42d9cb 100644 --- a/common/cryptoutil/src/AsmCrypto.cpp +++ b/common/cryptoutil/src/AsmCrypto.cpp @@ -155,6 +155,7 @@ AsmCrypto::getAsmToken(void) std::string macStr(macClone); _INFO("%s", macStr.c_str()); asmTok = strdup(macClone); + SAFE_DELETE(macClone); return macStr; } } else { @@ -163,13 +164,14 @@ AsmCrypto::getAsmToken(void) time_t t; srand((unsigned) time(&t)); mac = (char*)calloc(128, sizeof(char)); - snprintf(mac, 128 - 1, "%d", (rand()%1000 + 1)); + snprintf(mac, 128 - 1, "%d", (AsmCrypto::genRandomInt()%1000 + 1)); char *macClone = _SAFE_DUP(mac); _INFO("%s", macClone); std::string macStr(macClone); _INFO("%s", macStr.c_str()); asmTok = strdup(macClone); + SAFE_DELETE(macClone); return macStr; } @@ -199,15 +201,19 @@ AsmCrypto::getAsmToken(void) time_t t; srand((unsigned) time(&t)); mac = (char*)calloc(128, sizeof(char)); - snprintf(mac, 128 - 1, "%d", (rand()%1000 + 1)); + snprintf(mac, 128 - 1, "%d", (genRandomInt()%1000 + 1)); } file = fopen(ASM_CONFIG_FILE, "w+"); - fwrite(mac, sizeof(char), strlen(mac), file); - fclose(file); + if (file != NULL) { + fwrite(mac, sizeof(char), strlen(mac), file); + fclose(file); + } std::string tok(mac, strlen(mac)); _END; asmTok = strdup(mac); + SAFE_DELETE(mac); + return tok; } else { @@ -217,6 +223,11 @@ AsmCrypto::getAsmToken(void) fclose(file); _END; return std::string(); + } else if (size > 1000) { + _ERR("Too big config file, size=[%d], allowed=[1000]", size); + fclose(file); + _END; + return std::string(); } fseek(file, 0, SEEK_SET); @@ -237,6 +248,7 @@ AsmCrypto::getAsmToken(void) std::string tok(config, strlen(config)); _END; asmTok = strdup(config); + SAFE_DELETE(config); return tok; } } @@ -422,11 +434,12 @@ AsmCrypto::genB64Decodes(const unsigned char *input, int inlen, unsigned char * _ERR("BIO_read failed. size or data error"); return -1; } - if(b64) - { + if(b64) { BIO_free_all(b64); } + SAFE_DELETE(base64); + _INFO("%s", output); _INFO("outlen len = %d", *outlen); @@ -580,27 +593,6 @@ AsmCrypto::createRSAKeyPair(int ksz, char **pubkey, int *pubkey_len, char **prik return 0; } -int -AsmCrypto::createSha256Digest(const unsigned char *ip, int ip_len, char **op) -{ - unsigned char hash[SHA256_DIGEST_LENGTH]; - SHA256_CTX sha256; - SHA256_Init(&sha256); - SHA256_Update(&sha256, ip, ip_len); - SHA256_Final(hash, &sha256); - - char *op_temp = (char *) (calloc(1, (SHA256_DIGEST_LENGTH * 2) + 1)); - int i = 0; - for(i = 0; i < SHA256_DIGEST_LENGTH; i++) - { - sprintf(op_temp + (i * 2), "%02x", hash[i]); - } - - *op = op_temp; - - return 0; -} - unsigned char* AsmCrypto::readDer(const char *der_file_name, int *len) { @@ -621,6 +613,7 @@ AsmCrypto::readDer(const char *der_file_name, int *len) int ret = __load_cert_from_x509(pcert, &cert); if(ret != 0) { + SAFE_DELETE(cert); return NULL; } @@ -628,7 +621,10 @@ AsmCrypto::readDer(const char *der_file_name, int *len) _INFO("ReadDERCertFile end"); - return cert->raw_cert; + unsigned char *rawCert = cert->raw_cert; + SAFE_DELETE(cert); + + return rawCert; } @@ -715,149 +711,6 @@ void hex2bin(const char *str, int str_len, void *mem) } int -AsmCrypto::signWithRSAPSSMGF1(const char *message, int m_len, - const char *privKeyFile, const char *pwd, - unsigned char **signature, int *sig_len) -{ - _BEGIN; - int err_no; - unsigned int size; - unsigned int dgst_size; - unsigned char mess[RSA_MAX_MES_LENGTH]; - unsigned char dgst[RSA_MAX_DGST_SIZE]; - unsigned char tbs[RSA_MAX_SIGN_SIZE]; - unsigned char *sig = (unsigned char *)calloc(1, sizeof(RSA_MAX_SIGN_SIZE)); - //RSA *rsa = NULL; - /*BIGNUM * bn_pub_exp = NULL;*/ - EVP_MD_CTX * mdctx = NULL; - const EVP_MD *md = NULL; - - OpenSSL_add_all_algorithms(); - - FILE *fp; - EVP_PKEY *pkey = NULL; - - fp = fopen(privKeyFile, "r"); - if (fp == NULL) - { - _ERR("Failed to open private key file"); - return -1; - } - - pkey = PEM_read_PrivateKey(fp, &pkey, NULL, (void *)pwd); - - fclose(fp); - - if (pkey == NULL) - { - _ERR("PEM_read_PrivateKey failed"); - return -1; - } - - RSA *rsa = EVP_PKEY_get1_RSA(pkey); - -// int bits = 256; - -// if (bits > RSA_MAX_BITS) -// { -// err_no = -1; -// goto err; -// } - - size = m_len / 2; -// if ( ((size) > RSA_MAX_MES_LENGTH) || ((size) > (bits/8))) -// return -1; - - hex2bin(message, m_len, (void *)mess); - -// if ( (bn_pub_exp = BN_new()) == NULL ) -// { -// err_no = -1; -// goto err; -// } - -// if(!BN_hex2bn(&bn_pub_exp, str_pub_exp)) -// { -// err_no = -1; -// goto err; -// } - - md = EVP_get_digestbynid(NID_sha256); - if(!md) - { - err_no = -1; - goto err; - } - - mdctx = EVP_MD_CTX_create(); - if ( !mdctx) - { - err_no = -1; - goto err; - } - - EVP_DigestInit_ex(mdctx, md, NULL); - EVP_DigestUpdate(mdctx, mess, size); - EVP_DigestFinal_ex(mdctx, dgst, &dgst_size); - EVP_MD_CTX_destroy(mdctx); - - /*rsa = RSA_new(); - if(!rsa) - { - err_no = RSA_ERR; - goto err; - } - RSA_set_method(rsa, (const RSA_METHOD *)RSA_get_default_method()); - - err_no = RSA_generate_key_ex(rsa, bits, bn_pub_exp, NULL); - if (err_no <= 0) - { - err_no = RSA_ERR; - goto err; - }*/ - - if (!RSA_padding_add_PKCS1_PSS_mgf1(rsa, tbs, dgst, md, md, -2 /* */ )) - { - err_no = -1; - goto err; - } - - err_no = RSA_private_encrypt(RSA_size(rsa), tbs, sig, rsa, RSA_NO_PADDING); - if(err_no < 0) - { - _INFO("ERR::RSA_private_encrypt"); - err_no = -1; - goto err; - } - - _INFO("SUCCESS::RSA_private_encrypt"); -// err_no = RSA_public_decrypt(RSA_size(rsa), sig, tbs, rsa, RSA_NO_PADDING); -// if (err_no <= 0) -// { -// err_no = RSA_ERR; -// goto err; -// } -// err_no = RSA_verify_PKCS1_PSS_mgf1(rsa, dgst, md, md, tbs, -2); -// if (err_no <= 0) -// { -// err_no = RSA_ERR; -// goto err; -// } - - *signature = sig; - *sig_len = 256; - - err_no = 0; - -err: - -// if(rsa) RSA_free(rsa); -// if(bn_pub_exp) BN_free(bn_pub_exp); - - return err_no; -} - -int AsmCrypto::digestSignRSAPSSMGF1(const char *message, int m_len, const char *privKeyFile, const char *pwd, unsigned char **signature, int *sig_len) @@ -934,6 +787,7 @@ AsmCrypto::digestSignRSAPSSMGF1(const char *message, int m_len, /* Obtain the signature */ if(EVP_SUCCESS != EVP_DigestSignFinal(mdctx, sig, &slen)) { _ERR("EVP_DigestSignFinal failed"); + SAFE_DELETE(sig); return -1; } @@ -1137,8 +991,10 @@ AsmCrypto::onPkgList(pkgmgrinfo_pkginfo_h handle, void *user_data) author_cert_hash = __get_pub_key_from_cert(author_cert); _INFO(""); - if(author_cert_hash == NULL) + if(author_cert_hash == NULL) { + pkgmgrinfo_pkginfo_destroy_certinfo(cert_handle); return 0; + } tz_facet_id_max_len = strlen(author_cert_hash) + 128; tz_facet_id = (char*)(calloc(1, tz_facet_id_max_len)); @@ -1154,8 +1010,10 @@ AsmCrypto::onPkgList(pkgmgrinfo_pkginfo_h handle, void *user_data) pkgmgrinfo_pkginfo_destroy_certinfo(cert_handle); /*pkgmgrinfo_pkginfo_destroy_pkginfo(handle);*/ + SAFE_DELETE(tz_facet_id); return -1; } else { + SAFE_DELETE(tz_facet_id); return 0; } @@ -1167,7 +1025,7 @@ AsmCrypto::onPkgList(pkgmgrinfo_pkginfo_h handle, void *user_data) } char* -AsmCrypto::getAppId(char *appIdPubKey) +AsmCrypto::getAppId(const char *appIdPubKey) { int ret = -1; @@ -1197,62 +1055,6 @@ AsmCrypto::getAppId(char *appIdPubKey) } unsigned char* -AsmCrypto::signRSA(const unsigned char *m, unsigned char *pri_key) -{ - _BEGIN; - - BIO *bio = NULL; - RSA *rsa = NULL; - unsigned int sign_len = 0; - unsigned char *sign = NULL; - - //int ret = -1; - - OpenSSL_add_all_algorithms(); - bio = BIO_new_mem_buf(pri_key, -1); - if(bio == NULL) - { - _ERR("BIO_new_mem_buf failed"); - goto error; - } - - rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL); - if(rsa == NULL) - { - _ERR("BIO_new_mem_buf failed"); - goto error; - } -// if(len > (unsigned int)RSA_size(rsa)) -// { -// _ERR("msg is too long failed"); -// goto error; -// } - - sign = (unsigned char *)calloc(1, (1024*128)); - if(RSA_sign(NID_sha1, m, strlen((char *)m), sign, &sign_len, rsa) != 1) - { - _ERR("msg is too long failed \n"); - goto error; - } - - _END; - return sign; - -error: - if(rsa) - { - RSA_free(rsa); - rsa = NULL; - } - if(bio) - { - BIO_free(bio); - bio = NULL; - } - return NULL; -} - -unsigned char* AsmCrypto::fidoSignWithKey(const unsigned char *msg, int msg_len, const unsigned char *private_key, int priv_key_len, int *sig_len) @@ -1379,3 +1181,10 @@ AsmCrypto::fidoSign(const unsigned char *msg, int msg_len, const char *private_k *sig_len = sig_len_loc; return sig; } + +int +AsmCrypto::genRandomInt(void) +{ + unsigned int seed = time(NULL); + return rand_r(&seed); +} diff --git a/common/datatypes/src/AsmRegRequest.cpp b/common/datatypes/src/AsmRegRequest.cpp index 1de41de..99b2930 100644 --- a/common/datatypes/src/AsmRegRequest.cpp +++ b/common/datatypes/src/AsmRegRequest.cpp @@ -56,7 +56,7 @@ AsmRegRequest::getAttestationType(void) AsmRegRequest::AsmRegRequest(void) { - + __attType = -1; } diff --git a/common/datatypes/src/AsmRequest.cpp b/common/datatypes/src/AsmRequest.cpp index 0047d9f..7452121 100644 --- a/common/datatypes/src/AsmRequest.cpp +++ b/common/datatypes/src/AsmRequest.cpp @@ -37,10 +37,10 @@ AsmRequest::~AsmRequest(void) if (__requestType == "Register") { delete static_cast(__args); } - if (__requestType == "Authenticate") { + else if (__requestType == "Authenticate") { delete static_cast(__args); } - if (__requestType == "Deregister") { + else if (__requestType == "Deregister") { delete static_cast(__args); } } diff --git a/common/datatypes/src/AsmResponse.cpp b/common/datatypes/src/AsmResponse.cpp index 6e221c3..1ad2761 100644 --- a/common/datatypes/src/AsmResponse.cpp +++ b/common/datatypes/src/AsmResponse.cpp @@ -26,7 +26,9 @@ AsmResponse::AsmResponse(void) { - + __statusCode = -1; + __respData = NULL; + __extList = NULL; } AsmResponse::~AsmResponse(void) diff --git a/common/uafv1tlvutil/inc/TlvData.h b/common/uafv1tlvutil/inc/TlvData.h index ad2fe94..f86150b 100644 --- a/common/uafv1tlvutil/inc/TlvData.h +++ b/common/uafv1tlvutil/inc/TlvData.h @@ -60,7 +60,7 @@ public: __authData = NULL; } - TlvEncodable(const T *authData) : __authData(authData){} + TlvEncodable(const T *authData) : __authData(authData), __encoder(NULL){} virtual ~TlvEncodable(void){} diff --git a/common/uafv1tlvutil/src/AttBasicFullTlvEncoder.cpp b/common/uafv1tlvutil/src/AttBasicFullTlvEncoder.cpp index 617ba9d..b93cc5e 100644 --- a/common/uafv1tlvutil/src/AttBasicFullTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/AttBasicFullTlvEncoder.cpp @@ -49,7 +49,10 @@ AttBasicFullTlvEncoder::encode(const void *authData) tlv_builder_end_composite(builder); _END; - return tlv_builder_get_buffer(builder); + Buffer *buff = tlv_builder_get_buffer(builder); + SAFE_DELETE(builder); + + return buff; } void * @@ -68,7 +71,13 @@ AttBasicFullTlvEncoder::decode(const unsigned char *rawData) AttestationBasicFull *getAttBasicFullInfo = ALLOC(AttestationBasicFull); tlv_s *child = tlv_decode(rawData + rawIter); - RET_IF_FAIL(child != NULL, NULL); + if (child == NULL) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + SAFE_DELETE(getAttBasicFullInfo); + + return NULL; + } bool foundMember = false; @@ -99,10 +108,24 @@ AttBasicFullTlvEncoder::decode(const unsigned char *rawData) if(rawIter >= endIter) break; + SAFE_DELETE(child->val); + SAFE_DELETE(child); + child = tlv_decode(rawData + rawIter); - RET_IF_FAIL(child != NULL, NULL); + if (child == NULL) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + SAFE_DELETE(getAttBasicFullInfo); + + return NULL; + } } + SAFE_DELETE(root->val); + SAFE_DELETE(root); + SAFE_DELETE(child->val); + SAFE_DELETE(child); + if(foundMember == false) { free(getAttBasicFullInfo); return NULL; diff --git a/common/uafv1tlvutil/src/AttBasicSurrTlvEncoder.cpp b/common/uafv1tlvutil/src/AttBasicSurrTlvEncoder.cpp index 606be95..540223c 100644 --- a/common/uafv1tlvutil/src/AttBasicSurrTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/AttBasicSurrTlvEncoder.cpp @@ -46,7 +46,10 @@ AttBasicSurrTlvEncoder::encode(const void *authData) tlv_builder_end_composite(builder); _END; - return tlv_builder_get_buffer(builder); + Buffer *buff = tlv_builder_get_buffer(builder); + SAFE_DELETE(builder); + + return buff; } void * @@ -65,7 +68,13 @@ AttBasicSurrTlvEncoder::decode(const unsigned char *rawData) AttestationBasicSurrogate *getAttBasicSurrInfo = ALLOC(AttestationBasicSurrogate); tlv_s *child = tlv_decode(rawData + rawIter); - RET_IF_FAIL(child != NULL, NULL); + if (child == NULL) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + SAFE_DELETE(getAttBasicSurrInfo); + + return NULL; + } bool foundMember = false; @@ -87,10 +96,23 @@ AttBasicSurrTlvEncoder::decode(const unsigned char *rawData) if(rawIter >= endIter) break; + SAFE_DELETE(child->val); + SAFE_DELETE(child); child = tlv_decode(rawData + rawIter); - RET_IF_FAIL(child != NULL, NULL); + if (child == NULL) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + SAFE_DELETE(getAttBasicSurrInfo); + + return NULL; + } } + SAFE_DELETE(root->val); + SAFE_DELETE(root); + SAFE_DELETE(child->val); + SAFE_DELETE(child); + if(foundMember == false) { free(getAttBasicSurrInfo); return NULL; diff --git a/common/uafv1tlvutil/src/AuthAssertionInfoTlvEncoder.cpp b/common/uafv1tlvutil/src/AuthAssertionInfoTlvEncoder.cpp index 32cb888..eff8d70 100644 --- a/common/uafv1tlvutil/src/AuthAssertionInfoTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/AuthAssertionInfoTlvEncoder.cpp @@ -91,6 +91,9 @@ AuthAssertionInfoTlvEncoder::decode(const unsigned char *rawData) rawIter += 2; CATCH: + SAFE_DELETE(root_val); + SAFE_DELETE(root); + _INFO("AuthAssertionInfoTlvEncoder::decode end"); return getAssertionInfo; } diff --git a/common/uafv1tlvutil/src/AuthCountersInfoTlvEncoder.cpp b/common/uafv1tlvutil/src/AuthCountersInfoTlvEncoder.cpp index 463d3c3..71c7565 100644 --- a/common/uafv1tlvutil/src/AuthCountersInfoTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/AuthCountersInfoTlvEncoder.cpp @@ -69,6 +69,9 @@ AuthCountersInfoTlvEncoder::decode(const unsigned char *rawData) _INFO("signCounter [%d]", getCountersInfo->signCounter); rawIter += 2; + SAFE_DELETE(root_val); + SAFE_DELETE(root); + _INFO("AuthCountersInfoTlvEncoder::decode end"); return getCountersInfo; } diff --git a/common/uafv1tlvutil/src/BufferTlvEncoder.cpp b/common/uafv1tlvutil/src/BufferTlvEncoder.cpp index e5d5d98..8f990a2 100644 --- a/common/uafv1tlvutil/src/BufferTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/BufferTlvEncoder.cpp @@ -46,6 +46,8 @@ BufferTlvEncoder::decode(const uint8_t *rawData) getBuffInfo->data = tlv->val; getBuffInfo->len = tlv->len; + SAFE_DELETE(tlv); + _INFO("BufferTlvEncoder end"); return getBuffInfo; } diff --git a/common/uafv1tlvutil/src/DeRegReqTlvEncoder.cpp b/common/uafv1tlvutil/src/DeRegReqTlvEncoder.cpp index d471d4e..830f1d4 100644 --- a/common/uafv1tlvutil/src/DeRegReqTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/DeRegReqTlvEncoder.cpp @@ -61,7 +61,10 @@ DeRegReqTlvEncoder::encode(const void *authData) tlv_builder_end_composite(builder); _INFO("DeRegReqTlvEncoder::encode end"); - return tlv_builder_get_buffer(builder); + Buffer *buff = tlv_builder_get_buffer(builder); + SAFE_DELETE(builder); + + return buff; } void * @@ -78,7 +81,12 @@ DeRegReqTlvEncoder::decode(const unsigned char *rawData) int endIter = rawIter + root->len; tlv_s *child = tlv_decode(rawData + rawIter); - RET_IF_FAIL(child != NULL, NULL); + if (child == NULL) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + + return NULL; + } DeregReq *getDeRegReqInfo = ALLOC(DeregReq); @@ -121,10 +129,23 @@ DeRegReqTlvEncoder::decode(const unsigned char *rawData) if(rawIter >= endIter) break; + SAFE_DELETE(child->val); + SAFE_DELETE(child); child = tlv_decode(rawData + rawIter); - RET_IF_FAIL(child != NULL, NULL); + if (child == NULL) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + SAFE_DELETE(getDeRegReqInfo); + + return NULL; + } } + SAFE_DELETE(root->val); + SAFE_DELETE(root); + SAFE_DELETE(child->val); + SAFE_DELETE(child); + if(foundMember == false) { free(getDeRegReqInfo); return NULL; diff --git a/common/uafv1tlvutil/src/DeRegRespTlvEncoder.cpp b/common/uafv1tlvutil/src/DeRegRespTlvEncoder.cpp index f74e3c3..1302893 100644 --- a/common/uafv1tlvutil/src/DeRegRespTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/DeRegRespTlvEncoder.cpp @@ -45,7 +45,10 @@ DeRegRespTlvEncoder::encode(const void *authData) tlv_builder_end_composite(builder); _INFO("DeRegRespTlvEncoder::encode end"); - return tlv_builder_get_buffer(builder); + Buffer *buff = tlv_builder_get_buffer(builder); + SAFE_DELETE(builder); + + return buff; } void * @@ -63,7 +66,13 @@ DeRegRespTlvEncoder::decode(const unsigned char *rawData) int rawIter = 2 + 2; tlv_s *child = tlv_decode(rawData + rawIter); - RET_IF_FAIL(child != NULL, NULL); + if (child == NULL) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + SAFE_DELETE(getDeRegRespInfo); + + return NULL; + } bool foundMember = false; @@ -73,6 +82,11 @@ DeRegRespTlvEncoder::decode(const unsigned char *rawData) foundMember = true; } + SAFE_DELETE(root->val); + SAFE_DELETE(root); + SAFE_DELETE(child->val); + SAFE_DELETE(child); + if(foundMember == false) { free(getDeRegRespInfo); return NULL; diff --git a/common/uafv1tlvutil/src/GetInfoReqTlvEncoder.cpp b/common/uafv1tlvutil/src/GetInfoReqTlvEncoder.cpp index 19dfd5f..8ce96ea 100644 --- a/common/uafv1tlvutil/src/GetInfoReqTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/GetInfoReqTlvEncoder.cpp @@ -35,7 +35,10 @@ GetInfoReqTlvEncoder::encode(const void *authData) tlv->len = 0; _INFO("GetInfoReqTlvEncoder::encode end"); - return tlv_to_buffer(tlv); + Buffer *tlvBuff = tlv_to_buffer(tlv); + SAFE_DELETE(tlv); + + return tlvBuff; } void* @@ -46,11 +49,18 @@ GetInfoReqTlvEncoder::decode(const unsigned char *rawData) tlv_s *root = tlv_decode(rawData); RET_IF_FAIL(root != NULL, NULL); - RET_IF_FAIL(root->tag == TAG_UAFV1_GETINFO_CMD, NULL); + if (root->tag != TAG_UAFV1_GETINFO_CMD) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + return NULL; + } GetInfoReq *getInfoReqInfo = ALLOC(GetInfoReq); getInfoReqInfo->tag = TAG_UAFV1_GETINFO_CMD; + SAFE_DELETE(root->val); + SAFE_DELETE(root); + _INFO("GetInfoReqTlvEncoder::decode end"); return getInfoReqInfo; } diff --git a/common/uafv1tlvutil/src/GetInfoRespTlvEncoder.cpp b/common/uafv1tlvutil/src/GetInfoRespTlvEncoder.cpp index a08074f..7485cd6 100644 --- a/common/uafv1tlvutil/src/GetInfoRespTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/GetInfoRespTlvEncoder.cpp @@ -198,6 +198,8 @@ AuthMetaTlvEncoder::decode(const uint8_t *rawData) CATCH: + SAFE_DELETE(tlv_val); + SAFE_DELETE(tlv); _INFO("AuthMetaTlvEncoder end"); return meta; } @@ -338,6 +340,7 @@ TcDispPNGChTlvEncoder::decode(const uint8_t *rawData) CATCH: + SAFE_DELETE(root); _INFO("TcDispPNGChTlvEncoder end"); return getTcDsipPngChInfo; } @@ -369,7 +372,11 @@ AuthInfoTlvEncoder::decode(const unsigned char *rawData) _INFO("AuthInfoTlvEncoder TOTAL LEN = [%d] bytes", end_iter); tlv_s *child = tlv_decode(rawData + rawIter); - RET_IF_FAIL(child != NULL, NULL); + if (child == NULL) { + SAFE_DELETE(tlv->val); + SAFE_DELETE(tlv); + return NULL; + } _INFO("AuthInfoTlvEncoder after child decode"); @@ -455,6 +462,10 @@ AuthInfoTlvEncoder::decode(const unsigned char *rawData) child = tlv_decode(rawData + rawIter); } + SAFE_DELETE(child); + SAFE_DELETE(tlv->val); + SAFE_DELETE(tlv); + if (foundMember == false) { free(authInfo); return NULL; @@ -600,7 +611,10 @@ GetInfoRespTlvEncoder::encode(const void *authData) _INFO("GetInfoRespTlvEncoder::encode 26"); _INFO("GetInfoRespTlvEncoder::encode end"); - return tlv_builder_get_buffer(builder); + Buffer *buff = tlv_builder_get_buffer(builder); + SAFE_DELETE(builder); + + return buff; } void* @@ -612,23 +626,31 @@ GetInfoRespTlvEncoder::decode(const unsigned char *rawData) _INFO(""); - GetAuthInfoResp *getInfoResp = (GetAuthInfoResp*)calloc(1, sizeof(GetAuthInfoResp)); - AuthenticatorInfo *auth = NULL; tlv_s *root = tlv_decode(rawData); - RET_IF_FAIL(root != NULL, NULL); + if (root == NULL) { + return NULL; + } int rawIter = 2 + 2; int end_iter = rawIter + root->len; _INFO("GetInfoRespTlvEncoder TOTAL LEN = [%d] bytes", end_iter); RET_IF_FAIL(root->tag == TAG_UAFV1_GETINFO_CMD_RESPONSE, NULL); + if (root->tag != TAG_UAFV1_GETINFO_CMD_RESPONSE) { + SAFE_DELETE(root); + return NULL; + } tlv_s *child = tlv_decode(rawData + rawIter); - RET_IF_FAIL(child != NULL, NULL); + if (child == NULL) { + SAFE_DELETE(root); + return NULL; + } bool foundMember = false; + GetAuthInfoResp *getInfoResp = (GetAuthInfoResp*)calloc(1, sizeof(GetAuthInfoResp)); while (1) { @@ -664,9 +686,15 @@ GetInfoRespTlvEncoder::decode(const unsigned char *rawData) if (rawIter >= end_iter) break; + SAFE_DELETE(child->val); + SAFE_DELETE(child); child = tlv_decode(rawData + rawIter); } + SAFE_DELETE(child->val); + SAFE_DELETE(child); + SAFE_DELETE(root); + if (foundMember == false) { free(getInfoResp); return NULL; diff --git a/common/uafv1tlvutil/src/IntTlvEncoder.cpp b/common/uafv1tlvutil/src/IntTlvEncoder.cpp index 5c0f4b5..9ee101e 100644 --- a/common/uafv1tlvutil/src/IntTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/IntTlvEncoder.cpp @@ -61,5 +61,7 @@ IntTlvEncoder::decode(const unsigned char *rawData) _INFO("IntTlvEncoder end"); + SAFE_DELETE(tlv->val); + SAFE_DELETE(tlv); return val_ptr; } diff --git a/common/uafv1tlvutil/src/RegAssertionInfoTlvEncoder.cpp b/common/uafv1tlvutil/src/RegAssertionInfoTlvEncoder.cpp index 928c166..220d3b1 100644 --- a/common/uafv1tlvutil/src/RegAssertionInfoTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/RegAssertionInfoTlvEncoder.cpp @@ -111,6 +111,8 @@ RegAssertionInfoTlvEncoder::decode(const unsigned char *rawData) CATCH: + SAFE_DELETE(root_val); + SAFE_DELETE(root); _INFO("RegAssertionInfoTlvEncoder::decode end"); return getAssertionInfo; } diff --git a/common/uafv1tlvutil/src/RegAuthAssertionTlvEncoder.cpp b/common/uafv1tlvutil/src/RegAuthAssertionTlvEncoder.cpp index 80ed1af..a848d6d 100644 --- a/common/uafv1tlvutil/src/RegAuthAssertionTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/RegAuthAssertionTlvEncoder.cpp @@ -51,6 +51,7 @@ RegAuthAssertionTlvEncoder::encode(const void *authData) regAssertionKrdBuff->len = getRegAssertionKrdTlv->len; regAssertionKrdBuff->data = getRegAssertionKrdTlv->val; tlv_builder_add_buffer(builder, TAG_UAFV1_KRD, regAssertionKrdBuff); + SAFE_DELETE(regAssertionKrdBuff); } if(getRegAssertion->attFull != NULL) { @@ -65,6 +66,8 @@ RegAuthAssertionTlvEncoder::encode(const void *authData) attBasicFullBuff->len = getAttBasicFullInfoTlv->len; attBasicFullBuff->data = getAttBasicFullInfoTlv->val; tlv_builder_add_buffer(builder, TAG_ATTESTATION_BASIC_FULL, attBasicFullBuff); + SAFE_DELETE(attBasicFullBuff); + SAFE_DELETE(getAttBasicFullBuffInfo); } else if(getRegAssertion->attSur != NULL) { @@ -78,10 +81,13 @@ RegAuthAssertionTlvEncoder::encode(const void *authData) attBasicSurrBuff->len = getAttBasicSurrInfoTlv->len; attBasicSurrBuff->data = getAttBasicSurrInfoTlv->val; tlv_builder_add_buffer(builder, TAG_ATTESTATION_BASIC_SURROGATE, attBasicSurrBuff); + SAFE_DELETE(attBasicSurrBuff); + SAFE_DELETE(getAttBasicSurrInfoBuff); } else { _ERR("No option of AttestationBasic is set"); + SAFE_DELETE(builder); return NULL; } @@ -89,7 +95,10 @@ RegAuthAssertionTlvEncoder::encode(const void *authData) tlv_builder_end_composite(builder); _END; - return tlv_builder_get_buffer(builder); + Buffer *buff = tlv_builder_get_buffer(builder); + SAFE_DELETE(builder); + + return buff; } void * @@ -100,9 +109,10 @@ RegAuthAssertionTlvEncoder::decode(const unsigned char *rawData) tlv_s *root = tlv_decode(rawData); RET_IF_FAIL(root != NULL, NULL); - RET_IF_FAIL(root->tag == TAG_UAFV1_REG_ASSERTION, NULL); - - RegAssertion *getRegAssertionInfo = ALLOC(RegAssertion); + if (root->tag != TAG_UAFV1_REG_ASSERTION) { + SAFE_DELETE(root); + return NULL; + } bool foundMember = false; @@ -111,8 +121,14 @@ RegAuthAssertionTlvEncoder::decode(const unsigned char *rawData) int endIter = rawIter + root->len; tlv_s *child = tlv_decode(rawData + rawIter); - RET_IF_FAIL(child != NULL, NULL); + if (child == NULL) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + + return NULL; + } + RegAssertion *getRegAssertionInfo = ALLOC(RegAssertion); while(1) { switch(child->tag) { @@ -146,11 +162,24 @@ RegAuthAssertionTlvEncoder::decode(const unsigned char *rawData) if(rawIter >= endIter) break; + SAFE_DELETE(child->val); + SAFE_DELETE(child); _INFO(""); child = tlv_decode(rawData + rawIter); - RET_IF_FAIL(child != NULL, NULL); + if (child == NULL) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + SAFE_DELETE(getRegAssertionInfo); + + return NULL; + } } + SAFE_DELETE(child->val); + SAFE_DELETE(child); + SAFE_DELETE(root->val); + SAFE_DELETE(root); + _INFO(""); if(foundMember == false) { _INFO(""); diff --git a/common/uafv1tlvutil/src/RegCountersInfoTlvEncoder.cpp b/common/uafv1tlvutil/src/RegCountersInfoTlvEncoder.cpp index d2ce9c7..0888a98 100644 --- a/common/uafv1tlvutil/src/RegCountersInfoTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/RegCountersInfoTlvEncoder.cpp @@ -94,6 +94,8 @@ RegCountersInfoTlvEncoder::decode(const unsigned char *rawData) rawIter += 4; CATCH: + SAFE_DELETE(root_val); + SAFE_DELETE(root); _INFO("RegCountersInfoTlvEncoder::decode end"); return getCountersInfo; } diff --git a/common/uafv1tlvutil/src/RegReqTlvEncoder.cpp b/common/uafv1tlvutil/src/RegReqTlvEncoder.cpp index 9d75efa..0f7b4c2 100644 --- a/common/uafv1tlvutil/src/RegReqTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/RegReqTlvEncoder.cpp @@ -73,7 +73,10 @@ RegAssertionTlvEncoder::encode(const void *authData) tlv_builder_end_composite(builder); _INFO("RegAssertionTlvEncoder::encode 12"); - return tlv_builder_get_buffer(builder); + Buffer *buff = tlv_builder_get_buffer(builder); + SAFE_DELETE(builder); + + return buff; } void* @@ -84,13 +87,21 @@ RegAssertionTlvEncoder::decode(const unsigned char *rawData) tlv_s* root = tlv_decode(rawData); RET_IF_FAIL(root != NULL, NULL); - RET_IF_FAIL(root->tag == TAG_UAFV1_REGISTER_CMD, NULL); + if (root->tag != TAG_UAFV1_REGISTER_CMD) { + SAFE_DELETE(root); + return NULL; + } int rawIter = 2 + 2; int endIter = rawIter + root->len; tlv_s* child = tlv_decode(root->val); - RET_IF_FAIL(child != NULL, NULL); + if (child == NULL) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + + return NULL; + } bool foundMember = false; RegisterReq *getRegReqInfo = ALLOC(RegisterReq); @@ -156,15 +167,29 @@ RegAssertionTlvEncoder::decode(const unsigned char *rawData) if(rawIter >= endIter) break; + SAFE_DELETE(child->val); + SAFE_DELETE(child); child = tlv_decode(rawData + rawIter); - RET_IF_FAIL(child != NULL, NULL); + if (child == NULL) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + + SAFE_DELETE(getRegReqInfo); + return NULL; + } } + SAFE_DELETE(child->val); + SAFE_DELETE(child); + SAFE_DELETE(root->val); + SAFE_DELETE(root); + if(foundMember == false) { free(getRegReqInfo); return NULL; } + SAFE_DELETE(root); _INFO("RegAssertionInfoTlvEncoder::decode end"); return getRegReqInfo; } diff --git a/common/uafv1tlvutil/src/RegRespTlvEncoder.cpp b/common/uafv1tlvutil/src/RegRespTlvEncoder.cpp index 639cbf8..a72c8a4 100644 --- a/common/uafv1tlvutil/src/RegRespTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/RegRespTlvEncoder.cpp @@ -59,7 +59,10 @@ RegRespTlvEncoder::encode(const void *authData) tlv_builder_end_composite(builder); - return tlv_builder_get_buffer(builder); + Buffer *buff = tlv_builder_get_buffer(builder); + SAFE_DELETE(builder); + + return buff; } void* @@ -68,19 +71,26 @@ RegRespTlvEncoder::decode(const unsigned char *rawData) _INFO("RegRespTlvEncoder::decode start"); RET_IF_FAIL(rawData != NULL, NULL); - RegisterResp *getRegRespInfo = ALLOC(RegisterResp); - tlv_s *root = tlv_decode(rawData); RET_IF_FAIL(root != NULL, NULL); - RET_IF_FAIL(root->tag == TAG_UAFV1_REGISTER_CMD_RESPONSE, NULL); + if (root->tag != TAG_UAFV1_REGISTER_CMD_RESPONSE) { + SAFE_DELETE(root); + return NULL; + } int rawIter = 2 + 2; int endIter = rawIter + root->len; tlv_s *child = tlv_decode(root->val); - RET_IF_FAIL(child != NULL, NULL); + if (child == NULL) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + + return NULL; + } bool foundMember = false; + RegisterResp *getRegRespInfo = ALLOC(RegisterResp); while(1) { @@ -118,11 +128,24 @@ RegRespTlvEncoder::decode(const unsigned char *rawData) break; } + SAFE_DELETE(child->val); + SAFE_DELETE(child); _INFO(""); child = tlv_decode(rawData + rawIter); - RET_IF_FAIL(child != NULL, NULL); + if (child == NULL) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + SAFE_DELETE(getRegRespInfo); + + return NULL; + } } + SAFE_DELETE(child->val); + SAFE_DELETE(child); + SAFE_DELETE(root->val); + SAFE_DELETE(root); + _INFO(""); if(foundMember == false) { _INFO(""); diff --git a/common/uafv1tlvutil/src/SignAuthAssertionTlvEncoder.cpp b/common/uafv1tlvutil/src/SignAuthAssertionTlvEncoder.cpp index 49bf21e..cb08bcf 100644 --- a/common/uafv1tlvutil/src/SignAuthAssertionTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/SignAuthAssertionTlvEncoder.cpp @@ -52,6 +52,7 @@ SignAuthAssertionTlvEncoder::encode(const void *authData) getSigDataBuff->data = getSigDataInfoTlv->val; tlv_builder_add_buffer(builder, TAG_UAFV1_SIGNED_DATA, getSigDataBuff); + SAFE_DELETE(getSigDataBuff); /*1.2 end*/ } @@ -63,7 +64,10 @@ SignAuthAssertionTlvEncoder::encode(const void *authData) tlv_builder_end_composite(builder); _END; - return tlv_builder_get_buffer(builder); + Buffer *buff = tlv_builder_get_buffer(builder); + SAFE_DELETE(builder); + + return buff; } void * @@ -86,7 +90,13 @@ SignAuthAssertionTlvEncoder::decode(const unsigned char *rawData) int endIter = rawIter + root->len; tlv_s *child = tlv_decode(rawData + rawIter); - RET_IF_FAIL(child != NULL, NULL); + if (child == NULL) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + SAFE_DELETE(getAuthAssInfo); + + return NULL; + } while(1) { @@ -110,10 +120,23 @@ SignAuthAssertionTlvEncoder::decode(const unsigned char *rawData) if(rawIter >= endIter) break; + SAFE_DELETE(child->val); + SAFE_DELETE(child); child = tlv_decode(rawData + rawIter); - RET_IF_FAIL(child != NULL, NULL); + if (child == NULL) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + SAFE_DELETE(getAuthAssInfo); + + return NULL; + } } + SAFE_DELETE(child->val); + SAFE_DELETE(child); + SAFE_DELETE(root->val); + SAFE_DELETE(root); + if(foundMember == false) { free(getAuthAssInfo); return NULL; diff --git a/common/uafv1tlvutil/src/SignReqTlvEncoder.cpp b/common/uafv1tlvutil/src/SignReqTlvEncoder.cpp index 12f49e5..42c6de3 100644 --- a/common/uafv1tlvutil/src/SignReqTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/SignReqTlvEncoder.cpp @@ -85,7 +85,10 @@ SignReqTlvEncoder::encode(const void *authData) tlv_builder_end_composite(builder); - return tlv_builder_get_buffer(builder); + Buffer *buff = tlv_builder_get_buffer(builder); + SAFE_DELETE(builder); + + return buff; } void * @@ -105,7 +108,13 @@ SignReqTlvEncoder::decode(const unsigned char *rawData) AuthenticateReq *getAuthReqInfo = NALLOC(1, AuthenticateReq); tlv_s *child = tlv_decode(rawData + rawIter); - RET_IF_FAIL(child != NULL, NULL); + if (child == NULL) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + SAFE_DELETE(getAuthReqInfo); + + return NULL; + } bool foundMember = false; @@ -162,10 +171,23 @@ SignReqTlvEncoder::decode(const unsigned char *rawData) if(rawIter >= endIter) break; + SAFE_DELETE(child->val); + SAFE_DELETE(child); child = tlv_decode(rawData + rawIter); - RET_IF_FAIL(child != NULL, NULL); + if (child == NULL) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + SAFE_DELETE(getAuthReqInfo); + + return NULL; + } } + SAFE_DELETE(child->val); + SAFE_DELETE(child); + SAFE_DELETE(root->val); + SAFE_DELETE(root); + if(foundMember == false) { free(getAuthReqInfo); return NULL; diff --git a/common/uafv1tlvutil/src/SignRespTlvEncoder.cpp b/common/uafv1tlvutil/src/SignRespTlvEncoder.cpp index 98a71ad..100d4f3 100644 --- a/common/uafv1tlvutil/src/SignRespTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/SignRespTlvEncoder.cpp @@ -38,8 +38,12 @@ UserNameKhTlvEncoder::decode(const unsigned char *rawData) RET_IF_FAIL(rawData != NULL, NULL); tlv_s *root = tlv_decode(rawData); - RET_IF_FAIL(root->tag == TAG_USERNAME_AND_KEYHANDLE, NULL); RET_IF_FAIL(root != NULL, NULL); + if (root->tag != TAG_USERNAME_AND_KEYHANDLE) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + return NULL; + } int rawIter = 2 + 2; int endIter = rawIter + root->len; @@ -47,7 +51,13 @@ UserNameKhTlvEncoder::decode(const unsigned char *rawData) UserNameKeyHandle *getUsnKhInfo = ALLOC(UserNameKeyHandle); tlv_s *child = tlv_decode(rawData + rawIter); - RET_IF_FAIL(child != NULL, NULL); + if (child == NULL) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + SAFE_DELETE(getUsnKhInfo); + + return NULL; + } bool foundMember = false; @@ -73,10 +83,22 @@ UserNameKhTlvEncoder::decode(const unsigned char *rawData) if(rawIter >= endIter) break; + SAFE_DELETE(child->val); + SAFE_DELETE(child); child = tlv_decode(rawData + rawIter); - RET_IF_FAIL(child != NULL, NULL); + if (child == NULL) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + SAFE_DELETE(getUsnKhInfo); + return NULL; + } } + SAFE_DELETE(child->val); + SAFE_DELETE(child); + SAFE_DELETE(root->val); + SAFE_DELETE(root); + if(foundMember == false) { free(getUsnKhInfo); return NULL; @@ -143,6 +165,7 @@ SignRespTlvEncoder::encode(const void *authData) else { _ERR("Neither UsernameKeyhandle List nor Authentication Assertion is set"); + SAFE_DELETE(builder); return NULL; } @@ -150,7 +173,10 @@ SignRespTlvEncoder::encode(const void *authData) tlv_builder_end_composite(builder); _INFO("SignRespTlvEncoder::encode end"); - return tlv_builder_get_buffer(builder); + Buffer *buff = tlv_builder_get_buffer(builder); + SAFE_DELETE(builder); + + return buff; } void * @@ -160,17 +186,27 @@ SignRespTlvEncoder::decode(const unsigned char *rawData) RET_IF_FAIL(rawData != NULL, NULL); tlv_s *root = tlv_decode(rawData); - RET_IF_FAIL(root->tag == TAG_UAFV1_SIGN_CMD_RESPONSE, NULL); RET_IF_FAIL(root != NULL, NULL); + if (root->tag != TAG_UAFV1_SIGN_CMD_RESPONSE) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + + return NULL; + } + int rawIter = 2 + 2; int endIter = rawIter + root->len; - AuthenticateResp *getAuthRespInfo = NALLOC(1, AuthenticateResp); - tlv_s *child = tlv_decode(rawData + rawIter); - RET_IF_FAIL(child != NULL, NULL); + if (child == NULL) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + + return NULL; + } + AuthenticateResp *getAuthRespInfo = NALLOC(1, AuthenticateResp); bool foundMember = false; while(1) { @@ -207,10 +243,23 @@ SignRespTlvEncoder::decode(const unsigned char *rawData) if(rawIter >= endIter) break; + SAFE_DELETE(child->val); + SAFE_DELETE(child); child = tlv_decode(rawData + rawIter); - RET_IF_FAIL(child != NULL, NULL); + if (child == NULL) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + SAFE_DELETE(getAuthRespInfo); + + return NULL; + } } + SAFE_DELETE(child->val); + SAFE_DELETE(child); + SAFE_DELETE(root->val); + SAFE_DELETE(root); + if(foundMember == false) { free(getAuthRespInfo); return NULL; diff --git a/common/uafv1tlvutil/src/SignedDataTlvEncoder.cpp b/common/uafv1tlvutil/src/SignedDataTlvEncoder.cpp index c147cce..94829f0 100644 --- a/common/uafv1tlvutil/src/SignedDataTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/SignedDataTlvEncoder.cpp @@ -77,7 +77,10 @@ SignedDataTlvEncoder::encode(const void *authData) tlv_builder_end_composite(builder); _END; - return tlv_builder_get_buffer(builder); + Buffer *buff = tlv_builder_get_buffer(builder); + SAFE_DELETE(builder); + + return buff; } void * @@ -93,7 +96,12 @@ SignedDataTlvEncoder::decode(const unsigned char *rawData) int endIter = rawIter + root->len; tlv_s *child = tlv_decode(rawData + rawIter); - RET_IF_FAIL(child != NULL, NULL); + if (child == NULL) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + + return NULL; + } SigData *getSigDataInfo = ALLOC(SigData); @@ -147,10 +155,23 @@ SignedDataTlvEncoder::decode(const unsigned char *rawData) if(rawIter >= endIter) break; + SAFE_DELETE(child->val); + SAFE_DELETE(child); child = tlv_decode(rawData + rawIter); - RET_IF_FAIL(child != NULL, NULL); + if (child == NULL) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + SAFE_DELETE(getSigDataInfo); + + return NULL; + } } + SAFE_DELETE(child->val); + SAFE_DELETE(child); + SAFE_DELETE(root->val); + SAFE_DELETE(root); + if(foundMember == false) { free(getSigDataInfo); return NULL; diff --git a/common/uafv1tlvutil/src/StringTlvEncoder.cpp b/common/uafv1tlvutil/src/StringTlvEncoder.cpp index 3427146..90cac50 100644 --- a/common/uafv1tlvutil/src/StringTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/StringTlvEncoder.cpp @@ -47,6 +47,7 @@ StringTlvEncoder::decode(const uint8_t *rawData) _INFO("[%s]", val); + SAFE_DELETE(tlv); _INFO("StringTlvEncoder end"); return val; } diff --git a/common/uafv1tlvutil/src/Tlv.cpp b/common/uafv1tlvutil/src/Tlv.cpp index 7f79dc0..7ae50e8 100644 --- a/common/uafv1tlvutil/src/Tlv.cpp +++ b/common/uafv1tlvutil/src/Tlv.cpp @@ -140,6 +140,7 @@ tlv_builder_add_int8(tlv_builder_s* builder, int tag, uint8_t val) //g_queue_push_head(builder->stack, head); free(node); + SAFE_DELETE(node_buff); return builder; } @@ -167,6 +168,7 @@ tlv_builder_add_int16(tlv_builder_s* builder, int tag, uint16_t val) //g_queue_push_head(builder->stack, head); free(node); + SAFE_DELETE(node_buff); return builder; } @@ -197,6 +199,7 @@ tlv_builder_add_string(tlv_builder_s *builder, int tag, char *val) //g_queue_push_head(builder->stack, head); free(node); + SAFE_DELETE(node_buff); return builder; } @@ -222,6 +225,7 @@ tlv_builder_add_buffer(tlv_builder_s *builder, int tag, Buffer *val) //g_queue_push_head(builder->stack, head); free(node); + SAFE_DELETE(node_buff); return builder; } @@ -249,6 +253,7 @@ tlv_builder_end_composite(tlv_builder_s *builder) //g_queue_push_head(builder->stack, cur_head); + SAFE_DELETE(head_buff); return builder; } diff --git a/common/uafv1tlvutil/src/Uafv1KrdTlvEncoder.cpp b/common/uafv1tlvutil/src/Uafv1KrdTlvEncoder.cpp index 3f06eb3..e040fae 100644 --- a/common/uafv1tlvutil/src/Uafv1KrdTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/Uafv1KrdTlvEncoder.cpp @@ -75,7 +75,10 @@ Uafv1KrdTlvEncoder::encode(const void *authData) tlv_builder_end_composite(builder); _INFO("Uafv1KrdTlvEncoder::encode end"); - return tlv_builder_get_buffer(builder); + Buffer *buff = tlv_builder_get_buffer(builder); + SAFE_DELETE(builder); + + return buff; } void * @@ -94,7 +97,11 @@ Uafv1KrdTlvEncoder::decode(const unsigned char *rawData) Krd *getKrdInfo = ALLOC(Krd); tlv_s *child = tlv_decode(rawData + rawIter); - RET_IF_FAIL(child != NULL, NULL); + if (child == NULL) { + free(getKrdInfo); + SAFE_DELETE(root); + return NULL; + } bool foundMember = false; @@ -143,10 +150,23 @@ Uafv1KrdTlvEncoder::decode(const unsigned char *rawData) if(rawIter >= endIter) break; + SAFE_DELETE(child->val); + SAFE_DELETE(child); child = tlv_decode(rawData + rawIter); - RET_IF_FAIL(child != NULL, NULL); + if (child == NULL) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + SAFE_DELETE(getKrdInfo); + + return NULL; + } } + SAFE_DELETE(child->val); + SAFE_DELETE(child); + SAFE_DELETE(root->val); + SAFE_DELETE(root); + if(foundMember == false) { free(getKrdInfo); return NULL; diff --git a/common/uiutil/src/AcUiAdaptor.cpp b/common/uiutil/src/AcUiAdaptor.cpp index 038447b..e1284d7 100644 --- a/common/uiutil/src/AcUiAdaptor.cpp +++ b/common/uiutil/src/AcUiAdaptor.cpp @@ -27,6 +27,7 @@ #include #include #include "AsmUiCommonTypes.h" +#include "asmcrypto.h" AcUiAdaptor* AcUiAdaptor::__this = NULL; static const int NONCE_LEN = 8; @@ -51,7 +52,7 @@ AcUiAdaptor::genNonce(void) char *nonce = NALLOC(NONCE_LEN + 1, char); for (int i = 0; i < NONCE_LEN; i++) { - int randNum = rand() % ('z' - '0'); + int randNum = AsmCrypto::genRandomInt() % ('z' - '0'); nonce[i] = '0' + randNum; } nonce[NONCE_LEN] = '\0'; @@ -189,6 +190,7 @@ AcUiAdaptor::AcUiAdaptor(void) { __sessionData = NULL; __result = -1; + __mainLoop = NULL; } AcUiAdaptor::~AcUiAdaptor(void) diff --git a/common/uiutil/src/PinAuthUiAdaptor.cpp b/common/uiutil/src/PinAuthUiAdaptor.cpp index 46fb643..f8c436c 100644 --- a/common/uiutil/src/PinAuthUiAdaptor.cpp +++ b/common/uiutil/src/PinAuthUiAdaptor.cpp @@ -27,6 +27,8 @@ #include #include #include "AsmUiCommonTypes.h" +#include "asmcrypto.h" + PinAuthUiAdaptor* PinAuthUiAdaptor::__this = NULL; static const int NONCE_LEN = 8; @@ -57,7 +59,7 @@ PinAuthUiAdaptor::genNonce(void) char *nonce = NALLOC(NONCE_LEN + 1, char); for (int i = 0; i < NONCE_LEN; i++) { - int randNum = rand() % ('z' - '0'); + int randNum = AsmCrypto::genRandomInt() % ('z' - '0'); nonce[i] = '0' + randNum; } nonce[NONCE_LEN] = '\0'; @@ -103,6 +105,7 @@ PinAuthUiAdaptor::getTokenFromUi(pin_auth_mode_e type, const std::string& appId, for (int i = 0; i < 10; i++) { uiPid = aul_launch_app_for_uid(ASM_UI_APP_NAME, b, OWNER_UID); _INFO("aul_launch_app = [%d]", uiPid); + bundle_free(b); if (uiPid < 0) { if (uiPid == AUL_R_EINVAL) _INFO("AUL_R_EINVAL"); @@ -192,6 +195,7 @@ PinAuthUiAdaptor::PinAuthUiAdaptor(void) __sessionData = NULL; __result = -1; __usrVerTok = NULL; + __uiAppPid = -1; } PinAuthUiAdaptor::~PinAuthUiAdaptor(void) diff --git a/common/uiutil/src/TCUiAdaptor.cpp b/common/uiutil/src/TCUiAdaptor.cpp index 0b0bb2a..8f98a81 100644 --- a/common/uiutil/src/TCUiAdaptor.cpp +++ b/common/uiutil/src/TCUiAdaptor.cpp @@ -26,6 +26,7 @@ #include #include #include "AsmUiCommonTypes.h" +#include "asmcrypto.h" TcUiAdaptor* TcUiAdaptor::__this = NULL; static const int NONCE_LEN = 8; @@ -50,7 +51,7 @@ TcUiAdaptor::genNonce(void) char *nonce = NALLOC(NONCE_LEN + 1, char); for (int i = 0; i < NONCE_LEN; i++) { - int randNum = rand() % ('z' - '0'); + int randNum = AsmCrypto::genRandomInt() % ('z' - '0'); nonce[i] = '0' + randNum; } nonce[NONCE_LEN] = '\0'; @@ -145,6 +146,7 @@ TcUiAdaptor::TcUiAdaptor(void) { __sessionData = NULL; __result = -1; + __mainLoop = NULL; } TcUiAdaptor::~TcUiAdaptor(void) diff --git a/server/auth_discovery/src/BAuthStub.cpp b/server/auth_discovery/src/BAuthStub.cpp index 229382d..a4eb035 100644 --- a/server/auth_discovery/src/BAuthStub.cpp +++ b/server/auth_discovery/src/BAuthStub.cpp @@ -143,8 +143,10 @@ _parse_enroll_request(char *enrollJson, char **appId, char **aaid) const char *appId_temp = json_object_get_string_member(rootObj, "appId"); const char *aaid_temp = json_object_get_string_member(rootObj, "aaid"); - *appId = strdup(appId_temp); - *aaid = strdup(aaid_temp); + if (appId_temp != NULL) + *appId = strdup(appId_temp); + if (aaid_temp != NULL) + *aaid = strdup(aaid_temp); if (parser != NULL) g_object_unref(parser); @@ -190,7 +192,11 @@ BAuthStub::enroll(const char *opt) char *appId = NULL; char *aaid = NULL; int res = _parse_enroll_request((char*)opt, &appId, &aaid); - RET_IF_FAIL(res == 0, -1); + if (res != 0) { + SAFE_DELETE(appId); + SAFE_DELETE(aaid); + return -1; + } _INFO("enroll json parsed successfully"); @@ -204,6 +210,8 @@ BAuthStub::enroll(const char *opt) std::string tok = uiAd->enrollUser(appIdStr, &ret); if(tok.c_str() == NULL) { _INFO("BAuthStub::enroll::token NULL"); + SAFE_DELETE(appId); + SAFE_DELETE(aaid); return -1; } _INFO("enrollUser = [%s]", tok.c_str()); @@ -212,22 +220,54 @@ BAuthStub::enroll(const char *opt) AsmCrypto::genHash256(tok.c_str(), tok.length(), digest); unsigned char *vToken = AsmCrypto::ToBase64Url(digest, DIGEST_LEN); std::string vTokStr((char*)vToken); + SAFE_DELETE(vToken); std::string devId = AsmCrypto::getDeviceId(); RET_IF_FAIL(devId.empty() == false, -1); + if (devId.empty() == true) { + SAFE_DELETE(appId); + SAFE_DELETE(aaid); + return -1; + } IStorageParcel *parcel = new SecretStorageParcel(); res = parcel->setString(STR_PROP_AAID, aaid); - RET_IF_FAIL(res == 0, -1); + if (res != 0) { + SAFE_DELETE(appId); + SAFE_DELETE(aaid); + return -1; + } + res = parcel->setString(STR_PROP_DEV_ID, devId); - RET_IF_FAIL(res == 0, -1); + if (res != 0) { + SAFE_DELETE(appId); + SAFE_DELETE(aaid); + return -1; + } + res = parcel->setString(STR_PROP_SECRET1, vTokStr); - RET_IF_FAIL(res == 0, -1); + if (res != 0) { + SAFE_DELETE(appId); + SAFE_DELETE(aaid); + return -1; + } + res = parcel->setInt(INT_PROP_UID, uid); - RET_IF_FAIL(res == 0, -1); + if (res != 0) { + SAFE_DELETE(appId); + SAFE_DELETE(aaid); + return -1; + } res = AsmStorage::getInstance()->insertData(parcel); - RET_IF_FAIL(res == 0, -1); + if (res != 0) { + SAFE_DELETE(appId); + SAFE_DELETE(aaid); + return -1; + } + + SAFE_DELETE(appId); + SAFE_DELETE(aaid); _INFO("Enroll data inserted success"); _INFO("BAuthStub::enroll::end"); diff --git a/server/auth_discovery/src/BleAdProvider.cpp b/server/auth_discovery/src/BleAdProvider.cpp index d8a24bf..1f66ec7 100644 --- a/server/auth_discovery/src/BleAdProvider.cpp +++ b/server/auth_discovery/src/BleAdProvider.cpp @@ -409,5 +409,7 @@ BleAdProvider::~BleAdProvider(void) BleAdProvider::BleAdProvider(void) { - + __stubCache = NULL; + __waitLoop = NULL; + __isValidInst = false; } diff --git a/server/auth_discovery/src/BleCon.cpp b/server/auth_discovery/src/BleCon.cpp index 5ce9f68..0636df2 100644 --- a/server/auth_discovery/src/BleCon.cpp +++ b/server/auth_discovery/src/BleCon.cpp @@ -6,6 +6,8 @@ BleCon::BleCon(void) { __gClient = NULL; + __waitLoop = NULL; + __resp = NULL; } BleCon::~BleCon(void) @@ -31,7 +33,7 @@ BleCon::onGattServerResponse(bt_gatt_h characteristic, char *value, btCon->__resp = new StringMap(); std::string k(RA_QUERY_KEY_RESPONSE); - std::string v(strdup(value)); + std::string v(value); btCon->__resp->insert(std::make_pair(k, v)); g_main_loop_quit(btCon->__waitLoop); @@ -82,6 +84,7 @@ BleCon::sendReqSync(StringMap *reqData) g_main_loop_run(__waitLoop); CATCH: + SAFE_DELETE(reqTlvB64Copy); g_main_loop_unref(__waitLoop); bt_gatt_client_unset_characteristic_value_changed_cb(__gClient->__btClientChrResp); _INFO("sendReqSync=%s", __resp); diff --git a/server/auth_discovery/src/BtADProvider.cpp b/server/auth_discovery/src/BtADProvider.cpp index 2bcd709..c9d370b 100644 --- a/server/auth_discovery/src/BtADProvider.cpp +++ b/server/auth_discovery/src/BtADProvider.cpp @@ -227,7 +227,13 @@ BtAdProvider::~BtAdProvider(void) BtAdProvider::BtAdProvider(void) { + __stubCache = NULL; + __waitLoop = NULL; + __isValidInst = false; + __isDiscovering = false; + __sAddr = NULL; + __isConCbSet = false; } void diff --git a/server/auth_discovery/src/BtCon.cpp b/server/auth_discovery/src/BtCon.cpp index ee16be2..01ac26b 100644 --- a/server/auth_discovery/src/BtCon.cpp +++ b/server/auth_discovery/src/BtCon.cpp @@ -71,11 +71,22 @@ BtCon::sendDataInternal(int sock_fd, char *data) int ret = bt_socket_send_data(sock_fd, full_data, full_data_len); _INFO("bt_socket_send_data=[%d]", ret); + SAFE_DELETE(full_data); + return 0; } BtCon::BtCon(void) { + __sock = NULL; + __waitLoop = NULL; + __resp = NULL; + + __fullData = NULL; + __fullDataLen = -1; + + __expDLen = -1; + __remDLen = -1; __activeTimerId = 0; } @@ -118,12 +129,14 @@ BtCon::receiveFinshed(void) char *fullDataString = (char*)calloc(__fullDataLen + 1, sizeof(char)); memcpy(fullDataString, __fullData, __fullDataLen); - std::string v(strdup(fullDataString)); + std::string v(fullDataString); _INFO("Total pack length = [%d]", __fullDataLen); __resp->insert(std::make_pair(k, v)); __activeTimerId = 0; + SAFE_DELETE(fullDataString); + g_main_loop_quit(__waitLoop); } @@ -247,6 +260,8 @@ BtCon::onBtSockDataReceived(bt_socket_received_data_s *data, void *user_data) btCon->__remDLen = btCon->__expDLen - d_first_frame_len; cur_pack_len = d_first_frame_len; + + SAFE_DELETE(d_len_str); } else { pack = (char*)calloc(data->data_size, sizeof(char)); @@ -309,6 +324,7 @@ BtCon::sendReqSync(StringMap *reqData) int ret = sendDataInternal(__sock->socket_fd, reqTlvB64Copy); //int ret = bt_socket_send_data(__sock->socket_fd, reqTlvB64Copy, dLen); _INFO("bt_socket_send_data=[%d]", ret); + SAFE_DELETE(reqTlvB64Copy); if (ret != 0) { _INFO("incomplete transfer=[%d]", ret); bt_socket_unset_data_received_cb(); diff --git a/server/auth_discovery/src/IoTCon.cpp b/server/auth_discovery/src/IoTCon.cpp index b0c6c63..38bf0f2 100644 --- a/server/auth_discovery/src/IoTCon.cpp +++ b/server/auth_discovery/src/IoTCon.cpp @@ -6,7 +6,9 @@ IoTCon::IoTCon(void) { - + __waitLoop = NULL; + __iotClient = NULL; + __resp = NULL; } IoTCon::~IoTCon(void) @@ -45,7 +47,7 @@ IoTCon::onResponsePut(iotcon_remote_resource_h resource, iotcon_error_e err, conn->__resp = new StringMap(); std::string k(RA_QUERY_KEY_RESPONSE); - std::string v(strdup(asm_resp)); + std::string v(asm_resp); conn->__resp->insert(std::make_pair(k, v)); } else { _ERR("Failed to get %s", RA_QUERY_KEY_RESPONSE); @@ -68,9 +70,9 @@ IoTCon::sendReqSync(StringMap *reqData) iotcon_attributes_create(&attr); char *reqTlvB64Copy = strdup(reqTlvB64.c_str()); - + char *svrIdCopy = strdup(svrId.c_str()); iotcon_attributes_add_str(attr, RA_QUERY_KEY_REQUEST, reqTlvB64Copy); - iotcon_attributes_add_str(attr, RA_QUERY_KEY_SERVER_ID, _SAFE_DUP(svrId.c_str())); + iotcon_attributes_add_str(attr, RA_QUERY_KEY_SERVER_ID, svrIdCopy); iotcon_representation_h repr = NULL; iotcon_representation_create(&repr); @@ -82,9 +84,15 @@ IoTCon::sendReqSync(StringMap *reqData) int ret = iotcon_remote_resource_put(__iotClient, repr, NULL, onResponsePut, this); if (ret != IOTCON_ERROR_NONE) { _ERR("iotcon_remote_resource_get failed"); + iotcon_representation_destroy(repr); + SAFE_DELETE(reqTlvB64Copy); + SAFE_DELETE(svrIdCopy); return NULL; } + iotcon_representation_destroy(repr); + SAFE_DELETE(reqTlvB64Copy); + SAFE_DELETE(svrIdCopy); _INFO("iotcon_remote_resource_get=[%d]", ret); g_main_loop_run(__waitLoop); diff --git a/server/auth_discovery/src/IotADProvider.cpp b/server/auth_discovery/src/IotADProvider.cpp index b23466a..570a6fe 100644 --- a/server/auth_discovery/src/IotADProvider.cpp +++ b/server/auth_discovery/src/IotADProvider.cpp @@ -130,10 +130,11 @@ IotADProvider::getAuthStubList(void) iotQ, resourceFoundCb, this); if (IOTCON_ERROR_NONE != ret) { _ERR("iotcon_find_resource failed"); - + iotcon_query_destroy(iotQ); return NULL; } + iotcon_query_destroy(iotQ); g_main_loop_run(__waitLoop); _INFO("After g_main_loop_run"); @@ -211,4 +212,6 @@ IotADProvider::IotADProvider(void) : __isValidInst(false) { __stubCache = NULL; + __waitLoop = NULL; + __isValidInst = false; } diff --git a/server/auth_discovery/src/RAuthStub.cpp b/server/auth_discovery/src/RAuthStub.cpp index c3bd402..922815f 100644 --- a/server/auth_discovery/src/RAuthStub.cpp +++ b/server/auth_discovery/src/RAuthStub.cpp @@ -177,6 +177,7 @@ RAuthStub::processRegister(const RegisterReq *regReq) _INFO(""); char *tlvRespB64 = NULL; processTlv(tlvReqB64, &tlvRespB64); + SAFE_DELETE(tlvReqB64); RET_IF_FAIL(tlvRespB64 != NULL, NULL); _INFO(""); @@ -202,6 +203,7 @@ RAuthStub::processAuthenticate(const AuthenticateReq *authnReq) char *tlvRespB64 = NULL; processTlv(tlvReqB64, &tlvRespB64); + SAFE_DELETE(tlvReqB64); RET_IF_FAIL(tlvRespB64 != NULL, NULL); unsigned char *tlvResp = NULL; @@ -228,6 +230,7 @@ RAuthStub::processDeregister(const DeregReq *deregReq) _INFO(""); char *tlvRespB64 = NULL; processTlv(tlvReqB64, &tlvRespB64); + SAFE_DELETE(tlvReqB64); RET_IF_FAIL(tlvRespB64 != NULL, NULL); _INFO(""); diff --git a/server/auth_discovery/src/RoamingUtil.cpp b/server/auth_discovery/src/RoamingUtil.cpp index 8633d9c..cbb3193 100644 --- a/server/auth_discovery/src/RoamingUtil.cpp +++ b/server/auth_discovery/src/RoamingUtil.cpp @@ -169,11 +169,16 @@ RoamingUtil::createAuthReq(const char *tlvB64) /*https://fidoalliance.org/specs/fido-uaf-v1.0-ps-20141208/fido-uaf-asm-api-v1.0-ps-20141208.html#access-control-for-asm-apis*/ _ERR(""); delete asmReq; + SAFE_DELETE(tlv->val); + SAFE_DELETE(tlv); + return NULL; } _INFO(""); + SAFE_DELETE(tlv->val); + SAFE_DELETE(tlv); return asmReq; } diff --git a/server/ops/src/AsmOp.cpp b/server/ops/src/AsmOp.cpp index 2c9ed8f..9dddba6 100644 --- a/server/ops/src/AsmOp.cpp +++ b/server/ops/src/AsmOp.cpp @@ -25,7 +25,9 @@ AsmOp::execute(void) AsmOp::AsmOp(void) { - + __req = NULL; + __resp = NULL; + __authStub = NULL; } AsmOp::~AsmOp(void) diff --git a/server/ops/src/GetInfoOp.cpp b/server/ops/src/GetInfoOp.cpp index 0125a00..30e095f 100644 --- a/server/ops/src/GetInfoOp.cpp +++ b/server/ops/src/GetInfoOp.cpp @@ -70,32 +70,34 @@ GetInfoOp::execute(void) IAuthStub *stub = *authStubIter; /*This call caches the response inside stub*/ GetAuthInfoResp *getInfo = stub->getInfo(); - GList *aListOfStub = getInfo->authList; - if ((getInfo != NULL) && (aListOfStub != NULL)) { + if (getInfo != NULL) { + GList *aListOfStub = getInfo->authList; + if (aListOfStub != NULL) { - while (aListOfStub != NULL) { + while (aListOfStub != NULL) { - AuthenticatorInfo *authInfo = (AuthenticatorInfo*)(aListOfStub->data); + AuthenticatorInfo *authInfo = (AuthenticatorInfo*)(aListOfStub->data); - //std::string devIdStr(authInfo->__devId); - //std::string aaidStr(authInfo->__aaid); + //std::string devIdStr(authInfo->__devId); + //std::string aaidStr(authInfo->__aaid); - int realIndex = authInfo->__authenticatorIndex; + int realIndex = authInfo->__authenticatorIndex; - int mappedIndex = realIndex;/*AuthIndexHandler::getInstance()-> - getMappedIndex(devIdStr, aaidStr, realIndex);*/ + int mappedIndex = realIndex;/*AuthIndexHandler::getInstance()-> + getMappedIndex(devIdStr, aaidStr, realIndex);*/ - if (stub->getType() == AUTH_TYPE_BOUND) { - stubMapB->insert(std::make_pair(mappedIndex, stub)); - _INFO("[%d][%p] Added to Bound cache", mappedIndex, stub); - } else { - stubMapR->insert(std::make_pair(mappedIndex, stub)); - _INFO("[%d][%p] Added to Roaming cache", mappedIndex, stub); - } + if (stub->getType() == AUTH_TYPE_BOUND) { + stubMapB->insert(std::make_pair(mappedIndex, stub)); + _INFO("[%d][%p] Added to Bound cache", mappedIndex, stub); + } else { + stubMapR->insert(std::make_pair(mappedIndex, stub)); + _INFO("[%d][%p] Added to Roaming cache", mappedIndex, stub); + } - aListOfStub = aListOfStub->next; + aListOfStub = aListOfStub->next; + } + getInfoList->push_back(getInfo); } - getInfoList->push_back(getInfo); } } diff --git a/server/src/AsmStorage.cpp b/server/src/AsmStorage.cpp index 6887fdd..add6a9f 100644 --- a/server/src/AsmStorage.cpp +++ b/server/src/AsmStorage.cpp @@ -370,6 +370,7 @@ AsmStorage::createIfNotExists(const std::string& dbName) snprintf(dbPath, 512 - 1, "%s", SECRET_DB_PATH); } else { + SAFE_DELETE(dbPath); return NULL; } @@ -382,6 +383,7 @@ AsmStorage::createIfNotExists(const std::string& dbName) if (dbH == NULL) { _ERR("Failed to create/open [%s]=[%d]", dbPath, ret); + SAFE_DELETE(dbPath); return NULL; } @@ -391,6 +393,7 @@ AsmStorage::createIfNotExists(const std::string& dbName) _INFO("createtable error = [%s]", errMsg); sqlite3_close(dbH); + SAFE_DELETE(dbPath); return NULL; } @@ -400,9 +403,11 @@ AsmStorage::createIfNotExists(const std::string& dbName) ret = sqlite3_open_v2(dbPath , &dbNew, SQLITE_OPEN_READWRITE, NULL); if (dbNew == NULL) { _ERR("sqlite3_open_v2 error = [%d]", ret); + SAFE_DELETE(dbPath); return NULL; } + SAFE_DELETE(dbPath); _INFO("DB open successful"); return dbNew; } @@ -422,6 +427,7 @@ AsmStorage::openDBHandle(const std::string& dbName) snprintf(dbPath, 512 - 1, "%s", SECRET_DB_PATH); } else { + SAFE_DELETE(dbPath); return NULL; } @@ -429,11 +435,13 @@ AsmStorage::openDBHandle(const std::string& dbName) int ret = db_util_open(dbPath, &dbH, DB_UTIL_REGISTER_HOOK_METHOD); if (SQLITE_OK != ret) { _ERR("db_util_open failed [%s]=[%d]", dbPath, ret); + SAFE_DELETE(dbPath); return NULL; } _INFO("db_util_open done [%s]=[%d]", dbPath, ret); + SAFE_DELETE(dbPath); return dbH; /*return createIfNotExists(dbName);;*/ } @@ -484,7 +492,7 @@ AsmStorage::insertData(IStorageParcel *parcel) time_t now = time(0); struct tm tstruct; char buf[BUFFLEN] = {0}; - tstruct = *gmtime(&now); // UTC datetime + gmtime_r(&now, &tstruct); strftime(buf, sizeof(buf), "%Y-%m-%d.%H:%M:%S", &tstruct); timeval curTime; @@ -534,6 +542,7 @@ AsmStorage::insertData(IStorageParcel *parcel) _INFO("%s", qrySelect); ret = sqlite3_exec(dbHandle, qrySelect, maxMappedIndexCb, &mappedIndex, &errMsg); _INFO("%d", ret); + SAFE_DELETE(qrySelect); CATCH_IF_FAIL(ret == SQLITE_OK); parcel->getInt(INT_PROP_AUTH_ID, &authIndex); diff --git a/server/src/ClientListener.cpp b/server/src/ClientListener.cpp index 157907e..0b4b564 100644 --- a/server/src/ClientListener.cpp +++ b/server/src/ClientListener.cpp @@ -177,6 +177,7 @@ ClientListner::getCallerId(GDBusMethodInvocation *invocation) std::string appIdStr(app_id, strlen(app_id)); + SAFE_DELETE(app_id); return appIdStr; } @@ -226,13 +227,8 @@ ClientListner::onClientRequest(Fidoasm *object, GDBusMethodInvocation *invocatio } _INFO("After operation exec "); - if (asmResp != NULL) { - _INFO("%s", asmResp); - fidoasm_complete_asm_request(__dbusObj, invocation, 0, asmResp); - } else { - _INFO(""); - fidoasm_complete_asm_request(__dbusObj, invocation, -1, RESP_NEG); - } + _INFO("%s", asmResp); + fidoasm_complete_asm_request(__dbusObj, invocation, 0, asmResp); _END; return true; @@ -283,13 +279,8 @@ ClientListner::onAgentRequest(Fidoasm *object, GDBusMethodInvocation *invocation } _INFO("After operation exec "); - if (asmResp != NULL) { - _INFO("%s", asmResp); - fidoasm_complete_ra_request(__dbusObj, invocation, 0, asmResp); - } else { - _INFO(""); - fidoasm_complete_ra_request(__dbusObj, invocation, -1, RESP_NEG); - } + _INFO("%s", asmResp); + fidoasm_complete_asm_request(__dbusObj, invocation, 0, asmResp); _END; return true; diff --git a/server/states/src/AuthenticateState.cpp b/server/states/src/AuthenticateState.cpp index cd95e1b..22d0176 100644 --- a/server/states/src/AuthenticateState.cpp +++ b/server/states/src/AuthenticateState.cpp @@ -119,7 +119,8 @@ AuthenticateState::selectUsernameKeyHandle(AuthenticateReq *signAuthReq, Authent keyHandle = it->second; } signAuthReq->khHList = NULL; - signAuthReq->khHList = g_list_append(signAuthReq->khHList, keyHandle->data); + if (keyHandle != NULL) + signAuthReq->khHList = g_list_append(signAuthReq->khHList, keyHandle->data); return 0; } @@ -329,6 +330,7 @@ AuthenticateState::handle(IAuthStub *stub, AsmRequest *asmReq, const char *str, if (recvKhDec != NULL) { std::string kIdStr((char*)recvKhDec); + SAFE_DELETE(recvKhDec); searchParcel->setString(STR_PROP_KEY_ID, kIdStr); _INFO("search=[%s][%s]", appIdStr.c_str(), kIdStr.c_str()); @@ -487,6 +489,8 @@ AuthenticateState::handle(IAuthStub *stub, AsmRequest *asmReq, const char *str, Buffer *assrtInfo = stub->encodeSignRespone(stubResp->authAssertion, &assrtScheme); if (assrtInfo == NULL || assrtInfo->data == NULL) { _ERR("encodeSignRespone failed"); + delete respData; + delete asmSignResp; return -1; } @@ -496,6 +500,7 @@ AuthenticateState::handle(IAuthStub *stub, AsmRequest *asmReq, const char *str, unsigned char *assrtStrData = AsmCrypto::ToBase64Url(assrtInfo->data, assrtInfo->len); std::string assrtStr((const char *)assrtStrData, strlen((char*)assrtStrData)); + SAFE_DELETE(assrtStrData); std::string assrtSchemeStr((const char *)(assrtScheme), strlen(assrtScheme)); respData->__assertion = assrtStr; @@ -503,6 +508,7 @@ AuthenticateState::handle(IAuthStub *stub, AsmRequest *asmReq, const char *str, asmSignResp->__respData = respData; char *signRespJson = JsonUtil::composeAsmAuthenticateResponse(asmSignResp); + delete asmSignResp; RET_IF_FAIL(signRespJson != NULL, -1); *out = signRespJson; diff --git a/server/states/src/GetRegsState.cpp b/server/states/src/GetRegsState.cpp index 27027de..97b710d 100644 --- a/server/states/src/GetRegsState.cpp +++ b/server/states/src/GetRegsState.cpp @@ -71,7 +71,11 @@ GetRegsState::handle(IAuthStub *authStub, AsmRequest *asmReq, const char *str, c searchParcel->setInt(INT_PROP_AUTH_IDX, asmReq->getAuthIndex()); std::vector* searchRes = AsmStorage::getInstance()->searchData(searchParcel); - RET_IF_FAIL(searchRes != NULL, -1); + if (searchRes == NULL) { + delete asmGetRegResp; + delete respData; + return -1; + } std::vector::iterator searchResIter = searchRes->begin(); for (; searchResIter != searchRes->end(); ++searchResIter) { @@ -117,6 +121,7 @@ GetRegsState::handle(IAuthStub *authStub, AsmRequest *asmReq, const char *str, c asmGetRegResp->__respData = respData; char *asmResp = JsonUtil::composeAsmGetRegsResponse(asmGetRegResp); + delete asmGetRegResp; RET_IF_FAIL(asmResp != NULL, -1); *out = asmResp; diff --git a/server/states/src/RegisterState.cpp b/server/states/src/RegisterState.cpp index 1eff7d0..a88af9e 100644 --- a/server/states/src/RegisterState.cpp +++ b/server/states/src/RegisterState.cpp @@ -111,6 +111,7 @@ RegisterState::handle(IAuthStub *stub, AsmRequest *asmReq, const char *str, char std::string appIdStr((const char *)(regAuthReq->appId), strlen(regAuthReq->appId)); unsigned char *keyHandleStr = AsmCrypto::ToBase64Url((unsigned char*)(stubResp->kh->data), stubResp->kh->len); std::string khStr((const char *)(keyHandleStr), strlen((char*)keyHandleStr)); + SAFE_DELETE(keyHandleStr); regParcel->setString(STR_PROP_CALLER_ID, asmReq->getCallerId()); regParcel->setString(STR_PROP_APP_ID, appIdStr); @@ -139,6 +140,7 @@ RegisterState::handle(IAuthStub *stub, AsmRequest *asmReq, const char *str, char if (tlvRespB64 != NULL) { *out = tlvRespB64; } + SAFE_DELETE(kIdEnc); } } else { @@ -173,6 +175,7 @@ RegisterState::handle(IAuthStub *stub, AsmRequest *asmReq, const char *str, char std::string appIdStr((const char *)(regAuthReq->appId), strlen(regAuthReq->appId)); unsigned char *keyHandleStr = AsmCrypto::ToBase64Url((unsigned char*)(stubResp->kh->data), stubResp->kh->len); std::string khStr((const char *)(keyHandleStr), strlen((char*)keyHandleStr)); + SAFE_DELETE(keyHandleStr); regParcel->setString(STR_PROP_CALLER_ID, asmReq->getCallerId()); @@ -189,6 +192,7 @@ RegisterState::handle(IAuthStub *stub, AsmRequest *asmReq, const char *str, char std::string kIdStr((const char *)(kIdEnc), strlen((char *)kIdEnc)); + SAFE_DELETE(kIdEnc); regParcel->setString(STR_PROP_KEY_ID, kIdStr); @@ -210,12 +214,23 @@ RegisterState::handle(IAuthStub *stub, AsmRequest *asmReq, const char *str, char _INFO(""); Buffer *regAssrt = stub->encodeRegisterRespone(stubResp->regAssertion, &assrtScheme); _INFO(""); - RET_IF_FAIL(regAssrt != NULL, -1); + + if (regAssrt == NULL) { + delete asmRegResp; + delete respData; + return -1; + } unsigned char *assrtStrData = AsmCrypto::ToBase64Url(regAssrt->data, regAssrt->len); - RET_IF_FAIL(assrtStrData != NULL, -1); + if (assrtStrData == NULL) { + delete asmRegResp; + delete respData; + + return -1; + } std::string assrtStr((const char *)assrtStrData, strlen((char*)assrtStrData)); + SAFE_DELETE(assrtStrData); std::string assrtSchemeStr((const char *)(assrtScheme), strlen(assrtScheme)); respData->__assertion = assrtStr; respData->__assertionScheme = assrtSchemeStr; @@ -223,8 +238,15 @@ RegisterState::handle(IAuthStub *stub, AsmRequest *asmReq, const char *str, char _INFO(""); char *regRespJson = JsonUtil::composeAsmRegisterResponse(asmRegResp); - RET_IF_FAIL(regRespJson != NULL, -1); + if (regRespJson == NULL) { + delete asmRegResp; + delete respData; + + return -1; + } + delete asmRegResp; + delete respData; _INFO(""); *out = regRespJson; } diff --git a/server/states/src/TCState.cpp b/server/states/src/TCState.cpp index 830694b..008d33e 100644 --- a/server/states/src/TCState.cpp +++ b/server/states/src/TCState.cpp @@ -55,7 +55,7 @@ TCState::getInfoForUi(AsmRequest *asmReq, std::vector **tcList, RET_IF_FAIL(tcFullList.size() > 0, 0); std::string appIdPubKey = asmAuthReq->getAppId(); - char *appIdReal = AsmCrypto::getAppId(strdup(appIdPubKey.c_str())); + char *appIdReal = AsmCrypto::getAppId(appIdPubKey.c_str()); RET_IF_FAIL(appIdReal != NULL, -1); std::vector *tcListLoc = new std::vector(); diff --git a/server/states/src/VerifyState.cpp b/server/states/src/VerifyState.cpp index b69289f..f3a6cbe 100644 --- a/server/states/src/VerifyState.cpp +++ b/server/states/src/VerifyState.cpp @@ -227,7 +227,7 @@ VerifyState::handle(IAuthStub *stub, AsmRequest *asmReq, const char *str, char * return -1; std::vector *resultList = AsmStorage::getInstance()->searchData(parcel); - if(resultList->size() == 0) { + if ((resultList == NULL) || (resultList->size() == 0)) { _ERR("VerifyState::handle:: User not registerd"); return -1; } diff --git a/silent_auth/silent_auth_entry.cpp b/silent_auth/silent_auth_entry.cpp index 5d04721..ac23823 100644 --- a/silent_auth/silent_auth_entry.cpp +++ b/silent_auth/silent_auth_entry.cpp @@ -160,6 +160,8 @@ CATCH: static void __print_big_string(const char *str) { + RET_IF_FAIL_VOID(str != NULL); + int len = strlen(str); int i = 0; for (; i < len; i+= chunk_size) @@ -353,6 +355,7 @@ processAuthenticate(unsigned char *assert_req) } else { _INFO("setEncoder EID_UAFV1_SIGN_REQ FAIL \n"); + SAFE_DELETE(getAuthRespInfo); return NULL; } @@ -362,6 +365,7 @@ processAuthenticate(unsigned char *assert_req) } else { _INFO("decode EID_UAFV1_SIGN_REQ FAIL \n"); + SAFE_DELETE(getAuthRespInfo); return NULL; } _INFO("===========================AUTHENTICATE REQUEST DECODE============================="); @@ -398,10 +402,10 @@ processAuthenticate(unsigned char *assert_req) if (0 != AsmCrypto::genB64Decodes(khStr, inputSz, output, - &outputSz)) - { + &outputSz)) { _ERR("Failed to decode base64."); free(output); + SAFE_DELETE(getAuthRespInfo); return NULL; } @@ -417,8 +421,7 @@ processAuthenticate(unsigned char *assert_req) key,//(const unsigned char*)symKey.c_str(), iv,//(const unsigned char*)symKey.c_str(), kh_str_dec); - if (dec_len > 0) - { + if (dec_len > 0) { char *khA = NULL; char *pri_key = NULL; char *user_name = NULL; @@ -429,8 +432,7 @@ processAuthenticate(unsigned char *assert_req) __parse_key_handle_json(kh_str_dec, &khA, &pri_key, &user_name); if ((khA != NULL) && (pri_key != NULL) && (user_name != NULL)) - /*TODO strcmp((char*)khATkn_b64_enc, khA) == 0)*/ - { + /*TODO strcmp((char*)khATkn_b64_enc, khA) == 0)*/ { /*pri_key and khAccessToken are b64 encoded*/ _INFO("Key Handle Parameters : [%s][%s][%s]", user_name, pri_key, khA); @@ -485,6 +487,7 @@ processAuthenticate(unsigned char *assert_req) { _ERR("Failed to decode base64."); free(khString_raw); + SAFE_DELETE(getAuthRespInfo); return NULL; } /*b64 decode of keyHandle*/ @@ -498,6 +501,7 @@ processAuthenticate(unsigned char *assert_req) unsigned char *keyId_b64_enc = AsmCrypto::ToBase64Url(digest, DIGEST_LEN); + SAFE_DELETE(khString_raw); getAuthRespInfo->authAssertion = ALLOC(AuthAssertion); getAuthRespInfo->authAssertion->sigData = ALLOC(SigData); @@ -527,6 +531,8 @@ processAuthenticate(unsigned char *assert_req) int ret = AsmCrypto::genHash256(getAuthReqInfo->tc, strlen(getAuthReqInfo->tc), tcHash); if(ret == false) { _ERR("processAuthenticate:: Failed to create Transaction content hash."); + SAFE_DELETE(getAuthRespInfo); + SAFE_DELETE(keyId_b64_enc); return NULL; } @@ -553,6 +559,8 @@ processAuthenticate(unsigned char *assert_req) /*Get UAuth.priv from keyhandle*/ _INFO("processAuthenticate:: Length of b64 encoded keyHandle : [%d]", strlen((char*)khHLIter->data)); + SAFE_DELETE(keyId_b64_enc); + int inputSz = strlen((char*)khHLIter->data); unsigned char* output = NULL; @@ -562,10 +570,10 @@ processAuthenticate(unsigned char *assert_req) if (0 != AsmCrypto::genB64Decodes((unsigned char*)khHLIter->data, inputSz, output, - &outputSz)) - { + &outputSz)) { _ERR("Failed to decode base64."); free(output); + SAFE_DELETE(getAuthRespInfo); return NULL; } @@ -581,9 +589,9 @@ processAuthenticate(unsigned char *assert_req) iv,//(const unsigned char*)symKey.c_str(), kh_str_dec); - if (dec_len <= 0) - { + if (dec_len <= 0) { _ERR("AESDecryptof keyhandle failed"); + SAFE_DELETE(getAuthRespInfo); return NULL; } @@ -601,6 +609,7 @@ processAuthenticate(unsigned char *assert_req) unsigned char *khATkn_b64_dec = AsmCrypto::FromBase64Url((unsigned char*)khA, strlen(khA)); if (memcmp(getAuthReqInfo->khATok->data, khATkn_b64_dec, DIGEST_LEN) != 0) { _INFO("ERR::processAuthenticate:: khAcessToken not matching"); + SAFE_DELETE(getAuthRespInfo); return NULL; } _INFO("processAuthenticate:: khAcessToken matchining"); @@ -615,6 +624,7 @@ processAuthenticate(unsigned char *assert_req) } else { _INFO("setEncoder EID_UAFV1_SIGN_DATA_RESP FAIL"); + SAFE_DELETE(getAuthRespInfo); return NULL; } @@ -624,6 +634,7 @@ processAuthenticate(unsigned char *assert_req) } else { _INFO("encode EID_UAFV1_SIGN_DATA_RESP FAIL"); + SAFE_DELETE(getAuthRespInfo); return NULL; } @@ -638,6 +649,7 @@ processAuthenticate(unsigned char *assert_req) if (sig_str == NULL) { _ERR("SignRSA failed for signature"); + SAFE_DELETE(getAuthRespInfo); return NULL; } @@ -648,12 +660,13 @@ processAuthenticate(unsigned char *assert_req) response_parsed = true; + SAFE_DELETE(sig_str); _INFO("SignRSA success for signature"); } - if (response_parsed == false) - { + if (response_parsed == false) { _ERR("processAuthenticate:: Failed to Get Sign Response"); + SAFE_DELETE(getAuthRespInfo); return NULL; } @@ -678,6 +691,7 @@ processAuthenticate(unsigned char *assert_req) } else { _INFO("setEncoder EID_UAFV1_SIGN_RESP FAIL \n"); + SAFE_DELETE(getAuthRespInfo); return NULL; } @@ -687,6 +701,7 @@ processAuthenticate(unsigned char *assert_req) } else { _INFO("encode EID_UAFV1_SIGN_RESP FAIL \n"); + SAFE_DELETE(getAuthRespInfo); return NULL; } @@ -715,6 +730,7 @@ processRegister(unsigned char *assert_req) } else { _INFO("setEncoder EID_UAFV1_REGISTER_REQ FAIL \n"); + SAFE_DELETE(getRegRespInfo); return NULL; } @@ -724,6 +740,7 @@ processRegister(unsigned char *assert_req) } else { _INFO("decode EID_UAFV1_REGISTER_REQ FAIL \n"); + SAFE_DELETE(getRegRespInfo); return NULL; } _INFO("===========================REGISTER REQUEST DECODE============================="); @@ -737,8 +754,8 @@ processRegister(unsigned char *assert_req) int pri_len = 0; int pub_len = 0; int ret_c = AsmCrypto::createRSAKeyPair(2048, &pub_key_raw, &pub_len, &priv_key_raw, &pri_len); - if (ret_c != 0) - { + if (ret_c != 0) { + SAFE_DELETE(getRegRespInfo); return NULL; } @@ -755,6 +772,7 @@ processRegister(unsigned char *assert_req) __print_big_string(kh_str); if (kh_str == NULL) { + SAFE_DELETE(getRegRespInfo); return NULL; } @@ -845,7 +863,9 @@ processRegister(unsigned char *assert_req) _INFO("encode EID_UAFV1_REG_ASSERTION_KRD_RESP PASS, length of encoded UAFV1KRD is = [%d]", uafv1KrdBuff->len); } else { - _INFO("encode EID_UAFV1_REG_ASSERTION_KRD_RESP FAIL"); + _ERR("encode EID_UAFV1_REG_ASSERTION_KRD_RESP FAIL"); + SAFE_DELETE(getRegRespInfo); + return NULL; } unsigned char *krdStr = (unsigned char*)calloc(1, uafv1KrdBuff->len); @@ -861,6 +881,7 @@ processRegister(unsigned char *assert_req) if (sign_raw == NULL) { _ERR("FIDO SignWithPrivateKeyFile failed"); + SAFE_DELETE(getRegRespInfo); return NULL; } @@ -884,6 +905,7 @@ processRegister(unsigned char *assert_req) memcpy(getRegRespInfo->regAssertion->attFull->cert->data, cert_raw, cert_len); getRegRespInfo->regAssertion->attFull->cert->len = cert_len; + SAFE_DELETE(cert_raw); TlvEncodable encodableRegResp(getRegRespInfo); Buffer *getRegRespInfoBuff = NULL; @@ -894,6 +916,8 @@ processRegister(unsigned char *assert_req) } else { _INFO("setEncoder EID_UAFV1_REGISTER_RESP FAIL \n"); + SAFE_DELETE(getRegRespInfo->kh); + SAFE_DELETE(getRegRespInfo); return NULL; } @@ -903,6 +927,7 @@ processRegister(unsigned char *assert_req) } else { _INFO("decode EID_UAFV1_REGISTER_RESP FAIL \n"); + SAFE_DELETE(getRegRespInfo); return NULL; } @@ -910,6 +935,7 @@ processRegister(unsigned char *assert_req) __reg_counter++; __sign_counter++; + SAFE_DELETE(krdStr); _INFO("========ProcessRegister end========="); return getRegRespInfoBuff; } @@ -978,6 +1004,10 @@ processGetInfo() } else { _INFO("setEncoder EID_UAFV1_GETINFO_RESP FAIL \n"); + SAFE_DELETE(authInfo->__aaid); + SAFE_DELETE(authInfo->__meta); + SAFE_DELETE(authInfo->__tcDispConType); + SAFE_DELETE(authInfo); return NULL; } @@ -988,10 +1018,18 @@ processGetInfo() } else { _INFO("encode EID_UAFV1_GETINFO_RESP FAIL \n"); + SAFE_DELETE(authInfo->__aaid); + SAFE_DELETE(authInfo->__meta); + SAFE_DELETE(authInfo->__tcDispConType); + SAFE_DELETE(authInfo); return NULL; } _INFO("===========================RESPONSE ENCODE============================="); + SAFE_DELETE(authInfo->__aaid); + SAFE_DELETE(authInfo->__meta); + SAFE_DELETE(authInfo->__tcDispConType); + SAFE_DELETE(authInfo); return getInfoRespBuff; } @@ -1002,6 +1040,7 @@ fido_auth_plugin_fido_command_process_internal(unsigned char *assert_req, _INFO("fido_auth_plugin_fido_command_process:: start"); tlv_s *root = tlv_decode(assert_req); + RET_IF_FAIL(root != NULL, -1); Buffer *getRespBuff = NULL; @@ -1042,10 +1081,16 @@ fido_auth_plugin_fido_command_process_internal(unsigned char *assert_req, break; } + SAFE_DELETE(root->val); + SAFE_DELETE(root); + if(foundMember == false) return -1; _INFO("fido_auth_plugin_fido_command_process:: end"); + if (getRespBuff == NULL) + return 0; + return getRespBuff->len; } @@ -1152,6 +1197,7 @@ fido_auth_plugin_verify(const char *cmd, const char *fch, char **verif_token) _INFO("[%s]", ts_str); int ret = syspopup_launch((char *)"fido-syspopup", b); + bundle_free(b); if (ret != 0) { _ERR("syspopup_launch Error = [%d]", ret); return -1; @@ -1177,6 +1223,7 @@ fido_auth_plugin_verify(const char *cmd, const char *fch, char **verif_token) r = buxton_get_value_sync(cli, layer, PWD_VERIFY_STATUS_TS_KEY, &val_ts); if (r == -1) { _ERR("buxton_get_value_sync=[%d]", r); + buxton_free_layer(layer); return -1; } if (val_ts != NULL) { @@ -1196,12 +1243,17 @@ fido_auth_plugin_verify(const char *cmd, const char *fch, char **verif_token) int val_verifiy = false; buxton_value_get_boolean(val_bool, &val_verifiy); _INFO("val_verifiy=[%d]", val_verifiy); - if (val_verifiy != 0) + if (val_verifiy != 0) { + buxton_free_layer(layer); return 0; - else + } + else { + buxton_free_layer(layer); return -1; + } } else { _ERR(""); + buxton_free_layer(layer); return -1; } } -- 2.7.4 From abcdc21134010c39cdeb827f414777f55ff5adcd Mon Sep 17 00:00:00 2001 From: Manasij Sur Roy Date: Fri, 12 May 2017 13:42:36 +0530 Subject: [PATCH 06/16] SVACE issue fix Change-Id: Ie38b89e8eca7acebd6bd84cc59af5362e87b7934 Signed-off-by: Manasij Sur Roy --- common/uafv1tlvutil/src/AttBasicFullTlvEncoder.cpp | 6 +++++- common/uafv1tlvutil/src/AttBasicSurrTlvEncoder.cpp | 6 +++++- common/uafv1tlvutil/src/DeRegReqTlvEncoder.cpp | 6 +++++- common/uafv1tlvutil/src/DeRegRespTlvEncoder.cpp | 6 +++++- common/uafv1tlvutil/src/GetInfoRespTlvEncoder.cpp | 5 ++++- common/uafv1tlvutil/src/RegAuthAssertionTlvEncoder.cpp | 4 ++++ common/uafv1tlvutil/src/RegReqTlvEncoder.cpp | 1 + common/uafv1tlvutil/src/RegRespTlvEncoder.cpp | 1 + common/uafv1tlvutil/src/SignAuthAssertionTlvEncoder.cpp | 7 ++++++- common/uafv1tlvutil/src/SignReqTlvEncoder.cpp | 6 +++++- common/uafv1tlvutil/src/Uafv1KrdTlvEncoder.cpp | 6 +++++- common/uiutil/src/PinAuthUiAdaptor.cpp | 3 ++- 12 files changed, 48 insertions(+), 9 deletions(-) diff --git a/common/uafv1tlvutil/src/AttBasicFullTlvEncoder.cpp b/common/uafv1tlvutil/src/AttBasicFullTlvEncoder.cpp index b93cc5e..233d16b 100644 --- a/common/uafv1tlvutil/src/AttBasicFullTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/AttBasicFullTlvEncoder.cpp @@ -63,7 +63,11 @@ AttBasicFullTlvEncoder::decode(const unsigned char *rawData) tlv_s *root = tlv_decode(rawData); RET_IF_FAIL(root != NULL, NULL); - RET_IF_FAIL(root->tag == TAG_ATTESTATION_BASIC_FULL, NULL); + if (root->tag != TAG_ATTESTATION_BASIC_FULL) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + return NULL; + } int rawIter = 2 + 2; int endIter = rawIter + root->len; diff --git a/common/uafv1tlvutil/src/AttBasicSurrTlvEncoder.cpp b/common/uafv1tlvutil/src/AttBasicSurrTlvEncoder.cpp index 540223c..7b37eaf 100644 --- a/common/uafv1tlvutil/src/AttBasicSurrTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/AttBasicSurrTlvEncoder.cpp @@ -60,7 +60,11 @@ AttBasicSurrTlvEncoder::decode(const unsigned char *rawData) tlv_s *root = tlv_decode(rawData); RET_IF_FAIL(root != NULL, NULL); - RET_IF_FAIL(root->tag == TAG_ATTESTATION_BASIC_SURROGATE, NULL); + if (root->tag != TAG_ATTESTATION_BASIC_SURROGATE) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + return NULL; + } int rawIter = 2 + 2; int endIter = rawIter + root->len; diff --git a/common/uafv1tlvutil/src/DeRegReqTlvEncoder.cpp b/common/uafv1tlvutil/src/DeRegReqTlvEncoder.cpp index 830f1d4..d4ff376 100644 --- a/common/uafv1tlvutil/src/DeRegReqTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/DeRegReqTlvEncoder.cpp @@ -75,7 +75,11 @@ DeRegReqTlvEncoder::decode(const unsigned char *rawData) tlv_s *root = tlv_decode(rawData); RET_IF_FAIL(root != NULL, NULL); - RET_IF_FAIL(root->tag == TAG_UAFV1_DEREGISTER_CMD, NULL); + if (root->tag != TAG_UAFV1_DEREGISTER_CMD) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + return NULL; + } int rawIter = 2 + 2; int endIter = rawIter + root->len; diff --git a/common/uafv1tlvutil/src/DeRegRespTlvEncoder.cpp b/common/uafv1tlvutil/src/DeRegRespTlvEncoder.cpp index 1302893..e6a8ac5 100644 --- a/common/uafv1tlvutil/src/DeRegRespTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/DeRegRespTlvEncoder.cpp @@ -59,7 +59,11 @@ DeRegRespTlvEncoder::decode(const unsigned char *rawData) tlv_s *root = tlv_decode(rawData); RET_IF_FAIL(root != NULL, NULL); - RET_IF_FAIL(root->tag == TAG_UAFV1_DEREGISTER_CMD_RESPONSE, NULL); + if (root->tag != TAG_UAFV1_DEREGISTER_CMD_RESPONSE) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + return NULL; + } DeregResp *getDeRegRespInfo = ALLOC(DeregResp); diff --git a/common/uafv1tlvutil/src/GetInfoRespTlvEncoder.cpp b/common/uafv1tlvutil/src/GetInfoRespTlvEncoder.cpp index 7485cd6..132a586 100644 --- a/common/uafv1tlvutil/src/GetInfoRespTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/GetInfoRespTlvEncoder.cpp @@ -459,6 +459,9 @@ AuthInfoTlvEncoder::decode(const unsigned char *rawData) if (rawIter >= end_iter) break; + SAFE_DELETE(child->val); + SAFE_DELETE(child); + child = tlv_decode(rawData + rawIter); } @@ -637,8 +640,8 @@ GetInfoRespTlvEncoder::decode(const unsigned char *rawData) int end_iter = rawIter + root->len; _INFO("GetInfoRespTlvEncoder TOTAL LEN = [%d] bytes", end_iter); - RET_IF_FAIL(root->tag == TAG_UAFV1_GETINFO_CMD_RESPONSE, NULL); if (root->tag != TAG_UAFV1_GETINFO_CMD_RESPONSE) { + SAFE_DELETE(root->val); SAFE_DELETE(root); return NULL; } diff --git a/common/uafv1tlvutil/src/RegAuthAssertionTlvEncoder.cpp b/common/uafv1tlvutil/src/RegAuthAssertionTlvEncoder.cpp index a848d6d..49e1aa8 100644 --- a/common/uafv1tlvutil/src/RegAuthAssertionTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/RegAuthAssertionTlvEncoder.cpp @@ -52,6 +52,7 @@ RegAuthAssertionTlvEncoder::encode(const void *authData) regAssertionKrdBuff->data = getRegAssertionKrdTlv->val; tlv_builder_add_buffer(builder, TAG_UAFV1_KRD, regAssertionKrdBuff); SAFE_DELETE(regAssertionKrdBuff); + SAFE_DELETE(getRegAssertionKrdTlv); } if(getRegAssertion->attFull != NULL) { @@ -68,6 +69,7 @@ RegAuthAssertionTlvEncoder::encode(const void *authData) tlv_builder_add_buffer(builder, TAG_ATTESTATION_BASIC_FULL, attBasicFullBuff); SAFE_DELETE(attBasicFullBuff); SAFE_DELETE(getAttBasicFullBuffInfo); + SAFE_DELETE(getAttBasicFullInfoTlv); } else if(getRegAssertion->attSur != NULL) { @@ -83,6 +85,7 @@ RegAuthAssertionTlvEncoder::encode(const void *authData) tlv_builder_add_buffer(builder, TAG_ATTESTATION_BASIC_SURROGATE, attBasicSurrBuff); SAFE_DELETE(attBasicSurrBuff); SAFE_DELETE(getAttBasicSurrInfoBuff); + SAFE_DELETE(getAttBasicSurrInfoTlv); } else { @@ -110,6 +113,7 @@ RegAuthAssertionTlvEncoder::decode(const unsigned char *rawData) tlv_s *root = tlv_decode(rawData); RET_IF_FAIL(root != NULL, NULL); if (root->tag != TAG_UAFV1_REG_ASSERTION) { + SAFE_DELETE(root->val); SAFE_DELETE(root); return NULL; } diff --git a/common/uafv1tlvutil/src/RegReqTlvEncoder.cpp b/common/uafv1tlvutil/src/RegReqTlvEncoder.cpp index 0f7b4c2..3226efd 100644 --- a/common/uafv1tlvutil/src/RegReqTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/RegReqTlvEncoder.cpp @@ -88,6 +88,7 @@ RegAssertionTlvEncoder::decode(const unsigned char *rawData) tlv_s* root = tlv_decode(rawData); RET_IF_FAIL(root != NULL, NULL); if (root->tag != TAG_UAFV1_REGISTER_CMD) { + SAFE_DELETE(root->val); SAFE_DELETE(root); return NULL; } diff --git a/common/uafv1tlvutil/src/RegRespTlvEncoder.cpp b/common/uafv1tlvutil/src/RegRespTlvEncoder.cpp index a72c8a4..ef1322e 100644 --- a/common/uafv1tlvutil/src/RegRespTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/RegRespTlvEncoder.cpp @@ -74,6 +74,7 @@ RegRespTlvEncoder::decode(const unsigned char *rawData) tlv_s *root = tlv_decode(rawData); RET_IF_FAIL(root != NULL, NULL); if (root->tag != TAG_UAFV1_REGISTER_CMD_RESPONSE) { + SAFE_DELETE(root->val); SAFE_DELETE(root); return NULL; } diff --git a/common/uafv1tlvutil/src/SignAuthAssertionTlvEncoder.cpp b/common/uafv1tlvutil/src/SignAuthAssertionTlvEncoder.cpp index cb08bcf..1032219 100644 --- a/common/uafv1tlvutil/src/SignAuthAssertionTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/SignAuthAssertionTlvEncoder.cpp @@ -53,6 +53,7 @@ SignAuthAssertionTlvEncoder::encode(const void *authData) tlv_builder_add_buffer(builder, TAG_UAFV1_SIGNED_DATA, getSigDataBuff); SAFE_DELETE(getSigDataBuff); + SAFE_DELETE(getSigDataInfoTlv); /*1.2 end*/ } @@ -78,7 +79,11 @@ SignAuthAssertionTlvEncoder::decode(const unsigned char *rawData) tlv_s *root = tlv_decode(rawData); RET_IF_FAIL(root != NULL, NULL); - RET_IF_FAIL(root->tag == TAG_UAFV1_AUTH_ASSERTION, NULL); + if (root->tag != TAG_UAFV1_AUTH_ASSERTION) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + return NULL; + } int rawIter = 2 + 2; AuthAssertion *getAuthAssInfo = ALLOC(AuthAssertion); diff --git a/common/uafv1tlvutil/src/SignReqTlvEncoder.cpp b/common/uafv1tlvutil/src/SignReqTlvEncoder.cpp index 42c6de3..65c82fe 100644 --- a/common/uafv1tlvutil/src/SignReqTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/SignReqTlvEncoder.cpp @@ -100,7 +100,11 @@ SignReqTlvEncoder::decode(const unsigned char *rawData) tlv_s *root = tlv_decode(rawData); RET_IF_FAIL(root != NULL, NULL); - RET_IF_FAIL(root->tag == TAG_UAFV1_SIGN_CMD, NULL); + if (root->tag != TAG_UAFV1_SIGN_CMD) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + return NULL; + } int rawIter = 2 + 2; int endIter = rawIter + root->len; diff --git a/common/uafv1tlvutil/src/Uafv1KrdTlvEncoder.cpp b/common/uafv1tlvutil/src/Uafv1KrdTlvEncoder.cpp index e040fae..d70db73 100644 --- a/common/uafv1tlvutil/src/Uafv1KrdTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/Uafv1KrdTlvEncoder.cpp @@ -89,7 +89,11 @@ Uafv1KrdTlvEncoder::decode(const unsigned char *rawData) tlv_s* root = tlv_decode(rawData); RET_IF_FAIL(root != NULL, NULL); - RET_IF_FAIL(root->tag == TAG_UAFV1_KRD, NULL); + if (root->tag != TAG_UAFV1_KRD) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + return NULL; + } int rawIter = 2 + 2; int endIter = rawIter + root->len; diff --git a/common/uiutil/src/PinAuthUiAdaptor.cpp b/common/uiutil/src/PinAuthUiAdaptor.cpp index f8c436c..38f0d62 100644 --- a/common/uiutil/src/PinAuthUiAdaptor.cpp +++ b/common/uiutil/src/PinAuthUiAdaptor.cpp @@ -105,7 +105,6 @@ PinAuthUiAdaptor::getTokenFromUi(pin_auth_mode_e type, const std::string& appId, for (int i = 0; i < 10; i++) { uiPid = aul_launch_app_for_uid(ASM_UI_APP_NAME, b, OWNER_UID); _INFO("aul_launch_app = [%d]", uiPid); - bundle_free(b); if (uiPid < 0) { if (uiPid == AUL_R_EINVAL) _INFO("AUL_R_EINVAL"); @@ -122,6 +121,8 @@ PinAuthUiAdaptor::getTokenFromUi(pin_auth_mode_e type, const std::string& appId, } } + bundle_free(b); + if (uiPid < 0) { *err = -1; return ""; -- 2.7.4 From 5117c9eebb22663eab9c7f8dc879250cba91ea9a Mon Sep 17 00:00:00 2001 From: Manasij Sur Roy Date: Wed, 17 May 2017 10:34:22 +0530 Subject: [PATCH 07/16] SVACE issue fix Change-Id: I7f25c8ee5e4455db7e76ecee5e74a0a85fd8d751 Signed-off-by: Manasij Sur Roy --- common/uafv1tlvutil/src/GetInfoRespTlvEncoder.cpp | 16 ++++++++++++++++ common/uafv1tlvutil/src/SignedDataTlvEncoder.cpp | 2 +- common/uafv1tlvutil/src/Uafv1KrdTlvEncoder.cpp | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/common/uafv1tlvutil/src/GetInfoRespTlvEncoder.cpp b/common/uafv1tlvutil/src/GetInfoRespTlvEncoder.cpp index 132a586..10d3983 100644 --- a/common/uafv1tlvutil/src/GetInfoRespTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/GetInfoRespTlvEncoder.cpp @@ -463,8 +463,16 @@ AuthInfoTlvEncoder::decode(const unsigned char *rawData) SAFE_DELETE(child); child = tlv_decode(rawData + rawIter); + if (child == NULL) { + SAFE_DELETE(tlv->val); + SAFE_DELETE(tlv); + SAFE_DELETE(authInfo); + + return NULL; + } } + SAFE_DELETE(child->val); SAFE_DELETE(child); SAFE_DELETE(tlv->val); SAFE_DELETE(tlv); @@ -648,6 +656,7 @@ GetInfoRespTlvEncoder::decode(const unsigned char *rawData) tlv_s *child = tlv_decode(rawData + rawIter); if (child == NULL) { + SAFE_DELETE(root->val); SAFE_DELETE(root); return NULL; } @@ -692,6 +701,13 @@ GetInfoRespTlvEncoder::decode(const unsigned char *rawData) SAFE_DELETE(child->val); SAFE_DELETE(child); child = tlv_decode(rawData + rawIter); + if (child == NULL) { + SAFE_DELETE(root->val); + SAFE_DELETE(root); + SAFE_DELETE(getInfoResp); + + return NULL; + } } SAFE_DELETE(child->val); diff --git a/common/uafv1tlvutil/src/SignedDataTlvEncoder.cpp b/common/uafv1tlvutil/src/SignedDataTlvEncoder.cpp index 94829f0..528cd27 100644 --- a/common/uafv1tlvutil/src/SignedDataTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/SignedDataTlvEncoder.cpp @@ -90,7 +90,7 @@ SignedDataTlvEncoder::decode(const unsigned char *rawData) RET_IF_FAIL(rawData != NULL, NULL); tlv_s *root = tlv_decode(rawData); - RET_IF_FAIL(rawData != NULL, NULL); + RET_IF_FAIL(root != NULL, NULL); int rawIter = 2 + 2; int endIter = rawIter + root->len; diff --git a/common/uafv1tlvutil/src/Uafv1KrdTlvEncoder.cpp b/common/uafv1tlvutil/src/Uafv1KrdTlvEncoder.cpp index d70db73..0f8640e 100644 --- a/common/uafv1tlvutil/src/Uafv1KrdTlvEncoder.cpp +++ b/common/uafv1tlvutil/src/Uafv1KrdTlvEncoder.cpp @@ -103,6 +103,7 @@ Uafv1KrdTlvEncoder::decode(const unsigned char *rawData) tlv_s *child = tlv_decode(rawData + rawIter); if (child == NULL) { free(getKrdInfo); + SAFE_DELETE(root->val); SAFE_DELETE(root); return NULL; } -- 2.7.4 From 15352499792177be948da246cac4f5bf673dbede Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Fri, 2 Jun 2017 08:20:54 +0900 Subject: [PATCH 08/16] Remove deprecated D-bus smack policies Change-Id: I1866a86eab06d7131ef7fdef9bb00b9cfdd40b69 --- packaging/org.tizen.fido-asm.conf | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/packaging/org.tizen.fido-asm.conf b/packaging/org.tizen.fido-asm.conf index 5a5fb04..d7b8b47 100644 --- a/packaging/org.tizen.fido-asm.conf +++ b/packaging/org.tizen.fido-asm.conf @@ -7,18 +7,6 @@ - - - - - - - - - - - - -- 2.7.4 From fb8ffabc2d9465d9da4c0de2192462591dc4bfdb Mon Sep 17 00:00:00 2001 From: jkjo92 Date: Mon, 12 Jun 2017 20:43:29 +0900 Subject: [PATCH 09/16] Changed to non-root deamon Change-Id: Ic8456a3eec8eb8bf95364318d70efb8eb1f50fc4 Signed-off-by: jkjo92 --- packaging/fido-asm.service | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packaging/fido-asm.service b/packaging/fido-asm.service index 132bf2a..4e34663 100644 --- a/packaging/fido-asm.service +++ b/packaging/fido-asm.service @@ -8,3 +8,6 @@ ExecStart=/usr/bin/fido-asm [Install] WantedBy=multi-user.target + +User=service_fw +Group=service_fw -- 2.7.4 From 5efdadd345418819f01d1a387c240367d85e0d3e Mon Sep 17 00:00:00 2001 From: Manasij Sur Roy Date: Fri, 16 Jun 2017 17:07:38 +0530 Subject: [PATCH 10/16] Added missing title and description support Change-Id: I68e3004a330d7bbb217df168f4360aac377e9001 Signed-off-by: Manasij Sur Roy --- server/auth_discovery/src/BAuthStub.cpp | 4 ++-- silent_auth/silent_auth_entry.cpp | 16 ++++++++++++++++ silent_auth/silent_auth_entry.h | 5 +++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/server/auth_discovery/src/BAuthStub.cpp b/server/auth_discovery/src/BAuthStub.cpp index a4eb035..88bc19d 100644 --- a/server/auth_discovery/src/BAuthStub.cpp +++ b/server/auth_discovery/src/BAuthStub.cpp @@ -79,8 +79,8 @@ BAuthStub::getInfo(void) /*Fill-up additional data*/ __cachedData->attach_hint = ATTACHMENT_HINT_INTERNAL; /*__cachedData->attach_hint = __pluginHandle->conn->attach_hint();*/ - /*__cachedData->title = __pluginHandle->conn->title();*/ - /*__cachedData->description = __pluginHandle->conn->description();*/ + __cachedData->title = __pluginHandle->conn->title(); + __cachedData->description = __pluginHandle->conn->description(); } /*Resetting fields altered during last RA operation*/ diff --git a/silent_auth/silent_auth_entry.cpp b/silent_auth/silent_auth_entry.cpp index ac23823..ac3718f 100644 --- a/silent_auth/silent_auth_entry.cpp +++ b/silent_auth/silent_auth_entry.cpp @@ -1114,6 +1114,22 @@ fido_auth_plugin_de_init(void) return 0; } +EXPORT_API char * +fido_auth_plugin_get_title(void) +{ + char *title = (char *)calloc(128, sizeof(char)); + snprintf(title, 128 - 1, "%s", "Tizen FIDO Authenticator"); + return title; +} + +EXPORT_API char * +fido_auth_plugin_get_description(void) +{ + char *desc = (char *)calloc(128, sizeof(char)); + snprintf(desc, 128 - 1, "%s", "Tizen FIDO PIN Authenticator"); + return desc; +} + /*int fido_auth_plugin_get_assertion_scheme(char **scheme); unsigned char* fido_auth_plugin_encode_assertion(int tag, const void *data); void* fido_auth_plugin_decode_assertion(int tag, unsigned char *assrt);*/ diff --git a/silent_auth/silent_auth_entry.h b/silent_auth/silent_auth_entry.h index 3c65036..3486943 100644 --- a/silent_auth/silent_auth_entry.h +++ b/silent_auth/silent_auth_entry.h @@ -29,6 +29,11 @@ fido_auth_plugin_is_connected(void); EXPORT_API int fido_auth_plugin_de_init(void); +EXPORT_API char * +fido_auth_plugin_get_title(void); + +EXPORT_API char * +fido_auth_plugin_get_description(void); //int fido_auth_plugin_get_assertion_scheme(char **scheme); //unsigned char* fido_auth_plugin_encode_assertion(int tag, const void *data); //void* fido_auth_plugin_decode_assertion(int tag, unsigned char *assrt); -- 2.7.4 From 2649ce10558f2f0eb80f4f7f8469c0788f58c7d9 Mon Sep 17 00:00:00 2001 From: Manasij Sur Roy Date: Mon, 19 Jun 2017 13:22:27 +0530 Subject: [PATCH 11/16] KONA reported issues fixed, removed unused components Change-Id: Ic063876bb15268eceb837e646a2f8067612617a0 Signed-off-by: Manasij Sur Roy --- CMakeLists.txt | 6 - ble_roaming_agent/CMakeLists.txt | 45 --- ble_roaming_agent/inc/BTRoamingKeys.h | 18 - ble_roaming_agent/src/bt_ragent_main.c | 41 --- ble_roaming_agent/src/fido_gatt_server.c | 312 ----------------- ble_roaming_agent/src/fido_gatt_server.h | 9 - bt_roaming_agent/src/bt_server.c | 2 + common/cryptoutil/src/AsmCrypto.cpp | 13 + fido-ble-ragent.manifest | 5 - packaging/fido-asm.spec | 68 ---- roaming_agent/CMakeLists.txt | 47 --- roaming_agent/inc/RoamingKeys.h | 16 - roaming_agent/src/iotcon_handler.c | 504 ---------------------------- roaming_agent/src/iotcon_handler.h | 15 - roaming_agent/src/ragent_main.c | 43 --- server/CMakeLists.txt | 1 - server/auth_discovery/inc/BleAdProvider.h | 39 --- server/auth_discovery/inc/BleCon.h | 48 --- server/auth_discovery/inc/BtAdProvider.h | 1 + server/auth_discovery/inc/IoTCon.h | 28 -- server/auth_discovery/inc/IotADProvider.h | 57 ---- server/auth_discovery/inc/RoamingUtil.h | 4 - server/auth_discovery/src/AuthManager.cpp | 25 -- server/auth_discovery/src/BleAdProvider.cpp | 415 ----------------------- server/auth_discovery/src/BleCon.cpp | 106 ------ server/auth_discovery/src/BtADProvider.cpp | 12 +- server/auth_discovery/src/BtCon.cpp | 1 - server/auth_discovery/src/IoTCon.cpp | 121 ------- server/auth_discovery/src/IotADProvider.cpp | 217 ------------ server/auth_discovery/src/RAuthStub.cpp | 1 - server/auth_discovery/src/RoamingUtil.cpp | 66 ---- 31 files changed, 23 insertions(+), 2263 deletions(-) delete mode 100644 ble_roaming_agent/CMakeLists.txt delete mode 100644 ble_roaming_agent/inc/BTRoamingKeys.h delete mode 100644 ble_roaming_agent/src/bt_ragent_main.c delete mode 100644 ble_roaming_agent/src/fido_gatt_server.c delete mode 100644 ble_roaming_agent/src/fido_gatt_server.h delete mode 100644 fido-ble-ragent.manifest delete mode 100644 roaming_agent/CMakeLists.txt delete mode 100644 roaming_agent/inc/RoamingKeys.h delete mode 100644 roaming_agent/src/iotcon_handler.c delete mode 100644 roaming_agent/src/iotcon_handler.h delete mode 100644 roaming_agent/src/ragent_main.c delete mode 100644 server/auth_discovery/inc/BleAdProvider.h delete mode 100644 server/auth_discovery/inc/BleCon.h delete mode 100644 server/auth_discovery/inc/IoTCon.h delete mode 100644 server/auth_discovery/inc/IotADProvider.h delete mode 100644 server/auth_discovery/src/BleAdProvider.cpp delete mode 100644 server/auth_discovery/src/BleCon.cpp delete mode 100644 server/auth_discovery/src/IoTCon.cpp delete mode 100644 server/auth_discovery/src/IotADProvider.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1aabe10..1807ca2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,17 +5,11 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(EXEC_PREFIX "\${prefix}") SET(INCLUDEDIR "\${prefix}/include ") -##ADD_SUBDIRECTORY(common) ADD_SUBDIRECTORY(server) -##ADD_SUBDIRECTORY(test/shell_tc) ADD_SUBDIRECTORY(silent_auth) ADD_SUBDIRECTORY(ui) -ADD_SUBDIRECTORY(roaming_agent) ADD_SUBDIRECTORY(common/dbus_interfaces) ADD_SUBDIRECTORY(bt_roaming_agent) -##ADD_SUBDIRECTORY(ble_roaming_agent) ADD_DEPENDENCIES(fido-asm fido-asm-dbus) ADD_DEPENDENCIES(fido-bt-ragent-service fido-asm-dbus) -##ADD_DEPENDENCIES(fido-ble-ragent-service fido-asm-dbus) -ADD_DEPENDENCIES(fido-roaming-agent-service fido-asm-dbus) ADD_DEPENDENCIES(asmui fido-asm-dbus) diff --git a/ble_roaming_agent/CMakeLists.txt b/ble_roaming_agent/CMakeLists.txt deleted file mode 100644 index f11cdcd..0000000 --- a/ble_roaming_agent/CMakeLists.txt +++ /dev/null @@ -1,45 +0,0 @@ -SET(BLE_RAGENT_DAEMON fido-ble-ragent-service) - -INCLUDE(FindPkgConfig) -pkg_check_modules(BLE_RAGENT_DAEMON_PKGS REQUIRED - dlog - glib-2.0 - capi-base-common - pkgmgr-info - gio-2.0 - gio-unix-2.0 - gmodule-2.0 - cynara-client - cynara-session - cynara-creds-gdbus - capi-network-connection - capi-base-common - capi-appfw-application - capi-appfw-app-manager - aul - json-glib-1.0 - capi-system-info - capi-system-system-settings - capi-network-bluetooth -) - -FOREACH(flag ${BLE_RAGENT_DAEMON_PKGS_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") -ENDFOREACH(flag) - -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE") -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS}") -SET(PKGS_LDFLAGS "${BLE_RAGENT_DAEMON_PKGS_LDFLAGS} -pie") - -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common) -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/ble_roaming_agent/inc/) - -FILE( GLOB BLE_RAGENT_DAEMON_SRCS_CC - src/*.c -) - -ADD_EXECUTABLE(${BLE_RAGENT_DAEMON} ${BLE_RAGENT_DAEMON_SRCS_CC}) - -TARGET_LINK_LIBRARIES(${BLE_RAGENT_DAEMON} ${BLE_RAGENT_DAEMON_PKGS_LDFLAGS} fido-asm-dbus "-ldl") - -INSTALL(TARGETS ${BLE_RAGENT_DAEMON} DESTINATION bin) diff --git a/ble_roaming_agent/inc/BTRoamingKeys.h b/ble_roaming_agent/inc/BTRoamingKeys.h deleted file mode 100644 index 5c066b8..0000000 --- a/ble_roaming_agent/inc/BTRoamingKeys.h +++ /dev/null @@ -1,18 +0,0 @@ -#include - -#ifndef _BT_ROAMINGKEYS_H -#define _BT_ROAMINGKEYS_H - -#define RA_BLE_FRAME_MAX_SIZE 20 -/*TODO: Change to some other uids*/ -#define RA_BLE_ADVERTISING_UUID "89D3502B-0F36-433A-8EF4-C502AD55F8DC" -#define RA_BLE_SERVICE_UUID "89D3502B-0F36-433A-8EF4-C502AD55F8DC" -#define RA_BLE_UUID_REQUEST "9B3C81D8-57B1-4A8A-B8DF-0E56F7CA51C2" -#define RA_BLE_UUID_RESPONSE "2F7CABCE-808D-411F-9A0C-BB92BA96C102" -#define RA_BLE_SERVICE_REVISION "1.0" -#define RA_BLE_FRAME_MAX_SIZE 20 -#define RA_BLE_DATA_MAX_SIZE 65536 - -#define BT_DISC_TIMEOUT_SEC 5 - -#endif // _BT_ROAMINGKEYS_H diff --git a/ble_roaming_agent/src/bt_ragent_main.c b/ble_roaming_agent/src/bt_ragent_main.c deleted file mode 100644 index 01f52f4..0000000 --- a/ble_roaming_agent/src/bt_ragent_main.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2014 - 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. - * - */ - -#include -#include - -#include "fido_gatt_server.h" -#include "AsmHelper.h" - -int -main(int argc, char *argv[]) -{ - _INFO("Starting BT Roaming Agent Service"); - - GMainLoop *mainloop = g_main_loop_new(NULL, FALSE); - - int ret = fido_gatt_server_init(); - _INFO("fido_gatt_server_init=[%d]", ret); - - g_main_loop_run(mainloop); - - _INFO("Stopping BT Roaming Agent Service"); - ret = fido_gatt_server_shutdown(); - _INFO("[%d]", ret); - - return 0; -} diff --git a/ble_roaming_agent/src/fido_gatt_server.c b/ble_roaming_agent/src/fido_gatt_server.c deleted file mode 100644 index d53328e..0000000 --- a/ble_roaming_agent/src/fido_gatt_server.c +++ /dev/null @@ -1,312 +0,0 @@ - -#include -#include -#include -#include - -#include - -#include "fido_gatt_server.h" -#include "BTRoamingKeys.h" -#include "AsmHelper.h" -#include "fido-client-ipc-stub.h" - -#include -#include -#include -#include - -static bool __isStarted = false; - -static Fidoasm* -__asm_get_dbus_proxy(void) -{ -#if !GLIB_CHECK_VERSION(2, 35, 0) - g_type_init(); -#endif - - GDBusConnection *connection = NULL; - GError *error = NULL; - - connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - - /* Create the object */ - Fidoasm *dbus_proxy = fidoasm_proxy_new_sync(connection, - G_DBUS_PROXY_FLAGS_NONE, - "org.tizen.fidoasm", - "/org/tizen/fidoasm", - NULL, - &error); - - if (error != NULL) - _ERR("bluetooth fidoasm_proxy_new_sync failed %s", error->message); - - return dbus_proxy; -} - -static void -__ra_notify_cb(int result, const char *remote_address, bt_gatt_server_h server, - bt_gatt_h characteristic, bool completed, void *user_data) -{ - _INFO("bluetooth ragent __ra_notify_cb=[%d]", result); -} - -static void -__ra__write_value_requested_cb(const char *remote_address, int request_id, bt_gatt_server_h server, - bt_gatt_h gatt_handle, int offset, - const char *value, int len, void *user_data) -{ - _INFO("bluetooth ragent __ra__write_value_requested_cb=[%s]", value); - - /*Call ASM dbus and receive the response*/ - Fidoasm *asm_proxy = __asm_get_dbus_proxy(); - if (asm_proxy == NULL) { - _ERR("bluetooth Failed to get ASM proxy"); - bt_gatt_server_send_response(request_id, BT_GATT_REQUEST_TYPE_WRITE, - offset, -1, NULL, 0); - return; - } - - - const char *tlvReqB64 = value; - char *tlvRespB64 = NULL; - GError *gErr = NULL; - int tz_err = 0; - fidoasm_call_asm_request_sync(asm_proxy, tlvReqB64, - &tz_err, &tlvRespB64, NULL, &gErr); - if (gErr != NULL) { - - bt_gatt_server_send_response(request_id, BT_GATT_REQUEST_TYPE_WRITE, - offset, -1, NULL, 0); - _ERR("bluetooth Failed returned from ASM"); - return; - } - - int ret = bt_gatt_set_value(gatt_handle, tlvRespB64, strlen(tlvRespB64)); - _INFO("bluetooth ragent bt_gatt_set_value=[%d]", ret); - - bt_gatt_server_send_response(request_id, BT_GATT_REQUEST_TYPE_WRITE, offset, 0, NULL, 0); - - ret = bt_gatt_server_notify_characteristic_changed_value(gatt_handle, __ra_notify_cb, remote_address, NULL); - _INFO("bluetooth ragent bt_gatt_server_notify_characteristic_changed_value=[%d]", ret); -} - -static void -__advertising_state_changed_cb(int result, bt_advertiser_h advertiser, - bt_adapter_le_advertising_state_e adv_state, void* user_data) -{ - _INFO("bluetooth ragent __advertising_state_changed_cb=[%d]", adv_state); -} - -#define MAX_BLE_SIZE 1024 - -static void -onGattConchanged(int result, bool connected, const char *remote_address, void *user_data) -{ - _INFO("remote_address=[%s]", remote_address); - _INFO("connected=[%d]", connected); - _INFO("[%d]", result); -} - -static int -__fido_gatt_server_start(void) -{ - _INFO("bluetooth Request to start GATT server"); - - if (__isStarted == true) { - _INFO("bluetooth Already started"); - return 0; - } - - _INFO("bluetooth New GATT server"); - __isStarted = true; - - bt_gatt_set_connection_state_changed_cb(onGattConchanged, NULL); - - int ret = BT_ERROR_NONE; - bt_gatt_server_h server = NULL; - bt_gatt_h service = NULL; - bt_gatt_h ctrl_pt_write_req = NULL; - bt_gatt_h ctrl_pt_notif_resp = NULL; - int permissions = BT_GATT_PERMISSION_READ | BT_GATT_PERMISSION_WRITE; - - /*Notification enabled */ - char *reqVal = (char*)calloc(MAX_BLE_SIZE, sizeof(char)); - char *respVal = (char*)calloc(MAX_BLE_SIZE, sizeof(char)); - - ret = bt_gatt_server_initialize(); - if (ret != BT_ERROR_NONE) { - _ERR("bluetooth ragent bt_gatt_server_initialize=[%d]", ret); - goto FAIL; - } - - ret = bt_gatt_server_create(&server); - if (ret != BT_ERROR_NONE) { - _ERR("bluetooth ragent bt_gatt_server_create=[%d]", ret); - goto FAIL; - } - - _INFO("bluetooth ragent gatt service create"); - ret = bt_gatt_service_create(RA_BLE_SERVICE_UUID, BT_GATT_SERVICE_TYPE_PRIMARY, &service); - if (ret != BT_ERROR_NONE) - goto FAIL; - - _INFO("bluetooth ragent Create GATT Characteristic"); - /* Create GATT Characteristic */ - ret = bt_gatt_characteristic_create(RA_BLE_UUID_REQUEST, - permissions, - BT_GATT_PROPERTY_WRITE, - reqVal, - MAX_BLE_SIZE, - &ctrl_pt_write_req); - if (ret != BT_ERROR_NONE) - goto FAIL; - - ret = bt_gatt_characteristic_create(RA_BLE_UUID_RESPONSE, - permissions, - BT_GATT_PROPERTY_NOTIFY, - respVal, - MAX_BLE_SIZE, - &ctrl_pt_notif_resp); - - _INFO("bluetooth ragent set GATT Characterisitic Callback"); - - ret = bt_gatt_server_set_write_value_requested_cb(ctrl_pt_write_req, - __ra__write_value_requested_cb, NULL); - if (ret != BT_ERROR_NONE) - goto FAIL; - - _INFO("bluetooth ragent Add GATT Characteristic in service"); - /* add GATT Characteristic in service */ - ret = bt_gatt_service_add_characteristic(service, ctrl_pt_write_req); - if (ret != BT_ERROR_NONE) - goto FAIL; - - ret = bt_gatt_service_add_characteristic(service, ctrl_pt_notif_resp); - if (ret != BT_ERROR_NONE) - goto FAIL; - - _INFO("bluetooth ragent Register GATT Service"); - ret = bt_gatt_server_register_service(server, service); - if (ret != BT_ERROR_NONE) { - _INFO("bluetooth ragent can not register gatt service."); - goto FAIL; - } - - - _INFO("bluetooth ragent GATT Server Done"); - - ret = bt_gatt_server_start(); - if (ret != BT_ERROR_NONE) { - _INFO("bluetooth ragent bt_gatt_server_start failed = [%d]", ret); - goto FAIL; - } - - _INFO("bluetooth ragent GATT Server started"); - - _INFO("bluetooth ragent starting LE adv"); - bt_advertiser_h adv_handle = NULL; - ret = bt_adapter_le_create_advertiser(&adv_handle); - if (ret != BT_ERROR_NONE) { - _INFO("bluetooth ragent bt_adapter_le_create_advertiser failed = [%d]", ret); - goto FAIL; - } - - _INFO("bluetooth ragent after bt_adapter_le_create_advertiser"); - - ret = bt_adapter_le_set_advertising_connectable(adv_handle, true); - if (ret != BT_ERROR_NONE) { - _INFO("bluetooth ragent bt_adapter_le_set_advertising_connectable failed = [%d]", ret); - goto FAIL; - } - - _INFO("bluetooth ragent after bt_adapter_le_set_advertising_connectable"); - - ret = bt_adapter_le_add_advertising_service_uuid(adv_handle, - BT_ADAPTER_LE_PACKET_ADVERTISING, RA_BLE_ADVERTISING_UUID); - if (ret != BT_ERROR_NONE) { - _INFO("bluetooth ragent bt_adapter_le_add_advertising_service_uuid failed = [%d]", ret); - goto FAIL; - } - - _INFO("bluetooth ragent after bt_adapter_le_add_advertising_service_uuid"); - - ret = bt_adapter_le_set_advertising_device_name(adv_handle, - BT_ADAPTER_LE_PACKET_SCAN_RESPONSE, true); - if (ret != BT_ERROR_NONE) { - _INFO("bluetooth ragent bt_adapter_le_set_advertising_device_name failed = [%d]", ret); - goto FAIL; - } - - _INFO("bluetooth ragent after bt_adapter_le_set_advertising_device_name"); - - ret = bt_adapter_le_start_advertising_new(adv_handle, - __advertising_state_changed_cb, adv_handle); - if (ret != BT_ERROR_NONE) { - _INFO("bluetooth ragent bt_adapter_le_start_advertising_new failed = [%d]", ret); - goto FAIL; - } - - _INFO("bluetooth ragent LE adv done"); - return 0; - -FAIL: - _INFO("bluetooth ragent ERROR"); - bt_gatt_characteristic_destroy(ctrl_pt_write_req); - bt_gatt_characteristic_destroy(ctrl_pt_notif_resp); - bt_gatt_service_destroy(service); - bt_gatt_server_destroy(server); - - return -1; -} - -static int -__fido_gatt_server_stop(void) -{ - _INFO("bluetooth Stopping GATT server"); - __isStarted = false; - bt_gatt_server_deinitialize(); - return 0; -} - -static void -__bt_state_changed_cb(int result, bt_adapter_state_e adapter_state, void* user_data) -{ - _INFO("bluetooth __bt_state_changed_cb=[%d]", adapter_state); - if (adapter_state == BT_ADAPTER_ENABLED) { - __fido_gatt_server_start(); - } -} - -int -fido_gatt_server_shutdown(void) -{ - return __fido_gatt_server_stop(); -} - -int -fido_gatt_server_init(void) -{ - int ret = bt_initialize(); - if ((ret != BT_ERROR_NONE) && (ret != BT_ERROR_ALREADY_DONE)) { - _ERR("bluetooth bt_init failed = [%d]", ret); - return -1; - } - - __isStarted = false; - - bt_adapter_set_state_changed_cb(__bt_state_changed_cb, NULL); - - bt_adapter_state_e adapter_state = BT_ADAPTER_DISABLED; - ret = bt_adapter_get_state(&adapter_state); - if (ret != BT_ERROR_NONE) { - _ERR("bluetooth bt_adapter_get_state failed = [%d]", ret); - return -1; - } - - if (adapter_state == BT_ADAPTER_ENABLED) { - return __fido_gatt_server_start(); - } - - return 0; -} diff --git a/ble_roaming_agent/src/fido_gatt_server.h b/ble_roaming_agent/src/fido_gatt_server.h deleted file mode 100644 index b03954b..0000000 --- a/ble_roaming_agent/src/fido_gatt_server.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _FIDO_GATT_SERVER_H_ -#define _FIDO_GATT_SERVER_H_ - - -int fido_gatt_server_init(void); -int fido_gatt_server_shutdown(void); - - -#endif /* _FIDO_GATT_SERVER_H_ */ diff --git a/bt_roaming_agent/src/bt_server.c b/bt_roaming_agent/src/bt_server.c index ce0ed1a..0154dd6 100644 --- a/bt_roaming_agent/src/bt_server.c +++ b/bt_roaming_agent/src/bt_server.c @@ -503,5 +503,7 @@ bt_server_stop(void) bt_socket_destroy_rfcomm(server->server_socket_fd); __destroy_server_handle(server); server = NULL; + int ret = bt_deinitialize(); + _INFO("bt_deinitialize=[%d]", ret); return 0; } diff --git a/common/cryptoutil/src/AsmCrypto.cpp b/common/cryptoutil/src/AsmCrypto.cpp index c42d9cb..24eb33d 100644 --- a/common/cryptoutil/src/AsmCrypto.cpp +++ b/common/cryptoutil/src/AsmCrypto.cpp @@ -156,6 +156,8 @@ AsmCrypto::getAsmToken(void) _INFO("%s", macStr.c_str()); asmTok = strdup(macClone); SAFE_DELETE(macClone); + + bt_deinitialize(); return macStr; } } else { @@ -172,6 +174,8 @@ AsmCrypto::getAsmToken(void) _INFO("%s", macStr.c_str()); asmTok = strdup(macClone); SAFE_DELETE(macClone); + + bt_deinitialize(); return macStr; } @@ -214,6 +218,7 @@ AsmCrypto::getAsmToken(void) asmTok = strdup(mac); SAFE_DELETE(mac); + bt_deinitialize(); return tok; } else { @@ -222,11 +227,15 @@ AsmCrypto::getAsmToken(void) if (size <= 0) { fclose(file); _END; + + bt_deinitialize(); return std::string(); } else if (size > 1000) { _ERR("Too big config file, size=[%d], allowed=[1000]", size); fclose(file); _END; + + bt_deinitialize(); return std::string(); } @@ -238,6 +247,8 @@ AsmCrypto::getAsmToken(void) free(config); fclose(file); _END; + + bt_deinitialize(); return std::string(); } @@ -249,6 +260,8 @@ AsmCrypto::getAsmToken(void) _END; asmTok = strdup(config); SAFE_DELETE(config); + + bt_deinitialize(); return tok; } } diff --git a/fido-ble-ragent.manifest b/fido-ble-ragent.manifest deleted file mode 100644 index 97e8c31..0000000 --- a/fido-ble-ragent.manifest +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/packaging/fido-asm.spec b/packaging/fido-asm.spec index 83ef1df..d327014 100644 --- a/packaging/fido-asm.spec +++ b/packaging/fido-asm.spec @@ -9,8 +9,6 @@ Source0: fido-asm-%{version}.tar.gz Source1: org.tizen.fido-asm.service Source2: org.tizen.fido-asm.conf Source3: fido-asm.service -Source4: fido-roaming-agent.service -##Source5: fido-ble-roaming-agent.service Source6: fido-bt-roaming-agent.service BuildRequires: cmake @@ -91,10 +89,6 @@ install -m 644 %SOURCE3 %{buildroot}%{_unitdir}/fido-asm.service mkdir -p %{buildroot}%{_libdir}/fido/asm/auth mkdir -p %{buildroot}%{_unitdir}/multi-user.target.wants -install -m 0644 %SOURCE4 %{buildroot}%{_unitdir}/fido-roaming-agent.service -%install_service multi-user.target.wants fido-roaming-agent.service - -mkdir -p %{buildroot}%{_unitdir}/multi-user.target.wants install -m 0644 %SOURCE6 %{buildroot}%{_unitdir}/fido-bt-roaming-agent.service %install_service multi-user.target.wants fido-bt-roaming-agent.service @@ -261,68 +255,6 @@ rm -r /opt/usr/data/silent_auth/ /opt/usr/data/silent_auth/fido_tizen_auth.key ################################################################################# -# FIDO IoT Roaming Agent -################################################################################# -%package -n fido_roaming_agent -Summary: FIDO Roaming Agent -Group: Account - -BuildRequires: cmake -BuildRequires: pkgconfig(capi-appfw-application) -BuildRequires: pkgconfig(dlog) -BuildRequires: pkgconfig(bundle) -BuildRequires: pkgconfig(json-glib-1.0) -BuildRequires: pkgconfig(glib-2.0) >= 2.26 -BuildRequires: pkgconfig(gio-unix-2.0) -BuildRequires: pkgconfig(capi-network-connection) - - -%description -n fido_roaming_agent -FIDO Roaming Agent IoTivity Server - -%post -n fido_roaming_agent -mkdir -p /opt/data/fido-ra/ -chown -R service_fw:service_fw /opt/data/fido-ra/ -chsmack -a '_' /opt/data/fido-ra/ - -chown -R service_fw:service_fw /opt/data/fido-ra/*.dat -chsmack -a '_' /opt/data/fido-ra/*.dat - -%files -n fido_roaming_agent -%manifest fido-roaming-agent.manifest -%{_bindir}/* -%{_unitdir}/fido-roaming-agent.service -%{_unitdir}/multi-user.target.wants/fido-roaming-agent.service -%attr(0777,service_fw,service_fw)/opt/data/fido-ra/*.dat - -################################################################################# -# FIDO BLE Roaming Agent -################################################################################# -##%package -n fido_ble_roaming_agent -##Summary: FIDO BLE Roaming Agent -##Group: Account - -##BuildRequires: cmake -##BuildRequires: pkgconfig(capi-appfw-application) -##BuildRequires: pkgconfig(dlog) -##BuildRequires: pkgconfig(bundle) -##BuildRequires: pkgconfig(json-glib-1.0) -##BuildRequires: pkgconfig(glib-2.0) >= 2.26 -##BuildRequires: pkgconfig(gio-unix-2.0) -##BuildRequires: pkgconfig(capi-network-connection) -##BuildRequires: pkgconfig(capi-network-bluetooth) - - -##%description -n fido_ble_roaming_agent -##FIDO BT Roaming Agent GATT Server - -##%files -n fido_ble_roaming_agent -##%manifest fido-ble-ragent.manifest -##%{_bindir}/fido-ble-ragent-service -##%{_unitdir}/fido-ble-roaming-agent.service -##%{_unitdir}/multi-user.target.wants/fido-ble-roaming-agent.service - -################################################################################# # FIDO BT Roaming Agent ################################################################################# %package -n fido_bt_roaming_agent diff --git a/roaming_agent/CMakeLists.txt b/roaming_agent/CMakeLists.txt deleted file mode 100644 index 3039ec9..0000000 --- a/roaming_agent/CMakeLists.txt +++ /dev/null @@ -1,47 +0,0 @@ -SET(RAGENT_DAEMON fido-roaming-agent-service) - -INCLUDE(FindPkgConfig) -pkg_check_modules(RAGENT_DAEMON_PKGS REQUIRED - dlog - db-util - glib-2.0 - capi-base-common - pkgmgr-info - gio-2.0 - gio-unix-2.0 - gmodule-2.0 - cynara-client - cynara-session - cynara-creds-gdbus - capi-network-connection - capi-base-common - capi-appfw-application - capi-appfw-app-manager - aul - json-glib-1.0 - iotcon - capi-system-info - capi-system-system-settings -) - -FOREACH(flag ${RAGENT_DAEMON_PKGS_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") -ENDFOREACH(flag) - -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE") -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS}") -SET(PKGS_LDFLAGS "${RAGENT_DAEMON_PKGS_LDFLAGS} -pie") - -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common) -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/roaming_agent/inc/) - -FILE( GLOB RAGENT_DAEMON_SRCS_CC - src/*.c -) - -ADD_EXECUTABLE(${RAGENT_DAEMON} ${RAGENT_DAEMON_SRCS_CC}) - -TARGET_LINK_LIBRARIES(${RAGENT_DAEMON} ${RAGENT_DAEMON_PKGS_LDFLAGS} fido-asm-dbus "-ldl") - -INSTALL(TARGETS ${RAGENT_DAEMON} DESTINATION bin) -INSTALL(FILES ${CMAKE_SOURCE_DIR}/common/fido-ra-acl-server.dat DESTINATION /opt/data/fido-ra) diff --git a/roaming_agent/inc/RoamingKeys.h b/roaming_agent/inc/RoamingKeys.h deleted file mode 100644 index 3b23bf9..0000000 --- a/roaming_agent/inc/RoamingKeys.h +++ /dev/null @@ -1,16 +0,0 @@ -#include - -#ifndef ROAMINGKEYS_H -#define ROAMINGKEYS_H - -#define RA_RESOURCE_URI "/fido/auth/roaming/pin" -#define RA_RESOURCE_TYPE "org.tizen.fidoauthroamingpin" - -#define RA_QUERY_KEY_REQUEST "ra_query_prcoess_tlv" -#define RA_QUERY_KEY_SERVER_ID "ra_query_server_id" -#define RA_QUERY_KEY_RESPONSE "ra_response" - -#define RA_ACL_SERVER tzplatform_mkpath(TZ_SYS_DATA, "fido-ra/fido-ra-acl-server.dat") -#define RA_ACL_CLIENT tzplatform_mkpath(TZ_SYS_DATA, "fido-asm/fido-ra-acl-client.dat") - -#endif // ROAMINGKEYS_H diff --git a/roaming_agent/src/iotcon_handler.c b/roaming_agent/src/iotcon_handler.c deleted file mode 100644 index 1703d64..0000000 --- a/roaming_agent/src/iotcon_handler.c +++ /dev/null @@ -1,504 +0,0 @@ -/* - * iotcon_handler.c - * - * Created on: May 16, 2016 - * Author: manasij.r - */ - -#include -#include -#include -#include - -#include -#include - -#include "iotcon_handler.h" -#include "RoamingKeys.h" -#include "AsmHelper.h" -#include "fido-client-ipc-stub.h" - -#include -#include -#include - -#define IC_FEATURE_OIC "http://tizen.org/feature/iot.oic" -#define IC_FEATURE_OCF "http://tizen.org/feature/iot.ocf" - -#include - -//#define ASM_GET_INFO_RESP "{\"responseData\":{\"Authenticators\":[{\"aaid\":\"R001#8001\",\"asmVersions\":[{\"major\":1,\"minor\":0}],\"assertionScheme\":\"UAFV1TLV\",\"title\":\"UAF PIN Roaming\",\"attestationTypes\":[15879],\"tcDisplayContentType\":\"text/plain\",\"description\":\"Tizen Roaming PIN Authenticator\",\"supportedExtensionIDs\":[\"abc\"],\"icon\":\"data:image/png;base64,iVBORw0KGgoAAA\",\"isRoamingAuthenticator\":true,\"isSecondFactorOnly\":false,\"isUserEnrolled\":true,\"keyProtection\":1,\"matcherProtection\":1,\"hasSettings\":true,\"tcDisplay\":1,\"authenticatorIndex\":9,\"authenticationAlgorithm\":1,\"attachmentHint\":2,\"userVerification\":4}]},\"statusCode\":0}" - -/* ra Resource */ -typedef struct _ra_resource_s { - bool state; - char *uri_path; - char *type; - iotcon_resource_interfaces_h ifaces; - int properties; - iotcon_resource_h handle; - iotcon_observers_h observers; - iotcon_representation_h repr; -} ra_resource_s; - -static void _request_handler(iotcon_resource_h resource, iotcon_request_h request, - void *user_data); - -static Fidoasm* -__asm_get_dbus_proxy(void) -{ -#if !GLIB_CHECK_VERSION(2, 35, 0) - g_type_init(); -#endif - - GDBusConnection *connection = NULL; - GError *error = NULL; - - connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - - /* Create the object */ - Fidoasm *dbus_proxy = fidoasm_proxy_new_sync(connection, - G_DBUS_PROXY_FLAGS_NONE, - "org.tizen.fidoasm", - "/org/tizen/fidoasm", - NULL, - &error); - - if (error != NULL) - _ERR("fidoasm_proxy_new_sync failed %s", error->message); - - return dbus_proxy; -} - -static int -_set_ra_resource(ra_resource_s *ra) -{ - _INFO("_set_ra_resource"); - - int ret; - - ra->state = false; - - ra->uri_path = strdup(RA_RESOURCE_URI); - if (NULL == ra->uri_path) { - return -1; - } - - ra->type = strdup(RA_RESOURCE_TYPE); - if (NULL == ra->type) { - free(ra->uri_path); - return -1; - } - - ret = iotcon_resource_interfaces_create(&ra->ifaces); - if (IOTCON_ERROR_NONE != ret) { - free(ra->type); - free(ra->uri_path); - return -1; - } - - ret = iotcon_resource_interfaces_add(ra->ifaces, IOTCON_INTERFACE_DEFAULT); - if (IOTCON_ERROR_NONE != ret) { - iotcon_resource_interfaces_destroy(ra->ifaces); - free(ra->type); - free(ra->uri_path); - return -1; - } - - ra->properties = IOTCON_RESOURCE_DISCOVERABLE; - -// ret = iotcon_observers_create(&ra->observers); -// if (IOTCON_ERROR_NONE != ret) { -// iotcon_resource_interfaces_destroy(ra->ifaces); -// free(ra->type); -// free(ra->uri_path); -// return -1; -// } - - _INFO("_set_ra_resource end"); - - return 0; -} - -static void _free_ra_resource(ra_resource_s *ra) -{ - iotcon_observers_destroy(ra->observers); - iotcon_resource_interfaces_destroy(ra->ifaces); - free(ra->type); - free(ra->uri_path); -} - -static iotcon_resource_h -_create_ra_resource(char *uri_path, char *type, - iotcon_resource_interfaces_h ifaces, int properties, void *user_data) -{ - _INFO("_create_ra_resource start"); - - int ret; - iotcon_resource_h handle; - iotcon_resource_types_h resource_types; - - ret = iotcon_resource_types_create(&resource_types); - if (IOTCON_ERROR_NONE != ret) { - return NULL; - } - - ret = iotcon_resource_types_add(resource_types, type); - if (IOTCON_ERROR_NONE != ret) { - iotcon_resource_types_destroy(resource_types); - return NULL; - } - - /* register ra resource */ - ret = iotcon_resource_create(uri_path, resource_types, ifaces, properties, - _request_handler, user_data, &handle); - if (IOTCON_ERROR_NONE != ret) { - iotcon_resource_types_destroy(resource_types); - return NULL; - } - - iotcon_resource_types_destroy(resource_types); - - _INFO("_create_ra_resource end"); - - return handle; -} - -static int -_send_response(iotcon_request_h request, iotcon_representation_h repr, - iotcon_response_result_e result) -{ - _INFO("_send_response start"); - - int ret; - iotcon_response_h response; - - ret = iotcon_response_create(request, &response); - if (IOTCON_ERROR_NONE != ret) { - return -1; - } - - ret = iotcon_response_set_result(response, result); - if (IOTCON_ERROR_NONE != ret) { - iotcon_response_destroy(response); - return -1; - } - - ret = iotcon_response_set_representation(response, repr); - if (IOTCON_ERROR_NONE != ret) { - iotcon_response_destroy(response); - return -1; - } - - /* send Representation to the client */ - ret = iotcon_response_send(response); - if (IOTCON_ERROR_NONE != ret) { - iotcon_response_destroy(response); - return -1; - } - - iotcon_response_destroy(response); - - _INFO("_send_response end"); - - return 0; -} - -static iotcon_representation_h -_create_ra_representation(ra_resource_s *ra, char *tlvRespB64) -{ - _INFO("_get_ra_representation start"); - - int ret; - iotcon_attributes_h state = NULL; - iotcon_representation_h repr = NULL; - - /* create a ra Representation */ - ret = iotcon_representation_create(&repr); - if (IOTCON_ERROR_NONE != ret) { - return NULL; - } - - _INFO("After iotcon_representation_create"); - - /* create a ra state */ - ret = iotcon_attributes_create(&state); - if (IOTCON_ERROR_NONE != ret) { - iotcon_representation_destroy(repr); - return NULL; - } - - _INFO("After iotcon_attributes_create"); - - ret = iotcon_representation_set_uri_path(repr, RA_RESOURCE_URI/*ra->uri_path*/); - if (IOTCON_ERROR_NONE != ret) { - iotcon_attributes_destroy(state); - iotcon_representation_destroy(repr); - return NULL; - } - - _INFO("After iotcon_representation_set_uri_path"); - - /*TODO:Call Mobile ASM with the incoming query (Base64 decoded TLV)*/ - //char tlv_b64_dec[5000] = {0,}; - //snprintf(tlv_b64_dec, 4999, "%s", ASM_GET_INFO_RESP); - ret = iotcon_attributes_add_str(state, RA_QUERY_KEY_RESPONSE, tlvRespB64); - if (IOTCON_ERROR_NONE != ret) { - iotcon_attributes_destroy(state); - iotcon_representation_destroy(repr); - return NULL; - } - - _INFO("After iotcon_attributes_add_str"); - ret = iotcon_representation_set_attributes(repr, state); - if (IOTCON_ERROR_NONE != ret) { - iotcon_attributes_destroy(state); - iotcon_representation_destroy(repr); - return NULL; - } - - //iotcon_attributes_destroy(state); - - _INFO("After end [%p]", repr); - return repr; -} - -char* -__getServerId(void) -{ - connection_h conn = NULL; - connection_create(&conn); - - static char *mac = NULL; - if (mac != NULL) - return mac; - - /*Try: Ethernet*/ - int ret = connection_get_mac_address(conn, CONNECTION_TYPE_ETHERNET, &mac); - - /*Try: Wifi*/ - if (ret != CONNECTION_ERROR_NONE) - ret = connection_get_mac_address(conn, CONNECTION_TYPE_WIFI, &mac); - - /*Try: BT*/ - if (ret != CONNECTION_ERROR_NONE) - ret = connection_get_mac_address(conn, CONNECTION_TYPE_BT, &mac); - - return mac; -} - -static int -_request_handler_put(ra_resource_s *ra, iotcon_request_h request) -{ - _INFO("_request_handler_put start"); - - int ret = 0; - - iotcon_representation_h repr = NULL; - iotcon_request_get_representation(request, &repr); - if (repr == NULL) { - _ERR("iotcon_request_get_representation failed"); - return -1; - } - - iotcon_attributes_h attr = NULL; - iotcon_representation_get_attributes(repr, &attr); - if (attr == NULL) { - _ERR("iotcon_representation_get_attributes failed"); - return -1; - } - - char *tlvReqB64 = NULL; - iotcon_attributes_get_str(attr, RA_QUERY_KEY_REQUEST, &tlvReqB64); - if (tlvReqB64 == NULL) { - _ERR("[%s] key missing", RA_QUERY_KEY_REQUEST); - _send_response(request, NULL, IOTCON_RESPONSE_ERROR); - - return -1; - } - - char *serverId = NULL; - iotcon_attributes_get_str(attr, RA_QUERY_KEY_SERVER_ID, &serverId); - if (serverId == NULL) { - _ERR("[%s] key missing", RA_QUERY_KEY_SERVER_ID); - _send_response(request, NULL, IOTCON_RESPONSE_ERROR); - - return -1; - } - - if (strcmp(serverId, __getServerId()) == 0) { - _ERR("Request from same Device is ignored"); - _send_response(request, NULL, IOTCON_RESPONSE_ERROR); - - return -1; - } - - - /*Call ASM dbus and receive the response*/ - Fidoasm *asm_proxy = __asm_get_dbus_proxy(); - if (asm_proxy == NULL) { - _ERR("Failed to get ASM proxy"); - _send_response(request, NULL, IOTCON_RESPONSE_ERROR); - return -1; - } - - - char *tlvRespB64 = NULL; - GError *gErr = NULL; - int tz_err = 0; - fidoasm_call_asm_request_sync(asm_proxy, tlvReqB64, - &tz_err, &tlvRespB64, NULL, &gErr); - if (gErr != NULL) { - - _send_response(request, NULL, IOTCON_RESPONSE_ERROR); - _ERR("Failed returned from ASM"); - return -1; - } - - iotcon_representation_h resp_repr; - - resp_repr = _create_ra_representation(ra, tlvRespB64); - if (NULL == resp_repr) { - _send_response(request, NULL, IOTCON_RESPONSE_ERROR); - _ERR("RA representation create failed"); - return -1; - } - - ret = _send_response(request, resp_repr, IOTCON_RESPONSE_OK); - if (0 != ret) { - iotcon_representation_destroy(resp_repr); - return -1; - } - - iotcon_representation_destroy(resp_repr); - - return 0; -} - -//static bool -//_query_cb(const char *key, const char *value, void *user_data) -//{ -// return IOTCON_FUNC_CONTINUE; -//} - -static void -_request_handler(iotcon_resource_h resource, iotcon_request_h request, - void *user_data) -{ - _INFO("_request_handler start"); - - /*TODO: Only allow if request is not coming from the same device*/ - - ra_resource_s *ra; - iotcon_query_h query; - //int ret, observe_id; - iotcon_request_type_e type; - //iotcon_observe_type_e observe_type; - //char *host_address; - - if (request == NULL) - return; - - int ret = iotcon_request_get_query(request, &query); - if (IOTCON_ERROR_NONE != ret) { - _send_response(request, NULL, IOTCON_RESPONSE_ERROR); - return; - } -// if (query) -// iotcon_query_foreach(query, _query_cb, NULL); - - ret = iotcon_request_get_request_type(request, &type); - if (IOTCON_ERROR_NONE != ret) { - _send_response(request, NULL, IOTCON_RESPONSE_ERROR); - return; - } - - - ra = user_data; - - - if (IOTCON_REQUEST_PUT == type) { - ret = _request_handler_put(ra, request); - } - else { - _send_response(request, NULL, IOTCON_RESPONSE_ERROR); - } - -} - -static bool -__iotcon_handler_is_supported(void) -{ - bool raSupported = false; - system_info_get_platform_bool(IC_FEATURE_OIC, &raSupported); - if (raSupported == false) - system_info_get_platform_bool(IC_FEATURE_OCF, &raSupported); - - return raSupported; -} - -int -iotcon_handler_init(void) -{ - _INFO("iotcon_handler_init"); - if (__iotcon_handler_is_supported() == false) { - _ERR("RA not supported"); - return -1; - } - - int ret; - ra_resource_s ra = {0}; - - - /* initialize iotcon */ - ret = iotcon_initialize(RA_ACL_SERVER); - if (IOTCON_ERROR_NONE != ret) { - return -1; - } - - /* set local ra resource */ - ret = _set_ra_resource(&ra); - if (0 != ret) { - iotcon_deinitialize(); - return -1; - } - - /* add resource options */ - ret = iotcon_resource_interfaces_add(ra.ifaces, IOTCON_INTERFACE_BATCH); - if (IOTCON_ERROR_NONE != ret) { - _free_ra_resource(&ra); - iotcon_deinitialize(); - - return -1; - } - //ra.properties |= IOTCON_RESOURCE_OBSERVABLE; - - /* add presence */ - //g_timeout_add_seconds(10, _presence_timer, NULL); - //iotcon_start_presence(10); - - /* create new ra resource */ - ra.handle = _create_ra_resource(ra.uri_path, ra.type, ra.ifaces, - ra.properties, &ra); - if (NULL == ra.handle) { - - _free_ra_resource(&ra); - iotcon_deinitialize(); - return -1; - } - - //_check_ra_state(my_ra); - - - //iotcon_resource_destroy(ra.handle); - - //_free_ra_resource(&ra); - - /* deinitialize iotcon */ - //iotcon_deinitialize(); - - return 0; -} - - - diff --git a/roaming_agent/src/iotcon_handler.h b/roaming_agent/src/iotcon_handler.h deleted file mode 100644 index 6513123..0000000 --- a/roaming_agent/src/iotcon_handler.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * iotcon_handler.h - * - * Created on: May 16, 2016 - * Author: manasij.r - */ - -#ifndef IOTCON_HANDLER_H_ -#define IOTCON_HANDLER_H_ - - -int iotcon_handler_init(void); - - -#endif /* IOTCON_HANDLER_H_ */ diff --git a/roaming_agent/src/ragent_main.c b/roaming_agent/src/ragent_main.c deleted file mode 100644 index 512f4d9..0000000 --- a/roaming_agent/src/ragent_main.c +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2014 - 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. - * - */ - -#include -#include - -#include "iotcon_handler.h" -#include "AsmHelper.h" - -int -main(int argc, char *argv[]) -{ - _INFO("Starting Roaming Agent Service"); - - int ret = iotcon_handler_init(); - if (ret != 0) { - _ERR("iotcon init failed [%d]", ret); - - return 0; - } - - GMainLoop *mainloop = g_main_loop_new(NULL, FALSE); - - g_main_loop_run(mainloop); - - _INFO("Stopping Roaming Agent Service"); - - return 0; -} diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 3ad6f4a..b72b411 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -22,7 +22,6 @@ pkg_check_modules(SERVICE_PKGS REQUIRED openssl aul json-glib-1.0 - iotcon openssl capi-system-info capi-system-system-settings diff --git a/server/auth_discovery/inc/BleAdProvider.h b/server/auth_discovery/inc/BleAdProvider.h deleted file mode 100644 index c59a96b..0000000 --- a/server/auth_discovery/inc/BleAdProvider.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef _BLE_AD_PROVIDER_H -#define _BLE_AD_PROVIDER_H - -#include - -#include "IADProvider.h" -#include - -class BleAdProvider : public IADProvider { - friend class AuthManager; -public: - virtual int init(void); - virtual auth_type_e getType(void); - virtual std::vector *getAuthStubList(void); - virtual void setCache(std::map *stubCache); - virtual IAuthStub* getStubFromCache(int mappedIdx); - - virtual ~BleAdProvider(void); - -private: - BleAdProvider(void); - - static void onGattConchanged(int result, bool connected, - const char *remote_address, void *user_data); - static void onBtStateChanged(int result, bt_adapter_state_e adapter_state, - void *user_data); - static void onLEScanResult(int result, bt_adapter_le_device_scan_result_info_s *info, - void *user_data); - static void finishDiscovery(gpointer data); - static gboolean discoverTimeOutCb(gpointer user_data); - -private: - std::map *__stubCache; - - GMainLoop *__waitLoop; - bool __isValidInst; -}; - -#endif // _BLE_AD_PROVIDER_H diff --git a/server/auth_discovery/inc/BleCon.h b/server/auth_discovery/inc/BleCon.h deleted file mode 100644 index 221deb2..0000000 --- a/server/auth_discovery/inc/BleCon.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef _BLE_CON_H -#define _BLE_CON_H - -#include "IAuthConnection.h" -#include -#include - -class GattClient { -public: - GattClient(void) - { - __btClientInfo = NULL; - __btClient = NULL; - __btClientSvc = NULL; - __btClientChrReq = NULL; - __btClientChrResp = NULL; - } - -public: - /*bt_adapter_le_device_scan_result_info_s *__btClientInfo;*/ - char *__btClientInfo; - bt_gatt_client_h __btClient; - bt_gatt_h __btClientSvc; - bt_gatt_h __btClientChrReq; - bt_gatt_h __btClientChrResp; -}; - -class BleCon : public IAuthConnection { -public: - BleCon(void); - ~BleCon(void); - - virtual int init(void *handle); - virtual StringMap* sendReqSync(StringMap *reqData); - virtual int shutdown(void); - virtual char* getInfo(void); -private: - static void onGattServerResponse(bt_gatt_h characteristic, char *value, - int len, void *user_data); - static void onGattWriteComplete(int result, bt_gatt_h request_handle, - void *user_data); -private: - GattClient *__gClient; - GMainLoop *__waitLoop; - StringMap *__resp; -}; - -#endif // _BLE_CON_H diff --git a/server/auth_discovery/inc/BtAdProvider.h b/server/auth_discovery/inc/BtAdProvider.h index 6925333..bfce2d9 100644 --- a/server/auth_discovery/inc/BtAdProvider.h +++ b/server/auth_discovery/inc/BtAdProvider.h @@ -34,6 +34,7 @@ private: bool __isDiscovering; char *__sAddr; bool __isConCbSet; + int __btInitResult; }; #endif // BTADPROVIDER_H diff --git a/server/auth_discovery/inc/IoTCon.h b/server/auth_discovery/inc/IoTCon.h deleted file mode 100644 index f337023..0000000 --- a/server/auth_discovery/inc/IoTCon.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef IOTCON_H -#define IOTCON_H - -#include "IAuthConnection.h" -#include -#include - -class IoTCon : public IAuthConnection { -public: - - IoTCon(void); - ~IoTCon(void); - - virtual int init(void *handle); - virtual StringMap* sendReqSync(StringMap *reqData); - virtual int shutdown(void); - virtual char* getInfo(void); - -private: - static void onResponsePut(iotcon_remote_resource_h resource, iotcon_error_e err, - iotcon_request_type_e request_type, iotcon_response_h response, void *user_data); -private: - GMainLoop *__waitLoop; - iotcon_remote_resource_h __iotClient; - StringMap* __resp; -}; - -#endif // IOTCON_H diff --git a/server/auth_discovery/inc/IotADProvider.h b/server/auth_discovery/inc/IotADProvider.h deleted file mode 100644 index cc1dc28..0000000 --- a/server/auth_discovery/inc/IotADProvider.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2014 - 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. - * - */ - -#ifndef _IOT_ADP_H_ -#define _IOT_ADP_H_ - -#include -#include -#include -#include - -#include "IADProvider.h" - -class IAuthStub; - -class IotADProvider : public IADProvider { - - friend class AuthManager; -public: - virtual int init(void); - virtual auth_type_e getType(void); - virtual std::vector *getAuthStubList(void); - virtual void setCache(std::map *stubCache); - virtual IAuthStub* getStubFromCache(int mappedIdx); - - virtual ~IotADProvider(void); - static void finishDiscovery(gpointer data); - static gboolean discoverTimeOutCb(gpointer user_data); - static bool resourceFoundCb(iotcon_remote_resource_h resource, iotcon_error_e result, - void *user_data); -private: - IotADProvider(void); - -private: - /*std::vector *__authList;*/ - std::map *__stubCache; - - GMainLoop *__waitLoop; - bool __isValidInst; - -}; - -#endif /* _IOT_ADP_H_ */ diff --git a/server/auth_discovery/inc/RoamingUtil.h b/server/auth_discovery/inc/RoamingUtil.h index a67e891..24e88aa 100644 --- a/server/auth_discovery/inc/RoamingUtil.h +++ b/server/auth_discovery/inc/RoamingUtil.h @@ -31,10 +31,6 @@ public: static bool isRASupported(void); - static std::string getBTMACAddr(void); - static std::string getDevName(void); - static std::string getP2PMACAddr(void); - static char *getServerId(void); private: RoamingUtil(void) {} diff --git a/server/auth_discovery/src/AuthManager.cpp b/server/auth_discovery/src/AuthManager.cpp index adfb8cb..65bc999 100644 --- a/server/auth_discovery/src/AuthManager.cpp +++ b/server/auth_discovery/src/AuthManager.cpp @@ -21,9 +21,7 @@ #include #include "BoundADProvider.h" -#include "IotADProvider.h" #include "RoamingUtil.h" -#include "BleAdProvider.h" #include "BtAdProvider.h" AuthManager* AuthManager::__this = NULL; @@ -37,29 +35,6 @@ AuthManager::initProviders(void) _INFO("Bound Provider=[%p]", badPro); __providerList.push_back(badPro); - -// if (RoamingUtil::isRASupported() == true) { -// IADProvider *radPro = new IotADProvider(); -// int retRa = radPro->init(); -// if (retRa == 0) { -// _INFO("Roaming Provider=[%p]", radPro); -// __providerList.push_back(radPro); -// } else { -// _INFO("RA not supported"); -// delete radPro; -// } -// } - -// IADProvider *blePro = new BleAdProvider(); -// int retBle = blePro->init(); -// if (retBle == 0) { -// _INFO("BLE Provider=[%p]", blePro); -// __providerList.push_back(blePro); -// } else { -// _INFO("BLE Provider not supported"); -// delete blePro; -// } - IADProvider *btPro = new BtAdProvider(); int retBt = btPro->init(); if (retBt == 0) { diff --git a/server/auth_discovery/src/BleAdProvider.cpp b/server/auth_discovery/src/BleAdProvider.cpp deleted file mode 100644 index 1f66ec7..0000000 --- a/server/auth_discovery/src/BleAdProvider.cpp +++ /dev/null @@ -1,415 +0,0 @@ - -#include "BleAdProvider.h" -#include "IAuthConnection.h" -#include "BleCon.h" -#include "RAuthStub.h" -#include "AsmHelper.h" -#include "BTRoamingKeys.h" - -/*BLE is not working on 3.0*/ -#define DISABLE_BLE - -void -BleAdProvider::onBtStateChanged(int result, bt_adapter_state_e adapter_state, - void *user_data) -{ - _INFO("bluetooth onBtStateChanged=[%d]", adapter_state); - BleAdProvider *btPro = (BleAdProvider*)user_data; - if (adapter_state == BT_ADAPTER_DISABLED) { - if (btPro->__stubCache != NULL) { - _INFO("bluetooth Deletting cache=[%p]", btPro->__stubCache); - delete btPro->__stubCache; - btPro->__stubCache = NULL; - } - } -} - -int -BleAdProvider::init(void) -{ -#ifdef DISABLE_BLE - _INFO("BLE is disabled by ASM"); - return -1; -#endif - - _INFO("bluetooth "); - __stubCache = NULL; - int ret = bt_initialize(); - if(ret != BT_ERROR_NONE && ret != BT_ERROR_ALREADY_DONE) { - _ERR("bluetooth rclient bluetooth service can not initialize=[%d]", ret); - return -1; - } - - bt_adapter_set_state_changed_cb(onBtStateChanged, this); - _INFO("bluetooth "); - return 0; -} - -auth_type_e -BleAdProvider::getType(void) -{ - return AUTH_TYPE_ROAMING; -} - -static bool -__bt_gatt_client_foreach_desc_cb(int total, int index, bt_gatt_h desc_handle, void *data) -{ - char *uuid = NULL; - - bt_gatt_get_uuid(desc_handle, &uuid); - - _INFO("bluetooth [%d / %d] uuid: (%s)", index, total, uuid); - - g_free(uuid); - - return true; -} - -static bool -__bt_gatt_client_foreach_chr_cb(int total, int index, bt_gatt_h chr_handle, void *data) -{ - int ret; - char *uuid = NULL; - - bt_gatt_get_uuid(chr_handle, &uuid); - - _INFO("bluetooth [%d / %d] uuid: (%s)", index, total, uuid); - - g_free(uuid); - - ret = bt_gatt_characteristic_foreach_descriptors(chr_handle, - __bt_gatt_client_foreach_desc_cb, NULL); - if (ret != BT_ERROR_NONE) - _INFO("bluetooth bt_gatt_characteristic_foreach_descriptors failed: %d", ret); - - return true; -} - -static bool -__svcCb(int total, int index, bt_gatt_h gatt_handle, - void *user_data) -{ - int ret; - char *uuid = NULL; - - bt_gatt_get_uuid(gatt_handle, &uuid); - _INFO("bluetooth [%d / %d] uuid: (%s)", index, total, uuid); - - g_free(uuid); - - ret = bt_gatt_service_foreach_characteristics(gatt_handle, - __bt_gatt_client_foreach_chr_cb, NULL); - if (ret != BT_ERROR_NONE) - _INFO("bluetooth bt_gatt_service_foreach_characteristics failed: %d", ret); - - return true; -} - -#define printIfAndRet(e1, e2, str) \ - if (e1 == e2) {\ - _INFO("bluetooth fido asm bt error=[%s]", str);\ - return; \ - }\ - -static void -printBTError(bt_error_e e) -{ - printIfAndRet(e, BT_ERROR_NONE, "BT_ERROR_NONE"); - printIfAndRet(e, BT_ERROR_CANCELLED, "BT_ERROR_CANCELLED"); - printIfAndRet(e, BT_ERROR_INVALID_PARAMETER, "BT_ERROR_INVALID_PARAMETER"); - printIfAndRet(e, BT_ERROR_OUT_OF_MEMORY, "BT_ERROR_OUT_OF_MEMORY"); - printIfAndRet(e, BT_ERROR_RESOURCE_BUSY, "BT_ERROR_RESOURCE_BUSY"); - printIfAndRet(e, BT_ERROR_TIMED_OUT, "BT_ERROR_TIMED_OUT"); - printIfAndRet(e, BT_ERROR_NOW_IN_PROGRESS, "BT_ERROR_NOW_IN_PROGRESS"); - printIfAndRet(e, BT_ERROR_NOT_SUPPORTED, "BT_ERROR_NOT_SUPPORTED"); - printIfAndRet(e, BT_ERROR_PERMISSION_DENIED, "BT_ERROR_PERMISSION_DENIED"); - printIfAndRet(e, BT_ERROR_QUOTA_EXCEEDED, "BT_ERROR_QUOTA_EXCEEDED"); - printIfAndRet(e, BT_ERROR_NO_DATA, "BT_ERROR_NO_DATA"); - printIfAndRet(e, BT_ERROR_DEVICE_POLICY_RESTRICTION, "BT_ERROR_DEVICE_POLICY_RESTRICTION"); - printIfAndRet(e, BT_ERROR_NOT_INITIALIZED, "BT_ERROR_NOT_INITIALIZED"); - printIfAndRet(e, BT_ERROR_NOT_ENABLED, "BT_ERROR_NOT_ENABLED"); - printIfAndRet(e, BT_ERROR_ALREADY_DONE, "BT_ERROR_ALREADY_DONE"); - printIfAndRet(e, BT_ERROR_ALREADY_DONE, "BT_ERROR_ALREADY_DONE"); - printIfAndRet(e, BT_ERROR_OPERATION_FAILED, "BT_ERROR_OPERATION_FAILED"); - printIfAndRet(e, BT_ERROR_NOT_IN_PROGRESS, "BT_ERROR_NOT_IN_PROGRESS"); - printIfAndRet(e, BT_ERROR_REMOTE_DEVICE_NOT_BONDED, "BT_ERROR_REMOTE_DEVICE_NOT_BONDED"); - printIfAndRet(e, BT_ERROR_AUTH_REJECTED, "BT_ERROR_AUTH_REJECTED"); - printIfAndRet(e, BT_ERROR_AUTH_FAILED, "BT_ERROR_AUTH_FAILED"); - printIfAndRet(e, BT_ERROR_REMOTE_DEVICE_NOT_FOUND, "BT_ERROR_REMOTE_DEVICE_NOT_FOUND"); - printIfAndRet(e, BT_ERROR_SERVICE_SEARCH_FAILED, "BT_ERROR_SERVICE_SEARCH_FAILED"); - printIfAndRet(e, BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED, "BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED"); - printIfAndRet(e, BT_ERROR_AGAIN, "BT_ERROR_AGAIN"); - printIfAndRet(e, BT_ERROR_SERVICE_NOT_FOUND, "BT_ERROR_SERVICE_NOT_FOUND"); - printIfAndRet(e, e, "Unknown"); -} - -void -BleAdProvider::onGattConchanged(int result, bool connected, const char *remote_address, void *user_data) -{ - _INFO("bluetooth remote_address=[%s]", remote_address); - _INFO("bluetooth connected=[%d]", connected); - _INFO("bluetooth [%d]", result); - printBTError(static_cast(result)); - if (connected == false) { - _ERR("bluetooth GATT disconnected"); - return; - } - - bt_gatt_h svc = NULL; - bt_gatt_h chrReq = NULL; - bt_gatt_h chrResp = NULL; - bt_gatt_client_h client = NULL; - - _INFO("bluetooth "); - int ret = bt_gatt_client_create(remote_address, &client); - if (ret != BT_ERROR_NONE) { - _ERR("bluetooth rclient bt_gatt_client_create failed=[%d]", ret); - return; - } - - ret = bt_gatt_client_foreach_services(client, __svcCb, NULL); - printBTError(static_cast(ret)); - - char *cRAddr = NULL; - ret = bt_gatt_client_get_remote_address(client, &cRAddr); - printBTError(static_cast(ret)); - - _INFO("bluetooth bt_gatt_client_get_remote_address=[%s]", cRAddr); - ret = bt_gatt_client_get_service(client, RA_BLE_SERVICE_UUID, &svc); - if (ret != BT_ERROR_NONE) { - _ERR("bluetooth rclient bt_gatt_client_get_service failed=[%d]", ret); - printBTError(static_cast(ret)); - return; - } - - _INFO("bluetooth "); - ret = bt_gatt_service_get_characteristic(svc, RA_BLE_UUID_REQUEST, &chrReq); - if (ret != BT_ERROR_NONE) { - _ERR("bluetooth rclient bt_gatt_service_get_characteristic failed=[%d]", ret); - return; - } - - _INFO("bluetooth "); - ret = bt_gatt_service_get_characteristic(svc, RA_BLE_UUID_RESPONSE, &chrResp); - if (ret != BT_ERROR_NONE) { - _ERR("bluetooth rclient bt_gatt_service_get_characteristic failed=[%d]", ret); - return; - } - - _INFO("bluetooth "); - GattClient *gC = new GattClient(); - gC->__btClientInfo = _SAFE_DUP(remote_address); - gC->__btClient = client; - gC->__btClientSvc = svc; - gC->__btClientChrReq = chrReq; - gC->__btClientChrResp = chrResp; - - IAuthConnection *bleClient = new BleCon(); - bleClient->init(gC); - - IAuthStub *raStub = new RAuthStub(); - raStub->initRemote(bleClient); - - BleAdProvider *blePro = (BleAdProvider*)user_data; - if (blePro->__stubCache == NULL) { - blePro->__stubCache = new std::map(); - } - - /*Index auto incremented, set properly during setCache*/ - blePro->__stubCache->insert(std::make_pair(blePro->__stubCache->size(), raStub)); - - BleAdProvider::finishDiscovery(user_data); -} - -void -BleAdProvider::onLEScanResult(int result, bt_adapter_le_device_scan_result_info_s *info, - void *user_data) -{ - _INFO("bluetooth rclient __bt_adapter_le_scan_result_cb=[%d]", result); - _INFO("bluetooth remote_address=[%s]", info->remote_address); - _INFO("bluetooth address_type=[%d]", info->address_type); - /*_INFO("bluetooth adv_data=[%s]", info->adv_data); - _INFO("bluetooth scan_data=[%s]", info->scan_data);*/ - - if (info->adv_data_len > 31 || info->scan_data_len > 31) { - _INFO("bluetooth ###################"); - bt_adapter_le_stop_scan(); - _INFO("bluetooth ###################"); - return; - } - - bt_adapter_le_packet_type_e pkt_type = BT_ADAPTER_LE_PACKET_ADVERTISING; - int i = 0; - for (i = 0; i < 2; i++) { - char **uuids; - char *device_name; - int tx_power_level; - bt_adapter_le_service_data_s *data_list; - int appearance; - int manufacturer_id; - char *manufacturer_data; - int manufacturer_data_len; - int count; - - pkt_type = static_cast(static_cast(pkt_type) + i); - if (pkt_type == BT_ADAPTER_LE_PACKET_ADVERTISING && info->adv_data == NULL) - continue; - if (pkt_type == BT_ADAPTER_LE_PACKET_SCAN_RESPONSE && info->scan_data == NULL) - break; - - if (bt_adapter_le_get_scan_result_service_uuids(info, pkt_type, &uuids, &count) == BT_ERROR_NONE) { - int i; - for (i = 0; i < count; i++) { - _INFO("bluetooth UUID[%d] = %s", i + 1, uuids[i]); - g_free(uuids[i]); - } - g_free(uuids); - } - if (bt_adapter_le_get_scan_result_device_name(info, pkt_type, &device_name) == BT_ERROR_NONE) { - _INFO("bluetooth Device name = %s", device_name); - g_free(device_name); - } - if (bt_adapter_le_get_scan_result_tx_power_level(info, pkt_type, &tx_power_level) == BT_ERROR_NONE) - _INFO("bluetooth TX Power level = %d", tx_power_level); - if (bt_adapter_le_get_scan_result_service_solicitation_uuids(info, pkt_type, &uuids, &count) == BT_ERROR_NONE) { - int i; - for (i = 0; i < count; i++) { - _INFO("bluetooth Solicitation UUID[%d] = %s", i + 1, uuids[i]); - g_free(uuids[i]); - } - g_free(uuids); - } - if (bt_adapter_le_get_scan_result_service_data_list(info, pkt_type, &data_list, &count) == BT_ERROR_NONE) { - int i; - for (i = 0; i < count; i++) { - _INFO("bluetooth Service Data[%d] = [0x%2.2X%2.2X:0x%.2X...]", i + 1, - data_list[i].service_uuid[0], data_list[i].service_uuid[1], data_list[i].service_data[0]); - } - bt_adapter_le_free_service_data_list(data_list, count); - } - if (bt_adapter_le_get_scan_result_appearance(info, pkt_type, &appearance) == BT_ERROR_NONE) - _INFO("bluetooth Appearance = %d", appearance); - if (bt_adapter_le_get_scan_result_manufacturer_data(info, pkt_type, &manufacturer_id, - &manufacturer_data, &manufacturer_data_len) == BT_ERROR_NONE) { - _INFO("bluetooth Manufacturer data[ID:%.4X, 0x%.2X%.2X...(len:%d)]", - manufacturer_id, manufacturer_data[0], manufacturer_data[1], manufacturer_data_len); - g_free(manufacturer_data); - } - } - - /*RA_BLE_ADVERTISING_UUID*/ - - /*_INFO("bluetooth [%d] sec timeout starting", BT_DISC_TIMEOUT_SEC); - g_timeout_add_seconds_full(G_PRIORITY_DEFAULT, BT_DISC_TIMEOUT_SEC, discoverTimeOutCb, user_data, - finishDiscovery);*/ - - _INFO("bluetooth Before bt_gatt_connect"); - - int ret = bt_gatt_connect(info->remote_address, false); - if (ret != BT_ERROR_NONE) { - _ERR("bluetooth rclient bt_gatt_connect failed=[%d]", ret); - return; - } - - _INFO("bluetooth bt_gatt_connect=[%d]", ret); -} - -void -BleAdProvider::finishDiscovery(gpointer data) -{ - _INFO("bluetooth "); - bt_adapter_le_stop_scan(); - - BleAdProvider *btPro = (BleAdProvider*)(data); - g_main_loop_quit(btPro->__waitLoop); -} - -gboolean -BleAdProvider::discoverTimeOutCb(gpointer user_data) -{ - _INFO("bluetooth discoverTimeOutCb"); - - return G_SOURCE_REMOVE; -} - -std::vector * -BleAdProvider::getAuthStubList(void) -{ - _INFO("bluetooth getAuthStubList"); - delete __stubCache; - __stubCache = NULL; - - __waitLoop = g_main_loop_new(NULL, FALSE); - - bt_gatt_set_connection_state_changed_cb(onGattConchanged, this); - - _INFO("bluetooth starting LE scan"); - int ret = bt_adapter_le_start_scan(onLEScanResult, this); - if (ret != BT_ERROR_NONE) { - bt_gatt_unset_connection_state_changed_cb(); - _ERR("bluetooth rclient bt_adapter_le_start_scan failed."); - bt_adapter_le_stop_scan(); - - return NULL; - } - - _INFO("bluetooth starting wait loop"); - g_main_loop_run(__waitLoop); - - _INFO("bluetooth After waitloop"); - - g_main_loop_unref(__waitLoop); - __waitLoop = NULL; - - if (__stubCache != NULL) { - _INFO("bluetooth BT Roaming Auth Count=[%d]", __stubCache->size()); - } else { - _ERR("bluetooth BT Roaming Auth List is NULL"); - return NULL; - } - - std::vector *stubList = NULL; - - std::map::iterator it = __stubCache->begin(); - for (; it != __stubCache->end(); ++it) { - if (stubList == NULL) - stubList = new std::vector(); - - stubList->push_back(it->second); - } - _INFO("bluetooth "); - return stubList; -} - -void -BleAdProvider::setCache(std::map *stubCache) -{ - _INFO("bluetooth BleAdProvider::setCache"); - if (stubCache != NULL) - _INFO("bluetooth New cache set size =[%d]", stubCache->size()); - - __stubCache = stubCache; -} - -IAuthStub* -BleAdProvider::getStubFromCache(int mappedIdx) -{ - if (__stubCache == NULL) { - _ERR("bluetooth Stub cache NULL"); - return NULL; - } - - return __stubCache->find(mappedIdx)->second; -} - -BleAdProvider::~BleAdProvider(void) -{ - -} - -BleAdProvider::BleAdProvider(void) -{ - __stubCache = NULL; - __waitLoop = NULL; - __isValidInst = false; -} diff --git a/server/auth_discovery/src/BleCon.cpp b/server/auth_discovery/src/BleCon.cpp deleted file mode 100644 index 0636df2..0000000 --- a/server/auth_discovery/src/BleCon.cpp +++ /dev/null @@ -1,106 +0,0 @@ -#include "BleCon.h" -#include "AsmHelper.h" -#include "BTRoamingKeys.h" -#include "RoamingKeys.h" - -BleCon::BleCon(void) -{ - __gClient = NULL; - __waitLoop = NULL; - __resp = NULL; -} - -BleCon::~BleCon(void) -{ - -} - -int -BleCon::init(void *handle) -{ - __gClient = (GattClient*)handle; - - return 0; -} - -void -BleCon::onGattServerResponse(bt_gatt_h characteristic, char *value, - int len, void *user_data) -{ - _INFO("Response length = [%d]", len); - - BleCon *btCon = (BleCon*)user_data; - btCon->__resp = new StringMap(); - - std::string k(RA_QUERY_KEY_RESPONSE); - std::string v(value); - btCon->__resp->insert(std::make_pair(k, v)); - - g_main_loop_quit(btCon->__waitLoop); -} - -void -BleCon::onGattWriteComplete(int result, bt_gatt_h request_handle, void *user_data) -{ - _INFO("[%d]", result); - BleCon *btCon = (BleCon*)user_data; - if (result != 0) { - g_main_loop_quit(btCon->__waitLoop); - } -} - -StringMap* -BleCon::sendReqSync(StringMap *reqData) -{ - _INFO("sendReqSync start"); - - RET_IF_FAIL(reqData != NULL, NULL); - RET_IF_FAIL(__gClient != NULL, NULL); - - __resp = NULL; - std::string reqTlvB64 = (reqData->find(RA_QUERY_KEY_REQUEST)->second); - char *reqTlvB64Copy = strdup(reqTlvB64.c_str()); - - __waitLoop = g_main_loop_new(NULL, FALSE); - - int ret = bt_gatt_client_set_characteristic_value_changed_cb(__gClient->__btClientChrResp, - onGattServerResponse, this); - _ERR("rclient bt_gatt_client_set_characteristic_value_changed_cb failed=[%d]", ret); - - - ret = bt_gatt_set_value(__gClient->__btClientChrReq, reqTlvB64Copy, strlen(reqTlvB64Copy)); - if (ret != BT_ERROR_NONE) { - _ERR("rclient bt_gatt_set_value failed=[%d]", ret); - goto CATCH; - } - - ret = bt_gatt_client_write_value(__gClient->__btClientChrReq, onGattWriteComplete, this); - if (ret != BT_ERROR_NONE) { - _ERR("rclient bt_gatt_client_write_value failed=[%d]", ret); - goto CATCH; - } - - _INFO("bt_gatt_client_write_value=[%d]", ret); - g_main_loop_run(__waitLoop); - -CATCH: - SAFE_DELETE(reqTlvB64Copy); - g_main_loop_unref(__waitLoop); - bt_gatt_client_unset_characteristic_value_changed_cb(__gClient->__btClientChrResp); - _INFO("sendReqSync=%s", __resp); - return __resp; -} - -int -BleCon::shutdown(void) -{ - return -1; -} - -char* -BleCon::getInfo(void) -{ - RET_IF_FAIL(__gClient != NULL, NULL); - - return __gClient->__btClientInfo; -} diff --git a/server/auth_discovery/src/BtADProvider.cpp b/server/auth_discovery/src/BtADProvider.cpp index c9d370b..ed14653 100644 --- a/server/auth_discovery/src/BtADProvider.cpp +++ b/server/auth_discovery/src/BtADProvider.cpp @@ -5,7 +5,6 @@ #include "RAuthStub.h" #include "AsmHelper.h" #include "BTRoamingKeys.h" -//#include #include #define RA_BT_SERVICE_UUID "00001101-0000-1000-8000-00805F9B34FB" @@ -16,9 +15,9 @@ BtAdProvider::init(void) __isDiscovering = false; __sAddr = NULL; - int ret = bt_initialize(); - _INFO("bt_initialize=[%d]", ret); - if (ret != BT_ERROR_NONE) + __btInitResult = bt_initialize(); + _INFO("bt_initialize=[%d]", __btInitResult); + if (__btInitResult != BT_ERROR_NONE) return -1; __stubCache = NULL; @@ -222,7 +221,10 @@ BtAdProvider::getStubFromCache(int mappedIdx) BtAdProvider::~BtAdProvider(void) { - + if (__btInitResult == BT_ERROR_NONE) { + int ret = bt_deinitialize(); + _INFO("bt_deinitialize=[%d]", ret); + } } BtAdProvider::BtAdProvider(void) diff --git a/server/auth_discovery/src/BtCon.cpp b/server/auth_discovery/src/BtCon.cpp index 01ac26b..3987316 100644 --- a/server/auth_discovery/src/BtCon.cpp +++ b/server/auth_discovery/src/BtCon.cpp @@ -1,7 +1,6 @@ #include "BtCon.h" #include "BTRoamingKeys.h" -#include "RoamingKeys.h" #include "AsmHelper.h" #include #include diff --git a/server/auth_discovery/src/IoTCon.cpp b/server/auth_discovery/src/IoTCon.cpp deleted file mode 100644 index 38bf0f2..0000000 --- a/server/auth_discovery/src/IoTCon.cpp +++ /dev/null @@ -1,121 +0,0 @@ - -#include "IoTCon.h" -#include "AuthnrTypes.h" -#include "AsmHelper.h" -#include "RoamingKeys.h" - -IoTCon::IoTCon(void) -{ - __waitLoop = NULL; - __iotClient = NULL; - __resp = NULL; -} - -IoTCon::~IoTCon(void) -{ - -} - -int -IoTCon::init(void *handle) -{ - __iotClient = (iotcon_remote_resource_h)handle; - - return 0; -} - -void -IoTCon::onResponsePut(iotcon_remote_resource_h resource, iotcon_error_e err, - iotcon_request_type_e request_type, iotcon_response_h response, void *user_data) -{ - _INFO(""); - - IoTCon *conn = (IoTCon*)user_data; - _INFO("onResponsePut [%p]", conn); - - iotcon_representation_h repr = NULL; - iotcon_attributes_h state = NULL; - - iotcon_response_get_representation(response, &repr); - - iotcon_representation_get_attributes(repr, &state); - - char *asm_resp = NULL; - iotcon_attributes_get_str(state, RA_QUERY_KEY_RESPONSE, &asm_resp); - if (asm_resp != NULL) { - _INFO("%s=%s", RA_QUERY_KEY_RESPONSE, asm_resp); - - conn->__resp = new StringMap(); - std::string k(RA_QUERY_KEY_RESPONSE); - std::string v(asm_resp); - conn->__resp->insert(std::make_pair(k, v)); - } else { - _ERR("Failed to get %s", RA_QUERY_KEY_RESPONSE); - conn->__resp = NULL; - } - - _INFO("Before g_main_loop_quit"); - g_main_loop_quit(conn->__waitLoop); -} - -StringMap * -IoTCon::sendReqSync(StringMap *reqData) -{ - RET_IF_FAIL(reqData != NULL, NULL); - - std::string reqTlvB64 = (reqData->find(RA_QUERY_KEY_REQUEST)->second); - std::string svrId = (reqData->find(RA_QUERY_KEY_SERVER_ID)->second); - - iotcon_attributes_h attr = NULL; - iotcon_attributes_create(&attr); - - char *reqTlvB64Copy = strdup(reqTlvB64.c_str()); - char *svrIdCopy = strdup(svrId.c_str()); - iotcon_attributes_add_str(attr, RA_QUERY_KEY_REQUEST, reqTlvB64Copy); - iotcon_attributes_add_str(attr, RA_QUERY_KEY_SERVER_ID, svrIdCopy); - - iotcon_representation_h repr = NULL; - iotcon_representation_create(&repr); - - iotcon_representation_set_attributes(repr, attr); - - - __waitLoop = g_main_loop_new(NULL, FALSE); - int ret = iotcon_remote_resource_put(__iotClient, repr, NULL, onResponsePut, this); - if (ret != IOTCON_ERROR_NONE) { - _ERR("iotcon_remote_resource_get failed"); - iotcon_representation_destroy(repr); - SAFE_DELETE(reqTlvB64Copy); - SAFE_DELETE(svrIdCopy); - return NULL; - } - - iotcon_representation_destroy(repr); - SAFE_DELETE(reqTlvB64Copy); - SAFE_DELETE(svrIdCopy); - _INFO("iotcon_remote_resource_get=[%d]", ret); - g_main_loop_run(__waitLoop); - - _INFO("sendReqSync end"); - - return __resp; -} - -char* -IoTCon::getInfo(void) -{ - char *devId = NULL; - int ret = iotcon_remote_resource_get_device_id(__iotClient, &devId); - if (ret == IOTCON_ERROR_NONE && devId != NULL) { - _INFO("Device Id = [%s]", devId); - return devId; - } - - return NULL; -} - -int -IoTCon::shutdown(void) -{ - return 0; -} diff --git a/server/auth_discovery/src/IotADProvider.cpp b/server/auth_discovery/src/IotADProvider.cpp deleted file mode 100644 index 570a6fe..0000000 --- a/server/auth_discovery/src/IotADProvider.cpp +++ /dev/null @@ -1,217 +0,0 @@ - -#include "IotADProvider.h" - -#include -#include "IoTCon.h" -#include "AsmHelper.h" -#include "RAuthStub.h" -#include "RoamingKeys.h" -#include "AuthIndexHanlder.h" -#include "RoamingUtil.h" - -#define EMPTY_STUB_LIST std::vector() - -#define AUTH_INDEX_START 5 - -void -IotADProvider::finishDiscovery(gpointer data) -{ - _INFO(""); - IotADProvider *rAuthManager = (IotADProvider*)(data); - g_main_loop_quit(rAuthManager->__waitLoop); -} - -gboolean -IotADProvider::discoverTimeOutCb(gpointer user_data) -{ - _INFO("discoverTimeOutCb"); - - return G_SOURCE_REMOVE; -} - -bool -IotADProvider::resourceFoundCb(iotcon_remote_resource_h resource, iotcon_error_e result, - void *user_data) -{ - _INFO(""); - - if (result != IOTCON_ERROR_NONE) { - _ERR("No remote resource found"); - return false; - //return; - } - - char *rDevId = NULL; - iotcon_remote_resource_get_device_id(resource, &rDevId); - if (rDevId == NULL) { - _ERR("iotcon_remote_resource_get_device_id failed"); - return false; - //return; - } - - char *rHostAddr = NULL; - iotcon_remote_resource_get_host_address(resource, &rHostAddr); - if (rHostAddr == NULL) { - _ERR("iotcon_remote_resource_get_host_address failed"); - return false; - //return; - } - - std::string p2pMacAddr = RoamingUtil::getP2PMACAddr(); - std::string btMacAddr = RoamingUtil::getBTMACAddr(); - - _INFO("[%s][%s]", p2pMacAddr.c_str(), btMacAddr.c_str()); - _INFO("[%s]", rDevId); - _INFO("[%s]", rHostAddr); - - if (p2pMacAddr.empty() == false) { - - if (strcmp(rDevId, p2pMacAddr.c_str()) == 0) { - _INFO("Ignoring request from same device"); - return false; - //return; - } - - } else if (btMacAddr.empty() == false) { - if (strcmp(rDevId, btMacAddr.c_str()) == 0) { - _INFO("Ignoring request from same device"); - return false; - //return; - } - } - - IotADProvider *radPro = (IotADProvider*)user_data; - _INFO("this=[%p]", radPro); - - iotcon_remote_resource_h resourceClone = NULL; - - _INFO("Before iotcon_remote_resource_clone"); - int ret = iotcon_remote_resource_clone(resource, &resourceClone); - _INFO("After iotcon_remote_resource_clone"); - if (ret != IOTCON_ERROR_NONE) { - _ERR("Failed to clone remote resource"); - return false; - //return; - } - - IAuthStub *stub = new RAuthStub(); - IAuthConnection *conH = new IoTCon(); - conH->init(resourceClone); - stub->initRemote(conH); - - if (radPro->__stubCache == NULL) { - radPro->__stubCache = new std::map(); - } - - /*Index auto incremented, set properly during setCache*/ - radPro->__stubCache->insert(std::make_pair(radPro->__stubCache->size(), stub)); - - return true; -} - -std::vector* -IotADProvider::getAuthStubList(void) -{ - delete __stubCache; - __stubCache = NULL; - - __waitLoop = g_main_loop_new(NULL, FALSE); - - g_timeout_add_seconds_full(G_PRIORITY_DEFAULT, 1, discoverTimeOutCb, this, - finishDiscovery); - - - iotcon_query_h iotQ = NULL; - iotcon_query_create(&iotQ); - - int ret = iotcon_query_set_resource_type(iotQ, RA_RESOURCE_TYPE); - - ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_ALL, - iotQ, resourceFoundCb, this); - if (IOTCON_ERROR_NONE != ret) { - _ERR("iotcon_find_resource failed"); - iotcon_query_destroy(iotQ); - return NULL; - } - - iotcon_query_destroy(iotQ); - g_main_loop_run(__waitLoop); - - _INFO("After g_main_loop_run"); - - g_main_loop_unref(__waitLoop); - __waitLoop = NULL; - - if (__stubCache != NULL) { - _INFO("Roaming Auth Count=[%d]", __stubCache->size()); - } else { - _ERR("Roaming Auth List is NULL"); - return NULL; - } - - std::vector *stubList = NULL; - - std::map::iterator it = __stubCache->begin(); - for (; it != __stubCache->end(); ++it) { - if (stubList == NULL) - stubList = new std::vector(); - - stubList->push_back(it->second); - } - _INFO(""); - return stubList; -} - -void -IotADProvider::setCache(std::map *stubCache) -{ - _INFO("IotADProvider::setCache"); - if (stubCache != NULL) - _INFO("New cache set size =[%d]", stubCache->size()); - - __stubCache = stubCache; -} - -IAuthStub* -IotADProvider::getStubFromCache(int mappedIdx) -{ - if (__stubCache == NULL) { - _ERR("Stub cache NULL"); - return NULL; - } - - return __stubCache->find(mappedIdx)->second; -} - -IotADProvider::~IotADProvider(void) -{ - if (__isValidInst == true) - iotcon_deinitialize(); -} - -int -IotADProvider::init(void) -{ - int ret = iotcon_initialize(RA_ACL_CLIENT); - if (IOTCON_ERROR_NONE != ret) { - __isValidInst = false; - return -1; - } - - __isValidInst = true; - return 0; -} - -auth_type_e -IotADProvider::getType(void) -{ - return AUTH_TYPE_ROAMING; -} - -IotADProvider::IotADProvider(void) - : __isValidInst(false) -{ - __stubCache = NULL; - __waitLoop = NULL; - __isValidInst = false; -} diff --git a/server/auth_discovery/src/RAuthStub.cpp b/server/auth_discovery/src/RAuthStub.cpp index 922815f..a2319b4 100644 --- a/server/auth_discovery/src/RAuthStub.cpp +++ b/server/auth_discovery/src/RAuthStub.cpp @@ -1,7 +1,6 @@ #include "RAuthStub.h" #include "AsmHelper.h" -#include "RoamingKeys.h" #include "RoamingUtil.h" #include "TlvData.h" #include "AuthIndexHanlder.h" diff --git a/server/auth_discovery/src/RoamingUtil.cpp b/server/auth_discovery/src/RoamingUtil.cpp index cbb3193..9fd6b76 100644 --- a/server/auth_discovery/src/RoamingUtil.cpp +++ b/server/auth_discovery/src/RoamingUtil.cpp @@ -340,48 +340,6 @@ RoamingUtil::isRASupported(void) return raSupported;*/ } -std::string -RoamingUtil::getBTMACAddr(void) -{ - static std::string g_mac_address; - if(g_mac_address.empty() == true) { - bt_initialize(); - char* mac_address = NULL; - bt_adapter_enable(); - int ret = bt_adapter_get_address(&mac_address); - if (ret != 0) { - _ERR("bt_adapter_get_address failed"); - return g_mac_address; - } - - _INFO("bluetooth get mac address : %s", mac_address); - g_mac_address = mac_address; - free(mac_address); - bt_deinitialize(); - } - _INFO("mac address:%s", g_mac_address.c_str()); - - return g_mac_address; -} - - -std::string -RoamingUtil::getDevName(void) -{ - static std::string g_device_name; - if(g_device_name.empty()) { - char* device_name = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR); - if (device_name == NULL) { - g_device_name = "Tizen"; - } else { - g_device_name = device_name; - } - _INFO("device_name: %s", g_device_name.c_str()); - } - - return g_device_name; -} - char RoamingUtil::makeP2PMAC(char c) { @@ -400,30 +358,6 @@ RoamingUtil::makeP2PMAC(char c) return convert_c; } -std::string -RoamingUtil::getP2PMACAddr(void) -{ - static std::string g_p2p_mac_address; - if(g_p2p_mac_address.empty()) { - char p2p_mac[MAC_ADDR_STR_LEN]; - memset(p2p_mac, 0x0, MAC_ADDR_STR_LEN); - - char* temp_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS); - if (temp_addr == NULL) { - _ERR("vconf_get_str Failed for %s", VCONFKEY_WIFI_BSSID_ADDRESS); - } else { - memcpy(p2p_mac, temp_addr, MAC_ADDR_STR_LEN-1); - p2p_mac[1] = makeP2PMAC(p2p_mac[1]); - _INFO("P2P mac is %s", p2p_mac); - free(temp_addr); - - g_p2p_mac_address = p2p_mac; - } - } - _INFO("p2p mac address:%s", g_p2p_mac_address.c_str()); - return g_p2p_mac_address; -} - char* RoamingUtil::getServerId(void) { -- 2.7.4 From 67d580dfe4c3bfa74ca80a92e153c5bc971035f2 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Fri, 23 Jun 2017 14:18:34 +0900 Subject: [PATCH 12/16] Fix fido-asm.service : User & Group is in wrong session. Signed-off-by: INSUN PYO Change-Id: I7aa42f521dbbcc356561f88c53a470f42422500b --- packaging/fido-asm.service | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packaging/fido-asm.service b/packaging/fido-asm.service index 4e34663..9cfc861 100644 --- a/packaging/fido-asm.service +++ b/packaging/fido-asm.service @@ -5,9 +5,8 @@ Requires=tizen-runtime.target [Service] ExecStart=/usr/bin/fido-asm - -[Install] -WantedBy=multi-user.target - User=service_fw Group=service_fw + +[Install] +WantedBy=multi-user.target \ No newline at end of file -- 2.7.4 From 6b450d4f323367db34cf692648cf81afd470f59c Mon Sep 17 00:00:00 2001 From: jkjo92 Date: Fri, 23 Jun 2017 19:16:44 +0900 Subject: [PATCH 13/16] [Kona Issue] Disable temporary UUID Change-Id: I3ee84889bef504981a0f5b4bc8b6fab9996bcf94 Signed-off-by: jkjo92 --- server/auth_discovery/src/BtADProvider.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 server/auth_discovery/src/BtADProvider.cpp diff --git a/server/auth_discovery/src/BtADProvider.cpp b/server/auth_discovery/src/BtADProvider.cpp old mode 100644 new mode 100755 index ed14653..9d096ac --- a/server/auth_discovery/src/BtADProvider.cpp +++ b/server/auth_discovery/src/BtADProvider.cpp @@ -7,7 +7,7 @@ #include "BTRoamingKeys.h" #include -#define RA_BT_SERVICE_UUID "00001101-0000-1000-8000-00805F9B34FB" +#define RA_BT_SERVICE_UUID "8F5E6268-CFCD-4474-AFA2-0FEBFED72D73" int BtAdProvider::init(void) -- 2.7.4 From 7caa832110640db90719707e595dab3aef07266c Mon Sep 17 00:00:00 2001 From: jkjo92 Date: Fri, 23 Jun 2017 19:16:44 +0900 Subject: [PATCH 14/16] [Kona Issue] Change to Random generated UUID Change-Id: I3ee84889bef504981a0f5b4bc8b6fab9996bcf94 Signed-off-by: jkjo92 --- server/auth_discovery/src/BtADProvider.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 server/auth_discovery/src/BtADProvider.cpp diff --git a/server/auth_discovery/src/BtADProvider.cpp b/server/auth_discovery/src/BtADProvider.cpp old mode 100644 new mode 100755 index ed14653..9d096ac --- a/server/auth_discovery/src/BtADProvider.cpp +++ b/server/auth_discovery/src/BtADProvider.cpp @@ -7,7 +7,7 @@ #include "BTRoamingKeys.h" #include -#define RA_BT_SERVICE_UUID "00001101-0000-1000-8000-00805F9B34FB" +#define RA_BT_SERVICE_UUID "8F5E6268-CFCD-4474-AFA2-0FEBFED72D73" int BtAdProvider::init(void) -- 2.7.4 From a354df0b8d9c867dcd0f7013b08d6874bbc355e0 Mon Sep 17 00:00:00 2001 From: jkjo92 Date: Mon, 3 Jul 2017 19:39:46 +0900 Subject: [PATCH 15/16] Use random generated BT UUID for Roaming Authentictor Change-Id: Ibe1931fee8709ad878ec46423a1969a04ba62b93 Signed-off-by: jkjo92 --- bt_roaming_agent/src/bt_server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 bt_roaming_agent/src/bt_server.c diff --git a/bt_roaming_agent/src/bt_server.c b/bt_roaming_agent/src/bt_server.c old mode 100644 new mode 100755 index 0154dd6..d94e877 --- a/bt_roaming_agent/src/bt_server.c +++ b/bt_roaming_agent/src/bt_server.c @@ -13,7 +13,7 @@ #include #include -#define RA_BT_SERVICE_UUID "00001101-0000-1000-8000-00805F9B34FB" +#define RA_BT_SERVICE_UUID "8F5E6268-CFCD-4474-AFA2-0FEBFED72D73" #define RA_LEN_DELIM ':' #define RA_LEN_DELIM_STR ":" #define DELIM_LEN 2 -- 2.7.4 From d2d972c1932bd4e1b5cbc4b2ba03d7eddea06cd7 Mon Sep 17 00:00:00 2001 From: jkjo92 Date: Tue, 4 Jul 2017 19:53:35 +0900 Subject: [PATCH 16/16] fix memory leak Change-Id: I6d9772ee2a55911623b2f034ae9be028f60bb410 Signed-off-by: jkjo92 --- ui/src/asm_ui.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) mode change 100644 => 100755 ui/src/asm_ui.c diff --git a/ui/src/asm_ui.c b/ui/src/asm_ui.c old mode 100644 new mode 100755 index 77eebd3..7a84fa4 --- a/ui/src/asm_ui.c +++ b/ui/src/asm_ui.c @@ -627,43 +627,43 @@ app_control(app_control_h app_control, void *data) { dlog_print(DLOG_INFO, "org.tizen.asmui", "fido asm ui app_control"); - __ad->mode = NULL; + SAFE_DELETE(__ad->mode); app_control_get_extra_data(app_control, TC_UI_KEY_MODE, &(__ad->mode)); - __ad->nonce = NULL; + SAFE_DELETE(__ad->nonce); app_control_get_extra_data(app_control, TC_UI_KEY_NONCE, &(__ad->nonce)); if (strcmp(__ad->mode, TC_UI_VAL_MODE_TC) == 0) { - __ad->app_id_in = NULL; + SAFE_DELETE(__ad->app_id_in); app_control_get_extra_data(app_control, TC_UI_KEY_APP, &(__ad->app_id_in)); - __ad->text_in = NULL; + SAFE_DELETE(__ad->text_in); app_control_get_extra_data(app_control, TC_UI_KEY_TEXT, &(__ad->text_in)); show_tc_ui(); } else if (strcmp(__ad->mode, TC_UI_VAL_MODE_ACCOUNT) == 0) { - __ad->app_id_in = NULL; + SAFE_DELETE(__ad->app_id_in); app_control_get_extra_data(app_control, TC_UI_KEY_APP, &(__ad->app_id_in)); - __ad->text_list_in = NULL; + SAFE_DELETE(__ad->text_list_in); __ad->text_list_in_len = 0; app_control_get_extra_data_array(app_control, TC_UI_KEY_ACC_LIST, &(__ad->text_list_in), &(__ad->text_list_in_len)); show_account_ui(); - } else if (strcmp(__ad->mode, TC_UI_VAL_MODE_PIN_ENROLL) == 0) { - __ad->app_id_in = NULL; + } else if (strcmp(__ad->mode, TC_UI_VAL_MODE_PIN_ENROLL) == 0) { + SAFE_DELETE(__ad->app_id_in); app_control_get_extra_data(app_control, TC_UI_KEY_APP, &(__ad->app_id_in)); show_pin_ui_enroll(); } else if (strcmp(__ad->mode, TC_UI_VAL_MODE_PIN_VERIFY) == 0) { - __ad->app_id_in = NULL; + SAFE_DELETE(__ad->app_id_in); app_control_get_extra_data(app_control, TC_UI_KEY_APP, &(__ad->app_id_in)); - __ad->token_in = NULL; + SAFE_DELETE(__ad->token_in); app_control_get_extra_data(app_control, TC_UI_KEY_TOK, &(__ad->token_in)); show_pin_ui_verify(); @@ -686,6 +686,12 @@ static void app_terminate(void *data) { dlog_print(DLOG_INFO, "org.tizen.asmui", "fido asm ui app_terminate"); + SAFE_DELETE(__ad->mode); + SAFE_DELETE(__ad->nonce); + SAFE_DELETE(__ad->app_id_in); + SAFE_DELETE(__ad->text_in); + SAFE_DELETE(__ad->text_list_in); + SAFE_DELETE(__ad->token_in); } static void -- 2.7.4