Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class CoseKey
- Object
- CoseKey
A credential’s public key as an authenticator sends it – a COSE_Key, RFC
9052 – turned into what Crypto.verify takes: an algorithm name and a
SubjectPublicKeyInfo.
Two kinds of key are read, the two every platform authenticator offers:
| COSE algorithm | Key | Verified as |
|---|---|---|
| -7, ES256 | EC2 on P-256, uncompressed | Crypto.ES256 |
| -257, RS256 | RSA of 2048 bits or more | Crypto.RS256 |
Any other algorithm is refused with
WebAuthnException.UNSUPPORTED_ALGORITHM – EdDSA (-8) among them, which
the server’s cryptography does not verify – and a key that names one of
the two and is not such a key with WebAuthnException.INVALID_KEY. The
registration options offer only these two, so a conforming authenticator
answers with nothing else.
Fields
public static final long ES256 = -7L | The COSE identifier of ES256: ECDSA on P-256 with SHA-256. |
public static final long RS256 = -257L | The COSE identifier of RS256: RSASSA-PKCS1-v1_5 with SHA-256. |
Methods
public static CoseKey parse(byte[] coseKey) | The key a COSE_Key encodes, as another relying party stored it: what a migration of passkeys reads. |
public static CoseKey of(long algorithm, byte[] publicKey) | The key read from stored bytes: what getPublicKey returned. |
public long getAlgorithm() | The COSE identifier of the key’s algorithm: ES256 or RS256. |
public byte[] getPublicKey() | The key as a SubjectPublicKeyInfo, in DER. |
public boolean verify(byte[] data, byte[] signature) | Whether signature is this key’s signature of data. |
Inherited methods
Field details
ES256
public static final long ES256 = -7LRS256
public static final long RS256 = -257LMethod details
parse
public static CoseKey parse(byte[] coseKey)The key a COSE_Key encodes, as another relying party stored it: what a migration of passkeys reads.
WebAuthnException: when it is not CBOR, or not a key of a supported algorithm
of
public static CoseKey of(long algorithm, byte[] publicKey)The key read from stored bytes: what getPublicKey returned.
WebAuthnException: whenalgorithmis not one this server verifies
getAlgorithm
public long getAlgorithm()getPublicKey
public byte[] getPublicKey()verify
public boolean verify(byte[] data, byte[] signature)Whether signature is this key’s signature of data. An ES256
signature is ASN.1 DER, as an authenticator sends it.
WebAuthnException:WebAuthnException.INVALID_KEYwhen the key cannot be used at all, which is not the same as a signature that is wrong