#include <cstring>
#include <cstdlib>
#include <cassert>
+#include <mutex>
+
+#include <system_info.h>
#include "device_certificate_manager.h"
#include "dcm_client.h"
#define API_DEVICE_CERTIFICATE_MANAGER_EXPORT __attribute__((visibility("default")))
#endif
+std::once_flag check_flag;
+static int check_result;
+
+void check_feature(void)
+{
+ bool is_supported;
+ if (SYSTEM_INFO_ERROR_NONE != system_info_get_platform_bool(
+ "http://tizen.org/feature/security.device_certificate", &is_supported))
+ check_result = DCM_ERROR_UNKNOWN;
+ else if (!is_supported)
+ check_result = DCM_ERROR_NOT_SUPPORTED;
+ else
+ check_result = DCM_ERROR_NONE;
+}
+
+#define CHECK_FEATURE_SUPPORTED \
+ do { \
+ try { \
+ std::call_once(check_flag, check_feature); \
+ if (check_result != DCM_ERROR_NONE) \
+ return check_result; \
+ } catch (...) { \
+ return DCM_ERROR_UNKNOWN; \
+ } \
+ } while (0)
+
struct dcm_key_context_internal {
std::shared_ptr<dcm_client_connection> connection;
};
API_DEVICE_CERTIFICATE_MANAGER_EXPORT
int dcm_create_key_context(const char *service, const char *usage, const char *key_type, void **key_ctx)
{
+ CHECK_FEATURE_SUPPORTED;
+
try {
if(!key_ctx)
return DCM_ERROR_INVALID_PARAMETER;
API_DEVICE_CERTIFICATE_MANAGER_EXPORT
int dcm_free_key_context(void *key_ctx)
{
+ CHECK_FEATURE_SUPPORTED;
+
if(!key_ctx)
return DCM_ERROR_NONE;
API_DEVICE_CERTIFICATE_MANAGER_EXPORT
int dcm_get_certificate_chain(const void *key_ctx, char **cert_chain, size_t *cert_chain_len)
{
+ CHECK_FEATURE_SUPPORTED;
+
if(!key_ctx || !cert_chain || !cert_chain_len)
return DCM_ERROR_INVALID_PARAMETER;
API_DEVICE_CERTIFICATE_MANAGER_EXPORT
int dcm_get_key_bit_length(const void *key_ctx, size_t *key_bit_len)
{
+ CHECK_FEATURE_SUPPORTED;
+
if(!key_ctx || !key_bit_len)
return DCM_ERROR_INVALID_PARAMETER;
API_DEVICE_CERTIFICATE_MANAGER_EXPORT
int dcm_get_key_type(const void *key_ctx, char **key_type)
{
+ CHECK_FEATURE_SUPPORTED;
+
if(!key_ctx || !key_type)
return DCM_ERROR_INVALID_PARAMETER;
const char *message, size_t message_len,
char **signature, size_t *signature_len)
{
+ CHECK_FEATURE_SUPPORTED;
+
if(!key_ctx || !signature || !signature_len)
return DCM_ERROR_INVALID_PARAMETER;
size_t message_len,
dcm_e2ee_bundle_h* bundle)
{
+ CHECK_FEATURE_SUPPORTED;
+
if (message == NULL || bundle == NULL)
return DCM_ERROR_INVALID_PARAMETER;
const unsigned char** message,
size_t* message_len)
{
+ CHECK_FEATURE_SUPPORTED;
+
if (bundle == NULL || message == NULL || message_len == NULL)
return DCM_ERROR_INVALID_PARAMETER;
API_DEVICE_CERTIFICATE_MANAGER_EXPORT
int dcm_e2ee_get_bundle_platform(const dcm_e2ee_bundle_h bundle, const char** platform)
{
+ CHECK_FEATURE_SUPPORTED;
+
if (bundle == NULL || platform == NULL)
return DCM_ERROR_INVALID_PARAMETER;
API_DEVICE_CERTIFICATE_MANAGER_EXPORT
int dcm_e2ee_get_bundle_pkg_id(const dcm_e2ee_bundle_h bundle, const char** pkg_id)
{
+ CHECK_FEATURE_SUPPORTED;
+
if (bundle == NULL || pkg_id == NULL)
return DCM_ERROR_INVALID_PARAMETER;
const unsigned char** payload,
size_t* payload_len)
{
+ CHECK_FEATURE_SUPPORTED;
+
if (bundle == NULL || payload == NULL || payload_len == NULL)
return DCM_ERROR_INVALID_PARAMETER;
char **signature,
size_t *signature_len)
{
+ CHECK_FEATURE_SUPPORTED;
+
if (key_ctx == NULL || payload == NULL || bundle == NULL || signature == NULL ||
signature_len == NULL)
return DCM_ERROR_INVALID_PARAMETER;
* @return #DCM_ERROR_NONE on success, otherwise a negative error value
*
* @retval #DCM_ERROR_NONE Successful
+ * @retval #DCM_ERROR_NOT_SUPPORTED Feature needed to run API is not supported
* @retval #DCM_ERROR_INVALID_PARAMETER Input parameter is invalid (message = NULL or bundle = NULL)
* or the message format is invalid.
* @retval #DCM_ERROR_MSG_FORMAT The message is not in Tizen platform format.
+ * @retval #DCM_ERROR_UNKNOWN Unknown error
*
* @see dcm_e2ee_free_bundle()
* @see #dcm_e2ee_bundle_h
* @return #DCM_ERROR_NONE on success, otherwise a negative error value
*
* @retval #DCM_ERROR_NONE Successful
+ * @retval #DCM_ERROR_NOT_SUPPORTED Feature needed to run API is not supported
* @retval #DCM_ERROR_INVALID_PARAMETER @a bundle, @a message or @a message_len is NULL.
+ * @retval #DCM_ERROR_UNKNOWN Unknown error
*
* @see dcm_e2ee_create_signed_bundle()
* @see dcm_e2ee_free_bundle()
* @return #DCM_ERROR_NONE on success, otherwise a negative error value
*
* @retval #DCM_ERROR_NONE Successful
+ * @retval #DCM_ERROR_NOT_SUPPORTED Feature needed to run API is not supported
* @retval #DCM_ERROR_INVALID_PARAMETER @a bundle or @a platform is NULL.
+ * @retval #DCM_ERROR_UNKNOWN Unknown error
*
* @see dcm_e2ee_create_bundle()
* @see dcm_e2ee_free_bundle()
* @return #DCM_ERROR_NONE on success, otherwise a negative error value
*
* @retval #DCM_ERROR_NONE Successful
+ * @retval #DCM_ERROR_NOT_SUPPORTED Feature needed to run API is not supported
* @retval #DCM_ERROR_INVALID_PARAMETER @a bundle or @a pkg_id is NULL.
+ * @retval #DCM_ERROR_UNKNOWN Unknown error
*
* @see dcm_e2ee_create_bundle()
* @see dcm_e2ee_free_bundle()
* @return #DCM_ERROR_NONE on success, otherwise a negative error value
*
* @retval #DCM_ERROR_NONE Successful
+ * @retval #DCM_ERROR_NOT_SUPPORTED Feature needed to run API is not supported
* @retval #DCM_ERROR_INVALID_PARAMETER @a bundle, @a payload or @a payload_len is NULL.
+ * @retval #DCM_ERROR_UNKNOWN Unknown error
*
* @see dcm_e2ee_create_bundle()
* @see dcm_e2ee_free_bundle()