How to use the webauthn.webauthn.COSEKeyException function in webauthn

To help you get started, we’ve selected a few webauthn 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 duo-labs / py_webauthn / webauthn / webauthn.py View on Github external
cose_public_key = cbor2.loads(key_bytes)

    if ALG_KEY not in cose_public_key:
        raise COSEKeyException(
            'Public key missing required algorithm parameter.')

    alg = cose_public_key[ALG_KEY]

    if alg == COSE_ALG_ES256:
        X_KEY = -2
        Y_KEY = -3

        required_keys = {ALG_KEY, X_KEY, Y_KEY}

        if not set(cose_public_key.keys()).issuperset(required_keys):
            raise COSEKeyException('Public key must match COSE_Key spec.')

        if len(cose_public_key[X_KEY]) != 32:
            raise RegistrationRejectedException('Bad public key.')
        x = int(codecs.encode(cose_public_key[X_KEY], 'hex'), 16)

        if len(cose_public_key[Y_KEY]) != 32:
            raise RegistrationRejectedException('Bad public key.')
        y = int(codecs.encode(cose_public_key[Y_KEY], 'hex'), 16)

        return alg, EllipticCurvePublicNumbers(
            x, y, SECP256R1()).public_key(backend=default_backend())
    elif alg in (COSE_ALG_PS256, COSE_ALG_RS256):
        E_KEY = -2
        N_KEY = -1

        required_keys = {ALG_KEY, E_KEY, N_KEY}
github duo-labs / py_webauthn / webauthn / webauthn.py View on Github external
def _load_cose_public_key(key_bytes):
    ALG_KEY = 3

    cose_public_key = cbor2.loads(key_bytes)

    if ALG_KEY not in cose_public_key:
        raise COSEKeyException(
            'Public key missing required algorithm parameter.')

    alg = cose_public_key[ALG_KEY]

    if alg == COSE_ALG_ES256:
        X_KEY = -2
        Y_KEY = -3

        required_keys = {ALG_KEY, X_KEY, Y_KEY}

        if not set(cose_public_key.keys()).issuperset(required_keys):
            raise COSEKeyException('Public key must match COSE_Key spec.')

        if len(cose_public_key[X_KEY]) != 32:
            raise RegistrationRejectedException('Bad public key.')
        x = int(codecs.encode(cose_public_key[X_KEY], 'hex'), 16)
github duo-labs / py_webauthn / webauthn / webauthn.py View on Github external
x = int(codecs.encode(cose_public_key[X_KEY], 'hex'), 16)

        if len(cose_public_key[Y_KEY]) != 32:
            raise RegistrationRejectedException('Bad public key.')
        y = int(codecs.encode(cose_public_key[Y_KEY], 'hex'), 16)

        return alg, EllipticCurvePublicNumbers(
            x, y, SECP256R1()).public_key(backend=default_backend())
    elif alg in (COSE_ALG_PS256, COSE_ALG_RS256):
        E_KEY = -2
        N_KEY = -1

        required_keys = {ALG_KEY, E_KEY, N_KEY}

        if not set(cose_public_key.keys()).issuperset(required_keys):
            raise COSEKeyException('Public key must match COSE_Key spec.')

        if len(cose_public_key[E_KEY]) != 3 or len(cose_public_key[N_KEY]) != 256:
            raise COSEKeyException('Bad public key.')

        e = int(codecs.encode(cose_public_key[E_KEY], 'hex'), 16)
        n = int(codecs.encode(cose_public_key[N_KEY], 'hex'), 16)

        return alg, RSAPublicNumbers(e,
                                     n).public_key(backend=default_backend())
    else:
        raise COSEKeyException('Unsupported algorithm.')
github duo-labs / py_webauthn / webauthn / webauthn.py View on Github external
raise RegistrationRejectedException('Bad public key.')
        y = int(codecs.encode(cose_public_key[Y_KEY], 'hex'), 16)

        return alg, EllipticCurvePublicNumbers(
            x, y, SECP256R1()).public_key(backend=default_backend())
    elif alg in (COSE_ALG_PS256, COSE_ALG_RS256):
        E_KEY = -2
        N_KEY = -1

        required_keys = {ALG_KEY, E_KEY, N_KEY}

        if not set(cose_public_key.keys()).issuperset(required_keys):
            raise COSEKeyException('Public key must match COSE_Key spec.')

        if len(cose_public_key[E_KEY]) != 3 or len(cose_public_key[N_KEY]) != 256:
            raise COSEKeyException('Bad public key.')

        e = int(codecs.encode(cose_public_key[E_KEY], 'hex'), 16)
        n = int(codecs.encode(cose_public_key[N_KEY], 'hex'), 16)

        return alg, RSAPublicNumbers(e,
                                     n).public_key(backend=default_backend())
    else:
        raise COSEKeyException('Unsupported algorithm.')
github duo-labs / py_webauthn / webauthn / webauthn.py View on Github external
required_keys = {ALG_KEY, E_KEY, N_KEY}

        if not set(cose_public_key.keys()).issuperset(required_keys):
            raise COSEKeyException('Public key must match COSE_Key spec.')

        if len(cose_public_key[E_KEY]) != 3 or len(cose_public_key[N_KEY]) != 256:
            raise COSEKeyException('Bad public key.')

        e = int(codecs.encode(cose_public_key[E_KEY], 'hex'), 16)
        n = int(codecs.encode(cose_public_key[N_KEY], 'hex'), 16)

        return alg, RSAPublicNumbers(e,
                                     n).public_key(backend=default_backend())
    else:
        raise COSEKeyException('Unsupported algorithm.')