2024-06-25 10:39:00 +07:00

44 lines
1.8 KiB
Kotlin

package net.sergeych.kiloparsec
import net.sergeych.crypto2.SigningKey
import net.sergeych.crypto2.VerifyingPublicKey
/**
* Scope for Kiloparsec client/server commands execution, contain per-connection specific data. The scope
* is used to call command implementation you add to the [KiloInterface] when constructing [KiloClient]
* [KiloClientConnection] or [KiloServerConnection].
*/
interface KiloScope<S> {
/**
* Session object. Any data provided by the caller when creating a new connection
*/
val session: S
/**
* The secure (L1) interface to call remote commands
*/
val remote: RemoteInterface
/**
* Unique per-connection token which is the same on the server and client side, though is never
* transmitted (derived from Diffie-Hellman key exchange or like process). It can be used as a
* safe nonce or seed to test connection integrity without sending check data over the channel.
*/
val sessionToken: UByteArray
/**
* If the remote part has provided a secret key, e.g., gave non-null [SigningKey] on construction,
* the kiloparsec checks it in the MITM-safe way and provides its [VerifyingPublicKey] shared key here.
* Knowing a remote party shared key, it is possible to be sure that the connection is made directly
* to this party with no middle point intruders.
*
* Note that if the key was provided but authentication failed, the connection __will not be established__,
* throwing [RemoteInterface.SecurityException].
*
* In spite of the above said, which means, non-null value in this field means the key is authorized, but
* It is up to the caller to ensure it is expected key of the remote party.
*/
val remoteIdentity: VerifyingPublicKey?
}