Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
Fix RSA Keys not stored
Browse files Browse the repository at this point in the history
  • Loading branch information
jamal2362 committed May 22, 2024
1 parent 581d37e commit 3ca5f85
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
41 changes: 37 additions & 4 deletions app/src/main/java/com/jamal2367/coreelec/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.tananaev.adblib.AdbBase64
import com.tananaev.adblib.AdbConnection
import com.tananaev.adblib.AdbCrypto
import com.tananaev.adblib.AdbStream
import java.io.File
import java.lang.ref.WeakReference
import java.net.Inet4Address
import java.net.NetworkInterface
Expand All @@ -33,6 +34,8 @@ class MainActivity : Activity() {
private var connection: AdbConnection? = null
private var stream: AdbStream? = null
private var myAsyncTask: MyAsyncTask? = null
private val publicKeyName: String = "public.key"
private val privateKeyName: String = "private.key"

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -79,8 +82,6 @@ class MainActivity : Activity() {
}

private fun onKeyCE(case: Int) {
Toast.makeText(this, getString(R.string.allow_usb_debugging_dialog), Toast.LENGTH_SHORT).show()

connection = null
stream = null

Expand All @@ -91,11 +92,11 @@ class MainActivity : Activity() {

fun adbCommander(ip: String?, case: Int) {
val socket = Socket(ip, 5555)
val generateAdbKeyPair = AdbCrypto.generateAdbKeyPair(AndroidBase64())
val crypto = readCryptoConfig(filesDir) ?: writeNewCryptoConfig(filesDir)

try {
if (stream == null || connection == null) {
connection = AdbConnection.create(socket, generateAdbKeyPair)
connection = AdbConnection.create(socket, crypto)
connection?.connect()
}

Expand Down Expand Up @@ -123,6 +124,38 @@ class MainActivity : Activity() {
}
}

private fun readCryptoConfig(dataDir: File?): AdbCrypto? {
val pubKey = File(dataDir, publicKeyName)
val privKey = File(dataDir, privateKeyName)

var crypto: AdbCrypto? = null
if (pubKey.exists() && privKey.exists()) {
crypto = try {
AdbCrypto.loadAdbKeyPair(AndroidBase64(), privKey, pubKey)
} catch (e: Exception) {
null
}
}

return crypto
}

private fun writeNewCryptoConfig(dataDir: File?): AdbCrypto? {
val pubKey = File(dataDir, publicKeyName)
val privKey = File(dataDir, privateKeyName)

var crypto: AdbCrypto?

try {
crypto = AdbCrypto.generateAdbKeyPair(AndroidBase64())
crypto.saveAdbKeyPair(privKey, pubKey)
} catch (e: Exception) {
crypto = null
}

return crypto
}

private fun openDeveloperSettings() {
val intent = Intent(Settings.ACTION_SETTINGS)
startActivity(intent)
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Neustart zu CoreELEC</string>
<string name="allow_usb_debugging_dialog">Das Dialogfeld für USB-Debugging bitte zulassen</string>
<string name="enable_usb_debugging_first">Aktiviere zuerst USB-Debugging in den Entwickleroptionen</string>
<string name="first_reboot_to_coreelec">Erster Neustart</string>
<string name="first_reboot_to_coreelec_info">"'"&lt;b>Erster Neustart&lt;/b>"'" muss beim ersten Start von CoreELEC oder nach einem Update des Android-Systems ausgeführt werden.</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-hu/strings.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Újraindítás CoreELEC-el</string>
<string name="allow_usb_debugging_dialog">Kérjük, engedélyezze a párbeszédpanelt az USB-hibakereséshez</string>
<string name="enable_usb_debugging_first">Először engedélyezze az USB hibakeresést a fejlesztői beállításoknál</string>
<string name="first_reboot_to_coreelec">Első újraindítás</string>
<string name="first_reboot_to_coreelec_info">"'"&lt;b>Első újraindítás&lt;/b>"'" a CoreELEC első indításakor vagy az Android rendszer frissítése után kell végrehajtani.</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Reboot to CoreELEC</string>
<string name="allow_usb_debugging_dialog">Please allow the dialog box for USB debugging</string>
<string name="enable_usb_debugging_first">Enable USB debugging first in the developer options</string>
<string name="first_reboot_to_coreelec">First reboot</string>
<string name="first_reboot_to_coreelec_info">"'"&lt;b>First reboot&lt;/b>"'" must be executed when CoreELEC is started for the first time or after an update of the Android system.</string>
Expand Down

0 comments on commit 3ca5f85

Please sign in to comment.