LCOV - code coverage report
Current view: top level - libreoffice/xmlsecurity/source/framework - signatureverifierimpl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 52 0.0 %
Date: 2012-12-27 Functions: 0 16 0.0 %
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             : 
      26             : namespace cssu = com::sun::star::uno;
      27             : namespace cssl = com::sun::star::lang;
      28             : namespace cssxc = com::sun::star::xml::crypto;
      29             : 
      30             : #define SERVICE_NAME "com.sun.star.xml.crypto.sax.SignatureVerifier"
      31             : #define IMPLEMENTATION_NAME "com.sun.star.xml.security.framework.SignatureVerifierImpl"
      32             : 
      33           0 : SignatureVerifierImpl::SignatureVerifierImpl( const cssu::Reference< cssl::XMultiServiceFactory >& rxMSF)
      34             : {
      35           0 :     mxMSF = rxMSF;
      36           0 : }
      37             : 
      38           0 : SignatureVerifierImpl::~SignatureVerifierImpl()
      39             : {
      40           0 : }
      41             : 
      42           0 : bool SignatureVerifierImpl::checkReady() const
      43             : /****** SignatureVerifierImpl/checkReady *************************************
      44             :  *
      45             :  *   NAME
      46             :  *  checkReady -- checks the conditions for the signature verification.
      47             :  *
      48             :  *   SYNOPSIS
      49             :  *  bReady = checkReady( );
      50             :  *
      51             :  *   FUNCTION
      52             :  *  checks whether all following conditions are satisfied:
      53             :  *  1. the result listener is ready;
      54             :  *  2. the SignatureEngine is ready.
      55             :  *
      56             :  *   INPUTS
      57             :  *  empty
      58             :  *
      59             :  *   RESULT
      60             :  *  bReady - true if all conditions are satisfied, false otherwise
      61             :  *
      62             :  *   AUTHOR
      63             :  *  Michael Mi
      64             :  *  Email: michael.mi@sun.com
      65             :  ******************************************************************************/
      66             : {
      67           0 :     return (m_xResultListener.is() && SignatureEngine::checkReady());
      68             : }
      69             : 
      70           0 : void SignatureVerifierImpl::notifyResultListener() const
      71             :     throw (cssu::Exception, cssu::RuntimeException)
      72             : /****** SignatureVerifierImpl/notifyResultListener ***************************
      73             :  *
      74             :  *   NAME
      75             :  *  notifyResultListener -- notifies the listener about the verify result.
      76             :  *
      77             :  *   SYNOPSIS
      78             :  *  notifyResultListener( );
      79             :  *
      80             :  *   FUNCTION
      81             :  *  see NAME.
      82             :  *
      83             :  *   INPUTS
      84             :  *  empty
      85             :  *
      86             :  *   RESULT
      87             :  *  empty
      88             :  *
      89             :  *   AUTHOR
      90             :  *  Michael Mi
      91             :  *  Email: michael.mi@sun.com
      92             :  ******************************************************************************/
      93             : {
      94             :     cssu::Reference< cssxc::sax::XSignatureVerifyResultListener >
      95           0 :         xSignatureVerifyResultListener ( m_xResultListener , cssu::UNO_QUERY ) ;
      96             : 
      97           0 :     xSignatureVerifyResultListener->signatureVerified( m_nSecurityId, m_nStatus );
      98           0 : }
      99             : 
     100           0 : void SignatureVerifierImpl::startEngine( const cssu::Reference<
     101             :     cssxc::XXMLSignatureTemplate >&
     102             :     xSignatureTemplate)
     103             :     throw (cssu::Exception, cssu::RuntimeException)
     104             : /****** SignatureVerifierImpl/startEngine ************************************
     105             :  *
     106             :  *   NAME
     107             :  *  startEngine -- verifies the signature.
     108             :  *
     109             :  *   SYNOPSIS
     110             :  *  startEngine( xSignatureTemplate );
     111             :  *
     112             :  *   FUNCTION
     113             :  *  see NAME.
     114             :  *
     115             :  *   INPUTS
     116             :  *  xSignatureTemplate - the signature template (along with all referenced
     117             :  *  elements) to be verified.
     118             :  *
     119             :  *   RESULT
     120             :  *  empty
     121             :  *
     122             :  *   AUTHOR
     123             :  *  Michael Mi
     124             :  *  Email: michael.mi@sun.com
     125             :  ******************************************************************************/
     126             : {
     127           0 :     cssu::Reference< cssxc::XXMLSignatureTemplate > xResultTemplate;
     128             :     try
     129             :     {
     130           0 :         xResultTemplate = m_xXMLSignature->validate(xSignatureTemplate, m_xXMLSecurityContext);
     131           0 :         m_nStatus = xResultTemplate->getStatus();
     132             :     }
     133           0 :     catch( cssu::Exception& )
     134             :     {
     135           0 :         m_nStatus = cssxc::SecurityOperationStatus_RUNTIMEERROR_FAILED;
     136           0 :     }
     137           0 : }
     138             : 
     139             : /* XSignatureVerifyResultBroadcaster */
     140           0 : void SAL_CALL SignatureVerifierImpl::addSignatureVerifyResultListener(
     141             :     const cssu::Reference< cssxc::sax::XSignatureVerifyResultListener >& listener )
     142             :     throw (cssu::Exception, cssu::RuntimeException)
     143             : {
     144           0 :     m_xResultListener = listener;
     145           0 :     tryToPerform();
     146           0 : }
     147             : 
     148           0 : void SAL_CALL SignatureVerifierImpl::removeSignatureVerifyResultListener(
     149             :     const cssu::Reference< cssxc::sax::XSignatureVerifyResultListener >&)
     150             :     throw (cssu::RuntimeException)
     151             : {
     152           0 : }
     153             : 
     154             : /* XInitialization */
     155           0 : void SAL_CALL SignatureVerifierImpl::initialize(
     156             :     const cssu::Sequence< cssu::Any >& aArguments )
     157             :     throw (cssu::Exception, cssu::RuntimeException)
     158             : {
     159             :     OSL_ASSERT(aArguments.getLength() == 5);
     160             : 
     161           0 :     rtl::OUString ouTempString;
     162             : 
     163           0 :     aArguments[0] >>= ouTempString;
     164           0 :     m_nSecurityId = ouTempString.toInt32();
     165           0 :     aArguments[1] >>= m_xSAXEventKeeper;
     166           0 :     aArguments[2] >>= ouTempString;
     167           0 :     m_nIdOfTemplateEC = ouTempString.toInt32();
     168           0 :     aArguments[3] >>= m_xXMLSecurityContext;
     169           0 :     aArguments[4] >>= m_xXMLSignature;
     170           0 : }
     171             : 
     172             : 
     173           0 : rtl::OUString SignatureVerifierImpl_getImplementationName ()
     174             :     throw (cssu::RuntimeException)
     175             : {
     176             :     return rtl::OUString(
     177           0 :         RTL_CONSTASCII_USTRINGPARAM ( IMPLEMENTATION_NAME ) );
     178             : }
     179             : 
     180           0 : sal_Bool SAL_CALL SignatureVerifierImpl_supportsService( const rtl::OUString& ServiceName )
     181             :     throw (cssu::RuntimeException)
     182             : {
     183           0 :     return ServiceName == SERVICE_NAME;
     184             : }
     185             : 
     186           0 : cssu::Sequence< rtl::OUString > SAL_CALL SignatureVerifierImpl_getSupportedServiceNames(  )
     187             :     throw (cssu::RuntimeException)
     188             : {
     189           0 :     cssu::Sequence < rtl::OUString > aRet(1);
     190           0 :     rtl::OUString* pArray = aRet.getArray();
     191           0 :     pArray[0] =  rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
     192           0 :     return aRet;
     193             : }
     194             : #undef SERVICE_NAME
     195             : 
     196           0 : cssu::Reference< cssu::XInterface > SAL_CALL SignatureVerifierImpl_createInstance(
     197             :     const cssu::Reference< cssl::XMultiServiceFactory >& rSMgr)
     198             :     throw( cssu::Exception )
     199             : {
     200           0 :     return (cppu::OWeakObject*) new SignatureVerifierImpl(rSMgr);
     201             : }
     202             : 
     203             : /* XServiceInfo */
     204           0 : rtl::OUString SAL_CALL SignatureVerifierImpl::getImplementationName(  )
     205             :     throw (cssu::RuntimeException)
     206             : {
     207           0 :     return SignatureVerifierImpl_getImplementationName();
     208             : }
     209           0 : sal_Bool SAL_CALL SignatureVerifierImpl::supportsService( const rtl::OUString& rServiceName )
     210             :     throw (cssu::RuntimeException)
     211             : {
     212           0 :     return SignatureVerifierImpl_supportsService( rServiceName );
     213             : }
     214           0 : cssu::Sequence< rtl::OUString > SAL_CALL SignatureVerifierImpl::getSupportedServiceNames(  )
     215             :     throw (cssu::RuntimeException)
     216             : {
     217           0 :     return SignatureVerifierImpl_getSupportedServiceNames();
     218             : }
     219             : 
     220             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10