Ensure mocked replies use native OK status (#60)

Corrects a bug where the native binder `status_t` was being set to application-level error codes (e.g., `KeyStore.NO_ERROR` which is 1).

Moreover, we call method `InterceptorUtils.createTypedObjectReply` to keep the code style consistent.
This commit is contained in:
JingMatrix
2025-12-08 04:30:01 +01:00
parent 2a76b18308
commit 83b65f09c9
3 changed files with 5 additions and 10 deletions
@@ -41,7 +41,7 @@ abstract class BinderInterceptor : Binder() {
* Skips the original call and immediately returns a custom reply parcel to the caller. The * Skips the original call and immediately returns a custom reply parcel to the caller. The
* provided parcel will be recycled after use. * provided parcel will be recycled after use.
*/ */
data class OverrideReply(val code: Int = 0, val reply: Parcel) : TransactionResult() data class OverrideReply(val reply: Parcel, val code: Int = 0) : TransactionResult()
/** /**
* Modifies the transaction's input data before forwarding it to the original binder method. * Modifies the transaction's input data before forwarding it to the original binder method.
@@ -52,7 +52,7 @@ object InterceptorUtils {
writeInt(KeyStore.NO_ERROR) writeInt(KeyStore.NO_ERROR)
} }
} }
return BinderInterceptor.TransactionResult.OverrideReply(0, parcel) return BinderInterceptor.TransactionResult.OverrideReply(parcel)
} }
/** Creates an `OverrideReply` parcel containing a raw byte array. */ /** Creates an `OverrideReply` parcel containing a raw byte array. */
@@ -62,7 +62,7 @@ object InterceptorUtils {
writeNoException() writeNoException()
writeByteArray(data) writeByteArray(data)
} }
return BinderInterceptor.TransactionResult.OverrideReply(KeyStore.NO_ERROR, parcel) return BinderInterceptor.TransactionResult.OverrideReply(parcel)
} }
/** Creates an `OverrideReply` parcel containing a Parcelable object. */ /** Creates an `OverrideReply` parcel containing a Parcelable object. */
@@ -75,7 +75,7 @@ object InterceptorUtils {
writeNoException() writeNoException()
writeTypedObject(obj, flags) writeTypedObject(obj, flags)
} }
return BinderInterceptor.TransactionResult.OverrideReply(0, parcel) return BinderInterceptor.TransactionResult.OverrideReply(parcel)
} }
/** /**
@@ -168,12 +168,7 @@ class KeyMintSecurityLevelInterceptor(
if (isAttestKeyRequest) attestationKeys.add(keyId) if (isAttestKeyRequest) attestationKeys.add(keyId)
// Return the metadata of our generated key, skipping the real hardware call. // Return the metadata of our generated key, skipping the real hardware call.
val resultParcel = return InterceptorUtils.createTypedObjectReply(response.metadata)
Parcel.obtain().apply {
writeNoException()
writeTypedObject(response.metadata, 0)
}
return TransactionResult.OverrideReply(0, resultParcel)
} else if (parsedParams.attestationChallenge != null) { } else if (parsedParams.attestationChallenge != null) {
return TransactionResult.Continue return TransactionResult.Continue
} }