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