4 * This is free software; see Copyright file in the source
5 * distribution for preciese wording.
7 * Copyright (C) 2002-2003 Aleksey Sanin <aleksey@aleksey.com>
13 /* TODO: aadd Skeleton include files */
15 #include <xmlsec/xmlsec.h>
16 #include <xmlsec/keys.h>
17 #include <xmlsec/transforms.h>
18 #include <xmlsec/errors.h>
20 #include <xmlsec/skeleton/app.h>
21 #include <xmlsec/skeleton/crypto.h>
24 * xmlSecSkeletonAppInit:
25 * @config: the path to Skeleton configuration (unused).
27 * General crypto engine initialization. This function is used
28 * by XMLSec command line utility and called before
29 * @xmlSecInit function.
31 * Returns: 0 on success or a negative value otherwise.
34 xmlSecSkeletonAppInit(const char* config ATTRIBUTE_UNUSED) {
35 /* TODO: initialize Skeleton crypto engine */
40 * xmlSecSkeletonAppShutdown:
42 * General crypto engine shutdown. This function is used
43 * by XMLSec command line utility and called after
44 * @xmlSecShutdown function.
46 * Returns: 0 on success or a negative value otherwise.
49 xmlSecSkeletonAppShutdown(void) {
50 /* TODO: shutdown Skeleton crypto engine */
56 * xmlSecSkeletonAppKeyLoad:
57 * @filename: the key filename.
58 * @format: the key file format.
59 * @pwd: the key file password.
60 * @pwdCallback: the key password callback.
61 * @pwdCallbackCtx: the user context for password callback.
63 * Reads key from the a file (not implemented yet).
65 * Returns: pointer to the key or NULL if an error occurs.
68 xmlSecSkeletonAppKeyLoad(const char *filename, xmlSecKeyDataFormat format,
71 void* pwdCallbackCtx) {
72 xmlSecAssert2(filename != NULL, NULL);
73 xmlSecAssert2(format != xmlSecKeyDataFormatUnknown, NULL);
76 xmlSecError(XMLSEC_ERRORS_HERE,
78 "xmlSecSkeletonAppKeyLoad",
79 XMLSEC_ERRORS_R_NOT_IMPLEMENTED,
80 XMLSEC_ERRORS_NO_MESSAGE);
85 * xmlSecSkeletonAppKeyLoadMemory:
86 * @data: the key binary data.
87 * @dataSize: the key binary data size.
88 * @format: the key data format.
89 * @pwd: the key data2 password.
90 * @pwdCallback: the key password callback.
91 * @pwdCallbackCtx: the user context for password callback.
93 * Reads key from a binary @data.
95 * Returns: pointer to the key or NULL if an error occurs.
98 xmlSecSkeletonAppKeyLoadMemory(const xmlSecByte* data, xmlSecSize dataSize, xmlSecKeyDataFormat format,
99 const char *pwd, void* pwdCallback, void* pwdCallbackCtx) {
100 xmlSecAssert2(data != NULL, NULL);
101 xmlSecAssert2(format != xmlSecKeyDataFormatUnknown, NULL);
104 xmlSecError(XMLSEC_ERRORS_HERE,
106 "xmlSecSkeletonAppKeyLoad",
107 XMLSEC_ERRORS_R_NOT_IMPLEMENTED,
108 XMLSEC_ERRORS_NO_MESSAGE);
113 #ifndef XMLSEC_NO_X509
115 * xmlSecSkeletonAppKeyCertLoad:
116 * @key: the pointer to key.
117 * @filename: the certificate filename.
118 * @format: the certificate file format.
120 * Reads the certificate from $@filename and adds it to key
121 * (not implemented yet).
123 * Returns: 0 on success or a negative value otherwise.
126 xmlSecSkeletonAppKeyCertLoad(xmlSecKeyPtr key, const char* filename,
127 xmlSecKeyDataFormat format) {
128 xmlSecAssert2(key != NULL, -1);
129 xmlSecAssert2(filename != NULL, -1);
130 xmlSecAssert2(format != xmlSecKeyDataFormatUnknown, -1);
133 xmlSecError(XMLSEC_ERRORS_HERE,
135 "xmlSecSkeletonAppKeyCertLoad",
136 XMLSEC_ERRORS_R_NOT_IMPLEMENTED,
137 XMLSEC_ERRORS_NO_MESSAGE);
142 * xmlSecSkeletonAppKeyCertLoadMemory:
143 * @key: the pointer to key.
144 * @data: the certificate binary data.
145 * @dataSize: the certificate binary data size.
146 * @format: the certificate file format.
148 * Reads the certificate from memory buffer and adds it to key.
150 * Returns: 0 on success or a negative value otherwise.
153 xmlSecSkeletonAppKeyCertLoadMemory(xmlSecKeyPtr key, const xmlSecByte* data, xmlSecSize dataSize,
154 xmlSecKeyDataFormat format) {
155 xmlSecAssert2(key != NULL, -1);
156 xmlSecAssert2(data != NULL, -1);
157 xmlSecAssert2(format != xmlSecKeyDataFormatUnknown, -1);
160 xmlSecError(XMLSEC_ERRORS_HERE,
162 "xmlSecSkeletonAppKeyCertLoadMemory",
163 XMLSEC_ERRORS_R_NOT_IMPLEMENTED,
164 XMLSEC_ERRORS_NO_MESSAGE);
169 * xmlSecSkeletonAppPkcs12Load:
170 * @filename: the PKCS12 key filename.
171 * @pwd: the PKCS12 file password.
172 * @pwdCallback: the password callback.
173 * @pwdCallbackCtx: the user context for password callback.
175 * Reads key and all associated certificates from the PKCS12 file
176 * (not implemented yet).
177 * For uniformity, call xmlSecSkeletonAppKeyLoad instead of this function. Pass
178 * in format=xmlSecKeyDataFormatPkcs12.
181 * Returns: pointer to the key or NULL if an error occurs.
184 xmlSecSkeletonAppPkcs12Load(const char *filename,
185 const char *pwd ATTRIBUTE_UNUSED,
186 void* pwdCallback ATTRIBUTE_UNUSED,
187 void* pwdCallbackCtx ATTRIBUTE_UNUSED) {
188 xmlSecAssert2(filename != NULL, NULL);
190 /* TODO: load pkcs12 file */
191 xmlSecError(XMLSEC_ERRORS_HERE,
193 "xmlSecSkeletonAppPkcs12Load",
194 XMLSEC_ERRORS_R_NOT_IMPLEMENTED,
195 XMLSEC_ERRORS_NO_MESSAGE);
200 * xmlSecSkeletonAppPkcs12LoadMemory:
201 * @data: the key binary data.
202 * @dataSize: the key binary data size.
203 * @pwd: the PKCS12 password.
204 * @pwdCallback: the password callback.
205 * @pwdCallbackCtx: the user context for password callback.
207 * Reads key and all associated certificates from the PKCS12 binary data.
208 * For uniformity, call xmlSecSkeletonAppKeyLoad instead of this function. Pass
209 * in format=xmlSecKeyDataFormatPkcs12.
211 * Returns: pointer to the key or NULL if an error occurs.
214 xmlSecSkeletonAppPkcs12LoadMemory(const xmlSecByte* data, xmlSecSize dataSize, const char *pwd,
215 void *pwdCallback ATTRIBUTE_UNUSED,
216 void* pwdCallbackCtx ATTRIBUTE_UNUSED) {
217 xmlSecAssert2(data != NULL, NULL);
219 /* TODO: load pkcs12 file */
220 xmlSecError(XMLSEC_ERRORS_HERE,
222 "xmlSecSkeletonAppPkcs12Load",
223 XMLSEC_ERRORS_R_NOT_IMPLEMENTED,
224 XMLSEC_ERRORS_NO_MESSAGE);
231 * xmlSecSkeletonAppKeysMngrCertLoad:
232 * @mngr: the keys manager.
233 * @filename: the certificate file.
234 * @format: the certificate file format.
235 * @type: the flag that indicates is the certificate in @filename
238 * Reads cert from @filename and adds to the list of trusted or known
239 * untrusted certs in @store (not implemented yet).
241 * Returns: 0 on success or a negative value otherwise.
244 xmlSecSkeletonAppKeysMngrCertLoad(xmlSecKeysMngrPtr mngr, const char *filename,
245 xmlSecKeyDataFormat format,
246 xmlSecKeyDataType type ATTRIBUTE_UNUSED) {
247 xmlSecAssert2(mngr != NULL, -1);
248 xmlSecAssert2(filename != NULL, -1);
249 xmlSecAssert2(format != xmlSecKeyDataFormatUnknown, -1);
251 /* TODO: load cert and add to keys manager */
252 xmlSecError(XMLSEC_ERRORS_HERE,
254 "xmlSecSkeletonAppKeysMngrCertLoad",
255 XMLSEC_ERRORS_R_NOT_IMPLEMENTED,
256 XMLSEC_ERRORS_NO_MESSAGE);
261 * xmlSecSkeletonAppKeysMngrCertLoadMemory:
262 * @mngr: the pointer to keys manager.
263 * @data: the key binary data.
264 * @dataSize: the key binary data size.
265 * @format: the certificate format (PEM or DER).
266 * @type: the certificate type (trusted/untrusted).
268 * Reads cert from @data and adds to the list of trusted or known
269 * untrusted certs in @store
271 * Returns: 0 on success or a negative value otherwise.
274 xmlSecSkeletonAppKeysMngrCertLoadMemory(xmlSecKeysMngrPtr mngr, const xmlSecByte* data,
275 xmlSecSize dataSize, xmlSecKeyDataFormat format,
276 xmlSecKeyDataType type) {
277 xmlSecAssert2(mngr != NULL, -1);
278 xmlSecAssert2(data != NULL, -1);
279 xmlSecAssert2(format != xmlSecKeyDataFormatUnknown, -1);
281 /* TODO: load cert and add to keys manager */
282 xmlSecError(XMLSEC_ERRORS_HERE,
284 "xmlSecSkeletonAppKeysMngrCertLoad",
285 XMLSEC_ERRORS_R_NOT_IMPLEMENTED,
286 XMLSEC_ERRORS_NO_MESSAGE);
290 #endif /* XMLSEC_NO_X509 */
293 * xmlSecSkeletonAppDefaultKeysMngrInit:
294 * @mngr: the pointer to keys manager.
296 * Initializes @mngr with simple keys store #xmlSecSimpleKeysStoreId
297 * and a default Skeleton crypto key data stores.
299 * Returns: 0 on success or a negative value otherwise.
302 xmlSecSkeletonAppDefaultKeysMngrInit(xmlSecKeysMngrPtr mngr) {
305 xmlSecAssert2(mngr != NULL, -1);
307 /* TODO: if Skeleton crypto engine has another default
308 * keys storage then use it!
311 /* create simple keys store if needed */
312 if(xmlSecKeysMngrGetKeysStore(mngr) == NULL) {
313 xmlSecKeyStorePtr keysStore;
315 keysStore = xmlSecKeyStoreCreate(xmlSecSimpleKeysStoreId);
316 if(keysStore == NULL) {
317 xmlSecError(XMLSEC_ERRORS_HERE,
319 "xmlSecKeyStoreCreate",
320 XMLSEC_ERRORS_R_XMLSEC_FAILED,
321 "xmlSecSimpleKeysStoreId");
325 ret = xmlSecKeysMngrAdoptKeysStore(mngr, keysStore);
327 xmlSecError(XMLSEC_ERRORS_HERE,
329 "xmlSecKeysMngrAdoptKeysStore",
330 XMLSEC_ERRORS_R_XMLSEC_FAILED,
331 XMLSEC_ERRORS_NO_MESSAGE);
332 xmlSecKeyStoreDestroy(keysStore);
337 ret = xmlSecSkeletonKeysMngrInit(mngr);
339 xmlSecError(XMLSEC_ERRORS_HERE,
341 "xmlSecSkeletonKeysMngrInit",
342 XMLSEC_ERRORS_R_XMLSEC_FAILED,
343 XMLSEC_ERRORS_NO_MESSAGE);
347 mngr->getKey = xmlSecKeysMngrGetKey;
352 * xmlSecSkeletonAppDefaultKeysMngrAdoptKey:
353 * @mngr: the pointer to keys manager.
354 * @key: the pointer to key.
356 * Adds @key to the keys manager @mngr created with #xmlSecSkeletonAppDefaultKeysMngrInit
359 * Returns: 0 on success or a negative value otherwise.
362 xmlSecSkeletonAppDefaultKeysMngrAdoptKey(xmlSecKeysMngrPtr mngr, xmlSecKeyPtr key) {
363 xmlSecKeyStorePtr store;
366 xmlSecAssert2(mngr != NULL, -1);
367 xmlSecAssert2(key != NULL, -1);
369 /* TODO: if Skeleton crypto engine has another default
370 * keys storage then use it!
373 store = xmlSecKeysMngrGetKeysStore(mngr);
375 xmlSecError(XMLSEC_ERRORS_HERE,
377 "xmlSecKeysMngrGetKeysStore",
378 XMLSEC_ERRORS_R_XMLSEC_FAILED,
379 XMLSEC_ERRORS_NO_MESSAGE);
383 ret = xmlSecSimpleKeysStoreAdoptKey(store, key);
385 xmlSecError(XMLSEC_ERRORS_HERE,
387 "xmlSecSimpleKeysStoreAdoptKey",
388 XMLSEC_ERRORS_R_XMLSEC_FAILED,
389 XMLSEC_ERRORS_NO_MESSAGE);
397 * xmlSecSkeletonAppDefaultKeysMngrLoad:
398 * @mngr: the pointer to keys manager.
401 * Loads XML keys file from @uri to the keys manager @mngr created
402 * with #xmlSecSkeletonAppDefaultKeysMngrInit function.
404 * Returns: 0 on success or a negative value otherwise.
407 xmlSecSkeletonAppDefaultKeysMngrLoad(xmlSecKeysMngrPtr mngr, const char* uri) {
408 xmlSecKeyStorePtr store;
411 xmlSecAssert2(mngr != NULL, -1);
412 xmlSecAssert2(uri != NULL, -1);
414 /* TODO: if Skeleton crypto engine has another default
415 * keys storage then use it!
418 store = xmlSecKeysMngrGetKeysStore(mngr);
420 xmlSecError(XMLSEC_ERRORS_HERE,
422 "xmlSecKeysMngrGetKeysStore",
423 XMLSEC_ERRORS_R_XMLSEC_FAILED,
424 XMLSEC_ERRORS_NO_MESSAGE);
428 ret = xmlSecSimpleKeysStoreLoad(store, uri, mngr);
430 xmlSecError(XMLSEC_ERRORS_HERE,
432 "xmlSecSimpleKeysStoreLoad",
433 XMLSEC_ERRORS_R_XMLSEC_FAILED,
434 "uri=%s", xmlSecErrorsSafeString(uri));
442 * xmlSecSkeletonAppDefaultKeysMngrSave:
443 * @mngr: the pointer to keys manager.
444 * @filename: the destination filename.
445 * @type: the type of keys to save (public/private/symmetric).
447 * Saves keys from @mngr to XML keys file.
449 * Returns: 0 on success or a negative value otherwise.
452 xmlSecSkeletonAppDefaultKeysMngrSave(xmlSecKeysMngrPtr mngr, const char* filename, xmlSecKeyDataType type) {
453 xmlSecKeyStorePtr store;
456 xmlSecAssert2(mngr != NULL, -1);
457 xmlSecAssert2(filename != NULL, -1);
459 /* TODO: if Skeleton crypto engine has another default
460 * keys storage then use it!
463 store = xmlSecKeysMngrGetKeysStore(mngr);
465 xmlSecError(XMLSEC_ERRORS_HERE,
467 "xmlSecKeysMngrGetKeysStore",
468 XMLSEC_ERRORS_R_XMLSEC_FAILED,
469 XMLSEC_ERRORS_NO_MESSAGE);
473 ret = xmlSecSimpleKeysStoreSave(store, filename, type);
475 xmlSecError(XMLSEC_ERRORS_HERE,
477 "xmlSecSimpleKeysStoreSave",
478 XMLSEC_ERRORS_R_XMLSEC_FAILED,
480 xmlSecErrorsSafeString(filename));
488 * xmlSecSkeletonAppGetDefaultPwdCallback:
490 * Gets default password callback.
492 * Returns: default password callback.
495 xmlSecSkeletonAppGetDefaultPwdCallback(void) {