Compare commits

..

2 commits

Author SHA1 Message Date
b090bb007c
fix: usb isd-r aid fallback 2025-04-01 20:39:12 +08:00
384270f57b
fix: usb isd-r aid fallback 2025-04-01 18:39:43 +08:00
4 changed files with 27 additions and 32 deletions

View file

@ -60,7 +60,7 @@ open class DefaultEuiccChannelFactory(protected val context: Context) : EuiccCha
Log.i(DefaultEuiccChannelManager.TAG, "Is OMAPI channel, setting MSS to 60")
it.lpa.setEs10xMss(60)
}
} catch (_: IllegalArgumentException) {
} catch (e: IllegalArgumentException) {
// Failed
Log.w(
DefaultEuiccChannelManager.TAG,
@ -80,29 +80,20 @@ 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
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 ${usbDevice.vendorId}:${usbDevice.productId}."
)
}
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,
)
}
override fun cleanup() {

View file

@ -55,7 +55,7 @@ open class DefaultEuiccChannelManager(
parseIsdrAidList(appContainer.preferenceRepository.isdrAidListFlow.first())
return isdrAidList.firstNotNullOfOrNull {
Log.i(TAG, "Opening channel, trying ISDR AID ${it.encodeHex()}")
Log.i(TAG, "Opening channel, trying ISD-R AID: ${it.encodeHex()}")
openFn(it)?.let { channel ->
if (channel.valid) {

View file

@ -70,12 +70,12 @@ class UsbApduInterface(
transmitApduByChannel(req, 0)
} catch (e: Exception) {
e.printStackTrace()
return -1
return 0
}
if (!isSuccessResponse(resp)) {
Log.d(TAG, "OPEN LOGICAL CHANNEL failed: ${resp.encodeHex()}")
return -1
return 0
}
val channelId = resp[0].toInt()
@ -87,7 +87,7 @@ class UsbApduInterface(
if (!isSuccessResponse(selectAidResp)) {
Log.d(TAG, "Select DF failed : ${selectAidResp.encodeHex()}")
return -1
return 0
}
channels.add(channelId)

View file

@ -34,12 +34,16 @@ 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).filter { !it.startsWith('#') }
.map(String::trim)
.filter(String::isNotEmpty)
.mapNotNull { runCatching(it::decodeHex).getOrNull() }
.mapNotNull {
try {
it.decodeHex()
} catch (_: IllegalArgumentException) {
null
}
}
.ifEmpty { listOf(EUICC_DEFAULT_ISDR_AID.decodeHex()) }
fun String.prettyPrintJson(): String {