gpg4libre: Recycle certificate selection dialog for encryption
Change-Id: I699ecff1f62b3dae7ac275823c6721810589c4cf Reviewed-on: https://gerrit.libreoffice.org/41507 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
This commit is contained in:
committed by
Thorsten Behrens
parent
7a9fb40cb0
commit
4f6bf3d64c
@@ -436,7 +436,7 @@ uno::Sequence< beans::NamedValue > OStorageHelper::CreateGpgPackageEncryptionDat
|
||||
// The use may provide a description while choosing a certificate.
|
||||
OUString aDescription;
|
||||
uno::Reference< security::XCertificate > xSignCertificate=
|
||||
xSigner->chooseCertificate(aDescription);
|
||||
xSigner->chooseEncryptionCertificate(aDescription);
|
||||
|
||||
uno::Sequence < sal_Int8 > aKeyID;
|
||||
if (xSignCertificate.is())
|
||||
|
@@ -130,11 +130,26 @@ interface XDocumentDigitalSignatures : com::sun::star::uno::XInterface
|
||||
void addLocationToTrustedSources( [in] string Location );
|
||||
|
||||
/** This method shows the CertificateChooser dialog, used by document and PDF signing
|
||||
Shows only private certificates
|
||||
|
||||
@since LibreOffice 5.3
|
||||
*/
|
||||
com::sun::star::security::XCertificate chooseCertificate( [out] string Description );
|
||||
|
||||
/** This is an alias for 'chooseCertificate', shows the CertificateChooser dialog
|
||||
with private certificates
|
||||
|
||||
@since LibreOffice 6.0
|
||||
*/
|
||||
com::sun::star::security::XCertificate chooseSigningCertificate( [out] string Description );
|
||||
|
||||
/** This method shows the CertificateChooser dialog with all certificates, private and
|
||||
other people's. Useful when choosing certificate/key for encryption
|
||||
|
||||
@since LibreOffice 6.0
|
||||
*/
|
||||
com::sun::star::security::XCertificate chooseEncryptionCertificate( [out] string Description );
|
||||
|
||||
} ;
|
||||
|
||||
} ; } ; } ; } ;
|
||||
|
@@ -49,6 +49,12 @@ struct UserData
|
||||
css::uno::Reference<css::xml::crypto::XSecurityEnvironment> xSecurityEnvironment;
|
||||
};
|
||||
|
||||
enum class UserAction
|
||||
{
|
||||
Sign,
|
||||
Encrypt
|
||||
};
|
||||
|
||||
class CertificateChooser : public ModalDialog
|
||||
{
|
||||
private:
|
||||
@@ -56,12 +62,16 @@ private:
|
||||
std::vector< css::uno::Reference< css::xml::crypto::XXMLSecurityContext > > mxSecurityContexts;
|
||||
std::vector<std::shared_ptr<UserData>> mvUserData;
|
||||
|
||||
VclPtr<FixedText> m_pFTSign;
|
||||
VclPtr<FixedText> m_pFTEncrypt;
|
||||
|
||||
VclPtr<SvSimpleTable> m_pCertLB;
|
||||
VclPtr<PushButton> m_pViewBtn;
|
||||
VclPtr<OKButton> m_pOKBtn;
|
||||
VclPtr<Edit> m_pDescriptionED;
|
||||
|
||||
bool mbInitialized;
|
||||
UserAction meAction;
|
||||
|
||||
DECL_LINK(ViewButtonHdl, Button*, void);
|
||||
DECL_LINK(CertificateHighlightHdl, SvTreeListBox*, void );
|
||||
@@ -75,7 +85,8 @@ private:
|
||||
public:
|
||||
CertificateChooser(vcl::Window* pParent,
|
||||
css::uno::Reference< css::uno::XComponentContext> const & rxCtx,
|
||||
std::vector< css::uno::Reference< css::xml::crypto::XXMLSecurityContext > > const & rxSecurityContexts);
|
||||
std::vector< css::uno::Reference< css::xml::crypto::XXMLSecurityContext > > const & rxSecurityContexts,
|
||||
UserAction eAction);
|
||||
virtual ~CertificateChooser() override;
|
||||
virtual void dispose() override;
|
||||
|
||||
|
@@ -445,7 +445,7 @@ sal_Bool DocumentDigitalSignatures::isAuthorTrusted(
|
||||
return bFound;
|
||||
}
|
||||
|
||||
Reference< css::security::XCertificate > DocumentDigitalSignatures::chooseCertificate(OUString& rDescription)
|
||||
Reference< css::security::XCertificate > DocumentDigitalSignatures::chooseCertificateImpl(OUString& rDescription, UserAction eAction)
|
||||
{
|
||||
std::vector< Reference< css::xml::crypto::XXMLSecurityContext > > xSecContexts;
|
||||
|
||||
@@ -455,7 +455,7 @@ Reference< css::security::XCertificate > DocumentDigitalSignatures::chooseCertif
|
||||
xSecContexts.push_back(aSignatureManager.getGpgSecurityContext());
|
||||
}
|
||||
|
||||
ScopedVclPtrInstance< CertificateChooser > aChooser(nullptr, mxCtx, xSecContexts);
|
||||
ScopedVclPtrInstance< CertificateChooser > aChooser(nullptr, mxCtx, xSecContexts, eAction);
|
||||
|
||||
if (aChooser->Execute() != RET_OK)
|
||||
return Reference< css::security::XCertificate >(nullptr);
|
||||
@@ -469,6 +469,20 @@ Reference< css::security::XCertificate > DocumentDigitalSignatures::chooseCertif
|
||||
return xCert;
|
||||
}
|
||||
|
||||
Reference< css::security::XCertificate > DocumentDigitalSignatures::chooseCertificate(OUString& rDescription)
|
||||
{
|
||||
return chooseCertificateImpl( rDescription, UserAction::Sign );
|
||||
}
|
||||
|
||||
Reference< css::security::XCertificate > DocumentDigitalSignatures::chooseSigningCertificate(OUString& rDescription)
|
||||
{
|
||||
return chooseCertificateImpl( rDescription, UserAction::Sign );
|
||||
}
|
||||
|
||||
Reference< css::security::XCertificate > DocumentDigitalSignatures::chooseEncryptionCertificate(OUString& rDescription)
|
||||
{
|
||||
return chooseCertificateImpl( rDescription, UserAction::Encrypt );
|
||||
}
|
||||
|
||||
sal_Bool DocumentDigitalSignatures::isLocationTrusted( const OUString& Location )
|
||||
{
|
||||
|
@@ -27,6 +27,7 @@
|
||||
#include <com/sun/star/security/XDocumentDigitalSignatures.hpp>
|
||||
#include <com/sun/star/io/XStream.hpp>
|
||||
#include <com/sun/star/io/XInputStream.hpp>
|
||||
#include <certificatechooser.hxx>
|
||||
#include <documentsignaturehelper.hxx>
|
||||
|
||||
namespace com { namespace sun { namespace star {
|
||||
@@ -61,6 +62,8 @@ private:
|
||||
/// @throws css::uno::RuntimeException
|
||||
css::uno::Sequence< css::security::DocumentSignatureInformation > ImplVerifySignatures( const css::uno::Reference< css::embed::XStorage >& rxStorage, const ::com::sun::star::uno::Reference< css::io::XInputStream >& xSignStream, DocumentSignatureMode eMode );
|
||||
|
||||
css::uno::Reference< css::security::XCertificate > chooseCertificateImpl(OUString& rDescription, UserAction eAction);
|
||||
|
||||
public:
|
||||
explicit DocumentDigitalSignatures( const css::uno::Reference< css::uno::XComponentContext>& rxCtx );
|
||||
virtual ~DocumentDigitalSignatures() override;
|
||||
@@ -101,6 +104,8 @@ public:
|
||||
void SAL_CALL addLocationToTrustedSources( const OUString& Location ) override;
|
||||
|
||||
css::uno::Reference< css::security::XCertificate > SAL_CALL chooseCertificate(OUString& rDescription) override;
|
||||
css::uno::Reference< css::security::XCertificate > SAL_CALL chooseSigningCertificate(OUString& rDescription) override;
|
||||
css::uno::Reference< css::security::XCertificate > SAL_CALL chooseEncryptionCertificate(OUString& rDescription) override;
|
||||
};
|
||||
|
||||
/// @throws css::uno::Exception
|
||||
|
@@ -36,10 +36,14 @@ using namespace css;
|
||||
|
||||
CertificateChooser::CertificateChooser(vcl::Window* _pParent,
|
||||
uno::Reference<uno::XComponentContext> const & _rxCtx,
|
||||
std::vector< css::uno::Reference< css::xml::crypto::XXMLSecurityContext > > const & rxSecurityContexts)
|
||||
std::vector< css::uno::Reference< css::xml::crypto::XXMLSecurityContext > > const & rxSecurityContexts,
|
||||
UserAction eAction)
|
||||
: ModalDialog(_pParent, "SelectCertificateDialog", "xmlsec/ui/selectcertificatedialog.ui"),
|
||||
mvUserData()
|
||||
mvUserData(),
|
||||
meAction( eAction )
|
||||
{
|
||||
get(m_pFTSign, "sign");
|
||||
get(m_pFTEncrypt, "encrypt");
|
||||
get(m_pOKBtn, "ok");
|
||||
get(m_pViewBtn, "viewcert");
|
||||
get(m_pDescriptionED, "description");
|
||||
@@ -76,6 +80,8 @@ CertificateChooser::~CertificateChooser()
|
||||
|
||||
void CertificateChooser::dispose()
|
||||
{
|
||||
m_pFTSign.clear();
|
||||
m_pFTEncrypt.clear();
|
||||
m_pCertLB.disposeAndClear();
|
||||
m_pViewBtn.clear();
|
||||
m_pOKBtn.clear();
|
||||
@@ -151,6 +157,20 @@ void CertificateChooser::ImplInitialize()
|
||||
if ( mbInitialized )
|
||||
return;
|
||||
|
||||
switch (meAction)
|
||||
{
|
||||
case UserAction::Sign:
|
||||
m_pFTSign->Show();
|
||||
m_pOKBtn->SetText( get<FixedText>("str_sign")->GetText() );
|
||||
break;
|
||||
|
||||
case UserAction::Encrypt:
|
||||
m_pFTEncrypt->Show();
|
||||
m_pOKBtn->SetText( get<FixedText>("str_encrypt")->GetText() );
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
for (auto &secContext : mxSecurityContexts)
|
||||
{
|
||||
if (!secContext.is())
|
||||
|
@@ -405,7 +405,7 @@ IMPL_LINK_NOARG(DigitalSignaturesDialog, AddButtonHdl, Button*, void)
|
||||
if (DocumentSignatureHelper::CanSignWithGPG(maSignatureManager.mxStore, m_sODFVersion))
|
||||
xSecContexts.push_back(maSignatureManager.getGpgSecurityContext());
|
||||
|
||||
ScopedVclPtrInstance< CertificateChooser > aChooser( this, mxCtx, xSecContexts );
|
||||
ScopedVclPtrInstance< CertificateChooser > aChooser( this, mxCtx, xSecContexts, UserAction::Sign );
|
||||
if ( aChooser->Execute() == RET_OK )
|
||||
{
|
||||
sal_Int32 nSecurityId;
|
||||
|
@@ -182,6 +182,17 @@
|
||||
<property name="hexpand">True</property>
|
||||
<property name="label" translatable="yes" context="selectcertificatedialog|STR_ENCIPHER_ONLY">Only for encipherment</property>
|
||||
</object>
|
||||
<!-- different prefix, STR_ is (mis)used in the code to map certificate usage flags to strings -->
|
||||
<object class="GtkLabel" id="str_sign">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="label" translatable="yes" context="selectcertificatedialog|str_sign">Sign</property>
|
||||
</object>
|
||||
<object class="GtkLabel" id="str_encrypt">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="label" translatable="yes" context="selectcertificatedialog|str_encrypt">Encrypt</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
@@ -190,18 +201,31 @@
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label1">
|
||||
<property name="visible">True</property>
|
||||
<object class="GtkLabel" id="sign">
|
||||
<property name="visible">False</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="ypad">1</property>
|
||||
<property name="label" translatable="yes" context="selectcertificatedialog|label1">Select the certificate you want to use for signing:</property>
|
||||
<property name="label" translatable="yes" context="selectcertificatedialog|sign">Select the certificate you want to use for signing:</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="encrypt">
|
||||
<property name="visible">False</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="ypad">1</property>
|
||||
<property name="label" translatable="yes" context="selectcertificatedialog|encrypt">Select the certificate you want to use for encryption:</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="svtlo-SvSimpleTableContainer" id="signatures">
|
||||
<property name="visible">True</property>
|
||||
|
Reference in New Issue
Block a user