diff options
-rw-r--r-- | res/layout/act_generatepubkey.xml | 124 | ||||
-rw-r--r-- | src/org/connectbot/util/HostDatabase.java | 8 | ||||
-rw-r--r-- | src/org/connectbot/util/PubkeyUtils.java | 30 |
3 files changed, 78 insertions, 84 deletions
diff --git a/res/layout/act_generatepubkey.xml b/res/layout/act_generatepubkey.xml index 4b73735..0a21104 100644 --- a/res/layout/act_generatepubkey.xml +++ b/res/layout/act_generatepubkey.xml @@ -17,70 +17,74 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. --> -<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:orientation="vertical" - android:layout_width="wrap_content" +<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" - android:paddingLeft="10dip" - android:paddingRight="10dip" - android:scrollbars="vertical"> - - <TableRow> - <TextView android:text="Nickname:" android:paddingRight="10dip" android:gravity="right|center_vertical" android:textAppearance="?android:attr/textAppearanceMedium" /> - <EditText android:id="@+id/nickname" android:hint="My work key" android:layout_width="200dip" android:layout_height="wrap_content" /> - </TableRow> - - <TableRow> - <TextView android:text="Type:" android:paddingRight="10dip" android:textAppearance="?android:attr/textAppearanceMedium" android:gravity="bottom|right" android:layout_gravity="center_vertical"/> - <RadioGroup - android:id="@+id/key_type" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:orientation="horizontal" - android:checkedButton="@+id/rsa"> - - <RadioButton - android:id="@+id/rsa" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="RSA" - android:paddingRight="30dip" - /> - - <RadioButton - android:id="@+id/dsa" + android:scrollbars="vertical" android:layout_width="fill_parent"> + + <TableLayout + android:orientation="vertical" + android:layout_height="wrap_content" + android:paddingLeft="10dip" + android:paddingRight="10dip" + android:scrollbars="vertical" android:layout_width="wrap_content"> + + <TableRow> + <TextView android:text="Nickname:" android:paddingRight="10dip" android:gravity="right|center_vertical" android:textAppearance="?android:attr/textAppearanceMedium" /> + <EditText android:id="@+id/nickname" android:hint="My work key" android:layout_height="wrap_content" android:singleLine="true" /> + </TableRow> + + <TableRow> + <TextView android:text="Type:" android:paddingRight="10dip" android:textAppearance="?android:attr/textAppearanceMedium" android:gravity="bottom|right" android:layout_gravity="center_vertical"/> + <RadioGroup + android:id="@+id/key_type" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="DSA" - /> - - </RadioGroup> - </TableRow> + android:orientation="horizontal" + android:checkedButton="@+id/rsa"> + + <RadioButton + android:id="@+id/rsa" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="RSA" + android:paddingRight="30dip" + /> + + <RadioButton + android:id="@+id/dsa" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="DSA" + /> - <TableRow> - <TextView android:text="Bits:" android:paddingRight="10dip" android:textAppearance="?android:attr/textAppearanceMedium" android:gravity="right|center_vertical" /> - <EditText android:id="@+id/bits" android:layout_width="200dip" android:layout_height="wrap_content" android:text="1024" android:numeric="integer"/> - </TableRow> - - <SeekBar android:layout_height="wrap_content" android:id="@+id/bits_slider" android:layout_width="fill_parent" android:paddingBottom="10dip" android:max="3328" android:progress="256"/> - - <TextView android:text="Note: password can be blank" android:gravity="right" android:layout_height="wrap_content" android:layout_width="wrap_content" /> - - <TableRow> - <TextView android:gravity="right|center_vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="Password:" /> - <EditText android:id="@+id/password1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:password="true"></EditText> - </TableRow> + </RadioGroup> + </TableRow> + + <TableRow> + <TextView android:text="Bits:" android:paddingRight="10dip" android:textAppearance="?android:attr/textAppearanceMedium" android:gravity="right|center_vertical" /> + <EditText android:id="@+id/bits" android:layout_height="wrap_content" android:text="1024" android:numeric="integer" android:singleLine="true" /> + </TableRow> + + <SeekBar android:layout_height="wrap_content" android:id="@+id/bits_slider" android:layout_width="fill_parent" android:paddingBottom="10dip" android:max="3328" android:progress="256"/> - <TableRow> - <LinearLayout android:orientation="vertical" android:gravity="right|center_vertical" > - <TextView android:gravity="right|bottom" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="Password:" /> - <TextView android:gravity="right|top" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceSmall" android:text="(again)" /> - </LinearLayout> - <EditText android:id="@+id/password2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:password="true"></EditText> - </TableRow> + <TextView android:text="Note: password can be blank" android:gravity="right" android:layout_height="wrap_content" android:layout_width="wrap_content" /> - <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/unlock_at_startup" android:text="Unlock when ConnectBot starts"/> + <TableRow> + <TextView android:gravity="right|center_vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="Password:" /> + <EditText android:id="@+id/password1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:password="true" android:singleLine="true"/> + </TableRow> + + <TableRow> + <LinearLayout android:orientation="vertical" android:gravity="right|center_vertical" > + <TextView android:gravity="right|bottom" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="Password:" /> + <TextView android:gravity="right|top" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceSmall" android:text="(again)" /> + </LinearLayout> + <EditText android:id="@+id/password2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:password="true" android:singleLine="true"/> + </TableRow> + + <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/unlock_at_startup" android:text="Unlock when ConnectBot starts"/> + + <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/save" android:text="Save" android:enabled="false"/> - <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/save" android:text="Save" android:enabled="false"/> - -</TableLayout>
\ No newline at end of file + </TableLayout> +</ScrollView>
\ No newline at end of file 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) { |