Change privilege of imei, meid, icc_id getter API 63/215663/3 accepted/tizen/unified/20191017.114036 submit/tizen/20191015.081321 submit/tizen/20191016.084917
authorSemun Lee <semun.lee@samsung.com>
Mon, 14 Oct 2019 04:02:20 +0000 (13:02 +0900)
committersinikang <sinikang@samsung.com>
Wed, 16 Oct 2019 02:43:25 +0000 (11:43 +0900)
imei, meid, icc_id is a nonresettable unique idendifier.
An app should have "http://tizen.org/privilege/securesysteminfo"
which is a partner level privilege since 5.5.

For backward compatibility, apps with api-version of 5.0 or less
will get dummy value if they have "http://tizen.org/privilege/telephony"
privilege.

Change-Id: I00bb9d423a0a96cb6c133cbaf91374c55eae096f
Signed-off-by: Semun Lee <semun.lee@samsung.com>
CMakeLists.txt
include/telephony_private.h
packaging/capi-telephony.spec
src/telephony_modem.c
src/telephony_private.c [new file with mode: 0644]
src/telephony_sim.c

index 03d5de419feba9b569a98fa623090989ef7a604a..f3f97d396c29573b5b48193578429232052dc94f 100644 (file)
@@ -6,7 +6,9 @@ SET(version "0.0.1")
 SET(maintainer "Wootak Jung<wootak.jung@samsung.com>")
 SET(description "Telephony Core API")
 SET(service "telephony")
