summaryrefslogtreecommitdiff
path: root/src/keysmngr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/keysmngr.c')
-rw-r--r--src/keysmngr.c165
1 files changed, 54 insertions, 111 deletions
diff --git a/src/keysmngr.c b/src/keysmngr.c
index 5315203a..61dc9c7b 100644
--- a/src/keysmngr.c
+++ b/src/keysmngr.c
@@ -1,13 +1,18 @@
-/**
+/*
* XML Security Library (http://www.aleksey.com/xmlsec).
*
- * Keys Manager.
*
* This is free software; see Copyright file in the source
* distribution for preciese wording.
*
* Copyright (C) 2002-2016 Aleksey Sanin <aleksey@aleksey.com>. All Rights Reserved.
*/
+/**
+ * SECTION:keysmngr
+ * @Short_description: Keys manager object functions.
+ * @Stability: Stable
+ *
+ */
#include "globals.h"
#include <stdlib.h>
@@ -25,6 +30,8 @@
#include <xmlsec/transforms.h>
#include <xmlsec/keysmngr.h>
#include <xmlsec/errors.h>
+#include <xmlsec/private.h>
+
/****************************************************************************
*
@@ -48,23 +55,14 @@ xmlSecKeysMngrCreate(void) {
/* Allocate a new xmlSecKeysMngr and fill the fields. */
mngr = (xmlSecKeysMngrPtr)xmlMalloc(sizeof(xmlSecKeysMngr));
if(mngr == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- NULL,
- XMLSEC_ERRORS_R_MALLOC_FAILED,
- "sizeof(xmlSecKeysMngr)=%d",
- (int)sizeof(xmlSecKeysMngr));
+ xmlSecMallocError(sizeof(xmlSecKeysMngr), NULL);
return(NULL);
}
memset(mngr, 0, sizeof(xmlSecKeysMngr));
ret = xmlSecPtrListInitialize(&(mngr->storesList), xmlSecKeyDataStorePtrListId);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "xmlSecPtrListInitialize",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "xmlSecKeyDataStorePtrListId");
+ xmlSecInternalError("xmlSecPtrListInitialize(xmlSecKeyDataStorePtrListId)", NULL);
return(NULL);
}
@@ -241,11 +239,8 @@ xmlSecKeyStoreCreate(xmlSecKeyStoreId id) {
/* Allocate a new xmlSecKeyStore and fill the fields. */
store = (xmlSecKeyStorePtr)xmlMalloc(id->objSize);
if(store == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyStoreKlassGetName(id)),
- NULL,
- XMLSEC_ERRORS_R_MALLOC_FAILED,
- "size=%d", id->objSize);
+ xmlSecMallocError(id->objSize,
+ xmlSecKeyStoreKlassGetName(id));
return(NULL);
}
memset(store, 0, id->objSize);
@@ -254,11 +249,8 @@ xmlSecKeyStoreCreate(xmlSecKeyStoreId id) {
if(id->initialize != NULL) {
ret = (id->initialize)(store);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyStoreKlassGetName(id)),
- "id->initialize",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("id->initialize",
+ xmlSecKeyStoreKlassGetName(id));
xmlSecKeyStoreDestroy(store);
return(NULL);
}
@@ -376,11 +368,8 @@ xmlSecSimpleKeysStoreAdoptKey(xmlSecKeyStorePtr store, xmlSecKeyPtr key) {
ret = xmlSecPtrListAdd(list, key);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyStoreGetName(store)),
- "xmlSecPtrListAdd",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecPtrListAdd",
+ xmlSecKeyStoreGetName(store));
return(-1);
}
@@ -399,7 +388,7 @@ xmlSecSimpleKeysStoreAdoptKey(xmlSecKeyStorePtr store, xmlSecKeyPtr key) {
*/
int
xmlSecSimpleKeysStoreLoad(xmlSecKeyStorePtr store, const char *uri,
- xmlSecKeysMngrPtr keysMngr) {
+ xmlSecKeysMngrPtr keysMngr ATTRIBUTE_UNUSED) {
xmlDocPtr doc;
xmlNodePtr root;
xmlNodePtr cur;
@@ -409,25 +398,19 @@ xmlSecSimpleKeysStoreLoad(xmlSecKeyStorePtr store, const char *uri,
xmlSecAssert2(xmlSecKeyStoreCheckId(store, xmlSecSimpleKeysStoreId), -1);
xmlSecAssert2(uri != NULL, -1);
+ UNREFERENCED_PARAMETER(keysMngr);
doc = xmlParseFile(uri);
if(doc == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyStoreGetName(store)),
- "xmlParseFile",
- XMLSEC_ERRORS_R_XML_FAILED,
- "uri=%s",
- xmlSecErrorsSafeString(uri));
+ xmlSecXmlError2("xmlParseFile", xmlSecKeyStoreGetName(store),
+ "uri=%s", xmlSecErrorsSafeString(uri));
return(-1);
}
root = xmlDocGetRootElement(doc);
if(!xmlSecCheckNodeName(root, BAD_CAST "Keys", xmlSecNs)) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyStoreGetName(store)),
- xmlSecErrorsSafeString(xmlSecNodeGetName(root)),
- XMLSEC_ERRORS_R_INVALID_NODE,
- "expected-node=<xmlsec:Keys>");
+ xmlSecInvalidNodeError(root, BAD_CAST "Keys",
+ xmlSecKeyStoreGetName(store));
xmlFreeDoc(doc);
return(-1);
}
@@ -436,30 +419,23 @@ xmlSecSimpleKeysStoreLoad(xmlSecKeyStorePtr store, const char *uri,
while((cur != NULL) && xmlSecCheckNodeName(cur, xmlSecNodeKeyInfo, xmlSecDSigNs)) {
key = xmlSecKeyCreate();
if(key == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyStoreGetName(store)),
- xmlSecErrorsSafeString(xmlSecNodeGetName(cur)),
- XMLSEC_ERRORS_R_INVALID_NODE,
- "expected-node=%s",
- xmlSecErrorsSafeString(xmlSecNodeKeyInfo));
+ xmlSecInternalError("xmlSecKeyCreate",
+ xmlSecKeyStoreGetName(store));
xmlFreeDoc(doc);
return(-1);
}
ret = xmlSecKeyInfoCtxInitialize(&keyInfoCtx, NULL);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyStoreGetName(store)),
- "xmlSecKeyInfoCtxInitialize",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecKeyInfoCtxInitialize",
+ xmlSecKeyStoreGetName(store));
xmlSecKeyDestroy(key);
xmlFreeDoc(doc);
return(-1);
}
keyInfoCtx.mode = xmlSecKeyInfoModeRead;
- keyInfoCtx.keysMngr = keysMngr;
+ keyInfoCtx.keysMngr = NULL;
keyInfoCtx.flags = XMLSEC_KEYINFO_FLAGS_DONT_STOP_ON_KEY_FOUND |
XMLSEC_KEYINFO_FLAGS_X509DATA_DONT_VERIFY_CERTS;
keyInfoCtx.keyReq.keyId = xmlSecKeyDataIdUnknown;
@@ -468,11 +444,8 @@ xmlSecSimpleKeysStoreLoad(xmlSecKeyStorePtr store, const char *uri,
ret = xmlSecKeyInfoNodeRead(cur, key, &keyInfoCtx);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyStoreGetName(store)),
- "xmlSecKeyInfoNodeRead",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecKeyInfoNodeRead",
+ xmlSecKeyStoreGetName(store));
xmlSecKeyInfoCtxFinalize(&keyInfoCtx);
xmlSecKeyDestroy(key);
xmlFreeDoc(doc);
@@ -483,11 +456,8 @@ xmlSecSimpleKeysStoreLoad(xmlSecKeyStorePtr store, const char *uri,
if(xmlSecKeyIsValid(key)) {
ret = xmlSecSimpleKeysStoreAdoptKey(store, key);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyStoreGetName(store)),
- "xmlSecSimpleKeysStoreAdoptKey",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecSimpleKeysStoreAdoptKey",
+ xmlSecKeyStoreGetName(store));
xmlSecKeyDestroy(key);
xmlFreeDoc(doc);
return(-1);
@@ -500,11 +470,7 @@ xmlSecSimpleKeysStoreLoad(xmlSecKeyStorePtr store, const char *uri,
}
if(cur != NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyStoreGetName(store)),
- xmlSecErrorsSafeString(xmlSecNodeGetName(cur)),
- XMLSEC_ERRORS_R_UNEXPECTED_NODE,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecUnexpectedNodeError(cur, xmlSecKeyStoreGetName(store));
xmlFreeDoc(doc);
return(-1);
}
@@ -547,11 +513,8 @@ xmlSecSimpleKeysStoreSave(xmlSecKeyStorePtr store, const char *filename, xmlSecK
/* create doc */
doc = xmlSecCreateTree(BAD_CAST "Keys", xmlSecNs);
if(doc == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyStoreGetName(store)),
- "xmlSecCreateTree",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecCreateTree",
+ xmlSecKeyStoreGetName(store));
return(-1);
}
@@ -566,12 +529,10 @@ xmlSecSimpleKeysStoreSave(xmlSecKeyStorePtr store, const char *filename, xmlSecK
cur = xmlSecAddChild(xmlDocGetRootElement(doc), xmlSecNodeKeyInfo, xmlSecDSigNs);
if(cur == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyStoreGetName(store)),
- "xmlSecAddChild",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeKeyInfo));
+ xmlSecInternalError2("xmlSecAddChild",
+ xmlSecKeyStoreGetName(store),
+ "node=%s",
+ xmlSecErrorsSafeString(xmlSecNodeKeyInfo));
xmlFreeDoc(doc);
return(-1);
}
@@ -579,12 +540,10 @@ xmlSecSimpleKeysStoreSave(xmlSecKeyStorePtr store, const char *filename, xmlSecK
/* special data key name */
if(xmlSecKeyGetName(key) != NULL) {
if(xmlSecAddChild(cur, xmlSecNodeKeyName, xmlSecDSigNs) == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyStoreGetName(store)),
- "xmlSecAddChild",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeKeyName));
+ xmlSecInternalError2("xmlSecAddChild",
+ xmlSecKeyStoreGetName(store),
+ "node=%s",
+ xmlSecErrorsSafeString(xmlSecNodeKeyName));
xmlFreeDoc(doc);
return(-1);
}
@@ -605,12 +564,9 @@ xmlSecSimpleKeysStoreSave(xmlSecKeyStorePtr store, const char *filename, xmlSecK
}
if(xmlSecAddChild(cur, dataId->dataNodeName, dataId->dataNodeNs) == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyStoreGetName(store)),
- "xmlSecAddChild",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "node=%s",
- xmlSecErrorsSafeString(dataId->dataNodeName));
+ xmlSecInternalError2("xmlSecAddChild",
+ xmlSecKeyStoreGetName(store),
+ "node=%s", xmlSecErrorsSafeString(dataId->dataNodeName));
xmlFreeDoc(doc);
return(-1);
}
@@ -618,11 +574,8 @@ xmlSecSimpleKeysStoreSave(xmlSecKeyStorePtr store, const char *filename, xmlSecK
ret = xmlSecKeyInfoCtxInitialize(&keyInfoCtx, NULL);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyStoreGetName(store)),
- "xmlSecKeyInfoCtxInitialize",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecKeyInfoCtxInitialize",
+ xmlSecKeyStoreGetName(store));
xmlFreeDoc(doc);
return(-1);
}
@@ -635,11 +588,8 @@ xmlSecSimpleKeysStoreSave(xmlSecKeyStorePtr store, const char *filename, xmlSecK
/* finally write key in the node */
ret = xmlSecKeyInfoNodeWrite(cur, key, &keyInfoCtx);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyStoreGetName(store)),
- "xmlSecKeyInfoNodeWrite",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecKeyInfoNodeWrite",
+ xmlSecKeyStoreGetName(store));
xmlSecKeyInfoCtxFinalize(&keyInfoCtx);
xmlFreeDoc(doc);
return(-1);
@@ -650,12 +600,8 @@ xmlSecSimpleKeysStoreSave(xmlSecKeyStorePtr store, const char *filename, xmlSecK
/* now write result */
ret = xmlSaveFormatFile(filename, doc, 1);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyStoreGetName(store)),
- "xmlSaveFormatFile",
- XMLSEC_ERRORS_R_XML_FAILED,
- "filename=%s",
- xmlSecErrorsSafeString(filename));
+ xmlSecXmlError2("xmlSaveFormatFile", xmlSecKeyStoreGetName(store),
+ "filename=%s", xmlSecErrorsSafeString(filename));
xmlFreeDoc(doc);
return(-1);
}
@@ -697,11 +643,8 @@ xmlSecSimpleKeysStoreInitialize(xmlSecKeyStorePtr store) {
ret = xmlSecPtrListInitialize(list, xmlSecKeyPtrListId);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyStoreGetName(store)),
- "xmlSecPtrListInitialize",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "xmlSecKeyPtrListId");
+ xmlSecInternalError("xmlSecPtrListInitialize(xmlSecKeyPtrListId)",
+ xmlSecKeyStoreGetName(store));
return(-1);
}