1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <framework/signatureverifierimpl.hxx>
22 #include <com/sun/star/xml/crypto/XXMLSignatureTemplate.hpp>
23 #include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
24 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
25 #include <comphelper/processfactory.hxx>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <osl/diagnose.h>
29 namespace cssu
= com::sun::star::uno
;
30 namespace cssl
= com::sun::star::lang
;
31 namespace cssxc
= com::sun::star::xml::crypto
;
33 #define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.SignatureVerifierImpl"
35 SignatureVerifierImpl::SignatureVerifierImpl()
36 : SignatureVerifierImpl_Base()
40 SignatureVerifierImpl::~SignatureVerifierImpl()
44 bool SignatureVerifierImpl::checkReady() const
45 /****** SignatureVerifierImpl/checkReady *************************************
48 * checkReady -- checks the conditions for the signature verification.
51 * bReady = checkReady( );
54 * checks whether all following conditions are satisfied:
55 * 1. the result listener is ready;
56 * 2. the SignatureEngine is ready.
59 * bReady - true if all conditions are satisfied, false otherwise
60 ******************************************************************************/
62 return (m_xResultListener
.is() && SignatureEngine::checkReady());
65 void SignatureVerifierImpl::notifyResultListener() const
66 /****** SignatureVerifierImpl/notifyResultListener ***************************
69 * notifyResultListener -- notifies the listener about the verify result.
70 ******************************************************************************/
72 cssu::Reference
< cssxc::sax::XSignatureVerifyResultListener
>
73 xSignatureVerifyResultListener ( m_xResultListener
, cssu::UNO_QUERY
) ;
75 xSignatureVerifyResultListener
->signatureVerified( m_nSecurityId
, m_nStatus
);
78 void SignatureVerifierImpl::startEngine( const rtl::Reference
<XMLSignatureTemplateImpl
>& xSignatureTemplate
)
79 /****** SignatureVerifierImpl/startEngine ************************************
82 * startEngine -- verifies the signature.
85 * xSignatureTemplate - the signature template (along with all referenced
86 * elements) to be verified.
87 ******************************************************************************/
89 cssu::Reference
< cssxc::XXMLSignatureTemplate
> xResultTemplate
;
92 xResultTemplate
= m_xXMLSignature
->validate(css::uno::Reference
<css::xml::crypto::XXMLSignatureTemplate
>(xSignatureTemplate
.get()), m_xXMLSecurityContext
);
93 m_nStatus
= xResultTemplate
->getStatus();
95 catch( cssu::Exception
& )
97 m_nStatus
= cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED
;
101 /* XSignatureVerifyResultBroadcaster */
102 void SAL_CALL
SignatureVerifierImpl::addSignatureVerifyResultListener(
103 const cssu::Reference
< cssxc::sax::XSignatureVerifyResultListener
>& listener
)
105 m_xResultListener
= listener
;
109 void SAL_CALL
SignatureVerifierImpl::removeSignatureVerifyResultListener(
110 const cssu::Reference
< cssxc::sax::XSignatureVerifyResultListener
>&)
114 /* XInitialization */
115 void SAL_CALL
SignatureVerifierImpl::initialize(
116 const cssu::Sequence
< cssu::Any
>& aArguments
)
118 OSL_ASSERT(aArguments
.getLength() == 5);
120 OUString ouTempString
;
122 aArguments
[0] >>= ouTempString
;
123 m_nSecurityId
= ouTempString
.toInt32();
124 aArguments
[1] >>= m_xSAXEventKeeper
;
125 aArguments
[2] >>= ouTempString
;
126 m_nIdOfTemplateEC
= ouTempString
.toInt32();
127 aArguments
[3] >>= m_xXMLSecurityContext
;
128 aArguments
[4] >>= m_xXMLSignature
;
132 OUString
SignatureVerifierImpl_getImplementationName ()
134 return OUString( IMPLEMENTATION_NAME
);
137 cssu::Sequence
< OUString
> SAL_CALL
SignatureVerifierImpl_getSupportedServiceNames( )
139 cssu::Sequence
<OUString
> aRet
{ "com.sun.star.xml.crypto.sax.SignatureVerifier" };
144 OUString SAL_CALL
SignatureVerifierImpl::getImplementationName( )
146 return SignatureVerifierImpl_getImplementationName();
149 sal_Bool SAL_CALL
SignatureVerifierImpl::supportsService( const OUString
& rServiceName
)
151 return cppu::supportsService(this, rServiceName
);
154 cssu::Sequence
< OUString
> SAL_CALL
SignatureVerifierImpl::getSupportedServiceNames( )
156 return SignatureVerifierImpl_getSupportedServiceNames();
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */