Skip to content

Commit

Permalink
update ssh module
Browse files Browse the repository at this point in the history
Signed-off-by: Hugefiver <[email protected]>
  • Loading branch information
hugefiver committed Aug 24, 2023
1 parent ec0b3a2 commit a0a66d6
Show file tree
Hide file tree
Showing 19 changed files with 618 additions and 86 deletions.
6 changes: 5 additions & 1 deletion third/ssh/agent/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ func startOpenSSHAgent(t *testing.T) (client ExtendedAgent, socket string, clean
// types supported vary by platform.
t.Skip("skipping test due to -short")
}
if runtime.GOOS == "windows" {
t.Skip("skipping on windows, we don't support connecting to the ssh-agent via a named pipe")
}

bin, err := exec.LookPath("ssh-agent")
if err != nil {
Expand Down Expand Up @@ -366,7 +369,8 @@ func TestAuth(t *testing.T) {
go func() {
conn, _, _, err := ssh.NewServerConn(a, &serverConf)
if err != nil {
t.Fatalf("Server: %v", err)
t.Errorf("NewServerConn error: %v", err)
return
}
conn.Close()
}()
Expand Down
9 changes: 6 additions & 3 deletions third/ssh/agent/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ func TestSetupForwardAgent(t *testing.T) {
incoming := make(chan *ssh.ServerConn, 1)
go func() {
conn, _, _, err := ssh.NewServerConn(a, &serverConf)
incoming <- conn
if err != nil {
t.Fatalf("Server: %v", err)
t.Errorf("NewServerConn error: %v", err)
return
}
incoming <- conn
}()

conf := ssh.ClientConfig{
Expand All @@ -71,8 +72,10 @@ func TestSetupForwardAgent(t *testing.T) {
if err := ForwardToRemote(client, socket); err != nil {
t.Fatalf("SetupForwardAgent: %v", err)
}

server := <-incoming
if server == nil {
t.Fatal("Unable to get server")
}
ch, reqs, err := server.OpenChannel(channelType, nil)
if err != nil {
t.Fatalf("OpenChannel(%q): %v", channelType, err)
Expand Down
7 changes: 4 additions & 3 deletions third/ssh/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package ssh

import (
"errors"
"fmt"
"io"
"net"
"testing"
Expand Down Expand Up @@ -90,16 +91,16 @@ func BenchmarkEndToEnd(b *testing.B) {
go func() {
newCh, err := server.Accept()
if err != nil {
b.Fatalf("Client: %v", err)
panic(fmt.Sprintf("Client: %v", err))
}
ch, incoming, err := newCh.Accept()
if err != nil {
b.Fatalf("Accept: %v", err)
panic(fmt.Sprintf("Accept: %v", err))
}
go DiscardRequests(incoming)
for i := 0; i < b.N; i++ {
if _, err := io.ReadFull(ch, output); err != nil {
b.Fatalf("ReadFull: %v", err)
panic(fmt.Sprintf("ReadFull: %v", err))
}
}
ch.Close()
Expand Down
121 changes: 121 additions & 0 deletions third/ssh/client_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,3 +955,124 @@ func TestAuthMethodGSSAPIWithMIC(t *testing.T) {
}
}
}

func TestCompatibleAlgoAndSignatures(t *testing.T) {
type testcase struct {
algo string
sigFormat string
compatible bool
}
testcases := []*testcase{
{
KeyAlgoRSA,
KeyAlgoRSA,
true,
},
{
KeyAlgoRSA,
KeyAlgoRSASHA256,
true,
},
{
KeyAlgoRSA,
KeyAlgoRSASHA512,
true,
},
{
KeyAlgoRSASHA256,
KeyAlgoRSA,
true,
},
{
KeyAlgoRSASHA512,
KeyAlgoRSA,
true,
},
{
KeyAlgoRSASHA512,
KeyAlgoRSASHA256,
true,
},
{
KeyAlgoRSASHA256,
KeyAlgoRSASHA512,
true,
},
{
KeyAlgoRSASHA512,
KeyAlgoRSASHA512,
true,
},
{
CertAlgoRSAv01,
KeyAlgoRSA,
true,
},
{
CertAlgoRSAv01,
KeyAlgoRSASHA256,
true,
},
{
CertAlgoRSAv01,
KeyAlgoRSASHA512,
true,
},
{
CertAlgoRSASHA256v01,
KeyAlgoRSASHA512,
true,
},
{
CertAlgoRSASHA512v01,
KeyAlgoRSASHA512,
true,
},
{
CertAlgoRSASHA512v01,
KeyAlgoRSASHA256,
true,
},
{
CertAlgoRSASHA256v01,
CertAlgoRSAv01,
true,
},
{
CertAlgoRSAv01,
CertAlgoRSASHA512v01,
true,
},
{
KeyAlgoECDSA256,
KeyAlgoRSA,
false,
},
{
KeyAlgoECDSA256,
KeyAlgoECDSA521,
false,
},
{
KeyAlgoECDSA256,
KeyAlgoECDSA256,
true,
},
{
KeyAlgoECDSA256,
KeyAlgoED25519,
false,
},
{
KeyAlgoED25519,
KeyAlgoED25519,
true,
},
}

for _, c := range testcases {
if isAlgoCompatible(c.algo, c.sigFormat) != c.compatible {
t.Errorf("algorithm %q, signature format %q, expected compatible to be %t", c.algo, c.sigFormat, c.compatible)
}
}
}
90 changes: 90 additions & 0 deletions third/ssh/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,93 @@ func TestNewClientConn(t *testing.T) {
})
}
}

func TestUnsupportedAlgorithm(t *testing.T) {
for _, tt := range []struct {
name string
config Config
wantError string
}{
{
"unsupported KEX",
Config{
KeyExchanges: []string{"unsupported"},
},
"no common algorithm",
},
{
"unsupported and supported KEXs",
Config{
KeyExchanges: []string{"unsupported", kexAlgoCurve25519SHA256},
},
"",
},
{
"unsupported cipher",
Config{
Ciphers: []string{"unsupported"},
},
"no common algorithm",
},
{
"unsupported and supported ciphers",
Config{
Ciphers: []string{"unsupported", chacha20Poly1305ID},
},
"",
},
{
"unsupported MAC",
Config{
MACs: []string{"unsupported"},
// MAC is used for non AAED ciphers.
Ciphers: []string{"aes256-ctr"},
},
"no common algorithm",
},
{
"unsupported and supported MACs",
Config{
MACs: []string{"unsupported", "[email protected]"},
// MAC is used for non AAED ciphers.
Ciphers: []string{"aes256-ctr"},
},
"",
},
} {
t.Run(tt.name, func(t *testing.T) {
c1, c2, err := netPipe()
if err != nil {
t.Fatalf("netPipe: %v", err)
}
defer c1.Close()
defer c2.Close()

serverConf := &ServerConfig{
Config: tt.config,
PasswordCallback: func(conn ConnMetadata, password []byte) (*Permissions, error) {
return &Permissions{}, nil
},
}
serverConf.AddHostKey(testSigners["rsa"])
go NewServerConn(c1, serverConf)

clientConf := &ClientConfig{
User: "testuser",
Config: tt.config,
Auth: []AuthMethod{
Password("testpw"),
},
HostKeyCallback: InsecureIgnoreHostKey(),
}
_, _, _, err = NewClientConn(c2, "", clientConf)
if err != nil {
if tt.wantError == "" || !strings.Contains(err.Error(), tt.wantError) {
t.Errorf("%s: got error %q, missing %q", tt.name, err.Error(), tt.wantError)
}
} else if tt.wantError != "" {
t.Errorf("%s: succeeded, but want error string %q", tt.name, tt.wantError)
}
})
}
}
4 changes: 2 additions & 2 deletions third/ssh/commit.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
64c3993f5c824fe7febbf8561179da523a4e98ea
Wed Jun 7 05:24:56 2023 +0000
b4ddeeda5bc71549846db71ba23e83ecb26f36ed
Fri Aug 4 16:27:49 2023 +0000
Loading

0 comments on commit a0a66d6

Please sign in to comment.