diff options
Diffstat (limited to 'xmlsecurity')
-rw-r--r-- | xmlsecurity/inc/macrosecurity.hxx | 3 | ||||
-rw-r--r-- | xmlsecurity/inc/strings.hrc | 2 | ||||
-rw-r--r-- | xmlsecurity/source/dialogs/macrosecurity.cxx | 76 | ||||
-rw-r--r-- | xmlsecurity/uiconfig/ui/securitytrustpage.ui | 4 |
4 files changed, 66 insertions, 19 deletions
diff --git a/xmlsecurity/inc/macrosecurity.hxx b/xmlsecurity/inc/macrosecurity.hxx index 3dafc9d6d4dd..88d1c18a325d 100644 --- a/xmlsecurity/inc/macrosecurity.hxx +++ b/xmlsecurity/inc/macrosecurity.hxx @@ -120,8 +120,9 @@ private: DECL_LINK(TrustCertLBSelectHdl, weld::TreeView&, void); DECL_LINK(TrustFileLocLBSelectHdl, weld::TreeView&, void); - void FillCertLB(); + void FillCertLB(const bool bShowWarnings = false); void ImplCheckButtons(); + void ShowBrokenCertificateError(const OUString& rData); public: MacroSecurityTrustedSourcesTP(weld::Container* pParent, MacroSecurity* pDlg); diff --git a/xmlsecurity/inc/strings.hrc b/xmlsecurity/inc/strings.hrc index deed17e9e1a2..e16a3dd7b5db 100644 --- a/xmlsecurity/inc/strings.hrc +++ b/xmlsecurity/inc/strings.hrc @@ -63,6 +63,8 @@ #define STR_SELECTSIGN NC_("selectcertificatedialog|str_selectsign", "Select") #define STR_ENCRYPT NC_("selectcertificatedialog|str_encrypt", "Encrypt") +#define STR_BROKEN_MACRO_CERTIFICATE_DATA NC_("STR_BROKEN_MACRO_CERTIFICATE_DATA", "Macro security problem!\n\nBroken certificate data: %{data}") + #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmlsecurity/source/dialogs/macrosecurity.cxx b/xmlsecurity/source/dialogs/macrosecurity.cxx index bb1015586cf4..0fbdbcf57323 100644 --- a/xmlsecurity/source/dialogs/macrosecurity.cxx +++ b/xmlsecurity/source/dialogs/macrosecurity.cxx @@ -21,6 +21,8 @@ #include <macrosecurity.hxx> #include <certificateviewer.hxx> #include <biginteger.hxx> +#include <resourcemanager.hxx> +#include <strings.hrc> #include <osl/file.hxx> #include <sal/log.hxx> @@ -195,27 +197,52 @@ void MacroSecurityTrustedSourcesTP::ImplCheckButtons() m_xRemoveLocPB->set_sensitive( bLocationSelected && !mbURLsReadonly); } +void MacroSecurityTrustedSourcesTP::ShowBrokenCertificateError(const OUString& rData) +{ + OUString aMsg = XsResId(STR_BROKEN_MACRO_CERTIFICATE_DATA); + aMsg = aMsg.replaceFirst("%{data}", rData); + std::unique_ptr<weld::MessageDialog> xErrorBox(Application::CreateMessageDialog(m_pDlg->getDialog(), + VclMessageType::Error, VclButtonsType::Ok, aMsg)); + xErrorBox->run(); +} IMPL_LINK_NOARG(MacroSecurityTrustedSourcesTP, ViewCertPBHdl, weld::Button&, void) { int nEntry = m_xTrustCertLB->get_selected_index(); if (nEntry != -1) { - sal_uInt16 nSelected = m_xTrustCertLB->get_id(nEntry).toUInt32(); - - uno::Reference< css::security::XCertificate > xCert = m_pDlg->m_xSecurityEnvironment->getCertificate( m_aTrustedAuthors[nSelected][0], xmlsecurity::numericStringToBigInteger( m_aTrustedAuthors[nSelected][1] ) ); - - // If we don't get it, create it from signature data: - if ( !xCert.is() ) - xCert = m_pDlg->m_xSecurityEnvironment->createCertificateFromAscii( m_aTrustedAuthors[nSelected][2] ) ; + const sal_uInt16 nSelected = m_xTrustCertLB->get_id(nEntry).toUInt32(); + uno::Reference< css::security::XCertificate > xCert; + try + { + xCert = m_pDlg->m_xSecurityEnvironment->getCertificate(m_aTrustedAuthors[nSelected][0], + xmlsecurity::numericStringToBigInteger(m_aTrustedAuthors[nSelected][1])); + } + catch (...) + { + TOOLS_WARN_EXCEPTION("xmlsecurity.dialogs", "matching certificate not found for: " << m_aTrustedAuthors[nSelected][0]); + } - SAL_WARN_IF( !xCert.is(), "xmlsecurity.dialogs", "*MacroSecurityTrustedSourcesTP::ViewCertPBHdl(): Certificate not found and can't be created!" ); + if (!xCert.is()) + { + try + { + xCert = m_pDlg->m_xSecurityEnvironment->createCertificateFromAscii(m_aTrustedAuthors[nSelected][2]); + } + catch (...) + { + TOOLS_WARN_EXCEPTION("xmlsecurity.dialogs", "certificate data couldn't be parsed: " << m_aTrustedAuthors[nSelected][2]); + } + } if ( xCert.is() ) { CertificateViewer aViewer(m_pDlg->getDialog(), m_pDlg->m_xSecurityEnvironment, xCert, false, nullptr); aViewer.run(); } + else + // should never happen, as we parsed the certificate data when we added it! + ShowBrokenCertificateError(m_aTrustedAuthors[nSelected][2]); } } @@ -297,7 +324,7 @@ IMPL_LINK_NOARG(MacroSecurityTrustedSourcesTP, TrustFileLocLBSelectHdl, weld::Tr ImplCheckButtons(); } -void MacroSecurityTrustedSourcesTP::FillCertLB() +void MacroSecurityTrustedSourcesTP::FillCertLB(const bool bShowWarnings) { m_xTrustCertLB->clear(); @@ -309,12 +336,27 @@ void MacroSecurityTrustedSourcesTP::FillCertLB() { css::uno::Sequence< OUString >& rEntry = m_aTrustedAuthors[ nEntry ]; - // create from RawData - uno::Reference< css::security::XCertificate > xCert = m_pDlg->m_xSecurityEnvironment->createCertificateFromAscii( rEntry[ 2 ] ); - - m_xTrustCertLB->append(OUString::number(nEntry), xmlsec::GetContentPart(xCert->getSubjectName())); - m_xTrustCertLB->set_text(nEntry, xmlsec::GetContentPart(xCert->getIssuerName()), 1); - m_xTrustCertLB->set_text(nEntry, utl::GetDateTimeString(xCert->getNotValidAfter()), 2); + try + { + // create from RawData + uno::Reference< css::security::XCertificate > xCert = m_pDlg->m_xSecurityEnvironment->createCertificateFromAscii(rEntry[2]); + m_xTrustCertLB->append(OUString::number(nEntry), xmlsec::GetContentPart(xCert->getSubjectName())); + m_xTrustCertLB->set_text(nEntry, xmlsec::GetContentPart(xCert->getIssuerName()), 1); + m_xTrustCertLB->set_text(nEntry, utl::GetDateTimeString(xCert->getNotValidAfter()), 2); + } + catch (...) + { + if (bShowWarnings) + { + TOOLS_WARN_EXCEPTION("xmlsecurity.dialogs", "certificate data couldn't be parsed: " << rEntry[2]); + OUString sData = rEntry[2]; + css::uno::Any tools_warn_exception(DbgGetCaughtException()); + OUString sException = OStringToOUString(exceptionToString(tools_warn_exception), RTL_TEXTENCODING_UTF8); + if (!sException.isEmpty()) + sData += " / " + sException; + ShowBrokenCertificateError(sData); + } + } } } } @@ -352,14 +394,12 @@ MacroSecurityTrustedSourcesTP::MacroSecurityTrustedSourcesTP(weld::Container* pP m_aTrustedAuthors = m_pDlg->m_aSecOptions.GetTrustedAuthors(); mbAuthorsReadonly = m_pDlg->m_aSecOptions.IsReadOnly( SvtSecurityOptions::EOption::MacroTrustedAuthors ); m_xTrustCertROFI->set_visible(mbAuthorsReadonly); - m_xTrustCertLB->set_sensitive(!mbAuthorsReadonly); - FillCertLB(); + FillCertLB(true); const css::uno::Sequence< OUString > aSecureURLs = m_pDlg->m_aSecOptions.GetSecureURLs(); mbURLsReadonly = m_pDlg->m_aSecOptions.IsReadOnly( SvtSecurityOptions::EOption::SecureUrls ); m_xTrustFileROFI->set_visible(mbURLsReadonly); - m_xTrustFileLocLB->set_sensitive(!mbURLsReadonly); m_xAddLocPB->set_sensitive(!mbURLsReadonly); for (const auto& rSecureURL : aSecureURLs) diff --git a/xmlsecurity/uiconfig/ui/securitytrustpage.ui b/xmlsecurity/uiconfig/ui/securitytrustpage.ui index 88edf37e485c..b9d5ef518396 100644 --- a/xmlsecurity/uiconfig/ui/securitytrustpage.ui +++ b/xmlsecurity/uiconfig/ui/securitytrustpage.ui @@ -169,6 +169,8 @@ <property name="can_focus">False</property> <property name="no_show_all">True</property> <property name="icon_name">res/lock.png</property> + <property name="halign">center</property> + <property name="valign">center</property> </object> <packing> <property name="left_attach">0</property> @@ -325,6 +327,8 @@ <property name="can_focus">False</property> <property name="no_show_all">True</property> <property name="icon_name">res/lock.png</property> + <property name="halign">center</property> + <property name="valign">center</property> </object> <packing> <property name="left_attach">0</property> |