comparison src/com/five_ten_sg/connectbot/util/PubkeyUtils.java @ 344:b40bc65fa09a

compensate for SecureRandom bug on older devices
author Carl Byington <carl@five-ten-sg.com>
date Thu, 31 Jul 2014 18:39:36 -0700
parents 91a31873c42a
children
comparison
equal deleted inserted replaced
343:df13118e8e79 344:b40bc65fa09a
27 import java.security.KeyPair; 27 import java.security.KeyPair;
28 import java.security.MessageDigest; 28 import java.security.MessageDigest;
29 import java.security.NoSuchAlgorithmException; 29 import java.security.NoSuchAlgorithmException;
30 import java.security.PrivateKey; 30 import java.security.PrivateKey;
31 import java.security.PublicKey; 31 import java.security.PublicKey;
32 import java.security.SecureRandom;
33 import java.security.interfaces.DSAParams; 32 import java.security.interfaces.DSAParams;
34 import java.security.interfaces.DSAPrivateKey; 33 import java.security.interfaces.DSAPrivateKey;
35 import java.security.interfaces.DSAPublicKey; 34 import java.security.interfaces.DSAPublicKey;
36 import java.security.interfaces.ECPrivateKey; 35 import java.security.interfaces.ECPrivateKey;
37 import java.security.interfaces.ECPublicKey; 36 import java.security.interfaces.ECPublicKey;
63 62
64 import com.five_ten_sg.connectbot.bean.PubkeyBean; 63 import com.five_ten_sg.connectbot.bean.PubkeyBean;
65 import android.util.Log; 64 import android.util.Log;
66 65
67 import ch.ethz.ssh2.crypto.Base64; 66 import ch.ethz.ssh2.crypto.Base64;
67 import ch.ethz.ssh2.crypto.SecureRandomFix;
68 import ch.ethz.ssh2.crypto.SimpleDERReader; 68 import ch.ethz.ssh2.crypto.SimpleDERReader;
69 import ch.ethz.ssh2.signature.DSASHA1Verify; 69 import ch.ethz.ssh2.signature.DSASHA1Verify;
70 import ch.ethz.ssh2.signature.ECDSASHA2Verify; 70 import ch.ethz.ssh2.signature.ECDSASHA2Verify;
71 import ch.ethz.ssh2.signature.RSASHA1Verify; 71 import ch.ethz.ssh2.signature.RSASHA1Verify;
72 72
300 sb.append(PKCS8_START); 300 sb.append(PKCS8_START);
301 sb.append('\n'); 301 sb.append('\n');
302 302
303 if (secret != null) { 303 if (secret != null) {
304 byte[] salt = new byte[8]; 304 byte[] salt = new byte[8];
305 SecureRandom random = new SecureRandom(); 305 SecureRandomFix random = new SecureRandomFix();
306 random.nextBytes(salt); 306 random.nextBytes(salt);
307 PBEParameterSpec defParams = new PBEParameterSpec(salt, 1); 307 PBEParameterSpec defParams = new PBEParameterSpec(salt, 1);
308 AlgorithmParameters params = AlgorithmParameters.getInstance(key.getAlgorithm()); 308 AlgorithmParameters params = AlgorithmParameters.getInstance(key.getAlgorithm());
309 params.init(defParams); 309 params.init(defParams);
310 PBEKeySpec pbeSpec = new PBEKeySpec(secret.toCharArray()); 310 PBEKeySpec pbeSpec = new PBEKeySpec(secret.toCharArray());