1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_xmlsecurity.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <stdio.h> 32*cdf0e10cSrcweir #include <string.h> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir #include <rtl/ustring.hxx> 35*cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx> 36*cdf0e10cSrcweir #include <cppuhelper/servicefactory.hxx> 37*cdf0e10cSrcweir #include <com/sun/star/bridge/XUnoUrlResolver.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/registry/XImplementationRegistration.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiComponentFactory.hpp> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir #include <iostream> 45*cdf0e10cSrcweir #include <fstream> 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir #include <util.hxx> 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 50*cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp> 51*cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp> 52*cdf0e10cSrcweir #include <com/sun/star/xml/sax/XParser.hpp> 53*cdf0e10cSrcweir #include <com/sun/star/xml/sax/XDocumentHandler.hpp> 54*cdf0e10cSrcweir #include <com/sun/star/xml/sax/XAttributeList.hpp> 55*cdf0e10cSrcweir #include <cppuhelper/implbase4.hxx> 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XSignatureCreationResultListener.hpp> 58*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XSignatureVerifyResultListener.hpp> 59*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XSAXEventKeeperStatusChangeListener.hpp> 60*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XSecuritySAXEventKeeper.hpp> 61*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XReferenceResolvedListener.hpp> 62*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/XXMLSignature.hpp> 63*cdf0e10cSrcweir #include <com/sun/star/xml/wrapper/XXMLDocumentWrapper.hpp> 64*cdf0e10cSrcweir #include <com/sun/star/xml/csax/XMLAttribute.hpp> 65*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/XSEInitializer.hpp> 66*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/SecurityOperationStatus.hpp> 67*cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSource.hpp> 68*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp> 69*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XKeyCollector.hpp> 70*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/ElementMarkPriority.hpp> 71*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XReferenceResolvedBroadcaster.hpp> 72*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XMissionTaker.hpp> 73*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XBlockerMonitor.hpp> 74*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XSignatureCreationResultBroadcaster.hpp> 75*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XSignatureVerifyResultBroadcaster.hpp> 76*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XReferenceCollector.hpp> 77*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XSAXEventKeeperStatusChangeBroadcaster.hpp> 78*cdf0e10cSrcweir #include <com/sun/star/xml/wrapper/XXMLDocumentWrapper.hpp> 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir #include <xmloff/attrlist.hxx> 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir //#include <malloc.h> 83*cdf0e10cSrcweir #include <stdio.h> 84*cdf0e10cSrcweir #include <stdlib.h> 85*cdf0e10cSrcweir #include <string.h> 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir /* 88*cdf0e10cSrcweir * Can not build under solaris. 89*cdf0e10cSrcweir * Delete the memory.h including by AF 90*cdf0e10cSrcweir #include <memory.h> 91*cdf0e10cSrcweir */ 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir #include <sys/types.h> 94*cdf0e10cSrcweir #include <sys/stat.h> 95*cdf0e10cSrcweir #include <osl/time.h> 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir #ifndef INCLUDED_VECTOR 100*cdf0e10cSrcweir #include <vector> 101*cdf0e10cSrcweir #define INCLUDED_VECTOR 102*cdf0e10cSrcweir #endif 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir #ifndef INCLUDED_STACK 105*cdf0e10cSrcweir #include <stack> 106*cdf0e10cSrcweir #define INCLUDED_STACK 107*cdf0e10cSrcweir #endif 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir /* xml security framework components */ 110*cdf0e10cSrcweir #define SIGNATURECREATOR_COMPONENT "com.sun.star.xml.crypto.sax.SignatureCreator" 111*cdf0e10cSrcweir #define SIGNATUREVERIFIER_COMPONENT "com.sun.star.xml.crypto.sax.SignatureVerifier" 112*cdf0e10cSrcweir #define JAVAFLATFILTER_COMPONENT "com.sun.star.xml.crypto.eval.JavaFlatFilter" 113*cdf0e10cSrcweir #define SAXEVENTKEEPER_COMPONENT "com.sun.star.xml.crypto.sax.SAXEventKeeper" 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir /* java based bridge components */ 116*cdf0e10cSrcweir #define SEINITIALIZER_JAVA_COMPONENT "com.sun.star.xml.security.bridge.jxsec.SEInitializer_JxsecImpl" 117*cdf0e10cSrcweir #define XMLSIGNATURE_JAVA_COMPONENT "com.sun.star.xml.security.bridge.jxsec.XMLSignature_JxsecImpl" 118*cdf0e10cSrcweir #define XMLDOCUMENTWRAPPER_JAVA_COMPONENT "com.sun.star.xml.security.bridge.jxsec.XMLDocumentWrapper_JxsecImpl" 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir /* c based bridge components */ 121*cdf0e10cSrcweir #define SEINITIALIZER_C_COMPONENT "com.sun.star.xml.crypto.SEInitializer" 122*cdf0e10cSrcweir #define XMLSIGNATURE_C_COMPONENT "com.sun.star.xml.crypto.XMLSignature" 123*cdf0e10cSrcweir #define XMLDOCUMENT_C_COMPONENT "com.sun.star.xml.wrapper.XMLDocumentWrapper" 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir /* security related elements and attributes */ 126*cdf0e10cSrcweir #define SIGNATURE_STR "Signature" 127*cdf0e10cSrcweir #define REFERENCE_STR "Reference" 128*cdf0e10cSrcweir #define SIGNEDINFO_STR "SignedInfo" 129*cdf0e10cSrcweir #define KEYINFO_STR "KeyInfo" 130*cdf0e10cSrcweir #define KEYVALUE_STR "KeyValue" 131*cdf0e10cSrcweir #define KEYNAME_STR "KeyName" 132*cdf0e10cSrcweir #define X509DATA_STR "X509Data" 133*cdf0e10cSrcweir #define ENCRYPTEDKEY_STR "EncryptedKey" 134*cdf0e10cSrcweir #define RETRIEVALMETHOD_STR "RetrievalMethod" 135*cdf0e10cSrcweir #define OTHER_ELEMENT_STR "OTHER_ELEMENT_STR" 136*cdf0e10cSrcweir #define REFNUM_ATTR_STR "refNum" 137*cdf0e10cSrcweir #define URI_ATTR_STR "URI" 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir #define RTL_ASCII_USTRINGPARAM( asciiStr ) asciiStr, strlen( asciiStr ), RTL_TEXTENCODING_ASCII_US 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir namespace cssu = com::sun::star::uno; 143*cdf0e10cSrcweir namespace cssl = com::sun::star::lang; 144*cdf0e10cSrcweir namespace cssb = com::sun::star::beans; 145*cdf0e10cSrcweir namespace cssi = com::sun::star::io; 146*cdf0e10cSrcweir namespace cssxc = com::sun::star::xml::crypto; 147*cdf0e10cSrcweir namespace cssxs = com::sun::star::xml::sax; 148*cdf0e10cSrcweir namespace cssxw = com::sun::star::xml::wrapper; 149*cdf0e10cSrcweir namespace cssxcsax = com::sun::star::xml::csax; 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir using namespace ::com::sun::star; 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir class XSecTester; 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir /* 158*cdf0e10cSrcweir * The XSecTester class is a C++ version of SecurityFramworkController.java 159*cdf0e10cSrcweir * 160*cdf0e10cSrcweir */ 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir class SecurityEntity 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir private: 165*cdf0e10cSrcweir static int m_nNextSecurityId; 166*cdf0e10cSrcweir rtl::OUString m_ouKeyURI; 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir protected: 169*cdf0e10cSrcweir com::sun::star::uno::Reference< 170*cdf0e10cSrcweir com::sun::star::lang::XMultiServiceFactory > mxMSF; 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir com::sun::star::uno::Reference< 173*cdf0e10cSrcweir com::sun::star::xml::crypto::sax::XReferenceResolvedListener > 174*cdf0e10cSrcweir m_xReferenceListener; 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir com::sun::star::uno::Reference< 177*cdf0e10cSrcweir com::sun::star::xml::crypto::sax::XSecuritySAXEventKeeper > 178*cdf0e10cSrcweir m_xSAXEventKeeper; 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir com::sun::star::uno::Reference< 181*cdf0e10cSrcweir com::sun::star::xml::crypto::XXMLSecurityContext > 182*cdf0e10cSrcweir m_xXMLSecurityContext; 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir com::sun::star::uno::Reference< 185*cdf0e10cSrcweir com::sun::star::xml::crypto::XXMLSignature > 186*cdf0e10cSrcweir m_xXMLSignature; 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir int m_nSecurityId; 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir private: 191*cdf0e10cSrcweir int getNextSecurityId() const; 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir protected: 194*cdf0e10cSrcweir SecurityEntity( 195*cdf0e10cSrcweir const com::sun::star::uno::Reference< 196*cdf0e10cSrcweir com::sun::star::xml::crypto::sax::XSecuritySAXEventKeeper >& 197*cdf0e10cSrcweir xSAXEventKeeper, 198*cdf0e10cSrcweir const com::sun::star::uno::Reference< 199*cdf0e10cSrcweir com::sun::star::xml::crypto::XXMLSecurityContext >& 200*cdf0e10cSrcweir xXMLSecurityContext, 201*cdf0e10cSrcweir const com::sun::star::uno::Reference< 202*cdf0e10cSrcweir com::sun::star::xml::crypto::XXMLSignature >& 203*cdf0e10cSrcweir xXMLSignature, 204*cdf0e10cSrcweir const com::sun::star::uno::Reference< 205*cdf0e10cSrcweir com::sun::star::lang::XMultiServiceFactory >& 206*cdf0e10cSrcweir rsMSF); 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir public: 209*cdf0e10cSrcweir void setKeyId(int nId); 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir int getSecurityId() const; 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir com::sun::star::uno::Reference< 214*cdf0e10cSrcweir com::sun::star::xml::crypto::sax::XReferenceResolvedListener > 215*cdf0e10cSrcweir getReferenceListener() const; 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir bool setKey( const rtl::OUString& ouUri, bool bIsExporting ); 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir void setKeyURI(const rtl::OUString& ouUri); 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir bool endMission(); 222*cdf0e10cSrcweir }; 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir class SignatureEntity : public SecurityEntity 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir private: 228*cdf0e10cSrcweir std::vector< rtl::OUString > m_vReferenceIds; 229*cdf0e10cSrcweir int m_nSignatureElementCollectorId; 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir bool hasReference(const rtl::OUString& ouUri) const; 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir public: 234*cdf0e10cSrcweir SignatureEntity( 235*cdf0e10cSrcweir const com::sun::star::uno::Reference< 236*cdf0e10cSrcweir com::sun::star::xml::crypto::sax::XSecuritySAXEventKeeper >& 237*cdf0e10cSrcweir xSAXEventKeeper, 238*cdf0e10cSrcweir bool bIsExporting, 239*cdf0e10cSrcweir XSecTester* pListener, 240*cdf0e10cSrcweir const com::sun::star::uno::Reference< 241*cdf0e10cSrcweir com::sun::star::xml::crypto::XXMLSecurityContext >& 242*cdf0e10cSrcweir xXMLSecurityContext, 243*cdf0e10cSrcweir const com::sun::star::uno::Reference< 244*cdf0e10cSrcweir com::sun::star::xml::crypto::XXMLSignature >& 245*cdf0e10cSrcweir xXMLSignature, 246*cdf0e10cSrcweir const com::sun::star::uno::Reference< 247*cdf0e10cSrcweir com::sun::star::lang::XMultiServiceFactory >& 248*cdf0e10cSrcweir rsMSF); 249*cdf0e10cSrcweir ~SignatureEntity(){}; 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir void setReferenceNumber() const; 252*cdf0e10cSrcweir bool setReference( const rtl::OUString& ouUri, bool bIsExporting ) const; 253*cdf0e10cSrcweir void addReferenceURI( const rtl::OUString& ouUri ); 254*cdf0e10cSrcweir }; 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir struct AncestorEvent 257*cdf0e10cSrcweir { 258*cdf0e10cSrcweir AncestorEvent( sal_Int32 nAttrNum ):aAttributeList(nAttrNum){}; 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir bool bIsStartElement; 261*cdf0e10cSrcweir rtl::OUString ouName; 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir com::sun::star::uno::Sequence< 264*cdf0e10cSrcweir com::sun::star::xml::csax::XMLAttribute > 265*cdf0e10cSrcweir aAttributeList; 266*cdf0e10cSrcweir }; 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir class XSecTester : public cppu::WeakImplHelper4 269*cdf0e10cSrcweir < 270*cdf0e10cSrcweir com::sun::star::xml::crypto::sax::XSignatureCreationResultListener, 271*cdf0e10cSrcweir com::sun::star::xml::crypto::sax::XSignatureVerifyResultListener, 272*cdf0e10cSrcweir com::sun::star::xml::crypto::sax::XSAXEventKeeperStatusChangeListener, 273*cdf0e10cSrcweir com::sun::star::xml::sax::XDocumentHandler 274*cdf0e10cSrcweir > 275*cdf0e10cSrcweir { 276*cdf0e10cSrcweir private: 277*cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > mxMSF; 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir sal_Int32 m_nTotalSignatureNumber; 280*cdf0e10cSrcweir sal_Int32 m_nSuccessfulSignatureNumber; 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir com::sun::star::uno::Reference< 283*cdf0e10cSrcweir com::sun::star::xml::sax::XDocumentHandler > 284*cdf0e10cSrcweir m_xExportHandler; 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir com::sun::star::uno::Reference< 287*cdf0e10cSrcweir com::sun::star::xml::crypto::sax::XSecuritySAXEventKeeper > 288*cdf0e10cSrcweir m_xSAXEventKeeper; 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir com::sun::star::uno::Reference< 291*cdf0e10cSrcweir com::sun::star::xml::wrapper::XXMLDocumentWrapper > 292*cdf0e10cSrcweir m_xXMLDocumentWrapper; 293*cdf0e10cSrcweir 294*cdf0e10cSrcweir com::sun::star::uno::Reference< 295*cdf0e10cSrcweir com::sun::star::xml::sax::XDocumentHandler > 296*cdf0e10cSrcweir m_xOutputHandler; 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir com::sun::star::uno::Reference< 299*cdf0e10cSrcweir com::sun::star::xml::sax::XParser > 300*cdf0e10cSrcweir m_xSaxParser; 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir std::stack< void* > m_stCurrentPath; 303*cdf0e10cSrcweir std::stack< bool > m_stCurrentPathType; 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir std::vector< AncestorEvent* > m_vAncestorEvents; 306*cdf0e10cSrcweir std::vector< SignatureEntity* > m_vSignatureList; 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir std::vector< rtl::OUString > m_vUnsolvedReferenceURIs; 309*cdf0e10cSrcweir std::vector< int > m_vUnsolvedReferenceKeeperIds; 310*cdf0e10cSrcweir std::vector< int > m_vUnsolvedReferenceRefNums; 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir bool m_bIsExporting; 313*cdf0e10cSrcweir bool m_bIsBlocking; 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir bool m_bIsInsideCollectedElement; 316*cdf0e10cSrcweir bool m_bIsSAXEventKeeperOnTheSAXChain; 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir com::sun::star::uno::Reference< 319*cdf0e10cSrcweir com::sun::star::xml::crypto::XXMLSecurityContext > 320*cdf0e10cSrcweir m_xXMLSecurityContext; 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir com::sun::star::uno::Reference< 323*cdf0e10cSrcweir com::sun::star::xml::crypto::XXMLSignature > 324*cdf0e10cSrcweir m_xXMLSignature; 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir rtl::OUString m_ouJavaCryptokenDir; 327*cdf0e10cSrcweir rtl::OUString m_ouCCryptokenDir; 328*cdf0e10cSrcweir rtl::OUString m_ouXMLDocumentWrapperComponentName; 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir private: 331*cdf0e10cSrcweir com::sun::star::uno::Reference< 332*cdf0e10cSrcweir com::sun::star::io::XOutputStream > 333*cdf0e10cSrcweir createOutputStream( const rtl::OUString& ouFile ); 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir rtl::OUString parseFile( 336*cdf0e10cSrcweir const rtl::OUString& ouInputFileName, 337*cdf0e10cSrcweir const rtl::OUString& ouOutputFileName, 338*cdf0e10cSrcweir bool bIsExporting, 339*cdf0e10cSrcweir bool bIsJavaBased); 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir void changeOutput(); 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir bool foundSecurityRelated(); 344*cdf0e10cSrcweir 345*cdf0e10cSrcweir void findKeyOrReference(SecurityEntity* pSecurityEntity, const rtl::OUString& ouUri, bool bIsFindKey); 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir bool checkSecurityElement( 348*cdf0e10cSrcweir const rtl::OUString& ouLocalName, 349*cdf0e10cSrcweir const com::sun::star::uno::Reference< 350*cdf0e10cSrcweir com::sun::star::xml::sax::XAttributeList>& xAttribs); 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir void checkReference( 353*cdf0e10cSrcweir const rtl::OUString& ouLocalName, 354*cdf0e10cSrcweir const com::sun::star::uno::Reference< 355*cdf0e10cSrcweir com::sun::star::xml::sax::XAttributeList>& xAttribs, 356*cdf0e10cSrcweir const rtl::OUString& ouId); 357*cdf0e10cSrcweir 358*cdf0e10cSrcweir void endMission(); 359*cdf0e10cSrcweir 360*cdf0e10cSrcweir void addStartAncestorEvent( 361*cdf0e10cSrcweir const rtl::OUString& ouName, 362*cdf0e10cSrcweir const com::sun::star::uno::Reference< 363*cdf0e10cSrcweir com::sun::star::xml::sax::XAttributeList>& xAttribs); 364*cdf0e10cSrcweir 365*cdf0e10cSrcweir void addEndAncestorEvent( const rtl::OUString& ouName ); 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir void flushAncestorEvents( 368*cdf0e10cSrcweir const com::sun::star::uno::Reference< 369*cdf0e10cSrcweir com::sun::star::xml::sax::XDocumentHandler >& xDocumentHandler); 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir void XSecTester::sendAncestorStartElementEvent( 372*cdf0e10cSrcweir const rtl::OUString& ouName, 373*cdf0e10cSrcweir const com::sun::star::uno::Sequence< 374*cdf0e10cSrcweir com::sun::star::xml::csax::XMLAttribute >& xAttrList, 375*cdf0e10cSrcweir const com::sun::star::uno::Reference< 376*cdf0e10cSrcweir com::sun::star::xml::sax::XDocumentHandler >& xDocumentHandler) const; 377*cdf0e10cSrcweir 378*cdf0e10cSrcweir void XSecTester::sendAncestorEndElementEvent( 379*cdf0e10cSrcweir const rtl::OUString& ouName, 380*cdf0e10cSrcweir const com::sun::star::uno::Reference< 381*cdf0e10cSrcweir com::sun::star::xml::sax::XDocumentHandler >& xDocumentHandler) const; 382*cdf0e10cSrcweir 383*cdf0e10cSrcweir std::vector< AncestorEvent* >::const_iterator XSecTester::checkAncestorStartElementEvent( 384*cdf0e10cSrcweir const std::vector< AncestorEvent* >::const_iterator& ii, 385*cdf0e10cSrcweir const com::sun::star::uno::Reference< 386*cdf0e10cSrcweir com::sun::star::xml::sax::XDocumentHandler >& xDocumentHandler) const; 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir public: 389*cdf0e10cSrcweir XSecTester(const com::sun::star::uno::Reference< 390*cdf0e10cSrcweir com::sun::star::lang::XMultiServiceFactory >& rxMSF) 391*cdf0e10cSrcweir :mxMSF( rxMSF ){}; 392*cdf0e10cSrcweir virtual ~XSecTester(){}; 393*cdf0e10cSrcweir 394*cdf0e10cSrcweir /* XSignatureCreationResultListener */ 395*cdf0e10cSrcweir virtual void SAL_CALL signatureCreated( 396*cdf0e10cSrcweir sal_Int32 securityId, 397*cdf0e10cSrcweir com::sun::star::xml::crypto::SecurityOperationStatus creationResult ) 398*cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 399*cdf0e10cSrcweir 400*cdf0e10cSrcweir /* XSignatureVerifyResultListener */ 401*cdf0e10cSrcweir virtual void SAL_CALL signatureVerified( 402*cdf0e10cSrcweir sal_Int32 securityId, 403*cdf0e10cSrcweir com::sun::star::xml::crypto::SecurityOperationStatus verifyResult ) 404*cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 405*cdf0e10cSrcweir 406*cdf0e10cSrcweir /* XSAXEventKeeperStatusChangeListener */ 407*cdf0e10cSrcweir virtual void SAL_CALL blockingStatusChanged( sal_Bool isBlocking ) 408*cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 409*cdf0e10cSrcweir virtual void SAL_CALL collectionStatusChanged( 410*cdf0e10cSrcweir sal_Bool isInsideCollectedElement ) 411*cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 412*cdf0e10cSrcweir virtual void SAL_CALL bufferStatusChanged( sal_Bool isBufferEmpty ) 413*cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 414*cdf0e10cSrcweir 415*cdf0e10cSrcweir /* XXMLSecTester */ 416*cdf0e10cSrcweir virtual rtl::OUString SAL_CALL transfer_without_sec( 417*cdf0e10cSrcweir const rtl::OUString& inputFileName, 418*cdf0e10cSrcweir const rtl::OUString& outputFileName, 419*cdf0e10cSrcweir sal_Bool isBridgeInvolved) 420*cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 421*cdf0e10cSrcweir virtual rtl::OUString SAL_CALL export_xml( 422*cdf0e10cSrcweir const rtl::OUString& inputFileName, 423*cdf0e10cSrcweir const rtl::OUString& outputFileName, 424*cdf0e10cSrcweir sal_Bool isJavaBased) 425*cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 426*cdf0e10cSrcweir virtual rtl::OUString SAL_CALL import_xml( 427*cdf0e10cSrcweir const rtl::OUString& inputFileName, 428*cdf0e10cSrcweir const rtl::OUString& outputFileName, 429*cdf0e10cSrcweir sal_Bool isJavaBased) 430*cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 431*cdf0e10cSrcweir 432*cdf0e10cSrcweir virtual void SAL_CALL setCryptoDir( 433*cdf0e10cSrcweir const rtl::OUString & javaDirName, 434*cdf0e10cSrcweir const rtl::OUString & cDirName) 435*cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 436*cdf0e10cSrcweir 437*cdf0e10cSrcweir /* XDocumentHandler */ 438*cdf0e10cSrcweir virtual void SAL_CALL endDocument() 439*cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 440*cdf0e10cSrcweir virtual void SAL_CALL startDocument() 441*cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 442*cdf0e10cSrcweir virtual void SAL_CALL characters(const class rtl::OUString&) 443*cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 444*cdf0e10cSrcweir virtual void SAL_CALL processingInstruction(const rtl::OUString&, const rtl::OUString&) 445*cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 446*cdf0e10cSrcweir virtual void SAL_CALL ignorableWhitespace(const rtl::OUString&) 447*cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 448*cdf0e10cSrcweir virtual void SAL_CALL startElement( 449*cdf0e10cSrcweir const rtl::OUString&, 450*cdf0e10cSrcweir const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >&) 451*cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 452*cdf0e10cSrcweir virtual void SAL_CALL endElement(const rtl::OUString&) 453*cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 454*cdf0e10cSrcweir virtual void SAL_CALL setDocumentLocator( 455*cdf0e10cSrcweir const com::sun::star::uno::Reference< com::sun::star::xml::sax::XLocator >&) 456*cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 457*cdf0e10cSrcweir }; 458*cdf0e10cSrcweir 459*cdf0e10cSrcweir rtl::OUString XSecTester::parseFile( 460*cdf0e10cSrcweir const rtl::OUString& ouInputFileName, 461*cdf0e10cSrcweir const rtl::OUString& ouOutputFileName, 462*cdf0e10cSrcweir bool bIsExporting, 463*cdf0e10cSrcweir bool bIsJavaBased) 464*cdf0e10cSrcweir { 465*cdf0e10cSrcweir rtl::OUString ouMessage; 466*cdf0e10cSrcweir 467*cdf0e10cSrcweir cssu::Reference<cssi::XInputStream> xInputStream = OpenInputStream(ouInputFileName); 468*cdf0e10cSrcweir 469*cdf0e10cSrcweir if (xInputStream != NULL ) 470*cdf0e10cSrcweir { 471*cdf0e10cSrcweir /* initialization */ 472*cdf0e10cSrcweir rtl::OUString SEInitializer_comp; 473*cdf0e10cSrcweir rtl::OUString XMLSignature_comp; 474*cdf0e10cSrcweir rtl::OUString tokenPath; 475*cdf0e10cSrcweir cssu::Reference < cssxc::XSEInitializer > xSEInitializer; 476*cdf0e10cSrcweir 477*cdf0e10cSrcweir if (bIsJavaBased) 478*cdf0e10cSrcweir { 479*cdf0e10cSrcweir SEInitializer_comp = rtl::OUString::createFromAscii( SEINITIALIZER_JAVA_COMPONENT ); 480*cdf0e10cSrcweir XMLSignature_comp = rtl::OUString::createFromAscii( XMLSIGNATURE_JAVA_COMPONENT); 481*cdf0e10cSrcweir m_ouXMLDocumentWrapperComponentName = rtl::OUString::createFromAscii( XMLDOCUMENTWRAPPER_JAVA_COMPONENT ); 482*cdf0e10cSrcweir tokenPath = m_ouJavaCryptokenDir; 483*cdf0e10cSrcweir } 484*cdf0e10cSrcweir else 485*cdf0e10cSrcweir { 486*cdf0e10cSrcweir SEInitializer_comp = rtl::OUString::createFromAscii( SEINITIALIZER_C_COMPONENT ); 487*cdf0e10cSrcweir XMLSignature_comp = rtl::OUString::createFromAscii( XMLSIGNATURE_C_COMPONENT); 488*cdf0e10cSrcweir m_ouXMLDocumentWrapperComponentName = rtl::OUString::createFromAscii( XMLDOCUMENT_C_COMPONENT ); 489*cdf0e10cSrcweir tokenPath = m_ouCCryptokenDir; 490*cdf0e10cSrcweir } 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir xSEInitializer = cssu::Reference < cssxc::XSEInitializer > ( 493*cdf0e10cSrcweir mxMSF->createInstance( SEInitializer_comp ), 494*cdf0e10cSrcweir cssu::UNO_QUERY ); 495*cdf0e10cSrcweir 496*cdf0e10cSrcweir m_xXMLSignature = cssu::Reference<cssxc::XXMLSignature> ( 497*cdf0e10cSrcweir mxMSF->createInstance( XMLSignature_comp ), 498*cdf0e10cSrcweir cssu::UNO_QUERY ); 499*cdf0e10cSrcweir 500*cdf0e10cSrcweir if ( xSEInitializer.is() && m_xXMLSignature.is()) 501*cdf0e10cSrcweir { 502*cdf0e10cSrcweir /* create SAX Parser */ 503*cdf0e10cSrcweir const rtl::OUString sSaxParser ( 504*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.Parser") ); 505*cdf0e10cSrcweir m_xSaxParser = cssu::Reference < cssxs::XParser > ( mxMSF->createInstance( sSaxParser ), cssu::UNO_QUERY ); 506*cdf0e10cSrcweir 507*cdf0e10cSrcweir /* create SAX Writer */ 508*cdf0e10cSrcweir const rtl::OUString sSaxWriter ( 509*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.Writer") ); 510*cdf0e10cSrcweir cssu::Reference < cssi::XActiveDataSource > xSaxWriter 511*cdf0e10cSrcweir ( mxMSF->createInstance( sSaxWriter ), cssu::UNO_QUERY ); 512*cdf0e10cSrcweir 513*cdf0e10cSrcweir cssu::Reference< cssi::XOutputStream > xOutputStream = OpenOutputStream(ouOutputFileName); 514*cdf0e10cSrcweir xSaxWriter->setOutputStream( xOutputStream ); 515*cdf0e10cSrcweir 516*cdf0e10cSrcweir cssxs::InputSource aInput; 517*cdf0e10cSrcweir aInput.sSystemId = ouInputFileName; 518*cdf0e10cSrcweir aInput.aInputStream = xInputStream; 519*cdf0e10cSrcweir 520*cdf0e10cSrcweir cssu::Reference < cssxs::XDocumentHandler > xSaxWriterHandler( xSaxWriter, cssu::UNO_QUERY); 521*cdf0e10cSrcweir 522*cdf0e10cSrcweir m_xXMLSecurityContext = 523*cdf0e10cSrcweir xSEInitializer->createSecurityContext(tokenPath); 524*cdf0e10cSrcweir 525*cdf0e10cSrcweir m_bIsExporting = bIsExporting; 526*cdf0e10cSrcweir m_xExportHandler = xSaxWriterHandler; 527*cdf0e10cSrcweir m_xOutputHandler = xSaxWriterHandler; 528*cdf0e10cSrcweir 529*cdf0e10cSrcweir m_xXMLDocumentWrapper = NULL; 530*cdf0e10cSrcweir m_xSAXEventKeeper = NULL; 531*cdf0e10cSrcweir m_bIsSAXEventKeeperOnTheSAXChain = false; 532*cdf0e10cSrcweir 533*cdf0e10cSrcweir m_bIsBlocking = false; 534*cdf0e10cSrcweir m_bIsInsideCollectedElement = false; 535*cdf0e10cSrcweir 536*cdf0e10cSrcweir OSL_ASSERT(m_vSignatureList.size() == 0); 537*cdf0e10cSrcweir OSL_ASSERT(m_vUnsolvedReferenceURIs.size() == 0); 538*cdf0e10cSrcweir OSL_ASSERT(m_vUnsolvedReferenceKeeperIds.size() == 0); 539*cdf0e10cSrcweir OSL_ASSERT(m_vUnsolvedReferenceRefNums.size() == 0); 540*cdf0e10cSrcweir OSL_ASSERT(m_stCurrentPath.empty()); 541*cdf0e10cSrcweir OSL_ASSERT(m_stCurrentPathType.empty()); 542*cdf0e10cSrcweir OSL_ASSERT(m_vAncestorEvents.empty()); 543*cdf0e10cSrcweir 544*cdf0e10cSrcweir changeOutput(); 545*cdf0e10cSrcweir 546*cdf0e10cSrcweir /* foundSecurityRelated(); */ 547*cdf0e10cSrcweir 548*cdf0e10cSrcweir /* Begin to parse */ 549*cdf0e10cSrcweir TimeValue startTime, endTime; 550*cdf0e10cSrcweir osl_getSystemTime( &startTime ); 551*cdf0e10cSrcweir 552*cdf0e10cSrcweir xSaxWriterHandler->startDocument(); 553*cdf0e10cSrcweir 554*cdf0e10cSrcweir if (m_bIsExporting) 555*cdf0e10cSrcweir { 556*cdf0e10cSrcweir m_xSaxParser->setDocumentHandler(this); 557*cdf0e10cSrcweir m_xSaxParser->parseStream(aInput); 558*cdf0e10cSrcweir } 559*cdf0e10cSrcweir else 560*cdf0e10cSrcweir { 561*cdf0e10cSrcweir m_xSaxParser->setDocumentHandler(this); 562*cdf0e10cSrcweir m_xSaxParser->parseStream(aInput); 563*cdf0e10cSrcweir } 564*cdf0e10cSrcweir 565*cdf0e10cSrcweir endMission(); 566*cdf0e10cSrcweir xSaxWriterHandler->endDocument(); 567*cdf0e10cSrcweir 568*cdf0e10cSrcweir osl_getSystemTime( &endTime ); 569*cdf0e10cSrcweir 570*cdf0e10cSrcweir flushAncestorEvents( NULL ); 571*cdf0e10cSrcweir 572*cdf0e10cSrcweir // Bug in SAXWriter, done in endDocument() 573*cdf0e10cSrcweir // xOutputStream->closeOutput(); 574*cdf0e10cSrcweir xInputStream->closeInput(); 575*cdf0e10cSrcweir 576*cdf0e10cSrcweir 577*cdf0e10cSrcweir /* 578*cdf0e10cSrcweir * Free the security context 579*cdf0e10cSrcweir */ 580*cdf0e10cSrcweir xSEInitializer->freeSecurityContext(m_xXMLSecurityContext); 581*cdf0e10cSrcweir m_xXMLSecurityContext = NULL; 582*cdf0e10cSrcweir 583*cdf0e10cSrcweir /* Calculate the time */ 584*cdf0e10cSrcweir double diff = ((double)((endTime.Nanosec + endTime.Seconds*1000000000.0) 585*cdf0e10cSrcweir - (startTime.Nanosec + startTime.Seconds*1000000000.0))) / 586*cdf0e10cSrcweir ((double)1000000000.0); 587*cdf0e10cSrcweir 588*cdf0e10cSrcweir char buf[32]; 589*cdf0e10cSrcweir sprintf(buf, "%.2f", diff); 590*cdf0e10cSrcweir ouMessage += rtl::OUString(RTL_ASCII_USTRINGPARAM(buf)); 591*cdf0e10cSrcweir } 592*cdf0e10cSrcweir else 593*cdf0e10cSrcweir { 594*cdf0e10cSrcweir ouMessage += rtl::OUString::createFromAscii( "N/A" ); 595*cdf0e10cSrcweir } 596*cdf0e10cSrcweir 597*cdf0e10cSrcweir } 598*cdf0e10cSrcweir else 599*cdf0e10cSrcweir { 600*cdf0e10cSrcweir ouMessage += rtl::OUString::createFromAscii( "-" ); 601*cdf0e10cSrcweir } 602*cdf0e10cSrcweir 603*cdf0e10cSrcweir return ouMessage; 604*cdf0e10cSrcweir } 605*cdf0e10cSrcweir 606*cdf0e10cSrcweir /* XSignatureCreationResultListener */ 607*cdf0e10cSrcweir void SAL_CALL XSecTester::signatureCreated( 608*cdf0e10cSrcweir sal_Int32 securityId, 609*cdf0e10cSrcweir cssxc::SecurityOperationStatus creationResult ) 610*cdf0e10cSrcweir throw (cssu::RuntimeException) 611*cdf0e10cSrcweir { 612*cdf0e10cSrcweir m_nTotalSignatureNumber++; 613*cdf0e10cSrcweir if (creationResult == cssxc::SecurityOperationStatus_OPERATION_SUCCEEDED) 614*cdf0e10cSrcweir { 615*cdf0e10cSrcweir m_nSuccessfulSignatureNumber++; 616*cdf0e10cSrcweir } 617*cdf0e10cSrcweir } 618*cdf0e10cSrcweir 619*cdf0e10cSrcweir /* XSignatureVerifyResultListener */ 620*cdf0e10cSrcweir void SAL_CALL XSecTester::signatureVerified( 621*cdf0e10cSrcweir sal_Int32 securityId, 622*cdf0e10cSrcweir cssxc::SecurityOperationStatus verifyResult ) 623*cdf0e10cSrcweir throw (cssu::RuntimeException) 624*cdf0e10cSrcweir { 625*cdf0e10cSrcweir m_nTotalSignatureNumber++; 626*cdf0e10cSrcweir if (verifyResult == cssxc::SecurityOperationStatus_OPERATION_SUCCEEDED) 627*cdf0e10cSrcweir { 628*cdf0e10cSrcweir m_nSuccessfulSignatureNumber++; 629*cdf0e10cSrcweir } 630*cdf0e10cSrcweir } 631*cdf0e10cSrcweir 632*cdf0e10cSrcweir /* XSAXEventKeeperStatusChangeListener */ 633*cdf0e10cSrcweir void SAL_CALL XSecTester::blockingStatusChanged( sal_Bool isBlocking ) 634*cdf0e10cSrcweir throw (cssu::RuntimeException) 635*cdf0e10cSrcweir { 636*cdf0e10cSrcweir this->m_bIsBlocking = isBlocking; 637*cdf0e10cSrcweir } 638*cdf0e10cSrcweir 639*cdf0e10cSrcweir void SAL_CALL XSecTester::collectionStatusChanged( sal_Bool isInsideCollectedElement ) 640*cdf0e10cSrcweir throw (cssu::RuntimeException) 641*cdf0e10cSrcweir { 642*cdf0e10cSrcweir this->m_bIsInsideCollectedElement = isInsideCollectedElement; 643*cdf0e10cSrcweir 644*cdf0e10cSrcweir if ( !m_bIsInsideCollectedElement && !m_bIsBlocking) 645*cdf0e10cSrcweir { 646*cdf0e10cSrcweir m_bIsSAXEventKeeperOnTheSAXChain = false; 647*cdf0e10cSrcweir } 648*cdf0e10cSrcweir else 649*cdf0e10cSrcweir { 650*cdf0e10cSrcweir m_bIsSAXEventKeeperOnTheSAXChain = true; 651*cdf0e10cSrcweir } 652*cdf0e10cSrcweir changeOutput(); 653*cdf0e10cSrcweir } 654*cdf0e10cSrcweir 655*cdf0e10cSrcweir void SAL_CALL XSecTester::bufferStatusChanged( sal_Bool isBufferEmpty ) 656*cdf0e10cSrcweir throw (cssu::RuntimeException) 657*cdf0e10cSrcweir { 658*cdf0e10cSrcweir if (isBufferEmpty) 659*cdf0e10cSrcweir { 660*cdf0e10cSrcweir m_xXMLDocumentWrapper = NULL; 661*cdf0e10cSrcweir 662*cdf0e10cSrcweir m_xSAXEventKeeper = NULL; 663*cdf0e10cSrcweir m_bIsSAXEventKeeperOnTheSAXChain = false; 664*cdf0e10cSrcweir changeOutput(); 665*cdf0e10cSrcweir } 666*cdf0e10cSrcweir } 667*cdf0e10cSrcweir 668*cdf0e10cSrcweir /* XXMLSecTester */ 669*cdf0e10cSrcweir rtl::OUString SAL_CALL XSecTester::export_xml( const rtl::OUString& inputFileName, const rtl::OUString& outputFileName, sal_Bool isJavaBased) 670*cdf0e10cSrcweir throw (cssu::RuntimeException) 671*cdf0e10cSrcweir { 672*cdf0e10cSrcweir rtl::OUString ouMessage; 673*cdf0e10cSrcweir 674*cdf0e10cSrcweir m_nTotalSignatureNumber = 0; 675*cdf0e10cSrcweir m_nSuccessfulSignatureNumber = 0; 676*cdf0e10cSrcweir 677*cdf0e10cSrcweir ouMessage += parseFile(inputFileName, outputFileName, sal_True, isJavaBased); 678*cdf0e10cSrcweir 679*cdf0e10cSrcweir rtl::OUString ouRemark = rtl::OUString::valueOf(m_nSuccessfulSignatureNumber) + 680*cdf0e10cSrcweir rtl::OUString(RTL_ASCII_USTRINGPARAM( "/" )) 681*cdf0e10cSrcweir + rtl::OUString::valueOf(m_nTotalSignatureNumber); 682*cdf0e10cSrcweir ouMessage += rtl::OUString(RTL_ASCII_USTRINGPARAM("\t")) + ouRemark; 683*cdf0e10cSrcweir 684*cdf0e10cSrcweir return ouMessage; 685*cdf0e10cSrcweir } 686*cdf0e10cSrcweir 687*cdf0e10cSrcweir rtl::OUString SAL_CALL XSecTester::import_xml( const rtl::OUString& inputFileName, const rtl::OUString& outputFileName, sal_Bool isJavaBased) 688*cdf0e10cSrcweir throw (cssu::RuntimeException) 689*cdf0e10cSrcweir { 690*cdf0e10cSrcweir rtl::OUString ouMessage; 691*cdf0e10cSrcweir 692*cdf0e10cSrcweir m_nTotalSignatureNumber = 0; 693*cdf0e10cSrcweir m_nSuccessfulSignatureNumber = 0; 694*cdf0e10cSrcweir 695*cdf0e10cSrcweir ouMessage += parseFile(inputFileName, outputFileName, sal_False, isJavaBased); 696*cdf0e10cSrcweir 697*cdf0e10cSrcweir rtl::OUString ouRemark = rtl::OUString::valueOf(m_nSuccessfulSignatureNumber) + 698*cdf0e10cSrcweir rtl::OUString(RTL_ASCII_USTRINGPARAM( "/" )) 699*cdf0e10cSrcweir + rtl::OUString::valueOf(m_nTotalSignatureNumber); 700*cdf0e10cSrcweir ouMessage += rtl::OUString(RTL_ASCII_USTRINGPARAM("\t")) + ouRemark; 701*cdf0e10cSrcweir 702*cdf0e10cSrcweir return ouMessage; 703*cdf0e10cSrcweir } 704*cdf0e10cSrcweir 705*cdf0e10cSrcweir rtl::OUString SAL_CALL XSecTester::transfer_without_sec( 706*cdf0e10cSrcweir const rtl::OUString& inputFileName, 707*cdf0e10cSrcweir const rtl::OUString& outputFileName, 708*cdf0e10cSrcweir sal_Bool isBridgeInvolved) 709*cdf0e10cSrcweir throw (cssu::RuntimeException) 710*cdf0e10cSrcweir { 711*cdf0e10cSrcweir rtl::OUString ouMessage; 712*cdf0e10cSrcweir 713*cdf0e10cSrcweir cssu::Reference< cssi::XInputStream > xInputStream = OpenInputStream(inputFileName); 714*cdf0e10cSrcweir 715*cdf0e10cSrcweir if (xInputStream != NULL ) 716*cdf0e10cSrcweir { 717*cdf0e10cSrcweir /* create SAX Parser */ 718*cdf0e10cSrcweir const rtl::OUString sSaxParser ( 719*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.Parser") ); 720*cdf0e10cSrcweir m_xSaxParser = cssu::Reference < cssxs::XParser > ( mxMSF->createInstance( sSaxParser ), cssu::UNO_QUERY ); 721*cdf0e10cSrcweir 722*cdf0e10cSrcweir /* create SAX Writer */ 723*cdf0e10cSrcweir const rtl::OUString sSaxWriter ( 724*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.Writer") ); 725*cdf0e10cSrcweir cssu::Reference < cssi::XActiveDataSource > xSaxWriter 726*cdf0e10cSrcweir ( mxMSF->createInstance( sSaxWriter ), cssu::UNO_QUERY ); 727*cdf0e10cSrcweir cssu::Reference < cssxs::XDocumentHandler > xSaxWriterHandler( 728*cdf0e10cSrcweir xSaxWriter, cssu::UNO_QUERY); 729*cdf0e10cSrcweir 730*cdf0e10cSrcweir if (!isBridgeInvolved) 731*cdf0e10cSrcweir { 732*cdf0e10cSrcweir /* connect the SAX Parser and the SAX Writer */ 733*cdf0e10cSrcweir m_xSaxParser->setDocumentHandler ( xSaxWriterHandler ); 734*cdf0e10cSrcweir } 735*cdf0e10cSrcweir else 736*cdf0e10cSrcweir { 737*cdf0e10cSrcweir /* create Java Flat Filter */ 738*cdf0e10cSrcweir const rtl::OUString sJavaFlatFilter( 739*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( JAVAFLATFILTER_COMPONENT ) ); 740*cdf0e10cSrcweir cssu::Reference < cssxs::XParser > xJavaFilterParser 741*cdf0e10cSrcweir ( mxMSF->createInstance( sJavaFlatFilter ), cssu::UNO_QUERY ); 742*cdf0e10cSrcweir cssu::Reference < cssxs::XDocumentHandler > xJavaFilterHandler( 743*cdf0e10cSrcweir xJavaFilterParser, cssu::UNO_QUERY ); 744*cdf0e10cSrcweir 745*cdf0e10cSrcweir if ( !xJavaFilterParser.is() ) 746*cdf0e10cSrcweir return rtl::OUString::createFromAscii( "NO JAVA" ); 747*cdf0e10cSrcweir 748*cdf0e10cSrcweir /* connect the SAX Parser, the Java Flat Filter and the SAX Writer */ 749*cdf0e10cSrcweir xJavaFilterParser->setDocumentHandler( xSaxWriterHandler ); 750*cdf0e10cSrcweir m_xSaxParser->setDocumentHandler ( xJavaFilterHandler ); 751*cdf0e10cSrcweir } 752*cdf0e10cSrcweir 753*cdf0e10cSrcweir 754*cdf0e10cSrcweir /* set output stream */ 755*cdf0e10cSrcweir cssu::Reference< cssi::XOutputStream > xOutputStream = 756*cdf0e10cSrcweir OpenOutputStream(outputFileName); 757*cdf0e10cSrcweir xSaxWriter->setOutputStream( xOutputStream ); 758*cdf0e10cSrcweir 759*cdf0e10cSrcweir /* prepare input stream */ 760*cdf0e10cSrcweir cssxs::InputSource aInput; 761*cdf0e10cSrcweir aInput.sSystemId = inputFileName; 762*cdf0e10cSrcweir aInput.aInputStream = xInputStream; 763*cdf0e10cSrcweir 764*cdf0e10cSrcweir TimeValue startTime, endTime; 765*cdf0e10cSrcweir osl_getSystemTime( &startTime ); 766*cdf0e10cSrcweir 767*cdf0e10cSrcweir m_xSaxParser->parseStream ( aInput ); 768*cdf0e10cSrcweir 769*cdf0e10cSrcweir // xOutputStream->closeOutput(); 770*cdf0e10cSrcweir xInputStream->closeInput(); 771*cdf0e10cSrcweir 772*cdf0e10cSrcweir osl_getSystemTime( &endTime ); 773*cdf0e10cSrcweir 774*cdf0e10cSrcweir double diff = ((double)((endTime.Nanosec + endTime.Seconds*1000000000.0) 775*cdf0e10cSrcweir - (startTime.Nanosec + startTime.Seconds*1000000000.0)))/((double)1000000000.0); 776*cdf0e10cSrcweir char buf[32]; 777*cdf0e10cSrcweir sprintf(buf, "%.2f", diff); 778*cdf0e10cSrcweir ouMessage += rtl::OUString(RTL_ASCII_USTRINGPARAM(buf)); 779*cdf0e10cSrcweir } 780*cdf0e10cSrcweir 781*cdf0e10cSrcweir return ouMessage; 782*cdf0e10cSrcweir } 783*cdf0e10cSrcweir 784*cdf0e10cSrcweir void SAL_CALL XSecTester::setCryptoDir(const rtl::OUString & javaDirName, const rtl::OUString & cDirName) 785*cdf0e10cSrcweir throw (cssu::RuntimeException) 786*cdf0e10cSrcweir { 787*cdf0e10cSrcweir m_ouJavaCryptokenDir = javaDirName; 788*cdf0e10cSrcweir m_ouCCryptokenDir = cDirName; 789*cdf0e10cSrcweir } 790*cdf0e10cSrcweir 791*cdf0e10cSrcweir 792*cdf0e10cSrcweir cssu::Reference< cssu::XInterface > SAL_CALL XSecTester_createInstance( 793*cdf0e10cSrcweir const cssu::Reference< cssl::XMultiServiceFactory > & rSMgr) 794*cdf0e10cSrcweir throw( cssu::Exception ) 795*cdf0e10cSrcweir { 796*cdf0e10cSrcweir return (cppu::OWeakObject*) new XSecTester( rSMgr ); 797*cdf0e10cSrcweir } 798*cdf0e10cSrcweir 799*cdf0e10cSrcweir int SecurityEntity::m_nNextSecurityId = 1; 800*cdf0e10cSrcweir 801*cdf0e10cSrcweir SecurityEntity::SecurityEntity( 802*cdf0e10cSrcweir const cssu::Reference<cssxc::sax::XSecuritySAXEventKeeper>& xSAXEventKeeper, 803*cdf0e10cSrcweir const cssu::Reference<cssxc::XXMLSecurityContext>& xXMLSecurityContext, 804*cdf0e10cSrcweir const cssu::Reference<cssxc::XXMLSignature>& xXMLSignature, 805*cdf0e10cSrcweir const cssu::Reference< cssl::XMultiServiceFactory > &rsMSF) 806*cdf0e10cSrcweir :m_xSAXEventKeeper(xSAXEventKeeper), 807*cdf0e10cSrcweir m_xXMLSecurityContext(xXMLSecurityContext), 808*cdf0e10cSrcweir m_xXMLSignature(xXMLSignature), 809*cdf0e10cSrcweir mxMSF(rsMSF), 810*cdf0e10cSrcweir m_ouKeyURI(RTL_ASCII_USTRINGPARAM("")) 811*cdf0e10cSrcweir { 812*cdf0e10cSrcweir m_nSecurityId = getNextSecurityId(); 813*cdf0e10cSrcweir } 814*cdf0e10cSrcweir 815*cdf0e10cSrcweir int SecurityEntity::getNextSecurityId() const 816*cdf0e10cSrcweir { 817*cdf0e10cSrcweir int nId = m_nNextSecurityId++; 818*cdf0e10cSrcweir return nId; 819*cdf0e10cSrcweir } 820*cdf0e10cSrcweir 821*cdf0e10cSrcweir void SecurityEntity::setKeyId(int nId) 822*cdf0e10cSrcweir { 823*cdf0e10cSrcweir cssu::Reference<cssxc::sax::XKeyCollector> keyCollector (m_xReferenceListener, cssu::UNO_QUERY); 824*cdf0e10cSrcweir keyCollector->setKeyId(nId); 825*cdf0e10cSrcweir } 826*cdf0e10cSrcweir 827*cdf0e10cSrcweir 828*cdf0e10cSrcweir void SecurityEntity::setKeyURI(const rtl::OUString& ouUri) 829*cdf0e10cSrcweir { 830*cdf0e10cSrcweir m_ouKeyURI = ouUri; 831*cdf0e10cSrcweir } 832*cdf0e10cSrcweir 833*cdf0e10cSrcweir cssu::Reference<cssxc::sax::XReferenceResolvedListener> SecurityEntity::getReferenceListener() const 834*cdf0e10cSrcweir { 835*cdf0e10cSrcweir return m_xReferenceListener; 836*cdf0e10cSrcweir } 837*cdf0e10cSrcweir 838*cdf0e10cSrcweir int SecurityEntity::getSecurityId() const 839*cdf0e10cSrcweir { 840*cdf0e10cSrcweir return m_nSecurityId; 841*cdf0e10cSrcweir } 842*cdf0e10cSrcweir 843*cdf0e10cSrcweir bool SecurityEntity::setKey(const rtl::OUString& ouUri, bool bIsExporting) 844*cdf0e10cSrcweir { 845*cdf0e10cSrcweir bool rc = false; 846*cdf0e10cSrcweir 847*cdf0e10cSrcweir if (m_ouKeyURI != rtl::OUString(RTL_ASCII_USTRINGPARAM("")) && 848*cdf0e10cSrcweir m_ouKeyURI == ouUri) 849*cdf0e10cSrcweir { 850*cdf0e10cSrcweir int nKeeperId = m_xSAXEventKeeper->addSecurityElementCollector( 851*cdf0e10cSrcweir bIsExporting ? 852*cdf0e10cSrcweir (cssxc::sax::ElementMarkPriority_BEFOREMODIFY): 853*cdf0e10cSrcweir (cssxc::sax::ElementMarkPriority_AFTERMODIFY), 854*cdf0e10cSrcweir true); 855*cdf0e10cSrcweir 856*cdf0e10cSrcweir setKeyId(nKeeperId); 857*cdf0e10cSrcweir m_xSAXEventKeeper->setSecurityId(nKeeperId, m_nSecurityId); 858*cdf0e10cSrcweir 859*cdf0e10cSrcweir cssu::Reference<cssxc::sax::XReferenceResolvedBroadcaster> xReferenceResolvedBroadcaster 860*cdf0e10cSrcweir (m_xSAXEventKeeper, cssu::UNO_QUERY); 861*cdf0e10cSrcweir xReferenceResolvedBroadcaster->addReferenceResolvedListener(nKeeperId, 862*cdf0e10cSrcweir m_xReferenceListener); 863*cdf0e10cSrcweir 864*cdf0e10cSrcweir rc = true; 865*cdf0e10cSrcweir } 866*cdf0e10cSrcweir 867*cdf0e10cSrcweir return rc; 868*cdf0e10cSrcweir } 869*cdf0e10cSrcweir 870*cdf0e10cSrcweir bool SecurityEntity::endMission() 871*cdf0e10cSrcweir { 872*cdf0e10cSrcweir cssu::Reference<cssxc::sax::XMissionTaker> xMissionTaker 873*cdf0e10cSrcweir (m_xReferenceListener, cssu::UNO_QUERY); 874*cdf0e10cSrcweir 875*cdf0e10cSrcweir return xMissionTaker->endMission(); 876*cdf0e10cSrcweir } 877*cdf0e10cSrcweir 878*cdf0e10cSrcweir SignatureEntity::SignatureEntity( 879*cdf0e10cSrcweir const cssu::Reference<cssxc::sax::XSecuritySAXEventKeeper>& xSAXEventKeeper, 880*cdf0e10cSrcweir bool bIsExporting, 881*cdf0e10cSrcweir XSecTester* pListener, 882*cdf0e10cSrcweir const cssu::Reference<cssxc::XXMLSecurityContext>& xXMLSecurityContext, 883*cdf0e10cSrcweir const cssu::Reference<cssxc::XXMLSignature>& xXMLSignature, 884*cdf0e10cSrcweir const cssu::Reference< cssl::XMultiServiceFactory >& rsMSF) 885*cdf0e10cSrcweir :SecurityEntity(xSAXEventKeeper, 886*cdf0e10cSrcweir xXMLSecurityContext, 887*cdf0e10cSrcweir xXMLSignature, 888*cdf0e10cSrcweir rsMSF) 889*cdf0e10cSrcweir { 890*cdf0e10cSrcweir if (bIsExporting) 891*cdf0e10cSrcweir { 892*cdf0e10cSrcweir m_nSignatureElementCollectorId = 893*cdf0e10cSrcweir m_xSAXEventKeeper->addSecurityElementCollector( 894*cdf0e10cSrcweir cssxc::sax::ElementMarkPriority_AFTERMODIFY, 895*cdf0e10cSrcweir true); 896*cdf0e10cSrcweir 897*cdf0e10cSrcweir m_xSAXEventKeeper->setSecurityId(m_nSignatureElementCollectorId, m_nSecurityId); 898*cdf0e10cSrcweir 899*cdf0e10cSrcweir m_xReferenceListener = cssu::Reference< cssxc::sax::XReferenceResolvedListener >( 900*cdf0e10cSrcweir mxMSF->createInstance( rtl::OUString::createFromAscii( SIGNATURECREATOR_COMPONENT )), 901*cdf0e10cSrcweir cssu::UNO_QUERY); 902*cdf0e10cSrcweir 903*cdf0e10cSrcweir cssu::Reference<cssl::XInitialization> xInitialization(m_xReferenceListener, cssu::UNO_QUERY); 904*cdf0e10cSrcweir 905*cdf0e10cSrcweir cssu::Sequence<cssu::Any> args(5); 906*cdf0e10cSrcweir char buf[16]; 907*cdf0e10cSrcweir 908*cdf0e10cSrcweir sprintf(buf, "%d", m_nSecurityId); 909*cdf0e10cSrcweir args[0] = cssu::makeAny(rtl::OUString(RTL_ASCII_USTRINGPARAM(buf))); 910*cdf0e10cSrcweir args[1] = cssu::makeAny(m_xSAXEventKeeper); 911*cdf0e10cSrcweir 912*cdf0e10cSrcweir sprintf(buf, "%d", m_nSignatureElementCollectorId); 913*cdf0e10cSrcweir args[2] = cssu::makeAny(rtl::OUString(RTL_ASCII_USTRINGPARAM(buf))); 914*cdf0e10cSrcweir args[3] = cssu::makeAny(m_xXMLSecurityContext->getSecurityEnvironment()); 915*cdf0e10cSrcweir args[4] = cssu::makeAny(m_xXMLSignature); 916*cdf0e10cSrcweir 917*cdf0e10cSrcweir xInitialization->initialize(args); 918*cdf0e10cSrcweir 919*cdf0e10cSrcweir int nBlockerId = m_xSAXEventKeeper->addBlocker(); 920*cdf0e10cSrcweir m_xSAXEventKeeper->setSecurityId(nBlockerId, m_nSecurityId); 921*cdf0e10cSrcweir 922*cdf0e10cSrcweir cssu::Reference<cssxc::sax::XBlockerMonitor> xBlockerMonitor(m_xReferenceListener, cssu::UNO_QUERY); 923*cdf0e10cSrcweir xBlockerMonitor->setBlockerId(nBlockerId); 924*cdf0e10cSrcweir 925*cdf0e10cSrcweir cssu::Reference< cssxc::sax::XSignatureCreationResultBroadcaster > xSignatureCreationResultBroadcaster 926*cdf0e10cSrcweir (m_xReferenceListener, cssu::UNO_QUERY); 927*cdf0e10cSrcweir xSignatureCreationResultBroadcaster->addSignatureCreationResultListener(pListener); 928*cdf0e10cSrcweir } 929*cdf0e10cSrcweir else 930*cdf0e10cSrcweir { 931*cdf0e10cSrcweir m_nSignatureElementCollectorId = 932*cdf0e10cSrcweir m_xSAXEventKeeper->addSecurityElementCollector( 933*cdf0e10cSrcweir cssxc::sax::ElementMarkPriority_BEFOREMODIFY, 934*cdf0e10cSrcweir false); 935*cdf0e10cSrcweir 936*cdf0e10cSrcweir m_xSAXEventKeeper->setSecurityId(m_nSignatureElementCollectorId, m_nSecurityId); 937*cdf0e10cSrcweir 938*cdf0e10cSrcweir m_xReferenceListener = cssu::Reference< cssxc::sax::XReferenceResolvedListener >( 939*cdf0e10cSrcweir mxMSF->createInstance( rtl::OUString::createFromAscii( SIGNATUREVERIFIER_COMPONENT )), 940*cdf0e10cSrcweir cssu::UNO_QUERY); 941*cdf0e10cSrcweir 942*cdf0e10cSrcweir cssu::Reference<cssl::XInitialization> xInitialization(m_xReferenceListener, cssu::UNO_QUERY); 943*cdf0e10cSrcweir 944*cdf0e10cSrcweir cssu::Sequence<cssu::Any> args(5); 945*cdf0e10cSrcweir char buf[16]; 946*cdf0e10cSrcweir 947*cdf0e10cSrcweir sprintf(buf, "%d", m_nSecurityId); 948*cdf0e10cSrcweir args[0] = cssu::makeAny(rtl::OUString(RTL_ASCII_USTRINGPARAM(buf))); 949*cdf0e10cSrcweir args[1] = cssu::makeAny(m_xSAXEventKeeper); 950*cdf0e10cSrcweir 951*cdf0e10cSrcweir sprintf(buf, "%d", m_nSignatureElementCollectorId); 952*cdf0e10cSrcweir args[2] = cssu::makeAny(rtl::OUString(RTL_ASCII_USTRINGPARAM(buf))); 953*cdf0e10cSrcweir args[3] = cssu::makeAny(m_xXMLSecurityContext); 954*cdf0e10cSrcweir args[4] = cssu::makeAny(m_xXMLSignature); 955*cdf0e10cSrcweir xInitialization->initialize(args); 956*cdf0e10cSrcweir 957*cdf0e10cSrcweir cssu::Reference< cssxc::sax::XSignatureVerifyResultBroadcaster > xSignatureVerifyResultBroadcaster 958*cdf0e10cSrcweir (m_xReferenceListener, cssu::UNO_QUERY); 959*cdf0e10cSrcweir xSignatureVerifyResultBroadcaster->addSignatureVerifyResultListener(pListener); 960*cdf0e10cSrcweir } 961*cdf0e10cSrcweir 962*cdf0e10cSrcweir cssu::Reference<cssxc::sax::XReferenceResolvedBroadcaster> xReferenceResolvedBroadcaster 963*cdf0e10cSrcweir (m_xSAXEventKeeper, cssu::UNO_QUERY); 964*cdf0e10cSrcweir xReferenceResolvedBroadcaster->addReferenceResolvedListener( 965*cdf0e10cSrcweir m_nSignatureElementCollectorId, m_xReferenceListener); 966*cdf0e10cSrcweir } 967*cdf0e10cSrcweir 968*cdf0e10cSrcweir void SignatureEntity::addReferenceURI(const rtl::OUString& ouUri) 969*cdf0e10cSrcweir { 970*cdf0e10cSrcweir m_vReferenceIds.push_back(ouUri); 971*cdf0e10cSrcweir } 972*cdf0e10cSrcweir 973*cdf0e10cSrcweir void SignatureEntity::setReferenceNumber() const 974*cdf0e10cSrcweir { 975*cdf0e10cSrcweir cssu::Reference<cssxc::sax::XReferenceCollector> xReferenceCollector 976*cdf0e10cSrcweir (m_xReferenceListener, cssu::UNO_QUERY); 977*cdf0e10cSrcweir xReferenceCollector->setReferenceCount(m_vReferenceIds.size()); 978*cdf0e10cSrcweir } 979*cdf0e10cSrcweir 980*cdf0e10cSrcweir bool SignatureEntity::hasReference(const rtl::OUString& ouUri) const 981*cdf0e10cSrcweir { 982*cdf0e10cSrcweir bool rc = false; 983*cdf0e10cSrcweir 984*cdf0e10cSrcweir std::vector<const rtl::OUString>::const_iterator ii; 985*cdf0e10cSrcweir for (ii = m_vReferenceIds.begin(); ii != m_vReferenceIds.end(); ++ii) 986*cdf0e10cSrcweir { 987*cdf0e10cSrcweir if (ouUri == *ii) 988*cdf0e10cSrcweir { 989*cdf0e10cSrcweir rc = true; 990*cdf0e10cSrcweir break; 991*cdf0e10cSrcweir } 992*cdf0e10cSrcweir } 993*cdf0e10cSrcweir 994*cdf0e10cSrcweir return rc; 995*cdf0e10cSrcweir } 996*cdf0e10cSrcweir 997*cdf0e10cSrcweir bool SignatureEntity::setReference(const rtl::OUString& ouUri, bool bIsExporting) const 998*cdf0e10cSrcweir { 999*cdf0e10cSrcweir bool rc = false; 1000*cdf0e10cSrcweir 1001*cdf0e10cSrcweir if (hasReference(ouUri)) 1002*cdf0e10cSrcweir { 1003*cdf0e10cSrcweir int nKeeperId = m_xSAXEventKeeper->addSecurityElementCollector( 1004*cdf0e10cSrcweir bIsExporting ? 1005*cdf0e10cSrcweir (cssxc::sax::ElementMarkPriority_AFTERMODIFY): 1006*cdf0e10cSrcweir (cssxc::sax::ElementMarkPriority_BEFOREMODIFY), 1007*cdf0e10cSrcweir false); 1008*cdf0e10cSrcweir 1009*cdf0e10cSrcweir m_xSAXEventKeeper->setSecurityId(nKeeperId, m_nSecurityId); 1010*cdf0e10cSrcweir 1011*cdf0e10cSrcweir cssu::Reference<cssxc::sax::XReferenceResolvedBroadcaster> xReferenceResolvedBroadcaster 1012*cdf0e10cSrcweir (m_xSAXEventKeeper, cssu::UNO_QUERY); 1013*cdf0e10cSrcweir xReferenceResolvedBroadcaster->addReferenceResolvedListener(nKeeperId, m_xReferenceListener); 1014*cdf0e10cSrcweir 1015*cdf0e10cSrcweir cssu::Reference<cssxc::sax::XReferenceCollector> xReferenceCollector 1016*cdf0e10cSrcweir (m_xReferenceListener, cssu::UNO_QUERY); 1017*cdf0e10cSrcweir xReferenceCollector->setReferenceId(nKeeperId); 1018*cdf0e10cSrcweir 1019*cdf0e10cSrcweir rc = true; 1020*cdf0e10cSrcweir } 1021*cdf0e10cSrcweir 1022*cdf0e10cSrcweir return rc; 1023*cdf0e10cSrcweir } 1024*cdf0e10cSrcweir 1025*cdf0e10cSrcweir /* XDocumentHandler */ 1026*cdf0e10cSrcweir void SAL_CALL XSecTester::startDocument() 1027*cdf0e10cSrcweir throw (cssu::RuntimeException) 1028*cdf0e10cSrcweir { 1029*cdf0e10cSrcweir } 1030*cdf0e10cSrcweir 1031*cdf0e10cSrcweir void SAL_CALL XSecTester::endDocument() 1032*cdf0e10cSrcweir throw (cssu::RuntimeException) 1033*cdf0e10cSrcweir { 1034*cdf0e10cSrcweir } 1035*cdf0e10cSrcweir 1036*cdf0e10cSrcweir void SAL_CALL XSecTester::characters(const class rtl::OUString & chars) 1037*cdf0e10cSrcweir throw (cssu::RuntimeException) 1038*cdf0e10cSrcweir { 1039*cdf0e10cSrcweir m_xExportHandler->characters(chars); 1040*cdf0e10cSrcweir } 1041*cdf0e10cSrcweir 1042*cdf0e10cSrcweir void SAL_CALL XSecTester::processingInstruction(const rtl::OUString & target, const rtl::OUString &data) 1043*cdf0e10cSrcweir throw (cssu::RuntimeException) 1044*cdf0e10cSrcweir { 1045*cdf0e10cSrcweir m_xExportHandler->processingInstruction(target, data); 1046*cdf0e10cSrcweir } 1047*cdf0e10cSrcweir 1048*cdf0e10cSrcweir void SAL_CALL XSecTester::ignorableWhitespace(const rtl::OUString &) 1049*cdf0e10cSrcweir throw (cssu::RuntimeException) 1050*cdf0e10cSrcweir { 1051*cdf0e10cSrcweir 1052*cdf0e10cSrcweir } 1053*cdf0e10cSrcweir 1054*cdf0e10cSrcweir void SAL_CALL XSecTester::startElement(const rtl::OUString & name, const cssu::Reference<cssxs::XAttributeList> &xAttribs) 1055*cdf0e10cSrcweir throw (cssu::RuntimeException) 1056*cdf0e10cSrcweir { 1057*cdf0e10cSrcweir rtl::OUString ouIdAttr = xAttribs->getValueByName( 1058*cdf0e10cSrcweir rtl::OUString(RTL_ASCII_USTRINGPARAM("id"))); 1059*cdf0e10cSrcweir 1060*cdf0e10cSrcweir if (ouIdAttr == NULL) 1061*cdf0e10cSrcweir { 1062*cdf0e10cSrcweir ouIdAttr = xAttribs->getValueByName( 1063*cdf0e10cSrcweir rtl::OUString(RTL_ASCII_USTRINGPARAM("Id"))); 1064*cdf0e10cSrcweir } 1065*cdf0e10cSrcweir 1066*cdf0e10cSrcweir bool bHasIdAttr = (ouIdAttr != NULL && ouIdAttr.getLength() > 0 ); 1067*cdf0e10cSrcweir bool needResend = false; 1068*cdf0e10cSrcweir 1069*cdf0e10cSrcweir if (bHasIdAttr || name.equalsAscii( SIGNATURE_STR )) 1070*cdf0e10cSrcweir { 1071*cdf0e10cSrcweir if (foundSecurityRelated() && ! m_bIsExporting) 1072*cdf0e10cSrcweir { 1073*cdf0e10cSrcweir needResend = true; 1074*cdf0e10cSrcweir } 1075*cdf0e10cSrcweir } 1076*cdf0e10cSrcweir 1077*cdf0e10cSrcweir if ( !m_bIsSAXEventKeeperOnTheSAXChain ) 1078*cdf0e10cSrcweir { 1079*cdf0e10cSrcweir addStartAncestorEvent(name, xAttribs); 1080*cdf0e10cSrcweir } 1081*cdf0e10cSrcweir 1082*cdf0e10cSrcweir bool bSuppressingForwarding = checkSecurityElement(name, xAttribs); 1083*cdf0e10cSrcweir 1084*cdf0e10cSrcweir checkReference(name, xAttribs, ouIdAttr); 1085*cdf0e10cSrcweir 1086*cdf0e10cSrcweir if (needResend) 1087*cdf0e10cSrcweir { 1088*cdf0e10cSrcweir m_xSAXEventKeeper->setNextHandler(NULL); 1089*cdf0e10cSrcweir 1090*cdf0e10cSrcweir cssu::Reference<cssxs::XDocumentHandler> xSAXEventKeeperHandler 1091*cdf0e10cSrcweir (m_xSAXEventKeeper, cssu::UNO_QUERY); 1092*cdf0e10cSrcweir 1093*cdf0e10cSrcweir xSAXEventKeeperHandler->startElement(name, xAttribs); 1094*cdf0e10cSrcweir m_xSAXEventKeeper->setNextHandler(this); 1095*cdf0e10cSrcweir } 1096*cdf0e10cSrcweir 1097*cdf0e10cSrcweir if (!bSuppressingForwarding) 1098*cdf0e10cSrcweir { 1099*cdf0e10cSrcweir m_xExportHandler->startElement(name, xAttribs); 1100*cdf0e10cSrcweir } 1101*cdf0e10cSrcweir } 1102*cdf0e10cSrcweir 1103*cdf0e10cSrcweir void SAL_CALL XSecTester::endElement(const rtl::OUString& name) 1104*cdf0e10cSrcweir throw (cssu::RuntimeException) 1105*cdf0e10cSrcweir { 1106*cdf0e10cSrcweir if (!m_stCurrentPath.empty()) 1107*cdf0e10cSrcweir { 1108*cdf0e10cSrcweir void* pSignedInfo = m_stCurrentPath.top(); 1109*cdf0e10cSrcweir bool bIsStringType = m_stCurrentPathType.top(); 1110*cdf0e10cSrcweir 1111*cdf0e10cSrcweir m_stCurrentPath.pop(); 1112*cdf0e10cSrcweir m_stCurrentPathType.pop(); 1113*cdf0e10cSrcweir 1114*cdf0e10cSrcweir if (bIsStringType && !strcmp((const char *)pSignedInfo, SIGNEDINFO_STR)) 1115*cdf0e10cSrcweir { 1116*cdf0e10cSrcweir if (!m_stCurrentPath.empty()) 1117*cdf0e10cSrcweir { 1118*cdf0e10cSrcweir void* pSignature = m_stCurrentPath.top(); 1119*cdf0e10cSrcweir bIsStringType = m_stCurrentPathType.top(); 1120*cdf0e10cSrcweir 1121*cdf0e10cSrcweir if (!bIsStringType && pSignature != NULL) 1122*cdf0e10cSrcweir { 1123*cdf0e10cSrcweir ((SignatureEntity *) pSignature)->setReferenceNumber(); 1124*cdf0e10cSrcweir } 1125*cdf0e10cSrcweir } 1126*cdf0e10cSrcweir } 1127*cdf0e10cSrcweir } 1128*cdf0e10cSrcweir 1129*cdf0e10cSrcweir if ( !m_bIsSAXEventKeeperOnTheSAXChain ) 1130*cdf0e10cSrcweir { 1131*cdf0e10cSrcweir addEndAncestorEvent(name); 1132*cdf0e10cSrcweir } 1133*cdf0e10cSrcweir 1134*cdf0e10cSrcweir m_xExportHandler->endElement(name); 1135*cdf0e10cSrcweir } 1136*cdf0e10cSrcweir 1137*cdf0e10cSrcweir void SAL_CALL XSecTester::setDocumentLocator( const cssu::Reference<cssxs::XLocator>& ) 1138*cdf0e10cSrcweir throw (cssu::RuntimeException) 1139*cdf0e10cSrcweir { 1140*cdf0e10cSrcweir } 1141*cdf0e10cSrcweir 1142*cdf0e10cSrcweir void XSecTester::changeOutput() 1143*cdf0e10cSrcweir { 1144*cdf0e10cSrcweir if (m_bIsExporting) 1145*cdf0e10cSrcweir { 1146*cdf0e10cSrcweir if (m_bIsSAXEventKeeperOnTheSAXChain) 1147*cdf0e10cSrcweir { 1148*cdf0e10cSrcweir m_xExportHandler = cssu::Reference<cssxs::XDocumentHandler> 1149*cdf0e10cSrcweir (m_xSAXEventKeeper, cssu::UNO_QUERY); 1150*cdf0e10cSrcweir 1151*cdf0e10cSrcweir m_xSAXEventKeeper->setNextHandler(NULL); 1152*cdf0e10cSrcweir 1153*cdf0e10cSrcweir flushAncestorEvents(m_xExportHandler); 1154*cdf0e10cSrcweir 1155*cdf0e10cSrcweir m_xSAXEventKeeper->setNextHandler(m_xOutputHandler); 1156*cdf0e10cSrcweir } 1157*cdf0e10cSrcweir else 1158*cdf0e10cSrcweir { 1159*cdf0e10cSrcweir m_xExportHandler = m_xOutputHandler; 1160*cdf0e10cSrcweir } 1161*cdf0e10cSrcweir } 1162*cdf0e10cSrcweir else 1163*cdf0e10cSrcweir { 1164*cdf0e10cSrcweir if (m_bIsSAXEventKeeperOnTheSAXChain) 1165*cdf0e10cSrcweir { 1166*cdf0e10cSrcweir cssu::Reference<cssxs::XDocumentHandler> xSAXEventKeeperHandler 1167*cdf0e10cSrcweir (m_xSAXEventKeeper, cssu::UNO_QUERY); 1168*cdf0e10cSrcweir 1169*cdf0e10cSrcweir m_xSAXEventKeeper->setNextHandler(NULL); 1170*cdf0e10cSrcweir 1171*cdf0e10cSrcweir flushAncestorEvents(xSAXEventKeeperHandler); 1172*cdf0e10cSrcweir 1173*cdf0e10cSrcweir m_xSaxParser->setDocumentHandler(xSAXEventKeeperHandler); 1174*cdf0e10cSrcweir m_xSAXEventKeeper->setNextHandler(this); 1175*cdf0e10cSrcweir } 1176*cdf0e10cSrcweir else 1177*cdf0e10cSrcweir { 1178*cdf0e10cSrcweir m_xSaxParser->setDocumentHandler(this); 1179*cdf0e10cSrcweir } 1180*cdf0e10cSrcweir 1181*cdf0e10cSrcweir } 1182*cdf0e10cSrcweir } 1183*cdf0e10cSrcweir 1184*cdf0e10cSrcweir bool XSecTester::foundSecurityRelated() 1185*cdf0e10cSrcweir { 1186*cdf0e10cSrcweir if (m_xSAXEventKeeper == NULL) 1187*cdf0e10cSrcweir { 1188*cdf0e10cSrcweir m_bIsBlocking = false; 1189*cdf0e10cSrcweir m_bIsInsideCollectedElement = false; 1190*cdf0e10cSrcweir 1191*cdf0e10cSrcweir m_xXMLDocumentWrapper = cssu::Reference<cssxw::XXMLDocumentWrapper> 1192*cdf0e10cSrcweir (mxMSF->createInstance( m_ouXMLDocumentWrapperComponentName ), 1193*cdf0e10cSrcweir cssu::UNO_QUERY); 1194*cdf0e10cSrcweir 1195*cdf0e10cSrcweir m_xSAXEventKeeper = cssu::Reference< cssxc::sax::XSecuritySAXEventKeeper > 1196*cdf0e10cSrcweir (mxMSF->createInstance( rtl::OUString::createFromAscii( SAXEVENTKEEPER_COMPONENT )), 1197*cdf0e10cSrcweir cssu::UNO_QUERY); 1198*cdf0e10cSrcweir 1199*cdf0e10cSrcweir cssu::Reference<cssl::XInitialization> xInitialization(m_xSAXEventKeeper, cssu::UNO_QUERY); 1200*cdf0e10cSrcweir 1201*cdf0e10cSrcweir cssu::Sequence <cssu::Any> arg(1); 1202*cdf0e10cSrcweir arg[0] = cssu::makeAny(m_xXMLDocumentWrapper); 1203*cdf0e10cSrcweir xInitialization->initialize(arg); 1204*cdf0e10cSrcweir 1205*cdf0e10cSrcweir cssu::Reference<cssxc::sax::XSAXEventKeeperStatusChangeBroadcaster> 1206*cdf0e10cSrcweir xSAXEventKeeperStatusChangeBroadcaster(m_xSAXEventKeeper, cssu::UNO_QUERY); 1207*cdf0e10cSrcweir xSAXEventKeeperStatusChangeBroadcaster->addSAXEventKeeperStatusChangeListener(this); 1208*cdf0e10cSrcweir } 1209*cdf0e10cSrcweir 1210*cdf0e10cSrcweir bool rc = false; 1211*cdf0e10cSrcweir 1212*cdf0e10cSrcweir if (!m_bIsSAXEventKeeperOnTheSAXChain) 1213*cdf0e10cSrcweir { 1214*cdf0e10cSrcweir rc = true; 1215*cdf0e10cSrcweir } 1216*cdf0e10cSrcweir 1217*cdf0e10cSrcweir m_bIsSAXEventKeeperOnTheSAXChain=true; 1218*cdf0e10cSrcweir changeOutput(); 1219*cdf0e10cSrcweir 1220*cdf0e10cSrcweir return rc; 1221*cdf0e10cSrcweir } 1222*cdf0e10cSrcweir 1223*cdf0e10cSrcweir void XSecTester::findKeyOrReference(SecurityEntity* pSecurityEntity, const rtl::OUString& ouUri, bool bIsFindingKey) 1224*cdf0e10cSrcweir { 1225*cdf0e10cSrcweir std::vector<rtl::OUString>::iterator ii_referenceURIs; 1226*cdf0e10cSrcweir std::vector<int>::iterator ii_referenceKeeperIds; 1227*cdf0e10cSrcweir std::vector<int>::iterator ii_referenceRefNums; 1228*cdf0e10cSrcweir 1229*cdf0e10cSrcweir for (ii_referenceURIs = m_vUnsolvedReferenceURIs.begin(), 1230*cdf0e10cSrcweir ii_referenceKeeperIds = m_vUnsolvedReferenceKeeperIds.begin(), 1231*cdf0e10cSrcweir ii_referenceRefNums = m_vUnsolvedReferenceRefNums.begin(); 1232*cdf0e10cSrcweir ii_referenceURIs != m_vUnsolvedReferenceURIs.end(); ) 1233*cdf0e10cSrcweir { 1234*cdf0e10cSrcweir rtl::OUString ouReferenceUri = *ii_referenceURIs; 1235*cdf0e10cSrcweir 1236*cdf0e10cSrcweir if (ouReferenceUri == ouUri) 1237*cdf0e10cSrcweir { 1238*cdf0e10cSrcweir int nKeeperId = *ii_referenceKeeperIds; 1239*cdf0e10cSrcweir int nRefNum = *ii_referenceRefNums; 1240*cdf0e10cSrcweir 1241*cdf0e10cSrcweir if ( bIsFindingKey ) 1242*cdf0e10cSrcweir { 1243*cdf0e10cSrcweir int nClonedKeeperId = m_xSAXEventKeeper->cloneElementCollector( 1244*cdf0e10cSrcweir nKeeperId, 1245*cdf0e10cSrcweir m_bIsExporting? 1246*cdf0e10cSrcweir (cssxc::sax::ElementMarkPriority_BEFOREMODIFY): 1247*cdf0e10cSrcweir (cssxc::sax::ElementMarkPriority_AFTERMODIFY)); 1248*cdf0e10cSrcweir 1249*cdf0e10cSrcweir pSecurityEntity->setKeyId(nClonedKeeperId); 1250*cdf0e10cSrcweir 1251*cdf0e10cSrcweir m_xSAXEventKeeper->setSecurityId(nClonedKeeperId, pSecurityEntity->getSecurityId()); 1252*cdf0e10cSrcweir 1253*cdf0e10cSrcweir cssu::Reference<cssxc::sax::XReferenceResolvedBroadcaster> 1254*cdf0e10cSrcweir xReferenceResolvedBroadcaster(m_xSAXEventKeeper, cssu::UNO_QUERY); 1255*cdf0e10cSrcweir xReferenceResolvedBroadcaster->addReferenceResolvedListener( 1256*cdf0e10cSrcweir nClonedKeeperId, 1257*cdf0e10cSrcweir pSecurityEntity->getReferenceListener()); 1258*cdf0e10cSrcweir } 1259*cdf0e10cSrcweir else 1260*cdf0e10cSrcweir { 1261*cdf0e10cSrcweir int nClonedKeeperId = m_xSAXEventKeeper->cloneElementCollector( 1262*cdf0e10cSrcweir nKeeperId, 1263*cdf0e10cSrcweir m_bIsExporting? 1264*cdf0e10cSrcweir (cssxc::sax::ElementMarkPriority_AFTERMODIFY): 1265*cdf0e10cSrcweir (cssxc::sax::ElementMarkPriority_BEFOREMODIFY)); 1266*cdf0e10cSrcweir 1267*cdf0e10cSrcweir m_xSAXEventKeeper->setSecurityId(nClonedKeeperId, pSecurityEntity->getSecurityId()); 1268*cdf0e10cSrcweir 1269*cdf0e10cSrcweir cssu::Reference<cssxc::sax::XReferenceResolvedBroadcaster> 1270*cdf0e10cSrcweir xReferenceResolvedBroadcaster 1271*cdf0e10cSrcweir (m_xSAXEventKeeper, cssu::UNO_QUERY); 1272*cdf0e10cSrcweir xReferenceResolvedBroadcaster->addReferenceResolvedListener( 1273*cdf0e10cSrcweir nClonedKeeperId, 1274*cdf0e10cSrcweir pSecurityEntity->getReferenceListener()); 1275*cdf0e10cSrcweir 1276*cdf0e10cSrcweir cssu::Reference<cssxc::sax::XReferenceCollector> xReferenceCollector 1277*cdf0e10cSrcweir (pSecurityEntity->getReferenceListener(), cssu::UNO_QUERY); 1278*cdf0e10cSrcweir xReferenceCollector->setReferenceId(nClonedKeeperId); 1279*cdf0e10cSrcweir } 1280*cdf0e10cSrcweir 1281*cdf0e10cSrcweir nRefNum--; 1282*cdf0e10cSrcweir if (nRefNum == 0) 1283*cdf0e10cSrcweir { 1284*cdf0e10cSrcweir m_xSAXEventKeeper->removeElementCollector(nKeeperId); 1285*cdf0e10cSrcweir 1286*cdf0e10cSrcweir ii_referenceURIs = m_vUnsolvedReferenceURIs.erase(ii_referenceURIs); 1287*cdf0e10cSrcweir ii_referenceKeeperIds = m_vUnsolvedReferenceKeeperIds.erase(ii_referenceKeeperIds); 1288*cdf0e10cSrcweir ii_referenceRefNums = m_vUnsolvedReferenceRefNums.erase(ii_referenceRefNums); 1289*cdf0e10cSrcweir } 1290*cdf0e10cSrcweir else 1291*cdf0e10cSrcweir { 1292*cdf0e10cSrcweir (*ii_referenceRefNums) = nRefNum; 1293*cdf0e10cSrcweir 1294*cdf0e10cSrcweir ii_referenceURIs++; 1295*cdf0e10cSrcweir ii_referenceKeeperIds++; 1296*cdf0e10cSrcweir ii_referenceRefNums++; 1297*cdf0e10cSrcweir } 1298*cdf0e10cSrcweir 1299*cdf0e10cSrcweir if (bIsFindingKey) 1300*cdf0e10cSrcweir { 1301*cdf0e10cSrcweir break; 1302*cdf0e10cSrcweir } 1303*cdf0e10cSrcweir } 1304*cdf0e10cSrcweir else 1305*cdf0e10cSrcweir { 1306*cdf0e10cSrcweir ii_referenceURIs++; 1307*cdf0e10cSrcweir ii_referenceKeeperIds++; 1308*cdf0e10cSrcweir ii_referenceRefNums++; 1309*cdf0e10cSrcweir } 1310*cdf0e10cSrcweir } 1311*cdf0e10cSrcweir } 1312*cdf0e10cSrcweir 1313*cdf0e10cSrcweir bool XSecTester::checkSecurityElement( 1314*cdf0e10cSrcweir const rtl::OUString& ouLocalName, 1315*cdf0e10cSrcweir const cssu::Reference<cssxs::XAttributeList>& xAttribs) 1316*cdf0e10cSrcweir { 1317*cdf0e10cSrcweir bool rc = false; 1318*cdf0e10cSrcweir 1319*cdf0e10cSrcweir if (ouLocalName.equalsAscii(SIGNATURE_STR)) 1320*cdf0e10cSrcweir { 1321*cdf0e10cSrcweir SignatureEntity* pSignatureEntity = new SignatureEntity( 1322*cdf0e10cSrcweir m_xSAXEventKeeper, 1323*cdf0e10cSrcweir m_bIsExporting, 1324*cdf0e10cSrcweir this, 1325*cdf0e10cSrcweir m_xXMLSecurityContext, 1326*cdf0e10cSrcweir m_xXMLSignature, 1327*cdf0e10cSrcweir mxMSF); 1328*cdf0e10cSrcweir 1329*cdf0e10cSrcweir m_vSignatureList.push_back(pSignatureEntity); 1330*cdf0e10cSrcweir 1331*cdf0e10cSrcweir m_stCurrentPath.push(pSignatureEntity); 1332*cdf0e10cSrcweir m_stCurrentPathType.push(false); 1333*cdf0e10cSrcweir } 1334*cdf0e10cSrcweir else if (ouLocalName.equalsAscii(REFERENCE_STR)) 1335*cdf0e10cSrcweir { 1336*cdf0e10cSrcweir if (!m_stCurrentPath.empty()) 1337*cdf0e10cSrcweir { 1338*cdf0e10cSrcweir void* pSignedInfo = m_stCurrentPath.top(); 1339*cdf0e10cSrcweir bool bIsStringType = m_stCurrentPathType.top(); 1340*cdf0e10cSrcweir 1341*cdf0e10cSrcweir m_stCurrentPath.pop(); 1342*cdf0e10cSrcweir m_stCurrentPathType.pop(); 1343*cdf0e10cSrcweir 1344*cdf0e10cSrcweir if (bIsStringType && !m_stCurrentPath.empty()) 1345*cdf0e10cSrcweir { 1346*cdf0e10cSrcweir void* pSignature = m_stCurrentPath.top(); 1347*cdf0e10cSrcweir bool bIsStringType2 = m_stCurrentPathType.top(); 1348*cdf0e10cSrcweir 1349*cdf0e10cSrcweir if (!strcmp((const char*)pSignedInfo, SIGNEDINFO_STR) && !bIsStringType2) 1350*cdf0e10cSrcweir { 1351*cdf0e10cSrcweir rtl::OUString ouUri = xAttribs->getValueByName 1352*cdf0e10cSrcweir (rtl::OUString(RTL_ASCII_USTRINGPARAM( URI_ATTR_STR ))); 1353*cdf0e10cSrcweir 1354*cdf0e10cSrcweir if (ouUri.matchAsciiL("#", 1, 0)) 1355*cdf0e10cSrcweir { 1356*cdf0e10cSrcweir rtl::OUString uri = ouUri.copy(1); 1357*cdf0e10cSrcweir SignatureEntity* pSignatureEntity = (SignatureEntity *)pSignature; 1358*cdf0e10cSrcweir 1359*cdf0e10cSrcweir if (uri != NULL && uri.getLength()>0) 1360*cdf0e10cSrcweir { 1361*cdf0e10cSrcweir pSignatureEntity->addReferenceURI(uri); 1362*cdf0e10cSrcweir findKeyOrReference(pSignatureEntity, uri, true); 1363*cdf0e10cSrcweir } 1364*cdf0e10cSrcweir } 1365*cdf0e10cSrcweir } 1366*cdf0e10cSrcweir } 1367*cdf0e10cSrcweir m_stCurrentPath.push(pSignedInfo); 1368*cdf0e10cSrcweir m_stCurrentPathType.push(bIsStringType); 1369*cdf0e10cSrcweir } 1370*cdf0e10cSrcweir m_stCurrentPath.push( (void *)REFERENCE_STR); 1371*cdf0e10cSrcweir m_stCurrentPathType.push(true); 1372*cdf0e10cSrcweir } 1373*cdf0e10cSrcweir else if(ouLocalName.equalsAscii(KEYVALUE_STR) || 1374*cdf0e10cSrcweir ouLocalName.equalsAscii(KEYNAME_STR) || 1375*cdf0e10cSrcweir ouLocalName.equalsAscii(X509DATA_STR) || 1376*cdf0e10cSrcweir ouLocalName.equalsAscii(ENCRYPTEDKEY_STR)) 1377*cdf0e10cSrcweir { 1378*cdf0e10cSrcweir if (!m_stCurrentPath.empty()) 1379*cdf0e10cSrcweir { 1380*cdf0e10cSrcweir void* pKeyInfo = m_stCurrentPath.top(); 1381*cdf0e10cSrcweir bool bIsStringType = m_stCurrentPathType.top(); 1382*cdf0e10cSrcweir 1383*cdf0e10cSrcweir m_stCurrentPath.pop(); 1384*cdf0e10cSrcweir m_stCurrentPathType.pop(); 1385*cdf0e10cSrcweir 1386*cdf0e10cSrcweir if (bIsStringType && !m_stCurrentPath.empty()) 1387*cdf0e10cSrcweir { 1388*cdf0e10cSrcweir bool bIsStringType2 = m_stCurrentPathType.top(); 1389*cdf0e10cSrcweir 1390*cdf0e10cSrcweir if (!bIsStringType2) 1391*cdf0e10cSrcweir { 1392*cdf0e10cSrcweir SecurityEntity *pSecurityEntity = 1393*cdf0e10cSrcweir (SecurityEntity *) (m_stCurrentPath.top()); 1394*cdf0e10cSrcweir pSecurityEntity->setKeyId(0); 1395*cdf0e10cSrcweir } 1396*cdf0e10cSrcweir } 1397*cdf0e10cSrcweir 1398*cdf0e10cSrcweir m_stCurrentPath.push(pKeyInfo); 1399*cdf0e10cSrcweir m_stCurrentPathType.push(bIsStringType); 1400*cdf0e10cSrcweir } 1401*cdf0e10cSrcweir 1402*cdf0e10cSrcweir m_stCurrentPath.push((void *)KEYVALUE_STR); 1403*cdf0e10cSrcweir m_stCurrentPathType.push(true); 1404*cdf0e10cSrcweir } 1405*cdf0e10cSrcweir else if(ouLocalName.equalsAscii(RETRIEVALMETHOD_STR)) 1406*cdf0e10cSrcweir { 1407*cdf0e10cSrcweir if (!m_stCurrentPath.empty()) 1408*cdf0e10cSrcweir { 1409*cdf0e10cSrcweir void* pKeyInfo = m_stCurrentPath.top(); 1410*cdf0e10cSrcweir bool bIsStringType = m_stCurrentPathType.top(); 1411*cdf0e10cSrcweir 1412*cdf0e10cSrcweir m_stCurrentPath.pop(); 1413*cdf0e10cSrcweir m_stCurrentPathType.pop(); 1414*cdf0e10cSrcweir 1415*cdf0e10cSrcweir if (bIsStringType && !m_stCurrentPath.empty()) 1416*cdf0e10cSrcweir { 1417*cdf0e10cSrcweir bool bIsStringType2 = m_stCurrentPathType.top(); 1418*cdf0e10cSrcweir 1419*cdf0e10cSrcweir if (!bIsStringType2) 1420*cdf0e10cSrcweir { 1421*cdf0e10cSrcweir SecurityEntity *pSecurityEntity = 1422*cdf0e10cSrcweir (SecurityEntity *) m_stCurrentPath.top(); 1423*cdf0e10cSrcweir rtl::OUString ouUri = xAttribs->getValueByName( 1424*cdf0e10cSrcweir rtl::OUString(RTL_ASCII_USTRINGPARAM( URI_ATTR_STR ))); 1425*cdf0e10cSrcweir 1426*cdf0e10cSrcweir if (!strcmp((const char *)pKeyInfo, KEYINFO_STR) && 1427*cdf0e10cSrcweir ouUri != NULL && ouUri.getLength()>0) 1428*cdf0e10cSrcweir { 1429*cdf0e10cSrcweir pSecurityEntity->setKeyURI(ouUri); 1430*cdf0e10cSrcweir findKeyOrReference(pSecurityEntity, ouUri, true); 1431*cdf0e10cSrcweir } 1432*cdf0e10cSrcweir } 1433*cdf0e10cSrcweir 1434*cdf0e10cSrcweir } 1435*cdf0e10cSrcweir 1436*cdf0e10cSrcweir m_stCurrentPath.push(pKeyInfo); 1437*cdf0e10cSrcweir m_stCurrentPathType.push(bIsStringType); 1438*cdf0e10cSrcweir } 1439*cdf0e10cSrcweir 1440*cdf0e10cSrcweir m_stCurrentPath.push((void *)RETRIEVALMETHOD_STR); 1441*cdf0e10cSrcweir m_stCurrentPathType.push(true); 1442*cdf0e10cSrcweir } 1443*cdf0e10cSrcweir else if(ouLocalName.equalsAscii(KEYINFO_STR)) 1444*cdf0e10cSrcweir { 1445*cdf0e10cSrcweir m_stCurrentPath.push((void *)KEYINFO_STR); 1446*cdf0e10cSrcweir m_stCurrentPathType.push(true); 1447*cdf0e10cSrcweir } 1448*cdf0e10cSrcweir else if(ouLocalName.equalsAscii(SIGNEDINFO_STR)) 1449*cdf0e10cSrcweir { 1450*cdf0e10cSrcweir m_stCurrentPath.push((void *)SIGNEDINFO_STR); 1451*cdf0e10cSrcweir m_stCurrentPathType.push(true); 1452*cdf0e10cSrcweir } 1453*cdf0e10cSrcweir else 1454*cdf0e10cSrcweir { 1455*cdf0e10cSrcweir m_stCurrentPath.push((void *)OTHER_ELEMENT_STR); 1456*cdf0e10cSrcweir m_stCurrentPathType.push(true); 1457*cdf0e10cSrcweir } 1458*cdf0e10cSrcweir 1459*cdf0e10cSrcweir return rc; 1460*cdf0e10cSrcweir } 1461*cdf0e10cSrcweir 1462*cdf0e10cSrcweir void XSecTester::checkReference( 1463*cdf0e10cSrcweir const rtl::OUString& ouLocalName, 1464*cdf0e10cSrcweir const cssu::Reference<cssxs::XAttributeList>& xAttribs, 1465*cdf0e10cSrcweir const rtl::OUString& ouId) 1466*cdf0e10cSrcweir { 1467*cdf0e10cSrcweir rtl::OUString refNumStr = 1468*cdf0e10cSrcweir xAttribs->getValueByName(rtl::OUString(RTL_ASCII_USTRINGPARAM(REFNUM_ATTR_STR))); 1469*cdf0e10cSrcweir 1470*cdf0e10cSrcweir if (ouId != NULL && ouId.getLength()>0 ) 1471*cdf0e10cSrcweir { 1472*cdf0e10cSrcweir int nRefNum = 999; 1473*cdf0e10cSrcweir if (refNumStr != NULL && refNumStr.getLength()>0 ) 1474*cdf0e10cSrcweir { 1475*cdf0e10cSrcweir nRefNum = refNumStr.toInt32(); 1476*cdf0e10cSrcweir } 1477*cdf0e10cSrcweir 1478*cdf0e10cSrcweir int nLength = m_vSignatureList.size(); 1479*cdf0e10cSrcweir for (int i = 0; i<nLength; ++i) 1480*cdf0e10cSrcweir { 1481*cdf0e10cSrcweir SignatureEntity* pSignatureEntity = m_vSignatureList.at(i); 1482*cdf0e10cSrcweir 1483*cdf0e10cSrcweir if (pSignatureEntity->setReference(ouId, m_bIsExporting)) 1484*cdf0e10cSrcweir { 1485*cdf0e10cSrcweir nRefNum--; 1486*cdf0e10cSrcweir } 1487*cdf0e10cSrcweir 1488*cdf0e10cSrcweir if (pSignatureEntity->setKey(ouId, m_bIsExporting)) 1489*cdf0e10cSrcweir { 1490*cdf0e10cSrcweir nRefNum--; 1491*cdf0e10cSrcweir } 1492*cdf0e10cSrcweir } 1493*cdf0e10cSrcweir 1494*cdf0e10cSrcweir if (nRefNum>0) 1495*cdf0e10cSrcweir { 1496*cdf0e10cSrcweir int nKeeperId; 1497*cdf0e10cSrcweir 1498*cdf0e10cSrcweir if (ouLocalName.equalsAscii(ENCRYPTEDKEY_STR)) 1499*cdf0e10cSrcweir { 1500*cdf0e10cSrcweir nKeeperId = m_xSAXEventKeeper->addSecurityElementCollector( 1501*cdf0e10cSrcweir m_bIsExporting ? 1502*cdf0e10cSrcweir (cssxc::sax::ElementMarkPriority_BEFOREMODIFY): 1503*cdf0e10cSrcweir (cssxc::sax::ElementMarkPriority_AFTERMODIFY), 1504*cdf0e10cSrcweir true); 1505*cdf0e10cSrcweir } 1506*cdf0e10cSrcweir else 1507*cdf0e10cSrcweir { 1508*cdf0e10cSrcweir nKeeperId = m_xSAXEventKeeper->addSecurityElementCollector( 1509*cdf0e10cSrcweir m_bIsExporting? 1510*cdf0e10cSrcweir (cssxc::sax::ElementMarkPriority_AFTERMODIFY): 1511*cdf0e10cSrcweir (cssxc::sax::ElementMarkPriority_BEFOREMODIFY), 1512*cdf0e10cSrcweir false); 1513*cdf0e10cSrcweir } 1514*cdf0e10cSrcweir 1515*cdf0e10cSrcweir m_vUnsolvedReferenceURIs.push_back(ouId); 1516*cdf0e10cSrcweir m_vUnsolvedReferenceKeeperIds.push_back(nKeeperId); 1517*cdf0e10cSrcweir m_vUnsolvedReferenceRefNums.push_back(nRefNum); 1518*cdf0e10cSrcweir } 1519*cdf0e10cSrcweir } 1520*cdf0e10cSrcweir } 1521*cdf0e10cSrcweir 1522*cdf0e10cSrcweir void XSecTester::endMission() 1523*cdf0e10cSrcweir { 1524*cdf0e10cSrcweir while (m_vSignatureList.size() > 0) 1525*cdf0e10cSrcweir { 1526*cdf0e10cSrcweir if (m_vSignatureList.size()>0) 1527*cdf0e10cSrcweir { 1528*cdf0e10cSrcweir SignatureEntity * pSignatureEntity = m_vSignatureList.at(0); 1529*cdf0e10cSrcweir m_vSignatureList.erase(m_vSignatureList.begin()); 1530*cdf0e10cSrcweir pSignatureEntity->endMission(); 1531*cdf0e10cSrcweir delete pSignatureEntity; 1532*cdf0e10cSrcweir } 1533*cdf0e10cSrcweir } 1534*cdf0e10cSrcweir 1535*cdf0e10cSrcweir while (m_vUnsolvedReferenceURIs.size()>0) 1536*cdf0e10cSrcweir { 1537*cdf0e10cSrcweir int nKeeperId = m_vUnsolvedReferenceKeeperIds.at(0); 1538*cdf0e10cSrcweir m_xSAXEventKeeper->removeElementCollector(nKeeperId); 1539*cdf0e10cSrcweir m_vUnsolvedReferenceURIs.erase(m_vUnsolvedReferenceURIs.begin()); 1540*cdf0e10cSrcweir m_vUnsolvedReferenceKeeperIds.erase(m_vUnsolvedReferenceKeeperIds.begin()); 1541*cdf0e10cSrcweir m_vUnsolvedReferenceRefNums.erase(m_vUnsolvedReferenceRefNums.begin()); 1542*cdf0e10cSrcweir } 1543*cdf0e10cSrcweir } 1544*cdf0e10cSrcweir 1545*cdf0e10cSrcweir void XSecTester::addStartAncestorEvent( 1546*cdf0e10cSrcweir const rtl::OUString& ouName, 1547*cdf0e10cSrcweir const cssu::Reference< cssxs::XAttributeList >& xAttribs) 1548*cdf0e10cSrcweir { 1549*cdf0e10cSrcweir sal_Int32 nLength = xAttribs->getLength(); 1550*cdf0e10cSrcweir AncestorEvent* ancestorEvent = new AncestorEvent( nLength ); 1551*cdf0e10cSrcweir 1552*cdf0e10cSrcweir ancestorEvent->bIsStartElement = true; 1553*cdf0e10cSrcweir ancestorEvent->ouName = ouName; 1554*cdf0e10cSrcweir 1555*cdf0e10cSrcweir for (int i = 0; i<nLength; ++i) 1556*cdf0e10cSrcweir { 1557*cdf0e10cSrcweir (ancestorEvent->aAttributeList[i]).sName = xAttribs->getNameByIndex((short)i); 1558*cdf0e10cSrcweir (ancestorEvent->aAttributeList[i]).sValue =xAttribs->getValueByIndex((short)i); 1559*cdf0e10cSrcweir } 1560*cdf0e10cSrcweir 1561*cdf0e10cSrcweir m_vAncestorEvents.push_back(ancestorEvent); 1562*cdf0e10cSrcweir } 1563*cdf0e10cSrcweir 1564*cdf0e10cSrcweir void XSecTester::addEndAncestorEvent(const rtl::OUString& ouName) 1565*cdf0e10cSrcweir { 1566*cdf0e10cSrcweir AncestorEvent* ancestorEvent = new AncestorEvent(0); 1567*cdf0e10cSrcweir 1568*cdf0e10cSrcweir ancestorEvent->bIsStartElement = false; 1569*cdf0e10cSrcweir ancestorEvent->ouName = ouName; 1570*cdf0e10cSrcweir 1571*cdf0e10cSrcweir m_vAncestorEvents.push_back(ancestorEvent); 1572*cdf0e10cSrcweir } 1573*cdf0e10cSrcweir 1574*cdf0e10cSrcweir void XSecTester::sendAncestorStartElementEvent( 1575*cdf0e10cSrcweir const rtl::OUString& ouName, 1576*cdf0e10cSrcweir const cssu::Sequence< cssxcsax::XMLAttribute >& attrList, 1577*cdf0e10cSrcweir const cssu::Reference< cssxs::XDocumentHandler >& xDocumentHandler) const 1578*cdf0e10cSrcweir { 1579*cdf0e10cSrcweir SvXMLAttributeList* pAttributeList = new SvXMLAttributeList(); 1580*cdf0e10cSrcweir cssu::Reference < cssxs::XAttributeList > xAttrList 1581*cdf0e10cSrcweir = cssu::Reference< cssxs::XAttributeList > (pAttributeList); 1582*cdf0e10cSrcweir 1583*cdf0e10cSrcweir sal_Int32 nLength = attrList.getLength(); 1584*cdf0e10cSrcweir 1585*cdf0e10cSrcweir for (int i = 0; i<nLength; ++i) 1586*cdf0e10cSrcweir { 1587*cdf0e10cSrcweir pAttributeList->AddAttribute( attrList[i].sName, attrList[i].sValue); 1588*cdf0e10cSrcweir } 1589*cdf0e10cSrcweir 1590*cdf0e10cSrcweir xDocumentHandler->startElement(ouName, xAttrList); 1591*cdf0e10cSrcweir } 1592*cdf0e10cSrcweir 1593*cdf0e10cSrcweir void XSecTester::sendAncestorEndElementEvent( 1594*cdf0e10cSrcweir const rtl::OUString& ouName, 1595*cdf0e10cSrcweir const cssu::Reference< cssxs::XDocumentHandler >& xDocumentHandler) const 1596*cdf0e10cSrcweir { 1597*cdf0e10cSrcweir xDocumentHandler->endElement(ouName); 1598*cdf0e10cSrcweir } 1599*cdf0e10cSrcweir 1600*cdf0e10cSrcweir std::vector< AncestorEvent* >::const_iterator XSecTester::checkAncestorStartElementEvent( 1601*cdf0e10cSrcweir const std::vector< AncestorEvent* >::const_iterator& ii, 1602*cdf0e10cSrcweir const cssu::Reference< cssxs::XDocumentHandler >& xDocumentHandler) const 1603*cdf0e10cSrcweir { 1604*cdf0e10cSrcweir std::vector< AncestorEvent* >::const_iterator next = ii+1; 1605*cdf0e10cSrcweir 1606*cdf0e10cSrcweir if (next == m_vAncestorEvents.end()) 1607*cdf0e10cSrcweir { 1608*cdf0e10cSrcweir sendAncestorStartElementEvent( 1609*cdf0e10cSrcweir (*ii)->ouName, (*ii)->aAttributeList, xDocumentHandler); 1610*cdf0e10cSrcweir } 1611*cdf0e10cSrcweir else 1612*cdf0e10cSrcweir { 1613*cdf0e10cSrcweir while ((next != m_vAncestorEvents.end()) && ((*next)->bIsStartElement)) 1614*cdf0e10cSrcweir { 1615*cdf0e10cSrcweir next = checkAncestorStartElementEvent(next, xDocumentHandler); 1616*cdf0e10cSrcweir } 1617*cdf0e10cSrcweir 1618*cdf0e10cSrcweir if (next != m_vAncestorEvents.end()) 1619*cdf0e10cSrcweir { 1620*cdf0e10cSrcweir next++; 1621*cdf0e10cSrcweir } 1622*cdf0e10cSrcweir } 1623*cdf0e10cSrcweir 1624*cdf0e10cSrcweir return next; 1625*cdf0e10cSrcweir } 1626*cdf0e10cSrcweir 1627*cdf0e10cSrcweir void XSecTester::flushAncestorEvents( 1628*cdf0e10cSrcweir const cssu::Reference< cssxs::XDocumentHandler >& xDocumentHandler) 1629*cdf0e10cSrcweir { 1630*cdf0e10cSrcweir std::vector< AncestorEvent* >::const_iterator ii; 1631*cdf0e10cSrcweir 1632*cdf0e10cSrcweir if (xDocumentHandler != NULL) 1633*cdf0e10cSrcweir { 1634*cdf0e10cSrcweir ii = m_vAncestorEvents.begin(); 1635*cdf0e10cSrcweir 1636*cdf0e10cSrcweir while (ii != m_vAncestorEvents.end()) 1637*cdf0e10cSrcweir { 1638*cdf0e10cSrcweir AncestorEvent* ancestorEvent = *ii; 1639*cdf0e10cSrcweir 1640*cdf0e10cSrcweir if (ancestorEvent->bIsStartElement) 1641*cdf0e10cSrcweir { 1642*cdf0e10cSrcweir ii = checkAncestorStartElementEvent(ii, xDocumentHandler); 1643*cdf0e10cSrcweir } 1644*cdf0e10cSrcweir else 1645*cdf0e10cSrcweir { 1646*cdf0e10cSrcweir sendAncestorEndElementEvent((*ii)->ouName, xDocumentHandler); 1647*cdf0e10cSrcweir ii++; 1648*cdf0e10cSrcweir } 1649*cdf0e10cSrcweir } 1650*cdf0e10cSrcweir } 1651*cdf0e10cSrcweir 1652*cdf0e10cSrcweir /* free the ancestor events list */ 1653*cdf0e10cSrcweir std::vector< AncestorEvent* >::iterator jj; 1654*cdf0e10cSrcweir 1655*cdf0e10cSrcweir while (m_vAncestorEvents.size()>0) 1656*cdf0e10cSrcweir { 1657*cdf0e10cSrcweir jj = m_vAncestorEvents.begin(); 1658*cdf0e10cSrcweir delete *jj; 1659*cdf0e10cSrcweir m_vAncestorEvents.erase(jj); 1660*cdf0e10cSrcweir } 1661*cdf0e10cSrcweir } 1662*cdf0e10cSrcweir 1663*cdf0e10cSrcweir /* 1664*cdf0e10cSrcweir * Get the length of a file in a platform independant fashion 1665*cdf0e10cSrcweir */ 1666*cdf0e10cSrcweir int getLength(const char *pInputFileName) 1667*cdf0e10cSrcweir { 1668*cdf0e10cSrcweir int nSize = 0; 1669*cdf0e10cSrcweir std::ifstream data(pInputFileName); 1670*cdf0e10cSrcweir 1671*cdf0e10cSrcweir data.seekg(0, std::ios_base::end); 1672*cdf0e10cSrcweir nSize = data.tellg(); 1673*cdf0e10cSrcweir 1674*cdf0e10cSrcweir return nSize; 1675*cdf0e10cSrcweir } 1676*cdf0e10cSrcweir 1677*cdf0e10cSrcweir void outputHeader() 1678*cdf0e10cSrcweir { 1679*cdf0e10cSrcweir fprintf(stderr, "%16s%4s%8s%12s%12s%12s%12s\n", "File Name", "E/I", "Size", "-C++", "-Java", "Forw-O", "No S/E"); 1680*cdf0e10cSrcweir fprintf(stderr, "===============================================================================\n"); 1681*cdf0e10cSrcweir } 1682*cdf0e10cSrcweir 1683*cdf0e10cSrcweir /* 1684*cdf0e10cSrcweir * print the output on the screen as well as in the GNUPlot data file 1685*cdf0e10cSrcweir */ 1686*cdf0e10cSrcweir void output(const rtl::OUString& ouInputFileName, 1687*cdf0e10cSrcweir const rtl::OUString& ouTime_C, 1688*cdf0e10cSrcweir const rtl::OUString& ouTime_Java, 1689*cdf0e10cSrcweir const rtl::OUString& ouTime_NoSecurity, 1690*cdf0e10cSrcweir const rtl::OUString& ouTime_JavaForwardOnly, 1691*cdf0e10cSrcweir const rtl::OUString& ouRemark_C, 1692*cdf0e10cSrcweir const rtl::OUString& ouRemark_Java, 1693*cdf0e10cSrcweir bool bIsExporting) 1694*cdf0e10cSrcweir { 1695*cdf0e10cSrcweir int nSize = getLength(rtl::OString(ouInputFileName, ouInputFileName.getLength(), RTL_TEXTENCODING_ASCII_US).getStr()); 1696*cdf0e10cSrcweir std::ofstream data; 1697*cdf0e10cSrcweir 1698*cdf0e10cSrcweir /* print screen */ 1699*cdf0e10cSrcweir int nPosition = ouInputFileName.lastIndexOf('\\'); 1700*cdf0e10cSrcweir rtl::OUString fileName = ouInputFileName.copy(nPosition + 1); 1701*cdf0e10cSrcweir 1702*cdf0e10cSrcweir fprintf(stderr, "%16s", rtl::OString(fileName, fileName.getLength(), RTL_TEXTENCODING_ASCII_US).getStr()); 1703*cdf0e10cSrcweir 1704*cdf0e10cSrcweir fprintf(stderr, "%4s", bIsExporting?"E":"I"); 1705*cdf0e10cSrcweir fprintf(stderr, "%7dK", nSize/1024); 1706*cdf0e10cSrcweir fprintf(stderr, "%8s %3s", 1707*cdf0e10cSrcweir rtl::OString(ouTime_C, ouTime_C.getLength(), RTL_TEXTENCODING_ASCII_US).getStr(), 1708*cdf0e10cSrcweir rtl::OString(ouRemark_C, ouRemark_C.getLength(), RTL_TEXTENCODING_ASCII_US).getStr()); 1709*cdf0e10cSrcweir fprintf(stderr, "%8s %3s", 1710*cdf0e10cSrcweir rtl::OString(ouTime_Java, ouTime_Java.getLength(), RTL_TEXTENCODING_ASCII_US).getStr(), 1711*cdf0e10cSrcweir rtl::OString(ouRemark_Java, ouRemark_Java.getLength(), RTL_TEXTENCODING_ASCII_US).getStr()); 1712*cdf0e10cSrcweir fprintf(stderr, "%12s", rtl::OString(ouTime_JavaForwardOnly, ouTime_JavaForwardOnly.getLength(), RTL_TEXTENCODING_ASCII_US).getStr()); 1713*cdf0e10cSrcweir fprintf(stderr, "%12s", rtl::OString(ouTime_NoSecurity, ouTime_NoSecurity.getLength(), RTL_TEXTENCODING_ASCII_US).getStr()); 1714*cdf0e10cSrcweir fprintf(stderr, "\n"); 1715*cdf0e10cSrcweir 1716*cdf0e10cSrcweir /* output the data as GNUPlot data file */ 1717*cdf0e10cSrcweir /* 1718*cdf0e10cSrcweir char str[32]; 1719*cdf0e10cSrcweir sprintf(str, "%d %s", nSize, rtl::OString(ouTime_C, ouTime_C.getLength(), RTL_TEXTENCODING_ASCII_US).getStr()); 1720*cdf0e10cSrcweir data.open("d:\\time_vs_size.txt", std::ios::app); 1721*cdf0e10cSrcweir data << str << std::endl; 1722*cdf0e10cSrcweir data.close(); 1723*cdf0e10cSrcweir 1724*cdf0e10cSrcweir sprintf(str, "%d %s", nSize, rtl::OString(ouTime_Java, ouTime_Java.getLength(), RTL_TEXTENCODING_ASCII_US).getStr()); 1725*cdf0e10cSrcweir data.open("d:\\time_vs_size_without_sec.txt", std::ios::app); 1726*cdf0e10cSrcweir data << str << std::endl; 1727*cdf0e10cSrcweir data.close(); 1728*cdf0e10cSrcweir */ 1729*cdf0e10cSrcweir } 1730*cdf0e10cSrcweir 1731*cdf0e10cSrcweir int main( int argc, char **argv ) 1732*cdf0e10cSrcweir { 1733*cdf0e10cSrcweir if (argc < 3) 1734*cdf0e10cSrcweir { 1735*cdf0e10cSrcweir fprintf(stderr, "Usage: testtool <exportbatchfile> <importbatchfile> [<cppcryptotoken>] [<javacryptotoken>]\n"); 1736*cdf0e10cSrcweir exit (-1); 1737*cdf0e10cSrcweir } 1738*cdf0e10cSrcweir 1739*cdf0e10cSrcweir rtl::OUString aExportBatchFile = rtl::OUString::createFromAscii(argv[1]); 1740*cdf0e10cSrcweir rtl::OUString aImportBatchFile = rtl::OUString::createFromAscii(argv[2]); 1741*cdf0e10cSrcweir rtl::OUString aCPPCryptoToken; 1742*cdf0e10cSrcweir if ( argc > 3 ) 1743*cdf0e10cSrcweir aCPPCryptoToken = rtl::OUString::createFromAscii(argv[3]); 1744*cdf0e10cSrcweir rtl::OUString aJavaCryptoToken; 1745*cdf0e10cSrcweir if ( argc > 4 ) 1746*cdf0e10cSrcweir aJavaCryptoToken = rtl::OUString::createFromAscii(argv[4]); 1747*cdf0e10cSrcweir 1748*cdf0e10cSrcweir try 1749*cdf0e10cSrcweir { 1750*cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xMSF = CreateDemoServiceFactory(); 1751*cdf0e10cSrcweir 1752*cdf0e10cSrcweir XSecTester* pTester = new XSecTester( xMSF ); 1753*cdf0e10cSrcweir uno::Reference< xml::sax::XDocumentHandler > xKeepARef = pTester; 1754*cdf0e10cSrcweir 1755*cdf0e10cSrcweir pTester->setCryptoDir( aJavaCryptoToken, aCPPCryptoToken ); 1756*cdf0e10cSrcweir 1757*cdf0e10cSrcweir rtl::OUString ouTime_C, ouTime_Java, ouTime_NoSecurity, ouTime_JavaForwardOnly; 1758*cdf0e10cSrcweir rtl::OUString ouInputFileName; 1759*cdf0e10cSrcweir rtl::OUString outputFileName1; 1760*cdf0e10cSrcweir rtl::OUString outputFileName2; 1761*cdf0e10cSrcweir rtl::OUString ouRemark_C, ouRemark_Java; 1762*cdf0e10cSrcweir 1763*cdf0e10cSrcweir outputHeader(); 1764*cdf0e10cSrcweir 1765*cdf0e10cSrcweir std::ifstream batch_export, batch_import; 1766*cdf0e10cSrcweir 1767*cdf0e10cSrcweir batch_export.open(OUStringToOString( aExportBatchFile, RTL_TEXTENCODING_ASCII_US ).getStr()); 1768*cdf0e10cSrcweir 1769*cdf0e10cSrcweir const int MAX_LINE = 80; 1770*cdf0e10cSrcweir char line[MAX_LINE + 1]; 1771*cdf0e10cSrcweir 1772*cdf0e10cSrcweir while (batch_export.getline(line, MAX_LINE)) 1773*cdf0e10cSrcweir { 1774*cdf0e10cSrcweir ouInputFileName = rtl::OUString::createFromAscii(line); 1775*cdf0e10cSrcweir int nPosition = ouInputFileName.lastIndexOf('.'); 1776*cdf0e10cSrcweir int nPosition1; 1777*cdf0e10cSrcweir 1778*cdf0e10cSrcweir /* 1779*cdf0e10cSrcweir * export the file with signautre/encryption (C++) 1780*cdf0e10cSrcweir */ 1781*cdf0e10cSrcweir outputFileName1 = ouInputFileName.copy(0, nPosition) + 1782*cdf0e10cSrcweir rtl::OUString::createFromAscii("-ex.xml"); 1783*cdf0e10cSrcweir ouTime_C = pTester->export_xml(ouInputFileName, outputFileName1, sal_False); 1784*cdf0e10cSrcweir nPosition1 = ouTime_C.lastIndexOf('\t'); 1785*cdf0e10cSrcweir ouRemark_C = ouTime_C.copy(nPosition1 + 1); 1786*cdf0e10cSrcweir ouTime_C = ouTime_C.copy(0, nPosition1); 1787*cdf0e10cSrcweir 1788*cdf0e10cSrcweir /* 1789*cdf0e10cSrcweir * export the file with signautre/encryption (Java) 1790*cdf0e10cSrcweir */ 1791*cdf0e10cSrcweir outputFileName1 = ouInputFileName.copy(0, nPosition) + 1792*cdf0e10cSrcweir rtl::OUString::createFromAscii("-ex2.xml"); 1793*cdf0e10cSrcweir ouTime_Java = pTester->export_xml(ouInputFileName, outputFileName1, sal_True); 1794*cdf0e10cSrcweir nPosition1 = ouTime_Java.lastIndexOf('\t'); 1795*cdf0e10cSrcweir ouRemark_Java = ouTime_Java.copy(nPosition1 + 1); 1796*cdf0e10cSrcweir ouTime_Java = ouTime_Java.copy(0, nPosition1); 1797*cdf0e10cSrcweir 1798*cdf0e10cSrcweir /* 1799*cdf0e10cSrcweir * export the file without signautre/encryption 1800*cdf0e10cSrcweir */ 1801*cdf0e10cSrcweir outputFileName2 = ouInputFileName.copy(0, nPosition) + 1802*cdf0e10cSrcweir rtl::OUString::createFromAscii("-ex-no.xml"); 1803*cdf0e10cSrcweir ouTime_NoSecurity = pTester->transfer_without_sec(ouInputFileName, outputFileName2, sal_False); 1804*cdf0e10cSrcweir 1805*cdf0e10cSrcweir /* 1806*cdf0e10cSrcweir * export the file with Java Flat Filter 1807*cdf0e10cSrcweir */ 1808*cdf0e10cSrcweir outputFileName2 = ouInputFileName.copy(0, nPosition) + 1809*cdf0e10cSrcweir rtl::OUString::createFromAscii("-ex-jf.xml"); 1810*cdf0e10cSrcweir ouTime_JavaForwardOnly = pTester->transfer_without_sec(ouInputFileName, outputFileName2, sal_True); 1811*cdf0e10cSrcweir 1812*cdf0e10cSrcweir /* 1813*cdf0e10cSrcweir * print output 1814*cdf0e10cSrcweir */ 1815*cdf0e10cSrcweir output(ouInputFileName, ouTime_C, ouTime_Java, ouTime_NoSecurity, ouTime_JavaForwardOnly, ouRemark_C, ouRemark_Java, true); 1816*cdf0e10cSrcweir } 1817*cdf0e10cSrcweir 1818*cdf0e10cSrcweir batch_export.close(); 1819*cdf0e10cSrcweir 1820*cdf0e10cSrcweir batch_import.open(OUStringToOString( aImportBatchFile, RTL_TEXTENCODING_ASCII_US ).getStr()); 1821*cdf0e10cSrcweir 1822*cdf0e10cSrcweir while (batch_import.getline(line, MAX_LINE)) 1823*cdf0e10cSrcweir { 1824*cdf0e10cSrcweir ouInputFileName = rtl::OUString::createFromAscii(line); 1825*cdf0e10cSrcweir int nPosition = ouInputFileName.lastIndexOf('.'); 1826*cdf0e10cSrcweir int nPosition1; 1827*cdf0e10cSrcweir 1828*cdf0e10cSrcweir /* 1829*cdf0e10cSrcweir * import the file with signautre/encryption (C++) 1830*cdf0e10cSrcweir */ 1831*cdf0e10cSrcweir outputFileName1 = ouInputFileName.copy(0, nPosition) + 1832*cdf0e10cSrcweir rtl::OUString::createFromAscii("-im.xml"); 1833*cdf0e10cSrcweir ouTime_C = pTester->import_xml(ouInputFileName, outputFileName1, sal_False); 1834*cdf0e10cSrcweir nPosition1 = ouTime_C.lastIndexOf('\t'); 1835*cdf0e10cSrcweir ouRemark_C = ouTime_C.copy(nPosition1 + 1); 1836*cdf0e10cSrcweir ouTime_C = ouTime_C.copy(0, nPosition1); 1837*cdf0e10cSrcweir 1838*cdf0e10cSrcweir /* 1839*cdf0e10cSrcweir * import the file with signautre/encryption (Java) 1840*cdf0e10cSrcweir */ 1841*cdf0e10cSrcweir outputFileName1 = ouInputFileName.copy(0, nPosition) + 1842*cdf0e10cSrcweir rtl::OUString::createFromAscii("-im2.xml"); 1843*cdf0e10cSrcweir ouTime_Java = pTester->import_xml(ouInputFileName, outputFileName1, sal_True); 1844*cdf0e10cSrcweir nPosition1 = ouTime_Java.lastIndexOf('\t'); 1845*cdf0e10cSrcweir ouRemark_Java = ouTime_Java.copy(nPosition1 + 1); 1846*cdf0e10cSrcweir ouTime_Java = ouTime_Java.copy(0, nPosition1); 1847*cdf0e10cSrcweir 1848*cdf0e10cSrcweir /* 1849*cdf0e10cSrcweir * import the file without signautre/encryption 1850*cdf0e10cSrcweir */ 1851*cdf0e10cSrcweir outputFileName2 = ouInputFileName.copy(0, nPosition) + 1852*cdf0e10cSrcweir rtl::OUString::createFromAscii("-im-no.xml"); 1853*cdf0e10cSrcweir ouTime_NoSecurity = pTester->transfer_without_sec(ouInputFileName, outputFileName2, sal_False); 1854*cdf0e10cSrcweir 1855*cdf0e10cSrcweir /* 1856*cdf0e10cSrcweir * import the file without signautre/encryption 1857*cdf0e10cSrcweir */ 1858*cdf0e10cSrcweir 1859*cdf0e10cSrcweir outputFileName2 = ouInputFileName.copy(0, nPosition) + 1860*cdf0e10cSrcweir rtl::OUString::createFromAscii("-im-jf.xml"); 1861*cdf0e10cSrcweir ouTime_JavaForwardOnly = pTester->transfer_without_sec(ouInputFileName, outputFileName2, sal_True); 1862*cdf0e10cSrcweir 1863*cdf0e10cSrcweir /* 1864*cdf0e10cSrcweir * print output 1865*cdf0e10cSrcweir */ 1866*cdf0e10cSrcweir output(ouInputFileName, ouTime_C, ouTime_Java, ouTime_NoSecurity, ouTime_JavaForwardOnly, ouRemark_C, ouRemark_Java, false); 1867*cdf0e10cSrcweir } 1868*cdf0e10cSrcweir 1869*cdf0e10cSrcweir batch_import.close(); 1870*cdf0e10cSrcweir 1871*cdf0e10cSrcweir fprintf(stderr, "\n"); 1872*cdf0e10cSrcweir } 1873*cdf0e10cSrcweir catch( cssu::Exception& e ) 1874*cdf0e10cSrcweir { 1875*cdf0e10cSrcweir fprintf( stderr , "\nEXCEPTION! Error Message: %s\n" , 1876*cdf0e10cSrcweir rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).getStr() ) ; 1877*cdf0e10cSrcweir } 1878*cdf0e10cSrcweir 1879*cdf0e10cSrcweir return 0; 1880*cdf0e10cSrcweir } 1881