diff options
Diffstat (limited to 'xmlsecurity/source/dialogs')
17 files changed, 4468 insertions, 0 deletions
diff --git a/xmlsecurity/source/dialogs/certificatechooser.cxx b/xmlsecurity/source/dialogs/certificatechooser.cxx new file mode 100644 index 000000000000..5a34945c639b --- /dev/null +++ b/xmlsecurity/source/dialogs/certificatechooser.cxx @@ -0,0 +1,238 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmlsecurity.hxx" + +#include <xmlsecurity/certificatechooser.hxx> +#include <xmlsecurity/certificateviewer.hxx> +#include <xmlsecurity/biginteger.hxx> +#include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp> +#include <comphelper/sequence.hxx> +#include <comphelper/processfactory.hxx> + +#include <com/sun/star/security/NoPasswordException.hpp> +#include <com/sun/star/security/CertificateCharacters.hpp> +#include <com/sun/star/security/SerialNumberAdapter.hpp> + +#include <dialogs.hrc> +#include <resourcemanager.hxx> +#include <vcl/msgbox.hxx> + +/* HACK: disable some warnings for MS-C */ +#ifdef _MSC_VER +#pragma warning (disable : 4355) // 4355: this used in initializer-list +#endif + +using namespace ::com::sun::star; + +#define INVAL_SEL 0xFFFF + +USHORT CertificateChooser::GetSelectedEntryPos( void ) const +{ + USHORT nSel = INVAL_SEL; + + SvLBoxEntry* pSel = maCertLB.FirstSelected(); + if( pSel ) + nSel = (USHORT) ( sal_uIntPtr ) pSel->GetUserData(); + + return (USHORT) nSel; +} + +CertificateChooser::CertificateChooser( Window* _pParent, uno::Reference< uno::XComponentContext>& _rxCtx, uno::Reference< dcss::xml::crypto::XSecurityEnvironment >& _rxSecurityEnvironment, const SignatureInformations& _rCertsToIgnore ) + :ModalDialog ( _pParent, XMLSEC_RES( RID_XMLSECDLG_CERTCHOOSER ) ) + ,maCertsToIgnore( _rCertsToIgnore ) + ,maHintFT ( this, XMLSEC_RES( FT_HINT_SELECT ) ) + ,maCertLB ( this, XMLSEC_RES( LB_SIGNATURES ) ) + ,maViewBtn ( this, XMLSEC_RES( BTN_VIEWCERT ) ) + ,maBottomSepFL ( this, XMLSEC_RES( FL_BOTTOM_SEP ) ) + ,maOKBtn ( this, XMLSEC_RES( BTN_OK ) ) + ,maCancelBtn ( this, XMLSEC_RES( BTN_CANCEL ) ) + ,maHelpBtn ( this, XMLSEC_RES( BTN_HELP ) ) +{ + static long nTabs[] = { 3, 0, 30*CS_LB_WIDTH/100, 60*CS_LB_WIDTH/100 }; + maCertLB.SetTabs( &nTabs[0] ); + maCertLB.InsertHeaderEntry( String( XMLSEC_RES( STR_HEADERBAR ) ) ); + maCertLB.SetSelectHdl( LINK( this, CertificateChooser, CertificateHighlightHdl ) ); + maCertLB.SetDoubleClickHdl( LINK( this, CertificateChooser, CertificateSelectHdl ) ); + maViewBtn.SetClickHdl( LINK( this, CertificateChooser, ViewButtonHdl ) ); + + FreeResource(); + + mxCtx = _rxCtx; + mxSecurityEnvironment = _rxSecurityEnvironment; + mbInitialized = FALSE; + + // disable buttons + CertificateHighlightHdl( NULL ); +} + +CertificateChooser::~CertificateChooser() +{ +} + +short CertificateChooser::Execute() +{ + // #i48432# + // We can't check for personal certificates before raising this dialog, + // because the mozilla implementation throws a NoPassword exception, + // if the user pressed cancel, and also if the database does not exist! + // But in the later case, the is no password query, and the user is confused + // that nothing happens when pressing "Add..." in the SignatureDialog. + + // PostUserEvent( LINK( this, CertificateChooser, Initialize ) ); + + // PostUserLink behavior is to slow, so do it directly before Execute(). + // Problem: This Dialog should be visible right now, and the parent should not be accessible. + // Show, Update, DIsableInput... + + Window* pMe = this; + Window* pParent = GetParent(); + if ( pParent ) + pParent->EnableInput( FALSE ); + pMe->Show(); + pMe->Update(); + ImplInitialize(); + if ( pParent ) + pParent->EnableInput( TRUE ); + return ModalDialog::Execute(); +} + +// IMPL_LINK( CertificateChooser, Initialize, void*, EMPTYARG ) +void CertificateChooser::ImplInitialize() +{ + if ( !mbInitialized ) + { + try + { + maCerts = mxSecurityEnvironment->getPersonalCertificates(); + } + catch (security::NoPasswordException&) + { + } + + uno::Reference< dcss::security::XSerialNumberAdapter> xSerialNumberAdapter = + ::com::sun::star::security::SerialNumberAdapter::create(mxCtx); + + sal_Int32 nCertificates = maCerts.getLength(); + sal_Int32 nCertificatesToIgnore = maCertsToIgnore.size(); + for( sal_Int32 nCert = nCertificates; nCert; ) + { + uno::Reference< security::XCertificate > xCert = maCerts[ --nCert ]; + sal_Bool bIgnoreThis = false; + + // Do we already use that? + if( nCertificatesToIgnore ) + { + rtl::OUString aIssuerName = xCert->getIssuerName(); + for( sal_Int32 nSig = 0; nSig < nCertificatesToIgnore; ++nSig ) + { + const SignatureInformation& rInf = maCertsToIgnore[ nSig ]; + if ( ( aIssuerName == rInf.ouX509IssuerName ) && + ( xSerialNumberAdapter->toString( xCert->getSerialNumber() ) == rInf.ouX509SerialNumber ) ) + { + bIgnoreThis = true; + break; + } + } + } + + if ( !bIgnoreThis ) + { + // Check if we have a private key for this... + long nCertificateCharacters = mxSecurityEnvironment->getCertificateCharacters( xCert ); + + if ( !( nCertificateCharacters & security::CertificateCharacters::HAS_PRIVATE_KEY ) ) + bIgnoreThis = true; + + } + + if ( bIgnoreThis ) + { + ::comphelper::removeElementAt( maCerts, nCert ); + nCertificates = maCerts.getLength(); + } + } + + // fill list of certificates; the first entry will be selected + for ( sal_Int32 nC = 0; nC < nCertificates; ++nC ) + { + String sEntry( XmlSec::GetContentPart( maCerts[ nC ]->getSubjectName() ) ); + sEntry += '\t'; + sEntry += XmlSec::GetContentPart( maCerts[ nC ]->getIssuerName() ); + sEntry += '\t'; + sEntry += XmlSec::GetDateString( maCerts[ nC ]->getNotValidAfter() ); + SvLBoxEntry* pEntry = maCertLB.InsertEntry( sEntry ); + pEntry->SetUserData( ( void* )nC ); // missuse user data as index + } + + // enable/disable buttons + CertificateHighlightHdl( NULL ); + mbInitialized = TRUE; + } +} + + +uno::Reference< dcss::security::XCertificate > CertificateChooser::GetSelectedCertificate() +{ + uno::Reference< dcss::security::XCertificate > xCert; + USHORT nSelected = GetSelectedEntryPos(); + if ( nSelected < maCerts.getLength() ) + xCert = maCerts[ nSelected ]; + return xCert; +} + +IMPL_LINK( CertificateChooser, CertificateHighlightHdl, void*, EMPTYARG ) +{ + sal_Bool bEnable = GetSelectedCertificate().is(); + maViewBtn.Enable( bEnable ); + maOKBtn.Enable( bEnable ); + return 0; +} + +IMPL_LINK( CertificateChooser, CertificateSelectHdl, void*, EMPTYARG ) +{ + EndDialog( RET_OK ); + return 0; +} + +IMPL_LINK( CertificateChooser, ViewButtonHdl, Button*, EMPTYARG ) +{ + ImplShowCertificateDetails(); + return 0; +} + +void CertificateChooser::ImplShowCertificateDetails() +{ + uno::Reference< dcss::security::XCertificate > xCert = GetSelectedCertificate(); + if( xCert.is() ) + { + CertificateViewer aViewer( this, mxSecurityEnvironment, xCert, TRUE ); + aViewer.Execute(); + } +} + diff --git a/xmlsecurity/source/dialogs/certificatechooser.src b/xmlsecurity/source/dialogs/certificatechooser.src new file mode 100644 index 000000000000..13ce734e46df --- /dev/null +++ b/xmlsecurity/source/dialogs/certificatechooser.src @@ -0,0 +1,87 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "dialogs.hrc" +#include "helpids.hrc" + +ModalDialog RID_XMLSECDLG_CERTCHOOSER +{ + HelpId = HID_XMLSEC_DLG_CERTCHOOSER; + Size = MAP_APPFONT( CS_WIDTH, CS_HEIGHT ); + OutputSize = TRUE; + Closeable = TRUE; + Moveable = TRUE; + SVLook = TRUE; + + Text [ en-US ] = "Select Certificate"; + + FixedText FT_HINT_SELECT + { + Pos = MAP_APPFONT( CS_COL_0, CS_ROW_0 ); + Size = MAP_APPFONT( CS_COL_2-CS_COL_0, RSC_CD_FIXEDTEXT_HEIGHT ); + Text [ en-US ] = "Select the certificate you want to use for signing"; + }; + Control LB_SIGNATURES + { + HelpId = HID_XMLSEC_CTRL_CHOOSESIGNATURES; + Pos = MAP_APPFONT( CS_COL_0, CS_ROW_1 ); + Size = MAP_APPFONT( CS_LB_WIDTH, CS_ROW_2-CS_ROW_1 ); + SVLook = TRUE; + Border = TRUE; + }; + String STR_HEADERBAR + { + Text [ en-US ] = "Issued to\tIssued by\tExpiration date"; + }; + PushButton BTN_VIEWCERT + { + Pos = MAP_APPFONT( CS_COL_1, CS_ROW_3 ); + Size = MAP_APPFONT( CS_COL_2-CS_COL_1, RSC_CD_PUSHBUTTON_HEIGHT ); + Text [ en-US ] = "View Certificate..."; + }; + FixedLine FL_BOTTOM_SEP + { + Pos = MAP_APPFONT( 0, DLGS_BOTTOM_FL_Y( CS_HEIGHT ) ); + Size = MAP_APPFONT( CS_WIDTH, RSC_CD_FIXEDLINE_HEIGHT ); + }; + OKButton BTN_OK + { + DefButton = TRUE; + Pos = MAP_APPFONT( DLGS_BOTTOM_OK_X( CS_WIDTH ), DLGS_BOTTOM_BTN_Y( CS_HEIGHT ) ); + Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT ); + }; + CancelButton BTN_CANCEL + { + Pos = MAP_APPFONT( DLGS_BOTTOM_CANCEL_X( CS_WIDTH ), DLGS_BOTTOM_BTN_Y( CS_HEIGHT ) ); + Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT ); + }; + HelpButton BTN_HELP + { + Pos = MAP_APPFONT( DLGS_BOTTOM_HELP_X( CS_WIDTH ), DLGS_BOTTOM_BTN_Y( CS_HEIGHT ) ); + Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT ); + }; +}; diff --git a/xmlsecurity/source/dialogs/certificateviewer.cxx b/xmlsecurity/source/dialogs/certificateviewer.cxx new file mode 100644 index 000000000000..af2ffc4352ed --- /dev/null +++ b/xmlsecurity/source/dialogs/certificateviewer.cxx @@ -0,0 +1,550 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmlsecurity.hxx" +#include <xmlsecurity/certificateviewer.hxx> +#include <com/sun/star/security/XCertificate.hpp> + +#include <com/sun/star/security/CertificateCharacters.hpp> +#include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp> +#include <com/sun/star/security/CertificateValidity.hpp> + +#include <unotools/localedatawrapper.hxx> +#include <unotools/datetime.hxx> + +#include "dialogs.hrc" +#include "resourcemanager.hxx" + +/* HACK: disable some warnings for MS-C */ +#ifdef _MSC_VER +#pragma warning (disable : 4355) // 4355: this used in initializer-list +#endif + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +namespace css = ::com::sun::star; + + +namespace +{ + void ShrinkToFit( FixedImage& _rImage ); + void AdjustPosAndSize( Control& _rCtrl, Point& _rStartIn_EndOut, long _nXOffset = 0 ); + + void ShrinkToFit( FixedImage& _rImg ) + { + _rImg.SetSizePixel( _rImg.GetImage().GetSizePixel() ); + } + + void AdjustPosAndSize( Control& _rCtrl, Point& _rStartIn_EndOut, long _nOffs ) + { + _rCtrl.SetPosPixel( _rStartIn_EndOut ); + _rStartIn_EndOut.X() += XmlSec::ShrinkToFitWidth( _rCtrl, _nOffs ); + } +} + +CertificateViewer::CertificateViewer( + Window* _pParent, + const cssu::Reference< dcss::xml::crypto::XSecurityEnvironment >& _rxSecurityEnvironment, + const cssu::Reference< dcss::security::XCertificate >& _rXCert, BOOL bCheckForPrivateKey ) + :TabDialog ( _pParent, XMLSEC_RES( RID_XMLSECDLG_CERTVIEWER ) ) + ,maTabCtrl ( this, XMLSEC_RES( 1 ) ) + ,maOkBtn ( this, XMLSEC_RES( BTN_OK ) ) + ,maHelpBtn ( this, XMLSEC_RES( BTN_HELP ) ) +{ + FreeResource(); + + mbCheckForPrivateKey = bCheckForPrivateKey; + + mxSecurityEnvironment = _rxSecurityEnvironment; + mxCert = _rXCert; + + maTabCtrl.SetTabPage( RID_XMLSECTP_GENERAL, new CertificateViewerGeneralTP( &maTabCtrl, this ) ); + maTabCtrl.SetTabPage( RID_XMLSECTP_DETAILS, new CertificateViewerDetailsTP( &maTabCtrl, this ) ); + maTabCtrl.SetTabPage( RID_XMLSECTP_CERTPATH, new CertificateViewerCertPathTP( &maTabCtrl, this ) ); + maTabCtrl.SetCurPageId( RID_XMLSECTP_GENERAL ); +} + +CertificateViewer::~CertificateViewer() +{ + delete maTabCtrl.GetTabPage( RID_XMLSECTP_CERTPATH ); + delete maTabCtrl.GetTabPage( RID_XMLSECTP_DETAILS ); + delete maTabCtrl.GetTabPage( RID_XMLSECTP_GENERAL ); +} + +CertificateViewerTP::CertificateViewerTP( Window* _pParent, const ResId& _rResId, CertificateViewer* _pDlg ) + :TabPage ( _pParent, _rResId ) + ,mpDlg ( _pDlg ) +{ +} + + +CertificateViewerGeneralTP::CertificateViewerGeneralTP( Window* _pParent, CertificateViewer* _pDlg ) + :CertificateViewerTP ( _pParent, XMLSEC_RES( RID_XMLSECTP_GENERAL ), _pDlg ) + ,maFrameWin ( this, XMLSEC_RES( WIN_FRAME ) ) + ,maCertImg ( this, XMLSEC_RES( IMG_CERT ) ) + ,maCertInfoFI ( this, XMLSEC_RES( FI_CERTINFO ) ) + ,maSep1FL ( this, XMLSEC_RES( FL_SEP1 ) ) + ,maHintNotTrustedFI ( this, XMLSEC_RES( FI_HINTNOTTRUST ) ) + ,maSep2FL ( this, XMLSEC_RES( FL_SEP2 ) ) + ,maIssuedToLabelFI ( this, XMLSEC_RES( FI_ISSTOLABEL ) ) + ,maIssuedToFI ( this, XMLSEC_RES( FI_ISSTO ) ) + ,maIssuedByLabelFI ( this, XMLSEC_RES( FI_ISSBYLABEL ) ) + ,maIssuedByFI ( this, XMLSEC_RES( FI_ISSBY ) ) + ,maValidDateFI ( this, XMLSEC_RES( FI_VALIDDATE ) ) + ,maKeyImg ( this, XMLSEC_RES( IMG_KEY ) ) + ,maHintCorrespPrivKeyFI ( this, XMLSEC_RES( FI_CORRPRIVKEY ) ) +{ + if ( GetSettings().GetStyleSettings().GetHighContrastMode() ) + maKeyImg.SetImage( Image( XMLSEC_RES( IMG_KEY_HC ) ) ); + + //Verify the certificate + sal_Int32 certStatus = mpDlg->mxSecurityEnvironment->verifyCertificate(mpDlg->mxCert, + Sequence<Reference<css::security::XCertificate> >()); + + bool bCertValid = certStatus == css::security::CertificateValidity::VALID ? true : false; + + bool bHC = GetSettings().GetStyleSettings().GetHighContrastMode(); + if ( !bCertValid ) + { + maCertImg.SetImage( + Image( XMLSEC_RES( bHC ? IMG_STATE_NOT_VALIDATED_HC : IMG_STATE_NOT_VALIDATED ) ) ); + maHintNotTrustedFI.SetText( String( XMLSEC_RES( STR_CERTIFICATE_NOT_VALIDATED ) ) ); + } + else if ( bHC ) + maCertImg.SetImage( Image( XMLSEC_RES( IMG_STATE_CERIFICATED_HC ) ) ); + + FreeResource(); + + Wallpaper aBack( GetSettings().GetStyleSettings().GetWindowColor() ); + maFrameWin.SetBackground( aBack ); + maCertImg.SetBackground( aBack ); + maCertInfoFI.SetBackground( aBack ); + maSep1FL.SetBackground( aBack ); + maHintNotTrustedFI.SetBackground( aBack ); + maSep2FL.SetBackground( aBack ); + maIssuedToLabelFI.SetBackground( aBack ); + maIssuedToFI.SetBackground( aBack ); + maIssuedByLabelFI.SetBackground( aBack ); + maIssuedByFI.SetBackground( aBack ); + maValidDateFI.SetBackground( aBack ); + maKeyImg.SetBackground( aBack ); + maHintCorrespPrivKeyFI.SetBackground( aBack ); + + // make some bold + Font aFnt( maCertInfoFI.GetFont() ); + aFnt.SetWeight( WEIGHT_BOLD ); + maCertInfoFI.SetFont( aFnt ); + maHintNotTrustedFI.SetFont( aFnt ); + maIssuedToLabelFI.SetFont( aFnt ); + maIssuedByLabelFI.SetFont( aFnt ); + maValidDateFI.SetFont( aFnt ); + + // insert data + cssu::Reference< dcss::security::XCertificate > xCert = mpDlg->mxCert; + + maIssuedToFI.SetText( XmlSec::GetContentPart( xCert->getSubjectName() ) ); + maIssuedByFI.SetText( XmlSec::GetContentPart( xCert->getIssuerName() ) ); + + // dynamic length because of the different languages + long nWidth1 = maIssuedToLabelFI.GetTextWidth( maIssuedToLabelFI.GetText() ); + long nWidth2 = maIssuedByLabelFI.GetTextWidth( maIssuedByLabelFI.GetText() ); + long nNewWidth = Max( nWidth1, nWidth2 ) + 5; + Size aNewSize = maIssuedToLabelFI.GetSizePixel(); + aNewSize.Width() = nNewWidth; + maIssuedToLabelFI.SetSizePixel( aNewSize ); + maIssuedByLabelFI.SetSizePixel( aNewSize ); + long nNewX = maIssuedToLabelFI.GetPosPixel().X() + nNewWidth + 1; + Point aNewPos = maIssuedToFI.GetPosPixel(); + aNewPos.X() = nNewX; + maIssuedToFI.SetPosPixel( aNewPos ); + aNewPos = maIssuedByFI.GetPosPixel(); + aNewPos.X() = nNewX; + maIssuedByFI.SetPosPixel( aNewPos ); + nNewWidth = maValidDateFI.GetSizePixel().Width() - nNewX; + aNewSize = maIssuedToFI.GetSizePixel(); + aNewSize.Width() = nNewWidth; + maIssuedToFI.SetSizePixel( aNewSize ); + maIssuedByFI.SetSizePixel( aNewSize ); + + DateTime aDateTimeStart; + DateTime aDateTimeEnd; + utl::typeConvert( xCert->getNotValidBefore(), aDateTimeStart ); + utl::typeConvert( xCert->getNotValidAfter(), aDateTimeEnd ); + String sText = maValidDateFI.GetText(); + sText.SearchAndReplace( String::CreateFromAscii( "%SDATE%" ), + GetSettings().GetUILocaleDataWrapper().getDate( aDateTimeStart.GetDate() ) ); + sText.SearchAndReplace( String::CreateFromAscii( "%EDATE%" ), + GetSettings().GetUILocaleDataWrapper().getDate( aDateTimeEnd.GetDate() ) ); + maValidDateFI.SetText( sText ); + + // adjust position of fixed text depending on image sizes + ShrinkToFit( maCertImg ); + ShrinkToFit( maKeyImg ); + XmlSec::AlignAfterImage( maCertImg, maCertInfoFI, 12 ); + XmlSec::AlignAfterImage( maKeyImg, maHintCorrespPrivKeyFI, 12 ); + + // Check if we have the private key... + BOOL bHasPrivateKey = FALSE; + // #i41270# Check only if we have that certificate in our security environment + if ( _pDlg->mbCheckForPrivateKey ) + { + long nCertificateCharacters = _pDlg->mxSecurityEnvironment->getCertificateCharacters( xCert ); + bHasPrivateKey = ( nCertificateCharacters & security::CertificateCharacters::HAS_PRIVATE_KEY ) ? TRUE : FALSE; + } + if ( !bHasPrivateKey ) + { + maKeyImg.Hide(); + maHintCorrespPrivKeyFI.Hide(); + } +} + +void CertificateViewerGeneralTP::ActivatePage() +{ + +} + + +struct Details_UserDatat +{ + String maTxt; + bool mbFixedWidthFont; + + inline Details_UserDatat( const String& _rTxt, bool _bFixedWidthFont ); +}; + +inline Details_UserDatat::Details_UserDatat( const String& _rTxt, bool _bFixedWidthFont ) + :maTxt ( _rTxt ) + ,mbFixedWidthFont ( _bFixedWidthFont ) +{ +} + + +void CertificateViewerDetailsTP::Clear( void ) +{ + maElementML.SetText( String() ); + ULONG i = 0; + SvLBoxEntry* pEntry = maElementsLB.GetEntry( i ); + while( pEntry ) + { + delete ( Details_UserDatat* ) pEntry->GetUserData(); + ++i; + pEntry = maElementsLB.GetEntry( i ); + } + + maElementsLB.Clear(); +} + +void CertificateViewerDetailsTP::InsertElement( const String& _rField, const String& _rValue, + const String& _rDetails, bool _bFixedWidthFont ) +{ + SvLBoxEntry* pEntry = maElementsLB.InsertEntry( _rField ); + maElementsLB.SetEntryText( _rValue, pEntry, 1 ); + pEntry->SetUserData( ( void* ) new Details_UserDatat( _rDetails, _bFixedWidthFont ) ); +} + +CertificateViewerDetailsTP::CertificateViewerDetailsTP( Window* _pParent, CertificateViewer* _pDlg ) + :CertificateViewerTP ( _pParent, XMLSEC_RES( RID_XMLSECTP_DETAILS ), _pDlg ) + ,maElementsLB ( this, XMLSEC_RES( LB_ELEMENTS ) ) + ,maElementML ( this, XMLSEC_RES( ML_ELEMENT ) ) + ,maStdFont ( maElementML.GetControlFont() ) + ,maFixedWidthFont ( OutputDevice::GetDefaultFont( DEFAULTFONT_UI_FIXED, LANGUAGE_DONTKNOW, DEFAULTFONT_FLAGS_ONLYONE, this ) ) +{ + WinBits nStyle = maElementsLB.GetStyle(); + nStyle &= ~WB_HSCROLL; + maElementsLB.SetStyle( nStyle ); + + maFixedWidthFont.SetHeight( maStdFont.GetHeight() ); + + static long nTabs[] = { 2, 0, 30*CS_LB_WIDTH/100 }; + maElementsLB.SetTabs( &nTabs[ 0 ] ); + maElementsLB.InsertHeaderEntry( String( XMLSEC_RES( STR_HEADERBAR ) ) ); + + // fill list box + Reference< security::XCertificate > xCert = mpDlg->mxCert; + UINT16 nLineBreak = 16; + const char* pHexSep = " "; + String aLBEntry; + String aDetails; + // --> PB 2004-10-11 #i35107# - 0 == "V1", 1 == "V2", ..., n = "V(n+1)" + aLBEntry = String::CreateFromAscii( "V" ); + aLBEntry += String::CreateFromInt32( xCert->getVersion() + 1 ); + // <-- + InsertElement( String( XMLSEC_RES( STR_VERSION ) ), aLBEntry, aLBEntry ); + Sequence< sal_Int8 > aSeq = xCert->getSerialNumber(); + aLBEntry = XmlSec::GetHexString( aSeq, pHexSep ); + aDetails = XmlSec::GetHexString( aSeq, pHexSep, nLineBreak ); + InsertElement( String( XMLSEC_RES( STR_SERIALNUM ) ), aLBEntry, aDetails, true ); + + std::pair< ::rtl::OUString, ::rtl::OUString> pairIssuer = + XmlSec::GetDNForCertDetailsView(xCert->getIssuerName()); + aLBEntry = pairIssuer.first; + aDetails = pairIssuer.second; + InsertElement( String( XMLSEC_RES( STR_ISSUER ) ), aLBEntry, aDetails ); + /* + aSeq = xCert->getIssuerUniqueID(); + aLBEntry = XmlSec::GetHexString( aSeq, pHexSep ); + aDetails = XmlSec::GetHexString( aSeq, pHexSep, nLineBreak ); + InsertElement( String( XMLSEC_RES( STR_ISSUER_ID ) ), aLBEntry, aDetails, true ); + */ + + DateTime aDateTime; + utl::typeConvert( xCert->getNotValidBefore(), aDateTime ); + aLBEntry = GetSettings().GetUILocaleDataWrapper().getDate( aDateTime.GetDate() ); + aLBEntry += String::CreateFromAscii( " " ); + aLBEntry += GetSettings().GetUILocaleDataWrapper().getTime( aDateTime.GetTime() ); + InsertElement( String( XMLSEC_RES( STR_VALIDFROM ) ), aLBEntry, aLBEntry ); + utl::typeConvert( xCert->getNotValidAfter(), aDateTime ); + aLBEntry = GetSettings().GetUILocaleDataWrapper().getDate( aDateTime.GetDate() ); + aLBEntry += String::CreateFromAscii( " " ); + aLBEntry += GetSettings().GetUILocaleDataWrapper().getTime( aDateTime.GetTime() ); + InsertElement( String( XMLSEC_RES( STR_VALIDTO ) ), aLBEntry, aLBEntry ); + + std::pair< ::rtl::OUString, ::rtl::OUString > pairSubject = + XmlSec::GetDNForCertDetailsView(xCert->getSubjectName()); + aLBEntry = pairSubject.first; + aDetails = pairSubject.second; + InsertElement( String( XMLSEC_RES( STR_SUBJECT ) ), aLBEntry, aDetails ); + /* + aSeq = xCert->getSubjectUniqueID(); + aLBEntry = XmlSec::GetHexString( aSeq, pHexSep ); + aDetails = XmlSec::GetHexString( aSeq, pHexSep, nLineBreak ); + InsertElement( String( XMLSEC_RES( STR_SUBJECT_ID ) ), aLBEntry, aDetails, true ); + */ + aLBEntry = aDetails = xCert->getSubjectPublicKeyAlgorithm(); + InsertElement( String( XMLSEC_RES( STR_SUBJECT_PUBKEY_ALGO ) ), aLBEntry, aDetails ); + aSeq = xCert->getSubjectPublicKeyValue(); + aLBEntry = XmlSec::GetHexString( aSeq, pHexSep ); + aDetails = XmlSec::GetHexString( aSeq, pHexSep, nLineBreak ); + InsertElement( String( XMLSEC_RES( STR_SUBJECT_PUBKEY_VAL ) ), aLBEntry, aDetails, true ); + + aLBEntry = aDetails = xCert->getSignatureAlgorithm(); + InsertElement( String( XMLSEC_RES( STR_SIGNATURE_ALGO ) ), aLBEntry, aDetails ); + + aSeq = xCert->getSHA1Thumbprint(); + aLBEntry = XmlSec::GetHexString( aSeq, pHexSep ); + aDetails = XmlSec::GetHexString( aSeq, pHexSep, nLineBreak ); + InsertElement( String( XMLSEC_RES( STR_THUMBPRINT_SHA1 ) ), aLBEntry, aDetails, true ); + + aSeq = xCert->getMD5Thumbprint(); + aLBEntry = XmlSec::GetHexString( aSeq, pHexSep ); + aDetails = XmlSec::GetHexString( aSeq, pHexSep, nLineBreak ); + InsertElement( String( XMLSEC_RES( STR_THUMBPRINT_MD5 ) ), aLBEntry, aDetails, true ); + + FreeResource(); + + maElementsLB.SetSelectHdl( LINK( this, CertificateViewerDetailsTP, ElementSelectHdl ) ); +} + +CertificateViewerDetailsTP::~CertificateViewerDetailsTP() +{ + Clear(); +} + +void CertificateViewerDetailsTP::ActivatePage() +{ +} + +IMPL_LINK( CertificateViewerDetailsTP, ElementSelectHdl, void*, EMPTYARG ) +{ + SvLBoxEntry* pEntry = maElementsLB.FirstSelected(); + String aElementText; + bool bFixedWidthFont; + if( pEntry ) + { + const Details_UserDatat* p = ( Details_UserDatat* ) pEntry->GetUserData(); + aElementText = p->maTxt; + bFixedWidthFont = p->mbFixedWidthFont; + } + else + bFixedWidthFont = false; + + maElementML.SetFont( bFixedWidthFont? maFixedWidthFont : maStdFont ); + maElementML.SetControlFont( bFixedWidthFont? maFixedWidthFont : maStdFont ); + maElementML.SetText( aElementText ); + + return 0; +} + +struct CertPath_UserData +{ + cssu::Reference< dcss::security::XCertificate > mxCert; + String maStatus; + bool mbValid; + + CertPath_UserData( cssu::Reference< dcss::security::XCertificate > xCert, bool bValid): + mxCert(xCert), + mbValid(bValid) + { + } +}; + + +CertificateViewerCertPathTP::CertificateViewerCertPathTP( Window* _pParent, CertificateViewer* _pDlg ) + :CertificateViewerTP ( _pParent, XMLSEC_RES( RID_XMLSECTP_CERTPATH ), _pDlg ) + ,maCertPathFT ( this, XMLSEC_RES( FT_CERTPATH ) ) + ,maCertPathLB ( this, XMLSEC_RES( LB_SIGNATURES ) ) + ,maViewCertPB ( this, XMLSEC_RES( BTN_VIEWCERT ) ) + ,maCertStatusFT ( this, XMLSEC_RES( FT_CERTSTATUS ) ) + ,maCertStatusML ( this, XMLSEC_RES( ML_CERTSTATUS ) ) + ,mpParent ( _pDlg ) + ,mbFirstActivateDone ( false ) + ,maCertImage ( XMLSEC_RES( IMG_CERT_SMALL ) ) + ,maCertNotValidatedImage( XMLSEC_RES( IMG_CERT_NOTVALIDATED_SMALL ) ) + ,msCertOK ( XMLSEC_RES( STR_PATH_CERT_OK ) ) + ,msCertNotValidated ( XMLSEC_RES( STR_PATH_CERT_NOT_VALIDATED ) ) + +{ + if ( GetSettings().GetStyleSettings().GetHighContrastMode() ) + { + maCertImage = Image( XMLSEC_RES( IMG_CERT_SMALL_HC ) ); + maCertNotValidatedImage = Image( XMLSEC_RES( IMG_CERT_NOTVALIDATED_SMALL_HC ) ); + } + + FreeResource(); + + maCertPathLB.SetNodeDefaultImages(); + maCertPathLB.SetSublistOpenWithLeftRight(); + maCertPathLB.SetSelectHdl( LINK( this, CertificateViewerCertPathTP, CertSelectHdl ) ); + maViewCertPB.SetClickHdl( LINK( this, CertificateViewerCertPathTP, ViewCertHdl ) ); + + // check if buttontext is to wide + const long nOffset = 10; + String sText = maViewCertPB.GetText(); + long nTxtW = maViewCertPB.GetTextWidth( sText ); + if ( sText.Search( '~' ) == STRING_NOTFOUND ) + nTxtW += nOffset; + long nBtnW = maViewCertPB.GetSizePixel().Width(); + if ( nTxtW > nBtnW ) + { + // broaden the button + long nDelta = nTxtW - nBtnW; + Size aNewSize = maViewCertPB.GetSizePixel(); + aNewSize.Width() += nDelta; + maViewCertPB.SetSizePixel( aNewSize ); + // and give it a new position + Point aNewPos = maViewCertPB.GetPosPixel(); + aNewPos.X() -= nDelta; + maViewCertPB.SetPosPixel( aNewPos ); + } +} + +CertificateViewerCertPathTP::~CertificateViewerCertPathTP() +{ + Clear(); +} + +void CertificateViewerCertPathTP::ActivatePage() +{ + if ( !mbFirstActivateDone ) + { + mbFirstActivateDone = true; + Sequence< Reference< security::XCertificate > > aCertPath = + mpParent->mxSecurityEnvironment->buildCertificatePath( mpParent->mxCert ); + const Reference< security::XCertificate >* pCertPath = aCertPath.getConstArray(); + + String aState; + sal_Int32 i, nCnt = aCertPath.getLength(); + SvLBoxEntry* pParent = NULL; + for( i = nCnt; i; ) + { + const Reference< security::XCertificate > rCert = pCertPath[ --i ]; + String sName = XmlSec::GetContentPart( rCert->getSubjectName() ); + //Verify the certificate + sal_Int32 certStatus = mpDlg->mxSecurityEnvironment->verifyCertificate(rCert, + Sequence<Reference<css::security::XCertificate> >()); + bool bCertValid = certStatus == css::security::CertificateValidity::VALID ? true : false; + pParent = InsertCert( pParent, sName, rCert, bCertValid); + } + + maCertPathLB.Select( pParent ); + maViewCertPB.Disable(); // Own certificate selected + + while( pParent ) + { + maCertPathLB.Expand( pParent ); + pParent = maCertPathLB.GetParent( pParent ); + } + + CertSelectHdl( NULL ); + } +} + +IMPL_LINK( CertificateViewerCertPathTP, ViewCertHdl, void*, EMPTYARG ) +{ + SvLBoxEntry* pEntry = maCertPathLB.FirstSelected(); + if( pEntry ) + { + CertificateViewer aViewer( this, mpDlg->mxSecurityEnvironment, ((CertPath_UserData*)pEntry->GetUserData())->mxCert, FALSE ); + aViewer.Execute(); + } + + return 0; +} + +IMPL_LINK( CertificateViewerCertPathTP, CertSelectHdl, void*, EMPTYARG ) +{ + String sStatus; + SvLBoxEntry* pEntry = maCertPathLB.FirstSelected(); + if( pEntry ) + { + CertPath_UserData* pData = (CertPath_UserData*) pEntry->GetUserData(); + if ( pData ) + sStatus = pData->mbValid ? msCertOK : msCertNotValidated; + } + + maCertStatusML.SetText( sStatus ); + maViewCertPB.Enable( pEntry && ( pEntry != maCertPathLB.Last() ) ); + return 0; +} + +void CertificateViewerCertPathTP::Clear( void ) +{ + maCertStatusML.SetText( String() ); + ULONG i = 0; + SvLBoxEntry* pEntry = maCertPathLB.GetEntry( i ); + while( pEntry ) + { + delete ( CertPath_UserData* ) pEntry->GetUserData(); + ++i; + pEntry = maCertPathLB.GetEntry( i ); + } + + maCertPathLB.Clear(); +} + +SvLBoxEntry* CertificateViewerCertPathTP::InsertCert( + SvLBoxEntry* _pParent, const String& _rName, cssu::Reference< dcss::security::XCertificate > rxCert, + bool bValid) +{ + Image aImage = bValid ? maCertImage : maCertNotValidatedImage; + SvLBoxEntry* pEntry = maCertPathLB.InsertEntry( _rName, aImage, aImage, _pParent ); + pEntry->SetUserData( ( void* ) new CertPath_UserData( rxCert, bValid ) ); + + return pEntry; +} + diff --git a/xmlsecurity/source/dialogs/certificateviewer.src b/xmlsecurity/source/dialogs/certificateviewer.src new file mode 100644 index 000000000000..3a9466aeb9a8 --- /dev/null +++ b/xmlsecurity/source/dialogs/certificateviewer.src @@ -0,0 +1,347 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "dialogs.hrc" +#include "helpids.hrc" + +TabDialog RID_XMLSECDLG_CERTVIEWER +{ + HelpID = HID_XMLSEC_DLG_CERTVIEWER; + Size = MAP_APPFONT( TD_WIDTH, TD_HEIGHT ); + OutputSize = TRUE; + Closeable = TRUE; + Moveable = TRUE; + SVLook = TRUE; + + Text [ en-US ] = "View Certificate"; + TabControl 1 + { + Pos = MAP_APPFONT( TD_SP_INNERBORDER_LEFT, TD_SP_INNERBORDER_TOP ); + Size = MAP_APPFONT( TP_WIDTH, TP_HEIGHT+RIDDER_HEIGHT ); + SVLook = TRUE ; + PageList = + { + PageItem + { + Identifier = RID_XMLSECTP_GENERAL; + Text [ en-US ] = "General"; + }; + PageItem + { + Identifier = RID_XMLSECTP_DETAILS; + Text [ en-US ] = "Details"; + }; + PageItem + { + Identifier = RID_XMLSECTP_CERTPATH; + Text [ en-US ] = "Certification Path"; + }; + }; + }; + OKButton BTN_OK + { + Pos = MAP_APPFONT( CV_COL_A, CV_ROW_A ); + Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT ); + DefButton = TRUE; + }; + HelpButton BTN_HELP + { + Pos = MAP_APPFONT( CV_COL_C, CV_ROW_A ); + Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT ); + }; +}; + +TabPage RID_XMLSECTP_GENERAL +{ + HelpId = HID_XMLSEC_TP_GENERAL; + Size = MAP_APPFONT( TP_WIDTH, TP_HEIGHT ); + OutputSize = TRUE; + Hide = TRUE; + SVLook = TRUE; + Window WIN_FRAME + { + SVLook = TRUE; + Border = TRUE; + Pos = MAP_APPFONT( CV_COL_0, CV_ROW_0 ); + Size = MAP_APPFONT( CV_CONT_WIDTH, CV_CONT_HEIGHT ); + }; + FixedImage IMG_CERT + { + Pos = MAP_APPFONT( CW_COL_0, CW_ROW_0 ); + Size = MAP_APPFONT( IMG1_WIDTH, IMG1_HEIGHT ); + Fixed = Image + { + ImageBitmap = Bitmap { File = "certificate_40x56.png"; }; + MaskColor = STD_MASKCOLOR; + }; + }; + FixedText FI_CERTINFO + { + Pos = MAP_APPFONT( CW_COL_3, CW_ROW_1 ); + Size = MAP_APPFONT( CW_COL_5-CW_COL_3, RSC_CD_FIXEDTEXT_HEIGHT ); + Text [ en-US ] = " Certificate Information"; + }; + FixedLine FL_SEP1 + { + Pos = MAP_APPFONT( CW_COL_0, CW_ROW_3 ); + Size = MAP_APPFONT( CW_COL_5-CW_COL_0, RSC_CD_FIXEDLINE_HEIGHT ); + }; + FixedText FI_HINTNOTTRUST + { + Pos = MAP_APPFONT( CW_COL_1, CW_ROW_4 ); + Size = MAP_APPFONT( CW_COL_5a-CW_COL_1, CW_ROW_4a-CW_ROW_4 ); + WordBreak = TRUE; + Text [ en-US ] = "This certificate is intended for the following purpose(s):"; + }; + FixedLine FL_SEP2 + { + Pos = MAP_APPFONT( CW_COL_0, CW_ROW_5 ); + Size = MAP_APPFONT( CW_COL_5-CW_COL_0, RSC_CD_FIXEDLINE_HEIGHT ); + }; + FixedText FI_ISSTOLABEL + { + Pos = MAP_APPFONT( CW_COL_1, CW_ROW_6 ); + Size = MAP_APPFONT( CW_COL_4-CW_COL_1-1, RSC_CD_FIXEDTEXT_HEIGHT ); + Text [ en-US ] = "Issued to:"; + }; + FixedText FI_ISSTO + { + Pos = MAP_APPFONT( CW_COL_4, CW_ROW_6 ); + Size = MAP_APPFONT( CW_COL_5-CW_COL_4, RSC_CD_FIXEDTEXT_HEIGHT ); + }; + FixedText FI_ISSBYLABEL + { + Pos = MAP_APPFONT( CW_COL_1, CW_ROW_7 ); + Size = MAP_APPFONT( CW_COL_4-CW_COL_1-1, RSC_CD_FIXEDTEXT_HEIGHT ); + Text [ en-US ] = "Issued by:"; + }; + FixedText FI_ISSBY + { + Pos = MAP_APPFONT( CW_COL_4, CW_ROW_7 ); + Size = MAP_APPFONT( CW_COL_5-CW_COL_4, RSC_CD_FIXEDTEXT_HEIGHT ); + }; + FixedText FI_VALIDDATE + { + Pos = MAP_APPFONT( CW_COL_1, CW_ROW_8 ); + Size = MAP_APPFONT( CW_COL_5-CW_COL_1-1, RSC_CD_FIXEDTEXT_HEIGHT ); + Text [ en-US ] = "Valid from %SDATE% to %EDATE%"; + }; + FixedImage IMG_KEY + { + Pos = MAP_APPFONT( CW_COL_0, CW_ROW_9 ); + Size = MAP_APPFONT( IMG2_WIDTH, IMG2_HEIGHT ); + Fixed = Image + { + ImageBitmap = Bitmap { File = "key_12.png"; }; + MaskColor = STD_MASKCOLOR; + }; + }; + FixedText FI_CORRPRIVKEY + { + Pos = MAP_APPFONT( CW_COL_1a, CW_ROW_10 ); + Size = MAP_APPFONT( CW_COL_5-CW_COL_1a, RSC_CD_FIXEDTEXT_HEIGHT ); + Text [ en-US ] = "You have a private key that corresponds to this certificate."; + }; + String STR_CERTIFICATE_NOT_VALIDATED + { + Text [ en-US ] = "The certificate could not be validated."; + }; + Image IMG_STATE_NOT_VALIDATED + { + ImageBitmap = Bitmap { File = "notcertificate_40x56.png"; }; + MaskColor = STD_MASKCOLOR; + }; + Image IMG_STATE_CERIFICATED_HC + { + ImageBitmap = Bitmap { File = "certificate_40x56_h.png"; }; + MaskColor = STD_MASKCOLOR; + }; + Image IMG_STATE_NOT_VALIDATED_HC + { + ImageBitmap = Bitmap { File = "notcertificate_40x56_h.png"; }; + MaskColor = STD_MASKCOLOR; + }; + Image IMG_KEY_HC + { + ImageBitmap = Bitmap { File = "key_12_h.png"; }; + MaskColor = STD_MASKCOLOR; + }; +}; + +TabPage RID_XMLSECTP_DETAILS +{ + HelpId = HID_XMLSEC_TP_DETAILS; + Size = MAP_APPFONT( TP_WIDTH, TP_HEIGHT ); + OutputSize = TRUE; + Hide = TRUE; + SVLook = TRUE; + Control LB_ELEMENTS + { + HelpId = HID_XMLSEC_CTRL_ELEMENTS; + Pos = MAP_APPFONT( CV_COL_0, CV_ROW_0 ); + Size = MAP_APPFONT( CV_CONT_WIDTH, CV_ROW_1-CV_ROW_0 ); + SVLook = TRUE; + Border = TRUE; + }; + String STR_HEADERBAR + { + Text [ en-US ] = "Field\tValue"; + }; + MultiLineEdit ML_ELEMENT + { + Pos = MAP_APPFONT( CV_COL_0, CV_ROW_2 ); + Size = MAP_APPFONT( CV_CONT_WIDTH, CV_ROW_3-CV_ROW_2 ); + ReadOnly = TRUE; + Border = TRUE; + VSCROLL = TRUE; + }; + String STR_VERSION + { + Text [ en-US ] = "Version"; + }; + String STR_SERIALNUM + { + Text [ en-US ] = "Serial Number"; + }; + String STR_SIGALGORITHM + { + Text [ en-US ] = "Signature Algorithm"; + }; + String STR_ISSUER + { + Text [ en-US ] = "Issuer"; + }; + String STR_ISSUER_ID + { + Text [ en-US ] = "Issuer Unique ID"; + }; + String STR_VALIDFROM + { + Text [ en-US ] = "Valid From"; + }; + String STR_VALIDTO + { + Text [ en-US ] = "Valid to"; + }; + String STR_SUBJECT + { + Text [ en-US ] = "Subject"; + }; + String STR_SUBJECT_ID + { + Text [ en-US ] = "Subject Unique ID"; + }; + String STR_SUBJECT_PUBKEY_ALGO + { + Text [ en-US ] = "Subject Algorithm"; + }; + String STR_SUBJECT_PUBKEY_VAL + { + Text [ en-US ] = "Public Key"; + }; + String STR_SIGNATURE_ALGO + { + Text [ en-US ] = "Signature Algorithm"; + }; + String STR_THUMBPRINT_SHA1 + { + Text [ en-US ] = "Thumbprint SHA1"; + }; + String STR_THUMBPRINT_MD5 + { + Text [ en-US ] = "Thumbprint MD5"; + }; +}; + +TabPage RID_XMLSECTP_CERTPATH +{ + HelpId = HID_XMLSEC_TP_CERTPATH; + Size = MAP_APPFONT( TP_WIDTH, TP_HEIGHT ); + OutputSize = TRUE; + Hide = TRUE; + SVLook = TRUE; + FixedText FT_CERTPATH + { + Pos = MAP_APPFONT( CV_COL_0, CVP_ROW_0 ); + Size = MAP_APPFONT( CV_CONT_WIDTH, RSC_CD_FIXEDTEXT_HEIGHT ); + Text [ en-US ] = "Certification path"; + }; + Control LB_SIGNATURES + { + HelpId = HID_XMLSEC_CTRL_VIEWSIGNATURES; + Pos = MAP_APPFONT( CV_COL_0, CVP_ROW_1 ); + Size = MAP_APPFONT( CV_CONT_WIDTH, REST_HEIGHT/3*2 ); + SVLook = TRUE; + Border = TRUE; + }; + PushButton BTN_VIEWCERT + { + Pos = MAP_APPFONT( CV_COL_1-(CV_COL_B-CV_COL_A), CVP_ROW_2 ); + Size = MAP_APPFONT( CV_COL_B-CV_COL_A, RSC_CD_PUSHBUTTON_HEIGHT ); + Text [ en-US ] = "View Certificate..."; + }; + FixedText FT_CERTSTATUS + { + Pos = MAP_APPFONT( CV_COL_0, CVP_ROW_3 ); + Size = MAP_APPFONT( CV_CONT_WIDTH, RSC_CD_FIXEDTEXT_HEIGHT ); + Text [ en-US ] = "Certification status"; + }; + MultiLineEdit ML_CERTSTATUS + { + Pos = MAP_APPFONT( CV_COL_0, CVP_ROW_4 ); + Size = MAP_APPFONT( CV_CONT_WIDTH, REST_HEIGHT/3 ); + ReadOnly = TRUE; + Border = TRUE; + }; + Image IMG_CERT_SMALL + { + ImageBitmap = Bitmap { File = "certificate_16.png"; }; + MaskColor = STD_MASKCOLOR; + }; + Image IMG_CERT_SMALL_HC + { + ImageBitmap = Bitmap { File = "certificate_16_h.png"; }; + MaskColor = STD_MASKCOLOR; + }; + Image IMG_CERT_NOTVALIDATED_SMALL + { + ImageBitmap = Bitmap { File = "notcertificate_16.png"; }; + MaskColor = STD_MASKCOLOR; + }; + Image IMG_CERT_NOTVALIDATED_SMALL_HC + { + ImageBitmap = Bitmap { File = "notcertificate_16_h.png"; }; + MaskColor = STD_MASKCOLOR; + }; + String STR_PATH_CERT_OK + { + Text [ en-US ] = "The certificate is OK."; + }; + String STR_PATH_CERT_NOT_VALIDATED + { + Text [ en-US ] = "The certificate could not be validated."; + }; +}; diff --git a/xmlsecurity/source/dialogs/dialogs.hrc b/xmlsecurity/source/dialogs/dialogs.hrc new file mode 100644 index 000000000000..b30eb9198e32 --- /dev/null +++ b/xmlsecurity/source/dialogs/dialogs.hrc @@ -0,0 +1,360 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _DIALOGS_HRC +#define _DIALOGS_HRC + +#include <svtools/controldims.hrc> +#include <xmlsecurity/global.hrc> + +#define STD_MASKCOLOR Color{Red=0xffff;Green=0x0000;Blue=0xffff;} + +#define FL_BOTTOM_SEP 50 +#define BTN_OK 51 +#define BTN_CANCEL 52 +#define BTN_HELP 53 +#define LB_SIGNATURES 54 +#define BTN_VIEWCERT 55 +#define STR_HEADERBAR 56 +#define BTN_RESET 57 +#define STR_VALID_SIGNATURE 58 +#define STR_NO_INFO_TO_VERIFY 59 +#define STR_INVALID_SIGNATURE 60 + +// --------- general metrics --------- +#define DLGS_WIDTH 287 +#define DLGS_HEIGHT 195 +// --------- ... for tab dialogs ----- +#define TP_WIDTH 260 +#define TP_HEIGHT 185 +#define RIDDER_HEIGHT (RSC_CD_PUSHBUTTON_HEIGHT) +#define TD_SP_INNERBORDER_LEFT 3 +#define TD_SP_INNERBORDER_RIGHT 3 +#define TD_SP_INNERBORDER_TOP 3 +#define TD_SP_INNERBORDER_BOTTOM 3 +#define TD_WIDTH (TP_WIDTH+RSC_SP_DLG_INNERBORDER_LEFT+RSC_SP_DLG_INNERBORDER_RIGHT) +#define TD_HEIGHT (TP_HEIGHT+TD_SP_INNERBORDER_TOP+2*TD_SP_INNERBORDER_BOTTOM+RSC_CD_PUSHBUTTON_HEIGHT+RIDDER_HEIGHT) + +#define SEP_FL_SPACE_Y 6 +#define SEP_FL_ADJ_Y(val) (val-3) +#define DLGS_BOTTOM_BTN_L(dlgh) (dlgh-RSC_SP_DLG_INNERBORDER_BOTTOM) +#define DLGS_BOTTOM_BTN_Y(dlgh) (DLGS_BOTTOM_BTN_L(dlgh)-RSC_CD_PUSHBUTTON_HEIGHT) +#define DLGS_BOTTOM_FL_Y(dlgh) (DLGS_BOTTOM_BTN_Y(dlgh)-SEP_FL_SPACE_Y-5) +#define DLGS_BOTTOM_LAST_CTRL_L(dlgh) (DLGS_BOTTOM_BTN_Y(dlgh)-2*SEP_FL_SPACE_Y-3) +#define DLGS_BOTTOM_HELP_X(dlgw) (dlgw-RSC_SP_DLG_INNERBORDER_RIGHT-RSC_CD_PUSHBUTTON_WIDTH) +#define DLGS_BOTTOM_CANCEL_X(dlgw) (DLGS_BOTTOM_HELP_X(dlgw)-RSC_SP_CTRL_X-RSC_CD_PUSHBUTTON_WIDTH) +#define DLGS_BOTTOM_OK_X(dlgw) (DLGS_BOTTOM_CANCEL_X(dlgw)-RSC_SP_CTRL_DESC_X-RSC_CD_PUSHBUTTON_WIDTH) + + +// --------- dialog Digital Signatures --------- +#define BTN_ADDCERT 2 +#define BTN_REMOVECERT 3 +#define FT_HINT_DOC 4 +#define FT_HINT_BASIC 5 +#define FT_HINT_PACK 6 +#define IMG_STATE_VALID 7 +#define FI_STATE_VALID 8 +#define IMG_STATE_BROKEN 9 +#define FI_STATE_BROKEN 10 +#define IMG_STATE_NOTVALIDATED 11 +#define FI_STATE_NOTVALIDATED 12 +#define IMG_STATE_VALID_HC 13 +#define IMG_STATE_BROKEN_HC 14 +#define IMG_STATE_NOTVALIDATED_HC 15 +#define FI_STATE_OLDSIGNATURE 16 + +//#define DS_WIDTH DLGS_WIDTH +//#define DS_HEIGHT DLGS_HEIGHT +#define DS_BTNWIDTH_1 70 +#define DS_BTNSPACE_X RSC_SP_CTRL_X +#define DS_WIDTH (RSC_SP_DLG_INNERBORDER_LEFT+RSC_SP_DLG_INNERBORDER_RIGHT+2*DS_BTNSPACE_X+3*DS_BTNWIDTH_1) +#define DS_HEIGHT (DLGS_WIDTH*2/3) + +#define DS_COL_0 RSC_SP_DLG_INNERBORDER_LEFT +//#define DS_COL_MID (DS_WIDTH/2) +//#define DS_COL_3 (DS_COL_MID-(DS_BTNWIDTH_1/2)) +//#define DS_COL_4 (DS_COL_2+DS_BTNWIDTH_1) +//#define DS_COL_2 (DS_COL_3-DS_BTNSPACE_X) +//#define DS_COL_1 (DS_COL_2-DS_BTNWIDTH_1) +#define DS_COL_1 DS_COL_0 +#define DS_COL_2 (DS_COL_1+DS_BTNWIDTH_1) +#define DS_COL_3 (DS_COL_2+DS_BTNSPACE_X) +#define DS_COL_4 (DS_COL_3+DS_BTNWIDTH_1) +#define DS_COL_5 (DS_COL_4+DS_BTNSPACE_X) +//#define DS_COL_6 (DS_COL_5+DS_BTNWIDTH_1) +#define DS_COL_7 (DS_WIDTH-RSC_SP_DLG_INNERBORDER_RIGHT) +#define DS_COL_6 DS_COL_7 + +#define DS_ROW_0 RSC_SP_DLG_INNERBORDER_TOP +#define DS_ROW_1 (DS_ROW_0+RSC_CD_FIXEDTEXT_HEIGHT+RSC_SP_CTRL_DESC_X) +#define DS_ROW_7 DLGS_BOTTOM_BTN_L(DS_HEIGHT) +#define DS_ROW_6 DLGS_BOTTOM_BTN_Y(DS_HEIGHT) +#define DS_ROW_5 DLGS_BOTTOM_FL_Y(DS_HEIGHT) +#define DS_ROW_4 DLGS_BOTTOM_LAST_CTRL_L(DS_HEIGHT) +#define DS_ROW_3 (DS_ROW_4-RSC_CD_PUSHBUTTON_HEIGHT) +#define DS_ROW_2A (DS_ROW_3-RSC_CD_FIXEDTEXT_HEIGHT-RSC_SP_CTRL_Y) +#define DS_ROW_2 (DS_ROW_2A-RSC_SP_CTRL_GROUP_Y) + +#define DS_LB_WIDTH (DS_COL_7-DS_COL_0) + +// --------- dialog Ceritficate chooser --------- +#define FT_HINT_SELECT 1 + +#define CS_WIDTH DLGS_WIDTH +#define CS_HEIGHT DLGS_HEIGHT +#define CS_BTNWIDTH_1 DS_BTNWIDTH_1 + +#define CS_COL_0 RSC_SP_DLG_INNERBORDER_LEFT +#define CS_COL_2 (CS_WIDTH-RSC_SP_DLG_INNERBORDER_RIGHT) +#define CS_COL_1 (CS_COL_2-CS_BTNWIDTH_1) + +#define CS_ROW_0 RSC_SP_DLG_INNERBORDER_TOP +#define CS_ROW_1 (CS_ROW_0+RSC_CD_FIXEDTEXT_HEIGHT+RSC_SP_CTRL_DESC_X) +#define CS_ROW_4 DLGS_BOTTOM_LAST_CTRL_L(CS_HEIGHT) +#define CS_ROW_3 (CS_ROW_4-RSC_CD_PUSHBUTTON_HEIGHT) +#define CS_ROW_2 (CS_ROW_3-RSC_SP_CTRL_Y) + +#define CS_LB_WIDTH (CS_COL_2-CS_COL_0) + +// --------- tab dialog Certificate viewer --------- + +#define CV_COL_0 TD_SP_INNERBORDER_LEFT +#define CV_COL_1 (TP_WIDTH-RSC_SP_TBPG_INNERBORDER_RIGHT) +#define CV_ROW_0 RSC_SP_TBPG_INNERBORDER_TOP +#define CV_ROW_3 (TP_HEIGHT-RSC_SP_TBPG_INNERBORDER_BOTTOM) +#define CV_CONT_WIDTH (CV_COL_1-CV_COL_0) +#define CV_CONT_HEIGHT (CV_ROW_3-CV_ROW_0) +#define CV_ROW_1 (CV_ROW_0+2*CV_CONT_HEIGHT/3) +#define CV_ROW_2 (CV_ROW_1+RSC_SP_CTRL_GROUP_Y) + +#define CV_COL_D (TD_WIDTH-TD_SP_INNERBORDER_RIGHT) +#define CV_COL_C (CV_COL_D-RSC_CD_PUSHBUTTON_WIDTH) +#define CV_COL_B (CV_COL_C-RSC_SP_CTRL_X) +#define CV_COL_A (CV_COL_B-RSC_CD_PUSHBUTTON_WIDTH) + +#define CV_ROW_B (TD_HEIGHT-TD_SP_INNERBORDER_BOTTOM) +#define CV_ROW_A (CV_ROW_B-RSC_CD_PUSHBUTTON_HEIGHT) + +// --------- tab page Certificate viewer - General --------- +#define WIN_FRAME 2 +#define IMG_CERT 3 +#define FI_CERTINFO 4 +#define FL_SEP1 5 +#define FI_HINTNOTTRUST 6 +#define FL_SEP2 7 +#define FI_ISSTOLABEL 8 +#define FI_ISSTO 9 +#define FI_ISSBYLABEL 10 +#define FI_ISSBY 11 +#define FI_VALIDDATE 12 +#define IMG_KEY 13 +#define FI_CORRPRIVKEY 14 +#define STR_CERTIFICATE_NOT_VALIDATED 15 +#define IMG_STATE_NOT_VALIDATED 16 +#define IMG_STATE_CERIFICATED_HC 17 +#define IMG_STATE_NOT_VALIDATED_HC 18 +#define IMG_KEY_HC 19 + +#define IMG1_WIDTH 33 +#define IMG1_HEIGHT 22 +#define IMG2_WIDTH 20 +#define IMG2_HEIGHT 20 +#define DATE_WIDTH 30 +#define CW_COL_0 (CV_COL_0+RSC_SP_GRP_INNERBORDER_LEFT) +#define CW_COL_1 (CW_COL_0+RSC_SP_FLGR_SPACE_X) +#define CW_COL_1a (CW_COL_0+IMG2_WIDTH+1) +#define CW_COL_2 (CW_COL_0+IMG1_WIDTH) +#define CW_COL_3 (CW_COL_2+RSC_SP_CTRL_GROUP_X) +#define CW_COL_4 (CW_COL_1+40) +#define CW_COL_5 (CV_CONT_WIDTH-RSC_SP_GRP_INNERBORDER_RIGHT) +#define CW_COL_5a (CW_COL_5-RSC_SP_GRP_INNERBORDER_RIGHT) +#define CW_COL_4a (CW_COL_1+38) +#define CW_COL_4b (CW_COL_4a+DATE_WIDTH) +#define CW_COL_4c (CW_COL_4b+3) +#define CW_COL_4d (CW_COL_4c+8) +#define CW_COL_4e (CW_COL_4d+3) +#define CW_ROW_0 (CV_ROW_0+RSC_SP_GRP_INNERBORDER_TOP) +#define CW_ROW_1 (CW_ROW_0+RSC_SP_GRP_INNERBORDER_TOP) +#define CW_ROW_2 (CW_ROW_0+IMG1_HEIGHT) +#define CW_ROW_3 (CW_ROW_2+3) +#define CW_ROW_4 (CW_ROW_3+RSC_SP_CTRL_Y+RSC_CD_FIXEDLINE_HEIGHT) +#define CW_ROW_4a (CW_ROW_4+35) +#define CW_ROW_5 (CW_ROW_4a+3) +#define CW_ROW_6 (CW_ROW_5+RSC_SP_CTRL_Y+RSC_CD_FIXEDLINE_HEIGHT) +#define CW_ROW_7 (CW_ROW_6+RSC_SP_CTRL_Y+RSC_CD_FIXEDTEXT_HEIGHT) +#define CW_ROW_8 (CW_ROW_7+RSC_SP_CTRL_Y+RSC_CD_FIXEDTEXT_HEIGHT) +#define CW_ROW_9 (CW_ROW_8+RSC_SP_CTRL_Y+RSC_CD_FIXEDTEXT_HEIGHT) +#define CW_ROW_10 (CW_ROW_9+2) +#define CW_ROW_11 (CW_ROW_9+IMG2_HEIGHT) + +// --------- tab page Certificate viewer - Details --------- + +#define LB_ELEMENTS 1 +#define ML_ELEMENT 2 + +#define STR_VERSION 1 +#define STR_SERIALNUM 2 +#define STR_SIGALGORITHM 3 +#define STR_ISSUER 4 +#define STR_ISSUER_ID 5 +#define STR_VALIDFROM 6 +#define STR_VALIDTO 7 +#define STR_SUBJECT 8 +#define STR_SUBJECT_ID 9 +#define STR_SUBJECT_PUBKEY_ALGO 10 +#define STR_SUBJECT_PUBKEY_VAL 11 +#define STR_SIGNATURE_ALGO 12 +#define STR_THUMBPRINT_SHA1 13 +#define STR_THUMBPRINT_MD5 14 + +// --------- tab page Certificate viewer - Certification Path --------- + +#define FT_CERTPATH 1 +#define FT_CERTSTATUS 2 +#define ML_CERTSTATUS 3 +#define IMG_CERT_SMALL 4 +#define IMG_CERT_SMALL_HC 5 +#define IMG_CERT_NOTVALIDATED_SMALL 6 +#define IMG_CERT_NOTVALIDATED_SMALL_HC 7 +#define STR_PATH_CERT_OK 8 +#define STR_PATH_CERT_NOT_VALIDATED 9 + +#define CVP_ROW_0 RSC_SP_TBPG_INNERBORDER_TOP +#define CVP_ROW_1 (CVP_ROW_0+RSC_CD_FIXEDTEXT_HEIGHT+RSC_SP_CTRL_DESC_Y) +#define REST_HEIGHT (TP_HEIGHT-CVP_ROW_1-2*RSC_SP_GRP_SPACE_Y-RSC_CD_FIXEDTEXT_HEIGHT-RSC_CD_PUSHBUTTON_HEIGHT) +#define CVP_ROW_2 (CVP_ROW_1+REST_HEIGHT/3*2+RSC_SP_CTRL_DESC_Y) +#define CVP_ROW_3 (CVP_ROW_2+RSC_CD_PUSHBUTTON_HEIGHT) +#define CVP_ROW_4 (CVP_ROW_3+RSC_CD_FIXEDTEXT_HEIGHT+RSC_SP_CTRL_DESC_Y) + +//#define CV_ROW_0A (CV_ROW_0+RSC_SP_CTRL_DESC_Y+RSC_CD_FIXEDTEXT_HEIGHT) +//#define CV_ROW_2A (CV_ROW_2+RSC_SP_CTRL_DESC_Y+RSC_CD_FIXEDTEXT_HEIGHT) + +// --------- tab dialog macro security --------- + +#define MS_COL_A (TD_WIDTH-RSC_SP_DLG_INNERBORDER_LEFT) +#define MS_COL_B (MS_COL_A-RSC_CD_PUSHBUTTON_WIDTH) +#define MS_COL_C (MS_COL_B-RSC_SP_CTRL_X) +#define MS_COL_D (MS_COL_C-RSC_CD_PUSHBUTTON_WIDTH) +#define MS_COL_E (MS_COL_D-RSC_SP_CTRL_X) +#define MS_COL_F (MS_COL_E-RSC_CD_PUSHBUTTON_WIDTH) +#define MS_COL_G (MS_COL_F-RSC_SP_CTRL_X) +#define MS_COL_H (MS_COL_G-RSC_CD_PUSHBUTTON_WIDTH) + +// --------- tab page security level --------- + +#define FL_SECLEVEL 1 +#define RB_VERYHIGH 2 +#define RB_HIGH 3 +#define RB_MEDIUM 4 +#define RB_LOW 5 +#define FI_SEC_READONLY 6 + +#define RSC_BIG_RADIOBUTTON 40 +#define SL_RB_DIST_Y (RSC_SP_FLGR_SPACE_Y+RSC_BIG_RADIOBUTTON) +#define SL_COL_0 RSC_SP_TBPG_INNERBORDER_LEFT +#define SL_COL_1 (SL_COL_0+RSC_SP_FLGR_SPACE_X) +#define SL_COL_3 (TP_WIDTH-RSC_SP_TBPG_INNERBORDER_RIGHT) +#define SL_COL_2 ((SL_COL_3-SL_COL_1)*100/105) +#define SL_ROW_0 RSC_SP_TBPG_INNERBORDER_TOP +#define SL_ROW_1 (SL_ROW_0+SL_RB_DIST_Y) +#define SL_ROW_2 (SL_ROW_1+SL_RB_DIST_Y) +#define SL_ROW_3 (SL_ROW_2+SL_RB_DIST_Y) +#define SL_ROW_4 (TP_HEIGHT-RSC_SP_TBPG_INNERBORDER_BOTTOM) + +// --------- tab page trusted sources --------- + +#define FL_TRUSTCERT 1 +#define LB_TRUSTCERT 2 +#define PB_ADD_TRUSTCERT 3 +#define PB_VIEW_TRUSTCERT 4 +#define PB_REMOVE_TRUSTCERT 5 +#define FL_TRUSTFILELOC 6 +#define FI_TRUSTFILELOC 7 +#define LB_TRUSTFILELOC 8 +#define FL_ADD_TRUSTFILELOC 9 +#define FL_REMOVE_TRUSTFILELOC 10 +#define FI_TRUSTCERT_RO 11 +#define FI_TRUSTFILE_RO 12 + +#define TS_COL_0 RSC_SP_TBPG_INNERBORDER_LEFT +#define TS_COL_1 (TS_COL_0+RSC_SP_FLGR_SPACE_X) +#define TS_COL_8 (TP_WIDTH-RSC_SP_TBPG_INNERBORDER_RIGHT) +#define TS_COL_7 (TS_COL_8-RSC_SP_FLGR_SPACE_X) +#define TS_COL_6 (TS_COL_7-RSC_CD_PUSHBUTTON_WIDTH) +#define TS_COL_5 (TS_COL_6-RSC_SP_CTRL_GROUP_X) +#define TS_COL_4 (TS_COL_5-RSC_CD_PUSHBUTTON_WIDTH) +#define TS_COL_3 (TS_COL_4-RSC_SP_CTRL_GROUP_X) +#define TS_COL_2 (TS_COL_3-RSC_CD_PUSHBUTTON_WIDTH) + +#define RSC_CD_TABLISTBOX_HEIGHT 6*RSC_BS_CHARHEIGHT +#define TS_ROW_0 RSC_SP_TBPG_INNERBORDER_TOP +#define TS_ROW_1 (TS_ROW_0+RSC_CD_FIXEDLINE_HEIGHT+RSC_SP_FLGR_SPACE_Y) +#define TS_ROW_2 (TS_ROW_1+RSC_CD_TABLISTBOX_HEIGHT+RSC_SP_FLGR_SPACE_Y) +#define TS_ROW_3 (TS_ROW_2+RSC_CD_PUSHBUTTON_HEIGHT+RSC_SP_FLGR_SPACE_Y) +#define TS_ROW_4 (TS_ROW_3+RSC_CD_FIXEDLINE_HEIGHT+RSC_SP_FLGR_SPACE_Y) +#define TS_ROW_5 (TS_ROW_4+3*RSC_CD_FIXEDTEXT_HEIGHT+RSC_SP_FLGR_SPACE_Y) + +#define TS_ROW_8 (TP_HEIGHT-RSC_SP_TBPG_INNERBORDER_BOTTOM) +#define TS_ROW_7 (TS_ROW_8-RSC_CD_PUSHBUTTON_HEIGHT) +#define TS_ROW_6 (TS_ROW_7-RSC_SP_FLGR_SPACE_Y) + +// --------- signed macro warning --------- + +#define FI_DOCNAME 1 +#define FI_DESCR1A 2 +#define FI_SIGNS 3 +#define PB_VIEWSIGNS 4 +#define FI_DESCR2 5 +#define CB_ALWAYSTRUST 6 +#define PB_ENABLE 7 +#define PB_DISABLE 8 +#define FI_DESCR1B 9 + +#define MW_WIDTH DLGS_WIDTH +#define MW_HEIGHT DLGS_HEIGHT + +#define MW_SYMBOL_WIDTH (20) + +#define MW_COL_0 (RSC_SP_DLG_INNERBORDER_LEFT) +#define MW_COL_1 (MW_COL_0+MW_SYMBOL_WIDTH) +#define MW_COL_4 (MW_WIDTH-RSC_SP_DLG_INNERBORDER_RIGHT) +#define MW_COL_3 (MW_COL_4-RSC_CD_PUSHBUTTON_WIDTH) +#define MW_COL_2 (MW_COL_3-RSC_SP_CTRL_DESC_X) +#define MW_COL_A (DLGS_BOTTOM_OK_X(MW_WIDTH)) +#define MW_COL_C (DLGS_BOTTOM_CANCEL_X(MW_WIDTH)) +#define MW_COL_E (DLGS_BOTTOM_HELP_X(MW_WIDTH)) +#define MW_ROW_0 (RSC_SP_DLG_INNERBORDER_TOP) +#define MW_ROW_1 (MW_ROW_0+3*RSC_CD_FIXEDTEXT_HEIGHT+RSC_SP_CTRL_Y) +#define MW_ROW_2 (MW_ROW_1+RSC_CD_FIXEDTEXT_HEIGHT+RSC_SP_CTRL_Y) +#define MW_ROW_7 (MW_HEIGHT-RSC_SP_DLG_INNERBORDER_BOTTOM) +#define MW_ROW_6 (DLGS_BOTTOM_BTN_Y(MW_HEIGHT)) +#define MW_ROW_5 (DLGS_BOTTOM_FL_Y(MW_HEIGHT)) +#define MW_ROW_4 (MW_ROW_5-RSC_CD_CHECKBOX_HEIGHT-RSC_SP_CTRL_Y) +#define MW_ROW_3 (MW_ROW_4-4*RSC_CD_FIXEDTEXT_HEIGHT+RSC_SP_CTRL_Y) + +#endif + diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx new file mode 100644 index 000000000000..df032dcbe5ef --- /dev/null +++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx @@ -0,0 +1,846 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmlsecurity.hxx" +#include <xmlsecurity/digitalsignaturesdialog.hxx> +#include <xmlsecurity/certificatechooser.hxx> +#include <xmlsecurity/certificateviewer.hxx> +#include <xmlsecurity/biginteger.hxx> +#include <xmloff/xmluconv.hxx> +#include <com/sun/star/embed/XStorage.hpp> +#include <com/sun/star/embed/ElementModes.hpp> +#include <com/sun/star/io/XSeekable.hpp> +#include <com/sun/star/io/XTruncate.hpp> +#include <com/sun/star/embed/XTransactedObject.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/security/NoPasswordException.hpp> +#include <com/sun/star/lang/DisposedException.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/security/CertificateValidity.hdl> +#include <com/sun/star/packages/WrongPasswordException.hpp> +#include <com/sun/star/security/SerialNumberAdapter.hpp> +#include <com/sun/star/security/XDocumentDigitalSignatures.hpp> +#include <com/sun/star/xml/dom/XDocumentBuilder.hpp> +#include <com/sun/star/packages/manifest/XManifestReader.hpp> + + +#include <rtl/ustrbuf.hxx> +#include <rtl/uri.hxx> + +#include <tools/date.hxx> +#include <tools/time.hxx> + +#include "dialogs.hrc" +#include "digitalsignaturesdialog.hrc" +#include "helpids.hrc" +#include "resourcemanager.hxx" + +#include <vcl/msgbox.hxx> // Until encrypted docs work... +#include <unotools/configitem.hxx> +#include <comphelper/componentcontext.hxx> + +#define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) ) + + +/* HACK: disable some warnings for MS-C */ +#ifdef _MSC_VER +#pragma warning (disable : 4355) // 4355: this used in initializer-list +#endif + +using namespace ::com::sun::star::security; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star; +namespace css = ::com::sun::star; +using ::rtl::OUString; + +namespace +{ + class SaveODFItem: public utl::ConfigItem + { + sal_Int16 m_nODF; + public: + virtual void Commit(); + virtual void Notify( const ::com::sun::star::uno::Sequence< rtl::OUString >& aPropertyNames ); + SaveODFItem(); + //See group ODF in Common.xcs + bool isLessODF1_2() + { + return m_nODF < 3; + } + }; + +void SaveODFItem::Commit() {} +void SaveODFItem::Notify( const ::com::sun::star::uno::Sequence< rtl::OUString >& ) {} + + SaveODFItem::SaveODFItem(): utl::ConfigItem(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "Office.Common/Save"))), m_nODF(0) + { + OUString sDef(RTL_CONSTASCII_USTRINGPARAM("ODF/DefaultVersion")); + Sequence< css::uno::Any > aValues = GetProperties( Sequence<OUString>(&sDef,1) ); + if ( aValues.getLength() == 1) + { + sal_Int16 nTmp = 0; + if ( aValues[0] >>= nTmp ) + m_nODF = nTmp; + else + throw uno::RuntimeException( + OUString(RTL_CONSTASCII_USTRINGPARAM( + "[xmlsecurity]SaveODFItem::SaveODFItem(): Wrong Type!")), 0 ); + + } + else + throw uno::RuntimeException( + OUString(RTL_CONSTASCII_USTRINGPARAM( + "[xmlsecurity] Could not open property Office.Common/Save/ODF/DefaultVersion")), 0); + } +} + +/* Using the zip storage, we cannot get the properties "MediaType" and "IsEncrypted" + We use the manifest to find out if a file is xml and if it is encrypted. + The parameter is an encoded uri. However, the manifest contains paths. Therefore + the path is encoded as uri, so they can be compared. +*/ +bool DigitalSignaturesDialog::isXML(const rtl::OUString& rURI ) +{ + OSL_ASSERT(mxStore.is()); + + bool bIsXML = false; + bool bPropsAvailable = false; + const OUString sPropFullPath(RTL_CONSTASCII_USTRINGPARAM("FullPath")); + const OUString sPropMediaType(RTL_CONSTASCII_USTRINGPARAM("MediaType")); + const OUString sPropDigest(RTL_CONSTASCII_USTRINGPARAM("Digest")); + + for (int i = 0; i < m_manifest.getLength(); i++) + { + Any digest; + const Sequence< css::beans::PropertyValue >& entry = m_manifest[i]; + OUString sPath, sMediaType; + bool bEncrypted = false; + for (int j = 0; j < entry.getLength(); j++) + { + const css::beans::PropertyValue & prop = entry[j]; + + if (prop.Name.equals( sPropFullPath ) ) + prop.Value >>= sPath; + else if (prop.Name.equals( sPropMediaType ) ) + prop.Value >>= sMediaType; + else if (prop.Name.equals( sPropDigest ) ) + bEncrypted = true; + } + if (DocumentSignatureHelper::equalsReferenceUriManifestPath(rURI, sPath)) + { + bIsXML = sMediaType.equals(OUSTR("text/xml")) && ! bEncrypted; + bPropsAvailable = true; + break; + } + } + if (!bPropsAvailable) + { + //This would be the case for at least mimetype, META-INF/manifest.xml + //META-INF/macrosignatures.xml. + //Files can only be encrypted if they are in the manifest.xml. + //That is, the current file cannot be encrypted, otherwise bPropsAvailable + //would be true. + OUString aXMLExt( RTL_CONSTASCII_USTRINGPARAM( "XML" ) ); + sal_Int32 nSep = rURI.lastIndexOf( '.' ); + if ( nSep != (-1) ) + { + OUString aExt = rURI.copy( nSep+1 ); + if (aExt.equalsIgnoreAsciiCase(aXMLExt )) + bIsXML = true; + } + } + return bIsXML; +} + +DigitalSignaturesDialog::DigitalSignaturesDialog( + Window* pParent, + uno::Reference< uno::XComponentContext >& rxCtx, DocumentSignatureMode eMode, + sal_Bool bReadOnly, const ::rtl::OUString& sODFVersion, bool bHasDocumentSignature) + :ModalDialog ( pParent, XMLSEC_RES( RID_XMLSECDLG_DIGSIG ) ) + ,mxCtx ( rxCtx ) + ,maSignatureHelper ( rxCtx ) + ,meSignatureMode ( eMode ) + ,maHintDocFT ( this, XMLSEC_RES( FT_HINT_DOC ) ) + ,maHintBasicFT ( this, XMLSEC_RES( FT_HINT_BASIC ) ) + ,maHintPackageFT ( this, XMLSEC_RES( FT_HINT_PACK ) ) + ,maSignaturesLB ( this, XMLSEC_RES( LB_SIGNATURES ) ) + ,maSigsValidImg ( this, XMLSEC_RES( IMG_STATE_VALID ) ) + ,maSigsValidFI ( this, XMLSEC_RES( FI_STATE_VALID ) ) + ,maSigsInvalidImg ( this, XMLSEC_RES( IMG_STATE_BROKEN ) ) + ,maSigsInvalidFI ( this, XMLSEC_RES( FI_STATE_BROKEN ) ) + ,maSigsNotvalidatedImg( this, XMLSEC_RES( IMG_STATE_NOTVALIDATED ) ) + ,maSigsNotvalidatedFI ( this, XMLSEC_RES( FI_STATE_NOTVALIDATED ) ) + ,maSigsOldSignatureFI ( this, XMLSEC_RES( FI_STATE_OLDSIGNATURE) ) + ,maViewBtn ( this, XMLSEC_RES( BTN_VIEWCERT ) ) + ,maAddBtn ( this, XMLSEC_RES( BTN_ADDCERT ) ) + ,maRemoveBtn ( this, XMLSEC_RES( BTN_REMOVECERT ) ) + ,maBottomSepFL ( this, XMLSEC_RES( FL_BOTTOM_SEP ) ) + ,maOKBtn ( this, XMLSEC_RES( BTN_OK ) ) + ,maHelpBtn ( this, XMLSEC_RES( BTN_HELP ) ) + ,m_sODFVersion (sODFVersion) + ,m_bHasDocumentSignature(bHasDocumentSignature) + ,m_bWarningShowSignMacro(false) +{ + // --> PB #i48253 the tablistbox needs its own unique id + maSignaturesLB.Window::SetUniqueId( HID_XMLSEC_TREE_SIGNATURESDLG ); + // <-- + Size aControlSize( maSignaturesLB.GetSizePixel() ); + aControlSize = maSignaturesLB.PixelToLogic( aControlSize, MapMode( MAP_APPFONT ) ); + const long nControlWidth = aControlSize.Width(); + static long nTabs[] = { 4, 0, 6*nControlWidth/100, 36*nControlWidth/100, 74*nControlWidth/100 }; + maSignaturesLB.SetTabs( &nTabs[ 0 ] ); + maSignaturesLB.InsertHeaderEntry( String( XMLSEC_RES( STR_HEADERBAR ) ) ); + + maSigsNotvalidatedFI.SetText( String( XMLSEC_RES( STR_NO_INFO_TO_VERIFY ) ) ); + + if ( GetSettings().GetStyleSettings().GetHighContrastMode() ) + { + // high contrast mode needs other images + maSigsValidImg.SetImage( Image( XMLSEC_RES( IMG_STATE_VALID_HC ) ) ); + maSigsInvalidImg.SetImage( Image( XMLSEC_RES( IMG_STATE_BROKEN_HC ) ) ); + maSigsNotvalidatedImg.SetImage( Image( XMLSEC_RES( IMG_STATE_NOTVALIDATED_HC ) ) ); + } + + FreeResource(); + + mbVerifySignatures = true; + mbSignaturesChanged = false; + + maSignaturesLB.SetSelectHdl( LINK( this, DigitalSignaturesDialog, SignatureHighlightHdl ) ); + maSignaturesLB.SetDoubleClickHdl( LINK( this, DigitalSignaturesDialog, SignatureSelectHdl ) ); + + maViewBtn.SetClickHdl( LINK( this, DigitalSignaturesDialog, ViewButtonHdl ) ); + maViewBtn.Disable(); + + maAddBtn.SetClickHdl( LINK( this, DigitalSignaturesDialog, AddButtonHdl ) ); + if ( bReadOnly ) + maAddBtn.Disable(); + + maRemoveBtn.SetClickHdl( LINK( this, DigitalSignaturesDialog, RemoveButtonHdl ) ); + maRemoveBtn.Disable(); + + maOKBtn.SetClickHdl( LINK( this, DigitalSignaturesDialog, OKButtonHdl) ); + + switch( meSignatureMode ) + { + case SignatureModeDocumentContent: maHintDocFT.Show(); break; + case SignatureModeMacros: maHintBasicFT.Show(); break; + case SignatureModePackage: maHintPackageFT.Show(); break; + } + + // adjust fixed text to images + XmlSec::AlignAndFitImageAndControl( maSigsValidImg, maSigsValidFI, 5 ); + XmlSec::AlignAndFitImageAndControl( maSigsInvalidImg, maSigsInvalidFI, 5 ); + XmlSec::AlignAndFitImageAndControl( maSigsNotvalidatedImg, maSigsNotvalidatedFI, 5 ); + XmlSec::AlignAndFitImageAndControl( maSigsNotvalidatedImg, maSigsOldSignatureFI, 5 ); +} + +DigitalSignaturesDialog::~DigitalSignaturesDialog() +{ +} + +BOOL DigitalSignaturesDialog::Init( const rtl::OUString& rTokenName ) +{ + bool bInit = maSignatureHelper.Init( rTokenName ); + + DBG_ASSERT( bInit, "Error initializing security context!" ); + + if ( bInit ) + { + maSignatureHelper.SetStartVerifySignatureHdl( LINK( this, DigitalSignaturesDialog, StartVerifySignatureHdl ) ); + } + + return bInit; +} + +void DigitalSignaturesDialog::SetStorage( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& rxStore ) +{ + mxStore = rxStore; + maSignatureHelper.SetStorage( mxStore, m_sODFVersion); + + Reference < css::packages::manifest::XManifestReader > xReader( + mxCtx->getServiceManager()->createInstanceWithContext( + OUSTR("com.sun.star.packages.manifest.ManifestReader"), mxCtx), UNO_QUERY_THROW); + + //Get the manifest.xml + Reference < css::embed::XStorage > xSubStore(rxStore->openStorageElement( + OUSTR("META-INF"), css::embed::ElementModes::READ), UNO_QUERY_THROW); + + Reference< css::io::XInputStream > xStream( + xSubStore->openStreamElement(OUSTR("manifest.xml"), css::embed::ElementModes::READ), + UNO_QUERY_THROW); + + m_manifest = xReader->readManifestSequence(xStream); +} + +void DigitalSignaturesDialog::SetSignatureStream( const cssu::Reference < css::io::XStream >& rxStream ) +{ + mxSignatureStream = rxStream; +} + +bool DigitalSignaturesDialog::canAddRemove() +{ + //m56 + bool ret = true; + OSL_ASSERT(mxStore.is()); + bool bDoc1_1 = DocumentSignatureHelper::isODFPre_1_2(m_sODFVersion); + SaveODFItem item; + bool bSave1_1 = item.isLessODF1_2(); + + // see specification + //cvs: specs/www/appwide/security/Electronic_Signatures_and_Security.sxw + //Paragraph 'Behavior with regard to ODF 1.2' + //For both, macro and document + if ( (!bSave1_1 && bDoc1_1) || (bSave1_1 && bDoc1_1) ) + { + //#4 + ErrorBox err(NULL, XMLSEC_RES(RID_XMLSECDLG_OLD_ODF_FORMAT)); + err.Execute(); + ret = false; + } + + //As of OOo 3.2 the document signature includes in macrosignatures.xml. That is + //adding a macro signature will break an existing document signature. + //The sfx2 will remove the documentsignature when the user adds a macro signature + if (meSignatureMode == SignatureModeMacros + && ret) + { + if (m_bHasDocumentSignature && !m_bWarningShowSignMacro) + { + //The warning says that the document signatures will be removed if the user + //continues. He can then either press 'OK' or 'NO' + //It the user presses 'Add' or 'Remove' several times then, then the warning + //is shown every time until the user presses 'OK'. From then on, the warning + //is not displayed anymore as long as the signatures dialog is alive. + if (QueryBox( + NULL, XMLSEC_RES(MSG_XMLSECDLG_QUERY_REMOVEDOCSIGNBEFORESIGN)).Execute() == RET_NO) + ret = false; + else + m_bWarningShowSignMacro = true; + + } + } + return ret; +} + +bool DigitalSignaturesDialog::canAdd() +{ + if (canAddRemove()) + return true; + return false; +} + +bool DigitalSignaturesDialog::canRemove() +{ + if (canAddRemove()) + return true; + return false; +} + +short DigitalSignaturesDialog::Execute() +{ + // Verify Signatures and add certificates to ListBox... + mbVerifySignatures = true; + ImplGetSignatureInformations(false); + ImplFillSignaturesBox(); + + // Only verify once, content will not change. + // But for refreshing signature information, StartVerifySignatureHdl will be called after each add/remove + mbVerifySignatures = false; + + return Dialog::Execute(); +} + +IMPL_LINK( DigitalSignaturesDialog, SignatureHighlightHdl, void*, EMPTYARG ) +{ + bool bSel = maSignaturesLB.FirstSelected() ? true : false; + maViewBtn.Enable( bSel ); + if ( maAddBtn.IsEnabled() ) // not read only + maRemoveBtn.Enable( bSel ); + + return 0; +} + +IMPL_LINK( DigitalSignaturesDialog, OKButtonHdl, void*, EMPTYARG ) +{ + // Export all other signatures... + SignatureStreamHelper aStreamHelper = ImplOpenSignatureStream( + embed::ElementModes::WRITE|embed::ElementModes::TRUNCATE, false ); + uno::Reference< io::XOutputStream > xOutputStream( + aStreamHelper.xSignatureStream, uno::UNO_QUERY ); + uno::Reference< com::sun::star::xml::sax::XDocumentHandler> xDocumentHandler = + maSignatureHelper.CreateDocumentHandlerWithHeader( xOutputStream ); + + int nInfos = maCurrentSignatureInformations.size(); + for( int n = 0 ; n < nInfos ; ++n ) + maSignatureHelper.ExportSignature( + xDocumentHandler, maCurrentSignatureInformations[ n ] ); + + maSignatureHelper.CloseDocumentHandler( xDocumentHandler); + + // If stream was not provided, we are responsible for committing it.... + if ( !mxSignatureStream.is() ) + { + uno::Reference< embed::XTransactedObject > xTrans( + aStreamHelper.xSignatureStorage, uno::UNO_QUERY ); + xTrans->commit(); + } + + EndDialog(RET_OK); + return 0; +} + +IMPL_LINK( DigitalSignaturesDialog, SignatureSelectHdl, void*, EMPTYARG ) +{ + ImplShowSignaturesDetails(); + return 0; +} + +IMPL_LINK( DigitalSignaturesDialog, ViewButtonHdl, Button*, EMPTYARG ) +{ + ImplShowSignaturesDetails(); + return 0; +} + +IMPL_LINK( DigitalSignaturesDialog, AddButtonHdl, Button*, EMPTYARG ) +{ + if( ! canAdd()) + return 0; + try + { + uno::Reference<com::sun::star::xml::crypto::XSecurityEnvironment> xSecEnv = maSignatureHelper.GetSecurityEnvironment(); + + uno::Reference<com::sun::star::security::XSerialNumberAdapter> xSerialNumberAdapter = + ::com::sun::star::security::SerialNumberAdapter::create(mxCtx); + CertificateChooser aChooser( this, mxCtx, xSecEnv, maCurrentSignatureInformations ); + if ( aChooser.Execute() == RET_OK ) + { + uno::Reference< ::com::sun::star::security::XCertificate > xCert = aChooser.GetSelectedCertificate(); + if ( !xCert.is() ) + { + DBG_ERRORFILE( "no certificate selected" ); + return -1; + } + rtl::OUString aCertSerial = xSerialNumberAdapter->toString( xCert->getSerialNumber() ); + if ( !aCertSerial.getLength() ) + { + DBG_ERROR( "Error in Certificate, problem with serial number!" ); + return -1; + } + + maSignatureHelper.StartMission(); + + sal_Int32 nSecurityId = maSignatureHelper.GetNewSecurityId(); + + rtl::OUStringBuffer aStrBuffer; + SvXMLUnitConverter::encodeBase64(aStrBuffer, xCert->getEncoded()); + + maSignatureHelper.SetX509Certificate( nSecurityId, + xCert->getIssuerName(), aCertSerial, + aStrBuffer.makeStringAndClear()); + + std::vector< rtl::OUString > aElements = + DocumentSignatureHelper::CreateElementList( + mxStore, rtl::OUString(), meSignatureMode, OOo3_2Document); + + sal_Int32 nElements = aElements.size(); + for ( sal_Int32 n = 0; n < nElements; n++ ) + { + bool bBinaryMode = !isXML(aElements[n]); + maSignatureHelper.AddForSigning( nSecurityId, aElements[n], aElements[n], bBinaryMode ); + } + + maSignatureHelper.SetDateTime( nSecurityId, Date(), Time() ); + + // We open a signature stream in which the existing and the new + //signature is written. ImplGetSignatureInformation (later in this function) will + //then read the stream an will fill maCurrentSignatureInformations. The final signature + //is written when the user presses OK. Then only maCurrentSignatureInformation and + //a sax writer are used to write the information. + SignatureStreamHelper aStreamHelper = ImplOpenSignatureStream( + css::embed::ElementModes::WRITE|css::embed::ElementModes::TRUNCATE, true); + Reference< css::io::XOutputStream > xOutputStream( + aStreamHelper.xSignatureStream, UNO_QUERY_THROW); + Reference< css::xml::sax::XDocumentHandler> xDocumentHandler = + maSignatureHelper.CreateDocumentHandlerWithHeader( xOutputStream ); + + // Export old signatures... + int nInfos = maCurrentSignatureInformations.size(); + for ( int n = 0; n < nInfos; n++ ) + maSignatureHelper.ExportSignature( xDocumentHandler, maCurrentSignatureInformations[n]); + + // Create a new one... + maSignatureHelper.CreateAndWriteSignature( xDocumentHandler ); + + // That's it... + maSignatureHelper.CloseDocumentHandler( xDocumentHandler); + + maSignatureHelper.EndMission(); + + aStreamHelper = SignatureStreamHelper(); // release objects... + + mbSignaturesChanged = true; + + sal_Int32 nStatus = maSignatureHelper.GetSignatureInformation( nSecurityId ).nStatus; + + if ( nStatus == ::com::sun::star::xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED ) + { + mbSignaturesChanged = true; + + // Can't simply remember current information, need parsing for getting full information :( + // We need to verify the signatures again, otherwise the status in the signature information + // will not contain + // SecurityOperationStatus_OPERATION_SUCCEEDED + mbVerifySignatures = true; + ImplGetSignatureInformations(true); + ImplFillSignaturesBox(); + } + } + } + catch ( uno::Exception& ) + { + DBG_ERROR( "Exception while adding a signature!" ); + // Don't keep invalid entries... + ImplGetSignatureInformations(true); + ImplFillSignaturesBox(); + } + + return 0; +} + +IMPL_LINK( DigitalSignaturesDialog, RemoveButtonHdl, Button*, EMPTYARG ) +{ + if (!canRemove()) + return 0; + if( maSignaturesLB.FirstSelected() ) + { + try + { + USHORT nSelected = (USHORT) (sal_uIntPtr) maSignaturesLB.FirstSelected()->GetUserData(); + maCurrentSignatureInformations.erase( maCurrentSignatureInformations.begin()+nSelected ); + + // Export all other signatures... + SignatureStreamHelper aStreamHelper = ImplOpenSignatureStream( + css::embed::ElementModes::WRITE | css::embed::ElementModes::TRUNCATE, true); + Reference< css::io::XOutputStream > xOutputStream( + aStreamHelper.xSignatureStream, UNO_QUERY_THROW); + Reference< css::xml::sax::XDocumentHandler> xDocumentHandler = + maSignatureHelper.CreateDocumentHandlerWithHeader( xOutputStream ); + + int nInfos = maCurrentSignatureInformations.size(); + for( int n = 0 ; n < nInfos ; ++n ) + maSignatureHelper.ExportSignature( xDocumentHandler, maCurrentSignatureInformations[ n ] ); + + maSignatureHelper.CloseDocumentHandler( xDocumentHandler); + + mbSignaturesChanged = true; + + aStreamHelper = SignatureStreamHelper(); // release objects... + + ImplFillSignaturesBox(); + } + catch ( uno::Exception& ) + { + DBG_ERROR( "Exception while removing a signature!" ); + // Don't keep invalid entries... + ImplGetSignatureInformations(true); + ImplFillSignaturesBox(); + } + } + + return 0; +} + +IMPL_LINK( DigitalSignaturesDialog, StartVerifySignatureHdl, void*, EMPTYARG ) +{ + return mbVerifySignatures ? 1 : 0; +} + +void DigitalSignaturesDialog::ImplFillSignaturesBox() +{ + maSignaturesLB.Clear(); + + uno::Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment > xSecEnv = maSignatureHelper.GetSecurityEnvironment(); + uno::Reference<com::sun::star::security::XSerialNumberAdapter> xSerialNumberAdapter = + ::com::sun::star::security::SerialNumberAdapter::create(mxCtx); + + uno::Reference< ::com::sun::star::security::XCertificate > xCert; + + String aNullStr; + int nInfos = maCurrentSignatureInformations.size(); + int nValidSigs = 0, nValidCerts = 0; + bool bAllNewSignatures = true; + + if( nInfos ) + { + for( int n = 0; n < nInfos; ++n ) + { + DocumentSignatureAlgorithm mode = DocumentSignatureHelper::getDocumentAlgorithm( + m_sODFVersion, maCurrentSignatureInformations[n]); + std::vector< rtl::OUString > aElementsToBeVerified = + DocumentSignatureHelper::CreateElementList( + mxStore, ::rtl::OUString(), meSignatureMode, mode); + + const SignatureInformation& rInfo = maCurrentSignatureInformations[n]; + //First we try to get the certificate which is embedded in the XML Signature + if (rInfo.ouX509Certificate.getLength()) + xCert = xSecEnv->createCertificateFromAscii(rInfo.ouX509Certificate); + else { + //There must be an embedded certificate because we use it to get the + //issuer name. We cannot use /Signature/KeyInfo/X509Data/X509IssuerName + //because it could be modified by an attacker. The issuer is displayed + //in the digital signature dialog. + //Comparing the X509IssuerName with the one from the X509Certificate in order + //to find out if the X509IssuerName was modified does not work. See #i62684 + DBG_ASSERT(sal_False, "Could not find embedded certificate!"); + } + + //In case there is no embedded certificate we try to get it from a local store + //Todo: This probably could be removed, see above. + if (!xCert.is()) + xCert = xSecEnv->getCertificate( rInfo.ouX509IssuerName, xSerialNumberAdapter->toSequence( rInfo.ouX509SerialNumber ) ); + + DBG_ASSERT( xCert.is(), "Certificate not found and can't be created!" ); + + String aSubject; + String aIssuer; + String aDateTimeStr; + + bool bSigValid = false; + bool bCertValid = false; + if( xCert.is() ) + { + //check the validity of the cert + try { + sal_Int32 certResult = xSecEnv->verifyCertificate(xCert, + Sequence<css::uno::Reference<css::security::XCertificate> >()); + + bCertValid = certResult == css::security::CertificateValidity::VALID ? true : false; + if ( bCertValid ) + nValidCerts++; + + } catch (css::uno::SecurityException& ) { + OSL_ENSURE(0, "Verification of certificate failed"); + bCertValid = false; + } + + aSubject = XmlSec::GetContentPart( xCert->getSubjectName() ); + aIssuer = XmlSec::GetContentPart( xCert->getIssuerName() ); + // --> PB 2004-10-12 #i20172# String with date and time information + aDateTimeStr = XmlSec::GetDateTimeString( rInfo.stDateTime ); + } + bSigValid = ( rInfo.nStatus == ::com::sun::star::xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED ); + + if ( bSigValid ) + { + bSigValid = DocumentSignatureHelper::checkIfAllFilesAreSigned( + aElementsToBeVerified, rInfo, mode); + + if( bSigValid ) + nValidSigs++; + } + + Image aImage; + if (!bSigValid) + { + aImage = maSigsInvalidImg.GetImage(); + } + else if (bSigValid && !bCertValid) + { + aImage = maSigsNotvalidatedImg.GetImage(); + } + //Check if the signature is a "old" document signature, that is, which was created + //by an version of OOo previous to 3.2 + else if (meSignatureMode == SignatureModeDocumentContent + && bSigValid && bCertValid && !DocumentSignatureHelper::isOOo3_2_Signature( + maCurrentSignatureInformations[n])) + { + aImage = maSigsNotvalidatedImg.GetImage(); + bAllNewSignatures &= false; + } + else if (meSignatureMode == SignatureModeDocumentContent + && bSigValid && bCertValid && DocumentSignatureHelper::isOOo3_2_Signature( + maCurrentSignatureInformations[n])) + { + aImage = maSigsValidImg.GetImage(); + } + else if (meSignatureMode == SignatureModeMacros + && bSigValid && bCertValid) + { + aImage = aImage = maSigsValidImg.GetImage(); + } + + SvLBoxEntry* pEntry = maSignaturesLB.InsertEntry( aNullStr, aImage, aImage ); + maSignaturesLB.SetEntryText( aSubject, pEntry, 1 ); + maSignaturesLB.SetEntryText( aIssuer, pEntry, 2 ); + maSignaturesLB.SetEntryText( aDateTimeStr, pEntry, 3 ); + pEntry->SetUserData( ( void* ) n ); // missuse user data as index + } + } + + bool bAllSigsValid = (nValidSigs == nInfos); + bool bAllCertsValid = (nValidCerts == nInfos); + bool bShowValidState = nInfos && (bAllSigsValid && bAllCertsValid && bAllNewSignatures); + + bool bShowNotValidatedState = nInfos && (bAllSigsValid && (!bAllCertsValid || !bAllNewSignatures)); + bool bShowInvalidState = nInfos && !bAllSigsValid; + + maSigsValidImg.Show( bShowValidState); + maSigsValidFI.Show( bShowValidState ); + maSigsInvalidImg.Show( bShowInvalidState ); + maSigsInvalidFI.Show( bShowInvalidState ); + + maSigsNotvalidatedImg.Show(bShowNotValidatedState); + //bAllNewSignatures is always true if we are not in document mode + maSigsNotvalidatedFI.Show(nInfos && bAllSigsValid && ! bAllCertsValid); + maSigsOldSignatureFI.Show(nInfos && bAllSigsValid && bAllCertsValid && !bAllNewSignatures); + + SignatureHighlightHdl( NULL ); +} + + +//If bUseTempStream is true then the temporary signature stream is used. +//Otherwise the real signature stream is used. +void DigitalSignaturesDialog::ImplGetSignatureInformations(bool bUseTempStream) +{ + maCurrentSignatureInformations.clear(); + + maSignatureHelper.StartMission(); + + SignatureStreamHelper aStreamHelper = ImplOpenSignatureStream( + css::embed::ElementModes::READ, bUseTempStream); + if ( aStreamHelper.xSignatureStream.is() ) + { + uno::Reference< io::XInputStream > xInputStream( aStreamHelper.xSignatureStream, uno::UNO_QUERY ); + maSignatureHelper.ReadAndVerifySignature( xInputStream ); + } + maSignatureHelper.EndMission(); + + maCurrentSignatureInformations = maSignatureHelper.GetSignatureInformations(); + + mbVerifySignatures = false; +} + +void DigitalSignaturesDialog::ImplShowSignaturesDetails() +{ + if( maSignaturesLB.FirstSelected() ) + { + USHORT nSelected = (USHORT) (sal_uIntPtr) maSignaturesLB.FirstSelected()->GetUserData(); + const SignatureInformation& rInfo = maCurrentSignatureInformations[ nSelected ]; + css::uno::Reference<css::xml::crypto::XSecurityEnvironment > xSecEnv = + maSignatureHelper.GetSecurityEnvironment(); + css::uno::Reference<com::sun::star::security::XSerialNumberAdapter> xSerialNumberAdapter = + ::com::sun::star::security::SerialNumberAdapter::create(mxCtx); + // Use Certificate from doc, not from key store + uno::Reference< dcss::security::XCertificate > xCert; + if (rInfo.ouX509Certificate.getLength()) + xCert = xSecEnv->createCertificateFromAscii(rInfo.ouX509Certificate); + //fallback if no certificate is embedded, get if from store + if (!xCert.is()) + xCert = xSecEnv->getCertificate( rInfo.ouX509IssuerName, xSerialNumberAdapter->toSequence( rInfo.ouX509SerialNumber ) ); + + DBG_ASSERT( xCert.is(), "Error getting cCertificate!" ); + if ( xCert.is() ) + { + CertificateViewer aViewer( this, maSignatureHelper.GetSecurityEnvironment(), xCert, FALSE ); + aViewer.Execute(); + } + } +} + +//If bTempStream is true, then a temporary stream is return. If it is false then, the actual +//signature stream is used. +//Everytime the user presses Add a new temporary stream is created. +//We keep the temporary stream as member because ImplGetSignatureInformations +//will later access the stream to create DocumentSignatureInformation objects +//which are stored in maCurrentSignatureInformations. +SignatureStreamHelper DigitalSignaturesDialog::ImplOpenSignatureStream( + sal_Int32 nStreamOpenMode, bool bTempStream) +{ + SignatureStreamHelper aHelper; + if (bTempStream) + { + if (nStreamOpenMode & css::embed::ElementModes::TRUNCATE) + { + //We write always into a new temporary stream. + mxTempSignatureStream = Reference < css::io::XStream >( + mxCtx->getServiceManager()->createInstanceWithContext( + OUSTR( "com.sun.star.io.TempFile" ), mxCtx) , + UNO_QUERY_THROW); + aHelper.xSignatureStream = mxTempSignatureStream; + } + else + { + //When we read from the temp stream, then we must have previously + //created one. + OSL_ASSERT(mxTempSignatureStream.is()); + } + aHelper.xSignatureStream = mxTempSignatureStream; + } + else + { + //No temporary stream + if (!mxSignatureStream.is()) + { + //We may not have a dedicated stream for writing the signature + //So we take one directly from the storage + //Or DocumentDigitalSignatures::showDocumentContentSignatures was called, + //in which case Add/Remove is not allowed. This is done, for example, if the + //document is readonly + aHelper = DocumentSignatureHelper::OpenSignatureStream( + mxStore, nStreamOpenMode, meSignatureMode ); + } + else + { + aHelper.xSignatureStream = mxSignatureStream; + } + } + + if (nStreamOpenMode & css::embed::ElementModes::TRUNCATE) + { + css::uno::Reference < css::io::XTruncate > xTruncate( + aHelper.xSignatureStream, UNO_QUERY_THROW); + DBG_ASSERT( xTruncate.is(), "ImplOpenSignatureStream - Stream does not support xTruncate!" ); + xTruncate->truncate(); + } + else if ( bTempStream || mxSignatureStream.is()) + { + //In case we read the signature stream from the storage directly, + //which is the case when DocumentDigitalSignatures::showDocumentContentSignatures + //then XSeakable is not supported + css::uno::Reference < css::io::XSeekable > xSeek( + aHelper.xSignatureStream, UNO_QUERY_THROW); + DBG_ASSERT( xSeek.is(), "ImplOpenSignatureStream - Stream does not support xSeekable!" ); + xSeek->seek( 0 ); + } + + return aHelper; +} + diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.hrc b/xmlsecurity/source/dialogs/digitalsignaturesdialog.hrc new file mode 100644 index 000000000000..d63b44834f2c --- /dev/null +++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.hrc @@ -0,0 +1,36 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#if ! defined INCLUDED_DIGITALSIGNATURESDIALOG_HRC +#define INCLUDED_DIGITALSIGNATURESDIALOG_HRC + +//global.hrc in xmlsecurity/inc starts at 1000 +#define RID_DIGITALSIGNATUREDLG_START 2000 + +#define RID_XMLSECDLG_OLD_ODF_FORMAT RID_DIGITALSIGNATUREDLG_START +#define MSG_XMLSECDLG_QUERY_REMOVEDOCSIGNBEFORESIGN (RID_DIGITALSIGNATUREDLG_START + 1) +#endif diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.src b/xmlsecurity/source/dialogs/digitalsignaturesdialog.src new file mode 100644 index 000000000000..87d2de520103 --- /dev/null +++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.src @@ -0,0 +1,219 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "dialogs.hrc" +#include "helpids.hrc" +#include "digitalsignaturesdialog.hrc" + +ModalDialog RID_XMLSECDLG_DIGSIG +{ + HelpId = HID_XMLSEC_DLG_DIGSIG; + Size = MAP_APPFONT( 234, 191 ); + OutputSize = TRUE; + Closeable = TRUE; + Moveable = TRUE; + SVLook = TRUE; + + Text [ en-US ] = "Digital Signatures"; + + FixedText FT_HINT_DOC + { + Pos = MAP_APPFONT( 6, 3 ); + Size = MAP_APPFONT( 222, 8 ); + Hide = TRUE; + Text [ en-US ] = "The following have signed the document content:"; + }; + FixedText FT_HINT_BASIC + { + Pos = MAP_APPFONT( 6, 3 ); + Size = MAP_APPFONT( 222, 8 ); + Hide = TRUE; + Text [ en-US ] = "The following have signed the document macro:"; + }; + FixedText FT_HINT_PACK + { + Pos = MAP_APPFONT( 6, 3 ); + Size = MAP_APPFONT( 222, 8 ); + Hide = TRUE; + Text [ en-US ] = "The following have signed this package:"; + }; + Control LB_SIGNATURES + { + HelpId = HID_XMLSEC_CTRL_SIGNATURESDLG; + Pos = MAP_APPFONT( 6, 14 ); + Size = MAP_APPFONT( 222, 109 ); + SVLook = TRUE; + Border = TRUE; + }; + String STR_HEADERBAR + { + Text [ en-US ] = "\tSigned by\tDigital ID issued by\tDate"; + }; + String STR_VALID_SIGNATURE + { + Text [ en-US ] = "Valid signature"; + }; + String STR_NO_INFO_TO_VERIFY + { + Text [ en-US ] = "Certificate could not be validated"; + }; + String STR_INVALID_SIGNATURE + { + Text [ en-US ] = "The signatures in this document are invalid"; + }; + + FixedImage IMG_STATE_VALID + { + Pos = MAP_APPFONT( 6, 127 ); + Size = MAP_APPFONT( 33, 22 ); + Fixed = Image + { + ImageBitmap = Bitmap { File = "signet_11x16.png"; }; + MaskColor = STD_MASKCOLOR; + }; + }; + FixedText FI_STATE_VALID + { + Pos = MAP_APPFONT( 6, 127 ); + Size = MAP_APPFONT( 222, 8 ); + Hide = TRUE; + Text [ en-US ] = "The signatures in this document are valid"; + }; + FixedText FI_STATE_OLDSIGNATURE + { + Pos = MAP_APPFONT( 6, 127 ); + Size = MAP_APPFONT( 222, 8 ); + Hide = TRUE; + Text [ en-US ] = "Not all parts of the document are signed"; + }; + FixedImage IMG_STATE_BROKEN + { + Pos = MAP_APPFONT( 6, 127 ); + Size = MAP_APPFONT( 33, 22 ); + Fixed = Image + { + ImageBitmap = Bitmap { File = "caution_11x16.png"; }; + MaskColor = STD_MASKCOLOR; + }; + }; + FixedText FI_STATE_BROKEN + { + Pos = MAP_APPFONT( 6, 127 ); + Size = MAP_APPFONT( 222, 8 ); + Hide = TRUE; + Text [ en-US ] = "The signatures in this document are invalid"; + }; + FixedImage IMG_STATE_NOTVALIDATED + { + Pos = MAP_APPFONT( 6, 127 ); + Size = MAP_APPFONT( 33, 22 ); + Fixed = Image + { + ImageBitmap = Bitmap { File = "notcertificate_16.png"; }; + MaskColor = STD_MASKCOLOR; + }; + }; + FixedText FI_STATE_NOTVALIDATED + { + Pos = MAP_APPFONT( 6, 127 ); + Size = MAP_APPFONT( 222, 8 ); + Hide = TRUE; + }; + PushButton BTN_VIEWCERT + { + Pos = MAP_APPFONT( 6, 142 ); + Size = MAP_APPFONT( 70, 14 ); + Text [ en-US ] = "View Certificate..."; + }; + PushButton BTN_ADDCERT + { + Pos = MAP_APPFONT( 82, 142 ); + Size = MAP_APPFONT( 70, 14 ); + Text [ en-US ] = "Sign Document..."; + }; + PushButton BTN_REMOVECERT + { + Pos = MAP_APPFONT( 158, 142 ); + Size = MAP_APPFONT( 70, 14 ); + Text [ en-US ] = "Remove"; + }; + FixedLine FL_BOTTOM_SEP + { + Pos = MAP_APPFONT( 0, 160 ); + Size = MAP_APPFONT( 234, 8 ); + }; + OKButton BTN_OK + { + DefButton = TRUE; + Pos = MAP_APPFONT( 178, 171 ); + Size = MAP_APPFONT( 50, 14 ); + Text [ en-US ] = "Close"; + }; + HelpButton BTN_HELP + { + Pos = MAP_APPFONT( 6, 171 ); + Size = MAP_APPFONT( 50, 14 ); + }; + Image IMG_STATE_VALID_HC + { + ImageBitmap = Bitmap { File = "signet_11x16_h.png"; }; + MaskColor = STD_MASKCOLOR; + }; + Image IMG_STATE_BROKEN_HC + { + ImageBitmap = Bitmap { File = "caution_11x16_h.png"; }; + MaskColor = STD_MASKCOLOR; + }; + Image IMG_STATE_NOTVALIDATED_HC + { + ImageBitmap = Bitmap { File = "notcertificate_16_h.png"; }; + MaskColor = STD_MASKCOLOR; + }; +}; + + +ErrorBox RID_XMLSECDLG_OLD_ODF_FORMAT +{ + Buttons = WB_OK ; + DefButton = WB_DEF_OK ; + Message [ en-US ] = + "This document contains signatures in ODF 1.1 (OpenOffice.org 2.x) format. " + "Signing documents in %PRODUCTNAME %PRODUCTVERSION requires ODF 1.2 format version. " + "Thus no signatures can be added or removed to this document.\n\n" + "Save document in ODF 1.2 format and add all desired signatures again."; +}; + + +QueryBox MSG_XMLSECDLG_QUERY_REMOVEDOCSIGNBEFORESIGN +{ + Buttons = WB_YES_NO ; + DefButton = WB_DEF_NO ; + Message [ en-US ] = "Adding or removing a macro signature will remove all document signatures.\n" + "Do you really want to continue?"; +}; + + diff --git a/xmlsecurity/source/dialogs/helpids.hrc b/xmlsecurity/source/dialogs/helpids.hrc new file mode 100644 index 000000000000..6456dddb47b9 --- /dev/null +++ b/xmlsecurity/source/dialogs/helpids.hrc @@ -0,0 +1,67 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _XMLSEC_HELPIDS_HRC +#define _XMLSEC_HELPIDS_HRC + +// include --------------------------------------------------------------- + +#include <svl/solar.hrc> + +// Help-Ids -------------------------------------------------------------- + +#define HID_XMLSEC_TP_MACROSEC (HID_XMLSECURITY_START + 0) +#define HID_XMLSEC_TP_SECLEVEL (HID_XMLSECURITY_START + 1) +#define HID_XMLSEC_TP_TRUSTSOURCES (HID_XMLSECURITY_START + 2) +#define HID_XMLSEC_DLG_CERTVIEWER (HID_XMLSECURITY_START + 3) +#define HID_XMLSEC_TP_GENERAL (HID_XMLSECURITY_START + 4) +#define HID_XMLSEC_TP_DETAILS (HID_XMLSECURITY_START + 5) +#define HID_XMLSEC_TP_CERTPATH (HID_XMLSECURITY_START + 6) +#define HID_XMLSEC_DLG_DIGSIG (HID_XMLSECURITY_START + 7) +#define HID_XMLSEC_TP_MACROWARN (HID_XMLSECURITY_START + 8) +#define HID_XMLSEC_DLG_CERTCHOOSER (HID_XMLSECURITY_START + 9) +#define HID_XMLSEC_CTRL_TRUSTSOURCES (HID_XMLSECURITY_START + 10) +#define HID_XMLSEC_CTRL_ELEMENTS (HID_XMLSECURITY_START + 11) +#define HID_XMLSEC_CTRL_VIEWSIGNATURES (HID_XMLSECURITY_START + 12) +#define HID_XMLSEC_CTRL_SIGNATURESDLG (HID_XMLSECURITY_START + 13) +#define HID_XMLSEC_CTRL_CHOOSESIGNATURES (HID_XMLSECURITY_START + 14) +#define HID_XMLSEC_TREE_SIGNATURESDLG (HID_XMLSECURITY_START + 15) + +// pb: please update ACT_XMLSECURITY_HID_END below, thx. + +// ----------------------------------------------------------------------- +// overflow check -------------------------------------------------------- +// ----------------------------------------------------------------------- + +#define ACT_XMLSECURITY_HID_END HID_XMLSEC_TREE_SIGNATURESDLG + +#if ACT_XMLSECURITY_HID_END > HID_XMLSECURITY_END +#error helpids overflow in #line, #file +#endif + +#endif // #ifndef _XMLSEC_HELPIDS_HRC + diff --git a/xmlsecurity/source/dialogs/macrosecurity.cxx b/xmlsecurity/source/dialogs/macrosecurity.cxx new file mode 100644 index 000000000000..0bee4e2011e7 --- /dev/null +++ b/xmlsecurity/source/dialogs/macrosecurity.cxx @@ -0,0 +1,469 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmlsecurity.hxx" + +#include <xmlsecurity/macrosecurity.hxx> +#include <xmlsecurity/certificatechooser.hxx> +#include <xmlsecurity/certificateviewer.hxx> +#include <xmlsecurity/biginteger.hxx> + +#include <osl/file.hxx> +#include <vcl/help.hxx> + + +#include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp> +#include <com/sun/star/security/SerialNumberAdapter.hpp> +#include <comphelper/sequence.hxx> +#include <sfx2/filedlghelper.hxx> +#include <svl/pickerhelper.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/XFolderPicker.hpp> +#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp> +#include <tools/urlobj.hxx> + +#include <vcl/msgbox.hxx> + +#include "dialogs.hrc" +#include "resourcemanager.hxx" + +/* HACK: disable some warnings for MS-C */ +#ifdef _MSC_VER +#pragma warning (disable : 4355) // 4355: this used in initializer-list +#endif + +using namespace ::com::sun::star; + + +IMPL_LINK( MacroSecurity, OkBtnHdl, void*, EMPTYARG ) +{ + mpLevelTP->ClosePage(); + mpTrustSrcTP->ClosePage(); + + EndDialog( RET_OK ); + + return 0; +} + +MacroSecurity::MacroSecurity( Window* _pParent, const cssu::Reference< cssu::XComponentContext> &_rxCtx, const cssu::Reference< dcss::xml::crypto::XSecurityEnvironment >& _rxSecurityEnvironment ) + :TabDialog ( _pParent, XMLSEC_RES( RID_XMLSECTP_MACROSEC ) ) + ,maTabCtrl ( this, XMLSEC_RES( 1 ) ) + ,maOkBtn ( this, XMLSEC_RES( BTN_OK ) ) + ,maCancelBtn ( this, XMLSEC_RES( BTN_CANCEL ) ) + ,maHelpBtn ( this, XMLSEC_RES( BTN_HELP ) ) + ,maResetBtn ( this, XMLSEC_RES( BTN_RESET ) ) +{ + FreeResource(); + + mxCtx = _rxCtx; + mxSecurityEnvironment = _rxSecurityEnvironment; + + mpLevelTP = new MacroSecurityLevelTP( &maTabCtrl, this ); + mpTrustSrcTP = new MacroSecurityTrustedSourcesTP( &maTabCtrl, this ); + + maTabCtrl.SetTabPage( RID_XMLSECTP_SECLEVEL, mpLevelTP ); + maTabCtrl.SetTabPage( RID_XMLSECTP_TRUSTSOURCES, mpTrustSrcTP ); + maTabCtrl.SetCurPageId( RID_XMLSECTP_SECLEVEL ); + + maOkBtn.SetClickHdl( LINK( this, MacroSecurity, OkBtnHdl ) ); +} + +MacroSecurity::~MacroSecurity() +{ + delete maTabCtrl.GetTabPage( RID_XMLSECTP_TRUSTSOURCES ); + delete maTabCtrl.GetTabPage( RID_XMLSECTP_SECLEVEL ); +} + + +MacroSecurityTP::MacroSecurityTP( Window* _pParent, const ResId& _rResId, MacroSecurity* _pDlg ) + :TabPage ( _pParent, _rResId ) + ,mpDlg ( _pDlg ) +{ +} + +MacroSecurityLevelTP::MacroSecurityLevelTP( Window* _pParent, MacroSecurity* _pDlg ) + :MacroSecurityTP ( _pParent, XMLSEC_RES( RID_XMLSECTP_SECLEVEL ), _pDlg ) + ,maSecLevelFL ( this, XMLSEC_RES( FL_SECLEVEL ) ) + ,maSecReadonlyFI ( this, XMLSEC_RES( FI_SEC_READONLY )) + ,maVeryHighRB ( this, XMLSEC_RES( RB_VERYHIGH ) ) + ,maHighRB ( this, XMLSEC_RES( RB_HIGH ) ) + ,maMediumRB ( this, XMLSEC_RES( RB_MEDIUM ) ) + ,maLowRB ( this, XMLSEC_RES( RB_LOW ) ) +{ + FreeResource(); + + maLowRB.SetClickHdl( LINK( this, MacroSecurityLevelTP, RadioButtonHdl ) ); + maMediumRB.SetClickHdl( LINK( this, MacroSecurityLevelTP, RadioButtonHdl ) ); + maHighRB.SetClickHdl( LINK( this, MacroSecurityLevelTP, RadioButtonHdl ) ); + maVeryHighRB.SetClickHdl( LINK( this, MacroSecurityLevelTP, RadioButtonHdl ) ); + + mnCurLevel = (USHORT) mpDlg->maSecOptions.GetMacroSecurityLevel(); + sal_Bool bReadonly = mpDlg->maSecOptions.IsReadOnly( SvtSecurityOptions::E_MACRO_SECLEVEL ); + + RadioButton* pCheck = 0; + switch( mnCurLevel ) + { + case 3: pCheck = &maVeryHighRB; break; + case 2: pCheck = &maHighRB; break; + case 1: pCheck = &maMediumRB; break; + case 0: pCheck = &maLowRB; break; + } + if(pCheck) + pCheck->Check(); + else + { + DBG_ERROR("illegal macro security level"); + } + maSecReadonlyFI.Show(bReadonly); + if(bReadonly) + { + //move to the selected button + if( pCheck && pCheck != &maVeryHighRB) + { + long nDiff = pCheck->GetPosPixel().Y() - maVeryHighRB.GetPosPixel().Y(); + Point aPos(maSecReadonlyFI.GetPosPixel()); + aPos.Y() += nDiff; + maSecReadonlyFI.SetPosPixel(aPos); + } + maVeryHighRB.Enable(sal_False); + maHighRB.Enable(sal_False); + maMediumRB.Enable(sal_False); + maLowRB.Enable(sal_False); + } + +} + +IMPL_LINK( MacroSecurityLevelTP, RadioButtonHdl, RadioButton*, EMPTYARG ) +{ + USHORT nNewLevel = 0; + if( maVeryHighRB.IsChecked() ) + nNewLevel = 3; + else if( maHighRB.IsChecked() ) + nNewLevel = 2; + else if( maMediumRB.IsChecked() ) + nNewLevel = 1; + + if ( nNewLevel != mnCurLevel ) + { + mnCurLevel = nNewLevel; + mpDlg->EnableReset(); + } + + return 0; +} + +void MacroSecurityLevelTP::ClosePage( void ) +{ + mpDlg->maSecOptions.SetMacroSecurityLevel( mnCurLevel ); +} + +void MacroSecurityTrustedSourcesTP::ImplCheckButtons() +{ + bool bCertSelected = maTrustCertLB.FirstSelected() != NULL; + maViewCertPB.Enable( bCertSelected ); + maRemoveCertPB.Enable( bCertSelected && !mbAuthorsReadonly); + + bool bLocationSelected = maTrustFileLocLB.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND; + maRemoveLocPB.Enable( bLocationSelected && !mbURLsReadonly); +} + + +IMPL_LINK( MacroSecurityTrustedSourcesTP, ViewCertPBHdl, void*, EMPTYARG ) +{ + if( maTrustCertLB.FirstSelected() ) + { + USHORT nSelected = USHORT( sal_uIntPtr( maTrustCertLB.FirstSelected()->GetUserData() ) ); + + uno::Reference< dcss::security::XSerialNumberAdapter > xSerialNumberAdapter = + ::com::sun::star::security::SerialNumberAdapter::create(mpDlg->mxCtx); + + uno::Reference< dcss::security::XCertificate > xCert = mpDlg->mxSecurityEnvironment->getCertificate( maTrustedAuthors[nSelected][0], xSerialNumberAdapter->toSequence( maTrustedAuthors[nSelected][1] ) ); + + // If we don't get it, create it from signature data: + if ( !xCert.is() ) + xCert = mpDlg->mxSecurityEnvironment->createCertificateFromAscii( maTrustedAuthors[nSelected][2] ) ; + + DBG_ASSERT( xCert.is(), "*MacroSecurityTrustedSourcesTP::ViewCertPBHdl(): Certificate not found and can't be created!" ); + + if ( xCert.is() ) + { + CertificateViewer aViewer( this, mpDlg->mxSecurityEnvironment, xCert, FALSE ); + aViewer.Execute(); + } + } + return 0; +} + +IMPL_LINK( MacroSecurityTrustedSourcesTP, RemoveCertPBHdl, void*, EMPTYARG ) +{ + if( maTrustCertLB.FirstSelected() ) + { + USHORT nAuthor = USHORT( sal_uIntPtr( maTrustCertLB.FirstSelected()->GetUserData() ) ); + ::comphelper::removeElementAt( maTrustedAuthors, nAuthor ); + + FillCertLB(); + ImplCheckButtons(); + } + + return 0; +} + +IMPL_LINK( MacroSecurityTrustedSourcesTP, AddLocPBHdl, void*, EMPTYARG ) +{ + try + { + rtl::OUString aService( RTL_CONSTASCII_USTRINGPARAM( FOLDER_PICKER_SERVICE_NAME ) ); + uno::Reference < lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() ); + uno::Reference < ui::dialogs::XFolderPicker > xFolderPicker( xFactory->createInstance( aService ), uno::UNO_QUERY ); + + short nRet = xFolderPicker->execute(); + + if( ui::dialogs::ExecutableDialogResults::OK != nRet ) + return 0; + + rtl::OUString aPathStr = xFolderPicker->getDirectory(); + INetURLObject aNewObj( aPathStr ); + aNewObj.removeFinalSlash(); + + // then the new path also an URL else system path + ::rtl::OUString aSystemFileURL = ( aNewObj.GetProtocol() != INET_PROT_NOT_VALID ) ? + aPathStr : aNewObj.getFSysPath( INetURLObject::FSYS_DETECT ); + + String aNewPathStr(aSystemFileURL); + + if ( osl::FileBase::getSystemPathFromFileURL( aSystemFileURL, aSystemFileURL ) == osl::FileBase::E_None ) + aNewPathStr = aSystemFileURL; + + if( maTrustFileLocLB.GetEntryPos( aNewPathStr ) == LISTBOX_ENTRY_NOTFOUND ) + { + maTrustFileLocLB.InsertEntry( aNewPathStr ); + } + + ImplCheckButtons(); + } + catch( uno::Exception& ) + { + DBG_ERRORFILE( "MacroSecurityTrustedSourcesTP::AddLocPBHdl(): exception from folder picker" ); + } + + return 0; +} + +IMPL_LINK( MacroSecurityTrustedSourcesTP, RemoveLocPBHdl, void*, EMPTYARG ) +{ + USHORT nSel = maTrustFileLocLB.GetSelectEntryPos(); + if( nSel != LISTBOX_ENTRY_NOTFOUND ) + { + maTrustFileLocLB.RemoveEntry( nSel ); + // --> PB 2004-09-21 #i33584# + // after remove an entry, select another one if exists + USHORT nNewCount = maTrustFileLocLB.GetEntryCount(); + if ( nNewCount > 0 ) + { + if ( nSel >= nNewCount ) + nSel = nNewCount - 1; + maTrustFileLocLB.SelectEntryPos( nSel ); + } + // <-- + ImplCheckButtons(); + } + + return 0; +} + +IMPL_LINK( MacroSecurityTrustedSourcesTP, TrustCertLBSelectHdl, void*, EMPTYARG ) +{ + ImplCheckButtons(); + return 0; +} + +IMPL_LINK( MacroSecurityTrustedSourcesTP, TrustFileLocLBSelectHdl, void*, EMPTYARG ) +{ + ImplCheckButtons(); + return 0; +} + +void MacroSecurityTrustedSourcesTP::FillCertLB( void ) +{ + maTrustCertLB.Clear(); + + sal_uInt32 nEntries = maTrustedAuthors.getLength(); + + if ( nEntries && mpDlg->mxSecurityEnvironment.is() ) + { + for( sal_uInt32 nEntry = 0 ; nEntry < nEntries ; ++nEntry ) + { + cssu::Sequence< ::rtl::OUString >& rEntry = maTrustedAuthors[ nEntry ]; + uno::Reference< css::security::XCertificate > xCert; + + // create from RawData + xCert = mpDlg->mxSecurityEnvironment->createCertificateFromAscii( rEntry[ 2 ] ); + + SvLBoxEntry* pLBEntry = maTrustCertLB.InsertEntry( XmlSec::GetContentPart( xCert->getSubjectName() ) ); + maTrustCertLB.SetEntryText( XmlSec::GetContentPart( xCert->getIssuerName() ), pLBEntry, 1 ); + maTrustCertLB.SetEntryText( XmlSec::GetDateTimeString( xCert->getNotValidAfter() ), pLBEntry, 2 ); + pLBEntry->SetUserData( ( void* ) sal_Int32( nEntry ) ); // missuse user data as index + } + } +} + +MacroSecurityTrustedSourcesTP::MacroSecurityTrustedSourcesTP( Window* _pParent, MacroSecurity* _pDlg ) + :MacroSecurityTP ( _pParent, XMLSEC_RES( RID_XMLSECTP_TRUSTSOURCES ), _pDlg ) + ,maTrustCertFL ( this, XMLSEC_RES( FL_TRUSTCERT ) ) + ,maTrustCertROFI ( this, XMLSEC_RES( FI_TRUSTCERT_RO ) ) + ,maTrustCertLB ( this, XMLSEC_RES( LB_TRUSTCERT ) ) + ,maAddCertPB ( this, XMLSEC_RES( PB_ADD_TRUSTCERT ) ) + ,maViewCertPB ( this, XMLSEC_RES( PB_VIEW_TRUSTCERT ) ) + ,maRemoveCertPB ( this, XMLSEC_RES( PB_REMOVE_TRUSTCERT ) ) + ,maTrustFileLocFL ( this, XMLSEC_RES( FL_TRUSTFILELOC ) ) + ,maTrustFileROFI ( this, XMLSEC_RES( FI_TRUSTFILE_RO ) ) + ,maTrustFileLocFI ( this, XMLSEC_RES( FI_TRUSTFILELOC ) ) + ,maTrustFileLocLB ( this, XMLSEC_RES( LB_TRUSTFILELOC ) ) + ,maAddLocPB ( this, XMLSEC_RES( FL_ADD_TRUSTFILELOC ) ) + ,maRemoveLocPB ( this, XMLSEC_RES( FL_REMOVE_TRUSTFILELOC ) ) +{ + static long nTabs[] = { 3, 0, 35*CS_LB_WIDTH/100, 70*CS_LB_WIDTH/100 }; + maTrustCertLB.SetTabs( &nTabs[ 0 ] ); + maTrustCertLB.InsertHeaderEntry( String( XMLSEC_RES( STR_HEADERBAR ) ) ); + + FreeResource(); + + maTrustCertLB.SetSelectHdl( LINK( this, MacroSecurityTrustedSourcesTP, TrustCertLBSelectHdl ) ); + maAddCertPB.Hide(); // not used in the moment... + maViewCertPB.SetClickHdl( LINK( this, MacroSecurityTrustedSourcesTP, ViewCertPBHdl ) ); + maViewCertPB.Disable(); + maRemoveCertPB.SetClickHdl( LINK( this, MacroSecurityTrustedSourcesTP, RemoveCertPBHdl ) ); + maRemoveCertPB.Disable(); + + maTrustFileLocLB.SetSelectHdl( LINK( this, MacroSecurityTrustedSourcesTP, TrustFileLocLBSelectHdl ) ); + maAddLocPB.SetClickHdl( LINK( this, MacroSecurityTrustedSourcesTP, AddLocPBHdl ) ); + maRemoveLocPB.SetClickHdl( LINK( this, MacroSecurityTrustedSourcesTP, RemoveLocPBHdl ) ); + maRemoveLocPB.Disable(); + + maTrustedAuthors = mpDlg->maSecOptions.GetTrustedAuthors(); + mbAuthorsReadonly = mpDlg->maSecOptions.IsReadOnly( SvtSecurityOptions::E_MACRO_TRUSTEDAUTHORS ); + maTrustCertROFI.Show( mbAuthorsReadonly ); + mbAuthorsReadonly ? maTrustCertLB.DisableTable() : maTrustCertLB.EnableTable(); +// unused button +// maAddCertPB.Enable( !mbAuthorsReadonly ); + + FillCertLB(); + + cssu::Sequence< rtl::OUString > aSecureURLs = mpDlg->maSecOptions.GetSecureURLs(); + mbURLsReadonly = mpDlg->maSecOptions.IsReadOnly( SvtSecurityOptions::E_SECUREURLS ); + maTrustFileROFI.Show( mbURLsReadonly ); + maTrustFileLocLB.Enable( !mbURLsReadonly ); + maAddLocPB .Enable( !mbURLsReadonly ); + + sal_Int32 nEntryCnt = aSecureURLs.getLength(); + for( sal_Int32 i = 0 ; i < nEntryCnt ; ++i ) + { + ::rtl::OUString aSystemFileURL( aSecureURLs[ i ] ); + osl::FileBase::getSystemPathFromFileURL( aSystemFileURL, aSystemFileURL ); + maTrustFileLocLB.InsertEntry( aSystemFileURL ); + } +} + +void MacroSecurityTrustedSourcesTP::ActivatePage() +{ + mpDlg->EnableReset( false ); + FillCertLB(); +} + +void MacroSecurityTrustedSourcesTP::ClosePage( void ) +{ + USHORT nEntryCnt = maTrustFileLocLB.GetEntryCount(); + if( nEntryCnt ) + { + cssu::Sequence< rtl::OUString > aSecureURLs( nEntryCnt ); + for( USHORT i = 0 ; i < nEntryCnt ; ++i ) + { + ::rtl::OUString aURL( maTrustFileLocLB.GetEntry( i ) ); + osl::FileBase::getFileURLFromSystemPath( aURL, aURL ); + aSecureURLs[ i ] = aURL; + } + + mpDlg->maSecOptions.SetSecureURLs( aSecureURLs ); + } + // --> PB 2004-09-21 #i33584# + // don't forget to remove the old saved SecureURLs + else + mpDlg->maSecOptions.SetSecureURLs( cssu::Sequence< rtl::OUString >() ); + // <-- + + mpDlg->maSecOptions.SetTrustedAuthors( maTrustedAuthors ); +} +/*-- 26.02.2004 13:31:04--------------------------------------------------- + + -----------------------------------------------------------------------*/ +ReadOnlyImage::ReadOnlyImage(Window* pParent, const ResId rResId) : + FixedImage(pParent, rResId) +{ + sal_Bool bHighContrast = pParent->GetSettings().GetStyleSettings().GetHighContrastMode(); + SetImage( Image(XMLSEC_RES( bHighContrast ? RID_XMLSECTP_LOCK_HC : RID_XMLSECTP_LOCK ))); +} + +/*-- 26.02.2004 13:31:04--------------------------------------------------- + + -----------------------------------------------------------------------*/ +ReadOnlyImage::~ReadOnlyImage() +{ +} +/*-- 26.02.2004 13:31:04--------------------------------------------------- + + -----------------------------------------------------------------------*/ +void ReadOnlyImage::RequestHelp( const HelpEvent& rHEvt ) +{ + if( Help::IsBalloonHelpEnabled() || Help::IsQuickHelpEnabled() ) + { + Rectangle aLogicPix( LogicToPixel( Rectangle( Point(), GetOutputSize() ) ) ); + Rectangle aScreenRect( OutputToScreenPixel( aLogicPix.TopLeft() ), + OutputToScreenPixel( aLogicPix.BottomRight() ) ); + + String aStr(ReadOnlyImage::GetHelpTip()); + if ( Help::IsBalloonHelpEnabled() ) + Help::ShowBalloon( this, rHEvt.GetMousePosPixel(), aScreenRect, + aStr ); + else if ( Help::IsQuickHelpEnabled() ) + Help::ShowQuickHelp( this, aScreenRect, aStr ); + } + else + Window::RequestHelp( rHEvt ); +} + +/*-- 26.02.2004 14:20:21--------------------------------------------------- + + -----------------------------------------------------------------------*/ +const String& ReadOnlyImage::GetHelpTip() +{ + static String aStr(XMLSEC_RES( RID_XMLSECTP_READONLY_CONFIG_TIP)); + return aStr; +} + diff --git a/xmlsecurity/source/dialogs/macrosecurity.src b/xmlsecurity/source/dialogs/macrosecurity.src new file mode 100644 index 000000000000..0683606f500c --- /dev/null +++ b/xmlsecurity/source/dialogs/macrosecurity.src @@ -0,0 +1,240 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "dialogs.hrc" +#include "helpids.hrc" + +TabDialog RID_XMLSECTP_MACROSEC +{ + HelpID = HID_XMLSEC_TP_MACROSEC; + Size = MAP_APPFONT( TD_WIDTH, TD_HEIGHT ); + OutputSize = TRUE; + Closeable = TRUE; + Moveable = TRUE; + SVLook = TRUE; + + Text [ en-US ] = "Macro Security"; + TabControl 1 + { + Pos = MAP_APPFONT( TD_SP_INNERBORDER_LEFT, TD_SP_INNERBORDER_TOP ); + Size = MAP_APPFONT( TP_WIDTH, TP_HEIGHT+RIDDER_HEIGHT ); + SVLook = TRUE ; + PageList = + { + PageItem + { + Identifier = RID_XMLSECTP_SECLEVEL; + Text [ en-US ] = "Security Level"; + }; + PageItem + { + Identifier = RID_XMLSECTP_TRUSTSOURCES; + Text [ en-US ] = "Trusted Sources"; + }; + }; + }; + OKButton BTN_OK + { + Pos = MAP_APPFONT( MS_COL_H, CV_ROW_A ); + Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT ); + DefButton = TRUE; + }; + CancelButton BTN_CANCEL + { + Pos = MAP_APPFONT( MS_COL_F, CV_ROW_A ); + Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT ); + }; + HelpButton BTN_HELP + { + Pos = MAP_APPFONT( MS_COL_D, CV_ROW_A ); + Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT ); + }; + PushButton BTN_RESET + { + Pos = MAP_APPFONT( MS_COL_B, CV_ROW_A ); + Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT ); + Text [ en-US ] = "Reset"; + }; +}; + +TabPage RID_XMLSECTP_SECLEVEL +{ + HelpId = HID_XMLSEC_TP_SECLEVEL; + Size = MAP_APPFONT( TP_WIDTH, TP_HEIGHT ); + OutputSize = TRUE; + Hide = TRUE; + SVLook = TRUE; + FixedLine FL_SECLEVEL + { + Pos = MAP_APPFONT( SL_COL_0, SL_ROW_0 ); + Size = MAP_APPFONT( SL_COL_3-SL_COL_0, RSC_CD_FIXEDLINE_HEIGHT ); + Hide = TRUE; + }; + FixedImage FI_SEC_READONLY + { + Pos = MAP_APPFONT( SL_COL_1 - 7, SL_ROW_0 + 4 ); + Size = MAP_APPFONT( 6, 6 ); + }; + RadioButton RB_VERYHIGH + { + Pos = MAP_APPFONT( SL_COL_1, SL_ROW_0 ); + Size = MAP_APPFONT( SL_COL_2-SL_COL_1, RSC_BIG_RADIOBUTTON ); + WordBreak = TRUE; + Text [ en-US ] = "~Very high.\nOnly macros from trusted file locations are allowed to run. All other macros, regardless whether signed or not, are disabled."; + }; + RadioButton RB_HIGH + { + Pos = MAP_APPFONT( SL_COL_1, SL_ROW_1 ); + Size = MAP_APPFONT( SL_COL_2-SL_COL_1, RSC_BIG_RADIOBUTTON ); + WordBreak = TRUE; + Text [ en-US ] = "H~igh.\nOnly signed macros from trusted sources are allowed to run. Unsigned macros are disabled."; + }; + RadioButton RB_MEDIUM + { + Pos = MAP_APPFONT( SL_COL_1, SL_ROW_2 ); + Size = MAP_APPFONT( SL_COL_2-SL_COL_1, RSC_BIG_RADIOBUTTON ); + WordBreak = TRUE; + Text [ en-US ] = "~Medium.\nConfirmation required before executing macros from untrusted sources."; + }; + RadioButton RB_LOW + { + Pos = MAP_APPFONT( SL_COL_1, SL_ROW_3 ); + Size = MAP_APPFONT( SL_COL_2-SL_COL_1, SL_ROW_4-SL_ROW_3 ); + WordBreak = TRUE; + Text [ en-US ] = "~Low (not recommended).\nAll macros will be executed without confirmation. Use this setting only if you are certain that all documents that will be opened are safe."; + }; +}; + +TabPage RID_XMLSECTP_TRUSTSOURCES +{ + HelpId = HID_XMLSEC_TP_TRUSTSOURCES; + Size = MAP_APPFONT( TP_WIDTH, TP_HEIGHT ); + OutputSize = TRUE; + Hide = TRUE; + SVLook = TRUE; + FixedLine FL_TRUSTCERT + { + Pos = MAP_APPFONT( TS_COL_0, TS_ROW_0 ); + Size = MAP_APPFONT( TS_COL_8-TS_COL_0, RSC_CD_FIXEDLINE_HEIGHT ); + Text [ en-US ] = "Trusted certificates"; + }; + FixedImage FI_TRUSTCERT_RO + { + Pos = MAP_APPFONT( TS_COL_1 - 7, TS_ROW_1 ); + Size = MAP_APPFONT( 6, 6 ); + }; + Control LB_TRUSTCERT + { + HelpId = HID_XMLSEC_CTRL_TRUSTSOURCES; + Pos = MAP_APPFONT( TS_COL_1, TS_ROW_1 ); + Size = MAP_APPFONT( TS_COL_7-TS_COL_1, RSC_CD_TABLISTBOX_HEIGHT ); + SVLook = TRUE; + Border = TRUE; + }; + String STR_HEADERBAR + { + Text [ en-US ] = "Issued to\tIssued by\tExpiration date"; + }; + PushButton PB_ADD_TRUSTCERT + { + Pos = MAP_APPFONT( TS_COL_2, TS_ROW_2 ); + Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT ); + Text [ en-US ] = "Add..."; + }; + PushButton PB_VIEW_TRUSTCERT + { + Pos = MAP_APPFONT( TS_COL_4, TS_ROW_2 ); + Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT ); + Text [ en-US ] = "View..."; + }; + PushButton PB_REMOVE_TRUSTCERT + { + Pos = MAP_APPFONT( TS_COL_6, TS_ROW_2 ); + Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT ); + Text [ en-US ] = "Remove"; + }; + FixedLine FL_TRUSTFILELOC + { + Pos = MAP_APPFONT( TS_COL_0, TS_ROW_3 ); + Size = MAP_APPFONT( TS_COL_8-TS_COL_0, RSC_CD_FIXEDLINE_HEIGHT ); + Text [ en-US ] = "Trusted file locations"; + }; + FixedText FI_TRUSTFILELOC + { + Pos = MAP_APPFONT( TS_COL_1, TS_ROW_4 ); + Size = MAP_APPFONT( TS_COL_7-TS_COL_1, 3*RSC_CD_FIXEDLINE_HEIGHT ); + WordBreak = TRUE; + Text [ en-US ] = "Document macros are always executed if they have been opened from one of the following locations."; + }; + FixedImage FI_TRUSTFILE_RO + { + Pos = MAP_APPFONT( TS_COL_1 - 7, TS_ROW_5 ); + Size = MAP_APPFONT( 6, 6 ); + }; + ListBox LB_TRUSTFILELOC + { + Pos = MAP_APPFONT( TS_COL_1, TS_ROW_5 ); + Size = MAP_APPFONT( TS_COL_7-TS_COL_1, TS_ROW_6-TS_ROW_5 ); + SVLook = TRUE; + Border = TRUE; + VScroll = TRUE; + Sort = TRUE; + }; + PushButton FL_ADD_TRUSTFILELOC + { + Pos = MAP_APPFONT( TS_COL_4, TS_ROW_7 ); + Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT ); + Text [ en-US ] = "Add..."; + }; + PushButton FL_REMOVE_TRUSTFILELOC + { + Pos = MAP_APPFONT( TS_COL_6, TS_ROW_7 ); + Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT ); + Text [ en-US ] = "Remove"; + }; +}; +String RID_XMLSECTP_READONLY_CONFIG_TIP +{ + Text [ en-US ] = "This setting is protected by the Administrator"; +}; +Image RID_XMLSECTP_LOCK +{ + ImageBitmap = Bitmap + { + File = "lock.bmp"; + }; + MaskColor = Color { Red=0xffff; Green=0x0000; Blue=0xffff; }; +}; +Image RID_XMLSECTP_LOCK_HC +{ + ImageBitmap = Bitmap + { + File = "lock_hc.bmp"; + }; + MaskColor = Color { Red=0xffff; Green=0x0000; Blue=0xffff; }; +}; + diff --git a/xmlsecurity/source/dialogs/makefile.mk b/xmlsecurity/source/dialogs/makefile.mk new file mode 100644 index 000000000000..4cead130d887 --- /dev/null +++ b/xmlsecurity/source/dialogs/makefile.mk @@ -0,0 +1,64 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=xmlsecurity +TARGET=dialogs +TARGETTYPE=GUI + + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk +.INCLUDE : $(PRJ)$/util$/target.pmk + + +# --- Files -------------------------------------------------------- + +BMP_IN=$(PRJ)$/res + +SRS1NAME=dialogs +SRC1FILES = \ + digitalsignaturesdialog.src \ + certificatechooser.src \ + certificateviewer.src \ + macrosecurity.src + +SLOFILES= \ + $(SLO)$/digitalsignaturesdialog.obj \ + $(SLO)$/certificatechooser.obj \ + $(SLO)$/certificateviewer.obj \ + $(SLO)$/macrosecurity.obj \ + $(SLO)$/resourcemanager.obj + + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk diff --git a/xmlsecurity/source/dialogs/resourcemanager.cxx b/xmlsecurity/source/dialogs/resourcemanager.cxx new file mode 100644 index 000000000000..e41cf546f74f --- /dev/null +++ b/xmlsecurity/source/dialogs/resourcemanager.cxx @@ -0,0 +1,431 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmlsecurity.hxx" + +#include "resourcemanager.hxx" + +#include <vcl/svapp.hxx> +#include <vcl/fixed.hxx> +#include <svtools/stdctrl.hxx> +#include <svl/solar.hrc> +#include <unotools/syslocale.hxx> +#include <rtl/ustring.h> +#include <rtl/ustrbuf.h> +#include <vector> + +using ::rtl::OUString; +using namespace std; + +namespace XmlSec +{ + static ResMgr* pResMgr = 0; + static SvtSysLocale* pSysLocale = 0; + + ResMgr* GetResMgr( void ) + { + if( !pResMgr ) + { + ByteString aName( "xmlsec" ); +// pResMgr = ResMgr::CreateResMgr( aName.GetBuffer(), Application::GetSettings().GetUILanguage() ); +// LanguageType aLang( LANGUAGE_ENGLISH_US ); +// pResMgr = ResMgr::CreateResMgr( aName.GetBuffer(), aLang ); +// MT: Change to Locale + pResMgr = ResMgr::CreateResMgr( aName.GetBuffer() ); + } + + return pResMgr; + } + + const LocaleDataWrapper& GetLocaleData( void ) + { + if (!pSysLocale) + pSysLocale = new SvtSysLocale; + return pSysLocale->GetLocaleData(); + } + + DateTime GetDateTime( const ::com::sun::star::util::DateTime& _rDT ) + { + return DateTime( + Date( _rDT.Day, _rDT.Month, _rDT.Year ), + Time( _rDT.Hours, _rDT.Minutes, _rDT.Seconds, _rDT.HundredthSeconds ) ); + } + + String GetDateTimeString( const ::com::sun::star::util::DateTime& _rDT ) + { + // --> PB 2004-10-12 #i20172# String with date and time information + DateTime aDT( GetDateTime( _rDT ) ); + const LocaleDataWrapper& rLoDa = GetLocaleData(); + String sRet( rLoDa.getDate( aDT ) ); + sRet += ' '; + sRet += rLoDa.getTime( aDT ); + return sRet; + } + + String GetDateTimeString( const rtl::OUString& _rDate, const rtl::OUString& _rTime ) + { + String sDay( _rDate, 6, 2 ); + String sMonth( _rDate, 4, 2 ); + String sYear( _rDate, 0, 4 ); + + String sHour( _rTime, 0, 2 ); + String sMin( _rTime, 4, 2 ); + String sSec( _rTime, 6, 2 ); + + + Date aDate( (USHORT)sDay.ToInt32(), (USHORT) sMonth.ToInt32(), (USHORT)sYear.ToInt32() ); + Time aTime( sHour.ToInt32(), sMin.ToInt32(), sSec.ToInt32(), 0 ); + const LocaleDataWrapper& rLoDa = GetLocaleData(); + String aStr( rLoDa.getDate( aDate ) ); + aStr.AppendAscii( " " ); + aStr += rLoDa.getTime( aTime ); + return aStr; + } + + String GetDateString( const ::com::sun::star::util::DateTime& _rDT ) + { + return GetLocaleData().getDate( GetDateTime( _rDT ) ); + } + + /* + Creates two strings based on the distinguished name which are displayed in the + certificate details view. The first string contains only the values of the attribute + and valudes pairs, which are separated by commas. All escape characters ('"') are + removed. + The second string is for the details view at the bottom. It shows the attribute/value + pairs on different lines. All escape characters ('"') are removed. + */ + pair< OUString, OUString> GetDNForCertDetailsView( const OUString & rRawString) + { + vector< pair< OUString, OUString > > vecAttrValueOfDN = parseDN(rRawString); + ::rtl::OUStringBuffer s1, s2; + OUString sEqual(RTL_CONSTASCII_USTRINGPARAM(" = ")); + typedef vector< pair < OUString, OUString > >::const_iterator CIT; + for (CIT i = vecAttrValueOfDN.begin(); i < vecAttrValueOfDN.end(); i ++) + { + if (i != vecAttrValueOfDN.begin()) + { + s1.append(static_cast<sal_Unicode>(',')); + s2.append(static_cast<sal_Unicode>('\n')); + } + s1.append(i->second); + s2.append(i->first); + s2.append(sEqual); + s2.append(i->second); + } + return make_pair(s1.makeStringAndClear(), s2.makeStringAndClear()); + } + +/* + Whenever the attribute value contains special characters, such as '"' or ',' (without '') + then the value will be enclosed in double quotes by the respective Windows or NSS function + which we use to retrieve, for example, the subject name. If double quotes appear in the value then + they are escaped with a double quote. This function removes the escape characters. +*/ +#ifdef WNT +vector< pair< OUString, OUString> > parseDN(const OUString& rRawString) +{ + vector< pair<OUString, OUString> > retVal; + bool bInEscape = false; + bool bInValue = false; + bool bInType = true; + sal_Int32 nTypeNameStart = 0; + OUString sType; + ::rtl::OUStringBuffer sbufValue; + sal_Int32 length = rRawString.getLength(); + + for (sal_Int32 i = 0; i < length; i++) + { + sal_Unicode c = rRawString[i]; + + if (c == '=') + { + if (! bInValue) + { + sType = rRawString.copy(nTypeNameStart, i - nTypeNameStart); + sType = sType.trim(); + bInType = false; + } + else + { + sbufValue.append(c); + } + } + else if (c == '"') + { + if (!bInEscape) + { + //If this is the quote is the first of the couple which enclose the + //whole value, because the value contains special characters + //then we just drop it. That is, this character must be followed by + //a character which is not '"'. + if ( i + 1 < length && rRawString[i+1] == '"') + bInEscape = true; + else + bInValue = !bInValue; //value is enclosed in " " + } + else + { + //This quote is escaped by a preceding quote and therefore is + //part of the value + sbufValue.append(c); + bInEscape = false; + } + } + else if (c == ',' || c == '+') + { + //The comma separate the attribute value pairs. + //If the comma is not part of a value (the value would then be enclosed in '"'), + //then we have reached the end of the value + if (!bInValue) + { + OSL_ASSERT(sType.getLength()); + retVal.push_back(make_pair(sType, sbufValue.makeStringAndClear())); + sType = OUString(); + //The next char is the start of the new type + nTypeNameStart = i + 1; + bInType = true; + } + else + { + //The whole string is enclosed because it contains special characters. + //The enclosing '"' are not part of certificate but will be added by + //the function (Windows or NSS) which retrieves DN + sbufValue.append(c); + } + } + else + { + if (!bInType) + sbufValue.append(c); + } + } + if (sbufValue.getLength()) + { + OSL_ASSERT(sType.getLength()); + retVal.push_back(make_pair(sType, sbufValue.makeStringAndClear())); + } + return retVal; + } +#else +vector< pair< OUString, OUString> > parseDN(const OUString& rRawString) + { + vector< pair<OUString, OUString> > retVal; + //bInEscape == true means that the preceding character is an escape character + bool bInEscape = false; + bool bInValue = false; + bool bInType = true; + sal_Int32 nTypeNameStart = 0; + OUString sType; + ::rtl::OUStringBuffer sbufValue; + sal_Int32 length = rRawString.getLength(); + + for (sal_Int32 i = 0; i < length; i++) + { + sal_Unicode c = rRawString[i]; + + if (c == '=') + { + if (! bInValue) + { + sType = rRawString.copy(nTypeNameStart, i - nTypeNameStart); + sType = sType.trim(); + bInType = false; + } + else + { + sbufValue.append(c); + } + } + else if (c == '\\') + { + if (!bInEscape) + { + bInEscape = true; + } + else + { // bInEscape is true + sbufValue.append(c); + bInEscape = false; + } + } + else if (c == '"') + { + //an unescaped '"' is either at the beginning or end of the value + if (!bInEscape) + { + if ( !bInValue) + bInValue = true; + else if (bInValue) + bInValue = false; + } + else + { + //This quote is escaped by a preceding quote and therefore is + //part of the value + sbufValue.append(c); + bInEscape = false; + } + } + else if (c == ',' || c == '+') + { + //The comma separate the attribute value pairs. + //If the comma is not part of a value (the value would then be enclosed in '"'), + //then we have reached the end of the value + if (!bInValue) + { + OSL_ASSERT(sType.getLength()); + retVal.push_back(make_pair(sType, sbufValue.makeStringAndClear())); + sType = OUString(); + //The next char is the start of the new type + nTypeNameStart = i + 1; + bInType = true; + } + else + { + //The whole string is enclosed because it contains special characters. + //The enclosing '"' are not part of certificate but will be added by + //the function (Windows or NSS) which retrieves DN + sbufValue.append(c); + } + } + else + { + if (!bInType) + { + sbufValue.append(c); + bInEscape = false; + } + } + } + if (sbufValue.getLength()) + { + OSL_ASSERT(sType.getLength()); + retVal.push_back(make_pair(sType, sbufValue.makeStringAndClear())); + } + return retVal; + } + +#endif + + String GetContentPart( const String& _rRawString ) + { + char const * aIDs[] = { "CN", "OU", "O", "E", NULL }; + OUString retVal; + int i = 0; + vector< pair< OUString, OUString > > vecAttrValueOfDN = parseDN(_rRawString); + while ( aIDs[i] ) + { + OUString sPartId = OUString::createFromAscii( aIDs[i++] ); + typedef vector< pair < OUString, OUString > >::const_iterator CIT; + for (CIT idn = vecAttrValueOfDN.begin(); idn != vecAttrValueOfDN.end(); idn++) + { + if (idn->first.equals(sPartId)) + { + retVal = idn->second; + break; + } + } + if (retVal.getLength()) + break; + } + return retVal; + } + + String GetHexString( const ::com::sun::star::uno::Sequence< sal_Int8 >& _rSeq, const char* _pSep, UINT16 _nLineBreak ) + { + const sal_Int8* pSerNumSeq = _rSeq.getConstArray(); + int nCnt = _rSeq.getLength(); + String aStr; + const char pHexDigs[ 17 ] = "0123456789ABCDEF"; + char pBuffer[ 3 ] = " "; + UINT8 nNum; + UINT16 nBreakStart = _nLineBreak? _nLineBreak : 1; + UINT16 nBreak = nBreakStart; + for( int i = 0 ; i < nCnt ; ++i ) + { + nNum = UINT8( pSerNumSeq[ i ] ); + + //MM : exchange the buffer[0] and buffer[1], which make it consistent with Mozilla and Windows + pBuffer[ 1 ] = pHexDigs[ nNum & 0x0F ]; + nNum >>= 4; + pBuffer[ 0 ] = pHexDigs[ nNum ]; + aStr.AppendAscii( pBuffer ); + + --nBreak; + if( nBreak ) + aStr.AppendAscii( _pSep ); + else + { + nBreak = nBreakStart; + aStr.AppendAscii( "\n" ); + } + } + + return aStr; + } + + long ShrinkToFitWidth( Control& _rCtrl, long _nOffs ) + { + long nWidth = _rCtrl.GetTextWidth( _rCtrl.GetText() ); + Size aSize( _rCtrl.GetSizePixel() ); + nWidth += _nOffs; + aSize.Width() = nWidth; + _rCtrl.SetSizePixel( aSize ); + return nWidth; + } + + void AlignAfterImage( const FixedImage& _rImage, Control& _rCtrl, long _nXOffset ) + { + Point aPos( _rImage.GetPosPixel() ); + Size aSize( _rImage.GetSizePixel() ); + long n = aPos.X(); + n += aSize.Width(); + n += _nXOffset; + aPos.X() = n; + n = aPos.Y(); + n += aSize.Height() / 2; // y-position is in the middle of the image + n -= _rCtrl.GetSizePixel().Height() / 2; // center Control + aPos.Y() = n; + _rCtrl.SetPosPixel( aPos ); + } + + void AlignAfterImage( const FixedImage& _rImage, FixedInfo& _rFI, long _nXOffset ) + { + AlignAfterImage( _rImage, static_cast< Control& >( _rFI ), _nXOffset ); + ShrinkToFitWidth( _rFI ); + } + + void AlignAndFitImageAndControl( FixedImage& _rImage, FixedInfo& _rFI, long _nXOffset ) + { + _rImage.SetSizePixel( _rImage.GetImage().GetSizePixel() ); + AlignAfterImage( _rImage, _rFI, _nXOffset ); + } +} + + diff --git a/xmlsecurity/source/dialogs/resourcemanager.hxx b/xmlsecurity/source/dialogs/resourcemanager.hxx new file mode 100644 index 000000000000..9ca06d17d0b5 --- /dev/null +++ b/xmlsecurity/source/dialogs/resourcemanager.hxx @@ -0,0 +1,69 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _RESOURCEMANAGER_HXX +#define _RESOURCEMANAGER_HXX + +#include <tools/resmgr.hxx> +#include <tools/datetime.hxx> +#include <com/sun/star/util/DateTime.hpp> +#include <com/sun/star/uno/Sequence.hxx> + +#include <vector> + +class FixedImage; +class FixedInfo; +class Control; +class LocaleDataWrapper; + +namespace XmlSec +{ + ResMgr* GetResMgr( void ); + + const LocaleDataWrapper& GetLocaleData( void ); + DateTime GetDateTime( const ::com::sun::star::util::DateTime& _rDT ); + String GetDateTimeString( const ::com::sun::star::util::DateTime& _rDT ); + String GetDateTimeString( const rtl::OUString& _rDate, const rtl::OUString& _rTime ); + String GetDateString( const ::com::sun::star::util::DateTime& _rDT ); + + std::vector< std::pair< ::rtl::OUString, ::rtl::OUString> > + parseDN(const ::rtl::OUString& rRawString); + std::pair< ::rtl::OUString, ::rtl::OUString> GetDNForCertDetailsView( + const ::rtl::OUString & rRawString); + String GetContentPart( const String& _rRawString ); + + String GetHexString( const ::com::sun::star::uno::Sequence< sal_Int8 >& _rSeq, const char* _pSep = ":", UINT16 _nLineBreak = 0xFFFF ); + + long ShrinkToFitWidth( Control& _rCtrl, long _nOffs = 0 ); // return = new width + void AlignAfterImage( const FixedImage& _rImage, Control& _rCtrl, long _nXOffset = 0 ); + void AlignAfterImage( const FixedImage& _rImage, FixedInfo& _rFI, long _nXOffset = 0 ); + void AlignAndFitImageAndControl( FixedImage& _rImage, FixedInfo& _rFI, long _nXOffset = 0 ); +} + +#define XMLSEC_RES(id) ResId(id,*XmlSec::GetResMgr()) + +#endif diff --git a/xmlsecurity/source/dialogs/stbcontrl.cxx b/xmlsecurity/source/dialogs/stbcontrl.cxx new file mode 100644 index 000000000000..cc18373f04d8 --- /dev/null +++ b/xmlsecurity/source/dialogs/stbcontrl.cxx @@ -0,0 +1,188 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmlsecurity.hxx" + +// include --------------------------------------------------------------- +#include <tools/shl.hxx> +#ifndef _STATUS_HXX //autogen +#include <vcl/status.hxx> +#endif +#ifndef _MENU_HXX //autogen +#include <vcl/menu.hxx> +#endif +#include <vcl/image.hxx> +//#ifndef _SFXITEMPOOL_HXX +//#include <svl/itempool.hxx> +//#endif +#include <sfx2/app.hxx> +#include <sfx2/module.hxx> +#include <sfx2/dispatch.hxx> +#include <sfx2/objsh.hxx> + +#include <svl/eitem.hxx> + + +#include <xmlsecurity/stbcontrl.hxx> + +#define PAINT_OFFSET 5 + +//#include "sizeitem.hxx" +//#include "dialmgr.hxx" +//#include "dlgutil.hxx" +//#include "stbctrls.h" + +//#include "dialogs.hrc" + +/*#ifndef _UNOTOOLS_LOCALEDATAWRAPPER_HXX +#include <unotools/localedatawrapper.hxx> +#endif +#ifndef _UNOTOOLS_PROCESSFACTORY_HXX +#include <comphelper/processfactory.hxx> +#endif*/ + + + +SFX_IMPL_STATUSBAR_CONTROL( XmlSecStatusBarControl, SfxBoolItem ); + +/* +class FunctionPopup_Impl : public PopupMenu +{ +public: + FunctionPopup_Impl( USHORT nCheck ); + + USHORT GetSelected() const { return nSelected; } + +private: + USHORT nSelected; + + virtual void Select(); +}; + +// ----------------------------------------------------------------------- + +FunctionPopup_Impl::FunctionPopup_Impl( USHORT nCheck ) : + PopupMenu( ResId( RID_SVXMNU_PSZ_FUNC, DIALOG_MGR() ) ), + nSelected( 0 ) +{ + if (nCheck) + CheckItem( nCheck ); +} + +// ----------------------------------------------------------------------- + +void FunctionPopup_Impl::Select() +{ + nSelected = GetCurItemId(); +} +*/ + + + +struct XmlSecStatusBarControl::XmlSecStatusBarControl_Impl +{ + Point maPos; + Size maSize; + bool mbSigned; + Image maImage; +}; + + +XmlSecStatusBarControl::XmlSecStatusBarControl( USHORT _nId, StatusBar& _rStb, SfxBindings& _rBind ) + :SfxStatusBarControl( _nId, _rStb, _rBind ) + + ,mpImpl( new XmlSecStatusBarControl_Impl ) +{ + mpImpl->mbSigned = false; +// pImp->maImage = Image( ResId( RID_SVXBMP_POSITION, DIALOG_MGR() ) ); +} + +XmlSecStatusBarControl::~XmlSecStatusBarControl() +{ + delete mpImpl; +} + +void XmlSecStatusBarControl::StateChanged( USHORT nSID, SfxItemState eState, const SfxPoolItem* pState ) +{ + GetStatusBar().SetHelpText( GetId(), String() ); // necessary ? + GetStatusBar().SetHelpId( GetId(), nSID ); // necessary ? + + if( SFX_ITEM_AVAILABLE != eState ) + { + mpImpl->mbSigned = false; + } + else if( pState->ISA( SfxBoolItem ) ) + { + mpImpl->mbSigned = ( ( SfxBoolItem* ) pState )->GetValue(); + } + else + { + DBG_ERRORFILE( "+XmlSecStatusBarControl::StateChanged(): invalid item type" ); + mpImpl->mbSigned = false; + } + + if( GetStatusBar().AreItemsVisible() ) // necessary ? + GetStatusBar().SetItemData( GetId(), 0 ); + + GetStatusBar().SetItemText( GetId(), String() ); // necessary ? +} + +void XmlSecStatusBarControl::Command( const CommandEvent& rCEvt ) +{ + // can / has to be done when integrated in Office! +// if( rCEvt.GetCommand() == .... ) + if( false ) + { +// GetBindings().GetDispatcher()->Execute( SID_PSZ_FUNCTION, SFX_CALLMODE_RECORD, &aItem, 0L ); + } + else + SfxStatusBarControl::Command( rCEvt ); +} + +void XmlSecStatusBarControl::Paint( const UserDrawEvent& rUsrEvt ) +{ + OutputDevice* pDev = rUsrEvt.GetDevice(); + DBG_ASSERT( pDev, "-XmlSecStatusBarControl::Paint(): no Output Device... this will lead to nirvana..." ); + const Rectangle& rRect = rUsrEvt.GetRect(); + StatusBar& rBar = GetStatusBar(); + Point aItemPos = rBar.GetItemTextPos( GetId() ); + Color aOldLineColor = pDev->GetLineColor(); + Color aOldFillColor = pDev->GetFillColor(); + + // just 4 testing until we've got a bitmap + pDev->SetLineColor(); + pDev->SetFillColor( pDev->GetBackground().GetColor() ); + + String s( String::CreateFromAscii( mpImpl->mbSigned? "X" : "-" ) ); + pDev->DrawRect( rRect ); + pDev->DrawText( Point( rRect.Left() + rRect.GetWidth() / 2 - pDev->GetTextWidth( s ) / 2, aItemPos.Y() ), s ); + + pDev->SetLineColor( aOldLineColor ); + pDev->SetFillColor( aOldFillColor ); +} + diff --git a/xmlsecurity/source/dialogs/warnings.cxx b/xmlsecurity/source/dialogs/warnings.cxx new file mode 100644 index 000000000000..b92266f427d7 --- /dev/null +++ b/xmlsecurity/source/dialogs/warnings.cxx @@ -0,0 +1,145 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmlsecurity.hxx" + +#include <xmlsecurity/warnings.hxx> +#include <xmlsecurity/certificateviewer.hxx> +#include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp> +#include <comphelper/sequence.hxx> + +// MM : added for password exception +#include <vcl/msgbox.hxx> +#include <com/sun/star/security/NoPasswordException.hpp> +using namespace ::com::sun::star::security; + + +#include "dialogs.hrc" +#include "resourcemanager.hxx" + +/* HACK: disable some warnings for MS-C */ +#ifdef _MSC_VER +#pragma warning (disable : 4355) // 4355: this used in initializer-list +#endif + +using namespace ::com::sun::star; +using namespace ::com::sun::star; + + +MacroWarning::MacroWarning( Window* _pParent, uno::Reference< dcss::xml::crypto::XSecurityEnvironment >& _rxSecurityEnvironment, cssu::Reference< dcss::security::XCertificate >& _rxCert ) + :ModalDialog ( _pParent, XMLSEC_RES( RID_XMLSECTP_MACROWARN ) ) + ,maDocNameFI ( this, ResId( FI_DOCNAME ) ) + ,maDescr1aFI ( this, ResId( FI_DESCR1A ) ) + ,maDescr1bFI ( this, ResId( FI_DESCR1B ) ) + ,maSignsFI ( this, ResId( FI_SIGNS ) ) + ,maViewSignsBtn ( this, ResId( PB_VIEWSIGNS ) ) + ,maDescr2FI ( this, ResId( FI_DESCR2 ) ) + ,maAlwaysTrustCB ( this, ResId( CB_ALWAYSTRUST ) ) + ,maBottomSepFL ( this, ResId( FL_BOTTOM_SEP ) ) + ,maEnableBtn ( this, ResId( PB_DISABLE ) ) + ,maDisableBtn ( this, ResId( PB_DISABLE ) ) + ,maHelpBtn ( this, ResId( BTN_HELP ) ) + ,mbSignedMode ( true ) +{ + FreeResource(); + + mxSecurityEnvironment = _rxSecurityEnvironment; + mxCert = _rxCert; + + // hide unused parts + maDescr1bFI.Hide(); + + maViewSignsBtn.SetClickHdl( LINK( this, MacroWarning, ViewSignsBtnHdl ) ); + maEnableBtn.SetClickHdl( LINK( this, MacroWarning, EnableBtnHdl ) ); +// maDisableBtn.SetClickHdl( LINK( this, MacroWarning, DisableBtnHdl ) ); + + if( mxCert.is() ) + maSignsFI.SetText( XmlSec::GetContentPart( mxCert->getSubjectName() ) ); + else + // nothing to view! + maViewSignsBtn.Disable(); +} + +MacroWarning::MacroWarning( Window* _pParent ) + :ModalDialog ( _pParent, XMLSEC_RES( RID_XMLSECTP_MACROWARN ) ) + ,maDocNameFI ( this, ResId( FI_DOCNAME ) ) + ,maDescr1aFI ( this, ResId( FI_DESCR1A ) ) + ,maDescr1bFI ( this, ResId( FI_DESCR1B ) ) + ,maSignsFI ( this, ResId( FI_SIGNS ) ) + ,maViewSignsBtn ( this, ResId( PB_VIEWSIGNS ) ) + ,maDescr2FI ( this, ResId( FI_DESCR2 ) ) + ,maAlwaysTrustCB ( this, ResId( CB_ALWAYSTRUST ) ) + ,maBottomSepFL ( this, ResId( FL_BOTTOM_SEP ) ) + ,maEnableBtn ( this, ResId( PB_DISABLE ) ) + ,maDisableBtn ( this, ResId( PB_DISABLE ) ) + ,maHelpBtn ( this, ResId( BTN_HELP ) ) + ,mbSignedMode ( false ) +{ + FreeResource(); + + // hide unused parts + maDescr1aFI.Hide(); + maSignsFI.Hide(); + maViewSignsBtn.Hide(); + maAlwaysTrustCB.Hide(); + maDescr2FI.Hide(); + + // move hint up to position of signer list + maDescr1bFI.SetPosPixel( maSignsFI.GetPosPixel() ); +} + +MacroWarning::~MacroWarning() +{ +} + +IMPL_LINK( MacroWarning, ViewSignsBtnHdl, void*, EMPTYARG ) +{ + DBG_ASSERT( mxCert.is(), "*MacroWarning::ViewSignsBtnHdl(): no certificate set!" ); + + CertificateViewer aViewer( this, mxSecurityEnvironment, mxCert ); + aViewer.Execute(); + + return 0; +} + +IMPL_LINK( MacroWarning, EnableBtnHdl, void*, EMPTYARG ) +{ + if( mbSignedMode && maAlwaysTrustCB.IsChecked() ) + { // insert path into trusted path list + + } + + EndDialog( RET_OK ); + return 0; +} + +/*IMPL_LINK( MacroWarning, DisableBtnHdl, void*, EMPTYARG ) +{ + return 0; +}*/ + diff --git a/xmlsecurity/source/dialogs/warnings.src b/xmlsecurity/source/dialogs/warnings.src new file mode 100644 index 000000000000..2e0e697dae1f --- /dev/null +++ b/xmlsecurity/source/dialogs/warnings.src @@ -0,0 +1,112 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "dialogs.hrc" +#include "helpids.hrc" + +ModalDialog RID_XMLSECTP_MACROWARN +{ + HelpId = HID_XMLSEC_TP_MACROWARN; + Size = MAP_APPFONT( MW_WIDTH, MW_HEIGHT ); + OutputSize = TRUE; + Closeable = TRUE; + Moveable = TRUE; + SVLook = TRUE; + + Text [ en-US ] = "Security Warning"; + + FixedText FI_DOCNAME + { + Pos = MAP_APPFONT( MW_COL_1, MW_ROW_0 ); + Size = MAP_APPFONT( MW_COL_4-MW_COL_1, 3*RSC_CD_FIXEDTEXT_HEIGHT ); + Wordbreak = TRUE; + Text [ en-US ] = ""; + }; + FixedText FI_DESCR1A + { + Pos = MAP_APPFONT( MW_COL_1, MW_ROW_1 ); + Size = MAP_APPFONT( MW_COL_4-MW_COL_1, RSC_CD_FIXEDTEXT_HEIGHT ); + Wordbreak = TRUE; + Text [ en-US ] = "The document contains document macros signed by:"; + }; + FixedText FI_DESCR1B + { + Pos = MAP_APPFONT( MW_COL_1, MW_ROW_1 ); + Size = MAP_APPFONT( MW_COL_4-MW_COL_1, RSC_CD_FIXEDTEXT_HEIGHT ); + Wordbreak = TRUE; + Text [ en-US ] = "The document contains document macros."; + }; + FixedText FI_SIGNS + { + Pos = MAP_APPFONT( MW_COL_1, MW_ROW_2 ); + Size = MAP_APPFONT( MW_COL_4-MW_COL_2, MW_ROW_3-MW_ROW_2 ); + Wordbreak = TRUE; + Text [ en-US ] = ""; + }; + PushButton PB_VIEWSIGNS + { + Pos = MAP_APPFONT( MW_COL_3, MW_ROW_2 ); + Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT ); + Text [ en-US ] = "View Signatures..."; + }; + FixedText FI_DESCR2 + { + Pos = MAP_APPFONT( MW_COL_1, MW_ROW_3 ); + Size = MAP_APPFONT( MW_COL_4-MW_COL_1, RSC_CD_FIXEDTEXT_HEIGHT ); + Wordbreak = TRUE; + Text [ en-US ] = "Macros may contain viruses. Disabling macros for a document is always save. If you disable macros you may lose functionality provided by the document macros."; + }; + CheckBox CB_ALWAYSTRUST + { + Pos = MAP_APPFONT( MW_COL_1, MW_ROW_4 ); + Size = MAP_APPFONT( MW_COL_4-MW_COL_1, RSC_CD_CHECKBOX_HEIGHT ); + Text [ en-US ] = "Always trust macros from this source"; + }; + FixedLine FL_BOTTOM_SEP + { + Pos = MAP_APPFONT( 0, DLGS_BOTTOM_FL_Y( MW_HEIGHT ) ); + Size = MAP_APPFONT( MW_WIDTH, RSC_CD_FIXEDLINE_HEIGHT ); + }; + PushButton PB_ENABLE + { + Pos = MAP_APPFONT( DLGS_BOTTOM_OK_X( MW_WIDTH ), DLGS_BOTTOM_BTN_Y( MW_HEIGHT ) ); + Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT ); + Text [ en-US ] = "Enable Macros"; + }; + CancelButton PB_DISABLE + { + Pos = MAP_APPFONT( DLGS_BOTTOM_CANCEL_X( MW_WIDTH ), DLGS_BOTTOM_BTN_Y( MW_HEIGHT ) ); + Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT ); + Text [ en-US ] = "Disable Macros"; + }; + HelpButton BTN_HELP + { + Pos = MAP_APPFONT( DLGS_BOTTOM_HELP_X( MW_WIDTH ), DLGS_BOTTOM_BTN_Y( MW_HEIGHT ) ); + Size = MAP_APPFONT( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT ); + }; +}; + |