Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2c476679df | ||
|
|
0ec7e8322c | ||
|
|
6fad3dfc18 | ||
|
|
21d60a1521 |
+1
-1
@@ -50,7 +50,7 @@ func (ih InvalidHashPrefixError) Error() string {
|
|||||||
type InvalidCostError int
|
type InvalidCostError int
|
||||||
|
|
||||||
func (ic InvalidCostError) Error() string {
|
func (ic InvalidCostError) Error() string {
|
||||||
return fmt.Sprintf("crypto/bcrypt: cost %d is outside allowed range (%d,%d)", int(ic), int(MinCost), int(MaxCost))
|
return fmt.Sprintf("crypto/bcrypt: cost %d is outside allowed range (%d,%d)", int(ic), MinCost, MaxCost)
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
+42
-35
@@ -264,36 +264,35 @@ func (s *String) ReadASN1Boolean(out *bool) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
var bigIntType = reflect.TypeOf((*big.Int)(nil)).Elem()
|
|
||||||
|
|
||||||
// ReadASN1Integer decodes an ASN.1 INTEGER into out and advances. If out does
|
// ReadASN1Integer decodes an ASN.1 INTEGER into out and advances. If out does
|
||||||
// not point to an integer or to a big.Int, it panics. It reports whether the
|
// not point to an integer, to a big.Int, or to a []byte it panics. Only
|
||||||
// read was successful.
|
// positive and zero values can be decoded into []byte, and they are returned as
|
||||||
|
// big-endian binary values that share memory with s. Positive values will have
|
||||||
|
// no leading zeroes, and zero will be returned as a single zero byte.
|
||||||
|
// ReadASN1Integer reports whether the read was successful.
|
||||||
func (s *String) ReadASN1Integer(out interface{}) bool {
|
func (s *String) ReadASN1Integer(out interface{}) bool {
|
||||||
if reflect.TypeOf(out).Kind() != reflect.Ptr {
|
switch out := out.(type) {
|
||||||
panic("out is not a pointer")
|
case *int, *int8, *int16, *int32, *int64:
|
||||||
}
|
|
||||||
switch reflect.ValueOf(out).Elem().Kind() {
|
|
||||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
|
||||||
var i int64
|
var i int64
|
||||||
if !s.readASN1Int64(&i) || reflect.ValueOf(out).Elem().OverflowInt(i) {
|
if !s.readASN1Int64(&i) || reflect.ValueOf(out).Elem().OverflowInt(i) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
reflect.ValueOf(out).Elem().SetInt(i)
|
reflect.ValueOf(out).Elem().SetInt(i)
|
||||||
return true
|
return true
|
||||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
case *uint, *uint8, *uint16, *uint32, *uint64:
|
||||||
var u uint64
|
var u uint64
|
||||||
if !s.readASN1Uint64(&u) || reflect.ValueOf(out).Elem().OverflowUint(u) {
|
if !s.readASN1Uint64(&u) || reflect.ValueOf(out).Elem().OverflowUint(u) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
reflect.ValueOf(out).Elem().SetUint(u)
|
reflect.ValueOf(out).Elem().SetUint(u)
|
||||||
return true
|
return true
|
||||||
case reflect.Struct:
|
case *big.Int:
|
||||||
if reflect.TypeOf(out).Elem() == bigIntType {
|
return s.readASN1BigInt(out)
|
||||||
return s.readASN1BigInt(out.(*big.Int))
|
case *[]byte:
|
||||||
}
|
return s.readASN1Bytes(out)
|
||||||
|
default:
|
||||||
|
panic("out does not point to an integer type")
|
||||||
}
|
}
|
||||||
panic("out does not point to an integer type")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkASN1Integer(bytes []byte) bool {
|
func checkASN1Integer(bytes []byte) bool {
|
||||||
@@ -333,6 +332,21 @@ func (s *String) readASN1BigInt(out *big.Int) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *String) readASN1Bytes(out *[]byte) bool {
|
||||||
|
var bytes String
|
||||||
|
if !s.ReadASN1(&bytes, asn1.INTEGER) || !checkASN1Integer(bytes) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if bytes[0]&0x80 == 0x80 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for len(bytes) > 1 && bytes[0] == 0 {
|
||||||
|
bytes = bytes[1:]
|
||||||
|
}
|
||||||
|
*out = bytes
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func (s *String) readASN1Int64(out *int64) bool {
|
func (s *String) readASN1Int64(out *int64) bool {
|
||||||
var bytes String
|
var bytes String
|
||||||
if !s.ReadASN1(&bytes, asn1.INTEGER) || !checkASN1Integer(bytes) || !asn1Signed(out, bytes) {
|
if !s.ReadASN1(&bytes, asn1.INTEGER) || !checkASN1Integer(bytes) || !asn1Signed(out, bytes) {
|
||||||
@@ -532,7 +546,7 @@ func (s *String) ReadASN1BitString(out *encoding_asn1.BitString) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
paddingBits := uint8(bytes[0])
|
paddingBits := bytes[0]
|
||||||
bytes = bytes[1:]
|
bytes = bytes[1:]
|
||||||
if paddingBits > 7 ||
|
if paddingBits > 7 ||
|
||||||
len(bytes) == 0 && paddingBits != 0 ||
|
len(bytes) == 0 && paddingBits != 0 ||
|
||||||
@@ -554,7 +568,7 @@ func (s *String) ReadASN1BitStringAsBytes(out *[]byte) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
paddingBits := uint8(bytes[0])
|
paddingBits := bytes[0]
|
||||||
if paddingBits != 0 {
|
if paddingBits != 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -654,34 +668,27 @@ func (s *String) SkipOptionalASN1(tag asn1.Tag) bool {
|
|||||||
return s.ReadASN1(&unused, tag)
|
return s.ReadASN1(&unused, tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadOptionalASN1Integer attempts to read an optional ASN.1 INTEGER
|
// ReadOptionalASN1Integer attempts to read an optional ASN.1 INTEGER explicitly
|
||||||
// explicitly tagged with tag into out and advances. If no element with a
|
// tagged with tag into out and advances. If no element with a matching tag is
|
||||||
// matching tag is present, it writes defaultValue into out instead. If out
|
// present, it writes defaultValue into out instead. Otherwise, it behaves like
|
||||||
// does not point to an integer or to a big.Int, it panics. It reports
|
// ReadASN1Integer.
|
||||||
// whether the read was successful.
|
|
||||||
func (s *String) ReadOptionalASN1Integer(out interface{}, tag asn1.Tag, defaultValue interface{}) bool {
|
func (s *String) ReadOptionalASN1Integer(out interface{}, tag asn1.Tag, defaultValue interface{}) bool {
|
||||||
if reflect.TypeOf(out).Kind() != reflect.Ptr {
|
|
||||||
panic("out is not a pointer")
|
|
||||||
}
|
|
||||||
var present bool
|
var present bool
|
||||||
var i String
|
var i String
|
||||||
if !s.ReadOptionalASN1(&i, &present, tag) {
|
if !s.ReadOptionalASN1(&i, &present, tag) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if !present {
|
if !present {
|
||||||
switch reflect.ValueOf(out).Elem().Kind() {
|
switch out.(type) {
|
||||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
case *int, *int8, *int16, *int32, *int64,
|
||||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
*uint, *uint8, *uint16, *uint32, *uint64, *[]byte:
|
||||||
reflect.ValueOf(out).Elem().Set(reflect.ValueOf(defaultValue))
|
reflect.ValueOf(out).Elem().Set(reflect.ValueOf(defaultValue))
|
||||||
case reflect.Struct:
|
case *big.Int:
|
||||||
if reflect.TypeOf(out).Elem() != bigIntType {
|
if defaultValue, ok := defaultValue.(*big.Int); ok {
|
||||||
panic("invalid integer type")
|
out.(*big.Int).Set(defaultValue)
|
||||||
}
|
} else {
|
||||||
if reflect.TypeOf(defaultValue).Kind() != reflect.Ptr ||
|
|
||||||
reflect.TypeOf(defaultValue).Elem() != bigIntType {
|
|
||||||
panic("out points to big.Int, but defaultValue does not")
|
panic("out points to big.Int, but defaultValue does not")
|
||||||
}
|
}
|
||||||
out.(*big.Int).Set(defaultValue.(*big.Int))
|
|
||||||
default:
|
default:
|
||||||
panic("invalid integer type")
|
panic("invalid integer type")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,6 +154,32 @@ func TestReadASN1IntegerSigned(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Repeat the same cases, reading into a []byte.
|
||||||
|
t.Run("bytes", func(t *testing.T) {
|
||||||
|
for i, test := range testData64 {
|
||||||
|
in := String(test.in)
|
||||||
|
var out []byte
|
||||||
|
ok := in.ReadASN1Integer(&out)
|
||||||
|
if test.out < 0 {
|
||||||
|
if ok {
|
||||||
|
t.Errorf("#%d: in.ReadASN1Integer(%d) = %v, want false", i, test.out, ok)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
t.Errorf("#%d: in.ReadASN1Integer() = %v, want true", i, ok)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
n := new(big.Int).SetBytes(out).Int64()
|
||||||
|
if n != test.out {
|
||||||
|
t.Errorf("#%d: in.ReadASN1Integer() = %v, want true; out = %x, want %d", i, ok, out, test.out)
|
||||||
|
}
|
||||||
|
if out[0] == 0 && len(out) > 1 {
|
||||||
|
t.Errorf("#%d: in.ReadASN1Integer() = %v; out = %x, has leading zeroes", i, ok, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Repeat with the implicit-tagging functions
|
// Repeat with the implicit-tagging functions
|
||||||
t.Run("WithTag", func(t *testing.T) {
|
t.Run("WithTag", func(t *testing.T) {
|
||||||
for i, test := range testData64 {
|
for i, test := range testData64 {
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ func TestECDHStdLib(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
shared := decodeHex(tt.Shared)
|
shared := decodeHex(tt.Shared)
|
||||||
x, err := curve.ECDH(priv, pub)
|
x, err := priv.ECDH(pub)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if tg.Curve == "curve25519" && !shouldPass {
|
if tg.Curve == "curve25519" && !shouldPass {
|
||||||
// ECDH is expected to only return an error when using X25519,
|
// ECDH is expected to only return an error when using X25519,
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ func (r *openpgpReader) Read(p []byte) (n int, err error) {
|
|||||||
n, err = r.b64Reader.Read(p)
|
n, err = r.b64Reader.Read(p)
|
||||||
r.currentCRC = crc24(r.currentCRC, p[:n])
|
r.currentCRC = crc24(r.currentCRC, p[:n])
|
||||||
|
|
||||||
if err == io.EOF && r.lReader.crcSet && r.lReader.crc != uint32(r.currentCRC&crc24Mask) {
|
if err == io.EOF && r.lReader.crcSet && r.lReader.crc != r.currentCRC&crc24Mask {
|
||||||
return 0, ArmorCorrupt
|
return 0, ArmorCorrupt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -132,9 +132,7 @@ func TestClientAuthPublicKey(t *testing.T) {
|
|||||||
if err := tryAuth(t, config); err != nil {
|
if err := tryAuth(t, config); err != nil {
|
||||||
t.Fatalf("unable to dial remote side: %s", err)
|
t.Fatalf("unable to dial remote side: %s", err)
|
||||||
}
|
}
|
||||||
// Once the server implements the server-sig-algs extension, this will turn
|
if len(signer.used) != 1 || signer.used[0] != KeyAlgoRSASHA256 {
|
||||||
// into KeyAlgoRSASHA256.
|
|
||||||
if len(signer.used) != 1 || signer.used[0] != KeyAlgoRSA {
|
|
||||||
t.Errorf("unexpected Sign/SignWithAlgorithm calls: %q", signer.used)
|
t.Errorf("unexpected Sign/SignWithAlgorithm calls: %q", signer.used)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
_ "crypto/sha1"
|
_ "crypto/sha1"
|
||||||
@@ -118,6 +119,20 @@ func algorithmsForKeyFormat(keyFormat string) []string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// it supports the server-sig-algs extension. Order is irrelevant.
|
||||||
|
var supportedPubKeyAuthAlgos = []string{
|
||||||
|
KeyAlgoED25519,
|
||||||
|
KeyAlgoSKED25519, KeyAlgoSKECDSA256,
|
||||||
|
KeyAlgoECDSA256, KeyAlgoECDSA384, KeyAlgoECDSA521,
|
||||||
|
KeyAlgoRSASHA256, KeyAlgoRSASHA512, KeyAlgoRSA,
|
||||||
|
KeyAlgoDSA,
|
||||||
|
}
|
||||||
|
|
||||||
|
var supportedPubKeyAuthAlgosList = strings.Join(supportedPubKeyAuthAlgos, ",")
|
||||||
|
|
||||||
// unexpectedMessageError results when the SSH message that we received didn't
|
// unexpectedMessageError results when the SSH message that we received didn't
|
||||||
// match what we wanted.
|
// match what we wanted.
|
||||||
func unexpectedMessageError(expected, got uint8) error {
|
func unexpectedMessageError(expected, got uint8) error {
|
||||||
|
|||||||
+20
-1
@@ -615,7 +615,8 @@ func (t *handshakeTransport) enterKeyExchange(otherInitPacket []byte) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if t.sessionID == nil {
|
firstKeyExchange := t.sessionID == nil
|
||||||
|
if firstKeyExchange {
|
||||||
t.sessionID = result.H
|
t.sessionID = result.H
|
||||||
}
|
}
|
||||||
result.SessionID = t.sessionID
|
result.SessionID = t.sessionID
|
||||||
@@ -626,6 +627,24 @@ func (t *handshakeTransport) enterKeyExchange(otherInitPacket []byte) error {
|
|||||||
if err = t.conn.writePacket([]byte{msgNewKeys}); err != nil {
|
if err = t.conn.writePacket([]byte{msgNewKeys}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// On the server side, after the first SSH_MSG_NEWKEYS, send a SSH_MSG_EXT_INFO
|
||||||
|
// message with the server-sig-algs extension if the client supports it. See
|
||||||
|
// RFC 8308, Sections 2.4 and 3.1.
|
||||||
|
if !isClient && firstKeyExchange && contains(clientInit.KexAlgos, "ext-info-c") {
|
||||||
|
extInfo := &extInfoMsg{
|
||||||
|
NumExtensions: 1,
|
||||||
|
Payload: make([]byte, 0, 4+15+4+len(supportedPubKeyAuthAlgosList)),
|
||||||
|
}
|
||||||
|
extInfo.Payload = appendInt(extInfo.Payload, len("server-sig-algs"))
|
||||||
|
extInfo.Payload = append(extInfo.Payload, "server-sig-algs"...)
|
||||||
|
extInfo.Payload = appendInt(extInfo.Payload, len(supportedPubKeyAuthAlgosList))
|
||||||
|
extInfo.Payload = append(extInfo.Payload, supportedPubKeyAuthAlgosList...)
|
||||||
|
if err := t.conn.writePacket(Marshal(extInfo)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if packet, err := t.conn.readPacket(); err != nil {
|
if packet, err := t.conn.readPacket(); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if packet[0] != msgNewKeys {
|
} else if packet[0] != msgNewKeys {
|
||||||
|
|||||||
+2
-11
@@ -291,15 +291,6 @@ func (s *connection) serverHandshake(config *ServerConfig) (*Permissions, error)
|
|||||||
return perms, err
|
return perms, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func isAcceptableAlgo(algo string) bool {
|
|
||||||
switch algo {
|
|
||||||
case KeyAlgoRSA, KeyAlgoRSASHA256, KeyAlgoRSASHA512, KeyAlgoDSA, KeyAlgoECDSA256, KeyAlgoECDSA384, KeyAlgoECDSA521, KeyAlgoSKECDSA256, KeyAlgoED25519, KeyAlgoSKED25519,
|
|
||||||
CertAlgoRSAv01, CertAlgoDSAv01, CertAlgoECDSA256v01, CertAlgoECDSA384v01, CertAlgoECDSA521v01, CertAlgoSKECDSA256v01, CertAlgoED25519v01, CertAlgoSKED25519v01:
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func checkSourceAddress(addr net.Addr, sourceAddrs string) error {
|
func checkSourceAddress(addr net.Addr, sourceAddrs string) error {
|
||||||
if addr == nil {
|
if addr == nil {
|
||||||
return errors.New("ssh: no address known for client, but source-address match required")
|
return errors.New("ssh: no address known for client, but source-address match required")
|
||||||
@@ -514,7 +505,7 @@ userAuthLoop:
|
|||||||
return nil, parseError(msgUserAuthRequest)
|
return nil, parseError(msgUserAuthRequest)
|
||||||
}
|
}
|
||||||
algo := string(algoBytes)
|
algo := string(algoBytes)
|
||||||
if !isAcceptableAlgo(algo) {
|
if !contains(supportedPubKeyAuthAlgos, underlyingAlgo(algo)) {
|
||||||
authErr = fmt.Errorf("ssh: algorithm %q not accepted", algo)
|
authErr = fmt.Errorf("ssh: algorithm %q not accepted", algo)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -572,7 +563,7 @@ userAuthLoop:
|
|||||||
// algorithm name that corresponds to algo with
|
// algorithm name that corresponds to algo with
|
||||||
// sig.Format. This is usually the same, but
|
// sig.Format. This is usually the same, but
|
||||||
// for certs, the names differ.
|
// for certs, the names differ.
|
||||||
if !isAcceptableAlgo(sig.Format) {
|
if !contains(supportedPubKeyAuthAlgos, sig.Format) {
|
||||||
authErr = fmt.Errorf("ssh: algorithm %q not accepted", sig.Format)
|
authErr = fmt.Errorf("ssh: algorithm %q not accepted", sig.Format)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user