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 "decryptorimpl.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 SERVICE_NAME "com.sun.star.xml.crypto.sax.Decryptor"
42 #define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.DecryptorImpl"
44 #define DECLARE_ASCII( SASCIIVALUE ) \
45 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SASCIIVALUE ) )
47 DecryptorImpl::DecryptorImpl( const cssu::Reference
< cssl::XMultiServiceFactory
>& rxMSF
)
52 DecryptorImpl::~DecryptorImpl()
56 bool DecryptorImpl::checkReady() const
57 /****** DecryptorImpl/checkReady *********************************************
60 * checkReady -- checks the conditions for the decryption.
63 * bReady = checkReady( );
66 * checks whether all following conditions are satisfied:
67 * 1. the result listener is ready;
68 * 2. the EncryptionEngine is ready.
74 * bReady - true if all conditions are satisfied, false otherwise
77 * 05.01.2004 - implemented
81 * Email: michael.mi@sun.com
82 ******************************************************************************/
84 return (m_xResultListener
.is() && EncryptionEngine::checkReady());
87 void DecryptorImpl::notifyResultListener() const
88 throw (cssu::Exception
, cssu::RuntimeException
)
89 /****** DecryptorImpl/notifyResultListener ***********************************
92 * notifyResultListener -- notifies the listener about the decryption
96 * notifyResultListener( );
108 * 05.01.2004 - implemented
112 * Email: michael.mi@sun.com
113 ******************************************************************************/
115 cssu::Reference
< cssxc::sax::XDecryptionResultListener
>
116 xDecryptionResultListener ( m_xResultListener
, cssu::UNO_QUERY
) ;
118 xDecryptionResultListener
->decrypted(m_nSecurityId
,m_nStatus
);
121 void DecryptorImpl::startEngine( const cssu::Reference
<
122 cssxc::XXMLEncryptionTemplate
>&
124 throw (cssu::Exception
, cssu::RuntimeException
)
125 /****** DecryptorImpl/startEngine ********************************************
128 * startEngine -- decrypts the encryption.
131 * startEngine( xEncryptionTemplate );
134 * decrypts the encryption element, then if succeeds, updates the link
135 * of old template element to the new encryption element in
139 * xEncryptionTemplate - the encryption template to be decrypted.
145 * 05.01.2004 - implemented
149 * Email: michael.mi@sun.com
150 ******************************************************************************/
152 cssu::Reference
< cssxc::XXMLEncryptionTemplate
> xResultTemplate
;
155 xResultTemplate
= m_xXMLEncryption
->decrypt(xEncryptionTemplate
, m_xXMLSecurityContext
);
156 m_nStatus
= xResultTemplate
->getStatus();
158 catch( cssu::Exception
& )
160 m_nStatus
= cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED
;
163 if (m_nStatus
== cssxc::SecurityOperationStatus_OPERATION_SUCCEEDED
)
165 cssu::Reference
< cssxw::XXMLElementWrapper
> xDecryptedElement
166 = xResultTemplate
->getTemplate();
167 m_xSAXEventKeeper
->setElement(m_nIdOfTemplateEC
, xDecryptedElement
);
171 /* XDecryptionResultBroadcaster */
172 void SAL_CALL
DecryptorImpl::addDecryptionResultListener( const cssu::Reference
< cssxc::sax::XDecryptionResultListener
>& listener
)
173 throw (cssu::Exception
, cssu::RuntimeException
)
175 m_xResultListener
= listener
;
179 void SAL_CALL
DecryptorImpl::removeDecryptionResultListener( const cssu::Reference
< cssxc::sax::XDecryptionResultListener
>&)
180 throw (cssu::RuntimeException
)
184 /* XInitialization */
185 void SAL_CALL
DecryptorImpl::initialize( const cssu::Sequence
< cssu::Any
>& aArguments
)
186 throw (cssu::Exception
, cssu::RuntimeException
)
188 OSL_ASSERT(aArguments
.getLength() == 5);
190 rtl::OUString ouTempString
;
192 aArguments
[0] >>= ouTempString
;
193 m_nSecurityId
= ouTempString
.toInt32();
194 aArguments
[1] >>= m_xSAXEventKeeper
;
195 aArguments
[2] >>= ouTempString
;
196 m_nIdOfTemplateEC
= ouTempString
.toInt32();
197 aArguments
[3] >>= m_xXMLSecurityContext
;
198 aArguments
[4] >>= m_xXMLEncryption
;
201 rtl::OUString
DecryptorImpl_getImplementationName ()
202 throw (cssu::RuntimeException
)
204 return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME
) );
207 sal_Bool SAL_CALL
DecryptorImpl_supportsService( const rtl::OUString
& ServiceName
)
208 throw (cssu::RuntimeException
)
210 return ServiceName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME
));
213 cssu::Sequence
< rtl::OUString
> SAL_CALL
DecryptorImpl_getSupportedServiceNames( )
214 throw (cssu::RuntimeException
)
216 cssu::Sequence
< rtl::OUString
> aRet(1);
217 rtl::OUString
* pArray
= aRet
.getArray();
218 pArray
[0] = rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME
) );
223 cssu::Reference
< cssu::XInterface
> SAL_CALL
DecryptorImpl_createInstance( const cssu::Reference
< cssl::XMultiServiceFactory
>& rSMgr
)
224 throw( cssu::Exception
)
226 return (cppu::OWeakObject
*) new DecryptorImpl(rSMgr
);
230 rtl::OUString SAL_CALL
DecryptorImpl::getImplementationName( )
231 throw (cssu::RuntimeException
)
233 return DecryptorImpl_getImplementationName();
235 sal_Bool SAL_CALL
DecryptorImpl::supportsService( const rtl::OUString
& rServiceName
)
236 throw (cssu::RuntimeException
)
238 return DecryptorImpl_supportsService( rServiceName
);
240 cssu::Sequence
< rtl::OUString
> SAL_CALL
DecryptorImpl::getSupportedServiceNames( )
241 throw (cssu::RuntimeException
)
243 return DecryptorImpl_getSupportedServiceNames();