Skip to content

Commit

Permalink
fix major version check
Browse files Browse the repository at this point in the history
  • Loading branch information
hugefiver committed Nov 24, 2021
1 parent e79b0f9 commit e1a48e9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions third/crypto/ssh/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,15 @@ func (s *connection) serverHandshake(config *ServerConfig) (*Permissions, error)
// precheck version string
var major, minor int
n, err := fmt.Sscanf(string(s.clientVersion), "SSH-%d.%d", &major, &minor)
if err != nil || n != 2 || (major != 2 && minor != 0) {
if err != nil || n != 2 {
s.sshConn.conn.Write([]byte("Invalid SSH identification string.\r\n"))
// s.sshConn.conn.Write([]byte("Protocol mismatch.\r\n"))
err := s.sshConn.Close()
if err == nil {
err = errors.New("client version format invalid")
}
return nil, err
} else if major != 2 && minor != 0 {
s.sshConn.conn.Write([]byte("Protocol major versions differ.\r\n"))
err := s.sshConn.Close()
if err == nil {
err = errors.New("client major version don't match")
Expand Down

0 comments on commit e1a48e9

Please sign in to comment.