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
17 changes: 3 additions & 14 deletions cmd/ssh-gateway/auth.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"encoding/base64"
"errors"
"fmt"
"time"
Expand Down Expand Up @@ -50,22 +49,12 @@ func kbdInteractiveAuthenticator(cfg *Config, store *sessionStore) func(ssh.Conn
func formatAuthPrompt(authURLBase, nonce, code string, timeout time.Duration) string {
authURL := fmt.Sprintf("%s/ssh-auth?s=%s", authURLBase, nonce)
return fmt.Sprintf(
"%sRCP SSH browser authentication required.\r\n\r\n"+
"RCP SSH browser authentication required.\r\n\r\n"+
"1. Open this URL in your browser:\r\n %s\r\n\r\n"+
"2. Enter this 6-digit code on the auth page:\r\n%s\r\n\r\n"+
"If your terminal supports clipboard integration, the code was copied automatically.\r\n"+
"2. Enter this 6-digit code on the auth page: %s\r\n\r\n"+
"Waiting for browser authentication. Timeout: %s\r\n",
terminalClipboardCopy(code),
terminalHyperlink(authURL, authURL),
authURL,
code,
timeout,
)
}

func terminalHyperlink(url, label string) string {
return fmt.Sprintf("\x1b]8;;%s\a%s\x1b]8;;\a", url, label)
}

func terminalClipboardCopy(text string) string {
return fmt.Sprintf("\x1b]52;c;%s\a", base64.StdEncoding.EncodeToString([]byte(text)))
}
17 changes: 6 additions & 11 deletions cmd/ssh-gateway/auth_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"encoding/base64"
"strings"
"testing"
"time"
Expand All @@ -14,8 +13,7 @@ func TestFormatAuthPromptShowsBrowserAuthSteps(t *testing.T) {
"RCP SSH browser authentication required.",
"1. Open this URL in your browser:",
"https://khu-return.com/ssh-auth?s=nonce-1",
"2. Enter this 6-digit code on the auth page:",
"\r\n363161\r\n",
"2. Enter this 6-digit code on the auth page: 363161",
"Waiting for browser authentication. Timeout: 5m0s",
}
for _, s := range want {
Expand All @@ -25,16 +23,13 @@ func TestFormatAuthPromptShowsBrowserAuthSteps(t *testing.T) {
}
}

func TestFormatAuthPromptAddsTerminalConveniences(t *testing.T) {
func TestFormatAuthPromptDoesNotEmitTerminalEscapeSequences(t *testing.T) {
prompt := formatAuthPrompt("https://khu-return.com", "nonce-1", "363161", 5*time.Minute)
url := "https://khu-return.com/ssh-auth?s=nonce-1"

if !strings.Contains(prompt, "\x1b]8;;"+url+"\a"+url+"\x1b]8;;\a") {
t.Fatalf("prompt should include OSC 8 hyperlink for URL:\n%q", prompt)
if strings.Contains(prompt, "\x1b") {
t.Fatalf("prompt should not include ESC bytes:\n%q", prompt)
}

encodedCode := base64.StdEncoding.EncodeToString([]byte("363161"))
if !strings.Contains(prompt, "\x1b]52;c;"+encodedCode+"\a") {
t.Fatalf("prompt should include OSC 52 clipboard copy for code:\n%q", prompt)
if strings.Contains(prompt, "\a") {
t.Fatalf("prompt should not include BEL bytes:\n%q", prompt)
}
}