Skip to content

Commit 1df5837

Browse files
committed
Strengthen default number of PBE iterations on key store
1 parent 5a2e4f2 commit 1df5837

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

convex-core/src/main/java/convex/core/Constants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,6 @@ public class Constants {
220220
*/
221221
public static final long MAX_BLOCK_BACKDATE = 60*1000;
222222

223+
public static final int PBE_ITERATIONS = 100000;
224+
223225
}

convex-core/src/main/java/convex/core/crypto/PFXTools.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77
import java.security.GeneralSecurityException;
88
import java.security.Key;
99
import java.security.KeyStore;
10+
import java.security.KeyStore.PasswordProtection;
11+
import java.security.KeyStore.SecretKeyEntry;
1012
import java.security.KeyStoreException;
1113
import java.security.NoSuchAlgorithmException;
1214
import java.security.UnrecoverableKeyException;
1315

1416
import javax.crypto.SecretKey;
17+
import javax.crypto.spec.PBEParameterSpec;
1518
import javax.crypto.spec.SecretKeySpec;
1619

20+
import convex.core.Constants;
1721
import convex.core.util.Utils;
1822

1923

@@ -126,8 +130,17 @@ public static KeyStore setKeyPair(KeyStore ks, String alias, AKeyPair kp, char[]
126130
if (keyPassword == null) throw new IllegalArgumentException("Password is mandatory for private key");
127131

128132
byte[] bs=((AKeyPair)kp).getSeed().getBytes();
129-
SecretKey secretKeyPrivate = new SecretKeySpec(bs, "Ed25519");
130-
ks.setKeyEntry(alias, secretKeyPrivate, keyPassword, null);
133+
SecretKey secretKeySeed = new SecretKeySpec(bs, "Ed25519");
134+
135+
// See https://neilmadden.blog/2017/11/17/java-keystores-the-gory-details/
136+
SecretKeyEntry keyEntry=new SecretKeyEntry(secretKeySeed);
137+
byte[] salt=new byte[20];
138+
139+
PasswordProtection protection= new PasswordProtection(keyPassword,
140+
"PBEWithHmacSHA512AndAES_128",
141+
new PBEParameterSpec(salt, Constants.PBE_ITERATIONS));
142+
ks.setEntry(alias, keyEntry, protection);
143+
// ks.setKeyEntry(alias, secretKeySeed, keyPassword, null);
131144

132145
return ks;
133146
}

0 commit comments

Comments
 (0)