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