Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly supports [email protected] #18

Merged
merged 2 commits into from
Aug 29, 2024
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
10 changes: 5 additions & 5 deletions crypto/ssh/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,17 +699,17 @@ func (t *handshakeTransport) enterKeyExchange(otherInitPacket []byte) error {
if !isClient && firstKeyExchange && contains(clientInit.KexAlgos, "ext-info-c") {
supportedPubKeyAuthAlgosList := strings.Join(t.publicKeyAuthAlgorithms, ",")
extInfo := &extInfoMsg{
NumExtensions: 1,
NumExtensions: 2,
Payload: make([]byte, 0, 4+15+4+len(supportedPubKeyAuthAlgosList)+4+16+4+1),
}
extInfo.Payload = appendInt(extInfo.Payload, len("server-sig-algs"))
extInfo.Payload = append(extInfo.Payload, "server-sig-algs"...)
extInfo.Payload = appendInt(extInfo.Payload, len(supportedPubKeyAuthAlgosList))
extInfo.Payload = append(extInfo.Payload, supportedPubKeyAuthAlgosList...)
// extInfo.Payload = appendInt(extInfo.Payload, len("[email protected]"))
// extInfo.Payload = append(extInfo.Payload, "[email protected]"...)
// extInfo.Payload = appendInt(extInfo.Payload, 1)
// extInfo.Payload = append(extInfo.Payload, "0"...)
extInfo.Payload = appendInt(extInfo.Payload, len("[email protected]"))
extInfo.Payload = append(extInfo.Payload, "[email protected]"...)
extInfo.Payload = appendInt(extInfo.Payload, 1)
extInfo.Payload = append(extInfo.Payload, "0"...)
if err := t.conn.writePacket(Marshal(extInfo)); err != nil {
return err
}
Expand Down
20 changes: 17 additions & 3 deletions crypto/ssh/pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,12 +442,23 @@ func (s *PipeSession) Close() {
}
}

func pipe(dst, src packetConn) error {
func pipe(dst, src packetConn, handlePing bool) error {
for {
msg, err := src.readPacket()
if err != nil {
return err
}
if handlePing && msg[0] == msgPing {
var ping pingMsg
if err := Unmarshal(msg, &ping); err != nil {
return fmt.Errorf("failed to unmarshal [email protected] message: %w", err)
}
err = src.writePacket(Marshal(pongMsg(ping)))
if err != nil {
return err
}
continue
}
err = dst.writePacket(msg)
if err != nil {
return err
Expand All @@ -459,11 +470,14 @@ func (s *PipeSession) RunPipe() error {
c := make(chan error)
go func() {
defer s.Downstream.transport.Close()
c <- pipe(s.Downstream.transport, s.Upstream.transport)
c <- pipe(s.Downstream.transport, s.Upstream.transport, false)
}()
go func() {
defer s.Upstream.transport.Close()
c <- pipe(s.Upstream.transport, s.Downstream.transport)
// If the upstream doesn't support [email protected], short-circuit with a pong response
upstream_ping_version := s.Upstream.extensions["[email protected]"]
upstream_supports_ping := len(upstream_ping_version) == 1 && upstream_ping_version[0] == byte('0')
c <- pipe(s.Upstream.transport, s.Downstream.transport, !upstream_supports_ping)
}()
return <-c
}
Expand Down
Loading