fix: usb isd-r aid fallback #188
5 changed files with 34 additions and 32 deletions
|
@ -60,11 +60,11 @@ open class DefaultEuiccChannelFactory(protected val context: Context) : EuiccCha
|
||||||
Log.i(DefaultEuiccChannelManager.TAG, "Is OMAPI channel, setting MSS to 60")
|
Log.i(DefaultEuiccChannelManager.TAG, "Is OMAPI channel, setting MSS to 60")
|
||||||
it.lpa.setEs10xMss(60)
|
it.lpa.setEs10xMss(60)
|
||||||
}
|
}
|
||||||
} catch (e: IllegalArgumentException) {
|
} catch (_: IllegalArgumentException) {
|
||||||
// Failed
|
// Failed
|
||||||
Log.w(
|
Log.w(
|
||||||
DefaultEuiccChannelManager.TAG,
|
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
|
if (bulkIn == null || bulkOut == null) return null
|
||||||
val conn = usbManager.openDevice(usbDevice) ?: return null
|
val conn = usbManager.openDevice(usbDevice) ?: return null
|
||||||
if (!conn.claimInterface(usbInterface, true)) return null
|
if (!conn.claimInterface(usbInterface, true)) return null
|
||||||
return EuiccChannelImpl(
|
try {
|
||||||
context.getString(R.string.usb),
|
return EuiccChannelImpl(
|
||||||
FakeUiccPortInfoCompat(FakeUiccCardInfoCompat(EuiccChannelManager.USB_CHANNEL_ID)),
|
context.getString(R.string.usb),
|
||||||
intrinsicChannelName = usbDevice.productName,
|
FakeUiccPortInfoCompat(FakeUiccCardInfoCompat(EuiccChannelManager.USB_CHANNEL_ID)),
|
||||||
UsbApduInterface(
|
intrinsicChannelName = usbDevice.productName,
|
||||||
conn,
|
UsbApduInterface(
|
||||||
bulkIn,
|
conn,
|
||||||
bulkOut,
|
bulkIn,
|
||||||
context.preferenceRepository.verboseLoggingFlow
|
bulkOut,
|
||||||
),
|
context.preferenceRepository.verboseLoggingFlow
|
||||||
isdrAid,
|
),
|
||||||
context.preferenceRepository.verboseLoggingFlow,
|
isdrAid,
|
||||||
context.preferenceRepository.ignoreTLSCertificateFlow,
|
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() {
|
override fun cleanup() {
|
||||||
|
|
|
@ -277,11 +277,7 @@ open class DefaultEuiccChannelManager(
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
val channel = tryOpenChannelFirstValidAid {
|
val channel = tryOpenChannelFirstValidAid {
|
||||||
euiccChannelFactory.tryOpenUsbEuiccChannel(
|
euiccChannelFactory.tryOpenUsbEuiccChannel(device, iface, it)
|
||||||
device,
|
|
||||||
iface,
|
|
||||||
it
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
if (channel != null && channel.lpa.valid) {
|
if (channel != null && channel.lpa.valid) {
|
||||||
usbChannel = channel
|
usbChannel = channel
|
||||||
|
|
|
@ -53,7 +53,7 @@ class UsbApduInterface(
|
||||||
"A9088100820101830107".decodeHex(),
|
"A9088100820101830107".decodeHex(),
|
||||||
le = null,
|
le = null,
|
||||||
)
|
)
|
||||||
transmitApduByChannel(terminalCapabilities, 0,)
|
transmitApduByChannel(terminalCapabilities, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun disconnect() {
|
override fun disconnect() {
|
||||||
|
|
|
@ -34,15 +34,12 @@ fun formatFreeSpace(size: Int): String =
|
||||||
* If none is found, at least EUICC_DEFAULT_ISDR_AID is returned
|
* If none is found, at least EUICC_DEFAULT_ISDR_AID is returned
|
||||||
*/
|
*/
|
||||||
fun parseIsdrAidList(s: String): List<ByteArray> =
|
fun parseIsdrAidList(s: String): List<ByteArray> =
|
||||||
s.split('\n').map(String::trim).filter { !it.startsWith('#') }
|
s.split('\n')
|
||||||
.map(String::trim)
|
.map(String::trim)
|
||||||
.mapNotNull {
|
.filter { !it.startsWith('#') }
|
||||||
try {
|
.map(String::trim)
|
||||||
it.decodeHex()
|
.filter(String::isNotEmpty)
|
||||||
} catch (_: IllegalArgumentException) {
|
.mapNotNull { runCatching(it::decodeHex).getOrNull() }
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.ifEmpty { listOf(EUICC_DEFAULT_ISDR_AID.decodeHex()) }
|
.ifEmpty { listOf(EUICC_DEFAULT_ISDR_AID.decodeHex()) }
|
||||||
|
|
||||||
fun String.prettyPrintJson(): String {
|
fun String.prettyPrintJson(): String {
|
||||||
|
|
|
@ -44,11 +44,11 @@ class PrivilegedEuiccChannelFactory(context: Context) : DefaultEuiccChannelFacto
|
||||||
context.preferenceRepository.verboseLoggingFlow,
|
context.preferenceRepository.verboseLoggingFlow,
|
||||||
context.preferenceRepository.ignoreTLSCertificateFlow,
|
context.preferenceRepository.ignoreTLSCertificateFlow,
|
||||||
)
|
)
|
||||||
} catch (e: IllegalArgumentException) {
|
} catch (_: IllegalArgumentException) {
|
||||||
// Failed
|
// Failed
|
||||||
Log.w(
|
Log.w(
|
||||||
DefaultEuiccChannelManager.TAG,
|
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()}."
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue