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: decryptorimpl.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 "decryptorimpl.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 SERVICE_NAME "com.sun.star.xml.crypto.sax.Decryptor"
45 #define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.DecryptorImpl"
47 #define DECLARE_ASCII( SASCIIVALUE ) \
48 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SASCIIVALUE ) )
50 DecryptorImpl::DecryptorImpl( const cssu::Reference
< cssl::XMultiServiceFactory
>& rxMSF
)
55 DecryptorImpl::~DecryptorImpl()
59 bool DecryptorImpl::checkReady() const
60 /****** DecryptorImpl/checkReady *********************************************
63 * checkReady -- checks the conditions for the decryption.
66 * bReady = checkReady( );
69 * checks whether all following conditions are satisfied:
70 * 1. the result listener is ready;
71 * 2. the EncryptionEngine is ready.
77 * bReady - true if all conditions are satisfied, false otherwise
80 * 05.01.2004 - implemented
84 * Email: michael.mi@sun.com
85 ******************************************************************************/
87 return (m_xResultListener
.is() && EncryptionEngine::checkReady());
90 void DecryptorImpl::notifyResultListener() const
91 throw (cssu::Exception
, cssu::RuntimeException
)
92 /****** DecryptorImpl/notifyResultListener ***********************************
95 * notifyResultListener -- notifies the listener about the decryption
99 * notifyResultListener( );
111 * 05.01.2004 - implemented
115 * Email: michael.mi@sun.com
116 ******************************************************************************/
118 cssu::Reference
< cssxc::sax::XDecryptionResultListener
>
119 xDecryptionResultListener ( m_xResultListener
, cssu::UNO_QUERY
) ;
121 xDecryptionResultListener
->decrypted(m_nSecurityId
,m_nStatus
);
124 void DecryptorImpl::startEngine( const cssu::Reference
<
125 cssxc::XXMLEncryptionTemplate
>&
127 throw (cssu::Exception
, cssu::RuntimeException
)
128 /****** DecryptorImpl/startEngine ********************************************
131 * startEngine -- decrypts the encryption.
134 * startEngine( xEncryptionTemplate );
137 * decrypts the encryption element, then if succeeds, updates the link
138 * of old template element to the new encryption element in
142 * xEncryptionTemplate - the encryption template to be decrypted.
148 * 05.01.2004 - implemented
152 * Email: michael.mi@sun.com
153 ******************************************************************************/
155 cssu::Reference
< cssxc::XXMLEncryptionTemplate
> xResultTemplate
;
158 xResultTemplate
= m_xXMLEncryption
->decrypt(xEncryptionTemplate
, m_xXMLSecurityContext
);
159 m_nStatus
= xResultTemplate
->getStatus();
161 catch( cssu::Exception
& )
163 m_nStatus
= cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED
;
166 if (m_nStatus
== cssxc::SecurityOperationStatus_OPERATION_SUCCEEDED
)
168 cssu::Reference
< cssxw::XXMLElementWrapper
> xDecryptedElement
169 = xResultTemplate
->getTemplate();
170 m_xSAXEventKeeper
->setElement(m_nIdOfTemplateEC
, xDecryptedElement
);
174 /* XDecryptionResultBroadcaster */
175 void SAL_CALL
DecryptorImpl::addDecryptionResultListener( const cssu::Reference
< cssxc::sax::XDecryptionResultListener
>& listener
)
176 throw (cssu::Exception
, cssu::RuntimeException
)
178 m_xResultListener
= listener
;
182 void SAL_CALL
DecryptorImpl::removeDecryptionResultListener( const cssu::Reference
< cssxc::sax::XDecryptionResultListener
>&)
183 throw (cssu::RuntimeException
)
187 /* XInitialization */
188 void SAL_CALL
DecryptorImpl::initialize( const cssu::Sequence
< cssu::Any
>& aArguments
)
189 throw (cssu::Exception
, cssu::RuntimeException
)
191 OSL_ASSERT(aArguments
.getLength() == 5);
193 rtl::OUString ouTempString
;
195 aArguments
[0] >>= ouTempString
;
196 m_nSecurityId
= ouTempString
.toInt32();
197 aArguments
[1] >>= m_xSAXEventKeeper
;
198 aArguments
[2] >>= ouTempString
;
199 m_nIdOfTemplateEC
= ouTempString
.toInt32();
200 aArguments
[3] >>= m_xXMLSecurityContext
;
201 aArguments
[4] >>= m_xXMLEncryption
;
204 rtl::OUString
DecryptorImpl_getImplementationName ()
205 throw (cssu::RuntimeException
)
207 return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME
) );
210 sal_Bool SAL_CALL
DecryptorImpl_supportsService( const rtl::OUString
& ServiceName
)
211 throw (cssu::RuntimeException
)
213 return ServiceName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME
));
216 cssu::Sequence
< rtl::OUString
> SAL_CALL
DecryptorImpl_getSupportedServiceNames( )
217 throw (cssu::RuntimeException
)
219 cssu::Sequence
< rtl::OUString
> aRet(1);
220 rtl::OUString
* pArray
= aRet
.getArray();
221 pArray
[0] = rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME
) );
226 cssu::Reference
< cssu::XInterface
> SAL_CALL
DecryptorImpl_createInstance( const cssu::Reference
< cssl::XMultiServiceFactory
>& rSMgr
)
227 throw( cssu::Exception
)
229 return (cppu::OWeakObject
*) new DecryptorImpl(rSMgr
);
233 rtl::OUString SAL_CALL
DecryptorImpl::getImplementationName( )
234 throw (cssu::RuntimeException
)
236 return DecryptorImpl_getImplementationName();
238 sal_Bool SAL_CALL
DecryptorImpl::supportsService( const rtl::OUString
& rServiceName
)
239 throw (cssu::RuntimeException
)
241 return DecryptorImpl_supportsService( rServiceName
);
243 cssu::Sequence
< rtl::OUString
> SAL_CALL
DecryptorImpl::getSupportedServiceNames( )
244 throw (cssu::RuntimeException
)
246 return DecryptorImpl_getSupportedServiceNames();