LCOV - code coverage report
Current view: top level - libreoffice/xmlsecurity/source/dialogs - certificateviewer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 302 0.0 %
Date: 2012-12-27 Functions: 0 29 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <xmlsecurity/certificateviewer.hxx>
      21             : #include <com/sun/star/security/XCertificate.hpp>
      22             : 
      23             : #include <com/sun/star/security/CertificateCharacters.hpp>
      24             : #include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp>
      25             : #include <com/sun/star/security/CertificateValidity.hpp>
      26             : 
      27             : #include <unotools/localedatawrapper.hxx>
      28             : #include <unotools/datetime.hxx>
      29             : #include "svtools/treelistentry.hxx"
      30             : 
      31             : #include "dialogs.hrc"
      32             : #include "resourcemanager.hxx"
      33             : 
      34             : /* HACK: disable some warnings for MS-C */
      35             : #ifdef _MSC_VER
      36             : #pragma warning (disable : 4355)    // 4355: this used in initializer-list
      37             : #endif
      38             : 
      39             : using namespace ::com::sun::star;
      40             : using namespace ::com::sun::star::uno;
      41             : 
      42             : namespace
      43             : {
      44           0 :     void ShrinkToFit( FixedImage& _rImg )
      45             :     {
      46           0 :         _rImg.SetSizePixel( _rImg.GetImage().GetSizePixel() );
      47           0 :     }
      48             : }
      49             : 
      50           0 : CertificateViewer::CertificateViewer(
      51             :         Window* _pParent,
      52             :         const cssu::Reference< dcss::xml::crypto::XSecurityEnvironment >& _rxSecurityEnvironment,
      53             :         const cssu::Reference< dcss::security::XCertificate >& _rXCert, bool bCheckForPrivateKey )
      54           0 :     :TabDialog      ( _pParent, XMLSEC_RES( RID_XMLSECDLG_CERTVIEWER ) )
      55           0 :     ,maTabCtrl      ( this, XMLSEC_RES( 1 ) )
      56           0 :     ,maOkBtn        ( this, XMLSEC_RES( BTN_OK ) )
      57           0 :     ,maHelpBtn      ( this, XMLSEC_RES( BTN_HELP ) )
      58             : {
      59           0 :     FreeResource();
      60             : 
      61           0 :     mbCheckForPrivateKey = bCheckForPrivateKey;
      62             : 
      63           0 :     mxSecurityEnvironment = _rxSecurityEnvironment;
      64           0 :     mxCert = _rXCert;
      65             : 
      66           0 :     maTabCtrl.SetTabPage( RID_XMLSECTP_GENERAL, new CertificateViewerGeneralTP( &maTabCtrl, this ) );
      67           0 :     maTabCtrl.SetTabPage( RID_XMLSECTP_DETAILS, new CertificateViewerDetailsTP( &maTabCtrl, this ) );
      68           0 :     maTabCtrl.SetTabPage( RID_XMLSECTP_CERTPATH, new CertificateViewerCertPathTP( &maTabCtrl, this ) );
      69           0 :     maTabCtrl.SetCurPageId( RID_XMLSECTP_GENERAL );
      70           0 : }
      71             : 
      72           0 : CertificateViewer::~CertificateViewer()
      73             : {
      74           0 :     delete maTabCtrl.GetTabPage( RID_XMLSECTP_CERTPATH );
      75           0 :     delete maTabCtrl.GetTabPage( RID_XMLSECTP_DETAILS );
      76           0 :     delete maTabCtrl.GetTabPage( RID_XMLSECTP_GENERAL );
      77           0 : }
      78             : 
      79           0 : CertificateViewerTP::CertificateViewerTP( Window* _pParent, const ResId& _rResId, CertificateViewer* _pDlg )
      80             :     :TabPage        ( _pParent, _rResId )
      81           0 :     ,mpDlg          ( _pDlg )
      82             : {
      83           0 : }
      84             : 
      85             : 
      86           0 : CertificateViewerGeneralTP::CertificateViewerGeneralTP( Window* _pParent, CertificateViewer* _pDlg )
      87           0 :     :CertificateViewerTP    ( _pParent, XMLSEC_RES( RID_XMLSECTP_GENERAL ), _pDlg )
      88           0 :     ,maFrameWin             ( this, XMLSEC_RES( WIN_FRAME ) )
      89           0 :     ,maCertImg              ( this, XMLSEC_RES( IMG_CERT ) )
      90           0 :     ,maCertInfoFI           ( this, XMLSEC_RES( FI_CERTINFO ) )
      91           0 :     ,maSep1FL               ( this, XMLSEC_RES( FL_SEP1 ) )
      92           0 :     ,maHintNotTrustedFI     ( this, XMLSEC_RES( FI_HINTNOTTRUST ) )
      93           0 :     ,maSep2FL               ( this, XMLSEC_RES( FL_SEP2 ) )
      94           0 :     ,maIssuedToLabelFI      ( this, XMLSEC_RES( FI_ISSTOLABEL ) )
      95           0 :     ,maIssuedToFI           ( this, XMLSEC_RES( FI_ISSTO ) )
      96           0 :     ,maIssuedByLabelFI      ( this, XMLSEC_RES( FI_ISSBYLABEL ) )
      97           0 :     ,maIssuedByFI           ( this, XMLSEC_RES( FI_ISSBY ) )
      98           0 :     ,maValidDateFI          ( this, XMLSEC_RES( FI_VALIDDATE ) )
      99           0 :     ,maKeyImg               ( this, XMLSEC_RES( IMG_KEY ) )
     100           0 :     ,maHintCorrespPrivKeyFI ( this, XMLSEC_RES( FI_CORRPRIVKEY ) )
     101             : {
     102             :     //Verify the certificate
     103           0 :     sal_Int32 certStatus = mpDlg->mxSecurityEnvironment->verifyCertificate(mpDlg->mxCert,
     104           0 :          Sequence<Reference<css::security::XCertificate> >());
     105             : 
     106           0 :     bool bCertValid = certStatus == css::security::CertificateValidity::VALID ?  true : false;
     107             : 
     108           0 :     if ( !bCertValid )
     109             :     {
     110             :         maCertImg.SetImage(
     111           0 :             Image( XMLSEC_RES( IMG_STATE_NOT_VALIDATED ) ) );
     112           0 :         maHintNotTrustedFI.SetText( XMLSEC_RES( STR_CERTIFICATE_NOT_VALIDATED ) );
     113             :     }
     114             : 
     115           0 :     FreeResource();
     116             : 
     117           0 :     Wallpaper aBack( GetSettings().GetStyleSettings().GetWindowColor() );
     118           0 :     maFrameWin.SetBackground( aBack );
     119           0 :     maCertImg.SetBackground( aBack );
     120           0 :     maCertInfoFI.SetBackground( aBack );
     121           0 :     maSep1FL.SetBackground( aBack );
     122           0 :     maHintNotTrustedFI.SetBackground( aBack );
     123           0 :     maSep2FL.SetBackground( aBack );
     124           0 :     maIssuedToLabelFI.SetBackground( aBack );
     125           0 :     maIssuedToFI.SetBackground( aBack );
     126           0 :     maIssuedByLabelFI.SetBackground( aBack );
     127           0 :     maIssuedByFI.SetBackground( aBack );
     128           0 :     maValidDateFI.SetBackground( aBack );
     129           0 :     maKeyImg.SetBackground( aBack );
     130           0 :     maHintCorrespPrivKeyFI.SetBackground( aBack );
     131             : 
     132             :     // make some bold
     133           0 :     Font    aFnt( maCertInfoFI.GetFont() );
     134           0 :     aFnt.SetWeight( WEIGHT_BOLD );
     135           0 :     maCertInfoFI.SetFont( aFnt );
     136           0 :     maHintNotTrustedFI.SetFont( aFnt );
     137           0 :     maIssuedToLabelFI.SetFont( aFnt );
     138           0 :     maIssuedByLabelFI.SetFont( aFnt );
     139           0 :     maValidDateFI.SetFont( aFnt );
     140             : 
     141             :     // insert data
     142           0 :     cssu::Reference< dcss::security::XCertificate > xCert = mpDlg->mxCert;
     143             : 
     144           0 :     maIssuedToFI.SetText( XmlSec::GetContentPart( xCert->getSubjectName() ) );
     145           0 :     maIssuedByFI.SetText( XmlSec::GetContentPart( xCert->getIssuerName() ) );
     146             : 
     147             :     // dynamic length because of the different languages
     148           0 :     long nWidth1 = maIssuedToLabelFI.GetTextWidth( maIssuedToLabelFI.GetText() );
     149           0 :     long nWidth2 = maIssuedByLabelFI.GetTextWidth( maIssuedByLabelFI.GetText() );
     150           0 :     long nNewWidth = Max( nWidth1, nWidth2 ) + 5;
     151           0 :     Size aNewSize = maIssuedToLabelFI.GetSizePixel();
     152           0 :     aNewSize.Width() = nNewWidth;
     153           0 :     maIssuedToLabelFI.SetSizePixel( aNewSize );
     154           0 :     maIssuedByLabelFI.SetSizePixel( aNewSize );
     155           0 :     long nNewX = maIssuedToLabelFI.GetPosPixel().X() + nNewWidth + 1;
     156           0 :     Point aNewPos = maIssuedToFI.GetPosPixel();
     157           0 :     aNewPos.X() = nNewX;
     158           0 :     maIssuedToFI.SetPosPixel( aNewPos );
     159           0 :     aNewPos = maIssuedByFI.GetPosPixel();
     160           0 :     aNewPos.X() = nNewX;
     161           0 :     maIssuedByFI.SetPosPixel( aNewPos );
     162           0 :     nNewWidth = maValidDateFI.GetSizePixel().Width() - nNewX;
     163           0 :     aNewSize = maIssuedToFI.GetSizePixel();
     164           0 :     aNewSize.Width() = nNewWidth;
     165           0 :     maIssuedToFI.SetSizePixel( aNewSize );
     166           0 :     maIssuedByFI.SetSizePixel( aNewSize );
     167             : 
     168           0 :     DateTime aDateTimeStart( DateTime::EMPTY );
     169           0 :     DateTime aDateTimeEnd( DateTime::EMPTY );
     170           0 :     utl::typeConvert( xCert->getNotValidBefore(), aDateTimeStart );
     171           0 :     utl::typeConvert( xCert->getNotValidAfter(), aDateTimeEnd );
     172           0 :     OUString sText = maValidDateFI.GetText();
     173             :     sText = sText.replaceFirst( "%SDATE%",
     174           0 :         GetSettings().GetUILocaleDataWrapper().getDate( aDateTimeStart.GetDate() ) );
     175             :     sText = sText.replaceFirst( "%EDATE%",
     176           0 :         GetSettings().GetUILocaleDataWrapper().getDate( aDateTimeEnd.GetDate() ) );
     177           0 :     maValidDateFI.SetText( sText );
     178             : 
     179             :     // adjust position of fixed text depending on image sizes
     180           0 :     ShrinkToFit( maCertImg );
     181           0 :     ShrinkToFit( maKeyImg );
     182           0 :     XmlSec::AlignAfterImage( maCertImg, maCertInfoFI, 12 );
     183           0 :     XmlSec::AlignAfterImage( maKeyImg, maHintCorrespPrivKeyFI, 12 );
     184             : 
     185             :     // Check if we have the private key...
     186           0 :     sal_Bool bHasPrivateKey = sal_False;
     187             :     // #i41270# Check only if we have that certificate in our security environment
     188           0 :     if ( _pDlg->mbCheckForPrivateKey )
     189             :     {
     190           0 :         long nCertificateCharacters = _pDlg->mxSecurityEnvironment->getCertificateCharacters( xCert );
     191           0 :         bHasPrivateKey = ( nCertificateCharacters & security::CertificateCharacters::HAS_PRIVATE_KEY ) ? sal_True : sal_False;
     192             :     }
     193           0 :     if ( !bHasPrivateKey )
     194             :     {
     195           0 :         maKeyImg.Hide();
     196           0 :         maHintCorrespPrivKeyFI.Hide();
     197           0 :     }
     198           0 : }
     199             : 
     200           0 : void CertificateViewerGeneralTP::ActivatePage()
     201             : {
     202             : 
     203           0 : }
     204             : 
     205             : 
     206           0 : struct Details_UserDatat
     207             : {
     208             :     OUString        maTxt;
     209             :     bool            mbFixedWidthFont;
     210             : 
     211             :     inline          Details_UserDatat( const OUString& _rTxt, bool _bFixedWidthFont );
     212             : };
     213             : 
     214           0 : inline Details_UserDatat::Details_UserDatat( const OUString& _rTxt, bool _bFixedWidthFont )
     215             :     :maTxt              ( _rTxt )
     216           0 :     ,mbFixedWidthFont   ( _bFixedWidthFont )
     217             : {
     218           0 : }
     219             : 
     220             : 
     221           0 : void CertificateViewerDetailsTP::Clear( void )
     222             : {
     223           0 :     maElementML.SetText( OUString() );
     224           0 :     sal_uLong           i = 0;
     225           0 :     SvTreeListEntry*    pEntry = maElementsLB.GetEntry( i );
     226           0 :     while( pEntry )
     227             :     {
     228           0 :         delete ( Details_UserDatat* ) pEntry->GetUserData();
     229           0 :         ++i;
     230           0 :         pEntry = maElementsLB.GetEntry( i );
     231             :     }
     232             : 
     233           0 :     maElementsLB.Clear();
     234           0 : }
     235             : 
     236           0 : void CertificateViewerDetailsTP::InsertElement( const OUString& _rField, const OUString& _rValue,
     237             :                                                 const OUString& _rDetails, bool _bFixedWidthFont )
     238             : {
     239           0 :     SvTreeListEntry*    pEntry = maElementsLB.InsertEntry( _rField );
     240           0 :     maElementsLB.SetEntryText( _rValue, pEntry, 1 );
     241           0 :     pEntry->SetUserData( ( void* ) new Details_UserDatat( _rDetails, _bFixedWidthFont ) );
     242           0 : }
     243             : 
     244           0 : CertificateViewerDetailsTP::CertificateViewerDetailsTP( Window* _pParent, CertificateViewer* _pDlg )
     245           0 :     :CertificateViewerTP    ( _pParent, XMLSEC_RES( RID_XMLSECTP_DETAILS ), _pDlg  )
     246           0 :     ,m_aElementsLBContainer(this, XMLSEC_RES(LB_ELEMENTS))
     247             :     ,maElementsLB(m_aElementsLBContainer)
     248           0 :     ,maElementML            ( this, XMLSEC_RES( ML_ELEMENT ) )
     249             :     ,maStdFont              ( maElementML.GetControlFont() )
     250           0 :     ,maFixedWidthFont       ( OutputDevice::GetDefaultFont( DEFAULTFONT_UI_FIXED, LANGUAGE_DONTKNOW, DEFAULTFONT_FLAGS_ONLYONE, this ) )
     251             : {
     252           0 :     WinBits nStyle = maElementsLB.GetStyle();
     253           0 :     nStyle &= ~WB_HSCROLL;
     254           0 :     maElementsLB.SetStyle( nStyle );
     255             : 
     256           0 :     maFixedWidthFont.SetHeight( maStdFont.GetHeight() );
     257             : 
     258             :     static long nTabs[] = { 2, 0, 30*CS_LB_WIDTH/100 };
     259           0 :     maElementsLB.SetTabs( &nTabs[ 0 ] );
     260           0 :     maElementsLB.InsertHeaderEntry( XMLSEC_RES( STR_HEADERBAR ) );
     261             : 
     262             :     // fill list box
     263           0 :     Reference< security::XCertificate > xCert = mpDlg->mxCert;
     264           0 :     sal_uInt16                  nLineBreak = 16;
     265           0 :     const char*             pHexSep = " ";
     266           0 :     OUString                aLBEntry;
     267           0 :     OUString                aDetails;
     268             :     // Certificate Versions are reported wrong (#i35107#) - 0 == "V1", 1 == "V2", ..., n = "V(n+1)"
     269           0 :     aLBEntry = rtl::OUString( "V" );
     270           0 :     aLBEntry += OUString::valueOf( sal_Int32( xCert->getVersion() + 1 ) );
     271           0 :     InsertElement( XMLSEC_RES( STR_VERSION ), aLBEntry, aLBEntry );
     272           0 :     Sequence< sal_Int8 >    aSeq = xCert->getSerialNumber();
     273           0 :     aLBEntry = XmlSec::GetHexString( aSeq, pHexSep );
     274           0 :     aDetails = XmlSec::GetHexString( aSeq, pHexSep, nLineBreak );
     275           0 :     InsertElement( XMLSEC_RES( STR_SERIALNUM ), aLBEntry, aDetails, true );
     276             : 
     277             :     std::pair< ::rtl::OUString, ::rtl::OUString> pairIssuer =
     278           0 :         XmlSec::GetDNForCertDetailsView(xCert->getIssuerName());
     279           0 :     aLBEntry = pairIssuer.first;
     280           0 :     aDetails = pairIssuer.second;
     281           0 :     InsertElement( XMLSEC_RES( STR_ISSUER ), aLBEntry, aDetails );
     282             : 
     283           0 :     DateTime aDateTime( DateTime::EMPTY );
     284           0 :     utl::typeConvert( xCert->getNotValidBefore(), aDateTime );
     285           0 :     aLBEntry = GetSettings().GetUILocaleDataWrapper().getDate( aDateTime.GetDate() );
     286           0 :     aLBEntry += rtl::OUString( " " );
     287           0 :     aLBEntry += GetSettings().GetUILocaleDataWrapper().getTime( aDateTime.GetTime() );
     288           0 :     InsertElement( XMLSEC_RES( STR_VALIDFROM ), aLBEntry, aLBEntry  );
     289           0 :     utl::typeConvert( xCert->getNotValidAfter(), aDateTime );
     290           0 :     aLBEntry = GetSettings().GetUILocaleDataWrapper().getDate( aDateTime.GetDate() );
     291           0 :     aLBEntry += rtl::OUString( " " );
     292           0 :     aLBEntry += GetSettings().GetUILocaleDataWrapper().getTime( aDateTime.GetTime() );
     293           0 :     InsertElement( XMLSEC_RES( STR_VALIDTO ), aLBEntry, aLBEntry );
     294             : 
     295             :     std::pair< ::rtl::OUString, ::rtl::OUString > pairSubject =
     296           0 :         XmlSec::GetDNForCertDetailsView(xCert->getSubjectName());
     297           0 :     aLBEntry = pairSubject.first;
     298           0 :     aDetails = pairSubject.second;
     299           0 :     InsertElement( XMLSEC_RES( STR_SUBJECT ), aLBEntry, aDetails );
     300             : 
     301           0 :     aLBEntry = aDetails = xCert->getSubjectPublicKeyAlgorithm();
     302           0 :     InsertElement( XMLSEC_RES( STR_SUBJECT_PUBKEY_ALGO ), aLBEntry, aDetails );
     303           0 :     aSeq = xCert->getSubjectPublicKeyValue();
     304           0 :     aLBEntry = XmlSec::GetHexString( aSeq, pHexSep );
     305           0 :     aDetails = XmlSec::GetHexString( aSeq, pHexSep, nLineBreak );
     306           0 :     InsertElement( XMLSEC_RES( STR_SUBJECT_PUBKEY_VAL ), aLBEntry, aDetails, true );
     307             : 
     308           0 :     aLBEntry = aDetails = xCert->getSignatureAlgorithm();
     309           0 :     InsertElement( XMLSEC_RES( STR_SIGNATURE_ALGO ), aLBEntry, aDetails );
     310             : 
     311           0 :     aSeq = xCert->getSHA1Thumbprint();
     312           0 :     aLBEntry = XmlSec::GetHexString( aSeq, pHexSep );
     313           0 :     aDetails = XmlSec::GetHexString( aSeq, pHexSep, nLineBreak );
     314           0 :     InsertElement( XMLSEC_RES( STR_THUMBPRINT_SHA1 ), aLBEntry, aDetails, true );
     315             : 
     316           0 :     aSeq = xCert->getMD5Thumbprint();
     317           0 :     aLBEntry = XmlSec::GetHexString( aSeq, pHexSep );
     318           0 :     aDetails = XmlSec::GetHexString( aSeq, pHexSep, nLineBreak );
     319           0 :     InsertElement( XMLSEC_RES( STR_THUMBPRINT_MD5 ), aLBEntry, aDetails, true );
     320             : 
     321           0 :     FreeResource();
     322             : 
     323           0 :     maElementsLB.SetSelectHdl( LINK( this, CertificateViewerDetailsTP, ElementSelectHdl ) );
     324           0 : }
     325             : 
     326           0 : CertificateViewerDetailsTP::~CertificateViewerDetailsTP()
     327             : {
     328           0 :     Clear();
     329           0 : }
     330             : 
     331           0 : void CertificateViewerDetailsTP::ActivatePage()
     332             : {
     333           0 : }
     334             : 
     335           0 : IMPL_LINK_NOARG(CertificateViewerDetailsTP, ElementSelectHdl)
     336             : {
     337           0 :     SvTreeListEntry*    pEntry = maElementsLB.FirstSelected();
     338           0 :     OUString        aElementText;
     339             :     bool            bFixedWidthFont;
     340           0 :     if( pEntry )
     341             :     {
     342           0 :         const Details_UserDatat*    p = ( Details_UserDatat* ) pEntry->GetUserData();
     343           0 :         aElementText = p->maTxt;
     344           0 :         bFixedWidthFont = p->mbFixedWidthFont;
     345             :     }
     346             :     else
     347           0 :         bFixedWidthFont = false;
     348             : 
     349           0 :     maElementML.SetFont( bFixedWidthFont? maFixedWidthFont : maStdFont );
     350           0 :     maElementML.SetControlFont( bFixedWidthFont? maFixedWidthFont : maStdFont );
     351           0 :     maElementML.SetText( aElementText );
     352             : 
     353           0 :     return 0;
     354             : }
     355             : 
     356           0 : struct CertPath_UserData
     357             : {
     358             :     cssu::Reference< dcss::security::XCertificate > mxCert;
     359             :     OUString                                        maStatus;
     360             :     bool mbValid;
     361             : 
     362           0 :     CertPath_UserData( cssu::Reference< dcss::security::XCertificate > xCert, bool bValid):
     363             :         mxCert(xCert),
     364           0 :         mbValid(bValid)
     365             :     {
     366           0 :     }
     367             : };
     368             : 
     369             : 
     370           0 : CertificateViewerCertPathTP::CertificateViewerCertPathTP( Window* _pParent, CertificateViewer* _pDlg )
     371           0 :     :CertificateViewerTP    ( _pParent, XMLSEC_RES( RID_XMLSECTP_CERTPATH ), _pDlg  )
     372           0 :     ,maCertPathFT           ( this, XMLSEC_RES( FT_CERTPATH ) )
     373           0 :     ,maCertPathLB           ( this, XMLSEC_RES( LB_SIGNATURES ) )
     374           0 :     ,maViewCertPB           ( this, XMLSEC_RES( BTN_VIEWCERT ) )
     375           0 :     ,maCertStatusFT         ( this, XMLSEC_RES( FT_CERTSTATUS ) )
     376           0 :     ,maCertStatusML         ( this, XMLSEC_RES( ML_CERTSTATUS ) )
     377             :     ,mpParent               ( _pDlg )
     378             :     ,mbFirstActivateDone    ( false )
     379           0 :     ,maCertImage            ( XMLSEC_RES( IMG_CERT_SMALL ) )
     380           0 :     ,maCertNotValidatedImage( XMLSEC_RES( IMG_CERT_NOTVALIDATED_SMALL ) )
     381           0 :     ,msCertOK               ( XMLSEC_RES( STR_PATH_CERT_OK ) )
     382           0 :     ,msCertNotValidated     ( XMLSEC_RES( STR_PATH_CERT_NOT_VALIDATED ) )
     383             : 
     384             : {
     385           0 :     FreeResource();
     386             : 
     387           0 :     maCertPathLB.SetNodeDefaultImages();
     388           0 :     maCertPathLB.SetSublistOpenWithLeftRight();
     389           0 :     maCertPathLB.SetSelectHdl( LINK( this, CertificateViewerCertPathTP, CertSelectHdl ) );
     390           0 :     maViewCertPB.SetClickHdl( LINK( this, CertificateViewerCertPathTP, ViewCertHdl ) );
     391             : 
     392             :     // check if buttontext is to wide
     393           0 :     const long nOffset = 10;
     394           0 :     OUString sText = maViewCertPB.GetText();
     395           0 :     long nTxtW = maViewCertPB.GetTextWidth( sText );
     396           0 :     if ( sText.indexOf( '~' ) == -1 )
     397           0 :         nTxtW += nOffset;
     398           0 :     long nBtnW = maViewCertPB.GetSizePixel().Width();
     399           0 :     if ( nTxtW > nBtnW )
     400             :     {
     401             :         // broaden the button
     402           0 :         long nDelta = nTxtW - nBtnW;
     403           0 :         Size aNewSize = maViewCertPB.GetSizePixel();
     404           0 :         aNewSize.Width() += nDelta;
     405           0 :         maViewCertPB.SetSizePixel( aNewSize );
     406             :         // and give it a new position
     407           0 :         Point aNewPos = maViewCertPB.GetPosPixel();
     408           0 :         aNewPos.X() -= nDelta;
     409           0 :         maViewCertPB.SetPosPixel( aNewPos );
     410           0 :     }
     411           0 : }
     412             : 
     413           0 : CertificateViewerCertPathTP::~CertificateViewerCertPathTP()
     414             : {
     415           0 :     Clear();
     416           0 : }
     417             : 
     418           0 : void CertificateViewerCertPathTP::ActivatePage()
     419             : {
     420           0 :     if ( !mbFirstActivateDone )
     421             :     {
     422           0 :         mbFirstActivateDone = true;
     423             :         Sequence< Reference< security::XCertificate > > aCertPath =
     424           0 :             mpParent->mxSecurityEnvironment->buildCertificatePath( mpParent->mxCert );
     425           0 :         const Reference< security::XCertificate >* pCertPath = aCertPath.getConstArray();
     426             : 
     427           0 :         sal_Int32 i, nCnt = aCertPath.getLength();
     428           0 :         SvTreeListEntry* pParent = NULL;
     429           0 :         for( i = nCnt; i; )
     430             :         {
     431           0 :             const Reference< security::XCertificate > rCert = pCertPath[ --i ];
     432           0 :             OUString sName = XmlSec::GetContentPart( rCert->getSubjectName() );
     433             :             //Verify the certificate
     434           0 :             sal_Int32 certStatus = mpDlg->mxSecurityEnvironment->verifyCertificate(rCert,
     435           0 :                  Sequence<Reference<css::security::XCertificate> >());
     436           0 :             bool bCertValid = certStatus == css::security::CertificateValidity::VALID ? true : false;
     437           0 :             pParent = InsertCert( pParent, sName, rCert, bCertValid);
     438           0 :         }
     439             : 
     440           0 :         maCertPathLB.Select( pParent );
     441           0 :         maViewCertPB.Disable(); // Own certificate selected
     442             : 
     443           0 :         while( pParent )
     444             :         {
     445           0 :             maCertPathLB.Expand( pParent );
     446           0 :             pParent = maCertPathLB.GetParent( pParent );
     447             :         }
     448             : 
     449           0 :         CertSelectHdl( NULL );
     450             :     }
     451           0 : }
     452             : 
     453           0 : IMPL_LINK_NOARG(CertificateViewerCertPathTP, ViewCertHdl)
     454             : {
     455           0 :     SvTreeListEntry* pEntry = maCertPathLB.FirstSelected();
     456           0 :     if( pEntry )
     457             :     {
     458           0 :         CertificateViewer aViewer( this, mpDlg->mxSecurityEnvironment, ((CertPath_UserData*)pEntry->GetUserData())->mxCert, false );
     459           0 :         aViewer.Execute();
     460             :     }
     461             : 
     462           0 :     return 0;
     463             : }
     464             : 
     465           0 : IMPL_LINK_NOARG(CertificateViewerCertPathTP, CertSelectHdl)
     466             : {
     467           0 :     OUString sStatus;
     468           0 :     SvTreeListEntry* pEntry = maCertPathLB.FirstSelected();
     469           0 :     if( pEntry )
     470             :     {
     471           0 :         CertPath_UserData* pData = (CertPath_UserData*) pEntry->GetUserData();
     472           0 :         if ( pData )
     473           0 :             sStatus = pData->mbValid ? msCertOK : msCertNotValidated;
     474             :     }
     475             : 
     476           0 :     maCertStatusML.SetText( sStatus );
     477           0 :     maViewCertPB.Enable( pEntry && ( pEntry != maCertPathLB.Last() ) );
     478           0 :     return 0;
     479             : }
     480             : 
     481           0 : void CertificateViewerCertPathTP::Clear( void )
     482             : {
     483           0 :     maCertStatusML.SetText( OUString() );
     484           0 :     sal_uLong           i = 0;
     485           0 :     SvTreeListEntry*    pEntry = maCertPathLB.GetEntry( i );
     486           0 :     while( pEntry )
     487             :     {
     488           0 :         delete ( CertPath_UserData* ) pEntry->GetUserData();
     489           0 :         ++i;
     490           0 :         pEntry = maCertPathLB.GetEntry( i );
     491             :     }
     492             : 
     493           0 :     maCertPathLB.Clear();
     494           0 : }
     495             : 
     496           0 : SvTreeListEntry* CertificateViewerCertPathTP::InsertCert(
     497             :     SvTreeListEntry* _pParent, const OUString& _rName, cssu::Reference< dcss::security::XCertificate > rxCert,
     498             :     bool bValid)
     499             : {
     500           0 :     Image aImage = bValid ? maCertImage : maCertNotValidatedImage;
     501           0 :     SvTreeListEntry* pEntry = maCertPathLB.InsertEntry( _rName, aImage, aImage, _pParent );
     502           0 :     pEntry->SetUserData( ( void* ) new CertPath_UserData( rxCert, bValid ) );
     503             : 
     504           0 :     return pEntry;
     505             : }
     506             : 
     507             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10