Bump version to 5.0-14
[LibreOffice.git] / xmlsecurity / source / framework / signatureverifierimpl.cxx
blob6ef0bedc79c30b021348a08df3d1c6247b8b25a9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "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( const cssu::Reference< css::uno::XComponentContext >& xContext)
36 : SignatureVerifierImpl_Base(xContext)
40 SignatureVerifierImpl::~SignatureVerifierImpl()
44 bool SignatureVerifierImpl::checkReady() const
45 /****** SignatureVerifierImpl/checkReady *************************************
47 * NAME
48 * checkReady -- checks the conditions for the signature verification.
50 * SYNOPSIS
51 * bReady = checkReady( );
53 * FUNCTION
54 * checks whether all following conditions are satisfied:
55 * 1. the result listener is ready;
56 * 2. the SignatureEngine is ready.
58 * INPUTS
59 * empty
61 * RESULT
62 * bReady - true if all conditions are satisfied, false otherwise
64 * AUTHOR
65 * Michael Mi
66 * Email: michael.mi@sun.com
67 ******************************************************************************/
69 return (m_xResultListener.is() && SignatureEngine::checkReady());
72 void SignatureVerifierImpl::notifyResultListener() const
73 throw (cssu::Exception, cssu::RuntimeException)
74 /****** SignatureVerifierImpl/notifyResultListener ***************************
76 * NAME
77 * notifyResultListener -- notifies the listener about the verify result.
79 * SYNOPSIS
80 * notifyResultListener( );
82 * FUNCTION
83 * see NAME.
85 * INPUTS
86 * empty
88 * RESULT
89 * empty
91 * AUTHOR
92 * Michael Mi
93 * Email: michael.mi@sun.com
94 ******************************************************************************/
96 cssu::Reference< cssxc::sax::XSignatureVerifyResultListener >
97 xSignatureVerifyResultListener ( m_xResultListener , cssu::UNO_QUERY ) ;
99 xSignatureVerifyResultListener->signatureVerified( m_nSecurityId, m_nStatus );
102 void SignatureVerifierImpl::startEngine( const cssu::Reference<
103 cssxc::XXMLSignatureTemplate >&
104 xSignatureTemplate)
105 throw (cssu::Exception, cssu::RuntimeException)
106 /****** SignatureVerifierImpl/startEngine ************************************
108 * NAME
109 * startEngine -- verifies the signature.
111 * SYNOPSIS
112 * startEngine( xSignatureTemplate );
114 * FUNCTION
115 * see NAME.
117 * INPUTS
118 * xSignatureTemplate - the signature template (along with all referenced
119 * elements) to be verified.
121 * RESULT
122 * empty
124 * AUTHOR
125 * Michael Mi
126 * Email: michael.mi@sun.com
127 ******************************************************************************/
129 cssu::Reference< cssxc::XXMLSignatureTemplate > xResultTemplate;
132 xResultTemplate = m_xXMLSignature->validate(xSignatureTemplate, m_xXMLSecurityContext);
133 m_nStatus = xResultTemplate->getStatus();
135 catch( cssu::Exception& )
137 m_nStatus = cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED;
141 /* XSignatureVerifyResultBroadcaster */
142 void SAL_CALL SignatureVerifierImpl::addSignatureVerifyResultListener(
143 const cssu::Reference< cssxc::sax::XSignatureVerifyResultListener >& listener )
144 throw (cssu::Exception, cssu::RuntimeException, std::exception)
146 m_xResultListener = listener;
147 tryToPerform();
150 void SAL_CALL SignatureVerifierImpl::removeSignatureVerifyResultListener(
151 const cssu::Reference< cssxc::sax::XSignatureVerifyResultListener >&)
152 throw (cssu::RuntimeException, std::exception)
156 /* XInitialization */
157 void SAL_CALL SignatureVerifierImpl::initialize(
158 const cssu::Sequence< cssu::Any >& aArguments )
159 throw (cssu::Exception, cssu::RuntimeException, std::exception)
161 OSL_ASSERT(aArguments.getLength() == 5);
163 OUString ouTempString;
165 aArguments[0] >>= ouTempString;
166 m_nSecurityId = ouTempString.toInt32();
167 aArguments[1] >>= m_xSAXEventKeeper;
168 aArguments[2] >>= ouTempString;
169 m_nIdOfTemplateEC = ouTempString.toInt32();
170 aArguments[3] >>= m_xXMLSecurityContext;
171 aArguments[4] >>= m_xXMLSignature;
175 OUString SignatureVerifierImpl_getImplementationName ()
176 throw (cssu::RuntimeException)
178 return OUString( IMPLEMENTATION_NAME );
181 cssu::Sequence< OUString > SAL_CALL SignatureVerifierImpl_getSupportedServiceNames( )
182 throw (cssu::RuntimeException)
184 cssu::Sequence < OUString > aRet(1);
185 OUString* pArray = aRet.getArray();
186 pArray[0] = "com.sun.star.xml.crypto.sax.SignatureVerifier";
187 return aRet;
190 cssu::Reference< cssu::XInterface > SAL_CALL SignatureVerifierImpl_createInstance(
191 const cssu::Reference< cssl::XMultiServiceFactory >& rSMgr)
192 throw( cssu::Exception )
194 return (cppu::OWeakObject*) new SignatureVerifierImpl( comphelper::getComponentContext(rSMgr) );
197 /* XServiceInfo */
198 OUString SAL_CALL SignatureVerifierImpl::getImplementationName( )
199 throw (cssu::RuntimeException, std::exception)
201 return SignatureVerifierImpl_getImplementationName();
204 sal_Bool SAL_CALL SignatureVerifierImpl::supportsService( const OUString& rServiceName )
205 throw (cssu::RuntimeException, std::exception)
207 return cppu::supportsService(this, rServiceName);
210 cssu::Sequence< OUString > SAL_CALL SignatureVerifierImpl::getSupportedServiceNames( )
211 throw (cssu::RuntimeException, std::exception)
213 return SignatureVerifierImpl_getSupportedServiceNames();
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */