Skip to content

Commit

Permalink
Properly supports [email protected] (#18)
Browse files Browse the repository at this point in the history
* Properly supports `[email protected]`

* Check for `[email protected]` protocol version
  • Loading branch information
stevapple authored Aug 29, 2024
1 parent 1486234 commit ab1b3ba
Show file tree
Hide file tree
Showing 2 changed files with 22 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
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

0 comments on commit ab1b3ba

Please sign in to comment.