-
Notifications
You must be signed in to change notification settings - Fork 257
Add Application Secrets TEE client library #413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| project(asteec | ||
| VERSION 1.0.0 | ||
| LANGUAGES C | ||
| ) | ||
|
|
||
| add_compile_options(${C_COMPILE_OPTIONS}) | ||
|
|
||
| include(GNUInstallDirs) | ||
|
|
||
| ################################################################################ | ||
| # Source files | ||
| ################################################################################ | ||
| set(SRC | ||
| src/asteec.c | ||
| ) | ||
|
|
||
| ################################################################################ | ||
| # Built library | ||
| ################################################################################ | ||
| add_library(asteec ${SRC}) | ||
|
|
||
| configure_file(asteec.pc.in asteec.pc @ONLY) | ||
|
|
||
| set_target_properties(asteec PROPERTIES | ||
| VERSION ${PROJECT_VERSION} | ||
| SOVERSION ${PROJECT_VERSION_MAJOR} | ||
| ) | ||
|
|
||
| ################################################################################ | ||
| # Flags always set | ||
| ################################################################################ | ||
| target_compile_definitions(asteec | ||
| PRIVATE -D_GNU_SOURCE | ||
| PRIVATE -DBINARY_PREFIX="LT" | ||
| ) | ||
|
|
||
| ################################################################################ | ||
| # Public and private header and library dependencies | ||
| ################################################################################ | ||
| target_include_directories(asteec PUBLIC | ||
| $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> | ||
| $<INSTALL_INTERFACE:include> | ||
| ) | ||
|
|
||
| target_link_libraries(asteec | ||
| PRIVATE teec | ||
| ) | ||
|
|
||
| ################################################################################ | ||
| # Install targets | ||
| ################################################################################ | ||
| install(TARGETS asteec | ||
| DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
| ) | ||
|
|
||
| install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") | ||
|
|
||
| install(FILES "${CMAKE_CURRENT_BINARY_DIR}/asteec.pc" | ||
| DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| include ../flags.mk | ||
| include ../config.mk | ||
|
|
||
| OUT_DIR := $(OO)/libasteec | ||
|
|
||
| .PHONY: all libasteec clean | ||
|
|
||
| all: libasteec | ||
| install: libasteec | ||
|
|
||
| LIB_NAME := libasteec | ||
| MAJOR_VERSION := 1 | ||
| MINOR_VERSION := 0 | ||
| PATCH_VERSION := 0 | ||
|
|
||
| LIB_MAJOR := $(LIB_NAME).so.$(MAJOR_VERSION) | ||
| LIB_MAJ_MIN := $(LIB_NAME).so.$(MAJOR_VERSION).$(MINOR_VERSION) | ||
| LIB_MAJ_MIN_PAT := $(LIB_NAME).so.$(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION) | ||
| LIBASTEEC_SO_LIBRARY := $(LIB_MAJ_MIN_PAT) | ||
| LIBASTEEC_AR_LIBRARY := $(LIB_NAME).a | ||
|
|
||
| LIBASTEEC_SRC_DIR := src | ||
|
|
||
| LIBASTEEC_SRCS = asteec.c | ||
|
|
||
| LIBASTEEC_INCLUDES = ${CURDIR}/include | ||
| LIBASTEEC_INCLUDES += ${CURDIR}/../libteec/include | ||
|
|
||
| LIBASTEEC_CFLAGS := $(addprefix -I, $(LIBASTEEC_INCLUDES)) \ | ||
| $(CFLAGS) -D_GNU_SOURCE -fPIC | ||
|
|
||
| LIBASTEEC_LFLAGS := $(LDFLAGS) -L$(OUT_DIR)/../libteec -lteec | ||
|
|
||
| LIBASTEEC_OBJ_DIR := $(OUT_DIR) | ||
| LIBASTEEC_OBJS := $(patsubst %.c,$(LIBASTEEC_OBJ_DIR)/%.o, $(LIBASTEEC_SRCS)) | ||
|
|
||
| $(LIBASTEEC_OBJ_DIR)/%.o: ${LIBASTEEC_SRC_DIR}/%.c | ||
| $(VPREFIX)mkdir -p $(LIBASTEEC_OBJ_DIR) | ||
| @echo " CC $<" | ||
| $(VPREFIX)$(CC) $(LIBASTEEC_CFLAGS) -c $< -o $@ | ||
|
|
||
| libasteec: $(OUT_DIR)/$(LIBASTEEC_SO_LIBRARY) | ||
|
|
||
| $(OUT_DIR)/$(LIBASTEEC_SO_LIBRARY): $(LIBASTEEC_OBJS) | ||
| @echo " LINK $@" | ||
| $(VPREFIX)$(CC) -shared -Wl,-soname,$(LIB_MAJOR) -o $@ $+ $(LIBASTEEC_LFLAGS) | ||
| @echo "" | ||
|
|
||
| libasteec: $(OUT_DIR)/$(LIBASTEEC_AR_LIBRARY) | ||
|
|
||
| $(OUT_DIR)/$(LIBASTEEC_AR_LIBRARY): $(LIBASTEEC_OBJS) | ||
| @echo " AR $@" | ||
| $(VPREFIX)$(AR) rcs $@ $+ | ||
|
|
||
| libasteec: | ||
| $(VPREFIX)ln -sf $(LIB_MAJ_MIN_PAT) $(OUT_DIR)/$(LIB_MAJ_MIN) | ||
| $(VPREFIX)ln -sf $(LIB_MAJ_MIN) $(OUT_DIR)/$(LIB_MAJOR) | ||
| $(VPREFIX)ln -sf $(LIB_MAJOR) $(OUT_DIR)/$(LIB_NAME).so | ||
|
|
||
| ################################################################################ | ||
| # Cleaning up configuration | ||
| ################################################################################ | ||
| clean: | ||
| $(RM) $(LIBASTEEC_OBJS) | ||
| $(RM) $(OUT_DIR)/$(LIB_MAJ_MIN_PAT) | ||
| $(RM) $(OUT_DIR)/$(LIB_MAJ_MIN) | ||
| $(RM) $(OUT_DIR)/$(LIB_MAJOR) | ||
| $(RM) $(OUT_DIR)/$(LIBASTEEC_SO_LIBRARY) | ||
| $(RM) $(OUT_DIR)/$(LIBASTEEC_AR_LIBRARY) | ||
| $(call rmdir,$(OUT_DIR)) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| prefix="@CMAKE_INSTALL_PREFIX@" | ||
| exec_prefix="${prefix}" | ||
| libdir="${prefix}/lib" | ||
| includedir="${prefix}/include" | ||
|
|
||
| Name: @PROJECT_NAME@ | ||
| Description: Application Secrets TEE Client library | ||
| Version: @PROJECT_VERSION@ | ||
| Requires: teec | ||
| Cflags: -I"${includedir}" | ||
| Libs: -L"${libdir}" -lasteec |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* SPDX-License-Identifier: BSD-2-Clause */ | ||
| /* | ||
| * Copyright (c) 2026, Vaisala Oyj. | ||
| */ | ||
|
|
||
| #ifndef ASTEEC_H | ||
| #define ASTEEC_H | ||
|
|
||
| #include <stddef.h> | ||
| #include <stdint.h> | ||
| #include <sys/types.h> | ||
| #include <tee_client_api.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /** | ||
| * asteec_seal() - Seal secret using hardware unique TA specific key | ||
| * | ||
| * @param login_method Login method such as TEEC_LOGIN_PUBLIC or TEEC_LOGIN_GROUP | ||
| * @param login_gid Group ID, used with TEEC_LOGIN_GROUP and | ||
| * TEEC_LOGIN_GROUP_APPLICATION methods | ||
| * @param plain Pointer to plain secret | ||
| * @param plain_len Byte length of plain secret | ||
| * @param sealed Pointer to buffer to receive sealed secret datablob. | ||
| * May be NULL when *sealed_len is 0 to query the | ||
| * required output size. | ||
| * @param sealed_len On input, byte length of buffer @sealed. On output, | ||
| * updated with the actual size on success or the required | ||
| * size when TEEC_ERROR_SHORT_BUFFER is returned. | ||
| * | ||
| * @return TEEC_SUCCESS on success, TEEC_ERROR_* on failure | ||
| */ | ||
| TEEC_Result asteec_seal(uint32_t login_method, gid_t login_gid, | ||
| const void *plain, size_t plain_len, | ||
| void *sealed, size_t *sealed_len); | ||
|
|
||
| /** | ||
| * asteec_unseal() - Unseal secret using hardware unique TA specific key | ||
| * | ||
| * @param login_method Login method such as TEEC_LOGIN_PUBLIC or TEEC_LOGIN_GROUP | ||
| * @param login_gid Group ID, used with TEEC_LOGIN_GROUP and | ||
| * TEEC_LOGIN_GROUP_APPLICATION methods | ||
| * @param sealed Pointer to sealed secret datablob | ||
| * @param sealed_len Byte length of sealed secret datablob | ||
| * @param plain Pointer to buffer to receive plain secret. | ||
| * May be NULL when *plain_len is 0 to query the | ||
| * required output size. | ||
| * @param plain_len On input, byte length of buffer @plain. On output, | ||
| * updated with the actual size on success or the required | ||
| * size when TEEC_ERROR_SHORT_BUFFER is returned. | ||
| * | ||
| * @return TEEC_SUCCESS on success, TEEC_ERROR_* on failure | ||
| */ | ||
| TEEC_Result asteec_unseal(uint32_t login_method, gid_t login_gid, | ||
| const void *sealed, size_t sealed_len, | ||
| void *plain, size_t *plain_len); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* ASTEEC_H */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* SPDX-License-Identifier: BSD-2-Clause */ | ||
| /* | ||
| * Copyright (c) 2026, Vaisala Oyj. | ||
| */ | ||
|
|
||
| #ifndef APP_SECRETS_TA_H | ||
| #define APP_SECRETS_TA_H | ||
|
|
||
| #define APP_SECRETS_TA_UUID \ | ||
| { 0x5ca4d9d9, 0xdee4, 0x47f4, \ | ||
| { 0x97, 0x7a, 0x7e, 0xad, 0xc0, 0x60, 0xe5, 0x2c } } | ||
|
|
||
| /* | ||
| * Seal secret using hardware unique TA specific key | ||
| * | ||
| * [in] memref[0] Plain secret | ||
| * [out] memref[1] Sealed secret datablob | ||
| */ | ||
| #define TA_APPSECRETS_CMD_SEAL_SECRET 0x0 | ||
|
|
||
| /* | ||
| * Unseal secret using hardware unique TA specific key | ||
| * | ||
| * [in] memref[0] Sealed secret datablob | ||
| * [out] memref[1] Plain secret | ||
| */ | ||
| #define TA_APPSECRETS_CMD_UNSEAL_SECRET 0x1 | ||
|
|
||
| #endif /* APP_SECRETS_TA_H */ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest making the build of this library optional like for libteecacl: