Kaydet (Commit) 4f6bf3d6 authored tarafından Katarina Behrens's avatar Katarina Behrens Kaydeden (comit) Thorsten Behrens

gpg4libre: Recycle certificate selection dialog for encryption

Change-Id: I699ecff1f62b3dae7ac275823c6721810589c4cf
Reviewed-on: https://gerrit.libreoffice.org/41507Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarThorsten Behrens <Thorsten.Behrens@CIB.de>
üst 7a9fb40c
...@@ -436,7 +436,7 @@ uno::Sequence< beans::NamedValue > OStorageHelper::CreateGpgPackageEncryptionDat ...@@ -436,7 +436,7 @@ uno::Sequence< beans::NamedValue > OStorageHelper::CreateGpgPackageEncryptionDat
// The use may provide a description while choosing a certificate. // The use may provide a description while choosing a certificate.
OUString aDescription; OUString aDescription;
uno::Reference< security::XCertificate > xSignCertificate= uno::Reference< security::XCertificate > xSignCertificate=
xSigner->chooseCertificate(aDescription); xSigner->chooseEncryptionCertificate(aDescription);
uno::Sequence < sal_Int8 > aKeyID; uno::Sequence < sal_Int8 > aKeyID;
if (xSignCertificate.is()) if (xSignCertificate.is())
......
...@@ -130,11 +130,26 @@ interface XDocumentDigitalSignatures : com::sun::star::uno::XInterface ...@@ -130,11 +130,26 @@ interface XDocumentDigitalSignatures : com::sun::star::uno::XInterface
void addLocationToTrustedSources( [in] string Location ); void addLocationToTrustedSources( [in] string Location );
/** This method shows the CertificateChooser dialog, used by document and PDF signing /** This method shows the CertificateChooser dialog, used by document and PDF signing
Shows only private certificates
@since LibreOffice 5.3 @since LibreOffice 5.3
*/ */
com::sun::star::security::XCertificate chooseCertificate( [out] string Description ); 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 ...@@ -49,6 +49,12 @@ struct UserData
css::uno::Reference<css::xml::crypto::XSecurityEnvironment> xSecurityEnvironment; css::uno::Reference<css::xml::crypto::XSecurityEnvironment> xSecurityEnvironment;
}; };
enum class UserAction
{
Sign,
Encrypt
};
class CertificateChooser : public ModalDialog class CertificateChooser : public ModalDialog
{ {
private: private:
...@@ -56,12 +62,16 @@ private: ...@@ -56,12 +62,16 @@ private:
std::vector< css::uno::Reference< css::xml::crypto::XXMLSecurityContext > > mxSecurityContexts; std::vector< css::uno::Reference< css::xml::crypto::XXMLSecurityContext > > mxSecurityContexts;
std::vector<std::shared_ptr<UserData>> mvUserData; std::vector<std::shared_ptr<UserData>> mvUserData;
VclPtr<FixedText> m_pFTSign;
VclPtr<FixedText> m_pFTEncrypt;
VclPtr<SvSimpleTable> m_pCertLB; VclPtr<SvSimpleTable> m_pCertLB;
VclPtr<PushButton> m_pViewBtn; VclPtr<PushButton> m_pViewBtn;
VclPtr<OKButton> m_pOKBtn; VclPtr<OKButton> m_pOKBtn;
VclPtr<Edit> m_pDescriptionED; VclPtr<Edit> m_pDescriptionED;
bool mbInitialized; bool mbInitialized;
UserAction meAction;
DECL_LINK(ViewButtonHdl, Button*, void); DECL_LINK(ViewButtonHdl, Button*, void);
DECL_LINK(CertificateHighlightHdl, SvTreeListBox*, void ); DECL_LINK(CertificateHighlightHdl, SvTreeListBox*, void );
...@@ -75,7 +85,8 @@ private: ...@@ -75,7 +85,8 @@ private:
public: public:
CertificateChooser(vcl::Window* pParent, CertificateChooser(vcl::Window* pParent,
css::uno::Reference< css::uno::XComponentContext> const & rxCtx, 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 ~CertificateChooser() override;
virtual void dispose() override; virtual void dispose() override;
......
...@@ -445,7 +445,7 @@ sal_Bool DocumentDigitalSignatures::isAuthorTrusted( ...@@ -445,7 +445,7 @@ sal_Bool DocumentDigitalSignatures::isAuthorTrusted(
return bFound; 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; std::vector< Reference< css::xml::crypto::XXMLSecurityContext > > xSecContexts;
...@@ -455,7 +455,7 @@ Reference< css::security::XCertificate > DocumentDigitalSignatures::chooseCertif ...@@ -455,7 +455,7 @@ Reference< css::security::XCertificate > DocumentDigitalSignatures::chooseCertif
xSecContexts.push_back(aSignatureManager.getGpgSecurityContext()); xSecContexts.push_back(aSignatureManager.getGpgSecurityContext());
} }
ScopedVclPtrInstance< CertificateChooser > aChooser(nullptr, mxCtx, xSecContexts); ScopedVclPtrInstance< CertificateChooser > aChooser(nullptr, mxCtx, xSecContexts, eAction);
if (aChooser->Execute() != RET_OK) if (aChooser->Execute() != RET_OK)
return Reference< css::security::XCertificate >(nullptr); return Reference< css::security::XCertificate >(nullptr);
...@@ -469,6 +469,20 @@ Reference< css::security::XCertificate > DocumentDigitalSignatures::chooseCertif ...@@ -469,6 +469,20 @@ Reference< css::security::XCertificate > DocumentDigitalSignatures::chooseCertif
return xCert; 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 ) sal_Bool DocumentDigitalSignatures::isLocationTrusted( const OUString& Location )
{ {
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <com/sun/star/security/XDocumentDigitalSignatures.hpp> #include <com/sun/star/security/XDocumentDigitalSignatures.hpp>
#include <com/sun/star/io/XStream.hpp> #include <com/sun/star/io/XStream.hpp>
#include <com/sun/star/io/XInputStream.hpp> #include <com/sun/star/io/XInputStream.hpp>
#include <certificatechooser.hxx>
#include <documentsignaturehelper.hxx> #include <documentsignaturehelper.hxx>
namespace com { namespace sun { namespace star { namespace com { namespace sun { namespace star {
...@@ -61,6 +62,8 @@ private: ...@@ -61,6 +62,8 @@ private:
/// @throws css::uno::RuntimeException /// @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::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: public:
explicit DocumentDigitalSignatures( const css::uno::Reference< css::uno::XComponentContext>& rxCtx ); explicit DocumentDigitalSignatures( const css::uno::Reference< css::uno::XComponentContext>& rxCtx );
virtual ~DocumentDigitalSignatures() override; virtual ~DocumentDigitalSignatures() override;
...@@ -101,6 +104,8 @@ public: ...@@ -101,6 +104,8 @@ public:
void SAL_CALL addLocationToTrustedSources( const OUString& Location ) override; 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 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 /// @throws css::uno::Exception
......
...@@ -36,10 +36,14 @@ using namespace css; ...@@ -36,10 +36,14 @@ using namespace css;
CertificateChooser::CertificateChooser(vcl::Window* _pParent, CertificateChooser::CertificateChooser(vcl::Window* _pParent,
uno::Reference<uno::XComponentContext> const & _rxCtx, 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"), : 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_pOKBtn, "ok");
get(m_pViewBtn, "viewcert"); get(m_pViewBtn, "viewcert");
get(m_pDescriptionED, "description"); get(m_pDescriptionED, "description");
...@@ -76,6 +80,8 @@ CertificateChooser::~CertificateChooser() ...@@ -76,6 +80,8 @@ CertificateChooser::~CertificateChooser()
void CertificateChooser::dispose() void CertificateChooser::dispose()
{ {
m_pFTSign.clear();
m_pFTEncrypt.clear();
m_pCertLB.disposeAndClear(); m_pCertLB.disposeAndClear();
m_pViewBtn.clear(); m_pViewBtn.clear();
m_pOKBtn.clear(); m_pOKBtn.clear();
...@@ -151,6 +157,20 @@ void CertificateChooser::ImplInitialize() ...@@ -151,6 +157,20 @@ void CertificateChooser::ImplInitialize()
if ( mbInitialized ) if ( mbInitialized )
return; 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) for (auto &secContext : mxSecurityContexts)
{ {
if (!secContext.is()) if (!secContext.is())
......
...@@ -405,7 +405,7 @@ IMPL_LINK_NOARG(DigitalSignaturesDialog, AddButtonHdl, Button*, void) ...@@ -405,7 +405,7 @@ IMPL_LINK_NOARG(DigitalSignaturesDialog, AddButtonHdl, Button*, void)
if (DocumentSignatureHelper::CanSignWithGPG(maSignatureManager.mxStore, m_sODFVersion)) if (DocumentSignatureHelper::CanSignWithGPG(maSignatureManager.mxStore, m_sODFVersion))
xSecContexts.push_back(maSignatureManager.getGpgSecurityContext()); xSecContexts.push_back(maSignatureManager.getGpgSecurityContext());
ScopedVclPtrInstance< CertificateChooser > aChooser( this, mxCtx, xSecContexts ); ScopedVclPtrInstance< CertificateChooser > aChooser( this, mxCtx, xSecContexts, UserAction::Sign );
if ( aChooser->Execute() == RET_OK ) if ( aChooser->Execute() == RET_OK )
{ {
sal_Int32 nSecurityId; sal_Int32 nSecurityId;
......
...@@ -182,6 +182,17 @@ ...@@ -182,6 +182,17 @@
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="label" translatable="yes" context="selectcertificatedialog|STR_ENCIPHER_ONLY">Only for encipherment</property> <property name="label" translatable="yes" context="selectcertificatedialog|STR_ENCIPHER_ONLY">Only for encipherment</property>
</object> </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> </child>
</object> </object>
<packing> <packing>
...@@ -190,18 +201,31 @@ ...@@ -190,18 +201,31 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkLabel" id="label1"> <object class="GtkLabel" id="sign">
<property name="visible">True</property> <property name="visible">False</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="xalign">0</property> <property name="xalign">0</property>
<property name="ypad">1</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> </object>
<packing> <packing>
<property name="left_attach">0</property> <property name="left_attach">0</property>
<property name="top_attach">0</property> <property name="top_attach">0</property>
</packing> </packing>
</child> </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> <child>
<object class="svtlo-SvSimpleTableContainer" id="signatures"> <object class="svtlo-SvSimpleTableContainer" id="signatures">
<property name="visible">True</property> <property name="visible">True</property>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment