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 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_xmlsecurity.hxx" 30 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> 35 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; 40 41 #define SERVICE_NAME "com.sun.star.xml.crypto.sax.Decryptor" 42 #define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.DecryptorImpl" 43 44 #define DECLARE_ASCII( SASCIIVALUE ) \ 45 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SASCIIVALUE ) ) 46 47 DecryptorImpl::DecryptorImpl( const cssu::Reference< cssl::XMultiServiceFactory >& rxMSF) 48 { 49 mxMSF = rxMSF; 50 } 51 52 DecryptorImpl::~DecryptorImpl() 53 { 54 } 55 56 bool DecryptorImpl::checkReady() const 57 /****** DecryptorImpl/checkReady ********************************************* 58 * 59 * NAME 60 * checkReady -- checks the conditions for the decryption. 61 * 62 * SYNOPSIS 63 * bReady = checkReady( ); 64 * 65 * FUNCTION 66 * checks whether all following conditions are satisfied: 67 * 1. the result listener is ready; 68 * 2. the EncryptionEngine is ready. 69 * 70 * INPUTS 71 * empty 72 * 73 * RESULT 74 * bReady - true if all conditions are satisfied, false otherwise 75 * 76 * HISTORY 77 * 05.01.2004 - implemented 78 * 79 * AUTHOR 80 * Michael Mi 81 * Email: michael.mi@sun.com 82 ******************************************************************************/ 83 { 84 return (m_xResultListener.is() && EncryptionEngine::checkReady()); 85 } 86 87 void DecryptorImpl::notifyResultListener() const 88 throw (cssu::Exception, cssu::RuntimeException) 89 /****** DecryptorImpl/notifyResultListener *********************************** 90 * 91 * NAME 92 * notifyResultListener -- notifies the listener about the decryption 93 * result. 94 * 95 * SYNOPSIS 96 * notifyResultListener( ); 97 * 98 * FUNCTION 99 * see NAME. 100 * 101 * INPUTS 102 * empty 103 * 104 * RESULT 105 * empty 106 * 107 * HISTORY 108 * 05.01.2004 - implemented 109 * 110 * AUTHOR 111 * Michael Mi 112 * Email: michael.mi@sun.com 113 ******************************************************************************/ 114 { 115 cssu::Reference< cssxc::sax::XDecryptionResultListener > 116 xDecryptionResultListener ( m_xResultListener , cssu::UNO_QUERY ) ; 117 118 xDecryptionResultListener->decrypted(m_nSecurityId,m_nStatus); 119 } 120 121 void DecryptorImpl::startEngine( const cssu::Reference< 122 cssxc::XXMLEncryptionTemplate >& 123 xEncryptionTemplate) 124 throw (cssu::Exception, cssu::RuntimeException) 125 /****** DecryptorImpl/startEngine ******************************************** 126 * 127 * NAME 128 * startEngine -- decrypts the encryption. 129 * 130 * SYNOPSIS 131 * startEngine( xEncryptionTemplate ); 132 * 133 * FUNCTION 134 * decrypts the encryption element, then if succeeds, updates the link 135 * of old template element to the new encryption element in 136 * SAXEventKeeper. 137 * 138 * INPUTS 139 * xEncryptionTemplate - the encryption template to be decrypted. 140 * 141 * RESULT 142 * empty 143 * 144 * HISTORY 145 * 05.01.2004 - implemented 146 * 147 * AUTHOR 148 * Michael Mi 149 * Email: michael.mi@sun.com 150 ******************************************************************************/ 151 { 152 cssu::Reference< cssxc::XXMLEncryptionTemplate > xResultTemplate; 153 try 154 { 155 xResultTemplate = m_xXMLEncryption->decrypt(xEncryptionTemplate, m_xXMLSecurityContext); 156 m_nStatus = xResultTemplate->getStatus(); 157 } 158 catch( cssu::Exception& ) 159 { 160 m_nStatus = cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED; 161 } 162 163 if (m_nStatus == cssxc::SecurityOperationStatus_OPERATION_SUCCEEDED) 164 { 165 cssu::Reference< cssxw::XXMLElementWrapper > xDecryptedElement 166 = xResultTemplate->getTemplate(); 167 m_xSAXEventKeeper->setElement(m_nIdOfTemplateEC, xDecryptedElement); 168 } 169 } 170 171 /* XDecryptionResultBroadcaster */ 172 void SAL_CALL DecryptorImpl::addDecryptionResultListener( const cssu::Reference< cssxc::sax::XDecryptionResultListener >& listener ) 173 throw (cssu::Exception, cssu::RuntimeException) 174 { 175 m_xResultListener = listener; 176 tryToPerform(); 177 } 178 179 void SAL_CALL DecryptorImpl::removeDecryptionResultListener( const cssu::Reference< cssxc::sax::XDecryptionResultListener >&) 180 throw (cssu::RuntimeException) 181 { 182 } 183 184 /* XInitialization */ 185 void SAL_CALL DecryptorImpl::initialize( const cssu::Sequence< cssu::Any >& aArguments ) 186 throw (cssu::Exception, cssu::RuntimeException) 187 { 188 OSL_ASSERT(aArguments.getLength() == 5); 189 190 rtl::OUString ouTempString; 191 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; 199 } 200 201 rtl::OUString DecryptorImpl_getImplementationName () 202 throw (cssu::RuntimeException) 203 { 204 return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) ); 205 } 206 207 sal_Bool SAL_CALL DecryptorImpl_supportsService( const rtl::OUString& ServiceName ) 208 throw (cssu::RuntimeException) 209 { 210 return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME )); 211 } 212 213 cssu::Sequence< rtl::OUString > SAL_CALL DecryptorImpl_getSupportedServiceNames( ) 214 throw (cssu::RuntimeException) 215 { 216 cssu::Sequence < rtl::OUString > aRet(1); 217 rtl::OUString* pArray = aRet.getArray(); 218 pArray[0] = rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) ); 219 return aRet; 220 } 221 #undef SERVICE_NAME 222 223 cssu::Reference< cssu::XInterface > SAL_CALL DecryptorImpl_createInstance( const cssu::Reference< cssl::XMultiServiceFactory >& rSMgr) 224 throw( cssu::Exception ) 225 { 226 return (cppu::OWeakObject*) new DecryptorImpl(rSMgr); 227 } 228 229 /* XServiceInfo */ 230 rtl::OUString SAL_CALL DecryptorImpl::getImplementationName( ) 231 throw (cssu::RuntimeException) 232 { 233 return DecryptorImpl_getImplementationName(); 234 } 235 sal_Bool SAL_CALL DecryptorImpl::supportsService( const rtl::OUString& rServiceName ) 236 throw (cssu::RuntimeException) 237 { 238 return DecryptorImpl_supportsService( rServiceName ); 239 } 240 cssu::Sequence< rtl::OUString > SAL_CALL DecryptorImpl::getSupportedServiceNames( ) 241 throw (cssu::RuntimeException) 242 { 243 return DecryptorImpl_getSupportedServiceNames(); 244 } 245 246