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 "signatureverifierimpl.hxx" 32 #include <com/sun/star/xml/crypto/XXMLSignatureTemplate.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.SignatureVerifier" 42 #define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.SignatureVerifierImpl" 43 44 #define DECLARE_ASCII( SASCIIVALUE ) \ 45 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SASCIIVALUE ) ) 46 47 SignatureVerifierImpl::SignatureVerifierImpl( const cssu::Reference< cssl::XMultiServiceFactory >& rxMSF) 48 { 49 mxMSF = rxMSF; 50 } 51 52 SignatureVerifierImpl::~SignatureVerifierImpl() 53 { 54 } 55 56 bool SignatureVerifierImpl::checkReady() const 57 /****** SignatureVerifierImpl/checkReady ************************************* 58 * 59 * NAME 60 * checkReady -- checks the conditions for the signature verification. 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 SignatureEngine 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() && SignatureEngine::checkReady()); 85 } 86 87 void SignatureVerifierImpl::notifyResultListener() const 88 throw (cssu::Exception, cssu::RuntimeException) 89 /****** SignatureVerifierImpl/notifyResultListener *************************** 90 * 91 * NAME 92 * notifyResultListener -- notifies the listener about the verify result. 93 * 94 * SYNOPSIS 95 * notifyResultListener( ); 96 * 97 * FUNCTION 98 * see NAME. 99 * 100 * INPUTS 101 * empty 102 * 103 * RESULT 104 * empty 105 * 106 * HISTORY 107 * 05.01.2004 - implemented 108 * 109 * AUTHOR 110 * Michael Mi 111 * Email: michael.mi@sun.com 112 ******************************************************************************/ 113 { 114 cssu::Reference< cssxc::sax::XSignatureVerifyResultListener > 115 xSignatureVerifyResultListener ( m_xResultListener , cssu::UNO_QUERY ) ; 116 117 xSignatureVerifyResultListener->signatureVerified( m_nSecurityId, m_nStatus ); 118 } 119 120 void SignatureVerifierImpl::startEngine( const cssu::Reference< 121 cssxc::XXMLSignatureTemplate >& 122 xSignatureTemplate) 123 throw (cssu::Exception, cssu::RuntimeException) 124 /****** SignatureVerifierImpl/startEngine ************************************ 125 * 126 * NAME 127 * startEngine -- verifies the signature. 128 * 129 * SYNOPSIS 130 * startEngine( xSignatureTemplate ); 131 * 132 * FUNCTION 133 * see NAME. 134 * 135 * INPUTS 136 * xSignatureTemplate - the signature template (along with all referenced 137 * elements) to be verified. 138 * 139 * RESULT 140 * empty 141 * 142 * HISTORY 143 * 05.01.2004 - implemented 144 * 145 * AUTHOR 146 * Michael Mi 147 * Email: michael.mi@sun.com 148 ******************************************************************************/ 149 { 150 cssu::Reference< cssxc::XXMLSignatureTemplate > xResultTemplate; 151 try 152 { 153 xResultTemplate = m_xXMLSignature->validate(xSignatureTemplate, m_xXMLSecurityContext); 154 m_nStatus = xResultTemplate->getStatus(); 155 } 156 catch( cssu::Exception& ) 157 { 158 m_nStatus = cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED; 159 } 160 } 161 162 /* XSignatureVerifyResultBroadcaster */ 163 void SAL_CALL SignatureVerifierImpl::addSignatureVerifyResultListener( 164 const cssu::Reference< cssxc::sax::XSignatureVerifyResultListener >& listener ) 165 throw (cssu::Exception, cssu::RuntimeException) 166 { 167 m_xResultListener = listener; 168 tryToPerform(); 169 } 170 171 void SAL_CALL SignatureVerifierImpl::removeSignatureVerifyResultListener( 172 const cssu::Reference< cssxc::sax::XSignatureVerifyResultListener >&) 173 throw (cssu::RuntimeException) 174 { 175 } 176 177 /* XInitialization */ 178 void SAL_CALL SignatureVerifierImpl::initialize( 179 const cssu::Sequence< cssu::Any >& aArguments ) 180 throw (cssu::Exception, cssu::RuntimeException) 181 { 182 OSL_ASSERT(aArguments.getLength() == 5); 183 184 rtl::OUString ouTempString; 185 186 aArguments[0] >>= ouTempString; 187 m_nSecurityId = ouTempString.toInt32(); 188 aArguments[1] >>= m_xSAXEventKeeper; 189 aArguments[2] >>= ouTempString; 190 m_nIdOfTemplateEC = ouTempString.toInt32(); 191 aArguments[3] >>= m_xXMLSecurityContext; 192 aArguments[4] >>= m_xXMLSignature; 193 } 194 195 196 rtl::OUString SignatureVerifierImpl_getImplementationName () 197 throw (cssu::RuntimeException) 198 { 199 return rtl::OUString( 200 RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) ); 201 } 202 203 sal_Bool SAL_CALL SignatureVerifierImpl_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 SignatureVerifierImpl_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 SignatureVerifierImpl_createInstance( 220 const cssu::Reference< cssl::XMultiServiceFactory >& rSMgr) 221 throw( cssu::Exception ) 222 { 223 return (cppu::OWeakObject*) new SignatureVerifierImpl(rSMgr); 224 } 225 226 /* XServiceInfo */ 227 rtl::OUString SAL_CALL SignatureVerifierImpl::getImplementationName( ) 228 throw (cssu::RuntimeException) 229 { 230 return SignatureVerifierImpl_getImplementationName(); 231 } 232 sal_Bool SAL_CALL SignatureVerifierImpl::supportsService( const rtl::OUString& rServiceName ) 233 throw (cssu::RuntimeException) 234 { 235 return SignatureVerifierImpl_supportsService( rServiceName ); 236 } 237 cssu::Sequence< rtl::OUString > SAL_CALL SignatureVerifierImpl::getSupportedServiceNames( ) 238 throw (cssu::RuntimeException) 239 { 240 return SignatureVerifierImpl_getSupportedServiceNames(); 241 } 242 243