LCOV - code coverage report
Current view: top level - xmlsecurity/source/dialogs - certificateviewer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 303 0.0 %
Date: 2012-08-25 Functions: 0 29 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 866 0.0 %

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

Generated by: LCOV version 1.10