Kaydet (Commit) 42460fd4 authored tarafından Miklos Vajna's avatar Miklos Vajna

xmlsecurity: avoid using the SerialNumberAdapter wrapper

This service is only used in xmlsecurity and it's a wrapper around two
free functions in the same module.

Change-Id: Ibc5a026b51eda6c2b4b27b7254dedc220dbf909a
Reviewed-on: https://gerrit.libreoffice.org/34772Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarJenkins <ci@libreoffice.org>
üst 6af6a5fa
......@@ -211,7 +211,8 @@ const char* keywordToString(RTFKeyword nKeyword)
static util::DateTime lcl_getDateTime(RTFParserState& aState)
{
return {0 /*100sec*/, 0 /*sec*/, aState.nMinute, aState.nHour,
aState.nDay, aState.nMonth, aState.nYear, false};
aState.nDay, aState.nMonth, aState.nYear, false
};
}
static void lcl_DestinationToMath(OUStringBuffer* pDestinationText, oox::formulaimport::XmlStreamBuilder& rMathBuffer, bool& rMathNor)
......
......@@ -25,8 +25,13 @@
#include <com/sun/star/uno/Sequence.h>
OUString bigIntegerToNumericString( const css::uno::Sequence< sal_Int8 >& serial );
css::uno::Sequence< sal_Int8 > numericStringToBigInteger ( const OUString& serialNumber );
#include <xsecxmlsecdllapi.h>
namespace xmlsecurity
{
XSECXMLSEC_DLLPUBLIC OUString bigIntegerToNumericString( const css::uno::Sequence< sal_Int8 >& serial );
XSECXMLSEC_DLLPUBLIC css::uno::Sequence< sal_Int8 > numericStringToBigInteger ( const OUString& serialNumber );
}
#endif
......
......@@ -22,7 +22,6 @@
#include <com/sun/star/embed/XTransactedObject.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/frame/XStorable.hpp>
#include <com/sun/star/security/SerialNumberAdapter.hpp>
#include <com/sun/star/xml/crypto/SEInitializer.hpp>
#include <com/sun/star/io/TempFile.hpp>
#include <com/sun/star/packages/manifest/ManifestReader.hpp>
......
......@@ -42,7 +42,6 @@
#include <vcl/layout.hxx>
#include <unotools/securityoptions.hxx>
#include <com/sun/star/security/CertificateValidity.hpp>
#include <com/sun/star/security/SerialNumberAdapter.hpp>
#include <comphelper/documentconstants.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
......@@ -316,9 +315,6 @@ DocumentDigitalSignatures::ImplVerifySignatures(
if ( nInfos )
{
Reference<security::XSerialNumberAdapter> xSerialNumberAdapter =
css::security::SerialNumberAdapter::create(mxCtx);
for( int n = 0; n < nInfos; ++n )
{
DocumentSignatureAlgorithm mode = DocumentSignatureHelper::getDocumentAlgorithm(
......@@ -333,7 +329,7 @@ DocumentDigitalSignatures::ImplVerifySignatures(
if (!rInfo.ouX509Certificate.isEmpty())
rSigInfo.Signer = xSecEnv->createCertificateFromAscii( rInfo.ouX509Certificate ) ;
if (!rSigInfo.Signer.is())
rSigInfo.Signer = xSecEnv->getCertificate( rInfo.ouX509IssuerName, xSerialNumberAdapter->toSequence( rInfo.ouX509SerialNumber ) );
rSigInfo.Signer = xSecEnv->getCertificate( rInfo.ouX509IssuerName, xmlsecurity::numericStringToBigInteger( rInfo.ouX509SerialNumber ) );
// Time support again (#i38744#)
Date aDate( rInfo.stDateTime.Day, rInfo.stDateTime.Month, rInfo.stDateTime.Year );
......@@ -431,10 +427,7 @@ sal_Bool DocumentDigitalSignatures::isAuthorTrusted(
{
bool bFound = false;
Reference<security::XSerialNumberAdapter> xSerialNumberAdapter =
css::security::SerialNumberAdapter::create(mxCtx);
OUString sSerialNum = xSerialNumberAdapter->toString( Author->getSerialNumber() );
OUString sSerialNum = xmlsecurity::bigIntegerToNumericString( Author->getSerialNumber() );
Sequence< SvtSecurityOptions::Certificate > aTrustedAuthors = SvtSecurityOptions().GetTrustedAuthors();
const SvtSecurityOptions::Certificate* pAuthors = aTrustedAuthors.getConstArray();
......@@ -486,12 +479,9 @@ void DocumentDigitalSignatures::addAuthorToTrustedSources(
{
SvtSecurityOptions aSecOpts;
Reference<security::XSerialNumberAdapter> xSerialNumberAdapter =
css::security::SerialNumberAdapter::create(mxCtx);
SvtSecurityOptions::Certificate aNewCert( 3 );
aNewCert[ 0 ] = Author->getIssuerName();
aNewCert[ 1 ] = xSerialNumberAdapter->toString( Author->getSerialNumber() );
aNewCert[ 1 ] = xmlsecurity::bigIntegerToNumericString( Author->getSerialNumber() );
OUStringBuffer aStrBuffer;
::sax::Converter::encodeBase64(aStrBuffer, Author->getEncoded());
......
......@@ -27,7 +27,6 @@
#include <com/sun/star/security/NoPasswordException.hpp>
#include <com/sun/star/security/CertificateCharacters.hpp>
#include <com/sun/star/security/SerialNumberAdapter.hpp>
#include "resourcemanager.hxx"
#include <vcl/msgbox.hxx>
......@@ -168,9 +167,6 @@ void CertificateChooser::ImplInitialize()
{
}
uno::Reference< css::security::XSerialNumberAdapter> xSerialNumberAdapter =
css::security::SerialNumberAdapter::create(mxCtx);
sal_Int32 nCertificates = maCerts.getLength();
for( sal_Int32 nCert = nCertificates; nCert; )
{
......
......@@ -32,7 +32,6 @@
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/security/CertificateValidity.hpp>
#include <com/sun/star/packages/WrongPasswordException.hpp>
#include <com/sun/star/security/SerialNumberAdapter.hpp>
#include <com/sun/star/security/XDocumentDigitalSignatures.hpp>
#include <com/sun/star/xml/dom/XDocumentBuilder.hpp>
#include <com/sun/star/packages/manifest/ManifestReader.hpp>
......@@ -458,8 +457,6 @@ void DigitalSignaturesDialog::ImplFillSignaturesBox()
m_pSignaturesLB->Clear();
uno::Reference<xml::crypto::XSecurityEnvironment> xSecEnv = maSignatureManager.getSecurityEnvironment();
uno::Reference<css::security::XSerialNumberAdapter> xSerialNumberAdapter =
css::security::SerialNumberAdapter::create(mxCtx);
uno::Reference< css::security::XCertificate > xCert;
......@@ -494,7 +491,7 @@ void DigitalSignaturesDialog::ImplFillSignaturesBox()
//In case there is no embedded certificate we try to get it from a local store
//Todo: This probably could be removed, see above.
if (!xCert.is())
xCert = xSecEnv->getCertificate( rInfo.ouX509IssuerName, xSerialNumberAdapter->toSequence( rInfo.ouX509SerialNumber ) );
xCert = xSecEnv->getCertificate( rInfo.ouX509IssuerName, xmlsecurity::numericStringToBigInteger( rInfo.ouX509SerialNumber ) );
SAL_WARN_IF( !xCert.is(), "xmlsecurity.dialogs", "Certificate not found and can't be created!" );
......@@ -639,15 +636,13 @@ void DigitalSignaturesDialog::ImplShowSignaturesDetails()
sal_uInt16 nSelected = (sal_uInt16) reinterpret_cast<sal_uIntPtr>( m_pSignaturesLB->FirstSelected()->GetUserData() );
const SignatureInformation& rInfo = maSignatureManager.maCurrentSignatureInformations[ nSelected ];
uno::Reference<xml::crypto::XSecurityEnvironment> xSecEnv = maSignatureManager.getSecurityEnvironment();
css::uno::Reference<com::sun::star::security::XSerialNumberAdapter> xSerialNumberAdapter =
css::security::SerialNumberAdapter::create(mxCtx);
// Use Certificate from doc, not from key store
uno::Reference< css::security::XCertificate > xCert;
if (!rInfo.ouX509Certificate.isEmpty())
xCert = xSecEnv->createCertificateFromAscii(rInfo.ouX509Certificate);
//fallback if no certificate is embedded, get if from store
if (!xCert.is())
xCert = xSecEnv->getCertificate( rInfo.ouX509IssuerName, xSerialNumberAdapter->toSequence( rInfo.ouX509SerialNumber ) );
xCert = xSecEnv->getCertificate( rInfo.ouX509IssuerName, xmlsecurity::numericStringToBigInteger( rInfo.ouX509SerialNumber ) );
SAL_WARN_IF( !xCert.is(), "xmlsecurity.dialogs", "Error getting Certificate!" );
if ( xCert.is() )
......
......@@ -29,7 +29,6 @@
#include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp>
#include <com/sun/star/security/SerialNumberAdapter.hpp>
#include <comphelper/sequence.hxx>
#include <sfx2/filedlghelper.hxx>
#include <comphelper/processfactory.hxx>
......@@ -221,10 +220,7 @@ IMPL_LINK_NOARG(MacroSecurityTrustedSourcesTP, ViewCertPBHdl, Button*, void)
{
sal_uInt16 nSelected = sal_uInt16( sal_uIntPtr( m_pTrustCertLB->FirstSelected()->GetUserData() ) );
uno::Reference< css::security::XSerialNumberAdapter > xSerialNumberAdapter =
css::security::SerialNumberAdapter::create(mpDlg->mxCtx);
uno::Reference< css::security::XCertificate > xCert = mpDlg->mxSecurityEnvironment->getCertificate( maTrustedAuthors[nSelected][0], xSerialNumberAdapter->toSequence( maTrustedAuthors[nSelected][1] ) );
uno::Reference< css::security::XCertificate > xCert = mpDlg->mxSecurityEnvironment->getCertificate( maTrustedAuthors[nSelected][0], xmlsecurity::numericStringToBigInteger( maTrustedAuthors[nSelected][1] ) );
// If we don't get it, create it from signature data:
if ( !xCert.is() )
......
......@@ -23,7 +23,6 @@
#include <com/sun/star/embed/ElementModes.hpp>
#include <com/sun/star/io/TempFile.hpp>
#include <com/sun/star/io/XTruncate.hpp>
#include <com/sun/star/security/SerialNumberAdapter.hpp>
#include <com/sun/star/embed/XTransactedObject.hpp>
#include <com/sun/star/xml/crypto/SEInitializer.hpp>
......@@ -35,6 +34,7 @@
#include <o3tl/make_unique.hxx>
#include <certificate.hxx>
#include <biginteger.hxx>
using namespace com::sun::star;
......@@ -239,8 +239,7 @@ bool DocumentSignatureManager::add(const uno::Reference<security::XCertificate>&
return false;
}
uno::Reference<security::XSerialNumberAdapter> xSerialNumberAdapter = security::SerialNumberAdapter::create(mxContext);
OUString aCertSerial = xSerialNumberAdapter->toString(xCert->getSerialNumber());
OUString aCertSerial = xmlsecurity::bigIntegerToNumericString(xCert->getSerialNumber());
if (aCertSerial.isEmpty())
{
SAL_WARN("xmlsecurity.helper", "Error in Certificate, problem with serial number!");
......
......@@ -25,6 +25,8 @@
using namespace ::com::sun::star::uno ;
namespace xmlsecurity
{
Sequence< sal_Int8 > numericStringToBigInteger ( const OUString& numeral )
{
if( numeral.getStr() != nullptr )
......@@ -106,5 +108,6 @@ OUString bigIntegerToNumericString ( const Sequence< sal_Int8 >& integer )
return aRet ;
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -618,7 +618,7 @@ Reference< XCertificate > SecurityEnvironment_MSCryptImpl::getCertificate( const
}
Reference< XCertificate > SecurityEnvironment_MSCryptImpl::getCertificate( const OUString& issuerName, const OUString& serialNumber ) {
Sequence< sal_Int8 > serial = numericStringToBigInteger( serialNumber ) ;
Sequence< sal_Int8 > serial = xmlsecurity::numericStringToBigInteger( serialNumber ) ;
return getCertificate( issuerName, serial ) ;
}
......
......@@ -60,11 +60,11 @@ private:
virtual OUString SAL_CALL toString(
css::uno::Sequence< sal_Int8 > const & SerialNumber) override
{ return bigIntegerToNumericString(SerialNumber); }
{ return xmlsecurity::bigIntegerToNumericString(SerialNumber); }
virtual css::uno::Sequence< sal_Int8 > SAL_CALL toSequence(
OUString const & SerialNumber) override
{ return numericStringToBigInteger(SerialNumber); }
{ return xmlsecurity::numericStringToBigInteger(SerialNumber); }
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment