detect wrong ssh-key passphrase
This commit is contained in:
parent
b22a221fe9
commit
fd9e958d40
1 changed files with 25 additions and 4 deletions
|
@ -88,7 +88,20 @@ public abstract class GitOperation {
|
||||||
* @param sshKey the ssh-key file
|
* @param sshKey the ssh-key file
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public void executeAfterAuthentication(String connectionMode, final String username, @Nullable final File sshKey) throws Exception {
|
public void executeAfterAuthentication(final String connectionMode, final String username, @Nullable final File sshKey) throws Exception {
|
||||||
|
executeAfterAuthentication(connectionMode, username, sshKey, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes the GitCommand in an async task after creating the authentication
|
||||||
|
*
|
||||||
|
* @param connectionMode the server-connection mode
|
||||||
|
* @param username the username
|
||||||
|
* @param sshKey the ssh-key file
|
||||||
|
* @param showError show the passphrase edit text in red
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private void executeAfterAuthentication(final String connectionMode, final String username, @Nullable final File sshKey, final boolean showError) throws Exception {
|
||||||
if (connectionMode.equalsIgnoreCase("ssh-key")) {
|
if (connectionMode.equalsIgnoreCase("ssh-key")) {
|
||||||
if (sshKey == null || !sshKey.exists()) {
|
if (sshKey == null || !sshKey.exists()) {
|
||||||
new AlertDialog.Builder(callingActivity)
|
new AlertDialog.Builder(callingActivity)
|
||||||
|
@ -135,8 +148,11 @@ public abstract class GitOperation {
|
||||||
passphrase.setHint("Passphrase");
|
passphrase.setHint("Passphrase");
|
||||||
passphrase.setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
|
passphrase.setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
|
||||||
passphrase.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
passphrase.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
||||||
|
if (showError) {
|
||||||
|
passphrase.setError("Wrong passphrase");
|
||||||
|
}
|
||||||
JSch jsch = new JSch();
|
JSch jsch = new JSch();
|
||||||
KeyPair keyPair = KeyPair.load(jsch, callingActivity.getFilesDir() + "/.ssh_key");
|
final KeyPair keyPair = KeyPair.load(jsch, callingActivity.getFilesDir() + "/.ssh_key");
|
||||||
if (keyPair.isEncrypted()) {
|
if (keyPair.isEncrypted()) {
|
||||||
new AlertDialog.Builder(callingActivity)
|
new AlertDialog.Builder(callingActivity)
|
||||||
.setTitle(callingActivity.getResources().getString(R.string.passphrase_dialog_title))
|
.setTitle(callingActivity.getResources().getString(R.string.passphrase_dialog_title))
|
||||||
|
@ -145,8 +161,13 @@ public abstract class GitOperation {
|
||||||
.setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
|
.setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int whichButton) {
|
public void onClick(DialogInterface dialog, int whichButton) {
|
||||||
try {
|
try {
|
||||||
// Authenticate using the ssh-key and then execute the command
|
if (keyPair.decrypt(passphrase.getText().toString())) {
|
||||||
setAuthentication(sshKey, username, passphrase.getText().toString()).execute();
|
// Authenticate using the ssh-key and then execute the command
|
||||||
|
setAuthentication(sshKey, username, passphrase.getText().toString()).execute();
|
||||||
|
} else {
|
||||||
|
// call back the method
|
||||||
|
executeAfterAuthentication(connectionMode, username, sshKey, true);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue