1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_xmlsecurity.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "signatureverifierimpl.hxx" 32*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/XXMLSignatureTemplate.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir namespace cssu = com::sun::star::uno; 37*cdf0e10cSrcweir namespace cssl = com::sun::star::lang; 38*cdf0e10cSrcweir namespace cssxc = com::sun::star::xml::crypto; 39*cdf0e10cSrcweir namespace cssxw = com::sun::star::xml::wrapper; 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir #define SERVICE_NAME "com.sun.star.xml.crypto.sax.SignatureVerifier" 42*cdf0e10cSrcweir #define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.SignatureVerifierImpl" 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir #define DECLARE_ASCII( SASCIIVALUE ) \ 45*cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SASCIIVALUE ) ) 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir SignatureVerifierImpl::SignatureVerifierImpl( const cssu::Reference< cssl::XMultiServiceFactory >& rxMSF) 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir mxMSF = rxMSF; 50*cdf0e10cSrcweir } 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir SignatureVerifierImpl::~SignatureVerifierImpl() 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir } 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir bool SignatureVerifierImpl::checkReady() const 57*cdf0e10cSrcweir /****** SignatureVerifierImpl/checkReady ************************************* 58*cdf0e10cSrcweir * 59*cdf0e10cSrcweir * NAME 60*cdf0e10cSrcweir * checkReady -- checks the conditions for the signature verification. 61*cdf0e10cSrcweir * 62*cdf0e10cSrcweir * SYNOPSIS 63*cdf0e10cSrcweir * bReady = checkReady( ); 64*cdf0e10cSrcweir * 65*cdf0e10cSrcweir * FUNCTION 66*cdf0e10cSrcweir * checks whether all following conditions are satisfied: 67*cdf0e10cSrcweir * 1. the result listener is ready; 68*cdf0e10cSrcweir * 2. the SignatureEngine is ready. 69*cdf0e10cSrcweir * 70*cdf0e10cSrcweir * INPUTS 71*cdf0e10cSrcweir * empty 72*cdf0e10cSrcweir * 73*cdf0e10cSrcweir * RESULT 74*cdf0e10cSrcweir * bReady - true if all conditions are satisfied, false otherwise 75*cdf0e10cSrcweir * 76*cdf0e10cSrcweir * HISTORY 77*cdf0e10cSrcweir * 05.01.2004 - implemented 78*cdf0e10cSrcweir * 79*cdf0e10cSrcweir * AUTHOR 80*cdf0e10cSrcweir * Michael Mi 81*cdf0e10cSrcweir * Email: michael.mi@sun.com 82*cdf0e10cSrcweir ******************************************************************************/ 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir return (m_xResultListener.is() && SignatureEngine::checkReady()); 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir void SignatureVerifierImpl::notifyResultListener() const 88*cdf0e10cSrcweir throw (cssu::Exception, cssu::RuntimeException) 89*cdf0e10cSrcweir /****** SignatureVerifierImpl/notifyResultListener *************************** 90*cdf0e10cSrcweir * 91*cdf0e10cSrcweir * NAME 92*cdf0e10cSrcweir * notifyResultListener -- notifies the listener about the verify result. 93*cdf0e10cSrcweir * 94*cdf0e10cSrcweir * SYNOPSIS 95*cdf0e10cSrcweir * notifyResultListener( ); 96*cdf0e10cSrcweir * 97*cdf0e10cSrcweir * FUNCTION 98*cdf0e10cSrcweir * see NAME. 99*cdf0e10cSrcweir * 100*cdf0e10cSrcweir * INPUTS 101*cdf0e10cSrcweir * empty 102*cdf0e10cSrcweir * 103*cdf0e10cSrcweir * RESULT 104*cdf0e10cSrcweir * empty 105*cdf0e10cSrcweir * 106*cdf0e10cSrcweir * HISTORY 107*cdf0e10cSrcweir * 05.01.2004 - implemented 108*cdf0e10cSrcweir * 109*cdf0e10cSrcweir * AUTHOR 110*cdf0e10cSrcweir * Michael Mi 111*cdf0e10cSrcweir * Email: michael.mi@sun.com 112*cdf0e10cSrcweir ******************************************************************************/ 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir cssu::Reference< cssxc::sax::XSignatureVerifyResultListener > 115*cdf0e10cSrcweir xSignatureVerifyResultListener ( m_xResultListener , cssu::UNO_QUERY ) ; 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir xSignatureVerifyResultListener->signatureVerified( m_nSecurityId, m_nStatus ); 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir void SignatureVerifierImpl::startEngine( const cssu::Reference< 121*cdf0e10cSrcweir cssxc::XXMLSignatureTemplate >& 122*cdf0e10cSrcweir xSignatureTemplate) 123*cdf0e10cSrcweir throw (cssu::Exception, cssu::RuntimeException) 124*cdf0e10cSrcweir /****** SignatureVerifierImpl/startEngine ************************************ 125*cdf0e10cSrcweir * 126*cdf0e10cSrcweir * NAME 127*cdf0e10cSrcweir * startEngine -- verifies the signature. 128*cdf0e10cSrcweir * 129*cdf0e10cSrcweir * SYNOPSIS 130*cdf0e10cSrcweir * startEngine( xSignatureTemplate ); 131*cdf0e10cSrcweir * 132*cdf0e10cSrcweir * FUNCTION 133*cdf0e10cSrcweir * see NAME. 134*cdf0e10cSrcweir * 135*cdf0e10cSrcweir * INPUTS 136*cdf0e10cSrcweir * xSignatureTemplate - the signature template (along with all referenced 137*cdf0e10cSrcweir * elements) to be verified. 138*cdf0e10cSrcweir * 139*cdf0e10cSrcweir * RESULT 140*cdf0e10cSrcweir * empty 141*cdf0e10cSrcweir * 142*cdf0e10cSrcweir * HISTORY 143*cdf0e10cSrcweir * 05.01.2004 - implemented 144*cdf0e10cSrcweir * 145*cdf0e10cSrcweir * AUTHOR 146*cdf0e10cSrcweir * Michael Mi 147*cdf0e10cSrcweir * Email: michael.mi@sun.com 148*cdf0e10cSrcweir ******************************************************************************/ 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir cssu::Reference< cssxc::XXMLSignatureTemplate > xResultTemplate; 151*cdf0e10cSrcweir try 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir xResultTemplate = m_xXMLSignature->validate(xSignatureTemplate, m_xXMLSecurityContext); 154*cdf0e10cSrcweir m_nStatus = xResultTemplate->getStatus(); 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir catch( cssu::Exception& ) 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir m_nStatus = cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED; 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir /* XSignatureVerifyResultBroadcaster */ 163*cdf0e10cSrcweir void SAL_CALL SignatureVerifierImpl::addSignatureVerifyResultListener( 164*cdf0e10cSrcweir const cssu::Reference< cssxc::sax::XSignatureVerifyResultListener >& listener ) 165*cdf0e10cSrcweir throw (cssu::Exception, cssu::RuntimeException) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir m_xResultListener = listener; 168*cdf0e10cSrcweir tryToPerform(); 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir void SAL_CALL SignatureVerifierImpl::removeSignatureVerifyResultListener( 172*cdf0e10cSrcweir const cssu::Reference< cssxc::sax::XSignatureVerifyResultListener >&) 173*cdf0e10cSrcweir throw (cssu::RuntimeException) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir /* XInitialization */ 178*cdf0e10cSrcweir void SAL_CALL SignatureVerifierImpl::initialize( 179*cdf0e10cSrcweir const cssu::Sequence< cssu::Any >& aArguments ) 180*cdf0e10cSrcweir throw (cssu::Exception, cssu::RuntimeException) 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir OSL_ASSERT(aArguments.getLength() == 5); 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir rtl::OUString ouTempString; 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir aArguments[0] >>= ouTempString; 187*cdf0e10cSrcweir m_nSecurityId = ouTempString.toInt32(); 188*cdf0e10cSrcweir aArguments[1] >>= m_xSAXEventKeeper; 189*cdf0e10cSrcweir aArguments[2] >>= ouTempString; 190*cdf0e10cSrcweir m_nIdOfTemplateEC = ouTempString.toInt32(); 191*cdf0e10cSrcweir aArguments[3] >>= m_xXMLSecurityContext; 192*cdf0e10cSrcweir aArguments[4] >>= m_xXMLSignature; 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir rtl::OUString SignatureVerifierImpl_getImplementationName () 197*cdf0e10cSrcweir throw (cssu::RuntimeException) 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir return rtl::OUString( 200*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) ); 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir sal_Bool SAL_CALL SignatureVerifierImpl_supportsService( const rtl::OUString& ServiceName ) 204*cdf0e10cSrcweir throw (cssu::RuntimeException) 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME )); 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir cssu::Sequence< rtl::OUString > SAL_CALL SignatureVerifierImpl_getSupportedServiceNames( ) 210*cdf0e10cSrcweir throw (cssu::RuntimeException) 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir cssu::Sequence < rtl::OUString > aRet(1); 213*cdf0e10cSrcweir rtl::OUString* pArray = aRet.getArray(); 214*cdf0e10cSrcweir pArray[0] = rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) ); 215*cdf0e10cSrcweir return aRet; 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir #undef SERVICE_NAME 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir cssu::Reference< cssu::XInterface > SAL_CALL SignatureVerifierImpl_createInstance( 220*cdf0e10cSrcweir const cssu::Reference< cssl::XMultiServiceFactory >& rSMgr) 221*cdf0e10cSrcweir throw( cssu::Exception ) 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir return (cppu::OWeakObject*) new SignatureVerifierImpl(rSMgr); 224*cdf0e10cSrcweir } 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir /* XServiceInfo */ 227*cdf0e10cSrcweir rtl::OUString SAL_CALL SignatureVerifierImpl::getImplementationName( ) 228*cdf0e10cSrcweir throw (cssu::RuntimeException) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir return SignatureVerifierImpl_getImplementationName(); 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir sal_Bool SAL_CALL SignatureVerifierImpl::supportsService( const rtl::OUString& rServiceName ) 233*cdf0e10cSrcweir throw (cssu::RuntimeException) 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir return SignatureVerifierImpl_supportsService( rServiceName ); 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir cssu::Sequence< rtl::OUString > SAL_CALL SignatureVerifierImpl::getSupportedServiceNames( ) 238*cdf0e10cSrcweir throw (cssu::RuntimeException) 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir return SignatureVerifierImpl_getSupportedServiceNames(); 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir 243