[Libreoffice-commits] core.git: 3 commits - xmlsecurity/Library_xsec_xmlsec.mk xmlsecurity/source

Caolán McNamara caolanm at redhat.com
Thu Jul 28 11:37:46 UTC 2016


 xmlsecurity/Library_xsec_xmlsec.mk                            |    2 
 xmlsecurity/source/xmlsec/certificateextension_certextn.cxx   |   54 ++++++
 xmlsecurity/source/xmlsec/certificateextension_certextn.hxx   |   38 ++++
 xmlsecurity/source/xmlsec/certificateextension_xmlsecimpl.cxx |   78 ----------
 xmlsecurity/source/xmlsec/certificateextension_xmlsecimpl.hxx |   36 ++--
 xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.cxx        |   25 ---
 xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.hxx        |   27 ++-
 xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx     |   67 +++++---
 8 files changed, 179 insertions(+), 148 deletions(-)

New commits:
commit 1ebd5de9de4291e7b5cbaaa912f5b4524c14ad81
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Thu Jul 28 10:13:45 2016 +0100

    Related: tdf#95144 now merge common code into a shared CertExtn struct
    
    Change-Id: I7514e092e4314d7cadee33df0e964362777b0b83

diff --git a/xmlsecurity/Library_xsec_xmlsec.mk b/xmlsecurity/Library_xsec_xmlsec.mk
index 65b3cfc..978f7ad 100644
--- a/xmlsecurity/Library_xsec_xmlsec.mk
+++ b/xmlsecurity/Library_xsec_xmlsec.mk
@@ -56,7 +56,7 @@ $(eval $(call gb_Library_use_externals,xsec_xmlsec,\
 
 $(eval $(call gb_Library_add_exception_objects,xsec_xmlsec,\
 	xmlsecurity/source/xmlsec/biginteger \
-	xmlsecurity/source/xmlsec/certificateextension_xmlsecimpl \
+	xmlsecurity/source/xmlsec/certificateextension_certextn \
 	xmlsecurity/source/xmlsec/errorcallback \
 	xmlsecurity/source/xmlsec/saxhelper \
 	xmlsecurity/source/xmlsec/serialnumberadapter \
diff --git a/xmlsecurity/source/xmlsec/certificateextension_xmlsecimpl.cxx b/xmlsecurity/source/xmlsec/certificateextension_certextn.cxx
similarity index 51%
rename from xmlsecurity/source/xmlsec/certificateextension_xmlsecimpl.cxx
rename to xmlsecurity/source/xmlsec/certificateextension_certextn.cxx
index c62648f..3c333d2 100644
--- a/xmlsecurity/source/xmlsec/certificateextension_xmlsecimpl.cxx
+++ b/xmlsecurity/source/xmlsec/certificateextension_certextn.cxx
@@ -17,59 +17,35 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
-#include <sal/config.h>
-#include <rtl/uuid.h>
+#include "certificateextension_certextn.hxx"
 
-#include "certificateextension_xmlsecimpl.hxx"
-
-using namespace ::com::sun::star::uno ;
-
-using ::com::sun::star::security::XCertificateExtension ;
-
-CertificateExtension_XmlSecImpl::CertificateExtension_XmlSecImpl() :
-    m_critical( false ) ,
-    m_xExtnId() ,
-    m_xExtnValue()
+CertificateExtension_CertExtn::CertificateExtension_CertExtn()
+    : m_critical(false)
 {
 }
 
-CertificateExtension_XmlSecImpl::~CertificateExtension_XmlSecImpl() {
-}
-
-
-//Methods from XCertificateExtension
-sal_Bool SAL_CALL CertificateExtension_XmlSecImpl::isCritical() throw( css::uno::RuntimeException, std::exception ) {
-    return m_critical ;
-}
-
-css::uno::Sequence< sal_Int8 > SAL_CALL CertificateExtension_XmlSecImpl::getExtensionId() throw( css::uno::RuntimeException, std::exception ) {
-    return m_xExtnId ;
-}
-
-css::uno::Sequence< sal_Int8 > SAL_CALL CertificateExtension_XmlSecImpl::getExtensionValue() throw( css::uno::RuntimeException, std::exception ) {
-    return m_xExtnValue ;
-}
-
-void CertificateExtension_XmlSecImpl::setCertExtn( unsigned char* value, unsigned int vlen, unsigned char* id, unsigned int idlen, bool critical ) {
+void CertificateExtension_CertExtn::setCertExtn(unsigned char* value, unsigned int vlen,
+                                                unsigned char* id, unsigned int idlen, bool critical)
+{
     unsigned int i ;
     if( value != nullptr && vlen != 0 ) {
-        Sequence< sal_Int8 > extnv( vlen ) ;
+        css::uno::Sequence< sal_Int8 > extnv( vlen ) ;
         for( i = 0; i < vlen ; i ++ )
             extnv[i] = *( value + i ) ;
 
         m_xExtnValue = extnv ;
     } else {
-        m_xExtnValue = Sequence<sal_Int8>();
+        m_xExtnValue = css::uno::Sequence<sal_Int8>();
     }
 
     if( id != nullptr && idlen != 0 ) {
-        Sequence< sal_Int8 > extnId( idlen ) ;
+        css::uno::Sequence< sal_Int8 > extnId( idlen ) ;
         for( i = 0; i < idlen ; i ++ )
             extnId[i] = *( id + i ) ;
 
         m_xExtnId = extnId ;
     } else {
-        m_xExtnId =  Sequence<sal_Int8>();
+        m_xExtnId = css::uno::Sequence<sal_Int8>();
     }
 
     m_critical = critical ;
diff --git a/xmlsecurity/source/xmlsec/certificateextension_certextn.hxx b/xmlsecurity/source/xmlsec/certificateextension_certextn.hxx
new file mode 100644
index 0000000..9f4d384
--- /dev/null
+++ b/xmlsecurity/source/xmlsec/certificateextension_certextn.hxx
@@ -0,0 +1,38 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_XMLSECURITY_SOURCE_XMLSEC_CERTIFICATEEXTENSION_CERTEXTN_HXX
+#define INCLUDED_XMLSECURITY_SOURCE_XMLSEC_CERTIFICATEEXTENSION_CERTEXTN_HXX
+
+#include <sal/config.h>
+#include <com/sun/star/uno/Sequence.hxx>
+
+struct CertificateExtension_CertExtn
+{
+    bool m_critical;
+    css::uno::Sequence< sal_Int8 > m_xExtnId;
+    css::uno::Sequence< sal_Int8 > m_xExtnValue;
+
+    CertificateExtension_CertExtn();
+    void setCertExtn(unsigned char* value, unsigned int vlen, unsigned char* id, unsigned int idlen, bool critical);
+};
+
+#endif // INCLUDED_XMLSECURITY_SOURCE_XMLSEC_CERTIFICATEEXTENSION_CERTEXTN_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmlsecurity/source/xmlsec/certificateextension_xmlsecimpl.hxx b/xmlsecurity/source/xmlsec/certificateextension_xmlsecimpl.hxx
index 0fcbca1..6c6723f 100644
--- a/xmlsecurity/source/xmlsec/certificateextension_xmlsecimpl.hxx
+++ b/xmlsecurity/source/xmlsec/certificateextension_xmlsecimpl.hxx
@@ -27,28 +27,36 @@
 #include <com/sun/star/uno/Exception.hpp>
 #include <com/sun/star/uno/SecurityException.hpp>
 #include <com/sun/star/security/XCertificateExtension.hpp>
+#include "certificateextension_certextn.hxx"
 
 class CertificateExtension_XmlSecImpl : public ::cppu::WeakImplHelper<
     css::security::XCertificateExtension >
 {
     private:
-        bool m_critical ;
-        css::uno::Sequence< sal_Int8 > m_xExtnId ;
-        css::uno::Sequence< sal_Int8 > m_xExtnValue ;
+        CertificateExtension_CertExtn m_Extn;
 
     public:
-        CertificateExtension_XmlSecImpl() ;
-        virtual ~CertificateExtension_XmlSecImpl() ;
-
         //Methods from XCertificateExtension
-        virtual sal_Bool SAL_CALL isCritical() throw( css::uno::RuntimeException, std::exception ) override ;
-
-        virtual css::uno::Sequence< sal_Int8 > SAL_CALL getExtensionId() throw( css::uno::RuntimeException, std::exception ) override ;
-
-        virtual css::uno::Sequence< sal_Int8 > SAL_CALL getExtensionValue() throw( css::uno::RuntimeException, std::exception ) override ;
-
-        void setCertExtn( unsigned char* value, unsigned int vlen, unsigned char* id, unsigned int idlen, bool critical ) ;
-} ;
+        virtual sal_Bool SAL_CALL isCritical() throw( css::uno::RuntimeException, std::exception ) override
+        {
+            return m_Extn.m_critical;
+        }
+
+        virtual css::uno::Sequence< sal_Int8 > SAL_CALL getExtensionId() throw( css::uno::RuntimeException, std::exception ) override
+        {
+            return m_Extn.m_xExtnId;
+        }
+
+        virtual css::uno::Sequence< sal_Int8 > SAL_CALL getExtensionValue() throw( css::uno::RuntimeException, std::exception ) override
+        {
+            return m_Extn.m_xExtnValue;
+        }
+
+        void setCertExtn(unsigned char* value, unsigned int vlen, unsigned char* id, unsigned int idlen, bool critical)
+        {
+            m_Extn.setCertExtn(value, vlen, id, idlen, critical);
+        }
+};
 
 #endif // INCLUDED_XMLSECURITY_SOURCE_XMLSEC_CERTIFICATEEXTENSION_XMLSECIMPL_HXX
 
diff --git a/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.cxx
index b418758..a4ca2a6 100644
--- a/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.cxx
+++ b/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.cxx
@@ -38,29 +38,6 @@ using namespace ::com::sun::star::security ;
 
 using ::com::sun::star::security::XCertificateExtension ;
 
-
-SanExtensionImpl::SanExtensionImpl() :
-m_critical( false )
-{
-}
-
-SanExtensionImpl::~SanExtensionImpl() {
-}
-
-
-//Methods from XCertificateExtension
-sal_Bool SAL_CALL SanExtensionImpl::isCritical() throw( css::uno::RuntimeException, std::exception ) {
-    return m_critical ;
-}
-
-css::uno::Sequence< sal_Int8 > SAL_CALL SanExtensionImpl::getExtensionId() throw( css::uno::RuntimeException, std::exception ) {
-    return m_xExtnId ;
-}
-
-css::uno::Sequence< sal_Int8 > SAL_CALL SanExtensionImpl::getExtensionValue() throw( css::uno::RuntimeException, std::exception ) {
-    return m_xExtnValue ;
-}
-
 namespace {
     // Helper functions from nss/lib/certdb/genname.c
     int GetNamesLength(CERTGeneralName *names)
@@ -88,8 +65,8 @@ css::uno::Sequence< css::security::CertAltNameEntry > SAL_CALL SanExtensionImpl:
         SECItem item;
 
         item.type = siDERCertBuffer;
-        item.data = reinterpret_cast<unsigned char*>(m_xExtnValue.getArray());
-        item.len = m_xExtnValue.getLength();
+        item.data = reinterpret_cast<unsigned char*>(m_Extn.m_xExtnValue.getArray());
+        item.len = m_Extn.m_xExtnValue.getLength();
 
         PRArenaPool *arena;
         CERTGeneralName *nameList;
@@ -193,29 +170,4 @@ OString SanExtensionImpl::removeOIDFromString( const OString &oidString)
 
 }
 
-void SanExtensionImpl::setCertExtn( unsigned char* value, unsigned int vlen, unsigned char* id, unsigned int idlen, bool critical ) {
-    unsigned int i ;
-    if( value != nullptr && vlen != 0 ) {
-        Sequence< sal_Int8 > extnv( vlen ) ;
-        for( i = 0; i < vlen ; i ++ )
-            extnv[i] = *( value + i ) ;
-
-        m_xExtnValue = extnv ;
-    } else {
-        m_xExtnValue = Sequence<sal_Int8>();
-    }
-
-    if( id != nullptr && idlen != 0 ) {
-        Sequence< sal_Int8 > extnId( idlen ) ;
-        for( i = 0; i < idlen ; i ++ )
-            extnId[i] = *( id + i ) ;
-
-        m_xExtnId = extnId ;
-    } else {
-        m_xExtnId =  Sequence<sal_Int8>();
-    }
-
-    m_critical = critical ;
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.hxx b/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.hxx
index 53c6814..ca74018 100644
--- a/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.hxx
+++ b/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.hxx
@@ -29,30 +29,38 @@
 #include <com/sun/star/security/XCertificateExtension.hpp>
 #include <com/sun/star/security/XSanExtension.hpp>
 #include <com/sun/star/security/CertAltNameEntry.hpp>
+#include "certificateextension_certextn.hxx"
 
 class SanExtensionImpl : public ::cppu::WeakImplHelper<
     css::security::XSanExtension >
 {
     private:
-        bool m_critical ;
-        css::uno::Sequence< sal_Int8 > m_xExtnId ;
-        css::uno::Sequence< sal_Int8 > m_xExtnValue ;
+        CertificateExtension_CertExtn m_Extn;
         css::uno::Sequence< css::security::CertAltNameEntry > m_Entries;
 
         static OString removeOIDFromString( const OString &oid);
 
     public:
-        SanExtensionImpl() ;
-        virtual ~SanExtensionImpl() ;
-
         //Methods from XCertificateExtension
-        virtual sal_Bool SAL_CALL isCritical() throw( css::uno::RuntimeException, std::exception ) override ;
+        virtual sal_Bool SAL_CALL isCritical() throw( css::uno::RuntimeException, std::exception ) override
+        {
+            return m_Extn.m_critical;
+        }
 
-        virtual css::uno::Sequence< sal_Int8 > SAL_CALL getExtensionId() throw( css::uno::RuntimeException, std::exception ) override ;
+        virtual css::uno::Sequence< sal_Int8 > SAL_CALL getExtensionId() throw( css::uno::RuntimeException, std::exception ) override
+        {
+            return m_Extn.m_xExtnId;
+        }
 
-        virtual css::uno::Sequence< sal_Int8 > SAL_CALL getExtensionValue() throw( css::uno::RuntimeException, std::exception ) override ;
+        virtual css::uno::Sequence< sal_Int8 > SAL_CALL getExtensionValue() throw( css::uno::RuntimeException, std::exception ) override
+        {
+            return m_Extn.m_xExtnValue;
+        }
 
-        void setCertExtn( unsigned char* value, unsigned int vlen, unsigned char* id, unsigned int idlen, bool critical ) ;
+        void setCertExtn(unsigned char* value, unsigned int vlen, unsigned char* id, unsigned int idlen, bool critical)
+        {
+            m_Extn.setCertExtn(value, vlen, id, idlen, critical);
+        }
 
         //Methods from XSanExtension
 
commit b073ef93313f9e07f9f8b7bf65dc74721b15da6c
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Thu Jul 28 09:56:51 2016 +0100

    Related: tdf#95144 rework to avoid bad casts
    
    Change-Id: I89f84dae055b9a1058771021cb42dbc442405206

diff --git a/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.cxx
index 49ff9c7..b418758 100644
--- a/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.cxx
+++ b/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.cxx
@@ -193,4 +193,29 @@ OString SanExtensionImpl::removeOIDFromString( const OString &oidString)
 
 }
 
+void SanExtensionImpl::setCertExtn( unsigned char* value, unsigned int vlen, unsigned char* id, unsigned int idlen, bool critical ) {
+    unsigned int i ;
+    if( value != nullptr && vlen != 0 ) {
+        Sequence< sal_Int8 > extnv( vlen ) ;
+        for( i = 0; i < vlen ; i ++ )
+            extnv[i] = *( value + i ) ;
+
+        m_xExtnValue = extnv ;
+    } else {
+        m_xExtnValue = Sequence<sal_Int8>();
+    }
+
+    if( id != nullptr && idlen != 0 ) {
+        Sequence< sal_Int8 > extnId( idlen ) ;
+        for( i = 0; i < idlen ; i ++ )
+            extnId[i] = *( id + i ) ;
+
+        m_xExtnId = extnId ;
+    } else {
+        m_xExtnId =  Sequence<sal_Int8>();
+    }
+
+    m_critical = critical ;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.hxx b/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.hxx
index dfbe91f..53c6814 100644
--- a/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.hxx
+++ b/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.hxx
@@ -52,6 +52,8 @@ class SanExtensionImpl : public ::cppu::WeakImplHelper<
 
         virtual css::uno::Sequence< sal_Int8 > SAL_CALL getExtensionValue() throw( css::uno::RuntimeException, std::exception ) override ;
 
+        void setCertExtn( unsigned char* value, unsigned int vlen, unsigned char* id, unsigned int idlen, bool critical ) ;
+
         //Methods from XSanExtension
 
         virtual css::uno::Sequence< css::security::CertAltNameEntry > SAL_CALL getAlternativeNames() throw( css::uno::RuntimeException, std::exception ) override ;
diff --git a/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx
index 392d1b9..be930a2 100644
--- a/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx
+++ b/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx
@@ -28,6 +28,7 @@
 
 #include <sal/config.h>
 #include <comphelper/servicehelper.hxx>
+#include <rtl/ref.hxx>
 #include "x509certificate_nssimpl.hxx"
 
 #include "certificateextension_xmlsecimpl.hxx"
@@ -178,8 +179,6 @@ css::uno::Sequence< sal_Int8 > SAL_CALL X509Certificate_NssImpl::getSubjectUniqu
 css::uno::Sequence< css::uno::Reference< css::security::XCertificateExtension > > SAL_CALL X509Certificate_NssImpl::getExtensions() throw ( css::uno::RuntimeException, std::exception) {
     if( m_pCert != nullptr && m_pCert->extensions != nullptr ) {
         CERTCertExtension** extns ;
-        CertificateExtension_XmlSecImpl* pExtn ;
-        bool crit ;
         int len ;
 
         for( len = 0, extns = m_pCert->extensions; *extns != nullptr; len ++, extns ++ ) ;
@@ -189,6 +188,12 @@ css::uno::Sequence< css::uno::Reference< css::security::XCertificateExtension >
             const SECItem id = (*extns)->id;
             OString oidString(CERT_GetOidString(&id));
 
+            bool crit;
+            if( (*extns)->critical.data == nullptr )
+                crit = false ;
+            else
+                crit = (*extns)->critical.data[0] == 0xFF;
+
             // remove "OID." prefix if existing
             OString objID;
             OString oid("OID.");
@@ -197,18 +202,23 @@ css::uno::Sequence< css::uno::Reference< css::security::XCertificateExtension >
             else
                 objID = oidString;
 
-            if ( objID.equals("2.5.29.17") )
-                pExtn = reinterpret_cast<CertificateExtension_XmlSecImpl*>(new SanExtensionImpl());
-            else
-                pExtn = new CertificateExtension_XmlSecImpl() ;
+            unsigned char* value = (*extns)->value.data;
+            unsigned int vlen = (*extns)->value.len;
+            unsigned char* objid = reinterpret_cast<unsigned char *>(const_cast<char *>(objID.getStr()));
+            unsigned int objidlen = objID.getLength();
 
-            if( (*extns)->critical.data == nullptr )
-                crit = false ;
+            if (objID.equals("2.5.29.17"))
+            {
+                SanExtensionImpl* pExtn = new SanExtensionImpl();
+                pExtn->setCertExtn(value, vlen, objid, objidlen, crit);
+                xExtns[len] = pExtn ;
+            }
             else
-                crit = (*extns)->critical.data[0] == 0xFF;
-            pExtn->setCertExtn( (*extns)->value.data, (*extns)->value.len, reinterpret_cast<unsigned char *>(const_cast<char *>(objID.getStr())), objID.getLength(), crit ) ;
-
-            xExtns[len] = pExtn ;
+            {
+                CertificateExtension_XmlSecImpl* pExtn = new CertificateExtension_XmlSecImpl();
+                pExtn->setCertExtn(value, vlen, objid, objidlen, crit);
+                xExtns[len] = pExtn;
+            }
         }
 
         return xExtns ;
@@ -219,33 +229,48 @@ css::uno::Sequence< css::uno::Reference< css::security::XCertificateExtension >
 
 css::uno::Reference< css::security::XCertificateExtension > SAL_CALL X509Certificate_NssImpl::findCertificateExtension( const css::uno::Sequence< sal_Int8 >& oid ) throw (css::uno::RuntimeException, std::exception) {
     if( m_pCert != nullptr && m_pCert->extensions != nullptr ) {
-        CertificateExtension_XmlSecImpl* pExtn ;
         CERTCertExtension** extns ;
         SECItem idItem ;
-        bool crit ;
 
         idItem.data = reinterpret_cast<unsigned char *>(const_cast<sal_Int8 *>(oid.getConstArray()));
         idItem.len = oid.getLength() ;
 
-        pExtn = nullptr ;
+        css::uno::Reference<css::security::XCertificateExtension> xExtn;
         for( extns = m_pCert->extensions; *extns != nullptr; extns ++ ) {
             if( SECITEM_CompareItem( &idItem, &(*extns)->id ) == SECEqual ) {
                 const SECItem id = (*extns)->id;
                 OString objId(CERT_GetOidString(&id));
-                if ( objId.equals("OID.2.5.29.17") )
-                    pExtn = reinterpret_cast<CertificateExtension_XmlSecImpl*>(new SanExtensionImpl());
-                else
-                    pExtn = new CertificateExtension_XmlSecImpl() ;
+
+                bool crit;
                 if( (*extns)->critical.data == nullptr )
                     crit = false ;
                 else
                     crit = (*extns)->critical.data[0] == 0xFF;
-                pExtn->setCertExtn( (*extns)->value.data, (*extns)->value.len, (*extns)->id.data, (*extns)->id.len, crit ) ;
+
+                unsigned char* value = (*extns)->value.data;
+                unsigned int vlen = (*extns)->value.len;
+                unsigned char* objid = (*extns)->id.data;
+                unsigned int objidlen = (*extns)->id.len;
+
+                if ( objId.equals("OID.2.5.29.17") )
+                {
+                    rtl::Reference<SanExtensionImpl> xSanImpl(
+                        new SanExtensionImpl());
+                    xSanImpl->setCertExtn(value, vlen, objid, objidlen, crit);
+                    xExtn = xSanImpl.get();
+                }
+                else
+                {
+                    rtl::Reference<CertificateExtension_XmlSecImpl> xSecImpl(
+                        new CertificateExtension_XmlSecImpl());
+                    xSecImpl->setCertExtn(value, vlen, objid, objidlen, crit);
+                    xExtn = xSecImpl.get();
+                }
                 break;
             }
         }
 
-        return pExtn ;
+        return xExtn;
     } else {
         return nullptr ;
     }
commit 2c110872b530029f84d213ae7f27d3f59fdd0f97
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Thu Jul 28 09:36:24 2016 +0100

    Related: tdf#95144 Revert fixes for bad casts and unused fields
    
    Revert "Bad cast from SanExtensionImpl to CertificateExtension_XmlSecImpl"
    
    This reverts commit 321b8ff86ba623b92aab5608eb94385e56823b65.
    
    Revert "loplugin:singlevalfields in writerfilter and xmlsec"
    
    This reverts commit a25327e4b18768e40c6044c86ce09136cfc23c10.
    
    cause these two together mean that we get a certificate is
    invalid dialog when the cert is perfectly fine on loading https
    sources
    
    Change-Id: Id8c1fb5ece4ecc0035500ce0b822a6b248d14282

diff --git a/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.cxx
index f322842..49ff9c7 100644
--- a/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.cxx
+++ b/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.cxx
@@ -39,7 +39,9 @@ using namespace ::com::sun::star::security ;
 using ::com::sun::star::security::XCertificateExtension ;
 
 
-SanExtensionImpl::SanExtensionImpl() {
+SanExtensionImpl::SanExtensionImpl() :
+m_critical( false )
+{
 }
 
 SanExtensionImpl::~SanExtensionImpl() {
@@ -48,7 +50,7 @@ SanExtensionImpl::~SanExtensionImpl() {
 
 //Methods from XCertificateExtension
 sal_Bool SAL_CALL SanExtensionImpl::isCritical() throw( css::uno::RuntimeException, std::exception ) {
-    return false;
+    return m_critical ;
 }
 
 css::uno::Sequence< sal_Int8 > SAL_CALL SanExtensionImpl::getExtensionId() throw( css::uno::RuntimeException, std::exception ) {
diff --git a/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.hxx b/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.hxx
index ff6f87e..dfbe91f 100644
--- a/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.hxx
+++ b/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.hxx
@@ -34,6 +34,7 @@ class SanExtensionImpl : public ::cppu::WeakImplHelper<
     css::security::XSanExtension >
 {
     private:
+        bool m_critical ;
         css::uno::Sequence< sal_Int8 > m_xExtnId ;
         css::uno::Sequence< sal_Int8 > m_xExtnValue ;
         css::uno::Sequence< css::security::CertAltNameEntry > m_Entries;
diff --git a/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx
index 86f256b..392d1b9 100644
--- a/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx
+++ b/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx
@@ -28,7 +28,6 @@
 
 #include <sal/config.h>
 #include <comphelper/servicehelper.hxx>
-#include <rtl/ref.hxx>
 #include "x509certificate_nssimpl.hxx"
 
 #include "certificateextension_xmlsecimpl.hxx"
@@ -179,6 +178,8 @@ css::uno::Sequence< sal_Int8 > SAL_CALL X509Certificate_NssImpl::getSubjectUniqu
 css::uno::Sequence< css::uno::Reference< css::security::XCertificateExtension > > SAL_CALL X509Certificate_NssImpl::getExtensions() throw ( css::uno::RuntimeException, std::exception) {
     if( m_pCert != nullptr && m_pCert->extensions != nullptr ) {
         CERTCertExtension** extns ;
+        CertificateExtension_XmlSecImpl* pExtn ;
+        bool crit ;
         int len ;
 
         for( len = 0, extns = m_pCert->extensions; *extns != nullptr; len ++, extns ++ ) ;
@@ -197,21 +198,17 @@ css::uno::Sequence< css::uno::Reference< css::security::XCertificateExtension >
                 objID = oidString;
 
             if ( objID.equals("2.5.29.17") )
-                xExtns[len] = reinterpret_cast<CertificateExtension_XmlSecImpl*>(new SanExtensionImpl());
+                pExtn = reinterpret_cast<CertificateExtension_XmlSecImpl*>(new SanExtensionImpl());
             else
-            {
-                CertificateExtension_XmlSecImpl* pExtn
-                    = new CertificateExtension_XmlSecImpl() ;
+                pExtn = new CertificateExtension_XmlSecImpl() ;
 
-                bool crit ;
-                if( (*extns)->critical.data == nullptr )
-                    crit = false ;
-                else
-                    crit = (*extns)->critical.data[0] == 0xFF;
-                pExtn->setCertExtn( (*extns)->value.data, (*extns)->value.len, reinterpret_cast<unsigned char *>(const_cast<char *>(objID.getStr())), objID.getLength(), crit ) ;
+            if( (*extns)->critical.data == nullptr )
+                crit = false ;
+            else
+                crit = (*extns)->critical.data[0] == 0xFF;
+            pExtn->setCertExtn( (*extns)->value.data, (*extns)->value.len, reinterpret_cast<unsigned char *>(const_cast<char *>(objID.getStr())), objID.getLength(), crit ) ;
 
-                xExtns[len] = pExtn ;
-            }
+            xExtns[len] = pExtn ;
         }
 
         return xExtns ;
@@ -222,31 +219,28 @@ css::uno::Sequence< css::uno::Reference< css::security::XCertificateExtension >
 
 css::uno::Reference< css::security::XCertificateExtension > SAL_CALL X509Certificate_NssImpl::findCertificateExtension( const css::uno::Sequence< sal_Int8 >& oid ) throw (css::uno::RuntimeException, std::exception) {
     if( m_pCert != nullptr && m_pCert->extensions != nullptr ) {
+        CertificateExtension_XmlSecImpl* pExtn ;
         CERTCertExtension** extns ;
         SECItem idItem ;
+        bool crit ;
 
         idItem.data = reinterpret_cast<unsigned char *>(const_cast<sal_Int8 *>(oid.getConstArray()));
         idItem.len = oid.getLength() ;
 
-        css::uno::Reference<css::security::XCertificateExtension> pExtn;
+        pExtn = nullptr ;
         for( extns = m_pCert->extensions; *extns != nullptr; extns ++ ) {
             if( SECITEM_CompareItem( &idItem, &(*extns)->id ) == SECEqual ) {
                 const SECItem id = (*extns)->id;
                 OString objId(CERT_GetOidString(&id));
                 if ( objId.equals("OID.2.5.29.17") )
-                    pExtn = new SanExtensionImpl();
+                    pExtn = reinterpret_cast<CertificateExtension_XmlSecImpl*>(new SanExtensionImpl());
                 else
-                {
-                    rtl::Reference<CertificateExtension_XmlSecImpl> x(
-                        new CertificateExtension_XmlSecImpl());
-                    bool crit ;
-                    if( (*extns)->critical.data == nullptr )
-                        crit = false ;
-                    else
-                        crit = (*extns)->critical.data[0] == 0xFF;
-                    x->setCertExtn( (*extns)->value.data, (*extns)->value.len, (*extns)->id.data, (*extns)->id.len, crit ) ;
-                    pExtn = x.get();
-                }
+                    pExtn = new CertificateExtension_XmlSecImpl() ;
+                if( (*extns)->critical.data == nullptr )
+                    crit = false ;
+                else
+                    crit = (*extns)->critical.data[0] == 0xFF;
+                pExtn->setCertExtn( (*extns)->value.data, (*extns)->value.len, (*extns)->id.data, (*extns)->id.len, crit ) ;
                 break;
             }
         }


More information about the Libreoffice-commits mailing list