1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_xmlsecurity.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <xsecctl.hxx>
32*cdf0e10cSrcweir #include <tools/debug.hxx>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XKeyCollector.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/ElementMarkPriority.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XReferenceResolvedBroadcaster.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XBlockerMonitor.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XReferenceCollector.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XSignatureCreationResultBroadcaster.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSource.hpp>
41*cdf0e10cSrcweir #include <rtl/uuid.h>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir #include <stdio.h>
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir namespace cssu = com::sun::star::uno;
46*cdf0e10cSrcweir namespace cssl = com::sun::star::lang;
47*cdf0e10cSrcweir namespace cssxc = com::sun::star::xml::crypto;
48*cdf0e10cSrcweir namespace cssxs = com::sun::star::xml::sax;
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir /* xml security framework components */
51*cdf0e10cSrcweir #define SIGNATURECREATOR_COMPONENT "com.sun.star.xml.crypto.sax.SignatureCreator"
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir /* protected: for signature generation */
54*cdf0e10cSrcweir rtl::OUString XSecController::createId()
55*cdf0e10cSrcweir {
56*cdf0e10cSrcweir 	cssu::Sequence< sal_Int8 > aSeq( 16 );
57*cdf0e10cSrcweir 	rtl_createUuid ((sal_uInt8 *)aSeq.getArray(), 0, sal_True);
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir 	char str[68]="ID_";
60*cdf0e10cSrcweir 	int length = 3;
61*cdf0e10cSrcweir 	for (int i=0; i<16; ++i)
62*cdf0e10cSrcweir 	{
63*cdf0e10cSrcweir 		length += sprintf(str+length, "%04x", (unsigned char)aSeq[i]);
64*cdf0e10cSrcweir 	}
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir 	return rtl::OUString::createFromAscii(str);
67*cdf0e10cSrcweir }
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir cssu::Reference< cssxc::sax::XReferenceResolvedListener > XSecController::prepareSignatureToWrite(
70*cdf0e10cSrcweir 	InternalSignatureInformation& internalSignatureInfor )
71*cdf0e10cSrcweir {
72*cdf0e10cSrcweir 	sal_Int32 nSecurityId = internalSignatureInfor.signatureInfor.nSecurityId;
73*cdf0e10cSrcweir 	SignatureReferenceInformations& vReferenceInfors = internalSignatureInfor.signatureInfor.vSignatureReferenceInfors;
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir 	sal_Int32 nIdOfSignatureElementCollector;
76*cdf0e10cSrcweir 	cssu::Reference< cssxc::sax::XReferenceResolvedListener > xReferenceResolvedListener;
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir 	nIdOfSignatureElementCollector =
79*cdf0e10cSrcweir 		m_xSAXEventKeeper->addSecurityElementCollector( cssxc::sax::ElementMarkPriority_AFTERMODIFY, sal_True );
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir 	m_xSAXEventKeeper->setSecurityId(nIdOfSignatureElementCollector, nSecurityId);
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir         /*
84*cdf0e10cSrcweir          * create a SignatureCreator
85*cdf0e10cSrcweir          */
86*cdf0e10cSrcweir 	cssu::Reference< cssl::XMultiComponentFactory > xMCF( mxCtx->getServiceManager() );
87*cdf0e10cSrcweir 	xReferenceResolvedListener = cssu::Reference< cssxc::sax::XReferenceResolvedListener >(
88*cdf0e10cSrcweir 		xMCF->createInstanceWithContext(
89*cdf0e10cSrcweir 			rtl::OUString::createFromAscii(SIGNATURECREATOR_COMPONENT), mxCtx),
90*cdf0e10cSrcweir 		cssu::UNO_QUERY);
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir 	cssu::Reference<cssl::XInitialization> xInitialization(xReferenceResolvedListener, cssu::UNO_QUERY);
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir 	cssu::Sequence<cssu::Any> args(5);
95*cdf0e10cSrcweir 	args[0] = cssu::makeAny(rtl::OUString::valueOf(nSecurityId));
96*cdf0e10cSrcweir 	args[1] = cssu::makeAny(m_xSAXEventKeeper);
97*cdf0e10cSrcweir 	args[2] = cssu::makeAny(rtl::OUString::valueOf(nIdOfSignatureElementCollector));
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir 	//i39448 : for nss, the internal module is used for signing, which needs to be improved later
100*cdf0e10cSrcweir 	sal_Int32 nEnvIndex = internalSignatureInfor.signatureInfor.nSecurityEnvironmentIndex;
101*cdf0e10cSrcweir 	if( nEnvIndex < 0 || nEnvIndex >= m_xSecurityContext->getSecurityEnvironmentNumber())
102*cdf0e10cSrcweir 	{// set defaultEnv
103*cdf0e10cSrcweir 		args[3] = cssu::makeAny(m_xSecurityContext->getSecurityEnvironment());
104*cdf0e10cSrcweir 	}
105*cdf0e10cSrcweir 	else
106*cdf0e10cSrcweir 	{
107*cdf0e10cSrcweir 		args[3] = cssu::makeAny(m_xSecurityContext->getSecurityEnvironmentByIndex(nEnvIndex));
108*cdf0e10cSrcweir 	}
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir 	args[4] = cssu::makeAny(m_xXMLSignature);
111*cdf0e10cSrcweir 	xInitialization->initialize(args);
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir 	sal_Int32 nBlockerId = m_xSAXEventKeeper->addBlocker();
114*cdf0e10cSrcweir 	m_xSAXEventKeeper->setSecurityId(nBlockerId, nSecurityId);
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir 	cssu::Reference<cssxc::sax::XBlockerMonitor> xBlockerMonitor(xReferenceResolvedListener, cssu::UNO_QUERY);
117*cdf0e10cSrcweir 	xBlockerMonitor->setBlockerId(nBlockerId);
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir 	cssu::Reference< cssxc::sax::XSignatureCreationResultBroadcaster >
120*cdf0e10cSrcweir 		xSignatureCreationResultBroadcaster(xReferenceResolvedListener, cssu::UNO_QUERY);
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 	xSignatureCreationResultBroadcaster->addSignatureCreationResultListener( this );
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir 	cssu::Reference<cssxc::sax::XReferenceResolvedBroadcaster>
125*cdf0e10cSrcweir 		xReferenceResolvedBroadcaster
126*cdf0e10cSrcweir 		(m_xSAXEventKeeper,
127*cdf0e10cSrcweir 		cssu::UNO_QUERY);
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir 	xReferenceResolvedBroadcaster->addReferenceResolvedListener(
130*cdf0e10cSrcweir 		nIdOfSignatureElementCollector,
131*cdf0e10cSrcweir 		xReferenceResolvedListener);
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir 	cssu::Reference<cssxc::sax::XReferenceCollector> xReferenceCollector
134*cdf0e10cSrcweir 		(xReferenceResolvedListener, cssu::UNO_QUERY);
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir 	int i;
137*cdf0e10cSrcweir 	int size = vReferenceInfors.size();
138*cdf0e10cSrcweir 	sal_Int32 nReferenceCount = 0;
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 	for(i=0; i<size; ++i)
141*cdf0e10cSrcweir 	{
142*cdf0e10cSrcweir 		sal_Int32 keeperId = internalSignatureInfor.vKeeperIds[i];
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir 		if ( keeperId != -1)
145*cdf0e10cSrcweir 		{
146*cdf0e10cSrcweir 			m_xSAXEventKeeper->setSecurityId(keeperId, nSecurityId);
147*cdf0e10cSrcweir 			xReferenceResolvedBroadcaster->addReferenceResolvedListener( keeperId, xReferenceResolvedListener);
148*cdf0e10cSrcweir 			xReferenceCollector->setReferenceId( keeperId );
149*cdf0e10cSrcweir 			nReferenceCount++;
150*cdf0e10cSrcweir 		}
151*cdf0e10cSrcweir 	}
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir 	xReferenceCollector->setReferenceCount( nReferenceCount );
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir 	/*
156*cdf0e10cSrcweir 	 * adds all URI binding
157*cdf0e10cSrcweir 	 */
158*cdf0e10cSrcweir 	cssu::Reference<cssxc::XUriBinding> xUriBinding
159*cdf0e10cSrcweir 		(xReferenceResolvedListener, cssu::UNO_QUERY);
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 	for(i=0; i<size; ++i)
162*cdf0e10cSrcweir 	{
163*cdf0e10cSrcweir 		const SignatureReferenceInformation& refInfor = vReferenceInfors[i];
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir 		cssu::Reference< com::sun::star::io::XInputStream > xInputStream
166*cdf0e10cSrcweir 			= getObjectInputStream( refInfor.ouURI );
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir 		if (xInputStream.is())
169*cdf0e10cSrcweir 		{
170*cdf0e10cSrcweir 			xUriBinding->setUriBinding(refInfor.ouURI,xInputStream);
171*cdf0e10cSrcweir 		}
172*cdf0e10cSrcweir 	}
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir 	cssu::Reference<cssxc::sax::XKeyCollector> keyCollector (xReferenceResolvedListener, cssu::UNO_QUERY);
175*cdf0e10cSrcweir 	keyCollector->setKeyId(0);
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir 	internalSignatureInfor.signatureInfor.ouSignatureId = createId();
178*cdf0e10cSrcweir 	internalSignatureInfor.signatureInfor.ouPropertyId = createId();
179*cdf0e10cSrcweir 	internalSignatureInfor.addReference(TYPE_SAMEDOCUMENT_REFERENCE, internalSignatureInfor.signatureInfor.ouPropertyId, -1 );
180*cdf0e10cSrcweir 	size++;
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir 	/*
183*cdf0e10cSrcweir 	 * replace both digestValues and signatueValue to " "
184*cdf0e10cSrcweir 	 */
185*cdf0e10cSrcweir 	for(i=0; i<size; ++i)
186*cdf0e10cSrcweir 	{
187*cdf0e10cSrcweir 		SignatureReferenceInformation& refInfor = vReferenceInfors[i];
188*cdf0e10cSrcweir 		refInfor.ouDigestValue = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CHAR_BLANK));
189*cdf0e10cSrcweir 	}
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir 	internalSignatureInfor.signatureInfor.ouSignatureValue = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CHAR_BLANK));
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 	return xReferenceResolvedListener;
194*cdf0e10cSrcweir }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir /* public: for signature generation */
197*cdf0e10cSrcweir void XSecController::collectToSign( sal_Int32 securityId, const rtl::OUString& referenceId )
198*cdf0e10cSrcweir {
199*cdf0e10cSrcweir 	/* DBG_ASSERT( m_xSAXEventKeeper.is(), "the SAXEventKeeper is NULL" ); */
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir 	chainOn(true);
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir 	if ( m_nStatusOfSecurityComponents == INITIALIZED )
204*cdf0e10cSrcweir 	/*
205*cdf0e10cSrcweir 	 * if all security components are ready, add a signature.
206*cdf0e10cSrcweir 	 */
207*cdf0e10cSrcweir 	{
208*cdf0e10cSrcweir 		sal_Int32 nKeeperId = m_xSAXEventKeeper->addSecurityElementCollector(
209*cdf0e10cSrcweir 			cssxc::sax::ElementMarkPriority_AFTERMODIFY, sal_False);
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir 		int index = findSignatureInfor( securityId );
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir 		if ( index == -1 )
214*cdf0e10cSrcweir 		{
215*cdf0e10cSrcweir 			InternalSignatureInformation isi(securityId, NULL);
216*cdf0e10cSrcweir 			isi.addReference(TYPE_SAMEDOCUMENT_REFERENCE, referenceId, nKeeperId );
217*cdf0e10cSrcweir 			m_vInternalSignatureInformations.push_back( isi );
218*cdf0e10cSrcweir 		}
219*cdf0e10cSrcweir 		else
220*cdf0e10cSrcweir 		{
221*cdf0e10cSrcweir 			m_vInternalSignatureInformations[index].addReference(TYPE_SAMEDOCUMENT_REFERENCE, referenceId, nKeeperId );
222*cdf0e10cSrcweir 		}
223*cdf0e10cSrcweir 	}
224*cdf0e10cSrcweir }
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir void XSecController::signAStream( sal_Int32 securityId, const rtl::OUString& uri, const rtl::OUString& /*objectURL*/, sal_Bool isBinary)
227*cdf0e10cSrcweir {
228*cdf0e10cSrcweir         sal_Int32 type = ((isBinary==sal_True)?TYPE_BINARYSTREAM_REFERENCE:TYPE_XMLSTREAM_REFERENCE);
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir 	int index = findSignatureInfor( securityId );
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir 	if (index == -1)
233*cdf0e10cSrcweir 	{
234*cdf0e10cSrcweir 		InternalSignatureInformation isi(securityId, NULL);
235*cdf0e10cSrcweir 		isi.addReference(type, uri, -1);
236*cdf0e10cSrcweir 		m_vInternalSignatureInformations.push_back( isi );
237*cdf0e10cSrcweir 	}
238*cdf0e10cSrcweir 	else
239*cdf0e10cSrcweir 	{
240*cdf0e10cSrcweir 		m_vInternalSignatureInformations[index].addReference(type, uri, -1);
241*cdf0e10cSrcweir 	}
242*cdf0e10cSrcweir }
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir void XSecController::setX509Certificate(
245*cdf0e10cSrcweir 	sal_Int32 nSecurityId,
246*cdf0e10cSrcweir 	const rtl::OUString& ouX509IssuerName,
247*cdf0e10cSrcweir 	const rtl::OUString& ouX509SerialNumber,
248*cdf0e10cSrcweir 	const rtl::OUString& ouX509Cert)
249*cdf0e10cSrcweir {
250*cdf0e10cSrcweir 	setX509Certificate(nSecurityId, -1, ouX509IssuerName, ouX509SerialNumber, ouX509Cert);
251*cdf0e10cSrcweir }
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir void XSecController::setX509Certificate(
254*cdf0e10cSrcweir 	sal_Int32 nSecurityId,
255*cdf0e10cSrcweir 	const sal_Int32	nSecurityEnvironmentIndex,
256*cdf0e10cSrcweir 	const rtl::OUString& ouX509IssuerName,
257*cdf0e10cSrcweir 	const rtl::OUString& ouX509SerialNumber,
258*cdf0e10cSrcweir 	const rtl::OUString& ouX509Cert)
259*cdf0e10cSrcweir {
260*cdf0e10cSrcweir 	int index = findSignatureInfor( nSecurityId );
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir 	if ( index == -1 )
263*cdf0e10cSrcweir 	{
264*cdf0e10cSrcweir 		InternalSignatureInformation isi(nSecurityId, NULL);
265*cdf0e10cSrcweir 		isi.signatureInfor.nSecurityEnvironmentIndex = nSecurityEnvironmentIndex;
266*cdf0e10cSrcweir 		isi.signatureInfor.ouX509IssuerName = ouX509IssuerName;
267*cdf0e10cSrcweir 		isi.signatureInfor.ouX509SerialNumber = ouX509SerialNumber;
268*cdf0e10cSrcweir 		isi.signatureInfor.ouX509Certificate = ouX509Cert;
269*cdf0e10cSrcweir 		m_vInternalSignatureInformations.push_back( isi );
270*cdf0e10cSrcweir 	}
271*cdf0e10cSrcweir 	else
272*cdf0e10cSrcweir 	{
273*cdf0e10cSrcweir 		SignatureInformation &si
274*cdf0e10cSrcweir 			= m_vInternalSignatureInformations[index].signatureInfor;
275*cdf0e10cSrcweir 		si.ouX509IssuerName = ouX509IssuerName;
276*cdf0e10cSrcweir 		si.ouX509SerialNumber = ouX509SerialNumber;
277*cdf0e10cSrcweir 		si.ouX509Certificate = ouX509Cert;
278*cdf0e10cSrcweir 		si.nSecurityEnvironmentIndex = nSecurityEnvironmentIndex;
279*cdf0e10cSrcweir 	}
280*cdf0e10cSrcweir }
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir void XSecController::setDate(
283*cdf0e10cSrcweir 	sal_Int32 nSecurityId,
284*cdf0e10cSrcweir 	const ::com::sun::star::util::DateTime& rDateTime )
285*cdf0e10cSrcweir {
286*cdf0e10cSrcweir 	int index = findSignatureInfor( nSecurityId );
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir 	if ( index == -1 )
289*cdf0e10cSrcweir 	{
290*cdf0e10cSrcweir 		InternalSignatureInformation isi(nSecurityId, NULL);
291*cdf0e10cSrcweir 		isi.signatureInfor.stDateTime = rDateTime;
292*cdf0e10cSrcweir 		m_vInternalSignatureInformations.push_back( isi );
293*cdf0e10cSrcweir 	}
294*cdf0e10cSrcweir 	else
295*cdf0e10cSrcweir 	{
296*cdf0e10cSrcweir 		SignatureInformation &si
297*cdf0e10cSrcweir 			= m_vInternalSignatureInformations[index].signatureInfor;
298*cdf0e10cSrcweir 		si.stDateTime = rDateTime;
299*cdf0e10cSrcweir 	}
300*cdf0e10cSrcweir }
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir bool XSecController::WriteSignature(
303*cdf0e10cSrcweir 	const cssu::Reference<cssxs::XDocumentHandler>& xDocumentHandler )
304*cdf0e10cSrcweir {
305*cdf0e10cSrcweir 	bool rc = false;
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir 	DBG_ASSERT( xDocumentHandler.is(), "I really need a document handler!" );
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir 	/*
310*cdf0e10cSrcweir 	 * chain the SAXEventKeeper to the SAX chain
311*cdf0e10cSrcweir 	 */
312*cdf0e10cSrcweir 	chainOn(true);
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir 	if ( m_nStatusOfSecurityComponents == INITIALIZED )
315*cdf0e10cSrcweir 	/*
316*cdf0e10cSrcweir 	 * if all security components are ready, add the signature
317*cdf0e10cSrcweir 	 * stream.
318*cdf0e10cSrcweir 	 */
319*cdf0e10cSrcweir 	{
320*cdf0e10cSrcweir 		m_bIsSAXEventKeeperSticky = true;
321*cdf0e10cSrcweir 		m_xSAXEventKeeper->setNextHandler(xDocumentHandler);
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir 		try
324*cdf0e10cSrcweir 		{
325*cdf0e10cSrcweir 			/*
326*cdf0e10cSrcweir 			 * export the signature template
327*cdf0e10cSrcweir 			 */
328*cdf0e10cSrcweir 			cssu::Reference<cssxs::XDocumentHandler> xSEKHandler( m_xSAXEventKeeper,cssu::UNO_QUERY);
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir 			int i;
331*cdf0e10cSrcweir 			int sigNum = m_vInternalSignatureInformations.size();
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir 			for (i=0; i<sigNum; ++i)
334*cdf0e10cSrcweir 			{
335*cdf0e10cSrcweir 				InternalSignatureInformation &isi = m_vInternalSignatureInformations[i];
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir 				/*
338*cdf0e10cSrcweir 				 * prepare the signature creator
339*cdf0e10cSrcweir 				 */
340*cdf0e10cSrcweir 				isi.xReferenceResolvedListener
341*cdf0e10cSrcweir 					= prepareSignatureToWrite( isi );
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir 				exportSignature( xSEKHandler, isi.signatureInfor );
344*cdf0e10cSrcweir 			}
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir 			m_bIsSAXEventKeeperSticky = false;
347*cdf0e10cSrcweir 			chainOff();
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir 			rc = true;
350*cdf0e10cSrcweir 		}
351*cdf0e10cSrcweir 		catch( cssxs::SAXException& )
352*cdf0e10cSrcweir 		{
353*cdf0e10cSrcweir 			m_pErrorMessage = ERROR_SAXEXCEPTIONDURINGCREATION;
354*cdf0e10cSrcweir 		}
355*cdf0e10cSrcweir 		catch( com::sun::star::io::IOException& )
356*cdf0e10cSrcweir 		{
357*cdf0e10cSrcweir 			m_pErrorMessage = ERROR_IOEXCEPTIONDURINGCREATION;
358*cdf0e10cSrcweir 		}
359*cdf0e10cSrcweir 		catch( cssu::Exception& )
360*cdf0e10cSrcweir 		{
361*cdf0e10cSrcweir 			m_pErrorMessage = ERROR_EXCEPTIONDURINGCREATION;
362*cdf0e10cSrcweir 		}
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir 		m_xSAXEventKeeper->setNextHandler( NULL );
365*cdf0e10cSrcweir 		m_bIsSAXEventKeeperSticky = false;
366*cdf0e10cSrcweir 	}
367*cdf0e10cSrcweir 	else
368*cdf0e10cSrcweir 	{
369*cdf0e10cSrcweir 		m_pErrorMessage = ERROR_CANNOTCREATEXMLSECURITYCOMPONENT;
370*cdf0e10cSrcweir 	}
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir 	return rc;
373*cdf0e10cSrcweir }
374*cdf0e10cSrcweir 
375