Compare commits

..

5 commits

Author SHA1 Message Date
6c774450ec fix: usb isd-r aid fallback (#188)
Reviewed-on: PeterCxy/OpenEUICC#188
Co-authored-by: septs <github@septs.pw>
Co-committed-by: septs <github@septs.pw>
2025-04-01 23:13:57 +02:00
00ddf09287 fix: improve lpa string parsing (#181)
Reviewed-on: PeterCxy/OpenEUICC#181
Co-authored-by: septs <github@septs.pw>
Co-committed-by: septs <github@septs.pw>
2025-04-01 03:19:21 +02:00
3662f93760 fix: send terminal capabilities (#187)
fix 9eSIM v1 (G+D) on USB

Reviewed-on: PeterCxy/OpenEUICC#187
Co-authored-by: septs <github@septs.pw>
Co-committed-by: septs <github@septs.pw>
2025-04-01 03:18:45 +02:00
05abed117a fix: click sn copy (#186)
Reviewed-on: PeterCxy/OpenEUICC#186
Co-authored-by: septs <github@septs.pw>
Co-committed-by: septs <github@septs.pw>
2025-04-01 03:18:22 +02:00
92fbfc5229 chore: add more isd-r aids (#184)
Reviewed-on: PeterCxy/OpenEUICC#184
Co-authored-by: septs <github@septs.pw>
Co-committed-by: septs <github@septs.pw>
2025-04-01 03:18:02 +02:00
9 changed files with 71 additions and 49 deletions

View file

@ -60,11 +60,11 @@ open class DefaultEuiccChannelFactory(protected val context: Context) : EuiccCha
Log.i(DefaultEuiccChannelManager.TAG, "Is OMAPI channel, setting MSS to 60")
it.lpa.setEs10xMss(60)
}
} catch (e: IllegalArgumentException) {
} catch (_: IllegalArgumentException) {
// Failed
Log.w(
DefaultEuiccChannelManager.TAG,
"OMAPI APDU interface unavailable for physical slot ${port.card.physicalSlotIndex}."
"OMAPI APDU interface unavailable for physical slot ${port.card.physicalSlotIndex} with ISD-R AID: ${isdrAid.encodeHex()}."
)
}
@ -80,20 +80,29 @@ open class DefaultEuiccChannelFactory(protected val context: Context) : EuiccCha
if (bulkIn == null || bulkOut == null) return null
val conn = usbManager.openDevice(usbDevice) ?: return null
if (!conn.claimInterface(usbInterface, true)) return null
return EuiccChannelImpl(
context.getString(R.string.usb),
FakeUiccPortInfoCompat(FakeUiccCardInfoCompat(EuiccChannelManager.USB_CHANNEL_ID)),
intrinsicChannelName = usbDevice.productName,
UsbApduInterface(
conn,
bulkIn,
bulkOut,
context.preferenceRepository.verboseLoggingFlow
),
isdrAid,
context.preferenceRepository.verboseLoggingFlow,
context.preferenceRepository.ignoreTLSCertificateFlow,
)
try {
return EuiccChannelImpl(
context.getString(R.string.usb),
FakeUiccPortInfoCompat(FakeUiccCardInfoCompat(EuiccChannelManager.USB_CHANNEL_ID)),
intrinsicChannelName = usbDevice.productName,
UsbApduInterface(
conn,
bulkIn,
bulkOut,
context.preferenceRepository.verboseLoggingFlow
),
isdrAid,
context.preferenceRepository.verboseLoggingFlow,
context.preferenceRepository.ignoreTLSCertificateFlow,
)
} catch (_: IllegalArgumentException) {
// Failed
Log.w(
DefaultEuiccChannelManager.TAG,
"USB APDU interface unavailable for ISD-R AID: ${isdrAid.encodeHex()}."
)
}
return null
}
override fun cleanup() {

View file

@ -277,11 +277,7 @@ open class DefaultEuiccChannelManager(
)
try {
val channel = tryOpenChannelFirstValidAid {
euiccChannelFactory.tryOpenUsbEuiccChannel(
device,
iface,
it
)
euiccChannelFactory.tryOpenUsbEuiccChannel(device, iface, it)
}
if (channel != null && channel.lpa.valid) {
usbChannel = channel

View file

@ -45,6 +45,15 @@ class UsbApduInterface(
e.printStackTrace()
throw e
}
// Send Terminal Capabilities
// Specs: ETSI TS 102 221 v15.0.0 - 11.1.19 TERMINAL CAPABILITY
val terminalCapabilities = buildCmd(
0x80.toByte(), 0xaa.toByte(), 0x00, 0x00,
"A9088100820101830107".decodeHex(),
le = null,
)
transmitApduByChannel(terminalCapabilities, 0)
}
override fun disconnect() {

View file

@ -104,7 +104,7 @@ class EuiccInfoActivity : BaseEuiccAccessActivity(), OpenEuiccContextMarker {
add(Item(R.string.euicc_info_eid, channel.lpa.eID, copiedToastResId = R.string.toast_eid_copied))
channel.tryParseEuiccVendorInfo()?.let { vendorInfo ->
vendorInfo.skuName?.let { add(Item(R.string.euicc_info_sku, it)) }
vendorInfo.serialNumber?.let { add(Item(R.string.euicc_info_sn, it)) }
vendorInfo.serialNumber?.let { add(Item(R.string.euicc_info_sn, it, copiedToastResId = R.string.toast_sn_copied)) }
vendorInfo.firmwareVersion?.let { add(Item(R.string.euicc_info_fw_ver, it)) }
vendorInfo.bootloaderVersion?.let { add(Item(R.string.euicc_info_bl_ver, it)) }
}

View file

@ -8,15 +8,15 @@ data class LPAString(
) {
companion object {
fun parse(input: String): LPAString {
val components = input.removePrefix("LPA:").split('$')
if (components.size < 2 || components[0] != "1") {
throw IllegalArgumentException("Invalid activation code format")
}
var token = input
if (token.startsWith("LPA:", ignoreCase = true)) token = token.drop(4)
val components = token.split('$').map { it.trim().ifBlank { null } }
require(components.getOrNull(0) == "1") { "Invalid AC_Format" }
return LPAString(
address = components[1].trim(),
matchingId = components.getOrNull(2)?.trim()?.ifBlank { null },
oid = components.getOrNull(3)?.trim()?.ifBlank { null },
confirmationCodeRequired = components.getOrNull(4)?.trim() == "1"
requireNotNull(components.getOrNull(1)) { "SM-DP+ is required" },
components.getOrNull(2),
components.getOrNull(3),
components.getOrNull(4) == "1"
)
}
}

View file

@ -45,11 +45,22 @@ const val EUICC_DEFAULT_ISDR_AID = "A0000005591010FFFFFFFF8900000100"
internal object PreferenceConstants {
val DEFAULT_AID_LIST = """
# One AID per line. Comment lines start with #.
# Refs: <https://euicc-manual.osmocom.org/docs/lpa/applet-id-oem/>
# eUICC standard
$EUICC_DEFAULT_ISDR_AID
# 5ber
# eSTK.me
A06573746B6D65FFFFFFFF4953442D52
# eSIM.me
A0000005591010000000008900000300
# 5ber.eSIM
A0000005591010FFFFFFFF8900050500
# Xesim
A0000005591010FFFFFFFF8900000177
""".trimIndent()
}
@ -97,13 +108,12 @@ class PreferenceFlowWrapper<T> private constructor(
defaultValue: T,
encoder: (T) -> T,
decoder: (T) -> T
) :
this(
context,
key,
context.dataStore.data.map { it[key]?.let(decoder) ?: defaultValue },
encoder
)
) : this(
context,
key,
context.dataStore.data.map { it[key]?.let(decoder) ?: defaultValue },
encoder
)
suspend fun updatePreference(value: T) {
context.dataStore.edit { it[key] = encoder(value) }

View file

@ -34,15 +34,12 @@ fun formatFreeSpace(size: Int): String =
* If none is found, at least EUICC_DEFAULT_ISDR_AID is returned
*/
fun parseIsdrAidList(s: String): List<ByteArray> =
s.split('\n').map(String::trim).filter { !it.startsWith('#') }
s.split('\n')
.map(String::trim)
.mapNotNull {
try {
it.decodeHex()
} catch (_: IllegalArgumentException) {
null
}
}
.filter { !it.startsWith('#') }
.map(String::trim)
.filter(String::isNotEmpty)
.mapNotNull { runCatching(it::decodeHex).getOrNull() }
.ifEmpty { listOf(EUICC_DEFAULT_ISDR_AID.decodeHex()) }
fun String.prettyPrintJson(): String {

View file

@ -11,6 +11,7 @@
android:id="@+id/isdr_aid_list_editor"
android:layout_width="0dp"
android:layout_height="0dp"
android:fontFamily="monospace"
android:importantForAutofill="no"
android:inputType="textMultiLine"
android:gravity="top|start"

View file

@ -44,11 +44,11 @@ class PrivilegedEuiccChannelFactory(context: Context) : DefaultEuiccChannelFacto
context.preferenceRepository.verboseLoggingFlow,
context.preferenceRepository.ignoreTLSCertificateFlow,
)
} catch (e: IllegalArgumentException) {
} catch (_: IllegalArgumentException) {
// Failed
Log.w(
DefaultEuiccChannelManager.TAG,
"TelephonyManager APDU interface unavailable for slot ${port.card.physicalSlotIndex} port ${port.portIndex}, falling back"
"TelephonyManager APDU interface unavailable for slot ${port.card.physicalSlotIndex} port ${port.portIndex} with ISD-R AID: ${isdrAid.encodeHex()}."
)
}
}