Class CoseKey

java.lang.Object
com.iizix.server.user.passkey.CoseKey

public final class CoseKey extends Object
The public key of a passkey in its COSE form (RFC 9052, RFC 9053), as the authenticator sends it in the attested credential data and as the server stores it (CC-LOGIN-L8-PASSKEYS): decoded, checked, and turned into a key of the Java platform that verifies the signatures of the authenticator. No library: the platform's own Signature, KeyFactory and curves.

The key is a peer's data. Its type, curve and algorithm must agree with each other as WebAuthn requires (ES256 is P-256, EdDSA is Ed25519), an elliptic curve point must be on its curve, an RSA modulus must have MIN_RSA_BITS bits at least, and a key that carries a private part is refused.

Author:
Christopher Mindus
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final int
    The COSE algorithm of the key.
    static final int
    COSE algorithms of RFC 9864, which name the curve: ESP256, Ed25519, ESP384, ESP512, Ed448.
    static final int
    COSE algorithms of RFC 9864, which name the curve: ESP256, Ed25519, ESP384, ESP512, Ed448.
    static final int
    COSE algorithm: EdDSA, for WebAuthn on Ed25519.
    static final int
    COSE algorithm: ECDSA with SHA-256 on P-256.
    static final int
    COSE algorithm: ECDSA with SHA-384 on P-384.
    static final int
    COSE algorithm: ECDSA with SHA-512 on P-521.
    static final int
    COSE algorithms of RFC 9864, which name the curve: ESP256, Ed25519, ESP384, ESP512, Ed448.
    static final int
    COSE algorithms of RFC 9864, which name the curve: ESP256, Ed25519, ESP384, ESP512, Ed448.
    static final int
    COSE algorithms of RFC 9864, which name the curve: ESP256, Ed25519, ESP384, ESP512, Ed448.
    static final int
    The least size of an RSA modulus that is accepted, in bits.
    static final int
    COSE algorithm: RSASSA-PKCS1-v1_5 with SHA-256.
  • Method Summary

    Modifier and Type
    Method
    Description
    static CoseKey
    decode(byte[] cose)
    Decodes a key from the bytes of its COSE form.
    byte[]
    Gets the bytes of the COSE form.
    Gets the key of the Java platform.
    boolean
    verify(byte[] signed, byte[] signature)
    Verifies a signature of the authenticator.
  • Field Details

    • ES256

      public static final int ES256
      COSE algorithm: ECDSA with SHA-256 on P-256.
      See Also:
    • EDDSA

      public static final int EDDSA
      COSE algorithm: EdDSA, for WebAuthn on Ed25519.
      See Also:
    • ES384

      public static final int ES384
      COSE algorithm: ECDSA with SHA-384 on P-384.
      See Also:
    • ES512

      public static final int ES512
      COSE algorithm: ECDSA with SHA-512 on P-521.
      See Also:
    • RS256

      public static final int RS256
      COSE algorithm: RSASSA-PKCS1-v1_5 with SHA-256.
      See Also:
    • ESP256

      public static final int ESP256
      COSE algorithms of RFC 9864, which name the curve: ESP256, Ed25519, ESP384, ESP512, Ed448.
      See Also:
    • ED25519

      public static final int ED25519
      COSE algorithms of RFC 9864, which name the curve: ESP256, Ed25519, ESP384, ESP512, Ed448.
      See Also:
    • ESP384

      public static final int ESP384
      COSE algorithms of RFC 9864, which name the curve: ESP256, Ed25519, ESP384, ESP512, Ed448.
      See Also:
    • ESP512

      public static final int ESP512
      COSE algorithms of RFC 9864, which name the curve: ESP256, Ed25519, ESP384, ESP512, Ed448.
      See Also:
    • ED448

      public static final int ED448
      COSE algorithms of RFC 9864, which name the curve: ESP256, Ed25519, ESP384, ESP512, Ed448.
      See Also:
    • MIN_RSA_BITS

      public static final int MIN_RSA_BITS
      The least size of an RSA modulus that is accepted, in bits.
      See Also:
    • algorithm

      public final int algorithm
      The COSE algorithm of the key.
  • Method Details

    • decode

      public static CoseKey decode(byte[] cose) throws PasskeyException
      Decodes a key from the bytes of its COSE form.
      Parameters:
      cose - The COSE form: exactly one CBOR map.
      Returns:
      The key.
      Throws:
      NullPointerException - If cose is null.
      PasskeyException - If the bytes are no COSE key of a kind that is supported, or the key is not a sound one.
    • verify

      public boolean verify(byte[] signed, byte[] signature)
      Verifies a signature of the authenticator.
      Parameters:
      signed - The data that was signed.
      signature - The signature: ASN.1 DER for ECDSA, as WebAuthn defines it.
      Returns:
      true when the signature is the key's signature of the data; false when it is not, and when it is not a signature at all.
      Throws:
      NullPointerException - If a parameter is null.
    • getEncoded

      public byte[] getEncoded()
      Gets the bytes of the COSE form.
      Returns:
      A copy of the bytes.
    • getPublicKey

      public PublicKey getPublicKey()
      Gets the key of the Java platform.
      Returns:
      The public key.