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 /****** DecryptorImpl/notifyResultListener *********************************** 85 * 86 * NAME 87 * notifyResultListener -- notifies the listener about the decryption 88 * result. 89 * 90 * SYNOPSIS 91 * notifyResultListener( ); 92 * 93 * FUNCTION 94 * see NAME. 95 * 96 * INPUTS 97 * empty 98 * 99 * RESULT 100 * empty 101 * 102 * HISTORY 103 * 05.01.2004 - implemented 104 * 105 * AUTHOR 106 * Michael Mi 107 * Email: michael.mi@sun.com 108 ******************************************************************************/ 109 { 110 cssu::Reference< cssxc::sax::XDecryptionResultListener > 111 xDecryptionResultListener ( m_xResultListener , cssu::UNO_QUERY ) ; 112 113 xDecryptionResultListener->decrypted(m_nSecurityId,m_nStatus); 114 } 115 116 void DecryptorImpl::startEngine( const cssu::Reference< 117 cssxc::XXMLEncryptionTemplate >& 118 xEncryptionTemplate) 119 /****** DecryptorImpl/startEngine ******************************************** 120 * 121 * NAME 122 * startEngine -- decrypts the encryption. 123 * 124 * SYNOPSIS 125 * startEngine( xEncryptionTemplate ); 126 * 127 * FUNCTION 128 * decrypts the encryption element, then if succeeds, updates the link 129 * of old template element to the new encryption element in 130 * SAXEventKeeper. 131 * 132 * INPUTS 133 * xEncryptionTemplate - the encryption template to be decrypted. 134 * 135 * RESULT 136 * empty 137 * 138 * HISTORY 139 * 05.01.2004 - implemented 140 * 141 * AUTHOR 142 * Michael Mi 143 * Email: michael.mi@sun.com 144 ******************************************************************************/ 145 { 146 cssu::Reference< cssxc::XXMLEncryptionTemplate > xResultTemplate; 147 try 148 { 149 xResultTemplate = m_xXMLEncryption->decrypt(xEncryptionTemplate, m_xXMLSecurityContext); 150 m_nStatus = xResultTemplate->getStatus(); 151 } 152 catch( cssu::Exception& ) 153 { 154 m_nStatus = cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED; 155 } 156 157 if (m_nStatus == cssxc::SecurityOperationStatus_OPERATION_SUCCEEDED) 158 { 159 cssu::Reference< cssxw::XXMLElementWrapper > xDecryptedElement 160 = xResultTemplate->getTemplate(); 161 m_xSAXEventKeeper->setElement(m_nIdOfTemplateEC, xDecryptedElement); 162 } 163 } 164 165 /* XDecryptionResultBroadcaster */ 166 void SAL_CALL DecryptorImpl::addDecryptionResultListener( const cssu::Reference< cssxc::sax::XDecryptionResultListener >& listener ) 167 { 168 m_xResultListener = listener; 169 tryToPerform(); 170 } 171 172 void SAL_CALL DecryptorImpl::removeDecryptionResultListener( const cssu::Reference< cssxc::sax::XDecryptionResultListener >&) 173 { 174 } 175 176 /* XInitialization */ 177 void SAL_CALL DecryptorImpl::initialize( const cssu::Sequence< cssu::Any >& aArguments ) 178 { 179 OSL_ASSERT(aArguments.getLength() == 5); 180 181 rtl::OUString ouTempString; 182 183 aArguments[0] >>= ouTempString; 184 m_nSecurityId = ouTempString.toInt32(); 185 aArguments[1] >>= m_xSAXEventKeeper; 186 aArguments[2] >>= ouTempString; 187 m_nIdOfTemplateEC = ouTempString.toInt32(); 188 aArguments[3] >>= m_xXMLSecurityContext; 189 aArguments[4] >>= m_xXMLEncryption; 190 } 191 192 rtl::OUString DecryptorImpl_getImplementationName () 193 { 194 return rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) ); 195 } 196 197 sal_Bool SAL_CALL DecryptorImpl_supportsService( const rtl::OUString& ServiceName ) 198 { 199 return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME )); 200 } 201 202 cssu::Sequence< rtl::OUString > SAL_CALL DecryptorImpl_getSupportedServiceNames( ) 203 { 204 cssu::Sequence < rtl::OUString > aRet(1); 205 rtl::OUString* pArray = aRet.getArray(); 206 pArray[0] = rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) ); 207 return aRet; 208 } 209 #undef SERVICE_NAME 210 211 cssu::Reference< cssu::XInterface > SAL_CALL DecryptorImpl_createInstance( const cssu::Reference< cssl::XMultiServiceFactory >& rSMgr) 212 { 213 return (cppu::OWeakObject*) new DecryptorImpl(rSMgr); 214 } 215 216 /* XServiceInfo */ 217 rtl::OUString SAL_CALL DecryptorImpl::getImplementationName( ) 218 { 219 return DecryptorImpl_getImplementationName(); 220 } 221 sal_Bool SAL_CALL DecryptorImpl::supportsService( const rtl::OUString& rServiceName ) 222 { 223 return DecryptorImpl_supportsService( rServiceName ); 224 } 225 cssu::Sequence< rtl::OUString > SAL_CALL DecryptorImpl::getSupportedServiceNames( ) 226 { 227 return DecryptorImpl_getSupportedServiceNames(); 228 } 229