How to use the fido2.cbor function in fido2

To help you get started, we’ve selected a few fido2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Yubico / python-fido2 / test / test_cbor.py View on Github external
def test_vectors(self):
        for (data, value) in _TEST_VECTORS:
            try:
                self.assertEqual(cbor.decode_from(a2b_hex(data)), (value, b""))
                self.assertEqual(cbor.decode(a2b_hex(data)), value)
                self.assertEqual(cbor2hex(value), data)
            except Exception:
                print("\nERROR in test vector, %s" % data)
                raise
github Yubico / python-fido2 / test / test_cbor.py View on Github external
def cbor2hex(data):
    return b2a_hex(cbor.encode(data)).decode()
github Yubico / python-fido2 / test / test_cbor.py View on Github external
def test_vectors(self):
        for (data, value) in _TEST_VECTORS:
            try:
                self.assertEqual(cbor.decode_from(a2b_hex(data)), (value, b""))
                self.assertEqual(cbor.decode(a2b_hex(data)), value)
                self.assertEqual(cbor2hex(value), data)
            except Exception:
                print("\nERROR in test vector, %s" % data)
                raise
github Yubico / python-fido2 / test / test_ctap2.py View on Github external
def test_send_cbor_ok(self):
        ctap = CTAP2(mock.MagicMock())
        ctap.device.call.return_value = b"\0" + cbor.encode({1: b"response"})

        self.assertEqual({1: b"response"}, ctap.send_cbor(2, b"foobar"))
        ctap.device.call.assert_called_with(
            0x10, b"\2" + cbor.encode(b"foobar"), mock.ANY, None
        )
github Yubico / python-fido2 / fido2 / ctap2.py View on Github external
def create(cls, rp_id_hash, flags, counter, credential_data=b"", extensions=None):
        """Create an AuthenticatorData instance.

        :param rp_id_hash: SHA256 hash of the RP ID.
        :param flags: Flags of the AuthenticatorData.
        :param counter: Signature counter of the authenticator data.
        :param credential_data: Authenticated credential data (only if attested
            credential data flag is set).
        :param extensions: Authenticator extensions (only if ED flag is set).
        :return: The authenticator data.
        """
        return cls(
            rp_id_hash
            + struct.pack(">BI", flags, counter)
            + credential_data
            + (cbor.encode(extensions) if extensions is not None else b"")
        )
github Yubico / python-fido2 / examples / server / server-u2f.py View on Github external
def authenticate_complete():
    if not credentials:
        abort(404)

    data = cbor.decode(request.get_data())
    credential_id = data["credentialId"]
    client_data = ClientData(data["clientDataJSON"])
    auth_data = AuthenticatorData(data["authenticatorData"])
    signature = data["signature"]
    print("clientData", client_data)
    print("AuthenticatorData", auth_data)

    server.authenticate_complete(
        session.pop("state"),
        credentials,
        credential_id,
        client_data,
        auth_data,
        signature,
    )
    print("ASSERTION OK")
github Yubico / python-fido2 / fido2 / ctap2.py View on Github external
def __init__(self, _):
        super(Info, self).__init__()

        data = dict((Info.KEY.get(k), v) for (k, v) in cbor.decode(self).items())
        self.versions = data[Info.KEY.VERSIONS]
        self.extensions = data.get(Info.KEY.EXTENSIONS, [])
        self.aaguid = data[Info.KEY.AAGUID]
        self.options = data.get(Info.KEY.OPTIONS, {})
        self.max_msg_size = data.get(Info.KEY.MAX_MSG_SIZE, 1024)
        self.pin_protocols = data.get(Info.KEY.PIN_PROTOCOLS, [])
        self.max_creds_in_list = data.get(Info.KEY.MAX_CREDS_IN_LIST)
        self.max_cred_id_length = data.get(Info.KEY.MAX_CRED_ID_LENGTH)
        self.transports = data.get(Info.KEY.TRANSPORTS, [])
        self.algorithms = data.get(Info.KEY.ALGORITHMS)
        self.data = data
github Yubico / python-fido2 / fido2 / ctap2.py View on Github external
def __init__(self, _):
        super(AuthenticatorData, self).__init__()

        reader = ByteBuffer(self)
        self.rp_id_hash = reader.read(32)
        self.flags = reader.unpack("B")
        self.counter = reader.unpack(">I")
        rest = reader.read()

        if self.flags & AuthenticatorData.FLAG.ATTESTED:
            self.credential_data, rest = AttestedCredentialData.unpack_from(rest)
        else:
            self.credential_data = None

        if self.flags & AuthenticatorData.FLAG.EXTENSION_DATA:
            self.extensions, rest = cbor.decode_from(rest)
        else:
            self.extensions = None

        if rest:
            raise ValueError("Wrong length")
github Yubico / python-fido2 / examples / server / server.py View on Github external
{
            "id": b"user_id",
            "name": "a_user",
            "displayName": "A. User",
            "icon": "https://example.com/image.png",
        },
        credentials,
        user_verification="discouraged",
        authenticator_attachment="cross-platform",
    )

    session["state"] = state
    print("\n\n\n\n")
    print(registration_data)
    print("\n\n\n\n")
    return cbor.encode(registration_data)