From 42e5cbc45341544c1dcceeeab8dc7cbc7c3cc569 Mon Sep 17 00:00:00 2001 From: Dongsun Lee Date: Mon, 2 Feb 2026 11:04:27 +0900 Subject: [PATCH] [Tizen.Security.TEEC][TCSACR-640] Remove all Tizen.Security.TEEC APIs --- src/Tizen.Security.TEEC/.gitignore | 1 - .../Interop/Interop.Errors.cs | 43 - .../Interop/Interop.Libraries.cs | 23 - .../Interop/Interop.Libteec.cs | 130 --- .../Interop/Interop.Types.cs | 167 --- .../Tizen.Security.TEEC.csproj | 13 - .../Tizen.Security.TEEC.sln | 34 - .../Tizen.Security.TEEC/Libteec.cs | 1037 ----------------- .../doc/api/Tizen.Security.TEEC.md | 58 - 9 files changed, 1506 deletions(-) delete mode 100644 src/Tizen.Security.TEEC/.gitignore delete mode 100644 src/Tizen.Security.TEEC/Interop/Interop.Errors.cs delete mode 100644 src/Tizen.Security.TEEC/Interop/Interop.Libraries.cs delete mode 100644 src/Tizen.Security.TEEC/Interop/Interop.Libteec.cs delete mode 100644 src/Tizen.Security.TEEC/Interop/Interop.Types.cs delete mode 100644 src/Tizen.Security.TEEC/Tizen.Security.TEEC.csproj delete mode 100755 src/Tizen.Security.TEEC/Tizen.Security.TEEC.sln delete mode 100644 src/Tizen.Security.TEEC/Tizen.Security.TEEC/Libteec.cs delete mode 100644 src/Tizen.Security.TEEC/doc/api/Tizen.Security.TEEC.md diff --git a/src/Tizen.Security.TEEC/.gitignore b/src/Tizen.Security.TEEC/.gitignore deleted file mode 100644 index a6c57f5fb2f..00000000000 --- a/src/Tizen.Security.TEEC/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.json diff --git a/src/Tizen.Security.TEEC/Interop/Interop.Errors.cs b/src/Tizen.Security.TEEC/Interop/Interop.Errors.cs deleted file mode 100644 index f79c033af8a..00000000000 --- a/src/Tizen.Security.TEEC/Interop/Interop.Errors.cs +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Interop.Errors.cs - * - * Created on: Apr 4, 2017 - * Author: k.dynowski - */ - -using System; - -internal static partial class Interop -{ - - private const string LogTag = "Tizen.Security.Libteec"; - internal enum LibteecError : uint - { - None = 0, - Generic = 0xFFFF0000, - NotImplemented = 0xFFFF0009, - NotSupported = 0xFFFF000A, - CommunicationFailed = 0xFFFF000E, - }; - - internal static void CheckNThrowException(int err, string msg) - { - switch ((uint)err) - { - case (uint)LibteecError.None: - return ; - case (uint)LibteecError.NotImplemented: - case (uint)LibteecError.NotSupported: - throw new NotSupportedException(string.Format("[{0}] {1} error=0x{2}", - LogTag, msg, err.ToString("X"))); - case (uint)LibteecError.CommunicationFailed: - case (uint)LibteecError.Generic: - throw new Exception(string.Format("[{0}] {1} error=0x{2}", - LogTag, msg, err.ToString("X"))); - default: - throw new InvalidOperationException(string.Format("[{0}] {1}, error=0x{2}", - LogTag, msg, err.ToString("X"))); - - } - } -} diff --git a/src/Tizen.Security.TEEC/Interop/Interop.Libraries.cs b/src/Tizen.Security.TEEC/Interop/Interop.Libraries.cs deleted file mode 100644 index 25c903eeb72..00000000000 --- a/src/Tizen.Security.TEEC/Interop/Interop.Libraries.cs +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 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. - * 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 - */ - -internal static partial class Interop -{ - internal static partial class Libraries - { - public const string Libteec = "libteec.so"; - } -} diff --git a/src/Tizen.Security.TEEC/Interop/Interop.Libteec.cs b/src/Tizen.Security.TEEC/Interop/Interop.Libteec.cs deleted file mode 100644 index 4b3f59b8bfc..00000000000 --- a/src/Tizen.Security.TEEC/Interop/Interop.Libteec.cs +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2017 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 - */ - -using System; -using System.Runtime.InteropServices; -//using Interop.Liibteec.Types; - -internal static partial class Interop -{ - internal static partial class Libteec - { - /// - /// This function initializes a new TEE Context, forming a connection between this client application and the - /// TEE identified by the string identifier name. - /// The client application may pass a name with a value of null, which means that the implementation must - /// select a default TEE to connect to. The supported name strings, the mapping of these names to a specific - /// TEE, and the nature of the default TEE are implementation-defined. - /// - //TEEC_Result TEEC_InitializeContext(const char *name, TEEC_Context *context); - [DllImport(Libraries.Libteec, EntryPoint = "TEEC_InitializeContext", CallingConvention = CallingConvention.Cdecl)] - static public extern int InitializeContext(string name, IntPtr context); - - /// - /// This function destroys an initialized TEE Context, closing the connection between the client application - /// and the TEE. The client application must only call this function when all sessions inside this TEE - /// context have been closed and all shared memory blocks have been released. - /// The implementation of this function must not fail; after this function returns, the client - /// application must be able to consider that the context has been closed. - /// The function implementation must do nothing if the value of the context pointer is null. - /// - //void TEEC_FinalizeContext(TEEC_Context *context); - [DllImport(Libraries.Libteec, EntryPoint = "TEEC_FinalizeContext", CallingConvention = CallingConvention.Cdecl)] - static public extern void FinalizeContext(IntPtr context); - - /// - /// This function registers a block of existing client application memory as a block of shared memory within - /// the scope of the specified TEE Context, in accordance with the parameters which have been set by the - /// client application inside the shared memory structure. - /// The input context must point to an initialized TEE Context. - /// The input shared Memory must point to the shared memory structure defining the memory region to register. - /// - //EEC_Result TEEC_RegisterSharedMemory(TEEC_Context *context, TEEC_SharedMemory *sharedMem); - [DllImport(Libraries.Libteec, EntryPoint = "TEEC_RegisterSharedMemory", CallingConvention = CallingConvention.Cdecl)] - static public extern int RegisterSharedMemory(IntPtr context, ref TEEC_SharedMemory sharedMem); - - /// - /// This function allocates a new block of memory as a block of shared memory within the scope of the - /// specified TEE Context, in accordance with the parameters which have been set by the client application - /// inside the shared memory structure. - /// The input context must point to an initialized TEE Context. - /// The input shared memory must point to the shared memory structure defining the region to allocate. - /// - //TEEC_Result TEEC_AllocateSharedMemory(TEEC_Context *context, TEEC_SharedMemory *sharedMem); - [DllImport(Libraries.Libteec, EntryPoint = "TEEC_AllocateSharedMemory", CallingConvention = CallingConvention.Cdecl)] - static public extern int AllocateSharedMemory(IntPtr context, ref TEEC_SharedMemory sharedMem); - - /// - /// This function deregisters or deallocates a previously initialized block of the shared memory. - /// For a memory buffer allocated using AllocateSharedMemory, the implementation must free the - /// underlying memory and the client application must not access this region after this function has been - /// called. In this case, the implementation must set the buffer and size fields of the shared memory - /// structure to null and 0 respectively before returning. - /// For memory registered using RegisterSharedMemory, the implementation must deregister the - /// underlying memory from the TEE, but the memory region will stay available to the client application for - /// other purposes as the memory is owned by it. - /// The implementation must do nothing if the value of the shared memory parameter is null. - /// - //void TEEC_ReleaseSharedMemory(TEEC_SharedMemory *sharedMem); - [DllImport(Libraries.Libteec, EntryPoint = "TEEC_ReleaseSharedMemory", CallingConvention = CallingConvention.Cdecl)] - static public extern void ReleaseSharedMemory(ref TEEC_SharedMemory sharedMem); - - /// - /// This function opens a new session between the client application and the specified trusted application. - /// The implementation must assume that all fields of this session structure are in an undefined state. - /// When this function returns TEEC_SUCCESS, the implementation must have populated this structure with - /// any information necessary for subsequent operations within the session. - /// The target trusted application is identified by the UUID passed in the parameter destination. - /// - //TEEC_Result TEEC_OpenSession(TEEC_Context *context, TEEC_Session *session, const TEEC_UUID *destination, uint connectionMethod, const void *connectionData, TEEC_Operation *operation, uint *returnOrigin); - [DllImport(Libraries.Libteec, EntryPoint = "TEEC_OpenSession", CallingConvention = CallingConvention.Cdecl)] - static public extern int OpenSession(IntPtr context, IntPtr session, ref TEEC_UUID destination, uint connectionMethod, byte[] connectionData, IntPtr operation, out uint returnOrigin); - - /// - /// This function closes a session which has been opened with a trusted application. - /// All commands within the session must have completed before this function can be called. - /// The implementation must do nothing if the input session parameter is null. - /// The implementation of this function must not fail; after this function returns, the Client - /// Application must be able to consider that the session has been closed. - /// - //void TEEC_CloseSession(TEEC_Session *session); - [DllImport(Libraries.Libteec, EntryPoint = "TEEC_CloseSession", CallingConvention = CallingConvention.Cdecl)] - static public extern void CloseSession(IntPtr session); - - /// - /// This function invokes a command within the specified session. - /// The parameter session must point to a valid open session. - /// The parameter commandID is an identifier that is used to indicate which of the exposed Trusted - /// Application functions should be invoked. The supported command identifier values are defined by the - /// trusted application's protocol. - /// - //TEEC_Result TEEC_InvokeCommand(TEEC_Session *session, uint commandID, TEEC_Operation *operation, uint *returnOrigin); - [DllImport(Libraries.Libteec, EntryPoint = "TEEC_InvokeCommand", CallingConvention = CallingConvention.Cdecl)] - static public extern int InvokeCommand(IntPtr session, uint commandID, IntPtr operation, out uint returnOrigin); - - /// - /// This function requests the cancelation of a pending open session operation or a command invocation - /// operation. As this is a synchronous API, this function must be called from a thread other than the one - /// executing the OpenSession or InvokeCommand function. - /// This function just sends a cancelation signal to the TEE and returns immediately; the operation is not - /// guaranteed to have been canceled when this function returns. In addition, the cancelation request is just - /// a hint; the TEE or the trusted application may ignore the cancelation request. - /// - //void TEEC_RequestCancellation(TEEC_Operation *operation); - [DllImport(Libraries.Libteec, EntryPoint = "TEEC_RequestCancellation", CallingConvention = CallingConvention.Cdecl)] - static public extern void RequestCancellation(IntPtr operation); - } -} diff --git a/src/Tizen.Security.TEEC/Interop/Interop.Types.cs b/src/Tizen.Security.TEEC/Interop/Interop.Types.cs deleted file mode 100644 index 0763d4553dc..00000000000 --- a/src/Tizen.Security.TEEC/Interop/Interop.Types.cs +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (c) 2017 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 - */ - - -using System; -using System.Runtime.InteropServices; -using Tizen.Internals; - -internal static partial class Interop -{ -#if PROFILE_TV - private const string PkgConfig = "trustzone-nwd"; -#else - private const string PkgConfig = "tef-libteec"; -#endif - - - [NativeStruct("TEEC_Context", Include="tee_client_api.h", PkgConfig=PkgConfig)] - [StructLayout(LayoutKind.Sequential)] - internal struct TEEC_Context - { - public readonly IntPtr imp; - } - - [NativeStruct("TEEC_Session", Include="tee_client_api.h", PkgConfig=PkgConfig)] - [StructLayout(LayoutKind.Sequential)] - internal struct TEEC_Session - { - public readonly IntPtr imp; - } - - [NativeStruct("TEEC_UUID", Include="tee_client_api.h", PkgConfig=PkgConfig)] - [StructLayout(LayoutKind.Sequential)] - internal struct TEEC_UUID - { - public UInt32 timeLow; - public UInt16 timeMid; - public UInt16 timeHiAndVersion; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] - public byte[] clockSeqAndNode; - - internal static TEEC_UUID ToTeecUuid(Guid guid) - { - TEEC_UUID uuid = new TEEC_UUID(); - byte[] bin = guid.ToByteArray(); - uuid.timeLow = BitConverter.ToUInt32(bin, 0); - uuid.timeMid = BitConverter.ToUInt16(bin, 4); - uuid.timeHiAndVersion = BitConverter.ToUInt16(bin, 6); - uuid.clockSeqAndNode = new byte[8]; - Array.Copy(bin, 8, uuid.clockSeqAndNode, 0, 8); - return uuid; - } - } - - [NativeStruct("TEEC_SharedMemory", Include="tee_client_api.h", PkgConfig=PkgConfig)] - [StructLayout(LayoutKind.Sequential,Pack=8)] - internal struct TEEC_SharedMemory - { - public IntPtr buffer; - public UIntPtr size; - public UInt32 flags; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)] - public byte[] padding; - } - - [NativeStruct("TEEC_Value", Include="tee_client_api.h", PkgConfig=PkgConfig)] - [StructLayout(LayoutKind.Sequential,Pack=8)] - internal struct TEEC_Value - { - public UInt32 a; - public UInt32 b; - } - - [NativeStruct("TEEC_TempMemoryReference", Include="tee_client_api.h", PkgConfig=PkgConfig, Arch=NativeStructArch.Only32Bits)] - [StructLayout(LayoutKind.Sequential)] - internal struct TEEC_TempMemoryReference32 - { - public Int32 buffer; - public UInt32 size; - } - - [NativeStruct("TEEC_RegisteredMemoryReference", Include="tee_client_api.h", PkgConfig=PkgConfig, Arch=NativeStructArch.Only32Bits)] - [StructLayout(LayoutKind.Sequential)] - internal struct TEEC_RegisteredMemoryReference32 - { - public Int32 parent; - public UInt32 size; - public UInt32 offset; - } - - [NativeStruct("TEEC_Parameter", Include="tee_client_api.h", PkgConfig=PkgConfig, Arch=NativeStructArch.Only32Bits)] - [StructLayout(LayoutKind.Explicit)] - internal struct TEEC_Parameter32 - { - [FieldOffset(0)] - public TEEC_TempMemoryReference32 tmpref; - [FieldOffset(0)] - public TEEC_RegisteredMemoryReference32 memref; - [FieldOffset(0)] - public TEEC_Value value; - } - - [NativeStruct("TEEC_Operation", Include="tee_client_api.h", PkgConfig=PkgConfig, Arch=NativeStructArch.Only32Bits)] - [StructLayout(LayoutKind.Sequential)] - internal struct TEEC_Operation32 - { - public UInt32 started; - public UInt32 paramTypes; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] - public TEEC_Parameter32[] paramlist; - public IntPtr imp; - } - - [NativeStruct("TEEC_TempMemoryReference", Include="tee_client_api.h", PkgConfig=PkgConfig, Arch=NativeStructArch.Only64Bits)] - [StructLayout(LayoutKind.Sequential)] - internal struct TEEC_TempMemoryReference64 - { - public Int64 buffer; - public UInt64 size; - } - - [NativeStruct("TEEC_RegisteredMemoryReference", Include="tee_client_api.h", PkgConfig=PkgConfig, Arch=NativeStructArch.Only64Bits)] - [StructLayout(LayoutKind.Sequential)] - internal struct TEEC_RegisteredMemoryReference64 - { - public Int64 parent; - public UInt64 size; - public UInt64 offset; - } - - [NativeStruct("TEEC_Parameter", Include="tee_client_api.h", PkgConfig=PkgConfig, Arch=NativeStructArch.Only64Bits)] - [StructLayout(LayoutKind.Explicit)] - internal struct TEEC_Parameter64 - { - [FieldOffset(0)] - public TEEC_TempMemoryReference64 tmpref; - [FieldOffset(0)] - public TEEC_RegisteredMemoryReference64 memref; - [FieldOffset(0)] - public TEEC_Value value; - } - - [NativeStruct("TEEC_Operation", Include="tee_client_api.h", PkgConfig=PkgConfig, Arch=NativeStructArch.Only64Bits)] - [StructLayout(LayoutKind.Sequential)] - internal struct TEEC_Operation64 - { - public UInt32 started; - public UInt32 paramTypes; - [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] - public TEEC_Parameter64[] paramlist; - public IntPtr imp; - } -} - diff --git a/src/Tizen.Security.TEEC/Tizen.Security.TEEC.csproj b/src/Tizen.Security.TEEC/Tizen.Security.TEEC.csproj deleted file mode 100644 index 6a5b48894b1..00000000000 --- a/src/Tizen.Security.TEEC/Tizen.Security.TEEC.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - net8.0 - - - - - - - - - diff --git a/src/Tizen.Security.TEEC/Tizen.Security.TEEC.sln b/src/Tizen.Security.TEEC/Tizen.Security.TEEC.sln deleted file mode 100755 index 3d3a8794bf4..00000000000 --- a/src/Tizen.Security.TEEC/Tizen.Security.TEEC.sln +++ /dev/null @@ -1,34 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26430.12 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.Security.TEEC", "Tizen.Security.TEEC.csproj", "{97FA66C9-A286-42FF-ADDC-80DC8CC9E446}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen", "..\Tizen\Tizen.csproj", "{6E871A27-B671-400B-A05D-58A6B3CBDAED}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.Log", "..\Tizen.Log\Tizen.Log.csproj", "{E8348A68-09CD-427F-A0E3-0A36E37B949D}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {97FA66C9-A286-42FF-ADDC-80DC8CC9E446}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {97FA66C9-A286-42FF-ADDC-80DC8CC9E446}.Debug|Any CPU.Build.0 = Debug|Any CPU - {97FA66C9-A286-42FF-ADDC-80DC8CC9E446}.Release|Any CPU.ActiveCfg = Release|Any CPU - {97FA66C9-A286-42FF-ADDC-80DC8CC9E446}.Release|Any CPU.Build.0 = Release|Any CPU - {6E871A27-B671-400B-A05D-58A6B3CBDAED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6E871A27-B671-400B-A05D-58A6B3CBDAED}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6E871A27-B671-400B-A05D-58A6B3CBDAED}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6E871A27-B671-400B-A05D-58A6B3CBDAED}.Release|Any CPU.Build.0 = Release|Any CPU - {E8348A68-09CD-427F-A0E3-0A36E37B949D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E8348A68-09CD-427F-A0E3-0A36E37B949D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E8348A68-09CD-427F-A0E3-0A36E37B949D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E8348A68-09CD-427F-A0E3-0A36E37B949D}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/src/Tizen.Security.TEEC/Tizen.Security.TEEC/Libteec.cs b/src/Tizen.Security.TEEC/Tizen.Security.TEEC/Libteec.cs deleted file mode 100644 index 40719ee485b..00000000000 --- a/src/Tizen.Security.TEEC/Tizen.Security.TEEC/Libteec.cs +++ /dev/null @@ -1,1037 +0,0 @@ -/* - * Copyright (c) 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. - * 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 - */ - -using System; -using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Threading; -using System.Threading.Tasks; -using System.Runtime.CompilerServices; -using System.IO; - -namespace Tizen.Security.TEEC -{ - /// - /// This type denotes the Session Login Method used in OpenSession. - /// - /// 3 - public class LoginMethod - { - /// No login data is provided. - /// 3 - public const uint Public = 0x00000000; - /// Login data about the user running the client application process is provided. - /// 3 - public const uint User = 0x00000001; - /// Login data about the group running the client application process is provided. - /// 3 - public const uint Group = 0x00000002; - /// Login data about the running client application itself is provided. - /// 3 - public const uint Application = 0x00000003; - } - - /// - /// This type denotes the Value parameter. - /// - /// 3 - public enum TEFValueType : UInt32 - { - /// The parameter is a ValueType tagged as the input. - Input = 0x00000001, - /// The parameter is a ValueType tagged as the output. - Output = 0x00000002, - /// The parameter is a ValueType tagged as both the input and the output. - InOut = 0x00000003, - } - - /// - /// This type denotes the TempMemoryReference parameter - /// describing a region of memory which needs to be temporarily registered for the duration of the operation. - /// - /// 3 - public enum TEFTempMemoryType : UInt32 - { - /// The parameter is a TempMemoryType and is tagged as the input. - Input = 0x00000005, - /// Same as the input, but the Memory Reference is tagged as the output. - Output = 0x00000006, - /// A Temporary Memory Reference tagged as both the input and the output. - InOut = 0x00000007, - } - - /// - /// This type denotes the SharedMemoryReference parameter. - /// - /// 3 - public enum TEFRegisteredMemoryType : UInt32 - { - /// The parameter is a registered memory reference that refers to the entirety of its parent shared memory block. - Whole = 0x0000000C, - /// A registered memory reference structure that refers to a partial region of its parent shared mMemory block and is tagged as the input. - PartialInput = 0x0000000D, - /// A registered memory reference structure that refers to a partial region of its parent shared memory block and is tagged as the output. - PartialOutput = 0x0000000E, - /// A registered memory reference structure that refers to a partial region of its parent shared memory block and is tagged as both the input and the output. - PartialInOut = 0x0000000F, - } - - /// - /// This type denotes the SharedMemory access direction. - /// - /// 3 - [Flags] - public enum SharedMemoryFlags : UInt32 - { - /// A flag indicates the shared memory can be read. - Input = 0x00000001, - /// A flag indicates the shared memory can be written. - Output = 0x00000002, - /// A flag indicates the shared memory can be read and written. - InOut = Input | Output, - } - - /// - /// This type denotes a shared memory block which has been either registered - /// with the implementation or allocated by it. - /// - /// 3 - public sealed class SharedMemory : IDisposable - { - private bool disposed = false; - private bool initialized = false; - private Context context; // keep reference for correct finalizers order - internal Interop.TEEC_SharedMemory shm; - internal IntPtr shmptr; - internal SharedMemory(Context context) - { - this.context = context; - shmptr = Marshal.AllocHGlobal(Marshal.SizeOf()); - } - internal void setShm(ref Interop.TEEC_SharedMemory shm) - { - this.shm = shm; - Marshal.StructureToPtr(shm, shmptr, false); - initialized = true; - ++context.shmcnt; - } - private void Dispose(bool disposing) - { - if (disposed) { - return ; - } - if (context == null) { - throw new Exception("internal error: context is null"); - } - if (initialized) { - Interop.Libteec.ReleaseSharedMemory(ref shm); - initialized = false; - --context.shmcnt; - } - Marshal.FreeHGlobal(shmptr); - shmptr = IntPtr.Zero; - context = null; - disposed = true; - } - - /// - /// Destructor of the class. - /// - ~SharedMemory() - { - Dispose(false); - } - - /// - /// Disposable interface implememtation. - /// - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - /// - /// This property represents the shared memory size in bytes. - /// - /// 3 - /// http://tizen.org/privilege/tee.client - /// partner - public UInt32 Size - { - get { return shm.size.ToUInt32(); } - } - /// - /// This property represents the start address of the shared memory block. - /// - /// 3 - /// http://tizen.org/privilege/tee.client - /// partner - public IntPtr Address - { - get { return shm.buffer; } - } - - /// - /// This function makes a copy and is designed for convenient operations on small buffers. - /// For large buffers, the direct address should be used. - /// - /// 3 - /// http://tizen.org/privilege/tee.client - /// partner - /// The source data buffer to copy data from. - /// The starting offset in the destination shared memory. - /// The operation is invalid. - public void SetData(byte[] data, int dstOffs) - { - Marshal.Copy(data, 0, shm.buffer + dstOffs, data.Length); - } - /// - /// This function makes a copy and is designed for convenient operations on small buffers. - /// For large buffers, the direct address should be used. - /// - /// 3 - /// http://tizen.org/privilege/tee.client - /// partner - /// The destination data buffer to copy data into. - /// The starting offset in the source shared memory. - /// The operation is invalid. - public void GetData(byte[] data, int srcOffs) - { - Marshal.Copy(shm.buffer + srcOffs, data, 0, data.Length); - } - }; - - /// - /// This type defines the payload of either an open session operation or an invoke command operation. It is - /// also used for cancelation of operations, which may be desirable even if no payload is passed. - /// Parameters are used to exchange data between CA and TA. - /// - /// 3 - public abstract class Parameter - { - internal Parameter(uint t) - { - this.NativeType = t; - } - internal uint NativeType { get; } - }; - - /// - /// This type defines a template for the parameter types. - /// - /// 3 - public abstract class BaseParameter : Parameter where TEnum : struct, IComparable, IFormattable, IConvertible // as close to Enum as possible - { - internal BaseParameter(TEnum t) : base((uint)(object)t) - { - Type = t; - } - - /// - /// This property represents the access type to this parameter. - /// - /// 3 - public TEnum Type { get; } - } - - /// - /// This type defines a temporary memory reference. - /// - /// 3 - public sealed class TempMemoryReference : BaseParameter - { - /// - /// Constructs a parameter object which holds information about the temporary memory copied to or from TA. - /// - /// 3 - /// The address of the allocated memory buffer. - /// The size of the buffer. - /// The kind of access allowed for TA . - public TempMemoryReference(IntPtr buffer, uint size, TEFTempMemoryType type) : - base(type) - { - this.Buffer = buffer; - this.Size = size; - } - /// - /// This property represents the memory address of the buffer. - /// - /// 3 - public IntPtr Buffer { get; } - /// - /// This property represents the size of the buffer. - /// - /// 3 - public uint Size { get; internal set; } - }; - - /// - /// This type defines a memory reference that uses a pre-registered or pre-allocated shared memory block. - /// - /// 3 - public sealed class RegisteredMemoryReference : BaseParameter - { - /// - /// Constructs a parameter object which holds information about the registered memory shared with TA. - /// - /// 3 - /// http://tizen.org/privilege/tee.client - /// partner - /// The shared memory - registered or allocated. - /// The size of the buffer part. - /// The offset of the buffer in the shared memory. - /// The kind of access allowed for TA . - public RegisteredMemoryReference(SharedMemory parent, uint size, uint offset, TEFRegisteredMemoryType type) : - base(type) - { - this.Parent = parent; - if (type == TEFRegisteredMemoryType.Whole) { - this.Size = parent.Size; - this.Offset = 0; - } - else { - this.Size = size; - this.Offset = offset; - } - } - - /// - /// This property represents the shared memory that is referred to. - /// - /// 3 - /// http://tizen.org/privilege/tee.client - /// partner - public SharedMemory Parent { get; } - /// - /// This property represents the size (in bytes) of the shared memory. - /// - /// 3 - /// http://tizen.org/privilege/tee.client - /// partner - public uint Size { get; internal set; } - /// - /// This property represents the offset (in bytes) from the start of the shared memory. - /// - /// 3 - /// http://tizen.org/privilege/tee.client - /// partner - public uint Offset { get; } - }; - - /// - /// This type defines a parameter that is not referencing the shared memory, but carries instead small raw data - /// passed by a value. - /// - /// 3 - public sealed class Value : BaseParameter - { - /// - /// Constructs a parameter object which holds information about integer values copied to or from TA. - /// - /// 3 - /// User paramter A. - /// User paramter B. - /// The kind of access allowed for TA . - public Value(uint a, uint b, TEFValueType type) : - base(type) - { - this.A = a; - this.B = b; - } - /// - /// This property represents an unsigned integer A. - /// - /// 3 - public uint A { get; internal set; } - /// - /// This property represents an unsigned integer B. - /// - /// 3 - public uint B { get; internal set; } - }; - - - /// - /// This type denotes a TEE Session, the logical container linking a client application with a particular trusted application. - /// - /// 3 - public sealed class Session : IDisposable - { - private bool disposed = false; - private bool opened = false; - private Context context; - private IntPtr session_imp; - private IntPtr opptr; - private SharedMemory[] shm = new SharedMemory[4]; - - internal Session(Context context) { - this.context = context; - this.session_imp = Marshal.AllocHGlobal(Marshal.SizeOf()); - this.opptr = Marshal.AllocHGlobal(Marshal.SizeOf()); - for (int i=0; i < 4; ++i) shm[i] = null; - } - - private void Dispose(bool disposing) - { - if (disposed) { - return ; - } - if (opened) { - Interop.Libteec.CloseSession(session_imp); - opened = false; - } - Marshal.FreeHGlobal(this.opptr); - Marshal.FreeHGlobal(this.session_imp); - this.opptr = IntPtr.Zero; - this.session_imp = IntPtr.Zero; - disposed = true; - } - - /// - /// Destructor of the class. - /// - ~Session() - { - Dispose(false); - } - - /// - /// Disposable interface implememtation. - /// - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - internal UInt32 InitParam(ref Interop.TEEC_Parameter32[] dst, int i, Parameter src) - { - if (IntPtr.Size != 4) throw new Exception("wrong arch - not 32bit"); - UInt32 rType = src.NativeType; - switch (src.NativeType) { - case (int)TEFValueType.Input: - case (int)TEFValueType.Output: - case (int)TEFValueType.InOut: - dst[i].value.a = ((Value)src).A; - dst[i].value.b = ((Value)src).B; - break; - - case (int)TEFTempMemoryType.Input: - case (int)TEFTempMemoryType.Output: - case (int)TEFTempMemoryType.InOut: - byte[] mem = new byte[(uint)((TempMemoryReference)src).Size]; - Marshal.Copy(((TempMemoryReference)src).Buffer, mem, 0, mem.Length); - shm[i] = context.AllocateSharedMemory((uint)mem.Length, SharedMemoryFlags.InOut); - Marshal.Copy(mem, 0, shm[i].shm.buffer, mem.Length); - dst[i].tmpref.size = (uint)mem.Length; - dst[i].tmpref.buffer = shm[i].shm.buffer.ToInt32(); - break; - - case (int)TEFRegisteredMemoryType.Whole: - RegisteredMemoryReference rmrw = (RegisteredMemoryReference)src; - rType = ((int)TEFRegisteredMemoryType.PartialInput & (int)TEFRegisteredMemoryType.PartialOutput) | rmrw.Parent.shm.flags; - dst[i].memref.parent = rmrw.Parent.shmptr.ToInt32(); - dst[i].memref.size = rmrw.Size; - dst[i].memref.offset = rmrw.Offset; - break; - - case (int)TEFRegisteredMemoryType.PartialInput: - case (int)TEFRegisteredMemoryType.PartialOutput: - case (int)TEFRegisteredMemoryType.PartialInOut: - RegisteredMemoryReference rmr = (RegisteredMemoryReference)src; - dst[i].memref.parent = rmr.Parent.shmptr.ToInt32(); - dst[i].memref.size = rmr.Size; - dst[i].memref.offset = rmr.Offset; - break; - - default: return 0; - } - return rType; - } - - internal void UpdateParam(Interop.TEEC_Parameter32 src, ref Parameter[] dst, int i) - { - if (IntPtr.Size != 4) throw new Exception("wrong arch - not 32bit"); - switch (dst[i].NativeType) { - case (int)TEFValueType.Input: - case (int)TEFValueType.Output: - case (int)TEFValueType.InOut: - ((Value)dst[i]).A = src.value.a; - ((Value)dst[i]).B = src.value.b; - break; - - case (int)TEFTempMemoryType.Input: - case (int)TEFTempMemoryType.Output: - case (int)TEFTempMemoryType.InOut: - byte[] mem = new byte[src.tmpref.size]; - Marshal.Copy(shm[i].shm.buffer, mem, 0, mem.Length); - Marshal.Copy(mem, 0, ((TempMemoryReference)dst[i]).Buffer, mem.Length); - ((TempMemoryReference)dst[i]).Size = src.tmpref.size; - break; - - case (int)TEFRegisteredMemoryType.Whole: - case (int)TEFRegisteredMemoryType.PartialInput: - case (int)TEFRegisteredMemoryType.PartialOutput: - case (int)TEFRegisteredMemoryType.PartialInOut: - ((RegisteredMemoryReference)dst[i]).Size = src.memref.size; - break; - - default: break; - } - } - - static internal Interop.TEEC_Operation32 Create_TEEC_Operation32() { - Interop.TEEC_Operation32 op = new Interop.TEEC_Operation32(); - op.started=0; - op.paramTypes=0; - op.paramlist = new Interop.TEEC_Parameter32[4]; - return op; - } - - internal UInt32 InitParam(ref Interop.TEEC_Parameter64[] dst, int i, Parameter src) - { - if (IntPtr.Size != 8) throw new Exception("wrong arch - not 64bit"); - UInt32 rType = src.NativeType; - switch (src.NativeType) { - case (int)TEFValueType.Input: - case (int)TEFValueType.Output: - case (int)TEFValueType.InOut: - dst[i].value.a = ((Value)src).A; - dst[i].value.b = ((Value)src).B; - break; - - case (int)TEFTempMemoryType.Input: - case (int)TEFTempMemoryType.Output: - case (int)TEFTempMemoryType.InOut: - byte[] mem = new byte[(uint)((TempMemoryReference)src).Size]; - Marshal.Copy(((TempMemoryReference)src).Buffer, mem, 0, mem.Length); - shm[i] = context.AllocateSharedMemory((uint)mem.Length, SharedMemoryFlags.InOut); - Marshal.Copy(mem, 0, shm[i].shm.buffer, mem.Length); - dst[i].tmpref.size = (UInt64)mem.Length; - dst[i].tmpref.buffer = shm[i].shm.buffer.ToInt64(); - break; - - case (int)TEFRegisteredMemoryType.Whole: - RegisteredMemoryReference rmrw = (RegisteredMemoryReference)src; - rType = ((int)TEFRegisteredMemoryType.PartialInput & (int)TEFRegisteredMemoryType.PartialOutput) | rmrw.Parent.shm.flags; - dst[i].memref.parent = rmrw.Parent.shmptr.ToInt64(); - dst[i].memref.size = rmrw.Size; - dst[i].memref.offset = rmrw.Offset; - break; - - case (int)TEFRegisteredMemoryType.PartialInput: - case (int)TEFRegisteredMemoryType.PartialOutput: - case (int)TEFRegisteredMemoryType.PartialInOut: - RegisteredMemoryReference rmr = (RegisteredMemoryReference)src; - dst[i].memref.parent = rmr.Parent.shmptr.ToInt64(); - dst[i].memref.size = rmr.Size; - dst[i].memref.offset = rmr.Offset; - break; - - default: - break; - } - return rType; - } - - internal void UpdateParam(Interop.TEEC_Parameter64 src, ref Parameter[] dst, int i) - { - if (IntPtr.Size != 8) throw new Exception("wrong arch - not 64bit"); - switch (dst[i].NativeType) { - case (int)TEFValueType.Input: - case (int)TEFValueType.Output: - case (int)TEFValueType.InOut: - ((Value)dst[i]).A = src.value.a; - ((Value)dst[i]).B = src.value.b; - break; - - case (int)TEFTempMemoryType.Input: - case (int)TEFTempMemoryType.Output: - case (int)TEFTempMemoryType.InOut: - byte[] mem = new byte[src.tmpref.size]; - Marshal.Copy(shm[i].shm.buffer, mem, 0, mem.Length); - Marshal.Copy(mem, 0, ((TempMemoryReference)dst[i]).Buffer, mem.Length); - ((TempMemoryReference)dst[i]).Size = (uint)src.tmpref.size; - break; - - case (int)TEFRegisteredMemoryType.Whole: - case (int)TEFRegisteredMemoryType.PartialInput: - case (int)TEFRegisteredMemoryType.PartialOutput: - case (int)TEFRegisteredMemoryType.PartialInOut: - ((RegisteredMemoryReference)dst[i]).Size = (uint)src.memref.size; - break; - - default: break; - } - } - - static internal Interop.TEEC_Operation64 Create_TEEC_Operation64() { - Interop.TEEC_Operation64 op = new Interop.TEEC_Operation64(); - op.started=0; - op.paramTypes=0; - op.paramlist = new Interop.TEEC_Parameter64[4]; - return op; - } - - internal void Open32(Guid destination, uint loginMethod, byte[] connectionData, Parameter[] paramlist) - { - Interop.TEEC_UUID uuid = Interop.TEEC_UUID.ToTeecUuid(destination); - - int ret; - uint ro; - if (paramlist != null) { - Interop.TEEC_Operation32 op = Create_TEEC_Operation32(); - for (int i=0; i < 4 && i < paramlist.Length; ++i) { - op.paramTypes |= InitParam(ref op.paramlist, i, paramlist[i]) << (8*i); - } - Marshal.StructureToPtr(op, opptr, false); - ret = Interop.Libteec.OpenSession(context.context_imp, session_imp, ref uuid, loginMethod, connectionData, opptr, out ro); - op = Marshal.PtrToStructure(opptr); - for (int i=0; i < 4 && i < paramlist.Length; ++i) { - UpdateParam(op.paramlist[i], ref paramlist, i); - } - } - else { - ret = Interop.Libteec.OpenSession(context.context_imp, session_imp, ref uuid, loginMethod, connectionData, IntPtr.Zero, out ro); - } - - for (int i=0; i < 4; ++i) { - if (shm[i] != null) { - shm[i].Dispose(); - shm[i] = null; - } - } - - //MAYBE map origin of return code to specyfic Exception - Interop.CheckNThrowException(ret, string.Format("OpenSession('{0}')", destination)); - opened = true; - } - internal void Open64(Guid destination, uint loginMethod, byte[] connectionData, Parameter[] paramlist) - { - Interop.TEEC_UUID uuid = Interop.TEEC_UUID.ToTeecUuid(destination); - - int ret; - uint ro; - if (paramlist != null) { - Interop.TEEC_Operation64 op = Create_TEEC_Operation64(); - for (int i=0; i < 4 && i < paramlist.Length; ++i) { - op.paramTypes |= InitParam(ref op.paramlist, i, paramlist[i]) << (8*i); - } - Marshal.StructureToPtr(op, opptr, false); - ret = Interop.Libteec.OpenSession(context.context_imp, session_imp, ref uuid, loginMethod, connectionData, opptr, out ro); - op = Marshal.PtrToStructure(opptr); - for (int i=0; i < 4 && i < paramlist.Length; ++i) { - UpdateParam(op.paramlist[i], ref paramlist, i); - } - } - else { - ret = Interop.Libteec.OpenSession(context.context_imp, session_imp, ref uuid, loginMethod, connectionData, IntPtr.Zero, out ro); - } - - for (int i=0; i < 4; ++i) { - if (shm[i] != null) { - shm[i].Dispose(); - shm[i] = null; - } - } - - //MAYBE map origin of return code to specyfic Exception - Interop.CheckNThrowException(ret, string.Format("OpenSession('{0}')", destination)); - opened = true; - } - - /// - /// This function closes a session which has been opened with a trusted application. - /// All commands within the session must be completed before this function can be called. - /// - /// 3 - /// http://tizen.org/privilege/tee.client - /// partner - /// http://tizen.org/feature/security.tee - /// Thrown when an application does not have the privilege to access this method. - /// The required feature is not supported. - /// The operation is invalid. - public void Close() { - Dispose(); - } - - /// - /// This function invokes a command within the specified session. - /// The parameter commandID is an identifier that is used to indicate which of the exposed trusted - /// application functions should be invoked. The supported command identifier values are defined by the - /// trusted application's protocol. - /// There can be up to four parameter objects given in the array. - /// - /// 3 - /// The command. - /// The array of parameters. - /// http://tizen.org/privilege/tee.client - /// partner - /// http://tizen.org/feature/security.tee - /// Thrown when an application does not have the privilege to access this method. - /// The required feature is not supported. - /// The operation is invalid. - /// The argument is wrong. - public void InvokeCommand(uint commandID, Parameter[] paramlist) - { - int ret; - uint ro; - if (paramlist != null) { - if (IntPtr.Size == 4) { - Interop.TEEC_Operation32 op = Create_TEEC_Operation32(); - for (int i=0; i < 4 && i < paramlist.Length; ++i) { - op.paramTypes |= InitParam(ref op.paramlist, i, paramlist[i]) << (8*i); - } - Marshal.StructureToPtr(op, opptr, false); - ret = Interop.Libteec.InvokeCommand(session_imp, commandID, opptr, out ro); - op = Marshal.PtrToStructure(opptr); - for (int i=0; i < 4 && i < paramlist.Length; ++i) { - UpdateParam(op.paramlist[i], ref paramlist, i); - } - } - else { - Interop.TEEC_Operation64 op = Create_TEEC_Operation64(); - for (int i=0; i < 4 && i < paramlist.Length; ++i) { - op.paramTypes |= InitParam(ref op.paramlist, i, paramlist[i]) << (8*i); - } - Marshal.StructureToPtr(op, opptr, false); - ret = Interop.Libteec.InvokeCommand(session_imp, commandID, opptr, out ro); - op = Marshal.PtrToStructure(opptr); - for (int i=0; i < 4 && i < paramlist.Length; ++i) { - UpdateParam(op.paramlist[i], ref paramlist, i); - } - } - } - else { - ret = Interop.Libteec.InvokeCommand(session_imp, commandID, IntPtr.Zero, out ro); - } - - for (int i=0; i < 4; ++i) { - if (shm[i] != null) { - shm[i].Dispose(); - shm[i] = null; - } - } - - //MAYBE map origin of return code to specific Exception - Interop.CheckNThrowException(ret, string.Format("InvokeCommand({0})", commandID)); - } - - /// - /// The asynchronous version of the InvokeCommand. - /// - /// 3 - /// The command. - /// The array of parameters. - /// The token for task manipulation. - /// Returns a task executing an invoke command in the background. - /// http://tizen.org/privilege/tee.client - /// partner - /// http://tizen.org/feature/security.tee - /// Thrown when an application does not have the privilege to access this method. - /// The required feature is not supported. - /// The operation is invalid. - /// One of the arguments is wrong. - public async Task InvokeCommandAsync(uint commandID, Parameter[] paramlist, CancellationToken token = default(CancellationToken)) - { - await Task.Factory.StartNew(() => InvokeCommand(commandID, paramlist)); - } - - }; - - static internal class TeeFeature - { - private static string name = "http://tizen.org/feature/security.tee"; - public static bool IsEnabled() { - /* FIXME - System.Information does not provide a Try-less variant of GetValue */ - if (!Tizen.System.Information.TryGetValue(name, out bool enabled)) { - unchecked { - Interop.CheckNThrowException((int)Interop.LibteecError.Generic, "Failed to query for TEE feature"); - } - } - return enabled; - } - } - - /// - /// This type denotes a TEE Context, the main logical container linking a Client Application with a particular TEE. - /// - /// 3 - public sealed class Context : IDisposable - { - private bool disposed = false; - private bool initialized = false; - internal IntPtr context_imp; - internal uint shmcnt = 0; - - /// - /// This function (constructor) initializes a new TEE Context, forming a connection between this client application and the - /// TEE identified by the string identifier name (empty or null name denotes a default TEE). - /// - /// 3 - /// The TEE name. - /// http://tizen.org/privilege/tee.client - /// partner - /// http://tizen.org/feature/security.tee - /// Thrown when an application does not have the privilege to access this method. - /// The required feature is not supported. - /// The operation is invalid. - public Context(string name) - { - if (!TeeFeature.IsEnabled()) - unchecked { - Interop.CheckNThrowException((int)Interop.LibteecError.NotSupported, string.Format("InitializeContext('{0}')", name)); - } - - context_imp = Marshal.AllocHGlobal(Marshal.SizeOf()); - if (name != null && name.Length == 0) - name = null; - try { - int ret = Interop.Libteec.InitializeContext(name, context_imp); - Interop.CheckNThrowException(ret, string.Format("InitializeContext('{0}')", name)); - initialized = true; - } - catch (global::System.DllNotFoundException e) - { - unchecked { - Interop.CheckNThrowException((int)Interop.LibteecError.NotImplemented, "Not found: " + e.Message); - } - } - } - - private void Dispose(bool disposing) - { - if (disposed) { - return ; - } - if (initialized) { - Interop.Libteec.FinalizeContext(context_imp); - initialized = false; - } - Marshal.FreeHGlobal(context_imp); - context_imp = IntPtr.Zero; - disposed = true; - } - - /// - /// Destructor of the class. - /// - ~Context() - { - Dispose(false); - } - - /// - /// This function implements the IDisposable interface. - /// - /// 3 - /// http://tizen.org/privilege/tee.client - /// partner - /// http://tizen.org/feature/security.tee - public void Dispose() { - if (shmcnt != 0) { - Tizen.Log.Error("TZ_CLIENTAPI", "Context.Dispose not all shm released yet!"); - return ; - } - Dispose(true); - GC.SuppressFinalize(this); - } - - /// - /// This function opens a new session between the client application and the specified trusted application. - /// The target trusted application is identified by an UUID passed in the parameter destination. - /// There can be up to four parameter objects given in the array. - /// - /// 3 - /// The UUID of the destination TA. - /// The authentication algorithm . - /// The data to be verified by a given login method. - /// The parameters to be passed to TA open-session-callback. - /// Returns opened session. - /// http://tizen.org/privilege/tee.client - /// partner - /// http://tizen.org/feature/security.tee - /// Thrown when an application does not have the privilege to access this method. - /// The required feature is not supported. - /// The operation is invalid. - /// One of the arguments is wrong. - public Session OpenSession(Guid destination, uint loginMethod, byte[] connectionData, Parameter[] paramlist) - { - Session ses = new Session(this); - if (IntPtr.Size == 4) - ses.Open32(destination, loginMethod, connectionData, paramlist); - else if (IntPtr.Size == 8) - ses.Open64(destination, loginMethod, connectionData, paramlist); - else throw new NotSupportedException("unsupported arch"); - return ses; - } - /// - /// @see OpenSession (Guid destination, uint connectionMethod, byte[] connectionData, Parameter[] paramlist, CancellationToken token). - /// - /// 3 - /// The UUID of the destination TA. - /// Returns opened session. - /// http://tizen.org/privilege/tee.client - /// partner - /// http://tizen.org/feature/security.tee - /// Thrown when an application does not have the privilege to access this method. - /// The required feature is not supported. - /// The operation is invalid. - public Session OpenSession(Guid destination) - { - Session ses = new Session(this); - if (IntPtr.Size == 4) - ses.Open32(destination, LoginMethod.Public, null, null); - else if (IntPtr.Size == 8) - ses.Open64(destination, LoginMethod.Public, null, null); - else throw new NotSupportedException("unsupported arch"); - return ses; - } - - /// - /// The asynchronous version of the OpenSession. - /// @see OpenSession (Guid destination, uint connectionMethod, byte[] connectionData, Parameter[] paramlist, CancellationToken token). - /// - /// 3 - /// The UUID of the destination TA. - /// The authentication algorithm . - /// The data to be verified by a given login method. - /// The parameters to be passed to the TA open-session-callback. - /// The token for the task manipulation. - /// Returns a Task executing the session open in the background. - /// http://tizen.org/privilege/tee.client - /// partner - /// http://tizen.org/feature/security.tee - /// Thrown when an application does not have the privilege to access this method. - /// The required feature is not supported. - /// The operation is invalid. - /// One of the arguments is wrong. - public async Task OpenSessionAsync(Guid destination, uint loginMethod, byte[] connectionData, Parameter[] paramlist, CancellationToken token = default(CancellationToken)) - { - Task task = Task.Factory.StartNew(() => - { - return OpenSession(destination, loginMethod, connectionData, paramlist); - }); - return await task; - } - /// - /// The asynchronous version of the OpenSession. - /// @see OpenSession (Guid destination, uint connectionMethod, byte[] connectionData, Parameter[] paramlist, CancellationToken token). - /// - /// 3 - /// The UUID of the destination TA. - /// The token for a task manipulation. - /// Returns a task executing session open in the background. - /// http://tizen.org/privilege/tee.client - /// partner - /// http://tizen.org/feature/security.tee - /// Thrown when an application does not have the privilege to access this method. - /// The required feature is not supported. - /// The operation is invalid. - public async Task OpenSessionAsync(Guid destination, CancellationToken token = default(CancellationToken)) - { - Task task = Task.Factory.StartNew(() => - { - return OpenSession(destination); - }); - return await task; - } - - /// - /// This function registers a block of the existing client application memory as a block of shared memory within - /// the scope of the specified context, in accordance with the parameters. - /// The input must point to the shared memory region to register. - /// - /// 3 - /// The address of the shared memory. - /// The size of the shared memory. - /// The flags describing the access modes (Input and/or Output). - /// Returns the SharedMemory handler. - /// http://tizen.org/privilege/tee.client - /// partner - /// http://tizen.org/feature/security.tee - /// Thrown when an application does not have the privilege to access this method. - /// The required feature is not supported. - /// The operation is invalid. - /// The argument is wrong. - public SharedMemory RegisterSharedMemory(IntPtr memaddr, UInt32 size, SharedMemoryFlags flags) - { - SharedMemory sharedmem = new SharedMemory(this); - Interop.TEEC_SharedMemory shm = new Interop.TEEC_SharedMemory(); - shm.buffer = memaddr; - shm.size = (UIntPtr)size; - shm.flags = (UInt32)flags; - int ret = Interop.Libteec.RegisterSharedMemory(context_imp, ref shm); - Interop.CheckNThrowException(ret, "RegisterSharedMemory"); - sharedmem.setShm(ref shm); - return sharedmem; - } - - /// - /// This function allocates a new block of memory as a block of shared memory within the scope of the - /// specified context, in accordance with the parameters. - /// - /// 3 - /// The size of shared memory. - /// The flags describing access modes (Input and/or Output). - /// Returns the Shared Memory handler. - /// http://tizen.org/privilege/tee.client - /// partner - /// http://tizen.org/feature/security.tee - /// Thrown when an application does not have the privilege to access this method. - /// The required feature is not supported. - /// The operation is invalid. - public SharedMemory AllocateSharedMemory(UInt32 size, SharedMemoryFlags flags) - { - SharedMemory sharedmem = new SharedMemory(this); - Interop.TEEC_SharedMemory shm = new Interop.TEEC_SharedMemory(); - shm.size = (UIntPtr)size; - shm.flags = (UInt32)flags; - int ret = Interop.Libteec.AllocateSharedMemory(context_imp, ref shm); - Interop.CheckNThrowException(ret, "AllocateSharedMemory"); - sharedmem.setShm(ref shm); - return sharedmem; - } - - /// - /// This function deregisters or deallocates a previously initialized block of the shared memory. - /// - /// - /// For a memory buffer allocated using AllocateSharedMemory, the implementation must free the - /// underlying memory and the client application must not access this region after this function has been - /// called. In this case, the implementation must clear the buffer and size fields of the shared memory - /// structure before returning. - /// For memory registered using RegisterSharedMemory, the implementation must deregister the - /// underlying memory from the TEE, but the memory region will stay available to the client application for - /// other purposes as the memory is owned by it. - /// - /// 3 - /// The shared memory object returned by RegisterSharedMemory or AllocateSharedMemory. - /// http://tizen.org/privilege/tee.client - /// partner - /// http://tizen.org/feature/security.tee - /// Thrown when an application does not have the privilege to access this method. - /// The required feature is not supported. - /// The operation is invalid. - /// The argument is wrong. - public void ReleaseSharedMemory(SharedMemory shm) - { - shm.Dispose(); - } - }; - -} diff --git a/src/Tizen.Security.TEEC/doc/api/Tizen.Security.TEEC.md b/src/Tizen.Security.TEEC/doc/api/Tizen.Security.TEEC.md deleted file mode 100644 index 56fa50b0545..00000000000 --- a/src/Tizen.Security.TEEC/doc/api/Tizen.Security.TEEC.md +++ /dev/null @@ -1,58 +0,0 @@ ---- -uid: Tizen.Security.TEEC -summary: The communication API for connecting Client Applications running in a rich operating environment - with security related Trusted Applications running inside a Trusted Execution Environment (TEE). -remarks: *content ---- -## Overview -A TEE provides an execution environment with security capabilities, which are either available to Trusted Applications -running inside the TEE or exposed externally to Client Applications. -The TEE Client API concentrates on the interface to enable efficient communications between -a Client Application and a Trusted Application running inside the TEE. -Higher level standards and protocol layers may be built on top of the foundation -provided by the TEE Client API – for example, to cover common tasks, such as secure storage, -cryptography, and run-time installation of new Trusted Applications. -The separation between the rich environment and the TEE is guaranted. - -The key design principles of the TEE Client API are: - * Client-side memory allocations - Where possible the design of the TEE Client API has placed the responsibility for memory - allocation on the calling Client Application code. This gives the Client developer choice of - memory allocation locations, enabling simple optimizations, such as stack-based allocation - or enhanced flexibility using placements in static global memory or thread-local storage. - - This design choice is evident in the API by the use of pointers to structures rather than - opaque handles to represent any manipulated objects. - * Aim for zero-copy data transfer - The features of the TEE Client API are chosen to maximize the possibility of zero-copy - data transfer between the Client Application and the Trusted Application. - However, short messages can also be passed by copy, which avoids the overhead of - sharing memory. - * Support memory sharing by pointers - The TEE Client API will be used to implement higher-level APIs, such as cryptography or - secure storage, where the caller will often provide memory buffers for input or output data - using simple C pointers. The TEE Client API must allow efficient sharing of this type of - memory, and as such does not rely on the Client Application being able to use bulk - memory buffers allocated by the TEE Client API. - * Specify only communication mechanisms - This API focuses on defining the underlying communications channel. It does not define - the format of the messages which pass over the channel, or the protocols used by specific - Trusted Applications. - -For security reasons, each device vendor usually uses their own TEE solution. -If you intend your LibTeec application to be used on a real device, -you must test your application on the TEE solution provided by the specific vendor. -When developing and installing your trusted application, refer to the documentation provided by the vendor. - -## Example -The following example demonstrates how to invoke command on Trused Application. - -```cs -Guid ta_uuid = new Guid("TA-guid-put-here"); -Context ctx = new Context(null); -Session ses = ctx.OpenSession(ta_uuid); -Parameter[] p = { new Value(1,2,TEFValueType.In) }; -ses.InvokeCommand(1, p); -ses.Close(); -ctx.Dispose(); -```