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