ServerRequestAuthentication
object ServerRequestAuthentication
Signs and verifies server requests with a device authentication key, format version 1 (docs/server-authentication.md). The signed input is:
u32 length | "KSecureMessage-ServerAuth-v1" (UTF-8)
u32 length | userId (UTF-8) | u32 length | deviceId (UTF-8)
u32 length | method (ASCII, upper case)
u32 length | canonical path (UTF-8)
SHA-256(body) (32)
timestamp: i64, epoch milliseconds
nonce (16)Content copied to clipboard
Integers are big-endian. The signature is Ed25519 over the whole input. The domain string keeps signatures made for anything else (signed prekeys, other protocols) from verifying as a request signature.
Properties
Functions
Link copied to clipboard
The bytes the signature covers. Throws IllegalArgumentException for a method that is not upper-case ASCII letters.
Link copied to clipboard
fun sign(keyPair: DeviceAuthenticationKeyPair, request: ServerRequest, timestamp: Instant, nonce: RequestNonce = RequestNonce.random()): RequestAuthentication
Link copied to clipboard
fun verify(publicKey: ByteArray, request: ServerRequest, authentication: RequestAuthentication): Boolean
true if authentication is a valid signature over request by the holder of publicKey. Checks the signature only: time window and nonce reuse are the server's job. Malformed keys, signatures and requests give false.