Skip to content

Commit

Permalink
Properly supports [email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
stevapple committed Aug 28, 2024
1 parent 1486234 commit 58559ca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
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
19 changes: 16 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,13 @@ 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_supports_ping := s.Upstream.extensions["[email protected]"]
c <- pipe(s.Upstream.transport, s.Downstream.transport, !upstream_supports_ping)
}()
return <-c
}
Expand Down

0 comments on commit 58559ca

Please sign in to comment.