update dev300-m58
[ooovba.git] / xmlsecurity / source / dialogs / certificateviewer.cxx
blobffdb86c6b24b4959442d709500234f03f8364954
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 aLBEntry = XmlSec::GetPureContent( xCert->getIssuerName(), ", " );
315 aDetails = XmlSec::GetPureContent( xCert->getIssuerName(), "\n", true );
316 InsertElement( String( XMLSEC_RES( STR_ISSUER ) ), aLBEntry, aDetails );
318 aSeq = xCert->getIssuerUniqueID();
319 aLBEntry = XmlSec::GetHexString( aSeq, pHexSep );
320 aDetails = XmlSec::GetHexString( aSeq, pHexSep, nLineBreak );
321 InsertElement( String( XMLSEC_RES( STR_ISSUER_ID ) ), aLBEntry, aDetails, true );
324 DateTime aDateTime;
325 utl::typeConvert( xCert->getNotValidBefore(), aDateTime );
326 aLBEntry = GetSettings().GetUILocaleDataWrapper().getDate( aDateTime.GetDate() );
327 aLBEntry += String::CreateFromAscii( " " );
328 aLBEntry += GetSettings().GetUILocaleDataWrapper().getTime( aDateTime.GetTime() );
329 InsertElement( String( XMLSEC_RES( STR_VALIDFROM ) ), aLBEntry, aLBEntry );
330 utl::typeConvert( xCert->getNotValidAfter(), aDateTime );
331 aLBEntry = GetSettings().GetUILocaleDataWrapper().getDate( aDateTime.GetDate() );
332 aLBEntry += String::CreateFromAscii( " " );
333 aLBEntry += GetSettings().GetUILocaleDataWrapper().getTime( aDateTime.GetTime() );
334 InsertElement( String( XMLSEC_RES( STR_VALIDTO ) ), aLBEntry, aLBEntry );
336 aLBEntry = XmlSec::GetPureContent( xCert->getSubjectName(), ", " );
337 aDetails = XmlSec::GetPureContent( xCert->getSubjectName(), "\n", true );
338 InsertElement( String( XMLSEC_RES( STR_SUBJECT ) ), aLBEntry, aDetails );
340 aSeq = xCert->getSubjectUniqueID();
341 aLBEntry = XmlSec::GetHexString( aSeq, pHexSep );
342 aDetails = XmlSec::GetHexString( aSeq, pHexSep, nLineBreak );
343 InsertElement( String( XMLSEC_RES( STR_SUBJECT_ID ) ), aLBEntry, aDetails, true );
345 aLBEntry = aDetails = xCert->getSubjectPublicKeyAlgorithm();
346 InsertElement( String( XMLSEC_RES( STR_SUBJECT_PUBKEY_ALGO ) ), aLBEntry, aDetails );
347 aSeq = xCert->getSubjectPublicKeyValue();
348 aLBEntry = XmlSec::GetHexString( aSeq, pHexSep );
349 aDetails = XmlSec::GetHexString( aSeq, pHexSep, nLineBreak );
350 InsertElement( String( XMLSEC_RES( STR_SUBJECT_PUBKEY_VAL ) ), aLBEntry, aDetails, true );
352 aLBEntry = aDetails = xCert->getSignatureAlgorithm();
353 InsertElement( String( XMLSEC_RES( STR_SIGNATURE_ALGO ) ), aLBEntry, aDetails );
355 aSeq = xCert->getSHA1Thumbprint();
356 aLBEntry = XmlSec::GetHexString( aSeq, pHexSep );
357 aDetails = XmlSec::GetHexString( aSeq, pHexSep, nLineBreak );
358 InsertElement( String( XMLSEC_RES( STR_THUMBPRINT_SHA1 ) ), aLBEntry, aDetails, true );
360 aSeq = xCert->getMD5Thumbprint();
361 aLBEntry = XmlSec::GetHexString( aSeq, pHexSep );
362 aDetails = XmlSec::GetHexString( aSeq, pHexSep, nLineBreak );
363 InsertElement( String( XMLSEC_RES( STR_THUMBPRINT_MD5 ) ), aLBEntry, aDetails, true );
365 FreeResource();
367 maElementsLB.SetSelectHdl( LINK( this, CertificateViewerDetailsTP, ElementSelectHdl ) );
370 CertificateViewerDetailsTP::~CertificateViewerDetailsTP()
372 Clear();
375 void CertificateViewerDetailsTP::ActivatePage()
379 IMPL_LINK( CertificateViewerDetailsTP, ElementSelectHdl, void*, EMPTYARG )
381 SvLBoxEntry* pEntry = maElementsLB.FirstSelected();
382 String aElementText;
383 bool bFixedWidthFont;
384 if( pEntry )
386 const Details_UserDatat* p = ( Details_UserDatat* ) pEntry->GetUserData();
387 aElementText = p->maTxt;
388 bFixedWidthFont = p->mbFixedWidthFont;
390 else
391 bFixedWidthFont = false;
393 maElementML.SetFont( bFixedWidthFont? maFixedWidthFont : maStdFont );
394 maElementML.SetControlFont( bFixedWidthFont? maFixedWidthFont : maStdFont );
395 maElementML.SetText( aElementText );
397 return 0;
400 struct CertPath_UserData
402 cssu::Reference< dcss::security::XCertificate > mxCert;
403 String maStatus;
404 bool mbValid;
406 CertPath_UserData( cssu::Reference< dcss::security::XCertificate > xCert, bool bValid):
407 mxCert(xCert),
408 mbValid(bValid)
414 CertificateViewerCertPathTP::CertificateViewerCertPathTP( Window* _pParent, CertificateViewer* _pDlg )
415 :CertificateViewerTP ( _pParent, XMLSEC_RES( RID_XMLSECTP_CERTPATH ), _pDlg )
416 ,maCertPathFT ( this, XMLSEC_RES( FT_CERTPATH ) )
417 ,maCertPathLB ( this, XMLSEC_RES( LB_SIGNATURES ) )
418 ,maViewCertPB ( this, XMLSEC_RES( BTN_VIEWCERT ) )
419 ,maCertStatusFT ( this, XMLSEC_RES( FT_CERTSTATUS ) )
420 ,maCertStatusML ( this, XMLSEC_RES( ML_CERTSTATUS ) )
421 ,mpParent ( _pDlg )
422 ,mbFirstActivateDone ( false )
423 ,maCertImage ( XMLSEC_RES( IMG_CERT_SMALL ) )
424 ,maCertNotValidatedImage( XMLSEC_RES( IMG_CERT_NOTVALIDATED_SMALL ) )
425 ,msCertOK ( XMLSEC_RES( STR_PATH_CERT_OK ) )
426 ,msCertNotValidated ( XMLSEC_RES( STR_PATH_CERT_NOT_VALIDATED ) )
429 if ( GetSettings().GetStyleSettings().GetWindowColor().IsDark() )
431 maCertImage = Image( XMLSEC_RES( IMG_CERT_SMALL_HC ) );
432 maCertNotValidatedImage = Image( XMLSEC_RES( IMG_CERT_NOTVALIDATED_SMALL_HC ) );
435 FreeResource();
437 maCertPathLB.SetNodeDefaultImages();
438 maCertPathLB.SetSublistOpenWithLeftRight();
439 maCertPathLB.SetSelectHdl( LINK( this, CertificateViewerCertPathTP, CertSelectHdl ) );
440 maViewCertPB.SetClickHdl( LINK( this, CertificateViewerCertPathTP, ViewCertHdl ) );
442 // check if buttontext is to wide
443 const long nOffset = 10;
444 String sText = maViewCertPB.GetText();
445 long nTxtW = maViewCertPB.GetTextWidth( sText );
446 if ( sText.Search( '~' ) == STRING_NOTFOUND )
447 nTxtW += nOffset;
448 long nBtnW = maViewCertPB.GetSizePixel().Width();
449 if ( nTxtW > nBtnW )
451 // broaden the button
452 long nDelta = nTxtW - nBtnW;
453 Size aNewSize = maViewCertPB.GetSizePixel();
454 aNewSize.Width() += nDelta;
455 maViewCertPB.SetSizePixel( aNewSize );
456 // and give it a new position
457 Point aNewPos = maViewCertPB.GetPosPixel();
458 aNewPos.X() -= nDelta;
459 maViewCertPB.SetPosPixel( aNewPos );
463 CertificateViewerCertPathTP::~CertificateViewerCertPathTP()
465 Clear();
468 void CertificateViewerCertPathTP::ActivatePage()
470 if ( !mbFirstActivateDone )
472 mbFirstActivateDone = true;
473 Sequence< Reference< security::XCertificate > > aCertPath =
474 mpParent->mxSecurityEnvironment->buildCertificatePath( mpParent->mxCert );
475 const Reference< security::XCertificate >* pCertPath = aCertPath.getConstArray();
477 String aState;
478 sal_Int32 i, nCnt = aCertPath.getLength();
479 SvLBoxEntry* pParent = NULL;
480 for( i = nCnt; i; )
482 const Reference< security::XCertificate > rCert = pCertPath[ --i ];
483 String sName = XmlSec::GetContentPart( rCert->getSubjectName() );
484 //Verify the certificate
485 sal_Int32 certStatus = mpDlg->mxSecurityEnvironment->verifyCertificate(rCert,
486 Sequence<Reference<css::security::XCertificate> >());
487 //We currently have two status
488 //These errors are alloweds
489 sal_Int32 validCertErrors = css::security::CertificateValidity::VALID
490 | css::security::CertificateValidity::UNKNOWN_REVOKATION;
492 //Build a mask to filter out the allowed errors
493 sal_Int32 mask = ~validCertErrors;
494 // "subtract" the allowed error flags from the result
495 sal_Int32 certErrors = certStatus & mask;
496 bool bCertValid = certErrors > 0 ? false : true;
497 pParent = InsertCert( pParent, sName, rCert, bCertValid);
500 maCertPathLB.Select( pParent );
501 maViewCertPB.Disable(); // Own certificate selected
503 while( pParent )
505 maCertPathLB.Expand( pParent );
506 pParent = maCertPathLB.GetParent( pParent );
509 CertSelectHdl( NULL );
513 IMPL_LINK( CertificateViewerCertPathTP, ViewCertHdl, void*, EMPTYARG )
515 SvLBoxEntry* pEntry = maCertPathLB.FirstSelected();
516 if( pEntry )
518 CertificateViewer aViewer( this, mpDlg->mxSecurityEnvironment, ((CertPath_UserData*)pEntry->GetUserData())->mxCert, FALSE );
519 aViewer.Execute();
522 return 0;
525 IMPL_LINK( CertificateViewerCertPathTP, CertSelectHdl, void*, EMPTYARG )
527 String sStatus;
528 SvLBoxEntry* pEntry = maCertPathLB.FirstSelected();
529 if( pEntry )
531 CertPath_UserData* pData = (CertPath_UserData*) pEntry->GetUserData();
532 if ( pData )
533 sStatus = pData->mbValid ? msCertOK : msCertNotValidated;
536 maCertStatusML.SetText( sStatus );
537 maViewCertPB.Enable( pEntry && ( pEntry != maCertPathLB.Last() ) );
538 return 0;
541 void CertificateViewerCertPathTP::Clear( void )
543 maCertStatusML.SetText( String() );
544 ULONG i = 0;
545 SvLBoxEntry* pEntry = maCertPathLB.GetEntry( i );
546 while( pEntry )
548 delete ( CertPath_UserData* ) pEntry->GetUserData();
549 ++i;
550 pEntry = maCertPathLB.GetEntry( i );
553 maCertPathLB.Clear();
556 SvLBoxEntry* CertificateViewerCertPathTP::InsertCert(
557 SvLBoxEntry* _pParent, const String& _rName, cssu::Reference< dcss::security::XCertificate > rxCert,
558 bool bValid)
560 Image aImage = bValid ? maCertImage : maCertNotValidatedImage;
561 SvLBoxEntry* pEntry = maCertPathLB.InsertEntry( _rName, aImage, aImage, _pParent );
562 pEntry->SetUserData( ( void* ) new CertPath_UserData( rxCert, bValid ) );
564 return pEntry;