2012-01-26 00:31:12 +04:00
|
|
|
// Copyright 2011 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package ssh
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2012-03-05 02:34:24 +04:00
|
|
|
"encoding/binary"
|
2014-04-10 00:57:52 +04:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2012-01-26 00:31:12 +04:00
|
|
|
"io"
|
|
|
|
"math/big"
|
|
|
|
"reflect"
|
2014-04-10 00:57:52 +04:00
|
|
|
"strconv"
|
2016-04-19 19:49:29 +03:00
|
|
|
"strings"
|
2012-01-26 00:31:12 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
// These are SSH message type numbers. They are scattered around several
|
2012-12-14 19:11:06 +04:00
|
|
|
// documents but many were taken from [SSH-PARAMETERS].
|
2012-01-26 00:31:12 +04:00
|
|
|
const (
|
2014-04-10 00:57:52 +04:00
|
|
|
msgIgnore = 2
|
|
|
|
msgUnimplemented = 3
|
|
|
|
msgDebug = 4
|
|
|
|
msgNewKeys = 21
|
2012-01-26 00:31:12 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
// SSH messages:
|
|
|
|
//
|
|
|
|
// These structures mirror the wire format of the corresponding SSH messages.
|
|
|
|
// They are marshaled using reflection with the marshal and unmarshal functions
|
|
|
|
// in this file. The only wrinkle is that a final member of type []byte with a
|
|
|
|
// ssh tag of "rest" receives the remainder of a packet when unmarshaling.
|
|
|
|
|
|
|
|
// See RFC 4253, section 11.1.
|
2014-04-10 00:57:52 +04:00
|
|
|
const msgDisconnect = 1
|
|
|
|
|
|
|
|
// disconnectMsg is the message that signals a disconnect. It is also
|
|
|
|
// the error type returned from mux.Wait()
|
2012-01-26 00:31:12 +04:00
|
|
|
type disconnectMsg struct {
|
2014-04-10 00:57:52 +04:00
|
|
|
Reason uint32 `sshtype:"1"`
|
2012-01-26 00:31:12 +04:00
|
|
|
Message string
|
|
|
|
Language string
|
|
|
|
}
|
|
|
|
|
2014-04-10 00:57:52 +04:00
|
|
|
func (d *disconnectMsg) Error() string {
|
2016-03-17 14:45:02 +03:00
|
|
|
return fmt.Sprintf("ssh: disconnect, reason %d: %s", d.Reason, d.Message)
|
2014-04-10 00:57:52 +04:00
|
|
|
}
|
|
|
|
|
2012-01-26 00:31:12 +04:00
|
|
|
// See RFC 4253, section 7.1.
|
2014-04-10 00:57:52 +04:00
|
|
|
const msgKexInit = 20
|
|
|
|
|
2012-01-26 00:31:12 +04:00
|
|
|
type kexInitMsg struct {
|
2014-04-10 00:57:52 +04:00
|
|
|
Cookie [16]byte `sshtype:"20"`
|
2012-01-26 00:31:12 +04:00
|
|
|
KexAlgos []string
|
|
|
|
ServerHostKeyAlgos []string
|
|
|
|
CiphersClientServer []string
|
|
|
|
CiphersServerClient []string
|
|
|
|
MACsClientServer []string
|
|
|
|
MACsServerClient []string
|
|
|
|
CompressionClientServer []string
|
|
|
|
CompressionServerClient []string
|
|
|
|
LanguagesClientServer []string
|
|
|
|
LanguagesServerClient []string
|
|
|
|
FirstKexFollows bool
|
|
|
|
Reserved uint32
|
|
|
|
}
|
|
|
|
|
|
|
|
// See RFC 4253, section 8.
|
2014-04-10 00:57:52 +04:00
|
|
|
|
2022-11-03 11:46:41 +03:00
|
|
|
// Diffie-Hellman
|
2014-04-10 00:57:52 +04:00
|
|
|
const msgKexDHInit = 30
|
|
|
|
|
2012-01-26 00:31:12 +04:00
|
|
|
type kexDHInitMsg struct {
|
2014-04-10 00:57:52 +04:00
|
|
|
X *big.Int `sshtype:"30"`
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
|
|
|
|
2014-04-10 00:57:52 +04:00
|
|
|
const msgKexECDHInit = 30
|
|
|
|
|
2013-08-28 18:50:25 +04:00
|
|
|
type kexECDHInitMsg struct {
|
2014-04-10 00:57:52 +04:00
|
|
|
ClientPubKey []byte `sshtype:"30"`
|
2013-08-28 18:50:25 +04:00
|
|
|
}
|
|
|
|
|
2014-04-10 00:57:52 +04:00
|
|
|
const msgKexECDHReply = 31
|
|
|
|
|
2013-08-28 18:50:25 +04:00
|
|
|
type kexECDHReplyMsg struct {
|
2014-04-10 00:57:52 +04:00
|
|
|
HostKey []byte `sshtype:"31"`
|
2013-08-28 18:50:25 +04:00
|
|
|
EphemeralPubKey []byte
|
|
|
|
Signature []byte
|
|
|
|
}
|
|
|
|
|
2014-04-10 00:57:52 +04:00
|
|
|
const msgKexDHReply = 31
|
|
|
|
|
2012-01-26 00:31:12 +04:00
|
|
|
type kexDHReplyMsg struct {
|
2014-04-10 00:57:52 +04:00
|
|
|
HostKey []byte `sshtype:"31"`
|
2012-01-26 00:31:12 +04:00
|
|
|
Y *big.Int
|
|
|
|
Signature []byte
|
|
|
|
}
|
|
|
|
|
2019-06-03 22:41:45 +03:00
|
|
|
// See RFC 4419, section 5.
|
|
|
|
const msgKexDHGexGroup = 31
|
|
|
|
|
|
|
|
type kexDHGexGroupMsg struct {
|
|
|
|
P *big.Int `sshtype:"31"`
|
|
|
|
G *big.Int
|
|
|
|
}
|
|
|
|
|
|
|
|
const msgKexDHGexInit = 32
|
|
|
|
|
|
|
|
type kexDHGexInitMsg struct {
|
|
|
|
X *big.Int `sshtype:"32"`
|
|
|
|
}
|
|
|
|
|
|
|
|
const msgKexDHGexReply = 33
|
|
|
|
|
|
|
|
type kexDHGexReplyMsg struct {
|
|
|
|
HostKey []byte `sshtype:"33"`
|
|
|
|
Y *big.Int
|
|
|
|
Signature []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
const msgKexDHGexRequest = 34
|
|
|
|
|
|
|
|
type kexDHGexRequestMsg struct {
|
|
|
|
MinBits uint32 `sshtype:"34"`
|
|
|
|
PreferedBits uint32
|
|
|
|
MaxBits uint32
|
|
|
|
}
|
|
|
|
|
2012-01-26 00:31:12 +04:00
|
|
|
// See RFC 4253, section 10.
|
2014-04-10 00:57:52 +04:00
|
|
|
const msgServiceRequest = 5
|
|
|
|
|
2012-01-26 00:31:12 +04:00
|
|
|
type serviceRequestMsg struct {
|
2014-04-10 00:57:52 +04:00
|
|
|
Service string `sshtype:"5"`
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// See RFC 4253, section 10.
|
2014-04-10 00:57:52 +04:00
|
|
|
const msgServiceAccept = 6
|
|
|
|
|
2012-01-26 00:31:12 +04:00
|
|
|
type serviceAcceptMsg struct {
|
2014-04-10 00:57:52 +04:00
|
|
|
Service string `sshtype:"6"`
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
|
|
|
|
ssh: support rsa-sha2-256/512 for client authentication
CL 220037 had implemented support for host authentication using
rsa-sha2-256/512, but not client public key authentication. OpenSSH
disabled the SHA-1 based ssh-rsa by default in version 8.8 (after
pre-announcing it in versions 8.2, 8.3, 8.4, 8.5, 8.6, and 8.7) although
some distributions re-enable it. GitHub will start rejecting ssh-rsa for
keys uploaded before November 2, 2021 on March 15, 2022.
https://github.blog/2021-09-01-improving-git-protocol-security-github/
The server side already worked, as long as the client selected one of
the SHA-2 algorithms, because the signature flowed freely to Verify.
There was however nothing verifying that the signature algorithm matched
the advertised one. The comment suggested the check was being performed,
but it got lost back in CL 86190043. Not a security issue because the
signature had to pass the callback's Verify method regardless, and both
values were checked to be acceptable.
Tested with OpenSSH 8.8 configured with "PubkeyAcceptedKeyTypes -ssh-rsa"
and no application-side changes.
The Signers returned by ssh/agent (when backed by an agent client)
didn't actually implement AlgorithmSigner but ParameterizedSigner, an
interface defined in an earlier version of CL 123955.
Updates golang/go#49269
Fixes golang/go#39885
For golang/go#49952
Change-Id: I13b41db8041f1112a70f106c55f077b904b12cb8
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/392394
Trust: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
2022-03-14 17:48:13 +03:00
|
|
|
// See RFC 8308, section 2.3
|
|
|
|
const msgExtInfo = 7
|
|
|
|
|
|
|
|
type extInfoMsg struct {
|
|
|
|
NumExtensions uint32 `sshtype:"7"`
|
|
|
|
Payload []byte `ssh:"rest"`
|
|
|
|
}
|
|
|
|
|
2012-01-26 00:31:12 +04:00
|
|
|
// See RFC 4252, section 5.
|
2014-04-10 00:57:52 +04:00
|
|
|
const msgUserAuthRequest = 50
|
|
|
|
|
2012-01-26 00:31:12 +04:00
|
|
|
type userAuthRequestMsg struct {
|
2014-04-10 00:57:52 +04:00
|
|
|
User string `sshtype:"50"`
|
2012-01-26 00:31:12 +04:00
|
|
|
Service string
|
|
|
|
Method string
|
|
|
|
Payload []byte `ssh:"rest"`
|
|
|
|
}
|
|
|
|
|
2016-04-06 22:39:42 +03:00
|
|
|
// Used for debug printouts of packets.
|
|
|
|
type userAuthSuccessMsg struct {
|
|
|
|
}
|
|
|
|
|
2012-01-26 00:31:12 +04:00
|
|
|
// See RFC 4252, section 5.1
|
2014-04-10 00:57:52 +04:00
|
|
|
const msgUserAuthFailure = 51
|
|
|
|
|
2012-01-26 00:31:12 +04:00
|
|
|
type userAuthFailureMsg struct {
|
2014-04-10 00:57:52 +04:00
|
|
|
Methods []string `sshtype:"51"`
|
2012-01-26 00:31:12 +04:00
|
|
|
PartialSuccess bool
|
|
|
|
}
|
|
|
|
|
2017-09-21 20:41:56 +03:00
|
|
|
// See RFC 4252, section 5.1
|
|
|
|
const msgUserAuthSuccess = 52
|
|
|
|
|
|
|
|
// See RFC 4252, section 5.4
|
|
|
|
const msgUserAuthBanner = 53
|
|
|
|
|
|
|
|
type userAuthBannerMsg struct {
|
|
|
|
Message string `sshtype:"53"`
|
|
|
|
// unused, but required to allow message parsing
|
|
|
|
Language string
|
|
|
|
}
|
|
|
|
|
2013-06-06 18:44:12 +04:00
|
|
|
// See RFC 4256, section 3.2
|
2014-04-10 00:57:52 +04:00
|
|
|
const msgUserAuthInfoRequest = 60
|
|
|
|
const msgUserAuthInfoResponse = 61
|
|
|
|
|
2013-06-06 18:44:12 +04:00
|
|
|
type userAuthInfoRequestMsg struct {
|
2022-03-14 20:38:28 +03:00
|
|
|
Name string `sshtype:"60"`
|
|
|
|
Instruction string
|
|
|
|
Language string
|
|
|
|
NumPrompts uint32
|
|
|
|
Prompts []byte `ssh:"rest"`
|
2013-06-06 18:44:12 +04:00
|
|
|
}
|
|
|
|
|
2012-01-26 00:31:12 +04:00
|
|
|
// See RFC 4254, section 5.1.
|
2014-04-10 00:57:52 +04:00
|
|
|
const msgChannelOpen = 90
|
|
|
|
|
2012-01-26 00:31:12 +04:00
|
|
|
type channelOpenMsg struct {
|
2014-04-10 00:57:52 +04:00
|
|
|
ChanType string `sshtype:"90"`
|
2017-11-28 07:39:32 +03:00
|
|
|
PeersID uint32
|
2012-01-26 00:31:12 +04:00
|
|
|
PeersWindow uint32
|
|
|
|
MaxPacketSize uint32
|
|
|
|
TypeSpecificData []byte `ssh:"rest"`
|
|
|
|
}
|
|
|
|
|
2014-04-10 00:57:52 +04:00
|
|
|
const msgChannelExtendedData = 95
|
|
|
|
const msgChannelData = 94
|
|
|
|
|
2016-04-06 22:39:42 +03:00
|
|
|
// Used for debug print outs of packets.
|
|
|
|
type channelDataMsg struct {
|
2017-11-28 07:39:32 +03:00
|
|
|
PeersID uint32 `sshtype:"94"`
|
2016-04-06 22:39:42 +03:00
|
|
|
Length uint32
|
|
|
|
Rest []byte `ssh:"rest"`
|
|
|
|
}
|
|
|
|
|
2012-01-26 00:31:12 +04:00
|
|
|
// See RFC 4254, section 5.1.
|
2014-04-10 00:57:52 +04:00
|
|
|
const msgChannelOpenConfirm = 91
|
|
|
|
|
2012-01-26 00:31:12 +04:00
|
|
|
type channelOpenConfirmMsg struct {
|
2017-11-28 07:39:32 +03:00
|
|
|
PeersID uint32 `sshtype:"91"`
|
|
|
|
MyID uint32
|
2012-01-26 00:31:12 +04:00
|
|
|
MyWindow uint32
|
|
|
|
MaxPacketSize uint32
|
|
|
|
TypeSpecificData []byte `ssh:"rest"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// See RFC 4254, section 5.1.
|
2014-04-10 00:57:52 +04:00
|
|
|
const msgChannelOpenFailure = 92
|
|
|
|
|
2012-01-26 00:31:12 +04:00
|
|
|
type channelOpenFailureMsg struct {
|
2017-11-28 07:39:32 +03:00
|
|
|
PeersID uint32 `sshtype:"92"`
|
2012-04-26 14:37:06 +04:00
|
|
|
Reason RejectionReason
|
2012-01-26 00:31:12 +04:00
|
|
|
Message string
|
|
|
|
Language string
|
|
|
|
}
|
|
|
|
|
2014-04-10 00:57:52 +04:00
|
|
|
const msgChannelRequest = 98
|
|
|
|
|
2012-01-26 00:31:12 +04:00
|
|
|
type channelRequestMsg struct {
|
2017-11-28 07:39:32 +03:00
|
|
|
PeersID uint32 `sshtype:"98"`
|
2012-01-26 00:31:12 +04:00
|
|
|
Request string
|
|
|
|
WantReply bool
|
|
|
|
RequestSpecificData []byte `ssh:"rest"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// See RFC 4254, section 5.4.
|
2014-04-10 00:57:52 +04:00
|
|
|
const msgChannelSuccess = 99
|
|
|
|
|
2012-01-26 00:31:12 +04:00
|
|
|
type channelRequestSuccessMsg struct {
|
2017-11-28 07:39:32 +03:00
|
|
|
PeersID uint32 `sshtype:"99"`
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// See RFC 4254, section 5.4.
|
2014-04-10 00:57:52 +04:00
|
|
|
const msgChannelFailure = 100
|
|
|
|
|
2012-01-26 00:31:12 +04:00
|
|
|
type channelRequestFailureMsg struct {
|
2017-11-28 07:39:32 +03:00
|
|
|
PeersID uint32 `sshtype:"100"`
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// See RFC 4254, section 5.3
|
2014-04-10 00:57:52 +04:00
|
|
|
const msgChannelClose = 97
|
|
|
|
|
2012-01-26 00:31:12 +04:00
|
|
|
type channelCloseMsg struct {
|
2017-11-28 07:39:32 +03:00
|
|
|
PeersID uint32 `sshtype:"97"`
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// See RFC 4254, section 5.3
|
2014-04-10 00:57:52 +04:00
|
|
|
const msgChannelEOF = 96
|
|
|
|
|
2012-01-26 00:31:12 +04:00
|
|
|
type channelEOFMsg struct {
|
2017-11-28 07:39:32 +03:00
|
|
|
PeersID uint32 `sshtype:"96"`
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// See RFC 4254, section 4
|
2014-04-10 00:57:52 +04:00
|
|
|
const msgGlobalRequest = 80
|
|
|
|
|
2012-01-26 00:31:12 +04:00
|
|
|
type globalRequestMsg struct {
|
2014-04-10 00:57:52 +04:00
|
|
|
Type string `sshtype:"80"`
|
2012-01-26 00:31:12 +04:00
|
|
|
WantReply bool
|
2014-04-10 00:57:52 +04:00
|
|
|
Data []byte `ssh:"rest"`
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
|
|
|
|
2012-05-01 09:43:58 +04:00
|
|
|
// See RFC 4254, section 4
|
2014-04-10 00:57:52 +04:00
|
|
|
const msgRequestSuccess = 81
|
|
|
|
|
2012-05-01 09:43:58 +04:00
|
|
|
type globalRequestSuccessMsg struct {
|
2014-04-10 00:57:52 +04:00
|
|
|
Data []byte `ssh:"rest" sshtype:"81"`
|
2012-05-01 09:43:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// See RFC 4254, section 4
|
2014-04-10 00:57:52 +04:00
|
|
|
const msgRequestFailure = 82
|
|
|
|
|
2012-05-01 09:43:58 +04:00
|
|
|
type globalRequestFailureMsg struct {
|
2014-04-10 00:57:52 +04:00
|
|
|
Data []byte `ssh:"rest" sshtype:"82"`
|
2012-05-01 09:43:58 +04:00
|
|
|
}
|
|
|
|
|
2012-01-26 00:31:12 +04:00
|
|
|
// See RFC 4254, section 5.2
|
2014-04-10 00:57:52 +04:00
|
|
|
const msgChannelWindowAdjust = 93
|
|
|
|
|
2012-01-26 00:31:12 +04:00
|
|
|
type windowAdjustMsg struct {
|
2017-11-28 07:39:32 +03:00
|
|
|
PeersID uint32 `sshtype:"93"`
|
2012-01-26 00:31:12 +04:00
|
|
|
AdditionalBytes uint32
|
|
|
|
}
|
|
|
|
|
|
|
|
// See RFC 4252, section 7
|
2014-04-10 00:57:52 +04:00
|
|
|
const msgUserAuthPubKeyOk = 60
|
|
|
|
|
2012-01-26 00:31:12 +04:00
|
|
|
type userAuthPubKeyOkMsg struct {
|
2014-04-10 00:57:52 +04:00
|
|
|
Algo string `sshtype:"60"`
|
|
|
|
PubKey []byte
|
|
|
|
}
|
|
|
|
|
2019-04-08 06:37:34 +03:00
|
|
|
// See RFC 4462, section 3
|
|
|
|
const msgUserAuthGSSAPIResponse = 60
|
|
|
|
|
|
|
|
type userAuthGSSAPIResponse struct {
|
|
|
|
SupportMech []byte `sshtype:"60"`
|
|
|
|
}
|
|
|
|
|
|
|
|
const msgUserAuthGSSAPIToken = 61
|
|
|
|
|
|
|
|
type userAuthGSSAPIToken struct {
|
|
|
|
Token []byte `sshtype:"61"`
|
|
|
|
}
|
|
|
|
|
|
|
|
const msgUserAuthGSSAPIMIC = 66
|
|
|
|
|
|
|
|
type userAuthGSSAPIMIC struct {
|
|
|
|
MIC []byte `sshtype:"66"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// See RFC 4462, section 3.9
|
|
|
|
const msgUserAuthGSSAPIErrTok = 64
|
|
|
|
|
|
|
|
type userAuthGSSAPIErrTok struct {
|
|
|
|
ErrorToken []byte `sshtype:"64"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// See RFC 4462, section 3.8
|
|
|
|
const msgUserAuthGSSAPIError = 65
|
|
|
|
|
|
|
|
type userAuthGSSAPIError struct {
|
|
|
|
MajorStatus uint32 `sshtype:"65"`
|
|
|
|
MinorStatus uint32
|
|
|
|
Message string
|
|
|
|
LanguageTag string
|
|
|
|
}
|
|
|
|
|
2023-08-31 15:41:07 +03:00
|
|
|
// Transport layer OpenSSH extension. See [PROTOCOL], section 1.9
|
|
|
|
const msgPing = 192
|
|
|
|
|
|
|
|
type pingMsg struct {
|
|
|
|
Data string `sshtype:"192"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Transport layer OpenSSH extension. See [PROTOCOL], section 1.9
|
|
|
|
const msgPong = 193
|
|
|
|
|
|
|
|
type pongMsg struct {
|
|
|
|
Data string `sshtype:"193"`
|
|
|
|
}
|
|
|
|
|
2016-04-19 19:49:29 +03:00
|
|
|
// typeTags returns the possible type bytes for the given reflect.Type, which
|
|
|
|
// should be a struct. The possible values are separated by a '|' character.
|
|
|
|
func typeTags(structType reflect.Type) (tags []byte) {
|
|
|
|
tagStr := structType.Field(0).Tag.Get("sshtype")
|
|
|
|
|
|
|
|
for _, tag := range strings.Split(tagStr, "|") {
|
|
|
|
i, err := strconv.Atoi(tag)
|
|
|
|
if err == nil {
|
|
|
|
tags = append(tags, byte(i))
|
|
|
|
}
|
2014-04-10 00:57:52 +04:00
|
|
|
}
|
2016-04-19 19:49:29 +03:00
|
|
|
|
|
|
|
return tags
|
2014-04-10 00:57:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func fieldError(t reflect.Type, field int, problem string) error {
|
|
|
|
if problem != "" {
|
|
|
|
problem = ": " + problem
|
|
|
|
}
|
|
|
|
return fmt.Errorf("ssh: unmarshal error for field %s of type %s%s", t.Field(field).Name, t.Name(), problem)
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
|
|
|
|
2014-04-10 00:57:52 +04:00
|
|
|
var errShortRead = errors.New("ssh: short read")
|
|
|
|
|
|
|
|
// Unmarshal parses data in SSH wire format into a structure. The out
|
|
|
|
// argument should be a pointer to struct. If the first member of the
|
2016-04-19 19:49:29 +03:00
|
|
|
// struct has the "sshtype" tag set to a '|'-separated set of numbers
|
|
|
|
// in decimal, the packet must start with one of those numbers. In
|
|
|
|
// case of error, Unmarshal returns a ParseError or
|
|
|
|
// UnexpectedMessageError.
|
2014-04-10 00:57:52 +04:00
|
|
|
func Unmarshal(data []byte, out interface{}) error {
|
|
|
|
v := reflect.ValueOf(out).Elem()
|
|
|
|
structType := v.Type()
|
2016-04-19 19:49:29 +03:00
|
|
|
expectedTypes := typeTags(structType)
|
|
|
|
|
|
|
|
var expectedType byte
|
|
|
|
if len(expectedTypes) > 0 {
|
|
|
|
expectedType = expectedTypes[0]
|
|
|
|
}
|
|
|
|
|
2014-04-10 00:57:52 +04:00
|
|
|
if len(data) == 0 {
|
|
|
|
return parseError(expectedType)
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
2016-04-19 19:49:29 +03:00
|
|
|
|
|
|
|
if len(expectedTypes) > 0 {
|
|
|
|
goodType := false
|
|
|
|
for _, e := range expectedTypes {
|
|
|
|
if e > 0 && data[0] == e {
|
|
|
|
goodType = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !goodType {
|
|
|
|
return fmt.Errorf("ssh: unexpected message type %d (expected one of %v)", data[0], expectedTypes)
|
2013-10-15 09:18:32 +04:00
|
|
|
}
|
2014-04-10 00:57:52 +04:00
|
|
|
data = data[1:]
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
var ok bool
|
|
|
|
for i := 0; i < v.NumField(); i++ {
|
|
|
|
field := v.Field(i)
|
|
|
|
t := field.Type()
|
|
|
|
switch t.Kind() {
|
|
|
|
case reflect.Bool:
|
2014-04-10 00:57:52 +04:00
|
|
|
if len(data) < 1 {
|
|
|
|
return errShortRead
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
2014-04-10 00:57:52 +04:00
|
|
|
field.SetBool(data[0] != 0)
|
|
|
|
data = data[1:]
|
2012-01-26 00:31:12 +04:00
|
|
|
case reflect.Array:
|
|
|
|
if t.Elem().Kind() != reflect.Uint8 {
|
2014-04-10 00:57:52 +04:00
|
|
|
return fieldError(structType, i, "array of unsupported type")
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
2014-04-10 00:57:52 +04:00
|
|
|
if len(data) < t.Len() {
|
|
|
|
return errShortRead
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
2012-03-05 02:34:24 +04:00
|
|
|
for j, n := 0, t.Len(); j < n; j++ {
|
2014-04-10 00:57:52 +04:00
|
|
|
field.Index(j).Set(reflect.ValueOf(data[j]))
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
2014-04-10 00:57:52 +04:00
|
|
|
data = data[t.Len():]
|
|
|
|
case reflect.Uint64:
|
|
|
|
var u64 uint64
|
|
|
|
if u64, data, ok = parseUint64(data); !ok {
|
|
|
|
return errShortRead
|
|
|
|
}
|
|
|
|
field.SetUint(u64)
|
2012-01-26 00:31:12 +04:00
|
|
|
case reflect.Uint32:
|
|
|
|
var u32 uint32
|
2014-04-10 00:57:52 +04:00
|
|
|
if u32, data, ok = parseUint32(data); !ok {
|
|
|
|
return errShortRead
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
|
|
|
field.SetUint(uint64(u32))
|
2014-04-10 00:57:52 +04:00
|
|
|
case reflect.Uint8:
|
|
|
|
if len(data) < 1 {
|
|
|
|
return errShortRead
|
|
|
|
}
|
|
|
|
field.SetUint(uint64(data[0]))
|
|
|
|
data = data[1:]
|
2012-01-26 00:31:12 +04:00
|
|
|
case reflect.String:
|
|
|
|
var s []byte
|
2014-04-10 00:57:52 +04:00
|
|
|
if s, data, ok = parseString(data); !ok {
|
|
|
|
return fieldError(structType, i, "")
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
|
|
|
field.SetString(string(s))
|
|
|
|
case reflect.Slice:
|
|
|
|
switch t.Elem().Kind() {
|
|
|
|
case reflect.Uint8:
|
|
|
|
if structType.Field(i).Tag.Get("ssh") == "rest" {
|
2014-04-10 00:57:52 +04:00
|
|
|
field.Set(reflect.ValueOf(data))
|
|
|
|
data = nil
|
2012-01-26 00:31:12 +04:00
|
|
|
} else {
|
|
|
|
var s []byte
|
2014-04-10 00:57:52 +04:00
|
|
|
if s, data, ok = parseString(data); !ok {
|
|
|
|
return errShortRead
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
|
|
|
field.Set(reflect.ValueOf(s))
|
|
|
|
}
|
|
|
|
case reflect.String:
|
|
|
|
var nl []string
|
2014-04-10 00:57:52 +04:00
|
|
|
if nl, data, ok = parseNameList(data); !ok {
|
|
|
|
return errShortRead
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
|
|
|
field.Set(reflect.ValueOf(nl))
|
|
|
|
default:
|
2014-04-10 00:57:52 +04:00
|
|
|
return fieldError(structType, i, "slice of unsupported type")
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
|
|
|
case reflect.Ptr:
|
|
|
|
if t == bigIntType {
|
|
|
|
var n *big.Int
|
2014-04-10 00:57:52 +04:00
|
|
|
if n, data, ok = parseInt(data); !ok {
|
|
|
|
return errShortRead
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
|
|
|
field.Set(reflect.ValueOf(n))
|
|
|
|
} else {
|
2014-04-10 00:57:52 +04:00
|
|
|
return fieldError(structType, i, "pointer to unsupported type")
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
|
|
|
default:
|
2016-04-19 19:49:29 +03:00
|
|
|
return fieldError(structType, i, fmt.Sprintf("unsupported type: %v", t))
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-10 00:57:52 +04:00
|
|
|
if len(data) != 0 {
|
|
|
|
return parseError(expectedType)
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-04-10 00:57:52 +04:00
|
|
|
// Marshal serializes the message in msg to SSH wire format. The msg
|
|
|
|
// argument should be a struct or pointer to struct. If the first
|
|
|
|
// member has the "sshtype" tag set to a number in decimal, that
|
|
|
|
// number is prepended to the result. If the last of member has the
|
|
|
|
// "ssh" tag set to "rest", its contents are appended to the output.
|
|
|
|
func Marshal(msg interface{}) []byte {
|
2013-10-15 09:18:32 +04:00
|
|
|
out := make([]byte, 0, 64)
|
2014-04-10 00:57:52 +04:00
|
|
|
return marshalStruct(out, msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
func marshalStruct(out []byte, msg interface{}) []byte {
|
|
|
|
v := reflect.Indirect(reflect.ValueOf(msg))
|
2016-04-19 19:49:29 +03:00
|
|
|
msgTypes := typeTags(v.Type())
|
|
|
|
if len(msgTypes) > 0 {
|
|
|
|
out = append(out, msgTypes[0])
|
2013-10-15 09:18:32 +04:00
|
|
|
}
|
2012-01-26 00:31:12 +04:00
|
|
|
|
2012-03-05 02:34:24 +04:00
|
|
|
for i, n := 0, v.NumField(); i < n; i++ {
|
2012-01-26 00:31:12 +04:00
|
|
|
field := v.Field(i)
|
2012-03-05 02:34:24 +04:00
|
|
|
switch t := field.Type(); t.Kind() {
|
2012-01-26 00:31:12 +04:00
|
|
|
case reflect.Bool:
|
|
|
|
var v uint8
|
|
|
|
if field.Bool() {
|
|
|
|
v = 1
|
|
|
|
}
|
|
|
|
out = append(out, v)
|
|
|
|
case reflect.Array:
|
|
|
|
if t.Elem().Kind() != reflect.Uint8 {
|
2014-04-10 00:57:52 +04:00
|
|
|
panic(fmt.Sprintf("array of non-uint8 in field %d: %T", i, field.Interface()))
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
2012-03-05 02:34:24 +04:00
|
|
|
for j, l := 0, t.Len(); j < l; j++ {
|
|
|
|
out = append(out, uint8(field.Index(j).Uint()))
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
|
|
|
case reflect.Uint32:
|
2012-03-05 02:34:24 +04:00
|
|
|
out = appendU32(out, uint32(field.Uint()))
|
2014-04-10 00:57:52 +04:00
|
|
|
case reflect.Uint64:
|
|
|
|
out = appendU64(out, uint64(field.Uint()))
|
|
|
|
case reflect.Uint8:
|
|
|
|
out = append(out, uint8(field.Uint()))
|
2012-01-26 00:31:12 +04:00
|
|
|
case reflect.String:
|
|
|
|
s := field.String()
|
2012-03-05 02:34:24 +04:00
|
|
|
out = appendInt(out, len(s))
|
2012-01-26 00:31:12 +04:00
|
|
|
out = append(out, s...)
|
|
|
|
case reflect.Slice:
|
|
|
|
switch t.Elem().Kind() {
|
|
|
|
case reflect.Uint8:
|
2012-03-05 02:34:24 +04:00
|
|
|
if v.Type().Field(i).Tag.Get("ssh") != "rest" {
|
|
|
|
out = appendInt(out, field.Len())
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
2012-03-05 02:34:24 +04:00
|
|
|
out = append(out, field.Bytes()...)
|
2012-01-26 00:31:12 +04:00
|
|
|
case reflect.String:
|
2012-03-05 02:34:24 +04:00
|
|
|
offset := len(out)
|
|
|
|
out = appendU32(out, 0)
|
|
|
|
if n := field.Len(); n > 0 {
|
|
|
|
for j := 0; j < n; j++ {
|
|
|
|
f := field.Index(j)
|
|
|
|
if j != 0 {
|
|
|
|
out = append(out, ',')
|
|
|
|
}
|
|
|
|
out = append(out, f.String()...)
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
2012-03-05 02:34:24 +04:00
|
|
|
// overwrite length value
|
|
|
|
binary.BigEndian.PutUint32(out[offset:], uint32(len(out)-offset-4))
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
|
|
|
default:
|
2014-04-10 00:57:52 +04:00
|
|
|
panic(fmt.Sprintf("slice of unknown type in field %d: %T", i, field.Interface()))
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
|
|
|
case reflect.Ptr:
|
|
|
|
if t == bigIntType {
|
|
|
|
var n *big.Int
|
|
|
|
nValue := reflect.ValueOf(&n)
|
|
|
|
nValue.Elem().Set(field)
|
|
|
|
needed := intLength(n)
|
|
|
|
oldLength := len(out)
|
|
|
|
|
|
|
|
if cap(out)-len(out) < needed {
|
|
|
|
newOut := make([]byte, len(out), 2*(len(out)+needed))
|
|
|
|
copy(newOut, out)
|
|
|
|
out = newOut
|
|
|
|
}
|
|
|
|
out = out[:oldLength+needed]
|
|
|
|
marshalInt(out[oldLength:], n)
|
|
|
|
} else {
|
2014-04-10 00:57:52 +04:00
|
|
|
panic(fmt.Sprintf("pointer to unknown type in field %d: %T", i, field.Interface()))
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
|
|
|
var bigOne = big.NewInt(1)
|
|
|
|
|
|
|
|
func parseString(in []byte) (out, rest []byte, ok bool) {
|
|
|
|
if len(in) < 4 {
|
|
|
|
return
|
|
|
|
}
|
2012-03-05 02:34:24 +04:00
|
|
|
length := binary.BigEndian.Uint32(in)
|
2015-06-23 18:05:18 +03:00
|
|
|
in = in[4:]
|
|
|
|
if uint32(len(in)) < length {
|
2012-01-26 00:31:12 +04:00
|
|
|
return
|
|
|
|
}
|
2015-06-23 18:05:18 +03:00
|
|
|
out = in[:length]
|
|
|
|
rest = in[length:]
|
2012-01-26 00:31:12 +04:00
|
|
|
ok = true
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
comma = []byte{','}
|
|
|
|
emptyNameList = []string{}
|
|
|
|
)
|
|
|
|
|
|
|
|
func parseNameList(in []byte) (out []string, rest []byte, ok bool) {
|
|
|
|
contents, rest, ok := parseString(in)
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(contents) == 0 {
|
|
|
|
out = emptyNameList
|
|
|
|
return
|
|
|
|
}
|
|
|
|
parts := bytes.Split(contents, comma)
|
|
|
|
out = make([]string, len(parts))
|
|
|
|
for i, part := range parts {
|
|
|
|
out[i] = string(part)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func parseInt(in []byte) (out *big.Int, rest []byte, ok bool) {
|
|
|
|
contents, rest, ok := parseString(in)
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
out = new(big.Int)
|
|
|
|
|
|
|
|
if len(contents) > 0 && contents[0]&0x80 == 0x80 {
|
|
|
|
// This is a negative number
|
|
|
|
notBytes := make([]byte, len(contents))
|
|
|
|
for i := range notBytes {
|
|
|
|
notBytes[i] = ^contents[i]
|
|
|
|
}
|
|
|
|
out.SetBytes(notBytes)
|
|
|
|
out.Add(out, bigOne)
|
|
|
|
out.Neg(out)
|
|
|
|
} else {
|
|
|
|
// Positive number
|
|
|
|
out.SetBytes(contents)
|
|
|
|
}
|
|
|
|
ok = true
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2012-03-05 02:34:24 +04:00
|
|
|
func parseUint32(in []byte) (uint32, []byte, bool) {
|
2012-01-26 00:31:12 +04:00
|
|
|
if len(in) < 4 {
|
2012-03-05 02:34:24 +04:00
|
|
|
return 0, nil, false
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
2012-03-05 02:34:24 +04:00
|
|
|
return binary.BigEndian.Uint32(in), in[4:], true
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
|
|
|
|
2012-03-05 02:34:24 +04:00
|
|
|
func parseUint64(in []byte) (uint64, []byte, bool) {
|
2012-02-24 21:52:06 +04:00
|
|
|
if len(in) < 8 {
|
2012-03-05 02:34:24 +04:00
|
|
|
return 0, nil, false
|
2012-02-24 21:52:06 +04:00
|
|
|
}
|
2012-03-05 02:34:24 +04:00
|
|
|
return binary.BigEndian.Uint64(in), in[8:], true
|
2012-02-24 21:52:06 +04:00
|
|
|
}
|
|
|
|
|
2012-01-26 00:31:12 +04:00
|
|
|
func intLength(n *big.Int) int {
|
|
|
|
length := 4 /* length bytes */
|
|
|
|
if n.Sign() < 0 {
|
|
|
|
nMinus1 := new(big.Int).Neg(n)
|
|
|
|
nMinus1.Sub(nMinus1, bigOne)
|
|
|
|
bitLen := nMinus1.BitLen()
|
|
|
|
if bitLen%8 == 0 {
|
|
|
|
// The number will need 0xff padding
|
|
|
|
length++
|
|
|
|
}
|
|
|
|
length += (bitLen + 7) / 8
|
|
|
|
} else if n.Sign() == 0 {
|
|
|
|
// A zero is the zero length string
|
|
|
|
} else {
|
|
|
|
bitLen := n.BitLen()
|
|
|
|
if bitLen%8 == 0 {
|
|
|
|
// The number will need 0x00 padding
|
|
|
|
length++
|
|
|
|
}
|
|
|
|
length += (bitLen + 7) / 8
|
|
|
|
}
|
|
|
|
|
|
|
|
return length
|
|
|
|
}
|
|
|
|
|
|
|
|
func marshalUint32(to []byte, n uint32) []byte {
|
2012-03-05 02:34:24 +04:00
|
|
|
binary.BigEndian.PutUint32(to, n)
|
2012-01-26 00:31:12 +04:00
|
|
|
return to[4:]
|
|
|
|
}
|
|
|
|
|
|
|
|
func marshalUint64(to []byte, n uint64) []byte {
|
2012-03-05 02:34:24 +04:00
|
|
|
binary.BigEndian.PutUint64(to, n)
|
2012-01-26 00:31:12 +04:00
|
|
|
return to[8:]
|
|
|
|
}
|
|
|
|
|
|
|
|
func marshalInt(to []byte, n *big.Int) []byte {
|
|
|
|
lengthBytes := to
|
|
|
|
to = to[4:]
|
|
|
|
length := 0
|
|
|
|
|
|
|
|
if n.Sign() < 0 {
|
|
|
|
// A negative number has to be converted to two's-complement
|
|
|
|
// form. So we'll subtract 1 and invert. If the
|
|
|
|
// most-significant-bit isn't set then we'll need to pad the
|
|
|
|
// beginning with 0xff in order to keep the number negative.
|
|
|
|
nMinus1 := new(big.Int).Neg(n)
|
|
|
|
nMinus1.Sub(nMinus1, bigOne)
|
|
|
|
bytes := nMinus1.Bytes()
|
|
|
|
for i := range bytes {
|
|
|
|
bytes[i] ^= 0xff
|
|
|
|
}
|
|
|
|
if len(bytes) == 0 || bytes[0]&0x80 == 0 {
|
|
|
|
to[0] = 0xff
|
|
|
|
to = to[1:]
|
|
|
|
length++
|
|
|
|
}
|
|
|
|
nBytes := copy(to, bytes)
|
|
|
|
to = to[nBytes:]
|
|
|
|
length += nBytes
|
|
|
|
} else if n.Sign() == 0 {
|
|
|
|
// A zero is the zero length string
|
|
|
|
} else {
|
|
|
|
bytes := n.Bytes()
|
|
|
|
if len(bytes) > 0 && bytes[0]&0x80 != 0 {
|
|
|
|
// We'll have to pad this with a 0x00 in order to
|
|
|
|
// stop it looking like a negative number.
|
|
|
|
to[0] = 0
|
|
|
|
to = to[1:]
|
|
|
|
length++
|
|
|
|
}
|
|
|
|
nBytes := copy(to, bytes)
|
|
|
|
to = to[nBytes:]
|
|
|
|
length += nBytes
|
|
|
|
}
|
|
|
|
|
|
|
|
lengthBytes[0] = byte(length >> 24)
|
|
|
|
lengthBytes[1] = byte(length >> 16)
|
|
|
|
lengthBytes[2] = byte(length >> 8)
|
|
|
|
lengthBytes[3] = byte(length)
|
|
|
|
return to
|
|
|
|
}
|
|
|
|
|
|
|
|
func writeInt(w io.Writer, n *big.Int) {
|
|
|
|
length := intLength(n)
|
|
|
|
buf := make([]byte, length)
|
|
|
|
marshalInt(buf, n)
|
|
|
|
w.Write(buf)
|
|
|
|
}
|
|
|
|
|
|
|
|
func writeString(w io.Writer, s []byte) {
|
|
|
|
var lengthBytes [4]byte
|
|
|
|
lengthBytes[0] = byte(len(s) >> 24)
|
|
|
|
lengthBytes[1] = byte(len(s) >> 16)
|
|
|
|
lengthBytes[2] = byte(len(s) >> 8)
|
|
|
|
lengthBytes[3] = byte(len(s))
|
|
|
|
w.Write(lengthBytes[:])
|
|
|
|
w.Write(s)
|
|
|
|
}
|
|
|
|
|
2012-04-20 23:17:42 +04:00
|
|
|
func stringLength(n int) int {
|
|
|
|
return 4 + n
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func marshalString(to []byte, s []byte) []byte {
|
|
|
|
to[0] = byte(len(s) >> 24)
|
|
|
|
to[1] = byte(len(s) >> 16)
|
|
|
|
to[2] = byte(len(s) >> 8)
|
|
|
|
to[3] = byte(len(s))
|
|
|
|
to = to[4:]
|
|
|
|
copy(to, s)
|
|
|
|
return to[len(s):]
|
|
|
|
}
|
|
|
|
|
|
|
|
var bigIntType = reflect.TypeOf((*big.Int)(nil))
|
|
|
|
|
2013-06-06 18:24:21 +04:00
|
|
|
// Decode a packet into its corresponding message.
|
|
|
|
func decode(packet []byte) (interface{}, error) {
|
2012-01-26 00:31:12 +04:00
|
|
|
var msg interface{}
|
|
|
|
switch packet[0] {
|
|
|
|
case msgDisconnect:
|
|
|
|
msg = new(disconnectMsg)
|
|
|
|
case msgServiceRequest:
|
|
|
|
msg = new(serviceRequestMsg)
|
|
|
|
case msgServiceAccept:
|
|
|
|
msg = new(serviceAcceptMsg)
|
ssh: support rsa-sha2-256/512 for client authentication
CL 220037 had implemented support for host authentication using
rsa-sha2-256/512, but not client public key authentication. OpenSSH
disabled the SHA-1 based ssh-rsa by default in version 8.8 (after
pre-announcing it in versions 8.2, 8.3, 8.4, 8.5, 8.6, and 8.7) although
some distributions re-enable it. GitHub will start rejecting ssh-rsa for
keys uploaded before November 2, 2021 on March 15, 2022.
https://github.blog/2021-09-01-improving-git-protocol-security-github/
The server side already worked, as long as the client selected one of
the SHA-2 algorithms, because the signature flowed freely to Verify.
There was however nothing verifying that the signature algorithm matched
the advertised one. The comment suggested the check was being performed,
but it got lost back in CL 86190043. Not a security issue because the
signature had to pass the callback's Verify method regardless, and both
values were checked to be acceptable.
Tested with OpenSSH 8.8 configured with "PubkeyAcceptedKeyTypes -ssh-rsa"
and no application-side changes.
The Signers returned by ssh/agent (when backed by an agent client)
didn't actually implement AlgorithmSigner but ParameterizedSigner, an
interface defined in an earlier version of CL 123955.
Updates golang/go#49269
Fixes golang/go#39885
For golang/go#49952
Change-Id: I13b41db8041f1112a70f106c55f077b904b12cb8
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/392394
Trust: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
2022-03-14 17:48:13 +03:00
|
|
|
case msgExtInfo:
|
|
|
|
msg = new(extInfoMsg)
|
2012-01-26 00:31:12 +04:00
|
|
|
case msgKexInit:
|
|
|
|
msg = new(kexInitMsg)
|
|
|
|
case msgKexDHInit:
|
|
|
|
msg = new(kexDHInitMsg)
|
|
|
|
case msgKexDHReply:
|
|
|
|
msg = new(kexDHReplyMsg)
|
|
|
|
case msgUserAuthRequest:
|
|
|
|
msg = new(userAuthRequestMsg)
|
2016-04-06 22:39:42 +03:00
|
|
|
case msgUserAuthSuccess:
|
|
|
|
return new(userAuthSuccessMsg), nil
|
2012-01-26 00:31:12 +04:00
|
|
|
case msgUserAuthFailure:
|
|
|
|
msg = new(userAuthFailureMsg)
|
|
|
|
case msgUserAuthPubKeyOk:
|
|
|
|
msg = new(userAuthPubKeyOkMsg)
|
|
|
|
case msgGlobalRequest:
|
|
|
|
msg = new(globalRequestMsg)
|
|
|
|
case msgRequestSuccess:
|
2012-05-01 09:43:58 +04:00
|
|
|
msg = new(globalRequestSuccessMsg)
|
2012-01-26 00:31:12 +04:00
|
|
|
case msgRequestFailure:
|
2012-05-01 09:43:58 +04:00
|
|
|
msg = new(globalRequestFailureMsg)
|
2012-01-26 00:31:12 +04:00
|
|
|
case msgChannelOpen:
|
|
|
|
msg = new(channelOpenMsg)
|
2016-04-06 22:39:42 +03:00
|
|
|
case msgChannelData:
|
|
|
|
msg = new(channelDataMsg)
|
2012-01-26 00:31:12 +04:00
|
|
|
case msgChannelOpenConfirm:
|
|
|
|
msg = new(channelOpenConfirmMsg)
|
|
|
|
case msgChannelOpenFailure:
|
|
|
|
msg = new(channelOpenFailureMsg)
|
|
|
|
case msgChannelWindowAdjust:
|
|
|
|
msg = new(windowAdjustMsg)
|
|
|
|
case msgChannelEOF:
|
|
|
|
msg = new(channelEOFMsg)
|
|
|
|
case msgChannelClose:
|
|
|
|
msg = new(channelCloseMsg)
|
|
|
|
case msgChannelRequest:
|
|
|
|
msg = new(channelRequestMsg)
|
|
|
|
case msgChannelSuccess:
|
|
|
|
msg = new(channelRequestSuccessMsg)
|
|
|
|
case msgChannelFailure:
|
|
|
|
msg = new(channelRequestFailureMsg)
|
2019-04-08 06:37:34 +03:00
|
|
|
case msgUserAuthGSSAPIToken:
|
|
|
|
msg = new(userAuthGSSAPIToken)
|
|
|
|
case msgUserAuthGSSAPIMIC:
|
|
|
|
msg = new(userAuthGSSAPIMIC)
|
|
|
|
case msgUserAuthGSSAPIErrTok:
|
|
|
|
msg = new(userAuthGSSAPIErrTok)
|
|
|
|
case msgUserAuthGSSAPIError:
|
|
|
|
msg = new(userAuthGSSAPIError)
|
2012-01-26 00:31:12 +04:00
|
|
|
default:
|
2014-04-10 00:57:52 +04:00
|
|
|
return nil, unexpectedMessageError(0, packet[0])
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
2014-04-10 00:57:52 +04:00
|
|
|
if err := Unmarshal(packet, msg); err != nil {
|
2013-06-06 18:24:21 +04:00
|
|
|
return nil, err
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
2013-06-06 18:24:21 +04:00
|
|
|
return msg, nil
|
2012-01-26 00:31:12 +04:00
|
|
|
}
|
2019-04-11 12:06:51 +03:00
|
|
|
|
|
|
|
var packetTypeNames = map[byte]string{
|
|
|
|
msgDisconnect: "disconnectMsg",
|
|
|
|
msgServiceRequest: "serviceRequestMsg",
|
|
|
|
msgServiceAccept: "serviceAcceptMsg",
|
ssh: support rsa-sha2-256/512 for client authentication
CL 220037 had implemented support for host authentication using
rsa-sha2-256/512, but not client public key authentication. OpenSSH
disabled the SHA-1 based ssh-rsa by default in version 8.8 (after
pre-announcing it in versions 8.2, 8.3, 8.4, 8.5, 8.6, and 8.7) although
some distributions re-enable it. GitHub will start rejecting ssh-rsa for
keys uploaded before November 2, 2021 on March 15, 2022.
https://github.blog/2021-09-01-improving-git-protocol-security-github/
The server side already worked, as long as the client selected one of
the SHA-2 algorithms, because the signature flowed freely to Verify.
There was however nothing verifying that the signature algorithm matched
the advertised one. The comment suggested the check was being performed,
but it got lost back in CL 86190043. Not a security issue because the
signature had to pass the callback's Verify method regardless, and both
values were checked to be acceptable.
Tested with OpenSSH 8.8 configured with "PubkeyAcceptedKeyTypes -ssh-rsa"
and no application-side changes.
The Signers returned by ssh/agent (when backed by an agent client)
didn't actually implement AlgorithmSigner but ParameterizedSigner, an
interface defined in an earlier version of CL 123955.
Updates golang/go#49269
Fixes golang/go#39885
For golang/go#49952
Change-Id: I13b41db8041f1112a70f106c55f077b904b12cb8
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/392394
Trust: Filippo Valsorda <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
2022-03-14 17:48:13 +03:00
|
|
|
msgExtInfo: "extInfoMsg",
|
2019-04-11 12:06:51 +03:00
|
|
|
msgKexInit: "kexInitMsg",
|
|
|
|
msgKexDHInit: "kexDHInitMsg",
|
|
|
|
msgKexDHReply: "kexDHReplyMsg",
|
|
|
|
msgUserAuthRequest: "userAuthRequestMsg",
|
|
|
|
msgUserAuthSuccess: "userAuthSuccessMsg",
|
|
|
|
msgUserAuthFailure: "userAuthFailureMsg",
|
|
|
|
msgUserAuthPubKeyOk: "userAuthPubKeyOkMsg",
|
|
|
|
msgGlobalRequest: "globalRequestMsg",
|
|
|
|
msgRequestSuccess: "globalRequestSuccessMsg",
|
|
|
|
msgRequestFailure: "globalRequestFailureMsg",
|
|
|
|
msgChannelOpen: "channelOpenMsg",
|
|
|
|
msgChannelData: "channelDataMsg",
|
|
|
|
msgChannelOpenConfirm: "channelOpenConfirmMsg",
|
|
|
|
msgChannelOpenFailure: "channelOpenFailureMsg",
|
|
|
|
msgChannelWindowAdjust: "windowAdjustMsg",
|
|
|
|
msgChannelEOF: "channelEOFMsg",
|
|
|
|
msgChannelClose: "channelCloseMsg",
|
|
|
|
msgChannelRequest: "channelRequestMsg",
|
|
|
|
msgChannelSuccess: "channelRequestSuccessMsg",
|
|
|
|
msgChannelFailure: "channelRequestFailureMsg",
|
|
|
|
}
|