Package com.hierynomus.sshj.signature
Class AbstractSecurityKeySignature
java.lang.Object
net.schmizz.sshj.signature.AbstractSignature
net.schmizz.sshj.signature.AbstractSignatureDSA
com.hierynomus.sshj.signature.AbstractSecurityKeySignature
- All Implemented Interfaces:
Signature
- Direct Known Subclasses:
SignatureSkEcdsa,SignatureSkEd25519
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 counterVerification 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
ConstructorsModifierConstructorDescriptionprotectedAbstractSecurityKeySignature(String algorithm, String keyTypeName) -
Method Summary
Modifier and TypeMethodDescriptionprotected 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.voidinitSign(PrivateKey privateKey) Initialize this signature with the given private key for signing.voidinitVerify(PublicKey publicKey) Initialize this signature with the given public key for signature verification.booleanReturnstrueifSignature.encode(byte[])already produces the full wire-format signature value (type + payload) and it should be written as a single string without an additionalputSignaturewrapper.protected static byte[]sha256(byte[] data) byte[]sign()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).voidupdate(byte[] foo, int off, int len) Update the computed signature with the given data.booleanverify(byte[] sig) Verify against the given signature.Methods inherited from class net.schmizz.sshj.signature.AbstractSignatureDSA
encodeAsnSignatureMethods inherited from class net.schmizz.sshj.signature.AbstractSignature
extractSig, getSignatureName, update
-
Constructor Details
-
AbstractSecurityKeySignature
-
-
Method Details
-
isSignaturePreEncoded
public boolean isSignaturePreEncoded()Description copied from interface:SignatureReturnstrueifSignature.encode(byte[])already produces the full wire-format signature value (type + payload) and it should be written as a single string without an additionalputSignaturewrapper. Returnsfalsefor all ordinary signatures. -
initVerify
Description copied from interface:SignatureInitialize this signature with the given public key for signature verification. Note that subsequent calls to eitherSignature.initVerify(PublicKey)orSignature.initSign(PrivateKey)will overwrite prior initialization.- Specified by:
initVerifyin interfaceSignature- Overrides:
initVerifyin classAbstractSignature- Parameters:
publicKey- the public key to use for signature verification
-
initSign
Description copied from interface:SignatureInitialize this signature with the given private key for signing. Note that subsequent calls to eitherSignature.initVerify(PublicKey)orSignature.initSign(PrivateKey)will overwrite prior initialization.- Specified by:
initSignin interfaceSignature- Overrides:
initSignin classAbstractSignature- Parameters:
privateKey- the private key to use for signing
-
update
public void update(byte[] foo, int off, int len) Description copied from interface:SignatureUpdate the computed signature with the given data.- Specified by:
updatein interfaceSignature- Overrides:
updatein classAbstractSignature- Parameters:
foo- byte-array to update withoff- offset within the arraylen- length until which to compute
-
sign
public byte[] sign()Description copied from interface:SignatureCompute the signature.- Specified by:
signin interfaceSignature- Overrides:
signin classAbstractSignature- 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 onsign()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:SignatureVerify against the given signature.- Parameters:
sig- the signature to verify against- Returns:
trueon successful verification,falseon 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).
-