Skip to content

Commit f402360

Browse files
Merge pull request #6171 from lxcmyf/feature/sensitive_information_optimization
feat(*): optimize sensitive information
2 parents 6b0aed7 + 8738da4 commit f402360

File tree

10 files changed

+63
-1097
lines changed

10 files changed

+63
-1097
lines changed

framework/src/test/java/org/tron/common/crypto/BouncyCastleTest.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.junit.Assert.assertArrayEquals;
44
import static org.junit.Assert.assertEquals;
5+
import static org.tron.common.utils.client.utils.AbiUtil.generateOccupationConstantPrivateKey;
56

67
import java.math.BigInteger;
78
import java.security.SignatureException;
@@ -20,12 +21,13 @@
2021
*/
2122
public class BouncyCastleTest {
2223

23-
private String privString = "c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4";
24-
private BigInteger privateKey = new BigInteger(privString, 16);
24+
// For safety reasons, test with a placeholder private key
25+
private final String privString = generateOccupationConstantPrivateKey();
26+
private final BigInteger privateKey = new BigInteger(privString, 16);
2527

2628
@Test
2729
public void testHex() {
28-
String spongyAddress = "cd2a3d9f938e13cd947ec05abc7fe734df8dd826";
30+
String spongyAddress = "2e988a386a799f506693793c6a5af6b54dfaabfb";
2931
ECKey key = ECKey.fromPrivate(privateKey);
3032
byte[] address = key.getAddress();
3133
assertEquals(spongyAddress,
@@ -55,10 +57,9 @@ public void testSha3Hash() {
5557

5658
@Test
5759
public void testECKeyAddress() {
58-
String spongyPubkey =
59-
"040947751e3022ecf3016be03ec77ab0ce3c2662b4843898cb068d74f698ccc8ad75"
60-
+ "aa17564ae80a20bb044ee7a6d903e8e8df624b089c95d66a0570f051e5a05b";
61-
String spongyAddress = "cd2a3d9f938e13cd947ec05abc7fe734df8dd826";
60+
String spongyPubkey = "04e90c7d3640a1568839c31b70a893ab6714ef8415b9de90cedfc1c8f353a6983e625529"
61+
+ "392df7fa514bdd65a2003f6619567d79bee89830e63e932dbd42362d34";
62+
String spongyAddress = "2e988a386a799f506693793c6a5af6b54dfaabfb";
6263
ECKey key = ECKey.fromPrivate(privateKey);
6364
byte[] pubkey = key.getPubKey();
6465
assertEquals(spongyPubkey, Hex.toHexString(pubkey));
@@ -71,7 +72,7 @@ public void testECKeyAddress() {
7172
public void testECKeySignature() throws SignatureException {
7273
SignInterface sign = SignUtils.fromPrivate(Hex.decode(privString), true);
7374
String msg = "transaction raw data";
74-
String spongyAddress = "cd2a3d9f938e13cd947ec05abc7fe734df8dd826";
75+
String spongyAddress = "2e988a386a799f506693793c6a5af6b54dfaabfb";
7576
byte[] hash = Sha256Hash.hash(true, msg.getBytes());
7677
String sig = sign.signHash(hash);
7778
byte[] address = SignUtils.signatureToAddress(hash, sig, true);
@@ -102,9 +103,9 @@ public void testSM3Hash() {
102103

103104
@Test
104105
public void testSM2Address() {
105-
String spongyPublickey = "04f9539070c135be6183cbff4539f8298755df5981022769cd16cfdcb917fa7e32"
106-
+ "4e83b50f0bdbb34acd6ccbb78d45a8a383403f26bbd03805a178c43407dfdeae";
107-
String spongyAddress = "7dc44d739a5226c0d3037bb7919f653eb2f938b9";
106+
String spongyPublickey = "04dc3547dbbc4c90a9cde599848e26cb145e805b3d11daaf9daae0680d9c6824058ac"
107+
+ "35ddecb12f3a8bbc3104a2b91a2b7d04851d773d9b4ab8d5e0359243c8628";
108+
String spongyAddress = "6cb22f88564bdd61eb4cdb36215add53bc702ff1";
108109
SM2 key = SM2.fromPrivate(privateKey);
109110
assertEquals(spongyPublickey, Hex.toHexString(key.getPubKey()));
110111
byte[] address = key.getAddress();
@@ -115,7 +116,7 @@ public void testSM2Address() {
115116
public void testSM2Signature() throws SignatureException {
116117
SignInterface sign = SignUtils.fromPrivate(Hex.decode(privString), false);
117118
String msg = "transaction raw data";
118-
String spongyAddress = "7dc44d739a5226c0d3037bb7919f653eb2f938b9";
119+
String spongyAddress = "6cb22f88564bdd61eb4cdb36215add53bc702ff1";
119120
byte[] hash = Sha256Hash.hash(false, msg.getBytes());
120121
String sig = sign.signHash(hash);
121122
byte[] address = SignUtils.signatureToAddress(hash, sig, false);

framework/src/test/java/org/tron/common/crypto/ECKeyTest.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import static org.junit.Assert.assertNotNull;
88
import static org.junit.Assert.assertTrue;
99
import static org.junit.Assert.fail;
10+
import static org.tron.common.utils.client.utils.AbiUtil.generateOccupationConstantPrivateKey;
1011

1112
import java.math.BigInteger;
1213
import java.security.KeyPairGenerator;
@@ -27,16 +28,17 @@
2728
@Slf4j
2829
public class ECKeyTest {
2930

30-
private String privString = "c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4";
31+
// For safety reasons, test with a placeholder private key
32+
private String privString = generateOccupationConstantPrivateKey();
3133
private BigInteger privateKey = new BigInteger(privString, 16);
3234

33-
private String pubString = "040947751e3022ecf3016be03ec77ab0ce3c2662b4843898cb068d74f698ccc"
34-
+ "8ad75aa17564ae80a20bb044ee7a6d903e8e8df624b089c95d66a0570f051e5a05b";
35+
private String pubString = "04e90c7d3640a1568839c31b70a893ab6714ef8415b9de90cedfc1c8f353a6983e62"
36+
+ "5529392df7fa514bdd65a2003f6619567d79bee89830e63e932dbd42362d34";
3537
private String compressedPubString =
36-
"030947751e3022ecf3016be03ec77ab0ce3c2662b4843898cb068d74f6" + "98ccc8ad";
38+
"02e90c7d3640a1568839c31b70a893ab6714ef8415b9de90cedfc1c8f353a6983e";
3739
private byte[] pubKey = Hex.decode(pubString);
3840
private byte[] compressedPubKey = Hex.decode(compressedPubString);
39-
private String address = "cd2a3d9f938e13cd947ec05abc7fe734df8dd826";
41+
private String address = "2e988a386a799f506693793c6a5af6b54dfaabfb";
4042
String eventSign = "eventBytesL(address,bytes,bytes32,uint256,string)";
4143

4244
@Test
@@ -46,7 +48,7 @@ public void testSha3() {
4648

4749
@Test
4850
public void testHashCode() {
49-
assertEquals(-351262686, ECKey.fromPrivate(privateKey).hashCode());
51+
assertEquals(-827927068, ECKey.fromPrivate(privateKey).hashCode());
5052
}
5153

5254
@Test

framework/src/test/java/org/tron/common/crypto/SM2KeyTest.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import static org.junit.Assert.assertNotNull;
77
import static org.junit.Assert.assertTrue;
88
import static org.junit.Assert.fail;
9+
import static org.tron.common.utils.client.utils.AbiUtil.generateOccupationConstantPrivateKey;
910

1011
import java.math.BigInteger;
1112
import java.security.KeyPairGenerator;
@@ -30,19 +31,20 @@ public class SM2KeyTest {
3031
//private String IDa = "[email protected]";
3132
private static BigInteger SM2_N = new BigInteger("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6"
3233
+ "B21C6052B53BBF40939D54123", 16);
33-
private String privString = "128B2FA8BD433C6C068C8D803DFF79792A519A55171B1B650C23661D15897263";
34+
// For safety reasons, test with a placeholder private key
35+
private String privString = generateOccupationConstantPrivateKey();
3436
private BigInteger privateKey = new BigInteger(privString, 16);
35-
private String pubString = "04d5548c7825cbb56150a3506cd57464af8a1ae0519dfaf3c58221dc810caf28d"
36-
+ "d921073768fe3d59ce54e79a49445cf73fed23086537027264d168946d479533e";
37+
private String pubString = "04dc3547dbbc4c90a9cde599848e26cb145e805b3d11daaf9daae0680d9c6824058ac"
38+
+ "35ddecb12f3a8bbc3104a2b91a2b7d04851d773d9b4ab8d5e0359243c8628";
3739
private String compressedPubString =
38-
"02d5548c7825cbb56150a3506cd57464af8a1ae0519dfaf3c58221dc810caf28dd";
40+
"02dc3547dbbc4c90a9cde599848e26cb145e805b3d11daaf9daae0680d9c682405";
3941
private byte[] pubKey = Hex.decode(pubString);
4042
private byte[] compressedPubKey = Hex.decode(compressedPubString);
41-
private String address = "62e49e4c2f4e3c0653a02f8859c1e6991b759e87";
43+
private String address = "6cb22f88564bdd61eb4cdb36215add53bc702ff1";
4244

4345
@Test
4446
public void testHashCode() {
45-
assertEquals(1126288006, SM2.fromPrivate(privateKey).hashCode());
47+
assertEquals(578690511, SM2.fromPrivate(privateKey).hashCode());
4648
}
4749

4850
@Test
@@ -114,7 +116,7 @@ public void testSM3Hash() {
114116
SM2Signer signer = key.getSM2SignerForHash();
115117
String message = "message digest";
116118
byte[] hash = signer.generateSM3Hash(message.getBytes());
117-
assertEquals("299C7DDB0D8DD2A85381BACBB92F738F390210A493A144C78E18C67B430DA882",
119+
assertEquals("2A723761EAE35429DF643648FD69FB7787E7FC32F321BFAF7E294390F529BAF4",
118120
Hex.toHexString(hash).toUpperCase());
119121
}
120122

framework/src/test/java/org/tron/common/utils/client/utils/AbiUtil.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,16 @@ public static byte[] encodeInput(String methodSign, String input) {
240240
return pack(coders, items);
241241
}
242242

243+
public static String generateOccupationConstantPrivateKey() {
244+
StringBuilder privateKey = new StringBuilder();
245+
String baseKey = "1234567890";
246+
for (int i = 0; i < 6; i++) {
247+
privateKey.append(baseKey);
248+
}
249+
privateKey.append("1234");
250+
return privateKey.toString();
251+
}
252+
243253
public static void main(String[] args) {
244254
String method = "test(string,int2,string)";
245255
String params = "asdf,3123,adf";

0 commit comments

Comments
 (0)