Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions desktop/internal/core/gitauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,37 @@ type GitAuthChallenge struct {
// Remote says the question comes from the SSH client of a remote connection (RemoteProbe),
// not from Git: it is answered with RemoteAuthRespond.
Remote bool
// Kind is what a Remote question asks for, one of the RemoteQuestion kinds; Core classifies
// OpenSSH's English wording, so the window can show a fitting form. Empty for Git.
Kind RemoteQuestionKind
// KeyType and Fingerprint name the unknown host key of a RemoteQuestionHostKey question, for
// example "ED25519" and "SHA256:…"; empty when OpenSSH did not print them.
KeyType string
Fingerprint string
// Done is closed once the request that asked has returned; no answer reaches it after that.
Done <-chan struct{}
}

// GitRetryAnswer is the answer to a Retry challenge that retries the transfer.
const GitRetryAnswer = "retry"

// RemoteQuestionKind is what an OpenSSH question of a remote connection asks for.
type RemoteQuestionKind string

// The kinds Core tells apart. Any other wording is RemoteQuestionOther, shown as asked.
const (
// RemoteQuestionHostKey asks to accept ("yes") or decline ("no") an unknown host key.
RemoteQuestionHostKey RemoteQuestionKind = "hostKey"
// RemoteQuestionPassword asks for the account's password.
RemoteQuestionPassword RemoteQuestionKind = "password"
// RemoteQuestionPassphrase asks for a private key's passphrase.
RemoteQuestionPassphrase RemoteQuestionKind = "passphrase"
// RemoteQuestionCode asks for a one-time or verification code.
RemoteQuestionCode RemoteQuestionKind = "code"
// RemoteQuestionOther is any other question.
RemoteQuestionOther RemoteQuestionKind = "other"
)

type gitAuthenticationKey struct{}

// WithGitAuthentication returns a context whose Git requests may ask the user for credentials:
Expand Down Expand Up @@ -83,6 +107,9 @@ func gitAuthenticationObserver(prompt func(GitAuthChallenge), done <-chan struct
Retry bool `json:"retry"`
Attempt int `json:"attempt"`
WorkingDirectory string `json:"workingDirectory"`
Kind string `json:"kind"`
KeyType string `json:"keyType"`
Fingerprint string `json:"fingerprint"`
}
if json.Unmarshal(raw, &event) == nil && event.Type == "authentication" && event.RequestID != "" {
prompt(GitAuthChallenge{
Expand All @@ -92,6 +119,9 @@ func gitAuthenticationObserver(prompt func(GitAuthChallenge), done <-chan struct
Retry: event.Retry,
Attempt: event.Attempt,
WorkingDirectory: event.WorkingDirectory,
Kind: RemoteQuestionKind(event.Kind),
KeyType: event.KeyType,
Fingerprint: event.Fingerprint,
Done: done,
})
}
Expand Down
38 changes: 35 additions & 3 deletions desktop/internal/core/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ type SavedRemoteConnection struct {
Group string `json:"group,omitempty"`
// RecentFolders are the host folders opened over the entry, the latest first.
RecentFolders []string `json:"recentFolders,omitempty"`
// LastConnectedAt is when a session last opened over the entry, in seconds since the Unix
// epoch; 0 when none has. Changing the entry's target clears it.
LastConnectedAt int64 `json:"lastConnectedAt,omitempty"`
}

// RemoteConnectionColor is an accent color Core accepts for a saved connection. The client picks
Expand Down Expand Up @@ -127,31 +130,60 @@ type RemoteConnectionFolder struct {
Path string `json:"path"`
}

// RemoteConnectionEdit is exactly one of Save, Remove and RememberFolder.
// RemoteConnectionImport adds Entries in order, each checked as a save without an ID; a name
// already taken gets the first free " (2)" to " (256)" suffix. Fills give saved entries a color
// or a group only where they have none. The first refusal leaves the list as it was.
type RemoteConnectionImport struct {
Entries []RemoteConnectionSave `json:"entries,omitempty"`
Fills []RemoteConnectionFill `json:"fills,omitempty"`
}

// RemoteConnectionFill gives the entry ID the Color and the Group it lacks.
type RemoteConnectionFill struct {
ID string `json:"id"`
Color RemoteConnectionColor `json:"color,omitempty"`
Group string `json:"group,omitempty"`
}

// RemoteConnectionEdit is exactly one of its fields. MarkConnected records the current time as
// the entry's LastConnectedAt.
type RemoteConnectionEdit struct {
Save *RemoteConnectionSave `json:"save,omitempty"`
Remove *RemoteConnectionID `json:"remove,omitempty"`
RememberFolder *RemoteConnectionFolder `json:"rememberFolder,omitempty"`
MarkConnected *RemoteConnectionID `json:"markConnected,omitempty"`
Import *RemoteConnectionImport `json:"import,omitempty"`
}

// RemoteConnectionsPublication is the outcome of an edit. Document is the text to publish, nil
// when the edit changed nothing; ID names the entry a save wrote.
// when the edit changed nothing; ID names the entry a save wrote, and IDs the entries an import
// added, in order.
type RemoteConnectionsPublication struct {
Changed bool `json:"changed"`
Document *string `json:"document"`
Connections []SavedRemoteConnection `json:"connections"`
Sections []RemoteConnectionSection `json:"sections"`
ID string `json:"id"`
IDs []string `json:"ids"`
}

// RemoteConnections reads the saved connections from document, the text of the source or nil
// when it does not exist. A document Core cannot decode fails with CodeParseFailed, with the
// field and the reason in RemoteConnectionFieldError.
func (c *Client) RemoteConnections(ctx context.Context, document *string) (RemoteConnectionsState, error) {
return c.SearchRemoteConnections(ctx, document, "")
}

// SearchRemoteConnections reads document as RemoteConnections does, keeping in Sections only the
// entries whose name, group and [user@]host[:port] contain every word of query, regardless of
// case; Connections stays the whole list. An empty query keeps every entry; one longer than 256
// characters fails with CodeInvalidRequest.
func (c *Client) SearchRemoteConnections(ctx context.Context, document *string, query string) (RemoteConnectionsState, error) {
var state RemoteConnectionsState
err := c.Execute(ctx, "remote.connections", struct {
Document *string `json:"document"`
}{document}, &state)
Query string `json:"query,omitempty"`
}{document, query}, &state)
return state, err
}

Expand Down
Loading
Loading