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 <stdio.h>
28*b1cdbd2cSJim Jagielski #include "helper.hxx"
29*b1cdbd2cSJim Jagielski
30*b1cdbd2cSJim Jagielski #include "libxml/tree.h"
31*b1cdbd2cSJim Jagielski #include "libxml/parser.h"
32*b1cdbd2cSJim Jagielski #ifndef XMLSEC_NO_XSLT
33*b1cdbd2cSJim Jagielski #include "libxslt/xslt.h"
34*b1cdbd2cSJim Jagielski #endif
35*b1cdbd2cSJim Jagielski
36*b1cdbd2cSJim Jagielski #include "securityenvironment_nssimpl.hxx"
37*b1cdbd2cSJim Jagielski #include "xmlelementwrapper_xmlsecimpl.hxx"
38*b1cdbd2cSJim Jagielski
39*b1cdbd2cSJim Jagielski #include "nspr.h"
40*b1cdbd2cSJim Jagielski #include "prtypes.h"
41*b1cdbd2cSJim Jagielski
42*b1cdbd2cSJim Jagielski #include "pk11func.h"
43*b1cdbd2cSJim Jagielski #include "cert.h"
44*b1cdbd2cSJim Jagielski #include "cryptohi.h"
45*b1cdbd2cSJim Jagielski #include "certdb.h"
46*b1cdbd2cSJim Jagielski #include "nss.h"
47*b1cdbd2cSJim Jagielski
48*b1cdbd2cSJim Jagielski #include "xmlsec/strings.h"
49*b1cdbd2cSJim Jagielski #include "xmlsec/xmltree.h"
50*b1cdbd2cSJim Jagielski
51*b1cdbd2cSJim Jagielski #include <rtl/ustring.hxx>
52*b1cdbd2cSJim Jagielski #include <cppuhelper/servicefactory.hxx>
53*b1cdbd2cSJim Jagielski
54*b1cdbd2cSJim Jagielski #include <com/sun/star/lang/XComponent.hpp>
55*b1cdbd2cSJim Jagielski #include <com/sun/star/beans/PropertyValue.hpp>
56*b1cdbd2cSJim Jagielski #include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
57*b1cdbd2cSJim Jagielski #include <com/sun/star/xml/wrapper/XXMLDocumentWrapper.hpp>
58*b1cdbd2cSJim Jagielski #include <com/sun/star/xml/crypto/XXMLEncryption.hpp>
59*b1cdbd2cSJim Jagielski #include <com/sun/star/xml/crypto/XXMLEncryptionTemplate.hpp>
60*b1cdbd2cSJim Jagielski #include <com/sun/star/xml/crypto/XXMLSecurityContext.hpp>
61*b1cdbd2cSJim Jagielski #include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp>
62*b1cdbd2cSJim Jagielski
63*b1cdbd2cSJim Jagielski using namespace ::rtl ;
64*b1cdbd2cSJim Jagielski using namespace ::cppu ;
65*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::uno ;
66*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::io ;
67*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::ucb ;
68*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::beans ;
69*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::document ;
70*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::lang ;
71*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::registry ;
72*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::xml::wrapper ;
73*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::xml::crypto ;
74*b1cdbd2cSJim Jagielski
main(int argc,char ** argv)75*b1cdbd2cSJim Jagielski int SAL_CALL main( int argc, char **argv )
76*b1cdbd2cSJim Jagielski {
77*b1cdbd2cSJim Jagielski CERTCertDBHandle* certHandle ;
78*b1cdbd2cSJim Jagielski PK11SlotInfo* slot = NULL ;
79*b1cdbd2cSJim Jagielski PK11SymKey* symKey = NULL ;
80*b1cdbd2cSJim Jagielski xmlDocPtr doc = NULL ;
81*b1cdbd2cSJim Jagielski xmlNodePtr tplNode ;
82*b1cdbd2cSJim Jagielski xmlNodePtr tarNode ;
83*b1cdbd2cSJim Jagielski FILE* dstFile = NULL ;
84*b1cdbd2cSJim Jagielski
85*b1cdbd2cSJim Jagielski if( argc != 7 ) {
86*b1cdbd2cSJim Jagielski fprintf( stderr, "Usage: %s < CertDir > <file_url of template> <file_url of result> <target element name> <target element namespace> <rdb file>\n\n" , argv[0] ) ;
87*b1cdbd2cSJim Jagielski return 1 ;
88*b1cdbd2cSJim Jagielski }
89*b1cdbd2cSJim Jagielski
90*b1cdbd2cSJim Jagielski //Init libxml and libxslt libraries
91*b1cdbd2cSJim Jagielski xmlInitParser();
92*b1cdbd2cSJim Jagielski LIBXML_TEST_VERSION
93*b1cdbd2cSJim Jagielski xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS;
94*b1cdbd2cSJim Jagielski xmlSubstituteEntitiesDefault(1);
95*b1cdbd2cSJim Jagielski
96*b1cdbd2cSJim Jagielski #ifndef XMLSEC_NO_XSLT
97*b1cdbd2cSJim Jagielski xmlIndentTreeOutput = 1;
98*b1cdbd2cSJim Jagielski #endif // XMLSEC_NO_XSLT
99*b1cdbd2cSJim Jagielski
100*b1cdbd2cSJim Jagielski //Initialize NSPR and NSS
101*b1cdbd2cSJim Jagielski PR_Init( PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 1 ) ;
102*b1cdbd2cSJim Jagielski PK11_SetPasswordFunc( PriPK11PasswordFunc ) ;
103*b1cdbd2cSJim Jagielski if( NSS_Init( argv[1] ) != SECSuccess ) {
104*b1cdbd2cSJim Jagielski fprintf( stderr , "### cannot intialize NSS!\n" ) ;
105*b1cdbd2cSJim Jagielski goto done ;
106*b1cdbd2cSJim Jagielski }
107*b1cdbd2cSJim Jagielski
108*b1cdbd2cSJim Jagielski certHandle = CERT_GetDefaultCertDB() ;
109*b1cdbd2cSJim Jagielski slot = PK11_GetInternalKeySlot() ;
110*b1cdbd2cSJim Jagielski
111*b1cdbd2cSJim Jagielski symKey = PK11_KeyGen( slot , CKM_DES3_CBC, NULL, 128, NULL ) ;
112*b1cdbd2cSJim Jagielski if( symKey == NULL ) {
113*b1cdbd2cSJim Jagielski fprintf( stderr , "### cannot create symmetric key!\n" ) ;
114*b1cdbd2cSJim Jagielski goto done ;
115*b1cdbd2cSJim Jagielski }
116*b1cdbd2cSJim Jagielski
117*b1cdbd2cSJim Jagielski //Load XML document
118*b1cdbd2cSJim Jagielski doc = xmlParseFile( argv[2] ) ;
119*b1cdbd2cSJim Jagielski if( doc == NULL || xmlDocGetRootElement( doc ) == NULL ) {
120*b1cdbd2cSJim Jagielski fprintf( stderr , "### Cannot load template xml document!\n" ) ;
121*b1cdbd2cSJim Jagielski goto done ;
122*b1cdbd2cSJim Jagielski }
123*b1cdbd2cSJim Jagielski
124*b1cdbd2cSJim Jagielski //Find the encryption template
125*b1cdbd2cSJim Jagielski tplNode = xmlSecFindNode( xmlDocGetRootElement( doc ), xmlSecNodeEncryptedData, xmlSecEncNs ) ;
126*b1cdbd2cSJim Jagielski if( tplNode == NULL ) {
127*b1cdbd2cSJim Jagielski fprintf( stderr , "### Cannot find the encryption template!\n" ) ;
128*b1cdbd2cSJim Jagielski goto done ;
129*b1cdbd2cSJim Jagielski }
130*b1cdbd2cSJim Jagielski
131*b1cdbd2cSJim Jagielski //Find the encryption template
132*b1cdbd2cSJim Jagielski tarNode = xmlSecFindNode( xmlDocGetRootElement( doc ), ( const unsigned char*)argv[4], ( const unsigned char*)argv[5] ) ;
133*b1cdbd2cSJim Jagielski if( tarNode == NULL ) {
134*b1cdbd2cSJim Jagielski fprintf( stderr , "### Cannot find the encryption target!\n" ) ;
135*b1cdbd2cSJim Jagielski goto done ;
136*b1cdbd2cSJim Jagielski }
137*b1cdbd2cSJim Jagielski
138*b1cdbd2cSJim Jagielski try {
139*b1cdbd2cSJim Jagielski Reference< XMultiComponentFactory > xManager = NULL ;
140*b1cdbd2cSJim Jagielski Reference< XComponentContext > xContext = NULL ;
141*b1cdbd2cSJim Jagielski
142*b1cdbd2cSJim Jagielski xManager = serviceManager( xContext , OUString::createFromAscii( "local" ), OUString::createFromAscii( argv[6] ) ) ;
143*b1cdbd2cSJim Jagielski
144*b1cdbd2cSJim Jagielski //Create encryption template
145*b1cdbd2cSJim Jagielski Reference< XInterface > tplElement =
146*b1cdbd2cSJim Jagielski xManager->createInstanceWithContext( OUString::createFromAscii( "com.sun.star.xml.security.bridge.xmlsec.XMLElementWrapper_XmlSecImpl" ) , xContext ) ;
147*b1cdbd2cSJim Jagielski OSL_ENSURE( tplElement.is() ,
148*b1cdbd2cSJim Jagielski "Encryptor - "
149*b1cdbd2cSJim Jagielski "Cannot get service instance of \"xsec.XMLElementWrapper\"" ) ;
150*b1cdbd2cSJim Jagielski
151*b1cdbd2cSJim Jagielski Reference< XXMLElementWrapper > xTplElement( tplElement , UNO_QUERY ) ;
152*b1cdbd2cSJim Jagielski OSL_ENSURE( xTplElement.is() ,
153*b1cdbd2cSJim Jagielski "Encryptor - "
154*b1cdbd2cSJim Jagielski "Cannot get interface of \"XXMLElementWrapper\" from service \"xsec.XMLElementWrapper\"" ) ;
155*b1cdbd2cSJim Jagielski
156*b1cdbd2cSJim Jagielski Reference< XUnoTunnel > xTplEleTunnel( xTplElement , UNO_QUERY ) ;
157*b1cdbd2cSJim Jagielski OSL_ENSURE( xTplEleTunnel.is() ,
158*b1cdbd2cSJim Jagielski "Encryptor - "
159*b1cdbd2cSJim Jagielski "Cannot get interface of \"XUnoTunnel\" from service \"xsec.XMLElementWrapper\"" ) ;
160*b1cdbd2cSJim Jagielski
161*b1cdbd2cSJim Jagielski XMLElementWrapper_XmlSecImpl* pTplElement = ( XMLElementWrapper_XmlSecImpl* )xTplEleTunnel->getSomething( XMLElementWrapper_XmlSecImpl::getUnoTunnelImplementationId() ) ;
162*b1cdbd2cSJim Jagielski OSL_ENSURE( pTplElement != NULL ,
163*b1cdbd2cSJim Jagielski "Encryptor - "
164*b1cdbd2cSJim Jagielski "Cannot get implementation of \"xsec.XMLElementWrapper\"" ) ;
165*b1cdbd2cSJim Jagielski
166*b1cdbd2cSJim Jagielski pTplElement->setNativeElement( tplNode ) ;
167*b1cdbd2cSJim Jagielski
168*b1cdbd2cSJim Jagielski //Create encryption target element
169*b1cdbd2cSJim Jagielski Reference< XInterface > tarElement =
170*b1cdbd2cSJim Jagielski xManager->createInstanceWithContext( OUString::createFromAscii( "com.sun.star.xml.security.bridge.xmlsec.XMLElementWrapper_XmlSecImpl" ) , xContext ) ;
171*b1cdbd2cSJim Jagielski OSL_ENSURE( tarElement.is() ,
172*b1cdbd2cSJim Jagielski "Encryptor - "
173*b1cdbd2cSJim Jagielski "Cannot get service instance of \"xsec.XMLElementWrapper\"" ) ;
174*b1cdbd2cSJim Jagielski
175*b1cdbd2cSJim Jagielski Reference< XXMLElementWrapper > xTarElement( tarElement , UNO_QUERY ) ;
176*b1cdbd2cSJim Jagielski OSL_ENSURE( xTarElement.is() ,
177*b1cdbd2cSJim Jagielski "Encryptor - "
178*b1cdbd2cSJim Jagielski "Cannot get interface of \"XXMLElementWrapper\" from service \"xsec.XMLElementWrapper\"" ) ;
179*b1cdbd2cSJim Jagielski
180*b1cdbd2cSJim Jagielski Reference< XUnoTunnel > xTarEleTunnel( xTarElement , UNO_QUERY ) ;
181*b1cdbd2cSJim Jagielski OSL_ENSURE( xTarEleTunnel.is() ,
182*b1cdbd2cSJim Jagielski "Encryptor - "
183*b1cdbd2cSJim Jagielski "Cannot get interface of \"XUnoTunnel\" from service \"xsec.XMLElementWrapper\"" ) ;
184*b1cdbd2cSJim Jagielski
185*b1cdbd2cSJim Jagielski XMLElementWrapper_XmlSecImpl* pTarElement = ( XMLElementWrapper_XmlSecImpl* )xTarEleTunnel->getSomething( XMLElementWrapper_XmlSecImpl::getUnoTunnelImplementationId() ) ;
186*b1cdbd2cSJim Jagielski OSL_ENSURE( pTarElement != NULL ,
187*b1cdbd2cSJim Jagielski "Encryptor - "
188*b1cdbd2cSJim Jagielski "Cannot get implementation of \"xsec.XMLElementWrapper\"" ) ;
189*b1cdbd2cSJim Jagielski
190*b1cdbd2cSJim Jagielski pTarElement->setNativeElement( tarNode ) ;
191*b1cdbd2cSJim Jagielski
192*b1cdbd2cSJim Jagielski
193*b1cdbd2cSJim Jagielski //Build XML Encryption template
194*b1cdbd2cSJim Jagielski Reference< XInterface > enctpl =
195*b1cdbd2cSJim Jagielski xManager->createInstanceWithContext( OUString::createFromAscii("com.sun.star.xml.crypto.XMLEncryptionTemplate"), xContext ) ;
196*b1cdbd2cSJim Jagielski OSL_ENSURE( enctpl.is() ,
197*b1cdbd2cSJim Jagielski "Encryptor - "
198*b1cdbd2cSJim Jagielski "Cannot get service instance of \"xsec.XMLEncryptionTemplate\"" ) ;
199*b1cdbd2cSJim Jagielski
200*b1cdbd2cSJim Jagielski Reference< XXMLEncryptionTemplate > xTemplate( enctpl , UNO_QUERY ) ;
201*b1cdbd2cSJim Jagielski OSL_ENSURE( xTemplate.is() ,
202*b1cdbd2cSJim Jagielski "Encryptor - "
203*b1cdbd2cSJim Jagielski "Cannot get interface of \"XXMLEncryptionTemplate\" from service \"xsec.XMLEncryptionTemplate\"" ) ;
204*b1cdbd2cSJim Jagielski
205*b1cdbd2cSJim Jagielski //Import the encryption template
206*b1cdbd2cSJim Jagielski xTemplate->setTemplate( xTplElement ) ;
207*b1cdbd2cSJim Jagielski xTemplate->setTarget( xTarElement ) ;
208*b1cdbd2cSJim Jagielski
209*b1cdbd2cSJim Jagielski //Create security environment
210*b1cdbd2cSJim Jagielski //Build Security Environment
211*b1cdbd2cSJim Jagielski Reference< XInterface > xsecenv =
212*b1cdbd2cSJim Jagielski xManager->createInstanceWithContext( OUString::createFromAscii("com.sun.star.xml.security.bridge.xmlsec.SecurityEnvironment_NssImpl"), xContext ) ;
213*b1cdbd2cSJim Jagielski OSL_ENSURE( xsecenv.is() ,
214*b1cdbd2cSJim Jagielski "Encryptor - "
215*b1cdbd2cSJim Jagielski "Cannot get service instance of \"xsec.SecurityEnvironment\"" ) ;
216*b1cdbd2cSJim Jagielski
217*b1cdbd2cSJim Jagielski Reference< XSecurityEnvironment > xSecEnv( xsecenv , UNO_QUERY ) ;
218*b1cdbd2cSJim Jagielski OSL_ENSURE( xSecEnv.is() ,
219*b1cdbd2cSJim Jagielski "Encryptor - "
220*b1cdbd2cSJim Jagielski "Cannot get interface of \"XSecurityEnvironment\" from service \"xsec.SecurityEnvironment\"" ) ;
221*b1cdbd2cSJim Jagielski
222*b1cdbd2cSJim Jagielski //Setup key slot and certDb
223*b1cdbd2cSJim Jagielski Reference< XUnoTunnel > xEnvTunnel( xsecenv , UNO_QUERY ) ;
224*b1cdbd2cSJim Jagielski OSL_ENSURE( xEnvTunnel.is() ,
225*b1cdbd2cSJim Jagielski "Encryptor - "
226*b1cdbd2cSJim Jagielski "Cannot get interface of \"XUnoTunnel\" from service \"xsec.SecurityEnvironment\"" ) ;
227*b1cdbd2cSJim Jagielski
228*b1cdbd2cSJim Jagielski SecurityEnvironment_NssImpl* pSecEnv = ( SecurityEnvironment_NssImpl* )xEnvTunnel->getSomething( SecurityEnvironment_NssImpl::getUnoTunnelId() ) ;
229*b1cdbd2cSJim Jagielski OSL_ENSURE( pSecEnv != NULL ,
230*b1cdbd2cSJim Jagielski "Encryptor - "
231*b1cdbd2cSJim Jagielski "Cannot get implementation of \"xsec.SecurityEnvironment\"" ) ;
232*b1cdbd2cSJim Jagielski
233*b1cdbd2cSJim Jagielski pSecEnv->setCryptoSlot( slot ) ;
234*b1cdbd2cSJim Jagielski pSecEnv->setCertDb( certHandle ) ;
235*b1cdbd2cSJim Jagielski pSecEnv->adoptSymKey( symKey ) ;
236*b1cdbd2cSJim Jagielski
237*b1cdbd2cSJim Jagielski
238*b1cdbd2cSJim Jagielski //Build XML Security Context
239*b1cdbd2cSJim Jagielski Reference< XInterface > xmlsecctx =
240*b1cdbd2cSJim Jagielski xManager->createInstanceWithContext( OUString::createFromAscii("com.sun.star.xml.security.bridge.xmlsec.XMLSecurityContext_NssImpl"), xContext ) ;
241*b1cdbd2cSJim Jagielski OSL_ENSURE( xmlsecctx.is() ,
242*b1cdbd2cSJim Jagielski "Encryptor - "
243*b1cdbd2cSJim Jagielski "Cannot get service instance of \"xsec.XMLSecurityContext\"" ) ;
244*b1cdbd2cSJim Jagielski
245*b1cdbd2cSJim Jagielski Reference< XXMLSecurityContext > xSecCtx( xmlsecctx , UNO_QUERY ) ;
246*b1cdbd2cSJim Jagielski OSL_ENSURE( xSecCtx.is() ,
247*b1cdbd2cSJim Jagielski "Encryptor - "
248*b1cdbd2cSJim Jagielski "Cannot get interface of \"XXMLSecurityContext\" from service \"xsec.XMLSecurityContext\"" ) ;
249*b1cdbd2cSJim Jagielski
250*b1cdbd2cSJim Jagielski xSecCtx->setSecurityEnvironment( xSecEnv ) ;
251*b1cdbd2cSJim Jagielski
252*b1cdbd2cSJim Jagielski //Get encrypter
253*b1cdbd2cSJim Jagielski Reference< XInterface > xmlencrypter =
254*b1cdbd2cSJim Jagielski xManager->createInstanceWithContext( OUString::createFromAscii("com.sun.star.xml.security.bridge.xmlsec.XMLEncryption_NssImpl"), xContext ) ;
255*b1cdbd2cSJim Jagielski OSL_ENSURE( xmlencrypter.is() ,
256*b1cdbd2cSJim Jagielski "Encryptor - "
257*b1cdbd2cSJim Jagielski "Cannot get service instance of \"xsec.XMLEncryption\"" ) ;
258*b1cdbd2cSJim Jagielski
259*b1cdbd2cSJim Jagielski Reference< XXMLEncryption > xEncrypter( xmlencrypter , UNO_QUERY ) ;
260*b1cdbd2cSJim Jagielski OSL_ENSURE( xEncrypter.is() ,
261*b1cdbd2cSJim Jagielski "Encryptor - "
262*b1cdbd2cSJim Jagielski "Cannot get interface of \"XXMLEncryption\" from service \"xsec.XMLEncryption\"" ) ;
263*b1cdbd2cSJim Jagielski
264*b1cdbd2cSJim Jagielski //perform encryption
265*b1cdbd2cSJim Jagielski xTemplate = xEncrypter->encrypt( xTemplate , xSecCtx ) ;
266*b1cdbd2cSJim Jagielski OSL_ENSURE( xTemplate.is() ,
267*b1cdbd2cSJim Jagielski "Encryptor - "
268*b1cdbd2cSJim Jagielski "Cannot encrypt the xml document" ) ;
269*b1cdbd2cSJim Jagielski } catch( Exception& e ) {
270*b1cdbd2cSJim Jagielski fprintf( stderr , "Error Message: %s\n" , OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US ).getStr() ) ;
271*b1cdbd2cSJim Jagielski goto done ;
272*b1cdbd2cSJim Jagielski }
273*b1cdbd2cSJim Jagielski
274*b1cdbd2cSJim Jagielski dstFile = fopen( argv[3], "w" ) ;
275*b1cdbd2cSJim Jagielski if( dstFile == NULL ) {
276*b1cdbd2cSJim Jagielski fprintf( stderr , "### Can not open file %s\n", argv[3] ) ;
277*b1cdbd2cSJim Jagielski goto done ;
278*b1cdbd2cSJim Jagielski }
279*b1cdbd2cSJim Jagielski
280*b1cdbd2cSJim Jagielski //Save result
281*b1cdbd2cSJim Jagielski xmlDocDump( dstFile, doc ) ;
282*b1cdbd2cSJim Jagielski
283*b1cdbd2cSJim Jagielski done:
284*b1cdbd2cSJim Jagielski if( dstFile != NULL )
285*b1cdbd2cSJim Jagielski fclose( dstFile ) ;
286*b1cdbd2cSJim Jagielski
287*b1cdbd2cSJim Jagielski if( symKey != NULL ) {
288*b1cdbd2cSJim Jagielski PK11_FreeSymKey( symKey ) ;
289*b1cdbd2cSJim Jagielski }
290*b1cdbd2cSJim Jagielski
291*b1cdbd2cSJim Jagielski if( slot != NULL )
292*b1cdbd2cSJim Jagielski PK11_FreeSlot( slot ) ;
293*b1cdbd2cSJim Jagielski
294*b1cdbd2cSJim Jagielski PK11_LogoutAll() ;
295*b1cdbd2cSJim Jagielski NSS_Shutdown() ;
296*b1cdbd2cSJim Jagielski
297*b1cdbd2cSJim Jagielski /* Shutdown libxslt/libxml */
298*b1cdbd2cSJim Jagielski #ifndef XMLSEC_NO_XSLT
299*b1cdbd2cSJim Jagielski xsltCleanupGlobals();
300*b1cdbd2cSJim Jagielski #endif /* XMLSEC_NO_XSLT */
301*b1cdbd2cSJim Jagielski xmlCleanupParser();
302*b1cdbd2cSJim Jagielski
303*b1cdbd2cSJim Jagielski return 0;
304*b1cdbd2cSJim Jagielski }
305*b1cdbd2cSJim Jagielski
306