|
29 | 29 | import org.apache.iotdb.db.storageengine.dataregion.wal.utils.WALMode; |
30 | 30 | import org.apache.iotdb.db.storageengine.rescon.disk.DirectoryChecker; |
31 | 31 |
|
32 | | -import com.google.common.base.Objects; |
33 | 32 | import org.apache.commons.io.FileUtils; |
34 | | -import org.apache.tsfile.common.conf.TSFileConfig; |
| 33 | +import org.apache.tsfile.common.conf.TSFileDescriptor; |
35 | 34 | import org.apache.tsfile.encrypt.EncryptUtils; |
| 35 | +import org.apache.tsfile.exception.encrypt.EncryptException; |
36 | 36 | import org.slf4j.Logger; |
37 | 37 | import org.slf4j.LoggerFactory; |
38 | 38 |
|
|
41 | 41 | import java.util.HashMap; |
42 | 42 | import java.util.Map; |
43 | 43 | import java.util.Map.Entry; |
| 44 | +import java.util.Objects; |
44 | 45 | import java.util.Properties; |
45 | 46 | import java.util.function.Supplier; |
46 | 47 |
|
@@ -306,11 +307,19 @@ public void serializeClusterID(String clusterId) throws IOException { |
306 | 307 | } |
307 | 308 |
|
308 | 309 | public void serializeEncryptMagicString() throws IOException { |
| 310 | + if (!Objects.equals(TSFileDescriptor.getInstance().getConfig().getEncryptType(), "UNENCRYPTED") |
| 311 | + && !Objects.equals( |
| 312 | + TSFileDescriptor.getInstance().getConfig().getEncryptType(), |
| 313 | + "org.apache.tsfile.encrypt.UNENCRYPTED")) { |
| 314 | + String token = System.getenv("user_encrypt_token"); |
| 315 | + if (token == null || token.trim().isEmpty()) { |
| 316 | + throw new EncryptException( |
| 317 | + "encryptType is not UNENCRYPTED, but user_encrypt_token is not set. Please set it in the environment variable."); |
| 318 | + } |
| 319 | + } |
309 | 320 | String encryptMagicString = |
310 | 321 | EncryptUtils.byteArrayToHexString( |
311 | | - EncryptUtils.getEncrypt() |
312 | | - .getEncryptor() |
313 | | - .encrypt(magicString.getBytes(TSFileConfig.STRING_CHARSET))); |
| 322 | + TSFileDescriptor.getInstance().getConfig().getEncryptKey()); |
314 | 323 | systemProperties.put(ENCRYPT_MAGIC_STRING, () -> encryptMagicString); |
315 | 324 | generateOrOverwriteSystemPropertiesFile(); |
316 | 325 | } |
@@ -354,15 +363,7 @@ public void checkEncryptMagicString() throws IOException, ConfigurationException |
354 | 363 | String encryptMagicString = properties.getProperty("encrypt_magic_string"); |
355 | 364 | if (encryptMagicString != null) { |
356 | 365 | byte[] magicBytes = EncryptUtils.hexStringToByteArray(encryptMagicString); |
357 | | - String newMagicString = |
358 | | - new String( |
359 | | - EncryptUtils.getEncrypt().getDecryptor().decrypt(magicBytes), |
360 | | - TSFileConfig.STRING_CHARSET); |
361 | | - if (!Objects.equal(magicString, newMagicString)) { |
362 | | - logger.error("encrypt_magic_string is not matched"); |
363 | | - throw new ConfigurationException( |
364 | | - "Changing encrypt key for tsfile encryption after first start is not permitted"); |
365 | | - } |
| 366 | + TSFileDescriptor.getInstance().getConfig().setEncryptKey(magicBytes); |
366 | 367 | } |
367 | 368 | } |
368 | 369 | } |
0 commit comments