Class AbstractSecurityKeySignature

All Implemented Interfaces:
Signature
Direct Known Subclasses:
SignatureSkEcdsa, SignatureSkEd25519

public abstract class AbstractSecurityKeySignature extends AbstractSignatureDSA
Base class for the OpenSSH FIDO/U2F security key signatures (sk-ecdsa-sha2-nistp256@openssh.com and sk-ssh-ed25519@openssh.com).

The difference from an ordinary SSH signature is what actually gets signed. A FIDO authenticator never sees the SSH payload directly; instead it signs a small fixed structure (WebAuthn calls it the authenticator data plus the client-data hash):

   signed = SHA256(application) || flags || counter || SHA256(sshData)
 
and the wire signature carries the flags and counter so the verifier can rebuild that structure:
   string  key type
   string  raw signature        (ECDSA r||s as two mpints, or 64-byte Ed25519 signature)
   byte    flags
   uint32  counter
 
Verification rebuilds signed and checks it with the underlying ECDSA/Ed25519 key. Signing is delegated to a SecurityKeySigner (the hardware bridge); this class only hashes the SSH payload, hands the challenge to the signer and assembles the wire format from what comes back.
See Also:
  • Field Summary

    Fields inherited from class net.schmizz.sshj.signature.AbstractSignature

    signature
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractSecurityKeySignature(String algorithm, String keyTypeName)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract byte[]
    deviceSignatureToSsh(byte[] deviceSignature)
    Convert the authenticator's native signature into the SSH raw-signature encoding (r||s as two mpints for ECDSA, unchanged for Ed25519).
    byte[]
    encode(byte[] sshRawSignature)
    Assemble the full SSH signature value: string keyType || string rawSig || byte flags || uint32 counter.
    void
    initSign(PrivateKey privateKey)
    Initialize this signature with the given private key for signing.
    void
    initVerify(PublicKey publicKey)
    Initialize this signature with the given public key for signature verification.
    boolean
    Returns true if Signature.encode(byte[]) already produces the full wire-format signature value (type + payload) and it should be written as a single string without an additional putSignature wrapper.
    protected static byte[]
    sha256(byte[] data)
     
    byte[]
    Compute the signature.
    protected abstract byte[]
    sshSignatureToDevice(byte[] sshRawSignature)
    Convert the SSH raw-signature encoding read off the wire into the byte format the JCA verification engine expects (DER for ECDSA, unchanged for Ed25519).
    void
    update(byte[] foo, int off, int len)
    Update the computed signature with the given data.
    boolean
    verify(byte[] sig)
    Verify against the given signature.

    Methods inherited from class net.schmizz.sshj.signature.AbstractSignatureDSA

    encodeAsnSignature

    Methods inherited from class net.schmizz.sshj.signature.AbstractSignature

    extractSig, getSignatureName, update

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AbstractSecurityKeySignature

      protected AbstractSecurityKeySignature(String algorithm, String keyTypeName)
  • Method Details

    • isSignaturePreEncoded

      public boolean isSignaturePreEncoded()
      Description copied from interface: Signature
      Returns true if Signature.encode(byte[]) already produces the full wire-format signature value (type + payload) and it should be written as a single string without an additional putSignature wrapper. Returns false for all ordinary signatures.
    • initVerify

      public void initVerify(PublicKey publicKey)
      Description copied from interface: Signature
      Initialize this signature with the given public key for signature verification. Note that subsequent calls to either Signature.initVerify(PublicKey) or Signature.initSign(PrivateKey) will overwrite prior initialization.
      Specified by:
      initVerify in interface Signature
      Overrides:
      initVerify in class AbstractSignature
      Parameters:
      publicKey - the public key to use for signature verification
    • initSign

      public void initSign(PrivateKey privateKey)
      Description copied from interface: Signature
      Initialize this signature with the given private key for signing. Note that subsequent calls to either Signature.initVerify(PublicKey) or Signature.initSign(PrivateKey) will overwrite prior initialization.
      Specified by:
      initSign in interface Signature
      Overrides:
      initSign in class AbstractSignature
      Parameters:
      privateKey - the private key to use for signing
    • update

      public void update(byte[] foo, int off, int len)
      Description copied from interface: Signature
      Update the computed signature with the given data.
      Specified by:
      update in interface Signature
      Overrides:
      update in class AbstractSignature
      Parameters:
      foo - byte-array to update with
      off - offset within the array
      len - length until which to compute
    • sign

      public byte[] sign()
      Description copied from interface: Signature
      Compute the signature.
      Specified by:
      sign in interface Signature
      Overrides:
      sign in class AbstractSignature
      Returns:
      the computed signature
    • encode

      public byte[] encode(byte[] sshRawSignature)
      Assemble the full SSH signature value: string keyType || string rawSig || byte flags || uint32 counter. Relies on sign() having been called first to capture the flags and counter.
      Parameters:
      sshRawSignature - the signature to encode
      Returns:
      Encoded signature
    • verify

      public boolean verify(byte[] sig)
      Description copied from interface: Signature
      Verify against the given signature.
      Parameters:
      sig - the signature to verify against
      Returns:
      true on successful verification, false on failure
    • sha256

      protected static byte[] sha256(byte[] data)
    • sshSignatureToDevice

      protected abstract byte[] sshSignatureToDevice(byte[] sshRawSignature) throws Buffer.BufferException
      Convert the SSH raw-signature encoding read off the wire into the byte format the JCA verification engine expects (DER for ECDSA, unchanged for Ed25519).
      Throws:
      Buffer.BufferException
    • deviceSignatureToSsh

      protected abstract byte[] deviceSignatureToSsh(byte[] deviceSignature)
      Convert the authenticator's native signature into the SSH raw-signature encoding (r||s as two mpints for ECDSA, unchanged for Ed25519).