Compare commits

..

2 commits

Author SHA1 Message Date
03bfdf373c lpac-jni: Expose customizable ISDR AIDs from lpac
...so that we could expose an option to the user going forward.
2025-02-17 17:07:11 -05:00
9517f53712 chore: Update lpac dependency 2025-02-15 14:26:45 -05:00
5 changed files with 32 additions and 4 deletions

View file

@ -15,12 +15,21 @@ class EuiccChannelImpl(
verboseLoggingFlow: Flow<Boolean>, verboseLoggingFlow: Flow<Boolean>,
ignoreTLSCertificateFlow: Flow<Boolean> ignoreTLSCertificateFlow: Flow<Boolean>
) : EuiccChannel { ) : EuiccChannel {
companion object {
// TODO: This needs to go somewhere else.
val ISDR_AID = "A0000005591010FFFFFFFF8900000100".decodeHex()
}
override val slotId = port.card.physicalSlotIndex override val slotId = port.card.physicalSlotIndex
override val logicalSlotId = port.logicalSlotIndex override val logicalSlotId = port.logicalSlotIndex
override val portId = port.portIndex override val portId = port.portIndex
override val lpa: LocalProfileAssistant = override val lpa: LocalProfileAssistant =
LocalProfileAssistantImpl(apduInterface, HttpInterfaceImpl(verboseLoggingFlow, ignoreTLSCertificateFlow)) LocalProfileAssistantImpl(
ISDR_AID,
apduInterface,
HttpInterfaceImpl(verboseLoggingFlow, ignoreTLSCertificateFlow)
)
override val atr: ByteArray? override val atr: ByteArray?
get() = (apduInterface as? ApduInterfaceAtrProvider)?.atr get() = (apduInterface as? ApduInterfaceAtrProvider)?.atr

View file

@ -5,7 +5,11 @@ internal object LpacJni {
System.loadLibrary("lpac-jni") System.loadLibrary("lpac-jni")
} }
external fun createContext(apduInterface: ApduInterface, httpInterface: HttpInterface): Long external fun createContext(
isdrAid: ByteArray,
apduInterface: ApduInterface,
httpInterface: HttpInterface
): Long
external fun destroyContext(handle: Long) external fun destroyContext(handle: Long)
external fun euiccInit(handle: Long): Int external fun euiccInit(handle: Long): Int

View file

@ -12,6 +12,7 @@ import net.typeblog.lpac_jni.LocalProfileNotification
import net.typeblog.lpac_jni.ProfileDownloadCallback import net.typeblog.lpac_jni.ProfileDownloadCallback
class LocalProfileAssistantImpl( class LocalProfileAssistantImpl(
isdrAid: ByteArray,
rawApduInterface: ApduInterface, rawApduInterface: ApduInterface,
rawHttpInterface: HttpInterface rawHttpInterface: HttpInterface
): LocalProfileAssistant { ): LocalProfileAssistant {
@ -76,7 +77,7 @@ class LocalProfileAssistantImpl(
private val httpInterface = HttpInterfaceWrapper(rawHttpInterface) private val httpInterface = HttpInterfaceWrapper(rawHttpInterface)
private var finalized = false private var finalized = false
private var contextHandle: Long = LpacJni.createContext(apduInterface, httpInterface) private var contextHandle: Long = LpacJni.createContext(isdrAid, apduInterface, httpInterface)
init { init {
if (LpacJni.euiccInit(contextHandle) < 0) { if (LpacJni.euiccInit(contextHandle) < 0) {

@ -1 +1 @@
Subproject commit a5a0516f084936e7e87cf7420fb99283fa3052ef Subproject commit 90f7104847d4bb392b275746da20a55177a67573

View file

@ -37,17 +37,30 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) {
JNIEXPORT jlong JNICALL JNIEXPORT jlong JNICALL
Java_net_typeblog_lpac_1jni_LpacJni_createContext(JNIEnv *env, jobject thiz, Java_net_typeblog_lpac_1jni_LpacJni_createContext(JNIEnv *env, jobject thiz,
jbyteArray isdr_aid,
jobject apdu_interface, jobject apdu_interface,
jobject http_interface) { jobject http_interface) {
struct lpac_jni_ctx *jni_ctx = NULL; struct lpac_jni_ctx *jni_ctx = NULL;
struct euicc_ctx *ctx = NULL; struct euicc_ctx *ctx = NULL;
jbyte *isdr_java = NULL;
uint32_t isdr_len = 0;
uint8_t *isdr_c = NULL;
ctx = calloc(1, sizeof(struct euicc_ctx)); ctx = calloc(1, sizeof(struct euicc_ctx));
jni_ctx = calloc(1, sizeof(struct lpac_jni_ctx)); jni_ctx = calloc(1, sizeof(struct lpac_jni_ctx));
isdr_java = (*env)->GetByteArrayElements(env, isdr_aid, JNI_FALSE);
isdr_len = (*env)->GetArrayLength(env, isdr_aid);
isdr_c = calloc(isdr_len, sizeof(uint8_t));
memcpy(isdr_c, isdr_java, isdr_len);
(*env)->ReleaseByteArrayElements(env, isdr_aid, isdr_java, JNI_ABORT);
ctx->apdu.interface = &lpac_jni_apdu_interface; ctx->apdu.interface = &lpac_jni_apdu_interface;
ctx->http.interface = &lpac_jni_http_interface; ctx->http.interface = &lpac_jni_http_interface;
jni_ctx->apdu_interface = (*env)->NewGlobalRef(env, apdu_interface); jni_ctx->apdu_interface = (*env)->NewGlobalRef(env, apdu_interface);
jni_ctx->http_interface = (*env)->NewGlobalRef(env, http_interface); jni_ctx->http_interface = (*env)->NewGlobalRef(env, http_interface);
ctx->aid = (const uint8_t *) isdr_c;
ctx->aid_len = isdr_len;
ctx->userdata = (void *) jni_ctx; ctx->userdata = (void *) jni_ctx;
return (jlong) ctx; return (jlong) ctx;
} }
@ -60,6 +73,7 @@ Java_net_typeblog_lpac_1jni_LpacJni_destroyContext(JNIEnv *env, jobject thiz, jl
(*env)->DeleteGlobalRef(env, jni_ctx->apdu_interface); (*env)->DeleteGlobalRef(env, jni_ctx->apdu_interface);
(*env)->DeleteGlobalRef(env, jni_ctx->http_interface); (*env)->DeleteGlobalRef(env, jni_ctx->http_interface);
free(jni_ctx); free(jni_ctx);
free((void *) ctx->aid);
free(ctx); free(ctx);
} }