Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Security.SecureRepository / Interop / Interop.CkmcTypes.cs
1 /*
2  *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License
15  */
16
17 using System;
18 using System.Runtime.InteropServices;
19
20 internal static partial class Interop
21 {
22     [StructLayout(LayoutKind.Sequential)]
23     internal struct CkmcPolicy
24     {
25         public CkmcPolicy(string password, bool extractable)
26         {
27             this.password = password;
28             this.extractable = extractable;
29         }
30         [MarshalAs(UnmanagedType.LPStr)]
31         public readonly string password;
32         [MarshalAs(UnmanagedType.Bool)]
33         public readonly bool extractable;
34     }
35
36     [StructLayout(LayoutKind.Sequential)]
37     internal struct CkmcKey
38     {
39         public CkmcKey(IntPtr binary, int keySize, int keyType, string password)
40         {
41             this.rawKey = binary;
42             this.size = (UIntPtr)keySize;
43             this.keyType = keyType;
44             this.password = password;
45         }
46         public readonly IntPtr rawKey;
47         public readonly UIntPtr size;
48         public readonly int keyType;
49         [MarshalAs(UnmanagedType.LPStr)]
50         public readonly string password;
51     }
52
53     [StructLayout(LayoutKind.Sequential)]
54     internal struct CkmcCert
55     {
56         public CkmcCert(IntPtr binary, int size, int dataFormat)
57         {
58             this.rawCert = binary;
59             this.size = (UIntPtr)size;
60             this.dataFormat = dataFormat;
61         }
62         public readonly IntPtr rawCert;
63         public readonly UIntPtr size;
64         public readonly int dataFormat;
65     }
66
67     [StructLayout(LayoutKind.Sequential)]
68     internal struct CkmcRawBuffer
69     {
70         public CkmcRawBuffer(IntPtr binary, int size)
71         {
72             this.data = binary;
73             this.size = (UIntPtr)size;
74         }
75         public readonly IntPtr data;
76         public readonly UIntPtr size;
77     }
78
79     [StructLayout(LayoutKind.Sequential)]
80     internal struct CkmcAliasList
81     {
82         public readonly IntPtr alias;
83         public readonly IntPtr next;
84     }
85
86     [StructLayout(LayoutKind.Sequential)]
87     internal struct CkmcCertList
88     {
89         public CkmcCertList(IntPtr cert, IntPtr next)
90         {
91             this.cert = cert;
92             this.next = next;
93         }
94         public readonly IntPtr cert;
95         public readonly IntPtr next;
96     }
97
98     [StructLayout(LayoutKind.Sequential)]
99     internal struct CkmcPkcs12
100     {
101         public CkmcPkcs12(IntPtr privateKey, IntPtr certificate, IntPtr caChain)
102         {
103             this.privateKey = privateKey;
104             this.certificate = certificate;
105             this.caChain = caChain;
106         }
107         public readonly IntPtr privateKey;
108         public readonly IntPtr certificate;
109         public readonly IntPtr caChain;
110     }
111
112     internal static partial class CkmcTypes
113     {
114         [DllImport(Libraries.KeyManager, EntryPoint = "ckmc_key_new", CallingConvention = CallingConvention.Cdecl)]
115         public static extern int KeyNew(byte[] rawKey, UIntPtr size, int keyType, string password, out IntPtr cert);
116         // int ckmc_key_new(unsigned char *raw_key, size_t key_size, ckmc_key_type_e key_type, char *password, ckmc_key_s **ppkey);
117         //
118         [DllImport(Libraries.KeyManager, EntryPoint = "ckmc_key_free", CallingConvention = CallingConvention.Cdecl)]
119         public static extern void KeyFree(IntPtr buffer);
120         // void ckmc_key_free(ckmc_key_s *key);
121
122         [DllImport(Libraries.KeyManager, EntryPoint = "ckmc_buffer_new", CallingConvention = CallingConvention.Cdecl)]
123         public static extern int BufferNew(byte[] data, UIntPtr size, out IntPtr buffer);
124         // int ckmc_buffer_new(unsigned char *data, size_t size, ckmc_raw_buffer_s** ppbuffer);
125
126         [DllImport(Libraries.KeyManager, EntryPoint = "ckmc_buffer_free", CallingConvention = CallingConvention.Cdecl)]
127         public static extern void BufferFree(IntPtr buffer);
128         // void ckmc_buffer_free(ckmc_raw_buffer_s* buffer);
129
130         [DllImport(Libraries.KeyManager, EntryPoint = "ckmc_cert_new", CallingConvention = CallingConvention.Cdecl)]
131         public static extern int CertNew(byte[] rawCert, UIntPtr size, int dataFormat, out IntPtr cert);
132         // int ckmc_cert_new(unsigned char *raw_cert, size_t cert_size, ckmc_data_format_e data_format, ckmc_cert_s** ppcert);
133
134         [DllImport(Libraries.KeyManager, EntryPoint = "ckmc_cert_free", CallingConvention = CallingConvention.Cdecl)]
135         public static extern void CertFree(IntPtr buffer);
136         // void ckmc_cert_free(ckmc_cert_s *cert);
137
138         [DllImport(Libraries.KeyManager, EntryPoint = "ckmc_load_cert_from_file", CallingConvention = CallingConvention.Cdecl)]
139         public static extern int LoadCertFromFile(string filePath, out IntPtr cert);
140         // int ckmc_load_cert_from_file(const char *file_path, ckmc_cert_s **cert);
141
142         [DllImport(Libraries.KeyManager, EntryPoint = "ckmc_pkcs12_new", CallingConvention = CallingConvention.Cdecl)]
143         public static extern int Pkcs12New(IntPtr key, IntPtr cert, IntPtr caCerts, out IntPtr p12_bundle);
144         // int ckmc_pkcs12_new(ckmc_key_s *private_key, ckmc_cert_s* cert, ckmc_cert_list_s *ca_cert_list, ckmc_pkcs12_s** pkcs12_bundle);
145
146         [DllImport(Libraries.KeyManager, EntryPoint = "ckmc_pkcs12_load", CallingConvention = CallingConvention.Cdecl)]
147         public static extern int Pkcs12Load(string filePath, string password, out IntPtr pkcs12);
148         // int ckmc_pkcs12_load(const char *file_path, const char* passphrase, ckmc_pkcs12_s **pkcs12_bundle);
149
150         [DllImport(Libraries.KeyManager, EntryPoint = "ckmc_pkcs12_free", CallingConvention = CallingConvention.Cdecl)]
151         public static extern void Pkcs12Free(IntPtr pkcs12);
152         // void ckmc_pkcs12_free(ckmc_pkcs12_s *pkcs12);
153
154         [DllImport(Libraries.KeyManager, EntryPoint = "ckmc_alias_list_new", CallingConvention = CallingConvention.Cdecl)]
155         public static extern int AliasListNew(string alias, out IntPtr aliasList);
156         // int ckmc_alias_list_new(char *alias, ckmc_alias_list_s **ppalias_list);
157
158         [DllImport(Libraries.KeyManager, EntryPoint = "ckmc_alias_list_add", CallingConvention = CallingConvention.Cdecl)]
159         public static extern int AliasListAdd(IntPtr previous, string alias, out IntPtr aliasList);
160         // int ckmc_alias_list_add(ckmc_alias_list_s *previous, char* alias, ckmc_alias_list_s **pplast);
161
162         [DllImport(Libraries.KeyManager, EntryPoint = "ckmc_alias_list_free", CallingConvention = CallingConvention.Cdecl)]
163         public static extern void AliasListFree(IntPtr first);
164         // void ckmc_alias_list_free(ckmc_alias_list_s* first);
165
166         [DllImport(Libraries.KeyManager, EntryPoint = "ckmc_alias_list_all_free", CallingConvention = CallingConvention.Cdecl)]
167         public static extern void AliasListAllFree(IntPtr first);
168         // void ckmc_alias_list_all_free(ckmc_alias_list_s* first);
169
170         [DllImport(Libraries.KeyManager, EntryPoint = "ckmc_cert_list_new", CallingConvention = CallingConvention.Cdecl)]
171         public static extern int CertListNew(IntPtr cert, out IntPtr certList);
172         // int ckmc_cert_list_new(ckmc_cert_s *cert, ckmc_cert_list_s **ppcert_list);
173
174         [DllImport(Libraries.KeyManager, EntryPoint = "ckmc_cert_list_add", CallingConvention = CallingConvention.Cdecl)]
175         public static extern int CertListAdd(IntPtr previous, IntPtr cert, out IntPtr certList);
176         // int ckmc_cert_list_add(ckmc_cert_list_s *previous, ckmc_cert_s *cert, ckmc_cert_list_s** pplast);
177
178         [DllImport(Libraries.KeyManager, EntryPoint = "ckmc_cert_list_free", CallingConvention = CallingConvention.Cdecl)]
179         public static extern void CertListFree(IntPtr first);
180         // void ckmc_cert_list_free(ckmc_cert_list_s *first);
181
182         [DllImport(Libraries.KeyManager, EntryPoint = "ckmc_cert_list_all_free", CallingConvention = CallingConvention.Cdecl)]
183         public static extern void CertListAllFree(IntPtr first);
184         // void ckmc_cert_list_all_free(ckmc_cert_list_s *first);
185
186         [DllImport(Libraries.KeyManager, EntryPoint = "ckmc_param_list_new", CallingConvention = CallingConvention.Cdecl)]
187         public static extern int ParamListNew(out IntPtr paramList);
188         // int ckmc_param_list_new(ckmc_param_list_h *pparams);
189
190         [DllImport(Libraries.KeyManager, EntryPoint = "ckmc_param_list_set_integer", CallingConvention = CallingConvention.Cdecl)]
191         public static extern int ParamListSetInteger(IntPtr paramList, int name, long value);
192         // int ckmc_param_list_set_integer(ckmc_param_list_h params, ckmc_param_name_e name, uint64_t value);
193
194         [DllImport(Libraries.KeyManager, EntryPoint = "ckmc_param_list_set_buffer", CallingConvention = CallingConvention.Cdecl)]
195         public static extern int ParamListSetBuffer(IntPtr paramList, int name, IntPtr buffer);
196         // int ckmc_param_list_set_buffer(ckmc_param_list_h params, ckmc_param_name_e name, const ckmc_raw_buffer_s* buffer);
197
198         [DllImport(Libraries.KeyManager, EntryPoint = "ckmc_param_list_get_integer", CallingConvention = CallingConvention.Cdecl)]
199         public static extern int ParamListGetInteger(IntPtr paramList, int name, out long value);
200         // int ckmc_param_list_get_integer(ckmc_param_list_h params, ckmc_param_name_e name, uint64_t *pvalue);
201
202         [DllImport(Libraries.KeyManager, EntryPoint = "ckmc_param_list_get_buffer", CallingConvention = CallingConvention.Cdecl)]
203         public static extern int ParamListGetBuffer(IntPtr paramList, int name, out IntPtr buffer);
204         // int ckmc_param_list_get_buffer(ckmc_param_list_h params, ckmc_param_name_e name, ckmc_raw_buffer_s **ppbuffer);
205
206         [DllImport(Libraries.KeyManager, EntryPoint = "ckmc_param_list_free", CallingConvention = CallingConvention.Cdecl)]
207         public static extern void ParamListFree(IntPtr first);
208         // void ckmc_param_list_free(ckmc_param_list_h params);
209
210         [DllImport(Libraries.KeyManager, EntryPoint = "ckmc_generate_new_params", CallingConvention = CallingConvention.Cdecl)]
211         public static extern int GenerateNewParam(int algoType, out IntPtr paramList);
212         // int ckmc_generate_new_params(ckmc_algo_type_e type, ckmc_param_list_h *pparams);
213     }
214 }