Files
libreoffice/xmlsecurity/source/dialogs/macrosecurity.cxx

442 lines
14 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
2004-07-16 05:28:08 +00:00
2004-07-16 05:28:08 +00:00
#include <xmlsecurity/macrosecurity.hxx>
2004-07-16 06:52:00 +00:00
#include <xmlsecurity/certificatechooser.hxx>
2004-07-16 05:28:08 +00:00
#include <xmlsecurity/certificateviewer.hxx>
2004-07-26 06:30:29 +00:00
#include <xmlsecurity/biginteger.hxx>
2004-07-26 11:13:29 +00:00
#include <osl/file.hxx>
#include <vcl/help.hxx>
#include <vcl/layout.hxx>
2004-07-26 11:13:29 +00:00
2004-07-16 05:28:08 +00:00
#include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp>
#include <com/sun/star/security/SerialNumberAdapter.hpp>
2004-07-16 05:28:08 +00:00
#include <comphelper/sequence.hxx>
2004-07-16 09:26:28 +00:00
#include <sfx2/filedlghelper.hxx>
#include <comphelper/processfactory.hxx>
#include <com/sun/star/uno/Exception.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/ui/dialogs/FolderPicker.hpp>
2004-07-16 09:26:28 +00:00
#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
#include <tools/urlobj.hxx>
#include <svtools/treelistentry.hxx>
2004-07-16 09:26:28 +00:00
2004-07-26 06:30:29 +00:00
#include <vcl/msgbox.hxx>
2004-07-16 05:28:08 +00:00
#include "dialogs.hrc"
#include "resourcemanager.hxx"
using namespace ::com::sun::star;
IMPL_LINK_NOARG(MacroSecurity, OkBtnHdl)
2004-07-20 14:43:12 +00:00
{
mpLevelTP->ClosePage();
mpTrustSrcTP->ClosePage();
2004-07-22 05:28:36 +00:00
EndDialog( RET_OK );
2004-07-20 14:43:12 +00:00
return 0;
}
MacroSecurity::MacroSecurity( vcl::Window* _pParent,
const css::uno::Reference< css::uno::XComponentContext> &_rxCtx,
const css::uno::Reference< css::xml::crypto::XSecurityEnvironment >& _rxSecurityEnvironment)
: TabDialog(_pParent, "MacroSecurityDialog", "xmlsec/ui/macrosecuritydialog.ui")
, mxCtx(_rxCtx)
, mxSecurityEnvironment(_rxSecurityEnvironment)
2004-07-16 05:28:08 +00:00
{
get(m_pTabCtrl, "tabcontrol");
get(m_pResetBtn, "reset");
get(m_pOkBtn, "ok");
2004-07-16 05:28:08 +00:00
mpLevelTP = new MacroSecurityLevelTP(m_pTabCtrl, this);
mpTrustSrcTP = new MacroSecurityTrustedSourcesTP(m_pTabCtrl, this);
2004-07-16 05:28:08 +00:00
m_nSecLevelId = m_pTabCtrl->GetPageId("SecurityLevelPage");
m_nSecTrustId = m_pTabCtrl->GetPageId("SecurityTrustPage");
2004-07-20 14:43:12 +00:00
m_pTabCtrl->SetTabPage(m_nSecLevelId, mpLevelTP);
m_pTabCtrl->SetTabPage(m_nSecTrustId, mpTrustSrcTP);
m_pTabCtrl->SetCurPageId(m_nSecLevelId);
2004-07-20 14:43:12 +00:00
m_pOkBtn->SetClickHdl( LINK( this, MacroSecurity, OkBtnHdl ) );
2004-07-16 05:28:08 +00:00
}
MacroSecurity::~MacroSecurity()
{
dispose();
}
void MacroSecurity::dispose()
2004-07-16 05:28:08 +00:00
{
delete m_pTabCtrl->GetTabPage(m_nSecTrustId);
delete m_pTabCtrl->GetTabPage(m_nSecLevelId);
TabDialog::dispose();
2004-07-16 05:28:08 +00:00
}
MacroSecurityTP::MacroSecurityTP(vcl::Window* _pParent, const OString& rID,
const OUString& rUIXMLDescription, MacroSecurity* _pDlg)
: TabPage(_pParent, rID, rUIXMLDescription)
, mpDlg(_pDlg)
{
}
2004-07-16 05:28:08 +00:00
MacroSecurityLevelTP::MacroSecurityLevelTP(vcl::Window* _pParent, MacroSecurity* _pDlg)
: MacroSecurityTP(_pParent, "SecurityLevelPage", "xmlsec/ui/securitylevelpage.ui", _pDlg)
2004-07-16 05:28:08 +00:00
{
get(m_pVeryHighRB, "vhigh");
get(m_pHighRB, "high");
get(m_pMediumRB, "med");
get(m_pLowRB, "low");
2004-08-04 05:13:56 +00:00
m_pLowRB->SetClickHdl( LINK( this, MacroSecurityLevelTP, RadioButtonHdl ) );
m_pMediumRB->SetClickHdl( LINK( this, MacroSecurityLevelTP, RadioButtonHdl ) );
m_pHighRB->SetClickHdl( LINK( this, MacroSecurityLevelTP, RadioButtonHdl ) );
m_pVeryHighRB->SetClickHdl( LINK( this, MacroSecurityLevelTP, RadioButtonHdl ) );
2004-08-04 05:13:56 +00:00
mnCurLevel = (sal_uInt16) mpDlg->maSecOptions.GetMacroSecurityLevel();
bool bReadonly = mpDlg->maSecOptions.IsReadOnly( SvtSecurityOptions::E_MACRO_SECLEVEL );
2004-08-04 05:13:56 +00:00
RadioButton* pCheck = 0;
FixedImage* pImage = 0;
switch (mnCurLevel)
2004-08-04 05:13:56 +00:00
{
case 3:
pCheck = m_pVeryHighRB;
pImage = get<FixedImage>("vhighimg");
break;
case 2:
pCheck = m_pHighRB;
pImage = get<FixedImage>("highimg");
break;
case 1:
pCheck = m_pMediumRB;
pImage = get<FixedImage>("medimg");
break;
case 0:
pCheck = m_pLowRB;
pImage = get<FixedImage>("lowimg");
break;
}
if (pCheck)
pCheck->Check();
else
{
2011-03-01 17:55:09 +01:00
OSL_FAIL("illegal macro security level");
}
if (bReadonly && pImage)
{
pImage->Show(true);
m_pVeryHighRB->Enable(false);
m_pHighRB->Enable(false);
m_pMediumRB->Enable(false);
m_pLowRB->Enable(false);
2004-08-04 05:13:56 +00:00
}
2004-07-16 05:28:08 +00:00
}
IMPL_LINK_NOARG(MacroSecurityLevelTP, RadioButtonHdl)
2004-07-16 05:28:08 +00:00
{
sal_uInt16 nNewLevel = 0;
if( m_pVeryHighRB->IsChecked() )
2004-08-04 05:13:56 +00:00
nNewLevel = 3;
else if( m_pHighRB->IsChecked() )
2004-08-04 05:13:56 +00:00
nNewLevel = 2;
else if( m_pMediumRB->IsChecked() )
2004-08-04 05:13:56 +00:00
nNewLevel = 1;
if ( nNewLevel != mnCurLevel )
{
mnCurLevel = nNewLevel;
mpDlg->EnableReset();
}
2004-07-20 14:43:12 +00:00
2004-08-04 05:13:56 +00:00
return 0;
2004-07-20 14:43:12 +00:00
}
void MacroSecurityLevelTP::ClosePage( void )
{
2004-08-04 05:13:56 +00:00
mpDlg->maSecOptions.SetMacroSecurityLevel( mnCurLevel );
2004-07-16 05:28:08 +00:00
}
2004-07-26 11:13:29 +00:00
void MacroSecurityTrustedSourcesTP::ImplCheckButtons()
2004-07-16 05:28:08 +00:00
{
bool bCertSelected = m_pTrustCertLB->FirstSelected() != NULL;
m_pViewCertPB->Enable( bCertSelected );
m_pRemoveCertPB->Enable( bCertSelected && !mbAuthorsReadonly);
2004-07-16 06:52:00 +00:00
bool bLocationSelected = m_pTrustFileLocLB->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND;
m_pRemoveLocPB->Enable( bLocationSelected && !mbURLsReadonly);
2004-07-26 11:13:29 +00:00
}
2004-07-16 06:52:00 +00:00
2004-07-16 05:28:08 +00:00
IMPL_LINK_NOARG(MacroSecurityTrustedSourcesTP, ViewCertPBHdl)
2004-07-16 05:28:08 +00:00
{
if( m_pTrustCertLB->FirstSelected() )
2004-07-16 06:52:00 +00:00
{
sal_uInt16 nSelected = sal_uInt16( sal_uIntPtr( m_pTrustCertLB->FirstSelected()->GetUserData() ) );
uno::Reference< css::security::XSerialNumberAdapter > xSerialNumberAdapter =
::com::sun::star::security::SerialNumberAdapter::create(mpDlg->mxCtx);
uno::Reference< css::security::XCertificate > xCert = mpDlg->mxSecurityEnvironment->getCertificate( maTrustedAuthors[nSelected][0], xSerialNumberAdapter->toSequence( maTrustedAuthors[nSelected][1] ) );
2004-07-16 06:52:00 +00:00
// If we don't get it, create it from signature data:
if ( !xCert.is() )
2004-07-26 11:13:29 +00:00
xCert = mpDlg->mxSecurityEnvironment->createCertificateFromAscii( maTrustedAuthors[nSelected][2] ) ;
2004-07-16 06:52:00 +00:00
DBG_ASSERT( xCert.is(), "*MacroSecurityTrustedSourcesTP::ViewCertPBHdl(): Certificate not found and can't be created!" );
2004-07-26 11:13:29 +00:00
if ( xCert.is() )
{
CertificateViewer aViewer( this, mpDlg->mxSecurityEnvironment, xCert, false );
2004-07-26 11:13:29 +00:00
aViewer.Execute();
}
2004-07-16 06:52:00 +00:00
}
2004-07-16 05:28:08 +00:00
return 0;
}
IMPL_LINK_NOARG(MacroSecurityTrustedSourcesTP, RemoveCertPBHdl)
2004-07-16 05:28:08 +00:00
{
if( m_pTrustCertLB->FirstSelected() )
2004-07-16 09:26:28 +00:00
{
sal_uInt16 nAuthor = sal_uInt16( sal_uIntPtr( m_pTrustCertLB->FirstSelected()->GetUserData() ) );
2004-07-28 08:12:09 +00:00
::comphelper::removeElementAt( maTrustedAuthors, nAuthor );
2004-07-16 09:26:28 +00:00
FillCertLB();
2004-07-26 11:13:29 +00:00
ImplCheckButtons();
2004-07-16 09:26:28 +00:00
}
2004-07-16 05:28:08 +00:00
return 0;
}
IMPL_LINK_NOARG(MacroSecurityTrustedSourcesTP, AddLocPBHdl)
2004-07-16 05:28:08 +00:00
{
2004-07-19 14:47:55 +00:00
try
{
uno::Reference < uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
uno::Reference < ui::dialogs::XFolderPicker2 > xFolderPicker = ui::dialogs::FolderPicker::create(xContext);
2004-07-16 09:26:28 +00:00
2004-07-19 14:47:55 +00:00
short nRet = xFolderPicker->execute();
2004-07-16 09:26:28 +00:00
2004-07-19 14:47:55 +00:00
if( ui::dialogs::ExecutableDialogResults::OK != nRet )
return 0;
2004-07-16 09:26:28 +00:00
OUString aPathStr = xFolderPicker->getDirectory();
2004-07-19 14:47:55 +00:00
INetURLObject aNewObj( aPathStr );
aNewObj.removeFinalSlash();
2004-07-16 09:26:28 +00:00
2004-07-19 14:47:55 +00:00
// then the new path also an URL else system path
OUString aSystemFileURL = ( aNewObj.GetProtocol() != INetProtocol::NotValid ) ?
aPathStr : aNewObj.getFSysPath( INetURLObject::FSYS_DETECT );
OUString aNewPathStr(aSystemFileURL);
2004-07-16 09:26:28 +00:00
2004-07-26 11:13:29 +00:00
if ( osl::FileBase::getSystemPathFromFileURL( aSystemFileURL, aSystemFileURL ) == osl::FileBase::E_None )
aNewPathStr = aSystemFileURL;
if( m_pTrustFileLocLB->GetEntryPos( aNewPathStr ) == LISTBOX_ENTRY_NOTFOUND )
2004-07-16 09:26:28 +00:00
{
m_pTrustFileLocLB->InsertEntry( aNewPathStr );
2004-07-16 09:26:28 +00:00
}
2004-07-26 11:13:29 +00:00
ImplCheckButtons();
2004-07-19 14:47:55 +00:00
}
catch( uno::Exception& )
{
SAL_WARN( "xmlsecurity.dialogs", "MacroSecurityTrustedSourcesTP::AddLocPBHdl(): exception from folder picker" );
2004-07-19 14:47:55 +00:00
}
2004-07-16 09:26:28 +00:00
2004-07-16 05:28:08 +00:00
return 0;
}
IMPL_LINK_NOARG(MacroSecurityTrustedSourcesTP, RemoveLocPBHdl)
2004-07-16 05:28:08 +00:00
{
sal_Int32 nSel = m_pTrustFileLocLB->GetSelectEntryPos();
2004-07-16 09:26:28 +00:00
if( nSel != LISTBOX_ENTRY_NOTFOUND )
{
m_pTrustFileLocLB->RemoveEntry( nSel );
// Trusted Path could not be removed (#i33584#)
// after remove an entry, select another one if exists
sal_Int32 nNewCount = m_pTrustFileLocLB->GetEntryCount();
if ( nNewCount > 0 )
{
if ( nSel >= nNewCount )
nSel = nNewCount - 1;
m_pTrustFileLocLB->SelectEntryPos( nSel );
}
2004-07-26 11:13:29 +00:00
ImplCheckButtons();
2004-07-16 09:26:28 +00:00
}
2004-07-16 05:28:08 +00:00
return 0;
}
IMPL_LINK_NOARG(MacroSecurityTrustedSourcesTP, TrustCertLBSelectHdl)
2004-07-16 06:52:00 +00:00
{
2004-07-26 11:13:29 +00:00
ImplCheckButtons();
2004-07-16 06:52:00 +00:00
return 0;
}
IMPL_LINK_NOARG(MacroSecurityTrustedSourcesTP, TrustFileLocLBSelectHdl)
2004-07-16 06:52:00 +00:00
{
2004-07-26 11:13:29 +00:00
ImplCheckButtons();
2004-07-16 06:52:00 +00:00
return 0;
}
void MacroSecurityTrustedSourcesTP::FillCertLB( void )
{
m_pTrustCertLB->Clear();
2004-07-16 06:52:00 +00:00
sal_uInt32 nEntries = maTrustedAuthors.getLength();
if ( nEntries && mpDlg->mxSecurityEnvironment.is() )
2004-07-20 14:43:12 +00:00
{
for( sal_uInt32 nEntry = 0 ; nEntry < nEntries ; ++nEntry )
{
css::uno::Sequence< OUString >& rEntry = maTrustedAuthors[ nEntry ];
uno::Reference< css::security::XCertificate > xCert;
2004-07-20 14:43:12 +00:00
// create from RawData
xCert = mpDlg->mxSecurityEnvironment->createCertificateFromAscii( rEntry[ 2 ] );
2004-07-20 14:43:12 +00:00
SvTreeListEntry* pLBEntry = m_pTrustCertLB->InsertEntry( XmlSec::GetContentPart( xCert->getSubjectName() ) );
m_pTrustCertLB->SetEntryText( XmlSec::GetContentPart( xCert->getIssuerName() ), pLBEntry, 1 );
m_pTrustCertLB->SetEntryText( XmlSec::GetDateTimeString( xCert->getNotValidAfter() ), pLBEntry, 2 );
pLBEntry->SetUserData( reinterpret_cast<void*>(nEntry) ); // missuse user data as index
}
2004-07-20 14:43:12 +00:00
}
2004-07-16 06:52:00 +00:00
}
class TrustCertLB : public SvSimpleTable
2004-07-16 05:28:08 +00:00
{
public:
TrustCertLB(SvSimpleTableContainer &rContainer)
: SvSimpleTable(rContainer, 0)
{
}
virtual void Resize() SAL_OVERRIDE
{
SvSimpleTable::Resize();
if (isInitialLayout(this))
{
const long nControlWidth = GetSizePixel().Width();
long aTabLocs[] = { 3, 0, 35*nControlWidth/100, 70*nControlWidth/100 };
SvSimpleTable::SetTabs(aTabLocs, MAP_PIXEL);
}
}
};
2004-07-22 12:41:57 +00:00
MacroSecurityTrustedSourcesTP::MacroSecurityTrustedSourcesTP(vcl::Window* _pParent, MacroSecurity* _pDlg)
: MacroSecurityTP(_pParent, "SecurityTrustPage", "xmlsec/ui/securitytrustpage.ui", _pDlg)
{
get(m_pTrustCertROFI, "lockcertimg");
get(m_pViewCertPB, "viewcert");
get(m_pRemoveCertPB, "removecert");
get(m_pTrustFileROFI, "lockfileimg");
get(m_pTrustFileLocLB, "locations");
m_pTrustFileLocLB->SetDropDownLineCount(6);
get(m_pAddLocPB, "addfile");
get(m_pRemoveLocPB, "removefile");
SvSimpleTableContainer *pCertificates = get<SvSimpleTableContainer>("certificates");
m_pTrustCertLB = new TrustCertLB(*pCertificates);
static long aTabs[] = { 3, 0, 0, 0 };
m_pTrustCertLB->SetTabs( aTabs );
m_pTrustCertLB->InsertHeaderEntry(get<FixedText>("to")->GetText() + "\t"
+ get<FixedText>("by")->GetText() + "\t" + get<FixedText>("date")->GetText());
m_pTrustCertLB->SetSelectHdl( LINK( this, MacroSecurityTrustedSourcesTP, TrustCertLBSelectHdl ) );
m_pViewCertPB->SetClickHdl( LINK( this, MacroSecurityTrustedSourcesTP, ViewCertPBHdl ) );
m_pViewCertPB->Disable();
m_pRemoveCertPB->SetClickHdl( LINK( this, MacroSecurityTrustedSourcesTP, RemoveCertPBHdl ) );
m_pRemoveCertPB->Disable();
m_pTrustFileLocLB->SetSelectHdl( LINK( this, MacroSecurityTrustedSourcesTP, TrustFileLocLBSelectHdl ) );
m_pAddLocPB->SetClickHdl( LINK( this, MacroSecurityTrustedSourcesTP, AddLocPBHdl ) );
m_pRemoveLocPB->SetClickHdl( LINK( this, MacroSecurityTrustedSourcesTP, RemoveLocPBHdl ) );
m_pRemoveLocPB->Disable();
2004-07-22 12:41:57 +00:00
2004-07-26 11:13:29 +00:00
maTrustedAuthors = mpDlg->maSecOptions.GetTrustedAuthors();
mbAuthorsReadonly = mpDlg->maSecOptions.IsReadOnly( SvtSecurityOptions::E_MACRO_TRUSTEDAUTHORS );
m_pTrustCertROFI->Show( mbAuthorsReadonly );
mbAuthorsReadonly ? m_pTrustCertLB->DisableTable() : m_pTrustCertLB->EnableTable();
2004-07-26 11:13:29 +00:00
FillCertLB();
css::uno::Sequence< OUString > aSecureURLs = mpDlg->maSecOptions.GetSecureURLs();
mbURLsReadonly = mpDlg->maSecOptions.IsReadOnly( SvtSecurityOptions::E_SECUREURLS );
m_pTrustFileROFI->Show( mbURLsReadonly );
m_pTrustFileLocLB->Enable( !mbURLsReadonly );
m_pAddLocPB->Enable( !mbURLsReadonly );
2004-07-26 11:13:29 +00:00
sal_Int32 nEntryCnt = aSecureURLs.getLength();
2004-07-22 12:41:57 +00:00
for( sal_Int32 i = 0 ; i < nEntryCnt ; ++i )
2004-07-26 11:13:29 +00:00
{
OUString aSystemFileURL( aSecureURLs[ i ] );
2004-07-26 11:13:29 +00:00
osl::FileBase::getSystemPathFromFileURL( aSystemFileURL, aSystemFileURL );
m_pTrustFileLocLB->InsertEntry( aSystemFileURL );
2004-07-26 11:13:29 +00:00
}
2004-07-16 05:28:08 +00:00
}
MacroSecurityTrustedSourcesTP::~MacroSecurityTrustedSourcesTP()
{
dispose();
}
void MacroSecurityTrustedSourcesTP::dispose()
{
delete m_pTrustCertLB;
MacroSecurityTP::dispose();
}
2004-07-16 05:28:08 +00:00
void MacroSecurityTrustedSourcesTP::ActivatePage()
{
2004-07-16 09:26:28 +00:00
mpDlg->EnableReset( false );
2004-07-20 14:43:12 +00:00
FillCertLB();
}
void MacroSecurityTrustedSourcesTP::ClosePage( void )
{
sal_Int32 nEntryCnt = m_pTrustFileLocLB->GetEntryCount();
2004-07-22 12:41:57 +00:00
if( nEntryCnt )
{
css::uno::Sequence< OUString > aSecureURLs( nEntryCnt );
for( sal_Int32 i = 0 ; i < nEntryCnt ; ++i )
2004-07-26 11:13:29 +00:00
{
OUString aURL( m_pTrustFileLocLB->GetEntry( i ) );
2004-07-26 11:13:29 +00:00
osl::FileBase::getFileURLFromSystemPath( aURL, aURL );
aSecureURLs[ i ] = aURL;
}
2004-07-22 12:41:57 +00:00
mpDlg->maSecOptions.SetSecureURLs( aSecureURLs );
}
// Trusted Path could not be removed (#i33584#)
// don't forget to remove the old saved SecureURLs
else
mpDlg->maSecOptions.SetSecureURLs( css::uno::Sequence< OUString >() );
2004-07-22 12:41:57 +00:00
2004-07-20 14:43:12 +00:00
mpDlg->maSecOptions.SetTrustedAuthors( maTrustedAuthors );
2004-07-16 05:28:08 +00:00
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */