xref: /trunk/main/xmlsecurity/source/framework/securityengine.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 maintains 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 operation 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 
128     /*
129      * clear up all resources used by this operation.
130      * This method is called after the operation finishes, or a End-Your-Mission
131      * message is received.
132      * Any derived class will implement this method respectively.
133      */
clearUp() const134     virtual void clearUp( ) const {};
135 
136         /*
137          * notifies any possible result listener.
138          * When verify a signature or conduct a decryption, the operation result will
139          * be transferred to a listener by this method.
140      * Any derived class will implement this method respectively.
141          */
notifyResultListener() const142     virtual void notifyResultListener() const
143         {};
144 
145     /*
146      * checks whether everything is ready.
147      * Any derived class will implement this method respectively.
148      */
checkReady() const149     virtual bool checkReady() const { return true; };
150 
151 public:
152     /* XReferenceResolvedListener */
153     virtual void SAL_CALL referenceResolved( sal_Int32 referenceId );
154 
155     /* XKeyCollector */
156     virtual void SAL_CALL setKeyId( sal_Int32 id );
157 
158         /* XMissionTaker */
159         virtual sal_Bool SAL_CALL endMission(  );
160 };
161 
162 #endif
163