This commit is contained in:
Henry Case 2019-04-01 10:33:27 +01:00
parent 89b7376f8e
commit a761d870cd
5 changed files with 20 additions and 96 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
bssl/src/build
delegator/out
delegator/.Makefile.x86_temp

View File

@ -1,30 +1,3 @@
/*
* Copyright (c) 2016, Linaro Limited
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <tee_internal_api.h> #include <tee_internal_api.h>
@ -39,6 +12,12 @@
#define ATTR_REF(CNT, ATTR, BUF) \ #define ATTR_REF(CNT, ATTR, BUF) \
TEE_InitRefAttribute(&attrs[(CNT)++], (ATTR), (BUF).b, (BUF).sz) TEE_InitRefAttribute(&attrs[(CNT)++], (ATTR), (BUF).b, (BUF).sz)
#define LOG_RET(ret) \
if((ret)!=TEE_SUCCESS) { \
EMSG("ERR: %d %X", __LINE__, ret); \
return ret; \
}
/* /*
* Called when the instance of the TA is created. This is the first call in * Called when the instance of the TA is created. This is the first call in
* the TA. * the TA.
@ -101,6 +80,7 @@ void TA_CloseSessionEntryPoint(void __maybe_unused *sess_ctx)
EMSG("Goodbye!\n"); EMSG("Goodbye!\n");
} }
// Creates new RSA key
static TEE_ObjectHandle create_rsa_key(struct keypair_t *kp) { static TEE_ObjectHandle create_rsa_key(struct keypair_t *kp) {
TEE_Result res; TEE_Result res;
TEE_ObjectHandle obj = TEE_HANDLE_NULL; TEE_ObjectHandle obj = TEE_HANDLE_NULL;
@ -136,6 +116,7 @@ err:
return TEE_HANDLE_NULL; return TEE_HANDLE_NULL;
} }
// Creates new ECC key
static TEE_ObjectHandle create_ecc_key(struct keypair_t *kp) { static TEE_ObjectHandle create_ecc_key(struct keypair_t *kp) {
TEE_Result res; TEE_Result res;
TEE_ObjectHandle obj = TEE_HANDLE_NULL; TEE_ObjectHandle obj = TEE_HANDLE_NULL;
@ -170,6 +151,7 @@ err:
return TEE_HANDLE_NULL; return TEE_HANDLE_NULL;
} }
// Puts the key to the storage
static TEE_Result install_key(uint32_t param_types, static TEE_Result install_key(uint32_t param_types,
TEE_Param params[4]) TEE_Param params[4])
{ {
@ -222,6 +204,7 @@ static TEE_Result install_key(uint32_t param_types,
return TEE_SUCCESS; return TEE_SUCCESS;
} }
// Checks if key exists in the storage
static TEE_Result has_key(uint32_t param_types, TEE_Param params[4]) { static TEE_Result has_key(uint32_t param_types, TEE_Param params[4]) {
TEE_Result ret; TEE_Result ret;
uint32_t c = 0; uint32_t c = 0;
@ -260,7 +243,7 @@ static TEE_Result has_key(uint32_t param_types, TEE_Param params[4]) {
return TEE_SUCCESS; return TEE_SUCCESS;
} }
// Performs key deletion from the secure storage
static TEE_Result del_key(uint32_t param_types, TEE_Param params[4]) { static TEE_Result del_key(uint32_t param_types, TEE_Param params[4]) {
TEE_Result ret; TEE_Result ret;
char fname[SHA256_SIZE] = {0}; char fname[SHA256_SIZE] = {0};
@ -293,13 +276,8 @@ static TEE_Result del_key(uint32_t param_types, TEE_Param params[4]) {
return TEE_SUCCESS; return TEE_SUCCESS;
} }
#define LOG_RET(ret) \ // Performs ECDSA signing with a key from secure storage
if((ret)!=TEE_SUCCESS) { \ static TEE_Result sign_ecdsa(uint32_t param_types, TEE_Param params[4]) {
EMSG("ERR: %d %X", __LINE__, ret); \
return ret; \
}
static TEE_Result EcdsaSign(uint32_t param_types, TEE_Param params[4]) {
TEE_Result ret; TEE_Result ret;
TEE_OperationHandle op = TEE_HANDLE_NULL; TEE_OperationHandle op = TEE_HANDLE_NULL;
@ -365,7 +343,7 @@ TEE_Result TA_InvokeCommandEntryPoint(void __maybe_unused *sess_ctx,
case TA_DEL_KEYS: case TA_DEL_KEYS:
return del_key(param_types, params); return del_key(param_types, params);
case TA_SIGN_ECC: case TA_SIGN_ECC:
return EcdsaSign(param_types, params); return sign_ecdsa(param_types, params);
default: default:
return TEE_ERROR_BAD_PARAMETERS; return TEE_ERROR_BAD_PARAMETERS;
} }

View File

@ -1,29 +1,3 @@
/*
* Copyright (c) 2016-2017, Linaro Limited
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef TA_DELEGATOR_TZ_H #ifndef TA_DELEGATOR_TZ_H
#define TA_DELEGATOR_TZ_H #define TA_DELEGATOR_TZ_H

View File

@ -1,5 +1,5 @@
#ifndef headers_H_ #ifndef TYPES_H
#define headers_H_ #define TYPES_H
#include <stdint.h> #include <stdint.h>
#define MOVBSIGN(x) (-((x) >> 31)) #define MOVBSIGN(x) (-((x) >> 31))
@ -57,4 +57,4 @@ struct keypair_t {
} u; } u;
}; };
#endif // headers_H_ #endif // TYPES_H

View File

@ -1,34 +1,3 @@
/*
* Copyright (c) 2016-2017, Linaro Limited
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* The name of this file must not be modified
*/
#ifndef USER_TA_HEADER_DEFINES_H #ifndef USER_TA_HEADER_DEFINES_H
#define USER_TA_HEADER_DEFINES_H #define USER_TA_HEADER_DEFINES_H