LCOV - code coverage report
Current view: top level - xmlsecurity/source/framework - signatureverifierimpl.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 2 50 4.0 %
Date: 2014-04-11 Functions: 1 15 6.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include "signatureverifierimpl.hxx"
      22             : #include <com/sun/star/xml/crypto/XXMLSignatureTemplate.hpp>
      23             : #include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
      24             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      25             : #include <comphelper/processfactory.hxx>
      26             : #include <cppuhelper/supportsservice.hxx>
      27             : 
      28             : namespace cssu = com::sun::star::uno;
      29             : namespace cssl = com::sun::star::lang;
      30             : namespace cssxc = com::sun::star::xml::crypto;
      31             : 
      32             : #define SERVICE_NAME "com.sun.star.xml.crypto.sax.SignatureVerifier"
      33             : #define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.SignatureVerifierImpl"
      34             : 
      35           0 : SignatureVerifierImpl::SignatureVerifierImpl( const cssu::Reference< css::uno::XComponentContext >& xContext)
      36           0 :   : SignatureVerifierImpl_Base(xContext)
      37             : {
      38           0 : }
      39             : 
      40           0 : SignatureVerifierImpl::~SignatureVerifierImpl()
      41             : {
      42           0 : }
      43             : 
      44           0 : bool SignatureVerifierImpl::checkReady() const
      45             : /****** SignatureVerifierImpl/checkReady *************************************
      46             :  *
      47             :  *   NAME
      48             :  *  checkReady -- checks the conditions for the signature verification.
      49             :  *
      50             :  *   SYNOPSIS
      51             :  *  bReady = checkReady( );
      52             :  *
      53             :  *   FUNCTION
      54             :  *  checks whether all following conditions are satisfied:
      55             :  *  1. the result listener is ready;
      56             :  *  2. the SignatureEngine is ready.
      57             :  *
      58             :  *   INPUTS
      59             :  *  empty
      60             :  *
      61             :  *   RESULT
      62             :  *  bReady - true if all conditions are satisfied, false otherwise
      63             :  *
      64             :  *   AUTHOR
      65             :  *  Michael Mi
      66             :  *  Email: michael.mi@sun.com
      67             :  ******************************************************************************/
      68             : {
      69           0 :     return (m_xResultListener.is() && SignatureEngine::checkReady());
      70             : }
      71             : 
      72           0 : void SignatureVerifierImpl::notifyResultListener() const
      73             :     throw (cssu::Exception, cssu::RuntimeException)
      74             : /****** SignatureVerifierImpl/notifyResultListener ***************************
      75             :  *
      76             :  *   NAME
      77             :  *  notifyResultListener -- notifies the listener about the verify result.
      78             :  *
      79             :  *   SYNOPSIS
      80             :  *  notifyResultListener( );
      81             :  *
      82             :  *   FUNCTION
      83             :  *  see NAME.
      84             :  *
      85             :  *   INPUTS
      86             :  *  empty
      87             :  *
      88             :  *   RESULT
      89             :  *  empty
      90             :  *
      91             :  *   AUTHOR
      92             :  *  Michael Mi
      93             :  *  Email: michael.mi@sun.com
      94             :  ******************************************************************************/
      95             : {
      96             :     cssu::Reference< cssxc::sax::XSignatureVerifyResultListener >
      97           0 :         xSignatureVerifyResultListener ( m_xResultListener , cssu::UNO_QUERY ) ;
      98             : 
      99           0 :     xSignatureVerifyResultListener->signatureVerified( m_nSecurityId, m_nStatus );
     100           0 : }
     101             : 
     102           0 : void SignatureVerifierImpl::startEngine( const cssu::Reference<
     103             :     cssxc::XXMLSignatureTemplate >&
     104             :     xSignatureTemplate)
     105             :     throw (cssu::Exception, cssu::RuntimeException)
     106             : /****** SignatureVerifierImpl/startEngine ************************************
     107             :  *
     108             :  *   NAME
     109             :  *  startEngine -- verifies the signature.
     110             :  *
     111             :  *   SYNOPSIS
     112             :  *  startEngine( xSignatureTemplate );
     113             :  *
     114             :  *   FUNCTION
     115             :  *  see NAME.
     116             :  *
     117             :  *   INPUTS
     118             :  *  xSignatureTemplate - the signature template (along with all referenced
     119             :  *  elements) to be verified.
     120             :  *
     121             :  *   RESULT
     122             :  *  empty
     123             :  *
     124             :  *   AUTHOR
     125             :  *  Michael Mi
     126             :  *  Email: michael.mi@sun.com
     127             :  ******************************************************************************/
     128             : {
     129           0 :     cssu::Reference< cssxc::XXMLSignatureTemplate > xResultTemplate;
     130             :     try
     131             :     {
     132           0 :         xResultTemplate = m_xXMLSignature->validate(xSignatureTemplate, m_xXMLSecurityContext);
     133           0 :         m_nStatus = xResultTemplate->getStatus();
     134             :     }
     135           0 :     catch( cssu::Exception& )
     136             :     {
     137           0 :         m_nStatus = cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED;
     138           0 :     }
     139           0 : }
     140             : 
     141             : /* XSignatureVerifyResultBroadcaster */
     142           0 : void SAL_CALL SignatureVerifierImpl::addSignatureVerifyResultListener(
     143             :     const cssu::Reference< cssxc::sax::XSignatureVerifyResultListener >& listener )
     144             :     throw (cssu::Exception, cssu::RuntimeException, std::exception)
     145             : {
     146           0 :     m_xResultListener = listener;
     147           0 :     tryToPerform();
     148           0 : }
     149             : 
     150           0 : void SAL_CALL SignatureVerifierImpl::removeSignatureVerifyResultListener(
     151             :     const cssu::Reference< cssxc::sax::XSignatureVerifyResultListener >&)
     152             :     throw (cssu::RuntimeException, std::exception)
     153             : {
     154           0 : }
     155             : 
     156             : /* XInitialization */
     157           0 : void SAL_CALL SignatureVerifierImpl::initialize(
     158             :     const cssu::Sequence< cssu::Any >& aArguments )
     159             :     throw (cssu::Exception, cssu::RuntimeException, std::exception)
     160             : {
     161             :     OSL_ASSERT(aArguments.getLength() == 5);
     162             : 
     163           0 :     OUString ouTempString;
     164             : 
     165           0 :     aArguments[0] >>= ouTempString;
     166           0 :     m_nSecurityId = ouTempString.toInt32();
     167           0 :     aArguments[1] >>= m_xSAXEventKeeper;
     168           0 :     aArguments[2] >>= ouTempString;
     169           0 :     m_nIdOfTemplateEC = ouTempString.toInt32();
     170           0 :     aArguments[3] >>= m_xXMLSecurityContext;
     171           0 :     aArguments[4] >>= m_xXMLSignature;
     172           0 : }
     173             : 
     174             : 
     175           2 : OUString SignatureVerifierImpl_getImplementationName ()
     176             :     throw (cssu::RuntimeException)
     177             : {
     178           2 :     return OUString( IMPLEMENTATION_NAME );
     179             : }
     180             : 
     181           0 : cssu::Sequence< OUString > SAL_CALL SignatureVerifierImpl_getSupportedServiceNames(  )
     182             :     throw (cssu::RuntimeException)
     183             : {
     184           0 :     cssu::Sequence < OUString > aRet(1);
     185           0 :     OUString* pArray = aRet.getArray();
     186           0 :     pArray[0] =  OUString ( SERVICE_NAME );
     187           0 :     return aRet;
     188             : }
     189             : #undef SERVICE_NAME
     190             : 
     191           0 : cssu::Reference< cssu::XInterface > SAL_CALL SignatureVerifierImpl_createInstance(
     192             :     const cssu::Reference< cssl::XMultiServiceFactory >& rSMgr)
     193             :     throw( cssu::Exception )
     194             : {
     195           0 :     return (cppu::OWeakObject*) new SignatureVerifierImpl( comphelper::getComponentContext(rSMgr) );
     196             : }
     197             : 
     198             : /* XServiceInfo */
     199           0 : OUString SAL_CALL SignatureVerifierImpl::getImplementationName(  )
     200             :     throw (cssu::RuntimeException, std::exception)
     201             : {
     202           0 :     return SignatureVerifierImpl_getImplementationName();
     203             : }
     204             : 
     205           0 : sal_Bool SAL_CALL SignatureVerifierImpl::supportsService( const OUString& rServiceName )
     206             :     throw (cssu::RuntimeException, std::exception)
     207             : {
     208           0 :     return cppu::supportsService(this, rServiceName);
     209             : }
     210             : 
     211           0 : cssu::Sequence< OUString > SAL_CALL SignatureVerifierImpl::getSupportedServiceNames(  )
     212             :     throw (cssu::RuntimeException, std::exception)
     213             : {
     214           0 :     return SignatureVerifierImpl_getSupportedServiceNames();
     215             : }
     216             : 
     217             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10