Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for custom ISD R AID / 5ber #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/kotlin/moe/sekiu/minilpa/Tool.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ import org.apache.commons.lang3.SystemUtils
import org.slf4j.LoggerFactory


class CONSTANTS {
companion object {
const val ISD_R_AID_FORMAT = "HH HH HH HH HH HH HH HH HH HH HH HH HH HH HH HH"
const val ISD_R_AID_DEFAULT = "A0 00 00 05 59 10 10 FF FF FF FF 89 00 00 01 00"
const val ISD_R_AID_5BER = "A0 00 00 05 59 10 10 FF FF FF FF 89 00 05 05 00"
}
}

inline fun <reified T> Any?.cast() = this as T

inline fun <reified T> Any?.castOrNull() = this as? T?
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/moe/sekiu/minilpa/lpa/LPACExecutor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class LPACExecutor() : LPABackend<Driver>
if (!lpacFile.exists() || lpacFile.isDirectory) throw OperationFailureException(language.`lpac-not-found-or-invalid`.format(lpacFile.canonicalPath))
var initialze = true
val env = mutableMapOf<String, String>()
var aid = setting.lpac.custom_aid.replace(" ", "").trim()
if (aid.length == 32) env["LPAC_CUSTOM_ISD_R_AID"] = aid
if (setting.debug.libeuicc.apdu) env["LIBEUICC_DEBUG_APDU"] = "true"
if (setting.debug.libeuicc.http) env["LIBEUICC_DEBUG_HTTP"] = "true"
LocalProfileAssistant.devices.selectedItem?.run { env["DRIVER_IFID"] = cast<Driver>().env }
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/moe/sekiu/minilpa/model/Language.kt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ data class Language @JvmOverloads constructor(
val backend : String = "Backend",
val `lpac-version` : String = "lpac Version: %s",
val `open-lpac-folder` : String = "Open lpac Folder",
val reset : String = "Reset",
val `5ber` : String = "5ber",
val `libeuicc-apdu-debug` : String = "LibEuicc APDU Debug",
val `libeuicc-http-debug` : String = "LibEuicc HTTP Debug",
val behavior : String = "Behavior",
Expand Down
7 changes: 7 additions & 0 deletions src/main/kotlin/moe/sekiu/minilpa/model/Setting.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import moe.sekiu.minilpa.language
import moe.sekiu.minilpa.lpa.LocalProfileAssistant
import moe.sekiu.minilpa.ui.component.MiniToolBar
import moe.sekiu.minilpa.yaml
import moe.sekiu.minilpa.CONSTANTS

@Serializable
data class Setting(
Expand All @@ -30,6 +31,7 @@ data class Setting(
var `emoji-design` : EmojiDesign = EmojiDesign.TWEMOJI,
var `auto-night-mode` : AutoNightMode = AutoNightMode.SYSTEM,
val debug : Debug = Debug(),
val lpac : Lpac = Lpac(),
val `notification-behavior` : NotificationBehavior = NotificationBehavior(),
var `show-details` : Boolean = true,

Expand Down Expand Up @@ -106,6 +108,11 @@ data class Setting(
)
}

@Serializable
data class Lpac(
var custom_aid : String = CONSTANTS.ISD_R_AID_DEFAULT
)

@Serializable
data class NotificationBehavior(
val install : Install = Install(),
Expand Down
24 changes: 24 additions & 0 deletions src/main/kotlin/moe/sekiu/minilpa/ui/SettingPanel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ import javax.swing.DefaultComboBoxModel
import javax.swing.JButton
import javax.swing.JCheckBox
import javax.swing.JComboBox
import javax.swing.JFormattedTextField
import javax.swing.JLabel
import javax.swing.JScrollPane
import javax.swing.JSeparator
import javax.swing.event.DocumentEvent
import javax.swing.event.DocumentListener
import javax.swing.text.MaskFormatter
import kotlinx.coroutines.runBlocking
import moe.sekiu.minilpa.BuildConfig
import moe.sekiu.minilpa.action
Expand All @@ -37,6 +41,7 @@ import moe.sekiu.minilpa.ui.component.MiniGroup
import moe.sekiu.minilpa.ui.component.MiniThemePanel
import moe.sekiu.minilpa.updateTheme
import moe.sekiu.minilpa.yaml
import moe.sekiu.minilpa.CONSTANTS
import net.miginfocom.swing.MigLayout
import org.apache.commons.lang3.SystemUtils

Expand Down Expand Up @@ -148,6 +153,25 @@ class SettingPanel : MiniPanel()
layout = MigLayout("wrap 1")
val openlpacFolder = JButton(language.`open-lpac-folder`).noFocus().action { lpacFolder.openExplorer() }
add(MiniGroup(version, openlpacFolder))

val aidMask = MaskFormatter(CONSTANTS.ISD_R_AID_FORMAT)
aidMask.setPlaceholderCharacter('0')

val customAid = JFormattedTextField(aidMask)
customAid.setValue(setting.lpac.custom_aid)
customAid.columns = 26
customAid.document.addDocumentListener(object : DocumentListener
{
override fun insertUpdate(ev : DocumentEvent) { setting.lpac.custom_aid = customAid.getText() }
override fun removeUpdate(ev : DocumentEvent) { }
override fun changedUpdate(ev : DocumentEvent) { }
})

val setAid_default = JButton(language.reset).noFocus().action { customAid.setValue(CONSTANTS.ISD_R_AID_DEFAULT) }
val setAid_5ber = JButton(language.`5ber`).noFocus().action { customAid.setValue(CONSTANTS.ISD_R_AID_5BER) }

add(MiniGroup(JLabel("ISD-R AID"), customAid, setAid_default, setAid_5ber))

add(JCheckBox(language.`libeuicc-apdu-debug`, setting.debug.libeuicc.apdu)
.noFocus().apply { action { setting.update { setting.debug.libeuicc.apdu = isSelected } } })
add(JCheckBox(language.`libeuicc-http-debug`, setting.debug.libeuicc.http)
Expand Down
1 change: 1 addition & 0 deletions src/main/languages/de_DE.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ open-log-floder: "Log Verzeichnis öffnen"
backend: "Backend"
lpac-version: "lpac Version: %s"
open-lpac-folder: "Öffne lpac Verzeichnis"
reset: "Zurücksetzen"
libeuicc-apdu-debug: "LibEuicc APDU Debug"
libeuicc-http-debug: "LibEuicc HTTP Debug"
behavior: "Verhalten"
Expand Down