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 _SECURITYENGINE_HXX 29*cdf0e10cSrcweir #define _SECURITYENGINE_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XReferenceResolvedListener.hpp> 32*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XReferenceResolvedBroadcaster.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XKeyCollector.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XMissionTaker.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/sax/XSAXEventKeeper.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/XXMLSignature.hpp> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #include <cppuhelper/implbase3.hxx> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir class SecurityEngine : public cppu::WeakImplHelper3 41*cdf0e10cSrcweir < 42*cdf0e10cSrcweir com::sun::star::xml::crypto::sax::XReferenceResolvedListener, 43*cdf0e10cSrcweir com::sun::star::xml::crypto::sax::XKeyCollector, 44*cdf0e10cSrcweir com::sun::star::xml::crypto::sax::XMissionTaker 45*cdf0e10cSrcweir > 46*cdf0e10cSrcweir /****** securityengine.hxx/CLASS SecurityEngine ******************************* 47*cdf0e10cSrcweir * 48*cdf0e10cSrcweir * NAME 49*cdf0e10cSrcweir * SecurityEngine -- Base class of SignatureEngine and EncryptionEngine 50*cdf0e10cSrcweir * 51*cdf0e10cSrcweir * FUNCTION 52*cdf0e10cSrcweir * Maintains common members and methods related with security engine 53*cdf0e10cSrcweir * operation. 54*cdf0e10cSrcweir * 55*cdf0e10cSrcweir * HISTORY 56*cdf0e10cSrcweir * 05.01.2004 - Interface supported: XReferenceResolvedListener, 57*cdf0e10cSrcweir * XKeyCollector, and XMissionTaker 58*cdf0e10cSrcweir * 59*cdf0e10cSrcweir * AUTHOR 60*cdf0e10cSrcweir * Michael Mi 61*cdf0e10cSrcweir * Email: michael.mi@sun.com 62*cdf0e10cSrcweir ******************************************************************************/ 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir protected: 65*cdf0e10cSrcweir com::sun::star::uno::Reference< 66*cdf0e10cSrcweir com::sun::star::lang::XMultiServiceFactory > mxMSF; 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir /* 69*cdf0e10cSrcweir * A SAXEventKeeper internally maintians all resources that a security 70*cdf0e10cSrcweir * operation needs. The m_xSAXEventKeeper member is used to release 71*cdf0e10cSrcweir * those resources when the security operation finishes. 72*cdf0e10cSrcweir */ 73*cdf0e10cSrcweir com::sun::star::uno::Reference< 74*cdf0e10cSrcweir com::sun::star::xml::crypto::sax::XSAXEventKeeper > m_xSAXEventKeeper; 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir /* 77*cdf0e10cSrcweir * the id of ElementCollector of the template element. 78*cdf0e10cSrcweir * For a signature, the template element is the Signature element, 79*cdf0e10cSrcweir * for a encryption, the EncryptedData/EncryptedKey element is. 80*cdf0e10cSrcweir */ 81*cdf0e10cSrcweir sal_Int32 m_nIdOfTemplateEC; 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir /* 84*cdf0e10cSrcweir * remembers how many referenced elements have been bufferred completely, 85*cdf0e10cSrcweir * including the key element, template element, and referenced element of 86*cdf0e10cSrcweir * signature. 87*cdf0e10cSrcweir */ 88*cdf0e10cSrcweir sal_Int32 m_nNumOfResolvedReferences; 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir /* 91*cdf0e10cSrcweir * the id of ElementCollector of the key element. 92*cdf0e10cSrcweir * If a Signature element or EncryptedData/EncryptedKey element has 93*cdf0e10cSrcweir * an internal key sub-element, then this member should be -1 94*cdf0e10cSrcweir */ 95*cdf0e10cSrcweir sal_Int32 m_nIdOfKeyEC; 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir /* 98*cdf0e10cSrcweir * remembers whether the current opertion has finished. 99*cdf0e10cSrcweir */ 100*cdf0e10cSrcweir bool m_bMissionDone; 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir /* 103*cdf0e10cSrcweir * the Id of the security entity, a signature or encryption, which is used for 104*cdf0e10cSrcweir * the result listener to identify the entity. 105*cdf0e10cSrcweir */ 106*cdf0e10cSrcweir sal_Int32 m_nSecurityId; 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir /* 109*cdf0e10cSrcweir * the status of the operation 110*cdf0e10cSrcweir */ 111*cdf0e10cSrcweir //bool m_bOperationSucceed; 112*cdf0e10cSrcweir com::sun::star::xml::crypto::SecurityOperationStatus m_nStatus; 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir /* 115*cdf0e10cSrcweir * the result listener, which will receives the security operation result. 116*cdf0e10cSrcweir */ 117*cdf0e10cSrcweir com::sun::star::uno::Reference< 118*cdf0e10cSrcweir com::sun::star::uno::XInterface > 119*cdf0e10cSrcweir m_xResultListener; 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir protected: 122*cdf0e10cSrcweir explicit SecurityEngine( const com::sun::star::uno::Reference< 123*cdf0e10cSrcweir com::sun::star::lang::XMultiServiceFactory >& rxMSF = NULL ); 124*cdf0e10cSrcweir virtual ~SecurityEngine() {}; 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir /* 127*cdf0e10cSrcweir * perform the security operation. 128*cdf0e10cSrcweir * Any derived class will implement this method respectively. 129*cdf0e10cSrcweir */ 130*cdf0e10cSrcweir virtual void tryToPerform( ) 131*cdf0e10cSrcweir throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException){}; 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir /* 134*cdf0e10cSrcweir * clear up all resources used by this operation. 135*cdf0e10cSrcweir * This method is called after the operation finishes, or a End-Your-Mission 136*cdf0e10cSrcweir * message is received. 137*cdf0e10cSrcweir * Any derived class will implement this method respectively. 138*cdf0e10cSrcweir */ 139*cdf0e10cSrcweir virtual void clearUp( ) const {}; 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir /* 142*cdf0e10cSrcweir * notifies any possible result listener. 143*cdf0e10cSrcweir * When verify a signature or conduct a decryption, the operation result will 144*cdf0e10cSrcweir * be transferred to a listener by this method. 145*cdf0e10cSrcweir * Any derived class will implement this method respectively. 146*cdf0e10cSrcweir */ 147*cdf0e10cSrcweir virtual void notifyResultListener() const 148*cdf0e10cSrcweir throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException) 149*cdf0e10cSrcweir {}; 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir /* 152*cdf0e10cSrcweir * checks whether everything is ready. 153*cdf0e10cSrcweir * Any derived class will implement this method respectively. 154*cdf0e10cSrcweir */ 155*cdf0e10cSrcweir virtual bool checkReady() const { return true; }; 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir public: 158*cdf0e10cSrcweir /* XReferenceResolvedListener */ 159*cdf0e10cSrcweir virtual void SAL_CALL referenceResolved( sal_Int32 referenceId ) 160*cdf0e10cSrcweir throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException); 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir /* XKeyCollector */ 163*cdf0e10cSrcweir virtual void SAL_CALL setKeyId( sal_Int32 id ) 164*cdf0e10cSrcweir throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException); 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir /* XMissionTaker */ 167*cdf0e10cSrcweir virtual sal_Bool SAL_CALL endMission( ) 168*cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 169*cdf0e10cSrcweir }; 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir #endif 172*cdf0e10cSrcweir 173