summaryrefslogtreecommitdiff
path: root/xmlsecurity
diff options
context:
space:
mode:
authorThorsten Behrens <Thorsten.Behrens@CIB.de>2017-06-24 00:17:04 +0200
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2017-06-24 18:13:47 +0200
commit879fea59a0bcc1a439e51ab0923e1cc41dff5bfb (patch)
treee59da93ed2d1baf5583dbe5575b38e04d2f55dd8 /xmlsecurity
parent1ac1caff62d0d72d158a2fafb3f06b7ec18cb346 (diff)
gpp4libre: error handling, proper key extraction
Change-Id: I1cb219f825393309219a4ebfb406482050b91228 Reviewed-on: https://gerrit.libreoffice.org/39191 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'xmlsecurity')
-rw-r--r--xmlsecurity/source/gpg/xmlsignature_gpgimpl.cxx12
1 files changed, 10 insertions, 2 deletions
diff --git a/xmlsecurity/source/gpg/xmlsignature_gpgimpl.cxx b/xmlsecurity/source/gpg/xmlsignature_gpgimpl.cxx
index 48d2097dad0f..63e26a76f8ea 100644
--- a/xmlsecurity/source/gpg/xmlsignature_gpgimpl.cxx
+++ b/xmlsecurity/source/gpg/xmlsignature_gpgimpl.cxx
@@ -171,7 +171,7 @@ SAL_CALL XMLSignature_GpgImpl::generate(
cur = xmlSecGetNextElementNode(cur->next);
cur = xmlSecGetNextElementNode(cur->children);
// check that this is now PGPData
- if(!xmlSecCheckNodeName(cur, xmlSecNamePGPData, xmlSecDSigNs))
+ if(!xmlSecCheckNodeName(cur, xmlSecNodePGPData, xmlSecDSigNs))
throw RuntimeException("The GpgME library failed to initialize for the OpenPGP protocol.");
// check that this is now PGPKeyID
cur = xmlSecGetNextElementNode(cur->children);
@@ -182,11 +182,16 @@ SAL_CALL XMLSignature_GpgImpl::generate(
GpgME::Context& rCtx=pSecEnv->getGpgContext();
rCtx.setKeyListMode(GPGME_KEYLIST_MODE_LOCAL);
GpgME::Error err;
+ xmlChar* pKey=xmlNodeGetContent(cur);
+ if(xmlSecBase64Decode(pKey, reinterpret_cast<xmlSecByte*>(pKey), xmlStrlen(pKey)) < 0)
+ throw RuntimeException("The GpgME library failed to initialize for the OpenPGP protocol.");
if( rCtx.addSigningKey(
rCtx.key(
- reinterpret_cast<char*>(xmlNodeGetContent(cur)), err, true)) )
+ reinterpret_cast<char*>(pKey), err, true)) )
throw RuntimeException("The GpgME library failed to initialize for the OpenPGP protocol.");
+ xmlFree(pKey);
+
// good, ctx is setup now, let's sign the lot
GpgME::Data data_in(
reinterpret_cast<char*>(xmlSecBufferGetData(pDsigCtx->transformCtx.result)),
@@ -202,6 +207,9 @@ SAL_CALL XMLSignature_GpgImpl::generate(
while( (curr=data_out.read(&buf, 1)) )
len += curr;
+ if(sign_res.error() || !len)
+ throw RuntimeException("The GpgME library failed to initialize for the OpenPGP protocol.");
+
// write signed data to xml
std::vector<unsigned char> buf2(len);
assert(data_out.seek(0,SEEK_SET) == 0);