Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 6745b62

Browse files
committed
Use SSHJ for SSH public key authentication
1 parent 1566524 commit 6745b62

17 files changed

+402
-350
lines changed

app/build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ dependencies {
101101
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
102102
}
103103
implementation deps.third_party.jsch
104+
implementation deps.third_party.sshj
105+
implementation deps.third_party.bouncycastle
104106
implementation deps.third_party.openpgp_ktx
105107
implementation deps.third_party.ssh_auth
106108
implementation deps.third_party.timber

app/lint.xml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?><!--
2+
~ Copyright © 2014-2020 The Android Password Store Authors. All Rights Reserved.
3+
~ SPDX-License-Identifier: GPL-3.0-only
4+
-->
5+
<lint>
6+
<issue id="InvalidPackage">
7+
<ignore regexp="X509LDAPCertStoreSpi" />
8+
</issue>
9+
</lint>

app/proguard-rules.pro

+3
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@
2424
-dontobfuscate
2525
-keep class com.jcraft.jsch.**
2626
-keep class org.eclipse.jgit.internal.JGitText { *; }
27+
-keep class org.bouncycastle.jcajce.provider.** { *; }
28+
-keep class org.bouncycastle.jce.provider.** { *; }
29+
-keep class !org.bouncycastle.jce.provider.X509LDAPCertStoreSpi { *; }

app/src/main/java/com/zeapo/pwdstore/git/BaseGitActivity.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,11 @@ abstract class BaseGitActivity : AppCompatActivity() {
146146
}
147147
if (PasswordRepository.isInitialized)
148148
PasswordRepository.addRemote("origin", newUrl, true)
149-
// HTTPS authentication sends the password to the server, so we must wipe the password when
150-
// the server is changed.
151-
if (previousUrl.isNotEmpty() && newUrl != previousUrl && protocol == Protocol.Https)
149+
// When the server changes, remote password and host key file should be deleted.
150+
if (previousUrl.isNotEmpty() && newUrl != previousUrl) {
152151
encryptedSettings.edit { remove("https_password") }
152+
File("$filesDir/.host_key").delete()
153+
}
153154
url = newUrl
154155
return GitUpdateUrlResult.Ok
155156
}
@@ -201,8 +202,7 @@ abstract class BaseGitActivity : AppCompatActivity() {
201202
return
202203
}
203204
}
204-
op.executeAfterAuthentication(connectionMode, serverUser,
205-
File("$filesDir/.ssh_key"), identity)
205+
op.executeAfterAuthentication(connectionMode, serverUser, identity)
206206
} catch (e: Exception) {
207207
e.printStackTrace()
208208
MaterialAlertDialogBuilder(this).setMessage(e.message).show()

app/src/main/java/com/zeapo/pwdstore/git/BreakOutOfDetached.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ class BreakOutOfDetached(fileDir: File, callingActivity: Activity) : GitOperatio
6262
.execute(*this.commands.toTypedArray())
6363
}
6464

65-
override fun onError(errorMessage: String) {
65+
override fun onError(err: Exception) {
6666
MaterialAlertDialogBuilder(callingActivity)
6767
.setTitle(callingActivity.resources.getString(R.string.jgit_error_dialog_title))
68-
.setMessage("Error occurred when checking out another branch operation $errorMessage")
68+
.setMessage("Error occurred when checking out another branch operation ${err.message}")
6969
.setPositiveButton(callingActivity.resources.getString(R.string.dialog_ok)) { _, _ ->
7070
callingActivity.finish()
7171
}.show()

app/src/main/java/com/zeapo/pwdstore/git/CloneOperation.kt

+3-28
Original file line numberDiff line numberDiff line change
@@ -34,43 +34,18 @@ class CloneOperation(fileDir: File, callingActivity: Activity) : GitOperation(fi
3434
return this
3535
}
3636

37-
/**
38-
* sets the authentication for user/pwd scheme
39-
*
40-
* @param username the username
41-
* @param password the password
42-
* @return the current object
43-
*/
44-
public override fun setAuthentication(username: String, password: String): CloneOperation {
45-
super.setAuthentication(username, password)
46-
return this
47-
}
48-
49-
/**
50-
* sets the authentication for the ssh-key scheme
51-
*
52-
* @param sshKey the ssh-key file
53-
* @param username the username
54-
* @param passphrase the passphrase
55-
* @return the current object
56-
*/
57-
public override fun setAuthentication(sshKey: File, username: String, passphrase: String): CloneOperation {
58-
super.setAuthentication(sshKey, username, passphrase)
59-
return this
60-
}
61-
6237
override fun execute() {
6338
(this.command as? CloneCommand)?.setCredentialsProvider(this.provider)
6439
GitAsyncTask(callingActivity, false, this, Intent()).execute(this.command)
6540
}
6641

67-
override fun onError(errorMessage: String) {
68-
super.onError(errorMessage)
42+
override fun onError(err: Exception) {
43+
super.onError(err)
6944
MaterialAlertDialogBuilder(callingActivity)
7045
.setTitle(callingActivity.resources.getString(R.string.jgit_error_dialog_title))
7146
.setMessage("Error occurred during the clone operation, " +
7247
callingActivity.resources.getString(R.string.jgit_error_dialog_text) +
73-
errorMessage +
48+
err.message +
7449
"\nPlease check the FAQ for possible reasons why this error might occur.")
7550
.setPositiveButton(callingActivity.resources.getString(R.string.dialog_ok)) { _, _ -> }
7651
.show()

app/src/main/java/com/zeapo/pwdstore/git/GitAsyncTask.java

-145
This file was deleted.

0 commit comments

Comments
 (0)