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 _ZIP_PACKAGE_STREAM_HXX
20 : #define _ZIP_PACKAGE_STREAM_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 > xStream;
51 : const ::com::sun::star::uno::Reference < com::sun::star::uno::XComponentContext > m_xContext;
52 : ZipPackage &rZipPackage;
53 : sal_Bool bToBeCompressed, bToBeEncrypted, bHaveOwnKey, bIsEncrypted;
54 :
55 : ::rtl::Reference< BaseEncryptionData > m_xBaseEncryptionData;
56 : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > m_aStorageEncryptionKeys;
57 : ::com::sun::star::uno::Sequence< sal_Int8 > m_aEncryptionKey;
58 :
59 : sal_Int32 m_nImportedStartKeyAlgorithm;
60 : sal_Int32 m_nImportedEncryptionAlgorithm;
61 : sal_Int32 m_nImportedChecksumAlgorithm;
62 : sal_Int32 m_nImportedDerivedKeySize;
63 :
64 : sal_uInt8 m_nStreamMode;
65 : sal_uInt32 m_nMagicalHackPos;
66 : sal_uInt32 m_nMagicalHackSize;
67 :
68 : sal_Bool m_bHasSeekable;
69 :
70 : sal_Bool m_bCompressedIsSetFromOutside;
71 :
72 : sal_Bool m_bFromManifest;
73 :
74 : bool m_bUseWinEncoding;
75 :
76 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetOwnSeekStream();
77 :
78 : public:
79 450 : sal_Bool HasOwnKey () const { return bHaveOwnKey;}
80 944 : sal_Bool IsToBeCompressed () const { return bToBeCompressed;}
81 949 : sal_Bool IsToBeEncrypted () const { return bToBeEncrypted;}
82 996 : sal_Bool IsEncrypted () const { return bIsEncrypted;}
83 10205 : sal_Bool IsPackageMember () const { return m_nStreamMode == PACKAGE_STREAM_PACKAGEMEMBER;}
84 :
85 2201 : sal_Bool IsFromManifest() const { return m_bFromManifest; }
86 2201 : void SetFromManifest( sal_Bool bValue ) { m_bFromManifest = bValue; }
87 :
88 : ::rtl::Reference< EncryptionData > GetEncryptionData( bool bWinEncoding = false );
89 :
90 : ::com::sun::star::uno::Sequence< sal_Int8 > GetEncryptionKey( bool bWinEncoding = false );
91 :
92 : sal_Int32 GetStartKeyGenID();
93 :
94 5 : const com::sun::star::uno::Sequence < sal_Int8 > getInitialisationVector () const
95 5 : { return m_xBaseEncryptionData->m_aInitVector;}
96 5 : const com::sun::star::uno::Sequence < sal_Int8 > getDigest () const
97 5 : { return m_xBaseEncryptionData->m_aDigest;}
98 5 : const com::sun::star::uno::Sequence < sal_Int8 > getSalt () const
99 5 : { return m_xBaseEncryptionData->m_aSalt;}
100 5 : sal_Int32 getIterationCount () const
101 5 : { return m_xBaseEncryptionData->m_nIterationCount;}
102 949 : sal_Int64 getSize () const
103 949 : { return aEntry.nSize;}
104 :
105 1898 : sal_uInt8 GetStreamMode() const { return m_nStreamMode; }
106 0 : sal_uInt32 GetMagicalHackPos() const { return m_nMagicalHackPos; }
107 0 : sal_uInt32 GetMagicalHackSize() const { return m_nMagicalHackSize; }
108 : sal_Int32 GetEncryptionAlgorithm() const;
109 : sal_Int32 GetBlockSize() const;
110 :
111 15 : void SetToBeCompressed (sal_Bool bNewValue) { bToBeCompressed = bNewValue;}
112 20 : void SetIsEncrypted (sal_Bool bNewValue) { bIsEncrypted = bNewValue;}
113 15 : void SetImportedStartKeyAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedStartKeyAlgorithm = nAlgorithm; }
114 15 : void SetImportedEncryptionAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedEncryptionAlgorithm = nAlgorithm; }
115 15 : void SetImportedChecksumAlgorithm( sal_Int32 nAlgorithm ) { m_nImportedChecksumAlgorithm = nAlgorithm; }
116 15 : void SetImportedDerivedKeySize( sal_Int32 nSize ) { m_nImportedDerivedKeySize = nSize; }
117 30 : void SetToBeEncrypted (sal_Bool bNewValue)
118 : {
119 30 : bToBeEncrypted = bNewValue;
120 30 : if ( bToBeEncrypted && !m_xBaseEncryptionData.is())
121 15 : m_xBaseEncryptionData = new BaseEncryptionData;
122 15 : else if ( !bToBeEncrypted && m_xBaseEncryptionData.is() )
123 0 : m_xBaseEncryptionData.clear();
124 30 : }
125 : void SetPackageMember (sal_Bool bNewValue);
126 :
127 5 : void setKey (const com::sun::star::uno::Sequence < sal_Int8 >& rNewKey )
128 5 : { m_aEncryptionKey = rNewKey; m_aStorageEncryptionKeys.realloc( 0 ); }
129 20 : void setInitialisationVector (const com::sun::star::uno::Sequence < sal_Int8 >& rNewVector )
130 20 : { m_xBaseEncryptionData->m_aInitVector = rNewVector;}
131 20 : void setSalt (const com::sun::star::uno::Sequence < sal_Int8 >& rNewSalt )
132 20 : { m_xBaseEncryptionData->m_aSalt = rNewSalt;}
133 20 : void setDigest (const com::sun::star::uno::Sequence < sal_Int8 >& rNewDigest )
134 20 : { m_xBaseEncryptionData->m_aDigest = rNewDigest;}
135 20 : void setIterationCount (const sal_Int32 nNewCount)
136 20 : { m_xBaseEncryptionData->m_nIterationCount = nNewCount;}
137 : void setSize (const sal_Int64 nNewSize);
138 :
139 867 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetOwnStreamNoWrap() { return xStream; }
140 :
141 : void CloseOwnStreamIfAny();
142 :
143 : ZipPackageStream ( ZipPackage & rNewPackage,
144 : const ::com::sun::star::uno::Reference < com::sun::star::uno::XComponentContext >& xContext,
145 : sal_Bool bAllowRemoveOnInsert );
146 : virtual ~ZipPackageStream( void );
147 :
148 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetRawEncrStreamNoHeaderCopy();
149 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > TryToGetRawFromDataStream(
150 : sal_Bool bAddHeaderForEncr );
151 :
152 : sal_Bool ParsePackageRawStream();
153 :
154 : void setZipEntryOnLoading( const ZipEntry &rInEntry);
155 : ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawData()
156 : throw(::com::sun::star::uno::RuntimeException);
157 :
158 : static const ::com::sun::star::uno::Sequence < sal_Int8 >& static_getImplementationId();
159 :
160 : // XActiveDataSink
161 : virtual void SAL_CALL setInputStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& aStream )
162 : throw(::com::sun::star::uno::RuntimeException);
163 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( )
164 : throw(::com::sun::star::uno::RuntimeException);
165 :
166 : // XDataSinkEncrSupport
167 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getDataStream()
168 : throw ( ::com::sun::star::packages::WrongPasswordException,
169 : ::com::sun::star::io::IOException,
170 : ::com::sun::star::uno::RuntimeException );
171 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawStream()
172 : throw ( ::com::sun::star::packages::NoEncryptionException,
173 : ::com::sun::star::io::IOException,
174 : ::com::sun::star::uno::RuntimeException );
175 : virtual void SAL_CALL setDataStream(
176 : const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& aStream )
177 : throw ( ::com::sun::star::io::IOException,
178 : ::com::sun::star::uno::RuntimeException );
179 : virtual void SAL_CALL setRawStream(
180 : const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& aStream )
181 : throw ( ::com::sun::star::packages::EncryptionNotAllowedException,
182 : ::com::sun::star::packages::NoRawFormatException,
183 : ::com::sun::star::io::IOException,
184 : ::com::sun::star::uno::RuntimeException );
185 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getPlainRawStream()
186 : throw ( ::com::sun::star::io::IOException,
187 : ::com::sun::star::uno::RuntimeException );
188 :
189 : // XUnoTunnel
190 : virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier )
191 : throw(::com::sun::star::uno::RuntimeException);
192 :
193 : // XPropertySet
194 : virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue )
195 : 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);
196 : virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName )
197 : throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
198 :
199 : // XServiceInfo
200 : virtual OUString SAL_CALL getImplementationName( )
201 : throw (::com::sun::star::uno::RuntimeException);
202 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
203 : throw (::com::sun::star::uno::RuntimeException);
204 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( )
205 : throw (::com::sun::star::uno::RuntimeException);
206 : };
207 : #endif
208 :
209 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|