-SET(dependents "dlog tapi glib-2.0 capi-base-common openssl1.1 capi-system-info")
+SET(dependents "dlog tapi glib-2.0 \
+       capi-base-common openssl1.1 capi-system-info \
+       cynara-client cynara-session cynara-creds-self")
 SET(pc_dependents "capi-base-common tapi")
 
 SET(Services
index 48f09bb850948682dd82b8b6c05a99f8c9ff14d7..bffd24fa80a87a1eefef978116bc893f05b4babc 100644 (file)
@@ -88,4 +88,11 @@ typedef struct {
        bool conference_status; /**< true: Conference call, false: Single call */
 } telephony_call_info_s;
 
+/**
+ * @brief Check if the caller process has a privilege.
+ * @return @c 1 when the caller has the privilege,
+ *         otherwise 0
+ */
+bool telephony_check_legacy_telephony_privilege();
+
 #endif /* __CAPI_TELEPHONY_PRIVATE_H__ */
index f674ad8e1395acd4f61c59016c69cde4761c1028..849345fba2cccb14590b6773f71f62f079e5fdb9 100644 (file)
@@ -1,17 +1,20 @@
 Name:       capi-telephony
 Summary:    Telephony Core API
-Version:    0.1.81
+Version:    0.1.82
 Release:    1
 Group:      System/Libraries
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
-BuildRequires:  cmake
-BuildRequires:  pkgconfig(dlog)
-BuildRequires:  pkgconfig(tapi)
-BuildRequires:  pkgconfig(glib-2.0)
-BuildRequires:  pkgconfig(capi-base-common)
-BuildRequires:  pkgconfig(openssl1.1)
-BuildRequires:  pkgconfig(capi-system-info)
+BuildRequires: cmake
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(tapi)
+BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(capi-base-common)
+BuildRequires: pkgconfig(openssl1.1)
+BuildRequires: pkgconfig(capi-system-info)
+BuildRequires: pkgconfig(cynara-client)
+BuildRequires: pkgconfig(cynara-session)
+BuildRequires: pkgconfig(cynara-creds-self)
 Requires(post): /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
 
index 1ded51d70da2d2a3b9e6eb97be5f6cb7b578f286..45b92b2e7d35f4f4721013f0998d5e054f8dff86 100644 (file)
@@ -64,8 +64,13 @@ int telephony_modem_get_imei(telephony_h handle, char **imei)
                /* LCOV_EXCL_START */
                LOGE("g_dbus_conn failed. error (%s)", gerr->message);
                if (strstr(gerr->message, "AccessDenied")) {
-                       LOGE("PERMISSION_DENIED");
-                       error = TELEPHONY_ERROR_PERMISSION_DENIED;
+                       if (telephony_check_legacy_telephony_privilege()) {
+                               LOGI("return pseudo value");
+                               *imei = strdup("000000000000000");
+                       } else {
+                               LOGE("PERMISSION_DENIED");
+                               error = TELEPHONY_ERROR_PERMISSION_DENIED;
+                       }
                } else {
                        LOGE("OPERATION_FAILED");
                        error = TELEPHONY_ERROR_OPERATION_FAILED;
@@ -168,8 +173,13 @@ int telephony_modem_get_meid(telephony_h handle, char **meid)
                /* LCOV_EXCL_START */
                LOGE("g_dbus_conn failed. error (%s)", gerr->message);
                if (strstr(gerr->message, "AccessDenied")) {
-                       LOGE("PERMISSION_DENIED");
-                       ret = TELEPHONY_ERROR_PERMISSION_DENIED;
+                       if (telephony_check_legacy_telephony_privilege()) {
+                               LOGI("return pseudo value");
+                               *meid = strdup("000000000000000");
+                       } else {
+                               LOGE("PERMISSION_DENIED");
+                               ret = TELEPHONY_ERROR_PERMISSION_DENIED;
+                       }
                } else {
                        LOGE("OPERATION_FAILED");
                        ret = TELEPHONY_ERROR_OPERATION_FAILED;
diff --git a/src/telephony_private.c b/src/telephony_private.c
new file mode 100644 (file)
index 0000000..133b258
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2019 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.
+ */
+#define _GNU_SOURCE
+
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include <dlog.h>
+#include <cynara-client.h>
+#include <cynara-session.h>
+#include <cynara-creds-self.h>
+
+#include "telephony_private.h"
+
+static bool telephony_check_privilege(const char *privilege)
+{
+       cynara *cynara_handle;
+       char *client;
+       char *uid;
+       char *session;
+       int ret;
+
+       ret = cynara_initialize(&cynara_handle, NULL);
+       if (ret != CYNARA_API_SUCCESS) {
+               LOGE("failed to cynara_initialize: %d", ret);
+               return false;
+       }
+
+       session = cynara_session_from_pid(getpid());
+       if (!session) {
+               cynara_finish(cynara_handle);
+               LOGE("failed to get cynara session");
+               return false;
+       }
+
+       ret = cynara_creds_self_get_client(CLIENT_METHOD_SMACK, &client);
+       if (ret != CYNARA_API_SUCCESS) {
+               free(session);
+               cynara_finish(cynara_handle);
+               LOGE("failed to get cynara client cred: %d", ret);
+               return false;
+       }
+
+       ret = cynara_creds_self_get_user(USER_METHOD_UID, &uid);
+       if (ret != CYNARA_API_SUCCESS) {
+               free(client);
+               free(session);
+               cynara_finish(cynara_handle);
+               LOGE("failed to get cynara user cred: %d", ret);
+               return false;
+       }
+
+       ret = cynara_check(cynara_handle, client, session, uid, privilege);
+
+       free(uid);
+       free(client);
+       free(session);
+       cynara_finish(cynara_handle);
+
+       if (ret == CYNARA_API_ACCESS_ALLOWED)
+               return true;
+
+       return false;
+}
+
+bool telephony_check_legacy_telephony_privilege()
+{
+       char *api_version;
+
+       api_version = getenv("TIZEN_API_VERSION");
+
+       if (!api_version) {
+               LOGE("failed to find api version");
+               return false;
+       }
+
+       /* since Tizen 5.5, this function always returns  */
+       /* since Tizen 5.5, this function always returns false */
+       if (strverscmp(api_version, "5.5") >= 0)
+               return false;
+
+       return telephony_check_privilege(
+               "http://tizen.org/privilege/telephony");
+}
index 3f92db988f5a60cdd0aac7d2d2babc97c827637a..9e74940ecfaffb9ba7c8ddbb84d02355b2fd691e 100644 (file)
@@ -132,6 +132,15 @@ int telephony_sim_get_icc_id(telephony_h handle, char **icc_id)
                        /* LCOV_EXCL_START */
                        LOGE("g_dbus_conn failed. error (%s)", gerr->message);
                        error_code = _convert_dbus_errmsg_to_sim_error(gerr->message);
+                       if (error_code == TELEPHONY_ERROR_PERMISSION_DENIED) {
+                               if (telephony_check_legacy_telephony_privilege()) {
+                                       LOGI("return pseudo value");
+                                       *icc_id = strdup("0000000000000000000");
+                                       error_code = TELEPHONY_ERROR_NONE;
+                               } else {
+                                       LOGE("PERMISSION_DENIED");
+                               }
+                       }
                        g_error_free(gerr);
                        /* LCOV_EXCL_STOP */
                }