2010-10-12 15:57:08 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-07-16 17:32:30 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2004-07-12 12:15:31 +00:00
|
|
|
|
2017-11-22 19:06:26 +01:00
|
|
|
#include <config_gpgme.h>
|
2006-09-16 13:41:33 +00:00
|
|
|
|
2017-10-23 22:27:10 +02:00
|
|
|
#include <xsecctl.hxx>
|
2004-07-12 12:15:31 +00:00
|
|
|
#include "xsecparser.hxx"
|
2016-01-12 18:54:29 +01:00
|
|
|
#include "ooxmlsecparser.hxx"
|
2017-10-23 22:27:10 +02:00
|
|
|
#include <framework/signatureverifierimpl.hxx>
|
|
|
|
#include <framework/saxeventkeeperimpl.hxx>
|
|
|
|
#include <gpg/xmlsignature_gpgimpl.hxx>
|
|
|
|
#include <gpg/SEInitializer.hxx>
|
2004-07-12 12:15:31 +00:00
|
|
|
|
2017-08-08 16:23:07 +02:00
|
|
|
#include <com/sun/star/uno/Sequence.hxx>
|
2004-07-12 12:15:31 +00:00
|
|
|
#include <com/sun/star/xml/crypto/sax/XKeyCollector.hpp>
|
|
|
|
#include <com/sun/star/xml/crypto/sax/ElementMarkPriority.hpp>
|
|
|
|
#include <com/sun/star/xml/crypto/sax/XReferenceResolvedBroadcaster.hpp>
|
|
|
|
#include <com/sun/star/xml/crypto/sax/XReferenceCollector.hpp>
|
|
|
|
#include <com/sun/star/xml/crypto/sax/XSignatureVerifyResultBroadcaster.hpp>
|
2017-06-21 18:00:55 +02:00
|
|
|
#include <com/sun/star/xml/crypto/XSEInitializer.hpp>
|
2017-08-08 16:23:07 +02:00
|
|
|
#include <com/sun/star/graphic/XGraphic.hpp>
|
|
|
|
#include <com/sun/star/graphic/GraphicProvider.hpp>
|
2004-07-12 12:15:31 +00:00
|
|
|
#include <com/sun/star/xml/sax/SAXParseException.hpp>
|
2016-01-12 18:54:29 +01:00
|
|
|
#include <com/sun/star/embed/StorageFormats.hpp>
|
2013-02-06 00:10:23 +02:00
|
|
|
#include <sal/log.hxx>
|
2013-03-17 08:36:26 +01:00
|
|
|
#include <unotools/datetime.hxx>
|
2017-08-08 16:23:07 +02:00
|
|
|
#include <comphelper/base64.hxx>
|
|
|
|
#include <comphelper/processfactory.hxx>
|
|
|
|
#include <comphelper/seqstream.hxx>
|
|
|
|
|
|
|
|
using namespace css;
|
|
|
|
using namespace css::uno;
|
|
|
|
using namespace css::beans;
|
2004-07-12 12:15:31 +00:00
|
|
|
namespace cssu = com::sun::star::uno;
|
|
|
|
namespace cssl = com::sun::star::lang;
|
|
|
|
namespace cssxc = com::sun::star::xml::crypto;
|
|
|
|
namespace cssxs = com::sun::star::xml::sax;
|
|
|
|
|
|
|
|
/* protected: for signature verify */
|
|
|
|
cssu::Reference< cssxc::sax::XReferenceResolvedListener > XSecController::prepareSignatureToRead(
|
|
|
|
sal_Int32 nSecurityId)
|
|
|
|
{
|
2016-10-24 12:10:27 +03:00
|
|
|
if ( m_eStatusOfSecurityComponents != InitializationState::INITIALIZED )
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2015-11-10 10:29:43 +01:00
|
|
|
return nullptr;
|
2004-07-12 12:15:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sal_Int32 nIdOfSignatureElementCollector;
|
|
|
|
cssu::Reference< cssxc::sax::XReferenceResolvedListener > xReferenceResolvedListener;
|
|
|
|
|
|
|
|
nIdOfSignatureElementCollector =
|
2016-04-20 17:21:57 +02:00
|
|
|
m_xSAXEventKeeper->addSecurityElementCollector( cssxc::sax::ElementMarkPriority_BEFOREMODIFY, false);
|
2004-07-12 12:15:31 +00:00
|
|
|
|
|
|
|
m_xSAXEventKeeper->setSecurityId(nIdOfSignatureElementCollector, nSecurityId);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* create a SignatureVerifier
|
|
|
|
*/
|
2017-01-09 09:22:34 +02:00
|
|
|
xReferenceResolvedListener = new SignatureVerifierImpl;
|
2004-07-12 12:15:31 +00:00
|
|
|
|
|
|
|
cssu::Reference<cssl::XInitialization> xInitialization(xReferenceResolvedListener, cssu::UNO_QUERY);
|
|
|
|
|
|
|
|
cssu::Sequence<cssu::Any> args(5);
|
2017-02-24 11:22:18 +02:00
|
|
|
args[0] <<= OUString::number(nSecurityId);
|
2017-03-17 09:50:25 +01:00
|
|
|
args[1] <<= uno::Reference<xml::crypto::sax::XSecuritySAXEventKeeper>(static_cast<cppu::OWeakObject*>(m_xSAXEventKeeper.get()), uno::UNO_QUERY);
|
2017-02-24 11:22:18 +02:00
|
|
|
args[2] <<= OUString::number(nIdOfSignatureElementCollector);
|
|
|
|
args[3] <<= m_xSecurityContext;
|
|
|
|
args[4] <<= m_xXMLSignature;
|
2004-07-12 12:15:31 +00:00
|
|
|
xInitialization->initialize(args);
|
|
|
|
|
|
|
|
cssu::Reference< cssxc::sax::XSignatureVerifyResultBroadcaster >
|
|
|
|
signatureVerifyResultBroadcaster(xReferenceResolvedListener, cssu::UNO_QUERY);
|
|
|
|
|
|
|
|
signatureVerifyResultBroadcaster->addSignatureVerifyResultListener( this );
|
|
|
|
|
2017-03-17 09:50:25 +01:00
|
|
|
m_xSAXEventKeeper->addReferenceResolvedListener(
|
2004-07-12 12:15:31 +00:00
|
|
|
nIdOfSignatureElementCollector,
|
|
|
|
xReferenceResolvedListener);
|
|
|
|
|
|
|
|
cssu::Reference<cssxc::sax::XKeyCollector> keyCollector (xReferenceResolvedListener, cssu::UNO_QUERY);
|
|
|
|
keyCollector->setKeyId(0);
|
|
|
|
|
|
|
|
return xReferenceResolvedListener;
|
|
|
|
}
|
|
|
|
|
|
|
|
void XSecController::addSignature()
|
|
|
|
{
|
2018-09-12 17:01:48 +02:00
|
|
|
cssu::Reference< cssxc::sax::XReferenceResolvedListener > xReferenceResolvedListener;
|
2004-07-12 12:15:31 +00:00
|
|
|
sal_Int32 nSignatureId = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (m_bVerifyCurrentSignature)
|
|
|
|
{
|
2017-10-25 09:14:24 +02:00
|
|
|
chainOn();
|
2004-07-12 12:15:31 +00:00
|
|
|
xReferenceResolvedListener = prepareSignatureToRead( m_nReservedSignatureId );
|
|
|
|
m_bVerifyCurrentSignature = false;
|
|
|
|
nSignatureId = m_nReservedSignatureId;
|
|
|
|
}
|
|
|
|
|
|
|
|
InternalSignatureInformation isi( nSignatureId, xReferenceResolvedListener );
|
|
|
|
m_vInternalSignatureInformations.push_back( isi );
|
|
|
|
}
|
|
|
|
|
2018-05-15 22:16:42 +02:00
|
|
|
void XSecController::setSignatureMethod(svl::crypto::SignatureMethodAlgorithm eAlgorithmID)
|
|
|
|
{
|
|
|
|
if (m_vInternalSignatureInformations.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_vInternalSignatureInformations.back().signatureInfor.eAlgorithmID = eAlgorithmID;
|
|
|
|
}
|
|
|
|
|
2017-06-21 18:00:55 +02:00
|
|
|
void XSecController::switchGpgSignature()
|
|
|
|
{
|
2017-12-07 22:40:47 +01:00
|
|
|
#if HAVE_FEATURE_GPGME
|
2017-06-21 18:00:55 +02:00
|
|
|
// swap signature verifier for the Gpg one
|
|
|
|
m_xXMLSignature.set(new XMLSignature_GpgImpl());
|
|
|
|
if (!m_vInternalSignatureInformations.empty())
|
|
|
|
{
|
|
|
|
SignatureVerifierImpl* pImpl=
|
|
|
|
dynamic_cast<SignatureVerifierImpl*>(
|
|
|
|
m_vInternalSignatureInformations.back().xReferenceResolvedListener.get());
|
|
|
|
if (pImpl)
|
|
|
|
{
|
|
|
|
css::uno::Reference<css::xml::crypto::XSEInitializer> xGpgSEInitializer(
|
|
|
|
new SEInitializerGpg());
|
|
|
|
pImpl->updateSignature(new XMLSignature_GpgImpl(),
|
|
|
|
xGpgSEInitializer->createSecurityContext(OUString()));
|
|
|
|
}
|
|
|
|
}
|
2017-06-30 10:18:07 +02:00
|
|
|
#else
|
|
|
|
(void) this;
|
2017-06-21 18:00:55 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-10-29 09:50:28 +03:00
|
|
|
void XSecController::addReference( const OUString& ouUri, sal_Int32 nDigestID )
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2012-02-18 00:03:39 +01:00
|
|
|
if (m_vInternalSignatureInformations.empty())
|
|
|
|
{
|
2013-02-06 00:10:23 +02:00
|
|
|
SAL_INFO("xmlsecurity.helper","XSecController::addReference: no signature");
|
2012-02-18 00:03:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
InternalSignatureInformation &isi = m_vInternalSignatureInformations.back();
|
2016-10-29 09:50:28 +03:00
|
|
|
isi.addReference(SignatureReferenceType::SAMEDOCUMENT, nDigestID, ouUri, -1 );
|
2004-07-12 12:15:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void XSecController::addStreamReference(
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString& ouUri,
|
2016-10-29 09:50:28 +03:00
|
|
|
bool isBinary,
|
|
|
|
sal_Int32 nDigestID )
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2016-01-05 10:38:39 +01:00
|
|
|
SignatureReferenceType type = (isBinary?SignatureReferenceType::BINARYSTREAM:SignatureReferenceType::XMLSTREAM);
|
2004-07-12 12:15:31 +00:00
|
|
|
|
2012-02-18 00:03:39 +01:00
|
|
|
if (m_vInternalSignatureInformations.empty())
|
|
|
|
{
|
2013-02-06 00:10:23 +02:00
|
|
|
SAL_INFO("xmlsecurity.helper","XSecController::addStreamReference: no signature");
|
2012-02-18 00:03:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
InternalSignatureInformation &isi = m_vInternalSignatureInformations.back();
|
2004-07-12 12:15:31 +00:00
|
|
|
|
|
|
|
if ( isi.xReferenceResolvedListener.is() )
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* get the input stream
|
|
|
|
*/
|
2015-11-26 09:49:00 +02:00
|
|
|
cssu::Reference< css::io::XInputStream > xObjectInputStream
|
2004-07-12 12:15:31 +00:00
|
|
|
= getObjectInputStream( ouUri );
|
|
|
|
|
|
|
|
if ( xObjectInputStream.is() )
|
|
|
|
{
|
|
|
|
cssu::Reference<cssxc::XUriBinding> xUriBinding
|
|
|
|
(isi.xReferenceResolvedListener, cssu::UNO_QUERY);
|
|
|
|
xUriBinding->setUriBinding(ouUri, xObjectInputStream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-29 09:50:28 +03:00
|
|
|
isi.addReference(type, nDigestID, ouUri, -1);
|
2004-07-12 12:15:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void XSecController::setReferenceCount() const
|
|
|
|
{
|
2012-02-18 00:03:39 +01:00
|
|
|
if (m_vInternalSignatureInformations.empty())
|
|
|
|
{
|
2013-02-06 00:10:23 +02:00
|
|
|
SAL_INFO("xmlsecurity.helper","XSecController::setReferenceCount: no signature");
|
2012-02-18 00:03:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const InternalSignatureInformation &isi =
|
|
|
|
m_vInternalSignatureInformations.back();
|
2004-07-12 12:15:31 +00:00
|
|
|
|
|
|
|
if ( isi.xReferenceResolvedListener.is() )
|
|
|
|
{
|
|
|
|
const SignatureReferenceInformations &refInfors = isi.signatureInfor.vSignatureReferenceInfors;
|
|
|
|
|
|
|
|
int refNum = refInfors.size();
|
|
|
|
sal_Int32 referenceCount = 0;
|
|
|
|
|
|
|
|
for(int i=0 ; i<refNum; ++i)
|
|
|
|
{
|
2016-01-05 10:38:39 +01:00
|
|
|
if (refInfors[i].nType == SignatureReferenceType::SAMEDOCUMENT )
|
2004-07-12 12:15:31 +00:00
|
|
|
/*
|
|
|
|
* same-document reference
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
referenceCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cssu::Reference<cssxc::sax::XReferenceCollector> xReferenceCollector
|
|
|
|
(isi.xReferenceResolvedListener, cssu::UNO_QUERY);
|
|
|
|
xReferenceCollector->setReferenceCount( referenceCount );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-27 10:03:53 +02:00
|
|
|
void XSecController::setX509IssuerName( OUString const & ouX509IssuerName )
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2012-02-18 00:03:39 +01:00
|
|
|
if (m_vInternalSignatureInformations.empty())
|
|
|
|
{
|
2013-02-06 00:10:23 +02:00
|
|
|
SAL_INFO("xmlsecurity.helper","XSecController::setX509IssuerName: no signature");
|
2012-02-18 00:03:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
InternalSignatureInformation &isi = m_vInternalSignatureInformations.back();
|
2004-07-12 12:15:31 +00:00
|
|
|
isi.signatureInfor.ouX509IssuerName = ouX509IssuerName;
|
|
|
|
}
|
|
|
|
|
2017-07-27 10:03:53 +02:00
|
|
|
void XSecController::setX509SerialNumber( OUString const & ouX509SerialNumber )
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2012-02-18 00:03:39 +01:00
|
|
|
if (m_vInternalSignatureInformations.empty())
|
|
|
|
{
|
2013-02-06 00:10:23 +02:00
|
|
|
SAL_INFO("xmlsecurity.helper","XSecController::setX509SerialNumber: no signature");
|
2012-02-18 00:03:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
InternalSignatureInformation &isi = m_vInternalSignatureInformations.back();
|
2004-07-12 12:15:31 +00:00
|
|
|
isi.signatureInfor.ouX509SerialNumber = ouX509SerialNumber;
|
|
|
|
}
|
|
|
|
|
2017-07-27 10:03:53 +02:00
|
|
|
void XSecController::setX509Certificate( OUString const & ouX509Certificate )
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2012-02-18 00:03:39 +01:00
|
|
|
if (m_vInternalSignatureInformations.empty())
|
|
|
|
{
|
2013-02-06 00:10:23 +02:00
|
|
|
SAL_INFO("xmlsecurity.helper","XSecController::setX509Certificate: no signature");
|
2012-02-18 00:03:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
InternalSignatureInformation &isi = m_vInternalSignatureInformations.back();
|
2004-07-12 12:15:31 +00:00
|
|
|
isi.signatureInfor.ouX509Certificate = ouX509Certificate;
|
|
|
|
}
|
|
|
|
|
2017-07-27 10:03:53 +02:00
|
|
|
void XSecController::setSignatureValue( OUString const & ouSignatureValue )
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2012-02-18 00:03:39 +01:00
|
|
|
if (m_vInternalSignatureInformations.empty())
|
|
|
|
{
|
2013-02-06 00:10:23 +02:00
|
|
|
SAL_INFO("xmlsecurity.helper","XSecController::setSignatureValue: no signature");
|
2012-02-18 00:03:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
InternalSignatureInformation &isi = m_vInternalSignatureInformations.back();
|
2004-07-12 12:15:31 +00:00
|
|
|
isi.signatureInfor.ouSignatureValue = ouSignatureValue;
|
|
|
|
}
|
|
|
|
|
2017-07-27 10:03:53 +02:00
|
|
|
void XSecController::setDigestValue( sal_Int32 nDigestID, OUString const & ouDigestValue )
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2012-02-18 00:03:39 +01:00
|
|
|
if (m_vInternalSignatureInformations.empty())
|
|
|
|
{
|
2013-02-06 00:10:23 +02:00
|
|
|
SAL_INFO("xmlsecurity.helper","XSecController::setDigestValue: no signature");
|
2012-02-18 00:03:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
InternalSignatureInformation &isi = m_vInternalSignatureInformations.back();
|
|
|
|
if (isi.signatureInfor.vSignatureReferenceInfors.empty())
|
|
|
|
{
|
2013-02-06 00:10:23 +02:00
|
|
|
SAL_INFO("xmlsecurity.helper","XSecController::setDigestValue: no signature reference");
|
2012-02-18 00:03:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
SignatureReferenceInformation &reference =
|
|
|
|
isi.signatureInfor.vSignatureReferenceInfors.back();
|
2016-10-29 09:50:28 +03:00
|
|
|
reference.nDigestID = nDigestID;
|
2004-07-12 12:15:31 +00:00
|
|
|
reference.ouDigestValue = ouDigestValue;
|
|
|
|
}
|
|
|
|
|
2017-07-27 10:03:53 +02:00
|
|
|
void XSecController::setGpgKeyID( OUString const & ouKeyID )
|
2017-06-21 16:54:52 +02:00
|
|
|
{
|
|
|
|
if (m_vInternalSignatureInformations.empty())
|
|
|
|
{
|
|
|
|
SAL_INFO("xmlsecurity.helper","XSecController::setGpgKeyID: no signature");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
InternalSignatureInformation &isi = m_vInternalSignatureInformations.back();
|
|
|
|
isi.signatureInfor.ouGpgKeyID = ouKeyID;
|
|
|
|
}
|
|
|
|
|
2017-07-27 10:03:53 +02:00
|
|
|
void XSecController::setGpgCertificate( OUString const & ouGpgCert )
|
2017-06-21 16:54:52 +02:00
|
|
|
{
|
|
|
|
if (m_vInternalSignatureInformations.empty())
|
|
|
|
{
|
|
|
|
SAL_INFO("xmlsecurity.helper","XSecController::setGpgCertificate: no signature");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
InternalSignatureInformation &isi = m_vInternalSignatureInformations.back();
|
|
|
|
isi.signatureInfor.ouGpgCertificate = ouGpgCert;
|
|
|
|
}
|
|
|
|
|
2017-07-27 10:03:53 +02:00
|
|
|
void XSecController::setGpgOwner( OUString const & ouGpgOwner )
|
2017-07-10 10:02:10 +02:00
|
|
|
{
|
|
|
|
if (m_vInternalSignatureInformations.empty())
|
|
|
|
{
|
|
|
|
SAL_INFO("xmlsecurity.helper","XSecController::setGpgOwner: no signature");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
InternalSignatureInformation &isi = m_vInternalSignatureInformations.back();
|
|
|
|
isi.signatureInfor.ouGpgOwner = ouGpgOwner;
|
|
|
|
}
|
|
|
|
|
2017-07-27 10:03:53 +02:00
|
|
|
void XSecController::setDate( OUString const & ouDate )
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2012-02-18 00:03:39 +01:00
|
|
|
if (m_vInternalSignatureInformations.empty())
|
|
|
|
{
|
2013-02-06 00:10:23 +02:00
|
|
|
SAL_INFO("xmlsecurity.helper","XSecController::setDate: no signature");
|
2012-02-18 00:03:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
InternalSignatureInformation &isi = m_vInternalSignatureInformations.back();
|
2017-07-18 16:40:59 +01:00
|
|
|
(void)utl::ISO8601parseDateTime( ouDate, isi.signatureInfor.stDateTime);
|
2006-04-07 10:57:46 +00:00
|
|
|
isi.signatureInfor.ouDateTime = ouDate;
|
2004-07-12 12:15:31 +00:00
|
|
|
}
|
|
|
|
|
2016-01-05 09:57:38 +01:00
|
|
|
void XSecController::setDescription(const OUString& rDescription)
|
|
|
|
{
|
|
|
|
if (m_vInternalSignatureInformations.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
InternalSignatureInformation& rInformation = m_vInternalSignatureInformations.back();
|
|
|
|
rInformation.signatureInfor.ouDescription = rDescription;
|
|
|
|
}
|
|
|
|
|
2016-03-04 09:40:17 +01:00
|
|
|
void XSecController::setSignatureBytes(const uno::Sequence<sal_Int8>& rBytes)
|
|
|
|
{
|
|
|
|
if (m_vInternalSignatureInformations.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
InternalSignatureInformation& rInformation = m_vInternalSignatureInformations.back();
|
|
|
|
rInformation.signatureInfor.aSignatureBytes = rBytes;
|
|
|
|
}
|
|
|
|
|
2016-02-12 09:49:37 +01:00
|
|
|
void XSecController::setCertDigest(const OUString& rCertDigest)
|
|
|
|
{
|
|
|
|
if (m_vInternalSignatureInformations.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
InternalSignatureInformation& rInformation = m_vInternalSignatureInformations.back();
|
|
|
|
rInformation.signatureInfor.ouCertDigest = rCertDigest;
|
|
|
|
}
|
|
|
|
|
2017-08-08 16:23:07 +02:00
|
|
|
namespace {
|
|
|
|
Reference<css::graphic::XGraphic> lcl_getGraphicFromString(const OUString& rImage)
|
|
|
|
{
|
|
|
|
Sequence<sal_Int8> seq;
|
|
|
|
comphelper::Base64::decode(seq, rImage);
|
|
|
|
|
|
|
|
Reference< graphic::XGraphic > xGraphic;
|
|
|
|
if( !seq.hasElements() )
|
|
|
|
return Reference<css::graphic::XGraphic>();
|
|
|
|
|
|
|
|
Reference< graphic::XGraphicProvider > xGraphicProvider(
|
|
|
|
graphic::GraphicProvider::create(comphelper::getProcessComponentContext()) );
|
|
|
|
Reference< io::XInputStream > xInputStream( new ::comphelper::SequenceInputStream( seq ) );
|
|
|
|
|
|
|
|
Sequence< PropertyValue > aArgs( 1 );
|
|
|
|
aArgs[ 0 ].Name = "InputStream";
|
|
|
|
aArgs[ 0 ].Value <<= xInputStream;
|
|
|
|
xGraphic = xGraphicProvider->queryGraphic(aArgs);
|
|
|
|
|
|
|
|
return xGraphic;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void XSecController::setValidSignatureImage(const OUString& rValidSigImg)
|
|
|
|
{
|
|
|
|
if (m_vInternalSignatureInformations.empty() || rValidSigImg.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
InternalSignatureInformation& rInformation = m_vInternalSignatureInformations.back();
|
|
|
|
rInformation.signatureInfor.aValidSignatureImage = lcl_getGraphicFromString(rValidSigImg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void XSecController::setInvalidSignatureImage(const OUString& rInvalidSigImg)
|
|
|
|
{
|
|
|
|
if (m_vInternalSignatureInformations.empty() || rInvalidSigImg.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
InternalSignatureInformation& rInformation = m_vInternalSignatureInformations.back();
|
|
|
|
rInformation.signatureInfor.aInvalidSignatureImage = lcl_getGraphicFromString(rInvalidSigImg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void XSecController::setSignatureLineId(const OUString& rSignatureLineId)
|
|
|
|
{
|
|
|
|
if (m_vInternalSignatureInformations.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
InternalSignatureInformation& rInformation = m_vInternalSignatureInformations.back();
|
|
|
|
rInformation.signatureInfor.ouSignatureLineId = rSignatureLineId;
|
|
|
|
}
|
|
|
|
|
2016-11-11 00:21:50 +02:00
|
|
|
void XSecController::addEncapsulatedX509Certificate(const OUString& rEncapsulatedX509Certificate)
|
|
|
|
{
|
|
|
|
if (m_vInternalSignatureInformations.empty())
|
|
|
|
return;
|
|
|
|
|
2016-11-11 17:07:31 +02:00
|
|
|
if (rEncapsulatedX509Certificate.isEmpty())
|
|
|
|
return;
|
|
|
|
|
2016-11-11 00:21:50 +02:00
|
|
|
InternalSignatureInformation& rInformation = m_vInternalSignatureInformations.back();
|
|
|
|
rInformation.signatureInfor.maEncapsulatedX509Certificates.insert(rEncapsulatedX509Certificate);
|
|
|
|
}
|
|
|
|
|
2017-07-27 10:03:53 +02:00
|
|
|
void XSecController::setId( OUString const & ouId )
|
2004-07-28 01:27:50 +00:00
|
|
|
{
|
2012-02-18 00:03:39 +01:00
|
|
|
if (m_vInternalSignatureInformations.empty())
|
|
|
|
{
|
2013-02-06 00:10:23 +02:00
|
|
|
SAL_INFO("xmlsecurity.helper","XSecController::setId: no signature");
|
2012-02-18 00:03:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
InternalSignatureInformation &isi = m_vInternalSignatureInformations.back();
|
2004-07-28 01:27:50 +00:00
|
|
|
isi.signatureInfor.ouSignatureId = ouId;
|
|
|
|
}
|
|
|
|
|
2017-07-27 10:03:53 +02:00
|
|
|
void XSecController::setPropertyId( OUString const & ouPropertyId )
|
2004-07-28 01:27:50 +00:00
|
|
|
{
|
2012-02-18 00:03:39 +01:00
|
|
|
if (m_vInternalSignatureInformations.empty())
|
|
|
|
{
|
2013-02-06 00:10:23 +02:00
|
|
|
SAL_INFO("xmlsecurity.helper","XSecController::setPropertyId: no signature");
|
2012-02-18 00:03:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
InternalSignatureInformation &isi = m_vInternalSignatureInformations.back();
|
2016-01-05 10:12:36 +01:00
|
|
|
|
|
|
|
if (isi.signatureInfor.ouPropertyId.isEmpty())
|
|
|
|
{
|
|
|
|
// <SignatureProperty> ID attribute is for the date.
|
|
|
|
isi.signatureInfor.ouPropertyId = ouPropertyId;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// <SignatureProperty> ID attribute is for the description.
|
|
|
|
isi.signatureInfor.ouDescriptionPropertyId = ouPropertyId;
|
|
|
|
}
|
2004-07-28 01:27:50 +00:00
|
|
|
}
|
|
|
|
|
2004-07-12 12:15:31 +00:00
|
|
|
/* public: for signature verify */
|
2013-04-07 12:06:47 +02:00
|
|
|
void XSecController::collectToVerify( const OUString& referenceId )
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2016-06-12 14:47:53 +02:00
|
|
|
/* SAL_WARN_IF( !m_xSAXEventKeeper.is(), "xmlsecurity", "the SAXEventKeeper is NULL" ); */
|
2004-07-12 12:15:31 +00:00
|
|
|
|
2016-10-24 12:10:27 +03:00
|
|
|
if ( m_eStatusOfSecurityComponents == InitializationState::INITIALIZED )
|
2004-07-12 12:15:31 +00:00
|
|
|
/*
|
|
|
|
* if all security components are ready, verify the signature.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
bool bJustChainingOn = false;
|
2018-09-12 17:01:48 +02:00
|
|
|
cssu::Reference< cssxs::XDocumentHandler > xHandler;
|
2004-07-12 12:15:31 +00:00
|
|
|
|
|
|
|
int i,j;
|
|
|
|
int sigNum = m_vInternalSignatureInformations.size();
|
|
|
|
|
|
|
|
for (i=0; i<sigNum; ++i)
|
|
|
|
{
|
|
|
|
InternalSignatureInformation& isi = m_vInternalSignatureInformations[i];
|
|
|
|
SignatureReferenceInformations& vReferenceInfors = isi.signatureInfor.vSignatureReferenceInfors;
|
|
|
|
int refNum = vReferenceInfors.size();
|
|
|
|
|
|
|
|
for (j=0; j<refNum; ++j)
|
|
|
|
{
|
|
|
|
SignatureReferenceInformation &refInfor = vReferenceInfors[j];
|
|
|
|
|
|
|
|
if (refInfor.ouURI == referenceId)
|
|
|
|
{
|
2017-10-25 09:14:24 +02:00
|
|
|
if (chainOn())
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
|
|
|
bJustChainingOn = true;
|
2015-11-10 10:29:43 +01:00
|
|
|
xHandler = m_xSAXEventKeeper->setNextHandler(nullptr);
|
2004-07-12 12:15:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sal_Int32 nKeeperId = m_xSAXEventKeeper->addSecurityElementCollector(
|
2016-04-20 17:21:57 +02:00
|
|
|
cssxc::sax::ElementMarkPriority_BEFOREMODIFY, false );
|
2004-07-12 12:15:31 +00:00
|
|
|
|
|
|
|
cssu::Reference<cssxc::sax::XReferenceCollector> xReferenceCollector
|
|
|
|
( isi.xReferenceResolvedListener, cssu::UNO_QUERY );
|
|
|
|
|
|
|
|
m_xSAXEventKeeper->setSecurityId(nKeeperId, isi.signatureInfor.nSecurityId);
|
2017-03-17 09:50:25 +01:00
|
|
|
m_xSAXEventKeeper->addReferenceResolvedListener( nKeeperId, isi.xReferenceResolvedListener);
|
2004-07-12 12:15:31 +00:00
|
|
|
xReferenceCollector->setReferenceId( nKeeperId );
|
|
|
|
|
|
|
|
isi.vKeeperIds[j] = nKeeperId;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( bJustChainingOn )
|
|
|
|
{
|
2017-03-17 09:50:25 +01:00
|
|
|
cssu::Reference< cssxs::XDocumentHandler > xSEKHandler(static_cast<cppu::OWeakObject*>(m_xSAXEventKeeper.get()), cssu::UNO_QUERY);
|
2004-07-12 12:15:31 +00:00
|
|
|
m_xSAXEventKeeper->setNextHandler(xHandler);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void XSecController::addSignature( sal_Int32 nSignatureId )
|
|
|
|
{
|
2016-06-13 09:21:03 +02:00
|
|
|
SAL_WARN_IF( !m_xSecParser.is(), "xmlsecurity.helper", "No XSecParser initialized" );
|
2004-07-12 12:15:31 +00:00
|
|
|
|
|
|
|
m_nReservedSignatureId = nSignatureId;
|
|
|
|
m_bVerifyCurrentSignature = true;
|
|
|
|
}
|
|
|
|
|
2017-04-21 08:17:42 +02:00
|
|
|
cssu::Reference< cssxs::XDocumentHandler > const & XSecController::createSignatureReader(XMLSignatureHelper& rXMLSignatureHelper, sal_Int32 nType)
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2016-01-12 18:54:29 +01:00
|
|
|
if (nType == embed::StorageFormats::OFOPXML)
|
2017-04-21 08:17:42 +02:00
|
|
|
m_xSecParser = new OOXMLSecParser(rXMLSignatureHelper, this);
|
2016-01-12 18:54:29 +01:00
|
|
|
else
|
2017-05-19 09:13:21 +02:00
|
|
|
m_xSecParser = new XSecParser(rXMLSignatureHelper, this);
|
2016-01-13 09:37:10 +01:00
|
|
|
cssu::Reference< cssl::XInitialization > xInitialization(m_xSecParser, uno::UNO_QUERY);
|
2004-07-12 12:15:31 +00:00
|
|
|
|
2017-10-06 09:19:04 +02:00
|
|
|
setSAXChainConnector(xInitialization);
|
2004-07-12 12:15:31 +00:00
|
|
|
|
2016-01-13 09:37:10 +01:00
|
|
|
return m_xSecParser;
|
2004-07-12 12:15:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void XSecController::releaseSignatureReader()
|
|
|
|
{
|
|
|
|
clearSAXChainConnector( );
|
2016-01-13 09:37:10 +01:00
|
|
|
m_xSecParser.clear();
|
2004-07-12 12:15:31 +00:00
|
|
|
}
|
|
|
|
|
2010-10-12 15:57:08 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|