LCOV - code coverage report
Current view: top level - uui/source - secmacrowarnings.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 124 0.8 %
Date: 2015-06-13 12:38:46 Functions: 2 19 10.5 %
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             : #include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp>
      21             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      22             : #include <com/sun/star/security/DocumentDigitalSignatures.hpp>
      23             : #include <comphelper/sequence.hxx>
      24             : #include <comphelper/documentconstants.hxx>
      25             : #include <comphelper/processfactory.hxx>
      26             : #include <sal/macros.h>
      27             : 
      28             : #include <vcl/msgbox.hxx>
      29             : #include <com/sun/star/security/NoPasswordException.hpp>
      30             : 
      31             : using namespace ::com::sun::star::security;
      32             : 
      33             : #include "ids.hrc"
      34             : #include "secmacrowarnings.hxx"
      35             : 
      36             : using namespace ::com::sun::star;
      37             : 
      38             : 
      39             : // HACK!!! copied from xmlsecurity/source/dialog/resourcemanager.cxx
      40             : 
      41             : namespace
      42             : {
      43           0 :     OUString GetContentPart( const OUString& _rRawString, const OUString& _rPartId )
      44             :     {
      45           0 :         OUString      s;
      46             : 
      47           0 :         sal_Int32  nContStart = _rRawString.indexOf( _rPartId );
      48           0 :         if( nContStart != -1 )
      49             :         {
      50           0 :             nContStart = nContStart + _rPartId.getLength();
      51           0 :             ++nContStart;                   // now its start of content, directly after Id
      52             : 
      53           0 :             sal_Int32  nContEnd = _rRawString.indexOf( ',', nContStart );
      54             : 
      55           0 :             if ( nContEnd != -1 )
      56           0 :                 s = _rRawString.copy( nContStart, nContEnd - nContStart );
      57             :             else
      58           0 :                 s = _rRawString.copy( nContStart );
      59             :         }
      60             : 
      61           0 :         return s;
      62             :     }
      63             : }
      64             : 
      65             : 
      66           0 : MacroWarning::MacroWarning( vcl::Window* _pParent, bool _bWithSignatures, ResMgr& )
      67             :     :ModalDialog            ( _pParent, "MacroWarnMedium", "uui/ui/macrowarnmedium.ui" )
      68             :     ,mpInfos                ( NULL )
      69             :     ,mbSignedMode           ( true )
      70             :     ,mbShowSignatures       ( _bWithSignatures )
      71           0 :     ,mnActSecLevel          ( 0 )
      72             : {
      73           0 :     get(mpSymbolImg, "symbolImage");
      74           0 :     get(mpDocNameFI, "docNameLabel");
      75           0 :     get(mpDescr1FI, "descr1Label");
      76           0 :     get(mpDescr1aFI, "descr1aLabel");
      77           0 :     get(mpSignsFI, "signsLabel");
      78           0 :     get(mpViewSignsBtn, "viewSignsButton");
      79           0 :     get(mpDescr2FI, "descr2Label");
      80           0 :     get(mpAlwaysTrustCB, "alwaysTrustCheckbutton");
      81           0 :     get(mpEnableBtn, "ok");
      82           0 :     get(mpDisableBtn, "cancel");
      83             : 
      84           0 :     InitControls();
      85             : 
      86           0 :     mpDisableBtn->SetClickHdl( LINK( this, MacroWarning, DisableBtnHdl ) );
      87           0 :     mpEnableBtn->SetClickHdl( LINK( this, MacroWarning, EnableBtnHdl ) );
      88           0 :     mpDisableBtn->GrabFocus(); // Default button, but focus is on view button
      89           0 : }
      90             : 
      91           0 : MacroWarning::~MacroWarning()
      92             : {
      93           0 :     disposeOnce();
      94           0 : }
      95             : 
      96           0 : void MacroWarning::dispose()
      97             : {
      98           0 :     mpSymbolImg.clear();
      99           0 :     mpDocNameFI.clear();
     100           0 :     mpDescr1aFI.clear();
     101           0 :     mpDescr1FI.clear();
     102           0 :     mpSignsFI.clear();
     103           0 :     mpViewSignsBtn.clear();
     104           0 :     mpDescr2FI.clear();
     105           0 :     mpAlwaysTrustCB.clear();
     106           0 :     mpEnableBtn.clear();
     107           0 :     mpDisableBtn.clear();
     108           0 :     ModalDialog::dispose();
     109           0 : }
     110             : 
     111           0 : void MacroWarning::SetDocumentURL( const OUString& rDocURL )
     112             : {
     113           0 :     mpDocNameFI->SetText( rDocURL );
     114           0 : }
     115             : 
     116           0 : IMPL_LINK_NOARG(MacroWarning, ViewSignsBtnHdl)
     117             : {
     118             :     DBG_ASSERT( mxCert.is(), "*MacroWarning::ViewSignsBtnHdl(): no certificate set!" );
     119             : 
     120             :     uno::Reference< security::XDocumentDigitalSignatures > xD(
     121           0 :         security::DocumentDigitalSignatures::createWithVersion(comphelper::getProcessComponentContext(), maODFVersion));
     122           0 :     if( xD.is() )
     123             :     {
     124           0 :         if( mxCert.is() )
     125           0 :             xD->showCertificate( mxCert );
     126           0 :         else if( mxStore.is() )
     127           0 :             xD->showScriptingContentSignatures( mxStore, uno::Reference< io::XInputStream >() );
     128             :     }
     129             : 
     130           0 :     return 0;
     131             : }
     132             : 
     133           0 : IMPL_LINK_NOARG(MacroWarning, EnableBtnHdl)
     134             : {
     135           0 :     if( mbSignedMode && mpAlwaysTrustCB->IsChecked() )
     136             :     {   // insert path into trusted path list
     137             :         uno::Reference< security::XDocumentDigitalSignatures > xD(
     138           0 :             security::DocumentDigitalSignatures::createWithVersion(comphelper::getProcessComponentContext(), maODFVersion));
     139           0 :         if( mxCert.is() )
     140           0 :             xD->addAuthorToTrustedSources( mxCert );
     141           0 :         else if( mxStore.is() )
     142             :         {
     143             :             DBG_ASSERT( mpInfos, "-MacroWarning::EnableBtnHdl(): no infos, search in nirvana..." );
     144             : 
     145           0 :             sal_Int32   nCnt = mpInfos->getLength();
     146           0 :             for( sal_Int32 i = 0 ; i < nCnt ; ++i )
     147           0 :                 xD->addAuthorToTrustedSources( (*mpInfos)[ i ].Signer );
     148           0 :         }
     149             :     }
     150             : 
     151           0 :     EndDialog( RET_OK );
     152           0 :     return 0;
     153             : }
     154             : 
     155           0 : IMPL_LINK_NOARG(MacroWarning, DisableBtnHdl)
     156             : {
     157           0 :     EndDialog( RET_CANCEL );
     158           0 :     return 0;
     159             : }
     160             : 
     161           0 : IMPL_LINK_NOARG(MacroWarning, AlwaysTrustCheckHdl)
     162             : {
     163           0 :     bool bEnable = ( mnActSecLevel < 2 || mpAlwaysTrustCB->IsChecked() );
     164           0 :     mpEnableBtn->Enable( bEnable );
     165           0 :     mpDisableBtn->Enable( !mpAlwaysTrustCB->IsChecked() );
     166             : 
     167           0 :     return 0;
     168             : }
     169             : 
     170           0 : void MacroWarning::InitControls()
     171             : {
     172             :     // set warning image
     173           0 :     Image aImg( WarningBox::GetStandardImage() );
     174           0 :     mpSymbolImg->SetImage( aImg );
     175           0 :     mpSymbolImg->SetSizePixel( aImg.GetSizePixel() );
     176             :     // set bold font and path ellipsis for docname fixedtext
     177           0 :     vcl::Font aTmpFont = mpDocNameFI->GetControlFont();
     178           0 :     aTmpFont.SetWeight( WEIGHT_BOLD );
     179           0 :     mpDocNameFI->SetControlFont( aTmpFont );
     180           0 :     WinBits nStyle = mpDocNameFI->GetStyle();
     181           0 :     nStyle |= WB_PATHELLIPSIS;
     182           0 :     mpDocNameFI->SetStyle( nStyle );
     183             :     // show signature controls?
     184           0 :     if( mbShowSignatures )
     185             :     {
     186           0 :         mpViewSignsBtn->SetClickHdl( LINK( this, MacroWarning, ViewSignsBtnHdl ) );
     187           0 :         mpViewSignsBtn->Disable();   // default
     188           0 :         mpAlwaysTrustCB->SetClickHdl( LINK( this, MacroWarning, AlwaysTrustCheckHdl ) );
     189             : 
     190           0 :         mnActSecLevel = SvtSecurityOptions().GetMacroSecurityLevel();
     191           0 :         if ( mnActSecLevel >= 2 )
     192           0 :             mpEnableBtn->Disable();
     193             :     }
     194             :     else
     195             :     {
     196           0 :         mpDescr1FI->Hide();
     197           0 :         mpDescr1aFI->Show();
     198           0 :         mpSignsFI->Hide();
     199           0 :         mpViewSignsBtn->Hide();
     200           0 :         mpAlwaysTrustCB->Hide();
     201             : 
     202             :         // move hint up to position of signer list
     203           0 :         mpDescr2FI->SetPosPixel( mpSignsFI->GetPosPixel() );
     204           0 :     }
     205           0 : }
     206             : 
     207           0 : void MacroWarning::SetStorage( const css::uno::Reference < css::embed::XStorage >& rxStore,
     208             :                                const OUString& aODFVersion,
     209             :                                const css::uno::Sequence< security::DocumentSignatureInformation >& rInfos )
     210             : {
     211           0 :     mxStore = rxStore;
     212           0 :     maODFVersion = aODFVersion;
     213           0 :     sal_Int32   nCnt = rInfos.getLength();
     214           0 :     if( mxStore.is() && nCnt > 0 )
     215             :     {
     216           0 :         mpInfos = &rInfos;
     217           0 :         OUString aCN_Id("CN");
     218           0 :         OUString s;
     219           0 :         s = GetContentPart( rInfos[ 0 ].Signer->getSubjectName(), aCN_Id );
     220             : 
     221           0 :         for( sal_Int32 i = 1 ; i < nCnt ; ++i )
     222             :         {
     223           0 :             s += "\n";
     224           0 :             s += GetContentPart( rInfos[ i ].Signer->getSubjectName(), aCN_Id );
     225             :         }
     226             : 
     227           0 :         mpSignsFI->SetText( s );
     228           0 :         mpViewSignsBtn->Enable();
     229             :     }
     230           0 : }
     231             : 
     232           0 : void MacroWarning::SetCertificate( const css::uno::Reference< css::security::XCertificate >& _rxCert )
     233             : {
     234           0 :     mxCert = _rxCert;
     235           0 :     if( mxCert.is() )
     236             :     {
     237           0 :         OUString aCN_Id("CN");
     238           0 :         OUString s;
     239           0 :         s = GetContentPart( mxCert->getSubjectName(), aCN_Id );
     240           0 :         mpSignsFI->SetText( s );
     241           0 :         mpViewSignsBtn->Enable();
     242             :     }
     243         159 : }
     244             : 
     245             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11