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 #ifndef _XSEC_CTL_HXX 29*cdf0e10cSrcweir #define _XSEC_CTL_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <xmlsecurity/sigstruct.hxx> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/xml/sax/XParser.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/xml/sax/XDocumentHandler.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/xml/sax/XAttributeList.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/XXMLSignature.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/XSEInitializer.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XSecurityController.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XElementStackKeeper.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XSecuritySAXEventKeeper.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XReferenceResolvedListener.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XSAXEventKeeperStatusChangeListener.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XSignatureCreationResultListener.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XSignatureVerifyResultListener.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/xml/wrapper/XXMLDocumentWrapper.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/beans/XFastPropertySet.hpp> 49*cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp> 50*cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp> 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir #include <cppuhelper/implbase4.hxx> 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir #ifndef INCLUDED_VECTOR 57*cdf0e10cSrcweir #include <vector> 58*cdf0e10cSrcweir #define INCLUDED_VECTOR 59*cdf0e10cSrcweir #endif 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir /* 62*cdf0e10cSrcweir * all error information 63*cdf0e10cSrcweir */ 64*cdf0e10cSrcweir #define ERROR_CANNOTCREATEXMLSECURITYCOMPONENT "Can't create XML security components." 65*cdf0e10cSrcweir #define ERROR_SAXEXCEPTIONDURINGCREATION "A SAX exception is throwed during signature creation." 66*cdf0e10cSrcweir #define ERROR_IOEXCEPTIONDURINGCREATION "An IO exception is throwed during signature creation." 67*cdf0e10cSrcweir #define ERROR_EXCEPTIONDURINGCREATION "An exception is throwed during signature creation." 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir /* 70*cdf0e10cSrcweir * all stringS in signature element 71*cdf0e10cSrcweir */ 72*cdf0e10cSrcweir #define TAG_SIGNATURE "Signature" 73*cdf0e10cSrcweir #define TAG_SIGNEDINFO "SignedInfo" 74*cdf0e10cSrcweir #define TAG_CANONICALIZATIONMETHOD "CanonicalizationMethod" 75*cdf0e10cSrcweir #define TAG_SIGNATUREMETHOD "SignatureMethod" 76*cdf0e10cSrcweir #define TAG_REFERENCE "Reference" 77*cdf0e10cSrcweir #define TAG_TRANSFORMS "Transforms" 78*cdf0e10cSrcweir #define TAG_TRANSFORM "Transform" 79*cdf0e10cSrcweir #define TAG_DIGESTMETHOD "DigestMethod" 80*cdf0e10cSrcweir #define TAG_DIGESTVALUE "DigestValue" 81*cdf0e10cSrcweir #define TAG_SIGNATUREVALUE "SignatureValue" 82*cdf0e10cSrcweir #define TAG_KEYINFO "KeyInfo" 83*cdf0e10cSrcweir #define TAG_X509DATA "X509Data" 84*cdf0e10cSrcweir #define TAG_X509ISSUERSERIAL "X509IssuerSerial" 85*cdf0e10cSrcweir #define TAG_X509ISSUERNAME "X509IssuerName" 86*cdf0e10cSrcweir #define TAG_X509SERIALNUMBER "X509SerialNumber" 87*cdf0e10cSrcweir #define TAG_X509CERTIFICATE "X509Certificate" 88*cdf0e10cSrcweir #define TAG_OBJECT "Object" 89*cdf0e10cSrcweir #define TAG_SIGNATUREPROPERTIES "SignatureProperties" 90*cdf0e10cSrcweir #define TAG_SIGNATUREPROPERTY "SignatureProperty" 91*cdf0e10cSrcweir #define TAG_TIMESTAMP "timestamp" 92*cdf0e10cSrcweir #define TAG_DATE "date" 93*cdf0e10cSrcweir //#define TAG_TIME "time" 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir #define ATTR_XMLNS "xmlns" 96*cdf0e10cSrcweir #define ATTR_ALGORITHM "Algorithm" 97*cdf0e10cSrcweir #define ATTR_URI "URI" 98*cdf0e10cSrcweir #define ATTR_ID "Id" 99*cdf0e10cSrcweir #define ATTR_TARGET "Target" 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir #define NSTAG_DC "dc" 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir #define NS_XMLDSIG "http://www.w3.org/2000/09/xmldsig#" 104*cdf0e10cSrcweir //#define NS_DATETIME "http://www.ietf.org/rfcXXXX.txt" 105*cdf0e10cSrcweir #define NS_DC "http://purl.org/dc/elements/1.1/" 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir #define ALGO_C14N "http://www.w3.org/TR/2001/REC-xml-c14n-20010315" 108*cdf0e10cSrcweir #define ALGO_RSASHA1 "http://www.w3.org/2000/09/xmldsig#rsa-sha1" 109*cdf0e10cSrcweir #define ALGO_XMLDSIGSHA1 "http://www.w3.org/2000/09/xmldsig#sha1" 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir #define CHAR_FRAGMENT "#" 112*cdf0e10cSrcweir #define CHAR_BLANK " " 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir /* 116*cdf0e10cSrcweir * status of security related components 117*cdf0e10cSrcweir */ 118*cdf0e10cSrcweir #define UNINITIALIZED 0 119*cdf0e10cSrcweir #define INITIALIZED 1 120*cdf0e10cSrcweir #define FAILTOINITIALIZED 2 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir #define RTL_ASCII_USTRINGPARAM( asciiStr ) asciiStr, strlen( asciiStr ), RTL_TEXTENCODING_ASCII_US 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir // forward declaration 125*cdf0e10cSrcweir class XSecParser; 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir class InternalSignatureInformation 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir public: 130*cdf0e10cSrcweir SignatureInformation signatureInfor; 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir com::sun::star::uno::Reference< 133*cdf0e10cSrcweir com::sun::star::xml::crypto::sax::XReferenceResolvedListener > 134*cdf0e10cSrcweir xReferenceResolvedListener; 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir ::std::vector< sal_Int32 > vKeeperIds; 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir InternalSignatureInformation( 139*cdf0e10cSrcweir sal_Int32 nId, 140*cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::xml::crypto::sax::XReferenceResolvedListener > 141*cdf0e10cSrcweir xListener) 142*cdf0e10cSrcweir :signatureInfor(nId) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir xReferenceResolvedListener = xListener; 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir void addReference( sal_Int32 type, rtl::OUString uri, sal_Int32 keeperId ) 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir signatureInfor.vSignatureReferenceInfors.push_back( 150*cdf0e10cSrcweir SignatureReferenceInformation(type, uri)); 151*cdf0e10cSrcweir vKeeperIds.push_back( keeperId ); 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir }; 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir typedef ::std::vector< InternalSignatureInformation > InternalSignatureInformations; 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir class XSecController : public cppu::WeakImplHelper4 158*cdf0e10cSrcweir < 159*cdf0e10cSrcweir com::sun::star::xml::crypto::sax::XSecurityController, 160*cdf0e10cSrcweir //com::sun::star::beans::XFastPropertySet, 161*cdf0e10cSrcweir com::sun::star::xml::crypto::sax::XSAXEventKeeperStatusChangeListener, 162*cdf0e10cSrcweir com::sun::star::xml::crypto::sax::XSignatureCreationResultListener, 163*cdf0e10cSrcweir com::sun::star::xml::crypto::sax::XSignatureVerifyResultListener 164*cdf0e10cSrcweir > 165*cdf0e10cSrcweir /****** XSecController.hxx/CLASS XSecController ******************************* 166*cdf0e10cSrcweir * 167*cdf0e10cSrcweir * NAME 168*cdf0e10cSrcweir * XSecController -- the xml security framework controller 169*cdf0e10cSrcweir * 170*cdf0e10cSrcweir * FUNCTION 171*cdf0e10cSrcweir * Controlls the whole xml security framework to create signatures or to 172*cdf0e10cSrcweir * verify signatures. 173*cdf0e10cSrcweir * 174*cdf0e10cSrcweir * HISTORY 175*cdf0e10cSrcweir * 05.01.2004 - Interface supported: XSecurityController, 176*cdf0e10cSrcweir * XFastPropertySet, XSAXEventKeeperStatusChangeListener, 177*cdf0e10cSrcweir * XSignatureCreationResultListener, 178*cdf0e10cSrcweir * XSignatureVerifyResultListener 179*cdf0e10cSrcweir * 180*cdf0e10cSrcweir * NOTES 181*cdf0e10cSrcweir * The XFastPropertySet interface is used to transfer common values to 182*cdf0e10cSrcweir * classes in other module, for instance, the signature id for all 183*cdf0e10cSrcweir * sessions is transferred to xmloff module through this interface. 184*cdf0e10cSrcweir * 185*cdf0e10cSrcweir * AUTHOR 186*cdf0e10cSrcweir * Michael Mi 187*cdf0e10cSrcweir * Email: michael.mi@sun.com 188*cdf0e10cSrcweir ******************************************************************************/ 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir friend class XSecParser; 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir private: 193*cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext> mxCtx; 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir /* 196*cdf0e10cSrcweir * used to buffer SAX events 197*cdf0e10cSrcweir */ 198*cdf0e10cSrcweir com::sun::star::uno::Reference< 199*cdf0e10cSrcweir com::sun::star::xml::wrapper::XXMLDocumentWrapper > m_xXMLDocumentWrapper; 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir /* 202*cdf0e10cSrcweir * the SAX events keeper 203*cdf0e10cSrcweir */ 204*cdf0e10cSrcweir com::sun::star::uno::Reference< 205*cdf0e10cSrcweir com::sun::star::xml::crypto::sax::XSecuritySAXEventKeeper > m_xSAXEventKeeper; 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir /* 208*cdf0e10cSrcweir * the bridge component which creates/verifies signature 209*cdf0e10cSrcweir */ 210*cdf0e10cSrcweir com::sun::star::uno::Reference< 211*cdf0e10cSrcweir com::sun::star::xml::crypto::XXMLSignature > m_xXMLSignature; 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir /* 214*cdf0e10cSrcweir * the Security Context 215*cdf0e10cSrcweir */ 216*cdf0e10cSrcweir com::sun::star::uno::Reference< 217*cdf0e10cSrcweir com::sun::star::xml::crypto::XXMLSecurityContext > m_xSecurityContext; 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir #if 0 220*cdf0e10cSrcweir /* 221*cdf0e10cSrcweir * the signature creation result listener 222*cdf0e10cSrcweir */ 223*cdf0e10cSrcweir com::sun::star::uno::Reference< 224*cdf0e10cSrcweir com::sun::star::xml::crypto::sax::XSignatureCreationResultListener > m_xSignatureCreationResultListener; 225*cdf0e10cSrcweir /* 226*cdf0e10cSrcweir * the signature verify result listener 227*cdf0e10cSrcweir */ 228*cdf0e10cSrcweir com::sun::star::uno::Reference< 229*cdf0e10cSrcweir com::sun::star::xml::crypto::sax::XSignatureVerifyResultListener > m_xSignatureVerifyResultListener; 230*cdf0e10cSrcweir #endif 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir /* 233*cdf0e10cSrcweir * the security id incrementer, in order to make any security id unique 234*cdf0e10cSrcweir * to the SAXEventKeeper. 235*cdf0e10cSrcweir * Because each XSecController has its own SAXEventKeeper, so this variable 236*cdf0e10cSrcweir * is not necessary to be static. 237*cdf0e10cSrcweir */ 238*cdf0e10cSrcweir sal_Int32 m_nNextSecurityId; 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir /* 241*cdf0e10cSrcweir * Signature information 242*cdf0e10cSrcweir */ 243*cdf0e10cSrcweir InternalSignatureInformations m_vInternalSignatureInformations; 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir /* 246*cdf0e10cSrcweir * the previous node on the SAX chain. 247*cdf0e10cSrcweir * The reason that use a Reference<XInterface> type variable 248*cdf0e10cSrcweir * is that the previous components are different when exporting 249*cdf0e10cSrcweir * and importing, and there is no other common interface they 250*cdf0e10cSrcweir * can provided. 251*cdf0e10cSrcweir */ 252*cdf0e10cSrcweir com::sun::star::uno::Reference< 253*cdf0e10cSrcweir com::sun::star::uno::XInterface > m_xPreviousNodeOnSAXChain; 254*cdf0e10cSrcweir /* 255*cdf0e10cSrcweir * whether the preivous node can provide an XInitiazlize interface, 256*cdf0e10cSrcweir * use this variable in order to typecast the XInterface to the 257*cdf0e10cSrcweir * correct interface type. 258*cdf0e10cSrcweir */ 259*cdf0e10cSrcweir bool m_bIsPreviousNodeInitializable; 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir /* 262*cdf0e10cSrcweir * the next node on the SAX chain. 263*cdf0e10cSrcweir * it can always provide an XDocumentHandler interface. 264*cdf0e10cSrcweir */ 265*cdf0e10cSrcweir com::sun::star::uno::Reference< 266*cdf0e10cSrcweir com::sun::star::xml::sax::XDocumentHandler > m_xNextNodeOnSAXChain; 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir /* 269*cdf0e10cSrcweir * the ElementStackKeeper is used to reserve the key SAX events. 270*cdf0e10cSrcweir * when the SAXEventKeeper is chained on the SAX chain, it need 271*cdf0e10cSrcweir * first get all missed key SAX events in order to make sure the 272*cdf0e10cSrcweir * DOM tree it buffering has the same structure with the original 273*cdf0e10cSrcweir * document. 274*cdf0e10cSrcweir * 275*cdf0e10cSrcweir * For a given section of a SAX event stream, the key SAX events 276*cdf0e10cSrcweir * are the minimal SAX event subset of that section, which, 277*cdf0e10cSrcweir * combining with SAX events outside of this section, has the same 278*cdf0e10cSrcweir * structure with the original document. 279*cdf0e10cSrcweir * 280*cdf0e10cSrcweir * For example, sees the following dom fragment: 281*cdf0e10cSrcweir * <A> 282*cdf0e10cSrcweir * <B/> 283*cdf0e10cSrcweir * <C> 284*cdf0e10cSrcweir * <D> 285*cdf0e10cSrcweir * <E/> 286*cdf0e10cSrcweir * </D> 287*cdf0e10cSrcweir * </C> 288*cdf0e10cSrcweir * </A> 289*cdf0e10cSrcweir * 290*cdf0e10cSrcweir * If we consider the SAX event section from startElement(<A>) to 291*cdf0e10cSrcweir * startElement(<D>), then the key SAX events are: 292*cdf0e10cSrcweir * 293*cdf0e10cSrcweir * startElement(<A>), startElement(<C>), startElement(<D>) 294*cdf0e10cSrcweir * 295*cdf0e10cSrcweir * The startElement(<B>) and endElement(<B>) is ignored, because 296*cdf0e10cSrcweir * they are unimportant for the tree structure in this section. 297*cdf0e10cSrcweir * 298*cdf0e10cSrcweir * If we consider the SAX event section from startElement(<D>) to 299*cdf0e10cSrcweir * endElement(<A>), the key SAX events are: 300*cdf0e10cSrcweir * 301*cdf0e10cSrcweir * startElement(<D>), endElement(<D>), endElement(<C>), 302*cdf0e10cSrcweir * endElement(<A>). 303*cdf0e10cSrcweir */ 304*cdf0e10cSrcweir com::sun::star::uno::Reference< 305*cdf0e10cSrcweir com::sun::star::xml::crypto::sax::XElementStackKeeper > m_xElementStackKeeper; 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir /* 308*cdf0e10cSrcweir * a flag representing whether the SAXEventKeeper is now on the 309*cdf0e10cSrcweir * SAX chain. 310*cdf0e10cSrcweir */ 311*cdf0e10cSrcweir bool m_bIsSAXEventKeeperConnected; 312*cdf0e10cSrcweir 313*cdf0e10cSrcweir /* 314*cdf0e10cSrcweir * a flag representing whether it is collecting some element, 315*cdf0e10cSrcweir * which means that the SAXEventKeeper can't be chained off the 316*cdf0e10cSrcweir * SAX chain. 317*cdf0e10cSrcweir */ 318*cdf0e10cSrcweir bool m_bIsCollectingElement; 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir /* 321*cdf0e10cSrcweir * a flag representing whether the SAX event stream is blocking, 322*cdf0e10cSrcweir * which also means that the SAXEventKeeper can't be chained off 323*cdf0e10cSrcweir * the SAX chain. 324*cdf0e10cSrcweir */ 325*cdf0e10cSrcweir bool m_bIsBlocking; 326*cdf0e10cSrcweir 327*cdf0e10cSrcweir /* 328*cdf0e10cSrcweir * a flag representing the current status of security related 329*cdf0e10cSrcweir * components. 330*cdf0e10cSrcweir */ 331*cdf0e10cSrcweir sal_Int32 m_nStatusOfSecurityComponents; 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir /* 334*cdf0e10cSrcweir * a flag representing whether the SAXEventKeeper need to be 335*cdf0e10cSrcweir * on the SAX chain all the time. 336*cdf0e10cSrcweir * This flag is used to the situation when creating signature. 337*cdf0e10cSrcweir */ 338*cdf0e10cSrcweir bool m_bIsSAXEventKeeperSticky; 339*cdf0e10cSrcweir 340*cdf0e10cSrcweir /* 341*cdf0e10cSrcweir * fast property vector 342*cdf0e10cSrcweir */ 343*cdf0e10cSrcweir std::vector< sal_Int32 > m_vFastPropertyIndexs; 344*cdf0e10cSrcweir std::vector< com::sun::star::uno::Any > m_vFastPropertyValues; 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir /* 347*cdf0e10cSrcweir * error message pointer 348*cdf0e10cSrcweir */ 349*cdf0e10cSrcweir const char *m_pErrorMessage; 350*cdf0e10cSrcweir 351*cdf0e10cSrcweir /* 352*cdf0e10cSrcweir * the XSecParser which is used to parse the signature stream 353*cdf0e10cSrcweir */ 354*cdf0e10cSrcweir XSecParser *m_pXSecParser; 355*cdf0e10cSrcweir 356*cdf0e10cSrcweir /* 357*cdf0e10cSrcweir * the caller assigned signature id for the next signature in the 358*cdf0e10cSrcweir * signature stream 359*cdf0e10cSrcweir */ 360*cdf0e10cSrcweir sal_Int32 m_nReservedSignatureId; 361*cdf0e10cSrcweir 362*cdf0e10cSrcweir /* 363*cdf0e10cSrcweir * representing whether to verify the current signature 364*cdf0e10cSrcweir */ 365*cdf0e10cSrcweir bool m_bVerifyCurrentSignature; 366*cdf0e10cSrcweir public: 367*cdf0e10cSrcweir /* 368*cdf0e10cSrcweir * An xUriBinding is provided to map Uris to XInputStream interfaces. 369*cdf0e10cSrcweir */ 370*cdf0e10cSrcweir com::sun::star::uno::Reference< 371*cdf0e10cSrcweir com::sun::star::xml::crypto::XUriBinding > m_xUriBinding; 372*cdf0e10cSrcweir 373*cdf0e10cSrcweir private: 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir /* 376*cdf0e10cSrcweir * Common methods 377*cdf0e10cSrcweir */ 378*cdf0e10cSrcweir sal_Bool convertNumber( sal_Int32& rValue, const rtl::OUString& rString, sal_Int32 nMin, sal_Int32 nMax ); 379*cdf0e10cSrcweir void convertDateTime( ::rtl::OUStringBuffer& rBuffer, const com::sun::star::util::DateTime& rDateTime ); 380*cdf0e10cSrcweir sal_Bool convertDateTime( com::sun::star::util::DateTime& rDateTime, const ::rtl::OUString& rString ); 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir void createXSecComponent( ); 383*cdf0e10cSrcweir int findSignatureInfor( sal_Int32 nSecurityId ) const; 384*cdf0e10cSrcweir bool chainOn( bool bRetrievingLastEvent ); 385*cdf0e10cSrcweir void chainOff(); 386*cdf0e10cSrcweir void checkChainingStatus(); 387*cdf0e10cSrcweir void initializeSAXChain(); 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir com::sun::star::uno::Reference< 390*cdf0e10cSrcweir com::sun::star::io::XInputStream > getObjectInputStream( const rtl::OUString& objectURL ); 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir //sal_Int32 getFastPropertyIndex(sal_Int32 nHandle) const; 393*cdf0e10cSrcweir 394*cdf0e10cSrcweir /* 395*cdf0e10cSrcweir * For signature generation 396*cdf0e10cSrcweir */ 397*cdf0e10cSrcweir rtl::OUString createId(); 398*cdf0e10cSrcweir com::sun::star::uno::Reference< 399*cdf0e10cSrcweir com::sun::star::xml::crypto::sax::XReferenceResolvedListener > prepareSignatureToWrite( 400*cdf0e10cSrcweir InternalSignatureInformation& signatureInfo ); 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir /* 403*cdf0e10cSrcweir * For signature verification 404*cdf0e10cSrcweir */ 405*cdf0e10cSrcweir void addSignature(); 406*cdf0e10cSrcweir void addReference( const rtl::OUString& ouUri); 407*cdf0e10cSrcweir void addStreamReference( 408*cdf0e10cSrcweir const rtl::OUString& ouUri, 409*cdf0e10cSrcweir bool isBinary ); 410*cdf0e10cSrcweir void setReferenceCount() const; 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir void setX509IssuerName( rtl::OUString& ouX509IssuerName ); 413*cdf0e10cSrcweir void setX509SerialNumber( rtl::OUString& ouX509SerialNumber ); 414*cdf0e10cSrcweir void setX509Certificate( rtl::OUString& ouX509Certificate ); 415*cdf0e10cSrcweir void setSignatureValue( rtl::OUString& ouSignatureValue ); 416*cdf0e10cSrcweir void setDigestValue( rtl::OUString& ouDigestValue ); 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir void setDate( rtl::OUString& ouDate ); 419*cdf0e10cSrcweir 420*cdf0e10cSrcweir void setId( rtl::OUString& ouId ); 421*cdf0e10cSrcweir void setPropertyId( rtl::OUString& ouPropertyId ); 422*cdf0e10cSrcweir 423*cdf0e10cSrcweir com::sun::star::uno::Reference< 424*cdf0e10cSrcweir com::sun::star::xml::crypto::sax::XReferenceResolvedListener > prepareSignatureToRead( 425*cdf0e10cSrcweir sal_Int32 nSecurityId ); 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir public: 428*cdf0e10cSrcweir XSecController(const com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext>& rxCtx); 429*cdf0e10cSrcweir ~XSecController(); 430*cdf0e10cSrcweir 431*cdf0e10cSrcweir sal_Int32 getNewSecurityId( ); 432*cdf0e10cSrcweir 433*cdf0e10cSrcweir void startMission( const com::sun::star::uno::Reference< 434*cdf0e10cSrcweir com::sun::star::xml::crypto::XUriBinding >& xUriBinding, 435*cdf0e10cSrcweir const com::sun::star::uno::Reference< 436*cdf0e10cSrcweir com::sun::star::xml::crypto::XXMLSecurityContext >& xSecurityContext ); 437*cdf0e10cSrcweir 438*cdf0e10cSrcweir void setSAXChainConnector( 439*cdf0e10cSrcweir const com::sun::star::uno::Reference< 440*cdf0e10cSrcweir com::sun::star::lang::XInitialization >& xInitialization, 441*cdf0e10cSrcweir const com::sun::star::uno::Reference< 442*cdf0e10cSrcweir com::sun::star::xml::sax::XDocumentHandler >& xDocumentHandler, 443*cdf0e10cSrcweir const com::sun::star::uno::Reference< 444*cdf0e10cSrcweir com::sun::star::xml::crypto::sax::XElementStackKeeper >& xElementStackKeeper); 445*cdf0e10cSrcweir 446*cdf0e10cSrcweir void setSAXChainConnector( 447*cdf0e10cSrcweir const com::sun::star::uno::Reference< 448*cdf0e10cSrcweir com::sun::star::xml::sax::XParser >& xParser, 449*cdf0e10cSrcweir const com::sun::star::uno::Reference< 450*cdf0e10cSrcweir com::sun::star::xml::sax::XDocumentHandler >& xDocumentHandler, 451*cdf0e10cSrcweir const com::sun::star::uno::Reference< 452*cdf0e10cSrcweir com::sun::star::xml::crypto::sax::XElementStackKeeper >& xElementStackKeeper); 453*cdf0e10cSrcweir 454*cdf0e10cSrcweir void clearSAXChainConnector(); 455*cdf0e10cSrcweir void endMission(); 456*cdf0e10cSrcweir const char* getErrorMessage(); 457*cdf0e10cSrcweir 458*cdf0e10cSrcweir SignatureInformation getSignatureInformation( sal_Int32 nSecurityId ) const; 459*cdf0e10cSrcweir SignatureInformations getSignatureInformations() const; 460*cdf0e10cSrcweir 461*cdf0e10cSrcweir void exportSignature( 462*cdf0e10cSrcweir const com::sun::star::uno::Reference< 463*cdf0e10cSrcweir com::sun::star::xml::sax::XDocumentHandler >& xDocumentHandler, 464*cdf0e10cSrcweir const SignatureInformation& signatureInfo ); 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir 467*cdf0e10cSrcweir /* 468*cdf0e10cSrcweir * For signature generation 469*cdf0e10cSrcweir */ 470*cdf0e10cSrcweir void collectToSign( sal_Int32 securityId, const rtl::OUString& referenceId ); 471*cdf0e10cSrcweir void signAStream( sal_Int32 securityId, const rtl::OUString& uri, const rtl::OUString& objectURL, sal_Bool isBinary); 472*cdf0e10cSrcweir 473*cdf0e10cSrcweir 474*cdf0e10cSrcweir /** sets data that describes the certificate. 475*cdf0e10cSrcweir 476*cdf0e10cSrcweir It is absolutely necessary that the parameter ouX509IssuerName is set. It contains 477*cdf0e10cSrcweir the base64 encoded certificate, which is DER encoded. The XMLSec needs it to find 478*cdf0e10cSrcweir the private key. Although issuer name and certificate should be sufficient to identify 479*cdf0e10cSrcweir the certificate the implementation in XMLSec is broken, both for Windows and mozilla. 480*cdf0e10cSrcweir The reason is that they use functions to find the certificate which take as parameter 481*cdf0e10cSrcweir the DER encoded ASN.1 issuer name. The issuer name is a DName, where most attributes 482*cdf0e10cSrcweir are of type DirectoryName, which is a choice of 5 string types. This information is 483*cdf0e10cSrcweir not contained in the issuer string and while it is converted to the ASN.1 name the 484*cdf0e10cSrcweir conversion function must assume a particular type, which is often wrong. For example, 485*cdf0e10cSrcweir the Windows function CertStrToName will use a T.61 string if the string does not contain 486*cdf0e10cSrcweir special characters. So if the certificate uses simple characters but encodes the 487*cdf0e10cSrcweir issuer attributes in Utf8, then CertStrToName will use T.61. The resulting DER encoded 488*cdf0e10cSrcweir ASN.1 name now contains different bytes which indicate the string type. The functions 489*cdf0e10cSrcweir for finding the certificate apparently use memcmp - hence they fail to find the 490*cdf0e10cSrcweir certificate. 491*cdf0e10cSrcweir */ 492*cdf0e10cSrcweir void setX509Certificate( 493*cdf0e10cSrcweir sal_Int32 nSecurityId, 494*cdf0e10cSrcweir const rtl::OUString& ouX509IssuerName, 495*cdf0e10cSrcweir const rtl::OUString& ouX509SerialNumber, 496*cdf0e10cSrcweir const rtl::OUString& ouX509Cert); 497*cdf0e10cSrcweir // see the other setX509Certifcate function 498*cdf0e10cSrcweir void setX509Certificate( 499*cdf0e10cSrcweir sal_Int32 nSecurityId, 500*cdf0e10cSrcweir const sal_Int32 nSecurityEnvironmentIndex, 501*cdf0e10cSrcweir const rtl::OUString& ouX509IssuerName, 502*cdf0e10cSrcweir const rtl::OUString& ouX509SerialNumber, 503*cdf0e10cSrcweir const rtl::OUString& ouX509Cert); 504*cdf0e10cSrcweir 505*cdf0e10cSrcweir void setDate( 506*cdf0e10cSrcweir sal_Int32 nSecurityId, 507*cdf0e10cSrcweir const ::com::sun::star::util::DateTime& rDateTime ); 508*cdf0e10cSrcweir 509*cdf0e10cSrcweir 510*cdf0e10cSrcweir bool WriteSignature( 511*cdf0e10cSrcweir const com::sun::star::uno::Reference< 512*cdf0e10cSrcweir com::sun::star::xml::sax::XDocumentHandler >& xDocumentHandler ); 513*cdf0e10cSrcweir 514*cdf0e10cSrcweir /* 515*cdf0e10cSrcweir * For signature verification 516*cdf0e10cSrcweir */ 517*cdf0e10cSrcweir void collectToVerify( const rtl::OUString& referenceId ); 518*cdf0e10cSrcweir void addSignature( sal_Int32 nSignatureId ); 519*cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler > createSignatureReader(); 520*cdf0e10cSrcweir void releaseSignatureReader(); 521*cdf0e10cSrcweir 522*cdf0e10cSrcweir public: 523*cdf0e10cSrcweir /* Interface methods */ 524*cdf0e10cSrcweir 525*cdf0e10cSrcweir /* 526*cdf0e10cSrcweir * XSecurityController 527*cdf0e10cSrcweir * 528*cdf0e10cSrcweir * no method in XSecurityController interface 529*cdf0e10cSrcweir */ 530*cdf0e10cSrcweir 531*cdf0e10cSrcweir /* 532*cdf0e10cSrcweir * XFastPropertySet 533*cdf0e10cSrcweir */ 534*cdf0e10cSrcweir /* 535*cdf0e10cSrcweir virtual void SAL_CALL setFastPropertyValue( 536*cdf0e10cSrcweir sal_Int32 nHandle, 537*cdf0e10cSrcweir const com::sun::star::uno::Any& aValue ) 538*cdf0e10cSrcweir throw ( 539*cdf0e10cSrcweir com::sun::star::beans::UnknownPropertyException, 540*cdf0e10cSrcweir com::sun::star::beans::PropertyVetoException, 541*cdf0e10cSrcweir com::sun::star::lang::IllegalArgumentException, 542*cdf0e10cSrcweir com::sun::star::lang::WrappedTargetException, 543*cdf0e10cSrcweir com::sun::star::uno::RuntimeException); 544*cdf0e10cSrcweir virtual com::sun::star::uno::Any SAL_CALL getFastPropertyValue( 545*cdf0e10cSrcweir sal_Int32 nHandle ) 546*cdf0e10cSrcweir throw ( 547*cdf0e10cSrcweir com::sun::star::beans::UnknownPropertyException, 548*cdf0e10cSrcweir com::sun::star::lang::WrappedTargetException, 549*cdf0e10cSrcweir com::sun::star::uno::RuntimeException); 550*cdf0e10cSrcweir */ 551*cdf0e10cSrcweir 552*cdf0e10cSrcweir /* 553*cdf0e10cSrcweir * XSAXEventKeeperStatusChangeListener 554*cdf0e10cSrcweir */ 555*cdf0e10cSrcweir virtual void SAL_CALL blockingStatusChanged( sal_Bool isBlocking ) 556*cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 557*cdf0e10cSrcweir virtual void SAL_CALL collectionStatusChanged( 558*cdf0e10cSrcweir sal_Bool isInsideCollectedElement ) 559*cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 560*cdf0e10cSrcweir virtual void SAL_CALL bufferStatusChanged( sal_Bool isBufferEmpty ) 561*cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 562*cdf0e10cSrcweir 563*cdf0e10cSrcweir /* 564*cdf0e10cSrcweir * XSignatureCreationResultListener 565*cdf0e10cSrcweir */ 566*cdf0e10cSrcweir virtual void SAL_CALL signatureCreated( sal_Int32 securityId, com::sun::star::xml::crypto::SecurityOperationStatus nResult ) 567*cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 568*cdf0e10cSrcweir 569*cdf0e10cSrcweir /* 570*cdf0e10cSrcweir * XSignatureVerifyResultListener 571*cdf0e10cSrcweir */ 572*cdf0e10cSrcweir virtual void SAL_CALL signatureVerified( sal_Int32 securityId, com::sun::star::xml::crypto::SecurityOperationStatus nResult ) 573*cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 574*cdf0e10cSrcweir }; 575*cdf0e10cSrcweir 576*cdf0e10cSrcweir #endif 577*cdf0e10cSrcweir 578