gpg4libre: When encrypting, show all available GPG keys

(not only private ones)

Change-Id: I3fd248f4cace1ea248267d5696da9cb70940744e
Reviewed-on: https://gerrit.libreoffice.org/41508
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
diff --git a/offapi/com/sun/star/xml/crypto/XSecurityEnvironment.idl b/offapi/com/sun/star/xml/crypto/XSecurityEnvironment.idl
index 7227a4e..f3d1ddb 100644
--- a/offapi/com/sun/star/xml/crypto/XSecurityEnvironment.idl
+++ b/offapi/com/sun/star/xml/crypto/XSecurityEnvironment.idl
@@ -99,6 +99,13 @@ interface XSecurityEnvironment : com::sun::star::uno::XInterface
     */
    string getSecurityEnvironmentInformation ( );

    /**
     * List all certificates, private (as returned by getPersonalCertificates) as well as those of other people/orgas
     *
     * @since LibreOffice 6.0
     */
    sequence< com::sun::star::security::XCertificate > getAllCertificates() raises( com::sun::star::uno::SecurityException ) ;

} ;

} ; } ; } ; } ; } ;
diff --git a/xmlsecurity/source/dialogs/certificatechooser.cxx b/xmlsecurity/source/dialogs/certificatechooser.cxx
index 52aa7e9..bf74d1b0 100644
--- a/xmlsecurity/source/dialogs/certificatechooser.cxx
+++ b/xmlsecurity/source/dialogs/certificatechooser.cxx
@@ -182,7 +182,10 @@ void CertificateChooser::ImplInitialize()
        uno::Sequence< uno::Reference< security::XCertificate > > xCerts;
        try
        {
            xCerts = secEnvironment->getPersonalCertificates();
            if ( meAction == UserAction::Sign )
                xCerts = secEnvironment->getPersonalCertificates();
            else
                xCerts = secEnvironment->getAllCertificates();
        }
        catch (security::NoPasswordException&)
        {
diff --git a/xmlsecurity/source/gpg/SecurityEnvironment.cxx b/xmlsecurity/source/gpg/SecurityEnvironment.cxx
index 367fa35..c3cd905 100644
--- a/xmlsecurity/source/gpg/SecurityEnvironment.cxx
+++ b/xmlsecurity/source/gpg/SecurityEnvironment.cxx
@@ -64,14 +64,14 @@ OUString SecurityEnvironmentGpg::getSecurityEnvironmentInformation()
    return OUString();
}

Sequence< Reference < XCertificate > > SecurityEnvironmentGpg::getPersonalCertificates()
Sequence< Reference < XCertificate > > SecurityEnvironmentGpg::getCertificatesImpl( bool bPrivateOnly )
{
    CertificateImpl* xCert;
    std::list< GpgME::Key > keyList;
    std::list< CertificateImpl* > certsList;

    m_ctx->setKeyListMode(GPGME_KEYLIST_MODE_LOCAL);
    GpgME::Error err = m_ctx->startKeyListing("", true);
    GpgME::Error err = m_ctx->startKeyListing("", bPrivateOnly );
    while (!err) {
        GpgME::Key k = m_ctx->nextKey(err);
        if (err)
@@ -99,6 +99,16 @@ Sequence< Reference < XCertificate > > SecurityEnvironmentGpg::getPersonalCertif
    return xCertificateSequence;
}

Sequence< Reference < XCertificate > > SecurityEnvironmentGpg::getPersonalCertificates()
{
    return getCertificatesImpl( true );
}

Sequence< Reference < XCertificate > > SecurityEnvironmentGpg::getAllCertificates()
{
    return getCertificatesImpl( false );
}

Reference< XCertificate > SecurityEnvironmentGpg::getCertificate( const OUString& keyId, const Sequence< sal_Int8 >& /*serialNumber*/ )
{
    CertificateImpl* xCert=nullptr;
diff --git a/xmlsecurity/source/gpg/SecurityEnvironment.hxx b/xmlsecurity/source/gpg/SecurityEnvironment.hxx
index 2af512b..fda9d706 100644
--- a/xmlsecurity/source/gpg/SecurityEnvironment.hxx
+++ b/xmlsecurity/source/gpg/SecurityEnvironment.hxx
@@ -67,6 +67,10 @@ public:
        const OUString& asciiCertificate ) override;

    GpgME::Context& getGpgContext() { return *m_ctx.get(); }
    virtual css::uno::Sequence< css::uno::Reference< css::security::XCertificate > > SAL_CALL getAllCertificates() override;

private:
    css::uno::Sequence< css::uno::Reference< css::security::XCertificate > > getCertificatesImpl( bool bPrivateOnly );
} ;

#endif // INCLUDED_XMLSECURITY_SOURCE_GPG_SECURITYENVIRONMENT_HXX
diff --git a/xmlsecurity/source/xmlsec/mscrypt/securityenvironment_mscryptimpl.hxx b/xmlsecurity/source/xmlsec/mscrypt/securityenvironment_mscryptimpl.hxx
index 932f69c..4bed0b9 100644
--- a/xmlsecurity/source/xmlsec/mscrypt/securityenvironment_mscryptimpl.hxx
+++ b/xmlsecurity/source/xmlsec/mscrypt/securityenvironment_mscryptimpl.hxx
@@ -84,6 +84,8 @@ class SecurityEnvironment_MSCryptImpl : public ::cppu::WeakImplHelper<

        //Methods from XSecurityEnvironment
        virtual css::uno::Sequence< css::uno::Reference< css::security::XCertificate > > SAL_CALL getPersonalCertificates() override;
        virtual css::uno::Sequence< css::uno::Reference< css::security::XCertificate > > SAL_CALL getAllCertificates() override
        { return css::uno::Sequence< css::uno::Reference< css::security::XCertificate > >(); }

        virtual css::uno::Reference< css::security::XCertificate > SAL_CALL getCertificate(
            const OUString& issuerName,
diff --git a/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.hxx b/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.hxx
index 46aba7b..fc83a3e 100644
--- a/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.hxx
+++ b/xmlsecurity/source/xmlsec/nss/securityenvironment_nssimpl.hxx
@@ -127,6 +127,8 @@ private:
        SECKEYPrivateKey* getPriKey( unsigned int position ) ;

        virtual css::uno::Sequence< css::uno::Reference< css::security::XCertificate > > SAL_CALL getPersonalCertificates() override ;
        virtual css::uno::Sequence< css::uno::Reference< css::security::XCertificate > > SAL_CALL getAllCertificates() override
        { return css::uno::Sequence< css::uno::Reference< css::security::XCertificate > >(); }

        virtual css::uno::Reference< css::security::XCertificate > SAL_CALL getCertificate( const OUString& issuerName, const css::uno::Sequence< sal_Int8 >& serialNumber ) override ;