update dev300-m58
[ooovba.git] / xmlsecurity / source / framework / signatureverifierimpl.cxx
blob22521c675fc1871a4c7b97052108e7ea8c96040d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: signatureverifierimpl.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmlsecurity.hxx"
34 #include "signatureverifierimpl.hxx"
35 #include <com/sun/star/xml/crypto/XXMLSignatureTemplate.hpp>
36 #include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39 namespace cssu = com::sun::star::uno;
40 namespace cssl = com::sun::star::lang;
41 namespace cssxc = com::sun::star::xml::crypto;
42 namespace cssxw = com::sun::star::xml::wrapper;
44 #define SERVICE_NAME "com.sun.star.xml.crypto.sax.SignatureVerifier"
45 #define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.SignatureVerifierImpl"
47 #define DECLARE_ASCII( SASCIIVALUE ) \
48 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SASCIIVALUE ) )
50 SignatureVerifierImpl::SignatureVerifierImpl( const cssu::Reference< cssl::XMultiServiceFactory >& rxMSF)
52 mxMSF = rxMSF;
55 SignatureVerifierImpl::~SignatureVerifierImpl()
59 bool SignatureVerifierImpl::checkReady() const
60 /****** SignatureVerifierImpl/checkReady *************************************
62 * NAME
63 * checkReady -- checks the conditions for the signature verification.
65 * SYNOPSIS
66 * bReady = checkReady( );
68 * FUNCTION
69 * checks whether all following conditions are satisfied:
70 * 1. the result listener is ready;
71 * 2. the SignatureEngine is ready.
73 * INPUTS
74 * empty
76 * RESULT
77 * bReady - true if all conditions are satisfied, false otherwise
79 * HISTORY
80 * 05.01.2004 - implemented
82 * AUTHOR
83 * Michael Mi
84 * Email: michael.mi@sun.com
85 ******************************************************************************/
87 return (m_xResultListener.is() && SignatureEngine::checkReady());
90 void SignatureVerifierImpl::notifyResultListener() const
91 throw (cssu::Exception, cssu::RuntimeException)
92 /****** SignatureVerifierImpl/notifyResultListener ***************************
94 * NAME
95 * notifyResultListener -- notifies the listener about the verify result.
97 * SYNOPSIS
98 * notifyResultListener( );
100 * FUNCTION
101 * see NAME.
103 * INPUTS
104 * empty
106 * RESULT
107 * empty
109 * HISTORY
110 * 05.01.2004 - implemented
112 * AUTHOR
113 * Michael Mi
114 * Email: michael.mi@sun.com
115 ******************************************************************************/
117 cssu::Reference< cssxc::sax::XSignatureVerifyResultListener >
118 xSignatureVerifyResultListener ( m_xResultListener , cssu::UNO_QUERY ) ;
120 xSignatureVerifyResultListener->signatureVerified( m_nSecurityId, m_nStatus );
123 void SignatureVerifierImpl::startEngine( const cssu::Reference<
124 cssxc::XXMLSignatureTemplate >&
125 xSignatureTemplate)
126 throw (cssu::Exception, cssu::RuntimeException)
127 /****** SignatureVerifierImpl/startEngine ************************************
129 * NAME
130 * startEngine -- verifies the signature.
132 * SYNOPSIS
133 * startEngine( xSignatureTemplate );
135 * FUNCTION
136 * see NAME.
138 * INPUTS
139 * xSignatureTemplate - the signature template (along with all referenced
140 * elements) to be verified.
142 * RESULT
143 * empty
145 * HISTORY
146 * 05.01.2004 - implemented
148 * AUTHOR
149 * Michael Mi
150 * Email: michael.mi@sun.com
151 ******************************************************************************/
153 cssu::Reference< cssxc::XXMLSignatureTemplate > xResultTemplate;
154 try
156 xResultTemplate = m_xXMLSignature->validate(xSignatureTemplate, m_xXMLSecurityContext);
157 m_nStatus = xResultTemplate->getStatus();
159 catch( cssu::Exception& )
161 m_nStatus = cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED;
165 /* XSignatureVerifyResultBroadcaster */
166 void SAL_CALL SignatureVerifierImpl::addSignatureVerifyResultListener(
167 const cssu::Reference< cssxc::sax::XSignatureVerifyResultListener >& listener )
168 throw (cssu::Exception, cssu::RuntimeException)
170 m_xResultListener = listener;
171 tryToPerform();
174 void SAL_CALL SignatureVerifierImpl::removeSignatureVerifyResultListener(
175 const cssu::Reference< cssxc::sax::XSignatureVerifyResultListener >&)
176 throw (cssu::RuntimeException)
180 /* XInitialization */
181 void SAL_CALL SignatureVerifierImpl::initialize(
182 const cssu::Sequence< cssu::Any >& aArguments )
183 throw (cssu::Exception, cssu::RuntimeException)
185 OSL_ASSERT(aArguments.getLength() == 5);
187 rtl::OUString ouTempString;
189 aArguments[0] >>= ouTempString;
190 m_nSecurityId = ouTempString.toInt32();
191 aArguments[1] >>= m_xSAXEventKeeper;
192 aArguments[2] >>= ouTempString;
193 m_nIdOfTemplateEC = ouTempString.toInt32();
194 aArguments[3] >>= m_xXMLSecurityContext;
195 aArguments[4] >>= m_xXMLSignature;
199 rtl::OUString SignatureVerifierImpl_getImplementationName ()
200 throw (cssu::RuntimeException)
202 return rtl::OUString(
203 RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
206 sal_Bool SAL_CALL SignatureVerifierImpl_supportsService( const rtl::OUString& ServiceName )
207 throw (cssu::RuntimeException)
209 return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ));
212 cssu::Sequence< rtl::OUString > SAL_CALL SignatureVerifierImpl_getSupportedServiceNames( )
213 throw (cssu::RuntimeException)
215 cssu::Sequence < rtl::OUString > aRet(1);
216 rtl::OUString* pArray = aRet.getArray();
217 pArray[0] = rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
218 return aRet;
220 #undef SERVICE_NAME
222 cssu::Reference< cssu::XInterface > SAL_CALL SignatureVerifierImpl_createInstance(
223 const cssu::Reference< cssl::XMultiServiceFactory >& rSMgr)
224 throw( cssu::Exception )
226 return (cppu::OWeakObject*) new SignatureVerifierImpl(rSMgr);
229 /* XServiceInfo */
230 rtl::OUString SAL_CALL SignatureVerifierImpl::getImplementationName( )
231 throw (cssu::RuntimeException)
233 return SignatureVerifierImpl_getImplementationName();
235 sal_Bool SAL_CALL SignatureVerifierImpl::supportsService( const rtl::OUString& rServiceName )
236 throw (cssu::RuntimeException)
238 return SignatureVerifierImpl_supportsService( rServiceName );
240 cssu::Sequence< rtl::OUString > SAL_CALL SignatureVerifierImpl::getSupportedServiceNames( )
241 throw (cssu::RuntimeException)
243 return SignatureVerifierImpl_getSupportedServiceNames();