facho-signer: se usa autoconf
FossilOrigin-Name: 5a7e25376d54d22f8d955c9b6827785d2efd673fee9813b27f4ce39d4a3e8f7e
This commit is contained in:
4
experimental/facho-signer/src/Makefile.am
Normal file
4
experimental/facho-signer/src/Makefile.am
Normal file
@@ -0,0 +1,4 @@
|
||||
bin_PROGRAMS = facho_signer
|
||||
facho_signer_SOURCES = xades/xmlsec1/xmltree.c xades/xmlsec1/errors.c xades/templates.c xades/xades.c facho_signer.c
|
||||
facho_signer_CFLAGS = $(XMLSEC1_CFLAGS) -DXMLSEC_NOT_CRYPTO_DYNAMIC_LOADING
|
||||
facho_signer_LDADD = $(XMLSEC1_LIBS)
|
||||
11
experimental/facho-signer/src/README.md
Normal file
11
experimental/facho-signer/src/README.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# facho-signer
|
||||
|
||||
|
||||
## guia
|
||||
|
||||
- http://xmlsoft.org/html/libxml-tree.html
|
||||
- http://xmlsoft.org/html/libxml-xpath.html
|
||||
- http://xmlsoft.org/examples/xpath1.c
|
||||
- http://xmlsoft.org/tutorial/ar01s05.html
|
||||
- https://www.aleksey.com/xmlsec/api/xmlsec-reference.html
|
||||
- https://zakird.com/2013/10/13/certificate-parsing-with-openssl
|
||||
407
experimental/facho-signer/src/facho_signer.c
Normal file
407
experimental/facho-signer/src/facho_signer.c
Normal file
@@ -0,0 +1,407 @@
|
||||
#include "config.h"
|
||||
#include "xades/xades.h"
|
||||
|
||||
#include <xmlsec/xmlsec.h>
|
||||
#include <xmlsec/xmltree.h>
|
||||
#include <xmlsec/xmldsig.h>
|
||||
#include <xmlsec/templates.h>
|
||||
#include <xmlsec/crypto.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
#define print_error(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
|
||||
#define print_info(fmt, ...) fprintf(stdout, fmt, ##__VA_ARGS__)
|
||||
|
||||
const xmlChar ublExtensionDSigNs[] = "urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2";
|
||||
const xmlChar policyIdDescription[] = "Política de firma para facturas electrónicas de la República de Colombia.";
|
||||
const xmlChar policyIdIdentifier[] = "https://facturaelectronica.dian.gov.co/politicadefirma/v2/politicadefirmav2.pdf";
|
||||
|
||||
char *basename = NULL;
|
||||
|
||||
// crea elemento /Invoice/ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent
|
||||
xmlNodePtr
|
||||
xmlFachoTmplUBLExtensionAddExtensionContent(xmlDocPtr doc);
|
||||
|
||||
// FeC requiere que el digest value del policy identifier sea
|
||||
// apartir del contenido de la url.
|
||||
int
|
||||
xmlFachoPolicyIdentifierCtxFromFilename(const xmlChar *, xmlSecBufferPtr);
|
||||
|
||||
|
||||
int
|
||||
xmlFachoTmplXadesCreate(xmlDocPtr doc, xmlNodePtr signNode) {
|
||||
xmlNodePtr qualifyingPropertiesNode = NULL;
|
||||
xmlNodePtr signedPropertiesNode = NULL;
|
||||
xmlNodePtr signedSignaturePropertiesNode = NULL;
|
||||
xmlNodePtr signingCertificateNode = NULL;
|
||||
xmlNodePtr signaturePolicyIdentifierNode = NULL;
|
||||
xmlNodePtr signaturePolicyIdNode = NULL;
|
||||
xmlNodePtr sigPolicyIdNode = NULL;
|
||||
xmlNodePtr sigPolicyHashNode = NULL;
|
||||
xmlNodePtr signerRoleNode = NULL;
|
||||
xmlNodePtr refNode = NULL;
|
||||
const xmlChar signedPropertiesId[] = "xmldsig-facho-signed-props";
|
||||
const xmlChar signedPropertiesRef[] = "#xmldsig-facho-signed-props";
|
||||
|
||||
qualifyingPropertiesNode = xmlXadesTmplQualifyingPropertiesCreate(doc, signNode, BAD_CAST "xades-ref1");
|
||||
if ( qualifyingPropertiesNode == NULL ) {
|
||||
print_error("error: failed to add QualifyingProperties node.\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
signedPropertiesNode = xmlXadesTmplAddSignedProperties(qualifyingPropertiesNode, signedPropertiesId);
|
||||
if ( signedPropertiesNode == NULL ) {
|
||||
print_error("error: xades failed to add signed properties node.\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
refNode = xmlSecTmplSignatureAddReference(signNode,
|
||||
xmlSecTransformSha256Id,
|
||||
BAD_CAST "xmldsig-facho-ref1",
|
||||
signedPropertiesRef,
|
||||
BAD_CAST "http://uri.etsi.org/01903#SignedProperties");
|
||||
if ( refNode == NULL ) {
|
||||
print_error("error: failed to add reference to signature template xades.\n");
|
||||
goto fail;
|
||||
}
|
||||
if ( xmlSecTmplReferenceAddTransform(refNode, xmlSecTransformInclC14NId) == NULL ) {
|
||||
print_error("error: failed to add enveloped transform to reference for xades\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
const time_t now = time(NULL);
|
||||
signedSignaturePropertiesNode = xmlXadesTmplAddSignedSignatureProperties(signedPropertiesNode, localtime(&now));
|
||||
if ( signedSignaturePropertiesNode == NULL ) {
|
||||
print_error("error: xades failed to add signed signature properties node.\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
signingCertificateNode = xmlXadesTmplAddSigningCertificate(signedSignaturePropertiesNode, xmlSecTransformSha256Id);
|
||||
if ( signingCertificateNode == NULL ) {
|
||||
print_error("error: failed to add SigningCertificate node \n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
signaturePolicyIdentifierNode = xmlXadesTmplAddSignaturePolicyIdentifier(signedSignaturePropertiesNode);
|
||||
if ( signaturePolicyIdentifierNode == NULL ) {
|
||||
print_error("error: failed to add PolicyIdentifier node\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
signaturePolicyIdNode = xmlXadesTmplAddSignaturePolicyId(signaturePolicyIdentifierNode);
|
||||
if ( signaturePolicyIdNode == NULL ) {
|
||||
print_error("error: failed to add SignaturePolicyId node.\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
sigPolicyIdNode = xmlXadesTmplAddSigPolicyId(signaturePolicyIdNode, policyIdIdentifier, policyIdDescription);
|
||||
if ( sigPolicyIdNode == NULL ) {
|
||||
print_error("error: failed to add SigPolicyId node.\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
sigPolicyHashNode = xmlXadesTmplAddSigPolicyHash(signaturePolicyIdNode, xmlSecTransformSha256Id);
|
||||
if ( sigPolicyHashNode == NULL ) {
|
||||
print_error("error: failed to add SigPolicyHash node.\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
signerRoleNode = xmlXadesTmplAddSignerRole(signedSignaturePropertiesNode, BAD_CAST "supplier");
|
||||
if ( signerRoleNode == NULL ) {
|
||||
print_error("error: failed to add SignerRole node.\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
||||
return(0);
|
||||
fail:
|
||||
xmlUnlinkNode(qualifyingPropertiesNode);
|
||||
xmlFreeNode(qualifyingPropertiesNode);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
static int
|
||||
xmlXadesAppInit() {
|
||||
xmlInitParser();
|
||||
LIBXML_TEST_VERSION;
|
||||
|
||||
if ( xmlSecInit() < 0 ) {
|
||||
print_error("xmlsec initialization failed.\n");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
if ( xmlSecCheckVersion() != 1 ) {
|
||||
print_error("loaded xmlsec library version is not compatible.\n");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
#ifdef XMLSEC_CRYPTO_DYNAMIC_LOADING
|
||||
if(xmlSecCryptoDLLoadLibrary( NULL ) < 0) {
|
||||
fprintf(stderr, "Error: unable to load default xmlsec-crypto library. Make sure\n"
|
||||
"that you have it installed and check shared libraries path\n"
|
||||
"(LD_LIBRARY_PATH and/or LTDL_LIBRARY_PATH) environment variables.\n");
|
||||
return(-1);
|
||||
}
|
||||
#endif /* XMLSEC_CRYPTO_DYNAMIC_LOADING */
|
||||
|
||||
if ( xmlSecCryptoAppInit(NULL) < 0 ) {
|
||||
print_error("crypto initialization failed.\n");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
if ( xmlSecCryptoInit() < 0 ) {
|
||||
print_error("xmlsec-crypto initialization failed.\n");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
static int
|
||||
xmlXadesAppShutdown() {
|
||||
|
||||
if ( xmlSecCryptoShutdown() < 0 ) {
|
||||
print_error("xmlSecCryptoShutdown failed.\n");
|
||||
}
|
||||
|
||||
if ( xmlSecCryptoAppShutdown() < 0 ) {
|
||||
print_error("xmlSecCryptoAppShutdown failed.\n");
|
||||
}
|
||||
|
||||
if ( xmlSecShutdown() < 0 ) {
|
||||
print_error("xmlsec shutdown failed.\n");
|
||||
}
|
||||
|
||||
xmlCleanupParser();
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
X509 *cert = xmlSecOpenSSLKeyDataX509GetCert(keyData, 0);
|
||||
if (cert == NULL) {
|
||||
print_error("xmlSecOpenSSLKeyDataX509GetKeyCert fail\n");
|
||||
}
|
||||
|
||||
char *issuer = X509_NAME_oneline(X509_get_issuer_name(cert), NULL, 0);
|
||||
|
||||
printf("x509 issuer: %s\n", issuer);
|
||||
|
||||
//https://stackoverflow.com/questions/9749560/how-to-calculate-x-509-certificates-sha-1-fingerprint-in-c-c-objective-c
|
||||
unsigned char md[EVP_MAX_MD_SIZE];
|
||||
unsigned int n;
|
||||
const EVP_MD *digest = EVP_get_digestbyname("sha256");
|
||||
X509_digest(cert, digest, md, &n);
|
||||
printf("%s", "Fingerprint:");
|
||||
for(int pos = 0; pos < 19 ; pos++) {
|
||||
printf("%02x:", md[pos]);
|
||||
}
|
||||
printf("%02x\n", md[19]);
|
||||
*/
|
||||
|
||||
static int
|
||||
xmlXadesSignFile(const char *filename, const char *pkcs12name, const char *password) {
|
||||
xmlDocPtr doc = NULL;
|
||||
xmlNodePtr signNode = NULL;
|
||||
xmlNodePtr refNode = NULL;
|
||||
xmlNodePtr keyInfoNode = NULL;
|
||||
xmlNodePtr x509DataNode = NULL;
|
||||
xmlNodePtr node = NULL;
|
||||
xmlSecDSigCtxPtr dsigCtx = NULL;
|
||||
xmlXadesDSigCtxPtr xadesDsigCtx = NULL;
|
||||
|
||||
int res = -1;
|
||||
|
||||
if (filename == NULL) {
|
||||
return(-1);
|
||||
}
|
||||
|
||||
doc = xmlParseFile(filename);
|
||||
if ( (doc == NULL) || (xmlDocGetRootElement(doc) == NULL) ) {
|
||||
print_error("error: unable to parse file %s\n", filename);
|
||||
goto done;
|
||||
}
|
||||
|
||||
signNode = xmlSecTmplSignatureCreate(doc, xmlSecTransformInclC14NId,
|
||||
xmlSecTransformRsaSha256Id, NULL);
|
||||
if ( signNode == NULL ) {
|
||||
print_error("error: failed to create signature template.\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
xmlAddChild(xmlDocGetRootElement(doc), signNode);
|
||||
|
||||
refNode = xmlSecTmplSignatureAddReference(signNode,
|
||||
xmlSecTransformSha256Id,
|
||||
BAD_CAST "xmldsig-facho-ref0", // id
|
||||
BAD_CAST "", //uri
|
||||
NULL); //type
|
||||
if ( refNode == NULL ) {
|
||||
print_error("error: failed to add reference to signature template.\n");
|
||||
goto done;
|
||||
}
|
||||
if ( xmlSecTmplReferenceAddTransform(refNode, xmlSecTransformEnvelopedId) == NULL ) {
|
||||
print_error("error: failed to add enveloped transform to reference\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
refNode = xmlSecTmplSignatureAddReference(signNode,
|
||||
xmlSecTransformSha256Id,
|
||||
BAD_CAST "xmldsig-facho-ref2",
|
||||
BAD_CAST "#xmldsig-facho-KeyInfo",
|
||||
NULL);
|
||||
if ( refNode == NULL ) {
|
||||
print_error("error: failed to add reference to signature template key-info.\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
keyInfoNode = xmlSecTmplSignatureEnsureKeyInfo(signNode, BAD_CAST "xmldsig-facho-KeyInfo");
|
||||
if ( keyInfoNode == NULL ) {
|
||||
print_error("error: failed to add key info.\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
x509DataNode = xmlSecTmplKeyInfoAddX509Data(keyInfoNode);
|
||||
if ( x509DataNode == NULL ) {
|
||||
print_error("error: failde to add x509 DATA \n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
if ( xmlSecTmplX509DataAddCertificate(x509DataNode) == NULL ) {
|
||||
print_error("error: failde to add x509Certificate node\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
||||
if ( xmlFachoTmplXadesCreate(doc, signNode) < 0 ){
|
||||
print_error("error: xmlFachoTmplXadesCreate failed.\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
dsigCtx = xmlSecDSigCtxCreate(NULL);
|
||||
if ( dsigCtx == NULL ) {
|
||||
print_error("error: dsig context creating failed\n");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
dsigCtx->signKey = xmlSecCryptoAppKeyLoad(pkcs12name,
|
||||
xmlSecKeyDataFormatPkcs12,
|
||||
password,
|
||||
NULL, NULL);
|
||||
if ( dsigCtx->signKey == NULL ) {
|
||||
print_error("error: failed to load pkcs12\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
xmlXadesPolicyIdentifierCtx policyIdCtx;
|
||||
|
||||
policyIdCtx.contentCallback = &xmlFachoPolicyIdentifierCtxFromFilename;
|
||||
|
||||
xadesDsigCtx = xmlXadesDSigCtxCreate(dsigCtx, XADES_DIGEST_SHA256, &policyIdCtx);
|
||||
if ( xadesDsigCtx == NULL ) {
|
||||
print_error("error: xades context creating failed.\n");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
if ( xmlXadesDSigCtxSign(xadesDsigCtx, signNode) < 0 ) {
|
||||
print_error("error: signature failed\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
node = xmlFachoTmplUBLExtensionAddExtensionContent(doc);
|
||||
if ( node == NULL ) {
|
||||
print_error("error: failed to add UBLExtensions/UBLExtension/ExtensionContent\n");
|
||||
goto done;
|
||||
}
|
||||
xmlUnlinkNode(signNode);
|
||||
xmlSecAddChildNode(node, signNode);
|
||||
|
||||
xmlDocDump(stdout, doc);
|
||||
|
||||
res = 0;
|
||||
|
||||
done:
|
||||
if ( xadesDsigCtx != NULL ) {
|
||||
xmlXadesDSigCtxDestroy(xadesDsigCtx);
|
||||
}
|
||||
|
||||
if ( dsigCtx != NULL ) {
|
||||
xmlSecDSigCtxDestroy(dsigCtx);
|
||||
}
|
||||
|
||||
if ( doc != NULL ) {
|
||||
xmlFreeDoc(doc);
|
||||
}
|
||||
return(res);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
basename = argv[0];
|
||||
int exitStatus = EXIT_SUCCESS;
|
||||
|
||||
if (argc != 4) {
|
||||
print_error("%s: <factura.xml> <pc12> <password>\n", basename);
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if ( xmlXadesAppInit() < 0 ) {
|
||||
print_error("initialization failed.\n");
|
||||
return(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if ( xmlXadesSignFile( argv[1], argv[2], argv[3] ) != 0 ) {
|
||||
print_error("%s", "fail to sign file\n");
|
||||
exitStatus = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
xmlXadesAppShutdown();
|
||||
return(exitStatus);
|
||||
}
|
||||
|
||||
|
||||
|
||||
xmlNodePtr
|
||||
xmlFachoTmplUBLExtensionAddExtensionContent(xmlDocPtr doc) {
|
||||
xmlNodePtr node = NULL;
|
||||
xmlNodePtr parent = NULL;
|
||||
const xmlChar ublExtensionsName[] = "UBLExtensions";
|
||||
const xmlChar ublExtensionName[] = "UBLExtension";
|
||||
const xmlChar extensionContentName[] = "ExtensionContent";
|
||||
|
||||
parent = xmlSecFindNode(xmlDocGetRootElement(doc), ublExtensionsName, ublExtensionDSigNs);
|
||||
if ( parent == NULL ) {
|
||||
parent = xmlSecAddChild(xmlDocGetRootElement(doc), ublExtensionsName, ublExtensionDSigNs);
|
||||
if ( parent == NULL ) {
|
||||
print_error("error: failed to cleate UBLExtensions.\n");
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
node = xmlSecAddChild(parent, ublExtensionName, ublExtensionDSigNs);
|
||||
if ( node == NULL ) {
|
||||
print_error("error: failed to add UBLExtension\n");
|
||||
xmlFreeNode(parent);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
node = xmlSecAddChild(node, extensionContentName, ublExtensionDSigNs);
|
||||
if ( node == NULL ) {
|
||||
print_error("error: failed to add ExtensionContent");
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
return(node);
|
||||
}
|
||||
|
||||
int
|
||||
xmlFachoPolicyIdentifierCtxFromFilename(const xmlChar *policyId, xmlSecBufferPtr buffer) {
|
||||
static unsigned char politicafirmav2[] = {
|
||||
/**
|
||||
* generado con https://github.com/Jamesits/bin2array
|
||||
*/
|
||||
#include "politicafirmav2.c"
|
||||
};
|
||||
|
||||
return xmlSecBufferAppend(buffer, politicafirmav2, sizeof(politicafirmav2));
|
||||
}
|
||||
1
experimental/facho-signer/src/politicafirmav2.c
Normal file
1
experimental/facho-signer/src/politicafirmav2.c
Normal file
File diff suppressed because one or more lines are too long
391
experimental/facho-signer/src/xades/minunit.h
Normal file
391
experimental/facho-signer/src/xades/minunit.h
Normal file
@@ -0,0 +1,391 @@
|
||||
/*
|
||||
* Copyright (c) 2012 David Siñuela Pastor, siu.4coders@gmail.com
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef MINUNIT_MINUNIT_H
|
||||
#define MINUNIT_MINUNIT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <Windows.h>
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
#define snprintf _snprintf
|
||||
#define __func__ __FUNCTION__
|
||||
#endif
|
||||
|
||||
#elif defined(__unix__) || defined(__unix) || defined(unix) || (defined(__APPLE__) && defined(__MACH__))
|
||||
|
||||
/* Change POSIX C SOURCE version for pure c99 compilers */
|
||||
#if !defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 200112L
|
||||
#undef _POSIX_C_SOURCE
|
||||
#define _POSIX_C_SOURCE 200112L
|
||||
#endif
|
||||
|
||||
#include <unistd.h> /* POSIX flags */
|
||||
#include <time.h> /* clock_gettime(), time() */
|
||||
#include <sys/time.h> /* gethrtime(), gettimeofday() */
|
||||
#include <sys/resource.h>
|
||||
#include <sys/times.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(__MACH__) && defined(__APPLE__)
|
||||
#include <mach/mach.h>
|
||||
#include <mach/mach_time.h>
|
||||
#endif
|
||||
|
||||
#if __GNUC__ >= 5 && !defined(__STDC_VERSION__)
|
||||
#define __func__ __extension__ __FUNCTION__
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error "Unable to define timers for an unknown OS."
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
/* Maximum length of last message */
|
||||
#define MINUNIT_MESSAGE_LEN 1024
|
||||
/* Accuracy with which floats are compared */
|
||||
#define MINUNIT_EPSILON 1E-12
|
||||
|
||||
/* Misc. counters */
|
||||
static int minunit_run = 0;
|
||||
static int minunit_assert = 0;
|
||||
static int minunit_fail = 0;
|
||||
static int minunit_status = 0;
|
||||
|
||||
/* Timers */
|
||||
static double minunit_real_timer = 0;
|
||||
static double minunit_proc_timer = 0;
|
||||
|
||||
/* Last message */
|
||||
static char minunit_last_message[MINUNIT_MESSAGE_LEN];
|
||||
|
||||
/* Test setup and teardown function pointers */
|
||||
static void (*minunit_setup)(void) = NULL;
|
||||
static void (*minunit_teardown)(void) = NULL;
|
||||
|
||||
/* Definitions */
|
||||
#define MU_TEST(method_name) static void method_name(void)
|
||||
#define MU_TEST_SUITE(suite_name) static void suite_name(void)
|
||||
|
||||
#define MU__SAFE_BLOCK(block) do {\
|
||||
block\
|
||||
} while(0)
|
||||
|
||||
/* Run test suite and unset setup and teardown functions */
|
||||
#define MU_RUN_SUITE(suite_name) MU__SAFE_BLOCK(\
|
||||
suite_name();\
|
||||
minunit_setup = NULL;\
|
||||
minunit_teardown = NULL;\
|
||||
)
|
||||
|
||||
/* Configure setup and teardown functions */
|
||||
#define MU_SUITE_CONFIGURE(setup_fun, teardown_fun) MU__SAFE_BLOCK(\
|
||||
minunit_setup = setup_fun;\
|
||||
minunit_teardown = teardown_fun;\
|
||||
)
|
||||
|
||||
/* Test runner */
|
||||
#define MU_RUN_TEST(test) MU__SAFE_BLOCK(\
|
||||
if (minunit_real_timer==0 && minunit_proc_timer==0) {\
|
||||
minunit_real_timer = mu_timer_real();\
|
||||
minunit_proc_timer = mu_timer_cpu();\
|
||||
}\
|
||||
if (minunit_setup) (*minunit_setup)();\
|
||||
minunit_status = 0;\
|
||||
test();\
|
||||
minunit_run++;\
|
||||
if (minunit_status) {\
|
||||
minunit_fail++;\
|
||||
printf("F");\
|
||||
printf("\n%s\n", minunit_last_message);\
|
||||
}\
|
||||
fflush(stdout);\
|
||||
if (minunit_teardown) (*minunit_teardown)();\
|
||||
)
|
||||
|
||||
/* Report */
|
||||
#define MU_REPORT() MU__SAFE_BLOCK(\
|
||||
double minunit_end_real_timer;\
|
||||
double minunit_end_proc_timer;\
|
||||
printf("\n\n%d tests, %d assertions, %d failures\n", minunit_run, minunit_assert, minunit_fail);\
|
||||
minunit_end_real_timer = mu_timer_real();\
|
||||
minunit_end_proc_timer = mu_timer_cpu();\
|
||||
printf("\nFinished in %.8f seconds (real) %.8f seconds (proc)\n\n",\
|
||||
minunit_end_real_timer - minunit_real_timer,\
|
||||
minunit_end_proc_timer - minunit_proc_timer);\
|
||||
)
|
||||
#define MU_EXIT_CODE minunit_fail
|
||||
|
||||
/* Assertions */
|
||||
#define mu_check(test) MU__SAFE_BLOCK(\
|
||||
minunit_assert++;\
|
||||
if (!(test)) {\
|
||||
snprintf(minunit_last_message, MINUNIT_MESSAGE_LEN, "%s failed:\n\t%s:%d: %s", __func__, __FILE__, __LINE__, #test);\
|
||||
minunit_status = 1;\
|
||||
return;\
|
||||
} else {\
|
||||
printf(".");\
|
||||
}\
|
||||
)
|
||||
|
||||
#define mu_fail(message) MU__SAFE_BLOCK(\
|
||||
minunit_assert++;\
|
||||
snprintf(minunit_last_message, MINUNIT_MESSAGE_LEN, "%s failed:\n\t%s:%d: %s", __func__, __FILE__, __LINE__, message);\
|
||||
minunit_status = 1;\
|
||||
return;\
|
||||
)
|
||||
|
||||
#define mu_assert(test, message) MU__SAFE_BLOCK(\
|
||||
minunit_assert++;\
|
||||
if (!(test)) {\
|
||||
snprintf(minunit_last_message, MINUNIT_MESSAGE_LEN, "%s failed:\n\t%s:%d: %s", __func__, __FILE__, __LINE__, message);\
|
||||
minunit_status = 1;\
|
||||
return;\
|
||||
} else {\
|
||||
printf(".");\
|
||||
}\
|
||||
)
|
||||
|
||||
#define mu_assert_int_eq(expected, result) MU__SAFE_BLOCK(\
|
||||
int minunit_tmp_e;\
|
||||
int minunit_tmp_r;\
|
||||
minunit_assert++;\
|
||||
minunit_tmp_e = (expected);\
|
||||
minunit_tmp_r = (result);\
|
||||
if (minunit_tmp_e != minunit_tmp_r) {\
|
||||
snprintf(minunit_last_message, MINUNIT_MESSAGE_LEN, "%s failed:\n\t%s:%d: %d expected but was %d", __func__, __FILE__, __LINE__, minunit_tmp_e, minunit_tmp_r);\
|
||||
minunit_status = 1;\
|
||||
return;\
|
||||
} else {\
|
||||
printf(".");\
|
||||
}\
|
||||
)
|
||||
|
||||
#define mu_assert_double_eq(expected, result) MU__SAFE_BLOCK(\
|
||||
double minunit_tmp_e;\
|
||||
double minunit_tmp_r;\
|
||||
minunit_assert++;\
|
||||
minunit_tmp_e = (expected);\
|
||||
minunit_tmp_r = (result);\
|
||||
if (fabs(minunit_tmp_e-minunit_tmp_r) > MINUNIT_EPSILON) {\
|
||||
int minunit_significant_figures = 1 - log10(MINUNIT_EPSILON);\
|
||||
snprintf(minunit_last_message, MINUNIT_MESSAGE_LEN, "%s failed:\n\t%s:%d: %.*g expected but was %.*g", __func__, __FILE__, __LINE__, minunit_significant_figures, minunit_tmp_e, minunit_significant_figures, minunit_tmp_r);\
|
||||
minunit_status = 1;\
|
||||
return;\
|
||||
} else {\
|
||||
printf(".");\
|
||||
}\
|
||||
)
|
||||
|
||||
#define mu_assert_string_eq(expected, result) MU__SAFE_BLOCK(\
|
||||
const char* minunit_tmp_e = expected;\
|
||||
const char* minunit_tmp_r = result;\
|
||||
minunit_assert++;\
|
||||
if (!minunit_tmp_e) {\
|
||||
minunit_tmp_e = "<null pointer>";\
|
||||
}\
|
||||
if (!minunit_tmp_r) {\
|
||||
minunit_tmp_r = "<null pointer>";\
|
||||
}\
|
||||
if(strcmp(minunit_tmp_e, minunit_tmp_r)) {\
|
||||
snprintf(minunit_last_message, MINUNIT_MESSAGE_LEN, "%s failed:\n\t%s:%d: '%s' expected but was '%s'", __func__, __FILE__, __LINE__, minunit_tmp_e, minunit_tmp_r);\
|
||||
minunit_status = 1;\
|
||||
return;\
|
||||
} else {\
|
||||
printf(".");\
|
||||
}\
|
||||
)
|
||||
|
||||
/*
|
||||
* The following two functions were written by David Robert Nadeau
|
||||
* from http://NadeauSoftware.com/ and distributed under the
|
||||
* Creative Commons Attribution 3.0 Unported License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the real time, in seconds, or -1.0 if an error occurred.
|
||||
*
|
||||
* Time is measured since an arbitrary and OS-dependent start time.
|
||||
* The returned real time is only useful for computing an elapsed time
|
||||
* between two calls to this function.
|
||||
*/
|
||||
static double mu_timer_real(void)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
/* Windows 2000 and later. ---------------------------------- */
|
||||
LARGE_INTEGER Time;
|
||||
LARGE_INTEGER Frequency;
|
||||
|
||||
QueryPerformanceFrequency(&Frequency);
|
||||
QueryPerformanceCounter(&Time);
|
||||
|
||||
Time.QuadPart *= 1000000;
|
||||
Time.QuadPart /= Frequency.QuadPart;
|
||||
|
||||
return (double)Time.QuadPart / 1000000.0;
|
||||
|
||||
#elif (defined(__hpux) || defined(hpux)) || ((defined(__sun__) || defined(__sun) || defined(sun)) && (defined(__SVR4) || defined(__svr4__)))
|
||||
/* HP-UX, Solaris. ------------------------------------------ */
|
||||
return (double)gethrtime( ) / 1000000000.0;
|
||||
|
||||
#elif defined(__MACH__) && defined(__APPLE__)
|
||||
/* OSX. ----------------------------------------------------- */
|
||||
static double timeConvert = 0.0;
|
||||
if ( timeConvert == 0.0 )
|
||||
{
|
||||
mach_timebase_info_data_t timeBase;
|
||||
(void)mach_timebase_info( &timeBase );
|
||||
timeConvert = (double)timeBase.numer /
|
||||
(double)timeBase.denom /
|
||||
1000000000.0;
|
||||
}
|
||||
return (double)mach_absolute_time( ) * timeConvert;
|
||||
|
||||
#elif defined(_POSIX_VERSION)
|
||||
/* POSIX. --------------------------------------------------- */
|
||||
struct timeval tm;
|
||||
#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0)
|
||||
{
|
||||
struct timespec ts;
|
||||
#if defined(CLOCK_MONOTONIC_PRECISE)
|
||||
/* BSD. --------------------------------------------- */
|
||||
const clockid_t id = CLOCK_MONOTONIC_PRECISE;
|
||||
#elif defined(CLOCK_MONOTONIC_RAW)
|
||||
/* Linux. ------------------------------------------- */
|
||||
const clockid_t id = CLOCK_MONOTONIC_RAW;
|
||||
#elif defined(CLOCK_HIGHRES)
|
||||
/* Solaris. ----------------------------------------- */
|
||||
const clockid_t id = CLOCK_HIGHRES;
|
||||
#elif defined(CLOCK_MONOTONIC)
|
||||
/* AIX, BSD, Linux, POSIX, Solaris. ----------------- */
|
||||
const clockid_t id = CLOCK_MONOTONIC;
|
||||
#elif defined(CLOCK_REALTIME)
|
||||
/* AIX, BSD, HP-UX, Linux, POSIX. ------------------- */
|
||||
const clockid_t id = CLOCK_REALTIME;
|
||||
#else
|
||||
const clockid_t id = (clockid_t)-1; /* Unknown. */
|
||||
#endif /* CLOCK_* */
|
||||
if ( id != (clockid_t)-1 && clock_gettime( id, &ts ) != -1 )
|
||||
return (double)ts.tv_sec +
|
||||
(double)ts.tv_nsec / 1000000000.0;
|
||||
/* Fall thru. */
|
||||
}
|
||||
#endif /* _POSIX_TIMERS */
|
||||
|
||||
/* AIX, BSD, Cygwin, HP-UX, Linux, OSX, POSIX, Solaris. ----- */
|
||||
gettimeofday( &tm, NULL );
|
||||
return (double)tm.tv_sec + (double)tm.tv_usec / 1000000.0;
|
||||
#else
|
||||
return -1.0; /* Failed. */
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of CPU time used by the current process,
|
||||
* in seconds, or -1.0 if an error occurred.
|
||||
*/
|
||||
static double mu_timer_cpu(void)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
/* Windows -------------------------------------------------- */
|
||||
FILETIME createTime;
|
||||
FILETIME exitTime;
|
||||
FILETIME kernelTime;
|
||||
FILETIME userTime;
|
||||
|
||||
/* This approach has a resolution of 1/64 second. Unfortunately, Windows' API does not offer better */
|
||||
if ( GetProcessTimes( GetCurrentProcess( ),
|
||||
&createTime, &exitTime, &kernelTime, &userTime ) != 0 )
|
||||
{
|
||||
ULARGE_INTEGER userSystemTime;
|
||||
memcpy(&userSystemTime, &userTime, sizeof(ULARGE_INTEGER));
|
||||
return (double)userSystemTime.QuadPart / 10000000.0;
|
||||
}
|
||||
|
||||
#elif defined(__unix__) || defined(__unix) || defined(unix) || (defined(__APPLE__) && defined(__MACH__))
|
||||
/* AIX, BSD, Cygwin, HP-UX, Linux, OSX, and Solaris --------- */
|
||||
|
||||
#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0)
|
||||
/* Prefer high-res POSIX timers, when available. */
|
||||
{
|
||||
clockid_t id;
|
||||
struct timespec ts;
|
||||
#if _POSIX_CPUTIME > 0
|
||||
/* Clock ids vary by OS. Query the id, if possible. */
|
||||
if ( clock_getcpuclockid( 0, &id ) == -1 )
|
||||
#endif
|
||||
#if defined(CLOCK_PROCESS_CPUTIME_ID)
|
||||
/* Use known clock id for AIX, Linux, or Solaris. */
|
||||
id = CLOCK_PROCESS_CPUTIME_ID;
|
||||
#elif defined(CLOCK_VIRTUAL)
|
||||
/* Use known clock id for BSD or HP-UX. */
|
||||
id = CLOCK_VIRTUAL;
|
||||
#else
|
||||
id = (clockid_t)-1;
|
||||
#endif
|
||||
if ( id != (clockid_t)-1 && clock_gettime( id, &ts ) != -1 )
|
||||
return (double)ts.tv_sec +
|
||||
(double)ts.tv_nsec / 1000000000.0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(RUSAGE_SELF)
|
||||
{
|
||||
struct rusage rusage;
|
||||
if ( getrusage( RUSAGE_SELF, &rusage ) != -1 )
|
||||
return (double)rusage.ru_utime.tv_sec +
|
||||
(double)rusage.ru_utime.tv_usec / 1000000.0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(_SC_CLK_TCK)
|
||||
{
|
||||
const double ticks = (double)sysconf( _SC_CLK_TCK );
|
||||
struct tms tms;
|
||||
if ( times( &tms ) != (clock_t)-1 )
|
||||
return (double)tms.tms_utime / ticks;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CLOCKS_PER_SEC)
|
||||
{
|
||||
clock_t cl = clock( );
|
||||
if ( cl != (clock_t)-1 )
|
||||
return (double)cl / (double)CLOCKS_PER_SEC;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
return -1; /* Failed. */
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MINUNIT_MINUNIT_H */
|
||||
13
experimental/facho-signer/src/xades/minunit_ext.h
Normal file
13
experimental/facho-signer/src/xades/minunit_ext.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef MINUNIT_EXT_H
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "minunit.h"
|
||||
|
||||
// cuando escribe esto el compilar me arrojo que si no era
|
||||
// mejor usar mu_assert_string_eq increble a
|
||||
//int mu_assert_string_equals(const char *a, const char *b) {
|
||||
// return mu_assert(strcmp(a, b) == 0, "string not equals");
|
||||
//}
|
||||
|
||||
#endif //MINUNIT_EXT_H
|
||||
428
experimental/facho-signer/src/xades/templates.c
Normal file
428
experimental/facho-signer/src/xades/templates.c
Normal file
@@ -0,0 +1,428 @@
|
||||
#include "xades.h"
|
||||
|
||||
#include <xmlsec/templates.h>
|
||||
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
xmlNodePtr
|
||||
xmlXadesAddChildRecursiveNs(xmlNodePtr startNode, const xmlChar* path, const xmlChar* nsPrefix) {
|
||||
char *curToken;
|
||||
char* cpath = strdup((char *)path);
|
||||
char* savePtr;
|
||||
xmlNodePtr curNode = NULL;
|
||||
xmlNodePtr parentNode = startNode;
|
||||
|
||||
|
||||
curToken = strtok_r(cpath, "/", &savePtr);
|
||||
while(curToken != NULL) {
|
||||
curNode = xmlSecFindChild(parentNode, BAD_CAST curToken, nsPrefix);
|
||||
if (curNode == NULL) {
|
||||
curNode = xmlSecAddChild(parentNode, BAD_CAST curToken, nsPrefix);
|
||||
if (curNode == NULL) {
|
||||
xmlXadesInternalError("xmlSecAddChild(%s)", curToken);
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
parentNode = curNode;
|
||||
|
||||
curToken = strtok_r(NULL, "/", &savePtr);
|
||||
}
|
||||
|
||||
free(cpath);
|
||||
return(curNode);
|
||||
}
|
||||
|
||||
xmlNodePtr
|
||||
xmlXadesTmplQualifyingPropertiesCreate(xmlDocPtr doc, xmlNodePtr signatureNode, const xmlChar *id) {
|
||||
xmlNodePtr objectNode;
|
||||
xmlNodePtr qualifyingPropertiesNode;
|
||||
|
||||
xmlNewGlobalNs(doc, xmlXadesDSigNs, BAD_CAST "xades");
|
||||
|
||||
objectNode = xmlSecTmplSignatureAddObject(signatureNode, NULL, NULL, NULL);
|
||||
if (objectNode == NULL) {
|
||||
xmlXadesInternalError("xmlSecTmplSignatureAddObject(signatureNode)", NULL);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
qualifyingPropertiesNode = xmlSecAddChild(objectNode, xmlXadesNodeQualifyingProperties, xmlXadesDSigNs);
|
||||
if (qualifyingPropertiesNode == NULL) {
|
||||
xmlXadesXmlError2("xmlNewDocNode", NULL, "node=%s", xmlXadesErrorsSafeString(xmlXadesNodeQualifyingProperties));
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
if (id != NULL) {
|
||||
xmlSetProp(qualifyingPropertiesNode, BAD_CAST "Id", id);
|
||||
}
|
||||
|
||||
return(qualifyingPropertiesNode);
|
||||
}
|
||||
|
||||
xmlNodePtr
|
||||
xmlXadesTmplQualifyingPropertiesCreateNsPref(xmlDocPtr doc, const xmlChar* id, const xmlChar* nsPrefix) {
|
||||
xmlNodePtr qualifyingPropertiesNode;
|
||||
xmlNsPtr ns;
|
||||
|
||||
// crear nodo
|
||||
qualifyingPropertiesNode = xmlNewDocNode(doc, NULL, xmlXadesNodeQualifyingProperties, NULL);
|
||||
if (qualifyingPropertiesNode == NULL) {
|
||||
xmlXadesXmlError2("xmlNewDocNode", NULL, "node=%s", xmlXadesErrorsSafeString(xmlXadesNodeQualifyingProperties));
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
// crear namespace y asignar
|
||||
ns = xmlNewNs(qualifyingPropertiesNode, xmlXadesDSigNs, nsPrefix);
|
||||
if (ns == NULL) {
|
||||
xmlXadesXmlError2("xmlNewNs", NULL,
|
||||
"ns=%s", xmlXadesErrorsSafeString(xmlXadesDSigNs));
|
||||
xmlFreeNode(qualifyingPropertiesNode);
|
||||
return(NULL);
|
||||
}
|
||||
xmlSetNs(qualifyingPropertiesNode, ns);
|
||||
|
||||
if (id != NULL) {
|
||||
xmlSetProp(qualifyingPropertiesNode, BAD_CAST "Id", id);
|
||||
}
|
||||
|
||||
|
||||
return (qualifyingPropertiesNode);
|
||||
}
|
||||
|
||||
xmlNodePtr
|
||||
xmlXadesTmplAddSignedProperties(xmlNodePtr qualifyingPropertiesNode, const xmlChar* id) {
|
||||
xmlNodePtr cur;
|
||||
|
||||
xmlXadesAssert2(qualifyingPropertiesNode != NULL, NULL);
|
||||
|
||||
cur = xmlSecAddChild(qualifyingPropertiesNode, xmlXadesNodeSignedProperties, xmlXadesDSigNs);
|
||||
if (cur == NULL) {
|
||||
xmlXadesInternalError("xmlSecAddChild(xmlXadesNodeSignedProperties)", NULL);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
if (id != NULL) {
|
||||
xmlSetProp(cur, BAD_CAST "Id", id);
|
||||
}
|
||||
|
||||
return(cur);
|
||||
}
|
||||
|
||||
xmlNodePtr
|
||||
xmlXadesTmplAddSignedSignatureProperties(xmlNodePtr signedPropertiesNode, struct tm* signingTime) {
|
||||
xmlNodePtr cur;
|
||||
xmlNodePtr node;
|
||||
|
||||
xmlXadesAssert2(signedPropertiesNode != NULL, NULL);
|
||||
|
||||
// add SignedSignatureProperties
|
||||
node = xmlSecAddChild(signedPropertiesNode, xmlXadesNodeSignedSignatureProperties, xmlXadesDSigNs);
|
||||
if (node == NULL) {
|
||||
xmlXadesInternalError("xmlSecAddChild(xmlXadesNodeSignedSignatureProperties)", NULL);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
// add SignigTime
|
||||
cur = xmlSecAddChild(node, xmlXadesNodeSigningTime, xmlXadesDSigNs);
|
||||
if (cur == NULL) {
|
||||
xmlXadesInternalError("xmlSecAddChild(xmlXadesNodeSigningTime)", NULL);
|
||||
xmlFreeNode(node);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
{
|
||||
int ret;
|
||||
char strtime[200];
|
||||
|
||||
if (strftime(strtime, sizeof(strtime), "%Y-%m-%dT%T", signingTime) == 0) {
|
||||
xmlXadesInternalError("strftime", NULL);
|
||||
xmlFreeNode(cur);
|
||||
xmlFreeNode(node);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
ret = xmlSecNodeEncodeAndSetContent(cur, BAD_CAST strtime);
|
||||
if (ret < 0) {
|
||||
xmlXadesInternalError("xmlSecNodeEncodeAndSetContent", NULL);
|
||||
xmlFreeNode(cur);
|
||||
xmlFreeNode(node);
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
return(node);
|
||||
}
|
||||
|
||||
xmlNodePtr
|
||||
xmlXadesTmplAddSigningCertificate(xmlNodePtr signedSignaturePropertiesNode, xmlSecTransformId digestMethodId) {
|
||||
xmlNodePtr node;
|
||||
|
||||
xmlXadesAssert2(signedSignaturePropertiesNode != NULL, NULL);
|
||||
if (xmlSecFindChild(signedSignaturePropertiesNode, xmlXadesNodeSigningCertificate, xmlXadesDSigNs) != NULL) {
|
||||
xmlXadesNodeAlreadyPresentError(signedSignaturePropertiesNode, xmlXadesNodeSigningCertificate, NULL);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
node = xmlSecAddChild(signedSignaturePropertiesNode, xmlXadesNodeSigningCertificate, xmlXadesDSigNs);
|
||||
if (node == NULL) {
|
||||
xmlXadesInternalError("xmlsecAddChild(xmlXadesNodeSigningCertificate)", NULL);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
return(node);
|
||||
}
|
||||
|
||||
xmlNodePtr
|
||||
xmlXadesTmplAddCert(xmlNodePtr signingCertificateNode) {
|
||||
xmlNodePtr certNode;
|
||||
|
||||
xmlXadesAssert2(signingCertificateNode != NULL, NULL);
|
||||
|
||||
certNode = xmlSecAddChild(signingCertificateNode, xmlXadesNodeCert, xmlXadesDSigNs);
|
||||
if (certNode == NULL) {
|
||||
xmlXadesInternalError("xmlSecAddChild(xmlXadesNodeCert)", NULL);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
return(certNode);
|
||||
}
|
||||
|
||||
xmlNodePtr
|
||||
xmlXadesTmplAddCertDigest(xmlNodePtr certNode, const xmlChar *digestMethod, const xmlChar *digestValue) {
|
||||
xmlNodePtr node;
|
||||
|
||||
xmlXadesAssert2(certNode != NULL, NULL);
|
||||
|
||||
node = xmlSecAddChild(certNode, xmlXadesNodeCertDigest, xmlXadesDSigNs);
|
||||
if ( node == NULL ) {
|
||||
xmlXadesInternalError("xmlSecAddChild(xmlXadesNodeCertDigest)", NULL);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
if ( xmlXadesTmplAddDigest(node, digestMethod, digestValue) == NULL) {
|
||||
xmlXadesInternalError("xmlXadesTmplAddDigest(node, digestMethodId)", NULL);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
return(certNode);
|
||||
}
|
||||
|
||||
xmlNodePtr
|
||||
xmlXadesTmplAddSignaturePolicyIdentifier(xmlNodePtr signedSignaturePropertiesNode) {
|
||||
xmlNodePtr cur;
|
||||
|
||||
xmlXadesAssert2(signedSignaturePropertiesNode != NULL, NULL);
|
||||
|
||||
cur = xmlSecAddChild(signedSignaturePropertiesNode, xmlXadesNodeSignaturePolicyIdentifier, xmlXadesDSigNs);
|
||||
if (cur == NULL) {
|
||||
xmlXadesInternalError("xmlsecAddChild(xmlXadesNodeSignaturePolicyIdentifier)", NULL);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
return(cur);
|
||||
}
|
||||
|
||||
xmlNodePtr
|
||||
xmlXadesTmplAddSignaturePolicyId(xmlNodePtr signaturePolicyIdentifierNode) {
|
||||
xmlNodePtr cur;
|
||||
|
||||
xmlXadesAssert2(signaturePolicyIdentifierNode != NULL, NULL);
|
||||
|
||||
cur = xmlSecAddChild(signaturePolicyIdentifierNode, xmlXadesNodeSignaturePolicyId, xmlXadesDSigNs);
|
||||
if (cur == NULL) {
|
||||
xmlXadesInternalError("xmlsecAddChild(cur)", NULL);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
return(cur);
|
||||
}
|
||||
|
||||
xmlNodePtr
|
||||
xmlXadesTmplAddSigPolicyId(xmlNodePtr signaturePolicyId, const xmlChar* identifier, const xmlChar *description) {
|
||||
xmlNodePtr sigPolicyIdNode;
|
||||
xmlNodePtr node;
|
||||
int ret;
|
||||
|
||||
sigPolicyIdNode = xmlSecAddChild(signaturePolicyId, xmlXadesNodeSigPolicyId, xmlXadesDSigNs);
|
||||
if (sigPolicyIdNode == NULL) {
|
||||
xmlXadesInternalError("xmlSecAddChild(xmlXadesNodeSigPolicyId)", NULL);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
node = xmlSecAddChild(sigPolicyIdNode, xmlXadesNodeIdentifier, xmlXadesDSigNs);
|
||||
if (node == NULL) {
|
||||
xmlXadesInternalError("xmlSecAddChild(xmlXadesNodeIdentifier)", NULL);
|
||||
xmlFreeNode(sigPolicyIdNode);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
ret = xmlSecNodeEncodeAndSetContent(node, identifier);
|
||||
if (ret < 0) {
|
||||
xmlXadesInternalError("xmlSecNodeEncodeAndSetContent", NULL);
|
||||
xmlFreeNode(sigPolicyIdNode);
|
||||
xmlFreeNode(node);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
node = xmlSecAddChild(sigPolicyIdNode, xmlXadesNodeDescription, xmlXadesDSigNs);
|
||||
if (node == NULL) {
|
||||
xmlXadesInternalError("xmlSecAddChild(xmlXadesNodeDescription)", NULL);
|
||||
xmlFreeNode(sigPolicyIdNode);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
ret = xmlSecNodeEncodeAndSetContent(node, description);
|
||||
if (ret < 0) {
|
||||
xmlXadesInternalError("xmlSecNodeEncodeAndSetContent", NULL);
|
||||
xmlFreeNode(sigPolicyIdNode);
|
||||
xmlFreeNode(node);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
return(sigPolicyIdNode);
|
||||
}
|
||||
|
||||
xmlNodePtr
|
||||
xmlXadesTmplAddSigPolicyHash(xmlNodePtr parentNode, xmlSecTransformId digestMethodId) {
|
||||
xmlNodePtr node;
|
||||
xmlXadesAssert2(parentNode != NULL, NULL);
|
||||
|
||||
//add policyHash
|
||||
node = xmlSecAddChild(parentNode, xmlXadesNodeSigPolicyHash, xmlXadesDSigNs);
|
||||
if (node == NULL) {
|
||||
xmlXadesInternalError("xmlSecAddChild(xmlXadesNodeSigPolicyHash)", NULL);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
if ( xmlXadesTmplAddDigest(node, digestMethodId->href, NULL) == NULL) {
|
||||
xmlXadesInternalError("xmlXadesTmplAddDigest(node, digestMethodId)", NULL);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
// MACHETE(bit4bit) como usar SecTransform para almacenar el digest
|
||||
xmlNodePtr
|
||||
xmlXadesTmplAddDigest(xmlNodePtr parentNode, const xmlChar *digestMethod, const xmlChar *digestValue) {
|
||||
xmlNodePtr node;
|
||||
|
||||
xmlXadesAssert2(parentNode != NULL, NULL);
|
||||
|
||||
if ( digestMethod != NULL ) {
|
||||
node = xmlSecAddChild(parentNode, xmlSecNodeDigestMethod, xmlSecDSigNs);
|
||||
if (node == NULL) {
|
||||
xmlXadesInternalError("xmlSecAddChild(xmlSecNodeDigestMethod)", NULL);
|
||||
return(NULL);
|
||||
}
|
||||
if (xmlSetProp(node, xmlSecAttrAlgorithm, digestMethod) == NULL) {
|
||||
xmlXadesXmlError2("xmlSetProp", NULL,
|
||||
"name=%s", xmlXadesErrorsSafeString(xmlSecAttrAlgorithm));
|
||||
xmlUnlinkNode(node);
|
||||
xmlFreeNode(node);
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
if ( digestValue != NULL ) {
|
||||
node = xmlSecAddChild(parentNode, xmlSecNodeDigestValue, xmlSecDSigNs);
|
||||
if (node == NULL) {
|
||||
xmlXadesInternalError("xmlSecAddChild(xmlSecNodeDigestValue)", NULL);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
if (xmlSecNodeEncodeAndSetContent(node, digestValue) < 0) {
|
||||
xmlXadesInternalError("xmlSecNodeEncodeAndSetContent", NULL);
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
return parentNode;
|
||||
}
|
||||
|
||||
xmlNodePtr
|
||||
xmlXadesTmplAddSignerRole(xmlNodePtr signedSignaturePropertiesNode, const xmlChar* role) {
|
||||
xmlNodePtr signerRoleNode;
|
||||
xmlNodePtr claimedRolesNode;
|
||||
xmlNodePtr claimedRoleNode;
|
||||
int ret;
|
||||
|
||||
signerRoleNode = xmlSecAddChild(signedSignaturePropertiesNode, xmlXadesNodeSignerRole, xmlXadesDSigNs);
|
||||
if (signerRoleNode == NULL) {
|
||||
xmlXadesInternalError("xmlSecAddChild(xmlXadesNodeSignerRole)", NULL);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
claimedRolesNode = xmlSecAddChild(signerRoleNode, xmlXadesNodeClaimedRoles, xmlXadesDSigNs);
|
||||
if (claimedRolesNode == NULL) {
|
||||
xmlXadesInternalError("xmlSecAddChild(xmlXadesNodeClaimedRoles)", NULL);
|
||||
xmlUnlinkNode(signerRoleNode);
|
||||
xmlFreeNode(signerRoleNode);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
claimedRoleNode = xmlSecAddChild(claimedRolesNode, xmlXadesNodeClaimedRole, xmlXadesDSigNs);
|
||||
if (claimedRoleNode == NULL) {
|
||||
xmlXadesInternalError("xmlSecAddChild(xmlXadesNodeClaimedRole)", NULL);
|
||||
xmlUnlinkNode(signerRoleNode);
|
||||
xmlFreeNode(signerRoleNode);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
ret = xmlSecNodeEncodeAndSetContent(claimedRoleNode, role);
|
||||
if (ret < 0) {
|
||||
xmlXadesInternalError("xmlSecNodeEncodeAndSetContent", NULL);
|
||||
xmlUnlinkNode(signerRoleNode);
|
||||
xmlFreeNode(signerRoleNode);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
return(signerRoleNode);
|
||||
}
|
||||
|
||||
|
||||
xmlNodePtr
|
||||
xmlXadesTmplAddIssuerSerial(xmlNodePtr certNode, const xmlChar *issuerName, const xmlChar *issuerNumber) {
|
||||
xmlNodePtr issuerSerialNode;
|
||||
xmlNodePtr node;
|
||||
|
||||
xmlXadesAssert2(certNode != NULL, NULL);
|
||||
|
||||
issuerSerialNode = xmlSecAddChild(certNode, xmlXadesNodeIssuerSerial, xmlXadesDSigNs);
|
||||
if ( issuerSerialNode == NULL ) {
|
||||
xmlXadesInternalError("xmlSecAddChild(certNode, xmlXadesIssuerSerial)", NULL);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
node = xmlSecAddChild(issuerSerialNode, xmlXadesNodeX509IssuerName, xmlSecDSigNs);
|
||||
if ( node == NULL ) {
|
||||
xmlXadesInternalError("xmlSecAddChild(xmlXadesNodeX509IssuerName)", NULL);
|
||||
xmlFreeNode(issuerSerialNode);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
if (xmlSecNodeEncodeAndSetContent(node, issuerName) < 0) {
|
||||
xmlXadesInternalError("xmlSecNodeEncodeAndSetContent", NULL);
|
||||
xmlUnlinkNode(issuerSerialNode);
|
||||
xmlFreeNode(issuerSerialNode);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
node = xmlSecAddChild(issuerSerialNode, xmlXadesNodeX509IssuerNumber, xmlSecDSigNs);
|
||||
if ( node == NULL ) {
|
||||
xmlXadesInternalError("xmlSecAddChild(xmlXadesNodeX509IssuerNumber)", NULL);
|
||||
xmlFreeNode(issuerSerialNode);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
if (xmlSecNodeEncodeAndSetContent(node, issuerNumber) < 0) {
|
||||
xmlXadesInternalError("xmlSecNodeEncodeAndSetContent", NULL);
|
||||
xmlUnlinkNode(issuerSerialNode);
|
||||
xmlFreeNode(issuerSerialNode);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
return(issuerSerialNode);
|
||||
}
|
||||
294
experimental/facho-signer/src/xades/xades.c
Normal file
294
experimental/facho-signer/src/xades/xades.c
Normal file
@@ -0,0 +1,294 @@
|
||||
#include "config.h"
|
||||
#include "xades.h"
|
||||
|
||||
#include <libxml/xpath.h>
|
||||
#include <libxml/xpathInternals.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/x509v3.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/bn.h>
|
||||
|
||||
#include <xmlsec/buffer.h>
|
||||
#include <xmlsec/app.h>
|
||||
#include <xmlsec/transforms.h>
|
||||
#include <xmlsec/keysdata.h>
|
||||
|
||||
#ifndef XMLSEC_CRYPTO_DYNAMIC_LOADING
|
||||
#include <xmlsec/openssl/crypto.h>
|
||||
#include <xmlsec/openssl/symbols.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
static xmlChar *
|
||||
xmlXadesSha256DigestValueInBase64(const unsigned char *message, size_t message_len);
|
||||
|
||||
static xmlNodePtr
|
||||
xmlXadesXPathFirstElement(xmlDocPtr doc, const xmlChar *xpath);
|
||||
|
||||
xmlXadesDSigCtxPtr
|
||||
xmlXadesDSigCtxCreate(xmlSecDSigCtxPtr dsigCtx, XADES_DIGEST_METHOD digestMethod, xmlXadesPolicyIdentifierCtxPtr policyCtx) {
|
||||
xmlXadesDSigCtxPtr ctx = NULL;
|
||||
|
||||
ctx = malloc(sizeof(xmlXadesDSigCtx));
|
||||
if ( ctx == NULL ) {
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
ctx->dsigCtx = dsigCtx;
|
||||
ctx->digestMethod = digestMethod;
|
||||
ctx->policyCtx = policyCtx;
|
||||
return ctx;
|
||||
}
|
||||
|
||||
int
|
||||
xmlXadesDSigCtxSign(xmlXadesDSigCtxPtr ctx, xmlNodePtr signNode) {
|
||||
xmlNodePtr signingCertificateNode = NULL;
|
||||
xmlSecKeyDataPtr keyDataX509;
|
||||
xmlSecSize certsSize;
|
||||
|
||||
signingCertificateNode = xmlXadesXPathFirstElement(signNode->doc, BAD_CAST "//ds:Object/xades:QualifyingProperties//xades:SigningCertificate[1]");
|
||||
if ( signingCertificateNode == NULL ) {
|
||||
return(-1);
|
||||
}
|
||||
|
||||
keyDataX509 = xmlSecKeyEnsureData(ctx->dsigCtx->signKey, xmlSecKeyDataX509Id);
|
||||
if ( keyDataX509 == NULL ) {
|
||||
xmlXadesInternalError("failed to get X509.\n", NULL);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
certsSize = xmlSecOpenSSLKeyDataX509GetCertsSize(keyDataX509);
|
||||
for (xmlSecSize i = 0; i < certsSize; i++) {
|
||||
// calculamos el digest del certificado
|
||||
unsigned char md[EVP_MAX_MD_SIZE];
|
||||
unsigned int md_n;
|
||||
// TODO(bit4bit) podemos obtener el digest de openssl por medio de la transformacion? o se puede usar la transformacion para generar el digest?
|
||||
xmlChar *digestMethod = NULL;
|
||||
EVP_MD *digest = NULL;
|
||||
|
||||
switch(ctx->digestMethod) {
|
||||
case XADES_DIGEST_SHA256:
|
||||
digestMethod = (xmlChar *)xmlSecTransformSha256Id->href;
|
||||
digest = (EVP_MD *) EVP_sha256();
|
||||
break;
|
||||
default:
|
||||
xmlXadesInternalError("xmlXadesDSigCtxSign not known how to handle digest method.\n", NULL);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
X509 *cert = xmlSecOpenSSLKeyDataX509GetCert(keyDataX509, i);
|
||||
if ( cert == NULL ) {
|
||||
xmlXadesInternalError("openssl: failed to get X509 cert.\n", NULL);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
X509_digest(cert, digest, md, &md_n);
|
||||
xmlChar *digestValue = xmlSecBase64Encode(md, md_n, 0);
|
||||
|
||||
xmlNodePtr certNode = xmlXadesTmplAddCert(signingCertificateNode);
|
||||
if ( certNode == NULL ) {
|
||||
xmlXadesInternalError("xmlXadesTmplAddCert(signingCertificateNode)\n", NULL);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
// adicionamos digest
|
||||
xmlXadesTmplAddCertDigest(certNode,
|
||||
digestMethod,
|
||||
digestValue);
|
||||
|
||||
char *issuerName = X509_NAME_oneline(X509_get_issuer_name(cert), NULL, 0);
|
||||
|
||||
/* TODO(bit4bit) formatear?
|
||||
char *issuerNamePtr = issuerName;
|
||||
|
||||
for(issuerNamePtr = strchr(issuerNamePtr, '/'); issuerNamePtr != NULL; issuerNamePtr = strchr(issuerNamePtr, '/')) {
|
||||
if (issuerNamePtr == issuerName) {
|
||||
issuerName += 1;
|
||||
} else {
|
||||
*issuerNamePtr = ',';
|
||||
}
|
||||
}*/
|
||||
|
||||
ASN1_INTEGER *serial = X509_get_serialNumber(cert);
|
||||
BIGNUM *bn = ASN1_INTEGER_to_BN(serial, NULL);
|
||||
if ( bn == NULL ) {
|
||||
xmlXadesInternalError("unable to convert ASN1_INTEGER_to_BN to BN\n", NULL);
|
||||
return(-1);
|
||||
}
|
||||
char *issuerNumber = BN_bn2dec(bn);
|
||||
if ( issuerNumber == NULL ) {
|
||||
xmlXadesInternalError("unable to convert BN to decimal string\n", NULL);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
if (xmlXadesTmplAddIssuerSerial(certNode, BAD_CAST issuerName, BAD_CAST issuerNumber) == NULL) {
|
||||
xmlXadesInternalError("xmlXadesTmplAddIssuerSerial", NULL);
|
||||
return(-1);
|
||||
}
|
||||
BN_free(bn);
|
||||
OPENSSL_free(issuerNumber);
|
||||
}
|
||||
|
||||
// digest de policy identifier
|
||||
xmlNodePtr sigPolicyId = xmlXadesXPathFirstElement(signNode->doc, BAD_CAST "//xades:SigPolicyId/xades:Identifier[1]");
|
||||
if ( sigPolicyId == NULL ) {
|
||||
xmlXadesInternalError("xmlXadesXPathFirstElement(xades:SigPolicyId/xades:Identifier\n", NULL);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
if ( ctx->policyCtx == NULL ) {
|
||||
xmlXadesInternalError("not found policy context.\n", NULL);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
if ( ctx->policyCtx != NULL ) {
|
||||
|
||||
|
||||
if ( ctx->policyCtx->contentCallback == NULL ) {
|
||||
xmlXadesInternalError("not found policy content callback.\n", NULL);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
|
||||
xmlSecTransformCtxPtr transformCtx = xmlSecTransformCtxCreate();
|
||||
if (transformCtx == NULL ) {
|
||||
xmlXadesInternalError("xmlSecTransformCtxCreate().\n", NULL);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
// elemento del digest
|
||||
xmlNodePtr sigPolicyHashDigestMethod = xmlXadesXPathFirstElement(signNode->doc, BAD_CAST "//xades:SigPolicyHash/ds:DigestMethod[1]");
|
||||
if ( sigPolicyHashDigestMethod == NULL ) {
|
||||
xmlXadesInternalError("xmlXadesXPathFirstElement(xades:SigPolicyHash/xades:DigestMethod\n", NULL);
|
||||
return(-1);
|
||||
}
|
||||
xmlSecTransformPtr transformPolicyDigestMethod = xmlSecTransformNodeRead(sigPolicyHashDigestMethod,
|
||||
xmlSecTransformUsageDigestMethod,
|
||||
transformCtx);
|
||||
if ( transformPolicyDigestMethod == NULL ) {
|
||||
xmlXadesInternalError("xmlSecTransformNodeRead\n", NULL);
|
||||
xmlFreeNode(sigPolicyHashDigestMethod);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
if ( xmlSecTransformCheckId(transformPolicyDigestMethod, xmlSecTransformSha256Id) == 0 ) {
|
||||
xmlXadesInternalError("sigPolicyHash only support sha256 digest method .\n", NULL);
|
||||
xmlFreeNode(sigPolicyHashDigestMethod);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
// TODO(bit4bit) podemos usar xmlSecTransform para calcular el digest?
|
||||
xmlNodePtr sigPolicyHashNode = xmlXadesXPathFirstElement(signNode->doc, BAD_CAST "//xades:SigPolicyHash[1]");
|
||||
if ( sigPolicyHashNode == NULL ) {
|
||||
xmlXadesInternalError("failed to find sigPolicyHash node.\n", NULL);
|
||||
xmlFreeNode(sigPolicyHashDigestMethod);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
// obtenemos contenido de la policy
|
||||
xmlChar *identifier = xmlNodeListGetString(signNode->doc, sigPolicyId->xmlChildrenNode, 1);
|
||||
xmlSecBufferPtr policyContent = xmlSecBufferCreate(1024);
|
||||
;
|
||||
if ( (ctx->policyCtx->contentCallback)(identifier, policyContent) < 0 ) {
|
||||
xmlXadesInternalError("policyContext callback fails.\n", NULL);
|
||||
xmlFree(identifier);
|
||||
return(-1);
|
||||
}
|
||||
xmlFree(identifier);
|
||||
|
||||
xmlChar *policyHashValue = xmlXadesSha256DigestValueInBase64(xmlSecBufferGetData(policyContent),
|
||||
xmlSecBufferGetSize(policyContent));
|
||||
|
||||
xmlSecBufferDestroy(policyContent);
|
||||
xmlXadesTmplAddDigest(sigPolicyHashNode, NULL, policyHashValue);
|
||||
}
|
||||
|
||||
return xmlSecDSigCtxSign(ctx->dsigCtx, signNode);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
xmlXadesDSigCtxDestroy(xmlXadesDSigCtxPtr ctx) {
|
||||
if ( ctx == NULL ) {
|
||||
return(-1);
|
||||
}
|
||||
|
||||
free(ctx);
|
||||
return(0);
|
||||
}
|
||||
|
||||
xmlNodePtr
|
||||
xmlXadesXPathFirstElement(xmlDocPtr doc, const xmlChar *xpath) {
|
||||
xmlXPathContextPtr xpathCtx;
|
||||
xmlXPathObjectPtr xpathResult;
|
||||
xmlNodePtr node;
|
||||
|
||||
// obtener QualifyingProteries
|
||||
|
||||
xpathCtx = xmlXPathNewContext(doc);
|
||||
/* register namespaces */
|
||||
// TOMADO DE: xmlsec1/src/xpath.c
|
||||
for(xmlNsPtr ns = xmlDocGetRootElement(doc)->nsDef; ns != NULL; ns = ns->next) {
|
||||
/* check that we have no other namespace with same prefix already */
|
||||
if((ns->prefix != NULL) && (xmlXPathNsLookup(xpathCtx, ns->prefix) == NULL)){
|
||||
int ret = xmlXPathRegisterNs(xpathCtx, ns->prefix, ns->href);
|
||||
if(ret != 0) {
|
||||
xmlXadesXmlError2("xmlXPathRegisterNs", NULL,
|
||||
"prefix=%s", xmlSecErrorsSafeString(ns->prefix));
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
xpathResult = xmlXPathEvalExpression(xpath, xpathCtx);
|
||||
if ( xmlXPathNodeSetIsEmpty( xpathResult->nodesetval ) ) {
|
||||
xmlXadesInternalError("can't find %s \n", xpath);
|
||||
xmlXPathFreeObject(xpathResult);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
// obtener puntero a nodo
|
||||
node = xpathResult->nodesetval->nodeTab[0];
|
||||
if ( node->type != XML_ELEMENT_NODE ) {
|
||||
xmlXadesInternalError("expected element\n", NULL);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
return(node);
|
||||
}
|
||||
|
||||
static xmlChar *
|
||||
xmlXadesSha256DigestValueInBase64(const unsigned char *message, size_t message_len)
|
||||
{
|
||||
unsigned char digest[2048];
|
||||
unsigned int digest_len;
|
||||
EVP_MD_CTX *mdctx;
|
||||
|
||||
if((mdctx = EVP_MD_CTX_new()) == NULL) {
|
||||
xmlXadesInternalError("EVP_MD_CTX_new().\n", NULL);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
if(1 != EVP_DigestInit_ex(mdctx, EVP_sha256(), NULL)) {
|
||||
xmlXadesInternalError("EVP_DigestInit_ex().\n", NULL);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
if(1 != EVP_DigestUpdate(mdctx, message, message_len)) {
|
||||
xmlXadesInternalError("EVP_DigestUpdate().\n", NULL);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
if(1 != EVP_DigestFinal_ex(mdctx, digest, &digest_len)) {
|
||||
xmlXadesInternalError("EVP_DigestFinal_ex().\n", NULL);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
EVP_MD_CTX_free(mdctx);
|
||||
return(xmlSecBase64Encode(digest, digest_len, 0));
|
||||
}
|
||||
123
experimental/facho-signer/src/xades/xades.h
Normal file
123
experimental/facho-signer/src/xades/xades.h
Normal file
@@ -0,0 +1,123 @@
|
||||
#ifndef XADES_H
|
||||
#define XADES_H
|
||||
|
||||
#include <libxml/tree.h>
|
||||
|
||||
#include <xmlsec/xmltree.h>
|
||||
#include <xmlsec/transforms.h>
|
||||
#include <xmlsec/xmldsig.h>
|
||||
#include <xmlsec/openssl/x509.h>
|
||||
#include <xmlsec/base64.h>
|
||||
|
||||
#include "xmlsec1/errors_helpers.h"
|
||||
|
||||
#define xmlXadesAssert2(p, ret) \
|
||||
xmlSecAssert2(p, ret)
|
||||
|
||||
#define xmlXadesNodeNotFoundError(errorFunction, startNode, targetNodeName, errorObject) \
|
||||
xmlSecNodeNotFoundError(errorFunction, startNode, targetNodeName, errorObject)
|
||||
|
||||
#define xmlXadesXmlError2(errorFunction, errorObject, msg, param) \
|
||||
xmlSecXmlError2(errorFunction, errorObject, msg, param)
|
||||
|
||||
#define xmlXadesErrorsSafeString(msg) \
|
||||
xmlSecErrorsSafeString(msg)
|
||||
|
||||
#define xmlXadesInternalError(errorFunction, errorObject) \
|
||||
xmlSecInternalError(errorFunction, errorObject)
|
||||
|
||||
#define xmlXadesNodeAlreadyPresentError(parent, nodeName, errObject) \
|
||||
xmlSecNodeAlreadyPresentError(parent, nodeName, errObject)
|
||||
|
||||
static const xmlChar xmlXadesNodeQualifyingProperties[] = "QualifyingProperties";
|
||||
static const xmlChar xmlXadesNodeSignedProperties[] = "SignedProperties";
|
||||
|
||||
static const xmlChar xmlXadesNodeSignedSignatureProperties[] = "SignedSignatureProperties";
|
||||
static const xmlChar xmlXadesNodeSigningTime[] = "SigningTime";
|
||||
static const xmlChar xmlXadesNodeSigningCertificate[] = "SigningCertificate";
|
||||
static const xmlChar xmlXadesNodeCert[] = "Cert";
|
||||
static const xmlChar xmlXadesNodeCertDigest[] = "CertDigest";
|
||||
static const xmlChar xmlXadesNodeSignaturePolicyIdentifier[] = "SignaturePolicyIdentifier";
|
||||
static const xmlChar xmlXadesNodeSignaturePolicyId[] = "SignaturePolicyId";
|
||||
static const xmlChar xmlXadesNodeSigPolicyId[] = "SigPolicyId";
|
||||
static const xmlChar xmlXadesNodeIdentifier[] = "Identifier";
|
||||
static const xmlChar xmlXadesNodeDescription[] = "Description";
|
||||
static const xmlChar xmlXadesNodeSigPolicyHash[] = "SigPolicyHash";
|
||||
|
||||
static const xmlChar xmlXadesNodeSignerRole[] = "SignerRole";
|
||||
static const xmlChar xmlXadesNodeClaimedRoles[] = "ClaimedRoles";
|
||||
static const xmlChar xmlXadesNodeClaimedRole[] = "ClaimedRole";
|
||||
static const xmlChar xmlXadesNodeIssuerSerial[] = "IssuerSerial";
|
||||
static const xmlChar xmlXadesNodeX509IssuerName[] = "X509IssuerName";
|
||||
static const xmlChar xmlXadesNodeX509IssuerNumber[] = "X509IssuerNumber";
|
||||
|
||||
static const xmlChar xmlXadesDSigNs[] = "http://uri.etsi.org/01903/v1.3.2#";
|
||||
|
||||
typedef int xmlXadesSize;
|
||||
typedef enum _XADES_DIGEST_METHOD{
|
||||
XADES_DIGEST_SHA256
|
||||
} XADES_DIGEST_METHOD;
|
||||
|
||||
typedef int(*xmlXadesPolicyIdentifierContentCallback)(const xmlChar *policyId, xmlSecBuffer *);
|
||||
|
||||
typedef struct _xmlXadesPolicyIdentifierCtx xmlXadesPolicyIdentifierCtx, *xmlXadesPolicyIdentifierCtxPtr;
|
||||
struct _xmlXadesPolicyIdentifierCtx {
|
||||
xmlXadesPolicyIdentifierContentCallback contentCallback;
|
||||
};
|
||||
|
||||
typedef struct _xmlXadesDSigCtx xmlXadesDSigCtx, *xmlXadesDSigCtxPtr;
|
||||
struct _xmlXadesDSigCtx {
|
||||
xmlSecDSigCtxPtr dsigCtx;
|
||||
XADES_DIGEST_METHOD digestMethod;
|
||||
xmlXadesPolicyIdentifierCtxPtr policyCtx;
|
||||
};
|
||||
|
||||
xmlXadesDSigCtxPtr
|
||||
xmlXadesDSigCtxCreate(xmlSecDSigCtxPtr dsigCtx, XADES_DIGEST_METHOD digestMethod, xmlXadesPolicyIdentifierCtxPtr policyCtx);
|
||||
|
||||
int
|
||||
xmlXadesDSigCtxSign(xmlXadesDSigCtxPtr ctx, xmlNodePtr signNode);
|
||||
|
||||
int
|
||||
xmlXadesDSigCtxDestroy(xmlXadesDSigCtxPtr ctx);
|
||||
|
||||
xmlNodePtr
|
||||
xmlXadesTmplQualifyingPropertiesCreate(xmlDocPtr doc, xmlNodePtr signatureNode, const xmlChar *id);
|
||||
|
||||
xmlNodePtr
|
||||
xmlXadesTmplAddSignedProperties(xmlNodePtr qualifyingPropertiesNode, const xmlChar* id);
|
||||
|
||||
xmlNodePtr
|
||||
xmlXadesTmplAddSigningCertificate(xmlNodePtr parentNode, xmlSecTransformId digestMethodId);
|
||||
|
||||
xmlNodePtr
|
||||
xmlXadesTmplAddCert(xmlNodePtr signingCertificateNode);
|
||||
|
||||
xmlNodePtr
|
||||
xmlXadesTmplAddCertDigest(xmlNodePtr signingCertificateNode, const xmlChar *digestMethod, const xmlChar *digestValue);
|
||||
|
||||
xmlNodePtr
|
||||
xmlXadesTmplAddSignedSignatureProperties(xmlNodePtr parentNode, struct tm* signingTime);
|
||||
|
||||
xmlNodePtr
|
||||
xmlXadesTmplAddSignaturePolicyIdentifier(xmlNodePtr signedSignaturePropertiesNode);
|
||||
|
||||
xmlNodePtr
|
||||
xmlXadesTmplAddSignaturePolicyId(xmlNodePtr signaturePolicyIdentifierNode);
|
||||
|
||||
xmlNodePtr
|
||||
xmlXadesTmplAddSigPolicyId(xmlNodePtr signaturePolicyId, const xmlChar* identifier, const xmlChar *description);
|
||||
|
||||
xmlNodePtr
|
||||
xmlXadesTmplAddSigPolicyHash(xmlNodePtr parentNode, xmlSecTransformId digestMethodId);
|
||||
|
||||
xmlNodePtr
|
||||
xmlXadesTmplAddSignerRole(xmlNodePtr signedSignaturePropertiesNode, const xmlChar* role);
|
||||
|
||||
xmlNodePtr
|
||||
xmlXadesTmplAddDigest(xmlNodePtr parentNode, const xmlChar *digestMethod, const xmlChar *digestValue);
|
||||
|
||||
xmlNodePtr
|
||||
xmlXadesTmplAddIssuerSerial(xmlNodePtr certNode, const xmlChar *issuerName, const xmlChar *issuerNumber);
|
||||
|
||||
#endif //XADES_H
|
||||
89
experimental/facho-signer/src/xades/xades_test.c
Normal file
89
experimental/facho-signer/src/xades/xades_test.c
Normal file
@@ -0,0 +1,89 @@
|
||||
#include <time.h>
|
||||
|
||||
#include <libxml/tree.h>
|
||||
#include "minunit.h"
|
||||
|
||||
#include "xades.h"
|
||||
|
||||
|
||||
MU_TEST(test_xml_add_node_recursive) {
|
||||
xmlDocPtr doc;
|
||||
xmlNodePtr root;
|
||||
xmlNodePtr child;
|
||||
xmlChar* xmlbuff;
|
||||
int xmlbuffsize;
|
||||
|
||||
doc = xmlNewDoc(BAD_CAST "1.0");
|
||||
root = xmlNewNode(NULL, BAD_CAST "root");
|
||||
xmlDocSetRootElement(doc, root);
|
||||
|
||||
child = xmlXadesAddChildRecursiveNs(root, BAD_CAST "A/B/C", NULL);
|
||||
mu_check(child != NULL);
|
||||
|
||||
xmlDocDumpMemory(doc, &xmlbuff, &xmlbuffsize);
|
||||
mu_assert_string_eq("<?xml version=\"1.0\"?>\n"
|
||||
"<root>\n"
|
||||
"<A>\n"
|
||||
"<B>\n"
|
||||
"<C/>\n"
|
||||
"</B>\n"
|
||||
"</A>\n"
|
||||
"</root>\n"
|
||||
, (char *)xmlbuff);
|
||||
}
|
||||
|
||||
MU_TEST(test_qualifying_properties_layout) {
|
||||
xmlDocPtr doc;
|
||||
xmlNodePtr root;
|
||||
xmlNodePtr node;
|
||||
xmlChar* xmlbuff;
|
||||
int buffersize;
|
||||
struct tm tm;
|
||||
|
||||
memset(&tm, 0, sizeof(tm));
|
||||
tm.tm_year = 2021 - 1900;
|
||||
tm.tm_mon = 11;
|
||||
tm.tm_mday = 6;
|
||||
tm.tm_hour = 12;
|
||||
tm.tm_min = 0;
|
||||
tm.tm_sec = 50;
|
||||
|
||||
|
||||
doc = xmlNewDoc(BAD_CAST "1.0");
|
||||
root = xmlNewNode(NULL, BAD_CAST "root");
|
||||
xmlDocSetRootElement(doc, root);
|
||||
|
||||
node = xmlXadesTmplQualifyingPropertiesCreateNsPref(doc, BAD_CAST "123", NULL);
|
||||
xmlXadesTmplAddSignedSignatureProperties(node, &tm);
|
||||
mu_check(node != NULL);
|
||||
|
||||
xmlSecAddChildNode(root, node);
|
||||
xmlDocDumpMemory(doc, &xmlbuff, &buffersize);
|
||||
|
||||
// bit4bit: no se como pasar el namespace al root
|
||||
mu_assert_string_eq("<?xml version=\"1.0\"?>\n"
|
||||
"<root>\n"
|
||||
"<QualifyingProperties xmlns=\"http://uri.etsi.org/01903/v1.3.2#\" id=\"123\">\n"
|
||||
"<SignedProperties>\n"
|
||||
"<SignedSignatureProperties>\n"
|
||||
"<SigningTime>2021-12-06T12:00:50</SigningTime>\n"
|
||||
"</SignedSignatureProperties>\n"
|
||||
"</SignedProperties>\n"
|
||||
"</QualifyingProperties>\n"
|
||||
"</root>\n"
|
||||
, (char *)xmlbuff);
|
||||
|
||||
xmlFree(xmlbuff);
|
||||
xmlFreeDoc(doc);
|
||||
}
|
||||
|
||||
MU_TEST_SUITE(test_suite) {
|
||||
MU_RUN_TEST(test_xml_add_node_recursive);
|
||||
MU_RUN_TEST(test_qualifying_properties_layout);
|
||||
}
|
||||
|
||||
int main() {
|
||||
MU_RUN_SUITE(test_suite);
|
||||
MU_REPORT();
|
||||
return MU_EXIT_CODE;
|
||||
}
|
||||
259
experimental/facho-signer/src/xades/xmlsec1/errors.c
Normal file
259
experimental/facho-signer/src/xades/xmlsec1/errors.c
Normal file
@@ -0,0 +1,259 @@
|
||||
/*
|
||||
* XML Security Library (http://www.aleksey.com/xmlsec).
|
||||
*
|
||||
*
|
||||
* 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:errors
|
||||
* @Short_description: Error reporting and logging functions.
|
||||
* @Stability: Stable
|
||||
*
|
||||
*/
|
||||
|
||||
#define XMLSEC_PRIVATE 1
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <libxml/tree.h>
|
||||
|
||||
#include <xmlsec/xmlsec.h>
|
||||
#include <xmlsec/xmltree.h>
|
||||
#include <xmlsec/private.h>
|
||||
#include <xmlsec/errors.h>
|
||||
|
||||
/* Must be bigger than fatal_error */
|
||||
#define XMLSEC_ERRORS_BUFFER_SIZE 1024
|
||||
|
||||
/* Must fit into xmlChar[XMLSEC_ERRORS_BUFFER_SIZE] */
|
||||
static const xmlChar fatal_error[] = "Can not format error message";
|
||||
|
||||
typedef struct _xmlSecErrorDescription xmlSecErrorDescription, *xmlSecErrorDescriptionPtr;
|
||||
struct _xmlSecErrorDescription {
|
||||
int errorCode;
|
||||
const char* errorMsg;
|
||||
};
|
||||
|
||||
static xmlSecErrorDescription xmlSecErrorsTable[XMLSEC_ERRORS_MAX_NUMBER + 1] = {
|
||||
{ XMLSEC_ERRORS_R_XMLSEC_FAILED, "xmlsec library function failed" },
|
||||
{ XMLSEC_ERRORS_R_MALLOC_FAILED, "malloc function failed" },
|
||||
{ XMLSEC_ERRORS_R_STRDUP_FAILED, "strdup function failed" },
|
||||
{ XMLSEC_ERRORS_R_CRYPTO_FAILED, "crypto library function failed" },
|
||||
{ XMLSEC_ERRORS_R_XML_FAILED, "libxml2 library function failed" },
|
||||
{ XMLSEC_ERRORS_R_XSLT_FAILED, "libxslt library function failed" },
|
||||
{ XMLSEC_ERRORS_R_IO_FAILED, "io function failed" },
|
||||
{ XMLSEC_ERRORS_R_DISABLED, "feature is disabled" },
|
||||
{ XMLSEC_ERRORS_R_NOT_IMPLEMENTED, "feature is not implemented" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_CONFIG, "invalid configuration" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_SIZE, "invalid size" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_DATA, "invalid data" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_RESULT, "invalid result" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_TYPE, "invalid type" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_OPERATION, "invalid operation" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_STATUS, "invalid status" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_FORMAT, "invalid format" },
|
||||
{ XMLSEC_ERRORS_R_DATA_NOT_MATCH, "data do not match" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_VERSION, "invalid version" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_NODE, "invalid node" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_NODE_CONTENT, "invalid node content" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_NODE_ATTRIBUTE, "invalid node attribute" },
|
||||
{ XMLSEC_ERRORS_R_MISSING_NODE_ATTRIBUTE, "missing node attribute" },
|
||||
{ XMLSEC_ERRORS_R_NODE_ALREADY_PRESENT, "node already present" },
|
||||
{ XMLSEC_ERRORS_R_UNEXPECTED_NODE, "unexpected node" },
|
||||
{ XMLSEC_ERRORS_R_NODE_NOT_FOUND, "node node found" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_TRANSFORM, "invalid transform" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_TRANSFORM_KEY, "invalid transform key" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_URI_TYPE, "invalid URI type" },
|
||||
{ XMLSEC_ERRORS_R_TRANSFORM_SAME_DOCUMENT_REQUIRED, "same document is required for transform" },
|
||||
{ XMLSEC_ERRORS_R_TRANSFORM_DISABLED, "transform is disabled" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_KEY_DATA, "invalid key data" },
|
||||
{ XMLSEC_ERRORS_R_KEY_DATA_NOT_FOUND, "key data is not found" },
|
||||
{ XMLSEC_ERRORS_R_KEY_DATA_ALREADY_EXIST, "key data already exist" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_KEY_DATA_SIZE, "invalid key data size" },
|
||||
{ XMLSEC_ERRORS_R_KEY_NOT_FOUND, "key is not found" },
|
||||
{ XMLSEC_ERRORS_R_KEYDATA_DISABLED, "key data is disabled" },
|
||||
{ XMLSEC_ERRORS_R_MAX_RETRIEVALS_LEVEL, "maximum key retrieval level" },
|
||||
{ XMLSEC_ERRORS_R_MAX_RETRIEVAL_TYPE_MISMATCH,"key retrieval type mismatch" },
|
||||
{ XMLSEC_ERRORS_R_MAX_ENCKEY_LEVEL, "maximum encrypted key level" },
|
||||
{ XMLSEC_ERRORS_R_CERT_VERIFY_FAILED, "certificate verification failed" },
|
||||
{ XMLSEC_ERRORS_R_CERT_NOT_FOUND, "certificate is not found" },
|
||||
{ XMLSEC_ERRORS_R_CERT_REVOKED, "certificate is revoked" },
|
||||
{ XMLSEC_ERRORS_R_CERT_ISSUER_FAILED, "certificate issuer check failed" },
|
||||
{ XMLSEC_ERRORS_R_CERT_NOT_YET_VALID, "certificate is not yet valid" },
|
||||
{ XMLSEC_ERRORS_R_CERT_HAS_EXPIRED, "certificate has expired" },
|
||||
{ XMLSEC_ERRORS_R_DSIG_NO_REFERENCES, "Reference nodes are not found" },
|
||||
{ XMLSEC_ERRORS_R_DSIG_INVALID_REFERENCE, "Reference verification failed" },
|
||||
{ XMLSEC_ERRORS_R_ASSERTION, "assertion" },
|
||||
{ 0, NULL}
|
||||
};
|
||||
|
||||
static xmlSecErrorsCallback xmlSecErrorsClbk = xmlSecErrorsDefaultCallback;
|
||||
static int xmlSecPrintErrorMessages = 1; /* whether the error messages will be printed immediately */
|
||||
|
||||
/**
|
||||
* xmlSecErrorsInit:
|
||||
*
|
||||
* Initializes the errors reporting. It is called from #xmlSecInit function.
|
||||
* and applications must not call this function directly.
|
||||
*/
|
||||
void
|
||||
xmlSecErrorsInit(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecErrorsShutdown:
|
||||
*
|
||||
* Cleanups the errors reporting. It is called from #xmlSecShutdown function.
|
||||
* and applications must not call this function directly.
|
||||
*/
|
||||
void
|
||||
xmlSecErrorsShutdown(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecErrorsSetCallback:
|
||||
* @callback: the new errors callback function.
|
||||
*
|
||||
* Sets the errors callback function to @callback that will be called
|
||||
* every time an error occurs.
|
||||
*/
|
||||
void
|
||||
xmlSecErrorsSetCallback(xmlSecErrorsCallback callback) {
|
||||
xmlSecErrorsClbk = callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecErrorsDefaultCallback:
|
||||
* @file: the error location file name (__FILE__ macro).
|
||||
* @line: the error location line number (__LINE__ macro).
|
||||
* @func: the error location function name (__FUNCTION__ macro).
|
||||
* @errorObject: the error specific error object
|
||||
* @errorSubject: the error specific error subject.
|
||||
* @reason: the error code.
|
||||
* @msg: the additional error message.
|
||||
*
|
||||
* The default error reporting callback that utilizes LibXML
|
||||
* error reporting #xmlGenericError function.
|
||||
*/
|
||||
void
|
||||
xmlSecErrorsDefaultCallback(const char* file, int line, const char* func,
|
||||
const char* errorObject, const char* errorSubject,
|
||||
int reason, const char* msg) {
|
||||
if(xmlSecPrintErrorMessages) {
|
||||
const char* error_msg = NULL;
|
||||
xmlSecSize i;
|
||||
|
||||
for(i = 0; (i < XMLSEC_ERRORS_MAX_NUMBER) && (xmlSecErrorsGetMsg(i) != NULL); ++i) {
|
||||
if(xmlSecErrorsGetCode(i) == reason) {
|
||||
error_msg = xmlSecErrorsGetMsg(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
xmlGenericError(xmlGenericErrorContext,
|
||||
"func=%s:file=%s:line=%d:obj=%s:subj=%s:error=%d:%s:%s\n",
|
||||
(func != NULL) ? func : "unknown",
|
||||
(file != NULL) ? file : "unknown",
|
||||
line,
|
||||
(errorObject != NULL) ? errorObject : "unknown",
|
||||
(errorSubject != NULL) ? errorSubject : "unknown",
|
||||
reason,
|
||||
(error_msg != NULL) ? error_msg : "",
|
||||
(msg != NULL) ? msg : "");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecErrorsDefaultCallbackEnableOutput:
|
||||
* @enabled: the flag.
|
||||
*
|
||||
* Enables or disables calling LibXML2 callback from the default
|
||||
* errors callback.
|
||||
*/
|
||||
void
|
||||
xmlSecErrorsDefaultCallbackEnableOutput(int enabled) {
|
||||
xmlSecPrintErrorMessages = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecErrorsGetCode:
|
||||
* @pos: the error position.
|
||||
*
|
||||
* Gets the known error code at position @pos.
|
||||
*
|
||||
* Returns: the known error code or 0 if @pos is greater than
|
||||
* total number of known error codes.
|
||||
*/
|
||||
int
|
||||
xmlSecErrorsGetCode(xmlSecSize pos) {
|
||||
/* could not use asserts here! */
|
||||
if(pos < sizeof(xmlSecErrorsTable) / sizeof(xmlSecErrorsTable[0])) {
|
||||
return(xmlSecErrorsTable[pos].errorCode);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecErrorsGetMsg:
|
||||
* @pos: the error position.
|
||||
*
|
||||
* Gets the known error message at position @pos.
|
||||
*
|
||||
* Returns: the known error message or NULL if @pos is greater than
|
||||
* total number of known error codes.
|
||||
*/
|
||||
const char*
|
||||
xmlSecErrorsGetMsg(xmlSecSize pos) {
|
||||
/* could not use asserts here! */
|
||||
if(pos < sizeof(xmlSecErrorsTable) / sizeof(xmlSecErrorsTable[0])) {
|
||||
return(xmlSecErrorsTable[pos].errorMsg);
|
||||
}
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecError:
|
||||
* @file: the error location filename (__FILE__).
|
||||
* @line: the error location line number (__LINE__).
|
||||
* @func: the error location function (__FUNCTION__).
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
* @errorSubject: the error specific error subject (e.g. failed function name).
|
||||
* @reason: the error code.
|
||||
* @msg: the error message in printf format.
|
||||
* @...: the parameters for the @msg.
|
||||
*
|
||||
* Reports an error to the default (#xmlSecErrorsDefaultCallback) or
|
||||
* application specific callback installed using #xmlSecErrorsSetCallback
|
||||
* function.
|
||||
*/
|
||||
void
|
||||
xmlSecError(const char* file, int line, const char* func,
|
||||
const char* errorObject, const char* errorSubject,
|
||||
int reason, const char* msg, ...) {
|
||||
if(xmlSecErrorsClbk != NULL) {
|
||||
xmlChar error_msg[XMLSEC_ERRORS_BUFFER_SIZE];
|
||||
int ret;
|
||||
|
||||
if(msg != NULL) {
|
||||
va_list va;
|
||||
|
||||
va_start(va, msg);
|
||||
ret = xmlStrVPrintf(error_msg, sizeof(error_msg), msg, va);
|
||||
if(ret < 0) {
|
||||
/* Can't really report an error from an error callback */
|
||||
memcpy(error_msg, fatal_error, sizeof(fatal_error));
|
||||
}
|
||||
error_msg[sizeof(error_msg) - 1] = '\0'; /* just in case */
|
||||
va_end(va);
|
||||
} else {
|
||||
error_msg[0] = '\0';
|
||||
}
|
||||
xmlSecErrorsClbk(file, line, func, errorObject, errorSubject, reason, (char*)error_msg);
|
||||
}
|
||||
}
|
||||
869
experimental/facho-signer/src/xades/xmlsec1/errors_helpers.h
Normal file
869
experimental/facho-signer/src/xades/xmlsec1/errors_helpers.h
Normal file
@@ -0,0 +1,869 @@
|
||||
/*
|
||||
* XML Security Library (http://www.aleksey.com/xmlsec).
|
||||
*
|
||||
* Internal header only used during the compilation,
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __XMLSEC_ERROR_HELPERS_H__
|
||||
#define __XMLSEC_ERROR_HELPERS_H__
|
||||
|
||||
#include <errno.h>
|
||||
#include <xmlsec/errors.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**********************************************************************
|
||||
*
|
||||
* Error handling macros.
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
/**
|
||||
* xmlSecInternalError:
|
||||
* @errorFunction: the failed function name.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting internal XMLSec errors.
|
||||
*/
|
||||
#define xmlSecInternalError(errorFunction, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
(errorFunction), \
|
||||
XMLSEC_ERRORS_R_XMLSEC_FAILED, \
|
||||
XMLSEC_ERRORS_NO_MESSAGE \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInternalError2:
|
||||
* @errorFunction: the failed function name.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
* @msg: the extra message.
|
||||
* @param: the extra message param.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting internal XMLSec errors.
|
||||
*/
|
||||
#define xmlSecInternalError2(errorFunction, errorObject, msg, param) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
(errorFunction), \
|
||||
XMLSEC_ERRORS_R_XMLSEC_FAILED, \
|
||||
(msg), (param) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInternalError3:
|
||||
* @errorFunction: the failed function name.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
* @msg: the extra message.
|
||||
* @param1: the extra message param1.
|
||||
* @param2: the extra message param2.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting internal XMLSec errors.
|
||||
*/
|
||||
#define xmlSecInternalError3(errorFunction, errorObject, msg, param1, param2) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
(errorFunction), \
|
||||
XMLSEC_ERRORS_R_XMLSEC_FAILED, \
|
||||
(msg), (param1), (param2) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInternalError4:
|
||||
* @errorFunction: the failed function name.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
* @msg: the extra message.
|
||||
* @param1: the extra message param1.
|
||||
* @param2: the extra message param2.
|
||||
* @param3: the extra message param3.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting internal XMLSec errors.
|
||||
*/
|
||||
#define xmlSecInternalError4(errorFunction, errorObject, msg, param1, param2, param3) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
(errorFunction), \
|
||||
XMLSEC_ERRORS_R_XMLSEC_FAILED, \
|
||||
(msg), (param1), (param2), (param3) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecMallocError:
|
||||
* @allocSize: the failed allocation size.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting xmlMalloc() errors.
|
||||
*/
|
||||
#define xmlSecMallocError(allocSize, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
"xmlMalloc", \
|
||||
XMLSEC_ERRORS_R_MALLOC_FAILED, \
|
||||
"size=%lu", (unsigned long)(allocSize) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecStrdupError:
|
||||
* @str: the failed string.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting xmlStrdup() errors.
|
||||
*/
|
||||
#define xmlSecStrdupError(str, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
"xmlStrdup", \
|
||||
XMLSEC_ERRORS_R_STRDUP_FAILED, \
|
||||
"size=%lu", (unsigned long)xmlStrlen(str) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecXmlError:
|
||||
* @errorFunction: the failed function.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting generic XML errors.
|
||||
*/
|
||||
#define xmlSecXmlError(errorFunction, errorObject) \
|
||||
{ \
|
||||
xmlErrorPtr error = xmlGetLastError(); \
|
||||
int code = (error != NULL) ? error->code : 0; \
|
||||
const char* message = (error != NULL) ? error->message : NULL; \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
(errorFunction), \
|
||||
XMLSEC_ERRORS_R_XML_FAILED, \
|
||||
"xml error: %lu: %s", \
|
||||
(unsigned long)code, \
|
||||
xmlSecErrorsSafeString(message) \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecXmlError2:
|
||||
* @errorFunction: the failed function.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
* @msg: the extra message.
|
||||
* @param: the extra message param.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting generic XML errors.
|
||||
*/
|
||||
#define xmlSecXmlError2(errorFunction, errorObject, msg, param) \
|
||||
{ \
|
||||
xmlErrorPtr error = xmlGetLastError(); \
|
||||
int code = (error != NULL) ? error->code : 0; \
|
||||
const char* message = (error != NULL) ? error->message : NULL; \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
(errorFunction), \
|
||||
XMLSEC_ERRORS_R_XML_FAILED, \
|
||||
msg "; xml error: %lu: %s", \
|
||||
(param), \
|
||||
(unsigned long)code, \
|
||||
xmlSecErrorsSafeString(message) \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecXmlParserError:
|
||||
* @errorFunction: the failed function.
|
||||
* @ctxt: the parser context.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting XML parser errors.
|
||||
*/
|
||||
#define xmlSecXmlParserError(errorFunction, ctxt, errorObject) \
|
||||
{ \
|
||||
xmlErrorPtr error = xmlCtxtGetLastError(ctxt);\
|
||||
int code = (error != NULL) ? error->code : 0; \
|
||||
const char* message = (error != NULL) ? error->message : NULL; \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
(errorFunction), \
|
||||
XMLSEC_ERRORS_R_XML_FAILED, \
|
||||
"xml error: %lu: %s", \
|
||||
(unsigned long)code, \
|
||||
xmlSecErrorsSafeString(message) \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecXmlParserError2:
|
||||
* @errorFunction: the failed function.
|
||||
* @ctxt: the parser context.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
* @msg: the extra message.
|
||||
* @param: the extra message param.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting XML parser errors.
|
||||
*/
|
||||
#define xmlSecXmlParserError2(errorFunction, ctxt, errorObject, msg, param) \
|
||||
{ \
|
||||
xmlErrorPtr error = xmlCtxtGetLastError(ctxt);\
|
||||
int code = (error != NULL) ? error->code : 0; \
|
||||
const char* message = (error != NULL) ? error->message : NULL; \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
(errorFunction), \
|
||||
XMLSEC_ERRORS_R_XML_FAILED, \
|
||||
msg "; xml error: %lu: %s", \
|
||||
(param), \
|
||||
(unsigned long)code, \
|
||||
xmlSecErrorsSafeString(message) \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecXsltError:
|
||||
* @errorFunction: the failed function.
|
||||
* @ctxt: the parser context.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting XSLT errors.
|
||||
*/
|
||||
#define xmlSecXsltError(errorFunction, ctxt, errorObject) \
|
||||
{ \
|
||||
xmlErrorPtr error = xmlGetLastError(); \
|
||||
int code = (error != NULL) ? error->code : 0; \
|
||||
const char* message = (error != NULL) ? error->message : NULL; \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
(errorFunction), \
|
||||
XMLSEC_ERRORS_R_XSLT_FAILED, \
|
||||
"xslt error: %lu: %s", \
|
||||
(unsigned long)code, \
|
||||
xmlSecErrorsSafeString(message) \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecIOError:
|
||||
* @errorFunction: the failed function.
|
||||
* @name: the filename, function name, uri, etc.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting IO errors.
|
||||
*/
|
||||
#define xmlSecIOError(errorFunction, name, errorObject) \
|
||||
{ \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
(errorFunction), \
|
||||
XMLSEC_ERRORS_R_IO_FAILED, \
|
||||
"name=\"%s\"; errno=%d", \
|
||||
xmlSecErrorsSafeString(name), \
|
||||
errno \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecNotImplementedError:
|
||||
* @details: the additional details.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "not implemented" errors.
|
||||
*/
|
||||
#define xmlSecNotImplementedError(details) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_NOT_IMPLEMENTED, \
|
||||
"details=%s", \
|
||||
xmlSecErrorsSafeString(details) \
|
||||
)
|
||||
/**
|
||||
* xmlSecInvalidSizeError:
|
||||
* @name: the name of the variable, parameter, etc.
|
||||
* @actual: the actual value.
|
||||
* @expected: the expected value.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid size" errors when
|
||||
* we expect exact match.
|
||||
*/
|
||||
#define xmlSecInvalidSizeError(name, actual, expected, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_SIZE, \
|
||||
"invalid size for '%s': actual=%lu is not equal to expected=%lu", \
|
||||
xmlSecErrorsSafeString(name), \
|
||||
(unsigned long)(actual), \
|
||||
(unsigned long)(expected) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInvalidSizeLessThanError:
|
||||
* @name: the name of the variable, parameter, etc.
|
||||
* @actual: the actual value.
|
||||
* @expected: the expected value.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid size" errors when
|
||||
* we expect at least the expected size.
|
||||
*/
|
||||
#define xmlSecInvalidSizeLessThanError(name, actual, expected, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_SIZE, \
|
||||
"invalid size for '%s': actual=%lu is less than expected=%lu", \
|
||||
xmlSecErrorsSafeString(name), \
|
||||
(unsigned long)(actual), \
|
||||
(unsigned long)(expected) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInvalidSizeMoreThanError:
|
||||
* @name: the name of the variable, parameter, etc.
|
||||
* @actual: the actual value.
|
||||
* @expected: the expected value.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid size" errors when
|
||||
* we expect at most the expected size.
|
||||
*/
|
||||
#define xmlSecInvalidSizeMoreThanError(name, actual, expected, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_NOT_IMPLEMENTED, \
|
||||
"invalid size for '%s': actual=%lu is more than expected=%lu", \
|
||||
xmlSecErrorsSafeString(name), \
|
||||
(unsigned long)(actual), \
|
||||
(unsigned long)(expected) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInvalidSizeNotMultipleOfError:
|
||||
* @name: the name of the variable, parameter, etc.
|
||||
* @actual: the actual value.
|
||||
* @divider: the expected divider.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid size" errors when
|
||||
* we expect the size to be a multiple of the divider.
|
||||
*/
|
||||
#define xmlSecInvalidSizeNotMultipleOfError(name, actual, divider, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_NOT_IMPLEMENTED, \
|
||||
"invalid size for '%s': actual=%lu is not a multiple of %lu", \
|
||||
xmlSecErrorsSafeString(name), \
|
||||
(unsigned long)(actual), \
|
||||
(unsigned long)(divider) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInvalidSizeOtherError:
|
||||
* @msg: the message about the error.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid size" errors when
|
||||
* we expect exact match.
|
||||
*/
|
||||
#define xmlSecInvalidSizeOtherError(msg, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_SIZE, \
|
||||
"invalid size: %s", \
|
||||
xmlSecErrorsSafeString(msg) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInvalidDataError:
|
||||
* @msg: the msg with explanation.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid data" errors.
|
||||
*/
|
||||
#define xmlSecInvalidDataError(msg, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_DATA, \
|
||||
"%s", \
|
||||
xmlSecErrorsSafeString(msg) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInvalidStringDataError:
|
||||
* @name: the name of the variable, parameter, etc.
|
||||
* @actual: the actual value as a string.
|
||||
* @expected: the expected value(s) as a string.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid data" errors for string.
|
||||
*/
|
||||
#define xmlSecInvalidStringDataError(name, actual, expected, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_DATA, \
|
||||
"invalid data for '%s': actual='%s' and expected %s", \
|
||||
xmlSecErrorsSafeString(name), \
|
||||
xmlSecErrorsSafeString(actual), \
|
||||
(expected) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInvalidIntegerDataError:
|
||||
* @name: the name of the variable, parameter, etc.
|
||||
* @actual: the actual value as an integer.
|
||||
* @expected: the expected value(s) as a string.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid data" errors for integers.
|
||||
*/
|
||||
#define xmlSecInvalidIntegerDataError(name, actual, expected, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_DATA, \
|
||||
"invalid data for '%s': actual=%ld and expected %s", \
|
||||
xmlSecErrorsSafeString(name), \
|
||||
(unsigned long)(actual), \
|
||||
(expected) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInvalidIntegerDataError2:
|
||||
* @name1: the name of the first variable, parameter, etc.
|
||||
* @actual1: the actual first value as an integer.
|
||||
* @name2: the name of the second variable, parameter, etc.
|
||||
* @actual2: the actual second value as an integer.
|
||||
* @expected: the expected value(s) as a string.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid data" errors for integers.
|
||||
*/
|
||||
#define xmlSecInvalidIntegerDataError2(name1, actual1, name2, actual2, expected, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_DATA, \
|
||||
"invalid data: actual value '%s'=%ld, actual value '%s'=%ld and expected %s", \
|
||||
xmlSecErrorsSafeString(name1), \
|
||||
(unsigned long)(actual1), \
|
||||
xmlSecErrorsSafeString(name2), \
|
||||
(unsigned long)(actual2), \
|
||||
(expected) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInvalidTypeError:
|
||||
* @msg: the msg with explanation.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid type" errors.
|
||||
*/
|
||||
#define xmlSecInvalidTypeError(msg, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_TYPE, \
|
||||
"%s", \
|
||||
xmlSecErrorsSafeString(msg) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInvalidStringTypeError:
|
||||
* @name: the name of the variable, parameter, etc.
|
||||
* @actual: the actual value as a string.
|
||||
* @expected: the expected value(s) as a string.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid type" errors for string.
|
||||
*/
|
||||
#define xmlSecInvalidStringTypeError(name, actual, expected, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_TYPE, \
|
||||
"invalid type for '%s': actual='%s' and expected %s", \
|
||||
xmlSecErrorsSafeString(name), \
|
||||
xmlSecErrorsSafeString(actual), \
|
||||
(expected) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInvalidIntegerTypeError:
|
||||
* @name: the name of the variable, parameter, etc.
|
||||
* @actual: the actual value as an integer.
|
||||
* @expected: the expected value(s) as a string.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid type" errors for integers.
|
||||
*/
|
||||
#define xmlSecInvalidIntegerTypeError(name, actual, expected, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_TYPE, \
|
||||
"invalid type for '%s': actual=%ld and expected %s", \
|
||||
xmlSecErrorsSafeString(name), \
|
||||
(unsigned long)(actual), \
|
||||
(expected) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInvalidIntegerTypeError2:
|
||||
* @name1: the name of the first variable, parameter, etc.
|
||||
* @actual1: the actual first value as an integer.
|
||||
* @name2: the name of the second variable, parameter, etc.
|
||||
* @actual2: the actual second value as an integer.
|
||||
* @expected: the expected value(s) as a string.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid type" errors for integers.
|
||||
*/
|
||||
#define xmlSecInvalidIntegerTypeError2(name1, actual1, name2, actual2, expected, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_TYPE, \
|
||||
"invalid type: actual value '%s'=%ld, actual value '%s'=%ld and expected %s", \
|
||||
xmlSecErrorsSafeString(name1), \
|
||||
(unsigned long)(actual1), \
|
||||
xmlSecErrorsSafeString(name2), \
|
||||
(unsigned long)(actual2), \
|
||||
(expected) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInvalidNodeError:
|
||||
* @actualNode: the actual node.
|
||||
* @expectedNodeName: the expected node name.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting an invalid node errors.
|
||||
*/
|
||||
#define xmlSecInvalidNodeError(actualNode, expectedNodeName, errorObject) \
|
||||
{ \
|
||||
const char* actualNodeName = xmlSecNodeGetName(actualNode); \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_NODE, \
|
||||
"actual=%s; expected=%s", \
|
||||
xmlSecErrorsSafeString(actualNodeName), \
|
||||
xmlSecErrorsSafeString(expectedNodeName) \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecInvalidNodeContentError:
|
||||
* @node: the node.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
* @reason: the reason why node content is invalid.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting an invalid node content errors.
|
||||
*/
|
||||
#define xmlSecInvalidNodeContentError(node, errorObject, reason) \
|
||||
{ \
|
||||
const char* nName = xmlSecNodeGetName(node); \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_NODE_CONTENT, \
|
||||
"node=%s; reason=%s", \
|
||||
xmlSecErrorsSafeString(nName), \
|
||||
xmlSecErrorsSafeString(reason) \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecInvalidNodeAttributeError:
|
||||
* @node: the node.
|
||||
* @attrName: the attribute name.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
* @reason: the reason why node content is invalid.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting an invalid node attribute errors.
|
||||
*/
|
||||
#define xmlSecInvalidNodeAttributeError(node, attrName, errorObject, reason) \
|
||||
{ \
|
||||
const char* nName = xmlSecNodeGetName(node); \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_NODE_ATTRIBUTE, \
|
||||
"node=%s; attribute=%s; reason=%s",\
|
||||
xmlSecErrorsSafeString(nName), \
|
||||
xmlSecErrorsSafeString(attrName), \
|
||||
xmlSecErrorsSafeString(reason) \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecNodeAlreadyPresentError:
|
||||
* @parent: the parent node.
|
||||
* @nodeName: the node name.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting node already present errors.
|
||||
*/
|
||||
#define xmlSecNodeAlreadyPresentError(parent, nodeName, errorObject) \
|
||||
{ \
|
||||
const char* pName = xmlSecNodeGetName(parent);\
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_NODE_ALREADY_PRESENT, \
|
||||
"parent=%s; node=%s", \
|
||||
xmlSecErrorsSafeString(pName), \
|
||||
xmlSecErrorsSafeString(nodeName) \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecUnexpectedNodeError:
|
||||
* @node: the node.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting an invalid node errors.
|
||||
*/
|
||||
#define xmlSecUnexpectedNodeError(node, errorObject) \
|
||||
{ \
|
||||
const char* nName = xmlSecNodeGetName(node); \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_UNEXPECTED_NODE, \
|
||||
"node=%s", \
|
||||
xmlSecErrorsSafeString(nName) \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecNodeNotFoundError:
|
||||
* @errorFunction: the failed function.
|
||||
* @startNode: the search start node.
|
||||
* @targetNodeName: the expected child node name.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting node not found errors.
|
||||
*/
|
||||
#define xmlSecNodeNotFoundError(errorFunction, startNode, targetNodeName, errorObject) \
|
||||
{ \
|
||||
const char* startNodeName = xmlSecNodeGetName(startNode); \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
(errorFunction), \
|
||||
XMLSEC_ERRORS_R_NODE_NOT_FOUND, \
|
||||
"startNode=%s; target=%s", \
|
||||
xmlSecErrorsSafeString(startNodeName), \
|
||||
xmlSecErrorsSafeString(targetNodeName) \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecInvalidTransfromError:
|
||||
* @transform: the transform.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting an invalid transform errors.
|
||||
*/
|
||||
#define xmlSecInvalidTransfromError(transform) \
|
||||
{ \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)xmlSecTransformGetName(transform), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_TRANSFORM, \
|
||||
XMLSEC_ERRORS_NO_MESSAGE \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecInvalidTransfromError2:
|
||||
* @transform: the transform.
|
||||
* @msg: the extra message.
|
||||
* @param: the extra message param.
|
||||
*
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting an invalid transform errors.
|
||||
*/
|
||||
#define xmlSecInvalidTransfromError2(transform, msg, param) \
|
||||
{ \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)xmlSecTransformGetName(transform), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_TRANSFORM, \
|
||||
(msg), (param) \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecInvalidTransfromStatusError:
|
||||
* @transform: the transform.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting an invalid transform status errors.
|
||||
*/
|
||||
#define xmlSecInvalidTransfromStatusError(transform) \
|
||||
{ \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)xmlSecTransformGetName(transform), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_STATUS, \
|
||||
"transformStatus=%d", \
|
||||
(int)((transform)->status) \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecInvalidTransfromStatusError2:
|
||||
* @transform: the transform.
|
||||
* @msg: the extra message.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting an invalid transform status errors.
|
||||
*/
|
||||
#define xmlSecInvalidTransfromStatusError2(transform, msg) \
|
||||
{ \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)xmlSecTransformGetName(transform), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_STATUS, \
|
||||
"transformStatus=%ld, msg=%s", \
|
||||
(long int)((transform)->status), \
|
||||
msg \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecInvalidKeyDataSizeError:
|
||||
* @name: the name of the variable, parameter, etc.
|
||||
* @actual: the actual value.
|
||||
* @expected: the expected value(s).
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid keydata size" errors.
|
||||
*/
|
||||
#define xmlSecInvalidKeyDataSizeError(actual, expected, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_KEY_DATA_SIZE, \
|
||||
"invalid key data size: actual=%ld and expected=%ld", \
|
||||
(unsigned long)(actual), \
|
||||
(unsigned long)(expected) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInvalidZeroKeyDataSizeError:
|
||||
* @name: the name of the variable, parameter, etc.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid keydata size" errors.
|
||||
*/
|
||||
#define xmlSecInvalidZeroKeyDataSizeError(errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_KEY_DATA_SIZE, \
|
||||
"invalid zero key data size" \
|
||||
)
|
||||
|
||||
|
||||
/**
|
||||
* xmlSecOtherError:
|
||||
* @code: the error code.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
* @details: the error message.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting other XMLSec errors.
|
||||
*/
|
||||
#define xmlSecOtherError(code, errorObject, details) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
(code), \
|
||||
"details=%s", \
|
||||
xmlSecErrorsSafeString(details) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecOtherError2:
|
||||
* @code: the error code.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
* @msg: the extra message.
|
||||
* @param: the extra message param.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting other XMLSec errors.
|
||||
*/
|
||||
#define xmlSecOtherError2(code, errorObject, msg, param) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
(code), \
|
||||
(msg), (param) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecOtherError3:
|
||||
* @code: the error code.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
* @msg: the extra message.
|
||||
* @param1: the extra message param.
|
||||
* @param2: the extra message param.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting other XMLSec errors.
|
||||
*/
|
||||
#define xmlSecOtherError3(code, errorObject, msg, param1, param2) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
(code), \
|
||||
(msg), (param1), (param2) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecOtherError4:
|
||||
* @code: the error code.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
* @msg: the extra message.
|
||||
* @param1: the extra message param.
|
||||
* @param2: the extra message param.
|
||||
* @param3: the extra message param.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting other XMLSec errors.
|
||||
*/
|
||||
#define xmlSecOtherError4(code, errorObject, msg, param1, param2, param3) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
(code), \
|
||||
(msg), (param1), (param2), (param3) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecOtherError5:
|
||||
* @code: the error code.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
* @msg: the extra message.
|
||||
* @param1: the extra message param.
|
||||
* @param2: the extra message param.
|
||||
* @param3: the extra message param.
|
||||
* @param4: the extra message param.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting other XMLSec errors.
|
||||
*/
|
||||
#define xmlSecOtherError5(code, errorObject, msg, param1, param2, param3, param4) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
(code), \
|
||||
(msg), (param1), (param2), (param3), (param4) \
|
||||
)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __XMLSEC_ERROR_HELPERS_H__ */
|
||||
1950
experimental/facho-signer/src/xades/xmlsec1/xmltree.c
Normal file
1950
experimental/facho-signer/src/xades/xmlsec1/xmltree.c
Normal file
File diff suppressed because it is too large
Load Diff
259
experimental/facho-signer/src/xmlsec1/errors.c
Normal file
259
experimental/facho-signer/src/xmlsec1/errors.c
Normal file
@@ -0,0 +1,259 @@
|
||||
/*
|
||||
* XML Security Library (http://www.aleksey.com/xmlsec).
|
||||
*
|
||||
*
|
||||
* 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:errors
|
||||
* @Short_description: Error reporting and logging functions.
|
||||
* @Stability: Stable
|
||||
*
|
||||
*/
|
||||
|
||||
#define XMLSEC_PRIVATE 1
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <libxml/tree.h>
|
||||
|
||||
#include <xmlsec/xmlsec.h>
|
||||
#include <xmlsec/xmltree.h>
|
||||
#include <xmlsec/private.h>
|
||||
#include <xmlsec/errors.h>
|
||||
|
||||
/* Must be bigger than fatal_error */
|
||||
#define XMLSEC_ERRORS_BUFFER_SIZE 1024
|
||||
|
||||
/* Must fit into xmlChar[XMLSEC_ERRORS_BUFFER_SIZE] */
|
||||
static const xmlChar fatal_error[] = "Can not format error message";
|
||||
|
||||
typedef struct _xmlSecErrorDescription xmlSecErrorDescription, *xmlSecErrorDescriptionPtr;
|
||||
struct _xmlSecErrorDescription {
|
||||
int errorCode;
|
||||
const char* errorMsg;
|
||||
};
|
||||
|
||||
static xmlSecErrorDescription xmlSecErrorsTable[XMLSEC_ERRORS_MAX_NUMBER + 1] = {
|
||||
{ XMLSEC_ERRORS_R_XMLSEC_FAILED, "xmlsec library function failed" },
|
||||
{ XMLSEC_ERRORS_R_MALLOC_FAILED, "malloc function failed" },
|
||||
{ XMLSEC_ERRORS_R_STRDUP_FAILED, "strdup function failed" },
|
||||
{ XMLSEC_ERRORS_R_CRYPTO_FAILED, "crypto library function failed" },
|
||||
{ XMLSEC_ERRORS_R_XML_FAILED, "libxml2 library function failed" },
|
||||
{ XMLSEC_ERRORS_R_XSLT_FAILED, "libxslt library function failed" },
|
||||
{ XMLSEC_ERRORS_R_IO_FAILED, "io function failed" },
|
||||
{ XMLSEC_ERRORS_R_DISABLED, "feature is disabled" },
|
||||
{ XMLSEC_ERRORS_R_NOT_IMPLEMENTED, "feature is not implemented" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_CONFIG, "invalid configuration" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_SIZE, "invalid size" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_DATA, "invalid data" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_RESULT, "invalid result" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_TYPE, "invalid type" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_OPERATION, "invalid operation" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_STATUS, "invalid status" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_FORMAT, "invalid format" },
|
||||
{ XMLSEC_ERRORS_R_DATA_NOT_MATCH, "data do not match" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_VERSION, "invalid version" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_NODE, "invalid node" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_NODE_CONTENT, "invalid node content" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_NODE_ATTRIBUTE, "invalid node attribute" },
|
||||
{ XMLSEC_ERRORS_R_MISSING_NODE_ATTRIBUTE, "missing node attribute" },
|
||||
{ XMLSEC_ERRORS_R_NODE_ALREADY_PRESENT, "node already present" },
|
||||
{ XMLSEC_ERRORS_R_UNEXPECTED_NODE, "unexpected node" },
|
||||
{ XMLSEC_ERRORS_R_NODE_NOT_FOUND, "node node found" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_TRANSFORM, "invalid transform" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_TRANSFORM_KEY, "invalid transform key" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_URI_TYPE, "invalid URI type" },
|
||||
{ XMLSEC_ERRORS_R_TRANSFORM_SAME_DOCUMENT_REQUIRED, "same document is required for transform" },
|
||||
{ XMLSEC_ERRORS_R_TRANSFORM_DISABLED, "transform is disabled" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_KEY_DATA, "invalid key data" },
|
||||
{ XMLSEC_ERRORS_R_KEY_DATA_NOT_FOUND, "key data is not found" },
|
||||
{ XMLSEC_ERRORS_R_KEY_DATA_ALREADY_EXIST, "key data already exist" },
|
||||
{ XMLSEC_ERRORS_R_INVALID_KEY_DATA_SIZE, "invalid key data size" },
|
||||
{ XMLSEC_ERRORS_R_KEY_NOT_FOUND, "key is not found" },
|
||||
{ XMLSEC_ERRORS_R_KEYDATA_DISABLED, "key data is disabled" },
|
||||
{ XMLSEC_ERRORS_R_MAX_RETRIEVALS_LEVEL, "maximum key retrieval level" },
|
||||
{ XMLSEC_ERRORS_R_MAX_RETRIEVAL_TYPE_MISMATCH,"key retrieval type mismatch" },
|
||||
{ XMLSEC_ERRORS_R_MAX_ENCKEY_LEVEL, "maximum encrypted key level" },
|
||||
{ XMLSEC_ERRORS_R_CERT_VERIFY_FAILED, "certificate verification failed" },
|
||||
{ XMLSEC_ERRORS_R_CERT_NOT_FOUND, "certificate is not found" },
|
||||
{ XMLSEC_ERRORS_R_CERT_REVOKED, "certificate is revoked" },
|
||||
{ XMLSEC_ERRORS_R_CERT_ISSUER_FAILED, "certificate issuer check failed" },
|
||||
{ XMLSEC_ERRORS_R_CERT_NOT_YET_VALID, "certificate is not yet valid" },
|
||||
{ XMLSEC_ERRORS_R_CERT_HAS_EXPIRED, "certificate has expired" },
|
||||
{ XMLSEC_ERRORS_R_DSIG_NO_REFERENCES, "Reference nodes are not found" },
|
||||
{ XMLSEC_ERRORS_R_DSIG_INVALID_REFERENCE, "Reference verification failed" },
|
||||
{ XMLSEC_ERRORS_R_ASSERTION, "assertion" },
|
||||
{ 0, NULL}
|
||||
};
|
||||
|
||||
static xmlSecErrorsCallback xmlSecErrorsClbk = xmlSecErrorsDefaultCallback;
|
||||
static int xmlSecPrintErrorMessages = 1; /* whether the error messages will be printed immediately */
|
||||
|
||||
/**
|
||||
* xmlSecErrorsInit:
|
||||
*
|
||||
* Initializes the errors reporting. It is called from #xmlSecInit function.
|
||||
* and applications must not call this function directly.
|
||||
*/
|
||||
void
|
||||
xmlSecErrorsInit(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecErrorsShutdown:
|
||||
*
|
||||
* Cleanups the errors reporting. It is called from #xmlSecShutdown function.
|
||||
* and applications must not call this function directly.
|
||||
*/
|
||||
void
|
||||
xmlSecErrorsShutdown(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecErrorsSetCallback:
|
||||
* @callback: the new errors callback function.
|
||||
*
|
||||
* Sets the errors callback function to @callback that will be called
|
||||
* every time an error occurs.
|
||||
*/
|
||||
void
|
||||
xmlSecErrorsSetCallback(xmlSecErrorsCallback callback) {
|
||||
xmlSecErrorsClbk = callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecErrorsDefaultCallback:
|
||||
* @file: the error location file name (__FILE__ macro).
|
||||
* @line: the error location line number (__LINE__ macro).
|
||||
* @func: the error location function name (__FUNCTION__ macro).
|
||||
* @errorObject: the error specific error object
|
||||
* @errorSubject: the error specific error subject.
|
||||
* @reason: the error code.
|
||||
* @msg: the additional error message.
|
||||
*
|
||||
* The default error reporting callback that utilizes LibXML
|
||||
* error reporting #xmlGenericError function.
|
||||
*/
|
||||
void
|
||||
xmlSecErrorsDefaultCallback(const char* file, int line, const char* func,
|
||||
const char* errorObject, const char* errorSubject,
|
||||
int reason, const char* msg) {
|
||||
if(xmlSecPrintErrorMessages) {
|
||||
const char* error_msg = NULL;
|
||||
xmlSecSize i;
|
||||
|
||||
for(i = 0; (i < XMLSEC_ERRORS_MAX_NUMBER) && (xmlSecErrorsGetMsg(i) != NULL); ++i) {
|
||||
if(xmlSecErrorsGetCode(i) == reason) {
|
||||
error_msg = xmlSecErrorsGetMsg(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
xmlGenericError(xmlGenericErrorContext,
|
||||
"func=%s:file=%s:line=%d:obj=%s:subj=%s:error=%d:%s:%s\n",
|
||||
(func != NULL) ? func : "unknown",
|
||||
(file != NULL) ? file : "unknown",
|
||||
line,
|
||||
(errorObject != NULL) ? errorObject : "unknown",
|
||||
(errorSubject != NULL) ? errorSubject : "unknown",
|
||||
reason,
|
||||
(error_msg != NULL) ? error_msg : "",
|
||||
(msg != NULL) ? msg : "");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecErrorsDefaultCallbackEnableOutput:
|
||||
* @enabled: the flag.
|
||||
*
|
||||
* Enables or disables calling LibXML2 callback from the default
|
||||
* errors callback.
|
||||
*/
|
||||
void
|
||||
xmlSecErrorsDefaultCallbackEnableOutput(int enabled) {
|
||||
xmlSecPrintErrorMessages = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecErrorsGetCode:
|
||||
* @pos: the error position.
|
||||
*
|
||||
* Gets the known error code at position @pos.
|
||||
*
|
||||
* Returns: the known error code or 0 if @pos is greater than
|
||||
* total number of known error codes.
|
||||
*/
|
||||
int
|
||||
xmlSecErrorsGetCode(xmlSecSize pos) {
|
||||
/* could not use asserts here! */
|
||||
if(pos < sizeof(xmlSecErrorsTable) / sizeof(xmlSecErrorsTable[0])) {
|
||||
return(xmlSecErrorsTable[pos].errorCode);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecErrorsGetMsg:
|
||||
* @pos: the error position.
|
||||
*
|
||||
* Gets the known error message at position @pos.
|
||||
*
|
||||
* Returns: the known error message or NULL if @pos is greater than
|
||||
* total number of known error codes.
|
||||
*/
|
||||
const char*
|
||||
xmlSecErrorsGetMsg(xmlSecSize pos) {
|
||||
/* could not use asserts here! */
|
||||
if(pos < sizeof(xmlSecErrorsTable) / sizeof(xmlSecErrorsTable[0])) {
|
||||
return(xmlSecErrorsTable[pos].errorMsg);
|
||||
}
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecError:
|
||||
* @file: the error location filename (__FILE__).
|
||||
* @line: the error location line number (__LINE__).
|
||||
* @func: the error location function (__FUNCTION__).
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
* @errorSubject: the error specific error subject (e.g. failed function name).
|
||||
* @reason: the error code.
|
||||
* @msg: the error message in printf format.
|
||||
* @...: the parameters for the @msg.
|
||||
*
|
||||
* Reports an error to the default (#xmlSecErrorsDefaultCallback) or
|
||||
* application specific callback installed using #xmlSecErrorsSetCallback
|
||||
* function.
|
||||
*/
|
||||
void
|
||||
xmlSecError(const char* file, int line, const char* func,
|
||||
const char* errorObject, const char* errorSubject,
|
||||
int reason, const char* msg, ...) {
|
||||
if(xmlSecErrorsClbk != NULL) {
|
||||
xmlChar error_msg[XMLSEC_ERRORS_BUFFER_SIZE];
|
||||
int ret;
|
||||
|
||||
if(msg != NULL) {
|
||||
va_list va;
|
||||
|
||||
va_start(va, msg);
|
||||
ret = xmlStrVPrintf(error_msg, sizeof(error_msg), msg, va);
|
||||
if(ret < 0) {
|
||||
/* Can't really report an error from an error callback */
|
||||
memcpy(error_msg, fatal_error, sizeof(fatal_error));
|
||||
}
|
||||
error_msg[sizeof(error_msg) - 1] = '\0'; /* just in case */
|
||||
va_end(va);
|
||||
} else {
|
||||
error_msg[0] = '\0';
|
||||
}
|
||||
xmlSecErrorsClbk(file, line, func, errorObject, errorSubject, reason, (char*)error_msg);
|
||||
}
|
||||
}
|
||||
869
experimental/facho-signer/src/xmlsec1/errors_helpers.h
Normal file
869
experimental/facho-signer/src/xmlsec1/errors_helpers.h
Normal file
@@ -0,0 +1,869 @@
|
||||
/*
|
||||
* XML Security Library (http://www.aleksey.com/xmlsec).
|
||||
*
|
||||
* Internal header only used during the compilation,
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __XMLSEC_ERROR_HELPERS_H__
|
||||
#define __XMLSEC_ERROR_HELPERS_H__
|
||||
|
||||
#include <errno.h>
|
||||
#include <xmlsec/errors.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**********************************************************************
|
||||
*
|
||||
* Error handling macros.
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
/**
|
||||
* xmlSecInternalError:
|
||||
* @errorFunction: the failed function name.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting internal XMLSec errors.
|
||||
*/
|
||||
#define xmlSecInternalError(errorFunction, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
(errorFunction), \
|
||||
XMLSEC_ERRORS_R_XMLSEC_FAILED, \
|
||||
XMLSEC_ERRORS_NO_MESSAGE \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInternalError2:
|
||||
* @errorFunction: the failed function name.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
* @msg: the extra message.
|
||||
* @param: the extra message param.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting internal XMLSec errors.
|
||||
*/
|
||||
#define xmlSecInternalError2(errorFunction, errorObject, msg, param) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
(errorFunction), \
|
||||
XMLSEC_ERRORS_R_XMLSEC_FAILED, \
|
||||
(msg), (param) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInternalError3:
|
||||
* @errorFunction: the failed function name.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
* @msg: the extra message.
|
||||
* @param1: the extra message param1.
|
||||
* @param2: the extra message param2.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting internal XMLSec errors.
|
||||
*/
|
||||
#define xmlSecInternalError3(errorFunction, errorObject, msg, param1, param2) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
(errorFunction), \
|
||||
XMLSEC_ERRORS_R_XMLSEC_FAILED, \
|
||||
(msg), (param1), (param2) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInternalError4:
|
||||
* @errorFunction: the failed function name.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
* @msg: the extra message.
|
||||
* @param1: the extra message param1.
|
||||
* @param2: the extra message param2.
|
||||
* @param3: the extra message param3.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting internal XMLSec errors.
|
||||
*/
|
||||
#define xmlSecInternalError4(errorFunction, errorObject, msg, param1, param2, param3) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
(errorFunction), \
|
||||
XMLSEC_ERRORS_R_XMLSEC_FAILED, \
|
||||
(msg), (param1), (param2), (param3) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecMallocError:
|
||||
* @allocSize: the failed allocation size.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting xmlMalloc() errors.
|
||||
*/
|
||||
#define xmlSecMallocError(allocSize, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
"xmlMalloc", \
|
||||
XMLSEC_ERRORS_R_MALLOC_FAILED, \
|
||||
"size=%lu", (unsigned long)(allocSize) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecStrdupError:
|
||||
* @str: the failed string.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting xmlStrdup() errors.
|
||||
*/
|
||||
#define xmlSecStrdupError(str, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
"xmlStrdup", \
|
||||
XMLSEC_ERRORS_R_STRDUP_FAILED, \
|
||||
"size=%lu", (unsigned long)xmlStrlen(str) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecXmlError:
|
||||
* @errorFunction: the failed function.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting generic XML errors.
|
||||
*/
|
||||
#define xmlSecXmlError(errorFunction, errorObject) \
|
||||
{ \
|
||||
xmlErrorPtr error = xmlGetLastError(); \
|
||||
int code = (error != NULL) ? error->code : 0; \
|
||||
const char* message = (error != NULL) ? error->message : NULL; \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
(errorFunction), \
|
||||
XMLSEC_ERRORS_R_XML_FAILED, \
|
||||
"xml error: %lu: %s", \
|
||||
(unsigned long)code, \
|
||||
xmlSecErrorsSafeString(message) \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecXmlError2:
|
||||
* @errorFunction: the failed function.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
* @msg: the extra message.
|
||||
* @param: the extra message param.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting generic XML errors.
|
||||
*/
|
||||
#define xmlSecXmlError2(errorFunction, errorObject, msg, param) \
|
||||
{ \
|
||||
xmlErrorPtr error = xmlGetLastError(); \
|
||||
int code = (error != NULL) ? error->code : 0; \
|
||||
const char* message = (error != NULL) ? error->message : NULL; \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
(errorFunction), \
|
||||
XMLSEC_ERRORS_R_XML_FAILED, \
|
||||
msg "; xml error: %lu: %s", \
|
||||
(param), \
|
||||
(unsigned long)code, \
|
||||
xmlSecErrorsSafeString(message) \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecXmlParserError:
|
||||
* @errorFunction: the failed function.
|
||||
* @ctxt: the parser context.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting XML parser errors.
|
||||
*/
|
||||
#define xmlSecXmlParserError(errorFunction, ctxt, errorObject) \
|
||||
{ \
|
||||
xmlErrorPtr error = xmlCtxtGetLastError(ctxt);\
|
||||
int code = (error != NULL) ? error->code : 0; \
|
||||
const char* message = (error != NULL) ? error->message : NULL; \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
(errorFunction), \
|
||||
XMLSEC_ERRORS_R_XML_FAILED, \
|
||||
"xml error: %lu: %s", \
|
||||
(unsigned long)code, \
|
||||
xmlSecErrorsSafeString(message) \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecXmlParserError2:
|
||||
* @errorFunction: the failed function.
|
||||
* @ctxt: the parser context.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
* @msg: the extra message.
|
||||
* @param: the extra message param.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting XML parser errors.
|
||||
*/
|
||||
#define xmlSecXmlParserError2(errorFunction, ctxt, errorObject, msg, param) \
|
||||
{ \
|
||||
xmlErrorPtr error = xmlCtxtGetLastError(ctxt);\
|
||||
int code = (error != NULL) ? error->code : 0; \
|
||||
const char* message = (error != NULL) ? error->message : NULL; \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
(errorFunction), \
|
||||
XMLSEC_ERRORS_R_XML_FAILED, \
|
||||
msg "; xml error: %lu: %s", \
|
||||
(param), \
|
||||
(unsigned long)code, \
|
||||
xmlSecErrorsSafeString(message) \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecXsltError:
|
||||
* @errorFunction: the failed function.
|
||||
* @ctxt: the parser context.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting XSLT errors.
|
||||
*/
|
||||
#define xmlSecXsltError(errorFunction, ctxt, errorObject) \
|
||||
{ \
|
||||
xmlErrorPtr error = xmlGetLastError(); \
|
||||
int code = (error != NULL) ? error->code : 0; \
|
||||
const char* message = (error != NULL) ? error->message : NULL; \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
(errorFunction), \
|
||||
XMLSEC_ERRORS_R_XSLT_FAILED, \
|
||||
"xslt error: %lu: %s", \
|
||||
(unsigned long)code, \
|
||||
xmlSecErrorsSafeString(message) \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecIOError:
|
||||
* @errorFunction: the failed function.
|
||||
* @name: the filename, function name, uri, etc.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting IO errors.
|
||||
*/
|
||||
#define xmlSecIOError(errorFunction, name, errorObject) \
|
||||
{ \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
(errorFunction), \
|
||||
XMLSEC_ERRORS_R_IO_FAILED, \
|
||||
"name=\"%s\"; errno=%d", \
|
||||
xmlSecErrorsSafeString(name), \
|
||||
errno \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecNotImplementedError:
|
||||
* @details: the additional details.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "not implemented" errors.
|
||||
*/
|
||||
#define xmlSecNotImplementedError(details) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
NULL, \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_NOT_IMPLEMENTED, \
|
||||
"details=%s", \
|
||||
xmlSecErrorsSafeString(details) \
|
||||
)
|
||||
/**
|
||||
* xmlSecInvalidSizeError:
|
||||
* @name: the name of the variable, parameter, etc.
|
||||
* @actual: the actual value.
|
||||
* @expected: the expected value.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid size" errors when
|
||||
* we expect exact match.
|
||||
*/
|
||||
#define xmlSecInvalidSizeError(name, actual, expected, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_SIZE, \
|
||||
"invalid size for '%s': actual=%lu is not equal to expected=%lu", \
|
||||
xmlSecErrorsSafeString(name), \
|
||||
(unsigned long)(actual), \
|
||||
(unsigned long)(expected) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInvalidSizeLessThanError:
|
||||
* @name: the name of the variable, parameter, etc.
|
||||
* @actual: the actual value.
|
||||
* @expected: the expected value.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid size" errors when
|
||||
* we expect at least the expected size.
|
||||
*/
|
||||
#define xmlSecInvalidSizeLessThanError(name, actual, expected, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_SIZE, \
|
||||
"invalid size for '%s': actual=%lu is less than expected=%lu", \
|
||||
xmlSecErrorsSafeString(name), \
|
||||
(unsigned long)(actual), \
|
||||
(unsigned long)(expected) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInvalidSizeMoreThanError:
|
||||
* @name: the name of the variable, parameter, etc.
|
||||
* @actual: the actual value.
|
||||
* @expected: the expected value.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid size" errors when
|
||||
* we expect at most the expected size.
|
||||
*/
|
||||
#define xmlSecInvalidSizeMoreThanError(name, actual, expected, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_NOT_IMPLEMENTED, \
|
||||
"invalid size for '%s': actual=%lu is more than expected=%lu", \
|
||||
xmlSecErrorsSafeString(name), \
|
||||
(unsigned long)(actual), \
|
||||
(unsigned long)(expected) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInvalidSizeNotMultipleOfError:
|
||||
* @name: the name of the variable, parameter, etc.
|
||||
* @actual: the actual value.
|
||||
* @divider: the expected divider.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid size" errors when
|
||||
* we expect the size to be a multiple of the divider.
|
||||
*/
|
||||
#define xmlSecInvalidSizeNotMultipleOfError(name, actual, divider, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_NOT_IMPLEMENTED, \
|
||||
"invalid size for '%s': actual=%lu is not a multiple of %lu", \
|
||||
xmlSecErrorsSafeString(name), \
|
||||
(unsigned long)(actual), \
|
||||
(unsigned long)(divider) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInvalidSizeOtherError:
|
||||
* @msg: the message about the error.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid size" errors when
|
||||
* we expect exact match.
|
||||
*/
|
||||
#define xmlSecInvalidSizeOtherError(msg, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_SIZE, \
|
||||
"invalid size: %s", \
|
||||
xmlSecErrorsSafeString(msg) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInvalidDataError:
|
||||
* @msg: the msg with explanation.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid data" errors.
|
||||
*/
|
||||
#define xmlSecInvalidDataError(msg, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_DATA, \
|
||||
"%s", \
|
||||
xmlSecErrorsSafeString(msg) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInvalidStringDataError:
|
||||
* @name: the name of the variable, parameter, etc.
|
||||
* @actual: the actual value as a string.
|
||||
* @expected: the expected value(s) as a string.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid data" errors for string.
|
||||
*/
|
||||
#define xmlSecInvalidStringDataError(name, actual, expected, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_DATA, \
|
||||
"invalid data for '%s': actual='%s' and expected %s", \
|
||||
xmlSecErrorsSafeString(name), \
|
||||
xmlSecErrorsSafeString(actual), \
|
||||
(expected) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInvalidIntegerDataError:
|
||||
* @name: the name of the variable, parameter, etc.
|
||||
* @actual: the actual value as an integer.
|
||||
* @expected: the expected value(s) as a string.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid data" errors for integers.
|
||||
*/
|
||||
#define xmlSecInvalidIntegerDataError(name, actual, expected, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_DATA, \
|
||||
"invalid data for '%s': actual=%ld and expected %s", \
|
||||
xmlSecErrorsSafeString(name), \
|
||||
(unsigned long)(actual), \
|
||||
(expected) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInvalidIntegerDataError2:
|
||||
* @name1: the name of the first variable, parameter, etc.
|
||||
* @actual1: the actual first value as an integer.
|
||||
* @name2: the name of the second variable, parameter, etc.
|
||||
* @actual2: the actual second value as an integer.
|
||||
* @expected: the expected value(s) as a string.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid data" errors for integers.
|
||||
*/
|
||||
#define xmlSecInvalidIntegerDataError2(name1, actual1, name2, actual2, expected, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_DATA, \
|
||||
"invalid data: actual value '%s'=%ld, actual value '%s'=%ld and expected %s", \
|
||||
xmlSecErrorsSafeString(name1), \
|
||||
(unsigned long)(actual1), \
|
||||
xmlSecErrorsSafeString(name2), \
|
||||
(unsigned long)(actual2), \
|
||||
(expected) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInvalidTypeError:
|
||||
* @msg: the msg with explanation.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid type" errors.
|
||||
*/
|
||||
#define xmlSecInvalidTypeError(msg, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_TYPE, \
|
||||
"%s", \
|
||||
xmlSecErrorsSafeString(msg) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInvalidStringTypeError:
|
||||
* @name: the name of the variable, parameter, etc.
|
||||
* @actual: the actual value as a string.
|
||||
* @expected: the expected value(s) as a string.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid type" errors for string.
|
||||
*/
|
||||
#define xmlSecInvalidStringTypeError(name, actual, expected, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_TYPE, \
|
||||
"invalid type for '%s': actual='%s' and expected %s", \
|
||||
xmlSecErrorsSafeString(name), \
|
||||
xmlSecErrorsSafeString(actual), \
|
||||
(expected) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInvalidIntegerTypeError:
|
||||
* @name: the name of the variable, parameter, etc.
|
||||
* @actual: the actual value as an integer.
|
||||
* @expected: the expected value(s) as a string.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid type" errors for integers.
|
||||
*/
|
||||
#define xmlSecInvalidIntegerTypeError(name, actual, expected, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_TYPE, \
|
||||
"invalid type for '%s': actual=%ld and expected %s", \
|
||||
xmlSecErrorsSafeString(name), \
|
||||
(unsigned long)(actual), \
|
||||
(expected) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInvalidIntegerTypeError2:
|
||||
* @name1: the name of the first variable, parameter, etc.
|
||||
* @actual1: the actual first value as an integer.
|
||||
* @name2: the name of the second variable, parameter, etc.
|
||||
* @actual2: the actual second value as an integer.
|
||||
* @expected: the expected value(s) as a string.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid type" errors for integers.
|
||||
*/
|
||||
#define xmlSecInvalidIntegerTypeError2(name1, actual1, name2, actual2, expected, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_TYPE, \
|
||||
"invalid type: actual value '%s'=%ld, actual value '%s'=%ld and expected %s", \
|
||||
xmlSecErrorsSafeString(name1), \
|
||||
(unsigned long)(actual1), \
|
||||
xmlSecErrorsSafeString(name2), \
|
||||
(unsigned long)(actual2), \
|
||||
(expected) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInvalidNodeError:
|
||||
* @actualNode: the actual node.
|
||||
* @expectedNodeName: the expected node name.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting an invalid node errors.
|
||||
*/
|
||||
#define xmlSecInvalidNodeError(actualNode, expectedNodeName, errorObject) \
|
||||
{ \
|
||||
const char* actualNodeName = xmlSecNodeGetName(actualNode); \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_NODE, \
|
||||
"actual=%s; expected=%s", \
|
||||
xmlSecErrorsSafeString(actualNodeName), \
|
||||
xmlSecErrorsSafeString(expectedNodeName) \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecInvalidNodeContentError:
|
||||
* @node: the node.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
* @reason: the reason why node content is invalid.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting an invalid node content errors.
|
||||
*/
|
||||
#define xmlSecInvalidNodeContentError(node, errorObject, reason) \
|
||||
{ \
|
||||
const char* nName = xmlSecNodeGetName(node); \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_NODE_CONTENT, \
|
||||
"node=%s; reason=%s", \
|
||||
xmlSecErrorsSafeString(nName), \
|
||||
xmlSecErrorsSafeString(reason) \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecInvalidNodeAttributeError:
|
||||
* @node: the node.
|
||||
* @attrName: the attribute name.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
* @reason: the reason why node content is invalid.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting an invalid node attribute errors.
|
||||
*/
|
||||
#define xmlSecInvalidNodeAttributeError(node, attrName, errorObject, reason) \
|
||||
{ \
|
||||
const char* nName = xmlSecNodeGetName(node); \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_NODE_ATTRIBUTE, \
|
||||
"node=%s; attribute=%s; reason=%s",\
|
||||
xmlSecErrorsSafeString(nName), \
|
||||
xmlSecErrorsSafeString(attrName), \
|
||||
xmlSecErrorsSafeString(reason) \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecNodeAlreadyPresentError:
|
||||
* @parent: the parent node.
|
||||
* @nodeName: the node name.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting node already present errors.
|
||||
*/
|
||||
#define xmlSecNodeAlreadyPresentError(parent, nodeName, errorObject) \
|
||||
{ \
|
||||
const char* pName = xmlSecNodeGetName(parent);\
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_NODE_ALREADY_PRESENT, \
|
||||
"parent=%s; node=%s", \
|
||||
xmlSecErrorsSafeString(pName), \
|
||||
xmlSecErrorsSafeString(nodeName) \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecUnexpectedNodeError:
|
||||
* @node: the node.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting an invalid node errors.
|
||||
*/
|
||||
#define xmlSecUnexpectedNodeError(node, errorObject) \
|
||||
{ \
|
||||
const char* nName = xmlSecNodeGetName(node); \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_UNEXPECTED_NODE, \
|
||||
"node=%s", \
|
||||
xmlSecErrorsSafeString(nName) \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecNodeNotFoundError:
|
||||
* @errorFunction: the failed function.
|
||||
* @startNode: the search start node.
|
||||
* @targetNodeName: the expected child node name.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting node not found errors.
|
||||
*/
|
||||
#define xmlSecNodeNotFoundError(errorFunction, startNode, targetNodeName, errorObject) \
|
||||
{ \
|
||||
const char* startNodeName = xmlSecNodeGetName(startNode); \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
(errorFunction), \
|
||||
XMLSEC_ERRORS_R_NODE_NOT_FOUND, \
|
||||
"startNode=%s; target=%s", \
|
||||
xmlSecErrorsSafeString(startNodeName), \
|
||||
xmlSecErrorsSafeString(targetNodeName) \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecInvalidTransfromError:
|
||||
* @transform: the transform.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting an invalid transform errors.
|
||||
*/
|
||||
#define xmlSecInvalidTransfromError(transform) \
|
||||
{ \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)xmlSecTransformGetName(transform), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_TRANSFORM, \
|
||||
XMLSEC_ERRORS_NO_MESSAGE \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecInvalidTransfromError2:
|
||||
* @transform: the transform.
|
||||
* @msg: the extra message.
|
||||
* @param: the extra message param.
|
||||
*
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting an invalid transform errors.
|
||||
*/
|
||||
#define xmlSecInvalidTransfromError2(transform, msg, param) \
|
||||
{ \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)xmlSecTransformGetName(transform), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_TRANSFORM, \
|
||||
(msg), (param) \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecInvalidTransfromStatusError:
|
||||
* @transform: the transform.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting an invalid transform status errors.
|
||||
*/
|
||||
#define xmlSecInvalidTransfromStatusError(transform) \
|
||||
{ \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)xmlSecTransformGetName(transform), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_STATUS, \
|
||||
"transformStatus=%d", \
|
||||
(int)((transform)->status) \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecInvalidTransfromStatusError2:
|
||||
* @transform: the transform.
|
||||
* @msg: the extra message.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting an invalid transform status errors.
|
||||
*/
|
||||
#define xmlSecInvalidTransfromStatusError2(transform, msg) \
|
||||
{ \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)xmlSecTransformGetName(transform), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_STATUS, \
|
||||
"transformStatus=%ld, msg=%s", \
|
||||
(long int)((transform)->status), \
|
||||
msg \
|
||||
); \
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlSecInvalidKeyDataSizeError:
|
||||
* @name: the name of the variable, parameter, etc.
|
||||
* @actual: the actual value.
|
||||
* @expected: the expected value(s).
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid keydata size" errors.
|
||||
*/
|
||||
#define xmlSecInvalidKeyDataSizeError(actual, expected, errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_KEY_DATA_SIZE, \
|
||||
"invalid key data size: actual=%ld and expected=%ld", \
|
||||
(unsigned long)(actual), \
|
||||
(unsigned long)(expected) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecInvalidZeroKeyDataSizeError:
|
||||
* @name: the name of the variable, parameter, etc.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting "invalid keydata size" errors.
|
||||
*/
|
||||
#define xmlSecInvalidZeroKeyDataSizeError(errorObject) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
XMLSEC_ERRORS_R_INVALID_KEY_DATA_SIZE, \
|
||||
"invalid zero key data size" \
|
||||
)
|
||||
|
||||
|
||||
/**
|
||||
* xmlSecOtherError:
|
||||
* @code: the error code.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
* @details: the error message.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting other XMLSec errors.
|
||||
*/
|
||||
#define xmlSecOtherError(code, errorObject, details) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
(code), \
|
||||
"details=%s", \
|
||||
xmlSecErrorsSafeString(details) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecOtherError2:
|
||||
* @code: the error code.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
* @msg: the extra message.
|
||||
* @param: the extra message param.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting other XMLSec errors.
|
||||
*/
|
||||
#define xmlSecOtherError2(code, errorObject, msg, param) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
(code), \
|
||||
(msg), (param) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecOtherError3:
|
||||
* @code: the error code.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
* @msg: the extra message.
|
||||
* @param1: the extra message param.
|
||||
* @param2: the extra message param.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting other XMLSec errors.
|
||||
*/
|
||||
#define xmlSecOtherError3(code, errorObject, msg, param1, param2) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
(code), \
|
||||
(msg), (param1), (param2) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecOtherError4:
|
||||
* @code: the error code.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
* @msg: the extra message.
|
||||
* @param1: the extra message param.
|
||||
* @param2: the extra message param.
|
||||
* @param3: the extra message param.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting other XMLSec errors.
|
||||
*/
|
||||
#define xmlSecOtherError4(code, errorObject, msg, param1, param2, param3) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
(code), \
|
||||
(msg), (param1), (param2), (param3) \
|
||||
)
|
||||
|
||||
/**
|
||||
* xmlSecOtherError5:
|
||||
* @code: the error code.
|
||||
* @errorObject: the error specific error object (e.g. transform, key data, etc).
|
||||
* @msg: the extra message.
|
||||
* @param1: the extra message param.
|
||||
* @param2: the extra message param.
|
||||
* @param3: the extra message param.
|
||||
* @param4: the extra message param.
|
||||
*
|
||||
* Macro. The XMLSec library macro for reporting other XMLSec errors.
|
||||
*/
|
||||
#define xmlSecOtherError5(code, errorObject, msg, param1, param2, param3, param4) \
|
||||
xmlSecError(XMLSEC_ERRORS_HERE, \
|
||||
(const char*)(errorObject), \
|
||||
NULL, \
|
||||
(code), \
|
||||
(msg), (param1), (param2), (param3), (param4) \
|
||||
)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __XMLSEC_ERROR_HELPERS_H__ */
|
||||
1950
experimental/facho-signer/src/xmlsec1/xmltree.c
Normal file
1950
experimental/facho-signer/src/xmlsec1/xmltree.c
Normal file
File diff suppressed because it is too large
Load Diff
200
experimental/facho-signer/src/xmlusigned.xml
Normal file
200
experimental/facho-signer/src/xmlusigned.xml
Normal file
@@ -0,0 +1,200 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Invoice xmlns="http://www.dian.gov.co/contratos/facturaelectronica/v1" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:cdt="urn:DocumentInformation:names:specification:ubl:colombia:schema:xsd:DocumentInformationAggregateComponents-1" xmlns:clm54217="urn:un:unece:uncefact:codelist:specification:54217:2001" xmlns:clmIANAMIMEMediaType="urn:un:unece:uncefact:codelist:specification:IANAMIMEMediaType:2003" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2" xmlns:sts="http://www.dian.gov.co/contratos/facturaelectronica/v1/Structures" xmlns:udt="urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xades="http://uri.etsi.org/01903/v1.3.2#" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:sig="http://www.w3.org/2000/09/xmldsig#">
|
||||
<ext:UBLExtensions>
|
||||
<ext:UBLExtension>
|
||||
<ext:ExtensionContent>
|
||||
<sts:DianExtensions>
|
||||
<sts:SoftwareSecurityCode schemeAgencyName="CO, DIAN (Dirección de Impuestos y Aduanas Nacionales)" schemeAgencyID="195">2bd9a18f23cf1188d36888d218e9b0c31df77aa00bc036eaeaa1619184054237eee56d2d8db4ecab0173f65f8dab7753</sts:SoftwareSecurityCode>
|
||||
<sts:AuthorizationProvider>
|
||||
<sts:AuthorizationProviderID schemeID="4" schemeName="31" schemeAgencyName="CO, DIAN (Dirección de Impuestos y Aduanas Nacionales)" schemeAgencyID="195">800197268</sts:AuthorizationProviderID>
|
||||
</sts:AuthorizationProvider>
|
||||
<sts:SoftwareProvider>
|
||||
<sts:ProviderID schemeAgencyName="CO, DIAN (Dirección de Impuestos y Aduanas Nacionales)" schemeAgencyID="195" schemeID="5" schemaName="31">900579212</sts:ProviderID>
|
||||
<sts:SoftwareID schemeAgencyName="CO, DIAN (Dirección de Impuestos y Aduanas Nacionales)" schemeAgencyID="195">01ab9caa-6838-461e-82fb-da44da36a084</sts:SoftwareID>
|
||||
</sts:SoftwareProvider>
|
||||
<sts:InvoiceSource>
|
||||
<cbc:IdentificationCode>CO</cbc:IdentificationCode>
|
||||
</sts:InvoiceSource>
|
||||
<sts:InvoiceControl>
|
||||
<sts:InvoiceAuthorization>fc8eac422eba16e22ffd8c6f94b3f40a6e38162c</sts:InvoiceAuthorization>
|
||||
<sts:AuthorizationPeriod>
|
||||
<cbc:StartDate>2019-01-19</cbc:StartDate>
|
||||
<cbc:EndDate>2030-01-19</cbc:EndDate>
|
||||
</sts:AuthorizationPeriod>
|
||||
<sts:AuthorizedInvoices>
|
||||
<sts:Prefix>SETP</sts:Prefix>
|
||||
<sts:From>990000000</sts:From>
|
||||
<sts:To>995000000</sts:To>
|
||||
</sts:AuthorizedInvoices>
|
||||
</sts:InvoiceControl>
|
||||
</sts:DianExtensions>
|
||||
</ext:ExtensionContent>
|
||||
</ext:UBLExtension>
|
||||
</ext:UBLExtensions>
|
||||
<cbc:UBLVersionID>UBL 2.1</cbc:UBLVersionID>
|
||||
<cbc:CustomizationID>10</cbc:CustomizationID>
|
||||
<cbc:ProfileID>DIAN 2.1</cbc:ProfileID>
|
||||
<cbc:ProfileExecutionID>2</cbc:ProfileExecutionID>
|
||||
<cbc:ID>SETP990000001</cbc:ID>
|
||||
<cbc:UUID schemeID="2" schemeName="CUFE-SHA384">50578625ce1fb2f6bb2bc57b22180d2763c8a868c4e62da72e0e43001f9c7f3459c81e2bf9324830175b1225af37e435</cbc:UUID>
|
||||
<cbc:DocumentCurrencyCode>COP</cbc:DocumentCurrencyCode>
|
||||
<cbc:IssueDate>2020-09-05</cbc:IssueDate>
|
||||
<cbc:IssueTime>22:38:53-05:00</cbc:IssueTime>
|
||||
<cbc:InvoiceTypeCode listAgencyID="195" listAgencyName="No matching global declaration available for the validation root" listURI="http://www.dian.gov.co">01</cbc:InvoiceTypeCode>
|
||||
<cbc:LineCountNumeric>1</cbc:LineCountNumeric>
|
||||
<cac:InvoicePeriod>
|
||||
<cbc:StartDate>2020-09-05</cbc:StartDate>
|
||||
<cbc:EndDate>2020-09-05</cbc:EndDate>
|
||||
</cac:InvoicePeriod>
|
||||
<cac:AccountingSupplierParty>
|
||||
<cbc:AdditionalAccountID>1</cbc:AdditionalAccountID>
|
||||
<cac:Party>
|
||||
<cac:PartyName>
|
||||
<cbc:Name>NEUROTEC TECNOLOGIA S.A.S</cbc:Name>
|
||||
</cac:PartyName>
|
||||
<cac:PhysicalLocation>
|
||||
<cac:Address>
|
||||
<cac:AddressLine>
|
||||
<cbc:Line/>
|
||||
</cac:AddressLine>
|
||||
</cac:Address>
|
||||
</cac:PhysicalLocation>
|
||||
<cac:PartyLegalEntity>
|
||||
<cbc:CompanyID schemeAgencyName="CO, DIAN (Dirección de Impuestos y Aduanas Nacionales)" schemeAgencyID="195" schemeID="5" schemeName="31">900579212</cbc:CompanyID>
|
||||
<cbc:RegistrationName>NEUROTEC TECNOLOGIA S.A.S</cbc:RegistrationName>
|
||||
<cac:RegistrationAddress>
|
||||
<cbc:CityName/>
|
||||
<cac:AddressLine>
|
||||
<cbc:Line/>
|
||||
</cac:AddressLine>
|
||||
<cac:Country>
|
||||
<cbc:IdentificationCode>CO</cbc:IdentificationCode>
|
||||
<cbc:Name>COLOMBIA</cbc:Name>
|
||||
</cac:Country>
|
||||
</cac:RegistrationAddress>
|
||||
</cac:PartyLegalEntity>
|
||||
<cac:PartyTaxScheme>
|
||||
<cbc:RegistrationName>NEUROTEC TECNOLOGIA S.A.S</cbc:RegistrationName>
|
||||
<cbc:CompanyID schemeAgencyName="CO, DIAN (Dirección de Impuestos y Aduanas Nacionales)" schemeAgencyID="195" schemeID="5" schemeName="31">900579212</cbc:CompanyID>
|
||||
<cbc:TaxLevelCode listName="48">O-07;O-09;O-14;O-48</cbc:TaxLevelCode>
|
||||
<cac:TaxScheme/>
|
||||
</cac:PartyTaxScheme>
|
||||
<cac:Contact>
|
||||
<cbc:ElectronicMail>sdds@sd.com</cbc:ElectronicMail>
|
||||
</cac:Contact>
|
||||
</cac:Party>
|
||||
</cac:AccountingSupplierParty>
|
||||
<cac:AccountingCustomerParty>
|
||||
<cbc:AdditionalAccountID>2</cbc:AdditionalAccountID>
|
||||
<cac:Party>
|
||||
<cac:PartyName>
|
||||
<cbc:Name>facho-customer</cbc:Name>
|
||||
</cac:PartyName>
|
||||
<cac:PhysicalLocation>
|
||||
<cac:Address>
|
||||
<cac:AddressLine>
|
||||
<cbc:Line/>
|
||||
</cac:AddressLine>
|
||||
</cac:Address>
|
||||
</cac:PhysicalLocation>
|
||||
<cac:PartyTaxScheme>
|
||||
<cbc:CompanyID schemeAgencyName="CO, DIAN (Dirección de Impuestos y Aduanas Nacionales)" schemeAgencyID="195" schemeID="" schemeName="13">43851425</cbc:CompanyID>
|
||||
<cbc:RegistrationName>facho-customer</cbc:RegistrationName>
|
||||
<cbc:TaxLevelCode>ZZ</cbc:TaxLevelCode>
|
||||
<cac:TaxScheme/>
|
||||
</cac:PartyTaxScheme>
|
||||
<cac:PartyLegalEntity>
|
||||
<cbc:RegistrationName>facho-customer</cbc:RegistrationName>
|
||||
<cac:RegistrationAddress>
|
||||
<cbc:CityName/>
|
||||
<cac:AddressLine>
|
||||
<cbc:Line/>
|
||||
</cac:AddressLine>
|
||||
<cac:Country>
|
||||
<cbc:IdentificationCode>CO</cbc:IdentificationCode>
|
||||
<cbc:Name>COLOMBIA</cbc:Name>
|
||||
</cac:Country>
|
||||
</cac:RegistrationAddress>
|
||||
</cac:PartyLegalEntity>
|
||||
</cac:Party>
|
||||
</cac:AccountingCustomerParty>
|
||||
<cac:LegalMonetaryTotal>
|
||||
<cbc:LineExtensionAmount currencyID="COP">100.00</cbc:LineExtensionAmount>
|
||||
<cbc:TaxExclusiveAmount currencyID="COP">100.00</cbc:TaxExclusiveAmount>
|
||||
<cbc:TaxInclusiveAmount currencyID="COP">119.00</cbc:TaxInclusiveAmount>
|
||||
<cbc:ChargeTotalAmount currencyID="COP">19.00</cbc:ChargeTotalAmount>
|
||||
<cbc:PayableAmount currencyID="COP">119.00</cbc:PayableAmount>
|
||||
</cac:LegalMonetaryTotal>
|
||||
<cac:TaxTotal/>
|
||||
<cac:TaxTotal>
|
||||
<cac:TaxSubtotal>
|
||||
<cac:TaxCategory>
|
||||
<cac:TaxScheme>
|
||||
<cbc:ID>01</cbc:ID>
|
||||
</cac:TaxScheme>
|
||||
</cac:TaxCategory>
|
||||
</cac:TaxSubtotal>
|
||||
<cbc:TaxAmount>19.00</cbc:TaxAmount>
|
||||
</cac:TaxTotal>
|
||||
<cac:TaxTotal>
|
||||
<cac:TaxSubtotal>
|
||||
<cac:TaxCategory>
|
||||
<cac:TaxScheme>
|
||||
<cbc:ID>04</cbc:ID>
|
||||
</cac:TaxScheme>
|
||||
</cac:TaxCategory>
|
||||
</cac:TaxSubtotal>
|
||||
<cbc:TaxAmount>0.00</cbc:TaxAmount>
|
||||
</cac:TaxTotal>
|
||||
<cac:TaxTotal>
|
||||
<cac:TaxSubtotal>
|
||||
<cac:TaxCategory>
|
||||
<cac:TaxScheme>
|
||||
<cbc:ID>03</cbc:ID>
|
||||
</cac:TaxScheme>
|
||||
</cac:TaxCategory>
|
||||
</cac:TaxSubtotal>
|
||||
<cbc:TaxAmount>0.00</cbc:TaxAmount>
|
||||
</cac:TaxTotal>
|
||||
<cac:InvoiceLine>
|
||||
<cbc:ID>1</cbc:ID>
|
||||
<cbc:InvoicedQuantity unitCode="NAR">1</cbc:InvoicedQuantity>
|
||||
<cbc:LineExtensionAmount currencyID="COP">100.0</cbc:LineExtensionAmount>
|
||||
<cac:TaxTotal>
|
||||
<cbc:TaxAmount currencyID="COP">19.0</cbc:TaxAmount>
|
||||
<cac:TaxSubtotal>
|
||||
<cbc:TaxableAmount currencyID="COP">100.0</cbc:TaxableAmount>
|
||||
<cbc:TaxAmount currencyID="COP">19.0</cbc:TaxAmount>
|
||||
<cac:TaxCategory>
|
||||
<cbc:Percent>19.0</cbc:Percent>
|
||||
<cac:TaxScheme>
|
||||
<cbc:ID>01</cbc:ID>
|
||||
<cbc:Name>IVA</cbc:Name>
|
||||
</cac:TaxScheme>
|
||||
</cac:TaxCategory>
|
||||
</cac:TaxSubtotal>
|
||||
</cac:TaxTotal>
|
||||
<cac:PricingReference>
|
||||
<cac:AlternativeConditionPrice>
|
||||
<cbc:PriceAmount currencyID="COP">100.0</cbc:PriceAmount>
|
||||
<cbc:PriceTypeCode>01</cbc:PriceTypeCode>
|
||||
<cbc:PriceType>x</cbc:PriceType>
|
||||
</cac:AlternativeConditionPrice>
|
||||
</cac:PricingReference>
|
||||
<cac:Item>
|
||||
<cbc:Description>test</cbc:Description>
|
||||
<cac:StandardItemIdentification>
|
||||
<cbc:ID>9999</cbc:ID>
|
||||
</cac:StandardItemIdentification>
|
||||
</cac:Item>
|
||||
<cac:Price>
|
||||
<cbc:PriceAmount currencyID="COP">100.0</cbc:PriceAmount>
|
||||
</cac:Price>
|
||||
</cac:InvoiceLine>
|
||||
<cac:PaymentMeans>
|
||||
<cbc:ID>1</cbc:ID>
|
||||
<cbc:PaymentMeansCode>10</cbc:PaymentMeansCode>
|
||||
<cbc:PaymentDueDate>2020-09-05</cbc:PaymentDueDate>
|
||||
<cbc:PaymentID>1</cbc:PaymentID>
|
||||
</cac:PaymentMeans>
|
||||
</Invoice>
|
||||
Reference in New Issue
Block a user