diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBEncryptionValueQueryIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBEncryptionValueQueryIT.java index b63e409a3e31c..e3d12924088eb 100644 --- a/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBEncryptionValueQueryIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBEncryptionValueQueryIT.java @@ -126,7 +126,7 @@ public static void setUp() throws Exception { .getConfig() .getCommonConfig() .setEncryptFlag(true) - .setEncryptType("org.apache.tsfile.encrypt.AES128"); + .setEncryptType("UNENCRYPTED"); EnvFactory.getEnv().initClusterEnvironment(); importData(); } diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBLoadEncryptedTsFileIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBLoadEncryptedTsFileIT.java index bbb2f173c36ea..7ff81f934cb72 100644 --- a/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBLoadEncryptedTsFileIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBLoadEncryptedTsFileIT.java @@ -52,7 +52,7 @@ public static void setUp() throws Exception { .getConfig() .getCommonConfig() .setEncryptFlag(true) - .setEncryptType("org.apache.tsfile.encrypt.AES128"); + .setEncryptType("UNENCRYPTED"); EnvFactory.getEnv().initClusterEnvironment(); } @@ -98,25 +98,10 @@ public void loadSameWayEncryptedTsFileTest() { cnt++; } Assert.assertEquals(3, cnt); - } catch (Exception e) { - Assert.fail(e.getMessage()); - } - } - - @Test - public void loadAnotherWayEncryptedTsFileTest() { - String unrecognizedType = "org.apache.tsfile.encrypt.SM4128"; - try (Connection connection = EnvFactory.getEnv().getConnection(); - Statement statement = connection.createStatement()) { - statement.execute("CREATE DATABASE root.tesgsg1"); - statement.execute("CREATE TIMESERIES root.testsg1.d1.s1 WITH DATATYPE=INT32, ENCODING=PLAIN"); - File tsfile = generateAnotherWayEncryptedFile(unrecognizedType); - statement.execute(String.format("load \"%s\"", tsfile.getParentFile().getAbsolutePath())); - ResultSet resultSet = statement.executeQuery("select s1 from root.testsg1.d1"); - Assert.fail(); } catch (Exception e) { Assert.assertTrue( - e.getMessage().contains("The encryption way of the TsFile is not supported.")); + e.getMessage() + .contains("TSFile encryption is enabled, and the Load TSFile function is disabled")); } } @@ -129,7 +114,7 @@ private File generateSameWayEncryptedFile() throws IOException { Files.createFile(tsfile.toPath()); TSFileConfig config = TSFileDescriptor.getInstance().getConfig(); config.setEncryptFlag("true"); - config.setEncryptType("org.apache.tsfile.encrypt.AES128"); + config.setEncryptType("UNENCRYPTED"); try (TsFileIOWriter writer = new TsFileIOWriter(tsfile, config)) { writer.startChunkGroup(IDeviceID.Factory.DEFAULT_FACTORY.create("root.testsg.d1")); @@ -151,38 +136,6 @@ private File generateSameWayEncryptedFile() throws IOException { return tsfile; } - private File generateAnotherWayEncryptedFile(String unrecognizedType) throws IOException { - Path tempDir = Files.createTempDirectory(""); - tempDir.toFile().deleteOnExit(); - String tsfileName = - TsFileNameGenerator.generateNewTsFileName(System.currentTimeMillis(), 1, 0, 0); - File tsfile = new File(tempDir + File.separator + tsfileName); - Files.createFile(tsfile.toPath()); - TSFileConfig config = TSFileDescriptor.getInstance().getConfig(); - config.setEncryptFlag("true"); - config.setEncryptType("org.apache.tsfile.encrypt.AES128"); - - try (TsFileIOWriter writer = new TsFileIOWriter(tsfile, config)) { - writer.startChunkGroup(IDeviceID.Factory.DEFAULT_FACTORY.create("root.testsg1.d1")); - ChunkWriterImpl chunkWriter = - new ChunkWriterImpl( - new MeasurementSchema("s1", TSDataType.INT32), - EncryptUtils.getEncryptParameter(config)); - chunkWriter.write(2, 1); - chunkWriter.write(3, 1); - chunkWriter.write(4, 1); - chunkWriter.sealCurrentPage(); - - chunkWriter.writeToFileWriter(writer); - writer.endChunkGroup(); - writer.setEncryptParam("2", unrecognizedType, EncryptUtils.getNormalKeyStr(config)); - writer.endFile(); - } - config.setEncryptFlag("false"); - config.setEncryptType("org.apache.tsfile.encrypt.UNENCRYPTED"); - return tsfile; - } - private List checkHeader( ResultSetMetaData resultSetMetaData, String expectedHeaderStrings, int[] expectedTypes) throws SQLException { diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBLoadPlainTsFileIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBLoadPlainTsFileIT.java deleted file mode 100644 index bdff3fb463c5f..0000000000000 --- a/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBLoadPlainTsFileIT.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * 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.db.storageengine.dataregion.tsfile.generator.TsFileNameGenerator; -import org.apache.iotdb.it.env.EnvFactory; - -import org.apache.tsfile.enums.TSDataType; -import org.apache.tsfile.file.metadata.IDeviceID; -import org.apache.tsfile.write.chunk.ChunkWriterImpl; -import org.apache.tsfile.write.schema.MeasurementSchema; -import org.apache.tsfile.write.writer.TsFileIOWriter; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.sql.*; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class IoTDBLoadPlainTsFileIT { - @BeforeClass - public static void setUp() throws Exception { - EnvFactory.getEnv() - .getConfig() - .getCommonConfig() - .setEncryptFlag(true) - .setEncryptType("org.apache.tsfile.encrypt.AES128"); - EnvFactory.getEnv().initClusterEnvironment(); - } - - @AfterClass - public static void tearDown() throws Exception { - EnvFactory.getEnv().cleanClusterEnvironment(); - } - - @Test - public void loadNormalTsFileTest() { - String[] retArray = - new String[] { - "2,1,", "3,1,", "4,1,", - }; - try (Connection connection = EnvFactory.getEnv().getConnection(); - Statement statement = connection.createStatement()) { - statement.execute("CREATE DATABASE root.tesgsg"); - statement.execute("CREATE TIMESERIES root.testsg.d1.s1 WITH DATATYPE=INT32, ENCODING=PLAIN"); - File tsfile = generateNormalFile(); - statement.execute(String.format("load \"%s\"", tsfile.getParentFile().getAbsolutePath())); - ResultSet resultSet = statement.executeQuery("select s1 from root.testsg.d1"); - ResultSetMetaData resultSetMetaData = resultSet.getMetaData(); - List actualIndexToExpectedIndexList = - checkHeader( - resultSetMetaData, - "Time,root.testsg.d1.s1,", - new int[] { - Types.TIMESTAMP, Types.INTEGER, - }); - - int cnt = 0; - while (resultSet.next()) { - String[] expectedStrings = retArray[cnt].split(","); - StringBuilder expectedBuilder = new StringBuilder(); - StringBuilder actualBuilder = new StringBuilder(); - for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) { - actualBuilder.append(resultSet.getString(i)).append(","); - expectedBuilder - .append(expectedStrings[actualIndexToExpectedIndexList.get(i - 1)]) - .append(","); - } - Assert.assertEquals(expectedBuilder.toString(), actualBuilder.toString()); - cnt++; - } - Assert.assertEquals(3, cnt); - } catch (Exception e) { - Assert.assertTrue( - e.getMessage().contains("The encryption way of the TsFile is not supported.")); - } - } - - private File generateNormalFile() throws IOException { - Path tempDir = Files.createTempDirectory(""); - tempDir.toFile().deleteOnExit(); - String tsfileName = - TsFileNameGenerator.generateNewTsFileName(System.currentTimeMillis(), 1, 0, 0); - File tsfile = new File(tempDir + File.separator + tsfileName); - Files.createFile(tsfile.toPath()); - - try (TsFileIOWriter writer = new TsFileIOWriter(tsfile)) { - writer.startChunkGroup(IDeviceID.Factory.DEFAULT_FACTORY.create("root.testsg.d1")); - ChunkWriterImpl chunkWriter = - new ChunkWriterImpl(new MeasurementSchema("s1", TSDataType.INT32)); - chunkWriter.write(2, 1); - chunkWriter.write(3, 1); - chunkWriter.write(4, 1); - chunkWriter.sealCurrentPage(); - - chunkWriter.writeToFileWriter(writer); - writer.endChunkGroup(); - writer.endFile(); - } - return tsfile; - } - - private List checkHeader( - ResultSetMetaData resultSetMetaData, String expectedHeaderStrings, int[] expectedTypes) - throws SQLException { - String[] expectedHeaders = expectedHeaderStrings.split(","); - Map expectedHeaderToTypeIndexMap = new HashMap<>(); - for (int i = 0; i < expectedHeaders.length; ++i) { - expectedHeaderToTypeIndexMap.put(expectedHeaders[i], i); - } - - List actualIndexToExpectedIndexList = new ArrayList<>(); - for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) { - Integer typeIndex = expectedHeaderToTypeIndexMap.get(resultSetMetaData.getColumnName(i)); - Assert.assertNotNull(typeIndex); - Assert.assertEquals(expectedTypes[typeIndex], resultSetMetaData.getColumnType(i)); - actualIndexToExpectedIndexList.add(typeIndex); - } - return actualIndexToExpectedIndexList; - } -} diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java index b652acf73294c..88362df8bd3d4 100755 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java @@ -1384,6 +1384,24 @@ public void loadProperties(TrimProperties properties) throws BadNodeUrlException .map(String::trim) .orElse(conf.getKerberosPrincipal())); TSFileDescriptor.getInstance().getConfig().setBatchSize(conf.getBatchSize()); + TSFileDescriptor.getInstance() + .getConfig() + .setEncryptFlag( + Optional.ofNullable(properties.getProperty("encrypt_flag", "false")) + .map(String::trim) + .orElse("false")); + TSFileDescriptor.getInstance() + .getConfig() + .setEncryptType( + Optional.ofNullable(properties.getProperty("encrypt_type", "UNENCRYPTED")) + .map(String::trim) + .orElse("UNENCRYPTED")); + TSFileDescriptor.getInstance() + .getConfig() + .setEncryptKeyFromPath( + Optional.ofNullable(properties.getProperty("encrypt_key_from_path", "")) + .map(String::trim) + .orElse("")); conf.setCoordinatorReadExecutorSize( Integer.parseInt( @@ -2492,24 +2510,6 @@ private void loadTsFileProps(TrimProperties properties) throws IOException { ConfigurationFileUtils.getConfigurationDefaultValue("compressor"))) .map(String::trim) .orElse(ConfigurationFileUtils.getConfigurationDefaultValue("compressor"))); - TSFileDescriptor.getInstance() - .getConfig() - .setEncryptFlag( - properties.getProperty( - "encrypt_flag", - ConfigurationFileUtils.getConfigurationDefaultValue("encrypt_flag"))); - TSFileDescriptor.getInstance() - .getConfig() - .setEncryptType( - properties.getProperty( - "encrypt_type", - ConfigurationFileUtils.getConfigurationDefaultValue("encrypt_type"))); - TSFileDescriptor.getInstance() - .getConfig() - .setEncryptKeyFromPath( - properties.getProperty( - "encrypt_key_path", - ConfigurationFileUtils.getConfigurationDefaultValue("encrypt_key_path"))); TSFileDescriptor.getInstance() .getConfig() .setMaxTsBlockSizeInBytes( diff --git a/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template b/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template index c7b9115eea051..af09a86be0003 100644 --- a/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template +++ b/iotdb-core/node-commons/src/assembly/resources/conf/iotdb-system.properties.template @@ -1570,21 +1570,6 @@ value_encoder=PLAIN # effectiveMode: hot_reload compressor=LZ4 -# Encryption configuration -# Data encryption function switch. -# effectiveMode: restart -encrypt_flag=false - -# Encryption configuration -# Data encryption method, supports org.apache.tsfile.encrypt.UNENCRYPTED, org.apache.tsfile.encrypt.AES128. -# effectiveMode: restart -encrypt_type=org.apache.tsfile.encrypt.UNENCRYPTED - -# Encryption configuration -# Data encryption key source. The key should be 16 byte String. -# effectiveMode: restart -encrypt_key_path= - #################### ### Authorization Configuration #################### diff --git a/pom.xml b/pom.xml index ad0eaea6bcfd0..112468fa60792 100644 --- a/pom.xml +++ b/pom.xml @@ -166,7 +166,7 @@ 0.14.1 1.9 1.5.6-3 - 1.2.0-241129-SNAPSHOT + 1.2.0-241211-SNAPSHOT