Update ooo320-m1
[ooovba.git] / xmlsecurity / source / framework / signaturecreatorimpl.cxx
blob36f193619c91cec92c0b1da1f74d6d59b54f1f63
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: signaturecreatorimpl.cxx,v $
10 * $Revision: 1.8 $
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 "signaturecreatorimpl.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.SignatureCreator"
45 #define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.SignatureCreatorImpl"
47 #define DECLARE_ASCII( SASCIIVALUE ) \
48 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SASCIIVALUE ) )
50 SignatureCreatorImpl::SignatureCreatorImpl( const cssu::Reference< cssl::XMultiServiceFactory >& rxMSF )
51 :m_nIdOfBlocker(-1)
53 mxMSF = rxMSF;
56 SignatureCreatorImpl::~SignatureCreatorImpl( )
60 bool SignatureCreatorImpl::checkReady() const
61 /****** SignatureCreatorImpl/checkReady **************************************
63 * NAME
64 * checkReady -- checks the conditions for the signature generation.
66 * SYNOPSIS
67 * bReady = checkReady( );
69 * FUNCTION
70 * checks whether all following conditions are satisfied:
71 * 1. the result listener is ready;
72 * 2. the id of the template blocker is known;
73 * 3. the SignatureEngine is ready.
75 * INPUTS
76 * empty
78 * RESULT
79 * bReady - true if all conditions are satisfied, false otherwise
81 * HISTORY
82 * 05.01.2004 - implemented
84 * AUTHOR
85 * Michael Mi
86 * Email: michael.mi@sun.com
87 ******************************************************************************/
89 return (m_xResultListener.is() &&
90 (m_nIdOfBlocker != -1) &&
91 SignatureEngine::checkReady());
94 void SignatureCreatorImpl::notifyResultListener() const
95 throw (cssu::Exception, cssu::RuntimeException)
96 /****** SignatureCreatorImpl/notifyResultListener *****************************
98 * NAME
99 * notifyResultListener -- notifies the listener about the signature
100 * creation result.
102 * SYNOPSIS
103 * notifyResultListener( );
105 * FUNCTION
106 * see NAME.
108 * INPUTS
109 * empty
111 * RESULT
112 * empty
114 * HISTORY
115 * 05.01.2004 - implemented
117 * AUTHOR
118 * Michael Mi
119 * Email: michael.mi@sun.com
120 ******************************************************************************/
122 cssu::Reference< cssxc::sax::XSignatureCreationResultListener >
123 xSignatureCreationResultListener ( m_xResultListener , cssu::UNO_QUERY ) ;
125 xSignatureCreationResultListener->signatureCreated( m_nSecurityId, m_nStatus );
128 void SignatureCreatorImpl::startEngine( const cssu::Reference<
129 cssxc::XXMLSignatureTemplate >&
130 xSignatureTemplate)
131 throw (cssu::Exception, cssu::RuntimeException)
132 /****** SignatureCreatorImpl/startEngine *************************************
134 * NAME
135 * startEngine -- generates the signature.
137 * SYNOPSIS
138 * startEngine( xSignatureTemplate );
140 * FUNCTION
141 * generates the signature element, then if succeeds, updates the link
142 * of old template element to the new signature element in
143 * SAXEventKeeper.
145 * INPUTS
146 * xSignatureTemplate - the signature template (along with all referenced
147 * elements) to be signed.
149 * RESULT
150 * empty
152 * HISTORY
153 * 05.01.2004 - implemented
155 * AUTHOR
156 * Michael Mi
157 * Email: michael.mi@sun.com
158 ******************************************************************************/
160 cssu::Reference< cssxc::XXMLSignatureTemplate > xResultTemplate;
161 try
163 xResultTemplate = m_xXMLSignature->generate(xSignatureTemplate, m_xSecurityEnvironment);
164 m_nStatus = xResultTemplate->getStatus();
166 catch( cssu::Exception& )
168 m_nStatus = cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED;
171 if (m_nStatus == cssxc::SecurityOperationStatus_OPERATION_SUCCEEDED)
173 cssu::Reference < cssxw::XXMLElementWrapper > xResultSignature = xResultTemplate->getTemplate();
174 m_xSAXEventKeeper->setElement(m_nIdOfTemplateEC, xResultSignature);
178 void SignatureCreatorImpl::clearUp() const
179 /****** SignatureCreatorImpl/clearUp *****************************************
181 * NAME
182 * clearUp -- clear up all resources used by the signature generation.
184 * SYNOPSIS
185 * clearUp( );
187 * FUNCTION
188 * cleaning resources up includes:
189 * 1. SignatureEngine's clearing up;
190 * 2. releases the Blocker for the signature template element.
192 * INPUTS
193 * empty
195 * RESULT
196 * empty
198 * HISTORY
199 * 05.01.2004 - implemented
201 * AUTHOR
202 * Michael Mi
203 * Email: michael.mi@sun.com
204 ******************************************************************************/
206 SignatureEngine::clearUp();
208 if (m_nIdOfBlocker != -1)
210 m_xSAXEventKeeper->removeBlocker(m_nIdOfBlocker);
214 /* XBlockerMonitor */
215 void SAL_CALL SignatureCreatorImpl::setBlockerId( sal_Int32 id )
216 throw (cssu::Exception, cssu::RuntimeException)
218 m_nIdOfBlocker = id;
219 tryToPerform();
222 /* XSignatureCreationResultBroadcaster */
223 void SAL_CALL SignatureCreatorImpl::addSignatureCreationResultListener(
224 const cssu::Reference< cssxc::sax::XSignatureCreationResultListener >& listener )
225 throw (cssu::Exception, cssu::RuntimeException)
227 m_xResultListener = listener;
228 tryToPerform();
231 void SAL_CALL SignatureCreatorImpl::removeSignatureCreationResultListener(
232 const cssu::Reference< cssxc::sax::XSignatureCreationResultListener >&)
233 throw (cssu::RuntimeException)
237 /* XInitialization */
238 void SAL_CALL SignatureCreatorImpl::initialize( const cssu::Sequence< cssu::Any >& aArguments )
239 throw (cssu::Exception, cssu::RuntimeException)
241 OSL_ASSERT(aArguments.getLength() == 5);
243 rtl::OUString ouTempString;
245 aArguments[0] >>= ouTempString;
246 m_nSecurityId = ouTempString.toInt32();
247 aArguments[1] >>= m_xSAXEventKeeper;
248 aArguments[2] >>= ouTempString;
249 m_nIdOfTemplateEC = ouTempString.toInt32();
250 aArguments[3] >>= m_xSecurityEnvironment;
251 aArguments[4] >>= m_xXMLSignature;
255 rtl::OUString SignatureCreatorImpl_getImplementationName ()
256 throw (cssu::RuntimeException)
258 return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
261 sal_Bool SAL_CALL SignatureCreatorImpl_supportsService( const rtl::OUString& ServiceName )
262 throw (cssu::RuntimeException)
264 return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ));
267 cssu::Sequence< rtl::OUString > SAL_CALL SignatureCreatorImpl_getSupportedServiceNames( )
268 throw (cssu::RuntimeException)
270 cssu::Sequence < rtl::OUString > aRet(1);
271 rtl::OUString* pArray = aRet.getArray();
272 pArray[0] = rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
273 return aRet;
275 #undef SERVICE_NAME
277 cssu::Reference< cssu::XInterface > SAL_CALL SignatureCreatorImpl_createInstance(
278 const cssu::Reference< cssl::XMultiServiceFactory >& rSMgr)
279 throw( cssu::Exception )
281 return (cppu::OWeakObject*) new SignatureCreatorImpl( rSMgr );
284 /* XServiceInfo */
285 rtl::OUString SAL_CALL SignatureCreatorImpl::getImplementationName( )
286 throw (cssu::RuntimeException)
288 return SignatureCreatorImpl_getImplementationName();
290 sal_Bool SAL_CALL SignatureCreatorImpl::supportsService( const rtl::OUString& rServiceName )
291 throw (cssu::RuntimeException)
293 return SignatureCreatorImpl_supportsService( rServiceName );
295 cssu::Sequence< rtl::OUString > SAL_CALL SignatureCreatorImpl::getSupportedServiceNames( )
296 throw (cssu::RuntimeException)
298 return SignatureCreatorImpl_getSupportedServiceNames();