Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify encrypt type and related tests #14273

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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"));
}
}

Expand All @@ -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"));
Expand All @@ -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<Integer> checkHeader(
ResultSetMetaData resultSetMetaData, String expectedHeaderStrings, int[] expectedTypes)
throws SQLException {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
####################
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
<thrift.version>0.14.1</thrift.version>
<xz.version>1.9</xz.version>
<zstd-jni.version>1.5.6-3</zstd-jni.version>
<tsfile.version>1.2.0-241129-SNAPSHOT</tsfile.version>
<tsfile.version>1.2.0-241209-SNAPSHOT</tsfile.version>
</properties>
<!--
if we claim dependencies in dependencyManagement, then we do not claim
Expand Down
Loading