1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: encryptionengine.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmlsecurity.hxx"
34 #include "encryptionengine.hxx"
35 #include <com/sun/star/xml/crypto/XXMLEncryptionTemplate.hpp>
36 #include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39 namespace cssu
= com::sun::star::uno
;
40 namespace cssl
= com::sun::star::lang
;
41 namespace cssxc
= com::sun::star::xml::crypto
;
42 namespace cssxw
= com::sun::star::xml::wrapper
;
44 #define ENCRYPTION_TEMPLATE "com.sun.star.xml.crypto.XMLEncryptionTemplate"
46 #define DECLARE_ASCII( SASCIIVALUE ) \
47 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SASCIIVALUE ) )
49 EncryptionEngine::EncryptionEngine( )
54 bool EncryptionEngine::checkReady() const
55 /****** EncryptionEngine/checkReady ******************************************
58 * checkReady -- checks the conditions for the main operation.
61 * bReady = checkReady( );
64 * checks whether all following conditions are satisfied:
65 * 1. the main operation has't begun yet;
66 * 2. the key material is known;
67 * 3. the id of the template blocker is known;
68 * 4. both the key element and the encryption template
75 * bReady - true if all conditions are satisfied, false otherwise
78 * 05.01.2004 - implemented
82 * Email: michael.mi@sun.com
83 ******************************************************************************/
87 sal_Int32 nKeyInc
= 0;
88 if (m_nIdOfKeyEC
!= 0)
95 m_nIdOfBlocker
== -1 ||
96 1+nKeyInc
> m_nNumOfResolvedReferences
)
104 void EncryptionEngine::tryToPerform( )
105 throw (cssu::Exception
, cssu::RuntimeException
)
106 /****** EncryptionEngine/tryToPerform ****************************************
109 * tryToPerform -- tries to perform the encryption/decryption operation.
115 * if the situation is ready, perform following operations.
116 * 1. prepares a encryption template;
117 * 2. calls the encryption bridge component;
118 * 3. clears up all used resources;
119 * 4. notifies the result listener;
120 * 5. sets the "accomplishment" flag.
129 * 05.01.2004 - implemented
133 * Email: michael.mi@sun.com
134 ******************************************************************************/
138 const rtl::OUString
sEncryptionTemplate (
139 RTL_CONSTASCII_USTRINGPARAM( ENCRYPTION_TEMPLATE
) );
140 cssu::Reference
< cssxc::XXMLEncryptionTemplate
> xEncryptionTemplate(
141 mxMSF
->createInstance( sEncryptionTemplate
), cssu::UNO_QUERY
);
143 OSL_ASSERT( xEncryptionTemplate
.is() );
145 cssu::Reference
< cssxw::XXMLElementWrapper
> xXMLElement
146 = m_xSAXEventKeeper
->getElement( m_nIdOfTemplateEC
);
148 xEncryptionTemplate
->setTemplate(xXMLElement
);
150 startEngine( xEncryptionTemplate
);
157 notifyResultListener();
159 m_bMissionDone
= true;
163 void EncryptionEngine::clearUp( ) const
164 /****** EncryptionEngine/clearup *********************************************
167 * clearUp -- clear up all resources used by this operation.
173 * cleaning resources up includes:
174 * 1. releases the ElementCollector for the encryption template element;
175 * 2. releases the Blocker for the encryption template element;
176 * 3. releases the ElementCollector for the key element, if there is one.
185 * 05.01.2004 - implemented
189 * Email: michael.mi@sun.com
190 ******************************************************************************/
192 cssu::Reference
< cssxc::sax::XReferenceResolvedBroadcaster
>
193 xReferenceResolvedBroadcaster( m_xSAXEventKeeper
, cssu::UNO_QUERY
);
195 xReferenceResolvedBroadcaster
->removeReferenceResolvedListener(
197 (const cssu::Reference
< cssxc::sax::XReferenceResolvedListener
>)((SecurityEngine
*)this));
199 m_xSAXEventKeeper
->removeElementCollector(m_nIdOfTemplateEC
);
201 if (m_nIdOfBlocker
!= -1)
203 m_xSAXEventKeeper
->removeBlocker(m_nIdOfBlocker
);
206 if (m_nIdOfKeyEC
!= 0 && m_nIdOfKeyEC
!= -1)
208 m_xSAXEventKeeper
->removeElementCollector(m_nIdOfKeyEC
);
212 /* XBlockerMonitor */
213 void SAL_CALL
EncryptionEngine::setBlockerId( sal_Int32 id
)
214 throw (com::sun::star::uno::Exception
, com::sun::star::uno::RuntimeException
)