LCOV - code coverage report
Current view: top level - xmlsecurity/source/component - documentdigitalsignatures.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 39 199 19.6 %
Date: 2015-06-13 12:38:46 Functions: 11 32 34.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "documentdigitalsignatures.hxx"
      21             : #include <xmlsecurity/digitalsignaturesdialog.hxx>
      22             : #include <xmlsecurity/certificatechooser.hxx>
      23             : #include <xmlsecurity/certificateviewer.hxx>
      24             : #include <xmlsecurity/macrosecurity.hxx>
      25             : #include <xmlsecurity/biginteger.hxx>
      26             : #include <xmlsecurity/global.hrc>
      27             : 
      28             : #include <sax/tools/converter.hxx>
      29             : 
      30             : #include <../dialogs/resourcemanager.hxx>
      31             : #include <com/sun/star/embed/XStorage.hpp>
      32             : #include <com/sun/star/embed/XTransactedObject.hpp>
      33             : #include <com/sun/star/embed/ElementModes.hpp>
      34             : #include <com/sun/star/ucb/XContent.hpp>
      35             : #include <com/sun/star/ucb/XContentIdentifierFactory.hpp>
      36             : #include <com/sun/star/ucb/XCommandEnvironment.hpp>
      37             : #include <com/sun/star/ucb/XCommandProcessor.hpp>
      38             : #include <com/sun/star/ucb/Command.hpp>
      39             : #include <vcl/layout.hxx>
      40             : #include <unotools/securityoptions.hxx>
      41             : #include <com/sun/star/security/CertificateValidity.hpp>
      42             : #include <com/sun/star/security/SerialNumberAdapter.hpp>
      43             : #include <comphelper/documentconstants.hxx>
      44             : #include <cppuhelper/supportsservice.hxx>
      45             : #include <com/sun/star/lang/IllegalArgumentException.hpp>
      46             : 
      47             : using namespace css;
      48             : using namespace css::uno;
      49             : 
      50         215 : DocumentDigitalSignatures::DocumentDigitalSignatures( const Reference< XComponentContext >& rxCtx ):
      51             :     mxCtx(rxCtx),
      52             :     m_sODFVersion(ODFVER_012_TEXT),
      53             :     m_nArgumentsCount(0),
      54         215 :     m_bHasDocumentSignature(false)
      55             : {
      56         215 : }
      57             : 
      58         215 : void DocumentDigitalSignatures::initialize( const Sequence< Any >& aArguments)
      59             :         throw (css::uno::Exception, css::uno::RuntimeException, std::exception)
      60             : {
      61         215 :     if (aArguments.getLength() > 2)
      62             :         throw css::lang::IllegalArgumentException(
      63             :           "DocumentDigitalSignatures::initialize requires zero, one, or two arguments",
      64           0 :           static_cast<XInitialization*>(this), 0);
      65             : 
      66         215 :     m_nArgumentsCount = aArguments.getLength();
      67             : 
      68         215 :     if (aArguments.getLength() > 0)
      69             :     {
      70         214 :         if (!(aArguments[0] >>= m_sODFVersion))
      71             :             throw css::lang::IllegalArgumentException(
      72             :                 "DocumentDigitalSignatures::initialize: the first arguments must be a string",
      73           0 :                 static_cast<XInitialization*>(this), 0);
      74             : 
      75         428 :         if (aArguments.getLength() == 2
      76         214 :             && !(aArguments[1] >>= m_bHasDocumentSignature))
      77             :             throw css::lang::IllegalArgumentException(
      78             :                 "DocumentDigitalSignatures::initialize: the second arguments must be a bool",
      79           0 :                 static_cast<XInitialization*>(this), 1);
      80             : 
      81             :         //the Version is supported as of ODF1.2, so for and 1.1 document or older we will receive the
      82             :         //an empty string. In this case we set it to ODFVER_010_TEXT. Then we can later check easily
      83             :         //if initialize was called. Only then m_sODFVersion.getLength() is greater than 0
      84         214 :         if (m_sODFVersion.isEmpty())
      85           7 :             m_sODFVersion = ODFVER_010_TEXT;
      86             :     }
      87         215 : }
      88             : 
      89           1 : OUString DocumentDigitalSignatures::getImplementationName()
      90             :     throw (css::uno::RuntimeException, std::exception)
      91             : {
      92           1 :     return GetImplementationName();
      93             : }
      94             : 
      95           0 : sal_Bool DocumentDigitalSignatures::supportsService(
      96             :     OUString const & ServiceName)
      97             :     throw (css::uno::RuntimeException, std::exception)
      98             : {
      99           0 :     return cppu::supportsService(this, ServiceName);
     100             : }
     101             : 
     102             : css::uno::Sequence<OUString>
     103           1 : DocumentDigitalSignatures::getSupportedServiceNames()
     104             :     throw (css::uno::RuntimeException, std::exception)
     105             : {
     106           1 :     return GetSupportedServiceNames();
     107             : }
     108             : 
     109           0 : sal_Bool DocumentDigitalSignatures::signDocumentContent(
     110             :     const Reference< css::embed::XStorage >& rxStorage,
     111             :     const Reference< css::io::XStream >& xSignStream)
     112             :         throw (RuntimeException, std::exception)
     113             : {
     114             :     OSL_ENSURE(!m_sODFVersion.isEmpty(), "DocumentDigitalSignatures: ODF Version not set, assuming minimum 1.2");
     115           0 :     return ImplViewSignatures( rxStorage, xSignStream, SignatureModeDocumentContent, false );
     116             : }
     117             : 
     118             : Sequence< css::security::DocumentSignatureInformation >
     119         214 : DocumentDigitalSignatures::verifyDocumentContentSignatures(
     120             :     const Reference< css::embed::XStorage >& rxStorage,
     121             :     const Reference< css::io::XInputStream >& xSignInStream ) throw (RuntimeException, std::exception)
     122             : {
     123             :     OSL_ENSURE(!m_sODFVersion.isEmpty(),"DocumentDigitalSignatures: ODF Version not set, assuming minimum 1.2");
     124         214 :     return ImplVerifySignatures( rxStorage, xSignInStream, SignatureModeDocumentContent );
     125             : }
     126             : 
     127           0 : void DocumentDigitalSignatures::showDocumentContentSignatures(
     128             :     const Reference< css::embed::XStorage >& rxStorage,
     129             :     const Reference< css::io::XInputStream >& xSignInStream ) throw (RuntimeException, std::exception)
     130             : {
     131             :     OSL_ENSURE(!m_sODFVersion.isEmpty(),"DocumentDigitalSignatures: ODF Version not set, assuming minimum 1.2");
     132           0 :     ImplViewSignatures( rxStorage, xSignInStream, SignatureModeDocumentContent, true );
     133           0 : }
     134             : 
     135           0 : OUString DocumentDigitalSignatures::getDocumentContentSignatureDefaultStreamName()
     136             :     throw (css::uno::RuntimeException, std::exception)
     137             : {
     138           0 :     return DocumentSignatureHelper::GetDocumentContentSignatureDefaultStreamName();
     139             : }
     140             : 
     141           0 : sal_Bool DocumentDigitalSignatures::signScriptingContent(
     142             :     const Reference< css::embed::XStorage >& rxStorage,
     143             :     const Reference< css::io::XStream >& xSignStream ) throw (RuntimeException, std::exception)
     144             : {
     145             :     OSL_ENSURE(!m_sODFVersion.isEmpty(),"DocumentDigitalSignatures: ODF Version not set, assuming minimum 1.2");
     146             :     OSL_ENSURE(m_nArgumentsCount == 2, "DocumentDigitalSignatures: Service was not initialized properly");
     147           0 :     return ImplViewSignatures( rxStorage, xSignStream, SignatureModeMacros, false );
     148             : }
     149             : 
     150             : Sequence< css::security::DocumentSignatureInformation >
     151           0 : DocumentDigitalSignatures::verifyScriptingContentSignatures(
     152             :     const Reference< css::embed::XStorage >& rxStorage,
     153             :     const Reference< css::io::XInputStream >& xSignInStream ) throw (RuntimeException, std::exception)
     154             : {
     155             :     OSL_ENSURE(!m_sODFVersion.isEmpty(),"DocumentDigitalSignatures: ODF Version not set, assuming minimum 1.2");
     156           0 :     return ImplVerifySignatures( rxStorage, xSignInStream, SignatureModeMacros );
     157             : }
     158             : 
     159           0 : void DocumentDigitalSignatures::showScriptingContentSignatures(
     160             :     const Reference< css::embed::XStorage >& rxStorage,
     161             :     const Reference< css::io::XInputStream >& xSignInStream ) throw (RuntimeException, std::exception)
     162             : {
     163             :     OSL_ENSURE(!m_sODFVersion.isEmpty(),"DocumentDigitalSignatures: ODF Version not set, assuming minimum 1.2");
     164           0 :     ImplViewSignatures( rxStorage, xSignInStream, SignatureModeMacros, true );
     165           0 : }
     166             : 
     167           0 : OUString DocumentDigitalSignatures::getScriptingContentSignatureDefaultStreamName()
     168             :     throw (css::uno::RuntimeException, std::exception)
     169             : {
     170           0 :     return DocumentSignatureHelper::GetScriptingContentSignatureDefaultStreamName();
     171             : }
     172             : 
     173             : 
     174           0 : sal_Bool DocumentDigitalSignatures::signPackage(
     175             :     const Reference< css::embed::XStorage >& rxStorage,
     176             :     const Reference< css::io::XStream >& xSignStream  ) throw (RuntimeException, std::exception)
     177             : {
     178             :     OSL_ENSURE(!m_sODFVersion.isEmpty(),"DocumentDigitalSignatures: ODF Version not set, assuming minimum 1.2");
     179           0 :     return ImplViewSignatures( rxStorage, xSignStream, SignatureModePackage, false );
     180             : }
     181             : 
     182             : Sequence< css::security::DocumentSignatureInformation >
     183           0 : DocumentDigitalSignatures::verifyPackageSignatures(
     184             :     const Reference< css::embed::XStorage >& rxStorage,
     185             :     const Reference< css::io::XInputStream >& xSignInStream ) throw (RuntimeException, std::exception)
     186             : {
     187             :     OSL_ENSURE(!m_sODFVersion.isEmpty(),"DocumentDigitalSignatures: ODF Version not set, assuming minimum 1.2");
     188           0 :     return ImplVerifySignatures( rxStorage, xSignInStream, SignatureModePackage );
     189             : }
     190             : 
     191           0 : void DocumentDigitalSignatures::showPackageSignatures(
     192             :     const Reference< css::embed::XStorage >& rxStorage,
     193             :     const Reference< css::io::XInputStream >& xSignInStream ) throw (RuntimeException, std::exception)
     194             : {
     195             :     OSL_ENSURE(!m_sODFVersion.isEmpty(),"DocumentDigitalSignatures: ODF Version not set, assuming minimum 1.2");
     196           0 :     ImplViewSignatures( rxStorage, xSignInStream, SignatureModePackage, true );
     197           0 : }
     198             : 
     199           0 : OUString DocumentDigitalSignatures::getPackageSignatureDefaultStreamName(  )
     200             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     201             : {
     202           0 :     return DocumentSignatureHelper::GetPackageSignatureDefaultStreamName();
     203             : }
     204             : 
     205             : 
     206           0 : bool DocumentDigitalSignatures::ImplViewSignatures(
     207             :     const Reference< css::embed::XStorage >& rxStorage,
     208             :     const Reference< css::io::XInputStream >& xSignStream,
     209             :     DocumentSignatureMode eMode, bool bReadOnly ) throw (RuntimeException, std::exception)
     210             : {
     211           0 :     Reference< io::XStream > xStream;
     212           0 :     if ( xSignStream.is() )
     213           0 :         xStream = Reference< io::XStream >( xSignStream, UNO_QUERY );
     214           0 :     return ImplViewSignatures( rxStorage, xStream, eMode, bReadOnly );
     215             : }
     216             : 
     217           0 : bool DocumentDigitalSignatures::ImplViewSignatures(
     218             :     const Reference< css::embed::XStorage >& rxStorage, const Reference< css::io::XStream >& xSignStream,
     219             :     DocumentSignatureMode eMode, bool bReadOnly ) throw (RuntimeException, std::exception)
     220             : {
     221           0 :     bool bChanges = false;
     222             :     ScopedVclPtrInstance<DigitalSignaturesDialog> aSignaturesDialog(
     223             :         nullptr, mxCtx, eMode, bReadOnly, m_sODFVersion,
     224           0 :         m_bHasDocumentSignature);
     225           0 :     bool bInit = aSignaturesDialog->Init();
     226             :     DBG_ASSERT( bInit, "Error initializing security context!" );
     227           0 :     if ( bInit )
     228             :     {
     229           0 :         aSignaturesDialog->SetStorage( rxStorage );
     230           0 :         aSignaturesDialog->SetSignatureStream( xSignStream );
     231           0 :         if ( aSignaturesDialog->Execute() )
     232             :         {
     233           0 :             if ( aSignaturesDialog->SignaturesChanged() )
     234             :             {
     235           0 :                 bChanges = true;
     236             :                 // If we have a storage and no stream, we are responsible for commit
     237           0 :                 if ( rxStorage.is() && !xSignStream.is() )
     238             :                 {
     239           0 :                     uno::Reference< embed::XTransactedObject > xTrans( rxStorage, uno::UNO_QUERY );
     240           0 :                     xTrans->commit();
     241             :                 }
     242             :             }
     243             :         }
     244             :     }
     245             :     else
     246             :     {
     247           0 :         ScopedVclPtrInstance< MessageDialog > aBox(nullptr, XMLSEC_RES(RID_XMLSECWB_NO_MOZILLA_PROFILE), VCL_MESSAGE_WARNING);
     248           0 :         aBox->Execute();
     249             :     }
     250             : 
     251           0 :     return bChanges;
     252             : }
     253             : 
     254             : Sequence< css::security::DocumentSignatureInformation >
     255         214 : DocumentDigitalSignatures::ImplVerifySignatures(
     256             :     const Reference< css::embed::XStorage >& rxStorage,
     257             :     const Reference< css::io::XInputStream >& xSignStream, DocumentSignatureMode eMode ) throw (RuntimeException)
     258             : {
     259         214 :     if (!rxStorage.is())
     260             :     {
     261             :         DBG_ASSERT(false, "Error, no XStorage provided");
     262           0 :         return Sequence<css::security::DocumentSignatureInformation>();
     263             :     }
     264             :     // First check for the InputStream, to avoid unnecessary initialization of the security environemnt...
     265         214 :     SignatureStreamHelper aStreamHelper;
     266         428 :     Reference< io::XInputStream > xInputStream = xSignStream;
     267             : 
     268         214 :     if ( !xInputStream.is() )
     269             :     {
     270         214 :         aStreamHelper = DocumentSignatureHelper::OpenSignatureStream( rxStorage, embed::ElementModes::READ, eMode );
     271         214 :         if ( aStreamHelper.xSignatureStream.is() )
     272           0 :             xInputStream = Reference< io::XInputStream >( aStreamHelper.xSignatureStream, UNO_QUERY );
     273             :     }
     274             : 
     275         214 :     if ( !xInputStream.is() )
     276         214 :         return Sequence< ::com::sun::star::security::DocumentSignatureInformation >(0);
     277             : 
     278             : 
     279           0 :     XMLSignatureHelper aSignatureHelper( mxCtx );
     280             : 
     281           0 :     bool bInit = aSignatureHelper.Init();
     282             : 
     283             :     DBG_ASSERT( bInit, "Error initializing security context!" );
     284             : 
     285           0 :     if ( !bInit )
     286           0 :         return Sequence< ::com::sun::star::security::DocumentSignatureInformation >(0);
     287             : 
     288           0 :     aSignatureHelper.SetStorage(rxStorage, m_sODFVersion);
     289             : 
     290           0 :     aSignatureHelper.StartMission();
     291             : 
     292           0 :     aSignatureHelper.ReadAndVerifySignature( xInputStream );
     293             : 
     294           0 :     aSignatureHelper.EndMission();
     295             : 
     296           0 :     Reference< ::com::sun::star::xml::crypto::XSecurityEnvironment > xSecEnv = aSignatureHelper.GetSecurityEnvironment();
     297             : 
     298           0 :     SignatureInformations aSignInfos = aSignatureHelper.GetSignatureInformations();
     299           0 :     int nInfos = aSignInfos.size();
     300           0 :     Sequence< css::security::DocumentSignatureInformation > aInfos(nInfos);
     301           0 :     css::security::DocumentSignatureInformation* arInfos = aInfos.getArray();
     302             : 
     303           0 :     if ( nInfos )
     304             :     {
     305             :        Reference<security::XSerialNumberAdapter> xSerialNumberAdapter =
     306           0 :             ::com::sun::star::security::SerialNumberAdapter::create(mxCtx);
     307             : 
     308           0 :         for( int n = 0; n < nInfos; ++n )
     309             :         {
     310             :             DocumentSignatureAlgorithm mode = DocumentSignatureHelper::getDocumentAlgorithm(
     311           0 :                 m_sODFVersion, aSignInfos[n]);
     312             :             const std::vector< OUString > aElementsToBeVerified =
     313             :                 DocumentSignatureHelper::CreateElementList(
     314           0 :                 rxStorage, eMode, mode);
     315             : 
     316           0 :             const SignatureInformation& rInfo = aSignInfos[n];
     317           0 :             css::security::DocumentSignatureInformation& rSigInfo = arInfos[n];
     318             : 
     319           0 :             if (!rInfo.ouX509Certificate.isEmpty())
     320           0 :                rSigInfo.Signer = xSecEnv->createCertificateFromAscii( rInfo.ouX509Certificate ) ;
     321           0 :             if (!rSigInfo.Signer.is())
     322           0 :                 rSigInfo.Signer = xSecEnv->getCertificate( rInfo.ouX509IssuerName, xSerialNumberAdapter->toSequence( rInfo.ouX509SerialNumber ) );
     323             : 
     324             :             // Time support again (#i38744#)
     325           0 :             Date aDate( rInfo.stDateTime.Day, rInfo.stDateTime.Month, rInfo.stDateTime.Year );
     326             :             tools::Time aTime( rInfo.stDateTime.Hours, rInfo.stDateTime.Minutes,
     327           0 :                         rInfo.stDateTime.Seconds, rInfo.stDateTime.NanoSeconds );
     328           0 :             rSigInfo.SignatureDate = aDate.GetDate();
     329           0 :             rSigInfo.SignatureTime = aTime.GetTime();
     330             : 
     331             :             // Verify certificate
     332             :             //We have patched our version of libxmlsec, so that it does not verify the certificates. This has two
     333             :             //reasons. First we want two separate status for signature and certificate. Second libxmlsec calls
     334             :             //CERT_VerifyCertificate (Solaris, Linux) falsely, so that it always regards the certificate as valid.
     335             :             //On Windows the checking of the certificate path is buggy. It does name matching (issuer, subject name)
     336             :             //to find the parent certificate. It does not take into account that there can be several certificates
     337             :             //with the same subject name.
     338           0 :             if (rSigInfo.Signer.is())
     339             :             {
     340             :                 try {
     341           0 :                     rSigInfo.CertificateStatus = xSecEnv->verifyCertificate(rSigInfo.Signer,
     342           0 :                         Sequence<Reference<css::security::XCertificate> >());
     343           0 :                 } catch (SecurityException& ) {
     344             :                     OSL_FAIL("Verification of certificate failed");
     345           0 :                     rSigInfo.CertificateStatus = css::security::CertificateValidity::INVALID;
     346             :                 }
     347             :             }
     348             :             else
     349             :             {
     350             :                 //We should always be able to get the certificates because it is contained in the document,
     351             :                 //unless the document is damaged so that signature xml file could not be parsed.
     352           0 :                 rSigInfo.CertificateStatus = css::security::CertificateValidity::INVALID;
     353             :             }
     354             : 
     355           0 :             rSigInfo.SignatureIsValid = ( rInfo.nStatus == ::com::sun::star::xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED );
     356             : 
     357             : 
     358           0 :             if ( rSigInfo.SignatureIsValid )
     359             :             {
     360             :                  rSigInfo.SignatureIsValid =
     361             :                       DocumentSignatureHelper::checkIfAllFilesAreSigned(
     362           0 :                       aElementsToBeVerified, rInfo, mode);
     363             :             }
     364           0 :             if (eMode == SignatureModeDocumentContent)
     365             :                 rSigInfo.PartialDocumentSignature =
     366           0 :                     ! DocumentSignatureHelper::isOOo3_2_Signature(aSignInfos[n]);
     367             : 
     368           0 :         }
     369             :     }
     370         214 :     return aInfos;
     371             : 
     372             : }
     373             : 
     374           0 : void DocumentDigitalSignatures::manageTrustedSources(  ) throw (RuntimeException, std::exception)
     375             : {
     376             :     // MT: i45295
     377             :     // SecEnv is only needed to display certificate information from trusted sources.
     378             :     // Macro Security also has some options where no security environment is needed, so raise dialog anyway.
     379             :     // Later I should change the code so the Dialog creates the SecEnv on demand...
     380             : 
     381           0 :     Reference< css::xml::crypto::XSecurityEnvironment > xSecEnv;
     382             : 
     383           0 :     XMLSignatureHelper aSignatureHelper( mxCtx );
     384           0 :     if ( aSignatureHelper.Init() )
     385           0 :         xSecEnv = aSignatureHelper.GetSecurityEnvironment();
     386             : 
     387           0 :     ScopedVclPtrInstance< MacroSecurity > aDlg( nullptr, mxCtx, xSecEnv );
     388           0 :     aDlg->Execute();
     389           0 : }
     390             : 
     391           0 : void DocumentDigitalSignatures::showCertificate(
     392             :     const Reference< css::security::XCertificate >& _Certificate ) throw (RuntimeException, std::exception)
     393             : {
     394           0 :     XMLSignatureHelper aSignatureHelper( mxCtx );
     395             : 
     396           0 :     bool bInit = aSignatureHelper.Init();
     397             : 
     398             :     DBG_ASSERT( bInit, "Error initializing security context!" );
     399             : 
     400           0 :     if ( bInit )
     401             :     {
     402           0 :         ScopedVclPtrInstance< CertificateViewer > aViewer( nullptr, aSignatureHelper.GetSecurityEnvironment(), _Certificate, false );
     403           0 :         aViewer->Execute();
     404           0 :     }
     405             : 
     406           0 : }
     407             : 
     408           0 : sal_Bool DocumentDigitalSignatures::isAuthorTrusted(
     409             :     const Reference< css::security::XCertificate >& Author ) throw (RuntimeException, std::exception)
     410             : {
     411           0 :     bool bFound = false;
     412             : 
     413             :     Reference<security::XSerialNumberAdapter> xSerialNumberAdapter =
     414           0 :         ::com::sun::star::security::SerialNumberAdapter::create(mxCtx);
     415             : 
     416           0 :     OUString sSerialNum = xSerialNumberAdapter->toString( Author->getSerialNumber() );
     417             : 
     418           0 :     Sequence< SvtSecurityOptions::Certificate > aTrustedAuthors = SvtSecurityOptions().GetTrustedAuthors();
     419           0 :     const SvtSecurityOptions::Certificate* pAuthors = aTrustedAuthors.getConstArray();
     420           0 :     const SvtSecurityOptions::Certificate* pAuthorsEnd = pAuthors + aTrustedAuthors.getLength();
     421           0 :     for ( ; pAuthors != pAuthorsEnd; ++pAuthors )
     422             :     {
     423           0 :         SvtSecurityOptions::Certificate aAuthor = *pAuthors;
     424           0 :         if ( ( aAuthor[0] == Author->getIssuerName() ) && ( aAuthor[1] == sSerialNum ) )
     425             :         {
     426           0 :             bFound = true;
     427           0 :             break;
     428             :         }
     429           0 :     }
     430             : 
     431           0 :     return bFound;
     432             : }
     433             : 
     434           0 : Reference< css::security::XCertificate > DocumentDigitalSignatures::chooseCertificate() throw (RuntimeException, std::exception)
     435             : {
     436           0 :     Reference< css::xml::crypto::XSecurityEnvironment > xSecEnv;
     437             : 
     438           0 :     XMLSignatureHelper aSignatureHelper( mxCtx );
     439           0 :     if ( aSignatureHelper.Init() )
     440           0 :         xSecEnv = aSignatureHelper.GetSecurityEnvironment();
     441             : 
     442           0 :     ScopedVclPtrInstance< CertificateChooser > aChooser( nullptr, mxCtx, xSecEnv, aSignatureHelper.GetSignatureInformations());
     443             : 
     444           0 :     if (aChooser->Execute() != RET_OK)
     445           0 :         return Reference< css::security::XCertificate >(0);
     446             : 
     447           0 :     Reference< css::security::XCertificate > xCert = aChooser->GetSelectedCertificate();
     448             : 
     449           0 :     if ( !xCert.is() )
     450           0 :         return Reference< css::security::XCertificate >(0);
     451             : 
     452           0 :     return xCert;
     453             : }
     454             : 
     455             : 
     456           0 : sal_Bool DocumentDigitalSignatures::isLocationTrusted( const OUString& Location ) throw (RuntimeException, std::exception)
     457             : {
     458           0 :     return SvtSecurityOptions().isTrustedLocationUri(Location);
     459             : }
     460             : 
     461           0 : void DocumentDigitalSignatures::addAuthorToTrustedSources(
     462             :     const Reference< css::security::XCertificate >& Author ) throw (RuntimeException, std::exception)
     463             : {
     464           0 :     SvtSecurityOptions aSecOpts;
     465             : 
     466             :     Reference<security::XSerialNumberAdapter> xSerialNumberAdapter =
     467           0 :         ::com::sun::star::security::SerialNumberAdapter::create(mxCtx);
     468             : 
     469           0 :     SvtSecurityOptions::Certificate aNewCert( 3 );
     470           0 :     aNewCert[ 0 ] = Author->getIssuerName();
     471           0 :     aNewCert[ 1 ] = xSerialNumberAdapter->toString( Author->getSerialNumber() );
     472             : 
     473           0 :     OUStringBuffer aStrBuffer;
     474           0 :     ::sax::Converter::encodeBase64(aStrBuffer, Author->getEncoded());
     475           0 :     aNewCert[ 2 ] = aStrBuffer.makeStringAndClear();
     476             : 
     477             : 
     478           0 :     Sequence< SvtSecurityOptions::Certificate > aTrustedAuthors = aSecOpts.GetTrustedAuthors();
     479           0 :     sal_Int32 nCnt = aTrustedAuthors.getLength();
     480           0 :     aTrustedAuthors.realloc( nCnt + 1 );
     481           0 :     aTrustedAuthors[ nCnt ] = aNewCert;
     482             : 
     483           0 :     aSecOpts.SetTrustedAuthors( aTrustedAuthors );
     484           0 : }
     485             : 
     486           0 : void DocumentDigitalSignatures::addLocationToTrustedSources( const OUString& Location ) throw (RuntimeException, std::exception)
     487             : {
     488           0 :     SvtSecurityOptions aSecOpt;
     489             : 
     490           0 :     Sequence< OUString > aSecURLs = aSecOpt.GetSecureURLs();
     491           0 :     sal_Int32 nCnt = aSecURLs.getLength();
     492           0 :     aSecURLs.realloc( nCnt + 1 );
     493           0 :     aSecURLs[ nCnt ] = Location;
     494             : 
     495           0 :     aSecOpt.SetSecureURLs( aSecURLs );
     496           0 : }
     497             : 
     498          26 : OUString DocumentDigitalSignatures::GetImplementationName() throw (RuntimeException)
     499             : {
     500          26 :     return OUString( "com.sun.star.security.DocumentDigitalSignatures" );
     501             : }
     502             : 
     503          25 : Sequence< OUString > DocumentDigitalSignatures::GetSupportedServiceNames() throw (css::uno::RuntimeException)
     504             : {
     505          25 :     Sequence < OUString > aRet(1);
     506          25 :     OUString* pArray = aRet.getArray();
     507          25 :     pArray[0] = "com.sun.star.security.DocumentDigitalSignatures";
     508          25 :     return aRet;
     509             : }
     510             : 
     511             : 
     512         215 : Reference< XInterface > DocumentDigitalSignatures_CreateInstance(
     513             :     const Reference< XComponentContext >& rCtx) throw ( Exception )
     514             : {
     515         215 :     return static_cast<cppu::OWeakObject*>(new DocumentDigitalSignatures( rCtx ));
     516         114 : }
     517             : 
     518             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11