Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions ssh/agent/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,11 @@ func TestServerResponseTooLarge(t *testing.T) {
n, err := b.Write(ssh.Marshal(response))
if n < 4 {
if runtime.GOOS == "plan9" {
if e1, ok := err.(*net.OpError); ok {
if e2, ok := e1.Err.(*os.PathError); ok {
switch e2.Err.Error() {
var opErr *net.OpError
if errors.As(err, &opErr) {
var pathErr *os.PathError
if errors.As(opErr.Err, &pathErr) {
switch pathErr.Err.Error() {
case "Hangup", "i/o on hungup channel":
// syscall.Pwrite returns -1 in this case even when some data did get written.
return
Expand Down
3 changes: 2 additions & 1 deletion ssh/cipher.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,8 @@ func (e cbcError) Error() string { return string(e) }
func (c *cbcCipher) readCipherPacket(seqNum uint32, r io.Reader) ([]byte, error) {
p, err := c.readCipherPacketLeaky(seqNum, r)
if err != nil {
if _, ok := err.(cbcError); ok {
var cbcErr cbcError
if errors.As(err, &cbcErr) {
// Verification error: read a fixed amount of
// data, to make distinguishing between
// failing MAC and failing length check more
Expand Down
3 changes: 2 additions & 1 deletion ssh/client_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ func (c *connection) clientAuthenticate(config *ClientConfig) error {
ok, methods, err := auth.auth(sessionID, config.User, c.transport, config.Rand, extensions)
if err != nil {
// On disconnect, return error immediately
if _, ok := err.(*disconnectMsg); ok {
var disc *disconnectMsg
if errors.As(err, &disc) {
return err
}
// We return the error later if there is no other method left to
Expand Down
7 changes: 4 additions & 3 deletions ssh/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ func ParseRawPrivateKeyWithPassphrase(pemBytes, passphrase []byte) (interface{},
// detect an incorrect password. In these cases decrypted DER bytes is
// random noise. If the parsing of the key returns an asn1.StructuralError
// we return x509.IncorrectPasswordError.
if _, ok := err.(asn1.StructuralError); ok {
if errors.As(err, &asn1.StructuralError{}) {
return nil, x509.IncorrectPasswordError
}

Expand Down Expand Up @@ -1548,12 +1548,13 @@ func parseOpenSSHPrivateKey(key []byte, decrypt openSSHDecryptFunc) (crypto.Priv

privKeyBlock, err := decrypt(w.CipherName, w.KdfName, w.KdfOpts, w.PrivKeyBlock)
if err != nil {
if err, ok := err.(*PassphraseMissingError); ok {
var pmErr *PassphraseMissingError
if errors.As(err, &pmErr) {
pub, errPub := ParsePublicKey(w.PubKey)
if errPub != nil {
return nil, fmt.Errorf("ssh: failed to parse embedded public key: %v", errPub)
}
err.PublicKey = pub
pmErr.PublicKey = pub
}
return nil, err
}
Expand Down
9 changes: 6 additions & 3 deletions ssh/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,8 @@ userAuthLoop:
candidate.user = s.user
candidate.pubKeyData = pubKeyData
candidate.perms, candidate.result = authConfig.PublicKeyCallback(s, pubKey)
_, isPartialSuccessError := candidate.result.(*PartialSuccessError)
var partialSuccessErr *PartialSuccessError
isPartialSuccessError := errors.As(candidate.result, &partialSuccessErr)
if isPartialSuccessError && config.VerifiedPublicKeyCallback != nil {
return nil, errors.New("ssh: invalid library usage: PublicKeyCallback must not return partial success when VerifiedPublicKeyCallback is defined")
}
Expand All @@ -695,7 +696,8 @@ userAuthLoop:
if len(payload) > 0 {
return nil, parseError(msgUserAuthRequest)
}
_, isPartialSuccessError := candidate.result.(*PartialSuccessError)
var partialSuccessErr *PartialSuccessError
isPartialSuccessError := errors.As(candidate.result, &partialSuccessErr)
if candidate.result == nil || isPartialSuccessError {
okMsg := userAuthPubKeyOkMsg{
Algo: algo,
Expand Down Expand Up @@ -823,7 +825,8 @@ userAuthLoop:

var failureMsg userAuthFailureMsg

if partialSuccess, ok := authErr.(*PartialSuccessError); ok {
var partialSuccess *PartialSuccessError
if errors.As(authErr, &partialSuccess) {
// After a partial success error we don't allow changing the user
// name and execute the NoClientAuthCallback.
partialSuccessReturned = true
Expand Down