Skip to content

Commit 3573f98

Browse files
committed
<fix>(crypto): add safe key store path.
1 parent 2355903 commit 3573f98

File tree

4 files changed

+5
-1
lines changed

4 files changed

+5
-1
lines changed

sdk-core/src/main/java/org/fisco/bcos/sdk/config/model/ConfigProperty.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public static InputStream getConfigInputStream(String configFilePath) throws Con
105105
}
106106
InputStream inputStream = null;
107107
try {
108+
configFilePath = configFilePath.replace("..", "");
108109
inputStream = new FileInputStream(configFilePath);
109110
if (inputStream != null) {
110111
return inputStream;

sdk-crypto/src/main/java/org/fisco/bcos/sdk/crypto/keystore/KeyTool.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ public static void storePublicKeyWithPem(PublicKey publicKey, String privateKeyF
289289
/** load information from the keyStoreFile */
290290
protected void load() {
291291
try {
292-
InputStream keyStoreFileInputStream = new FileInputStream(keyStoreFile);
292+
String safeFile = keyStoreFile.replace("..", "");
293+
InputStream keyStoreFileInputStream = new FileInputStream(safeFile);
293294
this.load(keyStoreFileInputStream);
294295
} catch (FileNotFoundException | org.bouncycastle.util.encoders.DecoderException e) {
295296
String errorMessage =

sdk-crypto/src/main/java/org/fisco/bcos/sdk/crypto/keystore/P12KeyStore.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ public static void storeKeyPairWithP12Format(
150150
Certificate[] certChain = new Certificate[1];
151151
certChain[0] = generateSelfSignedCertificate(keyPair, signatureAlgorithm);
152152
keyStore.setKeyEntry(NAME, privateKey, password.toCharArray(), certChain);
153+
privateKeyFilePath = privateKeyFilePath.replace("..", "");
153154
keyStore.store(new FileOutputStream(privateKeyFilePath), password.toCharArray());
154155
// store the public key
155156
storePublicKeyWithPem(privateKey, privateKeyFilePath);

sdk-crypto/src/main/java/org/fisco/bcos/sdk/crypto/keystore/PEMKeyStore.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public static void storeKeyPairWithPemFormat(
6969
try {
7070
KeyPair keyPair = convertHexedStringToKeyPair(hexedPrivateKey, curveName);
7171
// save the private key
72+
privateKeyFilePath = privateKeyFilePath.replace("..", "");
7273
PemWriter writer = new PemWriter(new FileWriter(privateKeyFilePath));
7374
BCECPrivateKey bcecPrivateKey = (BCECPrivateKey) (keyPair.getPrivate());
7475
writer.writeObject(new PemObject(PRIVATE_KEY, bcecPrivateKey.getEncoded()));

0 commit comments

Comments
 (0)