1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmlsecurity.hxx"
31 #include "signatureverifierimpl.hxx"
32 #include <com/sun/star/xml/crypto/XXMLSignatureTemplate.hpp>
33 #include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
36 namespace cssu
= com::sun::star::uno
;
37 namespace cssl
= com::sun::star::lang
;
38 namespace cssxc
= com::sun::star::xml::crypto
;
39 namespace cssxw
= com::sun::star::xml::wrapper
;
41 #define SERVICE_NAME "com.sun.star.xml.crypto.sax.SignatureVerifier"
42 #define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.SignatureVerifierImpl"
44 #define DECLARE_ASCII( SASCIIVALUE ) \
45 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SASCIIVALUE ) )
47 SignatureVerifierImpl::SignatureVerifierImpl( const cssu::Reference
< cssl::XMultiServiceFactory
>& rxMSF
)
52 SignatureVerifierImpl::~SignatureVerifierImpl()
56 bool SignatureVerifierImpl::checkReady() const
57 /****** SignatureVerifierImpl/checkReady *************************************
60 * checkReady -- checks the conditions for the signature verification.
63 * bReady = checkReady( );
66 * checks whether all following conditions are satisfied:
67 * 1. the result listener is ready;
68 * 2. the SignatureEngine is ready.
74 * bReady - true if all conditions are satisfied, false otherwise
77 * 05.01.2004 - implemented
81 * Email: michael.mi@sun.com
82 ******************************************************************************/
84 return (m_xResultListener
.is() && SignatureEngine::checkReady());
87 void SignatureVerifierImpl::notifyResultListener() const
88 throw (cssu::Exception
, cssu::RuntimeException
)
89 /****** SignatureVerifierImpl/notifyResultListener ***************************
92 * notifyResultListener -- notifies the listener about the verify result.
95 * notifyResultListener( );
107 * 05.01.2004 - implemented
111 * Email: michael.mi@sun.com
112 ******************************************************************************/
114 cssu::Reference
< cssxc::sax::XSignatureVerifyResultListener
>
115 xSignatureVerifyResultListener ( m_xResultListener
, cssu::UNO_QUERY
) ;
117 xSignatureVerifyResultListener
->signatureVerified( m_nSecurityId
, m_nStatus
);
120 void SignatureVerifierImpl::startEngine( const cssu::Reference
<
121 cssxc::XXMLSignatureTemplate
>&
123 throw (cssu::Exception
, cssu::RuntimeException
)
124 /****** SignatureVerifierImpl/startEngine ************************************
127 * startEngine -- verifies the signature.
130 * startEngine( xSignatureTemplate );
136 * xSignatureTemplate - the signature template (along with all referenced
137 * elements) to be verified.
143 * 05.01.2004 - implemented
147 * Email: michael.mi@sun.com
148 ******************************************************************************/
150 cssu::Reference
< cssxc::XXMLSignatureTemplate
> xResultTemplate
;
153 xResultTemplate
= m_xXMLSignature
->validate(xSignatureTemplate
, m_xXMLSecurityContext
);
154 m_nStatus
= xResultTemplate
->getStatus();
156 catch( cssu::Exception
& )
158 m_nStatus
= cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED
;
162 /* XSignatureVerifyResultBroadcaster */
163 void SAL_CALL
SignatureVerifierImpl::addSignatureVerifyResultListener(
164 const cssu::Reference
< cssxc::sax::XSignatureVerifyResultListener
>& listener
)
165 throw (cssu::Exception
, cssu::RuntimeException
)
167 m_xResultListener
= listener
;
171 void SAL_CALL
SignatureVerifierImpl::removeSignatureVerifyResultListener(
172 const cssu::Reference
< cssxc::sax::XSignatureVerifyResultListener
>&)
173 throw (cssu::RuntimeException
)
177 /* XInitialization */
178 void SAL_CALL
SignatureVerifierImpl::initialize(
179 const cssu::Sequence
< cssu::Any
>& aArguments
)
180 throw (cssu::Exception
, cssu::RuntimeException
)
182 OSL_ASSERT(aArguments
.getLength() == 5);
184 rtl::OUString ouTempString
;
186 aArguments
[0] >>= ouTempString
;
187 m_nSecurityId
= ouTempString
.toInt32();
188 aArguments
[1] >>= m_xSAXEventKeeper
;
189 aArguments
[2] >>= ouTempString
;
190 m_nIdOfTemplateEC
= ouTempString
.toInt32();
191 aArguments
[3] >>= m_xXMLSecurityContext
;
192 aArguments
[4] >>= m_xXMLSignature
;
196 rtl::OUString
SignatureVerifierImpl_getImplementationName ()
197 throw (cssu::RuntimeException
)
199 return rtl::OUString(
200 RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME
) );
203 sal_Bool SAL_CALL
SignatureVerifierImpl_supportsService( const rtl::OUString
& ServiceName
)
204 throw (cssu::RuntimeException
)
206 return ServiceName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME
));
209 cssu::Sequence
< rtl::OUString
> SAL_CALL
SignatureVerifierImpl_getSupportedServiceNames( )
210 throw (cssu::RuntimeException
)
212 cssu::Sequence
< rtl::OUString
> aRet(1);
213 rtl::OUString
* pArray
= aRet
.getArray();
214 pArray
[0] = rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME
) );
219 cssu::Reference
< cssu::XInterface
> SAL_CALL
SignatureVerifierImpl_createInstance(
220 const cssu::Reference
< cssl::XMultiServiceFactory
>& rSMgr
)
221 throw( cssu::Exception
)
223 return (cppu::OWeakObject
*) new SignatureVerifierImpl(rSMgr
);
227 rtl::OUString SAL_CALL
SignatureVerifierImpl::getImplementationName( )
228 throw (cssu::RuntimeException
)
230 return SignatureVerifierImpl_getImplementationName();
232 sal_Bool SAL_CALL
SignatureVerifierImpl::supportsService( const rtl::OUString
& rServiceName
)
233 throw (cssu::RuntimeException
)
235 return SignatureVerifierImpl_supportsService( rServiceName
);
237 cssu::Sequence
< rtl::OUString
> SAL_CALL
SignatureVerifierImpl::getSupportedServiceNames( )
238 throw (cssu::RuntimeException
)
240 return SignatureVerifierImpl_getSupportedServiceNames();