aboutsummaryrefslogtreecommitdiffstats
path: root/src/org
diff options
context:
space:
mode:
authorKenny Root <kenny@the-b.org>2008-10-29 17:36:59 +0000
committerKenny Root <kenny@the-b.org>2008-10-29 17:36:59 +0000
commita7b67f39ca37d14c23ae1f465593c18626355d8c (patch)
tree3f834b6f23c0067b6a908c41f2cb49d3c5eabac2 /src/org
parentdc59e640790d70a4542b37e3718dbccbd6be0d08 (diff)
downloadconnectbot-a7b67f39ca37d14c23ae1f465593c18626355d8c.tar.gz
connectbot-a7b67f39ca37d14c23ae1f465593c18626355d8c.tar.bz2
connectbot-a7b67f39ca37d14c23ae1f465593c18626355d8c.zip
* Allow scrolling in Pubkey Generator Activity until we get landscape orientation looking better.
* Don't drop and recreate HostDatabase on every new version. * Remove some unused pubkey helper functions debug statements. * Fix a typo in debug stateent.
Diffstat (limited to 'src/org')
-rw-r--r--src/org/connectbot/util/HostDatabase.java8
-rw-r--r--src/org/connectbot/util/PubkeyUtils.java30
2 files changed, 14 insertions, 24 deletions
diff --git a/src/org/connectbot/util/HostDatabase.java b/src/org/connectbot/util/HostDatabase.java
index 3cbc866..586180a 100644
--- a/src/org/connectbot/util/HostDatabase.java
+++ b/src/org/connectbot/util/HostDatabase.java
@@ -85,8 +85,12 @@ public class HostDatabase extends SQLiteOpenHelper {
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- db.execSQL("DROP TABLE IF EXISTS " + TABLE_HOSTS);
- onCreate(db);
+ // Versions of the database before the Android Market release will be
+ // shot without warning.
+ if (oldVersion <= 9) {
+ db.execSQL("DROP TABLE IF EXISTS " + TABLE_HOSTS);
+ onCreate(db);
+ }
}
/**
diff --git a/src/org/connectbot/util/PubkeyUtils.java b/src/org/connectbot/util/PubkeyUtils.java
index b73c58e..b62870d 100644
--- a/src/org/connectbot/util/PubkeyUtils.java
+++ b/src/org/connectbot/util/PubkeyUtils.java
@@ -41,8 +41,6 @@ import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec;
-import android.util.Log;
-
import com.trilead.ssh2.crypto.Base64;
import com.trilead.ssh2.signature.DSASHA1Verify;
import com.trilead.ssh2.signature.RSASHA1Verify;
@@ -59,7 +57,8 @@ public class PubkeyUtils {
public static String describeKey(Key key, int encrypted) {
String desc = null;
if (key instanceof RSAPublicKey) {
- desc = "RSA " + String.valueOf(((RSAPublicKey)key).getModulus().bitLength()) + "-bit";
+ int bits = ((RSAPublicKey)key).getModulus().bitLength();
+ desc = "RSA " + String.valueOf(bits) + "-bit";
} else if (key instanceof DSAPublicKey) {
desc = "DSA 1024-bit";
} else {
@@ -72,44 +71,31 @@ public class PubkeyUtils {
return desc;
}
- public static byte[] sha1(byte[] data) throws NoSuchAlgorithmException {
- MessageDigest hash = MessageDigest.getInstance("SHA-256");
- byte[] hashed = hash.digest(data);
- Log.d("KeyUtils", "hash is " + hashed.length + " bytes");
- return hash.digest(data);
+ public static byte[] sha256(byte[] data) throws NoSuchAlgorithmException {
+ return MessageDigest.getInstance("SHA-256").digest(data);
}
public static byte[] cipher(int mode, byte[] data, byte[] secret) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
- SecretKeySpec secretKeySpec = new SecretKeySpec(sha1(secret), "AES");
+ SecretKeySpec secretKeySpec = new SecretKeySpec(sha256(secret), "AES");
Cipher c = Cipher.getInstance("AES");
c.init(mode, secretKeySpec);
return c.doFinal(data);
- }
-
- public static byte[] encrypt(byte[] cleartext, byte[] secret) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
- return cipher(Cipher.ENCRYPT_MODE, cleartext, secret);
}
public static byte[] encrypt(byte[] cleartext, String secret) throws InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException {
return cipher(Cipher.ENCRYPT_MODE, cleartext, secret.getBytes());
}
- public static byte[] decrypt(byte[] ciphertext, byte[] secret) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
- return cipher(Cipher.DECRYPT_MODE, ciphertext, secret);
- }
-
public static byte[] decrypt(byte[] ciphertext, String secret) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
return cipher(Cipher.DECRYPT_MODE, ciphertext, secret.getBytes());
}
public static byte[] getEncodedPublic(PublicKey pk) {
- X509EncodedKeySpec x509 = new X509EncodedKeySpec(pk.getEncoded());
- return x509.getEncoded();
+ return new X509EncodedKeySpec(pk.getEncoded()).getEncoded();
}
public static byte[] getEncodedPrivate(PrivateKey pk) {
- PKCS8EncodedKeySpec pkcs8 = new PKCS8EncodedKeySpec(pk.getEncoded());
- return pkcs8.getEncoded();
+ return new PKCS8EncodedKeySpec(pk.getEncoded()).getEncoded();
}
public static byte[] getEncodedPrivate(PrivateKey pk, String secret) throws InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException {
@@ -153,7 +139,7 @@ public class PubkeyUtils {
dp.getP(), dp.getQ(), dp.getG(), ((DSAPublicKey) pk).getY());
}
- throw new IllegalArgumentException("PrivateKey is not RSA or DSA format");
+ throw new IllegalArgumentException("PublicKey is not RSA or DSA format");
}
public static Object convertToTrilead(PrivateKey priv, PublicKey pub) {