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 : #ifndef INCLUDED_PACKAGE_INC_ZIPPACKAGESTREAM_HXX
20 : #define INCLUDED_PACKAGE_INC_ZIPPACKAGESTREAM_HXX
21 :
22 : #include <com/sun/star/io/XActiveDataSink.hpp>
23 : #include <com/sun/star/io/XSeekable.hpp>
24 : #include <com/sun/star/beans/NamedValue.hpp>
25 : #include <com/sun/star/packages/XDataSinkEncrSupport.hpp>
26 : #include <com/sun/star/uno/XComponentContext.hpp>
27 : #include <ZipPackageEntry.hxx>
28 : #include <rtl/ref.hxx>
29 : #include <cppuhelper/implbase2.hxx>
30 :
31 : #include <EncryptionData.hxx>
32 : #include <mutexholder.hxx>
33 :
34 : #define PACKAGE_STREAM_NOTSET 0
35 : #define PACKAGE_STREAM_PACKAGEMEMBER 1
36 : #define PACKAGE_STREAM_DETECT 2
37 : #define PACKAGE_STREAM_DATA 3
38 : #define PACKAGE_STREAM_RAW 4
39 :
40 : class ZipPackage;
41 : struct ZipEntry;
42 : class ZipPackageStream : public cppu::ImplInheritanceHelper2
43 : <
44 : ZipPackageEntry,
45 : ::com::sun::star::io::XActiveDataSink,
46 : ::com::sun::star::packages::XDataSinkEncrSupport
47 : >
48 : {
49 : private:
50 : com::sun::star::uno::Reference < com::sun::star::io::XInputStream > m_xStream;
51 : ZipPackage &m_rZipPackage;
52 : bool m_bToBeCompressed, m_bToBeEncrypted, m_bHaveOwnKey, m_bIsEncrypted;
53 :
54 : ::rtl::Reference< BaseEncryptionData > m_xBaseEncryptionData;
55 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > m_aStorageEncryptionKeys;
56 : ::com::sun::star::uno::Sequence< sal_Int8 > m_aEncryptionKey;
57 :
58 : sal_Int32 m_nImportedStartKeyAlgorithm;
59 : sal_Int32 m_nImportedEncryptionAlgorithm;
60 : sal_Int32 m_nImportedChecksumAlgorithm;
61 : sal_Int32 m_nImportedDerivedKeySize;
62 :
63 : sal_uInt8 m_nStreamMode;
64 : sal_uInt32 m_nMagicalHackPos;
65 : sal_uInt32 m_nMagicalHackSize;
66 :
67 : bool m_bHasSeekable;
68 :
69 : bool m_bCompressedIsSetFromOutside;
70 :
71 : bool m_bFromManifest;
72 :
73 : bool m_bUseWinEncoding;
74 :
75 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetOwnSeekStream();
76 :
77 : public:
78 16494 : bool IsEncrypted () const { return m_bIsEncrypted;}
79 190372 : bool IsPackageMember () const { return m_nStreamMode == PACKAGE_STREAM_PACKAGEMEMBER;}
80 :
81 9606 : bool IsFromManifest() const { return m_bFromManifest; }
82 9606 : void SetFromManifest( bool bValue ) { m_bFromManifest = bValue; }
83 :
84 : ::rtl::Reference< EncryptionData > GetEncryptionData( bool bWinEncoding = false );
85 :
86 : ::com::sun::star::uno::Sequence< sal_Int8 > GetEncryptionKey( bool bWinEncoding = false );
87 :
88 : sal_Int32 GetStartKeyGenID();
89 :
90 : sal_Int32 GetEncryptionAlgorithm() const;
91 : sal_Int32 GetBlockSize() const;
92 :
93 50 : void SetToBeCompressed (bool bNewValue) { m_bToBeCompressed = bNewValue;}
94 62 : void SetIsEncrypted (bool bNewValue) { m_bIsEncrypted = bNewValue;}
95 50 : void SetImportedStartKeyAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedStartKeyAlgorithm = nAlgorithm; }
96 50 : void SetImportedEncryptionAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedEncryptionAlgorithm = nAlgorithm; }
97 50 : void SetImportedChecksumAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedChecksumAlgorithm = nAlgorithm; }
98 50 : void SetImportedDerivedKeySize( sal_Int32 nSize ) { m_nImportedDerivedKeySize = nSize; }
99 102 : void SetToBeEncrypted (bool bNewValue)
100 : {
101 102 : m_bToBeEncrypted = bNewValue;
102 102 : if ( m_bToBeEncrypted && !m_xBaseEncryptionData.is())
103 50 : m_xBaseEncryptionData = new BaseEncryptionData;
104 52 : else if ( !m_bToBeEncrypted && m_xBaseEncryptionData.is() )
105 0 : m_xBaseEncryptionData.clear();
106 102 : }
107 : void SetPackageMember (bool bNewValue);
108 :
109 60 : void setInitialisationVector (const com::sun::star::uno::Sequence < sal_Int8 >& rNewVector )
110 60 : { m_xBaseEncryptionData->m_aInitVector = rNewVector;}
111 60 : void setSalt (const com::sun::star::uno::Sequence < sal_Int8 >& rNewSalt )
112 60 : { m_xBaseEncryptionData->m_aSalt = rNewSalt;}
113 60 : void setDigest (const com::sun::star::uno::Sequence < sal_Int8 >& rNewDigest )
114 60 : { m_xBaseEncryptionData->m_aDigest = rNewDigest;}
115 60 : void setIterationCount (const sal_Int32 nNewCount)
116 60 : { m_xBaseEncryptionData->m_nIterationCount = nNewCount;}
117 : void setSize (const sal_Int64 nNewSize);
118 :
119 : void CloseOwnStreamIfAny();
120 :
121 : ZipPackageStream( ZipPackage & rNewPackage,
122 : const css::uno::Reference < css::uno::XComponentContext >& xContext,
123 : sal_Int32 nFormat,
124 : bool bAllowRemoveOnInsert );
125 : virtual ~ZipPackageStream( void );
126 :
127 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetRawEncrStreamNoHeaderCopy();
128 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > TryToGetRawFromDataStream(
129 : bool bAddHeaderForEncr );
130 :
131 : bool ParsePackageRawStream();
132 : virtual bool saveChild( const OUString &rPath,
133 : std::vector < css::uno::Sequence < css::beans::PropertyValue > > &rManList,
134 : ZipOutputStream & rZipOut,
135 : const css::uno::Sequence < sal_Int8 >& rEncryptionKey,
136 : const rtlRandomPool &rRandomPool ) SAL_OVERRIDE;
137 :
138 : void setZipEntryOnLoading( const ZipEntry &rInEntry);
139 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawData()
140 : throw(::com::sun::star::uno::RuntimeException);
141 :
142 : static ::com::sun::star::uno::Sequence < sal_Int8 > static_getImplementationId();
143 :
144 : // XActiveDataSink
145 : virtual void SAL_CALL setInputStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& aStream )
146 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
147 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( )
148 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
149 :
150 : // XDataSinkEncrSupport
151 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getDataStream()
152 : throw ( ::com::sun::star::packages::WrongPasswordException, ::com::sun::star::packages::zip::ZipException,
153 : ::com::sun::star::io::IOException,
154 : ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
155 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawStream()
156 : throw ( ::com::sun::star::packages::NoEncryptionException,
157 : ::com::sun::star::io::IOException,
158 : ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
159 : virtual void SAL_CALL setDataStream(
160 : const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& aStream )
161 : throw ( ::com::sun::star::io::IOException,
162 : ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
163 : virtual void SAL_CALL setRawStream(
164 : const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& aStream )
165 : throw ( ::com::sun::star::packages::EncryptionNotAllowedException,
166 : ::com::sun::star::packages::NoRawFormatException,
167 : ::com::sun::star::io::IOException,
168 : ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
169 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getPlainRawStream()
170 : throw ( ::com::sun::star::io::IOException, ::com::sun::star::packages::NoEncryptionException,
171 : ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
172 :
173 : // XUnoTunnel
174 : virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier )
175 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
176 :
177 : // XPropertySet
178 : virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue )
179 : throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
180 : virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName )
181 : throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
182 :
183 : // XServiceInfo
184 : virtual OUString SAL_CALL getImplementationName( )
185 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
186 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
187 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
188 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( )
189 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
190 : };
191 : #endif
192 :
193 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|