1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "signaturecreatorimpl.hxx"
22 #include <com/sun/star/xml/crypto/XXMLSignatureTemplate.hpp>
23 #include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
24 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
25 #include <comphelper/processfactory.hxx>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <osl/diagnose.h>
29 using namespace com::sun::star::uno
;
30 namespace cssu
= com::sun::star::uno
;
31 namespace cssl
= com::sun::star::lang
;
32 namespace cssxc
= com::sun::star::xml::crypto
;
33 namespace cssxw
= com::sun::star::xml::wrapper
;
35 #define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.SignatureCreatorImpl"
37 SignatureCreatorImpl::SignatureCreatorImpl( const Reference
<XComponentContext
> & xContext
)
38 : SignatureCreatorImpl_Base(xContext
), m_nIdOfBlocker(-1)
42 SignatureCreatorImpl::~SignatureCreatorImpl( )
46 bool SignatureCreatorImpl::checkReady() const
47 /****** SignatureCreatorImpl/checkReady **************************************
50 * checkReady -- checks the conditions for the signature generation.
53 * bReady = checkReady( );
56 * checks whether all following conditions are satisfied:
57 * 1. the result listener is ready;
58 * 2. the id of the template blocker is known;
59 * 3. the SignatureEngine is ready.
65 * bReady - true if all conditions are satisfied, false otherwise
69 * Email: michael.mi@sun.com
70 ******************************************************************************/
72 return (m_xResultListener
.is() &&
73 (m_nIdOfBlocker
!= -1) &&
74 SignatureEngine::checkReady());
77 void SignatureCreatorImpl::notifyResultListener() const
78 throw (cssu::Exception
, cssu::RuntimeException
)
79 /****** SignatureCreatorImpl/notifyResultListener *****************************
82 * notifyResultListener -- notifies the listener about the signature
86 * notifyResultListener( );
99 * Email: michael.mi@sun.com
100 ******************************************************************************/
102 cssu::Reference
< cssxc::sax::XSignatureCreationResultListener
>
103 xSignatureCreationResultListener ( m_xResultListener
, cssu::UNO_QUERY
) ;
105 xSignatureCreationResultListener
->signatureCreated( m_nSecurityId
, m_nStatus
);
108 void SignatureCreatorImpl::startEngine( const cssu::Reference
<
109 cssxc::XXMLSignatureTemplate
>&
111 throw (cssu::Exception
, cssu::RuntimeException
)
112 /****** SignatureCreatorImpl/startEngine *************************************
115 * startEngine -- generates the signature.
118 * startEngine( xSignatureTemplate );
121 * generates the signature element, then if succeeds, updates the link
122 * of old template element to the new signature element in
126 * xSignatureTemplate - the signature template (along with all referenced
127 * elements) to be signed.
134 * Email: michael.mi@sun.com
135 ******************************************************************************/
137 cssu::Reference
< cssxc::XXMLSignatureTemplate
> xResultTemplate
;
140 xResultTemplate
= m_xXMLSignature
->generate(xSignatureTemplate
, m_xSecurityEnvironment
);
141 m_nStatus
= xResultTemplate
->getStatus();
143 catch( cssu::Exception
& )
145 m_nStatus
= cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED
;
148 if (m_nStatus
== cssxc::SecurityOperationStatus_OPERATION_SUCCEEDED
)
150 cssu::Reference
< cssxw::XXMLElementWrapper
> xResultSignature
= xResultTemplate
->getTemplate();
151 m_xSAXEventKeeper
->setElement(m_nIdOfTemplateEC
, xResultSignature
);
155 void SignatureCreatorImpl::clearUp() const
156 /****** SignatureCreatorImpl/clearUp *****************************************
159 * clearUp -- clear up all resources used by the signature generation.
165 * cleaning resources up includes:
166 * 1. SignatureEngine's clearing up;
167 * 2. releases the Blocker for the signature template element.
177 * Email: michael.mi@sun.com
178 ******************************************************************************/
180 SignatureEngine::clearUp();
182 if (m_nIdOfBlocker
!= -1)
184 m_xSAXEventKeeper
->removeBlocker(m_nIdOfBlocker
);
188 /* XBlockerMonitor */
189 void SAL_CALL
SignatureCreatorImpl::setBlockerId( sal_Int32 id
)
190 throw (cssu::Exception
, cssu::RuntimeException
, std::exception
)
196 /* XSignatureCreationResultBroadcaster */
197 void SAL_CALL
SignatureCreatorImpl::addSignatureCreationResultListener(
198 const cssu::Reference
< cssxc::sax::XSignatureCreationResultListener
>& listener
)
199 throw (cssu::Exception
, cssu::RuntimeException
, std::exception
)
201 m_xResultListener
= listener
;
205 void SAL_CALL
SignatureCreatorImpl::removeSignatureCreationResultListener(
206 const cssu::Reference
< cssxc::sax::XSignatureCreationResultListener
>&)
207 throw (cssu::RuntimeException
, std::exception
)
211 /* XInitialization */
212 void SAL_CALL
SignatureCreatorImpl::initialize( const cssu::Sequence
< cssu::Any
>& aArguments
)
213 throw (cssu::Exception
, cssu::RuntimeException
, std::exception
)
215 OSL_ASSERT(aArguments
.getLength() == 5);
217 OUString ouTempString
;
219 aArguments
[0] >>= ouTempString
;
220 m_nSecurityId
= ouTempString
.toInt32();
221 aArguments
[1] >>= m_xSAXEventKeeper
;
222 aArguments
[2] >>= ouTempString
;
223 m_nIdOfTemplateEC
= ouTempString
.toInt32();
224 aArguments
[3] >>= m_xSecurityEnvironment
;
225 aArguments
[4] >>= m_xXMLSignature
;
229 OUString
SignatureCreatorImpl_getImplementationName ()
230 throw (cssu::RuntimeException
)
232 return OUString ( IMPLEMENTATION_NAME
);
235 cssu::Sequence
< OUString
> SAL_CALL
SignatureCreatorImpl_getSupportedServiceNames( )
236 throw (cssu::RuntimeException
)
238 cssu::Sequence
< OUString
> aRet(1);
239 OUString
* pArray
= aRet
.getArray();
240 pArray
[0] = "com.sun.star.xml.crypto.sax.SignatureCreator";
244 cssu::Reference
< cssu::XInterface
> SAL_CALL
SignatureCreatorImpl_createInstance(
245 const cssu::Reference
< cssl::XMultiServiceFactory
>& xMSF
)
246 throw( cssu::Exception
)
248 return (cppu::OWeakObject
*) new SignatureCreatorImpl( comphelper::getComponentContext( xMSF
) );
252 OUString SAL_CALL
SignatureCreatorImpl::getImplementationName( )
253 throw (cssu::RuntimeException
, std::exception
)
255 return SignatureCreatorImpl_getImplementationName();
258 sal_Bool SAL_CALL
SignatureCreatorImpl::supportsService( const OUString
& rServiceName
)
259 throw (cssu::RuntimeException
, std::exception
)
261 return cppu::supportsService(this, rServiceName
);
264 cssu::Sequence
< OUString
> SAL_CALL
SignatureCreatorImpl::getSupportedServiceNames( )
265 throw (cssu::RuntimeException
, std::exception
)
267 return SignatureCreatorImpl_getSupportedServiceNames();
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */