1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_xmlsecurity.hxx" 26 27 #include "decryptorimpl.hxx" 28 #include <com/sun/star/xml/crypto/XXMLEncryptionTemplate.hpp> 29 #include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp> 30 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 31 32 namespace cssu = com::sun::star::uno; 33 namespace cssl = com::sun::star::lang; 34 namespace cssxc = com::sun::star::xml::crypto; 35 namespace cssxw = com::sun::star::xml::wrapper; 36 37 #define SERVICE_NAME "com.sun.star.xml.crypto.sax.Decryptor" 38 #define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.DecryptorImpl" 39 40 #define DECLARE_ASCII( SASCIIVALUE ) \ 41 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SASCIIVALUE ) ) 42 43 DecryptorImpl::DecryptorImpl( const cssu::Reference< cssl::XMultiServiceFactory >& rxMSF) 44 { 45 mxMSF = rxMSF; 46 } 47 48 DecryptorImpl::~DecryptorImpl() 49 { 50 } 51 52 bool DecryptorImpl::checkReady() const 53 /****** DecryptorImpl/checkReady ********************************************* 54 * 55 * NAME 56 * checkReady -- checks the conditions for the decryption. 57 * 58 * SYNOPSIS 59 * bReady = checkReady( ); 60 * 61 * FUNCTION 62 * checks whether all following conditions are satisfied: 63 * 1. the result listener is ready; 64 * 2. the EncryptionEngine is ready. 65 * 66 * INPUTS 67 * empty 68 * 69 * RESULT 70 * bReady - true if all conditions are satisfied, false otherwise 71 * 72 * HISTORY 73 * 05.01.2004 - implemented 74 * 75 * AUTHOR 76 * Michael Mi 77 * Email: michael.mi@sun.com 78 ******************************************************************************/ 79 { 80 return (m_xResultListener.is() && EncryptionEngine::checkReady()); 81 } 82 83 void DecryptorImpl::notifyResultListener() const 84 throw (cssu::Exception, cssu::RuntimeException) 85 /****** DecryptorImpl/notifyResultListener *********************************** 86 * 87 * NAME 88 * notifyResultListener -- notifies the listener about the decryption 89 * result. 90 * 91 * SYNOPSIS 92 * notifyResultListener( ); 93 * 94 * FUNCTION 95 * see NAME. 96 * 97 * INPUTS 98 * empty 99 * 100 * RESULT 101 * empty 102 * 103 * HISTORY 104 * 05.01.2004 - implemented 105 * 106 * AUTHOR 107 * Michael Mi 108 * Email: michael.mi@sun.com 109 ******************************************************************************/ 110 { 111 cssu::Reference< cssxc::sax::XDecryptionResultListener > 112 xDecryptionResultListener ( m_xResultListener , cssu::UNO_QUERY ) ; 113 114 xDecryptionResultListener->decrypted(m_nSecurityId,m_nStatus); 115 } 116 117 void DecryptorImpl::startEngine( const cssu::Reference< 118 cssxc::XXMLEncryptionTemplate >& 119 xEncryptionTemplate) 120 throw (cssu::Exception, cssu::RuntimeException) 121 /****** DecryptorImpl/startEngine ******************************************** 122 * 123 * NAME 124 * startEngine -- decrypts the encryption. 125 * 126 * SYNOPSIS 127 * startEngine( xEncryptionTemplate ); 128 * 129 * FUNCTION 130 * decrypts the encryption element, then if succeeds, updates the link 131 * of old template element to the new encryption element in 132 * SAXEventKeeper. 133 * 134 * INPUTS 135 * xEncryptionTemplate - the encryption template to be decrypted. 136 * 137 * RESULT 138 * empty 139 * 140 * HISTORY 141 * 05.01.2004 - implemented 142 * 143 * AUTHOR 144 * Michael Mi 145 * Email: michael.mi@sun.com 146 ******************************************************************************/ 147 { 148 cssu::Reference< cssxc::XXMLEncryptionTemplate > xResultTemplate; 149 try 150 { 151 xResultTemplate = m_xXMLEncryption->decrypt(xEncryptionTemplate, m_xXMLSecurityContext); 152 m_nStatus = xResultTemplate->getStatus(); 153 } 154 catch( cssu::Exception& ) 155 { 156 m_nStatus = cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED; 157 } 158 159 if (m_nStatus == cssxc::SecurityOperationStatus_OPERATION_SUCCEEDED) 160 { 161 cssu::Reference< cssxw::XXMLElementWrapper > xDecryptedElement 162 = xResultTemplate->getTemplate(); 163 m_xSAXEventKeeper->setElement(m_nIdOfTemplateEC, xDecryptedElement); 164 } 165 } 166 167 /* XDecryptionResultBroadcaster */ 168 void SAL_CALL DecryptorImpl::addDecryptionResultListener( const cssu::Reference< cssxc::sax::XDecryptionResultListener >& listener ) 169 throw (cssu::Exception, cssu::RuntimeException) 170 { 171 m_xResultListener = listener; 172 tryToPerform(); 173 } 174 175 void SAL_CALL DecryptorImpl::removeDecryptionResultListener( const cssu::Reference< cssxc::sax::XDecryptionResultListener >&) 176 throw (cssu::RuntimeException) 177 { 178 } 179 180 /* XInitialization */ 181 void SAL_CALL DecryptorImpl::initialize( const cssu::Sequence< cssu::Any >& aArguments ) 182 throw (cssu::Exception, cssu::RuntimeException) 183 { 184 OSL_ASSERT(aArguments.getLength() == 5); 185 186 rtl::OUString ouTempString; 187 188 aArguments[0] >>= ouTempString; 189 m_nSecurityId = ouTempString.toInt32(); 190 aArguments[1] >>= m_xSAXEventKeeper; 191 aArguments[2] >>= ouTempString; 192 m_nIdOfTemplateEC = ouTempString.toInt32(); 193 aArguments[3] >>= m_xXMLSecurityContext; 194 aArguments[4] >>= m_xXMLEncryption; 195 } 196 197 rtl::OUString DecryptorImpl_getImplementationName () 198 throw (cssu::RuntimeException) 199 { 200 return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) ); 201 } 202 203 sal_Bool SAL_CALL DecryptorImpl_supportsService( const rtl::OUString& ServiceName ) 204 throw (cssu::RuntimeException) 205 { 206 return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME )); 207 } 208 209 cssu::Sequence< rtl::OUString > SAL_CALL DecryptorImpl_getSupportedServiceNames( ) 210 throw (cssu::RuntimeException) 211 { 212 cssu::Sequence < rtl::OUString > aRet(1); 213 rtl::OUString* pArray = aRet.getArray(); 214 pArray[0] = rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) ); 215 return aRet; 216 } 217 #undef SERVICE_NAME 218 219 cssu::Reference< cssu::XInterface > SAL_CALL DecryptorImpl_createInstance( const cssu::Reference< cssl::XMultiServiceFactory >& rSMgr) 220 throw( cssu::Exception ) 221 { 222 return (cppu::OWeakObject*) new DecryptorImpl(rSMgr); 223 } 224 225 /* XServiceInfo */ 226 rtl::OUString SAL_CALL DecryptorImpl::getImplementationName( ) 227 throw (cssu::RuntimeException) 228 { 229 return DecryptorImpl_getImplementationName(); 230 } 231 sal_Bool SAL_CALL DecryptorImpl::supportsService( const rtl::OUString& rServiceName ) 232 throw (cssu::RuntimeException) 233 { 234 return DecryptorImpl_supportsService( rServiceName ); 235 } 236 cssu::Sequence< rtl::OUString > SAL_CALL DecryptorImpl::getSupportedServiceNames( ) 237 throw (cssu::RuntimeException) 238 { 239 return DecryptorImpl_getSupportedServiceNames(); 240 } 241 242