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