1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmlsecurity.hxx"
31 #include "encryptionengine.hxx"
32 #include <com/sun/star/xml/crypto/XXMLEncryptionTemplate.hpp>
33 #include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
36 namespace cssu
= com::sun::star::uno
;
37 namespace cssl
= com::sun::star::lang
;
38 namespace cssxc
= com::sun::star::xml::crypto
;
39 namespace cssxw
= com::sun::star::xml::wrapper
;
41 #define ENCRYPTION_TEMPLATE "com.sun.star.xml.crypto.XMLEncryptionTemplate"
43 #define DECLARE_ASCII( SASCIIVALUE ) \
44 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SASCIIVALUE ) )
46 EncryptionEngine::EncryptionEngine( )
51 bool EncryptionEngine::checkReady() const
52 /****** EncryptionEngine/checkReady ******************************************
55 * checkReady -- checks the conditions for the main operation.
58 * bReady = checkReady( );
61 * checks whether all following conditions are satisfied:
62 * 1. the main operation has't begun yet;
63 * 2. the key material is known;
64 * 3. the id of the template blocker is known;
65 * 4. both the key element and the encryption template
72 * bReady - true if all conditions are satisfied, false otherwise
75 * 05.01.2004 - implemented
79 * Email: michael.mi@sun.com
80 ******************************************************************************/
84 sal_Int32 nKeyInc
= 0;
85 if (m_nIdOfKeyEC
!= 0)
92 m_nIdOfBlocker
== -1 ||
93 1+nKeyInc
> m_nNumOfResolvedReferences
)
101 void EncryptionEngine::tryToPerform( )
102 throw (cssu::Exception
, cssu::RuntimeException
)
103 /****** EncryptionEngine/tryToPerform ****************************************
106 * tryToPerform -- tries to perform the encryption/decryption operation.
112 * if the situation is ready, perform following operations.
113 * 1. prepares a encryption template;
114 * 2. calls the encryption bridge component;
115 * 3. clears up all used resources;
116 * 4. notifies the result listener;
117 * 5. sets the "accomplishment" flag.
126 * 05.01.2004 - implemented
130 * Email: michael.mi@sun.com
131 ******************************************************************************/
135 const rtl::OUString
sEncryptionTemplate (
136 RTL_CONSTASCII_USTRINGPARAM( ENCRYPTION_TEMPLATE
) );
137 cssu::Reference
< cssxc::XXMLEncryptionTemplate
> xEncryptionTemplate(
138 mxMSF
->createInstance( sEncryptionTemplate
), cssu::UNO_QUERY
);
140 OSL_ASSERT( xEncryptionTemplate
.is() );
142 cssu::Reference
< cssxw::XXMLElementWrapper
> xXMLElement
143 = m_xSAXEventKeeper
->getElement( m_nIdOfTemplateEC
);
145 xEncryptionTemplate
->setTemplate(xXMLElement
);
147 startEngine( xEncryptionTemplate
);
154 notifyResultListener();
156 m_bMissionDone
= true;
160 void EncryptionEngine::clearUp( ) const
161 /****** EncryptionEngine/clearup *********************************************
164 * clearUp -- clear up all resources used by this operation.
170 * cleaning resources up includes:
171 * 1. releases the ElementCollector for the encryption template element;
172 * 2. releases the Blocker for the encryption template element;
173 * 3. releases the ElementCollector for the key element, if there is one.
182 * 05.01.2004 - implemented
186 * Email: michael.mi@sun.com
187 ******************************************************************************/
189 cssu::Reference
< cssxc::sax::XReferenceResolvedBroadcaster
>
190 xReferenceResolvedBroadcaster( m_xSAXEventKeeper
, cssu::UNO_QUERY
);
192 xReferenceResolvedBroadcaster
->removeReferenceResolvedListener(
194 (const cssu::Reference
< cssxc::sax::XReferenceResolvedListener
>)((SecurityEngine
*)this));
196 m_xSAXEventKeeper
->removeElementCollector(m_nIdOfTemplateEC
);
198 if (m_nIdOfBlocker
!= -1)
200 m_xSAXEventKeeper
->removeBlocker(m_nIdOfBlocker
);
203 if (m_nIdOfKeyEC
!= 0 && m_nIdOfKeyEC
!= -1)
205 m_xSAXEventKeeper
->removeElementCollector(m_nIdOfKeyEC
);
209 /* XBlockerMonitor */
210 void SAL_CALL
EncryptionEngine::setBlockerId( sal_Int32 id
)
211 throw (com::sun::star::uno::Exception
, com::sun::star::uno::RuntimeException
)