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