jt2594838 commented on code in PR #13364:
URL: https://github.com/apache/iotdb/pull/13364#discussion_r1740290547
##########
integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBEncryptionValueQueryIT.java:
##########
Review Comment:
The loading TsFiles cases should be tested. Either loading a TsFile with
consistent encryption, or with unrecognized encryption.
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/common/tsfile/container/scan/SinglePageWholeChunkReader.java:
##########
@@ -107,10 +110,42 @@ public static ByteBuffer uncompressPageData(
return ByteBuffer.wrap(uncompressedPageData);
}
+ public static ByteBuffer decryptAndUncompressPageData(
+ PageHeader pageHeader,
+ IUnCompressor unCompressor,
+ ByteBuffer compressedPageData,
+ IDecryptor decryptor)
+ throws IOException {
+ int compressedPageBodyLength = pageHeader.getCompressedSize();
+ byte[] uncompressedPageData = new byte[pageHeader.getUncompressedSize()];
+ try {
+ byte[] decryptedPageData =
+ decryptor.decrypt(compressedPageData.array(), 0,
compressedPageBodyLength);
+ unCompressor.uncompress(
+ decryptedPageData, 0, compressedPageBodyLength,
uncompressedPageData, 0);
+ } catch (Exception e) {
+ throw new IOException(
+ "Decrypt and Uncompress error! uncompress size: "
+ + pageHeader.getUncompressedSize()
+ + "compressed size: "
+ + pageHeader.getCompressedSize()
+ + "page header: "
+ + pageHeader
+ + e.getMessage());
Review Comment:
Include `e `as the cause.
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/common/tsfile/container/scan/SinglePageWholeChunkReader.java:
##########
@@ -107,10 +110,42 @@ public static ByteBuffer uncompressPageData(
return ByteBuffer.wrap(uncompressedPageData);
}
+ public static ByteBuffer decryptAndUncompressPageData(
+ PageHeader pageHeader,
+ IUnCompressor unCompressor,
+ ByteBuffer compressedPageData,
+ IDecryptor decryptor)
+ throws IOException {
+ int compressedPageBodyLength = pageHeader.getCompressedSize();
+ byte[] uncompressedPageData = new byte[pageHeader.getUncompressedSize()];
+ try {
+ byte[] decryptedPageData =
+ decryptor.decrypt(compressedPageData.array(), 0,
compressedPageBodyLength);
+ unCompressor.uncompress(
+ decryptedPageData, 0, compressedPageBodyLength,
uncompressedPageData, 0);
+ } catch (Exception e) {
+ throw new IOException(
+ "Decrypt and Uncompress error! uncompress size: "
+ + pageHeader.getUncompressedSize()
+ + "compressed size: "
+ + pageHeader.getCompressedSize()
+ + "page header: "
+ + pageHeader
+ + e.getMessage());
+ }
Review Comment:
Avoid coying when not encrypted or compressed like those in TsFile.
##########
integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBEncryptionValueQueryIT.java:
##########
@@ -0,0 +1,677 @@
+/*
+ * 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
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.db.it.query;
+
+import org.apache.iotdb.it.env.EnvFactory;
+import org.apache.iotdb.it.framework.IoTDBTestRunner;
+import org.apache.iotdb.itbase.category.ClusterIT;
+import org.apache.iotdb.itbase.category.LocalStandaloneIT;
+
+import org.apache.tsfile.common.conf.TSFileDescriptor;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.fail;
+
+@RunWith(IoTDBTestRunner.class)
+@Category({LocalStandaloneIT.class, ClusterIT.class})
+public class IoTDBEncryptionValueQueryIT {
+ private static String[] sqls =
+ new String[] {
+ "CREATE DATABASE root.ln",
+ "create timeseries root.ln.wf01.wt01.status with
datatype=BOOLEAN,encoding=PLAIN",
+ "insert into root.ln.wf01.wt01(timestamp,status)
values(1509465600000,true)",
+ "insert into root.ln.wf01.wt01(timestamp,status)
values(1509465660000,true)",
+ "insert into root.ln.wf01.wt01(timestamp,status)
values(1509465720000,false)",
+ "insert into root.ln.wf01.wt01(timestamp,status)
values(1509465780000,false)",
+ "insert into root.ln.wf01.wt01(timestamp,status)
values(1509465840000,false)",
+ "insert into root.ln.wf01.wt01(timestamp,status)
values(1509465900000,false)",
+ "insert into root.ln.wf01.wt01(timestamp,status)
values(1509465960000,false)",
+ "insert into root.ln.wf01.wt01(timestamp,status)
values(1509466020000,false)",
+ "insert into root.ln.wf01.wt01(timestamp,status)
values(1509466080000,false)",
+ "insert into root.ln.wf01.wt01(timestamp,status)
values(1509466140000,false)",
+ "create timeseries root.ln.wf01.wt01.temperature with
datatype=FLOAT,encoding=RLE",
+ "insert into root.ln.wf01.wt01(timestamp,temperature)
values(1509465600000,25.957603)",
+ "insert into root.ln.wf01.wt01(timestamp,temperature)
values(1509465660000,24.359503)",
+ "insert into root.ln.wf01.wt01(timestamp,temperature)
values(1509465720000,20.092794)",
+ "insert into root.ln.wf01.wt01(timestamp,temperature)
values(1509465780000,20.182663)",
+ "insert into root.ln.wf01.wt01(timestamp,temperature)
values(1509465840000,21.125198)",
+ "insert into root.ln.wf01.wt01(timestamp,temperature)
values(1509465900000,22.720892)",
+ "insert into root.ln.wf01.wt01(timestamp,temperature)
values(1509465960000,20.71);",
+ "insert into root.ln.wf01.wt01(timestamp,temperature)
values(1509466020000,21.451046);",
+ "insert into root.ln.wf01.wt01(timestamp,temperature)
values(1509466080000,22.57987);",
+ "insert into root.ln.wf01.wt01(timestamp,temperature)
values(1509466140000,20.98177);",
+ "create timeseries root.ln.wf02.wt02.hardware with
datatype=TEXT,encoding=PLAIN",
+ "insert into root.ln.wf02.wt02(timestamp,hardware)
values(1509465600000,'v2')",
+ "insert into root.ln.wf02.wt02(timestamp,hardware)
values(1509465660000,'v2')",
+ "insert into root.ln.wf02.wt02(timestamp,hardware)
values(1509465720000,'v1')",
+ "insert into root.ln.wf02.wt02(timestamp,hardware)
values(1509465780000,'v1')",
+ "insert into root.ln.wf02.wt02(timestamp,hardware)
values(1509465840000,'v1')",
+ "insert into root.ln.wf02.wt02(timestamp,hardware)
values(1509465900000,'v1')",
+ "insert into root.ln.wf02.wt02(timestamp,hardware)
values(1509465960000,'v1')",
+ "insert into root.ln.wf02.wt02(timestamp,hardware)
values(1509466020000,'v1')",
+ "insert into root.ln.wf02.wt02(timestamp,hardware)
values(1509466080000,'v1')",
+ "insert into root.ln.wf02.wt02(timestamp,hardware)
values(1509466140000,'v1')",
+ "create timeseries root.ln.wf02.wt02.status with
datatype=BOOLEAN,encoding=PLAIN",
+ "insert into root.ln.wf02.wt02(timestamp,status)
values(1509465600000,true)",
+ "insert into root.ln.wf02.wt02(timestamp,status)
values(1509465660000,true)",
+ "insert into root.ln.wf02.wt02(timestamp,status)
values(1509465720000,false)",
+ "insert into root.ln.wf02.wt02(timestamp,status)
values(1509465780000,false)",
+ "insert into root.ln.wf02.wt02(timestamp,status)
values(1509465840000,false)",
+ "insert into root.ln.wf02.wt02(timestamp,status)
values(1509465900000,false)",
+ "insert into root.ln.wf02.wt02(timestamp,status)
values(1509465960000,false)",
+ "insert into root.ln.wf02.wt02(timestamp,status)
values(1509466020000,false)",
+ "insert into root.ln.wf02.wt02(timestamp,status)
values(1509466080000,false)",
+ "insert into root.ln.wf02.wt02(timestamp,status)
values(1509466140000,false)",
+ "CREATE DATABASE root.sgcc",
+ "create timeseries root.sgcc.wf03.wt01.status with
datatype=BOOLEAN,encoding=PLAIN",
+ "insert into root.sgcc.wf03.wt01(timestamp,status)
values(1509465600000,true)",
+ "insert into root.sgcc.wf03.wt01(timestamp,status)
values(1509465660000,true)",
+ "insert into root.sgcc.wf03.wt01(timestamp,status)
values(1509465720000,false)",
+ "insert into root.sgcc.wf03.wt01(timestamp,status)
values(1509465780000,false)",
+ "insert into root.sgcc.wf03.wt01(timestamp,status)
values(1509465840000,false)",
+ "insert into root.sgcc.wf03.wt01(timestamp,status)
values(1509465900000,false)",
+ "insert into root.sgcc.wf03.wt01(timestamp,status)
values(1509465960000,false)",
+ "insert into root.sgcc.wf03.wt01(timestamp,status)
values(1509466020000,false)",
+ "insert into root.sgcc.wf03.wt01(timestamp,status)
values(1509466080000,false)",
+ "insert into root.sgcc.wf03.wt01(timestamp,status)
values(1509466140000,false)",
+ "create timeseries root.sgcc.wf03.wt01.temperature with
datatype=FLOAT,encoding=RLE",
+ "insert into root.sgcc.wf03.wt01(timestamp,temperature)
values(1509465600000,25.957603)",
+ "insert into root.sgcc.wf03.wt01(timestamp,temperature)
values(1509465660000,24.359503)",
+ "insert into root.sgcc.wf03.wt01(timestamp,temperature)
values(1509465720000,20.092794)",
+ "insert into root.sgcc.wf03.wt01(timestamp,temperature)
values(1509465780000,20.182663)",
+ "insert into root.sgcc.wf03.wt01(timestamp,temperature)
values(1509465840000,21.125198)",
+ "insert into root.sgcc.wf03.wt01(timestamp,temperature)
values(1509465900000,22.720892)",
+ "insert into root.sgcc.wf03.wt01(timestamp,temperature)
values(1509465960000,20.71)",
+ "insert into root.sgcc.wf03.wt01(timestamp,temperature)
values(1509466020000,21.451046)",
+ "insert into root.sgcc.wf03.wt01(timestamp,temperature)
values(1509466080000,22.57987)",
+ "insert into root.sgcc.wf03.wt01(timestamp,temperature)
values(1509466140000,20.98177)",
+ };
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ TSFileDescriptor.getInstance().getConfig().setEncryptFlag("true");
+ TSFileDescriptor.getInstance().getConfig().setEncryptType("AES128");
+
TSFileDescriptor.getInstance().getConfig().setEncryptKey("mkmkmkmkmkmkmkmk");
Review Comment:
This will not be effective for the testing environment because the servers
are started in another process.
Refer to `EnvFactory.getEnv().getConfig()` to see how to change the config
in IT.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]