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
10cdf0e10cSrcweir *
11*06b3ce53SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
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.
19cdf0e10cSrcweir *
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 <stdio.h>
28cdf0e10cSrcweir #include "helper.hxx"
29cdf0e10cSrcweir
30cdf0e10cSrcweir #include "libxml/tree.h"
31cdf0e10cSrcweir #include "libxml/parser.h"
32cdf0e10cSrcweir #ifndef XMLSEC_NO_XSLT
33cdf0e10cSrcweir #include "libxslt/xslt.h"
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir
36cdf0e10cSrcweir #include "securityenvironment_nssimpl.hxx"
37cdf0e10cSrcweir #include "xmlelementwrapper_xmlsecimpl.hxx"
38cdf0e10cSrcweir
39cdf0e10cSrcweir #include "nspr.h"
40cdf0e10cSrcweir #include "prtypes.h"
41cdf0e10cSrcweir
42cdf0e10cSrcweir #include "pk11func.h"
43cdf0e10cSrcweir #include "cert.h"
44cdf0e10cSrcweir #include "cryptohi.h"
45cdf0e10cSrcweir #include "certdb.h"
46cdf0e10cSrcweir #include "nss.h"
47cdf0e10cSrcweir
48cdf0e10cSrcweir #include "xmlsec/strings.h"
49cdf0e10cSrcweir #include "xmlsec/xmltree.h"
50cdf0e10cSrcweir
51cdf0e10cSrcweir #include <rtl/ustring.hxx>
52cdf0e10cSrcweir
53cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
54cdf0e10cSrcweir #include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
55cdf0e10cSrcweir #include <com/sun/star/xml/wrapper/XXMLDocumentWrapper.hpp>
56cdf0e10cSrcweir #include <com/sun/star/xml/crypto/XXMLSignature.hpp>
57cdf0e10cSrcweir #include <com/sun/star/xml/crypto/XXMLSignatureTemplate.hpp>
58cdf0e10cSrcweir #include <com/sun/star/xml/crypto/XXMLSecurityContext.hpp>
59cdf0e10cSrcweir #include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp>
60cdf0e10cSrcweir
61cdf0e10cSrcweir using namespace ::rtl ;
62cdf0e10cSrcweir using namespace ::cppu ;
63cdf0e10cSrcweir using namespace ::com::sun::star::uno ;
64cdf0e10cSrcweir using namespace ::com::sun::star::io ;
65cdf0e10cSrcweir using namespace ::com::sun::star::ucb ;
66cdf0e10cSrcweir using namespace ::com::sun::star::beans ;
67cdf0e10cSrcweir using namespace ::com::sun::star::document ;
68cdf0e10cSrcweir using namespace ::com::sun::star::lang ;
69cdf0e10cSrcweir using namespace ::com::sun::star::xml::wrapper ;
70cdf0e10cSrcweir using namespace ::com::sun::star::xml::crypto ;
71cdf0e10cSrcweir
72cdf0e10cSrcweir
main(int argc,char ** argv)73cdf0e10cSrcweir int SAL_CALL main( int argc, char **argv )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir CERTCertDBHandle* certHandle ;
76cdf0e10cSrcweir PK11SlotInfo* slot ;
77cdf0e10cSrcweir xmlDocPtr doc ;
78cdf0e10cSrcweir xmlNodePtr tplNode ;
79cdf0e10cSrcweir xmlNodePtr tarNode ;
80cdf0e10cSrcweir xmlAttrPtr idAttr ;
81cdf0e10cSrcweir xmlChar* idValue ;
82cdf0e10cSrcweir xmlAttrPtr uriAttr ;
83cdf0e10cSrcweir xmlChar* uriValue ;
84cdf0e10cSrcweir OUString* uri ;
85cdf0e10cSrcweir Reference< XUriBinding > xUriBinding ;
86cdf0e10cSrcweir FILE* dstFile ;
87cdf0e10cSrcweir
88cdf0e10cSrcweir if( argc != 5 ) {
89cdf0e10cSrcweir fprintf( stderr, "Usage: %s < CertDir > <file_url of template> <file_url of result> <rdb file>\n\n" , argv[0] ) ;
90cdf0e10cSrcweir return 1 ;
91cdf0e10cSrcweir }
92cdf0e10cSrcweir
93cdf0e10cSrcweir for( int hhh = 0 ; hhh < 10 ; hhh ++ ) {
94cdf0e10cSrcweir slot = NULL ;
95cdf0e10cSrcweir doc = NULL ;
96cdf0e10cSrcweir uri = NULL ;
97cdf0e10cSrcweir dstFile = NULL ;
98cdf0e10cSrcweir
99cdf0e10cSrcweir
100cdf0e10cSrcweir //Init libxml and libxslt libraries
101cdf0e10cSrcweir xmlInitParser();
102cdf0e10cSrcweir LIBXML_TEST_VERSION
103cdf0e10cSrcweir xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS;
104cdf0e10cSrcweir xmlSubstituteEntitiesDefault(1);
105cdf0e10cSrcweir
106cdf0e10cSrcweir #ifndef XMLSEC_NO_XSLT
107cdf0e10cSrcweir xmlIndentTreeOutput = 1;
108cdf0e10cSrcweir #endif // XMLSEC_NO_XSLT
109cdf0e10cSrcweir
110cdf0e10cSrcweir
111cdf0e10cSrcweir //Initialize NSPR and NSS
112cdf0e10cSrcweir PR_Init( PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 1 ) ;
113cdf0e10cSrcweir PK11_SetPasswordFunc( PriPK11PasswordFunc ) ;
114cdf0e10cSrcweir if( NSS_Init( argv[1] ) != SECSuccess ) {
115cdf0e10cSrcweir fprintf( stderr , "### cannot intialize NSS!\n" ) ;
116cdf0e10cSrcweir goto done ;
117cdf0e10cSrcweir }
118cdf0e10cSrcweir
119cdf0e10cSrcweir certHandle = CERT_GetDefaultCertDB() ;
120cdf0e10cSrcweir slot = PK11_GetInternalKeySlot() ;
121cdf0e10cSrcweir
122cdf0e10cSrcweir if( PK11_NeedLogin( slot ) ) {
123cdf0e10cSrcweir SECStatus nRet = PK11_Authenticate( slot, PR_TRUE, NULL );
124cdf0e10cSrcweir if( nRet != SECSuccess ) {
125cdf0e10cSrcweir fprintf( stderr , "### cannot authehticate the crypto token!\n" ) ;
126cdf0e10cSrcweir goto done ;
127cdf0e10cSrcweir }
128cdf0e10cSrcweir }
129cdf0e10cSrcweir
130cdf0e10cSrcweir //Load XML document
131cdf0e10cSrcweir doc = xmlParseFile( argv[2] ) ;
132cdf0e10cSrcweir if( doc == NULL || xmlDocGetRootElement( doc ) == NULL ) {
133cdf0e10cSrcweir fprintf( stderr , "### Cannot load template xml document!\n" ) ;
134cdf0e10cSrcweir goto done ;
135cdf0e10cSrcweir }
136cdf0e10cSrcweir
137cdf0e10cSrcweir //Find the signature template
138cdf0e10cSrcweir tplNode = xmlSecFindNode( xmlDocGetRootElement( doc ), xmlSecNodeSignature, xmlSecDSigNs ) ;
139cdf0e10cSrcweir if( tplNode == NULL ) {
140cdf0e10cSrcweir fprintf( stderr , "### Cannot find the signature template!\n" ) ;
141cdf0e10cSrcweir goto done ;
142cdf0e10cSrcweir }
143cdf0e10cSrcweir
144cdf0e10cSrcweir //Find the element with ID attribute
145cdf0e10cSrcweir //Here we only try to find the "document" node.
146cdf0e10cSrcweir tarNode = xmlSecFindNode( xmlDocGetRootElement( doc ), ( xmlChar* )"document", ( xmlChar* )"http://openoffice.org/2000/office" ) ;
147cdf0e10cSrcweir if( tarNode == NULL ) {
148cdf0e10cSrcweir tarNode = xmlSecFindNode( xmlDocGetRootElement( doc ), ( xmlChar* )"document", NULL ) ;
149cdf0e10cSrcweir }
150cdf0e10cSrcweir
151cdf0e10cSrcweir //Find the "id" attrbute in the element
152cdf0e10cSrcweir if( tarNode != NULL ) {
153cdf0e10cSrcweir if( ( idAttr = xmlHasProp( tarNode, ( xmlChar* )"id" ) ) != NULL ) {
154cdf0e10cSrcweir //NULL
155cdf0e10cSrcweir } else if( ( idAttr = xmlHasProp( tarNode, ( xmlChar* )"Id" ) ) != NULL ) {
156cdf0e10cSrcweir //NULL
157cdf0e10cSrcweir } else {
158cdf0e10cSrcweir idAttr = NULL ;
159cdf0e10cSrcweir }
160cdf0e10cSrcweir }
161cdf0e10cSrcweir
162cdf0e10cSrcweir //Add ID to DOM
163cdf0e10cSrcweir if( idAttr != NULL ) {
164cdf0e10cSrcweir idValue = xmlNodeListGetString( tarNode->doc, idAttr->children, 1 ) ;
165cdf0e10cSrcweir if( idValue == NULL ) {
166cdf0e10cSrcweir fprintf( stderr , "### the ID value is NULL!\n" ) ;
167cdf0e10cSrcweir goto done ;
168cdf0e10cSrcweir }
169cdf0e10cSrcweir
170cdf0e10cSrcweir if( xmlAddID( NULL, doc, idValue, idAttr ) == NULL ) {
171cdf0e10cSrcweir fprintf( stderr , "### Can not add the ID value!\n" ) ;
172cdf0e10cSrcweir goto done ;
173cdf0e10cSrcweir }
174cdf0e10cSrcweir }
175cdf0e10cSrcweir
176cdf0e10cSrcweir //Reference handler
177cdf0e10cSrcweir //Find the signature reference
178cdf0e10cSrcweir tarNode = xmlSecFindNode( tplNode, xmlSecNodeReference, xmlSecDSigNs ) ;
179cdf0e10cSrcweir if( tarNode == NULL ) {
180cdf0e10cSrcweir fprintf( stderr , "### Cannot find the signature reference!\n" ) ;
181cdf0e10cSrcweir goto done ;
182cdf0e10cSrcweir }
183cdf0e10cSrcweir
184cdf0e10cSrcweir //Find the "URI" attrbute in the reference
185cdf0e10cSrcweir uriAttr = xmlHasProp( tarNode, ( xmlChar* )"URI" ) ;
186cdf0e10cSrcweir if( tarNode == NULL ) {
187cdf0e10cSrcweir fprintf( stderr , "### Cannot find URI of the reference!\n" ) ;
188cdf0e10cSrcweir goto done ;
189cdf0e10cSrcweir }
190cdf0e10cSrcweir
191cdf0e10cSrcweir //Get the "URI" attrbute value
192cdf0e10cSrcweir uriValue = xmlNodeListGetString( tarNode->doc, uriAttr->children, 1 ) ;
193cdf0e10cSrcweir if( uriValue == NULL ) {
194cdf0e10cSrcweir fprintf( stderr , "### the URI value is NULL!\n" ) ;
195cdf0e10cSrcweir goto done ;
196cdf0e10cSrcweir }
197cdf0e10cSrcweir
198cdf0e10cSrcweir if( strchr( ( const char* )uriValue, '/' ) != NULL && strchr( ( const char* )uriValue, '#' ) == NULL ) {
199cdf0e10cSrcweir fprintf( stdout , "### Find a stream URI [%s]\n", uriValue ) ;
200cdf0e10cSrcweir // uri = new ::rtl::OUString( ( const sal_Unicode* )uriValue ) ;
201cdf0e10cSrcweir uri = new ::rtl::OUString( ( const sal_Char* )uriValue, xmlStrlen( uriValue ), RTL_TEXTENCODING_ASCII_US ) ;
202cdf0e10cSrcweir }
203cdf0e10cSrcweir
204cdf0e10cSrcweir if( uri != NULL ) {
205cdf0e10cSrcweir fprintf( stdout , "### Find the URI [%s]\n", OUStringToOString( *uri , RTL_TEXTENCODING_ASCII_US ).getStr() ) ;
206cdf0e10cSrcweir Reference< XInputStream > xStream = createStreamFromFile( *uri ) ;
207cdf0e10cSrcweir if( !xStream.is() ) {
208cdf0e10cSrcweir fprintf( stderr , "### Can not get the URI stream!\n" ) ;
209cdf0e10cSrcweir goto done ;
210cdf0e10cSrcweir }
211cdf0e10cSrcweir
212cdf0e10cSrcweir xUriBinding = new OUriBinding( *uri, xStream ) ;
213cdf0e10cSrcweir }
214cdf0e10cSrcweir
215cdf0e10cSrcweir try {
216cdf0e10cSrcweir Reference< XMultiComponentFactory > xManager = NULL ;
217cdf0e10cSrcweir Reference< XComponentContext > xContext = NULL ;
218cdf0e10cSrcweir
219cdf0e10cSrcweir xManager = serviceManager( xContext , OUString::createFromAscii( "local" ), OUString::createFromAscii( argv[4] ) ) ;
220cdf0e10cSrcweir OSL_ENSURE( xManager.is() ,
221cdf0e10cSrcweir "ServicesManager - "
222cdf0e10cSrcweir "Cannot get service manager" ) ;
223cdf0e10cSrcweir
224cdf0e10cSrcweir //Create signature template
225cdf0e10cSrcweir Reference< XInterface > element =
226cdf0e10cSrcweir xManager->createInstanceWithContext( OUString::createFromAscii( "com.sun.star.xml.security.bridge.xmlsec.XMLElementWrapper_XmlSecImpl" ) , xContext ) ;
227cdf0e10cSrcweir OSL_ENSURE( element.is() ,
228cdf0e10cSrcweir "Signer - "
229cdf0e10cSrcweir "Cannot get service instance of \"wrapper.XMLElementWrapper\"" ) ;
230cdf0e10cSrcweir
231cdf0e10cSrcweir Reference< XXMLElementWrapper > xElement( element , UNO_QUERY ) ;
232cdf0e10cSrcweir OSL_ENSURE( xElement.is() ,
233cdf0e10cSrcweir "Signer - "
234cdf0e10cSrcweir "Cannot get interface of \"XXMLElement\" from service \"xsec.XMLElement\"" ) ;
235cdf0e10cSrcweir
236cdf0e10cSrcweir Reference< XUnoTunnel > xEleTunnel( xElement , UNO_QUERY ) ;
237cdf0e10cSrcweir OSL_ENSURE( xEleTunnel.is() ,
238cdf0e10cSrcweir "Signer - "
239cdf0e10cSrcweir "Cannot get interface of \"XUnoTunnel\" from service \"xsec.XMLElement\"" ) ;
240cdf0e10cSrcweir
241cdf0e10cSrcweir XMLElementWrapper_XmlSecImpl* pElement = ( XMLElementWrapper_XmlSecImpl* )xEleTunnel->getSomething( XMLElementWrapper_XmlSecImpl::getUnoTunnelImplementationId() ) ;
242cdf0e10cSrcweir OSL_ENSURE( pElement != NULL ,
243cdf0e10cSrcweir "Signer - "
244cdf0e10cSrcweir "Cannot get implementation of \"xsec.XMLElement\"" ) ;
245cdf0e10cSrcweir
246cdf0e10cSrcweir //Set signature template
247cdf0e10cSrcweir pElement->setNativeElement( tplNode ) ;
248cdf0e10cSrcweir
249cdf0e10cSrcweir //Build XML Signature template
250cdf0e10cSrcweir Reference< XInterface > signtpl =
251cdf0e10cSrcweir xManager->createInstanceWithContext( OUString::createFromAscii( "com.sun.star.xml.crypto.XMLSignatureTemplate" ) , xContext ) ;
252cdf0e10cSrcweir OSL_ENSURE( signtpl.is() ,
253cdf0e10cSrcweir "Signer - "
254cdf0e10cSrcweir "Cannot get service instance of \"xsec.XMLSignatureTemplate\"" ) ;
255cdf0e10cSrcweir
256cdf0e10cSrcweir Reference< XXMLSignatureTemplate > xTemplate( signtpl , UNO_QUERY ) ;
257cdf0e10cSrcweir OSL_ENSURE( xTemplate.is() ,
258cdf0e10cSrcweir "Signer - "
259cdf0e10cSrcweir "Cannot get interface of \"XXMLSignatureTemplate\" from service \"xsec.XMLSignatureTemplate\"" ) ;
260cdf0e10cSrcweir
261cdf0e10cSrcweir //Import the signature template
262cdf0e10cSrcweir xTemplate->setTemplate( xElement ) ;
263cdf0e10cSrcweir
264cdf0e10cSrcweir //Import the URI/Stream binding
265cdf0e10cSrcweir if( xUriBinding.is() )
266cdf0e10cSrcweir xTemplate->setBinding( xUriBinding ) ;
267cdf0e10cSrcweir
268cdf0e10cSrcweir //Create security environment
269cdf0e10cSrcweir //Build Security Environment
270cdf0e10cSrcweir Reference< XInterface > xsecenv =
271cdf0e10cSrcweir xManager->createInstanceWithContext( OUString::createFromAscii("com.sun.star.xml.security.bridge.xmlsec.SecurityEnvironment_NssImpl"), xContext ) ;
272cdf0e10cSrcweir OSL_ENSURE( xsecenv.is() ,
273cdf0e10cSrcweir "Signer - "
274cdf0e10cSrcweir "Cannot get service instance of \"xsec.SecurityEnvironment\"" ) ;
275cdf0e10cSrcweir
276cdf0e10cSrcweir Reference< XSecurityEnvironment > xSecEnv( xsecenv , UNO_QUERY ) ;
277cdf0e10cSrcweir OSL_ENSURE( xSecEnv.is() ,
278cdf0e10cSrcweir "Signer - "
279cdf0e10cSrcweir "Cannot get interface of \"XSecurityEnvironment\" from service \"xsec.SecurityEnvironment\"" ) ;
280cdf0e10cSrcweir
281cdf0e10cSrcweir //Setup key slot and certDb
282cdf0e10cSrcweir Reference< XUnoTunnel > xEnvTunnel( xsecenv , UNO_QUERY ) ;
283cdf0e10cSrcweir OSL_ENSURE( xElement.is() ,
284cdf0e10cSrcweir "Signer - "
285cdf0e10cSrcweir "Cannot get interface of \"XUnoTunnel\" from service \"xsec.SecurityEnvironment\"" ) ;
286cdf0e10cSrcweir
287cdf0e10cSrcweir SecurityEnvironment_NssImpl* pSecEnv = ( SecurityEnvironment_NssImpl* )xEnvTunnel->getSomething( SecurityEnvironment_NssImpl::getUnoTunnelId() ) ;
288cdf0e10cSrcweir OSL_ENSURE( pSecEnv != NULL ,
289cdf0e10cSrcweir "Signer - "
290cdf0e10cSrcweir "Cannot get implementation of \"xsec.SecurityEnvironment\"" ) ;
291cdf0e10cSrcweir
292cdf0e10cSrcweir pSecEnv->setCryptoSlot( slot ) ;
293cdf0e10cSrcweir pSecEnv->setCertDb( certHandle ) ;
294cdf0e10cSrcweir
295cdf0e10cSrcweir //Build XML Security Context
296cdf0e10cSrcweir Reference< XInterface > xmlsecctx =
297cdf0e10cSrcweir xManager->createInstanceWithContext( OUString::createFromAscii("com.sun.star.xml.security.bridge.xmlsec.XMLSecurityContext_NssImpl"), xContext ) ;
298cdf0e10cSrcweir OSL_ENSURE( xsecenv.is() ,
299cdf0e10cSrcweir "Signer - "
300cdf0e10cSrcweir "Cannot get service instance of \"xsec.XMLSecurityContext\"" ) ;
301cdf0e10cSrcweir
302cdf0e10cSrcweir Reference< XXMLSecurityContext > xSecCtx( xmlsecctx , UNO_QUERY ) ;
303cdf0e10cSrcweir OSL_ENSURE( xSecCtx.is() ,
304cdf0e10cSrcweir "Signer - "
305cdf0e10cSrcweir "Cannot get interface of \"XXMLSecurityContext\" from service \"xsec.XMLSecurityContext\"" ) ;
306cdf0e10cSrcweir
307cdf0e10cSrcweir xSecCtx->setSecurityEnvironment( xSecEnv ) ;
308cdf0e10cSrcweir
309cdf0e10cSrcweir //Generate XML signature
310cdf0e10cSrcweir Reference< XInterface > xmlsigner =
311cdf0e10cSrcweir xManager->createInstanceWithContext( OUString::createFromAscii("com.sun.star.xml.security.bridge.xmlsec.XMLSignature_NssImpl"), xContext ) ;
312cdf0e10cSrcweir OSL_ENSURE( xmlsigner.is() ,
313cdf0e10cSrcweir "Signer - "
314cdf0e10cSrcweir "Cannot get service instance of \"xsec.XMLSignature\"" ) ;
315cdf0e10cSrcweir
316cdf0e10cSrcweir Reference< XXMLSignature > xSigner( xmlsigner , UNO_QUERY ) ;
317cdf0e10cSrcweir OSL_ENSURE( xSigner.is() ,
318cdf0e10cSrcweir "Signer - "
319cdf0e10cSrcweir "Cannot get interface of \"XXMLSignature\" from service \"xsec.XMLSignature\"" ) ;
320cdf0e10cSrcweir
321cdf0e10cSrcweir //perform signature
322cdf0e10cSrcweir xTemplate = xSigner->generate( xTemplate , xSecCtx ) ;
323cdf0e10cSrcweir OSL_ENSURE( xTemplate.is() ,
324cdf0e10cSrcweir "Signer - "
325cdf0e10cSrcweir "Cannot generate the xml signature" ) ;
326cdf0e10cSrcweir } catch( Exception& e ) {
327cdf0e10cSrcweir fprintf( stderr , "Error Message: %s\n" , OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US ).getStr() ) ;
328cdf0e10cSrcweir goto done ;
329cdf0e10cSrcweir }
330cdf0e10cSrcweir
331cdf0e10cSrcweir dstFile = fopen( argv[3], "w" ) ;
332cdf0e10cSrcweir if( dstFile == NULL ) {
333cdf0e10cSrcweir fprintf( stderr , "### Can not open file %s\n", argv[3] ) ;
334cdf0e10cSrcweir goto done ;
335cdf0e10cSrcweir }
336cdf0e10cSrcweir
337cdf0e10cSrcweir //Save result
338cdf0e10cSrcweir xmlDocDump( dstFile, doc ) ;
339cdf0e10cSrcweir
340cdf0e10cSrcweir done:
341cdf0e10cSrcweir if( uri != NULL )
342cdf0e10cSrcweir delete uri ;
343cdf0e10cSrcweir
344cdf0e10cSrcweir if( dstFile != NULL )
345cdf0e10cSrcweir fclose( dstFile ) ;
346cdf0e10cSrcweir
347cdf0e10cSrcweir if( doc != NULL )
348cdf0e10cSrcweir xmlFreeDoc( doc ) ;
349cdf0e10cSrcweir
350cdf0e10cSrcweir if( slot != NULL )
351cdf0e10cSrcweir PK11_FreeSlot( slot ) ;
352cdf0e10cSrcweir
353cdf0e10cSrcweir PK11_LogoutAll() ;
354cdf0e10cSrcweir NSS_Shutdown() ;
355cdf0e10cSrcweir
356cdf0e10cSrcweir /* Shutdown libxslt/libxml */
357cdf0e10cSrcweir #ifndef XMLSEC_NO_XSLT
358cdf0e10cSrcweir xsltCleanupGlobals();
359cdf0e10cSrcweir #endif /* XMLSEC_NO_XSLT */
360cdf0e10cSrcweir xmlCleanupParser();
361cdf0e10cSrcweir
362cdf0e10cSrcweir }
363cdf0e10cSrcweir
364cdf0e10cSrcweir return 0;
365cdf0e10cSrcweir }
366cdf0e10cSrcweir
367