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
)
53 SignatureCreatorImpl::~SignatureCreatorImpl( )
57 bool SignatureCreatorImpl::checkReady() const
58 /****** SignatureCreatorImpl/checkReady **************************************
61 * checkReady -- checks the conditions for the signature generation.
64 * bReady = checkReady( );
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.
76 * bReady - true if all conditions are satisfied, false otherwise
79 * 05.01.2004 - implemented
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 *****************************
96 * notifyResultListener -- notifies the listener about the signature
100 * notifyResultListener( );
112 * 05.01.2004 - implemented
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
>&
128 throw (cssu::Exception
, cssu::RuntimeException
)
129 /****** SignatureCreatorImpl/startEngine *************************************
132 * startEngine -- generates the signature.
135 * startEngine( xSignatureTemplate );
138 * generates the signature element, then if succeeds, updates the link
139 * of old template element to the new signature element in
143 * xSignatureTemplate - the signature template (along with all referenced
144 * elements) to be signed.
150 * 05.01.2004 - implemented
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 *****************************************
179 * clearUp -- clear up all resources used by the signature generation.
185 * cleaning resources up includes:
186 * 1. SignatureEngine's clearing up;
187 * 2. releases the Blocker for the signature template element.
196 * 05.01.2004 - implemented
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
)
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
;
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
) );
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
);
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();