Skip to content

Commit ebb717d

Browse files
drakkanrolandshoemaker
authored andcommitted
ssh: validate key type in SSH_MSG_USERAUTH_PK_OK response
According to RFC 4252 Section 7 the algorithm in SSH_MSG_USERAUTH_PK_OK should match that of the request but some servers send the key type instead. OpenSSH checks for the key type, so we do the same. Fixes golang/go#66438 Fixes golang/go#64785 Fixes golang/go#56342 Fixes golang/go#54027 Change-Id: I2f733f0faece097e44ba7a97c868d30a53e21d79 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/573360 Auto-Submit: Nicola Murino <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Run-TryBot: Nicola Murino <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]> Reviewed-by: Filippo Valsorda <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Joedian Reid <[email protected]>
1 parent 0da2a6a commit ebb717d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

ssh/client_auth.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -404,10 +404,10 @@ func validateKey(key PublicKey, algo string, user string, c packetConn) (bool, e
404404
return false, err
405405
}
406406

407-
return confirmKeyAck(key, algo, c)
407+
return confirmKeyAck(key, c)
408408
}
409409

410-
func confirmKeyAck(key PublicKey, algo string, c packetConn) (bool, error) {
410+
func confirmKeyAck(key PublicKey, c packetConn) (bool, error) {
411411
pubKey := key.Marshal()
412412

413413
for {
@@ -425,7 +425,15 @@ func confirmKeyAck(key PublicKey, algo string, c packetConn) (bool, error) {
425425
if err := Unmarshal(packet, &msg); err != nil {
426426
return false, err
427427
}
428-
if msg.Algo != algo || !bytes.Equal(msg.PubKey, pubKey) {
428+
// According to RFC 4252 Section 7 the algorithm in
429+
// SSH_MSG_USERAUTH_PK_OK should match that of the request but some
430+
// servers send the key type instead. OpenSSH allows any algorithm
431+
// that matches the public key, so we do the same.
432+
// https://github.com/openssh/openssh-portable/blob/86bdd385/sshconnect2.c#L709
433+
if !contains(algorithmsForKeyFormat(key.Type()), msg.Algo) {
434+
return false, nil
435+
}
436+
if !bytes.Equal(msg.PubKey, pubKey) {
429437
return false, nil
430438
}
431439
return true, nil

0 commit comments

Comments
 (0)