LCOV - code coverage report
Current view: top level - xmlsecurity/source/framework - signatureverifierimpl.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 18 50 36.0 %
Date: 2015-06-13 12:38:46 Functions: 8 15 53.3 %
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             : #include <osl/diagnose.h>
      28             : 
      29             : namespace cssu = com::sun::star::uno;
      30             : namespace cssl = com::sun::star::lang;
      31             : namespace cssxc = com::sun::star::xml::crypto;
      32             : 
      33             : #define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.SignatureVerifierImpl"
      34             : 
      35           1 : SignatureVerifierImpl::SignatureVerifierImpl( const cssu::Reference< css::uno::XComponentContext >& xContext)
      36           1 :   : SignatureVerifierImpl_Base(xContext)
      37             : {
      38           1 : }
      39             : 
      40           2 : SignatureVerifierImpl::~SignatureVerifierImpl()
      41             : {
      42           2 : }
      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           8 : OUString SignatureVerifierImpl_getImplementationName ()
     176             :     throw (cssu::RuntimeException)
     177             : {
     178           8 :     return OUString( IMPLEMENTATION_NAME );
     179             : }
     180             : 
     181           2 : cssu::Sequence< OUString > SAL_CALL SignatureVerifierImpl_getSupportedServiceNames(  )
     182             :     throw (cssu::RuntimeException)
     183             : {
     184           2 :     cssu::Sequence < OUString > aRet(1);
     185           2 :     OUString* pArray = aRet.getArray();
     186           2 :     pArray[0] = "com.sun.star.xml.crypto.sax.SignatureVerifier";
     187           2 :     return aRet;
     188             : }
     189             : 
     190           1 : cssu::Reference< cssu::XInterface > SAL_CALL SignatureVerifierImpl_createInstance(
     191             :     const cssu::Reference< cssl::XMultiServiceFactory >& rSMgr)
     192             :     throw( cssu::Exception )
     193             : {
     194           1 :     return static_cast<cppu::OWeakObject*>(new SignatureVerifierImpl( comphelper::getComponentContext(rSMgr) ));
     195             : }
     196             : 
     197             : /* XServiceInfo */
     198           1 : OUString SAL_CALL SignatureVerifierImpl::getImplementationName(  )
     199             :     throw (cssu::RuntimeException, std::exception)
     200             : {
     201           1 :     return SignatureVerifierImpl_getImplementationName();
     202             : }
     203             : 
     204           0 : sal_Bool SAL_CALL SignatureVerifierImpl::supportsService( const OUString& rServiceName )
     205             :     throw (cssu::RuntimeException, std::exception)
     206             : {
     207           0 :     return cppu::supportsService(this, rServiceName);
     208             : }
     209             : 
     210           1 : cssu::Sequence< OUString > SAL_CALL SignatureVerifierImpl::getSupportedServiceNames(  )
     211             :     throw (cssu::RuntimeException, std::exception)
     212             : {
     213           1 :     return SignatureVerifierImpl_getSupportedServiceNames();
     214             : }
     215             : 
     216             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11