[xmlsec] Problem when using the xmlSecOpenSSLAppKeyLoadMemory() API.
Venkataragavan Vijayakumar
venkataragavan.v at gmail.com
Wed Apr 3 00:31:00 PDT 2013
Hi all,
Please check anything i am doing wrong in the key buffer creation. simply I
am directly copying the key from the private key file generated using
openssl. I have attached sample key file(dtls.key) , where i have taken the
key.
Please help me to solve this issue.
const xmlSecByte *keybuf =
"MIIBOwIBAAJBALe2myLsvZaYVDcZAkaHfaYnwlojm7ebRHGuLGUvYXHgmdMU9LLT6cMABq2me+ioQLhB0+KY4Nth91NG52spEtECAwEAAQJAMKWQCv15bolDs5tRuO9j3D2m/0tyjnn0881VQC39tbN6w+tCVhUHPEy+3l/jf7b/xkuIcbgV2voXVEVFjHmwCQIhAOTF+LdlVZ/TbIEM+GRTaYQQEXz0NjWWIARxDv6OWvdzAiEAzZPK3ZqQtXw3/E2HU6DGBFxB8S92PGk5EFKWaUtG06sCIQC+Cx9j6lBI5u9Z/RZS8V/UDy0X6h8mQMH0Lp9QI525tQIgaslZuNFAWDWlc1bmc+dw1PUDgAByf6D89mCgJyPmL68CIQCmkdwn7cuWI4GlVJnpDZ2iHZjeiih3oVR73/WquuyJqw==";
xmlSecSize keysize = strlen(keybuf);
assert(tmpl_file);
assert(key_file);
/* load template */
doc = xmlParseFile(tmpl_file);
if ((doc == NULL) || (xmlDocGetRootElement(doc) == NULL)){
fprintf(stderr, "Error: unable to parse file \"%s\"\n", tmpl_file);
goto done;
}
/* find start node */
node = xmlSecFindNode(xmlDocGetRootElement(doc), xmlSecNodeSignature,
xmlSecDSigNs);
if(node == NULL) {
fprintf(stderr, "Error: start node not found in \"%s\"\n", tmpl_file);
goto done;
}
/* create signature context, we don't need keys manager in this example */
dsigCtx = xmlSecDSigCtxCreate(NULL);
if(dsigCtx == NULL) {
fprintf(stderr,"Error: failed to create signature context\n");
goto done;
}
/* load private key, assuming that there is not password */
dsigCtx->signKey =
xmlSecCryptoAppKeyLoadMemory(keybuf,keysize,xmlSecKeyDataFormatPem, NULL,
NULL, NULL);
if(dsigCtx->signKey == NULL) {
fprintf(stderr,"Error: failed to load private pem key from \"%s\"\n",
key_file);
goto done;
}
Thanks,
Venkat.
On Tue, Apr 2, 2013 at 11:38 PM, Aleksey Sanin <aleksey at aleksey.com> wrote:
> You will need to debug what's going on at the openssl level. If I would
> guess then I would think you didn't load the key into memory correctly.
>
> Aleksey
>
> On 4/2/13 8:00 AM, Venkataragavan Vijayakumar wrote:
> > Hi All,
> >
> > Previously I have used the xmlSecCryptoAppKeyLoad() API to load the Key
> > file in the PEM format , it worked fine, but when i start to use
> > xmlSecCryptoAppKeyLoadMemory() with the same content in the key file is
> > given as input as buffer, it given error as
> >
> >
> >
> func=xmlSecOpenSSLAppKeyLoadBIO:file=app.c:line=263:obj=unknown:subj=PEM_read_bio_PrivateKey
> > and PEM_read_bio_PUBKEY:error=4:crypto library function
> > failed:
> >
> >
> func=xmlSecOpenSSLAppKeyLoadMemory:file=app.c:line=205:obj=unknown:subj=xmlSecOpenSSLAppKeyLoadBIO:error=1:xmlsec
> > library function failed:
> >
> >
> > *
> >
> > code used like this*:
> >
> > dsigCtx->signKey =
> > xmlSecCryptoAppKeyLoadMemory(keybuf,keysize,xmlSecKeyDataFormatPem,
> > NULL, NULL, NULL);
> > if(dsigCtx->signKey == NULL) {
> > fprintf(stderr,"Error: failed to load private pem key from
> > \"%s\"\n", key_file);
> > goto done;
> > }
> >
> > Please help me to resolve this issue.
> >
> > Thanks,
> > Venkat.
> >
> >
> >
> > _______________________________________________
> > xmlsec mailing list
> > xmlsec at aleksey.com
> > http://www.aleksey.com/mailman/listinfo/xmlsec
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.aleksey.com/pipermail/xmlsec/attachments/20130403/e9826608/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dtls.key
Type: application/octet-stream
Size: 497 bytes
Desc: not available
URL: <http://www.aleksey.com/pipermail/xmlsec/attachments/20130403/e9826608/attachment-0001.obj>
More information about the xmlsec
mailing list