1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: signaturecreatorimpl.cxx,v $
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
)
56 SignatureCreatorImpl::~SignatureCreatorImpl( )
60 bool SignatureCreatorImpl::checkReady() const
61 /****** SignatureCreatorImpl/checkReady **************************************
64 * checkReady -- checks the conditions for the signature generation.
67 * bReady = checkReady( );
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.
79 * bReady - true if all conditions are satisfied, false otherwise
82 * 05.01.2004 - implemented
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 *****************************
99 * notifyResultListener -- notifies the listener about the signature
103 * notifyResultListener( );
115 * 05.01.2004 - implemented
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
>&
131 throw (cssu::Exception
, cssu::RuntimeException
)
132 /****** SignatureCreatorImpl/startEngine *************************************
135 * startEngine -- generates the signature.
138 * startEngine( xSignatureTemplate );
141 * generates the signature element, then if succeeds, updates the link
142 * of old template element to the new signature element in
146 * xSignatureTemplate - the signature template (along with all referenced
147 * elements) to be signed.
153 * 05.01.2004 - implemented
157 * Email: michael.mi@sun.com
158 ******************************************************************************/
160 cssu::Reference
< cssxc::XXMLSignatureTemplate
> xResultTemplate
;
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 *****************************************
182 * clearUp -- clear up all resources used by the signature generation.
188 * cleaning resources up includes:
189 * 1. SignatureEngine's clearing up;
190 * 2. releases the Blocker for the signature template element.
199 * 05.01.2004 - implemented
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
)
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
;
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
) );
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
);
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();