1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _SECURITYENGINE_HXX
29 #define _SECURITYENGINE_HXX
30 
31 #include <com/sun/star/xml/crypto/sax/XReferenceResolvedListener.hpp>
32 #include <com/sun/star/xml/crypto/sax/XReferenceResolvedBroadcaster.hpp>
33 #include <com/sun/star/xml/crypto/sax/XKeyCollector.hpp>
34 #include <com/sun/star/xml/crypto/sax/XMissionTaker.hpp>
35 #include <com/sun/star/xml/crypto/sax/XSAXEventKeeper.hpp>
36 #include <com/sun/star/xml/crypto/XXMLSignature.hpp>
37 
38 #include <cppuhelper/implbase3.hxx>
39 
40 class SecurityEngine : public cppu::WeakImplHelper3
41 <
42 	com::sun::star::xml::crypto::sax::XReferenceResolvedListener,
43 	com::sun::star::xml::crypto::sax::XKeyCollector,
44 	com::sun::star::xml::crypto::sax::XMissionTaker
45 >
46 /****** securityengine.hxx/CLASS SecurityEngine *******************************
47  *
48  *   NAME
49  *	SecurityEngine -- Base class of SignatureEngine and EncryptionEngine
50  *
51  *   FUNCTION
52  *	Maintains common members and methods related with security engine
53  *	operation.
54  *
55  *   HISTORY
56  *	05.01.2004 -	Interface supported: XReferenceResolvedListener,
57  * 			XKeyCollector, and XMissionTaker
58  *
59  *   AUTHOR
60  *	Michael Mi
61  *	Email: michael.mi@sun.com
62  ******************************************************************************/
63 {
64 protected:
65 	com::sun::star::uno::Reference<
66 		com::sun::star::lang::XMultiServiceFactory > mxMSF;
67 
68 	/*
69 	 * A SAXEventKeeper internally maintians all resources that a security
70 	 * operation needs. The m_xSAXEventKeeper member is used to release
71 	 * those resources when the security operation finishes.
72 	 */
73 	com::sun::star::uno::Reference<
74 		com::sun::star::xml::crypto::sax::XSAXEventKeeper > m_xSAXEventKeeper;
75 
76 	/*
77 	 * the id of ElementCollector of the template element.
78 	 * For a signature, the template element is the Signature element,
79 	 * for a encryption, the EncryptedData/EncryptedKey element is.
80 	 */
81 	sal_Int32 m_nIdOfTemplateEC;
82 
83 	/*
84 	 * remembers how many referenced elements have been bufferred completely,
85 	 * including the key element, template element, and referenced element of
86 	 * signature.
87 	 */
88 	sal_Int32 m_nNumOfResolvedReferences;
89 
90 	/*
91 	 * the id of ElementCollector of the key element.
92 	 * If a Signature element or EncryptedData/EncryptedKey element has
93 	 * an internal key sub-element, then this member should be -1
94 	 */
95 	sal_Int32 m_nIdOfKeyEC;
96 
97 	/*
98 	 * remembers whether the current opertion has finished.
99 	 */
100 	bool      m_bMissionDone;
101 
102 	/*
103 	 * the Id of the security entity, a signature or encryption, which is used for
104 	 * the result listener to identify the entity.
105 	 */
106 	sal_Int32 m_nSecurityId;
107 
108 	/*
109 	 * the status of the operation
110 	 */
111 	//bool      m_bOperationSucceed;
112 	com::sun::star::xml::crypto::SecurityOperationStatus m_nStatus;
113 
114 	/*
115 	 * the result listener, which will receives the security operation result.
116 	 */
117 	com::sun::star::uno::Reference<
118 		com::sun::star::uno::XInterface >
119 		m_xResultListener;
120 
121 protected:
122 	explicit SecurityEngine( const com::sun::star::uno::Reference<
123 		com::sun::star::lang::XMultiServiceFactory >& rxMSF = NULL );
124 	virtual ~SecurityEngine() {};
125 
126 	/*
127 	 * perform the security operation.
128 	 * Any derived class will implement this method respectively.
129 	 */
130 	virtual void tryToPerform( )
131 		throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException){};
132 
133 	/*
134 	 * clear up all resources used by this operation.
135 	 * This method is called after the operation finishes, or a End-Your-Mission
136 	 * message is received.
137 	 * Any derived class will implement this method respectively.
138 	 */
139 	virtual void clearUp( ) const {};
140 
141         /*
142          * notifies any possible result listener.
143          * When verify a signature or conduct a decryption, the operation result will
144          * be transferred to a listener by this method.
145 	 * Any derived class will implement this method respectively.
146          */
147 	virtual void notifyResultListener() const
148 		throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException)
149 		{};
150 
151 	/*
152 	 * checks whether everything is ready.
153 	 * Any derived class will implement this method respectively.
154 	 */
155 	virtual bool checkReady() const { return true; };
156 
157 public:
158 	/* XReferenceResolvedListener */
159 	virtual void SAL_CALL referenceResolved( sal_Int32 referenceId )
160     		throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
161 
162 	/* XKeyCollector */
163 	virtual void SAL_CALL setKeyId( sal_Int32 id )
164     		throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
165 
166     	/* XMissionTaker */
167     	virtual sal_Bool SAL_CALL endMission(  )
168     		throw (com::sun::star::uno::RuntimeException);
169 };
170 
171 #endif
172 
173