You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by ar...@apache.org on 2021/09/04 16:14:29 UTC
[openoffice] 01/01: Avoid setting fields multiple times
This is an automated email from the ASF dual-hosted git repository.
ardovm pushed a commit to branch signatures
in repository https://gitbox.apache.org/repos/asf/openoffice.git
commit ef3a46e8a82b089876dea0dcc0f68585f7924b6c
Author: Arrigo Marchiori <ar...@yahoo.it>
AuthorDate: Sat Sep 4 18:01:41 2021 +0200
Avoid setting fields multiple times
---
main/xmlsecurity/source/helper/xsecctl.hxx | 45 +++++++++++++++++++++++++++
main/xmlsecurity/source/helper/xsecverify.cxx | 16 +++++++---
2 files changed, 57 insertions(+), 4 deletions(-)
diff --git a/main/xmlsecurity/source/helper/xsecctl.hxx b/main/xmlsecurity/source/helper/xsecctl.hxx
index 30ba2aa..1eb46b8 100644
--- a/main/xmlsecurity/source/helper/xsecctl.hxx
+++ b/main/xmlsecurity/source/helper/xsecctl.hxx
@@ -405,12 +405,57 @@ private:
bool isBinary );
void setReferenceCount() const;
+ /** Set a variable unless already set with a different value.
+ *
+ * @param variable variable to set.
+ * @param value value to set.
+ *
+ * @throw com::sun::star::uno::RuntimeException if the variable is not
+ * empty and its contents are different from value.
+ */
+ void setIfEmpty(rtl::OUString &variable, const rtl::OUString &value);
+ /** Set the X509 issuer name
+ *
+ * @param ouX509IssuerName value to set.
+ *
+ * This method should be called not more than once.
+ *
+ * @throw com::sun:star::uno::RuntimeException if a tampering is
+ * detected.
+ */
void setX509IssuerName( rtl::OUString& ouX509IssuerName );
+ /** Set the X509 serial number.
+ *
+ * @param ouX509SerialNumber value to set.
+ *
+ * This method should be called not more than once.
+ *
+ * @throw com::sun:star::uno::RuntimeException if a tampering is
+ * detected.
+ */
void setX509SerialNumber( rtl::OUString& ouX509SerialNumber );
+ /** Set the X509 certificate.
+ *
+ * @param ouX509Certificate value to set.
+ *
+ * This method should be called not more than once.
+ *
+ * @throw com::sun:star::uno::RuntimeException if a tampering is
+ * detected.
+ */
void setX509Certificate( rtl::OUString& ouX509Certificate );
void setSignatureValue( rtl::OUString& ouSignatureValue );
void setDigestValue( rtl::OUString& ouDigestValue );
+ /** Set the signature date.
+ *
+ * @param ouDate value to set.
+ *
+ * This method should be called not more than once.
+ *
+ * @throw com::sun:star::uno::RuntimeException if a tampering is
+ * detected.
+ */
void setDate( rtl::OUString& ouDate );
void setId( rtl::OUString& ouId );
diff --git a/main/xmlsecurity/source/helper/xsecverify.cxx b/main/xmlsecurity/source/helper/xsecverify.cxx
index 7e556a1..4cc3870 100644
--- a/main/xmlsecurity/source/helper/xsecverify.cxx
+++ b/main/xmlsecurity/source/helper/xsecverify.cxx
@@ -177,22 +177,30 @@ void XSecController::setReferenceCount() const
}
}
+void XSecController::setIfEmpty(rtl::OUString &variable, const rtl::OUString &value) {
+ if (variable.getLength() == 0) {
+ variable = value;
+ } else if (variable != value) {
+ throw cssu::RuntimeException(rtl::OUString::createFromAscii("Value already set. Tampering?"), *this);
+ }
+}
+
void XSecController::setX509IssuerName( rtl::OUString& ouX509IssuerName )
{
InternalSignatureInformation &isi = m_vInternalSignatureInformations[m_vInternalSignatureInformations.size()-1];
- isi.signatureInfor.ouX509IssuerName = ouX509IssuerName;
+ setIfEmpty(isi.signatureInfor.ouX509IssuerName, ouX509IssuerName);
}
void XSecController::setX509SerialNumber( rtl::OUString& ouX509SerialNumber )
{
InternalSignatureInformation &isi = m_vInternalSignatureInformations[m_vInternalSignatureInformations.size()-1];
- isi.signatureInfor.ouX509SerialNumber = ouX509SerialNumber;
+ setIfEmpty(isi.signatureInfor.ouX509SerialNumber, ouX509SerialNumber);
}
void XSecController::setX509Certificate( rtl::OUString& ouX509Certificate )
{
InternalSignatureInformation &isi = m_vInternalSignatureInformations[m_vInternalSignatureInformations.size()-1];
- isi.signatureInfor.ouX509Certificate = ouX509Certificate;
+ setIfEmpty(isi.signatureInfor.ouX509Certificate, ouX509Certificate);
}
void XSecController::setSignatureValue( rtl::OUString& ouSignatureValue )
@@ -212,7 +220,7 @@ void XSecController::setDate( rtl::OUString& ouDate )
{
InternalSignatureInformation &isi = m_vInternalSignatureInformations[m_vInternalSignatureInformations.size()-1];
convertDateTime( isi.signatureInfor.stDateTime, ouDate );
- isi.signatureInfor.ouDateTime = ouDate;
+ setIfEmpty(isi.signatureInfor.ouDateTime, ouDate);
}
/*