-
Notifications
You must be signed in to change notification settings - Fork 0
refactor(toolkit): move keystore-factory to plugins module #4
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| package org.tron.keystore; | ||
| package org.tron.common.crypto.keystore; | ||
|
|
||
| import static java.nio.charset.StandardCharsets.UTF_8; | ||
|
|
||
|
|
@@ -23,7 +23,6 @@ | |
| import org.tron.common.crypto.SignUtils; | ||
| import org.tron.common.utils.ByteArray; | ||
| import org.tron.common.utils.StringUtil; | ||
| import org.tron.core.config.args.Args; | ||
| import org.tron.core.exception.CipherException; | ||
|
|
||
| /** | ||
|
|
@@ -212,7 +211,7 @@ public static SignInterface decrypt(String password, WalletFile walletFile) | |
| byte[] encryptKey = Arrays.copyOfRange(derivedKey, 0, 16); | ||
| byte[] privateKey = performCipherOperation(Cipher.DECRYPT_MODE, iv, encryptKey, cipherText); | ||
|
|
||
| return SignUtils.fromPrivate(privateKey, Args.getInstance().isECKeyCryptoEngine()); | ||
| return SignUtils.fromPrivate(privateKey, true); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Hardcoding Prompt for AI agents |
||
| } | ||
|
|
||
| static void validate(WalletFile walletFile) throws CipherException { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||||||||||||||||||||||||||||||||
| package org.tron.keystore; | ||||||||||||||||||||||||||||||||||||
| package org.tron.common.crypto.keystore; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| import com.fasterxml.jackson.core.JsonParser; | ||||||||||||||||||||||||||||||||||||
| import com.fasterxml.jackson.databind.DeserializationFeature; | ||||||||||||||||||||||||||||||||||||
|
|
@@ -17,7 +17,6 @@ | |||||||||||||||||||||||||||||||||||
| import org.tron.common.crypto.SignInterface; | ||||||||||||||||||||||||||||||||||||
| import org.tron.common.crypto.SignUtils; | ||||||||||||||||||||||||||||||||||||
| import org.tron.common.utils.Utils; | ||||||||||||||||||||||||||||||||||||
| import org.tron.core.config.args.Args; | ||||||||||||||||||||||||||||||||||||
| import org.tron.core.exception.CipherException; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||
|
|
@@ -48,11 +47,9 @@ public static String generateLightNewWalletFile(String password, File destinatio | |||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| public static String generateNewWalletFile( | ||||||||||||||||||||||||||||||||||||
| String password, File destinationDirectory, boolean useFullScrypt) | ||||||||||||||||||||||||||||||||||||
| throws CipherException, IOException, InvalidAlgorithmParameterException, | ||||||||||||||||||||||||||||||||||||
| NoSuchAlgorithmException, NoSuchProviderException { | ||||||||||||||||||||||||||||||||||||
| throws CipherException, IOException { | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| SignInterface ecKeyPair = SignUtils.getGeneratedRandomSign(Utils.getRandom(), | ||||||||||||||||||||||||||||||||||||
| Args.getInstance().isECKeyCryptoEngine()); | ||||||||||||||||||||||||||||||||||||
| SignInterface ecKeyPair = SignUtils.getGeneratedRandomSign(Utils.getRandom(), true); | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+50
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Check if generateNewWalletFile is called from production code paths
rg -n "generateNewWalletFile|generateFullNewWalletFile|generateLightNewWalletFile" --type java -g '!**/test/**'Repository: Federico2014/java-tron Length of output: 808 🏁 Script executed: # Find all callers of the three methods across the entire codebase
rg -n "generateNewWalletFile|generateFullNewWalletFile|generateLightNewWalletFile" --type javaRepository: Federico2014/java-tron Length of output: 1079 🏁 Script executed: # Examine KeystoreFactory.java to verify the reference
find . -name "KeystoreFactory.java" -type f | head -5Repository: Federico2014/java-tron Length of output: 134 🏁 Script executed: # Check the signature and usage of Args vs CommonParameter for crypto engine config
rg -n "isECKeyCryptoEngine" --type java -B 2 -A 2 | head -50Repository: Federico2014/java-tron Length of output: 5666 🏁 Script executed: # Check KeystoreFactory.java around lines 62-63
sed -n '55,70p' ./plugins/src/main/java/common/org/tron/plugins/KeystoreFactory.javaRepository: Federico2014/java-tron Length of output: 710 🏁 Script executed: # Check WalletUtils.java imports and full context
head -60 crypto/src/main/java/org/tron/common/crypto/keystore/WalletUtils.javaRepository: Federico2014/java-tron Length of output: 2357 🏁 Script executed: # Check if Args class exists and is used for crypto engine config
rg -n "class Args|isECKeyCryptoEngine" --type java crypto/src/main/java | head -20Repository: Federico2014/java-tron Length of output: 1238 Hardcoded The hardcoded Although currently only used in tests, this method should respect the configured crypto engine for consistency and to support SM2-configured systems. 🔧 Proposed fix public static String generateNewWalletFile(
String password, File destinationDirectory, boolean useFullScrypt)
throws CipherException, IOException {
- SignInterface ecKeyPair = SignUtils.getGeneratedRandomSign(Utils.getRandom(), true);
+ SignInterface ecKeyPair = SignUtils.getGeneratedRandomSign(Utils.getRandom(),
+ CommonParameter.getInstance().isECKeyCryptoEngine());
return generateWalletFile(password, ecKeyPair, destinationDirectory, useFullScrypt);
}Requires adding: 📝 Committable suggestion
Suggested change
🤖 Prompt for AI AgentsThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Do not hardcode the crypto engine to ECKey here; it ignores runtime configuration and can generate keystores incompatible with SM2-configured environments. Prompt for AI agents
Suggested change
|
||||||||||||||||||||||||||||||||||||
| return generateWalletFile(password, ecKeyPair, destinationDirectory, useFullScrypt); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preserve crypto-engine selection in decrypt path.
At Line 214, forcing
SignUtils.fromPrivate(privateKey, true)always reconstructs EC keys and drops SM2 compatibility. This propagates to credential loading paths that callWallet.decrypt(...)directly.💡 Proposed fix (make engine explicit instead of hardcoded)
Please also update callers to pass the active engine selection explicitly (for example from runtime config) so SM2 deployments keep working.
🤖 Prompt for AI Agents