Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit a733475e authored by Marvin W.'s avatar Marvin W. 🐿️
Browse files

Fido: Add NFC support

parent 42d95395
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -33,11 +33,11 @@ public class PublicKeyCredentialDescriptor extends AutoSafeParcelable {
    private PublicKeyCredentialDescriptor() {
    }

    public PublicKeyCredentialDescriptor(String type, byte[] id, List<Transport> transports) throws UnsupportedPubKeyCredDescriptorException {
    public PublicKeyCredentialDescriptor(String type, byte[] id, List<Transport> transports) {
        try {
            this.type = PublicKeyCredentialType.fromString(type);
        } catch (PublicKeyCredentialType.UnsupportedPublicKeyCredTypeException e) {
            throw new UnsupportedPubKeyCredDescriptorException(e.getMessage(), e);
            throw new IllegalArgumentException(e);
        }
        this.id = id;
        this.transports = transports;
+1 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@

    <uses-permission android:name="android.permission.USE_BIOMETRIC" />
    <uses-permission android:name="android.permission.USE_FINGERPRINT" />
    <uses-permission android:name="android.permission.NFC" />
    <uses-permission
        android:name="android.permission.MANAGE_USB"
        tools:ignore="ProtectedPermissions" />
+36 −0
Original line number Diff line number Diff line
/*
 * SPDX-FileCopyrightText: 2022 microG Project Team
 * SPDX-License-Identifier: Apache-2.0
 */

package org.microg.gms.fido.core.protocol.msgs

fun encodeCommandApdu(
    cla: Byte,
    ins: Byte,
    p1: Byte,
    p2: Byte,
    data: ByteArray = ByteArray(0),
    le: Int = -1,
    extended: Boolean = data.size > 255 || le > 255
): ByteArray {
    val fixed = byteArrayOf(cla, ins, p1, p2)
    val ext = if (extended) byteArrayOf(0) else ByteArray(0)
    val req = when {
        data.isEmpty() -> ByteArray(0)
        extended -> byteArrayOf((data.size shr 8).toByte(), data.size.toByte()) + data
        else -> byteArrayOf(data.size.toByte()) + data
    }
    val res = when {
        le == -1 -> ByteArray(0)
        extended -> byteArrayOf((le shr 8).toByte(), le.toByte())
        else -> byteArrayOf(le.toByte())
    }
    return fixed + ext + req + res
}

fun decodeResponseApdu(bytes: ByteArray): Pair<Short, ByteArray> {
    require(bytes.size >= 2)
    return ((bytes[bytes.size - 2].toInt() and 0xff shl 8) + (bytes.last()
        .toInt() and 0xff)).toShort() to bytes.sliceArray(0 until bytes.size - 2)
}
+1 −9
Original line number Diff line number Diff line
@@ -24,15 +24,7 @@ abstract class Ctap1Request(
    val p2: Byte = 0,
    val data: ByteArray
) {
    val apdu = byteArrayOf(
        0,
        commandByte,
        p1,
        p2,
        0,
        (data.size shr 8).toByte(),
        data.size.toByte()
    ) + data
    val apdu = encodeCommandApdu(0, commandByte, p1, p2, data, extended = true)

    override fun toString(): String = "Ctap1Request(command=0x${commandByte.toString(16)}, " +
            "p1=0x${p1.toString(16)}, " +
+18 −0
Original line number Diff line number Diff line
/*
 * SPDX-FileCopyrightText: 2022 microG Project Team
 * SPDX-License-Identifier: Apache-2.0
 */

package org.microg.gms.fido.core.transport

import com.google.android.gms.fido.fido2.api.common.ErrorCode
import org.microg.gms.fido.core.RequestHandlingException
import org.microg.gms.fido.core.protocol.msgs.*

interface CtapConnection {
    val hasCtap1Support: Boolean
    val hasCtap2Support: Boolean

    suspend fun <Q : Ctap1Request, S : Ctap1Response> runCommand(command: Ctap1Command<Q, S>): S
    suspend fun <Q : Ctap2Request, S : Ctap2Response> runCommand(command: Ctap2Command<Q, S>): S
}
Loading