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