35 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_MIDDLE_MIX
75 if(in == NULL || inlen < 1 || out == NULL || outlen == NULL)
81 DOMElement* root = doc->getDocumentElement();
91 CAMsg::printMsg(LOG_ERR,
"Trying to sign a document with no signature-keys set!");
96 XERCES_CPP_NAMESPACE::DOMDocument* doc = NULL;
97 DOMNode* elemRoot = NULL;
98 if(node->getNodeType() == DOMNode::DOCUMENT_NODE)
100 doc = (XERCES_CPP_NAMESPACE::DOMDocument*)node;
101 elemRoot = doc->getDocumentElement();
106 doc = node->getOwnerDocument();
110 DOMNode* tmpSignature = NULL;
113 DOMNode* n = elemRoot->removeChild(tmpSignature);
123 if(canonicalBuff == NULL)
127 UINT8 dgst[SHA_DIGEST_LENGTH];
128 SHA1(canonicalBuff,
len, dgst);
129 delete[] canonicalBuff;
130 canonicalBuff = NULL;
132 UINT8 digestValue[512];
146 DOMElement* elemCanonicalizationMethod =
createDOMElement(doc,
"CanonicalizationMethod");
149 elemReference->setAttribute(XMLString::transcode(
"URI"), XMLString::transcode(
""));
160 else if(currentSignature->
pSig->isECDSA())
169 elemSignedInfo->appendChild(elemCanonicalizationMethod);
170 elemSignedInfo->appendChild(elemSignatureMethod);
171 elemSignedInfo->appendChild(elemReference);
172 elemReference->appendChild(elemDigestMethod);
173 elemReference->appendChild(elemDigestValue);
177 if(canonicalBuff==NULL)
185 delete[] canonicalBuff;
186 canonicalBuff = NULL;
189 currentSignature = currentSignature->
next;
197 currentSignature = currentSignature->
next;
206 elemSignature->appendChild(elemSignedInfo);
207 elemSignature->appendChild(elemSignatureValue);
213 DOMElement* tmpElemCerts = NULL;
217 elemKeyInfo->appendChild(tmpElemCerts);
218 elemSignature->appendChild(elemKeyInfo);
221 elemRoot->appendChild(elemSignature);
225 currentSignature = currentSignature->
next;
243 DOMElement* root = doc->getDocumentElement();
266 CAMsg::printMsg(LOG_DEBUG,
"Found %d Signature(s) in XML-Structure\n", signatureElementsCount);
272 bool verified =
false;
274 for(
UINT32 i=0; i<signatureElementsCount; i++)
277 CAMsg::printMsg(LOG_DEBUG,
"Trying to verify signature %d of %d!\n", i+1, signatureElementsCount);
278 DOMNode* elemSignature = signatureElements[i];
280 if(elemSignature == NULL)
285 DOMNode* elemSigInfo;
287 if(elemSigInfo == NULL)
293 DOMNode* elemSigMethod;
296 UINT8 algorithm[255];
299 if(signatureMethod != NULL &&
300 strncmp((
const char*)algorithm, (
const char*)signatureMethod, algLen) !=
E_SUCCESS)
302 CAMsg::printMsg(LOG_DEBUG,
"Did NOT find matching SignatureMethods: %s and %s!\n", signatureMethod, algorithm);
305 DOMNode* elemSigValue;
307 if(elemSigValue == NULL)
312 DOMNode* elemReference;
314 if(elemReference == NULL)
319 DOMNode* elemDigestValue;
321 if(elemDigestValue == NULL)
328 CAMsg::printMsg(LOG_DEBUG,
"Error: could not get digest value from XML\n");
336 if(dgstlen!=SHA_DIGEST_LENGTH)
338 CAMsg::printMsg(LOG_DEBUG,
"Error: digest is %d long, should be %d\n", dgstlen, SHA_DIGEST_LENGTH);
345 CAMsg::printMsg(LOG_DEBUG,
"Error: could not get signature value from XML\n");
350 CAMsg::printMsg(LOG_DEBUG,
"Error: could not decode signature value\n");
354 out =
new UINT8[outlen];
364 CAMsg::printMsg(LOG_WARNING,
"Signature verification not successful!\n");
377 for(
UINT32 i=0; i<signatureElementsCount; i++)
379 removedSignatures[i] = root->removeChild(signatureElements[i]);
380 if(removedSignatures[i] == NULL)
383 CAMsg::printMsg(LOG_ERR,
"Error removing signature-element %d of %d from Root-Node\n", i+1, signatureElementsCount);
391 for(
UINT32 i=0; i<signatureElementsCount; i++)
393 if(removedSignatures[i] != NULL)
395 root->appendChild(removedSignatures[i]);
399 UINT8 newDgst[SHA_DIGEST_LENGTH];
400 SHA1(out, outlen, newDgst);
403 for(
int i=0; i<SHA_DIGEST_LENGTH; i++)
405 if(newDgst[i] != dgst[i])
407 CAMsg::printMsg(LOG_ERR,
"Error checking XML-Signature DigestValue!\n");
428 if(a_signature == NULL || a_certs == NULL || a_ski == NULL || a_skiLen != SHA_DIGEST_LENGTH)
430 for(
SINT32 i=0; i<SHA_DIGEST_LENGTH; i++)
435 newSignature->
pSig = a_signature;
436 newSignature->
pCerts = a_certs;
437 newSignature->
pSKI =
new UINT8[a_skiLen];
438 memcpy(newSignature->
pSKI, a_ski, a_skiLen);
452 #if OPENSSL_VERSION_NUMBER < 0x10100000L
453 UINT8* tmp = (
UINT8*) hex_to_string((
unsigned char*)a_ski, SHA_DIGEST_LENGTH);
455 UINT8* tmp = (
UINT8*) OPENSSL_buf2hexstr((
unsigned char*)a_ski, SHA_DIGEST_LENGTH);
469 #ifndef ONLY_LOCAL_PROXY
483 strncmp((
char*)a_strSKI, (
char*)tmpSKI, strlen((
char*)tmpSKI) ) == 0)
491 strncmp((
char*)a_strSKI, (
char*)tmpSKI, strlen((
char*)tmpSKI) ) == 0)
struct __t_signature SIGNATURE
#define ECDSA_SHA1_REFERENCE
#define DSA_SHA1_REFERENCE
#define RSA_SHA1_REFERENCE
SINT32 setDOMElementAttribute(DOMNode *pElem, const char *attrName, const char *value)
SINT32 getDOMElementValue(const DOMNode *const pElem, UINT8 *value, UINT32 *valuelen)
Returns the content of the text node(s) under elem as null-terminated C String.
SINT32 setDOMElementValue(DOMElement *pElem, SINT32 value)
UINT32 strtrim(UINT8 *s)
Removes leading and ending whitespaces (chars<=32) from a zero terminated string.
XERCES_CPP_NAMESPACE::DOMDocument * parseDOMDocument(const UINT8 *const buff, UINT32 len)
Parses a buffer containing an XML document and returns this document.
DOMElement * createDOMElement(XERCES_CPP_NAMESPACE::DOMDocument *pOwnerDoc, const char *const name)
Creates a new DOMElement with the given name which belongs to the DOMDocument owernDoc.
SINT32 getDOMChildByName(const DOMNode *pNode, const char *const name, DOMElement *&child, bool deep)
SINT32 getDOMElementAttribute(const DOMNode *const elem, const char *attrName, UINT8 *value, UINT32 *len)
SINT32 getSignatureElements(DOMNode *parent, DOMNode **signatureNodes, UINT32 *length)
#define MAX_SIGNATURE_ELEMENTS
static SINT32 encode(const UINT8 *in, UINT32 len, UINT8 *out, UINT32 *outlen)
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...
static SINT32 decode(const UINT8 *in, UINT32 len, UINT8 *out, UINT32 *outlen)
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...
SINT32 encode(UINT8 *buff, UINT32 *bufflen, UINT32 type)
static SINT32 removeColons(const UINT8 *a_cSki, UINT32 a_cSkiLen, UINT8 *&r_ski, UINT32 *r_skiLen)
LERNGRUPPE Removes the colons from the string representation of the given SKI.
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
SINT32 sign(UINT8 *in, UINT32 inlen, UINT8 *sig, UINT32 *siglen)
Method for producing a single Signature for Key Exchange.
virtual ~CAMultiSignature()
SINT32 addSignature(CASignature *a_signature, CACertStore *a_certs, UINT8 *a_ski, UINT32 a_skiLen)
SINT32 getXORofSKIs(UINT8 *out, UINT32 outlen)
SINT32 getSKI(UINT8 *in, UINT32 inlen, const UINT8 *a_ski)
static SINT32 verifyXML(const UINT8 *const in, UINT32 inlen, CACertificate *a_cert)
SINT32 findSKI(const UINT8 *a_strSKI)
SINT32 signXML(DOMNode *a_node, bool appendCerts)
SINT32 verify(const UINT8 *const in, UINT32 inlen, DSA_SIG *const dsaSig) const
UINT8 * getSignatureMethod()
SINT32 getSignatureSize() const
SINT32 setVerifyKey(CACertificate *pCert)
Set the key for signature testing to the one include in pCert.
SINT32 sign(const UINT8 *const in, UINT32 inlen, UINT8 *sig, UINT32 *siglen) const
Perform Signature with either DSA, RSA or ECDSA.
static SINT32 makeCanonical(const DOMNode *node, UINT8 *buff, UINT32 *size)
Dumps the node and all childs in a 'cannonical form' into buff.
static SINT32 dumpToMem(const DOMNode *node, UINT8 *buff, UINT32 *size)
Dumps the node and all childs into buff.
struct __t_signature * next