mirror of
				https://gitea.com/Lydanne/buildx.git
				synced 2025-11-04 18:13:42 +08:00 
			
		
		
		
	deps: update buildkit, vendor changes
Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
This commit is contained in:
		
							
								
								
									
										13
									
								
								vendor/golang.org/x/crypto/ssh/agent/client.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										13
									
								
								vendor/golang.org/x/crypto/ssh/agent/client.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -141,9 +141,14 @@ const (
 | 
			
		||||
	agentAddSmartcardKeyConstrained = 26
 | 
			
		||||
 | 
			
		||||
	// 3.7 Key constraint identifiers
 | 
			
		||||
	agentConstrainLifetime  = 1
 | 
			
		||||
	agentConstrainConfirm   = 2
 | 
			
		||||
	agentConstrainExtension = 3
 | 
			
		||||
	agentConstrainLifetime = 1
 | 
			
		||||
	agentConstrainConfirm  = 2
 | 
			
		||||
	// Constraint extension identifier up to version 2 of the protocol. A
 | 
			
		||||
	// backward incompatible change will be required if we want to add support
 | 
			
		||||
	// for SSH_AGENT_CONSTRAIN_MAXSIGN which uses the same ID.
 | 
			
		||||
	agentConstrainExtensionV00 = 3
 | 
			
		||||
	// Constraint extension identifier in version 3 and later of the protocol.
 | 
			
		||||
	agentConstrainExtension = 255
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// maxAgentResponseBytes is the maximum agent reply size that is accepted. This
 | 
			
		||||
@@ -205,7 +210,7 @@ type constrainLifetimeAgentMsg struct {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type constrainExtensionAgentMsg struct {
 | 
			
		||||
	ExtensionName    string `sshtype:"3"`
 | 
			
		||||
	ExtensionName    string `sshtype:"255|3"`
 | 
			
		||||
	ExtensionDetails []byte
 | 
			
		||||
 | 
			
		||||
	// Rest is a field used for parsing, not part of message
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								vendor/golang.org/x/crypto/ssh/agent/server.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								vendor/golang.org/x/crypto/ssh/agent/server.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -208,7 +208,7 @@ func parseConstraints(constraints []byte) (lifetimeSecs uint32, confirmBeforeUse
 | 
			
		||||
		case agentConstrainConfirm:
 | 
			
		||||
			confirmBeforeUse = true
 | 
			
		||||
			constraints = constraints[1:]
 | 
			
		||||
		case agentConstrainExtension:
 | 
			
		||||
		case agentConstrainExtension, agentConstrainExtensionV00:
 | 
			
		||||
			var msg constrainExtensionAgentMsg
 | 
			
		||||
			if err = ssh.Unmarshal(constraints, &msg); err != nil {
 | 
			
		||||
				return 0, false, nil, err
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										28
									
								
								vendor/golang.org/x/crypto/ssh/channel.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										28
									
								
								vendor/golang.org/x/crypto/ssh/channel.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -187,9 +187,11 @@ type channel struct {
 | 
			
		||||
	pending    *buffer
 | 
			
		||||
	extPending *buffer
 | 
			
		||||
 | 
			
		||||
	// windowMu protects myWindow, the flow-control window.
 | 
			
		||||
	windowMu sync.Mutex
 | 
			
		||||
	myWindow uint32
 | 
			
		||||
	// windowMu protects myWindow, the flow-control window, and myConsumed,
 | 
			
		||||
	// the number of bytes consumed since we last increased myWindow
 | 
			
		||||
	windowMu   sync.Mutex
 | 
			
		||||
	myWindow   uint32
 | 
			
		||||
	myConsumed uint32
 | 
			
		||||
 | 
			
		||||
	// writeMu serializes calls to mux.conn.writePacket() and
 | 
			
		||||
	// protects sentClose and packetPool. This mutex must be
 | 
			
		||||
@@ -332,14 +334,24 @@ func (ch *channel) handleData(packet []byte) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *channel) adjustWindow(n uint32) error {
 | 
			
		||||
func (c *channel) adjustWindow(adj uint32) error {
 | 
			
		||||
	c.windowMu.Lock()
 | 
			
		||||
	// Since myWindow is managed on our side, and can never exceed
 | 
			
		||||
	// the initial window setting, we don't worry about overflow.
 | 
			
		||||
	c.myWindow += uint32(n)
 | 
			
		||||
	// Since myConsumed and myWindow are managed on our side, and can never
 | 
			
		||||
	// exceed the initial window setting, we don't worry about overflow.
 | 
			
		||||
	c.myConsumed += adj
 | 
			
		||||
	var sendAdj uint32
 | 
			
		||||
	if (channelWindowSize-c.myWindow > 3*c.maxIncomingPayload) ||
 | 
			
		||||
		(c.myWindow < channelWindowSize/2) {
 | 
			
		||||
		sendAdj = c.myConsumed
 | 
			
		||||
		c.myConsumed = 0
 | 
			
		||||
		c.myWindow += sendAdj
 | 
			
		||||
	}
 | 
			
		||||
	c.windowMu.Unlock()
 | 
			
		||||
	if sendAdj == 0 {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
	return c.sendMessage(windowAdjustMsg{
 | 
			
		||||
		AdditionalBytes: uint32(n),
 | 
			
		||||
		AdditionalBytes: sendAdj,
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								vendor/golang.org/x/crypto/ssh/client.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								vendor/golang.org/x/crypto/ssh/client.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -82,7 +82,7 @@ func NewClientConn(c net.Conn, addr string, config *ClientConfig) (Conn, <-chan
 | 
			
		||||
 | 
			
		||||
	if err := conn.clientHandshake(addr, &fullConf); err != nil {
 | 
			
		||||
		c.Close()
 | 
			
		||||
		return nil, nil, nil, fmt.Errorf("ssh: handshake failed: %v", err)
 | 
			
		||||
		return nil, nil, nil, fmt.Errorf("ssh: handshake failed: %w", err)
 | 
			
		||||
	}
 | 
			
		||||
	conn.mux = newMux(conn.transport)
 | 
			
		||||
	return conn, conn.mux.incomingChannels, conn.mux.incomingRequests, nil
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										20
									
								
								vendor/golang.org/x/crypto/ssh/client_auth.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										20
									
								
								vendor/golang.org/x/crypto/ssh/client_auth.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -307,7 +307,10 @@ func (cb publicKeyCallback) auth(session []byte, user string, c packetConn, rand
 | 
			
		||||
	}
 | 
			
		||||
	var methods []string
 | 
			
		||||
	var errSigAlgo error
 | 
			
		||||
	for _, signer := range signers {
 | 
			
		||||
 | 
			
		||||
	origSignersLen := len(signers)
 | 
			
		||||
	for idx := 0; idx < len(signers); idx++ {
 | 
			
		||||
		signer := signers[idx]
 | 
			
		||||
		pub := signer.PublicKey()
 | 
			
		||||
		as, algo, err := pickSignatureAlgorithm(signer, extensions)
 | 
			
		||||
		if err != nil && errSigAlgo == nil {
 | 
			
		||||
@@ -321,6 +324,21 @@ func (cb publicKeyCallback) auth(session []byte, user string, c packetConn, rand
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return authFailure, nil, err
 | 
			
		||||
		}
 | 
			
		||||
		// OpenSSH 7.2-7.7 advertises support for rsa-sha2-256 and rsa-sha2-512
 | 
			
		||||
		// in the "server-sig-algs" extension but doesn't support these
 | 
			
		||||
		// algorithms for certificate authentication, so if the server rejects
 | 
			
		||||
		// the key try to use the obtained algorithm as if "server-sig-algs" had
 | 
			
		||||
		// not been implemented if supported from the algorithm signer.
 | 
			
		||||
		if !ok && idx < origSignersLen && isRSACert(algo) && algo != CertAlgoRSAv01 {
 | 
			
		||||
			if contains(as.Algorithms(), KeyAlgoRSA) {
 | 
			
		||||
				// We retry using the compat algorithm after all signers have
 | 
			
		||||
				// been tried normally.
 | 
			
		||||
				signers = append(signers, &multiAlgorithmSigner{
 | 
			
		||||
					AlgorithmSigner:     as,
 | 
			
		||||
					supportedAlgorithms: []string{KeyAlgoRSA},
 | 
			
		||||
				})
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		if !ok {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										11
									
								
								vendor/golang.org/x/crypto/ssh/common.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										11
									
								
								vendor/golang.org/x/crypto/ssh/common.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -10,7 +10,6 @@ import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io"
 | 
			
		||||
	"math"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"sync"
 | 
			
		||||
 | 
			
		||||
	_ "crypto/sha1"
 | 
			
		||||
@@ -128,6 +127,14 @@ func isRSA(algo string) bool {
 | 
			
		||||
	return contains(algos, underlyingAlgo(algo))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func isRSACert(algo string) bool {
 | 
			
		||||
	_, ok := certKeyAlgoNames[algo]
 | 
			
		||||
	if !ok {
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
	return isRSA(algo)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// supportedPubKeyAuthAlgos specifies the supported client public key
 | 
			
		||||
// authentication algorithms. Note that this doesn't include certificate types
 | 
			
		||||
// since those use the underlying algorithm. This list is sent to the client if
 | 
			
		||||
@@ -140,8 +147,6 @@ var supportedPubKeyAuthAlgos = []string{
 | 
			
		||||
	KeyAlgoDSA,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var supportedPubKeyAuthAlgosList = strings.Join(supportedPubKeyAuthAlgos, ",")
 | 
			
		||||
 | 
			
		||||
// unexpectedMessageError results when the SSH message that we received didn't
 | 
			
		||||
// match what we wanted.
 | 
			
		||||
func unexpectedMessageError(expected, got uint8) error {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										63
									
								
								vendor/golang.org/x/crypto/ssh/handshake.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										63
									
								
								vendor/golang.org/x/crypto/ssh/handshake.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -11,6 +11,7 @@ import (
 | 
			
		||||
	"io"
 | 
			
		||||
	"log"
 | 
			
		||||
	"net"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"sync"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@@ -34,6 +35,16 @@ type keyingTransport interface {
 | 
			
		||||
	// direction will be effected if a msgNewKeys message is sent
 | 
			
		||||
	// or received.
 | 
			
		||||
	prepareKeyChange(*algorithms, *kexResult) error
 | 
			
		||||
 | 
			
		||||
	// setStrictMode sets the strict KEX mode, notably triggering
 | 
			
		||||
	// sequence number resets on sending or receiving msgNewKeys.
 | 
			
		||||
	// If the sequence number is already > 1 when setStrictMode
 | 
			
		||||
	// is called, an error is returned.
 | 
			
		||||
	setStrictMode() error
 | 
			
		||||
 | 
			
		||||
	// setInitialKEXDone indicates to the transport that the initial key exchange
 | 
			
		||||
	// was completed
 | 
			
		||||
	setInitialKEXDone()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// handshakeTransport implements rekeying on top of a keyingTransport
 | 
			
		||||
@@ -50,6 +61,10 @@ type handshakeTransport struct {
 | 
			
		||||
	// connection.
 | 
			
		||||
	hostKeys []Signer
 | 
			
		||||
 | 
			
		||||
	// publicKeyAuthAlgorithms is non-empty if we are the server. In that case,
 | 
			
		||||
	// it contains the supported client public key authentication algorithms.
 | 
			
		||||
	publicKeyAuthAlgorithms []string
 | 
			
		||||
 | 
			
		||||
	// hostKeyAlgorithms is non-empty if we are the client. In that case,
 | 
			
		||||
	// we accept these key types from the server as host key.
 | 
			
		||||
	hostKeyAlgorithms []string
 | 
			
		||||
@@ -95,6 +110,10 @@ type handshakeTransport struct {
 | 
			
		||||
 | 
			
		||||
	// The session ID or nil if first kex did not complete yet.
 | 
			
		||||
	sessionID []byte
 | 
			
		||||
 | 
			
		||||
	// strictMode indicates if the other side of the handshake indicated
 | 
			
		||||
	// that we should be following the strict KEX protocol restrictions.
 | 
			
		||||
	strictMode bool
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type pendingKex struct {
 | 
			
		||||
@@ -141,6 +160,7 @@ func newClientTransport(conn keyingTransport, clientVersion, serverVersion []byt
 | 
			
		||||
func newServerTransport(conn keyingTransport, clientVersion, serverVersion []byte, config *ServerConfig) *handshakeTransport {
 | 
			
		||||
	t := newHandshakeTransport(conn, &config.Config, clientVersion, serverVersion)
 | 
			
		||||
	t.hostKeys = config.hostKeys
 | 
			
		||||
	t.publicKeyAuthAlgorithms = config.PublicKeyAuthAlgorithms
 | 
			
		||||
	go t.readLoop()
 | 
			
		||||
	go t.kexLoop()
 | 
			
		||||
	return t
 | 
			
		||||
@@ -203,7 +223,10 @@ func (t *handshakeTransport) readLoop() {
 | 
			
		||||
			close(t.incoming)
 | 
			
		||||
			break
 | 
			
		||||
		}
 | 
			
		||||
		if p[0] == msgIgnore || p[0] == msgDebug {
 | 
			
		||||
		// If this is the first kex, and strict KEX mode is enabled,
 | 
			
		||||
		// we don't ignore any messages, as they may be used to manipulate
 | 
			
		||||
		// the packet sequence numbers.
 | 
			
		||||
		if !(t.sessionID == nil && t.strictMode) && (p[0] == msgIgnore || p[0] == msgDebug) {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
		t.incoming <- p
 | 
			
		||||
@@ -435,6 +458,11 @@ func (t *handshakeTransport) readOnePacket(first bool) ([]byte, error) {
 | 
			
		||||
	return successPacket, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	kexStrictClient = "kex-strict-c-v00@openssh.com"
 | 
			
		||||
	kexStrictServer = "kex-strict-s-v00@openssh.com"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// sendKexInit sends a key change message.
 | 
			
		||||
func (t *handshakeTransport) sendKexInit() error {
 | 
			
		||||
	t.mu.Lock()
 | 
			
		||||
@@ -448,7 +476,6 @@ func (t *handshakeTransport) sendKexInit() error {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	msg := &kexInitMsg{
 | 
			
		||||
		KexAlgos:                t.config.KeyExchanges,
 | 
			
		||||
		CiphersClientServer:     t.config.Ciphers,
 | 
			
		||||
		CiphersServerClient:     t.config.Ciphers,
 | 
			
		||||
		MACsClientServer:        t.config.MACs,
 | 
			
		||||
@@ -458,6 +485,13 @@ func (t *handshakeTransport) sendKexInit() error {
 | 
			
		||||
	}
 | 
			
		||||
	io.ReadFull(rand.Reader, msg.Cookie[:])
 | 
			
		||||
 | 
			
		||||
	// We mutate the KexAlgos slice, in order to add the kex-strict extension algorithm,
 | 
			
		||||
	// and possibly to add the ext-info extension algorithm. Since the slice may be the
 | 
			
		||||
	// user owned KeyExchanges, we create our own slice in order to avoid using user
 | 
			
		||||
	// owned memory by mistake.
 | 
			
		||||
	msg.KexAlgos = make([]string, 0, len(t.config.KeyExchanges)+2) // room for kex-strict and ext-info
 | 
			
		||||
	msg.KexAlgos = append(msg.KexAlgos, t.config.KeyExchanges...)
 | 
			
		||||
 | 
			
		||||
	isServer := len(t.hostKeys) > 0
 | 
			
		||||
	if isServer {
 | 
			
		||||
		for _, k := range t.hostKeys {
 | 
			
		||||
@@ -482,17 +516,24 @@ func (t *handshakeTransport) sendKexInit() error {
 | 
			
		||||
				msg.ServerHostKeyAlgos = append(msg.ServerHostKeyAlgos, keyFormat)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if t.sessionID == nil {
 | 
			
		||||
			msg.KexAlgos = append(msg.KexAlgos, kexStrictServer)
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		msg.ServerHostKeyAlgos = t.hostKeyAlgorithms
 | 
			
		||||
 | 
			
		||||
		// As a client we opt in to receiving SSH_MSG_EXT_INFO so we know what
 | 
			
		||||
		// algorithms the server supports for public key authentication. See RFC
 | 
			
		||||
		// 8308, Section 2.1.
 | 
			
		||||
		//
 | 
			
		||||
		// We also send the strict KEX mode extension algorithm, in order to opt
 | 
			
		||||
		// into the strict KEX mode.
 | 
			
		||||
		if firstKeyExchange := t.sessionID == nil; firstKeyExchange {
 | 
			
		||||
			msg.KexAlgos = make([]string, 0, len(t.config.KeyExchanges)+1)
 | 
			
		||||
			msg.KexAlgos = append(msg.KexAlgos, t.config.KeyExchanges...)
 | 
			
		||||
			msg.KexAlgos = append(msg.KexAlgos, "ext-info-c")
 | 
			
		||||
			msg.KexAlgos = append(msg.KexAlgos, kexStrictClient)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	packet := Marshal(msg)
 | 
			
		||||
@@ -598,6 +639,13 @@ func (t *handshakeTransport) enterKeyExchange(otherInitPacket []byte) error {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if t.sessionID == nil && ((isClient && contains(serverInit.KexAlgos, kexStrictServer)) || (!isClient && contains(clientInit.KexAlgos, kexStrictClient))) {
 | 
			
		||||
		t.strictMode = true
 | 
			
		||||
		if err := t.conn.setStrictMode(); err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// We don't send FirstKexFollows, but we handle receiving it.
 | 
			
		||||
	//
 | 
			
		||||
	// RFC 4253 section 7 defines the kex and the agreement method for
 | 
			
		||||
@@ -649,6 +697,7 @@ func (t *handshakeTransport) enterKeyExchange(otherInitPacket []byte) error {
 | 
			
		||||
	// message with the server-sig-algs extension if the client supports it. See
 | 
			
		||||
	// RFC 8308, Sections 2.4 and 3.1, and [PROTOCOL], Section 1.9.
 | 
			
		||||
	if !isClient && firstKeyExchange && contains(clientInit.KexAlgos, "ext-info-c") {
 | 
			
		||||
		supportedPubKeyAuthAlgosList := strings.Join(t.publicKeyAuthAlgorithms, ",")
 | 
			
		||||
		extInfo := &extInfoMsg{
 | 
			
		||||
			NumExtensions: 2,
 | 
			
		||||
			Payload:       make([]byte, 0, 4+15+4+len(supportedPubKeyAuthAlgosList)+4+16+4+1),
 | 
			
		||||
@@ -672,6 +721,12 @@ func (t *handshakeTransport) enterKeyExchange(otherInitPacket []byte) error {
 | 
			
		||||
		return unexpectedMessageError(msgNewKeys, packet[0])
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if firstKeyExchange {
 | 
			
		||||
		// Indicates to the transport that the first key exchange is completed
 | 
			
		||||
		// after receiving SSH_MSG_NEWKEYS.
 | 
			
		||||
		t.conn.setInitialKEXDone()
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										19
									
								
								vendor/golang.org/x/crypto/ssh/keys.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										19
									
								
								vendor/golang.org/x/crypto/ssh/keys.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1232,16 +1232,27 @@ func ParseRawPrivateKeyWithPassphrase(pemBytes, passphrase []byte) (interface{},
 | 
			
		||||
		return nil, fmt.Errorf("ssh: cannot decode encrypted private keys: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var result interface{}
 | 
			
		||||
 | 
			
		||||
	switch block.Type {
 | 
			
		||||
	case "RSA PRIVATE KEY":
 | 
			
		||||
		return x509.ParsePKCS1PrivateKey(buf)
 | 
			
		||||
		result, err = x509.ParsePKCS1PrivateKey(buf)
 | 
			
		||||
	case "EC PRIVATE KEY":
 | 
			
		||||
		return x509.ParseECPrivateKey(buf)
 | 
			
		||||
		result, err = x509.ParseECPrivateKey(buf)
 | 
			
		||||
	case "DSA PRIVATE KEY":
 | 
			
		||||
		return ParseDSAPrivateKey(buf)
 | 
			
		||||
		result, err = ParseDSAPrivateKey(buf)
 | 
			
		||||
	default:
 | 
			
		||||
		return nil, fmt.Errorf("ssh: unsupported key type %q", block.Type)
 | 
			
		||||
		err = fmt.Errorf("ssh: unsupported key type %q", block.Type)
 | 
			
		||||
	}
 | 
			
		||||
	// Because of deficiencies in the format, DecryptPEMBlock does not always
 | 
			
		||||
	// 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 {
 | 
			
		||||
		return nil, x509.IncorrectPasswordError
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return result, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ParseDSAPrivateKey returns a DSA private key from its ASN.1 DER encoding, as
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										27
									
								
								vendor/golang.org/x/crypto/ssh/server.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										27
									
								
								vendor/golang.org/x/crypto/ssh/server.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -64,6 +64,13 @@ type ServerConfig struct {
 | 
			
		||||
	// Config contains configuration shared between client and server.
 | 
			
		||||
	Config
 | 
			
		||||
 | 
			
		||||
	// PublicKeyAuthAlgorithms specifies the supported client public key
 | 
			
		||||
	// authentication algorithms. Note that this should not include certificate
 | 
			
		||||
	// types since those use the underlying algorithm. This list is sent to the
 | 
			
		||||
	// client if it supports the server-sig-algs extension. Order is irrelevant.
 | 
			
		||||
	// If unspecified then a default set of algorithms is used.
 | 
			
		||||
	PublicKeyAuthAlgorithms []string
 | 
			
		||||
 | 
			
		||||
	hostKeys []Signer
 | 
			
		||||
 | 
			
		||||
	// NoClientAuth is true if clients are allowed to connect without
 | 
			
		||||
@@ -201,9 +208,20 @@ func NewServerConn(c net.Conn, config *ServerConfig) (*ServerConn, <-chan NewCha
 | 
			
		||||
	if fullConf.MaxAuthTries == 0 {
 | 
			
		||||
		fullConf.MaxAuthTries = 6
 | 
			
		||||
	}
 | 
			
		||||
	if len(fullConf.PublicKeyAuthAlgorithms) == 0 {
 | 
			
		||||
		fullConf.PublicKeyAuthAlgorithms = supportedPubKeyAuthAlgos
 | 
			
		||||
	} else {
 | 
			
		||||
		for _, algo := range fullConf.PublicKeyAuthAlgorithms {
 | 
			
		||||
			if !contains(supportedPubKeyAuthAlgos, algo) {
 | 
			
		||||
				c.Close()
 | 
			
		||||
				return nil, nil, nil, fmt.Errorf("ssh: unsupported public key authentication algorithm %s", algo)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	// Check if the config contains any unsupported key exchanges
 | 
			
		||||
	for _, kex := range fullConf.KeyExchanges {
 | 
			
		||||
		if _, ok := serverForbiddenKexAlgos[kex]; ok {
 | 
			
		||||
			c.Close()
 | 
			
		||||
			return nil, nil, nil, fmt.Errorf("ssh: unsupported key exchange %s for server", kex)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
@@ -321,7 +339,7 @@ func checkSourceAddress(addr net.Addr, sourceAddrs string) error {
 | 
			
		||||
	return fmt.Errorf("ssh: remote address %v is not allowed because of source-address restriction", addr)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func gssExchangeToken(gssapiConfig *GSSAPIWithMICConfig, firstToken []byte, s *connection,
 | 
			
		||||
func gssExchangeToken(gssapiConfig *GSSAPIWithMICConfig, token []byte, s *connection,
 | 
			
		||||
	sessionID []byte, userAuthReq userAuthRequestMsg) (authErr error, perms *Permissions, err error) {
 | 
			
		||||
	gssAPIServer := gssapiConfig.Server
 | 
			
		||||
	defer gssAPIServer.DeleteSecContext()
 | 
			
		||||
@@ -331,7 +349,7 @@ func gssExchangeToken(gssapiConfig *GSSAPIWithMICConfig, firstToken []byte, s *c
 | 
			
		||||
			outToken     []byte
 | 
			
		||||
			needContinue bool
 | 
			
		||||
		)
 | 
			
		||||
		outToken, srcName, needContinue, err = gssAPIServer.AcceptSecContext(firstToken)
 | 
			
		||||
		outToken, srcName, needContinue, err = gssAPIServer.AcceptSecContext(token)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err, nil, nil
 | 
			
		||||
		}
 | 
			
		||||
@@ -353,6 +371,7 @@ func gssExchangeToken(gssapiConfig *GSSAPIWithMICConfig, firstToken []byte, s *c
 | 
			
		||||
		if err := Unmarshal(packet, userAuthGSSAPITokenReq); err != nil {
 | 
			
		||||
			return nil, nil, err
 | 
			
		||||
		}
 | 
			
		||||
		token = userAuthGSSAPITokenReq.Token
 | 
			
		||||
	}
 | 
			
		||||
	packet, err := s.transport.readPacket()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -524,7 +543,7 @@ userAuthLoop:
 | 
			
		||||
				return nil, parseError(msgUserAuthRequest)
 | 
			
		||||
			}
 | 
			
		||||
			algo := string(algoBytes)
 | 
			
		||||
			if !contains(supportedPubKeyAuthAlgos, underlyingAlgo(algo)) {
 | 
			
		||||
			if !contains(config.PublicKeyAuthAlgorithms, underlyingAlgo(algo)) {
 | 
			
		||||
				authErr = fmt.Errorf("ssh: algorithm %q not accepted", algo)
 | 
			
		||||
				break
 | 
			
		||||
			}
 | 
			
		||||
@@ -591,7 +610,7 @@ userAuthLoop:
 | 
			
		||||
				// algorithm name that corresponds to algo with
 | 
			
		||||
				// sig.Format.  This is usually the same, but
 | 
			
		||||
				// for certs, the names differ.
 | 
			
		||||
				if !contains(supportedPubKeyAuthAlgos, sig.Format) {
 | 
			
		||||
				if !contains(config.PublicKeyAuthAlgorithms, sig.Format) {
 | 
			
		||||
					authErr = fmt.Errorf("ssh: algorithm %q not accepted", sig.Format)
 | 
			
		||||
					break
 | 
			
		||||
				}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										35
									
								
								vendor/golang.org/x/crypto/ssh/tcpip.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										35
									
								
								vendor/golang.org/x/crypto/ssh/tcpip.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -5,6 +5,7 @@
 | 
			
		||||
package ssh
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"errors"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io"
 | 
			
		||||
@@ -332,6 +333,40 @@ func (l *tcpListener) Addr() net.Addr {
 | 
			
		||||
	return l.laddr
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// DialContext initiates a connection to the addr from the remote host.
 | 
			
		||||
//
 | 
			
		||||
// The provided Context must be non-nil. If the context expires before the
 | 
			
		||||
// connection is complete, an error is returned. Once successfully connected,
 | 
			
		||||
// any expiration of the context will not affect the connection.
 | 
			
		||||
//
 | 
			
		||||
// See func Dial for additional information.
 | 
			
		||||
func (c *Client) DialContext(ctx context.Context, n, addr string) (net.Conn, error) {
 | 
			
		||||
	if err := ctx.Err(); err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	type connErr struct {
 | 
			
		||||
		conn net.Conn
 | 
			
		||||
		err  error
 | 
			
		||||
	}
 | 
			
		||||
	ch := make(chan connErr)
 | 
			
		||||
	go func() {
 | 
			
		||||
		conn, err := c.Dial(n, addr)
 | 
			
		||||
		select {
 | 
			
		||||
		case ch <- connErr{conn, err}:
 | 
			
		||||
		case <-ctx.Done():
 | 
			
		||||
			if conn != nil {
 | 
			
		||||
				conn.Close()
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}()
 | 
			
		||||
	select {
 | 
			
		||||
	case res := <-ch:
 | 
			
		||||
		return res.conn, res.err
 | 
			
		||||
	case <-ctx.Done():
 | 
			
		||||
		return nil, ctx.Err()
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Dial initiates a connection to the addr from the remote host.
 | 
			
		||||
// The resulting connection has a zero LocalAddr() and RemoteAddr().
 | 
			
		||||
func (c *Client) Dial(n, addr string) (net.Conn, error) {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										32
									
								
								vendor/golang.org/x/crypto/ssh/transport.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										32
									
								
								vendor/golang.org/x/crypto/ssh/transport.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -49,6 +49,9 @@ type transport struct {
 | 
			
		||||
	rand      io.Reader
 | 
			
		||||
	isClient  bool
 | 
			
		||||
	io.Closer
 | 
			
		||||
 | 
			
		||||
	strictMode     bool
 | 
			
		||||
	initialKEXDone bool
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// packetCipher represents a combination of SSH encryption/MAC
 | 
			
		||||
@@ -74,6 +77,18 @@ type connectionState struct {
 | 
			
		||||
	pendingKeyChange chan packetCipher
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (t *transport) setStrictMode() error {
 | 
			
		||||
	if t.reader.seqNum != 1 {
 | 
			
		||||
		return errors.New("ssh: sequence number != 1 when strict KEX mode requested")
 | 
			
		||||
	}
 | 
			
		||||
	t.strictMode = true
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (t *transport) setInitialKEXDone() {
 | 
			
		||||
	t.initialKEXDone = true
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// prepareKeyChange sets up key material for a keychange. The key changes in
 | 
			
		||||
// both directions are triggered by reading and writing a msgNewKey packet
 | 
			
		||||
// respectively.
 | 
			
		||||
@@ -112,11 +127,12 @@ func (t *transport) printPacket(p []byte, write bool) {
 | 
			
		||||
// Read and decrypt next packet.
 | 
			
		||||
func (t *transport) readPacket() (p []byte, err error) {
 | 
			
		||||
	for {
 | 
			
		||||
		p, err = t.reader.readPacket(t.bufReader)
 | 
			
		||||
		p, err = t.reader.readPacket(t.bufReader, t.strictMode)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			break
 | 
			
		||||
		}
 | 
			
		||||
		if len(p) == 0 || (p[0] != msgIgnore && p[0] != msgDebug) {
 | 
			
		||||
		// in strict mode we pass through DEBUG and IGNORE packets only during the initial KEX
 | 
			
		||||
		if len(p) == 0 || (t.strictMode && !t.initialKEXDone) || (p[0] != msgIgnore && p[0] != msgDebug) {
 | 
			
		||||
			break
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
@@ -127,7 +143,7 @@ func (t *transport) readPacket() (p []byte, err error) {
 | 
			
		||||
	return p, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (s *connectionState) readPacket(r *bufio.Reader) ([]byte, error) {
 | 
			
		||||
func (s *connectionState) readPacket(r *bufio.Reader, strictMode bool) ([]byte, error) {
 | 
			
		||||
	packet, err := s.packetCipher.readCipherPacket(s.seqNum, r)
 | 
			
		||||
	s.seqNum++
 | 
			
		||||
	if err == nil && len(packet) == 0 {
 | 
			
		||||
@@ -140,6 +156,9 @@ func (s *connectionState) readPacket(r *bufio.Reader) ([]byte, error) {
 | 
			
		||||
			select {
 | 
			
		||||
			case cipher := <-s.pendingKeyChange:
 | 
			
		||||
				s.packetCipher = cipher
 | 
			
		||||
				if strictMode {
 | 
			
		||||
					s.seqNum = 0
 | 
			
		||||
				}
 | 
			
		||||
			default:
 | 
			
		||||
				return nil, errors.New("ssh: got bogus newkeys message")
 | 
			
		||||
			}
 | 
			
		||||
@@ -170,10 +189,10 @@ func (t *transport) writePacket(packet []byte) error {
 | 
			
		||||
	if debugTransport {
 | 
			
		||||
		t.printPacket(packet, true)
 | 
			
		||||
	}
 | 
			
		||||
	return t.writer.writePacket(t.bufWriter, t.rand, packet)
 | 
			
		||||
	return t.writer.writePacket(t.bufWriter, t.rand, packet, t.strictMode)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (s *connectionState) writePacket(w *bufio.Writer, rand io.Reader, packet []byte) error {
 | 
			
		||||
func (s *connectionState) writePacket(w *bufio.Writer, rand io.Reader, packet []byte, strictMode bool) error {
 | 
			
		||||
	changeKeys := len(packet) > 0 && packet[0] == msgNewKeys
 | 
			
		||||
 | 
			
		||||
	err := s.packetCipher.writeCipherPacket(s.seqNum, w, rand, packet)
 | 
			
		||||
@@ -188,6 +207,9 @@ func (s *connectionState) writePacket(w *bufio.Writer, rand io.Reader, packet []
 | 
			
		||||
		select {
 | 
			
		||||
		case cipher := <-s.pendingKeyChange:
 | 
			
		||||
			s.packetCipher = cipher
 | 
			
		||||
			if strictMode {
 | 
			
		||||
				s.seqNum = 0
 | 
			
		||||
			}
 | 
			
		||||
		default:
 | 
			
		||||
			panic("ssh: no key material for msgNewKeys")
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user