2016-01-12 18:54:29 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* 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/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "ooxmlsecparser.hxx"
|
|
|
|
|
|
|
|
using namespace com::sun::star;
|
|
|
|
|
|
|
|
OOXMLSecParser::OOXMLSecParser(XSecController* pXSecController)
|
2016-01-14 09:27:30 +01:00
|
|
|
: m_pXSecController(pXSecController)
|
|
|
|
,m_bInDigestValue(false)
|
|
|
|
,m_bInSignatureValue(false)
|
|
|
|
,m_bInX509Certificate(false)
|
2016-01-19 17:18:04 +01:00
|
|
|
,m_bInMdssiValue(false)
|
2016-01-12 18:54:29 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
OOXMLSecParser::~OOXMLSecParser()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL OOXMLSecParser::startDocument() throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
|
|
|
|
{
|
2016-01-14 09:25:06 +01:00
|
|
|
if (m_xNextHandler.is())
|
|
|
|
m_xNextHandler->startDocument();
|
2016-01-12 18:54:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL OOXMLSecParser::endDocument() throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
|
|
|
|
{
|
2016-01-14 09:25:06 +01:00
|
|
|
if (m_xNextHandler.is())
|
|
|
|
m_xNextHandler->endDocument();
|
2016-01-12 18:54:29 +01:00
|
|
|
}
|
|
|
|
|
2016-01-13 11:22:07 +01:00
|
|
|
void SAL_CALL OOXMLSecParser::startElement(const OUString& rName, const uno::Reference<xml::sax::XAttributeList>& xAttribs)
|
2016-01-12 18:54:29 +01:00
|
|
|
throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
|
|
|
|
{
|
2016-01-13 11:22:07 +01:00
|
|
|
OUString aId = xAttribs->getValueByName("Id");
|
|
|
|
if (!aId.isEmpty())
|
|
|
|
m_pXSecController->collectToVerify(aId);
|
|
|
|
|
|
|
|
if (rName == "Signature")
|
|
|
|
{
|
2016-01-14 09:25:06 +01:00
|
|
|
m_pXSecController->addSignature();
|
2016-01-13 11:22:07 +01:00
|
|
|
if (!aId.isEmpty())
|
|
|
|
m_pXSecController->setId(aId);
|
|
|
|
}
|
2016-01-13 15:24:04 +01:00
|
|
|
else if (rName == "Reference")
|
|
|
|
{
|
|
|
|
OUString aURI = xAttribs->getValueByName("URI");
|
|
|
|
if (aURI.startsWith("#"))
|
|
|
|
m_pXSecController->addReference(aURI.copy(1));
|
|
|
|
// TODO else
|
|
|
|
}
|
2016-01-14 09:24:13 +01:00
|
|
|
else if (rName == "DigestValue")
|
|
|
|
{
|
|
|
|
m_aDigestValue.clear();
|
|
|
|
m_bInDigestValue = true;
|
|
|
|
}
|
2016-01-14 09:26:06 +01:00
|
|
|
else if (rName == "SignatureValue")
|
|
|
|
{
|
|
|
|
m_aSignatureValue.clear();
|
|
|
|
m_bInSignatureValue = true;
|
|
|
|
}
|
2016-01-14 09:27:30 +01:00
|
|
|
else if (rName == "X509Certificate")
|
|
|
|
{
|
|
|
|
m_aX509Certificate.clear();
|
|
|
|
m_bInX509Certificate = true;
|
|
|
|
}
|
2016-01-19 17:18:04 +01:00
|
|
|
else if (rName == "mdssi:Value")
|
|
|
|
{
|
|
|
|
m_aMdssiValue.clear();
|
|
|
|
m_bInMdssiValue = true;
|
|
|
|
}
|
2016-01-14 09:25:06 +01:00
|
|
|
|
|
|
|
if (m_xNextHandler.is())
|
|
|
|
m_xNextHandler->startElement(rName, xAttribs);
|
2016-01-12 18:54:29 +01:00
|
|
|
}
|
|
|
|
|
2016-01-13 11:25:12 +01:00
|
|
|
void SAL_CALL OOXMLSecParser::endElement(const OUString& rName) throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
|
2016-01-12 18:54:29 +01:00
|
|
|
{
|
2016-01-13 11:25:12 +01:00
|
|
|
if (rName == "SignedInfo")
|
|
|
|
m_pXSecController->setReferenceCount();
|
2016-01-13 15:24:04 +01:00
|
|
|
else if (rName == "Reference")
|
2016-01-14 09:24:13 +01:00
|
|
|
m_pXSecController->setDigestValue(m_aDigestValue);
|
|
|
|
else if (rName == "DigestValue")
|
|
|
|
m_bInDigestValue = false;
|
2016-01-14 09:26:06 +01:00
|
|
|
else if (rName == "SignatureValue")
|
|
|
|
{
|
|
|
|
m_pXSecController->setSignatureValue(m_aSignatureValue);
|
|
|
|
m_bInSignatureValue = false;
|
|
|
|
}
|
2016-01-14 09:27:30 +01:00
|
|
|
else if (rName == "X509Certificate")
|
|
|
|
{
|
|
|
|
m_pXSecController->setX509Certificate(m_aX509Certificate);
|
|
|
|
m_bInX509Certificate = false;
|
|
|
|
}
|
2016-01-19 17:18:04 +01:00
|
|
|
else if (rName == "mdssi:Value")
|
|
|
|
{
|
|
|
|
m_pXSecController->setDate(m_aMdssiValue);
|
|
|
|
m_bInMdssiValue = false;
|
|
|
|
}
|
2016-01-14 09:25:06 +01:00
|
|
|
|
|
|
|
if (m_xNextHandler.is())
|
|
|
|
m_xNextHandler->endElement(rName);
|
2016-01-12 18:54:29 +01:00
|
|
|
}
|
|
|
|
|
2016-01-14 09:24:13 +01:00
|
|
|
void SAL_CALL OOXMLSecParser::characters(const OUString& rChars) throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
|
2016-01-12 18:54:29 +01:00
|
|
|
{
|
2016-01-14 09:24:13 +01:00
|
|
|
if (m_bInDigestValue)
|
|
|
|
m_aDigestValue += rChars;
|
2016-01-14 09:26:06 +01:00
|
|
|
else if (m_bInSignatureValue)
|
|
|
|
m_aSignatureValue += rChars;
|
2016-01-14 09:27:30 +01:00
|
|
|
else if (m_bInX509Certificate)
|
|
|
|
m_aX509Certificate += rChars;
|
2016-01-19 17:18:04 +01:00
|
|
|
else if (m_bInMdssiValue)
|
|
|
|
m_aMdssiValue += rChars;
|
2016-01-14 09:25:06 +01:00
|
|
|
|
|
|
|
if (m_xNextHandler.is())
|
|
|
|
m_xNextHandler->characters(rChars);
|
2016-01-12 18:54:29 +01:00
|
|
|
}
|
|
|
|
|
2016-01-14 09:25:06 +01:00
|
|
|
void SAL_CALL OOXMLSecParser::ignorableWhitespace(const OUString& rWhitespace) throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
|
2016-01-12 18:54:29 +01:00
|
|
|
{
|
2016-01-14 09:25:06 +01:00
|
|
|
if (m_xNextHandler.is())
|
|
|
|
m_xNextHandler->ignorableWhitespace(rWhitespace);
|
2016-01-12 18:54:29 +01:00
|
|
|
}
|
|
|
|
|
2016-01-14 09:25:06 +01:00
|
|
|
void SAL_CALL OOXMLSecParser::processingInstruction(const OUString& rTarget, const OUString& rData) throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
|
2016-01-12 18:54:29 +01:00
|
|
|
{
|
2016-01-14 09:25:06 +01:00
|
|
|
if (m_xNextHandler.is())
|
|
|
|
m_xNextHandler->processingInstruction(rTarget, rData);
|
2016-01-12 18:54:29 +01:00
|
|
|
}
|
|
|
|
|
2016-01-14 09:25:06 +01:00
|
|
|
void SAL_CALL OOXMLSecParser::setDocumentLocator(const uno::Reference<xml::sax::XLocator>& xLocator) throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
|
2016-01-12 18:54:29 +01:00
|
|
|
{
|
2016-01-14 09:25:06 +01:00
|
|
|
if (m_xNextHandler.is())
|
|
|
|
m_xNextHandler->setDocumentLocator(xLocator);
|
2016-01-12 18:54:29 +01:00
|
|
|
}
|
|
|
|
|
2016-01-14 09:25:06 +01:00
|
|
|
void SAL_CALL OOXMLSecParser::initialize(const uno::Sequence<uno::Any>& rArguments) throw (uno::Exception, uno::RuntimeException, std::exception)
|
2016-01-12 18:54:29 +01:00
|
|
|
{
|
2016-01-14 09:25:06 +01:00
|
|
|
rArguments[0] >>= m_xNextHandler;
|
2016-01-12 18:54:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|