Related: tdf#95144 rework to avoid bad casts

Change-Id: I89f84dae055b9a1058771021cb42dbc442405206
This commit is contained in:
Caolán McNamara 2016-07-28 09:56:51 +01:00
parent 2c110872b5
commit b073ef9331
3 changed files with 73 additions and 21 deletions

View File

@ -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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -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 ; 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 //Methods from XSanExtension
virtual css::uno::Sequence< css::security::CertAltNameEntry > SAL_CALL getAlternativeNames() throw( css::uno::RuntimeException, std::exception ) override ; virtual css::uno::Sequence< css::security::CertAltNameEntry > SAL_CALL getAlternativeNames() throw( css::uno::RuntimeException, std::exception ) override ;

View File

@ -28,6 +28,7 @@
#include <sal/config.h> #include <sal/config.h>
#include <comphelper/servicehelper.hxx> #include <comphelper/servicehelper.hxx>
#include <rtl/ref.hxx>
#include "x509certificate_nssimpl.hxx" #include "x509certificate_nssimpl.hxx"
#include "certificateextension_xmlsecimpl.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) { 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 ) { if( m_pCert != nullptr && m_pCert->extensions != nullptr ) {
CERTCertExtension** extns ; CERTCertExtension** extns ;
CertificateExtension_XmlSecImpl* pExtn ;
bool crit ;
int len ; int len ;
for( len = 0, extns = m_pCert->extensions; *extns != nullptr; len ++, extns ++ ) ; 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; const SECItem id = (*extns)->id;
OString oidString(CERT_GetOidString(&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 // remove "OID." prefix if existing
OString objID; OString objID;
OString oid("OID."); OString oid("OID.");
@ -197,18 +202,23 @@ css::uno::Sequence< css::uno::Reference< css::security::XCertificateExtension >
else else
objID = oidString; objID = oidString;
if ( objID.equals("2.5.29.17") ) unsigned char* value = (*extns)->value.data;
pExtn = reinterpret_cast<CertificateExtension_XmlSecImpl*>(new SanExtensionImpl()); unsigned int vlen = (*extns)->value.len;
else unsigned char* objid = reinterpret_cast<unsigned char *>(const_cast<char *>(objID.getStr()));
pExtn = new CertificateExtension_XmlSecImpl() ; unsigned int objidlen = objID.getLength();
if( (*extns)->critical.data == nullptr ) if (objID.equals("2.5.29.17"))
crit = false ; {
SanExtensionImpl* pExtn = new SanExtensionImpl();
pExtn->setCertExtn(value, vlen, objid, objidlen, crit);
xExtns[len] = pExtn ;
}
else 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 ) ; CertificateExtension_XmlSecImpl* pExtn = new CertificateExtension_XmlSecImpl();
pExtn->setCertExtn(value, vlen, objid, objidlen, crit);
xExtns[len] = pExtn ; xExtns[len] = pExtn;
}
} }
return xExtns ; 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) { 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 ) { if( m_pCert != nullptr && m_pCert->extensions != nullptr ) {
CertificateExtension_XmlSecImpl* pExtn ;
CERTCertExtension** extns ; CERTCertExtension** extns ;
SECItem idItem ; SECItem idItem ;
bool crit ;
idItem.data = reinterpret_cast<unsigned char *>(const_cast<sal_Int8 *>(oid.getConstArray())); idItem.data = reinterpret_cast<unsigned char *>(const_cast<sal_Int8 *>(oid.getConstArray()));
idItem.len = oid.getLength() ; idItem.len = oid.getLength() ;
pExtn = nullptr ; css::uno::Reference<css::security::XCertificateExtension> xExtn;
for( extns = m_pCert->extensions; *extns != nullptr; extns ++ ) { for( extns = m_pCert->extensions; *extns != nullptr; extns ++ ) {
if( SECITEM_CompareItem( &idItem, &(*extns)->id ) == SECEqual ) { if( SECITEM_CompareItem( &idItem, &(*extns)->id ) == SECEqual ) {
const SECItem id = (*extns)->id; const SECItem id = (*extns)->id;
OString objId(CERT_GetOidString(&id)); OString objId(CERT_GetOidString(&id));
if ( objId.equals("OID.2.5.29.17") )
pExtn = reinterpret_cast<CertificateExtension_XmlSecImpl*>(new SanExtensionImpl()); bool crit;
else
pExtn = new CertificateExtension_XmlSecImpl() ;
if( (*extns)->critical.data == nullptr ) if( (*extns)->critical.data == nullptr )
crit = false ; crit = false ;
else else
crit = (*extns)->critical.data[0] == 0xFF; 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; break;
} }
} }
return pExtn ; return xExtn;
} else { } else {
return nullptr ; return nullptr ;
} }