{"modulePath":"github.com/rm4n0s/clowder","version":"v1.2.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package sshcode\n\nPackage sshcode is the SSH server of the sign-in codes (SPEC §7.16, D52). A user who registered a public key runs ssh and the server answers with a one-time code, then closes the connection. It offers nothing else: no password, no shell, no forwarding.\n\nThe server talks to the rest of Clowder through two small interfaces, SignIn and Limiter, which internal/app satisfies. It is the only package that runs an SSH server, and it never imports internal/store.\n\n## Constants\n\n```go\nconst (\n\t// DefaultMaxConns is the most connections one process serves at once.\n\tDefaultMaxConns = 64\n\t// DefaultMaxConnsPerAddr is the most connections one client address may\n\t// hold at once (step 24.1): without it one address could keep every place\n\t// of DefaultMaxConns for the length of the handshake deadline and lock\n\t// everybody else out of the server. A person needs one connection at a\n\t// time.\n\tDefaultMaxConnsPerAddr = 8\n\t// DefaultHandshakeTimeout is how long a client has for the handshake,\n\t// the authentication included.\n\tDefaultHandshakeTimeout = 10 * time.Second\n\t// DefaultConnTimeout is the total time a connection lives.\n\tDefaultConnTimeout = 30 * time.Second\n)\n```\nThe limits of SPEC §7.16. A Config field that is zero takes the default.\n\n## Functions\n\n```go\nfunc LoadHostKey(path string) (ssh.Signer, error)\n```\nLoadHostKey returns the host key kept at path: the PEM of an OpenSSH private key. When the file does not exist it makes an Ed25519 key and stores it there, so that the next start, and the other processes that share the directory, use the same key.\n\nThe key is made exclusively. It is written to a temporary file in the same directory with mode 0600 and then linked to path, and the temporary file is removed. A reader therefore never sees a half-written key, and of two processes that start together one link wins and the other reads the winner's key.\n\nIt fails with tagHostKeyReadFailed when the file cannot be read, tagHostKeyInvalid when it is not a private key, and the tags of the making when the key cannot be made or stored (a missing directory among them).\n\n## Types\n\n```go\ntype Config struct {\n\t// HostKey is the host key of the server (see LoadHostKey).\n\tHostKey ssh.Signer\n\t// MaxConns is the most connections at once; more are closed when they\n\t// are accepted. Zero is DefaultMaxConns.\n\tMaxConns int\n\t// MaxConnsPerAddr is the most connections one client address may hold at\n\t// once; more are closed when they are accepted. Zero is\n\t// DefaultMaxConnsPerAddr.\n\tMaxConnsPerAddr int\n\t// HandshakeTimeout is the time for the handshake. Zero is\n\t// DefaultHandshakeTimeout.\n\tHandshakeTimeout time.Duration\n\t// ConnTimeout is the total time of a connection. Zero is\n\t// DefaultConnTimeout.\n\tConnTimeout time.Duration\n}\n```\nConfig holds the settings of the server.\n\n```go\ntype Limiter interface {\n\t// AllowAddr reports whether the address may connect.\n\tAllowAddr(ctx context.Context, addr string) bool\n\t// FailAddr records a failed login of the address.\n\tFailAddr(ctx context.Context, addr string)\n}\n```\nLimiter counts the failed logins of client addresses. \\*app.LoginLimiter satisfies it; it is the limiter of the web login too, so that the limit of SPEC §7.1 covers both.\n\n```go\ntype Server struct {\n\t// contains filtered or unexported fields\n}\n```\nServer is the SSH server of the sign-in codes. Make it with New and run it with Serve. It is safe for concurrent use.\n\n```go\nfunc New(cfg Config, signIn SignIn, limiter Limiter, logger *slog.Logger) *Server\n```\nNew makes a server. A nil logger discards the log.\n\n```go\nfunc (s *Server) Serve(ctx context.Context, ln net.Listener) error\n```\nServe accepts connections on ln until ctx is done. When ctx is done it closes ln and every open connection, waits for every goroutine it started and returns nil. It returns an error when ln fails for another reason, after it has closed the connections and waited the same way. The caller does not close ln.\n\n```go\ntype SignIn interface {\n\t// KeyAllowed reports whether the key with the fingerprint belongs to the\n\t// enabled user with the username. It says nothing about why not.\n\tKeyAllowed(ctx context.Context, username, fingerprint string) bool\n\t// IssueCode makes a code for the user and the key, for the client at addr.\n\tIssueCode(ctx context.Context, username, fingerprint, addr string) (app.IssuedSSHCode, error)\n}\n```\nSignIn is what the server asks of the services of internal/app. \\*app.SignIn satisfies it.\n\n","path":"github.com/rm4n0s/clowder/internal/sshcode","name":"sshcode","synopsis":"Package sshcode is the SSH server of the sign-in codes (SPEC §7.16, D52).","isRedistributable":true}
