1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski *
3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file
5*b1cdbd2cSJim Jagielski * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file
7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski *
11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski *
13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the
17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski * under the License.
19*b1cdbd2cSJim Jagielski *
20*b1cdbd2cSJim Jagielski *************************************************************/
21*b1cdbd2cSJim Jagielski
22*b1cdbd2cSJim Jagielski
23*b1cdbd2cSJim Jagielski
24*b1cdbd2cSJim Jagielski // MARKER(update_precomp.py): autogen include statement, do not remove
25*b1cdbd2cSJim Jagielski #include "precompiled_xmlsecurity.hxx"
26*b1cdbd2cSJim Jagielski
27*b1cdbd2cSJim Jagielski #include "signaturecreatorimpl.hxx"
28*b1cdbd2cSJim Jagielski #include <com/sun/star/xml/crypto/XXMLSignatureTemplate.hpp>
29*b1cdbd2cSJim Jagielski #include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
30*b1cdbd2cSJim Jagielski #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31*b1cdbd2cSJim Jagielski
32*b1cdbd2cSJim Jagielski namespace cssu = com::sun::star::uno;
33*b1cdbd2cSJim Jagielski namespace cssl = com::sun::star::lang;
34*b1cdbd2cSJim Jagielski namespace cssxc = com::sun::star::xml::crypto;
35*b1cdbd2cSJim Jagielski namespace cssxw = com::sun::star::xml::wrapper;
36*b1cdbd2cSJim Jagielski
37*b1cdbd2cSJim Jagielski #define SERVICE_NAME "com.sun.star.xml.crypto.sax.SignatureCreator"
38*b1cdbd2cSJim Jagielski #define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.SignatureCreatorImpl"
39*b1cdbd2cSJim Jagielski
40*b1cdbd2cSJim Jagielski #define DECLARE_ASCII( SASCIIVALUE ) \
41*b1cdbd2cSJim Jagielski rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SASCIIVALUE ) )
42*b1cdbd2cSJim Jagielski
SignatureCreatorImpl(const cssu::Reference<cssl::XMultiServiceFactory> & rxMSF)43*b1cdbd2cSJim Jagielski SignatureCreatorImpl::SignatureCreatorImpl( const cssu::Reference< cssl::XMultiServiceFactory >& rxMSF )
44*b1cdbd2cSJim Jagielski :m_nIdOfBlocker(-1)
45*b1cdbd2cSJim Jagielski {
46*b1cdbd2cSJim Jagielski mxMSF = rxMSF;
47*b1cdbd2cSJim Jagielski }
48*b1cdbd2cSJim Jagielski
~SignatureCreatorImpl()49*b1cdbd2cSJim Jagielski SignatureCreatorImpl::~SignatureCreatorImpl( )
50*b1cdbd2cSJim Jagielski {
51*b1cdbd2cSJim Jagielski }
52*b1cdbd2cSJim Jagielski
checkReady() const53*b1cdbd2cSJim Jagielski bool SignatureCreatorImpl::checkReady() const
54*b1cdbd2cSJim Jagielski /****** SignatureCreatorImpl/checkReady **************************************
55*b1cdbd2cSJim Jagielski *
56*b1cdbd2cSJim Jagielski * NAME
57*b1cdbd2cSJim Jagielski * checkReady -- checks the conditions for the signature generation.
58*b1cdbd2cSJim Jagielski *
59*b1cdbd2cSJim Jagielski * SYNOPSIS
60*b1cdbd2cSJim Jagielski * bReady = checkReady( );
61*b1cdbd2cSJim Jagielski *
62*b1cdbd2cSJim Jagielski * FUNCTION
63*b1cdbd2cSJim Jagielski * checks whether all following conditions are satisfied:
64*b1cdbd2cSJim Jagielski * 1. the result listener is ready;
65*b1cdbd2cSJim Jagielski * 2. the id of the template blocker is known;
66*b1cdbd2cSJim Jagielski * 3. the SignatureEngine is ready.
67*b1cdbd2cSJim Jagielski *
68*b1cdbd2cSJim Jagielski * INPUTS
69*b1cdbd2cSJim Jagielski * empty
70*b1cdbd2cSJim Jagielski *
71*b1cdbd2cSJim Jagielski * RESULT
72*b1cdbd2cSJim Jagielski * bReady - true if all conditions are satisfied, false otherwise
73*b1cdbd2cSJim Jagielski *
74*b1cdbd2cSJim Jagielski * HISTORY
75*b1cdbd2cSJim Jagielski * 05.01.2004 - implemented
76*b1cdbd2cSJim Jagielski *
77*b1cdbd2cSJim Jagielski * AUTHOR
78*b1cdbd2cSJim Jagielski * Michael Mi
79*b1cdbd2cSJim Jagielski * Email: michael.mi@sun.com
80*b1cdbd2cSJim Jagielski ******************************************************************************/
81*b1cdbd2cSJim Jagielski {
82*b1cdbd2cSJim Jagielski return (m_xResultListener.is() &&
83*b1cdbd2cSJim Jagielski (m_nIdOfBlocker != -1) &&
84*b1cdbd2cSJim Jagielski SignatureEngine::checkReady());
85*b1cdbd2cSJim Jagielski }
86*b1cdbd2cSJim Jagielski
notifyResultListener() const87*b1cdbd2cSJim Jagielski void SignatureCreatorImpl::notifyResultListener() const
88*b1cdbd2cSJim Jagielski throw (cssu::Exception, cssu::RuntimeException)
89*b1cdbd2cSJim Jagielski /****** SignatureCreatorImpl/notifyResultListener *****************************
90*b1cdbd2cSJim Jagielski *
91*b1cdbd2cSJim Jagielski * NAME
92*b1cdbd2cSJim Jagielski * notifyResultListener -- notifies the listener about the signature
93*b1cdbd2cSJim Jagielski * creation result.
94*b1cdbd2cSJim Jagielski *
95*b1cdbd2cSJim Jagielski * SYNOPSIS
96*b1cdbd2cSJim Jagielski * notifyResultListener( );
97*b1cdbd2cSJim Jagielski *
98*b1cdbd2cSJim Jagielski * FUNCTION
99*b1cdbd2cSJim Jagielski * see NAME.
100*b1cdbd2cSJim Jagielski *
101*b1cdbd2cSJim Jagielski * INPUTS
102*b1cdbd2cSJim Jagielski * empty
103*b1cdbd2cSJim Jagielski *
104*b1cdbd2cSJim Jagielski * RESULT
105*b1cdbd2cSJim Jagielski * empty
106*b1cdbd2cSJim Jagielski *
107*b1cdbd2cSJim Jagielski * HISTORY
108*b1cdbd2cSJim Jagielski * 05.01.2004 - implemented
109*b1cdbd2cSJim Jagielski *
110*b1cdbd2cSJim Jagielski * AUTHOR
111*b1cdbd2cSJim Jagielski * Michael Mi
112*b1cdbd2cSJim Jagielski * Email: michael.mi@sun.com
113*b1cdbd2cSJim Jagielski ******************************************************************************/
114*b1cdbd2cSJim Jagielski {
115*b1cdbd2cSJim Jagielski cssu::Reference< cssxc::sax::XSignatureCreationResultListener >
116*b1cdbd2cSJim Jagielski xSignatureCreationResultListener ( m_xResultListener , cssu::UNO_QUERY ) ;
117*b1cdbd2cSJim Jagielski
118*b1cdbd2cSJim Jagielski xSignatureCreationResultListener->signatureCreated( m_nSecurityId, m_nStatus );
119*b1cdbd2cSJim Jagielski }
120*b1cdbd2cSJim Jagielski
startEngine(const cssu::Reference<cssxc::XXMLSignatureTemplate> & xSignatureTemplate)121*b1cdbd2cSJim Jagielski void SignatureCreatorImpl::startEngine( const cssu::Reference<
122*b1cdbd2cSJim Jagielski cssxc::XXMLSignatureTemplate >&
123*b1cdbd2cSJim Jagielski xSignatureTemplate)
124*b1cdbd2cSJim Jagielski throw (cssu::Exception, cssu::RuntimeException)
125*b1cdbd2cSJim Jagielski /****** SignatureCreatorImpl/startEngine *************************************
126*b1cdbd2cSJim Jagielski *
127*b1cdbd2cSJim Jagielski * NAME
128*b1cdbd2cSJim Jagielski * startEngine -- generates the signature.
129*b1cdbd2cSJim Jagielski *
130*b1cdbd2cSJim Jagielski * SYNOPSIS
131*b1cdbd2cSJim Jagielski * startEngine( xSignatureTemplate );
132*b1cdbd2cSJim Jagielski *
133*b1cdbd2cSJim Jagielski * FUNCTION
134*b1cdbd2cSJim Jagielski * generates the signature element, then if succeeds, updates the link
135*b1cdbd2cSJim Jagielski * of old template element to the new signature element in
136*b1cdbd2cSJim Jagielski * SAXEventKeeper.
137*b1cdbd2cSJim Jagielski *
138*b1cdbd2cSJim Jagielski * INPUTS
139*b1cdbd2cSJim Jagielski * xSignatureTemplate - the signature template (along with all referenced
140*b1cdbd2cSJim Jagielski * elements) to be signed.
141*b1cdbd2cSJim Jagielski *
142*b1cdbd2cSJim Jagielski * RESULT
143*b1cdbd2cSJim Jagielski * empty
144*b1cdbd2cSJim Jagielski *
145*b1cdbd2cSJim Jagielski * HISTORY
146*b1cdbd2cSJim Jagielski * 05.01.2004 - implemented
147*b1cdbd2cSJim Jagielski *
148*b1cdbd2cSJim Jagielski * AUTHOR
149*b1cdbd2cSJim Jagielski * Michael Mi
150*b1cdbd2cSJim Jagielski * Email: michael.mi@sun.com
151*b1cdbd2cSJim Jagielski ******************************************************************************/
152*b1cdbd2cSJim Jagielski {
153*b1cdbd2cSJim Jagielski cssu::Reference< cssxc::XXMLSignatureTemplate > xResultTemplate;
154*b1cdbd2cSJim Jagielski try
155*b1cdbd2cSJim Jagielski {
156*b1cdbd2cSJim Jagielski xResultTemplate = m_xXMLSignature->generate(xSignatureTemplate, m_xSecurityEnvironment);
157*b1cdbd2cSJim Jagielski m_nStatus = xResultTemplate->getStatus();
158*b1cdbd2cSJim Jagielski }
159*b1cdbd2cSJim Jagielski catch( cssu::Exception& )
160*b1cdbd2cSJim Jagielski {
161*b1cdbd2cSJim Jagielski m_nStatus = cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED;
162*b1cdbd2cSJim Jagielski }
163*b1cdbd2cSJim Jagielski
164*b1cdbd2cSJim Jagielski if (m_nStatus == cssxc::SecurityOperationStatus_OPERATION_SUCCEEDED)
165*b1cdbd2cSJim Jagielski {
166*b1cdbd2cSJim Jagielski cssu::Reference < cssxw::XXMLElementWrapper > xResultSignature = xResultTemplate->getTemplate();
167*b1cdbd2cSJim Jagielski m_xSAXEventKeeper->setElement(m_nIdOfTemplateEC, xResultSignature);
168*b1cdbd2cSJim Jagielski }
169*b1cdbd2cSJim Jagielski }
170*b1cdbd2cSJim Jagielski
clearUp() const171*b1cdbd2cSJim Jagielski void SignatureCreatorImpl::clearUp() const
172*b1cdbd2cSJim Jagielski /****** SignatureCreatorImpl/clearUp *****************************************
173*b1cdbd2cSJim Jagielski *
174*b1cdbd2cSJim Jagielski * NAME
175*b1cdbd2cSJim Jagielski * clearUp -- clear up all resources used by the signature generation.
176*b1cdbd2cSJim Jagielski *
177*b1cdbd2cSJim Jagielski * SYNOPSIS
178*b1cdbd2cSJim Jagielski * clearUp( );
179*b1cdbd2cSJim Jagielski *
180*b1cdbd2cSJim Jagielski * FUNCTION
181*b1cdbd2cSJim Jagielski * cleaning resources up includes:
182*b1cdbd2cSJim Jagielski * 1. SignatureEngine's clearing up;
183*b1cdbd2cSJim Jagielski * 2. releases the Blocker for the signature template element.
184*b1cdbd2cSJim Jagielski *
185*b1cdbd2cSJim Jagielski * INPUTS
186*b1cdbd2cSJim Jagielski * empty
187*b1cdbd2cSJim Jagielski *
188*b1cdbd2cSJim Jagielski * RESULT
189*b1cdbd2cSJim Jagielski * empty
190*b1cdbd2cSJim Jagielski *
191*b1cdbd2cSJim Jagielski * HISTORY
192*b1cdbd2cSJim Jagielski * 05.01.2004 - implemented
193*b1cdbd2cSJim Jagielski *
194*b1cdbd2cSJim Jagielski * AUTHOR
195*b1cdbd2cSJim Jagielski * Michael Mi
196*b1cdbd2cSJim Jagielski * Email: michael.mi@sun.com
197*b1cdbd2cSJim Jagielski ******************************************************************************/
198*b1cdbd2cSJim Jagielski {
199*b1cdbd2cSJim Jagielski SignatureEngine::clearUp();
200*b1cdbd2cSJim Jagielski
201*b1cdbd2cSJim Jagielski if (m_nIdOfBlocker != -1)
202*b1cdbd2cSJim Jagielski {
203*b1cdbd2cSJim Jagielski m_xSAXEventKeeper->removeBlocker(m_nIdOfBlocker);
204*b1cdbd2cSJim Jagielski }
205*b1cdbd2cSJim Jagielski }
206*b1cdbd2cSJim Jagielski
207*b1cdbd2cSJim Jagielski /* XBlockerMonitor */
setBlockerId(sal_Int32 id)208*b1cdbd2cSJim Jagielski void SAL_CALL SignatureCreatorImpl::setBlockerId( sal_Int32 id )
209*b1cdbd2cSJim Jagielski throw (cssu::Exception, cssu::RuntimeException)
210*b1cdbd2cSJim Jagielski {
211*b1cdbd2cSJim Jagielski m_nIdOfBlocker = id;
212*b1cdbd2cSJim Jagielski tryToPerform();
213*b1cdbd2cSJim Jagielski }
214*b1cdbd2cSJim Jagielski
215*b1cdbd2cSJim Jagielski /* XSignatureCreationResultBroadcaster */
addSignatureCreationResultListener(const cssu::Reference<cssxc::sax::XSignatureCreationResultListener> & listener)216*b1cdbd2cSJim Jagielski void SAL_CALL SignatureCreatorImpl::addSignatureCreationResultListener(
217*b1cdbd2cSJim Jagielski const cssu::Reference< cssxc::sax::XSignatureCreationResultListener >& listener )
218*b1cdbd2cSJim Jagielski throw (cssu::Exception, cssu::RuntimeException)
219*b1cdbd2cSJim Jagielski {
220*b1cdbd2cSJim Jagielski m_xResultListener = listener;
221*b1cdbd2cSJim Jagielski tryToPerform();
222*b1cdbd2cSJim Jagielski }
223*b1cdbd2cSJim Jagielski
removeSignatureCreationResultListener(const cssu::Reference<cssxc::sax::XSignatureCreationResultListener> &)224*b1cdbd2cSJim Jagielski void SAL_CALL SignatureCreatorImpl::removeSignatureCreationResultListener(
225*b1cdbd2cSJim Jagielski const cssu::Reference< cssxc::sax::XSignatureCreationResultListener >&)
226*b1cdbd2cSJim Jagielski throw (cssu::RuntimeException)
227*b1cdbd2cSJim Jagielski {
228*b1cdbd2cSJim Jagielski }
229*b1cdbd2cSJim Jagielski
230*b1cdbd2cSJim Jagielski /* XInitialization */
initialize(const cssu::Sequence<cssu::Any> & aArguments)231*b1cdbd2cSJim Jagielski void SAL_CALL SignatureCreatorImpl::initialize( const cssu::Sequence< cssu::Any >& aArguments )
232*b1cdbd2cSJim Jagielski throw (cssu::Exception, cssu::RuntimeException)
233*b1cdbd2cSJim Jagielski {
234*b1cdbd2cSJim Jagielski OSL_ASSERT(aArguments.getLength() == 5);
235*b1cdbd2cSJim Jagielski
236*b1cdbd2cSJim Jagielski rtl::OUString ouTempString;
237*b1cdbd2cSJim Jagielski
238*b1cdbd2cSJim Jagielski aArguments[0] >>= ouTempString;
239*b1cdbd2cSJim Jagielski m_nSecurityId = ouTempString.toInt32();
240*b1cdbd2cSJim Jagielski aArguments[1] >>= m_xSAXEventKeeper;
241*b1cdbd2cSJim Jagielski aArguments[2] >>= ouTempString;
242*b1cdbd2cSJim Jagielski m_nIdOfTemplateEC = ouTempString.toInt32();
243*b1cdbd2cSJim Jagielski aArguments[3] >>= m_xSecurityEnvironment;
244*b1cdbd2cSJim Jagielski aArguments[4] >>= m_xXMLSignature;
245*b1cdbd2cSJim Jagielski }
246*b1cdbd2cSJim Jagielski
247*b1cdbd2cSJim Jagielski
SignatureCreatorImpl_getImplementationName()248*b1cdbd2cSJim Jagielski rtl::OUString SignatureCreatorImpl_getImplementationName ()
249*b1cdbd2cSJim Jagielski throw (cssu::RuntimeException)
250*b1cdbd2cSJim Jagielski {
251*b1cdbd2cSJim Jagielski return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
252*b1cdbd2cSJim Jagielski }
253*b1cdbd2cSJim Jagielski
SignatureCreatorImpl_supportsService(const rtl::OUString & ServiceName)254*b1cdbd2cSJim Jagielski sal_Bool SAL_CALL SignatureCreatorImpl_supportsService( const rtl::OUString& ServiceName )
255*b1cdbd2cSJim Jagielski throw (cssu::RuntimeException)
256*b1cdbd2cSJim Jagielski {
257*b1cdbd2cSJim Jagielski return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ));
258*b1cdbd2cSJim Jagielski }
259*b1cdbd2cSJim Jagielski
SignatureCreatorImpl_getSupportedServiceNames()260*b1cdbd2cSJim Jagielski cssu::Sequence< rtl::OUString > SAL_CALL SignatureCreatorImpl_getSupportedServiceNames( )
261*b1cdbd2cSJim Jagielski throw (cssu::RuntimeException)
262*b1cdbd2cSJim Jagielski {
263*b1cdbd2cSJim Jagielski cssu::Sequence < rtl::OUString > aRet(1);
264*b1cdbd2cSJim Jagielski rtl::OUString* pArray = aRet.getArray();
265*b1cdbd2cSJim Jagielski pArray[0] = rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
266*b1cdbd2cSJim Jagielski return aRet;
267*b1cdbd2cSJim Jagielski }
268*b1cdbd2cSJim Jagielski #undef SERVICE_NAME
269*b1cdbd2cSJim Jagielski
SignatureCreatorImpl_createInstance(const cssu::Reference<cssl::XMultiServiceFactory> & rSMgr)270*b1cdbd2cSJim Jagielski cssu::Reference< cssu::XInterface > SAL_CALL SignatureCreatorImpl_createInstance(
271*b1cdbd2cSJim Jagielski const cssu::Reference< cssl::XMultiServiceFactory >& rSMgr)
272*b1cdbd2cSJim Jagielski throw( cssu::Exception )
273*b1cdbd2cSJim Jagielski {
274*b1cdbd2cSJim Jagielski return (cppu::OWeakObject*) new SignatureCreatorImpl( rSMgr );
275*b1cdbd2cSJim Jagielski }
276*b1cdbd2cSJim Jagielski
277*b1cdbd2cSJim Jagielski /* XServiceInfo */
getImplementationName()278*b1cdbd2cSJim Jagielski rtl::OUString SAL_CALL SignatureCreatorImpl::getImplementationName( )
279*b1cdbd2cSJim Jagielski throw (cssu::RuntimeException)
280*b1cdbd2cSJim Jagielski {
281*b1cdbd2cSJim Jagielski return SignatureCreatorImpl_getImplementationName();
282*b1cdbd2cSJim Jagielski }
supportsService(const rtl::OUString & rServiceName)283*b1cdbd2cSJim Jagielski sal_Bool SAL_CALL SignatureCreatorImpl::supportsService( const rtl::OUString& rServiceName )
284*b1cdbd2cSJim Jagielski throw (cssu::RuntimeException)
285*b1cdbd2cSJim Jagielski {
286*b1cdbd2cSJim Jagielski return SignatureCreatorImpl_supportsService( rServiceName );
287*b1cdbd2cSJim Jagielski }
getSupportedServiceNames()288*b1cdbd2cSJim Jagielski cssu::Sequence< rtl::OUString > SAL_CALL SignatureCreatorImpl::getSupportedServiceNames( )
289*b1cdbd2cSJim Jagielski throw (cssu::RuntimeException)
290*b1cdbd2cSJim Jagielski {
291*b1cdbd2cSJim Jagielski return SignatureCreatorImpl_getSupportedServiceNames();
292*b1cdbd2cSJim Jagielski }
293*b1cdbd2cSJim Jagielski
294