Mojo · Noise Keys

Noise Keys

from ucall import Security, PeerAuthorizer 1.0.0-rc.1 · 60202332

An interface with Security.NOISE_XX learns client keys during the handshake, so it vets them through a PeerAuthorizer, and a client calling an “http+noise://” URL vets the server’s the same way:

def admit(peer_static_key: NoiseKey) -> Bool:
    return peer_static_key == trusted_key

var keys = library.generate_noise_keypair()
var sealed = Interface("0.0.0.0:8546")
sealed.security = Security.NOISE_XX
sealed.noise_private_key = keys[0]
sealed.peer_authorizer = PeerAuthorizer.to[admit]()

The authorizer returns a value through the C calling convention, which Mojo 1.2 was confirmed to lower correctly on Linux x86-64; the CI matrix confirms Linux AArch64 and macOS.

API

Types

NoiseKeyA 32-byte Curve25519 key, private or public, as every Noise handshake takes it.
comptime NoiseKey = SIMD[.uint8, 32]
StructSecurityThe transport security of an interface or a call, ucall_security_t in C.
struct Security

Fields

codec_intThe raw ucall_security_t value the ABI exchanges.

Values

NONESecurity(Int32(0))No encryption, plain TCP.
NOISE_XXSecurity(Int32(1))Trust on first use, needing an authorizer.
NOISE_IKSecurity(Int32(2))The client knows the server's public key in advance.
NOISE_KKSecurity(Int32(3))Both know each other's public keys in advance.

Conforms to

Copyable, Deinitable, Equatable, ImplicitlyCopyable, Movable, RegisterPassable, TrivialRegisterPassable
StructPeerAuthorizerWhether a peer presenting an authenticated static key may proceed past the handshake.2
struct PeerAuthorizer

Noise XX learns keys during the handshake rather than in advance, so it needs one on both sides. The default admits nobody, as it installs no authorizer at all.

Fields

callbackAddressThe ucall_peer_authorizer_t; NULL_ADDRESS installs none.
contextAddressPassed verbatim to callback; this binding's handlers need none.

Conforms to

Copyable, Defaultable, Deinitable, ImplicitlyCopyable, Movable, RegisterPassable, TrivialRegisterPassable
__init__No authorizer.
def __init__() -> Self
toAn authorizer admitting the peers whose authenticated static key handler accepts.
def to[handler: def(SIMD[.uint8, 32]) thin -> Bool]() -> Self

Parameters

handlerdef(SIMD[.uint8, 32]) thin -> BoolcomptimeReceives the peer's Curve25519 public key, and answers whether it may proceed.

Returns

The authorizer, for an interface or a client's options.