Kaydet (Commit) 32dfaf1e authored tarafından Miklos Vajna's avatar Miklos Vajna

xmlsecurity nss: avoid deleting the dsig context manually

Change-Id: I0198c1b0d6ba6c27072376943895718d536a284c
Reviewed-on: https://gerrit.libreoffice.org/61323
Tested-by: Jenkins
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst ae882ec4
......@@ -51,6 +51,10 @@ template <> struct default_delete<xmlSecKeysMngr>
{
void operator()(xmlSecKeysMngrPtr ptr) { SecurityEnvironment_NssImpl::destroyKeysManager(ptr); }
};
template <> struct default_delete<xmlSecDSigCtx>
{
void operator()(xmlSecDSigCtxPtr ptr) { xmlSecDSigCtxDestroy(ptr); }
};
}
class XMLSignature_NssImpl
......@@ -86,7 +90,6 @@ SAL_CALL XMLSignature_NssImpl::generate(
const Reference< XSecurityEnvironment >& aEnvironment
)
{
xmlSecDSigCtxPtr pDsigCtx = nullptr ;
xmlNodePtr pNode = nullptr ;
if( !aTemplate.is() )
......@@ -140,7 +143,7 @@ SAL_CALL XMLSignature_NssImpl::generate(
}
//Create Signature context
pDsigCtx = xmlSecDSigCtxCreate(pMngr.get());
std::unique_ptr<xmlSecDSigCtx> pDsigCtx(xmlSecDSigCtxCreate(pMngr.get()));
if( pDsigCtx == nullptr )
{
//throw XMLSignatureException() ;
......@@ -149,7 +152,7 @@ SAL_CALL XMLSignature_NssImpl::generate(
}
//Sign the template
if( xmlSecDSigCtxSign( pDsigCtx , pNode ) == 0 )
if( xmlSecDSigCtxSign( pDsigCtx.get() , pNode ) == 0 )
{
if (pDsigCtx->status == xmlSecDSigStatusSucceeded)
aTemplate->setStatus(css::xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED);
......@@ -161,9 +164,6 @@ SAL_CALL XMLSignature_NssImpl::generate(
aTemplate->setStatus(css::xml::crypto::SecurityOperationStatus_UNKNOWN);
}
xmlSecDSigCtxDestroy( pDsigCtx ) ;
//Unregistered the stream/URI binding
if( xUriBinding.is() )
xmlUnregisterStreamInputCallbacks() ;
......@@ -178,7 +178,6 @@ SAL_CALL XMLSignature_NssImpl::validate(
const Reference< XXMLSignatureTemplate >& aTemplate ,
const Reference< XXMLSecurityContext >& aSecurityCtx
) {
xmlSecDSigCtxPtr pDsigCtx = nullptr ;
xmlNodePtr pNode = nullptr ;
//sal_Bool valid ;
......@@ -235,7 +234,7 @@ SAL_CALL XMLSignature_NssImpl::validate(
}
//Create Signature context
pDsigCtx = xmlSecDSigCtxCreate(pMngr.get());
std::unique_ptr<xmlSecDSigCtx> pDsigCtx(xmlSecDSigCtxCreate(pMngr.get()));
if( pDsigCtx == nullptr )
{
clearErrorRecorder();
......@@ -246,7 +245,7 @@ SAL_CALL XMLSignature_NssImpl::validate(
pDsigCtx->keyInfoReadCtx.flags |= XMLSEC_KEYINFO_FLAGS_X509DATA_DONT_VERIFY_CERTS;
//Verify signature
int rs = xmlSecDSigCtxVerify( pDsigCtx , pNode );
int rs = xmlSecDSigCtxVerify( pDsigCtx.get() , pNode );
// Also verify manifest: this is empty for ODF, but contains everything (except signature metadata) for OOXML.
xmlSecSize nReferenceCount = xmlSecPtrListGetSize(&pDsigCtx->manifestReferences);
......@@ -265,14 +264,12 @@ SAL_CALL XMLSignature_NssImpl::validate(
if (rs == 0 && pDsigCtx->status == xmlSecDSigStatusSucceeded && nReferenceCount == nReferenceGood)
{
aTemplate->setStatus(css::xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED);
xmlSecDSigCtxDestroy( pDsigCtx ) ;
break;
}
else
{
aTemplate->setStatus(css::xml::crypto::SecurityOperationStatus_UNKNOWN);
}
xmlSecDSigCtxDestroy( pDsigCtx ) ;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment