[xmlsec] Load hmac key for signature

Monica Lau mllau2004 at yahoo.com
Fri Oct 8 17:35:39 PDT 2004


Hi,
 
Thanks so much for your code!  It's very clear now.
 
I modified sign2.c in the examples directory, but it failed to sign the document.  Here are my modifications below:

const xmlSecByte *keybuf = "secret";
xmlSecSize keysize = 6;

/* create signature template for RSA-SHA1 enveloped signature */
signNode = xmlSecTmplSignatureCreate(doc, xmlSecTransformExclC14NId, xmlSecTransformHmacSha1Id, NULL);

dsigCtx->signKey = CreateHmacKey(keybuf, keysize);

/* sign the template */
if(xmlSecDSigCtxSign(dsigCtx, signNode) < 0) {
fprintf(stderr,"Error: signature failed\n");
goto done;
}

-----------------------------------------------------------------------------

These are the error messages:

func=xmlSecKeyMatch:file=keys.c:line=703:obj=unknown:subj=xmlSecKeyIsValid(key):error=100:assertion:

func=xmlSecOpenSSLHmacSetKey:file=hmac.c:line=208:obj=unknown:subj=xmlSecKeyDataCheckId(value, xmlSecOpenSSLKeyDataHmacId):error=100:assertion:

func=xmlSecDSigCtxProcessKeyInfoNode:file=xmldsig.c:line=882:obj=unknown:subj=xmlSecTransformSetKey:error=1:xmlsec library function failed:transform=hmac-sha1

func=xmlSecDSigCtxProcessSignatureNode:file=xmldsig.c:line=565:obj=unknown:subj=xmlSecDSigCtxProcessKeyInfoNode:error=1:xmlsec library function failed:

func=xmlSecDSigCtxSign:file=xmldsig.c:line=303:obj=unknown:subj=xmlSecDSigCtxSigantureProcessNode:error=1:xmlsec library function failed:

Error: signature failed

------------------------------------------------------------------

Do you know why this is possibly failing?  Am I missing a step here?
 
Thanks,
Monica


Aleksey Sanin <aleksey at aleksey.com> wrote:
Creating HMAC key in xmlsec:
------------------------------

xmlSecKeyPtr CreateHmacKey(const xmlSecByte * buf, xmlSecSize size)
{
xmlSecKeyPtr key;
xmlSecKeyDataPtr key_data;
int ret;

key = xmlSecKeyCreate();
if(!key) {
return (NULL);
}

key_data = xmlSecKeyEnsureData(key, xmlSecKeyDataHmacId);
if(!key_data) {
xmlSecKeyDestroy(key);
return (NULL);
}

ret = xmlSecOpenSSLKeyDataHmacSet(key_data, buf, size);
if(ret < 0) {
xmlSecKeyDestroy(key);
return (NULL);
}

return (key);
}

------------------------------


Best,
Aleksey




		
---------------------------------
Do you Yahoo!?
vote.yahoo.com - Register online to vote today!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.aleksey.com/pipermail/xmlsec/attachments/20041008/004664a9/attachment-0002.htm


More information about the xmlsec mailing list