Skip to content

Commit d912f2e

Browse files
authored
Merge pull request #193 from Altinity/reverted_encrypted_disk_fix
Revert "Merge pull request ClickHouse#39761 from ClickHouse/backport/22.3/39687"
2 parents eef3761 + d83ed29 commit d912f2e

4 files changed

Lines changed: 4 additions & 74 deletions

File tree

src/IO/FileEncryptionCommon.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ class Encryptor
8080
/// the initialization vector is increased by an index of the current block
8181
/// and the index of the current block is calculated from this offset.
8282
void setOffset(size_t offset_) { offset = offset_; }
83-
size_t getOffset() const { return offset; }
8483

8584
/// Encrypts some data.
8685
/// Also the function moves `offset` by `size` (for successive encryptions).

src/IO/ReadBufferFromEncryptedFile.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ ReadBufferFromEncryptedFile::ReadBufferFromEncryptedFile(
2121
, encryptor(header_.algorithm, key_, header_.init_vector)
2222
{
2323
offset = offset_;
24+
encryptor.setOffset(offset_);
2425
need_seek = true;
2526
}
2627

@@ -59,6 +60,9 @@ off_t ReadBufferFromEncryptedFile::seek(off_t off, int whence)
5960
assert(!hasPendingData());
6061
}
6162

63+
/// The encryptor always needs to know what the current offset is.
64+
encryptor.setOffset(new_pos);
65+
6266
return new_pos;
6367
}
6468

@@ -90,10 +94,6 @@ bool ReadBufferFromEncryptedFile::nextImpl()
9094
/// The used cipher algorithms generate the same number of bytes in output as it were in input,
9195
/// so after deciphering the numbers of bytes will be still `bytes_read`.
9296
working_buffer.resize(bytes_read);
93-
94-
/// The decryptor needs to know what the current offset is (because it's used in the decryption algorithm).
95-
encryptor.setOffset(offset);
96-
9797
encryptor.decrypt(encrypted_buffer.data(), bytes_read, working_buffer.begin());
9898

9999
pos = working_buffer.begin();

src/IO/tests/gtest_file_encryption.cpp

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@
44
#include <gtest/gtest.h>
55
#include <IO/WriteBufferFromString.h>
66
#include <IO/FileEncryptionCommon.h>
7-
#include <IO/WriteBufferFromFile.h>
8-
#include <IO/WriteBufferFromEncryptedFile.h>
9-
#include <IO/ReadBufferFromEncryptedFile.h>
10-
#include <IO/ReadBufferFromFile.h>
11-
#include <IO/ReadHelpers.h>
12-
#include <Common/getRandomASCIIString.h>
13-
#include <filesystem>
147

158

169
using namespace DB;
@@ -217,48 +210,4 @@ INSTANTIATE_TEST_SUITE_P(All,
217210
})
218211
);
219212

220-
TEST(FileEncryptionPositionUpdateTest, Decryption)
221-
{
222-
String tmp_path = std::filesystem::current_path() / "test_offset_update";
223-
if (std::filesystem::exists(tmp_path))
224-
std::filesystem::remove(tmp_path);
225-
226-
String key = "1234567812345678";
227-
FileEncryption::Header header;
228-
header.algorithm = Algorithm::AES_128_CTR;
229-
header.key_id = 1;
230-
header.key_hash = calculateKeyHash(key);
231-
header.init_vector = InitVector::random();
232-
233-
auto lwb = std::make_unique<WriteBufferFromFile>(tmp_path);
234-
WriteBufferFromEncryptedFile wb(10, std::move(lwb), key, header);
235-
auto data = getRandomASCIIString(20);
236-
wb.write(data.data(), data.size());
237-
wb.finalize();
238-
239-
auto lrb = std::make_unique<ReadBufferFromFile>(tmp_path);
240-
ReadBufferFromEncryptedFile rb(10, std::move(lrb), key, header);
241-
rb.ignore(5);
242-
rb.ignore(5);
243-
rb.ignore(5);
244-
ASSERT_EQ(rb.getPosition(), 15);
245-
246-
String res;
247-
readStringUntilEOF(res, rb);
248-
ASSERT_EQ(res, data.substr(15));
249-
res.clear();
250-
251-
rb.seek(0, SEEK_SET);
252-
ASSERT_EQ(rb.getPosition(), 0);
253-
res.resize(5);
254-
rb.read(res.data(), res.size());
255-
ASSERT_EQ(res, data.substr(0, 5));
256-
res.clear();
257-
258-
rb.seek(1, SEEK_CUR);
259-
ASSERT_EQ(rb.getPosition(), 6);
260-
readStringUntilEOF(res, rb);
261-
ASSERT_EQ(res, data.substr(6));
262-
}
263-
264213
#endif

tests/integration/test_encrypted_disk/test.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -252,21 +252,3 @@ def make_storage_policy_with_keys(policy_name, keys):
252252
# Detach the part encrypted with the wrong key and check that another part containing "(2,'data'),(3,'data')" still can be read.
253253
node.query("ALTER TABLE encrypted_test DETACH PART '{}'".format(FIRST_PART_NAME))
254254
assert node.query(select_query) == "(2,'data'),(3,'data')"
255-
256-
257-
def test_read_in_order():
258-
node.query(
259-
"CREATE TABLE encrypted_test(`a` UInt64, `b` String(150)) ENGINE = MergeTree() ORDER BY (a, b) SETTINGS storage_policy='encrypted_policy'"
260-
)
261-
262-
node.query(
263-
"INSERT INTO encrypted_test SELECT * FROM generateRandom('a UInt64, b FixedString(150)') LIMIT 100000"
264-
)
265-
266-
node.query(
267-
"SELECT * FROM encrypted_test ORDER BY a, b SETTINGS optimize_read_in_order=1 FORMAT Null"
268-
)
269-
270-
node.query(
271-
"SELECT * FROM encrypted_test ORDER BY a, b SETTINGS optimize_read_in_order=0 FORMAT Null"
272-
)

0 commit comments

Comments
 (0)