Skip to content

Commit

Permalink
fix: invalid cert when connecting using rdp
Browse files Browse the repository at this point in the history
  • Loading branch information
AshutoshPatole committed Aug 26, 2024
1 parent bd63283 commit 12591d0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
11 changes: 6 additions & 5 deletions cmd/rdp.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ func ConnectToServerRDP(user, host, credentialKey string) {

_, err := exec.LookPath("xfreerdp")
if err != nil {
logrus.Fatalln(color.InRed("xfreerdp is not installed or not in PATH. Please install it and try again."))
return
logrus.Infoln(color.InRed("xfreerdp is not installed or not in PATH. Please install it and try again."))
logrus.Infoln("Required packages: pkg-mgr install xfreerdp xorg-x11-server-Xorg xorg-x11-xauth xorg-x11-xinit xorg-x11-xdm -y")
os.Exit(0)
}

if os.Getenv("DISPLAY") == "" {
Expand All @@ -84,6 +85,7 @@ func ConnectToServerRDP(user, host, credentialKey string) {
if err != nil {
logrus.Fatal(color.InRed("Error reading password"))
}
security.StoreCredentials(credentialKey, password)
} else {
password = retrievedPassword
}
Expand All @@ -98,14 +100,13 @@ func ConnectToServerRDP(user, host, credentialKey string) {
// Add a delay to ensure environment is set
time.Sleep(2 * time.Second)

var cmd *exec.Cmd

args := []string{
fmt.Sprintf("/u:%s", user),
fmt.Sprintf("/p:%s", string(password)),
fmt.Sprintf("/v:%s", host),
"+clipboard",
"/dynamic-resolution",
"/cert:ignore",
"/compression-level:2",
"/scale:100",
"/scale-desktop:100",
Expand All @@ -121,7 +122,7 @@ func ConnectToServerRDP(user, host, credentialKey string) {
args = append(args, "/log-level:TRACE", "/log-filters:*:TRACE")
}

cmd = exec.Command("xfreerdp", args...)
cmd := exec.Command("xfreerdp", args...)

if verbose {
cmd.Stdout = os.Stdout
Expand Down
2 changes: 1 addition & 1 deletion internal/security/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func StoreCredentials(key, value string) error {
func RetreiveCredentials(key string) (string, error) {
password, err := keyring.Get(appName, key)
if err != nil {
return "", fmt.Errorf("error fetching credentials", err)
return "", fmt.Errorf("error fetching credentials %v", err)
}
return password, nil
}
11 changes: 5 additions & 6 deletions internal/ssh/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ package ssh
import (
"errors"
"fmt"
"github.com/TwiN/go-color"
"github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh"
"os"
"os/exec"
"path/filepath"
"runtime"
"syscall"
"time"

"github.com/TwiN/go-color"
"github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh"
)

func Connect(user, server string) {
Expand All @@ -25,12 +26,10 @@ func Connect(user, server string) {
var sshCmd *exec.Cmd
switch runtime.GOOS {
case "linux":
sshCmd = exec.Command("ssh", user+"@"+server)
sshCmd = exec.Command("ssh -X", user+"@"+server)
case "darwin":
sshCmd = exec.Command("ssh", user+"@"+server)
case "windows":
//logrus.Error(color.InRed("SSH connection not implemented for Windows systems yet"))
//return
sshCmd = exec.Command("ssh", user+"@"+server)
default:
logrus.Error(color.InRed("Unsupported operating system"))
Expand Down

0 comments on commit 12591d0

Please sign in to comment.