From f6d8aa2e3c6934d2e049ea471ceb1becf69f1ae4 Mon Sep 17 00:00:00 2001 From: Iordan Iordanov Date: Sat, 25 Feb 2017 12:29:21 -0500 Subject: [PATCH] Fix for a bug where generating key before entering SSH hostname was discarding the connection and newly generated key. --- eclipse_projects/bVNC/AndroidManifest.xml | 2 +- .../com/iiordanov/bVNC/MainConfiguration.java | 54 ++++++++++++++-- .../bVNC/src/com/iiordanov/bVNC/aRDP.java | 60 ------------------ .../bVNC/src/com/iiordanov/bVNC/aSPICE.java | 62 ------------------ .../bVNC/src/com/iiordanov/bVNC/bVNC.java | 63 +------------------ 5 files changed, 50 insertions(+), 191 deletions(-) diff --git a/eclipse_projects/bVNC/AndroidManifest.xml b/eclipse_projects/bVNC/AndroidManifest.xml index 755bfd227..73d77ff23 100644 --- a/eclipse_projects/bVNC/AndroidManifest.xml +++ b/eclipse_projects/bVNC/AndroidManifest.xml @@ -1,7 +1,7 @@ + android:versionCode="3900" android:versionName="v3.9.0"> diff --git a/eclipse_projects/bVNC/src/com/iiordanov/bVNC/MainConfiguration.java b/eclipse_projects/bVNC/src/com/iiordanov/bVNC/MainConfiguration.java index a593be58f..07b9dc6e0 100644 --- a/eclipse_projects/bVNC/src/com/iiordanov/bVNC/MainConfiguration.java +++ b/eclipse_projects/bVNC/src/com/iiordanov/bVNC/MainConfiguration.java @@ -1,8 +1,5 @@ package com.iiordanov.bVNC; -import java.io.UnsupportedEncodingException; -import java.security.NoSuchAlgorithmException; -import java.security.spec.InvalidKeySpecException; import java.util.ArrayList; import java.util.Collections; @@ -10,10 +7,11 @@ import com.iiordanov.bVNC.dialogs.IntroTextDialog; import com.iiordanov.bVNC.dialogs.GetTextFragment; +import com.iiordanov.pubkeygenerator.GeneratePubkeyActivity; +import android.app.Activity; import android.app.ActivityManager.MemoryInfo; import android.support.v4.app.FragmentTransaction; -import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.graphics.Point; @@ -28,11 +26,11 @@ import android.view.ViewConfiguration; import android.widget.AdapterView; import android.widget.ArrayAdapter; +import android.widget.Button; import android.widget.EditText; import android.widget.Spinner; +import android.widget.Toast; -import android.content.SharedPreferences; -import android.content.SharedPreferences.Editor; import android.content.res.Configuration; public abstract class MainConfiguration extends FragmentActivity implements GetTextFragment.OnFragmentDismissedListener { @@ -49,6 +47,7 @@ public abstract class MainConfiguration extends FragmentActivity implements GetT GetTextFragment getPassword = null; GetTextFragment getNewPassword = null; private boolean isConnecting = false; + private Button buttonGeneratePubkey; protected abstract void updateViewFromSelected(); protected abstract void updateSelectedFromView(); @@ -84,6 +83,15 @@ public void onNothingSelected(AdapterView ad) { } }); + // Here we say what happens when the Pubkey Generate button is pressed. + buttonGeneratePubkey = (Button) findViewById(R.id.buttonGeneratePubkey); + buttonGeneratePubkey.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + generatePubkey (); + } + }); + database = ((App)getApplication()).getDatabase(); } @@ -206,6 +214,17 @@ public void arriveOnPage() { startingOrHasPaused = false; } + /** + * Starts the activity which manages keys. + */ + protected void generatePubkey () { + updateSelectedFromView(); + selected.saveAndWriteRecent(true, database); + Intent intent = new Intent(this, GeneratePubkeyActivity.class); + intent.putExtra("PrivateKey",selected.getSshPrivKey()); + startActivityForResult(intent, Constants.ACTIVITY_GEN_KEY); + } + public Database getDatabaseHelper() { return database; } @@ -461,4 +480,27 @@ private void removeGetPasswordFragments() { getSupportFragmentManager().executePendingTransactions(); } } + + /** + * This function is used to retrieve data returned by activities started with startActivityForResult. + */ + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + switch(requestCode) { + case (Constants.ACTIVITY_GEN_KEY): + if (resultCode == Activity.RESULT_OK) { + Bundle b = data.getExtras(); + String privateKey = (String)b.get("PrivateKey"); + if (!privateKey.equals(selected.getSshPrivKey()) && privateKey.length() != 0) + Toast.makeText(getBaseContext(), "New key generated/imported successfully. Tap 'Generate/Export Key' " + + " button to share, copy to clipboard, or export the public key now.", Toast.LENGTH_LONG).show(); + selected.setSshPrivKey(privateKey); + selected.setSshPubKey((String)b.get("PublicKey")); + selected.saveAndWriteRecent(true, database); + } else + Log.i (TAG, "The user cancelled SSH key generation."); + break; + } + } } diff --git a/eclipse_projects/bVNC/src/com/iiordanov/bVNC/aRDP.java b/eclipse_projects/bVNC/src/com/iiordanov/bVNC/aRDP.java index ff73d1e96..320e584db 100644 --- a/eclipse_projects/bVNC/src/com/iiordanov/bVNC/aRDP.java +++ b/eclipse_projects/bVNC/src/com/iiordanov/bVNC/aRDP.java @@ -19,44 +19,28 @@ package com.iiordanov.bVNC; -import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; -import android.app.ActivityManager.MemoryInfo; import android.content.DialogInterface; -import android.content.Intent; -import android.content.res.Configuration; -import net.sqlcipher.database.SQLiteDatabase; import android.os.Bundle; -import android.view.Display; -import android.view.Menu; -import android.view.MenuItem; import android.view.View; -import android.view.ViewConfiguration; import android.view.WindowManager; import android.widget.AdapterView; -import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.ListView; -import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; import android.widget.ToggleButton; import android.widget.CompoundButton.OnCheckedChangeListener; -import android.util.Log; import com.iiordanov.bVNC.Utils; import com.iiordanov.bVNC.dialogs.ImportExportDialog; import com.iiordanov.bVNC.dialogs.IntroTextDialog; -import com.iiordanov.pubkeygenerator.GeneratePubkeyActivity; - -import java.util.ArrayList; -import java.util.Collections; /** * aRDP is the Activity for setting up RDP connections. @@ -79,7 +63,6 @@ public class aRDP extends MainConfiguration { private EditText portText; private EditText passwordText; private Button goButton; - private Button buttonGeneratePubkey; private ToggleButton toggleAdvancedSettings; //private Spinner colorSpinner; private Spinner spinnerRdpGeometry; @@ -127,15 +110,6 @@ public void onCreate(Bundle icicle) { // Here we say what happens when the Pubkey Checkbox is checked/unchecked. checkboxUseSshPubkey = (CheckBox) findViewById(R.id.checkboxUseSshPubkey); - // Here we say what happens when the Pubkey Generate button is pressed. - buttonGeneratePubkey = (Button) findViewById(R.id.buttonGeneratePubkey); - buttonGeneratePubkey.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - generatePubkey (); - } - }); - // Define what happens when somebody selects different VNC connection types. connectionType = (Spinner) findViewById(R.id.connectionType); connectionType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @@ -481,38 +455,4 @@ public void setRemoteSoundTypeFromSettings (int type) { } groupRemoteSoundType.check(id); } - - /** - * Starts the activity which manages keys. - */ - private void generatePubkey () { - updateSelectedFromView(); - selected.saveAndWriteRecent(false, database); - Intent intent = new Intent(this, GeneratePubkeyActivity.class); - intent.putExtra("PrivateKey",selected.getSshPrivKey()); - startActivityForResult(intent, Constants.ACTIVITY_GEN_KEY); - } - - /** - * This function is used to retrieve data returned by activities started with startActivityForResult. - */ - @Override - public void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - switch(requestCode) { - case (Constants.ACTIVITY_GEN_KEY): - if (resultCode == Activity.RESULT_OK) { - Bundle b = data.getExtras(); - String privateKey = (String)b.get("PrivateKey"); - if (!privateKey.equals(selected.getSshPrivKey()) && privateKey.length() != 0) - Toast.makeText(getBaseContext(), "New key generated/imported successfully. Tap 'Generate/Export Key' " + - " button to share, copy to clipboard, or export the public key now.", Toast.LENGTH_LONG).show(); - selected.setSshPrivKey(privateKey); - selected.setSshPubKey((String)b.get("PublicKey")); - selected.saveAndWriteRecent(false, database); - } else - Log.i (TAG, "The user cancelled SSH key generation."); - break; - } - } } diff --git a/eclipse_projects/bVNC/src/com/iiordanov/bVNC/aSPICE.java b/eclipse_projects/bVNC/src/com/iiordanov/bVNC/aSPICE.java index 886489059..4fce9b705 100644 --- a/eclipse_projects/bVNC/src/com/iiordanov/bVNC/aSPICE.java +++ b/eclipse_projects/bVNC/src/com/iiordanov/bVNC/aSPICE.java @@ -23,28 +23,17 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintWriter; -import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; -import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; -import android.app.ActivityManager.MemoryInfo; import android.content.DialogInterface; -import android.content.Intent; import android.content.res.AssetManager; -import android.content.res.Configuration; import android.content.res.Resources; -import net.sqlcipher.database.SQLiteDatabase; import android.os.Bundle; import android.util.Log; -import android.view.Display; -import android.view.Menu; -import android.view.MenuItem; import android.view.View; -import android.view.ViewConfiguration; import android.view.WindowManager; import android.widget.AdapterView; import android.widget.ArrayAdapter; @@ -62,8 +51,6 @@ import com.iiordanov.bVNC.dialogs.ImportExportDialog; import com.iiordanov.bVNC.dialogs.ImportTlsCaDialog; -import com.iiordanov.bVNC.dialogs.IntroTextDialog; -import com.iiordanov.pubkeygenerator.GeneratePubkeyActivity; /** * aSPICE is the Activity for setting up SPICE connections. @@ -88,7 +75,6 @@ public class aSPICE extends MainConfiguration { private EditText tlsPort; private EditText passwordText; private Button goButton; - private Button buttonGeneratePubkey; private ToggleButton toggleAdvancedSettings; private Spinner spinnerGeometry; private EditText textNickname; @@ -136,15 +122,6 @@ public void onClick(View view) { // checked/unchecked. checkboxUseSshPubkey = (CheckBox) findViewById(R.id.checkboxUseSshPubkey); - // Here we say what happens when the Pubkey Generate button is pressed. - buttonGeneratePubkey = (Button) findViewById(R.id.buttonGeneratePubkey); - buttonGeneratePubkey.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - generatePubkey(); - } - }); - // Define what happens when somebody selects different VNC connection // types. connectionType = (Spinner) findViewById(R.id.connectionType); @@ -441,45 +418,6 @@ protected void updateSelectedFromView() { } } - /** - * Starts the activity which manages keys. - */ - private void generatePubkey() { - updateSelectedFromView(); - selected.saveAndWriteRecent(false, database); - Intent intent = new Intent(this, GeneratePubkeyActivity.class); - intent.putExtra("PrivateKey", selected.getSshPrivKey()); - startActivityForResult(intent, Constants.ACTIVITY_GEN_KEY); - } - - /** - * This function is used to retrieve data returned by activities started - * with startActivityForResult. - */ - @Override - public void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - switch (requestCode) { - case (Constants.ACTIVITY_GEN_KEY): - if (resultCode == Activity.RESULT_OK) { - Bundle b = data.getExtras(); - String privateKey = (String) b.get("PrivateKey"); - if (!privateKey.equals(selected.getSshPrivKey()) - && privateKey.length() != 0) - Toast.makeText( - getBaseContext(), - "New key generated/imported successfully. Tap 'Generate/Export Key' " - + " button to share, copy to clipboard, or export the public key now.", - Toast.LENGTH_LONG).show(); - selected.setSshPrivKey(privateKey); - selected.setSshPubKey((String) b.get("PublicKey")); - selected.saveAndWriteRecent(false, database); - } else - Log.i(TAG, "The user cancelled SSH key generation."); - break; - } - } - private List listFiles(String dirFrom) throws IOException { Resources res = getResources(); AssetManager am = res.getAssets(); diff --git a/eclipse_projects/bVNC/src/com/iiordanov/bVNC/bVNC.java b/eclipse_projects/bVNC/src/com/iiordanov/bVNC/bVNC.java index bf7b3de67..06a7a034a 100644 --- a/eclipse_projects/bVNC/src/com/iiordanov/bVNC/bVNC.java +++ b/eclipse_projects/bVNC/src/com/iiordanov/bVNC/bVNC.java @@ -21,21 +21,11 @@ package com.iiordanov.bVNC; -import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; -import android.app.ActivityManager.MemoryInfo; import android.content.DialogInterface; -import android.content.Intent; -import android.content.res.Configuration; -import net.sqlcipher.database.SQLiteDatabase; -import android.graphics.Point; import android.os.Bundle; -import android.view.Display; -import android.view.Menu; -import android.view.MenuItem; import android.view.View; -import android.view.ViewConfiguration; import android.view.WindowManager; import android.widget.AdapterView; import android.widget.ArrayAdapter; @@ -51,17 +41,10 @@ import android.widget.Toast; import android.widget.ToggleButton; import android.widget.CompoundButton.OnCheckedChangeListener; -import android.util.Log; -import com.iiordanov.bVNC.Utils; import com.iiordanov.bVNC.dialogs.AutoXCustomizeDialog; import com.iiordanov.bVNC.dialogs.ImportExportDialog; -import com.iiordanov.bVNC.dialogs.IntroTextDialog; import com.iiordanov.bVNC.dialogs.RepeaterDialog; -import com.iiordanov.pubkeygenerator.GeneratePubkeyActivity; - -import java.util.ArrayList; -import java.util.Collections; /** * bVNC is the Activity for setting up VNC connections. @@ -86,7 +69,6 @@ public class bVNC extends MainConfiguration { private EditText passwordText; private Button goButton; private Button repeaterButton; - private Button buttonGeneratePubkey; private Button buttonCustomizeX11Vnc; private ToggleButton toggleAdvancedSettings; private LinearLayout repeaterEntry; @@ -136,19 +118,10 @@ public void onClick(View v) { showDialog(R.layout.repeater_dialog); } }); - + // Here we say what happens when the Pubkey Checkbox is checked/unchecked. checkboxUseSshPubkey = (CheckBox) findViewById(R.id.checkboxUseSshPubkey); - // Here we say what happens when the Pubkey Generate button is pressed. - buttonGeneratePubkey = (Button) findViewById(R.id.buttonGeneratePubkey); - buttonGeneratePubkey.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - generatePubkey (); - } - }); - // Define what happens when somebody clicks on the customize auto X session dialog. buttonCustomizeX11Vnc = (Button) findViewById(R.id.buttonCustomizeX11Vnc); buttonCustomizeX11Vnc.setOnClickListener(new View.OnClickListener() { @@ -440,38 +413,4 @@ protected void updateSelectedFromView() { selected.setUseRepeater(false); } } - - /** - * Starts the activity which manages keys. - */ - private void generatePubkey () { - updateSelectedFromView(); - selected.saveAndWriteRecent(false, database); - Intent intent = new Intent(this, GeneratePubkeyActivity.class); - intent.putExtra("PrivateKey",selected.getSshPrivKey()); - startActivityForResult(intent, Constants.ACTIVITY_GEN_KEY); - } - - /** - * This function is used to retrieve data returned by activities started with startActivityForResult. - */ - @Override - public void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - switch(requestCode) { - case (Constants.ACTIVITY_GEN_KEY): - if (resultCode == Activity.RESULT_OK) { - Bundle b = data.getExtras(); - String privateKey = (String)b.get("PrivateKey"); - if (!privateKey.equals(selected.getSshPrivKey()) && privateKey.length() != 0) - Toast.makeText(getBaseContext(), "New key generated/imported successfully. Tap 'Generate/Export Key' " + - " button to share, copy to clipboard, or export the public key now.", Toast.LENGTH_LONG).show(); - selected.setSshPrivKey(privateKey); - selected.setSshPubKey((String)b.get("PublicKey")); - selected.saveAndWriteRecent(false, database); - } else - Log.i (TAG, "The user cancelled SSH key generation."); - break; - } - } }