2010-10-12 15:57:08 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-07-16 17:32:30 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2004-07-12 12:15:31 +00:00
|
|
|
|
2006-09-16 13:35:04 +00:00
|
|
|
|
2004-07-12 12:15:31 +00:00
|
|
|
#include <xmlsecurity/certificatechooser.hxx>
|
|
|
|
#include <xmlsecurity/certificateviewer.hxx>
|
2004-07-26 06:30:29 +00:00
|
|
|
#include <xmlsecurity/biginteger.hxx>
|
2004-07-12 12:15:31 +00:00
|
|
|
#include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp>
|
|
|
|
#include <comphelper/sequence.hxx>
|
2008-08-18 12:13:05 +00:00
|
|
|
#include <comphelper/processfactory.hxx>
|
2004-07-12 12:15:31 +00:00
|
|
|
|
|
|
|
#include <com/sun/star/security/NoPasswordException.hpp>
|
2004-07-22 14:37:38 +00:00
|
|
|
#include <com/sun/star/security/CertificateCharacters.hpp>
|
2008-08-18 12:13:05 +00:00
|
|
|
#include <com/sun/star/security/SerialNumberAdapter.hpp>
|
2004-07-12 12:15:31 +00:00
|
|
|
|
2014-05-19 11:57:34 +02:00
|
|
|
#include "resourcemanager.hxx"
|
2005-03-10 17:04:16 +00:00
|
|
|
#include <vcl/msgbox.hxx>
|
2014-05-19 11:57:34 +02:00
|
|
|
#include <svtools/treelistentry.hxx>
|
2005-03-10 17:04:16 +00:00
|
|
|
|
2004-07-12 12:15:31 +00:00
|
|
|
using namespace ::com::sun::star;
|
|
|
|
|
|
|
|
#define INVAL_SEL 0xFFFF
|
|
|
|
|
2011-01-14 14:16:44 +01:00
|
|
|
sal_uInt16 CertificateChooser::GetSelectedEntryPos( void ) const
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2011-01-14 14:16:44 +01:00
|
|
|
sal_uInt16 nSel = INVAL_SEL;
|
2004-07-12 12:15:31 +00:00
|
|
|
|
2012-12-29 18:11:33 +00:00
|
|
|
SvTreeListEntry* pSel = m_pCertLB->FirstSelected();
|
2004-07-12 12:15:31 +00:00
|
|
|
if( pSel )
|
2014-10-02 15:36:13 +02:00
|
|
|
nSel = (sal_uInt16) reinterpret_cast<sal_uIntPtr>( pSel->GetUserData() );
|
2004-07-12 12:15:31 +00:00
|
|
|
|
2011-01-14 14:16:44 +01:00
|
|
|
return (sal_uInt16) nSel;
|
2004-07-12 12:15:31 +00:00
|
|
|
}
|
|
|
|
|
2014-09-23 11:20:40 +02:00
|
|
|
CertificateChooser::CertificateChooser( vcl::Window* _pParent, uno::Reference< uno::XComponentContext>& _rxCtx, uno::Reference< css::xml::crypto::XSecurityEnvironment >& _rxSecurityEnvironment, const SignatureInformations& _rCertsToIgnore )
|
2012-12-29 18:11:33 +00:00
|
|
|
: ModalDialog(_pParent, "SelectCertificateDialog", "xmlsec/ui/selectcertificatedialog.ui")
|
|
|
|
, maCertsToIgnore( _rCertsToIgnore )
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2012-12-29 18:11:33 +00:00
|
|
|
get(m_pOKBtn, "ok");
|
|
|
|
get(m_pViewBtn, "viewcert");
|
|
|
|
|
|
|
|
Size aControlSize(275, 122);
|
|
|
|
const long nControlWidth = aControlSize.Width();
|
|
|
|
aControlSize = LogicToPixel(aControlSize, MAP_APPFONT);
|
2013-07-16 09:12:42 +01:00
|
|
|
SvSimpleTableContainer *pSignatures = get<SvSimpleTableContainer>("signatures");
|
2012-12-29 18:11:33 +00:00
|
|
|
pSignatures->set_width_request(aControlSize.Width());
|
|
|
|
pSignatures->set_height_request(aControlSize.Height());
|
|
|
|
|
2013-07-16 09:12:42 +01:00
|
|
|
m_pCertLB = new SvSimpleTable(*pSignatures);
|
2012-12-29 18:11:33 +00:00
|
|
|
static long nTabs[] = { 3, 0, 30*nControlWidth/100, 60*nControlWidth/100 };
|
|
|
|
m_pCertLB->SetTabs( &nTabs[0] );
|
2013-08-17 01:11:11 +02:00
|
|
|
m_pCertLB->InsertHeaderEntry(get<FixedText>("issuedto")->GetText() + "\t" + get<FixedText>("issuedby")->GetText()
|
|
|
|
+ "\t" + get<FixedText>("expiration")->GetText());
|
2012-12-29 18:11:33 +00:00
|
|
|
m_pCertLB->SetSelectHdl( LINK( this, CertificateChooser, CertificateHighlightHdl ) );
|
|
|
|
m_pCertLB->SetDoubleClickHdl( LINK( this, CertificateChooser, CertificateSelectHdl ) );
|
|
|
|
m_pViewBtn->SetClickHdl( LINK( this, CertificateChooser, ViewButtonHdl ) );
|
2004-07-12 12:15:31 +00:00
|
|
|
|
2008-08-18 12:13:05 +00:00
|
|
|
mxCtx = _rxCtx;
|
2004-07-12 12:15:31 +00:00
|
|
|
mxSecurityEnvironment = _rxSecurityEnvironment;
|
2012-09-25 17:28:22 +02:00
|
|
|
mbInitialized = false;
|
2004-07-12 12:15:31 +00:00
|
|
|
|
2005-05-18 08:57:17 +00:00
|
|
|
// disable buttons
|
|
|
|
CertificateHighlightHdl( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
CertificateChooser::~CertificateChooser()
|
2015-01-26 13:25:18 +02:00
|
|
|
{
|
|
|
|
dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CertificateChooser::dispose()
|
2005-05-18 08:57:17 +00:00
|
|
|
{
|
2012-12-29 18:11:33 +00:00
|
|
|
delete m_pCertLB;
|
2015-01-26 13:25:18 +02:00
|
|
|
ModalDialog::dispose();
|
2005-05-18 08:57:17 +00:00
|
|
|
}
|
2004-07-12 12:15:31 +00:00
|
|
|
|
2005-05-18 08:57:17 +00:00
|
|
|
short CertificateChooser::Execute()
|
|
|
|
{
|
|
|
|
// #i48432#
|
|
|
|
// We can't check for personal certificates before raising this dialog,
|
|
|
|
// because the mozilla implementation throws a NoPassword exception,
|
|
|
|
// if the user pressed cancel, and also if the database does not exist!
|
|
|
|
// But in the later case, the is no password query, and the user is confused
|
|
|
|
// that nothing happens when pressing "Add..." in the SignatureDialog.
|
|
|
|
|
|
|
|
// PostUserEvent( LINK( this, CertificateChooser, Initialize ) );
|
|
|
|
|
|
|
|
// PostUserLink behavior is to slow, so do it directly before Execute().
|
|
|
|
// Problem: This Dialog should be visible right now, and the parent should not be accessible.
|
|
|
|
// Show, Update, DIsableInput...
|
|
|
|
|
2014-09-23 11:20:40 +02:00
|
|
|
vcl::Window* pMe = this;
|
|
|
|
vcl::Window* pParent = GetParent();
|
2005-05-18 08:57:17 +00:00
|
|
|
if ( pParent )
|
2014-01-28 19:58:53 +01:00
|
|
|
pParent->EnableInput( false );
|
2005-05-18 08:57:17 +00:00
|
|
|
pMe->Show();
|
|
|
|
pMe->Update();
|
|
|
|
ImplInitialize();
|
|
|
|
if ( pParent )
|
2014-01-28 19:58:53 +01:00
|
|
|
pParent->EnableInput( true );
|
2005-05-18 08:57:17 +00:00
|
|
|
return ModalDialog::Execute();
|
|
|
|
}
|
|
|
|
|
2012-03-01 18:00:32 +01:00
|
|
|
// IMPL_LINK_NOARG(CertificateChooser, Initialize)
|
2005-05-18 08:57:17 +00:00
|
|
|
void CertificateChooser::ImplInitialize()
|
|
|
|
{
|
|
|
|
if ( !mbInitialized )
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2005-05-18 08:57:17 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
maCerts = mxSecurityEnvironment->getPersonalCertificates();
|
|
|
|
}
|
|
|
|
catch (security::NoPasswordException&)
|
|
|
|
{
|
|
|
|
}
|
2004-07-22 14:37:38 +00:00
|
|
|
|
2013-03-30 00:32:52 +01:00
|
|
|
uno::Reference< css::security::XSerialNumberAdapter> xSerialNumberAdapter =
|
2008-08-18 12:13:05 +00:00
|
|
|
::com::sun::star::security::SerialNumberAdapter::create(mxCtx);
|
|
|
|
|
2005-05-18 08:57:17 +00:00
|
|
|
sal_Int32 nCertificates = maCerts.getLength();
|
|
|
|
sal_Int32 nCertificatesToIgnore = maCertsToIgnore.size();
|
|
|
|
for( sal_Int32 nCert = nCertificates; nCert; )
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2005-05-18 08:57:17 +00:00
|
|
|
uno::Reference< security::XCertificate > xCert = maCerts[ --nCert ];
|
2014-04-23 13:44:07 +02:00
|
|
|
bool bIgnoreThis = false;
|
2005-05-18 08:57:17 +00:00
|
|
|
|
|
|
|
// Do we already use that?
|
|
|
|
if( nCertificatesToIgnore )
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString aIssuerName = xCert->getIssuerName();
|
2005-05-18 08:57:17 +00:00
|
|
|
for( sal_Int32 nSig = 0; nSig < nCertificatesToIgnore; ++nSig )
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2005-05-18 08:57:17 +00:00
|
|
|
const SignatureInformation& rInf = maCertsToIgnore[ nSig ];
|
|
|
|
if ( ( aIssuerName == rInf.ouX509IssuerName ) &&
|
2008-08-18 12:13:05 +00:00
|
|
|
( xSerialNumberAdapter->toString( xCert->getSerialNumber() ) == rInf.ouX509SerialNumber ) )
|
2005-05-18 08:57:17 +00:00
|
|
|
{
|
|
|
|
bIgnoreThis = true;
|
|
|
|
break;
|
|
|
|
}
|
2004-07-12 12:15:31 +00:00
|
|
|
}
|
|
|
|
}
|
2004-07-22 14:37:38 +00:00
|
|
|
|
2005-05-18 08:57:17 +00:00
|
|
|
if ( !bIgnoreThis )
|
|
|
|
{
|
|
|
|
// Check if we have a private key for this...
|
|
|
|
long nCertificateCharacters = mxSecurityEnvironment->getCertificateCharacters( xCert );
|
|
|
|
|
|
|
|
if ( !( nCertificateCharacters & security::CertificateCharacters::HAS_PRIVATE_KEY ) )
|
|
|
|
bIgnoreThis = true;
|
2004-07-22 14:37:38 +00:00
|
|
|
|
2005-05-18 08:57:17 +00:00
|
|
|
}
|
2004-07-22 14:37:38 +00:00
|
|
|
|
2005-05-18 08:57:17 +00:00
|
|
|
if ( bIgnoreThis )
|
|
|
|
{
|
|
|
|
::comphelper::removeElementAt( maCerts, nCert );
|
|
|
|
nCertificates = maCerts.getLength();
|
|
|
|
}
|
2004-07-22 14:37:38 +00:00
|
|
|
}
|
|
|
|
|
2005-05-18 08:57:17 +00:00
|
|
|
// fill list of certificates; the first entry will be selected
|
|
|
|
for ( sal_Int32 nC = 0; nC < nCertificates; ++nC )
|
2004-07-22 14:37:38 +00:00
|
|
|
{
|
2013-08-17 01:11:11 +02:00
|
|
|
SvTreeListEntry* pEntry = m_pCertLB->InsertEntry( XmlSec::GetContentPart( maCerts[ nC ]->getSubjectName() )
|
|
|
|
+ "\t" + XmlSec::GetContentPart( maCerts[ nC ]->getIssuerName() )
|
|
|
|
+ "\t" + XmlSec::GetDateString( maCerts[ nC ]->getNotValidAfter() ) );
|
2014-10-02 15:36:13 +02:00
|
|
|
pEntry->SetUserData( reinterpret_cast<void*>(nC) ); // missuse user data as index
|
2004-07-22 14:37:38 +00:00
|
|
|
}
|
2004-07-12 12:15:31 +00:00
|
|
|
|
2005-05-18 08:57:17 +00:00
|
|
|
// enable/disable buttons
|
|
|
|
CertificateHighlightHdl( NULL );
|
2012-09-25 17:28:22 +02:00
|
|
|
mbInitialized = true;
|
2004-07-12 12:15:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-30 00:32:52 +01:00
|
|
|
uno::Reference< css::security::XCertificate > CertificateChooser::GetSelectedCertificate()
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2013-03-30 00:32:52 +01:00
|
|
|
uno::Reference< css::security::XCertificate > xCert;
|
2011-01-14 14:16:44 +01:00
|
|
|
sal_uInt16 nSelected = GetSelectedEntryPos();
|
2005-03-10 17:04:16 +00:00
|
|
|
if ( nSelected < maCerts.getLength() )
|
2004-07-12 12:15:31 +00:00
|
|
|
xCert = maCerts[ nSelected ];
|
|
|
|
return xCert;
|
|
|
|
}
|
|
|
|
|
2012-03-01 18:00:32 +01:00
|
|
|
IMPL_LINK_NOARG(CertificateChooser, CertificateHighlightHdl)
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2014-04-23 13:44:07 +02:00
|
|
|
bool bEnable = GetSelectedCertificate().is();
|
2012-12-29 18:11:33 +00:00
|
|
|
m_pViewBtn->Enable( bEnable );
|
|
|
|
m_pOKBtn->Enable( bEnable );
|
2004-07-12 12:15:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-01 18:00:32 +01:00
|
|
|
IMPL_LINK_NOARG(CertificateChooser, CertificateSelectHdl)
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
2005-03-10 17:04:16 +00:00
|
|
|
EndDialog( RET_OK );
|
2004-07-12 12:15:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-01 18:00:32 +01:00
|
|
|
IMPL_LINK_NOARG(CertificateChooser, ViewButtonHdl)
|
2004-07-12 12:15:31 +00:00
|
|
|
{
|
|
|
|
ImplShowCertificateDetails();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CertificateChooser::ImplShowCertificateDetails()
|
|
|
|
{
|
2013-03-30 00:32:52 +01:00
|
|
|
uno::Reference< css::security::XCertificate > xCert = GetSelectedCertificate();
|
2004-07-12 12:15:31 +00:00
|
|
|
if( xCert.is() )
|
|
|
|
{
|
2015-02-11 14:42:23 +02:00
|
|
|
VclPtr<CertificateViewer> aViewer(new CertificateViewer( this, mxSecurityEnvironment, xCert, true ));
|
|
|
|
aViewer->Execute();
|
2004-07-12 12:15:31 +00:00
|
|
|
}
|
2005-03-10 17:04:16 +00:00
|
|
|
}
|
|
|
|
|
2010-10-12 15:57:08 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|