Skip to content

Commit

Permalink
Fix for a bug where generating key before entering SSH hostname was d…
Browse files Browse the repository at this point in the history
…iscarding

the connection and newly generated key.
  • Loading branch information
iiordanov committed Feb 25, 2017
1 parent 92c69fe commit f6d8aa2
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 191 deletions.
2 changes: 1 addition & 1 deletion eclipse_projects/bVNC/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iiordanov.bVNC" android:installLocation="auto"
android:versionCode="3891" android:versionName="v3.8.9">
android:versionCode="3900" android:versionName="v3.9.0">

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="10"></uses-sdk>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
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;

import net.sqlcipher.database.SQLiteDatabase;

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;
Expand All @@ -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 {
Expand All @@ -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();
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
}
60 changes: 0 additions & 60 deletions eclipse_projects/bVNC/src/com/iiordanov/bVNC/aRDP.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}
}
}
62 changes: 0 additions & 62 deletions eclipse_projects/bVNC/src/com/iiordanov/bVNC/aSPICE.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<String> listFiles(String dirFrom) throws IOException {
Resources res = getResources();
AssetManager am = res.getAssets();
Expand Down
Loading

0 comments on commit f6d8aa2

Please sign in to comment.