Skip to content

Commit c321b55

Browse files
committed
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.
1 parent a171d8e commit c321b55

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

app/src/main/java/org/matrix/TEESimulator/interception/core/BinderInterceptor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ abstract class BinderInterceptor : Binder() {
4141
* Skips the original call and immediately returns a custom reply parcel to the caller. The
4242
* provided parcel will be recycled after use.
4343
*/
44-
data class OverrideReply(val code: Int = 0, val reply: Parcel) : TransactionResult()
44+
data class OverrideReply(val reply: Parcel, val code: Int = 0) : TransactionResult()
4545

4646
/**
4747
* Modifies the transaction's input data before forwarding it to the original binder method.

app/src/main/java/org/matrix/TEESimulator/interception/keystore/InterceptorUtils.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ object InterceptorUtils {
5252
writeInt(KeyStore.NO_ERROR)
5353
}
5454
}
55-
return BinderInterceptor.TransactionResult.OverrideReply(0, parcel)
55+
return BinderInterceptor.TransactionResult.OverrideReply(parcel)
5656
}
5757

5858
/** Creates an `OverrideReply` parcel containing a raw byte array. */
@@ -62,7 +62,7 @@ object InterceptorUtils {
6262
writeNoException()
6363
writeByteArray(data)
6464
}
65-
return BinderInterceptor.TransactionResult.OverrideReply(KeyStore.NO_ERROR, parcel)
65+
return BinderInterceptor.TransactionResult.OverrideReply(parcel)
6666
}
6767

6868
/** Creates an `OverrideReply` parcel containing a Parcelable object. */
@@ -75,7 +75,7 @@ object InterceptorUtils {
7575
writeNoException()
7676
writeTypedObject(obj, flags)
7777
}
78-
return BinderInterceptor.TransactionResult.OverrideReply(0, parcel)
78+
return BinderInterceptor.TransactionResult.OverrideReply(parcel)
7979
}
8080

8181
/**

app/src/main/java/org/matrix/TEESimulator/interception/keystore/shim/KeyMintSecurityLevelInterceptor.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,7 @@ class KeyMintSecurityLevelInterceptor(
168168
if (isAttestKeyRequest) attestationKeys.add(keyId)
169169

170170
// Return the metadata of our generated key, skipping the real hardware call.
171-
val resultParcel =
172-
Parcel.obtain().apply {
173-
writeNoException()
174-
writeTypedObject(response.metadata, 0)
175-
}
176-
return TransactionResult.OverrideReply(0, resultParcel)
171+
return InterceptorUtils.createTypedObjectReply(response.metadata)
177172
} else if (parsedParams.attestationChallenge != null) {
178173
return TransactionResult.Continue
179174
}

0 commit comments

Comments
 (0)