lpac-jni: Expose customizable ISDR AIDs from lpac
All checks were successful
/ build-debug (push) Successful in 4m40s
All checks were successful
/ build-debug (push) Successful in 4m40s
...so that we could expose an option to the user going forward.
This commit is contained in:
parent
9517f53712
commit
03bfdf373c
4 changed files with 31 additions and 3 deletions
|
@ -15,12 +15,21 @@ class EuiccChannelImpl(
|
|||
verboseLoggingFlow: Flow<Boolean>,
|
||||
ignoreTLSCertificateFlow: Flow<Boolean>
|
||||
) : EuiccChannel {
|
||||
companion object {
|
||||
// TODO: This needs to go somewhere else.
|
||||
val ISDR_AID = "A0000005591010FFFFFFFF8900000100".decodeHex()
|
||||
}
|
||||
|
||||
override val slotId = port.card.physicalSlotIndex
|
||||
override val logicalSlotId = port.logicalSlotIndex
|
||||
override val portId = port.portIndex
|
||||
|
||||
override val lpa: LocalProfileAssistant =
|
||||
LocalProfileAssistantImpl(apduInterface, HttpInterfaceImpl(verboseLoggingFlow, ignoreTLSCertificateFlow))
|
||||
LocalProfileAssistantImpl(
|
||||
ISDR_AID,
|
||||
apduInterface,
|
||||
HttpInterfaceImpl(verboseLoggingFlow, ignoreTLSCertificateFlow)
|
||||
)
|
||||
|
||||
override val atr: ByteArray?
|
||||
get() = (apduInterface as? ApduInterfaceAtrProvider)?.atr
|
||||
|
|
|
@ -5,7 +5,11 @@ internal object LpacJni {
|
|||
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 euiccInit(handle: Long): Int
|
||||
|
|
|
@ -12,6 +12,7 @@ import net.typeblog.lpac_jni.LocalProfileNotification
|
|||
import net.typeblog.lpac_jni.ProfileDownloadCallback
|
||||
|
||||
class LocalProfileAssistantImpl(
|
||||
isdrAid: ByteArray,
|
||||
rawApduInterface: ApduInterface,
|
||||
rawHttpInterface: HttpInterface
|
||||
): LocalProfileAssistant {
|
||||
|
@ -76,7 +77,7 @@ class LocalProfileAssistantImpl(
|
|||
private val httpInterface = HttpInterfaceWrapper(rawHttpInterface)
|
||||
|
||||
private var finalized = false
|
||||
private var contextHandle: Long = LpacJni.createContext(apduInterface, httpInterface)
|
||||
private var contextHandle: Long = LpacJni.createContext(isdrAid, apduInterface, httpInterface)
|
||||
|
||||
init {
|
||||
if (LpacJni.euiccInit(contextHandle) < 0) {
|
||||
|
|
|
@ -37,17 +37,30 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) {
|
|||
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_net_typeblog_lpac_1jni_LpacJni_createContext(JNIEnv *env, jobject thiz,
|
||||
jbyteArray isdr_aid,
|
||||
jobject apdu_interface,
|
||||
jobject http_interface) {
|
||||
struct lpac_jni_ctx *jni_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));
|
||||
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->http.interface = &lpac_jni_http_interface;
|
||||
jni_ctx->apdu_interface = (*env)->NewGlobalRef(env, apdu_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;
|
||||
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->http_interface);
|
||||
free(jni_ctx);
|
||||
free((void *) ctx->aid);
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue