summaryrefslogtreecommitdiff
path: root/src/keyinfo.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/keyinfo.c')
-rw-r--r--src/keyinfo.c449
1 files changed, 164 insertions, 285 deletions
diff --git a/src/keyinfo.c b/src/keyinfo.c
index 958492f1..98dabc10 100644
--- a/src/keyinfo.c
+++ b/src/keyinfo.c
@@ -1,18 +1,27 @@
-/**
+/*
* XML Security Library (http://www.aleksey.com/xmlsec).
*
- * <dsig:KeyInfo/> element processing
- * (http://www.w3.org/TR/xmlSec-core/#sec-KeyInfo:
*
- * The KeyInfo Element
+ * This is free software; see Copyright file in the source
+ * distribution for preciese wording.
*
- * KeyInfo is an optional element that enables the recipient(s) to obtain
+ * Copyright (C) 2002-2016 Aleksey Sanin <aleksey@aleksey.com>. All Rights Reserved.
+ */
+/**
+ * SECTION:keyinfo
+ * @Short_description: &lt;dsig:KeyInfo/&gt; node parser functions.
+ * @Stability: Stable
+ *
+ *
+ * [KeyInfo](https://www.w3.org/TR/xmldsig-core/#sec-KeyInfo) is an
+ * optional element that enables the recipient(s) to obtain
* the key needed to validate the signature. KeyInfo may contain keys,
* names, certificates and other public key management information, such as
* in-band key distribution or key agreement data.
*
- * Schema Definition:
+ * Schema Definition:
*
+ * |[<!-- language="XML" -->
* <element name="KeyInfo" type="ds:KeyInfoType"/>
* <complexType name="KeyInfoType" mixed="true">
* <choice maxOccurs="unbounded">
@@ -28,19 +37,17 @@
* </choice>
* <attribute name="Id" type="ID" use="optional"/>
* </complexType>
+ * ]|
*
* DTD:
*
+ * |[<!-- language="XML" -->
* <!ELEMENT KeyInfo (#PCDATA|KeyName|KeyValue|RetrievalMethod|
* X509Data|PGPData|SPKIData|MgmtData %KeyInfo.ANY;)* >
* <!ATTLIST KeyInfo Id ID #IMPLIED >
- *
- *
- * 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.
+ * ]|
*/
+
#include "globals.h"
#include <stdlib.h>
@@ -111,22 +118,16 @@ xmlSecKeyInfoNodeRead(xmlNodePtr keyInfoNode, xmlSecKeyPtr key, xmlSecKeyInfoCtx
/* read data node */
ret = xmlSecKeyDataXmlRead(dataId, key, cur, keyInfoCtx);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(dataId)),
- "xmlSecKeyDataXmlRead",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeGetName(cur)));
+ xmlSecInternalError2("xmlSecKeyDataXmlRead",
+ xmlSecKeyDataKlassGetName(dataId),
+ "node=%s",
+ xmlSecErrorsSafeString(xmlSecNodeGetName(cur)));
return(-1);
}
} else if((keyInfoCtx->flags & XMLSEC_KEYINFO_FLAGS_STOP_ON_UNKNOWN_CHILD) != 0) {
/* there is a laxi schema validation but application may
* desire to disable unknown nodes*/
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- xmlSecErrorsSafeString(xmlSecNodeGetName(cur)),
- XMLSEC_ERRORS_R_INVALID_NODE,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecUnexpectedNodeError(cur, NULL);
return(-1);
}
}
@@ -178,21 +179,15 @@ xmlSecKeyInfoNodeWrite(xmlNodePtr keyInfoNode, xmlSecKeyPtr key, xmlSecKeyInfoCt
if(dataId != xmlSecKeyDataIdUnknown) {
ret = xmlSecKeyDataXmlWrite(dataId, key, cur, keyInfoCtx);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(dataId)),
- "xmlSecKeyDataXmlWrite",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeGetName(cur)));
+ xmlSecInternalError2("xmlSecKeyDataXmlWrite",
+ xmlSecKeyDataKlassGetName(dataId),
+ "node=%s",
+ xmlSecErrorsSafeString(xmlSecNodeGetName(cur)));
return(-1);
}
} else if((keyInfoCtx->flags & XMLSEC_KEYINFO_FLAGS_STOP_ON_UNKNOWN_CHILD) != 0) {
/* laxi schema validation but application can disable it*/
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- xmlSecErrorsSafeString(xmlSecNodeGetName(cur)),
- XMLSEC_ERRORS_R_INVALID_NODE,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecUnexpectedNodeError(cur, NULL);
return(-1);
}
}
@@ -223,21 +218,13 @@ xmlSecKeyInfoCtxCreate(xmlSecKeysMngrPtr keysMngr) {
/* Allocate a new xmlSecKeyInfoCtx and fill the fields. */
keyInfoCtx = (xmlSecKeyInfoCtxPtr)xmlMalloc(sizeof(xmlSecKeyInfoCtx));
if(keyInfoCtx == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- NULL,
- XMLSEC_ERRORS_R_MALLOC_FAILED,
- "size=%d", (int)sizeof(xmlSecKeyInfoCtx));
+ xmlSecMallocError(sizeof(xmlSecKeyInfoCtx), NULL);
return(NULL);
}
ret = xmlSecKeyInfoCtxInitialize(keyInfoCtx, keysMngr);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "xmlSecKeyInfoCtxInitialize",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecKeyInfoCtxInitialize", NULL);
xmlSecKeyInfoCtxDestroy(keyInfoCtx);
return(NULL);
}
@@ -280,22 +267,14 @@ xmlSecKeyInfoCtxInitialize(xmlSecKeyInfoCtxPtr keyInfoCtx, xmlSecKeysMngrPtr key
keyInfoCtx->base64LineSize = xmlSecBase64GetDefaultLineSize();
ret = xmlSecPtrListInitialize(&(keyInfoCtx->enabledKeyData), xmlSecKeyDataIdListId);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "xmlSecPtrListInitialize",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecPtrListInitialize", NULL);
return(-1);
}
keyInfoCtx->maxRetrievalMethodLevel = 1;
ret = xmlSecTransformCtxInitialize(&(keyInfoCtx->retrievalMethodCtx));
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "xmlSecTransformCtxInitialize",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecTransformCtxInitialize", NULL);
return(-1);
}
@@ -309,11 +288,7 @@ xmlSecKeyInfoCtxInitialize(xmlSecKeyInfoCtxPtr keyInfoCtx, xmlSecKeysMngrPtr key
ret = xmlSecKeyReqInitialize(&(keyInfoCtx->keyReq));
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "xmlSecKeyReqInitialize",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecKeyReqInitialize", NULL);
return(-1);
}
@@ -388,11 +363,7 @@ xmlSecKeyInfoCtxCreateEncCtx(xmlSecKeyInfoCtxPtr keyInfoCtx) {
/* we have to use tmp variable to avoid a recursive loop */
tmp = xmlSecEncCtxCreate(keyInfoCtx->keysMngr);
if(tmp == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "xmlSecEncCtxCreate",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecEncCtxCreate", NULL);
return(-1);
}
tmp->mode = xmlEncCtxModeEncryptedKey;
@@ -402,11 +373,7 @@ xmlSecKeyInfoCtxCreateEncCtx(xmlSecKeyInfoCtxPtr keyInfoCtx) {
case xmlSecKeyInfoModeRead:
ret = xmlSecKeyInfoCtxCopyUserPref(&(tmp->keyInfoReadCtx), keyInfoCtx);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "xmlSecKeyInfoCtxCopyUserPref",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecKeyInfoCtxCopyUserPref", NULL);
xmlSecEncCtxDestroy(tmp);
return(-1);
}
@@ -414,11 +381,7 @@ xmlSecKeyInfoCtxCreateEncCtx(xmlSecKeyInfoCtxPtr keyInfoCtx) {
case xmlSecKeyInfoModeWrite:
ret = xmlSecKeyInfoCtxCopyUserPref(&(tmp->keyInfoWriteCtx), keyInfoCtx);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "xmlSecKeyInfoCtxCopyUserPref",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecKeyInfoCtxCopyUserPref", NULL);
xmlSecEncCtxDestroy(tmp);
return(-1);
}
@@ -428,11 +391,8 @@ xmlSecKeyInfoCtxCreateEncCtx(xmlSecKeyInfoCtxPtr keyInfoCtx) {
return(0);
#else /* XMLSEC_NO_XMLENC */
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "xml encryption",
- XMLSEC_ERRORS_R_DISABLED,
- XMLSEC_ERRORS_NO_MESSAGE);
+
+ xmlSecOtherError(XMLSEC_ERRORS_R_DISABLED, NULL, "xml encryption");
return(-1);
#endif /* XMLSEC_NO_XMLENC */
}
@@ -462,11 +422,7 @@ xmlSecKeyInfoCtxCopyUserPref(xmlSecKeyInfoCtxPtr dst, xmlSecKeyInfoCtxPtr src) {
ret = xmlSecPtrListCopy(&(dst->enabledKeyData), &(src->enabledKeyData));
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "xmlSecPtrListCopy",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "enabledKeyData");
+ xmlSecInternalError("xmlSecPtrListCopy(enabledKeyData)", NULL);
return(-1);
}
@@ -475,11 +431,7 @@ xmlSecKeyInfoCtxCopyUserPref(xmlSecKeyInfoCtxPtr dst, xmlSecKeyInfoCtxPtr src) {
ret = xmlSecTransformCtxCopyUserPref(&(dst->retrievalMethodCtx),
&(src->retrievalMethodCtx));
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "xmlSecTransformCtxCopyUserPref",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "enabledKeyData");
+ xmlSecInternalError("xmlSecTransformCtxCopyUserPref(enabledKeyData)", NULL);
return(-1);
}
@@ -489,22 +441,14 @@ xmlSecKeyInfoCtxCopyUserPref(xmlSecKeyInfoCtxPtr dst, xmlSecKeyInfoCtxPtr src) {
if(src->encCtx != NULL) {
dst->encCtx = xmlSecEncCtxCreate(dst->keysMngr);
if(dst->encCtx == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "xmlSecEncCtxCreate",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecEncCtxCreate", NULL);
return(-1);
}
dst->encCtx->mode = xmlEncCtxModeEncryptedKey;
ret = xmlSecEncCtxCopyUserPref(dst->encCtx, src->encCtx);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "xmlSecEncCtxCopyUserPref",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecEncCtxCopyUserPref", NULL);
return(-1);
}
}
@@ -696,7 +640,6 @@ xmlSecKeyDataNameGetKlass(void) {
static int
xmlSecKeyDataNameXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNodePtr node, xmlSecKeyInfoCtxPtr keyInfoCtx) {
- const xmlChar* oldName;
xmlChar* newName;
int ret;
@@ -706,26 +649,10 @@ xmlSecKeyDataNameXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNodePtr node,
xmlSecAssert2(keyInfoCtx != NULL, -1);
xmlSecAssert2(keyInfoCtx->mode == xmlSecKeyInfoModeRead, -1);
- oldName = xmlSecKeyGetName(key);
+ /* read key name */
newName = xmlNodeGetContent(node);
if(newName == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- xmlSecErrorsSafeString(xmlSecNodeGetName(node)),
- XMLSEC_ERRORS_R_INVALID_NODE_CONTENT,
- XMLSEC_ERRORS_NO_MESSAGE);
- return(-1);
- }
- /* TODO: do we need to decode the name? */
-
- /* compare name values */
- if((oldName != NULL) && !xmlStrEqual(oldName, newName)) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "key name is already specified",
- XMLSEC_ERRORS_R_INVALID_KEY_DATA,
- XMLSEC_ERRORS_NO_MESSAGE);
- xmlFree(newName);
+ xmlSecInvalidNodeContentError(node, xmlSecKeyDataKlassGetName(id), "empty");
return(-1);
}
@@ -746,32 +673,49 @@ xmlSecKeyDataNameXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNodePtr node,
/* and copy what we've found */
ret = xmlSecKeyCopy(key, tmpKey);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecKeyCopy",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecKeyCopy",
+ xmlSecKeyDataKlassGetName(id));
xmlSecKeyDestroy(tmpKey);
xmlFree(newName);
return(-1);
}
xmlSecKeyDestroy(tmpKey);
- }
- }
- /* finally set key name if it is not there */
- if(xmlSecKeyGetName(key) == NULL) {
- ret = xmlSecKeySetName(key, newName);
- if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecKeySetName",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
- xmlFree(newName);
- return(-1);
+ /* and set the key name */
+ ret = xmlSecKeySetName(key, newName);
+ if(ret < 0) {
+ xmlSecInternalError("xmlSecKeySetName",
+ xmlSecKeyDataKlassGetName(id));
+ xmlFree(newName);
+ return(-1);
+ }
+ }
+ /* TODO: record the key names we tried */
+ } else {
+ const xmlChar* oldName;
+
+ /* if we already have a keyname, make sure that it matches or set it */
+ oldName = xmlSecKeyGetName(key);
+ if(oldName != NULL) {
+ if(!xmlStrEqual(oldName, newName)) {
+ xmlSecOtherError(XMLSEC_ERRORS_R_INVALID_KEY_DATA,
+ xmlSecKeyDataKlassGetName(id),
+ "key name is already specified");
+ xmlFree(newName);
+ return(-1);
+ }
+ } else {
+ ret = xmlSecKeySetName(key, newName);
+ if(ret < 0) {
+ xmlSecInternalError("xmlSecKeySetName",
+ xmlSecKeyDataKlassGetName(id));
+ xmlFree(newName);
+ return(-1);
+ }
}
}
+
+ /* done */
xmlFree(newName);
return(0);
}
@@ -779,6 +723,7 @@ xmlSecKeyDataNameXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNodePtr node,
static int
xmlSecKeyDataNameXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNodePtr node, xmlSecKeyInfoCtxPtr keyInfoCtx) {
const xmlChar* name;
+ int ret;
xmlSecAssert2(id == xmlSecKeyDataNameId, -1);
xmlSecAssert2(key != NULL, -1);
@@ -787,9 +732,21 @@ xmlSecKeyDataNameXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNodePtr node,
xmlSecAssert2(keyInfoCtx->mode == xmlSecKeyInfoModeWrite, -1);
name = xmlSecKeyGetName(key);
- if(name != NULL) {
- xmlSecNodeEncodeAndSetContent(node, name);
+ if(name == NULL) {
+ return(8);
+ }
+
+ if(!xmlSecIsEmptyNode(node)) {
+ return(0);
}
+
+ ret = xmlSecNodeEncodeAndSetContent(node, name);
+ if(ret < 0) {
+ xmlSecInternalError("xmlSecNodeEncodeAndSetContent", NULL);
+ return(-1);
+ }
+
+ /* done */
return(0);
}
@@ -896,32 +853,22 @@ xmlSecKeyDataValueXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNodePtr node,
/* read data node */
ret = xmlSecKeyDataXmlRead(dataId, key, cur, keyInfoCtx);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecKeyDataXmlRead",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeGetName(cur)));
+ xmlSecInternalError2("xmlSecKeyDataXmlRead",
+ xmlSecKeyDataKlassGetName(id),
+ "node=%s",
+ xmlSecErrorsSafeString(xmlSecNodeGetName(cur)));
return(-1);
}
} else if((keyInfoCtx->flags & XMLSEC_KEYINFO_FLAGS_KEYVALUE_STOP_ON_UNKNOWN_CHILD) != 0) {
/* laxi schema validation but application can disable it */
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- xmlSecErrorsSafeString(xmlSecNodeGetName(cur)),
- XMLSEC_ERRORS_R_INVALID_NODE,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecUnexpectedNodeError(cur, xmlSecKeyDataKlassGetName(id));
return(-1);
}
/* <dsig:KeyValue/> might have only one node */
cur = xmlSecGetNextElementNode(cur->next);
if(cur != NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- xmlSecErrorsSafeString(xmlSecNodeGetName(cur)),
- XMLSEC_ERRORS_R_UNEXPECTED_NODE,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecUnexpectedNodeError(cur, xmlSecKeyDataKlassGetName(id));
return(-1);
}
@@ -967,23 +914,19 @@ xmlSecKeyDataValueXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNodePtr node
/* create key node */
cur = xmlSecAddChild(node, nodeName, nodeNs);
if(cur == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecAddChild",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeGetName(node)));
+ xmlSecInternalError2("xmlSecAddChild",
+ xmlSecKeyDataKlassGetName(id),
+ "node=%s",
+ xmlSecErrorsSafeString(xmlSecNodeGetName(node)));
return(-1);
}
ret = xmlSecKeyDataXmlWrite(key->value->id, key, cur, keyInfoCtx);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecKeyDataXmlWrite",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeGetName(cur)));
+ xmlSecInternalError2("xmlSecKeyDataXmlWrite",
+ xmlSecKeyDataKlassGetName(id),
+ "node=%s",
+ xmlSecErrorsSafeString(xmlSecNodeGetName(cur)));
return(-1);
}
@@ -1090,13 +1033,11 @@ xmlSecKeyDataRetrievalMethodXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNod
/* check retrieval level */
if(keyInfoCtx->curRetrievalMethodLevel >= keyInfoCtx->maxRetrievalMethodLevel) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- NULL,
- XMLSEC_ERRORS_R_MAX_RETRIEVALS_LEVEL,
- "cur=%d;max=%d",
- keyInfoCtx->curRetrievalMethodLevel,
- keyInfoCtx->maxRetrievalMethodLevel);
+ xmlSecOtherError3(XMLSEC_ERRORS_R_MAX_RETRIEVALS_LEVEL,
+ xmlSecKeyDataKlassGetName(id),
+ "cur=%d;max=%d",
+ keyInfoCtx->curRetrievalMethodLevel,
+ keyInfoCtx->maxRetrievalMethodLevel);
goto done;
}
++keyInfoCtx->curRetrievalMethodLevel;
@@ -1113,14 +1054,12 @@ xmlSecKeyDataRetrievalMethodXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNod
}
}
- /* laxi schema validation but aplication can disable it */
+ /* laxi schema validation but application can disable it */
if(dataId == xmlSecKeyDataIdUnknown) {
if((keyInfoCtx->flags & XMLSEC_KEYINFO_FLAGS_RETRMETHOD_STOP_ON_UNKNOWN_HREF) != 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- xmlSecErrorsSafeString(xmlSecAttrType),
- XMLSEC_ERRORS_R_INVALID_NODE_ATTRIBUTE,
- "value=%s", xmlSecErrorsSafeString(retrType));
+ xmlSecInvalidNodeAttributeError(node, xmlSecAttrType,
+ xmlSecKeyDataKlassGetName(id),
+ "retrieval type is unknown");
} else {
res = 0;
}
@@ -1134,12 +1073,9 @@ xmlSecKeyDataRetrievalMethodXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNod
uri = xmlGetProp(node, xmlSecAttrURI);
ret = xmlSecTransformCtxSetUri(&(keyInfoCtx->retrievalMethodCtx), uri, node);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecTransformCtxSetUri",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "uri=%s",
- xmlSecErrorsSafeString(uri));
+ xmlSecInternalError2("xmlSecTransformCtxSetUri",
+ xmlSecKeyDataKlassGetName(id),
+ "uri=%s", xmlSecErrorsSafeString(uri));
goto done;
}
@@ -1149,23 +1085,17 @@ xmlSecKeyDataRetrievalMethodXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNod
ret = xmlSecTransformCtxNodesListRead(&(keyInfoCtx->retrievalMethodCtx),
cur, xmlSecTransformUsageDSigTransform);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecTransformCtxNodesListRead",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeGetName(cur)));
+ xmlSecInternalError2("xmlSecTransformCtxNodesListRead",
+ xmlSecKeyDataKlassGetName(id),
+ "node=%s",
+ xmlSecErrorsSafeString(xmlSecNodeGetName(cur)));
goto done;
}
cur = xmlSecGetNextElementNode(cur->next);
}
if(cur != NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- xmlSecErrorsSafeString(xmlSecNodeGetName(cur)),
- XMLSEC_ERRORS_R_UNEXPECTED_NODE,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecUnexpectedNodeError(cur, xmlSecKeyDataKlassGetName(id));
goto done;
}
@@ -1175,11 +1105,8 @@ xmlSecKeyDataRetrievalMethodXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNod
(keyInfoCtx->retrievalMethodCtx.result == NULL) ||
(xmlSecBufferGetData(keyInfoCtx->retrievalMethodCtx.result) == NULL)) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecTransformCtxExecute",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecTransformCtxExecute",
+ xmlSecKeyDataKlassGetName(id));
goto done;
}
@@ -1193,11 +1120,8 @@ xmlSecKeyDataRetrievalMethodXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNod
xmlSecBufferGetSize(keyInfoCtx->retrievalMethodCtx.result),
keyInfoCtx);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecKeyDataRetrievalMethodReadXmlResult",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecKeyDataRetrievalMethodReadXmlResult",
+ xmlSecKeyDataKlassGetName(id));
goto done;
}
} else {
@@ -1206,11 +1130,8 @@ xmlSecKeyDataRetrievalMethodXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNod
xmlSecBufferGetSize(keyInfoCtx->retrievalMethodCtx.result),
keyInfoCtx);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecKeyDataBinRead",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecKeyDataBinRead",
+ xmlSecKeyDataKlassGetName(id));
goto done;
}
}
@@ -1258,21 +1179,13 @@ xmlSecKeyDataRetrievalMethodReadXmlResult(xmlSecKeyDataId typeId, xmlSecKeyPtr k
doc = xmlRecoverMemory((const char*)buffer, bufferSize);
if(doc == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(typeId)),
- "xmlRecoverMemory",
- XMLSEC_ERRORS_R_XML_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecXmlError("xmlRecoverMemory", xmlSecKeyDataKlassGetName(typeId));
return(-1);
}
cur = xmlDocGetRootElement(doc);
if(cur == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(typeId)),
- "xmlDocGetRootElement",
- XMLSEC_ERRORS_R_XML_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecXmlError("xmlDocGetRootElement", xmlSecKeyDataKlassGetName(typeId));
xmlFreeDoc(doc);
return(-1);
}
@@ -1293,22 +1206,16 @@ xmlSecKeyDataRetrievalMethodReadXmlResult(xmlSecKeyDataId typeId, xmlSecKeyPtr k
/* laxi schema validation but application can disable it */
if((keyInfoCtx->flags & XMLSEC_KEYINFO_FLAGS_KEYVALUE_STOP_ON_UNKNOWN_CHILD) != 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(typeId)),
- xmlSecErrorsSafeString(xmlSecNodeGetName(cur)),
- XMLSEC_ERRORS_R_INVALID_NODE,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecUnexpectedNodeError(cur, xmlSecKeyDataKlassGetName(typeId));
return(-1);
}
return(0);
} else if((typeId != xmlSecKeyDataIdUnknown) && (typeId != dataId) &&
((keyInfoCtx->flags & XMLSEC_KEYINFO_FLAGS_RETRMETHOD_STOP_ON_MISMATCH_HREF) != 0)) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(typeId)),
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(dataId)),
- XMLSEC_ERRORS_R_MAX_RETRIEVAL_TYPE_MISMATCH,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecOtherError2(XMLSEC_ERRORS_R_MAX_RETRIEVAL_TYPE_MISMATCH,
+ xmlSecKeyDataKlassGetName(dataId),
+ "typeId=%s", xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(typeId)));
xmlFreeDoc(doc);
return(-1);
}
@@ -1316,12 +1223,10 @@ xmlSecKeyDataRetrievalMethodReadXmlResult(xmlSecKeyDataId typeId, xmlSecKeyPtr k
/* read data node */
ret = xmlSecKeyDataXmlRead(dataId, key, cur, keyInfoCtx);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(typeId)),
- "xmlSecKeyDataXmlRead",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "node=%s",
- xmlSecErrorsSafeString(xmlSecNodeGetName(cur)));
+ xmlSecInternalError2("xmlSecKeyDataXmlRead",
+ xmlSecKeyDataKlassGetName(typeId),
+ "node=%s",
+ xmlSecErrorsSafeString(xmlSecNodeGetName(cur)));
xmlFreeDoc(doc);
return(-1);
}
@@ -1420,13 +1325,11 @@ xmlSecKeyDataEncryptedKeyXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNodePt
/* check the enc level */
if(keyInfoCtx->curEncryptedKeyLevel >= keyInfoCtx->maxEncryptedKeyLevel) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- NULL,
- XMLSEC_ERRORS_R_MAX_ENCKEY_LEVEL,
- "cur=%d;max=%d",
- keyInfoCtx->curEncryptedKeyLevel,
- keyInfoCtx->maxEncryptedKeyLevel);
+ xmlSecOtherError3(XMLSEC_ERRORS_R_MAX_ENCKEY_LEVEL,
+ xmlSecKeyDataKlassGetName(id),
+ "cur=%d;max=%d",
+ (int)keyInfoCtx->curEncryptedKeyLevel,
+ (int)keyInfoCtx->maxEncryptedKeyLevel);
return(-1);
}
++keyInfoCtx->curEncryptedKeyLevel;
@@ -1437,11 +1340,8 @@ xmlSecKeyDataEncryptedKeyXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNodePt
} else {
ret = xmlSecKeyInfoCtxCreateEncCtx(keyInfoCtx);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecKeyInfoCtxCreateEncCtx",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecKeyInfoCtxCreateEncCtx",
+ xmlSecKeyDataKlassGetName(id));
return(-1);
}
}
@@ -1450,15 +1350,12 @@ xmlSecKeyDataEncryptedKeyXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNodePt
result = xmlSecEncCtxDecryptToBuffer(keyInfoCtx->encCtx, node);
if((result == NULL) || (xmlSecBufferGetData(result) == NULL)) {
/* We might have multiple EncryptedKey elements, encrypted
- * for different receipints but application can enforce
+ * for different recipients but application can enforce
* correct enc key.
*/
if((keyInfoCtx->flags & XMLSEC_KEYINFO_FLAGS_ENCKEY_DONT_STOP_ON_FAILED_DECRYPTION) != 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecEncCtxDecryptToBuffer",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecEncCtxDecryptToBuffer",
+ xmlSecKeyDataKlassGetName(id));
return(-1);
}
return(0);
@@ -1469,11 +1366,8 @@ xmlSecKeyDataEncryptedKeyXmlRead(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNodePt
xmlSecBufferGetSize(result),
keyInfoCtx);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecKeyDataBinRead",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecKeyDataBinRead",
+ xmlSecKeyDataKlassGetName(id));
return(-1);
}
--keyInfoCtx->curEncryptedKeyLevel;
@@ -1499,21 +1393,15 @@ xmlSecKeyDataEncryptedKeyXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNodeP
/* dump key to a binary buffer */
ret = xmlSecKeyInfoCtxInitialize(&keyInfoCtx2, NULL);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecKeyInfoCtxInitialize",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecKeyInfoCtxInitialize",
+ xmlSecKeyDataKlassGetName(id));
goto done;
}
ret = xmlSecKeyInfoCtxCopyUserPref(&keyInfoCtx2, keyInfoCtx);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecKeyInfoCtxCopyUserPref",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecKeyInfoCtxCopyUserPref",
+ xmlSecKeyDataKlassGetName(id));
xmlSecKeyInfoCtxFinalize(&keyInfoCtx2);
goto done;
}
@@ -1521,11 +1409,8 @@ xmlSecKeyDataEncryptedKeyXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNodeP
keyInfoCtx2.keyReq.keyType = xmlSecKeyDataTypeAny;
ret = xmlSecKeyDataBinWrite(key->value->id, key, &keyBuf, &keySize, &keyInfoCtx2);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecKeyDataBinWrite",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecKeyDataBinWrite",
+ xmlSecKeyDataKlassGetName(id));
xmlSecKeyInfoCtxFinalize(&keyInfoCtx2);
goto done;
}
@@ -1537,11 +1422,8 @@ xmlSecKeyDataEncryptedKeyXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNodeP
} else {
ret = xmlSecKeyInfoCtxCreateEncCtx(keyInfoCtx);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecKeyInfoCtxCreateEncCtx",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecKeyInfoCtxCreateEncCtx",
+ xmlSecKeyDataKlassGetName(id));
goto done;
}
}
@@ -1549,11 +1431,8 @@ xmlSecKeyDataEncryptedKeyXmlWrite(xmlSecKeyDataId id, xmlSecKeyPtr key, xmlNodeP
ret = xmlSecEncCtxBinaryEncrypt(keyInfoCtx->encCtx, node, keyBuf, keySize);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecKeyDataKlassGetName(id)),
- "xmlSecEncCtxBinaryEncrypt",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecEncCtxBinaryEncrypt",
+ xmlSecKeyDataKlassGetName(id));
goto done;
}