merge the formfield patch from ooo-build
[ooovba.git] / xmlsecurity / source / dialogs / certificateviewer.cxx
blob4bc825147ef11732b5923d2050b2938cea62e493
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: certificateviewer.cxx,v $
10 * $Revision: 1.25 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmlsecurity.hxx"
33 #include <xmlsecurity/certificateviewer.hxx>
34 #include <com/sun/star/security/XCertificate.hpp>
36 #include <com/sun/star/security/CertificateCharacters.hpp>
37 #include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp>
38 #include <com/sun/star/security/CertificateValidity.hpp>
40 #include <unotools/localedatawrapper.hxx>
41 #include <unotools/datetime.hxx>
43 #include "dialogs.hrc"
44 #include "resourcemanager.hxx"
46 /* HACK: disable some warnings for MS-C */
47 #ifdef _MSC_VER
48 #pragma warning (disable : 4355) // 4355: this used in initializer-list
49 #endif
51 using namespace ::com::sun::star;
52 using namespace ::com::sun::star::uno;
53 namespace css = ::com::sun::star;
56 namespace
58 void ShrinkToFit( FixedImage& _rImage );
59 void AdjustPosAndSize( Control& _rCtrl, Point& _rStartIn_EndOut, long _nXOffset = 0 );
61 void ShrinkToFit( FixedImage& _rImg )
63 _rImg.SetSizePixel( _rImg.GetImage().GetSizePixel() );
66 void AdjustPosAndSize( Control& _rCtrl, Point& _rStartIn_EndOut, long _nOffs )
68 _rCtrl.SetPosPixel( _rStartIn_EndOut );
69 _rStartIn_EndOut.X() += XmlSec::ShrinkToFitWidth( _rCtrl, _nOffs );
73 CertificateViewer::CertificateViewer(
74 Window* _pParent,
75 const cssu::Reference< dcss::xml::crypto::XSecurityEnvironment >& _rxSecurityEnvironment,
76 const cssu::Reference< dcss::security::XCertificate >& _rXCert, BOOL bCheckForPrivateKey )
77 :TabDialog ( _pParent, XMLSEC_RES( RID_XMLSECDLG_CERTVIEWER ) )
78 ,maTabCtrl ( this, XMLSEC_RES( 1 ) )
79 ,maOkBtn ( this, XMLSEC_RES( BTN_OK ) )
80 ,maHelpBtn ( this, XMLSEC_RES( BTN_HELP ) )
82 FreeResource();
84 mbCheckForPrivateKey = bCheckForPrivateKey;
86 mxSecurityEnvironment = _rxSecurityEnvironment;
87 mxCert = _rXCert;
89 maTabCtrl.SetTabPage( RID_XMLSECTP_GENERAL, new CertificateViewerGeneralTP( &maTabCtrl, this ) );
90 maTabCtrl.SetTabPage( RID_XMLSECTP_DETAILS, new CertificateViewerDetailsTP( &maTabCtrl, this ) );
91 maTabCtrl.SetTabPage( RID_XMLSECTP_CERTPATH, new CertificateViewerCertPathTP( &maTabCtrl, this ) );
92 maTabCtrl.SetCurPageId( RID_XMLSECTP_GENERAL );
95 CertificateViewer::~CertificateViewer()
97 delete maTabCtrl.GetTabPage( RID_XMLSECTP_CERTPATH );
98 delete maTabCtrl.GetTabPage( RID_XMLSECTP_DETAILS );
99 delete maTabCtrl.GetTabPage( RID_XMLSECTP_GENERAL );
102 CertificateViewerTP::CertificateViewerTP( Window* _pParent, const ResId& _rResId, CertificateViewer* _pDlg )
103 :TabPage ( _pParent, _rResId )
104 ,mpDlg ( _pDlg )
109 CertificateViewerGeneralTP::CertificateViewerGeneralTP( Window* _pParent, CertificateViewer* _pDlg )
110 :CertificateViewerTP ( _pParent, XMLSEC_RES( RID_XMLSECTP_GENERAL ), _pDlg )
111 ,maFrameWin ( this, XMLSEC_RES( WIN_FRAME ) )
112 ,maCertImg ( this, XMLSEC_RES( IMG_CERT ) )
113 ,maCertInfoFI ( this, XMLSEC_RES( FI_CERTINFO ) )
114 ,maSep1FL ( this, XMLSEC_RES( FL_SEP1 ) )
115 ,maHintNotTrustedFI ( this, XMLSEC_RES( FI_HINTNOTTRUST ) )
116 ,maSep2FL ( this, XMLSEC_RES( FL_SEP2 ) )
117 ,maIssuedToLabelFI ( this, XMLSEC_RES( FI_ISSTOLABEL ) )
118 ,maIssuedToFI ( this, XMLSEC_RES( FI_ISSTO ) )
119 ,maIssuedByLabelFI ( this, XMLSEC_RES( FI_ISSBYLABEL ) )
120 ,maIssuedByFI ( this, XMLSEC_RES( FI_ISSBY ) )
121 ,maValidDateFI ( this, XMLSEC_RES( FI_VALIDDATE ) )
122 ,maKeyImg ( this, XMLSEC_RES( IMG_KEY ) )
123 ,maHintCorrespPrivKeyFI ( this, XMLSEC_RES( FI_CORRPRIVKEY ) )
125 if ( GetSettings().GetStyleSettings().GetWindowColor().IsDark() )
126 maKeyImg.SetImage( Image( XMLSEC_RES( IMG_KEY_HC ) ) );
128 //Verify the certificate
129 sal_Int32 certStatus = mpDlg->mxSecurityEnvironment->verifyCertificate(mpDlg->mxCert,
130 Sequence<Reference<css::security::XCertificate> >());
131 //We currently have two status
132 //These errors are alloweds
133 sal_Int32 validCertErrors = css::security::CertificateValidity::VALID
134 | css::security::CertificateValidity::UNKNOWN_REVOKATION;
136 //Build a mask to filter out the allowed errors
137 sal_Int32 mask = ~validCertErrors;
138 // "subtract" the allowed error flags from the result
139 sal_Int32 certErrors = certStatus & mask;
140 bool bCertValid = certErrors > 0 ? false : true;
142 bool bIsDark = ( GetSettings().GetStyleSettings().GetWindowColor().IsDark() != FALSE );
143 if ( !bCertValid )
145 maCertImg.SetImage(
146 Image( XMLSEC_RES( bIsDark ? IMG_STATE_NOT_VALIDATED_HC : IMG_STATE_NOT_VALIDATED ) ) );
147 maHintNotTrustedFI.SetText( String( XMLSEC_RES( STR_CERTIFICATE_NOT_VALIDATED ) ) );
149 else if ( bIsDark )
150 maCertImg.SetImage( Image( XMLSEC_RES( IMG_STATE_CERIFICATED_HC ) ) );
152 FreeResource();
154 Wallpaper aBack( GetSettings().GetStyleSettings().GetWindowColor() );
155 maFrameWin.SetBackground( aBack );
156 maCertImg.SetBackground( aBack );
157 maCertInfoFI.SetBackground( aBack );
158 maSep1FL.SetBackground( aBack );
159 maHintNotTrustedFI.SetBackground( aBack );
160 maSep2FL.SetBackground( aBack );
161 maIssuedToLabelFI.SetBackground( aBack );
162 maIssuedToFI.SetBackground( aBack );
163 maIssuedByLabelFI.SetBackground( aBack );
164 maIssuedByFI.SetBackground( aBack );
165 maValidDateFI.SetBackground( aBack );
166 maKeyImg.SetBackground( aBack );
167 maHintCorrespPrivKeyFI.SetBackground( aBack );
169 // make some bold
170 Font aFnt( maCertInfoFI.GetFont() );
171 aFnt.SetWeight( WEIGHT_BOLD );
172 maCertInfoFI.SetFont( aFnt );
173 maHintNotTrustedFI.SetFont( aFnt );
174 maIssuedToLabelFI.SetFont( aFnt );
175 maIssuedByLabelFI.SetFont( aFnt );
176 maValidDateFI.SetFont( aFnt );
178 // insert data
179 cssu::Reference< dcss::security::XCertificate > xCert = mpDlg->mxCert;
181 maIssuedToFI.SetText( XmlSec::GetContentPart( xCert->getSubjectName() ) );
182 maIssuedByFI.SetText( XmlSec::GetContentPart( xCert->getIssuerName() ) );
184 // dynamic length because of the different languages
185 long nWidth1 = maIssuedToLabelFI.GetTextWidth( maIssuedToLabelFI.GetText() );
186 long nWidth2 = maIssuedByLabelFI.GetTextWidth( maIssuedByLabelFI.GetText() );
187 long nNewWidth = Max( nWidth1, nWidth2 ) + 5;
188 Size aNewSize = maIssuedToLabelFI.GetSizePixel();
189 aNewSize.Width() = nNewWidth;
190 maIssuedToLabelFI.SetSizePixel( aNewSize );
191 maIssuedByLabelFI.SetSizePixel( aNewSize );
192 long nNewX = maIssuedToLabelFI.GetPosPixel().X() + nNewWidth + 1;
193 Point aNewPos = maIssuedToFI.GetPosPixel();
194 aNewPos.X() = nNewX;
195 maIssuedToFI.SetPosPixel( aNewPos );
196 aNewPos = maIssuedByFI.GetPosPixel();
197 aNewPos.X() = nNewX;
198 maIssuedByFI.SetPosPixel( aNewPos );
199 nNewWidth = maValidDateFI.GetSizePixel().Width() - nNewX;
200 aNewSize = maIssuedToFI.GetSizePixel();
201 aNewSize.Width() = nNewWidth;
202 maIssuedToFI.SetSizePixel( aNewSize );
203 maIssuedByFI.SetSizePixel( aNewSize );
205 DateTime aDateTimeStart;
206 DateTime aDateTimeEnd;
207 utl::typeConvert( xCert->getNotValidBefore(), aDateTimeStart );
208 utl::typeConvert( xCert->getNotValidAfter(), aDateTimeEnd );
209 String sText = maValidDateFI.GetText();
210 sText.SearchAndReplace( String::CreateFromAscii( "%SDATE%" ),
211 GetSettings().GetUILocaleDataWrapper().getDate( aDateTimeStart.GetDate() ) );
212 sText.SearchAndReplace( String::CreateFromAscii( "%EDATE%" ),
213 GetSettings().GetUILocaleDataWrapper().getDate( aDateTimeEnd.GetDate() ) );
214 maValidDateFI.SetText( sText );
216 // adjust position of fixed text depending on image sizes
217 ShrinkToFit( maCertImg );
218 ShrinkToFit( maKeyImg );
219 XmlSec::AlignAfterImage( maCertImg, maCertInfoFI, 12 );
220 XmlSec::AlignAfterImage( maKeyImg, maHintCorrespPrivKeyFI, 12 );
222 // Check if we have the private key...
223 BOOL bHasPrivateKey = FALSE;
224 // #i41270# Check only if we have that certificate in our security environment
225 if ( _pDlg->mbCheckForPrivateKey )
227 long nCertificateCharacters = _pDlg->mxSecurityEnvironment->getCertificateCharacters( xCert );
228 bHasPrivateKey = ( nCertificateCharacters & security::CertificateCharacters::HAS_PRIVATE_KEY ) ? TRUE : FALSE;
230 if ( !bHasPrivateKey )
232 maKeyImg.Hide();
233 maHintCorrespPrivKeyFI.Hide();
237 void CertificateViewerGeneralTP::ActivatePage()
243 struct Details_UserDatat
245 String maTxt;
246 bool mbFixedWidthFont;
248 inline Details_UserDatat( const String& _rTxt, bool _bFixedWidthFont );
251 inline Details_UserDatat::Details_UserDatat( const String& _rTxt, bool _bFixedWidthFont )
252 :maTxt ( _rTxt )
253 ,mbFixedWidthFont ( _bFixedWidthFont )
258 void CertificateViewerDetailsTP::Clear( void )
260 maElementML.SetText( String() );
261 ULONG i = 0;
262 SvLBoxEntry* pEntry = maElementsLB.GetEntry( i );
263 while( pEntry )
265 delete ( Details_UserDatat* ) pEntry->GetUserData();
266 ++i;
267 pEntry = maElementsLB.GetEntry( i );
270 maElementsLB.Clear();
273 void CertificateViewerDetailsTP::InsertElement( const String& _rField, const String& _rValue,
274 const String& _rDetails, bool _bFixedWidthFont )
276 SvLBoxEntry* pEntry = maElementsLB.InsertEntry( _rField );
277 maElementsLB.SetEntryText( _rValue, pEntry, 1 );
278 pEntry->SetUserData( ( void* ) new Details_UserDatat( _rDetails, _bFixedWidthFont ) );
281 CertificateViewerDetailsTP::CertificateViewerDetailsTP( Window* _pParent, CertificateViewer* _pDlg )
282 :CertificateViewerTP ( _pParent, XMLSEC_RES( RID_XMLSECTP_DETAILS ), _pDlg )
283 ,maElementsLB ( this, XMLSEC_RES( LB_ELEMENTS ) )
284 ,maElementML ( this, XMLSEC_RES( ML_ELEMENT ) )
285 ,maStdFont ( maElementML.GetControlFont() )
286 ,maFixedWidthFont ( OutputDevice::GetDefaultFont( DEFAULTFONT_UI_FIXED, LANGUAGE_DONTKNOW, DEFAULTFONT_FLAGS_ONLYONE, this ) )
288 WinBits nStyle = maElementsLB.GetStyle();
289 nStyle &= ~WB_HSCROLL;
290 maElementsLB.SetStyle( nStyle );
292 maFixedWidthFont.SetHeight( maStdFont.GetHeight() );
294 static long nTabs[] = { 2, 0, 30*CS_LB_WIDTH/100 };
295 maElementsLB.SetTabs( &nTabs[ 0 ] );
296 maElementsLB.InsertHeaderEntry( String( XMLSEC_RES( STR_HEADERBAR ) ) );
298 // fill list box
299 Reference< security::XCertificate > xCert = mpDlg->mxCert;
300 UINT16 nLineBreak = 16;
301 const char* pHexSep = " ";
302 String aLBEntry;
303 String aDetails;
304 // --> PB 2004-10-11 #i35107# - 0 == "V1", 1 == "V2", ..., n = "V(n+1)"
305 aLBEntry = String::CreateFromAscii( "V" );
306 aLBEntry += String::CreateFromInt32( xCert->getVersion() + 1 );
307 // <--
308 InsertElement( String( XMLSEC_RES( STR_VERSION ) ), aLBEntry, aLBEntry );
309 Sequence< sal_Int8 > aSeq = xCert->getSerialNumber();
310 aLBEntry = XmlSec::GetHexString( aSeq, pHexSep );
311 aDetails = XmlSec::GetHexString( aSeq, pHexSep, nLineBreak );
312 InsertElement( String( XMLSEC_RES( STR_SERIALNUM ) ), aLBEntry, aDetails, true );
314 std::pair< ::rtl::OUString, ::rtl::OUString> pairIssuer =
315 XmlSec::GetDNForCertDetailsView(xCert->getIssuerName());
316 aLBEntry = pairIssuer.first;
317 aDetails = pairIssuer.second;
318 InsertElement( String( XMLSEC_RES( STR_ISSUER ) ), aLBEntry, aDetails );
320 aSeq = xCert->getIssuerUniqueID();
321 aLBEntry = XmlSec::GetHexString( aSeq, pHexSep );
322 aDetails = XmlSec::GetHexString( aSeq, pHexSep, nLineBreak );
323 InsertElement( String( XMLSEC_RES( STR_ISSUER_ID ) ), aLBEntry, aDetails, true );
326 DateTime aDateTime;
327 utl::typeConvert( xCert->getNotValidBefore(), aDateTime );
328 aLBEntry = GetSettings().GetUILocaleDataWrapper().getDate( aDateTime.GetDate() );
329 aLBEntry += String::CreateFromAscii( " " );
330 aLBEntry += GetSettings().GetUILocaleDataWrapper().getTime( aDateTime.GetTime() );
331 InsertElement( String( XMLSEC_RES( STR_VALIDFROM ) ), aLBEntry, aLBEntry );
332 utl::typeConvert( xCert->getNotValidAfter(), aDateTime );
333 aLBEntry = GetSettings().GetUILocaleDataWrapper().getDate( aDateTime.GetDate() );
334 aLBEntry += String::CreateFromAscii( " " );
335 aLBEntry += GetSettings().GetUILocaleDataWrapper().getTime( aDateTime.GetTime() );
336 InsertElement( String( XMLSEC_RES( STR_VALIDTO ) ), aLBEntry, aLBEntry );
338 std::pair< ::rtl::OUString, ::rtl::OUString > pairSubject =
339 XmlSec::GetDNForCertDetailsView(xCert->getSubjectName());
340 aLBEntry = pairSubject.first;
341 aDetails = pairSubject.second;
342 InsertElement( String( XMLSEC_RES( STR_SUBJECT ) ), aLBEntry, aDetails );
344 aSeq = xCert->getSubjectUniqueID();
345 aLBEntry = XmlSec::GetHexString( aSeq, pHexSep );
346 aDetails = XmlSec::GetHexString( aSeq, pHexSep, nLineBreak );
347 InsertElement( String( XMLSEC_RES( STR_SUBJECT_ID ) ), aLBEntry, aDetails, true );
349 aLBEntry = aDetails = xCert->getSubjectPublicKeyAlgorithm();
350 InsertElement( String( XMLSEC_RES( STR_SUBJECT_PUBKEY_ALGO ) ), aLBEntry, aDetails );
351 aSeq = xCert->getSubjectPublicKeyValue();
352 aLBEntry = XmlSec::GetHexString( aSeq, pHexSep );
353 aDetails = XmlSec::GetHexString( aSeq, pHexSep, nLineBreak );
354 InsertElement( String( XMLSEC_RES( STR_SUBJECT_PUBKEY_VAL ) ), aLBEntry, aDetails, true );
356 aLBEntry = aDetails = xCert->getSignatureAlgorithm();
357 InsertElement( String( XMLSEC_RES( STR_SIGNATURE_ALGO ) ), aLBEntry, aDetails );
359 aSeq = xCert->getSHA1Thumbprint();
360 aLBEntry = XmlSec::GetHexString( aSeq, pHexSep );
361 aDetails = XmlSec::GetHexString( aSeq, pHexSep, nLineBreak );
362 InsertElement( String( XMLSEC_RES( STR_THUMBPRINT_SHA1 ) ), aLBEntry, aDetails, true );
364 aSeq = xCert->getMD5Thumbprint();
365 aLBEntry = XmlSec::GetHexString( aSeq, pHexSep );
366 aDetails = XmlSec::GetHexString( aSeq, pHexSep, nLineBreak );
367 InsertElement( String( XMLSEC_RES( STR_THUMBPRINT_MD5 ) ), aLBEntry, aDetails, true );
369 FreeResource();
371 maElementsLB.SetSelectHdl( LINK( this, CertificateViewerDetailsTP, ElementSelectHdl ) );
374 CertificateViewerDetailsTP::~CertificateViewerDetailsTP()
376 Clear();
379 void CertificateViewerDetailsTP::ActivatePage()
383 IMPL_LINK( CertificateViewerDetailsTP, ElementSelectHdl, void*, EMPTYARG )
385 SvLBoxEntry* pEntry = maElementsLB.FirstSelected();
386 String aElementText;
387 bool bFixedWidthFont;
388 if( pEntry )
390 const Details_UserDatat* p = ( Details_UserDatat* ) pEntry->GetUserData();
391 aElementText = p->maTxt;
392 bFixedWidthFont = p->mbFixedWidthFont;
394 else
395 bFixedWidthFont = false;
397 maElementML.SetFont( bFixedWidthFont? maFixedWidthFont : maStdFont );
398 maElementML.SetControlFont( bFixedWidthFont? maFixedWidthFont : maStdFont );
399 maElementML.SetText( aElementText );
401 return 0;
404 struct CertPath_UserData
406 cssu::Reference< dcss::security::XCertificate > mxCert;
407 String maStatus;
408 bool mbValid;
410 CertPath_UserData( cssu::Reference< dcss::security::XCertificate > xCert, bool bValid):
411 mxCert(xCert),
412 mbValid(bValid)
418 CertificateViewerCertPathTP::CertificateViewerCertPathTP( Window* _pParent, CertificateViewer* _pDlg )
419 :CertificateViewerTP ( _pParent, XMLSEC_RES( RID_XMLSECTP_CERTPATH ), _pDlg )
420 ,maCertPathFT ( this, XMLSEC_RES( FT_CERTPATH ) )
421 ,maCertPathLB ( this, XMLSEC_RES( LB_SIGNATURES ) )
422 ,maViewCertPB ( this, XMLSEC_RES( BTN_VIEWCERT ) )
423 ,maCertStatusFT ( this, XMLSEC_RES( FT_CERTSTATUS ) )
424 ,maCertStatusML ( this, XMLSEC_RES( ML_CERTSTATUS ) )
425 ,mpParent ( _pDlg )
426 ,mbFirstActivateDone ( false )
427 ,maCertImage ( XMLSEC_RES( IMG_CERT_SMALL ) )
428 ,maCertNotValidatedImage( XMLSEC_RES( IMG_CERT_NOTVALIDATED_SMALL ) )
429 ,msCertOK ( XMLSEC_RES( STR_PATH_CERT_OK ) )
430 ,msCertNotValidated ( XMLSEC_RES( STR_PATH_CERT_NOT_VALIDATED ) )
433 if ( GetSettings().GetStyleSettings().GetWindowColor().IsDark() )
435 maCertImage = Image( XMLSEC_RES( IMG_CERT_SMALL_HC ) );
436 maCertNotValidatedImage = Image( XMLSEC_RES( IMG_CERT_NOTVALIDATED_SMALL_HC ) );
439 FreeResource();
441 maCertPathLB.SetNodeDefaultImages();
442 maCertPathLB.SetSublistOpenWithLeftRight();
443 maCertPathLB.SetSelectHdl( LINK( this, CertificateViewerCertPathTP, CertSelectHdl ) );
444 maViewCertPB.SetClickHdl( LINK( this, CertificateViewerCertPathTP, ViewCertHdl ) );
446 // check if buttontext is to wide
447 const long nOffset = 10;
448 String sText = maViewCertPB.GetText();
449 long nTxtW = maViewCertPB.GetTextWidth( sText );
450 if ( sText.Search( '~' ) == STRING_NOTFOUND )
451 nTxtW += nOffset;
452 long nBtnW = maViewCertPB.GetSizePixel().Width();
453 if ( nTxtW > nBtnW )
455 // broaden the button
456 long nDelta = nTxtW - nBtnW;
457 Size aNewSize = maViewCertPB.GetSizePixel();
458 aNewSize.Width() += nDelta;
459 maViewCertPB.SetSizePixel( aNewSize );
460 // and give it a new position
461 Point aNewPos = maViewCertPB.GetPosPixel();
462 aNewPos.X() -= nDelta;
463 maViewCertPB.SetPosPixel( aNewPos );
467 CertificateViewerCertPathTP::~CertificateViewerCertPathTP()
469 Clear();
472 void CertificateViewerCertPathTP::ActivatePage()
474 if ( !mbFirstActivateDone )
476 mbFirstActivateDone = true;
477 Sequence< Reference< security::XCertificate > > aCertPath =
478 mpParent->mxSecurityEnvironment->buildCertificatePath( mpParent->mxCert );
479 const Reference< security::XCertificate >* pCertPath = aCertPath.getConstArray();
481 String aState;
482 sal_Int32 i, nCnt = aCertPath.getLength();
483 SvLBoxEntry* pParent = NULL;
484 for( i = nCnt; i; )
486 const Reference< security::XCertificate > rCert = pCertPath[ --i ];
487 String sName = XmlSec::GetContentPart( rCert->getSubjectName() );
488 //Verify the certificate
489 sal_Int32 certStatus = mpDlg->mxSecurityEnvironment->verifyCertificate(rCert,
490 Sequence<Reference<css::security::XCertificate> >());
491 //We currently have two status
492 //These errors are alloweds
493 sal_Int32 validCertErrors = css::security::CertificateValidity::VALID
494 | css::security::CertificateValidity::UNKNOWN_REVOKATION;
496 //Build a mask to filter out the allowed errors
497 sal_Int32 mask = ~validCertErrors;
498 // "subtract" the allowed error flags from the result
499 sal_Int32 certErrors = certStatus & mask;
500 bool bCertValid = certErrors > 0 ? false : true;
501 pParent = InsertCert( pParent, sName, rCert, bCertValid);
504 maCertPathLB.Select( pParent );
505 maViewCertPB.Disable(); // Own certificate selected
507 while( pParent )
509 maCertPathLB.Expand( pParent );
510 pParent = maCertPathLB.GetParent( pParent );
513 CertSelectHdl( NULL );
517 IMPL_LINK( CertificateViewerCertPathTP, ViewCertHdl, void*, EMPTYARG )
519 SvLBoxEntry* pEntry = maCertPathLB.FirstSelected();
520 if( pEntry )
522 CertificateViewer aViewer( this, mpDlg->mxSecurityEnvironment, ((CertPath_UserData*)pEntry->GetUserData())->mxCert, FALSE );
523 aViewer.Execute();
526 return 0;
529 IMPL_LINK( CertificateViewerCertPathTP, CertSelectHdl, void*, EMPTYARG )
531 String sStatus;
532 SvLBoxEntry* pEntry = maCertPathLB.FirstSelected();
533 if( pEntry )
535 CertPath_UserData* pData = (CertPath_UserData*) pEntry->GetUserData();
536 if ( pData )
537 sStatus = pData->mbValid ? msCertOK : msCertNotValidated;
540 maCertStatusML.SetText( sStatus );
541 maViewCertPB.Enable( pEntry && ( pEntry != maCertPathLB.Last() ) );
542 return 0;
545 void CertificateViewerCertPathTP::Clear( void )
547 maCertStatusML.SetText( String() );
548 ULONG i = 0;
549 SvLBoxEntry* pEntry = maCertPathLB.GetEntry( i );
550 while( pEntry )
552 delete ( CertPath_UserData* ) pEntry->GetUserData();
553 ++i;
554 pEntry = maCertPathLB.GetEntry( i );
557 maCertPathLB.Clear();
560 SvLBoxEntry* CertificateViewerCertPathTP::InsertCert(
561 SvLBoxEntry* _pParent, const String& _rName, cssu::Reference< dcss::security::XCertificate > rxCert,
562 bool bValid)
564 Image aImage = bValid ? maCertImage : maCertNotValidatedImage;
565 SvLBoxEntry* pEntry = maCertPathLB.InsertEntry( _rName, aImage, aImage, _pParent );
566 pEntry->SetUserData( ( void* ) new CertPath_UserData( rxCert, bValid ) );
568 return pEntry;