cui/source/options/optgenrl.cxx | 38 ++++++++++++++- include/unotools/useroptions.hxx | 9 +++ unotools/source/config/useroptions.cxx | 54 ++++++++++++++++++++-- xmlsecurity/inc/certificatechooser.hxx | 2 xmlsecurity/source/dialogs/certificatechooser.cxx | 29 +++++++++++ 5 files changed, 123 insertions(+), 9 deletions(-)
New commits: commit 5c66c0711286bcfa9d3ab4a87777c2af9e1c25d9 Author: Katarina Behrens <katarina.behr...@cib.de> Date: Thu Dec 14 13:14:02 2017 +0100 Read/write 'encrypt to self' bit use some template functions to avoid duplicate code Change-Id: Ia178ea3a0561e34e0431749262f5f8f1f49b4fe7 Reviewed-on: https://gerrit.libreoffice.org/46693 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Thorsten Behrens <thorsten.behr...@cib.de> diff --git a/cui/source/options/optgenrl.cxx b/cui/source/options/optgenrl.cxx index 83a98e60c7b0..c25144f04266 100644 --- a/cui/source/options/optgenrl.cxx +++ b/cui/source/options/optgenrl.cxx @@ -443,11 +443,14 @@ bool SvxGeneralTabPage::GetData_Impl() : m_pSigningKeyLB->GetSelectedEntry(); OUString aEK = m_pEncryptionKeyLB->GetSelectedEntryPos() == 0 ? OUString() : m_pEncryptionKeyLB->GetSelectedEntry(); + aUserOpt.SetToken( UserOptToken::SigningKey, aSK ); aUserOpt.SetToken( UserOptToken::EncryptionKey, aEK ); + aUserOpt.SetBoolValue( UserOptToken::EncryptToSelf, m_pEncryptToSelfCB->IsChecked() ); - bModified |= m_pSigningKeyLB->IsValueChangedFromSaved(); - bModified |= m_pEncryptionKeyLB->IsValueChangedFromSaved(); + bModified |= m_pSigningKeyLB->IsValueChangedFromSaved() || + m_pEncryptionKeyLB->IsValueChangedFromSaved() || + m_pEncryptToSelfCB->IsValueChangedFromSaved(); #endif return bModified; @@ -489,6 +492,8 @@ void SvxGeneralTabPage::SetData_Impl() OUString aEK = aUserOpt.GetToken(UserOptToken::EncryptionKey); aEK.isEmpty() ? m_pEncryptionKeyLB->SelectEntryPos( 0 ) //i.e. 'No Key' : m_pEncryptionKeyLB->SelectEntry( aEK ); + + m_pEncryptToSelfCB->Check( aUserOpt.GetEncryptToSelf() ); #endif } diff --git a/include/unotools/useroptions.hxx b/include/unotools/useroptions.hxx index 946ba8d34c10..60c18df65ae2 100644 --- a/include/unotools/useroptions.hxx +++ b/include/unotools/useroptions.hxx @@ -47,7 +47,8 @@ enum class UserOptToken Apartment = 16, SigningKey = 17, EncryptionKey = 18, - LAST = EncryptionKey, + EncryptToSelf = 19, + LAST = EncryptToSelf, }; // class SvtUserOptions -------------------------------------------------- @@ -78,12 +79,14 @@ public: OUString GetEmail () const; OUString GetSigningKey () const; OUString GetEncryptionKey () const; + bool GetEncryptToSelf () const; OUString GetFullName () const; bool IsTokenReadonly (UserOptToken nToken) const; OUString GetToken (UserOptToken nToken) const; void SetToken (UserOptToken nToken, OUString const& rNewToken); + void SetBoolValue (UserOptToken nToken, bool bNewValue); private: class Impl; diff --git a/unotools/source/config/useroptions.cxx b/unotools/source/config/useroptions.cxx index e19168da2885..adf58180204a 100644 --- a/unotools/source/config/useroptions.cxx +++ b/unotools/source/config/useroptions.cxx @@ -67,7 +67,8 @@ static o3tl::enumarray<UserOptToken, char const *> vOptionNames = { "fathersname", // UserOptToken::FathersName "apartment", // UserOptToken::Apartment "signingkey", // UserOptToken::SigningKey - "encryptionkey" // UserOptToken::EncryptionKey + "encryptionkey", // UserOptToken::EncryptionKey + "encrypttoself" // UserOptToken::EncryptToSelf }; std::weak_ptr<SvtUserOptions::Impl> SvtUserOptions::xSharedImpl; @@ -96,12 +97,19 @@ public: bool IsTokenReadonly (UserOptToken nToken) const; OUString GetToken (UserOptToken nToken) const; void SetToken (UserOptToken nToken, OUString const& rNewToken); + bool GetBoolValue (UserOptToken nToken) const; + void SetBoolValue (UserOptToken nToken, bool& bNewValue); void Notify (); private: uno::Reference<util::XChangesListener> m_xChangeListener; uno::Reference<container::XNameAccess> m_xCfg; uno::Reference<beans::XPropertySet> m_xData; + + template < typename ValueType > + ValueType GetValue_Impl( UserOptToken nToken ) const; + template < typename ValueType > + void SetValue_Impl( UserOptToken nToken, ValueType const& rNewValue ); }; void SvtUserOptions::ChangeListener::changesOccurred (util::ChangesEvent const& rEvent) @@ -153,9 +161,10 @@ SvtUserOptions::Impl::Impl() : } } -OUString SvtUserOptions::Impl::GetToken (UserOptToken nToken) const +template < typename ValueType > +ValueType SvtUserOptions::Impl::GetValue_Impl (UserOptToken nToken) const { - OUString sToken; + ValueType sToken = ValueType(); try { if (m_xData.is()) @@ -168,7 +177,8 @@ OUString SvtUserOptions::Impl::GetToken (UserOptToken nToken) const return sToken; } -void SvtUserOptions::Impl::SetToken (UserOptToken nToken, OUString const& sToken) +template < typename ValueType > +void SvtUserOptions::Impl::SetValue_Impl (UserOptToken nToken, ValueType const& sToken) { try { @@ -182,6 +192,26 @@ void SvtUserOptions::Impl::SetToken (UserOptToken nToken, OUString const& sToken } } +OUString SvtUserOptions::Impl::GetToken (UserOptToken nToken) const +{ + return GetValue_Impl<OUString>( nToken ); +} + +void SvtUserOptions::Impl::SetToken (UserOptToken nToken, OUString const& sToken) +{ + SetValue_Impl<OUString>( nToken, sToken ); +} + +bool SvtUserOptions::Impl::GetBoolValue (UserOptToken nToken) const +{ + return GetValue_Impl<bool>( nToken ); +} + +void SvtUserOptions::Impl::SetBoolValue (UserOptToken nToken, bool& bNewValue) +{ + SetValue_Impl<bool>( nToken, bNewValue ); +} + OUString SvtUserOptions::Impl::GetFullName () const { OUString sFullName; @@ -299,6 +329,18 @@ void SvtUserOptions::SetToken (UserOptToken nToken, OUString const& rNewToken) xImpl->SetToken(nToken, rNewToken); } +void SvtUserOptions::SetBoolValue (UserOptToken nToken, bool bNewValue) +{ + osl::MutexGuard aGuard(GetInitMutex()); + xImpl->SetBoolValue(nToken, bNewValue); +} + +bool SvtUserOptions::GetEncryptToSelf() const +{ + osl::MutexGuard aGuard(GetInitMutex()); + return xImpl->GetBoolValue(UserOptToken::EncryptToSelf); +} + OUString SvtUserOptions::GetFullName () const { osl::MutexGuard aGuard(GetInitMutex()); commit df4fac1dbce087bbd01bbec242b93c72edcef74b Author: Katarina Behrens <katarina.behr...@cib.de> Date: Wed Dec 13 18:39:10 2017 +0100 Read/write preferred GPG signing/encryption keys Change-Id: I3e21469c5f4c4f199407bbe9faba2e2ddca531b3 Reviewed-on: https://gerrit.libreoffice.org/46692 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Thorsten Behrens <thorsten.behr...@cib.de> diff --git a/cui/source/options/optgenrl.cxx b/cui/source/options/optgenrl.cxx index b63fbf580b69..83a98e60c7b0 100644 --- a/cui/source/options/optgenrl.cxx +++ b/cui/source/options/optgenrl.cxx @@ -428,10 +428,29 @@ bool SvxGeneralTabPage::GetData_Impl() ); // modified? + bool bModified = false; for (auto const & i: vFields) + { if (i->pEdit->IsValueChangedFromSaved()) - return true; - return false; + { + bModified = true; + break; + } + } + +#if HAVE_FEATURE_GPGME + OUString aSK = m_pSigningKeyLB->GetSelectedEntryPos() == 0 ? OUString() //i.e. no key + : m_pSigningKeyLB->GetSelectedEntry(); + OUString aEK = m_pEncryptionKeyLB->GetSelectedEntryPos() == 0 ? OUString() + : m_pEncryptionKeyLB->GetSelectedEntry(); + aUserOpt.SetToken( UserOptToken::SigningKey, aSK ); + aUserOpt.SetToken( UserOptToken::EncryptionKey, aEK ); + + bModified |= m_pSigningKeyLB->IsValueChangedFromSaved(); + bModified |= m_pEncryptionKeyLB->IsValueChangedFromSaved(); +#endif + + return bModified; } @@ -461,6 +480,16 @@ void SvxGeneralTabPage::SetData_Impl() // saving for (auto const & i: vFields) i->pEdit->SaveValue(); + +#if HAVE_FEATURE_GPGME + OUString aSK = aUserOpt.GetToken(UserOptToken::SigningKey); + aSK.isEmpty() ? m_pSigningKeyLB->SelectEntryPos( 0 ) //i.e. 'No Key' + : m_pSigningKeyLB->SelectEntry( aSK ); + + OUString aEK = aUserOpt.GetToken(UserOptToken::EncryptionKey); + aEK.isEmpty() ? m_pEncryptionKeyLB->SelectEntryPos( 0 ) //i.e. 'No Key' + : m_pEncryptionKeyLB->SelectEntry( aEK ); +#endif } diff --git a/include/unotools/useroptions.hxx b/include/unotools/useroptions.hxx index f82201fdd28a..946ba8d34c10 100644 --- a/include/unotools/useroptions.hxx +++ b/include/unotools/useroptions.hxx @@ -45,7 +45,9 @@ enum class UserOptToken Zip = 14, FathersName = 15, Apartment = 16, - LAST = Apartment, + SigningKey = 17, + EncryptionKey = 18, + LAST = EncryptionKey, }; // class SvtUserOptions -------------------------------------------------- @@ -74,6 +76,8 @@ public: OUString GetTelephoneWork () const; OUString GetFax () const; OUString GetEmail () const; + OUString GetSigningKey () const; + OUString GetEncryptionKey () const; OUString GetFullName () const; diff --git a/unotools/source/config/useroptions.cxx b/unotools/source/config/useroptions.cxx index 31ce8c9893d0..e19168da2885 100644 --- a/unotools/source/config/useroptions.cxx +++ b/unotools/source/config/useroptions.cxx @@ -65,7 +65,9 @@ static o3tl::enumarray<UserOptToken, char const *> vOptionNames = { "initials", // UserOptToken::ID "postalcode", // UserOptToken::Zip "fathersname", // UserOptToken::FathersName - "apartment" // UserOptToken::Apartment + "apartment", // UserOptToken::Apartment + "signingkey", // UserOptToken::SigningKey + "encryptionkey" // UserOptToken::EncryptionKey }; std::weak_ptr<SvtUserOptions::Impl> SvtUserOptions::xSharedImpl; @@ -276,6 +278,8 @@ OUString SvtUserOptions::GetTelephoneHome () const { return GetToken(UserOptTok OUString SvtUserOptions::GetTelephoneWork () const { return GetToken(UserOptToken::TelephoneWork); } OUString SvtUserOptions::GetFax () const { return GetToken(UserOptToken::Fax); } OUString SvtUserOptions::GetEmail () const { return GetToken(UserOptToken::Email); } +OUString SvtUserOptions::GetSigningKey () const { return GetToken(UserOptToken::SigningKey); } +OUString SvtUserOptions::GetEncryptionKey () const { return GetToken(UserOptToken::EncryptionKey); } bool SvtUserOptions::IsTokenReadonly (UserOptToken nToken) const { commit ee40674b4c9343db5e69cd5118bdbcf8e6edad6d Author: Katarina Behrens <katarina.behr...@cib.de> Date: Thu Dec 14 18:12:56 2017 +0100 Do things with preferred GPG keys For signing, preselect the key in the list of available keys. For encryption, when 'encrypt to self' bit is set, add user's key to the list of keys to encryption. Change-Id: I5bbfd0e2cc97b76c1304a2a345a51cf83bc5949e Reviewed-on: https://gerrit.libreoffice.org/46694 Reviewed-by: Thorsten Behrens <thorsten.behr...@cib.de> Tested-by: Thorsten Behrens <thorsten.behr...@cib.de> diff --git a/xmlsecurity/inc/certificatechooser.hxx b/xmlsecurity/inc/certificatechooser.hxx index be3828b5c5e9..6049eb4a3869 100644 --- a/xmlsecurity/inc/certificatechooser.hxx +++ b/xmlsecurity/inc/certificatechooser.hxx @@ -73,6 +73,8 @@ private: bool mbInitialized; UserAction meAction; + OUString msPreferredKey; + css::uno::Reference<css::security::XCertificate> mxEncryptToSelf; DECL_LINK(ViewButtonHdl, Button*, void); DECL_LINK(CertificateHighlightHdl, SvTreeListBox*, void ); diff --git a/xmlsecurity/source/dialogs/certificatechooser.cxx b/xmlsecurity/source/dialogs/certificatechooser.cxx index bf100c6d0401..5a1edcae872d 100644 --- a/xmlsecurity/source/dialogs/certificatechooser.cxx +++ b/xmlsecurity/source/dialogs/certificatechooser.cxx @@ -17,7 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ - +#include <config_gpgme.h> #include <certificatechooser.hxx> #include <certificateviewer.hxx> #include <biginteger.hxx> @@ -31,6 +31,7 @@ #include <resourcemanager.hxx> #include <vcl/msgbox.hxx> #include <svtools/treelistentry.hxx> +#include <unotools/useroptions.hxx> using namespace css; @@ -159,11 +160,14 @@ void CertificateChooser::ImplInitialize() if ( mbInitialized ) return; + SvtUserOptions aUserOpts; + switch (meAction) { case UserAction::Sign: m_pFTSign->Show(); m_pOKBtn->SetText( get<FixedText>("str_sign")->GetText() ); + msPreferredKey = aUserOpts.GetSigningKey(); break; case UserAction::Encrypt: @@ -172,6 +176,7 @@ void CertificateChooser::ImplInitialize() m_pDescriptionED->Hide(); m_pCertLB->SetSelectionMode( SelectionMode::Multiple ); m_pOKBtn->SetText( get<FixedText>("str_encrypt")->GetText() ); + msPreferredKey = aUserOpts.GetEncryptionKey(); break; } @@ -210,6 +215,7 @@ void CertificateChooser::ImplInitialize() } } + // fill list of certificates; the first entry will be selected for ( sal_Int32 nC = 0; nC < nCertificates; ++nC ) { @@ -218,12 +224,26 @@ void CertificateChooser::ImplInitialize() userData->xSecurityContext = secContext; userData->xSecurityEnvironment = secEnvironment; mvUserData.push_back(userData); + + OUString sIssuer = XmlSec::GetContentPart( xCerts[ nC ]->getIssuerName() ); SvTreeListEntry* pEntry = m_pCertLB->InsertEntry( XmlSec::GetContentPart( xCerts[ nC ]->getSubjectName() ) - + "\t" + XmlSec::GetContentPart( xCerts[ nC ]->getIssuerName() ) + + "\t" + sIssuer + "\t" + XmlSec::GetCertificateKind( xCerts[ nC ]->getCertificateKind() ) + "\t" + XmlSec::GetDateString( xCerts[ nC ]->getNotValidAfter() ) + "\t" + UsageInClearText( xCerts[ nC ]->getCertificateUsage() ) ); pEntry->SetUserData( userData.get() ); + +#if HAVE_FEATURE_GPGME + // only GPG has preferred keys + if ( sIssuer == msPreferredKey ) + { + if ( meAction == UserAction::Sign ) + m_pCertLB->Select( pEntry ); + else if ( meAction == UserAction::Encrypt && + aUserOpts.GetEncryptToSelf() ) + mxEncryptToSelf = xCerts[nC]; + } +#endif } } @@ -259,6 +279,11 @@ uno::Sequence<uno::Reference< css::security::XCertificate > > CertificateChooser aRet.push_back( xCert ); } +#if HAVE_FEATURE_GPGME + if ( mxEncryptToSelf.is()) + aRet.push_back( mxEncryptToSelf ); +#endif + return comphelper::containerToSequence(aRet); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits