LCOV - code coverage report
Current view: top level - xmlsecurity/source/dialogs - certificateviewer.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 293 0.0 %
Date: 2014-04-14 Functions: 0 30 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             : #include <vcl/settings.hxx>
      35             : 
      36             : using namespace ::com::sun::star;
      37             : using namespace ::com::sun::star::uno;
      38             : 
      39             : namespace
      40             : {
      41           0 :     void ShrinkToFit( FixedImage& _rImg )
      42             :     {
      43           0 :         _rImg.SetSizePixel( _rImg.GetImage().GetSizePixel() );
      44           0 :     }
      45             : }
      46             : 
      47           0 : CertificateViewer::CertificateViewer(
      48             :         Window* _pParent,
      49             :         const css::uno::Reference< css::xml::crypto::XSecurityEnvironment >& _rxSecurityEnvironment,
      50             :         const css::uno::Reference< css::security::XCertificate >& _rXCert, bool bCheckForPrivateKey )
      51           0 :     : TabDialog(_pParent, "ViewCertDialog", "xmlsec/ui/viewcertdialog.ui" )
      52             : {
      53           0 :     get(mpTabCtrl, "tabcontrol");
      54             : 
      55           0 :     mbCheckForPrivateKey = bCheckForPrivateKey;
      56             : 
      57           0 :     mxSecurityEnvironment = _rxSecurityEnvironment;
      58           0 :     mxCert = _rXCert;
      59             : 
      60           0 :     mnGeneralId = mpTabCtrl->GetPageId("general");
      61           0 :     mnDetailsId = mpTabCtrl->GetPageId("details");
      62           0 :     mnPathId = mpTabCtrl->GetPageId("path");
      63             : 
      64           0 :     mpTabCtrl->SetTabPage(mnGeneralId, new CertificateViewerGeneralTP( mpTabCtrl, this));
      65           0 :     mpTabCtrl->SetTabPage(mnDetailsId, new CertificateViewerDetailsTP( mpTabCtrl, this));
      66           0 :     mpTabCtrl->SetTabPage(mnPathId, new CertificateViewerCertPathTP( mpTabCtrl, this));
      67           0 :     mpTabCtrl->SetCurPageId(mnGeneralId);
      68           0 : }
      69             : 
      70           0 : CertificateViewer::~CertificateViewer()
      71             : {
      72           0 :     delete mpTabCtrl->GetTabPage(mnGeneralId);
      73           0 :     delete mpTabCtrl->GetTabPage(mnDetailsId);
      74           0 :     delete mpTabCtrl->GetTabPage(mnPathId);
      75           0 : }
      76             : 
      77           0 : CertificateViewerTP::CertificateViewerTP( Window* _pParent, const ResId& _rResId, CertificateViewer* _pDlg )
      78             :     :TabPage        ( _pParent, _rResId )
      79           0 :     ,mpDlg          ( _pDlg )
      80             : {
      81           0 : }
      82             : 
      83           0 : CertificateViewerTP::CertificateViewerTP( Window* _pParent, const OString& rID,
      84             :     const OUString& rUIXMLDescription, CertificateViewer* _pDlg )
      85             :     : TabPage(_pParent, rID, rUIXMLDescription)
      86           0 :     , mpDlg(_pDlg)
      87             : {
      88           0 : }
      89             : 
      90           0 : CertificateViewerGeneralTP::CertificateViewerGeneralTP( Window* _pParent, CertificateViewer* _pDlg )
      91           0 :     :CertificateViewerTP    ( _pParent, XMLSEC_RES( RID_XMLSECTP_GENERAL ), _pDlg )
      92           0 :     ,maFrameWin             ( this, XMLSEC_RES( WIN_FRAME ) )
      93           0 :     ,maCertImg              ( this, XMLSEC_RES( IMG_CERT ) )
      94           0 :     ,maCertInfoFI           ( this, XMLSEC_RES( FI_CERTINFO ) )
      95           0 :     ,maSep1FL               ( this, XMLSEC_RES( FL_SEP1 ) )
      96           0 :     ,maHintNotTrustedFI     ( this, XMLSEC_RES( FI_HINTNOTTRUST ) )
      97           0 :     ,maSep2FL               ( this, XMLSEC_RES( FL_SEP2 ) )
      98           0 :     ,maIssuedToLabelFI      ( this, XMLSEC_RES( FI_ISSTOLABEL ) )
      99           0 :     ,maIssuedToFI           ( this, XMLSEC_RES( FI_ISSTO ) )
     100           0 :     ,maIssuedByLabelFI      ( this, XMLSEC_RES( FI_ISSBYLABEL ) )
     101           0 :     ,maIssuedByFI           ( this, XMLSEC_RES( FI_ISSBY ) )
     102           0 :     ,maValidDateFI          ( this, XMLSEC_RES( FI_VALIDDATE ) )
     103           0 :     ,maKeyImg               ( this, XMLSEC_RES( IMG_KEY ) )
     104           0 :     ,maHintCorrespPrivKeyFI ( this, XMLSEC_RES( FI_CORRPRIVKEY ) )
     105             : {
     106             :     //Verify the certificate
     107           0 :     sal_Int32 certStatus = mpDlg->mxSecurityEnvironment->verifyCertificate(mpDlg->mxCert,
     108           0 :          Sequence<Reference<css::security::XCertificate> >());
     109             : 
     110           0 :     bool bCertValid = certStatus == css::security::CertificateValidity::VALID ?  true : false;
     111             : 
     112           0 :     if ( !bCertValid )
     113             :     {
     114             :         maCertImg.SetImage(
     115           0 :             Image( XMLSEC_RES( IMG_STATE_NOT_VALIDATED ) ) );
     116           0 :         maHintNotTrustedFI.SetText( XMLSEC_RES( STR_CERTIFICATE_NOT_VALIDATED ) );
     117             :     }
     118             : 
     119           0 :     FreeResource();
     120             : 
     121           0 :     Wallpaper aBack( GetSettings().GetStyleSettings().GetWindowColor() );
     122           0 :     maFrameWin.SetBackground( aBack );
     123           0 :     maCertImg.SetBackground( aBack );
     124           0 :     maCertInfoFI.SetBackground( aBack );
     125           0 :     maSep1FL.SetBackground( aBack );
     126           0 :     maHintNotTrustedFI.SetBackground( aBack );
     127           0 :     maSep2FL.SetBackground( aBack );
     128           0 :     maIssuedToLabelFI.SetBackground( aBack );
     129           0 :     maIssuedToFI.SetBackground( aBack );
     130           0 :     maIssuedByLabelFI.SetBackground( aBack );
     131           0 :     maIssuedByFI.SetBackground( aBack );
     132           0 :     maValidDateFI.SetBackground( aBack );
     133           0 :     maKeyImg.SetBackground( aBack );
     134           0 :     maHintCorrespPrivKeyFI.SetBackground( aBack );
     135             : 
     136             :     // make some bold
     137           0 :     Font    aFnt( maCertInfoFI.GetFont() );
     138           0 :     aFnt.SetWeight( WEIGHT_BOLD );
     139           0 :     maCertInfoFI.SetFont( aFnt );
     140           0 :     maHintNotTrustedFI.SetFont( aFnt );
     141           0 :     maIssuedToLabelFI.SetFont( aFnt );
     142           0 :     maIssuedByLabelFI.SetFont( aFnt );
     143           0 :     maValidDateFI.SetFont( aFnt );
     144             : 
     145             :     // insert data
     146           0 :     css::uno::Reference< css::security::XCertificate > xCert = mpDlg->mxCert;
     147             : 
     148           0 :     maIssuedToFI.SetText( XmlSec::GetContentPart( xCert->getSubjectName() ) );
     149           0 :     maIssuedByFI.SetText( XmlSec::GetContentPart( xCert->getIssuerName() ) );
     150             : 
     151             :     // dynamic length because of the different languages
     152           0 :     long nWidth1 = maIssuedToLabelFI.GetTextWidth( maIssuedToLabelFI.GetText() );
     153           0 :     long nWidth2 = maIssuedByLabelFI.GetTextWidth( maIssuedByLabelFI.GetText() );
     154           0 :     long nNewWidth = std::max( nWidth1, nWidth2 ) + 5;
     155           0 :     Size aNewSize = maIssuedToLabelFI.GetSizePixel();
     156           0 :     aNewSize.Width() = nNewWidth;
     157           0 :     maIssuedToLabelFI.SetSizePixel( aNewSize );
     158           0 :     maIssuedByLabelFI.SetSizePixel( aNewSize );
     159           0 :     long nNewX = maIssuedToLabelFI.GetPosPixel().X() + nNewWidth + 1;
     160           0 :     Point aNewPos = maIssuedToFI.GetPosPixel();
     161           0 :     aNewPos.X() = nNewX;
     162           0 :     maIssuedToFI.SetPosPixel( aNewPos );
     163           0 :     aNewPos = maIssuedByFI.GetPosPixel();
     164           0 :     aNewPos.X() = nNewX;
     165           0 :     maIssuedByFI.SetPosPixel( aNewPos );
     166           0 :     nNewWidth = maValidDateFI.GetSizePixel().Width() - nNewX;
     167           0 :     aNewSize = maIssuedToFI.GetSizePixel();
     168           0 :     aNewSize.Width() = nNewWidth;
     169           0 :     maIssuedToFI.SetSizePixel( aNewSize );
     170           0 :     maIssuedByFI.SetSizePixel( aNewSize );
     171             : 
     172           0 :     DateTime aDateTimeStart( DateTime::EMPTY );
     173           0 :     DateTime aDateTimeEnd( DateTime::EMPTY );
     174           0 :     utl::typeConvert( xCert->getNotValidBefore(), aDateTimeStart );
     175           0 :     utl::typeConvert( xCert->getNotValidAfter(), aDateTimeEnd );
     176           0 :     OUString sText = maValidDateFI.GetText();
     177           0 :     sText = sText.replaceFirst( "%SDATE%",
     178           0 :         GetSettings().GetUILocaleDataWrapper().getDate( aDateTimeStart.GetDate() ) );
     179           0 :     sText = sText.replaceFirst( "%EDATE%",
     180           0 :         GetSettings().GetUILocaleDataWrapper().getDate( aDateTimeEnd.GetDate() ) );
     181           0 :     maValidDateFI.SetText( sText );
     182             : 
     183             :     // adjust position of fixed text depending on image sizes
     184           0 :     ShrinkToFit( maCertImg );
     185           0 :     ShrinkToFit( maKeyImg );
     186           0 :     XmlSec::AlignAfterImage( maCertImg, maCertInfoFI, 12 );
     187           0 :     XmlSec::AlignAfterImage( maKeyImg, maHintCorrespPrivKeyFI, 12 );
     188             : 
     189             :     // Check if we have the private key...
     190           0 :     sal_Bool bHasPrivateKey = sal_False;
     191             :     // #i41270# Check only if we have that certificate in our security environment
     192           0 :     if ( _pDlg->mbCheckForPrivateKey )
     193             :     {
     194           0 :         long nCertificateCharacters = _pDlg->mxSecurityEnvironment->getCertificateCharacters( xCert );
     195           0 :         bHasPrivateKey = ( nCertificateCharacters & security::CertificateCharacters::HAS_PRIVATE_KEY ) ? sal_True : sal_False;
     196             :     }
     197           0 :     if ( !bHasPrivateKey )
     198             :     {
     199           0 :         maKeyImg.Hide();
     200           0 :         maHintCorrespPrivKeyFI.Hide();
     201           0 :     }
     202           0 : }
     203             : 
     204           0 : void CertificateViewerGeneralTP::ActivatePage()
     205             : {
     206             : 
     207           0 : }
     208             : 
     209             : 
     210           0 : struct Details_UserDatat
     211             : {
     212             :     OUString        maTxt;
     213             :     bool            mbFixedWidthFont;
     214             : 
     215             :     inline          Details_UserDatat( const OUString& _rTxt, bool _bFixedWidthFont );
     216             : };
     217             : 
     218           0 : inline Details_UserDatat::Details_UserDatat( const OUString& _rTxt, bool _bFixedWidthFont )
     219             :     :maTxt              ( _rTxt )
     220           0 :     ,mbFixedWidthFont   ( _bFixedWidthFont )
     221             : {
     222           0 : }
     223             : 
     224             : 
     225           0 : void CertificateViewerDetailsTP::Clear( void )
     226             : {
     227           0 :     maElementML.SetText( OUString() );
     228           0 :     sal_uLong           i = 0;
     229           0 :     SvTreeListEntry*    pEntry = maElementsLB.GetEntry( i );
     230           0 :     while( pEntry )
     231             :     {
     232           0 :         delete ( Details_UserDatat* ) pEntry->GetUserData();
     233           0 :         ++i;
     234           0 :         pEntry = maElementsLB.GetEntry( i );
     235             :     }
     236             : 
     237           0 :     maElementsLB.Clear();
     238           0 : }
     239             : 
     240           0 : void CertificateViewerDetailsTP::InsertElement( const OUString& _rField, const OUString& _rValue,
     241             :                                                 const OUString& _rDetails, bool _bFixedWidthFont )
     242             : {
     243           0 :     SvTreeListEntry*    pEntry = maElementsLB.InsertEntry( _rField );
     244           0 :     maElementsLB.SetEntryText( _rValue, pEntry, 1 );
     245           0 :     pEntry->SetUserData( ( void* ) new Details_UserDatat( _rDetails, _bFixedWidthFont ) );
     246           0 : }
     247             : 
     248           0 : CertificateViewerDetailsTP::CertificateViewerDetailsTP( Window* _pParent, CertificateViewer* _pDlg )
     249           0 :     :CertificateViewerTP    ( _pParent, XMLSEC_RES( RID_XMLSECTP_DETAILS ), _pDlg  )
     250           0 :     ,m_aElementsLBContainer(this, XMLSEC_RES(LB_ELEMENTS))
     251             :     ,maElementsLB(m_aElementsLBContainer)
     252           0 :     ,maElementML            ( this, XMLSEC_RES( ML_ELEMENT ) )
     253             :     ,maStdFont              ( maElementML.GetControlFont() )
     254           0 :     ,maFixedWidthFont       ( OutputDevice::GetDefaultFont( DEFAULTFONT_UI_FIXED, LANGUAGE_DONTKNOW, DEFAULTFONT_FLAGS_ONLYONE, this ) )
     255             : {
     256           0 :     WinBits nStyle = maElementsLB.GetStyle();
     257           0 :     nStyle &= ~WB_HSCROLL;
     258           0 :     maElementsLB.SetStyle( nStyle );
     259             : 
     260           0 :     maFixedWidthFont.SetHeight( maStdFont.GetHeight() );
     261             : 
     262             :     static long nTabs[] = { 2, 0, 30*CS_LB_WIDTH/100 };
     263           0 :     maElementsLB.SetTabs( &nTabs[ 0 ] );
     264           0 :     maElementsLB.InsertHeaderEntry( XMLSEC_RES( STR_HEADERBAR ) );
     265             : 
     266             :     // fill list box
     267           0 :     Reference< security::XCertificate > xCert = mpDlg->mxCert;
     268           0 :     sal_uInt16                  nLineBreak = 16;
     269           0 :     const char*             pHexSep = " ";
     270           0 :     OUString                aLBEntry;
     271           0 :     OUString                aDetails;
     272             :     // Certificate Versions are reported wrong (#i35107#) - 0 == "V1", 1 == "V2", ..., n = "V(n+1)"
     273           0 :     aLBEntry = "V" + OUString::number( xCert->getVersion() + 1 );
     274           0 :     InsertElement( XMLSEC_RES( STR_VERSION ), aLBEntry, aLBEntry );
     275           0 :     Sequence< sal_Int8 >    aSeq = xCert->getSerialNumber();
     276           0 :     aLBEntry = XmlSec::GetHexString( aSeq, pHexSep );
     277           0 :     aDetails = XmlSec::GetHexString( aSeq, pHexSep, nLineBreak );
     278           0 :     InsertElement( XMLSEC_RES( STR_SERIALNUM ), aLBEntry, aDetails, true );
     279             : 
     280             :     std::pair< OUString, OUString> pairIssuer =
     281           0 :         XmlSec::GetDNForCertDetailsView(xCert->getIssuerName());
     282           0 :     aLBEntry = pairIssuer.first;
     283           0 :     aDetails = pairIssuer.second;
     284           0 :     InsertElement( XMLSEC_RES( STR_ISSUER ), aLBEntry, aDetails );
     285             : 
     286           0 :     DateTime aDateTime( DateTime::EMPTY );
     287           0 :     utl::typeConvert( xCert->getNotValidBefore(), aDateTime );
     288           0 :     aLBEntry = GetSettings().GetUILocaleDataWrapper().getDate( aDateTime.GetDate() );
     289           0 :     aLBEntry += " ";
     290           0 :     aLBEntry += GetSettings().GetUILocaleDataWrapper().getTime( aDateTime.GetTime() );
     291           0 :     InsertElement( XMLSEC_RES( STR_VALIDFROM ), aLBEntry, aLBEntry  );
     292           0 :     utl::typeConvert( xCert->getNotValidAfter(), aDateTime );
     293           0 :     aLBEntry = GetSettings().GetUILocaleDataWrapper().getDate( aDateTime.GetDate() );
     294           0 :     aLBEntry += " ";
     295           0 :     aLBEntry += GetSettings().GetUILocaleDataWrapper().getTime( aDateTime.GetTime() );
     296           0 :     InsertElement( XMLSEC_RES( STR_VALIDTO ), aLBEntry, aLBEntry );
     297             : 
     298             :     std::pair< OUString, OUString > pairSubject =
     299           0 :         XmlSec::GetDNForCertDetailsView(xCert->getSubjectName());
     300           0 :     aLBEntry = pairSubject.first;
     301           0 :     aDetails = pairSubject.second;
     302           0 :     InsertElement( XMLSEC_RES( STR_SUBJECT ), aLBEntry, aDetails );
     303             : 
     304           0 :     aLBEntry = aDetails = xCert->getSubjectPublicKeyAlgorithm();
     305           0 :     InsertElement( XMLSEC_RES( STR_SUBJECT_PUBKEY_ALGO ), aLBEntry, aDetails );
     306           0 :     aSeq = xCert->getSubjectPublicKeyValue();
     307           0 :     aLBEntry = XmlSec::GetHexString( aSeq, pHexSep );
     308           0 :     aDetails = XmlSec::GetHexString( aSeq, pHexSep, nLineBreak );
     309           0 :     InsertElement( XMLSEC_RES( STR_SUBJECT_PUBKEY_VAL ), aLBEntry, aDetails, true );
     310             : 
     311           0 :     aLBEntry = aDetails = xCert->getSignatureAlgorithm();
     312           0 :     InsertElement( XMLSEC_RES( STR_SIGNATURE_ALGO ), aLBEntry, aDetails );
     313             : 
     314           0 :     aSeq = xCert->getSHA1Thumbprint();
     315           0 :     aLBEntry = XmlSec::GetHexString( aSeq, pHexSep );
     316           0 :     aDetails = XmlSec::GetHexString( aSeq, pHexSep, nLineBreak );
     317           0 :     InsertElement( XMLSEC_RES( STR_THUMBPRINT_SHA1 ), aLBEntry, aDetails, true );
     318             : 
     319           0 :     aSeq = xCert->getMD5Thumbprint();
     320           0 :     aLBEntry = XmlSec::GetHexString( aSeq, pHexSep );
     321           0 :     aDetails = XmlSec::GetHexString( aSeq, pHexSep, nLineBreak );
     322           0 :     InsertElement( XMLSEC_RES( STR_THUMBPRINT_MD5 ), aLBEntry, aDetails, true );
     323             : 
     324           0 :     FreeResource();
     325             : 
     326           0 :     maElementsLB.SetSelectHdl( LINK( this, CertificateViewerDetailsTP, ElementSelectHdl ) );
     327           0 : }
     328             : 
     329           0 : CertificateViewerDetailsTP::~CertificateViewerDetailsTP()
     330             : {
     331           0 :     Clear();
     332           0 : }
     333             : 
     334           0 : void CertificateViewerDetailsTP::ActivatePage()
     335             : {
     336           0 : }
     337             : 
     338           0 : IMPL_LINK_NOARG(CertificateViewerDetailsTP, ElementSelectHdl)
     339             : {
     340           0 :     SvTreeListEntry*    pEntry = maElementsLB.FirstSelected();
     341           0 :     OUString        aElementText;
     342             :     bool            bFixedWidthFont;
     343           0 :     if( pEntry )
     344             :     {
     345           0 :         const Details_UserDatat*    p = ( Details_UserDatat* ) pEntry->GetUserData();
     346           0 :         aElementText = p->maTxt;
     347           0 :         bFixedWidthFont = p->mbFixedWidthFont;
     348             :     }
     349             :     else
     350           0 :         bFixedWidthFont = false;
     351             : 
     352           0 :     maElementML.SetFont( bFixedWidthFont? maFixedWidthFont : maStdFont );
     353           0 :     maElementML.SetControlFont( bFixedWidthFont? maFixedWidthFont : maStdFont );
     354           0 :     maElementML.SetText( aElementText );
     355             : 
     356           0 :     return 0;
     357             : }
     358             : 
     359           0 : struct CertPath_UserData
     360             : {
     361             :     css::uno::Reference< css::security::XCertificate > mxCert;
     362             :     OUString                                        maStatus;
     363             :     bool mbValid;
     364             : 
     365           0 :     CertPath_UserData( css::uno::Reference< css::security::XCertificate > xCert, bool bValid):
     366             :         mxCert(xCert),
     367           0 :         mbValid(bValid)
     368             :     {
     369           0 :     }
     370             : };
     371             : 
     372             : 
     373           0 : CertificateViewerCertPathTP::CertificateViewerCertPathTP( Window* _pParent, CertificateViewer* _pDlg )
     374             :     : CertificateViewerTP(_pParent, "CertPage", "xmlsec/ui/certpage.ui", _pDlg)
     375             :     , mpParent(_pDlg)
     376           0 :     , mbFirstActivateDone(false)
     377             : {
     378           0 :     get(mpCertPathLB, "signatures");
     379           0 :     get(mpViewCertPB, "viewcert");
     380           0 :     get(mpCertStatusML, "status");
     381             : 
     382           0 :     msCertOK = get<FixedText>("certok")->GetText();
     383           0 :     msCertNotValidated = get<FixedText>("certnotok")->GetText();
     384           0 :     maCertImage = get<FixedImage>("imgok")->GetImage();
     385           0 :     maCertNotValidatedImage = get<FixedImage>("imgnotok")->GetImage();
     386             : 
     387           0 :     Size aControlSize(LogicToPixel(Size(251, 45), MAP_APPFONT));
     388           0 :     mpCertPathLB->set_width_request(aControlSize.Width());
     389           0 :     mpCertPathLB->set_height_request(aControlSize.Height());
     390           0 :     mpCertStatusML->set_width_request(aControlSize.Width());
     391           0 :     mpCertStatusML->set_height_request(aControlSize.Height());
     392             : 
     393           0 :     mpCertPathLB->SetNodeDefaultImages();
     394           0 :     mpCertPathLB->SetSublistOpenWithLeftRight();
     395           0 :     mpCertPathLB->SetSelectHdl( LINK( this, CertificateViewerCertPathTP, CertSelectHdl ) );
     396           0 :     mpViewCertPB->SetClickHdl( LINK( this, CertificateViewerCertPathTP, ViewCertHdl ) );
     397           0 : }
     398             : 
     399           0 : CertificateViewerCertPathTP::~CertificateViewerCertPathTP()
     400             : {
     401           0 :     Clear();
     402           0 : }
     403             : 
     404           0 : void CertificateViewerCertPathTP::ActivatePage()
     405             : {
     406           0 :     if ( !mbFirstActivateDone )
     407             :     {
     408           0 :         mbFirstActivateDone = true;
     409             :         Sequence< Reference< security::XCertificate > > aCertPath =
     410           0 :             mpParent->mxSecurityEnvironment->buildCertificatePath( mpParent->mxCert );
     411           0 :         const Reference< security::XCertificate >* pCertPath = aCertPath.getConstArray();
     412             : 
     413           0 :         sal_Int32 i, nCnt = aCertPath.getLength();
     414           0 :         SvTreeListEntry* pParent = NULL;
     415           0 :         for( i = nCnt; i; )
     416             :         {
     417           0 :             const Reference< security::XCertificate > rCert = pCertPath[ --i ];
     418           0 :             OUString sName = XmlSec::GetContentPart( rCert->getSubjectName() );
     419             :             //Verify the certificate
     420           0 :             sal_Int32 certStatus = mpDlg->mxSecurityEnvironment->verifyCertificate(rCert,
     421           0 :                  Sequence<Reference<css::security::XCertificate> >());
     422           0 :             bool bCertValid = certStatus == css::security::CertificateValidity::VALID ? true : false;
     423           0 :             pParent = InsertCert( pParent, sName, rCert, bCertValid);
     424           0 :         }
     425             : 
     426           0 :         mpCertPathLB->Select( pParent );
     427           0 :         mpViewCertPB->Disable(); // Own certificate selected
     428             : 
     429           0 :         while( pParent )
     430             :         {
     431           0 :             mpCertPathLB->Expand( pParent );
     432           0 :             pParent = mpCertPathLB->GetParent( pParent );
     433             :         }
     434             : 
     435           0 :         CertSelectHdl( NULL );
     436             :     }
     437           0 : }
     438             : 
     439           0 : IMPL_LINK_NOARG(CertificateViewerCertPathTP, ViewCertHdl)
     440             : {
     441           0 :     SvTreeListEntry* pEntry = mpCertPathLB->FirstSelected();
     442           0 :     if( pEntry )
     443             :     {
     444           0 :         CertificateViewer aViewer( this, mpDlg->mxSecurityEnvironment, ((CertPath_UserData*)pEntry->GetUserData())->mxCert, false );
     445           0 :         aViewer.Execute();
     446             :     }
     447             : 
     448           0 :     return 0;
     449             : }
     450             : 
     451           0 : IMPL_LINK_NOARG(CertificateViewerCertPathTP, CertSelectHdl)
     452             : {
     453           0 :     OUString sStatus;
     454           0 :     SvTreeListEntry* pEntry = mpCertPathLB->FirstSelected();
     455           0 :     if( pEntry )
     456             :     {
     457           0 :         CertPath_UserData* pData = (CertPath_UserData*) pEntry->GetUserData();
     458           0 :         if ( pData )
     459           0 :             sStatus = pData->mbValid ? msCertOK : msCertNotValidated;
     460             :     }
     461             : 
     462           0 :     mpCertStatusML->SetText( sStatus );
     463           0 :     mpViewCertPB->Enable( pEntry && ( pEntry != mpCertPathLB->Last() ) );
     464           0 :     return 0;
     465             : }
     466             : 
     467           0 : void CertificateViewerCertPathTP::Clear( void )
     468             : {
     469           0 :     mpCertStatusML->SetText( OUString() );
     470           0 :     sal_uLong           i = 0;
     471           0 :     SvTreeListEntry*    pEntry = mpCertPathLB->GetEntry( i );
     472           0 :     while( pEntry )
     473             :     {
     474           0 :         delete ( CertPath_UserData* ) pEntry->GetUserData();
     475           0 :         ++i;
     476           0 :         pEntry = mpCertPathLB->GetEntry( i );
     477             :     }
     478             : 
     479           0 :     mpCertPathLB->Clear();
     480           0 : }
     481             : 
     482           0 : SvTreeListEntry* CertificateViewerCertPathTP::InsertCert(
     483             :     SvTreeListEntry* _pParent, const OUString& _rName, css::uno::Reference< css::security::XCertificate > rxCert,
     484             :     bool bValid)
     485             : {
     486           0 :     Image aImage = bValid ? maCertImage : maCertNotValidatedImage;
     487           0 :     SvTreeListEntry* pEntry = mpCertPathLB->InsertEntry( _rName, aImage, aImage, _pParent );
     488           0 :     pEntry->SetUserData( ( void* ) new CertPath_UserData( rxCert, bValid ) );
     489             : 
     490           0 :     return pEntry;
     491             : }
     492             : 
     493             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10