1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _SECURITYENGINE_HXX 25 #define _SECURITYENGINE_HXX 26 27 #include <com/sun/star/xml/crypto/sax/XReferenceResolvedListener.hpp> 28 #include <com/sun/star/xml/crypto/sax/XReferenceResolvedBroadcaster.hpp> 29 #include <com/sun/star/xml/crypto/sax/XKeyCollector.hpp> 30 #include <com/sun/star/xml/crypto/sax/XMissionTaker.hpp> 31 #include <com/sun/star/xml/crypto/sax/XSAXEventKeeper.hpp> 32 #include <com/sun/star/xml/crypto/XXMLSignature.hpp> 33 34 #include <cppuhelper/implbase3.hxx> 35 36 class SecurityEngine : public cppu::WeakImplHelper3 37 < 38 com::sun::star::xml::crypto::sax::XReferenceResolvedListener, 39 com::sun::star::xml::crypto::sax::XKeyCollector, 40 com::sun::star::xml::crypto::sax::XMissionTaker 41 > 42 /****** securityengine.hxx/CLASS SecurityEngine ******************************* 43 * 44 * NAME 45 * SecurityEngine -- Base class of SignatureEngine and EncryptionEngine 46 * 47 * FUNCTION 48 * Maintains common members and methods related with security engine 49 * operation. 50 * 51 * HISTORY 52 * 05.01.2004 - Interface supported: XReferenceResolvedListener, 53 * XKeyCollector, and XMissionTaker 54 * 55 * AUTHOR 56 * Michael Mi 57 * Email: michael.mi@sun.com 58 ******************************************************************************/ 59 { 60 protected: 61 com::sun::star::uno::Reference< 62 com::sun::star::lang::XMultiServiceFactory > mxMSF; 63 64 /* 65 * A SAXEventKeeper internally maintians all resources that a security 66 * operation needs. The m_xSAXEventKeeper member is used to release 67 * those resources when the security operation finishes. 68 */ 69 com::sun::star::uno::Reference< 70 com::sun::star::xml::crypto::sax::XSAXEventKeeper > m_xSAXEventKeeper; 71 72 /* 73 * the id of ElementCollector of the template element. 74 * For a signature, the template element is the Signature element, 75 * for a encryption, the EncryptedData/EncryptedKey element is. 76 */ 77 sal_Int32 m_nIdOfTemplateEC; 78 79 /* 80 * remembers how many referenced elements have been bufferred completely, 81 * including the key element, template element, and referenced element of 82 * signature. 83 */ 84 sal_Int32 m_nNumOfResolvedReferences; 85 86 /* 87 * the id of ElementCollector of the key element. 88 * If a Signature element or EncryptedData/EncryptedKey element has 89 * an internal key sub-element, then this member should be -1 90 */ 91 sal_Int32 m_nIdOfKeyEC; 92 93 /* 94 * remembers whether the current opertion has finished. 95 */ 96 bool m_bMissionDone; 97 98 /* 99 * the Id of the security entity, a signature or encryption, which is used for 100 * the result listener to identify the entity. 101 */ 102 sal_Int32 m_nSecurityId; 103 104 /* 105 * the status of the operation 106 */ 107 //bool m_bOperationSucceed; 108 com::sun::star::xml::crypto::SecurityOperationStatus m_nStatus; 109 110 /* 111 * the result listener, which will receives the security operation result. 112 */ 113 com::sun::star::uno::Reference< 114 com::sun::star::uno::XInterface > 115 m_xResultListener; 116 117 protected: 118 explicit SecurityEngine( const com::sun::star::uno::Reference< 119 com::sun::star::lang::XMultiServiceFactory >& rxMSF = NULL ); ~SecurityEngine()120 virtual ~SecurityEngine() {}; 121 122 /* 123 * perform the security operation. 124 * Any derived class will implement this method respectively. 125 */ tryToPerform()126 virtual void tryToPerform( ) 127 throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException){}; 128 129 /* 130 * clear up all resources used by this operation. 131 * This method is called after the operation finishes, or a End-Your-Mission 132 * message is received. 133 * Any derived class will implement this method respectively. 134 */ clearUp() const135 virtual void clearUp( ) const {}; 136 137 /* 138 * notifies any possible result listener. 139 * When verify a signature or conduct a decryption, the operation result will 140 * be transferred to a listener by this method. 141 * Any derived class will implement this method respectively. 142 */ notifyResultListener() const143 virtual void notifyResultListener() const 144 throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException) 145 {}; 146 147 /* 148 * checks whether everything is ready. 149 * Any derived class will implement this method respectively. 150 */ checkReady() const151 virtual bool checkReady() const { return true; }; 152 153 public: 154 /* XReferenceResolvedListener */ 155 virtual void SAL_CALL referenceResolved( sal_Int32 referenceId ) 156 throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException); 157 158 /* XKeyCollector */ 159 virtual void SAL_CALL setKeyId( sal_Int32 id ) 160 throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException); 161 162 /* XMissionTaker */ 163 virtual sal_Bool SAL_CALL endMission( ) 164 throw (com::sun::star::uno::RuntimeException); 165 }; 166 167 #endif 168 169