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