Files
libreoffice/package/source/zippackage/ZipPackageStream.cxx

1318 lines
49 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2012-06-22 18:32:07 +01:00
/*
* 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 .
*/
#include <ZipPackageStream.hxx>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/packages/zip/ZipConstants.hpp>
2010-04-13 10:28:25 +02:00
#include <com/sun/star/embed/StorageFormats.hpp>
#include <com/sun/star/packages/zip/ZipIOException.hpp>
#include <com/sun/star/io/TempFile.hpp>
#include <com/sun/star/io/XInputStream.hpp>
#include <com/sun/star/io/XOutputStream.hpp>
#include <com/sun/star/io/XStream.hpp>
#include <com/sun/star/io/XSeekable.hpp>
2011-03-09 17:29:09 +01:00
#include <com/sun/star/xml/crypto/DigestID.hpp>
#include <com/sun/star/xml/crypto/CipherID.hpp>
#include <string.h>
#include <CRC32.hxx>
#include <ZipOutputEntry.hxx>
#include <ZipOutputStream.hxx>
#include <ZipPackage.hxx>
#include <ZipPackageFolder.hxx>
#include <ZipFile.hxx>
#include <EncryptedDataHeader.hxx>
2010-10-10 19:46:46 -05:00
#include <osl/diagnose.h>
#include "wrapstreamforshare.hxx"
#include <comphelper/processfactory.hxx>
#include <comphelper/seekableinput.hxx>
#include <comphelper/storagehelper.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <cppuhelper/typeprovider.hxx>
#include <rtl/instance.hxx>
#include <rtl/random.h>
#include <PackageConstants.hxx>
using namespace com::sun::star::packages::zip::ZipConstants;
using namespace com::sun::star::packages::zip;
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star;
using namespace cppu;
2010-10-15 12:18:51 -05:00
#if OSL_DEBUG_LEVEL > 0
#define THROW_WHERE SAL_WHERE
#else
#define THROW_WHERE ""
#endif
namespace { struct lcl_CachedImplId : public rtl::Static< cppu::OImplementationId, lcl_CachedImplId > {}; }
::com::sun::star::uno::Sequence < sal_Int8 > ZipPackageStream::static_getImplementationId()
{
return lcl_CachedImplId::get().getImplementationId();
}
ZipPackageStream::ZipPackageStream ( ZipPackage & rNewPackage,
const uno::Reference< XComponentContext >& xContext,
sal_Int32 nFormat,
bool bAllowRemoveOnInsert )
: m_rZipPackage( rNewPackage )
, m_bToBeCompressed ( true )
, m_bToBeEncrypted ( false )
, m_bHaveOwnKey ( false )
, m_bIsEncrypted ( false )
, m_nImportedStartKeyAlgorithm( 0 )
2011-03-09 17:29:09 +01:00
, m_nImportedEncryptionAlgorithm( 0 )
, m_nImportedChecksumAlgorithm( 0 )
, m_nImportedDerivedKeySize( 0 )
, m_nStreamMode( PACKAGE_STREAM_NOTSET )
, m_nMagicalHackPos( 0 )
, m_nMagicalHackSize( 0 )
, m_bHasSeekable( false )
, m_bCompressedIsSetFromOutside( false )
, m_bFromManifest( false )
2011-03-09 17:29:09 +01:00
, m_bUseWinEncoding( false )
{
m_xContext = xContext;
m_nFormat = nFormat;
mbAllowRemoveOnInsert = bAllowRemoveOnInsert;
SetFolder ( false );
aEntry.nVersion = -1;
aEntry.nFlag = 0;
aEntry.nMethod = -1;
aEntry.nTime = -1;
aEntry.nCrc = -1;
aEntry.nCompressedSize = -1;
aEntry.nSize = -1;
aEntry.nOffset = -1;
CWS-TOOLING: integrate CWS encsig09 2009-09-14 15:11:29 +0200 oc r276125 : #i105049# MacroSignatur needs Macro 2009-09-09 17:09:46 +0200 jl r276005 : #i103989# could not signe encrypted doc containing a formular object 2009-09-09 13:11:24 +0200 jl r275985 : #i103989# could not signe encrypted doc containing a formular object 2009-09-08 15:54:02 +0200 mav r275934 : #i103906# fix the automation test scenario ( tempfile should be writable for the user ) 2009-09-07 14:01:39 +0200 mav r275895 : #i103906# fix the problem with reload 2009-09-07 09:34:48 +0200 mav r275871 : #i104786# do the ODF version check only for ODF documents 2009-09-07 08:19:06 +0200 mav r275870 : #i104389# fix text 2009-09-06 22:24:21 +0200 mav r275867 : #i104786# check the consistency of ODF version 2009-09-06 22:23:24 +0200 mav r275866 : #i104786# check the consistency of ODF version 2009-09-06 22:23:00 +0200 mav r275865 : #i104786# check the consistency of ODF version 2009-09-06 22:22:36 +0200 mav r275864 : #i104786# check the consistency of ODF version 2009-09-06 22:22:03 +0200 mav r275863 : #i104786# check the consistency of ODF version 2009-09-02 17:09:30 +0200 mav r275722 : #i104715# let repairing mechanics use the streams correctly 2009-09-01 16:52:49 +0200 mav r275670 : #i104389# notify user not to trust the corrupted document 2009-09-01 16:31:37 +0200 mav r275668 : #i104389# use vnd.sun.star.zip: protocol to access zip files 2009-09-01 16:30:32 +0200 mav r275667 : #i104389# use vnd.sun.star.zip: protocol to access zip files 2009-09-01 16:22:13 +0200 jl r275666 : #i104339# small content change 2009-09-01 14:20:42 +0200 jl r275660 : #i103519# remove some debug output 2009-09-01 13:51:52 +0200 jl r275659 : #i103519# NSS uses '\' for escaping in distinguished names 2009-09-01 12:49:47 +0200 mav r275655 : #i104389# use zip-mode to read from jar files 2009-09-01 12:40:22 +0200 mav r275653 : #i104389# use zip-mode to read from jar files 2009-09-01 12:32:29 +0200 mav r275652 : #i104389# use constants 2009-08-31 21:58:00 +0200 mav r275637 : #i10000# fix warning 2009-08-31 21:11:17 +0200 mav r275636 : #i104227# adding of scripting signature removes the document signature 2009-08-31 20:55:05 +0200 mav r275635 : #i103905# ZipStorage supports Compressed property 2009-08-31 20:53:55 +0200 mav r275634 : #i103905# adjust macro signature transfer to usage of ZipStorage 2009-08-31 15:30:49 +0200 jl r275609 : #i103989# warning is shown as long the user does not click 'OK' 2009-08-31 14:36:10 +0200 jl r275608 : #i103989# changed warning text when signing macro and there is a document signature. This warning is only displayed once 2009-08-31 13:34:41 +0200 mav r275603 : #i104452# disable macros in repaired documents 2009-08-31 13:33:42 +0200 mav r275602 : #i104452# disable macros in repaired documents 2009-08-31 13:03:56 +0200 jl r275600 : #i45212# signature dialog could not be started when using read-only documents 2009-08-31 09:26:13 +0200 mav r275583 : #i104578# store the additional entry as the last one to workaround parsing problem in OOo3.1 and later 2009-08-30 20:54:25 +0200 mav r275562 : #i10000# adopt for unix 2009-08-30 10:56:00 +0200 mav r275561 : CWS-TOOLING: rebase CWS encsig09 to trunk@275331 (milestone: DEV300:m56) 2009-08-28 16:34:00 +0200 mav r275539 : #i104578# write necessary info in manifest.xml for ODF1.2 encrypted document 2009-08-28 14:04:22 +0200 mav r275533 : #104587# fix handling of readonly streams 2009-08-28 13:58:10 +0200 mav r275531 : #i104389# fix the broken document handling 2009-08-28 11:40:39 +0200 mav r275522 : #i104389# fix the signature streams check 2009-08-27 21:48:12 +0200 mav r275509 : #i103927# show the warning 2009-08-27 21:47:48 +0200 mav r275508 : #i103927# show the warning 2009-08-27 16:45:59 +0200 jl r275495 : #i45212# remove unused variable 2009-08-27 16:34:00 +0200 jl r275494 : #i103989# 2009-08-27 13:54:28 +0200 jl r275482 : #i103519# fixed replacement of 'S' by 'ST' 2009-08-27 12:32:21 +0200 mav r275472 : #i10000# fix warning 2009-08-27 11:58:11 +0200 mav r275467 : #i104389# handle the entry path correctly 2009-08-26 17:18:35 +0200 jl r275438 : #i103519# subject and issuer distinguished names were not properly displayed. The strings were obtained by system functions (Windows, NSS), which use quotes to escape the values, when they contain special characters 2009-08-26 11:00:20 +0200 mav r275403 : #i10000# fix warnings 2009-08-26 08:25:45 +0200 mav r275392 : #i10000# fix warning 2009-08-26 08:02:22 +0200 mav r275391 : #i10000# adopt for linux 2009-08-26 07:40:30 +0200 mav r275390 : #i10000# fix warning 2009-08-26 07:35:28 +0200 mav r275389 : #i10000# use correct include file name 2009-08-25 15:01:41 +0200 jl r275356 : #i103989# better check for mimetype of streams 2009-08-25 09:07:09 +0200 mav r275335 : CWS-TOOLING: rebase CWS encsig09 to trunk@274622 (milestone: DEV300:m54) 2009-08-24 18:17:02 +0200 mav r275329 : #i103927# check the nonencrypted streams 2009-08-24 18:14:14 +0200 mav r275328 : #i103927# check the nonencrypted streams 2009-08-24 17:59:34 +0200 mav r275327 : #i103927#,#i104389# check the package consistency and nonencrypted streams 2009-08-24 16:18:28 +0200 jl r275323 : #i103989# added comment 2009-08-24 13:08:47 +0200 jl r275305 : #i45212# #i66276# only write the X509Certificate element once and allow to add remove several certificates at a time 2009-08-21 12:57:28 +0200 ufi r275239 : 104339 2009-08-21 08:39:05 +0200 jl r275213 : #i10398# comparing URIs of signed files with the 'element list' 2009-08-20 13:39:47 +0200 jl r275178 : #i10398# displaying 'new partially signed' status in the status bar 2009-08-20 13:35:39 +0200 jl r275177 : #i10398# displaying 'new partially signed' status in the status bar 2009-08-20 13:29:06 +0200 jl r275176 : #i10398# displaying 'new partially signed' status in the status bar 2009-08-20 13:26:21 +0200 jl r275175 : #i10398# displaying 'new partially signed' status in the status bar 2009-08-20 12:05:09 +0200 ufi r275170 : i104339 2009-08-19 12:24:54 +0200 jl r275146 : #i10398# displaying 'old signature' icon and status in signature dialog 2009-08-18 15:18:48 +0200 jl r275111 : #i103989# document signatures containing manifest.xml are now validated according to the final ODF1.2 spec 2009-08-18 11:41:06 +0200 mav r275087 : #i103927# detect if encrypted ODF1.2 document contains nonencrypted streams 2009-08-18 11:35:13 +0200 mav r275085 : #i103927# detect if encrypted ODF1.2 document contains nonencrypted streams 2009-08-14 17:32:41 +0200 jl r274999 : #i103989# using c14n tranformation for XML streams 2009-08-14 15:27:43 +0200 jl r274987 : #i103989# remove special handling for encrypted document streams in UriBindingHelper::OpenInputStream, since we use zip storage this is not necessary anymore 2009-08-14 15:08:10 +0200 jl r274983 : #i103989# Showing a message when adding or removing a macro signature, that the document signature will be removed 2009-08-14 14:57:27 +0200 jl r274982 : #i103989# accesing Sequence at invalid index 2009-08-11 08:55:02 +0200 mav r274846 : #i103905# let signing service know if there is already a valid document signature 2009-08-10 11:33:37 +0200 jl r274799 : #i103905# do not truncate the stream 2009-08-10 10:43:47 +0200 mav r274797 : #i103905# provide the storage version 2009-08-07 16:58:46 +0200 jl r274780 : #i103989# 2009-08-07 16:56:19 +0200 jl r274779 : #i103989# using odf version string etc. 2009-08-07 15:20:53 +0200 mav r274771 : #i103905# provide the storage version 2009-08-07 15:19:12 +0200 mav r274770 : #i103905# provide the storage version 2009-08-07 12:41:45 +0200 mav r274758 : #103930# do not store thumbnail in case of encrypted document 2009-08-07 12:36:52 +0200 mav r274757 : #i103905# provide the storage version 2009-08-07 12:15:54 +0200 mav r274754 : #i103760# the signed state is not lost on saving 2009-08-07 12:06:19 +0200 mav r274753 : #i103760# avoid warning regarding signature removal on export 2009-08-07 12:06:01 +0200 mav r274752 : #i103760# avoid warning regarding signature removal on export 2009-08-06 08:47:34 +0200 mav r274703 : #i103905# allow to transport ODF version to the signing component 2009-08-05 21:34:42 +0200 mav r274701 : #i103905# allow to transport ODF version to the signing component 2009-08-05 15:48:17 +0200 mav r274683 : #i103905# allow to transport ODF version to the signing component 2009-08-05 14:58:12 +0200 jl r274673 : #i103989# documentsignature now signes all streams except documentsignatures.xml, all streams are processed as binary files 2009-08-05 12:00:32 +0200 mav r274648 : #i103905# allow to transport ODF version to the signing component 2009-08-04 10:57:04 +0200 jl r274612 : #i103989# added XInitialization 2009-07-31 10:32:27 +0200 mav r274516 : #i103905# use zip storage to sign documents 2009-07-30 14:01:33 +0200 mav r274489 : #i103906# optimize the usage of temporary medium 2009-07-30 14:00:28 +0200 mav r274488 : #i103906# optimize the usage of temporary medium 2009-07-30 13:59:09 +0200 mav r274487 : #i103906# optimize the usage of temporary medium 2009-07-30 13:50:44 +0200 mav r274485 : #i103906# optimize the usage of temporary medium 2009-07-30 13:49:53 +0200 mav r274484 : #i103906# optimize the usage of temporary medium 2009-07-30 13:49:13 +0200 mav r274483 : #i103906# optimize the usage of temporary medium 2009-07-30 13:47:09 +0200 mav r274482 : #i103905#,#i103906# let the signing process use zip-storage; optimize the usage of temporary medium 2009-07-21 09:10:31 +0200 mav r274159 : CWS-TOOLING: rebase CWS encsig09 to trunk@273468 (milestone: DEV300:m51) 2009-05-05 08:39:01 +0200 mav r271496 : #i100832# allow to sign macros only when there are any
2009-09-17 13:53:54 +00:00
aEntry.nPathLen = -1;
aEntry.nExtraLen = -1;
}
ZipPackageStream::~ZipPackageStream( void )
{
}
2011-03-09 17:29:09 +01:00
void ZipPackageStream::setZipEntryOnLoading( const ZipEntry &rInEntry )
{
aEntry.nVersion = rInEntry.nVersion;
aEntry.nFlag = rInEntry.nFlag;
aEntry.nMethod = rInEntry.nMethod;
aEntry.nTime = rInEntry.nTime;
aEntry.nCrc = rInEntry.nCrc;
aEntry.nCompressedSize = rInEntry.nCompressedSize;
aEntry.nSize = rInEntry.nSize;
aEntry.nOffset = rInEntry.nOffset;
CWS-TOOLING: integrate CWS encsig09 2009-09-14 15:11:29 +0200 oc r276125 : #i105049# MacroSignatur needs Macro 2009-09-09 17:09:46 +0200 jl r276005 : #i103989# could not signe encrypted doc containing a formular object 2009-09-09 13:11:24 +0200 jl r275985 : #i103989# could not signe encrypted doc containing a formular object 2009-09-08 15:54:02 +0200 mav r275934 : #i103906# fix the automation test scenario ( tempfile should be writable for the user ) 2009-09-07 14:01:39 +0200 mav r275895 : #i103906# fix the problem with reload 2009-09-07 09:34:48 +0200 mav r275871 : #i104786# do the ODF version check only for ODF documents 2009-09-07 08:19:06 +0200 mav r275870 : #i104389# fix text 2009-09-06 22:24:21 +0200 mav r275867 : #i104786# check the consistency of ODF version 2009-09-06 22:23:24 +0200 mav r275866 : #i104786# check the consistency of ODF version 2009-09-06 22:23:00 +0200 mav r275865 : #i104786# check the consistency of ODF version 2009-09-06 22:22:36 +0200 mav r275864 : #i104786# check the consistency of ODF version 2009-09-06 22:22:03 +0200 mav r275863 : #i104786# check the consistency of ODF version 2009-09-02 17:09:30 +0200 mav r275722 : #i104715# let repairing mechanics use the streams correctly 2009-09-01 16:52:49 +0200 mav r275670 : #i104389# notify user not to trust the corrupted document 2009-09-01 16:31:37 +0200 mav r275668 : #i104389# use vnd.sun.star.zip: protocol to access zip files 2009-09-01 16:30:32 +0200 mav r275667 : #i104389# use vnd.sun.star.zip: protocol to access zip files 2009-09-01 16:22:13 +0200 jl r275666 : #i104339# small content change 2009-09-01 14:20:42 +0200 jl r275660 : #i103519# remove some debug output 2009-09-01 13:51:52 +0200 jl r275659 : #i103519# NSS uses '\' for escaping in distinguished names 2009-09-01 12:49:47 +0200 mav r275655 : #i104389# use zip-mode to read from jar files 2009-09-01 12:40:22 +0200 mav r275653 : #i104389# use zip-mode to read from jar files 2009-09-01 12:32:29 +0200 mav r275652 : #i104389# use constants 2009-08-31 21:58:00 +0200 mav r275637 : #i10000# fix warning 2009-08-31 21:11:17 +0200 mav r275636 : #i104227# adding of scripting signature removes the document signature 2009-08-31 20:55:05 +0200 mav r275635 : #i103905# ZipStorage supports Compressed property 2009-08-31 20:53:55 +0200 mav r275634 : #i103905# adjust macro signature transfer to usage of ZipStorage 2009-08-31 15:30:49 +0200 jl r275609 : #i103989# warning is shown as long the user does not click 'OK' 2009-08-31 14:36:10 +0200 jl r275608 : #i103989# changed warning text when signing macro and there is a document signature. This warning is only displayed once 2009-08-31 13:34:41 +0200 mav r275603 : #i104452# disable macros in repaired documents 2009-08-31 13:33:42 +0200 mav r275602 : #i104452# disable macros in repaired documents 2009-08-31 13:03:56 +0200 jl r275600 : #i45212# signature dialog could not be started when using read-only documents 2009-08-31 09:26:13 +0200 mav r275583 : #i104578# store the additional entry as the last one to workaround parsing problem in OOo3.1 and later 2009-08-30 20:54:25 +0200 mav r275562 : #i10000# adopt for unix 2009-08-30 10:56:00 +0200 mav r275561 : CWS-TOOLING: rebase CWS encsig09 to trunk@275331 (milestone: DEV300:m56) 2009-08-28 16:34:00 +0200 mav r275539 : #i104578# write necessary info in manifest.xml for ODF1.2 encrypted document 2009-08-28 14:04:22 +0200 mav r275533 : #104587# fix handling of readonly streams 2009-08-28 13:58:10 +0200 mav r275531 : #i104389# fix the broken document handling 2009-08-28 11:40:39 +0200 mav r275522 : #i104389# fix the signature streams check 2009-08-27 21:48:12 +0200 mav r275509 : #i103927# show the warning 2009-08-27 21:47:48 +0200 mav r275508 : #i103927# show the warning 2009-08-27 16:45:59 +0200 jl r275495 : #i45212# remove unused variable 2009-08-27 16:34:00 +0200 jl r275494 : #i103989# 2009-08-27 13:54:28 +0200 jl r275482 : #i103519# fixed replacement of 'S' by 'ST' 2009-08-27 12:32:21 +0200 mav r275472 : #i10000# fix warning 2009-08-27 11:58:11 +0200 mav r275467 : #i104389# handle the entry path correctly 2009-08-26 17:18:35 +0200 jl r275438 : #i103519# subject and issuer distinguished names were not properly displayed. The strings were obtained by system functions (Windows, NSS), which use quotes to escape the values, when they contain special characters 2009-08-26 11:00:20 +0200 mav r275403 : #i10000# fix warnings 2009-08-26 08:25:45 +0200 mav r275392 : #i10000# fix warning 2009-08-26 08:02:22 +0200 mav r275391 : #i10000# adopt for linux 2009-08-26 07:40:30 +0200 mav r275390 : #i10000# fix warning 2009-08-26 07:35:28 +0200 mav r275389 : #i10000# use correct include file name 2009-08-25 15:01:41 +0200 jl r275356 : #i103989# better check for mimetype of streams 2009-08-25 09:07:09 +0200 mav r275335 : CWS-TOOLING: rebase CWS encsig09 to trunk@274622 (milestone: DEV300:m54) 2009-08-24 18:17:02 +0200 mav r275329 : #i103927# check the nonencrypted streams 2009-08-24 18:14:14 +0200 mav r275328 : #i103927# check the nonencrypted streams 2009-08-24 17:59:34 +0200 mav r275327 : #i103927#,#i104389# check the package consistency and nonencrypted streams 2009-08-24 16:18:28 +0200 jl r275323 : #i103989# added comment 2009-08-24 13:08:47 +0200 jl r275305 : #i45212# #i66276# only write the X509Certificate element once and allow to add remove several certificates at a time 2009-08-21 12:57:28 +0200 ufi r275239 : 104339 2009-08-21 08:39:05 +0200 jl r275213 : #i10398# comparing URIs of signed files with the 'element list' 2009-08-20 13:39:47 +0200 jl r275178 : #i10398# displaying 'new partially signed' status in the status bar 2009-08-20 13:35:39 +0200 jl r275177 : #i10398# displaying 'new partially signed' status in the status bar 2009-08-20 13:29:06 +0200 jl r275176 : #i10398# displaying 'new partially signed' status in the status bar 2009-08-20 13:26:21 +0200 jl r275175 : #i10398# displaying 'new partially signed' status in the status bar 2009-08-20 12:05:09 +0200 ufi r275170 : i104339 2009-08-19 12:24:54 +0200 jl r275146 : #i10398# displaying 'old signature' icon and status in signature dialog 2009-08-18 15:18:48 +0200 jl r275111 : #i103989# document signatures containing manifest.xml are now validated according to the final ODF1.2 spec 2009-08-18 11:41:06 +0200 mav r275087 : #i103927# detect if encrypted ODF1.2 document contains nonencrypted streams 2009-08-18 11:35:13 +0200 mav r275085 : #i103927# detect if encrypted ODF1.2 document contains nonencrypted streams 2009-08-14 17:32:41 +0200 jl r274999 : #i103989# using c14n tranformation for XML streams 2009-08-14 15:27:43 +0200 jl r274987 : #i103989# remove special handling for encrypted document streams in UriBindingHelper::OpenInputStream, since we use zip storage this is not necessary anymore 2009-08-14 15:08:10 +0200 jl r274983 : #i103989# Showing a message when adding or removing a macro signature, that the document signature will be removed 2009-08-14 14:57:27 +0200 jl r274982 : #i103989# accesing Sequence at invalid index 2009-08-11 08:55:02 +0200 mav r274846 : #i103905# let signing service know if there is already a valid document signature 2009-08-10 11:33:37 +0200 jl r274799 : #i103905# do not truncate the stream 2009-08-10 10:43:47 +0200 mav r274797 : #i103905# provide the storage version 2009-08-07 16:58:46 +0200 jl r274780 : #i103989# 2009-08-07 16:56:19 +0200 jl r274779 : #i103989# using odf version string etc. 2009-08-07 15:20:53 +0200 mav r274771 : #i103905# provide the storage version 2009-08-07 15:19:12 +0200 mav r274770 : #i103905# provide the storage version 2009-08-07 12:41:45 +0200 mav r274758 : #103930# do not store thumbnail in case of encrypted document 2009-08-07 12:36:52 +0200 mav r274757 : #i103905# provide the storage version 2009-08-07 12:15:54 +0200 mav r274754 : #i103760# the signed state is not lost on saving 2009-08-07 12:06:19 +0200 mav r274753 : #i103760# avoid warning regarding signature removal on export 2009-08-07 12:06:01 +0200 mav r274752 : #i103760# avoid warning regarding signature removal on export 2009-08-06 08:47:34 +0200 mav r274703 : #i103905# allow to transport ODF version to the signing component 2009-08-05 21:34:42 +0200 mav r274701 : #i103905# allow to transport ODF version to the signing component 2009-08-05 15:48:17 +0200 mav r274683 : #i103905# allow to transport ODF version to the signing component 2009-08-05 14:58:12 +0200 jl r274673 : #i103989# documentsignature now signes all streams except documentsignatures.xml, all streams are processed as binary files 2009-08-05 12:00:32 +0200 mav r274648 : #i103905# allow to transport ODF version to the signing component 2009-08-04 10:57:04 +0200 jl r274612 : #i103989# added XInitialization 2009-07-31 10:32:27 +0200 mav r274516 : #i103905# use zip storage to sign documents 2009-07-30 14:01:33 +0200 mav r274489 : #i103906# optimize the usage of temporary medium 2009-07-30 14:00:28 +0200 mav r274488 : #i103906# optimize the usage of temporary medium 2009-07-30 13:59:09 +0200 mav r274487 : #i103906# optimize the usage of temporary medium 2009-07-30 13:50:44 +0200 mav r274485 : #i103906# optimize the usage of temporary medium 2009-07-30 13:49:53 +0200 mav r274484 : #i103906# optimize the usage of temporary medium 2009-07-30 13:49:13 +0200 mav r274483 : #i103906# optimize the usage of temporary medium 2009-07-30 13:47:09 +0200 mav r274482 : #i103905#,#i103906# let the signing process use zip-storage; optimize the usage of temporary medium 2009-07-21 09:10:31 +0200 mav r274159 : CWS-TOOLING: rebase CWS encsig09 to trunk@273468 (milestone: DEV300:m51) 2009-05-05 08:39:01 +0200 mav r271496 : #i100832# allow to sign macros only when there are any
2009-09-17 13:53:54 +00:00
aEntry.sPath = rInEntry.sPath;
aEntry.nPathLen = rInEntry.nPathLen;
aEntry.nExtraLen = rInEntry.nExtraLen;
if ( aEntry.nMethod == STORED )
m_bToBeCompressed = false;
}
void ZipPackageStream::CloseOwnStreamIfAny()
{
if ( m_xStream.is() )
{
m_xStream->closeInput();
m_xStream = uno::Reference< io::XInputStream >();
m_bHasSeekable = false;
}
}
uno::Reference< io::XInputStream > ZipPackageStream::GetOwnSeekStream()
{
if ( !m_bHasSeekable && m_xStream.is() )
{
// The package component requires that every stream either be FROM a package or it must support XSeekable!
// The only exception is a nonseekable stream that is provided only for storing, if such a stream
// is accessed before commit it MUST be wrapped.
// Wrap the stream in case it is not seekable
m_xStream = ::comphelper::OSeekableInputWrapper::CheckSeekableCanWrap( m_xStream, m_xContext );
uno::Reference< io::XSeekable > xSeek( m_xStream, UNO_QUERY );
if ( !xSeek.is() )
throw RuntimeException( THROW_WHERE "The stream must support XSeekable!" );
m_bHasSeekable = true;
}
return m_xStream;
}
uno::Reference< io::XInputStream > ZipPackageStream::GetRawEncrStreamNoHeaderCopy()
{
if ( m_nStreamMode != PACKAGE_STREAM_RAW || !GetOwnSeekStream().is() )
throw io::IOException(THROW_WHERE );
2011-03-09 17:29:09 +01:00
if ( m_xBaseEncryptionData.is() )
throw ZipIOException(THROW_WHERE "Encrypted stream without encryption data!" );
uno::Reference< io::XSeekable > xSeek( GetOwnSeekStream(), UNO_QUERY );
if ( !xSeek.is() )
throw ZipIOException(THROW_WHERE "The stream must be seekable!" );
// skip header
xSeek->seek( n_ConstHeaderSize + m_xBaseEncryptionData->m_aInitVector.getLength() +
m_xBaseEncryptionData->m_aSalt.getLength() + m_xBaseEncryptionData->m_aDigest.getLength() );
// create temporary stream
uno::Reference < io::XTempFile > xTempFile = io::TempFile::create(m_xContext);
uno::Reference < io::XOutputStream > xTempOut = xTempFile->getOutputStream();
uno::Reference < io::XInputStream > xTempIn = xTempFile->getInputStream();;
uno::Reference < io::XSeekable > xTempSeek( xTempOut, UNO_QUERY_THROW );
// copy the raw stream to the temporary file starting from the current position
::comphelper::OStorageHelper::CopyInputToOutput( GetOwnSeekStream(), xTempOut );
xTempOut->closeOutput();
xTempSeek->seek( 0 );
return xTempIn;
}
sal_Int32 ZipPackageStream::GetEncryptionAlgorithm() const
{
return m_nImportedEncryptionAlgorithm ? m_nImportedEncryptionAlgorithm : m_rZipPackage.GetEncAlgID();
}
sal_Int32 ZipPackageStream::GetBlockSize() const
{
return GetEncryptionAlgorithm() == ::com::sun::star::xml::crypto::CipherID::AES_CBC_W3C_PADDING ? 16 : 8;
}
2011-03-09 17:29:09 +01:00
::rtl::Reference< EncryptionData > ZipPackageStream::GetEncryptionData( bool bUseWinEncoding )
{
2011-03-09 17:29:09 +01:00
::rtl::Reference< EncryptionData > xResult;
if ( m_xBaseEncryptionData.is() )
xResult = new EncryptionData(
*m_xBaseEncryptionData,
GetEncryptionKey( bUseWinEncoding ),
GetEncryptionAlgorithm(),
m_nImportedChecksumAlgorithm ? m_nImportedChecksumAlgorithm : m_rZipPackage.GetChecksumAlgID(),
m_nImportedDerivedKeySize ? m_nImportedDerivedKeySize : m_rZipPackage.GetDefaultDerivedKeySize(),
GetStartKeyGenID() );
2011-03-09 17:29:09 +01:00
return xResult;
}
uno::Sequence< sal_Int8 > ZipPackageStream::GetEncryptionKey( bool bUseWinEncoding )
{
uno::Sequence< sal_Int8 > aResult;
sal_Int32 nKeyGenID = GetStartKeyGenID();
2011-03-09 17:29:09 +01:00
bUseWinEncoding = ( bUseWinEncoding || m_bUseWinEncoding );
if ( m_bHaveOwnKey && m_aStorageEncryptionKeys.getLength() )
2011-03-09 17:29:09 +01:00
{
OUString aNameToFind;
2011-03-09 17:29:09 +01:00
if ( nKeyGenID == xml::crypto::DigestID::SHA256 )
aNameToFind = PACKAGE_ENCRYPTIONDATA_SHA256UTF8;
else if ( nKeyGenID == xml::crypto::DigestID::SHA1 )
{
aNameToFind = bUseWinEncoding ? PACKAGE_ENCRYPTIONDATA_SHA1MS1252 : PACKAGE_ENCRYPTIONDATA_SHA1UTF8;
}
else
throw uno::RuntimeException(THROW_WHERE "No expected key is provided!" );
2011-03-09 17:29:09 +01:00
for ( sal_Int32 nInd = 0; nInd < m_aStorageEncryptionKeys.getLength(); nInd++ )
if ( m_aStorageEncryptionKeys[nInd].Name.equals( aNameToFind ) )
m_aStorageEncryptionKeys[nInd].Value >>= aResult;
// empty keys are not allowed here
// so it is not important whether there is no key, or the key is empty, it is an error
if ( !aResult.getLength() )
throw uno::RuntimeException(THROW_WHERE "No expected key is provided!" );
2011-03-09 17:29:09 +01:00
}
else
aResult = m_aEncryptionKey;
if ( !aResult.getLength() || !m_bHaveOwnKey )
aResult = m_rZipPackage.GetEncryptionKey();
2011-03-09 17:29:09 +01:00
return aResult;
}
sal_Int32 ZipPackageStream::GetStartKeyGenID()
2011-03-17 09:16:41 +01:00
{
// generally should all the streams use the same Start Key
// but if raw copy without password takes place, we should preserve the imported algorithm
return m_nImportedStartKeyAlgorithm ? m_nImportedStartKeyAlgorithm : m_rZipPackage.GetStartKeyGenID();
2011-03-17 09:16:41 +01:00
}
uno::Reference< io::XInputStream > ZipPackageStream::TryToGetRawFromDataStream( bool bAddHeaderForEncr )
2011-03-09 17:29:09 +01:00
{
if ( m_nStreamMode != PACKAGE_STREAM_DATA || !GetOwnSeekStream().is() || ( bAddHeaderForEncr && !m_bToBeEncrypted ) )
throw packages::NoEncryptionException(THROW_WHERE );
Sequence< sal_Int8 > aKey;
if ( m_bToBeEncrypted )
{
2011-03-09 17:29:09 +01:00
aKey = GetEncryptionKey();
if ( !aKey.getLength() )
throw packages::NoEncryptionException(THROW_WHERE );
}
try
{
// create temporary file
uno::Reference < io::XStream > xTempStream(
io::TempFile::create(m_xContext),
uno::UNO_QUERY_THROW );
// create a package based on it
ZipPackage* pPackage = new ZipPackage( m_xContext );
2011-03-09 17:29:09 +01:00
uno::Reference< XSingleServiceFactory > xPackageAsFactory( static_cast< XSingleServiceFactory* >( pPackage ) );
if ( !xPackageAsFactory.is() )
throw RuntimeException(THROW_WHERE );
Sequence< Any > aArgs( 1 );
aArgs[0] <<= xTempStream;
pPackage->initialize( aArgs );
// create a new package stream
2011-03-09 17:29:09 +01:00
uno::Reference< XDataSinkEncrSupport > xNewPackStream( xPackageAsFactory->createInstance(), UNO_QUERY );
if ( !xNewPackStream.is() )
throw RuntimeException(THROW_WHERE );
xNewPackStream->setDataStream( static_cast< io::XInputStream* >(
new WrapStreamForShare( GetOwnSeekStream(), m_rZipPackage.GetSharedMutexRef() ) ) );
2011-03-09 17:29:09 +01:00
uno::Reference< XPropertySet > xNewPSProps( xNewPackStream, UNO_QUERY );
if ( !xNewPSProps.is() )
throw RuntimeException(THROW_WHERE );
// copy all the properties of this stream to the new stream
xNewPSProps->setPropertyValue("MediaType", makeAny( msMediaType ) );
xNewPSProps->setPropertyValue("Compressed", makeAny( m_bToBeCompressed ) );
if ( m_bToBeEncrypted )
{
xNewPSProps->setPropertyValue(ENCRYPTION_KEY_PROPERTY, makeAny( aKey ) );
xNewPSProps->setPropertyValue("Encrypted", makeAny( true ) );
}
// insert a new stream in the package
2011-03-09 17:29:09 +01:00
uno::Reference< XUnoTunnel > xTunnel;
Any aRoot = pPackage->getByHierarchicalName("/");
aRoot >>= xTunnel;
2011-03-09 17:29:09 +01:00
uno::Reference< container::XNameContainer > xRootNameContainer( xTunnel, UNO_QUERY );
if ( !xRootNameContainer.is() )
throw RuntimeException(THROW_WHERE );
2011-03-09 17:29:09 +01:00
uno::Reference< XUnoTunnel > xNPSTunnel( xNewPackStream, UNO_QUERY );
xRootNameContainer->insertByName("dummy", makeAny( xNPSTunnel ) );
// commit the temporary package
pPackage->commitChanges();
// get raw stream from the temporary package
2011-03-09 17:29:09 +01:00
uno::Reference< io::XInputStream > xInRaw;
if ( bAddHeaderForEncr )
xInRaw = xNewPackStream->getRawStream();
else
xInRaw = xNewPackStream->getPlainRawStream();
// create another temporary file
uno::Reference < io::XOutputStream > xTempOut(
io::TempFile::create(m_xContext),
uno::UNO_QUERY_THROW );
uno::Reference < io::XInputStream > xTempIn( xTempOut, UNO_QUERY_THROW );
uno::Reference < io::XSeekable > xTempSeek( xTempOut, UNO_QUERY_THROW );
// copy the raw stream to the temporary file
::comphelper::OStorageHelper::CopyInputToOutput( xInRaw, xTempOut );
xTempOut->closeOutput();
xTempSeek->seek( 0 );
// close raw stream, package stream and folder
2011-03-09 17:29:09 +01:00
xInRaw = uno::Reference< io::XInputStream >();
xNewPSProps = uno::Reference< XPropertySet >();
xNPSTunnel = uno::Reference< XUnoTunnel >();
xNewPackStream = uno::Reference< XDataSinkEncrSupport >();
xTunnel = uno::Reference< XUnoTunnel >();
xRootNameContainer = uno::Reference< container::XNameContainer >();
// return the stream representing the first temporary file
return xTempIn;
}
catch ( RuntimeException& )
{
throw;
}
catch ( Exception& )
{
}
throw io::IOException(THROW_WHERE );
}
bool ZipPackageStream::ParsePackageRawStream()
{
OSL_ENSURE( GetOwnSeekStream().is(), "A stream must be provided!\n" );
if ( !GetOwnSeekStream().is() )
return false;
bool bOk = false;
2011-03-09 17:29:09 +01:00
::rtl::Reference< BaseEncryptionData > xTempEncrData;
sal_Int32 nMagHackSize = 0;
Sequence < sal_Int8 > aHeader ( 4 );
try
{
if ( GetOwnSeekStream()->readBytes ( aHeader, 4 ) == 4 )
{
const sal_Int8 *pHeader = aHeader.getConstArray();
sal_uInt32 nHeader = ( pHeader [0] & 0xFF ) |
( pHeader [1] & 0xFF ) << 8 |
( pHeader [2] & 0xFF ) << 16 |
( pHeader [3] & 0xFF ) << 24;
if ( nHeader == n_ConstHeader )
{
// this is one of our god-awful, but extremely devious hacks, everyone cheer
2011-03-09 17:29:09 +01:00
xTempEncrData = new BaseEncryptionData;
OUString aMediaType;
2011-03-09 17:29:09 +01:00
sal_Int32 nEncAlgorithm = 0;
sal_Int32 nChecksumAlgorithm = 0;
sal_Int32 nDerivedKeySize = 0;
sal_Int32 nStartKeyGenID = 0;
if ( ZipFile::StaticFillData( xTempEncrData, nEncAlgorithm, nChecksumAlgorithm, nDerivedKeySize, nStartKeyGenID, nMagHackSize, aMediaType, GetOwnSeekStream() ) )
{
// We'll want to skip the data we've just read, so calculate how much we just read
// and remember it
2011-03-09 17:29:09 +01:00
m_nMagicalHackPos = n_ConstHeaderSize + xTempEncrData->m_aSalt.getLength()
+ xTempEncrData->m_aInitVector.getLength()
+ xTempEncrData->m_aDigest.getLength()
+ aMediaType.getLength() * sizeof( sal_Unicode );
2011-03-09 17:29:09 +01:00
m_nImportedEncryptionAlgorithm = nEncAlgorithm;
m_nImportedChecksumAlgorithm = nChecksumAlgorithm;
m_nImportedDerivedKeySize = nDerivedKeySize;
m_nImportedStartKeyAlgorithm = nStartKeyGenID;
m_nMagicalHackSize = nMagHackSize;
msMediaType = aMediaType;
bOk = true;
}
}
}
}
catch( Exception& )
{
}
if ( !bOk )
{
// the provided stream is not a raw stream
return false;
}
2011-03-09 17:29:09 +01:00
m_xBaseEncryptionData = xTempEncrData;
SetIsEncrypted ( true );
// it's already compressed and encrypted
m_bToBeEncrypted = m_bToBeCompressed = false;
return true;
}
static void ImplSetStoredData( ZipEntry & rEntry, uno::Reference< io::XInputStream> & rStream )
{
// It's very annoying that we have to do this, but lots of zip packages
// don't allow data descriptors for STORED streams, meaning we have to
// know the size and CRC32 of uncompressed streams before we actually
// write them !
CRC32 aCRC32;
rEntry.nMethod = STORED;
rEntry.nCompressedSize = rEntry.nSize = aCRC32.updateStream ( rStream );
rEntry.nCrc = aCRC32.getValue();
}
bool ZipPackageStream::saveChild(
const OUString &rPath,
std::vector < uno::Sequence < beans::PropertyValue > > &rManList,
ZipOutputStream & rZipOut,
const uno::Sequence < sal_Int8 >& rEncryptionKey,
const rtlRandomPool &rRandomPool)
{
bool bSuccess = true;
const OUString sMediaTypeProperty ("MediaType");
const OUString sVersionProperty ("Version");
const OUString sFullPathProperty ("FullPath");
const OUString sInitialisationVectorProperty ("InitialisationVector");
const OUString sSaltProperty ("Salt");
const OUString sIterationCountProperty ("IterationCount");
const OUString sSizeProperty ("Size");
const OUString sDigestProperty ("Digest");
const OUString sEncryptionAlgProperty ("EncryptionAlgorithm");
const OUString sStartKeyAlgProperty ("StartKeyAlgorithm");
const OUString sDigestAlgProperty ("DigestAlgorithm");
const OUString sDerivedKeySizeProperty ("DerivedKeySize");
uno::Sequence < beans::PropertyValue > aPropSet (PKG_SIZE_NOENCR_MNFST);
// if pTempEntry is necessary, it will be released and passed to the ZipOutputStream
// and be deleted in the ZipOutputStream destructor
std::unique_ptr < ZipEntry > pAutoTempEntry ( new ZipEntry );
ZipEntry* pTempEntry = pAutoTempEntry.get();
// In case the entry we are reading is also the entry we are writing, we will
// store the ZipEntry data in pTempEntry
ZipPackageFolder::copyZipEntry ( *pTempEntry, aEntry );
pTempEntry->sPath = rPath;
pTempEntry->nPathLen = (sal_Int16)( OUStringToOString( pTempEntry->sPath, RTL_TEXTENCODING_UTF8 ).getLength() );
const bool bToBeEncrypted = m_bToBeEncrypted && (rEncryptionKey.getLength() || m_bHaveOwnKey);
const bool bToBeCompressed = bToBeEncrypted ? sal_True : m_bToBeCompressed;
aPropSet[PKG_MNFST_MEDIATYPE].Name = sMediaTypeProperty;
aPropSet[PKG_MNFST_MEDIATYPE].Value <<= GetMediaType( );
aPropSet[PKG_MNFST_VERSION].Name = sVersionProperty;
aPropSet[PKG_MNFST_VERSION].Value <<= OUString(); // no version is stored for streams currently
aPropSet[PKG_MNFST_FULLPATH].Name = sFullPathProperty;
aPropSet[PKG_MNFST_FULLPATH].Value <<= pTempEntry->sPath;
OSL_ENSURE( m_nStreamMode != PACKAGE_STREAM_NOTSET, "Unacceptable ZipPackageStream mode!" );
bool bRawStream = false;
if ( m_nStreamMode == PACKAGE_STREAM_DETECT )
bRawStream = ParsePackageRawStream();
else if ( m_nStreamMode == PACKAGE_STREAM_RAW )
bRawStream = true;
bool bTransportOwnEncrStreamAsRaw = false;
// During the storing the original size of the stream can be changed
// TODO/LATER: get rid of this hack
sal_Int64 nOwnStreamOrigSize = bRawStream ? m_nMagicalHackSize : aEntry.nSize;
bool bUseNonSeekableAccess = false;
uno::Reference < io::XInputStream > xStream;
if ( !IsPackageMember() && !bRawStream && !bToBeEncrypted && bToBeCompressed )
{
// the stream is not a package member, not a raw stream,
// it should not be encrypted and it should be compressed,
// in this case nonseekable access can be used
xStream = m_xStream;
uno::Reference < io::XSeekable > xSeek ( xStream, uno::UNO_QUERY );
bUseNonSeekableAccess = ( xStream.is() && !xSeek.is() );
}
if ( !bUseNonSeekableAccess )
{
xStream = getRawData();
if ( !xStream.is() )
{
OSL_FAIL( "ZipPackageStream didn't have a stream associated with it, skipping!" );
bSuccess = false;
return bSuccess;
}
uno::Reference < io::XSeekable > xSeek ( xStream, uno::UNO_QUERY );
try
{
if ( xSeek.is() )
{
// If the stream is a raw one, then we should be positioned
// at the beginning of the actual data
if ( !bToBeCompressed || bRawStream )
{
// The raw stream can neither be encrypted nor connected
OSL_ENSURE( !bRawStream || !(bToBeCompressed || bToBeEncrypted), "The stream is already encrypted!\n" );
xSeek->seek ( bRawStream ? m_nMagicalHackPos : 0 );
ImplSetStoredData ( *pTempEntry, xStream );
// TODO/LATER: Get rid of hacks related to switching of Flag Method and Size properties!
}
else if ( bToBeEncrypted )
{
// this is the correct original size
pTempEntry->nSize = xSeek->getLength();
nOwnStreamOrigSize = pTempEntry->nSize;
}
xSeek->seek ( 0 );
}
else
{
// Okay, we don't have an xSeekable stream. This is possibly bad.
// check if it's one of our own streams, if it is then we know that
// each time we ask for it we'll get a new stream that will be
// at position zero...otherwise, assert and skip this stream...
if ( IsPackageMember() )
{
// if the password has been changed than the stream should not be package member any more
if ( m_bIsEncrypted && m_bToBeEncrypted )
{
// Should be handled close to the raw stream handling
bTransportOwnEncrStreamAsRaw = true;
pTempEntry->nMethod = STORED;
// TODO/LATER: get rid of this situation
// this size should be different from the one that will be stored in manifest.xml
// it is used in storing algorithms and after storing the correct size will be set
pTempEntry->nSize = pTempEntry->nCompressedSize;
}
}
else
{
bSuccess = false;
return bSuccess;
}
}
}
catch ( uno::Exception& )
{
bSuccess = false;
return bSuccess;
}
if ( bToBeEncrypted || bRawStream || bTransportOwnEncrStreamAsRaw )
{
if ( bToBeEncrypted && !bTransportOwnEncrStreamAsRaw )
{
uno::Sequence < sal_Int8 > aSalt( 16 ), aVector( GetBlockSize() );
rtl_random_getBytes ( rRandomPool, aSalt.getArray(), 16 );
rtl_random_getBytes ( rRandomPool, aVector.getArray(), aVector.getLength() );
sal_Int32 nIterationCount = 1024;
if ( !m_bHaveOwnKey )
{
m_aEncryptionKey = rEncryptionKey;
m_aStorageEncryptionKeys.realloc( 0 );
}
setInitialisationVector ( aVector );
setSalt ( aSalt );
setIterationCount ( nIterationCount );
}
// last property is digest, which is inserted later if we didn't have
// a magic header
aPropSet.realloc(PKG_SIZE_ENCR_MNFST);
aPropSet[PKG_MNFST_INIVECTOR].Name = sInitialisationVectorProperty;
aPropSet[PKG_MNFST_INIVECTOR].Value <<= m_xBaseEncryptionData->m_aInitVector;
aPropSet[PKG_MNFST_SALT].Name = sSaltProperty;
aPropSet[PKG_MNFST_SALT].Value <<= m_xBaseEncryptionData->m_aSalt;
aPropSet[PKG_MNFST_ITERATION].Name = sIterationCountProperty;
aPropSet[PKG_MNFST_ITERATION].Value <<= m_xBaseEncryptionData->m_nIterationCount;
// Need to store the uncompressed size in the manifest
OSL_ENSURE( nOwnStreamOrigSize >= 0, "The stream size was not correctly initialized!\n" );
aPropSet[PKG_MNFST_UCOMPSIZE].Name = sSizeProperty;
aPropSet[PKG_MNFST_UCOMPSIZE].Value <<= nOwnStreamOrigSize;
if ( bRawStream || bTransportOwnEncrStreamAsRaw )
{
::rtl::Reference< EncryptionData > xEncData = GetEncryptionData();
if ( !xEncData.is() )
throw uno::RuntimeException();
aPropSet[PKG_MNFST_DIGEST].Name = sDigestProperty;
aPropSet[PKG_MNFST_DIGEST].Value <<= m_xBaseEncryptionData->m_aDigest;
aPropSet[PKG_MNFST_ENCALG].Name = sEncryptionAlgProperty;
aPropSet[PKG_MNFST_ENCALG].Value <<= xEncData->m_nEncAlg;
aPropSet[PKG_MNFST_STARTALG].Name = sStartKeyAlgProperty;
aPropSet[PKG_MNFST_STARTALG].Value <<= xEncData->m_nStartKeyGenID;
aPropSet[PKG_MNFST_DIGESTALG].Name = sDigestAlgProperty;
aPropSet[PKG_MNFST_DIGESTALG].Value <<= xEncData->m_nCheckAlg;
aPropSet[PKG_MNFST_DERKEYSIZE].Name = sDerivedKeySizeProperty;
aPropSet[PKG_MNFST_DERKEYSIZE].Value <<= xEncData->m_nDerivedKeySize;
}
}
}
// If the entry is already stored in the zip file in the format we
// want for this write...copy it raw
if ( !bUseNonSeekableAccess
&& ( bRawStream || bTransportOwnEncrStreamAsRaw
|| ( IsPackageMember() && !bToBeEncrypted
&& ( ( aEntry.nMethod == DEFLATED && bToBeCompressed )
|| ( aEntry.nMethod == STORED && !bToBeCompressed ) ) ) ) )
{
// If it's a PackageMember, then it's an unbuffered stream and we need
// to get a new version of it as we can't seek backwards.
if ( IsPackageMember() )
{
xStream = getRawData();
if ( !xStream.is() )
{
// Make sure that we actually _got_ a new one !
bSuccess = false;
return bSuccess;
}
}
try
{
if ( bRawStream )
xStream->skipBytes( m_nMagicalHackPos );
rZipOut.putNextEntry(*pTempEntry);
// the entry is provided to the ZipOutputStream that will delete it
pAutoTempEntry.release();
uno::Sequence < sal_Int8 > aSeq ( n_ConstBufferSize );
sal_Int32 nLength;
do
{
nLength = xStream->readBytes( aSeq, n_ConstBufferSize );
rZipOut.rawWrite(aSeq, 0, nLength);
}
while ( nLength == n_ConstBufferSize );
rZipOut.rawCloseEntry();
}
catch ( ZipException& )
{
bSuccess = false;
}
catch ( io::IOException& )
{
bSuccess = false;
}
}
else
{
// This stream is defenitly not a raw stream
// If nonseekable access is used the stream should be at the beginning and
// is useless after the storing. Thus if the storing fails the package should
// be thrown away ( as actually it is done currently )!
// To allow to reuse the package after the error, the optimization must be removed!
// If it's a PackageMember, then our previous reference held a 'raw' stream
// so we need to re-get it, unencrypted, uncompressed and positioned at the
// beginning of the stream
if ( IsPackageMember() )
{
xStream = getInputStream();
if ( !xStream.is() )
{
// Make sure that we actually _got_ a new one !
bSuccess = false;
return bSuccess;
}
}
if ( bToBeCompressed )
{
pTempEntry->nMethod = DEFLATED;
pTempEntry->nCrc = -1;
pTempEntry->nCompressedSize = pTempEntry->nSize = -1;
}
try
{
rZipOut.putNextEntry(*pTempEntry, bToBeEncrypted);
// the entry is provided to the ZipOutputStream that will delete it
pAutoTempEntry.release();
sal_Int32 nLength;
uno::Sequence < sal_Int8 > aSeq (n_ConstBufferSize);
if (pTempEntry->nMethod == STORED)
{
do
{
nLength = xStream->readBytes(aSeq, n_ConstBufferSize);
rZipOut.rawWrite(aSeq, 0, nLength);
}
while ( nLength == n_ConstBufferSize );
}
else
{
ZipOutputEntry aZipEntry(m_xContext, *pTempEntry, this, bToBeEncrypted);
do
{
nLength = xStream->readBytes(aSeq, n_ConstBufferSize);
aZipEntry.write(aSeq, 0, nLength);
}
while ( nLength == n_ConstBufferSize );
aZipEntry.closeEntry();
uno::Sequence< sal_Int8 > aCompressedData = aZipEntry.getData();
rZipOut.rawWrite(aCompressedData, 0, aCompressedData.getLength());
}
rZipOut.rawCloseEntry();
}
catch ( ZipException& )
{
bSuccess = false;
}
catch ( io::IOException& )
{
bSuccess = false;
}
if ( bToBeEncrypted )
{
::rtl::Reference< EncryptionData > xEncData = GetEncryptionData();
if ( !xEncData.is() )
throw uno::RuntimeException();
aPropSet[PKG_MNFST_DIGEST].Name = sDigestProperty;
aPropSet[PKG_MNFST_DIGEST].Value <<= m_xBaseEncryptionData->m_aDigest;
aPropSet[PKG_MNFST_ENCALG].Name = sEncryptionAlgProperty;
aPropSet[PKG_MNFST_ENCALG].Value <<= xEncData->m_nEncAlg;
aPropSet[PKG_MNFST_STARTALG].Name = sStartKeyAlgProperty;
aPropSet[PKG_MNFST_STARTALG].Value <<= xEncData->m_nStartKeyGenID;
aPropSet[PKG_MNFST_DIGESTALG].Name = sDigestAlgProperty;
aPropSet[PKG_MNFST_DIGESTALG].Value <<= xEncData->m_nCheckAlg;
aPropSet[PKG_MNFST_DERKEYSIZE].Name = sDerivedKeySizeProperty;
aPropSet[PKG_MNFST_DERKEYSIZE].Value <<= xEncData->m_nDerivedKeySize;
SetIsEncrypted ( true );
}
}
if( bSuccess )
{
if ( !IsPackageMember() )
{
CloseOwnStreamIfAny();
SetPackageMember ( true );
}
if ( bRawStream )
{
// the raw stream was integrated and now behaves
// as usual encrypted stream
SetToBeEncrypted( true );
}
// Then copy it back afterwards...
ZipPackageFolder::copyZipEntry ( aEntry, *pTempEntry );
// TODO/LATER: get rid of this hack ( the encrypted stream size property is changed during saving )
if ( IsEncrypted() )
setSize( nOwnStreamOrigSize );
aEntry.nOffset *= -1;
}
if ( aPropSet.getLength()
&& ( m_nFormat == embed::StorageFormats::PACKAGE || m_nFormat == embed::StorageFormats::OFOPXML ) )
rManList.push_back( aPropSet );
return bSuccess;
}
void ZipPackageStream::SetPackageMember( bool bNewValue )
{
if ( bNewValue )
{
m_nStreamMode = PACKAGE_STREAM_PACKAGEMEMBER;
m_nMagicalHackPos = 0;
m_nMagicalHackSize = 0;
}
else if ( m_nStreamMode == PACKAGE_STREAM_PACKAGEMEMBER )
m_nStreamMode = PACKAGE_STREAM_NOTSET; // must be reset
}
// XActiveDataSink
2011-03-09 17:29:09 +01:00
void SAL_CALL ZipPackageStream::setInputStream( const uno::Reference< io::XInputStream >& aStream )
throw( RuntimeException, std::exception )
{
// if seekable access is required the wrapping will be done on demand
m_xStream = aStream;
2011-03-09 17:29:09 +01:00
m_nImportedEncryptionAlgorithm = 0;
m_bHasSeekable = false;
SetPackageMember ( false );
2000-11-28 15:49:34 +00:00
aEntry.nTime = -1;
m_nStreamMode = PACKAGE_STREAM_DETECT;
}
2011-03-09 17:29:09 +01:00
uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getRawData()
throw( RuntimeException )
{
try
{
2011-03-09 17:29:09 +01:00
if ( IsPackageMember() )
{
return m_rZipPackage.getZipFile().getRawData( aEntry, GetEncryptionData(), m_bIsEncrypted, m_rZipPackage.GetSharedMutexRef() );
}
else if ( GetOwnSeekStream().is() )
{
return new WrapStreamForShare( GetOwnSeekStream(), m_rZipPackage.GetSharedMutexRef() );
}
else
2011-03-09 17:29:09 +01:00
return uno::Reference < io::XInputStream > ();
}
2011-03-09 17:29:09 +01:00
catch ( ZipException & )//rException )
{
Merge commit 'ooo/DEV300_m106' into libreoffice-3-4 Conflicts: extensions/source/svg/svgaction.cxx extensions/source/svg/svgaction.hxx extensions/source/svg/svgcom.hxx extensions/source/svg/svgprinter.cxx extensions/source/svg/svgprinter.hxx extensions/source/svg/svguno.cxx extensions/source/svg/svgwriter.cxx extensions/source/svg/svgwriter.hxx javainstaller2/src/JavaSetup/org/openoffice/setup/Controller/InstallationOngoingCtrl.java javainstaller2/src/JavaSetup/org/openoffice/setup/InstallData.java javainstaller2/src/JavaSetup/org/openoffice/setup/Installer/LinuxInstaller.java package/inc/ZipFile.hxx package/inc/ZipOutputStream.hxx package/inc/ZipPackage.hxx package/inc/ZipPackageStream.hxx package/source/manifest/ManifestExport.cxx package/source/manifest/ManifestImport.cxx package/source/manifest/UnoRegister.cxx package/source/xstor/owriteablestream.cxx package/source/xstor/xstorage.cxx package/source/xstor/xstorage.hxx package/source/zipapi/EntryInputStream.cxx package/source/zipapi/EntryInputStream.hxx package/source/zipapi/XFileStream.cxx package/source/zipapi/XFileStream.hxx package/source/zipapi/XMemoryStream.cxx package/source/zipapi/XUnbufferedStream.cxx package/source/zipapi/XUnbufferedStream.hxx package/source/zipapi/ZipFile.cxx package/source/zipapi/ZipOutputStream.cxx package/source/zipapi/sha1context.hxx package/source/zippackage/ZipPackage.cxx package/source/zippackage/ZipPackageFolder.cxx package/source/zippackage/ZipPackageStream.cxx setup_native/source/win32/customactions/shellextensions/registerextensions.cxx wizards/com/sun/star/wizards/letter/LetterWizardDialogImpl.java xmlsecurity/prj/build.lst xmlsecurity/source/helper/xmlsignaturehelper.cxx xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.cxx xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.hxx
2011-04-22 15:08:05 +02:00
OSL_FAIL( "ZipException thrown" );//rException.Message);
2011-03-09 17:29:09 +01:00
return uno::Reference < io::XInputStream > ();
}
2011-03-09 17:29:09 +01:00
catch ( Exception & )
{
Merge commit 'ooo/DEV300_m106' into libreoffice-3-4 Conflicts: extensions/source/svg/svgaction.cxx extensions/source/svg/svgaction.hxx extensions/source/svg/svgcom.hxx extensions/source/svg/svgprinter.cxx extensions/source/svg/svgprinter.hxx extensions/source/svg/svguno.cxx extensions/source/svg/svgwriter.cxx extensions/source/svg/svgwriter.hxx javainstaller2/src/JavaSetup/org/openoffice/setup/Controller/InstallationOngoingCtrl.java javainstaller2/src/JavaSetup/org/openoffice/setup/InstallData.java javainstaller2/src/JavaSetup/org/openoffice/setup/Installer/LinuxInstaller.java package/inc/ZipFile.hxx package/inc/ZipOutputStream.hxx package/inc/ZipPackage.hxx package/inc/ZipPackageStream.hxx package/source/manifest/ManifestExport.cxx package/source/manifest/ManifestImport.cxx package/source/manifest/UnoRegister.cxx package/source/xstor/owriteablestream.cxx package/source/xstor/xstorage.cxx package/source/xstor/xstorage.hxx package/source/zipapi/EntryInputStream.cxx package/source/zipapi/EntryInputStream.hxx package/source/zipapi/XFileStream.cxx package/source/zipapi/XFileStream.hxx package/source/zipapi/XMemoryStream.cxx package/source/zipapi/XUnbufferedStream.cxx package/source/zipapi/XUnbufferedStream.hxx package/source/zipapi/ZipFile.cxx package/source/zipapi/ZipOutputStream.cxx package/source/zipapi/sha1context.hxx package/source/zippackage/ZipPackage.cxx package/source/zippackage/ZipPackageFolder.cxx package/source/zippackage/ZipPackageStream.cxx setup_native/source/win32/customactions/shellextensions/registerextensions.cxx wizards/com/sun/star/wizards/letter/LetterWizardDialogImpl.java xmlsecurity/prj/build.lst xmlsecurity/source/helper/xmlsignaturehelper.cxx xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.cxx xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.hxx
2011-04-22 15:08:05 +02:00
OSL_FAIL( "Exception is thrown during stream wrapping!\n" );
2011-03-09 17:29:09 +01:00
return uno::Reference < io::XInputStream > ();
}
}
2011-03-09 17:29:09 +01:00
uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getInputStream()
throw( RuntimeException, std::exception )
{
try
2000-12-04 10:30:09 +00:00
{
2011-03-09 17:29:09 +01:00
if ( IsPackageMember() )
2000-12-04 10:30:09 +00:00
{
return m_rZipPackage.getZipFile().getInputStream( aEntry, GetEncryptionData(), m_bIsEncrypted, m_rZipPackage.GetSharedMutexRef() );
2000-12-04 10:30:09 +00:00
}
else if ( GetOwnSeekStream().is() )
2000-12-04 10:30:09 +00:00
{
return new WrapStreamForShare( GetOwnSeekStream(), m_rZipPackage.GetSharedMutexRef() );
2000-12-04 10:30:09 +00:00
}
else
2011-03-09 17:29:09 +01:00
return uno::Reference < io::XInputStream > ();
}
2011-03-09 17:29:09 +01:00
catch ( ZipException & )//rException )
{
Merge commit 'ooo/DEV300_m106' into libreoffice-3-4 Conflicts: extensions/source/svg/svgaction.cxx extensions/source/svg/svgaction.hxx extensions/source/svg/svgcom.hxx extensions/source/svg/svgprinter.cxx extensions/source/svg/svgprinter.hxx extensions/source/svg/svguno.cxx extensions/source/svg/svgwriter.cxx extensions/source/svg/svgwriter.hxx javainstaller2/src/JavaSetup/org/openoffice/setup/Controller/InstallationOngoingCtrl.java javainstaller2/src/JavaSetup/org/openoffice/setup/InstallData.java javainstaller2/src/JavaSetup/org/openoffice/setup/Installer/LinuxInstaller.java package/inc/ZipFile.hxx package/inc/ZipOutputStream.hxx package/inc/ZipPackage.hxx package/inc/ZipPackageStream.hxx package/source/manifest/ManifestExport.cxx package/source/manifest/ManifestImport.cxx package/source/manifest/UnoRegister.cxx package/source/xstor/owriteablestream.cxx package/source/xstor/xstorage.cxx package/source/xstor/xstorage.hxx package/source/zipapi/EntryInputStream.cxx package/source/zipapi/EntryInputStream.hxx package/source/zipapi/XFileStream.cxx package/source/zipapi/XFileStream.hxx package/source/zipapi/XMemoryStream.cxx package/source/zipapi/XUnbufferedStream.cxx package/source/zipapi/XUnbufferedStream.hxx package/source/zipapi/ZipFile.cxx package/source/zipapi/ZipOutputStream.cxx package/source/zipapi/sha1context.hxx package/source/zippackage/ZipPackage.cxx package/source/zippackage/ZipPackageFolder.cxx package/source/zippackage/ZipPackageStream.cxx setup_native/source/win32/customactions/shellextensions/registerextensions.cxx wizards/com/sun/star/wizards/letter/LetterWizardDialogImpl.java xmlsecurity/prj/build.lst xmlsecurity/source/helper/xmlsignaturehelper.cxx xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.cxx xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.hxx
2011-04-22 15:08:05 +02:00
OSL_FAIL( "ZipException thrown" );//rException.Message);
2011-03-09 17:29:09 +01:00
return uno::Reference < io::XInputStream > ();
}
catch ( Exception &ex )
{
Merge commit 'ooo/DEV300_m106' into libreoffice-3-4 Conflicts: extensions/source/svg/svgaction.cxx extensions/source/svg/svgaction.hxx extensions/source/svg/svgcom.hxx extensions/source/svg/svgprinter.cxx extensions/source/svg/svgprinter.hxx extensions/source/svg/svguno.cxx extensions/source/svg/svgwriter.cxx extensions/source/svg/svgwriter.hxx javainstaller2/src/JavaSetup/org/openoffice/setup/Controller/InstallationOngoingCtrl.java javainstaller2/src/JavaSetup/org/openoffice/setup/InstallData.java javainstaller2/src/JavaSetup/org/openoffice/setup/Installer/LinuxInstaller.java package/inc/ZipFile.hxx package/inc/ZipOutputStream.hxx package/inc/ZipPackage.hxx package/inc/ZipPackageStream.hxx package/source/manifest/ManifestExport.cxx package/source/manifest/ManifestImport.cxx package/source/manifest/UnoRegister.cxx package/source/xstor/owriteablestream.cxx package/source/xstor/xstorage.cxx package/source/xstor/xstorage.hxx package/source/zipapi/EntryInputStream.cxx package/source/zipapi/EntryInputStream.hxx package/source/zipapi/XFileStream.cxx package/source/zipapi/XFileStream.hxx package/source/zipapi/XMemoryStream.cxx package/source/zipapi/XUnbufferedStream.cxx package/source/zipapi/XUnbufferedStream.hxx package/source/zipapi/ZipFile.cxx package/source/zipapi/ZipOutputStream.cxx package/source/zipapi/sha1context.hxx package/source/zippackage/ZipPackage.cxx package/source/zippackage/ZipPackageFolder.cxx package/source/zippackage/ZipPackageStream.cxx setup_native/source/win32/customactions/shellextensions/registerextensions.cxx wizards/com/sun/star/wizards/letter/LetterWizardDialogImpl.java xmlsecurity/prj/build.lst xmlsecurity/source/helper/xmlsignaturehelper.cxx xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.cxx xmlsecurity/source/xmlsec/nss/seinitializer_nssimpl.hxx
2011-04-22 15:08:05 +02:00
OSL_FAIL( "Exception is thrown during stream wrapping!\n" );
OSL_FAIL(OUStringToOString(ex.Message, RTL_TEXTENCODING_UTF8).getStr());
2012-02-17 16:32:02 +00:00
(void)ex;
2011-03-09 17:29:09 +01:00
return uno::Reference < io::XInputStream > ();
2000-12-04 10:30:09 +00:00
}
}
// XDataSinkEncrSupport
2011-03-09 17:29:09 +01:00
uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getDataStream()
throw ( packages::WrongPasswordException, ZipException,
io::IOException,
RuntimeException, std::exception )
{
// There is no stream attached to this object
if ( m_nStreamMode == PACKAGE_STREAM_NOTSET )
2011-03-09 17:29:09 +01:00
return uno::Reference< io::XInputStream >();
// this method can not be used together with old approach
if ( m_nStreamMode == PACKAGE_STREAM_DETECT )
throw packages::zip::ZipIOException(THROW_WHERE );
2011-03-09 17:29:09 +01:00
if ( IsPackageMember() )
{
2011-03-09 17:29:09 +01:00
uno::Reference< io::XInputStream > xResult;
try
{
xResult = m_rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData(), m_bIsEncrypted, m_rZipPackage.GetSharedMutexRef() );
2011-03-09 17:29:09 +01:00
}
catch( const packages::WrongPasswordException& )
2011-03-09 17:29:09 +01:00
{
if ( m_rZipPackage.GetStartKeyGenID() == xml::crypto::DigestID::SHA1 )
2011-03-09 17:29:09 +01:00
{
try
{
// rhbz#1013844 / fdo#47482 workaround for the encrypted
// OpenOffice.org 1.0 documents generated by Libreoffice <=
// 3.6 with the new encryption format and using SHA256, but
// missing a specified startkey of SHA256
// force SHA256 and see if that works
m_nImportedStartKeyAlgorithm = xml::crypto::DigestID::SHA256;
xResult = m_rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData(), m_bIsEncrypted, m_rZipPackage.GetSharedMutexRef() );
return xResult;
}
catch (const packages::WrongPasswordException&)
{
// if that didn't work, restore to SHA1 and trundle through the *other* earlier
// bug fix
m_nImportedStartKeyAlgorithm = xml::crypto::DigestID::SHA1;
}
// workaround for the encrypted documents generated with the old OOo1.x bug.
if ( !m_bUseWinEncoding )
{
xResult = m_rZipPackage.getZipFile().getDataStream( aEntry, GetEncryptionData( true ), m_bIsEncrypted, m_rZipPackage.GetSharedMutexRef() );
m_bUseWinEncoding = true;
}
else
throw;
2011-03-09 17:29:09 +01:00
}
else
throw;
}
return xResult;
}
else if ( m_nStreamMode == PACKAGE_STREAM_RAW )
return ZipFile::StaticGetDataFromRawStream( m_xContext, GetOwnSeekStream(), GetEncryptionData() );
else if ( GetOwnSeekStream().is() )
{
return new WrapStreamForShare( GetOwnSeekStream(), m_rZipPackage.GetSharedMutexRef() );
}
else
return uno::Reference< io::XInputStream >();
}
2011-03-09 17:29:09 +01:00
uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getRawStream()
throw ( packages::NoEncryptionException,
io::IOException,
uno::RuntimeException, std::exception )
{
// There is no stream attached to this object
if ( m_nStreamMode == PACKAGE_STREAM_NOTSET )
2011-03-09 17:29:09 +01:00
return uno::Reference< io::XInputStream >();
// this method can not be used together with old approach
if ( m_nStreamMode == PACKAGE_STREAM_DETECT )
throw packages::zip::ZipIOException(THROW_WHERE );
2011-03-09 17:29:09 +01:00
if ( IsPackageMember() )
{
if ( !m_bIsEncrypted || !GetEncryptionData().is() )
throw packages::NoEncryptionException(THROW_WHERE );
return m_rZipPackage.getZipFile().getWrappedRawStream( aEntry, GetEncryptionData(), msMediaType, m_rZipPackage.GetSharedMutexRef() );
}
else if ( GetOwnSeekStream().is() )
{
if ( m_nStreamMode == PACKAGE_STREAM_RAW )
{
return new WrapStreamForShare( GetOwnSeekStream(), m_rZipPackage.GetSharedMutexRef() );
}
else if ( m_nStreamMode == PACKAGE_STREAM_DATA && m_bToBeEncrypted )
return TryToGetRawFromDataStream( true );
}
throw packages::NoEncryptionException(THROW_WHERE );
}
2011-03-09 17:29:09 +01:00
void SAL_CALL ZipPackageStream::setDataStream( const uno::Reference< io::XInputStream >& aStream )
throw ( io::IOException,
RuntimeException, std::exception )
{
setInputStream( aStream );
m_nStreamMode = PACKAGE_STREAM_DATA;
}
2011-03-09 17:29:09 +01:00
void SAL_CALL ZipPackageStream::setRawStream( const uno::Reference< io::XInputStream >& aStream )
throw ( packages::EncryptionNotAllowedException,
packages::NoRawFormatException,
io::IOException,
RuntimeException, std::exception )
{
// wrap the stream in case it is not seekable
uno::Reference< io::XInputStream > xNewStream = ::comphelper::OSeekableInputWrapper::CheckSeekableCanWrap( aStream, m_xContext );
2011-03-09 17:29:09 +01:00
uno::Reference< io::XSeekable > xSeek( xNewStream, UNO_QUERY );
if ( !xSeek.is() )
throw RuntimeException(THROW_WHERE "The stream must support XSeekable!" );
xSeek->seek( 0 );
uno::Reference< io::XInputStream > xOldStream = m_xStream;
m_xStream = xNewStream;
if ( !ParsePackageRawStream() )
{
m_xStream = xOldStream;
throw packages::NoRawFormatException(THROW_WHERE );
}
// the raw stream MUST have seekable access
m_bHasSeekable = true;
SetPackageMember ( false );
aEntry.nTime = -1;
m_nStreamMode = PACKAGE_STREAM_RAW;
}
uno::Reference< io::XInputStream > SAL_CALL ZipPackageStream::getPlainRawStream()
throw ( io::IOException, packages::NoEncryptionException,
uno::RuntimeException, std::exception )
{
// There is no stream attached to this object
if ( m_nStreamMode == PACKAGE_STREAM_NOTSET )
2011-03-09 17:29:09 +01:00
return uno::Reference< io::XInputStream >();
// this method can not be used together with old approach
if ( m_nStreamMode == PACKAGE_STREAM_DETECT )
throw packages::zip::ZipIOException(THROW_WHERE );
2011-03-09 17:29:09 +01:00
if ( IsPackageMember() )
{
return m_rZipPackage.getZipFile().getRawData( aEntry, GetEncryptionData(), m_bIsEncrypted, m_rZipPackage.GetSharedMutexRef() );
}
else if ( GetOwnSeekStream().is() )
{
if ( m_nStreamMode == PACKAGE_STREAM_RAW )
{
// the header should not be returned here
return GetRawEncrStreamNoHeaderCopy();
}
else if ( m_nStreamMode == PACKAGE_STREAM_DATA )
return TryToGetRawFromDataStream( false );
}
2011-03-09 17:29:09 +01:00
return uno::Reference< io::XInputStream >();
}
// XUnoTunnel
sal_Int64 SAL_CALL ZipPackageStream::getSomething( const Sequence< sal_Int8 >& aIdentifier )
throw( RuntimeException, std::exception )
{
sal_Int64 nMe = 0;
if ( aIdentifier.getLength() == 16 &&
0 == memcmp( static_getImplementationId().getConstArray(), aIdentifier.getConstArray(), 16 ) )
nMe = reinterpret_cast < sal_Int64 > ( this );
return nMe;
}
// XPropertySet
void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName, const Any& aValue )
throw( beans::UnknownPropertyException, beans::PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException, std::exception )
{
if ( aPropertyName == "MediaType" )
{
if ( m_rZipPackage.getFormat() != embed::StorageFormats::PACKAGE && m_rZipPackage.getFormat() != embed::StorageFormats::OFOPXML )
throw beans::PropertyVetoException(THROW_WHERE );
if ( aValue >>= msMediaType )
{
if ( !msMediaType.isEmpty() )
{
if ( msMediaType.indexOf ( "text" ) != -1
|| msMediaType == "application/vnd.sun.star.oleobject" )
m_bToBeCompressed = true;
else if ( !m_bCompressedIsSetFromOutside )
m_bToBeCompressed = false;
}
}
else
throw IllegalArgumentException(THROW_WHERE "MediaType must be a string!",
2011-03-09 17:29:09 +01:00
uno::Reference< XInterface >(),
2 );
}
else if ( aPropertyName == "Size" )
{
if ( !( aValue >>= aEntry.nSize ) )
throw IllegalArgumentException(THROW_WHERE "Wrong type for Size property!",
2011-03-09 17:29:09 +01:00
uno::Reference< XInterface >(),
2 );
}
else if ( aPropertyName == "Encrypted" )
{
if ( m_rZipPackage.getFormat() != embed::StorageFormats::PACKAGE )
throw beans::PropertyVetoException(THROW_WHERE );
bool bEnc = false;
if ( aValue >>= bEnc )
{
// In case of new raw stream, the stream must not be encrypted on storing
if ( bEnc && m_nStreamMode == PACKAGE_STREAM_RAW )
throw IllegalArgumentException(THROW_WHERE "Raw stream can not be encrypted on storing",
2011-03-09 17:29:09 +01:00
uno::Reference< XInterface >(),
2 );
m_bToBeEncrypted = bEnc;
if ( m_bToBeEncrypted && !m_xBaseEncryptionData.is() )
2011-03-09 17:29:09 +01:00
m_xBaseEncryptionData = new BaseEncryptionData;
}
else
throw IllegalArgumentException(THROW_WHERE "Wrong type for Encrypted property!",
2011-03-09 17:29:09 +01:00
uno::Reference< XInterface >(),
2 );
}
else if ( aPropertyName == ENCRYPTION_KEY_PROPERTY )
{
if ( m_rZipPackage.getFormat() != embed::StorageFormats::PACKAGE )
throw beans::PropertyVetoException(THROW_WHERE );
2011-03-09 17:29:09 +01:00
uno::Sequence< sal_Int8 > aNewKey;
if ( !( aValue >>= aNewKey ) )
{
OUString sTempString;
if ( ( aValue >>= sTempString ) )
{
CWS-TOOLING: integrate CWS encsig09 2009-09-14 15:11:29 +0200 oc r276125 : #i105049# MacroSignatur needs Macro 2009-09-09 17:09:46 +0200 jl r276005 : #i103989# could not signe encrypted doc containing a formular object 2009-09-09 13:11:24 +0200 jl r275985 : #i103989# could not signe encrypted doc containing a formular object 2009-09-08 15:54:02 +0200 mav r275934 : #i103906# fix the automation test scenario ( tempfile should be writable for the user ) 2009-09-07 14:01:39 +0200 mav r275895 : #i103906# fix the problem with reload 2009-09-07 09:34:48 +0200 mav r275871 : #i104786# do the ODF version check only for ODF documents 2009-09-07 08:19:06 +0200 mav r275870 : #i104389# fix text 2009-09-06 22:24:21 +0200 mav r275867 : #i104786# check the consistency of ODF version 2009-09-06 22:23:24 +0200 mav r275866 : #i104786# check the consistency of ODF version 2009-09-06 22:23:00 +0200 mav r275865 : #i104786# check the consistency of ODF version 2009-09-06 22:22:36 +0200 mav r275864 : #i104786# check the consistency of ODF version 2009-09-06 22:22:03 +0200 mav r275863 : #i104786# check the consistency of ODF version 2009-09-02 17:09:30 +0200 mav r275722 : #i104715# let repairing mechanics use the streams correctly 2009-09-01 16:52:49 +0200 mav r275670 : #i104389# notify user not to trust the corrupted document 2009-09-01 16:31:37 +0200 mav r275668 : #i104389# use vnd.sun.star.zip: protocol to access zip files 2009-09-01 16:30:32 +0200 mav r275667 : #i104389# use vnd.sun.star.zip: protocol to access zip files 2009-09-01 16:22:13 +0200 jl r275666 : #i104339# small content change 2009-09-01 14:20:42 +0200 jl r275660 : #i103519# remove some debug output 2009-09-01 13:51:52 +0200 jl r275659 : #i103519# NSS uses '\' for escaping in distinguished names 2009-09-01 12:49:47 +0200 mav r275655 : #i104389# use zip-mode to read from jar files 2009-09-01 12:40:22 +0200 mav r275653 : #i104389# use zip-mode to read from jar files 2009-09-01 12:32:29 +0200 mav r275652 : #i104389# use constants 2009-08-31 21:58:00 +0200 mav r275637 : #i10000# fix warning 2009-08-31 21:11:17 +0200 mav r275636 : #i104227# adding of scripting signature removes the document signature 2009-08-31 20:55:05 +0200 mav r275635 : #i103905# ZipStorage supports Compressed property 2009-08-31 20:53:55 +0200 mav r275634 : #i103905# adjust macro signature transfer to usage of ZipStorage 2009-08-31 15:30:49 +0200 jl r275609 : #i103989# warning is shown as long the user does not click 'OK' 2009-08-31 14:36:10 +0200 jl r275608 : #i103989# changed warning text when signing macro and there is a document signature. This warning is only displayed once 2009-08-31 13:34:41 +0200 mav r275603 : #i104452# disable macros in repaired documents 2009-08-31 13:33:42 +0200 mav r275602 : #i104452# disable macros in repaired documents 2009-08-31 13:03:56 +0200 jl r275600 : #i45212# signature dialog could not be started when using read-only documents 2009-08-31 09:26:13 +0200 mav r275583 : #i104578# store the additional entry as the last one to workaround parsing problem in OOo3.1 and later 2009-08-30 20:54:25 +0200 mav r275562 : #i10000# adopt for unix 2009-08-30 10:56:00 +0200 mav r275561 : CWS-TOOLING: rebase CWS encsig09 to trunk@275331 (milestone: DEV300:m56) 2009-08-28 16:34:00 +0200 mav r275539 : #i104578# write necessary info in manifest.xml for ODF1.2 encrypted document 2009-08-28 14:04:22 +0200 mav r275533 : #104587# fix handling of readonly streams 2009-08-28 13:58:10 +0200 mav r275531 : #i104389# fix the broken document handling 2009-08-28 11:40:39 +0200 mav r275522 : #i104389# fix the signature streams check 2009-08-27 21:48:12 +0200 mav r275509 : #i103927# show the warning 2009-08-27 21:47:48 +0200 mav r275508 : #i103927# show the warning 2009-08-27 16:45:59 +0200 jl r275495 : #i45212# remove unused variable 2009-08-27 16:34:00 +0200 jl r275494 : #i103989# 2009-08-27 13:54:28 +0200 jl r275482 : #i103519# fixed replacement of 'S' by 'ST' 2009-08-27 12:32:21 +0200 mav r275472 : #i10000# fix warning 2009-08-27 11:58:11 +0200 mav r275467 : #i104389# handle the entry path correctly 2009-08-26 17:18:35 +0200 jl r275438 : #i103519# subject and issuer distinguished names were not properly displayed. The strings were obtained by system functions (Windows, NSS), which use quotes to escape the values, when they contain special characters 2009-08-26 11:00:20 +0200 mav r275403 : #i10000# fix warnings 2009-08-26 08:25:45 +0200 mav r275392 : #i10000# fix warning 2009-08-26 08:02:22 +0200 mav r275391 : #i10000# adopt for linux 2009-08-26 07:40:30 +0200 mav r275390 : #i10000# fix warning 2009-08-26 07:35:28 +0200 mav r275389 : #i10000# use correct include file name 2009-08-25 15:01:41 +0200 jl r275356 : #i103989# better check for mimetype of streams 2009-08-25 09:07:09 +0200 mav r275335 : CWS-TOOLING: rebase CWS encsig09 to trunk@274622 (milestone: DEV300:m54) 2009-08-24 18:17:02 +0200 mav r275329 : #i103927# check the nonencrypted streams 2009-08-24 18:14:14 +0200 mav r275328 : #i103927# check the nonencrypted streams 2009-08-24 17:59:34 +0200 mav r275327 : #i103927#,#i104389# check the package consistency and nonencrypted streams 2009-08-24 16:18:28 +0200 jl r275323 : #i103989# added comment 2009-08-24 13:08:47 +0200 jl r275305 : #i45212# #i66276# only write the X509Certificate element once and allow to add remove several certificates at a time 2009-08-21 12:57:28 +0200 ufi r275239 : 104339 2009-08-21 08:39:05 +0200 jl r275213 : #i10398# comparing URIs of signed files with the 'element list' 2009-08-20 13:39:47 +0200 jl r275178 : #i10398# displaying 'new partially signed' status in the status bar 2009-08-20 13:35:39 +0200 jl r275177 : #i10398# displaying 'new partially signed' status in the status bar 2009-08-20 13:29:06 +0200 jl r275176 : #i10398# displaying 'new partially signed' status in the status bar 2009-08-20 13:26:21 +0200 jl r275175 : #i10398# displaying 'new partially signed' status in the status bar 2009-08-20 12:05:09 +0200 ufi r275170 : i104339 2009-08-19 12:24:54 +0200 jl r275146 : #i10398# displaying 'old signature' icon and status in signature dialog 2009-08-18 15:18:48 +0200 jl r275111 : #i103989# document signatures containing manifest.xml are now validated according to the final ODF1.2 spec 2009-08-18 11:41:06 +0200 mav r275087 : #i103927# detect if encrypted ODF1.2 document contains nonencrypted streams 2009-08-18 11:35:13 +0200 mav r275085 : #i103927# detect if encrypted ODF1.2 document contains nonencrypted streams 2009-08-14 17:32:41 +0200 jl r274999 : #i103989# using c14n tranformation for XML streams 2009-08-14 15:27:43 +0200 jl r274987 : #i103989# remove special handling for encrypted document streams in UriBindingHelper::OpenInputStream, since we use zip storage this is not necessary anymore 2009-08-14 15:08:10 +0200 jl r274983 : #i103989# Showing a message when adding or removing a macro signature, that the document signature will be removed 2009-08-14 14:57:27 +0200 jl r274982 : #i103989# accesing Sequence at invalid index 2009-08-11 08:55:02 +0200 mav r274846 : #i103905# let signing service know if there is already a valid document signature 2009-08-10 11:33:37 +0200 jl r274799 : #i103905# do not truncate the stream 2009-08-10 10:43:47 +0200 mav r274797 : #i103905# provide the storage version 2009-08-07 16:58:46 +0200 jl r274780 : #i103989# 2009-08-07 16:56:19 +0200 jl r274779 : #i103989# using odf version string etc. 2009-08-07 15:20:53 +0200 mav r274771 : #i103905# provide the storage version 2009-08-07 15:19:12 +0200 mav r274770 : #i103905# provide the storage version 2009-08-07 12:41:45 +0200 mav r274758 : #103930# do not store thumbnail in case of encrypted document 2009-08-07 12:36:52 +0200 mav r274757 : #i103905# provide the storage version 2009-08-07 12:15:54 +0200 mav r274754 : #i103760# the signed state is not lost on saving 2009-08-07 12:06:19 +0200 mav r274753 : #i103760# avoid warning regarding signature removal on export 2009-08-07 12:06:01 +0200 mav r274752 : #i103760# avoid warning regarding signature removal on export 2009-08-06 08:47:34 +0200 mav r274703 : #i103905# allow to transport ODF version to the signing component 2009-08-05 21:34:42 +0200 mav r274701 : #i103905# allow to transport ODF version to the signing component 2009-08-05 15:48:17 +0200 mav r274683 : #i103905# allow to transport ODF version to the signing component 2009-08-05 14:58:12 +0200 jl r274673 : #i103989# documentsignature now signes all streams except documentsignatures.xml, all streams are processed as binary files 2009-08-05 12:00:32 +0200 mav r274648 : #i103905# allow to transport ODF version to the signing component 2009-08-04 10:57:04 +0200 jl r274612 : #i103989# added XInitialization 2009-07-31 10:32:27 +0200 mav r274516 : #i103905# use zip storage to sign documents 2009-07-30 14:01:33 +0200 mav r274489 : #i103906# optimize the usage of temporary medium 2009-07-30 14:00:28 +0200 mav r274488 : #i103906# optimize the usage of temporary medium 2009-07-30 13:59:09 +0200 mav r274487 : #i103906# optimize the usage of temporary medium 2009-07-30 13:50:44 +0200 mav r274485 : #i103906# optimize the usage of temporary medium 2009-07-30 13:49:53 +0200 mav r274484 : #i103906# optimize the usage of temporary medium 2009-07-30 13:49:13 +0200 mav r274483 : #i103906# optimize the usage of temporary medium 2009-07-30 13:47:09 +0200 mav r274482 : #i103905#,#i103906# let the signing process use zip-storage; optimize the usage of temporary medium 2009-07-21 09:10:31 +0200 mav r274159 : CWS-TOOLING: rebase CWS encsig09 to trunk@273468 (milestone: DEV300:m51) 2009-05-05 08:39:01 +0200 mav r271496 : #i100832# allow to sign macros only when there are any
2009-09-17 13:53:54 +00:00
sal_Int32 nPathLength = sTempString.getLength();
Sequence < sal_Int8 > aSequence ( nPathLength );
sal_Int8 *pArray = aSequence.getArray();
const sal_Unicode *pChar = sTempString.getStr();
2011-03-09 17:29:09 +01:00
for ( sal_Int16 i = 0; i < nPathLength; i++ )
pArray[i] = static_cast < const sal_Int8 > ( pChar[i] );
aNewKey = aSequence;
}
else
throw IllegalArgumentException(THROW_WHERE "Wrong type for EncryptionKey property!",
2011-03-09 17:29:09 +01:00
uno::Reference< XInterface >(),
2 );
}
if ( aNewKey.getLength() )
{
2011-03-09 17:29:09 +01:00
if ( !m_xBaseEncryptionData.is() )
m_xBaseEncryptionData = new BaseEncryptionData;
m_aEncryptionKey = aNewKey;
// In case of new raw stream, the stream must not be encrypted on storing
m_bHaveOwnKey = true;
2011-03-09 17:29:09 +01:00
if ( m_nStreamMode != PACKAGE_STREAM_RAW )
m_bToBeEncrypted = true;
2011-03-09 17:29:09 +01:00
}
else
{
m_bHaveOwnKey = false;
2011-03-09 17:29:09 +01:00
m_aEncryptionKey.realloc( 0 );
}
m_aStorageEncryptionKeys.realloc( 0 );
}
else if ( aPropertyName == STORAGE_ENCRYPTION_KEYS_PROPERTY )
2011-03-09 17:29:09 +01:00
{
if ( m_rZipPackage.getFormat() != embed::StorageFormats::PACKAGE )
throw beans::PropertyVetoException(THROW_WHERE );
2011-03-09 17:29:09 +01:00
uno::Sequence< beans::NamedValue > aKeys;
if ( !( aValue >>= aKeys ) )
{
throw IllegalArgumentException(THROW_WHERE "Wrong type for StorageEncryptionKeys property!",
2011-03-09 17:29:09 +01:00
uno::Reference< XInterface >(),
2 );
}
if ( aKeys.getLength() )
{
if ( !m_xBaseEncryptionData.is() )
m_xBaseEncryptionData = new BaseEncryptionData;
m_aStorageEncryptionKeys = aKeys;
// In case of new raw stream, the stream must not be encrypted on storing
m_bHaveOwnKey = true;
if ( m_nStreamMode != PACKAGE_STREAM_RAW )
m_bToBeEncrypted = true;
}
else
2011-03-09 17:29:09 +01:00
{
m_bHaveOwnKey = false;
2011-03-09 17:29:09 +01:00
m_aStorageEncryptionKeys.realloc( 0 );
}
m_aEncryptionKey.realloc( 0 );
}
else if ( aPropertyName == "Compressed" )
{
bool bCompr = false;
if ( aValue >>= bCompr )
{
// In case of new raw stream, the stream must not be encrypted on storing
if ( bCompr && m_nStreamMode == PACKAGE_STREAM_RAW )
throw IllegalArgumentException(THROW_WHERE "Raw stream can not be encrypted on storing",
2011-03-09 17:29:09 +01:00
uno::Reference< XInterface >(),
2 );
m_bToBeCompressed = bCompr;
m_bCompressedIsSetFromOutside = true;
}
else
throw IllegalArgumentException(THROW_WHERE "Wrong type for Compressed property!",
2011-03-09 17:29:09 +01:00
uno::Reference< XInterface >(),
2 );
}
else
throw beans::UnknownPropertyException(THROW_WHERE );
}
Any SAL_CALL ZipPackageStream::getPropertyValue( const OUString& PropertyName )
throw( beans::UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception )
{
Any aAny;
if ( PropertyName == "MediaType" )
{
aAny <<= msMediaType;
return aAny;
}
else if ( PropertyName == "Size" )
{
aAny <<= aEntry.nSize;
return aAny;
}
else if ( PropertyName == "Encrypted" )
{
aAny <<= ((m_nStreamMode == PACKAGE_STREAM_RAW) || m_bToBeEncrypted);
return aAny;
}
else if ( PropertyName == "WasEncrypted" )
{
aAny <<= m_bIsEncrypted;
return aAny;
}
else if ( PropertyName == "Compressed" )
{
aAny <<= m_bToBeCompressed;
return aAny;
}
else if ( PropertyName == ENCRYPTION_KEY_PROPERTY )
{
2011-03-09 17:29:09 +01:00
aAny <<= m_aEncryptionKey;
return aAny;
}
else if ( PropertyName == STORAGE_ENCRYPTION_KEYS_PROPERTY )
{
aAny <<= m_aStorageEncryptionKeys;
return aAny;
}
else
throw beans::UnknownPropertyException(THROW_WHERE );
}
void ZipPackageStream::setSize ( const sal_Int64 nNewSize )
{
2011-03-09 17:29:09 +01:00
if ( aEntry.nCompressedSize != nNewSize )
aEntry.nMethod = DEFLATED;
aEntry.nSize = nNewSize;
}
OUString ZipPackageStream::getImplementationName()
throw ( RuntimeException, std::exception )
{
return OUString ("ZipPackageStream");
}
Sequence< OUString > ZipPackageStream::getSupportedServiceNames()
throw ( RuntimeException, std::exception )
{
2011-03-09 17:29:09 +01:00
Sequence< OUString > aNames( 1 );
aNames[0] = "com.sun.star.packages.PackageStream";
return aNames;
}
sal_Bool SAL_CALL ZipPackageStream::supportsService( OUString const & rServiceName )
throw ( RuntimeException, std::exception )
{
return cppu::supportsService(this, rServiceName);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */