Skip to content

Commit aed7e17

Browse files
committed
ssh: fix partial success for SSH cert authentication
If PublicKeyCallback returns ErrPartialSuccess we need to check source address and update the returned error if this check fails
1 parent 2aafde1 commit aed7e17

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

ssh/server.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,10 +558,16 @@ userAuthLoop:
558558
candidate.user = s.user
559559
candidate.pubKeyData = pubKeyData
560560
candidate.perms, candidate.result = config.PublicKeyCallback(s, pubKey)
561-
if candidate.result == nil && candidate.perms != nil && candidate.perms.CriticalOptions != nil && candidate.perms.CriticalOptions[sourceAddressCriticalOption] != "" {
562-
candidate.result = checkSourceAddress(
561+
// If PublicKeyCallback returns ErrPartialSuccess we need to check source address
562+
// and update the returned error if this check fails
563+
if (candidate.result == nil || candidate.result == ErrPartialSuccess) && candidate.perms != nil && candidate.perms.CriticalOptions != nil && candidate.perms.CriticalOptions[sourceAddressCriticalOption] != "" {
564+
err = checkSourceAddress(
563565
s.RemoteAddr(),
564566
candidate.perms.CriticalOptions[sourceAddressCriticalOption])
567+
// We need to update candidate.result only if the source address check fails
568+
if err != nil {
569+
candidate.result = err
570+
}
565571
}
566572
cache.add(candidate)
567573
}

0 commit comments

Comments
 (0)