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