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

Generated by: LCOV version 1.10