summaryrefslogtreecommitdiff
path: root/gadget
diff options
context:
space:
mode:
authorKyungwook Tak <k.tak@samsung.com>2016-02-01 16:56:17 +0900
committerKyungwook Tak <k.tak@samsung.com>2016-02-02 16:32:48 +0900
commit76ec2c96010e505f2f3054001b2fa0cdcbe2e7e4 (patch)
tree0847292c001ad690e68322e605f79cbb10dd07e7 /gadget
parent39ee3a98394613824f37c60ae7ee6454a79902cc (diff)
downloadlibcryptsvc-76ec2c96010e505f2f3054001b2fa0cdcbe2e7e4.tar.gz
libcryptsvc-76ec2c96010e505f2f3054001b2fa0cdcbe2e7e4.tar.bz2
libcryptsvc-76ec2c96010e505f2f3054001b2fa0cdcbe2e7e4.zip
Refactor build system and add internal test
* Refine cmake files * Remove duplicated codes in duid-gadget * Add internal test * Remove useless files (.changes, NOTICE) Change-Id: I5cc7e16db85cc734d65794f8a505bcdd1dfd8726 Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
Diffstat (limited to 'gadget')
-rw-r--r--gadget/CMakeLists.txt40
-rw-r--r--gadget/duid-gadget.c54
2 files changed, 32 insertions, 62 deletions
diff --git a/gadget/CMakeLists.txt b/gadget/CMakeLists.txt
index dcb40c9..0a9b713 100644
--- a/gadget/CMakeLists.txt
+++ b/gadget/CMakeLists.txt
@@ -1,28 +1,34 @@
-SET(GADGET duid-gadget)
+PKG_CHECK_MODULES(GADGET_DEP REQUIRED ${CRYPTSVC_REQUIRES})
+
SET(GADGET_SRCS
- duid-gadget.c
- ../srcs/SecCryptoSvc.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/duid-gadget.c
+ ${PROJECT_SOURCE_DIR}/srcs/SecCryptoSvc.c
)
SET(GADGET_VENDOR samsung)
SET(GADGET_DIR ${TZ_SYS_ETC})
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
+INCLUDE_DIRECTORIES(
+ ${GADGET_DEP_INCLUDE_DIRS}
+ ${CMAKE_CURRENT_SOURCE_DIR}
+)
-INCLUDE(FindPkgConfig)
-PKG_CHECK_MODULES(GADGET_PKGS REQUIRED dlog openssl)
+SET(GADGET_CFLAGS "${GADGET_DEP_CFLAGS} -fPIE")
+SET(GADGET_CFLAGS "${GADGET_CFLAGS} -DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
+SET(GADGET_CFLAGS "${GADGET_CFLAGS} -DVENDOR=\"${GADGET_VENDOR}\"")
+SET(GADGET_CFLAGS "${GADGET_CFLAGS} -DAPP_NAME=\"${TARGET_GADGET}\"")
+SET(GADGET_CFLAGS "${GADGET_CFLAGS} -DAPP_DIR=\"${GADGET_DIR}\"")
-FOREACH(flag ${GADGET_PKGS_CFLAGS})
- SET(GADGET_CFLAGS "${GADGET_CFLAGS} ${flag} -fPIE")
-ENDFOREACH(flag)
+ADD_EXECUTABLE(${TARGET_GADGET} ${GADGET_SRCS})
-SET(GADGET_CFLAGS, "${GADGET_CFLAGS} -DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
-SET(GADGET_CFLAGS, "${GADGET_CFLAGS} -DVENDOR=\"${GADGET_VENDOR}\"")
-SET(GADGET_CFLAGS, "${GADGET_CFLAGS} -DAPP_NAME=\"${GADGET}\"")
-SET(GADGET_CFLAGS, "${GADGET_CFLAGS} -DAPP_DIR=\"${GADGET_DIR}\"")
+SET_TARGET_PROPERTIES(${TARGET_GADGET}
+ PROPERTIES
+ COMPILE_FLAGS "${GADGET_CFLAGS}"
+)
-ADD_EXECUTABLE(${GADGET} ${GADGET_SRCS})
-SET_TARGET_PROPERTIES(${GADGET} PROPERTIES COMPILE_FLAGS "${GADGET_CFLAGS}")
-TARGET_LINK_LIBRARIES(${GADGET} ${GADGET_PKGS_LDFLAGS} -pie)
+TARGET_LINK_LIBRARIES(${TARGET_GADGET}
+ ${GADGET_DEP_LDFLAGS}
+ -pie
+)
-INSTALL(TARGETS ${GADGET} DESTINATION ${GADGET_DIR} )
+INSTALL(TARGETS ${TARGET_GADGET} DESTINATION ${GADGET_DIR})
diff --git a/gadget/duid-gadget.c b/gadget/duid-gadget.c
index 48ff6f6..799b926 100644
--- a/gadget/duid-gadget.c
+++ b/gadget/duid-gadget.c
@@ -1,6 +1,5 @@
/*
- *
- * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2000 - 2016 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.
@@ -18,56 +17,21 @@
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
-
-#include <openssl/evp.h>
-#include <openssl/rand.h>
#include <SecCryptoSvc.h>
int main()
{
- const char *version = "1.0#";
- char info[] = {0xca, 0xfe, 0xbe, 0xbe, 0x78, 0x07, 0x02, 0x03};
-
- int ret = 0;
- int keyLen = 20;
- unsigned char *pKey = NULL;
- unsigned char *pDuid = NULL;
- char *pId = NULL;
- char *pKeyVersion = NULL;
-
- if (!(pKey = (unsigned char *)malloc(keyLen)))
- goto exit;
-
- if (!SecFrameGeneratePlatformUniqueKey(keyLen, pKey)) {
- fprintf(stderr, "Failed to get duid\n");
- goto exit;
- }
+ char *duid = GetDuid(20);
- if (!(pDuid = (unsigned char *)malloc(keyLen)))
- goto exit;
+ if (duid == NULL) {
+ fprintf(stderr, "Failed to get duid\n");
+ return 0;
+ }
- PKCS5_PBKDF2_HMAC_SHA1(info, 8, pKey, keyLen, 1, keyLen, pDuid);
+ printf("%s", duid);
- if (!(pId = Base64Encoding((char *)pDuid, keyLen)))
- goto exit;
+ free(duid);
- if (!(pKeyVersion = (char *)calloc(strlen(pId) + strlen(version) + 1, sizeof(char))))
- goto exit;
-
- strncpy(pKeyVersion, version, strlen(version));
- strncat(pKeyVersion, pId, strlen(pId));
- printf("%s", pKeyVersion);
-
- ret = 1;
-
-exit:
- free(pKey);
- free(pDuid);
- free(pId);
- free(pKeyVersion);
-
- return ret;
+ return 1;
}
-