merged tag ooo/OOO330_m14
[LibreOffice.git] / xmlsecurity / source / framework / signaturecreatorimpl.cxx
blob761b981237f6912f59c90e965def52a7d6a0f4dc
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 "signaturecreatorimpl.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.SignatureCreator"
42 #define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.SignatureCreatorImpl"
44 #define DECLARE_ASCII( SASCIIVALUE ) \
45 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SASCIIVALUE ) )
47 SignatureCreatorImpl::SignatureCreatorImpl( const cssu::Reference< cssl::XMultiServiceFactory >& rxMSF )
48 :m_nIdOfBlocker(-1)
50 mxMSF = rxMSF;
53 SignatureCreatorImpl::~SignatureCreatorImpl( )
57 bool SignatureCreatorImpl::checkReady() const
58 /****** SignatureCreatorImpl/checkReady **************************************
60 * NAME
61 * checkReady -- checks the conditions for the signature generation.
63 * SYNOPSIS
64 * bReady = checkReady( );
66 * FUNCTION
67 * checks whether all following conditions are satisfied:
68 * 1. the result listener is ready;
69 * 2. the id of the template blocker is known;
70 * 3. the SignatureEngine is ready.
72 * INPUTS
73 * empty
75 * RESULT
76 * bReady - true if all conditions are satisfied, false otherwise
78 * HISTORY
79 * 05.01.2004 - implemented
81 * AUTHOR
82 * Michael Mi
83 * Email: michael.mi@sun.com
84 ******************************************************************************/
86 return (m_xResultListener.is() &&
87 (m_nIdOfBlocker != -1) &&
88 SignatureEngine::checkReady());
91 void SignatureCreatorImpl::notifyResultListener() const
92 throw (cssu::Exception, cssu::RuntimeException)
93 /****** SignatureCreatorImpl/notifyResultListener *****************************
95 * NAME
96 * notifyResultListener -- notifies the listener about the signature
97 * creation result.
99 * SYNOPSIS
100 * notifyResultListener( );
102 * FUNCTION
103 * see NAME.
105 * INPUTS
106 * empty
108 * RESULT
109 * empty
111 * HISTORY
112 * 05.01.2004 - implemented
114 * AUTHOR
115 * Michael Mi
116 * Email: michael.mi@sun.com
117 ******************************************************************************/
119 cssu::Reference< cssxc::sax::XSignatureCreationResultListener >
120 xSignatureCreationResultListener ( m_xResultListener , cssu::UNO_QUERY ) ;
122 xSignatureCreationResultListener->signatureCreated( m_nSecurityId, m_nStatus );
125 void SignatureCreatorImpl::startEngine( const cssu::Reference<
126 cssxc::XXMLSignatureTemplate >&
127 xSignatureTemplate)
128 throw (cssu::Exception, cssu::RuntimeException)
129 /****** SignatureCreatorImpl/startEngine *************************************
131 * NAME
132 * startEngine -- generates the signature.
134 * SYNOPSIS
135 * startEngine( xSignatureTemplate );
137 * FUNCTION
138 * generates the signature element, then if succeeds, updates the link
139 * of old template element to the new signature element in
140 * SAXEventKeeper.
142 * INPUTS
143 * xSignatureTemplate - the signature template (along with all referenced
144 * elements) to be signed.
146 * RESULT
147 * empty
149 * HISTORY
150 * 05.01.2004 - implemented
152 * AUTHOR
153 * Michael Mi
154 * Email: michael.mi@sun.com
155 ******************************************************************************/
157 cssu::Reference< cssxc::XXMLSignatureTemplate > xResultTemplate;
160 xResultTemplate = m_xXMLSignature->generate(xSignatureTemplate, m_xSecurityEnvironment);
161 m_nStatus = xResultTemplate->getStatus();
163 catch( cssu::Exception& )
165 m_nStatus = cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED;
168 if (m_nStatus == cssxc::SecurityOperationStatus_OPERATION_SUCCEEDED)
170 cssu::Reference < cssxw::XXMLElementWrapper > xResultSignature = xResultTemplate->getTemplate();
171 m_xSAXEventKeeper->setElement(m_nIdOfTemplateEC, xResultSignature);
175 void SignatureCreatorImpl::clearUp() const
176 /****** SignatureCreatorImpl/clearUp *****************************************
178 * NAME
179 * clearUp -- clear up all resources used by the signature generation.
181 * SYNOPSIS
182 * clearUp( );
184 * FUNCTION
185 * cleaning resources up includes:
186 * 1. SignatureEngine's clearing up;
187 * 2. releases the Blocker for the signature template element.
189 * INPUTS
190 * empty
192 * RESULT
193 * empty
195 * HISTORY
196 * 05.01.2004 - implemented
198 * AUTHOR
199 * Michael Mi
200 * Email: michael.mi@sun.com
201 ******************************************************************************/
203 SignatureEngine::clearUp();
205 if (m_nIdOfBlocker != -1)
207 m_xSAXEventKeeper->removeBlocker(m_nIdOfBlocker);
211 /* XBlockerMonitor */
212 void SAL_CALL SignatureCreatorImpl::setBlockerId( sal_Int32 id )
213 throw (cssu::Exception, cssu::RuntimeException)
215 m_nIdOfBlocker = id;
216 tryToPerform();
219 /* XSignatureCreationResultBroadcaster */
220 void SAL_CALL SignatureCreatorImpl::addSignatureCreationResultListener(
221 const cssu::Reference< cssxc::sax::XSignatureCreationResultListener >& listener )
222 throw (cssu::Exception, cssu::RuntimeException)
224 m_xResultListener = listener;
225 tryToPerform();
228 void SAL_CALL SignatureCreatorImpl::removeSignatureCreationResultListener(
229 const cssu::Reference< cssxc::sax::XSignatureCreationResultListener >&)
230 throw (cssu::RuntimeException)
234 /* XInitialization */
235 void SAL_CALL SignatureCreatorImpl::initialize( const cssu::Sequence< cssu::Any >& aArguments )
236 throw (cssu::Exception, cssu::RuntimeException)
238 OSL_ASSERT(aArguments.getLength() == 5);
240 rtl::OUString ouTempString;
242 aArguments[0] >>= ouTempString;
243 m_nSecurityId = ouTempString.toInt32();
244 aArguments[1] >>= m_xSAXEventKeeper;
245 aArguments[2] >>= ouTempString;
246 m_nIdOfTemplateEC = ouTempString.toInt32();
247 aArguments[3] >>= m_xSecurityEnvironment;
248 aArguments[4] >>= m_xXMLSignature;
252 rtl::OUString SignatureCreatorImpl_getImplementationName ()
253 throw (cssu::RuntimeException)
255 return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
258 sal_Bool SAL_CALL SignatureCreatorImpl_supportsService( const rtl::OUString& ServiceName )
259 throw (cssu::RuntimeException)
261 return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ));
264 cssu::Sequence< rtl::OUString > SAL_CALL SignatureCreatorImpl_getSupportedServiceNames( )
265 throw (cssu::RuntimeException)
267 cssu::Sequence < rtl::OUString > aRet(1);
268 rtl::OUString* pArray = aRet.getArray();
269 pArray[0] = rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
270 return aRet;
272 #undef SERVICE_NAME
274 cssu::Reference< cssu::XInterface > SAL_CALL SignatureCreatorImpl_createInstance(
275 const cssu::Reference< cssl::XMultiServiceFactory >& rSMgr)
276 throw( cssu::Exception )
278 return (cppu::OWeakObject*) new SignatureCreatorImpl( rSMgr );
281 /* XServiceInfo */
282 rtl::OUString SAL_CALL SignatureCreatorImpl::getImplementationName( )
283 throw (cssu::RuntimeException)
285 return SignatureCreatorImpl_getImplementationName();
287 sal_Bool SAL_CALL SignatureCreatorImpl::supportsService( const rtl::OUString& rServiceName )
288 throw (cssu::RuntimeException)
290 return SignatureCreatorImpl_supportsService( rServiceName );
292 cssu::Sequence< rtl::OUString > SAL_CALL SignatureCreatorImpl::getSupportedServiceNames( )
293 throw (cssu::RuntimeException)
295 return SignatureCreatorImpl_getSupportedServiceNames();