xref: /titanic_50/usr/src/lib/libkmf/include/kmfapi.h (revision adecd3c68045d04dc367d30faf2eb5cac1f45d5a)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  *
25  *
26  * Constant definitions and function prototypes for the KMF library.
27  * Commonly used data types are defined in "kmftypes.h".
28  */
29 
30 #ifndef _KMFAPI_H
31 #define	_KMFAPI_H
32 
33 #pragma ident	"%Z%%M%	%I%	%E% SMI"
34 
35 #include <kmftypes.h>
36 #include <security/cryptoki.h>
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 /*
43  * Setup operations.
44  */
45 extern KMF_RETURN KMF_Initialize(KMF_HANDLE_T *, char *, char *);
46 extern KMF_RETURN KMF_ConfigureKeystore(KMF_HANDLE_T, KMF_CONFIG_PARAMS *);
47 extern KMF_RETURN KMF_Finalize(KMF_HANDLE_T);
48 
49 /*
50  * Key operations.
51  */
52 extern KMF_RETURN KMF_SignDataWithKey(KMF_HANDLE_T,
53 	KMF_KEY_HANDLE *, KMF_OID *,
54 	KMF_DATA *, KMF_DATA *);
55 
56 extern KMF_RETURN KMF_VerifyDataWithKey(KMF_HANDLE_T,
57 	KMF_KEY_HANDLE *, KMF_ALGORITHM_INDEX, KMF_DATA *, KMF_DATA *);
58 
59 extern KMF_RETURN KMF_CreateKeypair(KMF_HANDLE_T,
60 	KMF_CREATEKEYPAIR_PARAMS *, KMF_KEY_HANDLE *, KMF_KEY_HANDLE *);
61 
62 extern KMF_RETURN KMF_DeleteKeyFromKeystore(KMF_HANDLE_T,
63 	KMF_DELETEKEY_PARAMS *, KMF_KEY_HANDLE *);
64 
65 extern KMF_RETURN KMF_SignCertRecord(KMF_HANDLE_T, KMF_KEY_HANDLE *,
66 	KMF_X509_CERTIFICATE *, KMF_DATA *);
67 
68 extern KMF_RETURN KMF_FindKey(KMF_HANDLE_T, KMF_FINDKEY_PARAMS *,
69 	KMF_KEY_HANDLE *, uint32_t *);
70 
71 extern KMF_RETURN KMF_StorePrivateKey(KMF_HANDLE_T, KMF_STOREKEY_PARAMS *,
72 	KMF_RAW_KEY_DATA *);
73 
74 extern KMF_RETURN KMF_CreateSymKey(KMF_HANDLE_T, KMF_CREATESYMKEY_PARAMS *,
75 	KMF_KEY_HANDLE *);
76 
77 extern KMF_RETURN KMF_GetSymKeyValue(KMF_HANDLE_T, KMF_KEY_HANDLE *,
78 	KMF_RAW_SYM_KEY *);
79 
80 /*
81  * Certificate operations.
82  */
83 extern KMF_RETURN KMF_FindCert(KMF_HANDLE_T, KMF_FINDCERT_PARAMS *,
84 	KMF_X509_DER_CERT *, uint32_t *);
85 
86 extern KMF_RETURN KMF_EncodeCertRecord(KMF_X509_CERTIFICATE *,
87 	KMF_DATA *);
88 extern KMF_RETURN KMF_SignCertWithKey(KMF_HANDLE_T, const KMF_DATA *,
89 	KMF_KEY_HANDLE *, KMF_DATA *);
90 extern KMF_RETURN KMF_SignCertWithCert(KMF_HANDLE_T,
91 	KMF_CRYPTOWITHCERT_PARAMS *,
92 	const KMF_DATA *, KMF_DATA *, KMF_DATA *);
93 
94 extern KMF_RETURN KMF_SignDataWithCert(KMF_HANDLE_T,
95 	KMF_CRYPTOWITHCERT_PARAMS *, KMF_DATA *, KMF_DATA *, KMF_DATA *);
96 
97 extern KMF_RETURN KMF_VerifyCertWithKey(KMF_HANDLE_T, KMF_KEY_HANDLE *,
98 	const KMF_DATA *);
99 extern KMF_RETURN KMF_VerifyCertWithCert(KMF_HANDLE_T, const KMF_DATA *,
100 	const KMF_DATA *);
101 extern KMF_RETURN KMF_VerifyDataWithCert(KMF_HANDLE_T, KMF_DATA *, KMF_DATA *,
102 	const KMF_DATA *);
103 
104 extern KMF_RETURN KMF_EncryptWithCert(KMF_HANDLE_T, KMF_DATA *,
105 	KMF_DATA *, KMF_DATA *);
106 
107 extern KMF_RETURN KMF_DecryptWithCert(KMF_HANDLE_T,
108 	KMF_CRYPTOWITHCERT_PARAMS *, KMF_DATA *, KMF_DATA *, KMF_DATA *);
109 
110 extern KMF_RETURN KMF_StoreCert(KMF_HANDLE_T,
111 	KMF_STORECERT_PARAMS *, KMF_DATA *);
112 extern KMF_RETURN KMF_ImportCert(KMF_HANDLE_T, KMF_IMPORTCERT_PARAMS *);
113 extern KMF_RETURN KMF_DeleteCertFromKeystore(KMF_HANDLE_T,
114 	KMF_DELETECERT_PARAMS *);
115 
116 extern KMF_RETURN KMF_ValidateCert(KMF_HANDLE_T,
117 	KMF_VALIDATECERT_PARAMS *, int  *);
118 
119 extern KMF_RETURN KMF_CreateCertFile(KMF_DATA *, KMF_ENCODE_FORMAT, char *);
120 
121 extern KMF_RETURN KMF_DownloadCert(KMF_HANDLE_T, char *, char *, int,
122 	unsigned int, char *, KMF_ENCODE_FORMAT *);
123 extern KMF_RETURN KMF_IsCertFile(KMF_HANDLE_T, char *, KMF_ENCODE_FORMAT *);
124 
125 extern KMF_RETURN KMF_CheckCertDate(KMF_HANDLE_T, KMF_DATA *);
126 
127 /*
128  * CRL operations.
129  */
130 extern KMF_RETURN KMF_ImportCRL(KMF_HANDLE_T, KMF_IMPORTCRL_PARAMS *);
131 extern KMF_RETURN KMF_DeleteCRL(KMF_HANDLE_T, KMF_DELETECRL_PARAMS *);
132 extern KMF_RETURN KMF_ListCRL(KMF_HANDLE_T, KMF_LISTCRL_PARAMS *, char **);
133 extern KMF_RETURN KMF_FindCRL(KMF_HANDLE_T, KMF_FINDCRL_PARAMS *,
134 	char **, int *);
135 
136 extern KMF_RETURN KMF_FindCertInCRL(KMF_HANDLE_T,
137 	KMF_FINDCERTINCRL_PARAMS *);
138 extern KMF_RETURN KMF_VerifyCRLFile(KMF_HANDLE_T,
139 	KMF_VERIFYCRL_PARAMS *);
140 
141 extern KMF_RETURN KMF_CheckCRLDate(KMF_HANDLE_T,
142 	KMF_CHECKCRLDATE_PARAMS *);
143 extern KMF_RETURN KMF_DownloadCRL(KMF_HANDLE_T, char *, char *,
144 	int, unsigned int, char *, KMF_ENCODE_FORMAT *);
145 extern KMF_RETURN KMF_IsCRLFile(KMF_HANDLE_T, char *, KMF_ENCODE_FORMAT *);
146 
147 /*
148  * CSR operations.
149  */
150 extern KMF_RETURN KMF_SetCSRPubKey(KMF_HANDLE_T,
151 	KMF_KEY_HANDLE *, KMF_CSR_DATA *);
152 extern KMF_RETURN KMF_SetCSRVersion(KMF_CSR_DATA *, uint32_t);
153 extern KMF_RETURN KMF_SetCSRSubjectName(KMF_CSR_DATA *, KMF_X509_NAME *);
154 extern KMF_RETURN KMF_CreateCSRFile(KMF_DATA *, KMF_ENCODE_FORMAT, char *);
155 extern KMF_RETURN KMF_SetCSRExtension(KMF_CSR_DATA *, KMF_X509_EXTENSION *);
156 extern KMF_RETURN KMF_SetCSRSignatureAlgorithm(KMF_CSR_DATA *,
157 	KMF_ALGORITHM_INDEX);
158 extern KMF_RETURN KMF_SetCSRSubjectAltName(KMF_CSR_DATA *, char *,
159 	int, KMF_GENERALNAMECHOICES);
160 extern KMF_RETURN KMF_SetCSRKeyUsage(KMF_CSR_DATA *, int, uint16_t);
161 extern KMF_RETURN KMF_SignCSR(KMF_HANDLE_T, const KMF_CSR_DATA *,
162 	KMF_KEY_HANDLE *, KMF_DATA *);
163 
164 /*
165  * GetCert operations.
166  */
167 extern KMF_RETURN KMF_GetCertExtensionData(const KMF_DATA *, KMF_OID *,
168 	KMF_X509_EXTENSION *);
169 
170 extern KMF_RETURN KMF_GetCertCriticalExtensions(const KMF_DATA *,
171 	KMF_X509_EXTENSION **, int *);
172 
173 extern KMF_RETURN KMF_GetCertNonCriticalExtensions(const KMF_DATA *,
174 	KMF_X509_EXTENSION **, int *);
175 
176 extern KMF_RETURN KMF_GetCertKeyUsageExt(const KMF_DATA *,
177 	KMF_X509EXT_KEY_USAGE *);
178 
179 extern KMF_RETURN KMF_GetCertEKU(const KMF_DATA *, KMF_X509EXT_EKU *);
180 
181 extern KMF_RETURN KMF_GetCertBasicConstraintExt(const KMF_DATA *,
182 	KMF_BOOL *, KMF_X509EXT_BASICCONSTRAINTS *);
183 
184 extern KMF_RETURN KMF_GetCertPoliciesExt(const KMF_DATA *,
185 	KMF_BOOL *, KMF_X509EXT_CERT_POLICIES *);
186 
187 extern KMF_RETURN KMF_GetCertAuthInfoAccessExt(const KMF_DATA *,
188 	KMF_X509EXT_AUTHINFOACCESS *);
189 
190 extern KMF_RETURN KMF_GetCertCRLDistributionPointsExt(const KMF_DATA *,
191 	KMF_X509EXT_CRLDISTPOINTS *);
192 
193 extern KMF_RETURN KMF_GetCertVersionString(KMF_HANDLE_T,
194 	const KMF_DATA *, char **);
195 
196 extern KMF_RETURN KMF_GetCertSubjectNameString(KMF_HANDLE_T, const KMF_DATA *,
197 	char **);
198 
199 extern KMF_RETURN KMF_GetCertIssuerNameString(KMF_HANDLE_T,
200 	const KMF_DATA *, char **);
201 
202 extern KMF_RETURN KMF_GetCertSerialNumberString(KMF_HANDLE_T, const KMF_DATA *,
203 	char **);
204 
205 extern KMF_RETURN KMF_GetCertStartDateString(KMF_HANDLE_T,
206 	const KMF_DATA *, char **);
207 
208 extern KMF_RETURN KMF_GetCertEndDateString(KMF_HANDLE_T,
209 	const KMF_DATA *, char **);
210 
211 extern KMF_RETURN KMF_GetCertPubKeyAlgString(KMF_HANDLE_T,
212 	const KMF_DATA *, char **);
213 
214 extern KMF_RETURN KMF_GetCertSignatureAlgString(KMF_HANDLE_T,
215 	const KMF_DATA *, char **);
216 
217 extern KMF_RETURN KMF_GetCertPubKeyDataString(KMF_HANDLE_T,
218 	const KMF_DATA *, char **);
219 
220 extern KMF_RETURN KMF_GetCertEmailString(KMF_HANDLE_T,
221 	const KMF_DATA *, char **);
222 
223 extern KMF_RETURN KMF_GetCertExtensionString(KMF_HANDLE_T, const KMF_DATA *,
224 	KMF_PRINTABLE_ITEM, char **);
225 
226 extern KMF_RETURN KMF_GetCertIDData(const KMF_DATA *, KMF_DATA *);
227 extern KMF_RETURN KMF_GetCertIDString(const KMF_DATA *, char **);
228 extern KMF_RETURN KMF_GetCertValidity(const KMF_DATA *, time_t *, time_t *);
229 
230 /*
231  * SetCert operations
232  */
233 extern KMF_RETURN KMF_SetCertPubKey(KMF_HANDLE_T, KMF_KEY_HANDLE *,
234 	KMF_X509_CERTIFICATE *);
235 
236 extern KMF_RETURN KMF_SetCertSubjectName(KMF_X509_CERTIFICATE *,
237 	KMF_X509_NAME *);
238 
239 extern KMF_RETURN KMF_SetCertKeyUsage(KMF_X509_CERTIFICATE *, int, uint16_t);
240 
241 extern KMF_RETURN KMF_SetCertIssuerName(KMF_X509_CERTIFICATE *,
242 	KMF_X509_NAME *);
243 
244 extern KMF_RETURN KMF_SetCertSignatureAlgorithm(KMF_X509_CERTIFICATE *,
245 	KMF_ALGORITHM_INDEX);
246 
247 extern KMF_RETURN KMF_SetCertValidityTimes(KMF_X509_CERTIFICATE *,
248 	time_t, uint32_t);
249 
250 extern KMF_RETURN KMF_SetCertSerialNumber(KMF_X509_CERTIFICATE *,
251 	KMF_BIGINT *);
252 
253 extern KMF_RETURN KMF_SetCertVersion(KMF_X509_CERTIFICATE *, uint32_t);
254 
255 extern KMF_RETURN KMF_SetCertIssuerAltName(KMF_X509_CERTIFICATE *,
256 	int, KMF_GENERALNAMECHOICES, char *);
257 
258 extern KMF_RETURN KMF_SetCertSubjectAltName(KMF_X509_CERTIFICATE *,
259 	int, KMF_GENERALNAMECHOICES, char *);
260 
261 extern KMF_RETURN KMF_AddCertEKU(KMF_X509_CERTIFICATE *, KMF_OID *, int);
262 
263 extern KMF_RETURN KMF_SetCertExtension(KMF_X509_CERTIFICATE *,
264 	KMF_X509_EXTENSION *);
265 
266 extern KMF_RETURN KMF_SetCertBasicConstraintExt(KMF_X509_CERTIFICATE *,
267 	KMF_BOOL, KMF_X509EXT_BASICCONSTRAINTS *);
268 
269 extern KMF_RETURN KMF_ExportPK12(KMF_HANDLE_T, KMF_EXPORTP12_PARAMS *, char *);
270 extern KMF_RETURN KMF_ImportPK12(KMF_HANDLE_T, char *, KMF_CREDENTIAL *,
271 	KMF_DATA **, int *, KMF_RAW_KEY_DATA **, int *);
272 
273 /*
274  * Get OCSP response operation.
275  */
276 extern KMF_RETURN KMF_GetOCSPForCert(KMF_HANDLE_T, KMF_DATA *,	KMF_DATA *,
277 	KMF_DATA *);
278 
279 extern KMF_RETURN KMF_CreateOCSPRequest(KMF_HANDLE_T, KMF_OCSPREQUEST_PARAMS *,
280 	char *);
281 
282 extern KMF_RETURN KMF_GetEncodedOCSPResponse(KMF_HANDLE_T, char *, char *, int,
283 	char *, int, char *, unsigned int);
284 
285 extern KMF_RETURN KMF_GetOCSPStatusForCert(KMF_HANDLE_T,
286 	KMF_OCSPRESPONSE_PARAMS_INPUT *,
287 	KMF_OCSPRESPONSE_PARAMS_OUTPUT *);
288 
289 /*
290  * Policy Operations
291  */
292 extern KMF_RETURN KMF_SetPolicy(KMF_HANDLE_T, char *, char *);
293 
294 /*
295  * Error handling.
296  */
297 extern KMF_RETURN KMF_GetPluginErrorString(KMF_HANDLE_T, char **);
298 extern KMF_RETURN KMF_GetKMFErrorString(KMF_RETURN, char **);
299 
300 /*
301  * Miscellaneous
302  */
303 extern KMF_RETURN KMF_DNParser(char *, KMF_X509_NAME *);
304 extern KMF_RETURN KMF_DN2Der(KMF_X509_NAME *, KMF_DATA *);
305 extern KMF_RETURN KMF_ReadInputFile(KMF_HANDLE_T, char *, KMF_DATA *);
306 extern KMF_RETURN KMF_Der2Pem(KMF_OBJECT_TYPE, unsigned char *,
307 	int, unsigned char **, int *);
308 extern KMF_RETURN KMF_Pem2Der(unsigned char *, int, unsigned char **, int *);
309 extern char *KMF_OID2String(KMF_OID *);
310 extern KMF_RETURN KMF_String2OID(char *, KMF_OID *);
311 extern int KMF_CompareRDNs(KMF_X509_NAME *, KMF_X509_NAME *);
312 extern KMF_RETURN KMF_GetFileFormat(char *, KMF_ENCODE_FORMAT *);
313 extern uint16_t KMF_StringToKeyUsage(char *);
314 extern KMF_RETURN KMF_SetTokenPin(KMF_HANDLE_T, KMF_SETPIN_PARAMS *,
315 	KMF_CREDENTIAL *);
316 extern KMF_RETURN KMF_HexString2Bytes(unsigned char *, unsigned char **,
317 	size_t *);
318 
319 /*
320  * Memory cleanup operations
321  */
322 extern void KMF_FreeDN(KMF_X509_NAME *);
323 extern void KMF_FreeKMFCert(KMF_HANDLE_T, KMF_X509_DER_CERT *);
324 extern void KMF_FreeData(KMF_DATA *);
325 extern void KMF_FreeAlgOID(KMF_X509_ALGORITHM_IDENTIFIER *);
326 extern void KMF_FreeExtension(KMF_X509_EXTENSION *);
327 extern void KMF_FreeTBSCSR(KMF_TBS_CSR *);
328 extern void KMF_FreeSignedCSR(KMF_CSR_DATA *);
329 extern void KMF_FreeTBSCert(KMF_X509_TBS_CERT *);
330 extern void KMF_FreeSignedCert(KMF_X509_CERTIFICATE *);
331 extern void KMF_FreeString(char *);
332 extern void KMF_FreeEKU(KMF_X509EXT_EKU *);
333 extern void KMF_FreeSPKI(KMF_X509_SPKI *);
334 extern void KMF_FreeKMFKey(KMF_HANDLE_T, KMF_KEY_HANDLE *);
335 extern void KMF_FreeBigint(KMF_BIGINT *);
336 extern void KMF_FreeRawKey(KMF_RAW_KEY_DATA *);
337 extern void KMF_FreeRawSymKey(KMF_RAW_SYM_KEY *);
338 extern void KMF_FreeCRLDistributionPoints(KMF_X509EXT_CRLDISTPOINTS *);
339 
340 /* APIs for PKCS#11 token */
341 extern KMF_RETURN KMF_PK11TokenLookup(KMF_HANDLE_T, char *, CK_SLOT_ID *);
342 
343 #ifdef __cplusplus
344 }
345 #endif
346 #endif /* _KMFAPI_H */
347