Bump golang.org/x/crypto
Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.0.0-20220411220226-7b82a4e95df4 to 0.17.0. - [Commits](https://github.com/golang/crypto/commits/v0.17.0) --- updated-dependencies: - dependency-name: golang.org/x/crypto dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]>
This commit is contained in:
@@ -31,9 +31,9 @@ require (
|
|||||||
github.com/sergi/go-diff v1.2.0 // indirect
|
github.com/sergi/go-diff v1.2.0 // indirect
|
||||||
github.com/spf13/pflag v1.0.5 // indirect
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
github.com/xanzy/ssh-agent v0.3.1 // indirect
|
github.com/xanzy/ssh-agent v0.3.1 // indirect
|
||||||
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
|
golang.org/x/crypto v0.17.0 // indirect
|
||||||
golang.org/x/net v0.7.0 // indirect
|
golang.org/x/net v0.10.0 // indirect
|
||||||
golang.org/x/sys v0.5.0 // indirect
|
golang.org/x/sys v0.15.0 // indirect
|
||||||
google.golang.org/appengine v1.6.7 // indirect
|
google.golang.org/appengine v1.6.7 // indirect
|
||||||
google.golang.org/protobuf v1.28.0 // indirect
|
google.golang.org/protobuf v1.28.0 // indirect
|
||||||
gopkg.in/warnings.v0 v0.1.2 // indirect
|
gopkg.in/warnings.v0 v0.1.2 // indirect
|
||||||
|
|||||||
@@ -210,8 +210,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
|
|||||||
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
||||||
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
||||||
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 h1:kUhD7nTDoI3fVd9G4ORWrbV5NY0liEs/Jg2pv5f+bBA=
|
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
|
||||||
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
|
||||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||||
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
||||||
@@ -271,8 +271,8 @@ golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81R
|
|||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
golang.org/x/net v0.0.0-20210326060303-6b1517762897/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k=
|
golang.org/x/net v0.0.0-20210326060303-6b1517762897/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k=
|
||||||
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||||
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
|
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
|
||||||
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
@@ -324,20 +324,20 @@ golang.org/x/sys v0.0.0-20210502180810-71e4cd670f79/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
|
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
|
||||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY=
|
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
|
||||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
|
||||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
|
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
|
|||||||
-3
@@ -1,3 +0,0 @@
|
|||||||
# This source code refers to The Go Authors for copyright purposes.
|
|
||||||
# The master list of authors is in the main Go distribution,
|
|
||||||
# visible at https://tip.golang.org/AUTHORS.
|
|
||||||
-3
@@ -1,3 +0,0 @@
|
|||||||
# This source code was written by the Go contributors.
|
|
||||||
# The master list of contributors is in the main Go distribution,
|
|
||||||
# visible at https://tip.golang.org/CONTRIBUTORS.
|
|
||||||
+7
-4
@@ -13,7 +13,10 @@
|
|||||||
// golang.org/x/crypto/chacha20poly1305).
|
// golang.org/x/crypto/chacha20poly1305).
|
||||||
package cast5 // import "golang.org/x/crypto/cast5"
|
package cast5 // import "golang.org/x/crypto/cast5"
|
||||||
|
|
||||||
import "errors"
|
import (
|
||||||
|
"errors"
|
||||||
|
"math/bits"
|
||||||
|
)
|
||||||
|
|
||||||
const BlockSize = 8
|
const BlockSize = 8
|
||||||
const KeySize = 16
|
const KeySize = 16
|
||||||
@@ -241,19 +244,19 @@ func (c *Cipher) keySchedule(in []byte) {
|
|||||||
// These are the three 'f' functions. See RFC 2144, section 2.2.
|
// These are the three 'f' functions. See RFC 2144, section 2.2.
|
||||||
func f1(d, m uint32, r uint8) uint32 {
|
func f1(d, m uint32, r uint8) uint32 {
|
||||||
t := m + d
|
t := m + d
|
||||||
I := (t << r) | (t >> (32 - r))
|
I := bits.RotateLeft32(t, int(r))
|
||||||
return ((sBox[0][I>>24] ^ sBox[1][(I>>16)&0xff]) - sBox[2][(I>>8)&0xff]) + sBox[3][I&0xff]
|
return ((sBox[0][I>>24] ^ sBox[1][(I>>16)&0xff]) - sBox[2][(I>>8)&0xff]) + sBox[3][I&0xff]
|
||||||
}
|
}
|
||||||
|
|
||||||
func f2(d, m uint32, r uint8) uint32 {
|
func f2(d, m uint32, r uint8) uint32 {
|
||||||
t := m ^ d
|
t := m ^ d
|
||||||
I := (t << r) | (t >> (32 - r))
|
I := bits.RotateLeft32(t, int(r))
|
||||||
return ((sBox[0][I>>24] - sBox[1][(I>>16)&0xff]) + sBox[2][(I>>8)&0xff]) ^ sBox[3][I&0xff]
|
return ((sBox[0][I>>24] - sBox[1][(I>>16)&0xff]) + sBox[2][(I>>8)&0xff]) ^ sBox[3][I&0xff]
|
||||||
}
|
}
|
||||||
|
|
||||||
func f3(d, m uint32, r uint8) uint32 {
|
func f3(d, m uint32, r uint8) uint32 {
|
||||||
t := m - d
|
t := m - d
|
||||||
I := (t << r) | (t >> (32 - r))
|
I := bits.RotateLeft32(t, int(r))
|
||||||
return ((sBox[0][I>>24] + sBox[1][(I>>16)&0xff]) ^ sBox[2][(I>>8)&0xff]) - sBox[3][I&0xff]
|
return ((sBox[0][I>>24] + sBox[1][(I>>16)&0xff]) ^ sBox[2][(I>>8)&0xff]) - sBox[3][I&0xff]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -2,8 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build go1.11 && gc && !purego
|
//go:build gc && !purego
|
||||||
// +build go1.11,gc,!purego
|
|
||||||
|
|
||||||
package chacha20
|
package chacha20
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -2,8 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build go1.11 && gc && !purego
|
//go:build gc && !purego
|
||||||
// +build go1.11,gc,!purego
|
|
||||||
|
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -12,7 +12,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"math/bits"
|
"math/bits"
|
||||||
|
|
||||||
"golang.org/x/crypto/internal/subtle"
|
"golang.org/x/crypto/internal/alias"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -189,7 +189,7 @@ func (s *Cipher) XORKeyStream(dst, src []byte) {
|
|||||||
panic("chacha20: output smaller than input")
|
panic("chacha20: output smaller than input")
|
||||||
}
|
}
|
||||||
dst = dst[:len(src)]
|
dst = dst[:len(src)]
|
||||||
if subtle.InexactOverlap(dst, src) {
|
if alias.InexactOverlap(dst, src) {
|
||||||
panic("chacha20: invalid buffer overlap")
|
panic("chacha20: invalid buffer overlap")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -2,8 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build (!arm64 && !s390x && !ppc64le) || (arm64 && !go1.11) || !gc || purego
|
//go:build (!arm64 && !s390x && !ppc64le) || !gc || purego
|
||||||
// +build !arm64,!s390x,!ppc64le arm64,!go1.11 !gc purego
|
|
||||||
|
|
||||||
package chacha20
|
package chacha20
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build gc && !purego
|
//go:build gc && !purego
|
||||||
// +build gc,!purego
|
|
||||||
|
|
||||||
package chacha20
|
package chacha20
|
||||||
|
|
||||||
|
|||||||
-1
@@ -20,7 +20,6 @@
|
|||||||
// due to the calling conventions and initialization of constants.
|
// due to the calling conventions and initialization of constants.
|
||||||
|
|
||||||
//go:build gc && !purego
|
//go:build gc && !purego
|
||||||
// +build gc,!purego
|
|
||||||
|
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build gc && !purego
|
//go:build gc && !purego
|
||||||
// +build gc,!purego
|
|
||||||
|
|
||||||
package chacha20
|
package chacha20
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build gc && !purego
|
//go:build gc && !purego
|
||||||
// +build gc,!purego
|
|
||||||
|
|
||||||
#include "go_asm.h"
|
#include "go_asm.h"
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
|
|||||||
+6
-92
@@ -5,70 +5,18 @@
|
|||||||
// Package curve25519 provides an implementation of the X25519 function, which
|
// Package curve25519 provides an implementation of the X25519 function, which
|
||||||
// performs scalar multiplication on the elliptic curve known as Curve25519.
|
// performs scalar multiplication on the elliptic curve known as Curve25519.
|
||||||
// See RFC 7748.
|
// See RFC 7748.
|
||||||
|
//
|
||||||
|
// Starting in Go 1.20, this package is a wrapper for the X25519 implementation
|
||||||
|
// in the crypto/ecdh package.
|
||||||
package curve25519 // import "golang.org/x/crypto/curve25519"
|
package curve25519 // import "golang.org/x/crypto/curve25519"
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/subtle"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"golang.org/x/crypto/curve25519/internal/field"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ScalarMult sets dst to the product scalar * point.
|
// ScalarMult sets dst to the product scalar * point.
|
||||||
//
|
//
|
||||||
// Deprecated: when provided a low-order point, ScalarMult will set dst to all
|
// Deprecated: when provided a low-order point, ScalarMult will set dst to all
|
||||||
// zeroes, irrespective of the scalar. Instead, use the X25519 function, which
|
// zeroes, irrespective of the scalar. Instead, use the X25519 function, which
|
||||||
// will return an error.
|
// will return an error.
|
||||||
func ScalarMult(dst, scalar, point *[32]byte) {
|
func ScalarMult(dst, scalar, point *[32]byte) {
|
||||||
var e [32]byte
|
scalarMult(dst, scalar, point)
|
||||||
|
|
||||||
copy(e[:], scalar[:])
|
|
||||||
e[0] &= 248
|
|
||||||
e[31] &= 127
|
|
||||||
e[31] |= 64
|
|
||||||
|
|
||||||
var x1, x2, z2, x3, z3, tmp0, tmp1 field.Element
|
|
||||||
x1.SetBytes(point[:])
|
|
||||||
x2.One()
|
|
||||||
x3.Set(&x1)
|
|
||||||
z3.One()
|
|
||||||
|
|
||||||
swap := 0
|
|
||||||
for pos := 254; pos >= 0; pos-- {
|
|
||||||
b := e[pos/8] >> uint(pos&7)
|
|
||||||
b &= 1
|
|
||||||
swap ^= int(b)
|
|
||||||
x2.Swap(&x3, swap)
|
|
||||||
z2.Swap(&z3, swap)
|
|
||||||
swap = int(b)
|
|
||||||
|
|
||||||
tmp0.Subtract(&x3, &z3)
|
|
||||||
tmp1.Subtract(&x2, &z2)
|
|
||||||
x2.Add(&x2, &z2)
|
|
||||||
z2.Add(&x3, &z3)
|
|
||||||
z3.Multiply(&tmp0, &x2)
|
|
||||||
z2.Multiply(&z2, &tmp1)
|
|
||||||
tmp0.Square(&tmp1)
|
|
||||||
tmp1.Square(&x2)
|
|
||||||
x3.Add(&z3, &z2)
|
|
||||||
z2.Subtract(&z3, &z2)
|
|
||||||
x2.Multiply(&tmp1, &tmp0)
|
|
||||||
tmp1.Subtract(&tmp1, &tmp0)
|
|
||||||
z2.Square(&z2)
|
|
||||||
|
|
||||||
z3.Mult32(&tmp1, 121666)
|
|
||||||
x3.Square(&x3)
|
|
||||||
tmp0.Add(&tmp0, &z3)
|
|
||||||
z3.Multiply(&x1, &z2)
|
|
||||||
z2.Multiply(&tmp1, &tmp0)
|
|
||||||
}
|
|
||||||
|
|
||||||
x2.Swap(&x3, swap)
|
|
||||||
z2.Swap(&z3, swap)
|
|
||||||
|
|
||||||
z2.Invert(&z2)
|
|
||||||
x2.Multiply(&x2, &z2)
|
|
||||||
copy(dst[:], x2.Bytes())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScalarBaseMult sets dst to the product scalar * base where base is the
|
// ScalarBaseMult sets dst to the product scalar * base where base is the
|
||||||
@@ -77,7 +25,7 @@ func ScalarMult(dst, scalar, point *[32]byte) {
|
|||||||
// It is recommended to use the X25519 function with Basepoint instead, as
|
// It is recommended to use the X25519 function with Basepoint instead, as
|
||||||
// copying into fixed size arrays can lead to unexpected bugs.
|
// copying into fixed size arrays can lead to unexpected bugs.
|
||||||
func ScalarBaseMult(dst, scalar *[32]byte) {
|
func ScalarBaseMult(dst, scalar *[32]byte) {
|
||||||
ScalarMult(dst, scalar, &basePoint)
|
scalarBaseMult(dst, scalar)
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -90,21 +38,10 @@ const (
|
|||||||
// Basepoint is the canonical Curve25519 generator.
|
// Basepoint is the canonical Curve25519 generator.
|
||||||
var Basepoint []byte
|
var Basepoint []byte
|
||||||
|
|
||||||
var basePoint = [32]byte{9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
var basePoint = [32]byte{9}
|
||||||
|
|
||||||
func init() { Basepoint = basePoint[:] }
|
func init() { Basepoint = basePoint[:] }
|
||||||
|
|
||||||
func checkBasepoint() {
|
|
||||||
if subtle.ConstantTimeCompare(Basepoint, []byte{
|
|
||||||
0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
}) != 1 {
|
|
||||||
panic("curve25519: global Basepoint value was modified")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// X25519 returns the result of the scalar multiplication (scalar * point),
|
// X25519 returns the result of the scalar multiplication (scalar * point),
|
||||||
// according to RFC 7748, Section 5. scalar, point and the return value are
|
// according to RFC 7748, Section 5. scalar, point and the return value are
|
||||||
// slices of 32 bytes.
|
// slices of 32 bytes.
|
||||||
@@ -120,26 +57,3 @@ func X25519(scalar, point []byte) ([]byte, error) {
|
|||||||
var dst [32]byte
|
var dst [32]byte
|
||||||
return x25519(&dst, scalar, point)
|
return x25519(&dst, scalar, point)
|
||||||
}
|
}
|
||||||
|
|
||||||
func x25519(dst *[32]byte, scalar, point []byte) ([]byte, error) {
|
|
||||||
var in [32]byte
|
|
||||||
if l := len(scalar); l != 32 {
|
|
||||||
return nil, fmt.Errorf("bad scalar length: %d, expected %d", l, 32)
|
|
||||||
}
|
|
||||||
if l := len(point); l != 32 {
|
|
||||||
return nil, fmt.Errorf("bad point length: %d, expected %d", l, 32)
|
|
||||||
}
|
|
||||||
copy(in[:], scalar)
|
|
||||||
if &point[0] == &Basepoint[0] {
|
|
||||||
checkBasepoint()
|
|
||||||
ScalarBaseMult(dst, &in)
|
|
||||||
} else {
|
|
||||||
var base, zero [32]byte
|
|
||||||
copy(base[:], point)
|
|
||||||
ScalarMult(dst, &in, &base)
|
|
||||||
if subtle.ConstantTimeCompare(dst[:], zero[:]) == 1 {
|
|
||||||
return nil, fmt.Errorf("bad input point: low order point")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return dst[:], nil
|
|
||||||
}
|
|
||||||
|
|||||||
+105
@@ -0,0 +1,105 @@
|
|||||||
|
// Copyright 2019 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.
|
||||||
|
|
||||||
|
//go:build !go1.20
|
||||||
|
|
||||||
|
package curve25519
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/subtle"
|
||||||
|
"errors"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"golang.org/x/crypto/curve25519/internal/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
func scalarMult(dst, scalar, point *[32]byte) {
|
||||||
|
var e [32]byte
|
||||||
|
|
||||||
|
copy(e[:], scalar[:])
|
||||||
|
e[0] &= 248
|
||||||
|
e[31] &= 127
|
||||||
|
e[31] |= 64
|
||||||
|
|
||||||
|
var x1, x2, z2, x3, z3, tmp0, tmp1 field.Element
|
||||||
|
x1.SetBytes(point[:])
|
||||||
|
x2.One()
|
||||||
|
x3.Set(&x1)
|
||||||
|
z3.One()
|
||||||
|
|
||||||
|
swap := 0
|
||||||
|
for pos := 254; pos >= 0; pos-- {
|
||||||
|
b := e[pos/8] >> uint(pos&7)
|
||||||
|
b &= 1
|
||||||
|
swap ^= int(b)
|
||||||
|
x2.Swap(&x3, swap)
|
||||||
|
z2.Swap(&z3, swap)
|
||||||
|
swap = int(b)
|
||||||
|
|
||||||
|
tmp0.Subtract(&x3, &z3)
|
||||||
|
tmp1.Subtract(&x2, &z2)
|
||||||
|
x2.Add(&x2, &z2)
|
||||||
|
z2.Add(&x3, &z3)
|
||||||
|
z3.Multiply(&tmp0, &x2)
|
||||||
|
z2.Multiply(&z2, &tmp1)
|
||||||
|
tmp0.Square(&tmp1)
|
||||||
|
tmp1.Square(&x2)
|
||||||
|
x3.Add(&z3, &z2)
|
||||||
|
z2.Subtract(&z3, &z2)
|
||||||
|
x2.Multiply(&tmp1, &tmp0)
|
||||||
|
tmp1.Subtract(&tmp1, &tmp0)
|
||||||
|
z2.Square(&z2)
|
||||||
|
|
||||||
|
z3.Mult32(&tmp1, 121666)
|
||||||
|
x3.Square(&x3)
|
||||||
|
tmp0.Add(&tmp0, &z3)
|
||||||
|
z3.Multiply(&x1, &z2)
|
||||||
|
z2.Multiply(&tmp1, &tmp0)
|
||||||
|
}
|
||||||
|
|
||||||
|
x2.Swap(&x3, swap)
|
||||||
|
z2.Swap(&z3, swap)
|
||||||
|
|
||||||
|
z2.Invert(&z2)
|
||||||
|
x2.Multiply(&x2, &z2)
|
||||||
|
copy(dst[:], x2.Bytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
func scalarBaseMult(dst, scalar *[32]byte) {
|
||||||
|
checkBasepoint()
|
||||||
|
scalarMult(dst, scalar, &basePoint)
|
||||||
|
}
|
||||||
|
|
||||||
|
func x25519(dst *[32]byte, scalar, point []byte) ([]byte, error) {
|
||||||
|
var in [32]byte
|
||||||
|
if l := len(scalar); l != 32 {
|
||||||
|
return nil, errors.New("bad scalar length: " + strconv.Itoa(l) + ", expected 32")
|
||||||
|
}
|
||||||
|
if l := len(point); l != 32 {
|
||||||
|
return nil, errors.New("bad point length: " + strconv.Itoa(l) + ", expected 32")
|
||||||
|
}
|
||||||
|
copy(in[:], scalar)
|
||||||
|
if &point[0] == &Basepoint[0] {
|
||||||
|
scalarBaseMult(dst, &in)
|
||||||
|
} else {
|
||||||
|
var base, zero [32]byte
|
||||||
|
copy(base[:], point)
|
||||||
|
scalarMult(dst, &in, &base)
|
||||||
|
if subtle.ConstantTimeCompare(dst[:], zero[:]) == 1 {
|
||||||
|
return nil, errors.New("bad input point: low order point")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dst[:], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkBasepoint() {
|
||||||
|
if subtle.ConstantTimeCompare(Basepoint, []byte{
|
||||||
|
0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
}) != 1 {
|
||||||
|
panic("curve25519: global Basepoint value was modified")
|
||||||
|
}
|
||||||
|
}
|
||||||
+46
@@ -0,0 +1,46 @@
|
|||||||
|
// Copyright 2022 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.
|
||||||
|
|
||||||
|
//go:build go1.20
|
||||||
|
|
||||||
|
package curve25519
|
||||||
|
|
||||||
|
import "crypto/ecdh"
|
||||||
|
|
||||||
|
func x25519(dst *[32]byte, scalar, point []byte) ([]byte, error) {
|
||||||
|
curve := ecdh.X25519()
|
||||||
|
pub, err := curve.NewPublicKey(point)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
priv, err := curve.NewPrivateKey(scalar)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
out, err := priv.ECDH(pub)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
copy(dst[:], out)
|
||||||
|
return dst[:], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func scalarMult(dst, scalar, point *[32]byte) {
|
||||||
|
if _, err := x25519(dst, scalar[:], point[:]); err != nil {
|
||||||
|
// The only error condition for x25519 when the inputs are 32 bytes long
|
||||||
|
// is if the output would have been the all-zero value.
|
||||||
|
for i := range dst {
|
||||||
|
dst[i] = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func scalarBaseMult(dst, scalar *[32]byte) {
|
||||||
|
curve := ecdh.X25519()
|
||||||
|
priv, err := curve.NewPrivateKey(scalar[:])
|
||||||
|
if err != nil {
|
||||||
|
panic("curve25519: internal error: scalarBaseMult was not 32 bytes")
|
||||||
|
}
|
||||||
|
copy(dst[:], priv.PublicKey().Bytes())
|
||||||
|
}
|
||||||
-1
@@ -1,7 +1,6 @@
|
|||||||
// Code generated by command: go run fe_amd64_asm.go -out ../fe_amd64.s -stubs ../fe_amd64.go -pkg field. DO NOT EDIT.
|
// Code generated by command: go run fe_amd64_asm.go -out ../fe_amd64.s -stubs ../fe_amd64.go -pkg field. DO NOT EDIT.
|
||||||
|
|
||||||
//go:build amd64 && gc && !purego
|
//go:build amd64 && gc && !purego
|
||||||
// +build amd64,gc,!purego
|
|
||||||
|
|
||||||
package field
|
package field
|
||||||
|
|
||||||
|
|||||||
-1
@@ -1,7 +1,6 @@
|
|||||||
// Code generated by command: go run fe_amd64_asm.go -out ../fe_amd64.s -stubs ../fe_amd64.go -pkg field. DO NOT EDIT.
|
// Code generated by command: go run fe_amd64_asm.go -out ../fe_amd64.s -stubs ../fe_amd64.go -pkg field. DO NOT EDIT.
|
||||||
|
|
||||||
//go:build amd64 && gc && !purego
|
//go:build amd64 && gc && !purego
|
||||||
// +build amd64,gc,!purego
|
|
||||||
|
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build !amd64 || !gc || purego
|
//go:build !amd64 || !gc || purego
|
||||||
// +build !amd64 !gc purego
|
|
||||||
|
|
||||||
package field
|
package field
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build arm64 && gc && !purego
|
//go:build arm64 && gc && !purego
|
||||||
// +build arm64,gc,!purego
|
|
||||||
|
|
||||||
package field
|
package field
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build arm64 && gc && !purego
|
//go:build arm64 && gc && !purego
|
||||||
// +build arm64,gc,!purego
|
|
||||||
|
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build !arm64 || !gc || purego
|
//go:build !arm64 || !gc || purego
|
||||||
// +build !arm64 !gc purego
|
|
||||||
|
|
||||||
package field
|
package field
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -245,7 +245,7 @@ func feSquareGeneric(v, a *Element) {
|
|||||||
v.carryPropagate()
|
v.carryPropagate()
|
||||||
}
|
}
|
||||||
|
|
||||||
// carryPropagate brings the limbs below 52 bits by applying the reduction
|
// carryPropagateGeneric brings the limbs below 52 bits by applying the reduction
|
||||||
// identity (a * 2²⁵⁵ + b = a * 19 + b) to the l4 carry. TODO inline
|
// identity (a * 2²⁵⁵ + b = a * 19 + b) to the l4 carry. TODO inline
|
||||||
func (v *Element) carryPropagateGeneric() *Element {
|
func (v *Element) carryPropagateGeneric() *Element {
|
||||||
c0 := v.l0 >> 51
|
c0 := v.l0 >> 51
|
||||||
|
|||||||
Generated
Vendored
+2
-4
@@ -3,11 +3,9 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build !purego
|
//go:build !purego
|
||||||
// +build !purego
|
|
||||||
|
|
||||||
// Package subtle implements functions that are often useful in cryptographic
|
// Package alias implements memory aliasing tests.
|
||||||
// code but require careful thought to use correctly.
|
package alias
|
||||||
package subtle // import "golang.org/x/crypto/internal/subtle"
|
|
||||||
|
|
||||||
import "unsafe"
|
import "unsafe"
|
||||||
|
|
||||||
Generated
Vendored
+2
-4
@@ -3,11 +3,9 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build purego
|
//go:build purego
|
||||||
// +build purego
|
|
||||||
|
|
||||||
// Package subtle implements functions that are often useful in cryptographic
|
// Package alias implements memory aliasing tests.
|
||||||
// code but require careful thought to use correctly.
|
package alias
|
||||||
package subtle // import "golang.org/x/crypto/internal/subtle"
|
|
||||||
|
|
||||||
// This is the Google App Engine standard variant based on reflect
|
// This is the Google App Engine standard variant based on reflect
|
||||||
// because the unsafe package and cgo are disallowed.
|
// because the unsafe package and cgo are disallowed.
|
||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build !go1.13
|
//go:build !go1.13
|
||||||
// +build !go1.13
|
|
||||||
|
|
||||||
package poly1305
|
package poly1305
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build go1.13
|
//go:build go1.13
|
||||||
// +build go1.13
|
|
||||||
|
|
||||||
package poly1305
|
package poly1305
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build (!amd64 && !ppc64le && !s390x) || !gc || purego
|
//go:build (!amd64 && !ppc64le && !s390x) || !gc || purego
|
||||||
// +build !amd64,!ppc64le,!s390x !gc purego
|
|
||||||
|
|
||||||
package poly1305
|
package poly1305
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build gc && !purego
|
//go:build gc && !purego
|
||||||
// +build gc,!purego
|
|
||||||
|
|
||||||
package poly1305
|
package poly1305
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build gc && !purego
|
//go:build gc && !purego
|
||||||
// +build gc,!purego
|
|
||||||
|
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build gc && !purego
|
//go:build gc && !purego
|
||||||
// +build gc,!purego
|
|
||||||
|
|
||||||
package poly1305
|
package poly1305
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build gc && !purego
|
//go:build gc && !purego
|
||||||
// +build gc,!purego
|
|
||||||
|
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build gc && !purego
|
//go:build gc && !purego
|
||||||
// +build gc,!purego
|
|
||||||
|
|
||||||
package poly1305
|
package poly1305
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build gc && !purego
|
//go:build gc && !purego
|
||||||
// +build gc,!purego
|
|
||||||
|
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -61,7 +61,7 @@ type Key struct {
|
|||||||
type KeyRing interface {
|
type KeyRing interface {
|
||||||
// KeysById returns the set of keys that have the given key id.
|
// KeysById returns the set of keys that have the given key id.
|
||||||
KeysById(id uint64) []Key
|
KeysById(id uint64) []Key
|
||||||
// KeysByIdAndUsage returns the set of keys with the given id
|
// KeysByIdUsage returns the set of keys with the given id
|
||||||
// that also meet the key usage given by requiredUsage.
|
// that also meet the key usage given by requiredUsage.
|
||||||
// The requiredUsage is expressed as the bitwise-OR of
|
// The requiredUsage is expressed as the bitwise-OR of
|
||||||
// packet.KeyFlag* values.
|
// packet.KeyFlag* values.
|
||||||
@@ -183,7 +183,7 @@ func (el EntityList) KeysById(id uint64) (keys []Key) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// KeysByIdAndUsage returns the set of keys with the given id that also meet
|
// KeysByIdUsage returns the set of keys with the given id that also meet
|
||||||
// the key usage given by requiredUsage. The requiredUsage is expressed as
|
// the key usage given by requiredUsage. The requiredUsage is expressed as
|
||||||
// the bitwise-OR of packet.KeyFlag* values.
|
// the bitwise-OR of packet.KeyFlag* values.
|
||||||
func (el EntityList) KeysByIdUsage(id uint64, requiredUsage byte) (keys []Key) {
|
func (el EntityList) KeysByIdUsage(id uint64, requiredUsage byte) (keys []Key) {
|
||||||
|
|||||||
+1
-1
@@ -60,7 +60,7 @@ func (c *Compressed) parse(r io.Reader) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// compressedWriterCloser represents the serialized compression stream
|
// compressedWriteCloser represents the serialized compression stream
|
||||||
// header and the compressor. Its Close() method ensures that both the
|
// header and the compressor. Its Close() method ensures that both the
|
||||||
// compressor and serialized stream header are closed. Its Write()
|
// compressor and serialized stream header are closed. Its Write()
|
||||||
// method writes to the compressor.
|
// method writes to the compressor.
|
||||||
|
|||||||
+1
-2
@@ -7,7 +7,6 @@ package packet
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
|
|
||||||
"golang.org/x/crypto/openpgp/errors"
|
"golang.org/x/crypto/openpgp/errors"
|
||||||
)
|
)
|
||||||
@@ -26,7 +25,7 @@ type OpaquePacket struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (op *OpaquePacket) parse(r io.Reader) (err error) {
|
func (op *OpaquePacket) parse(r io.Reader) (err error) {
|
||||||
op.Contents, err = ioutil.ReadAll(r)
|
op.Contents, err = io.ReadAll(r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -13,7 +13,6 @@ import (
|
|||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
@@ -133,7 +132,7 @@ func (pk *PrivateKey) parse(r io.Reader) (err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pk.encryptedData, err = ioutil.ReadAll(r)
|
pk.encryptedData, err = io.ReadAll(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -236,7 +236,7 @@ func (w *seMDCWriter) Close() (err error) {
|
|||||||
return w.w.Close()
|
return w.w.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// noOpCloser is like an ioutil.NopCloser, but for an io.Writer.
|
// noOpCloser is like an io.NopCloser, but for an io.Writer.
|
||||||
type noOpCloser struct {
|
type noOpCloser struct {
|
||||||
w io.Writer
|
w io.Writer
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -9,7 +9,6 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
"image/jpeg"
|
"image/jpeg"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const UserAttrImageSubpacket = 1
|
const UserAttrImageSubpacket = 1
|
||||||
@@ -56,7 +55,7 @@ func NewUserAttribute(contents ...*OpaqueSubpacket) *UserAttribute {
|
|||||||
|
|
||||||
func (uat *UserAttribute) parse(r io.Reader) (err error) {
|
func (uat *UserAttribute) parse(r io.Reader) (err error) {
|
||||||
// RFC 4880, section 5.13
|
// RFC 4880, section 5.13
|
||||||
b, err := ioutil.ReadAll(r)
|
b, err := io.ReadAll(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -6,7 +6,6 @@ package packet
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -66,7 +65,7 @@ func NewUserId(name, comment, email string) *UserId {
|
|||||||
|
|
||||||
func (uid *UserId) parse(r io.Reader) (err error) {
|
func (uid *UserId) parse(r io.Reader) (err error) {
|
||||||
// RFC 4880, section 5.11
|
// RFC 4880, section 5.11
|
||||||
b, err := ioutil.ReadAll(r)
|
b, err := io.ReadAll(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -268,7 +268,7 @@ func HashIdToString(id byte) (name string, ok bool) {
|
|||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
// HashIdToHash returns an OpenPGP hash id which corresponds the given Hash.
|
// HashToHashId returns an OpenPGP hash id which corresponds the given Hash.
|
||||||
func HashToHashId(h crypto.Hash) (id byte, ok bool) {
|
func HashToHashId(h crypto.Hash) (id byte, ok bool) {
|
||||||
for _, m := range hashToHashIdMapping {
|
for _, m := range hashToHashIdMapping {
|
||||||
if m.hash == h {
|
if m.hash == h {
|
||||||
|
|||||||
+1
-1
@@ -402,7 +402,7 @@ func (s signatureWriter) Close() error {
|
|||||||
return s.encryptedData.Close()
|
return s.encryptedData.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// noOpCloser is like an ioutil.NopCloser, but for an io.Writer.
|
// noOpCloser is like an io.NopCloser, but for an io.Writer.
|
||||||
// TODO: we have two of these in OpenPGP packages alone. This probably needs
|
// TODO: we have two of these in OpenPGP packages alone. This probably needs
|
||||||
// to be promoted somewhere more common.
|
// to be promoted somewhere more common.
|
||||||
type noOpCloser struct {
|
type noOpCloser struct {
|
||||||
|
|||||||
+43
-9
@@ -16,6 +16,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"crypto/dsa"
|
"crypto/dsa"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
|
"crypto/ed25519"
|
||||||
"crypto/elliptic"
|
"crypto/elliptic"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
@@ -26,7 +27,6 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"golang.org/x/crypto/ed25519"
|
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ type ExtendedAgent interface {
|
|||||||
type ConstraintExtension struct {
|
type ConstraintExtension struct {
|
||||||
// ExtensionName consist of a UTF-8 string suffixed by the
|
// ExtensionName consist of a UTF-8 string suffixed by the
|
||||||
// implementation domain following the naming scheme defined
|
// implementation domain following the naming scheme defined
|
||||||
// in Section 4.2 of [RFC4251], e.g. "[email protected]".
|
// in Section 4.2 of RFC 4251, e.g. "[email protected]".
|
||||||
ExtensionName string
|
ExtensionName string
|
||||||
// ExtensionDetails contains the actual content of the extended
|
// ExtensionDetails contains the actual content of the extended
|
||||||
// constraint.
|
// constraint.
|
||||||
@@ -141,9 +141,14 @@ const (
|
|||||||
agentAddSmartcardKeyConstrained = 26
|
agentAddSmartcardKeyConstrained = 26
|
||||||
|
|
||||||
// 3.7 Key constraint identifiers
|
// 3.7 Key constraint identifiers
|
||||||
agentConstrainLifetime = 1
|
agentConstrainLifetime = 1
|
||||||
agentConstrainConfirm = 2
|
agentConstrainConfirm = 2
|
||||||
agentConstrainExtension = 3
|
// 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
|
// maxAgentResponseBytes is the maximum agent reply size that is accepted. This
|
||||||
@@ -205,7 +210,7 @@ type constrainLifetimeAgentMsg struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type constrainExtensionAgentMsg struct {
|
type constrainExtensionAgentMsg struct {
|
||||||
ExtensionName string `sshtype:"3"`
|
ExtensionName string `sshtype:"255|3"`
|
||||||
ExtensionDetails []byte
|
ExtensionDetails []byte
|
||||||
|
|
||||||
// Rest is a field used for parsing, not part of message
|
// Rest is a field used for parsing, not part of message
|
||||||
@@ -226,7 +231,9 @@ var ErrExtensionUnsupported = errors.New("agent: extension unsupported")
|
|||||||
|
|
||||||
type extensionAgentMsg struct {
|
type extensionAgentMsg struct {
|
||||||
ExtensionType string `sshtype:"27"`
|
ExtensionType string `sshtype:"27"`
|
||||||
Contents []byte
|
// NOTE: this matches OpenSSH's PROTOCOL.agent, not the IETF draft [PROTOCOL.agent],
|
||||||
|
// so that it matches what OpenSSH actually implements in the wild.
|
||||||
|
Contents []byte `ssh:"rest"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Key represents a protocol 2 public key as defined in
|
// Key represents a protocol 2 public key as defined in
|
||||||
@@ -729,7 +736,7 @@ func (c *client) insertCert(s interface{}, cert *ssh.Certificate, comment string
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if bytes.Compare(cert.Key.Marshal(), signer.PublicKey().Marshal()) != 0 {
|
if !bytes.Equal(cert.Key.Marshal(), signer.PublicKey().Marshal()) {
|
||||||
return errors.New("agent: signer and cert have different public key")
|
return errors.New("agent: signer and cert have different public key")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -772,7 +779,7 @@ func (s *agentKeyringSigner) Sign(rand io.Reader, data []byte) (*ssh.Signature,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *agentKeyringSigner) SignWithAlgorithm(rand io.Reader, data []byte, algorithm string) (*ssh.Signature, error) {
|
func (s *agentKeyringSigner) SignWithAlgorithm(rand io.Reader, data []byte, algorithm string) (*ssh.Signature, error) {
|
||||||
if algorithm == "" || algorithm == s.pub.Type() {
|
if algorithm == "" || algorithm == underlyingAlgo(s.pub.Type()) {
|
||||||
return s.Sign(rand, data)
|
return s.Sign(rand, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -791,6 +798,33 @@ func (s *agentKeyringSigner) SignWithAlgorithm(rand io.Reader, data []byte, algo
|
|||||||
|
|
||||||
var _ ssh.AlgorithmSigner = &agentKeyringSigner{}
|
var _ ssh.AlgorithmSigner = &agentKeyringSigner{}
|
||||||
|
|
||||||
|
// certKeyAlgoNames is a mapping from known certificate algorithm names to the
|
||||||
|
// corresponding public key signature algorithm.
|
||||||
|
//
|
||||||
|
// This map must be kept in sync with the one in certs.go.
|
||||||
|
var certKeyAlgoNames = map[string]string{
|
||||||
|
ssh.CertAlgoRSAv01: ssh.KeyAlgoRSA,
|
||||||
|
ssh.CertAlgoRSASHA256v01: ssh.KeyAlgoRSASHA256,
|
||||||
|
ssh.CertAlgoRSASHA512v01: ssh.KeyAlgoRSASHA512,
|
||||||
|
ssh.CertAlgoDSAv01: ssh.KeyAlgoDSA,
|
||||||
|
ssh.CertAlgoECDSA256v01: ssh.KeyAlgoECDSA256,
|
||||||
|
ssh.CertAlgoECDSA384v01: ssh.KeyAlgoECDSA384,
|
||||||
|
ssh.CertAlgoECDSA521v01: ssh.KeyAlgoECDSA521,
|
||||||
|
ssh.CertAlgoSKECDSA256v01: ssh.KeyAlgoSKECDSA256,
|
||||||
|
ssh.CertAlgoED25519v01: ssh.KeyAlgoED25519,
|
||||||
|
ssh.CertAlgoSKED25519v01: ssh.KeyAlgoSKED25519,
|
||||||
|
}
|
||||||
|
|
||||||
|
// underlyingAlgo returns the signature algorithm associated with algo (which is
|
||||||
|
// an advertised or negotiated public key or host key algorithm). These are
|
||||||
|
// usually the same, except for certificate algorithms.
|
||||||
|
func underlyingAlgo(algo string) string {
|
||||||
|
if a, ok := certKeyAlgoNames[algo]; ok {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
return algo
|
||||||
|
}
|
||||||
|
|
||||||
// Calls an extension method. It is up to the agent implementation as to whether or not
|
// Calls an extension method. It is up to the agent implementation as to whether or not
|
||||||
// any particular extension is supported and may always return an error. Because the
|
// any particular extension is supported and may always return an error. Because the
|
||||||
// type of the response is up to the implementation, this returns the bytes of the
|
// type of the response is up to the implementation, this returns the bytes of the
|
||||||
|
|||||||
+3
-3
@@ -7,6 +7,7 @@ package agent
|
|||||||
import (
|
import (
|
||||||
"crypto/dsa"
|
"crypto/dsa"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
|
"crypto/ed25519"
|
||||||
"crypto/elliptic"
|
"crypto/elliptic"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
@@ -16,11 +17,10 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"golang.org/x/crypto/ed25519"
|
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server wraps an Agent and uses it to implement the agent side of
|
// server wraps an Agent and uses it to implement the agent side of
|
||||||
// the SSH-agent, wire protocol.
|
// the SSH-agent, wire protocol.
|
||||||
type server struct {
|
type server struct {
|
||||||
agent Agent
|
agent Agent
|
||||||
@@ -208,7 +208,7 @@ func parseConstraints(constraints []byte) (lifetimeSecs uint32, confirmBeforeUse
|
|||||||
case agentConstrainConfirm:
|
case agentConstrainConfirm:
|
||||||
confirmBeforeUse = true
|
confirmBeforeUse = true
|
||||||
constraints = constraints[1:]
|
constraints = constraints[1:]
|
||||||
case agentConstrainExtension:
|
case agentConstrainExtension, agentConstrainExtensionV00:
|
||||||
var msg constrainExtensionAgentMsg
|
var msg constrainExtensionAgentMsg
|
||||||
if err = ssh.Unmarshal(constraints, &msg); err != nil {
|
if err = ssh.Unmarshal(constraints, &msg); err != nil {
|
||||||
return 0, false, nil, err
|
return 0, false, nil, err
|
||||||
|
|||||||
+33
-9
@@ -16,8 +16,9 @@ import (
|
|||||||
|
|
||||||
// Certificate algorithm names from [PROTOCOL.certkeys]. These values can appear
|
// Certificate algorithm names from [PROTOCOL.certkeys]. These values can appear
|
||||||
// in Certificate.Type, PublicKey.Type, and ClientConfig.HostKeyAlgorithms.
|
// in Certificate.Type, PublicKey.Type, and ClientConfig.HostKeyAlgorithms.
|
||||||
// Unlike key algorithm names, these are not passed to AlgorithmSigner and don't
|
// Unlike key algorithm names, these are not passed to AlgorithmSigner nor
|
||||||
// appear in the Signature.Format field.
|
// returned by MultiAlgorithmSigner and don't appear in the Signature.Format
|
||||||
|
// field.
|
||||||
const (
|
const (
|
||||||
CertAlgoRSAv01 = "[email protected]"
|
CertAlgoRSAv01 = "[email protected]"
|
||||||
CertAlgoDSAv01 = "[email protected]"
|
CertAlgoDSAv01 = "[email protected]"
|
||||||
@@ -251,14 +252,21 @@ type algorithmOpenSSHCertSigner struct {
|
|||||||
// private key is held by signer. It returns an error if the public key in cert
|
// private key is held by signer. It returns an error if the public key in cert
|
||||||
// doesn't match the key used by signer.
|
// doesn't match the key used by signer.
|
||||||
func NewCertSigner(cert *Certificate, signer Signer) (Signer, error) {
|
func NewCertSigner(cert *Certificate, signer Signer) (Signer, error) {
|
||||||
if bytes.Compare(cert.Key.Marshal(), signer.PublicKey().Marshal()) != 0 {
|
if !bytes.Equal(cert.Key.Marshal(), signer.PublicKey().Marshal()) {
|
||||||
return nil, errors.New("ssh: signer and cert have different public key")
|
return nil, errors.New("ssh: signer and cert have different public key")
|
||||||
}
|
}
|
||||||
|
|
||||||
if algorithmSigner, ok := signer.(AlgorithmSigner); ok {
|
switch s := signer.(type) {
|
||||||
|
case MultiAlgorithmSigner:
|
||||||
|
return &multiAlgorithmSigner{
|
||||||
|
AlgorithmSigner: &algorithmOpenSSHCertSigner{
|
||||||
|
&openSSHCertSigner{cert, signer}, s},
|
||||||
|
supportedAlgorithms: s.Algorithms(),
|
||||||
|
}, nil
|
||||||
|
case AlgorithmSigner:
|
||||||
return &algorithmOpenSSHCertSigner{
|
return &algorithmOpenSSHCertSigner{
|
||||||
&openSSHCertSigner{cert, signer}, algorithmSigner}, nil
|
&openSSHCertSigner{cert, signer}, s}, nil
|
||||||
} else {
|
default:
|
||||||
return &openSSHCertSigner{cert, signer}, nil
|
return &openSSHCertSigner{cert, signer}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -432,7 +440,9 @@ func (c *CertChecker) CheckCert(principal string, cert *Certificate) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SignCert signs the certificate with an authority, setting the Nonce,
|
// SignCert signs the certificate with an authority, setting the Nonce,
|
||||||
// SignatureKey, and Signature fields.
|
// SignatureKey, and Signature fields. If the authority implements the
|
||||||
|
// MultiAlgorithmSigner interface the first algorithm in the list is used. This
|
||||||
|
// is useful if you want to sign with a specific algorithm.
|
||||||
func (c *Certificate) SignCert(rand io.Reader, authority Signer) error {
|
func (c *Certificate) SignCert(rand io.Reader, authority Signer) error {
|
||||||
c.Nonce = make([]byte, 32)
|
c.Nonce = make([]byte, 32)
|
||||||
if _, err := io.ReadFull(rand, c.Nonce); err != nil {
|
if _, err := io.ReadFull(rand, c.Nonce); err != nil {
|
||||||
@@ -440,8 +450,20 @@ func (c *Certificate) SignCert(rand io.Reader, authority Signer) error {
|
|||||||
}
|
}
|
||||||
c.SignatureKey = authority.PublicKey()
|
c.SignatureKey = authority.PublicKey()
|
||||||
|
|
||||||
// Default to KeyAlgoRSASHA512 for ssh-rsa signers.
|
if v, ok := authority.(MultiAlgorithmSigner); ok {
|
||||||
if v, ok := authority.(AlgorithmSigner); ok && v.PublicKey().Type() == KeyAlgoRSA {
|
if len(v.Algorithms()) == 0 {
|
||||||
|
return errors.New("the provided authority has no signature algorithm")
|
||||||
|
}
|
||||||
|
// Use the first algorithm in the list.
|
||||||
|
sig, err := v.SignWithAlgorithm(rand, c.bytesForSigning(), v.Algorithms()[0])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c.Signature = sig
|
||||||
|
return nil
|
||||||
|
} else if v, ok := authority.(AlgorithmSigner); ok && v.PublicKey().Type() == KeyAlgoRSA {
|
||||||
|
// Default to KeyAlgoRSASHA512 for ssh-rsa signers.
|
||||||
|
// TODO: consider using KeyAlgoRSASHA256 as default.
|
||||||
sig, err := v.SignWithAlgorithm(rand, c.bytesForSigning(), KeyAlgoRSASHA512)
|
sig, err := v.SignWithAlgorithm(rand, c.bytesForSigning(), KeyAlgoRSASHA512)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -460,6 +482,8 @@ func (c *Certificate) SignCert(rand io.Reader, authority Signer) error {
|
|||||||
|
|
||||||
// certKeyAlgoNames is a mapping from known certificate algorithm names to the
|
// certKeyAlgoNames is a mapping from known certificate algorithm names to the
|
||||||
// corresponding public key signature algorithm.
|
// corresponding public key signature algorithm.
|
||||||
|
//
|
||||||
|
// This map must be kept in sync with the one in agent/client.go.
|
||||||
var certKeyAlgoNames = map[string]string{
|
var certKeyAlgoNames = map[string]string{
|
||||||
CertAlgoRSAv01: KeyAlgoRSA,
|
CertAlgoRSAv01: KeyAlgoRSA,
|
||||||
CertAlgoRSASHA256v01: KeyAlgoRSASHA256,
|
CertAlgoRSASHA256v01: KeyAlgoRSASHA256,
|
||||||
|
|||||||
+20
-8
@@ -187,9 +187,11 @@ type channel struct {
|
|||||||
pending *buffer
|
pending *buffer
|
||||||
extPending *buffer
|
extPending *buffer
|
||||||
|
|
||||||
// windowMu protects myWindow, the flow-control window.
|
// windowMu protects myWindow, the flow-control window, and myConsumed,
|
||||||
windowMu sync.Mutex
|
// the number of bytes consumed since we last increased myWindow
|
||||||
myWindow uint32
|
windowMu sync.Mutex
|
||||||
|
myWindow uint32
|
||||||
|
myConsumed uint32
|
||||||
|
|
||||||
// writeMu serializes calls to mux.conn.writePacket() and
|
// writeMu serializes calls to mux.conn.writePacket() and
|
||||||
// protects sentClose and packetPool. This mutex must be
|
// protects sentClose and packetPool. This mutex must be
|
||||||
@@ -332,14 +334,24 @@ func (ch *channel) handleData(packet []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *channel) adjustWindow(n uint32) error {
|
func (c *channel) adjustWindow(adj uint32) error {
|
||||||
c.windowMu.Lock()
|
c.windowMu.Lock()
|
||||||
// Since myWindow is managed on our side, and can never exceed
|
// Since myConsumed and myWindow are managed on our side, and can never
|
||||||
// the initial window setting, we don't worry about overflow.
|
// exceed the initial window setting, we don't worry about overflow.
|
||||||
c.myWindow += uint32(n)
|
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()
|
c.windowMu.Unlock()
|
||||||
|
if sendAdj == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return c.sendMessage(windowAdjustMsg{
|
return c.sendMessage(windowAdjustMsg{
|
||||||
AdditionalBytes: uint32(n),
|
AdditionalBytes: sendAdj,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-7
@@ -15,7 +15,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"hash"
|
"hash"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
|
|
||||||
"golang.org/x/crypto/chacha20"
|
"golang.org/x/crypto/chacha20"
|
||||||
"golang.org/x/crypto/internal/poly1305"
|
"golang.org/x/crypto/internal/poly1305"
|
||||||
@@ -97,13 +96,13 @@ func streamCipherMode(skip int, createFunc func(key, iv []byte) (cipher.Stream,
|
|||||||
// are not supported and will not be negotiated, even if explicitly requested in
|
// are not supported and will not be negotiated, even if explicitly requested in
|
||||||
// ClientConfig.Crypto.Ciphers.
|
// ClientConfig.Crypto.Ciphers.
|
||||||
var cipherModes = map[string]*cipherMode{
|
var cipherModes = map[string]*cipherMode{
|
||||||
// Ciphers from RFC4344, which introduced many CTR-based ciphers. Algorithms
|
// Ciphers from RFC 4344, which introduced many CTR-based ciphers. Algorithms
|
||||||
// are defined in the order specified in the RFC.
|
// are defined in the order specified in the RFC.
|
||||||
"aes128-ctr": {16, aes.BlockSize, streamCipherMode(0, newAESCTR)},
|
"aes128-ctr": {16, aes.BlockSize, streamCipherMode(0, newAESCTR)},
|
||||||
"aes192-ctr": {24, aes.BlockSize, streamCipherMode(0, newAESCTR)},
|
"aes192-ctr": {24, aes.BlockSize, streamCipherMode(0, newAESCTR)},
|
||||||
"aes256-ctr": {32, aes.BlockSize, streamCipherMode(0, newAESCTR)},
|
"aes256-ctr": {32, aes.BlockSize, streamCipherMode(0, newAESCTR)},
|
||||||
|
|
||||||
// Ciphers from RFC4345, which introduces security-improved arcfour ciphers.
|
// Ciphers from RFC 4345, which introduces security-improved arcfour ciphers.
|
||||||
// They are defined in the order specified in the RFC.
|
// They are defined in the order specified in the RFC.
|
||||||
"arcfour128": {16, 0, streamCipherMode(1536, newRC4)},
|
"arcfour128": {16, 0, streamCipherMode(1536, newRC4)},
|
||||||
"arcfour256": {32, 0, streamCipherMode(1536, newRC4)},
|
"arcfour256": {32, 0, streamCipherMode(1536, newRC4)},
|
||||||
@@ -111,11 +110,12 @@ var cipherModes = map[string]*cipherMode{
|
|||||||
// Cipher defined in RFC 4253, which describes SSH Transport Layer Protocol.
|
// Cipher defined in RFC 4253, which describes SSH Transport Layer Protocol.
|
||||||
// Note that this cipher is not safe, as stated in RFC 4253: "Arcfour (and
|
// Note that this cipher is not safe, as stated in RFC 4253: "Arcfour (and
|
||||||
// RC4) has problems with weak keys, and should be used with caution."
|
// RC4) has problems with weak keys, and should be used with caution."
|
||||||
// RFC4345 introduces improved versions of Arcfour.
|
// RFC 4345 introduces improved versions of Arcfour.
|
||||||
"arcfour": {16, 0, streamCipherMode(0, newRC4)},
|
"arcfour": {16, 0, streamCipherMode(0, newRC4)},
|
||||||
|
|
||||||
// AEAD ciphers
|
// AEAD ciphers
|
||||||
gcmCipherID: {16, 12, newGCMCipher},
|
gcm128CipherID: {16, 12, newGCMCipher},
|
||||||
|
gcm256CipherID: {32, 12, newGCMCipher},
|
||||||
chacha20Poly1305ID: {64, 0, newChaCha20Cipher},
|
chacha20Poly1305ID: {64, 0, newChaCha20Cipher},
|
||||||
|
|
||||||
// CBC mode is insecure and so is not included in the default config.
|
// CBC mode is insecure and so is not included in the default config.
|
||||||
@@ -497,7 +497,7 @@ func (c *cbcCipher) readCipherPacket(seqNum uint32, r io.Reader) ([]byte, error)
|
|||||||
// data, to make distinguishing between
|
// data, to make distinguishing between
|
||||||
// failing MAC and failing length check more
|
// failing MAC and failing length check more
|
||||||
// difficult.
|
// difficult.
|
||||||
io.CopyN(ioutil.Discard, r, int64(c.oracleCamouflage))
|
io.CopyN(io.Discard, r, int64(c.oracleCamouflage))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return p, err
|
return p, err
|
||||||
@@ -642,7 +642,7 @@ const chacha20Poly1305ID = "[email protected]"
|
|||||||
//
|
//
|
||||||
// https://tools.ietf.org/html/draft-josefsson-ssh-chacha20-poly1305-openssh-00
|
// https://tools.ietf.org/html/draft-josefsson-ssh-chacha20-poly1305-openssh-00
|
||||||
//
|
//
|
||||||
// the methods here also implement padding, which RFC4253 Section 6
|
// the methods here also implement padding, which RFC 4253 Section 6
|
||||||
// also requires of stream ciphers.
|
// also requires of stream ciphers.
|
||||||
type chacha20Poly1305Cipher struct {
|
type chacha20Poly1305Cipher struct {
|
||||||
lengthKey [32]byte
|
lengthKey [32]byte
|
||||||
|
|||||||
+1
-1
@@ -82,7 +82,7 @@ func NewClientConn(c net.Conn, addr string, config *ClientConfig) (Conn, <-chan
|
|||||||
|
|
||||||
if err := conn.clientHandshake(addr, &fullConf); err != nil {
|
if err := conn.clientHandshake(addr, &fullConf); err != nil {
|
||||||
c.Close()
|
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)
|
conn.mux = newMux(conn.transport)
|
||||||
return conn, conn.mux.incomingChannels, conn.mux.incomingRequests, nil
|
return conn, conn.mux.incomingChannels, conn.mux.incomingRequests, nil
|
||||||
|
|||||||
+85
-31
@@ -71,7 +71,9 @@ func (c *connection) clientAuthenticate(config *ClientConfig) error {
|
|||||||
for auth := AuthMethod(new(noneAuth)); auth != nil; {
|
for auth := AuthMethod(new(noneAuth)); auth != nil; {
|
||||||
ok, methods, err := auth.auth(sessionID, config.User, c.transport, config.Rand, extensions)
|
ok, methods, err := auth.auth(sessionID, config.User, c.transport, config.Rand, extensions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
// We return the error later if there is no other method left to
|
||||||
|
// try.
|
||||||
|
ok = authFailure
|
||||||
}
|
}
|
||||||
if ok == authSuccess {
|
if ok == authSuccess {
|
||||||
// success
|
// success
|
||||||
@@ -101,6 +103,12 @@ func (c *connection) clientAuthenticate(config *ClientConfig) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if auth == nil && err != nil {
|
||||||
|
// We have an error and there are no other authentication methods to
|
||||||
|
// try, so we return it.
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return fmt.Errorf("ssh: unable to authenticate, attempted methods %v, no supported methods remain", tried)
|
return fmt.Errorf("ssh: unable to authenticate, attempted methods %v, no supported methods remain", tried)
|
||||||
}
|
}
|
||||||
@@ -217,21 +225,45 @@ func (cb publicKeyCallback) method() string {
|
|||||||
return "publickey"
|
return "publickey"
|
||||||
}
|
}
|
||||||
|
|
||||||
func pickSignatureAlgorithm(signer Signer, extensions map[string][]byte) (as AlgorithmSigner, algo string) {
|
func pickSignatureAlgorithm(signer Signer, extensions map[string][]byte) (MultiAlgorithmSigner, string, error) {
|
||||||
|
var as MultiAlgorithmSigner
|
||||||
keyFormat := signer.PublicKey().Type()
|
keyFormat := signer.PublicKey().Type()
|
||||||
|
|
||||||
// Like in sendKexInit, if the public key implements AlgorithmSigner we
|
// If the signer implements MultiAlgorithmSigner we use the algorithms it
|
||||||
// assume it supports all algorithms, otherwise only the key format one.
|
// support, if it implements AlgorithmSigner we assume it supports all
|
||||||
as, ok := signer.(AlgorithmSigner)
|
// algorithms, otherwise only the key format one.
|
||||||
if !ok {
|
switch s := signer.(type) {
|
||||||
return algorithmSignerWrapper{signer}, keyFormat
|
case MultiAlgorithmSigner:
|
||||||
|
as = s
|
||||||
|
case AlgorithmSigner:
|
||||||
|
as = &multiAlgorithmSigner{
|
||||||
|
AlgorithmSigner: s,
|
||||||
|
supportedAlgorithms: algorithmsForKeyFormat(underlyingAlgo(keyFormat)),
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
as = &multiAlgorithmSigner{
|
||||||
|
AlgorithmSigner: algorithmSignerWrapper{signer},
|
||||||
|
supportedAlgorithms: []string{underlyingAlgo(keyFormat)},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getFallbackAlgo := func() (string, error) {
|
||||||
|
// Fallback to use if there is no "server-sig-algs" extension or a
|
||||||
|
// common algorithm cannot be found. We use the public key format if the
|
||||||
|
// MultiAlgorithmSigner supports it, otherwise we return an error.
|
||||||
|
if !contains(as.Algorithms(), underlyingAlgo(keyFormat)) {
|
||||||
|
return "", fmt.Errorf("ssh: no common public key signature algorithm, server only supports %q for key type %q, signer only supports %v",
|
||||||
|
underlyingAlgo(keyFormat), keyFormat, as.Algorithms())
|
||||||
|
}
|
||||||
|
return keyFormat, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
extPayload, ok := extensions["server-sig-algs"]
|
extPayload, ok := extensions["server-sig-algs"]
|
||||||
if !ok {
|
if !ok {
|
||||||
// If there is no "server-sig-algs" extension, fall back to the key
|
// If there is no "server-sig-algs" extension use the fallback
|
||||||
// format algorithm.
|
// algorithm.
|
||||||
return as, keyFormat
|
algo, err := getFallbackAlgo()
|
||||||
|
return as, algo, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// The server-sig-algs extension only carries underlying signature
|
// The server-sig-algs extension only carries underlying signature
|
||||||
@@ -245,15 +277,22 @@ func pickSignatureAlgorithm(signer Signer, extensions map[string][]byte) (as Alg
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
keyAlgos := algorithmsForKeyFormat(keyFormat)
|
// Filter algorithms based on those supported by MultiAlgorithmSigner.
|
||||||
|
var keyAlgos []string
|
||||||
|
for _, algo := range algorithmsForKeyFormat(keyFormat) {
|
||||||
|
if contains(as.Algorithms(), underlyingAlgo(algo)) {
|
||||||
|
keyAlgos = append(keyAlgos, algo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
algo, err := findCommon("public key signature algorithm", keyAlgos, serverAlgos)
|
algo, err := findCommon("public key signature algorithm", keyAlgos, serverAlgos)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If there is no overlap, try the key anyway with the key format
|
// If there is no overlap, return the fallback algorithm to support
|
||||||
// algorithm, to support servers that fail to list all supported
|
// servers that fail to list all supported algorithms.
|
||||||
// algorithms.
|
algo, err := getFallbackAlgo()
|
||||||
return as, keyFormat
|
return as, algo, err
|
||||||
}
|
}
|
||||||
return as, algo
|
return as, algo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cb publicKeyCallback) auth(session []byte, user string, c packetConn, rand io.Reader, extensions map[string][]byte) (authResult, []string, error) {
|
func (cb publicKeyCallback) auth(session []byte, user string, c packetConn, rand io.Reader, extensions map[string][]byte) (authResult, []string, error) {
|
||||||
@@ -267,14 +306,39 @@ func (cb publicKeyCallback) auth(session []byte, user string, c packetConn, rand
|
|||||||
return authFailure, nil, err
|
return authFailure, nil, err
|
||||||
}
|
}
|
||||||
var methods []string
|
var methods []string
|
||||||
for _, signer := range signers {
|
var errSigAlgo error
|
||||||
pub := signer.PublicKey()
|
|
||||||
as, algo := pickSignatureAlgorithm(signer, extensions)
|
|
||||||
|
|
||||||
|
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 {
|
||||||
|
// If we cannot negotiate a signature algorithm store the first
|
||||||
|
// error so we can return it to provide a more meaningful message if
|
||||||
|
// no other signers work.
|
||||||
|
errSigAlgo = err
|
||||||
|
continue
|
||||||
|
}
|
||||||
ok, err := validateKey(pub, algo, user, c)
|
ok, err := validateKey(pub, algo, user, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return authFailure, nil, err
|
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 {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -317,22 +381,12 @@ func (cb publicKeyCallback) auth(session []byte, user string, c packetConn, rand
|
|||||||
// contain the "publickey" method, do not attempt to authenticate with any
|
// contain the "publickey" method, do not attempt to authenticate with any
|
||||||
// other keys. According to RFC 4252 Section 7, the latter can occur when
|
// other keys. According to RFC 4252 Section 7, the latter can occur when
|
||||||
// additional authentication methods are required.
|
// additional authentication methods are required.
|
||||||
if success == authSuccess || !containsMethod(methods, cb.method()) {
|
if success == authSuccess || !contains(methods, cb.method()) {
|
||||||
return success, methods, err
|
return success, methods, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return authFailure, methods, nil
|
return authFailure, methods, errSigAlgo
|
||||||
}
|
|
||||||
|
|
||||||
func containsMethod(methods []string, method string) bool {
|
|
||||||
for _, m := range methods {
|
|
||||||
if m == method {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// validateKey validates the key provided is acceptable to the server.
|
// validateKey validates the key provided is acceptable to the server.
|
||||||
|
|||||||
+65
-19
@@ -27,7 +27,7 @@ const (
|
|||||||
// supportedCiphers lists ciphers we support but might not recommend.
|
// supportedCiphers lists ciphers we support but might not recommend.
|
||||||
var supportedCiphers = []string{
|
var supportedCiphers = []string{
|
||||||
"aes128-ctr", "aes192-ctr", "aes256-ctr",
|
"aes128-ctr", "aes192-ctr", "aes256-ctr",
|
||||||
"[email protected]",
|
"[email protected]", gcm256CipherID,
|
||||||
chacha20Poly1305ID,
|
chacha20Poly1305ID,
|
||||||
"arcfour256", "arcfour128", "arcfour",
|
"arcfour256", "arcfour128", "arcfour",
|
||||||
aes128cbcID,
|
aes128cbcID,
|
||||||
@@ -36,7 +36,7 @@ var supportedCiphers = []string{
|
|||||||
|
|
||||||
// preferredCiphers specifies the default preference for ciphers.
|
// preferredCiphers specifies the default preference for ciphers.
|
||||||
var preferredCiphers = []string{
|
var preferredCiphers = []string{
|
||||||
"[email protected]",
|
"[email protected]", gcm256CipherID,
|
||||||
chacha20Poly1305ID,
|
chacha20Poly1305ID,
|
||||||
"aes128-ctr", "aes192-ctr", "aes256-ctr",
|
"aes128-ctr", "aes192-ctr", "aes256-ctr",
|
||||||
}
|
}
|
||||||
@@ -48,7 +48,8 @@ var supportedKexAlgos = []string{
|
|||||||
// P384 and P521 are not constant-time yet, but since we don't
|
// P384 and P521 are not constant-time yet, but since we don't
|
||||||
// reuse ephemeral keys, using them for ECDH should be OK.
|
// reuse ephemeral keys, using them for ECDH should be OK.
|
||||||
kexAlgoECDH256, kexAlgoECDH384, kexAlgoECDH521,
|
kexAlgoECDH256, kexAlgoECDH384, kexAlgoECDH521,
|
||||||
kexAlgoDH14SHA256, kexAlgoDH14SHA1, kexAlgoDH1SHA1,
|
kexAlgoDH14SHA256, kexAlgoDH16SHA512, kexAlgoDH14SHA1,
|
||||||
|
kexAlgoDH1SHA1,
|
||||||
}
|
}
|
||||||
|
|
||||||
// serverForbiddenKexAlgos contains key exchange algorithms, that are forbidden
|
// serverForbiddenKexAlgos contains key exchange algorithms, that are forbidden
|
||||||
@@ -58,8 +59,9 @@ var serverForbiddenKexAlgos = map[string]struct{}{
|
|||||||
kexAlgoDHGEXSHA256: {}, // server half implementation is only minimal to satisfy the automated tests
|
kexAlgoDHGEXSHA256: {}, // server half implementation is only minimal to satisfy the automated tests
|
||||||
}
|
}
|
||||||
|
|
||||||
// preferredKexAlgos specifies the default preference for key-exchange algorithms
|
// preferredKexAlgos specifies the default preference for key-exchange
|
||||||
// in preference order.
|
// algorithms in preference order. The diffie-hellman-group16-sha512 algorithm
|
||||||
|
// is disabled by default because it is a bit slower than the others.
|
||||||
var preferredKexAlgos = []string{
|
var preferredKexAlgos = []string{
|
||||||
kexAlgoCurve25519SHA256, kexAlgoCurve25519SHA256LibSSH,
|
kexAlgoCurve25519SHA256, kexAlgoCurve25519SHA256LibSSH,
|
||||||
kexAlgoECDH256, kexAlgoECDH384, kexAlgoECDH521,
|
kexAlgoECDH256, kexAlgoECDH384, kexAlgoECDH521,
|
||||||
@@ -69,12 +71,12 @@ var preferredKexAlgos = []string{
|
|||||||
// supportedHostKeyAlgos specifies the supported host-key algorithms (i.e. methods
|
// supportedHostKeyAlgos specifies the supported host-key algorithms (i.e. methods
|
||||||
// of authenticating servers) in preference order.
|
// of authenticating servers) in preference order.
|
||||||
var supportedHostKeyAlgos = []string{
|
var supportedHostKeyAlgos = []string{
|
||||||
CertAlgoRSASHA512v01, CertAlgoRSASHA256v01,
|
CertAlgoRSASHA256v01, CertAlgoRSASHA512v01,
|
||||||
CertAlgoRSAv01, CertAlgoDSAv01, CertAlgoECDSA256v01,
|
CertAlgoRSAv01, CertAlgoDSAv01, CertAlgoECDSA256v01,
|
||||||
CertAlgoECDSA384v01, CertAlgoECDSA521v01, CertAlgoED25519v01,
|
CertAlgoECDSA384v01, CertAlgoECDSA521v01, CertAlgoED25519v01,
|
||||||
|
|
||||||
KeyAlgoECDSA256, KeyAlgoECDSA384, KeyAlgoECDSA521,
|
KeyAlgoECDSA256, KeyAlgoECDSA384, KeyAlgoECDSA521,
|
||||||
KeyAlgoRSASHA512, KeyAlgoRSASHA256,
|
KeyAlgoRSASHA256, KeyAlgoRSASHA512,
|
||||||
KeyAlgoRSA, KeyAlgoDSA,
|
KeyAlgoRSA, KeyAlgoDSA,
|
||||||
|
|
||||||
KeyAlgoED25519,
|
KeyAlgoED25519,
|
||||||
@@ -84,7 +86,7 @@ var supportedHostKeyAlgos = []string{
|
|||||||
// This is based on RFC 4253, section 6.4, but with hmac-md5 variants removed
|
// This is based on RFC 4253, section 6.4, but with hmac-md5 variants removed
|
||||||
// because they have reached the end of their useful life.
|
// because they have reached the end of their useful life.
|
||||||
var supportedMACs = []string{
|
var supportedMACs = []string{
|
||||||
"[email protected]", "hmac-sha2-256", "hmac-sha1", "hmac-sha1-96",
|
"[email protected]", "hmac-sha2-[email protected]", "hmac-sha2-256", "hmac-sha2-512", "hmac-sha1", "hmac-sha1-96",
|
||||||
}
|
}
|
||||||
|
|
||||||
var supportedCompressions = []string{compressionNone}
|
var supportedCompressions = []string{compressionNone}
|
||||||
@@ -118,6 +120,33 @@ func algorithmsForKeyFormat(keyFormat string) []string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isRSA returns whether algo is a supported RSA algorithm, including certificate
|
||||||
|
// algorithms.
|
||||||
|
func isRSA(algo string) bool {
|
||||||
|
algos := algorithmsForKeyFormat(KeyAlgoRSA)
|
||||||
|
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
|
||||||
|
// it supports the server-sig-algs extension. Order is irrelevant.
|
||||||
|
var supportedPubKeyAuthAlgos = []string{
|
||||||
|
KeyAlgoED25519,
|
||||||
|
KeyAlgoSKED25519, KeyAlgoSKECDSA256,
|
||||||
|
KeyAlgoECDSA256, KeyAlgoECDSA384, KeyAlgoECDSA521,
|
||||||
|
KeyAlgoRSASHA256, KeyAlgoRSASHA512, KeyAlgoRSA,
|
||||||
|
KeyAlgoDSA,
|
||||||
|
}
|
||||||
|
|
||||||
// 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 {
|
||||||
@@ -149,21 +178,22 @@ type directionAlgorithms struct {
|
|||||||
|
|
||||||
// rekeyBytes returns a rekeying intervals in bytes.
|
// rekeyBytes returns a rekeying intervals in bytes.
|
||||||
func (a *directionAlgorithms) rekeyBytes() int64 {
|
func (a *directionAlgorithms) rekeyBytes() int64 {
|
||||||
// According to RFC4344 block ciphers should rekey after
|
// According to RFC 4344 block ciphers should rekey after
|
||||||
// 2^(BLOCKSIZE/4) blocks. For all AES flavors BLOCKSIZE is
|
// 2^(BLOCKSIZE/4) blocks. For all AES flavors BLOCKSIZE is
|
||||||
// 128.
|
// 128.
|
||||||
switch a.Cipher {
|
switch a.Cipher {
|
||||||
case "aes128-ctr", "aes192-ctr", "aes256-ctr", gcmCipherID, aes128cbcID:
|
case "aes128-ctr", "aes192-ctr", "aes256-ctr", gcm128CipherID, gcm256CipherID, aes128cbcID:
|
||||||
return 16 * (1 << 32)
|
return 16 * (1 << 32)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// For others, stick with RFC4253 recommendation to rekey after 1 Gb of data.
|
// For others, stick with RFC 4253 recommendation to rekey after 1 Gb of data.
|
||||||
return 1 << 30
|
return 1 << 30
|
||||||
}
|
}
|
||||||
|
|
||||||
var aeadCiphers = map[string]bool{
|
var aeadCiphers = map[string]bool{
|
||||||
gcmCipherID: true,
|
gcm128CipherID: true,
|
||||||
|
gcm256CipherID: true,
|
||||||
chacha20Poly1305ID: true,
|
chacha20Poly1305ID: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,16 +276,16 @@ type Config struct {
|
|||||||
// unspecified, a size suitable for the chosen cipher is used.
|
// unspecified, a size suitable for the chosen cipher is used.
|
||||||
RekeyThreshold uint64
|
RekeyThreshold uint64
|
||||||
|
|
||||||
// The allowed key exchanges algorithms. If unspecified then a
|
// The allowed key exchanges algorithms. If unspecified then a default set
|
||||||
// default set of algorithms is used.
|
// of algorithms is used. Unsupported values are silently ignored.
|
||||||
KeyExchanges []string
|
KeyExchanges []string
|
||||||
|
|
||||||
// The allowed cipher algorithms. If unspecified then a sensible
|
// The allowed cipher algorithms. If unspecified then a sensible default is
|
||||||
// default is used.
|
// used. Unsupported values are silently ignored.
|
||||||
Ciphers []string
|
Ciphers []string
|
||||||
|
|
||||||
// The allowed MAC algorithms. If unspecified then a sensible default
|
// The allowed MAC algorithms. If unspecified then a sensible default is
|
||||||
// is used.
|
// used. Unsupported values are silently ignored.
|
||||||
MACs []string
|
MACs []string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,7 +302,7 @@ func (c *Config) SetDefaults() {
|
|||||||
var ciphers []string
|
var ciphers []string
|
||||||
for _, c := range c.Ciphers {
|
for _, c := range c.Ciphers {
|
||||||
if cipherModes[c] != nil {
|
if cipherModes[c] != nil {
|
||||||
// reject the cipher if we have no cipherModes definition
|
// Ignore the cipher if we have no cipherModes definition.
|
||||||
ciphers = append(ciphers, c)
|
ciphers = append(ciphers, c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -281,10 +311,26 @@ func (c *Config) SetDefaults() {
|
|||||||
if c.KeyExchanges == nil {
|
if c.KeyExchanges == nil {
|
||||||
c.KeyExchanges = preferredKexAlgos
|
c.KeyExchanges = preferredKexAlgos
|
||||||
}
|
}
|
||||||
|
var kexs []string
|
||||||
|
for _, k := range c.KeyExchanges {
|
||||||
|
if kexAlgoMap[k] != nil {
|
||||||
|
// Ignore the KEX if we have no kexAlgoMap definition.
|
||||||
|
kexs = append(kexs, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.KeyExchanges = kexs
|
||||||
|
|
||||||
if c.MACs == nil {
|
if c.MACs == nil {
|
||||||
c.MACs = supportedMACs
|
c.MACs = supportedMACs
|
||||||
}
|
}
|
||||||
|
var macs []string
|
||||||
|
for _, m := range c.MACs {
|
||||||
|
if macModes[m] != nil {
|
||||||
|
// Ignore the MAC if we have no macModes definition.
|
||||||
|
macs = append(macs, m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.MACs = macs
|
||||||
|
|
||||||
if c.RekeyThreshold == 0 {
|
if c.RekeyThreshold == 0 {
|
||||||
// cipher specific default
|
// cipher specific default
|
||||||
|
|||||||
+2
-2
@@ -52,7 +52,7 @@ type Conn interface {
|
|||||||
|
|
||||||
// SendRequest sends a global request, and returns the
|
// SendRequest sends a global request, and returns the
|
||||||
// reply. If wantReply is true, it returns the response status
|
// reply. If wantReply is true, it returns the response status
|
||||||
// and payload. See also RFC4254, section 4.
|
// and payload. See also RFC 4254, section 4.
|
||||||
SendRequest(name string, wantReply bool, payload []byte) (bool, []byte, error)
|
SendRequest(name string, wantReply bool, payload []byte) (bool, []byte, error)
|
||||||
|
|
||||||
// OpenChannel tries to open an channel. If the request is
|
// OpenChannel tries to open an channel. If the request is
|
||||||
@@ -97,7 +97,7 @@ func (c *connection) Close() error {
|
|||||||
return c.sshConn.conn.Close()
|
return c.sshConn.conn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// sshconn provides net.Conn metadata, but disallows direct reads and
|
// sshConn provides net.Conn metadata, but disallows direct reads and
|
||||||
// writes.
|
// writes.
|
||||||
type sshConn struct {
|
type sshConn struct {
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
|
|||||||
+1
@@ -13,6 +13,7 @@ others.
|
|||||||
|
|
||||||
References:
|
References:
|
||||||
|
|
||||||
|
[PROTOCOL]: https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/PROTOCOL?rev=HEAD
|
||||||
[PROTOCOL.certkeys]: http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/PROTOCOL.certkeys?rev=HEAD
|
[PROTOCOL.certkeys]: http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/PROTOCOL.certkeys?rev=HEAD
|
||||||
[SSH-PARAMETERS]: http://www.iana.org/assignments/ssh-parameters/ssh-parameters.xml#ssh-parameters-1
|
[SSH-PARAMETERS]: http://www.iana.org/assignments/ssh-parameters/ssh-parameters.xml#ssh-parameters-1
|
||||||
|
|
||||||
|
|||||||
+137
-35
@@ -11,6 +11,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -34,6 +35,16 @@ type keyingTransport interface {
|
|||||||
// direction will be effected if a msgNewKeys message is sent
|
// direction will be effected if a msgNewKeys message is sent
|
||||||
// or received.
|
// or received.
|
||||||
prepareKeyChange(*algorithms, *kexResult) error
|
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
|
// handshakeTransport implements rekeying on top of a keyingTransport
|
||||||
@@ -50,6 +61,10 @@ type handshakeTransport struct {
|
|||||||
// connection.
|
// connection.
|
||||||
hostKeys []Signer
|
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,
|
// hostKeyAlgorithms is non-empty if we are the client. In that case,
|
||||||
// we accept these key types from the server as host key.
|
// we accept these key types from the server as host key.
|
||||||
hostKeyAlgorithms []string
|
hostKeyAlgorithms []string
|
||||||
@@ -58,11 +73,13 @@ type handshakeTransport struct {
|
|||||||
incoming chan []byte
|
incoming chan []byte
|
||||||
readError error
|
readError error
|
||||||
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
writeError error
|
writeError error
|
||||||
sentInitPacket []byte
|
sentInitPacket []byte
|
||||||
sentInitMsg *kexInitMsg
|
sentInitMsg *kexInitMsg
|
||||||
pendingPackets [][]byte // Used when a key exchange is in progress.
|
pendingPackets [][]byte // Used when a key exchange is in progress.
|
||||||
|
writePacketsLeft uint32
|
||||||
|
writeBytesLeft int64
|
||||||
|
|
||||||
// If the read loop wants to schedule a kex, it pings this
|
// If the read loop wants to schedule a kex, it pings this
|
||||||
// channel, and the write loop will send out a kex
|
// channel, and the write loop will send out a kex
|
||||||
@@ -71,7 +88,8 @@ type handshakeTransport struct {
|
|||||||
|
|
||||||
// If the other side requests or confirms a kex, its kexInit
|
// If the other side requests or confirms a kex, its kexInit
|
||||||
// packet is sent here for the write loop to find it.
|
// packet is sent here for the write loop to find it.
|
||||||
startKex chan *pendingKex
|
startKex chan *pendingKex
|
||||||
|
kexLoopDone chan struct{} // closed (with writeError non-nil) when kexLoop exits
|
||||||
|
|
||||||
// data for host key checking
|
// data for host key checking
|
||||||
hostKeyCallback HostKeyCallback
|
hostKeyCallback HostKeyCallback
|
||||||
@@ -86,14 +104,16 @@ type handshakeTransport struct {
|
|||||||
// Algorithms agreed in the last key exchange.
|
// Algorithms agreed in the last key exchange.
|
||||||
algorithms *algorithms
|
algorithms *algorithms
|
||||||
|
|
||||||
|
// Counters exclusively owned by readLoop.
|
||||||
readPacketsLeft uint32
|
readPacketsLeft uint32
|
||||||
readBytesLeft int64
|
readBytesLeft int64
|
||||||
|
|
||||||
writePacketsLeft uint32
|
|
||||||
writeBytesLeft int64
|
|
||||||
|
|
||||||
// The session ID or nil if first kex did not complete yet.
|
// The session ID or nil if first kex did not complete yet.
|
||||||
sessionID []byte
|
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 {
|
type pendingKex struct {
|
||||||
@@ -108,7 +128,8 @@ func newHandshakeTransport(conn keyingTransport, config *Config, clientVersion,
|
|||||||
clientVersion: clientVersion,
|
clientVersion: clientVersion,
|
||||||
incoming: make(chan []byte, chanSize),
|
incoming: make(chan []byte, chanSize),
|
||||||
requestKex: make(chan struct{}, 1),
|
requestKex: make(chan struct{}, 1),
|
||||||
startKex: make(chan *pendingKex, 1),
|
startKex: make(chan *pendingKex),
|
||||||
|
kexLoopDone: make(chan struct{}),
|
||||||
|
|
||||||
config: config,
|
config: config,
|
||||||
}
|
}
|
||||||
@@ -139,6 +160,7 @@ func newClientTransport(conn keyingTransport, clientVersion, serverVersion []byt
|
|||||||
func newServerTransport(conn keyingTransport, clientVersion, serverVersion []byte, config *ServerConfig) *handshakeTransport {
|
func newServerTransport(conn keyingTransport, clientVersion, serverVersion []byte, config *ServerConfig) *handshakeTransport {
|
||||||
t := newHandshakeTransport(conn, &config.Config, clientVersion, serverVersion)
|
t := newHandshakeTransport(conn, &config.Config, clientVersion, serverVersion)
|
||||||
t.hostKeys = config.hostKeys
|
t.hostKeys = config.hostKeys
|
||||||
|
t.publicKeyAuthAlgorithms = config.PublicKeyAuthAlgorithms
|
||||||
go t.readLoop()
|
go t.readLoop()
|
||||||
go t.kexLoop()
|
go t.kexLoop()
|
||||||
return t
|
return t
|
||||||
@@ -201,7 +223,10 @@ func (t *handshakeTransport) readLoop() {
|
|||||||
close(t.incoming)
|
close(t.incoming)
|
||||||
break
|
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
|
continue
|
||||||
}
|
}
|
||||||
t.incoming <- p
|
t.incoming <- p
|
||||||
@@ -340,16 +365,17 @@ write:
|
|||||||
t.mu.Unlock()
|
t.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// drain startKex channel. We don't service t.requestKex
|
|
||||||
// because nobody does blocking sends there.
|
|
||||||
go func() {
|
|
||||||
for init := range t.startKex {
|
|
||||||
init.done <- t.writeError
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// Unblock reader.
|
// Unblock reader.
|
||||||
t.conn.Close()
|
t.conn.Close()
|
||||||
|
|
||||||
|
// drain startKex channel. We don't service t.requestKex
|
||||||
|
// because nobody does blocking sends there.
|
||||||
|
for request := range t.startKex {
|
||||||
|
request.done <- t.getWriteError()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mark that the loop is done so that Close can return.
|
||||||
|
close(t.kexLoopDone)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The protocol uses uint32 for packet counters, so we can't let them
|
// The protocol uses uint32 for packet counters, so we can't let them
|
||||||
@@ -432,6 +458,11 @@ func (t *handshakeTransport) readOnePacket(first bool) ([]byte, error) {
|
|||||||
return successPacket, nil
|
return successPacket, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
kexStrictClient = "[email protected]"
|
||||||
|
kexStrictServer = "[email protected]"
|
||||||
|
)
|
||||||
|
|
||||||
// sendKexInit sends a key change message.
|
// sendKexInit sends a key change message.
|
||||||
func (t *handshakeTransport) sendKexInit() error {
|
func (t *handshakeTransport) sendKexInit() error {
|
||||||
t.mu.Lock()
|
t.mu.Lock()
|
||||||
@@ -445,7 +476,6 @@ func (t *handshakeTransport) sendKexInit() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
msg := &kexInitMsg{
|
msg := &kexInitMsg{
|
||||||
KexAlgos: t.config.KeyExchanges,
|
|
||||||
CiphersClientServer: t.config.Ciphers,
|
CiphersClientServer: t.config.Ciphers,
|
||||||
CiphersServerClient: t.config.Ciphers,
|
CiphersServerClient: t.config.Ciphers,
|
||||||
MACsClientServer: t.config.MACs,
|
MACsClientServer: t.config.MACs,
|
||||||
@@ -455,36 +485,55 @@ func (t *handshakeTransport) sendKexInit() error {
|
|||||||
}
|
}
|
||||||
io.ReadFull(rand.Reader, msg.Cookie[:])
|
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
|
isServer := len(t.hostKeys) > 0
|
||||||
if isServer {
|
if isServer {
|
||||||
for _, k := range t.hostKeys {
|
for _, k := range t.hostKeys {
|
||||||
// If k is an AlgorithmSigner, presume it supports all signature algorithms
|
// If k is a MultiAlgorithmSigner, we restrict the signature
|
||||||
// associated with the key format. (Ideally AlgorithmSigner would have a
|
// algorithms. If k is a AlgorithmSigner, presume it supports all
|
||||||
// method to advertise supported algorithms, but it doesn't. This means that
|
// signature algorithms associated with the key format. If k is not
|
||||||
// adding support for a new algorithm is a breaking change, as we will
|
// an AlgorithmSigner, we can only assume it only supports the
|
||||||
// immediately negotiate it even if existing implementations don't support
|
// algorithms that matches the key format. (This means that Sign
|
||||||
// it. If that ever happens, we'll have to figure something out.)
|
// can't pick a different default).
|
||||||
// If k is not an AlgorithmSigner, we can only assume it only supports the
|
|
||||||
// algorithms that matches the key format. (This means that Sign can't pick
|
|
||||||
// a different default.)
|
|
||||||
keyFormat := k.PublicKey().Type()
|
keyFormat := k.PublicKey().Type()
|
||||||
if _, ok := k.(AlgorithmSigner); ok {
|
|
||||||
|
switch s := k.(type) {
|
||||||
|
case MultiAlgorithmSigner:
|
||||||
|
for _, algo := range algorithmsForKeyFormat(keyFormat) {
|
||||||
|
if contains(s.Algorithms(), underlyingAlgo(algo)) {
|
||||||
|
msg.ServerHostKeyAlgos = append(msg.ServerHostKeyAlgos, algo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case AlgorithmSigner:
|
||||||
msg.ServerHostKeyAlgos = append(msg.ServerHostKeyAlgos, algorithmsForKeyFormat(keyFormat)...)
|
msg.ServerHostKeyAlgos = append(msg.ServerHostKeyAlgos, algorithmsForKeyFormat(keyFormat)...)
|
||||||
} else {
|
default:
|
||||||
msg.ServerHostKeyAlgos = append(msg.ServerHostKeyAlgos, keyFormat)
|
msg.ServerHostKeyAlgos = append(msg.ServerHostKeyAlgos, keyFormat)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if t.sessionID == nil {
|
||||||
|
msg.KexAlgos = append(msg.KexAlgos, kexStrictServer)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
msg.ServerHostKeyAlgos = t.hostKeyAlgorithms
|
msg.ServerHostKeyAlgos = t.hostKeyAlgorithms
|
||||||
|
|
||||||
// As a client we opt in to receiving SSH_MSG_EXT_INFO so we know what
|
// 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
|
// algorithms the server supports for public key authentication. See RFC
|
||||||
// 8308, Section 2.1.
|
// 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 {
|
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, "ext-info-c")
|
||||||
|
msg.KexAlgos = append(msg.KexAlgos, kexStrictClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
packet := Marshal(msg)
|
packet := Marshal(msg)
|
||||||
@@ -545,7 +594,16 @@ func (t *handshakeTransport) writePacket(p []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *handshakeTransport) Close() error {
|
func (t *handshakeTransport) Close() error {
|
||||||
return t.conn.Close()
|
// Close the connection. This should cause the readLoop goroutine to wake up
|
||||||
|
// and close t.startKex, which will shut down kexLoop if running.
|
||||||
|
err := t.conn.Close()
|
||||||
|
|
||||||
|
// Wait for the kexLoop goroutine to complete.
|
||||||
|
// At that point we know that the readLoop goroutine is complete too,
|
||||||
|
// because kexLoop itself waits for readLoop to close the startKex channel.
|
||||||
|
<-t.kexLoopDone
|
||||||
|
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *handshakeTransport) enterKeyExchange(otherInitPacket []byte) error {
|
func (t *handshakeTransport) enterKeyExchange(otherInitPacket []byte) error {
|
||||||
@@ -581,6 +639,13 @@ func (t *handshakeTransport) enterKeyExchange(otherInitPacket []byte) error {
|
|||||||
return err
|
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.
|
// We don't send FirstKexFollows, but we handle receiving it.
|
||||||
//
|
//
|
||||||
// RFC 4253 section 7 defines the kex and the agreement method for
|
// RFC 4253 section 7 defines the kex and the agreement method for
|
||||||
@@ -615,7 +680,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,12 +692,41 @@ 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, 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),
|
||||||
|
}
|
||||||
|
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...)
|
||||||
|
extInfo.Payload = appendInt(extInfo.Payload, len("[email protected]"))
|
||||||
|
extInfo.Payload = append(extInfo.Payload, "[email protected]"...)
|
||||||
|
extInfo.Payload = appendInt(extInfo.Payload, 1)
|
||||||
|
extInfo.Payload = append(extInfo.Payload, "0"...)
|
||||||
|
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 {
|
||||||
return unexpectedMessageError(msgNewKeys, packet[0])
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -654,9 +749,16 @@ func (a algorithmSignerWrapper) SignWithAlgorithm(rand io.Reader, data []byte, a
|
|||||||
|
|
||||||
func pickHostKey(hostKeys []Signer, algo string) AlgorithmSigner {
|
func pickHostKey(hostKeys []Signer, algo string) AlgorithmSigner {
|
||||||
for _, k := range hostKeys {
|
for _, k := range hostKeys {
|
||||||
|
if s, ok := k.(MultiAlgorithmSigner); ok {
|
||||||
|
if !contains(s.Algorithms(), underlyingAlgo(algo)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if algo == k.PublicKey().Type() {
|
if algo == k.PublicKey().Type() {
|
||||||
return algorithmSignerWrapper{k}
|
return algorithmSignerWrapper{k}
|
||||||
}
|
}
|
||||||
|
|
||||||
k, ok := k.(AlgorithmSigner)
|
k, ok := k.(AlgorithmSigner)
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
|
|||||||
+12
@@ -23,6 +23,7 @@ const (
|
|||||||
kexAlgoDH1SHA1 = "diffie-hellman-group1-sha1"
|
kexAlgoDH1SHA1 = "diffie-hellman-group1-sha1"
|
||||||
kexAlgoDH14SHA1 = "diffie-hellman-group14-sha1"
|
kexAlgoDH14SHA1 = "diffie-hellman-group14-sha1"
|
||||||
kexAlgoDH14SHA256 = "diffie-hellman-group14-sha256"
|
kexAlgoDH14SHA256 = "diffie-hellman-group14-sha256"
|
||||||
|
kexAlgoDH16SHA512 = "diffie-hellman-group16-sha512"
|
||||||
kexAlgoECDH256 = "ecdh-sha2-nistp256"
|
kexAlgoECDH256 = "ecdh-sha2-nistp256"
|
||||||
kexAlgoECDH384 = "ecdh-sha2-nistp384"
|
kexAlgoECDH384 = "ecdh-sha2-nistp384"
|
||||||
kexAlgoECDH521 = "ecdh-sha2-nistp521"
|
kexAlgoECDH521 = "ecdh-sha2-nistp521"
|
||||||
@@ -430,6 +431,17 @@ func init() {
|
|||||||
hashFunc: crypto.SHA256,
|
hashFunc: crypto.SHA256,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is the group called diffie-hellman-group16-sha512 in RFC
|
||||||
|
// 8268 and Oakley Group 16 in RFC 3526.
|
||||||
|
p, _ = new(big.Int).SetString("FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D788719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA993B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934063199FFFFFFFFFFFFFFFF", 16)
|
||||||
|
|
||||||
|
kexAlgoMap[kexAlgoDH16SHA512] = &dhGroup{
|
||||||
|
g: new(big.Int).SetInt64(2),
|
||||||
|
p: p,
|
||||||
|
pMinus1: new(big.Int).Sub(p, bigOne),
|
||||||
|
hashFunc: crypto.SHA512,
|
||||||
|
}
|
||||||
|
|
||||||
kexAlgoMap[kexAlgoECDH521] = &ecdh{elliptic.P521()}
|
kexAlgoMap[kexAlgoECDH521] = &ecdh{elliptic.P521()}
|
||||||
kexAlgoMap[kexAlgoECDH384] = &ecdh{elliptic.P384()}
|
kexAlgoMap[kexAlgoECDH384] = &ecdh{elliptic.P384()}
|
||||||
kexAlgoMap[kexAlgoECDH256] = &ecdh{elliptic.P256()}
|
kexAlgoMap[kexAlgoECDH256] = &ecdh{elliptic.P256()}
|
||||||
|
|||||||
+342
-61
@@ -11,13 +11,16 @@ import (
|
|||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
"crypto/dsa"
|
"crypto/dsa"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
|
"crypto/ed25519"
|
||||||
"crypto/elliptic"
|
"crypto/elliptic"
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
|
"crypto/rand"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/asn1"
|
"encoding/asn1"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"encoding/binary"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"errors"
|
"errors"
|
||||||
@@ -26,7 +29,6 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/crypto/ed25519"
|
|
||||||
"golang.org/x/crypto/ssh/internal/bcrypt_pbkdf"
|
"golang.org/x/crypto/ssh/internal/bcrypt_pbkdf"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -184,7 +186,7 @@ func ParseKnownHosts(in []byte) (marker string, hosts []string, pubKey PublicKey
|
|||||||
return "", nil, nil, "", nil, io.EOF
|
return "", nil, nil, "", nil, io.EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseAuthorizedKeys parses a public key from an authorized_keys
|
// ParseAuthorizedKey parses a public key from an authorized_keys
|
||||||
// file used in OpenSSH according to the sshd(8) manual page.
|
// file used in OpenSSH according to the sshd(8) manual page.
|
||||||
func ParseAuthorizedKey(in []byte) (out PublicKey, comment string, options []string, rest []byte, err error) {
|
func ParseAuthorizedKey(in []byte) (out PublicKey, comment string, options []string, rest []byte, err error) {
|
||||||
for len(in) > 0 {
|
for len(in) > 0 {
|
||||||
@@ -295,6 +297,18 @@ func MarshalAuthorizedKey(key PublicKey) []byte {
|
|||||||
return b.Bytes()
|
return b.Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshalPrivateKey returns a PEM block with the private key serialized in the
|
||||||
|
// OpenSSH format.
|
||||||
|
func MarshalPrivateKey(key crypto.PrivateKey, comment string) (*pem.Block, error) {
|
||||||
|
return marshalOpenSSHPrivateKey(key, comment, unencryptedOpenSSHMarshaler)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalPrivateKeyWithPassphrase returns a PEM block holding the encrypted
|
||||||
|
// private key serialized in the OpenSSH format.
|
||||||
|
func MarshalPrivateKeyWithPassphrase(key crypto.PrivateKey, comment string, passphrase []byte) (*pem.Block, error) {
|
||||||
|
return marshalOpenSSHPrivateKey(key, comment, passphraseProtectedOpenSSHMarshaler(passphrase))
|
||||||
|
}
|
||||||
|
|
||||||
// PublicKey represents a public key using an unspecified algorithm.
|
// PublicKey represents a public key using an unspecified algorithm.
|
||||||
//
|
//
|
||||||
// Some PublicKeys provided by this package also implement CryptoPublicKey.
|
// Some PublicKeys provided by this package also implement CryptoPublicKey.
|
||||||
@@ -321,7 +335,7 @@ type CryptoPublicKey interface {
|
|||||||
|
|
||||||
// A Signer can create signatures that verify against a public key.
|
// A Signer can create signatures that verify against a public key.
|
||||||
//
|
//
|
||||||
// Some Signers provided by this package also implement AlgorithmSigner.
|
// Some Signers provided by this package also implement MultiAlgorithmSigner.
|
||||||
type Signer interface {
|
type Signer interface {
|
||||||
// PublicKey returns the associated PublicKey.
|
// PublicKey returns the associated PublicKey.
|
||||||
PublicKey() PublicKey
|
PublicKey() PublicKey
|
||||||
@@ -336,9 +350,9 @@ type Signer interface {
|
|||||||
// An AlgorithmSigner is a Signer that also supports specifying an algorithm to
|
// An AlgorithmSigner is a Signer that also supports specifying an algorithm to
|
||||||
// use for signing.
|
// use for signing.
|
||||||
//
|
//
|
||||||
// An AlgorithmSigner can't advertise the algorithms it supports, so it should
|
// An AlgorithmSigner can't advertise the algorithms it supports, unless it also
|
||||||
// be prepared to be invoked with every algorithm supported by the public key
|
// implements MultiAlgorithmSigner, so it should be prepared to be invoked with
|
||||||
// format.
|
// every algorithm supported by the public key format.
|
||||||
type AlgorithmSigner interface {
|
type AlgorithmSigner interface {
|
||||||
Signer
|
Signer
|
||||||
|
|
||||||
@@ -349,6 +363,75 @@ type AlgorithmSigner interface {
|
|||||||
SignWithAlgorithm(rand io.Reader, data []byte, algorithm string) (*Signature, error)
|
SignWithAlgorithm(rand io.Reader, data []byte, algorithm string) (*Signature, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MultiAlgorithmSigner is an AlgorithmSigner that also reports the algorithms
|
||||||
|
// supported by that signer.
|
||||||
|
type MultiAlgorithmSigner interface {
|
||||||
|
AlgorithmSigner
|
||||||
|
|
||||||
|
// Algorithms returns the available algorithms in preference order. The list
|
||||||
|
// must not be empty, and it must not include certificate types.
|
||||||
|
Algorithms() []string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewSignerWithAlgorithms returns a signer restricted to the specified
|
||||||
|
// algorithms. The algorithms must be set in preference order. The list must not
|
||||||
|
// be empty, and it must not include certificate types. An error is returned if
|
||||||
|
// the specified algorithms are incompatible with the public key type.
|
||||||
|
func NewSignerWithAlgorithms(signer AlgorithmSigner, algorithms []string) (MultiAlgorithmSigner, error) {
|
||||||
|
if len(algorithms) == 0 {
|
||||||
|
return nil, errors.New("ssh: please specify at least one valid signing algorithm")
|
||||||
|
}
|
||||||
|
var signerAlgos []string
|
||||||
|
supportedAlgos := algorithmsForKeyFormat(underlyingAlgo(signer.PublicKey().Type()))
|
||||||
|
if s, ok := signer.(*multiAlgorithmSigner); ok {
|
||||||
|
signerAlgos = s.Algorithms()
|
||||||
|
} else {
|
||||||
|
signerAlgos = supportedAlgos
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, algo := range algorithms {
|
||||||
|
if !contains(supportedAlgos, algo) {
|
||||||
|
return nil, fmt.Errorf("ssh: algorithm %q is not supported for key type %q",
|
||||||
|
algo, signer.PublicKey().Type())
|
||||||
|
}
|
||||||
|
if !contains(signerAlgos, algo) {
|
||||||
|
return nil, fmt.Errorf("ssh: algorithm %q is restricted for the provided signer", algo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return &multiAlgorithmSigner{
|
||||||
|
AlgorithmSigner: signer,
|
||||||
|
supportedAlgorithms: algorithms,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type multiAlgorithmSigner struct {
|
||||||
|
AlgorithmSigner
|
||||||
|
supportedAlgorithms []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *multiAlgorithmSigner) Algorithms() []string {
|
||||||
|
return s.supportedAlgorithms
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *multiAlgorithmSigner) isAlgorithmSupported(algorithm string) bool {
|
||||||
|
if algorithm == "" {
|
||||||
|
algorithm = underlyingAlgo(s.PublicKey().Type())
|
||||||
|
}
|
||||||
|
for _, algo := range s.supportedAlgorithms {
|
||||||
|
if algorithm == algo {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *multiAlgorithmSigner) SignWithAlgorithm(rand io.Reader, data []byte, algorithm string) (*Signature, error) {
|
||||||
|
if !s.isAlgorithmSupported(algorithm) {
|
||||||
|
return nil, fmt.Errorf("ssh: algorithm %q is not supported: %v", algorithm, s.supportedAlgorithms)
|
||||||
|
}
|
||||||
|
return s.AlgorithmSigner.SignWithAlgorithm(rand, data, algorithm)
|
||||||
|
}
|
||||||
|
|
||||||
type rsaPublicKey rsa.PublicKey
|
type rsaPublicKey rsa.PublicKey
|
||||||
|
|
||||||
func (r *rsaPublicKey) Type() string {
|
func (r *rsaPublicKey) Type() string {
|
||||||
@@ -512,6 +595,10 @@ func (k *dsaPrivateKey) Sign(rand io.Reader, data []byte) (*Signature, error) {
|
|||||||
return k.SignWithAlgorithm(rand, data, k.PublicKey().Type())
|
return k.SignWithAlgorithm(rand, data, k.PublicKey().Type())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (k *dsaPrivateKey) Algorithms() []string {
|
||||||
|
return []string{k.PublicKey().Type()}
|
||||||
|
}
|
||||||
|
|
||||||
func (k *dsaPrivateKey) SignWithAlgorithm(rand io.Reader, data []byte, algorithm string) (*Signature, error) {
|
func (k *dsaPrivateKey) SignWithAlgorithm(rand io.Reader, data []byte, algorithm string) (*Signature, error) {
|
||||||
if algorithm != "" && algorithm != k.PublicKey().Type() {
|
if algorithm != "" && algorithm != k.PublicKey().Type() {
|
||||||
return nil, fmt.Errorf("ssh: unsupported signature algorithm %s", algorithm)
|
return nil, fmt.Errorf("ssh: unsupported signature algorithm %s", algorithm)
|
||||||
@@ -961,13 +1048,16 @@ func (s *wrappedSigner) Sign(rand io.Reader, data []byte) (*Signature, error) {
|
|||||||
return s.SignWithAlgorithm(rand, data, s.pubKey.Type())
|
return s.SignWithAlgorithm(rand, data, s.pubKey.Type())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *wrappedSigner) Algorithms() []string {
|
||||||
|
return algorithmsForKeyFormat(s.pubKey.Type())
|
||||||
|
}
|
||||||
|
|
||||||
func (s *wrappedSigner) SignWithAlgorithm(rand io.Reader, data []byte, algorithm string) (*Signature, error) {
|
func (s *wrappedSigner) SignWithAlgorithm(rand io.Reader, data []byte, algorithm string) (*Signature, error) {
|
||||||
if algorithm == "" {
|
if algorithm == "" {
|
||||||
algorithm = s.pubKey.Type()
|
algorithm = s.pubKey.Type()
|
||||||
}
|
}
|
||||||
|
|
||||||
supportedAlgos := algorithmsForKeyFormat(s.pubKey.Type())
|
if !contains(s.Algorithms(), algorithm) {
|
||||||
if !contains(supportedAlgos, algorithm) {
|
|
||||||
return nil, fmt.Errorf("ssh: unsupported signature algorithm %q for key format %q", algorithm, s.pubKey.Type())
|
return nil, fmt.Errorf("ssh: unsupported signature algorithm %q for key format %q", algorithm, s.pubKey.Type())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1087,9 +1177,9 @@ func (*PassphraseMissingError) Error() string {
|
|||||||
return "ssh: this private key is passphrase protected"
|
return "ssh: this private key is passphrase protected"
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseRawPrivateKey returns a private key from a PEM encoded private key. It
|
// ParseRawPrivateKey returns a private key from a PEM encoded private key. It supports
|
||||||
// supports RSA (PKCS#1), PKCS#8, DSA (OpenSSL), and ECDSA private keys. If the
|
// RSA, DSA, ECDSA, and Ed25519 private keys in PKCS#1, PKCS#8, OpenSSL, and OpenSSH
|
||||||
// private key is encrypted, it will return a PassphraseMissingError.
|
// formats. If the private key is encrypted, it will return a PassphraseMissingError.
|
||||||
func ParseRawPrivateKey(pemBytes []byte) (interface{}, error) {
|
func ParseRawPrivateKey(pemBytes []byte) (interface{}, error) {
|
||||||
block, _ := pem.Decode(pemBytes)
|
block, _ := pem.Decode(pemBytes)
|
||||||
if block == nil {
|
if block == nil {
|
||||||
@@ -1142,16 +1232,27 @@ func ParseRawPrivateKeyWithPassphrase(pemBytes, passphrase []byte) (interface{},
|
|||||||
return nil, fmt.Errorf("ssh: cannot decode encrypted private keys: %v", err)
|
return nil, fmt.Errorf("ssh: cannot decode encrypted private keys: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var result interface{}
|
||||||
|
|
||||||
switch block.Type {
|
switch block.Type {
|
||||||
case "RSA PRIVATE KEY":
|
case "RSA PRIVATE KEY":
|
||||||
return x509.ParsePKCS1PrivateKey(buf)
|
result, err = x509.ParsePKCS1PrivateKey(buf)
|
||||||
case "EC PRIVATE KEY":
|
case "EC PRIVATE KEY":
|
||||||
return x509.ParseECPrivateKey(buf)
|
result, err = x509.ParseECPrivateKey(buf)
|
||||||
case "DSA PRIVATE KEY":
|
case "DSA PRIVATE KEY":
|
||||||
return ParseDSAPrivateKey(buf)
|
result, err = ParseDSAPrivateKey(buf)
|
||||||
default:
|
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
|
// ParseDSAPrivateKey returns a DSA private key from its ASN.1 DER encoding, as
|
||||||
@@ -1241,28 +1342,106 @@ func passphraseProtectedOpenSSHKey(passphrase []byte) openSSHDecryptFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func unencryptedOpenSSHMarshaler(privKeyBlock []byte) ([]byte, string, string, string, error) {
|
||||||
|
key := generateOpenSSHPadding(privKeyBlock, 8)
|
||||||
|
return key, "none", "none", "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func passphraseProtectedOpenSSHMarshaler(passphrase []byte) openSSHEncryptFunc {
|
||||||
|
return func(privKeyBlock []byte) ([]byte, string, string, string, error) {
|
||||||
|
salt := make([]byte, 16)
|
||||||
|
if _, err := rand.Read(salt); err != nil {
|
||||||
|
return nil, "", "", "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
opts := struct {
|
||||||
|
Salt []byte
|
||||||
|
Rounds uint32
|
||||||
|
}{salt, 16}
|
||||||
|
|
||||||
|
// Derive key to encrypt the private key block.
|
||||||
|
k, err := bcrypt_pbkdf.Key(passphrase, salt, int(opts.Rounds), 32+aes.BlockSize)
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", "", "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add padding matching the block size of AES.
|
||||||
|
keyBlock := generateOpenSSHPadding(privKeyBlock, aes.BlockSize)
|
||||||
|
|
||||||
|
// Encrypt the private key using the derived secret.
|
||||||
|
|
||||||
|
dst := make([]byte, len(keyBlock))
|
||||||
|
key, iv := k[:32], k[32:]
|
||||||
|
block, err := aes.NewCipher(key)
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", "", "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
stream := cipher.NewCTR(block, iv)
|
||||||
|
stream.XORKeyStream(dst, keyBlock)
|
||||||
|
|
||||||
|
return dst, "aes256-ctr", "bcrypt", string(Marshal(opts)), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const privateKeyAuthMagic = "openssh-key-v1\x00"
|
||||||
|
|
||||||
type openSSHDecryptFunc func(CipherName, KdfName, KdfOpts string, PrivKeyBlock []byte) ([]byte, error)
|
type openSSHDecryptFunc func(CipherName, KdfName, KdfOpts string, PrivKeyBlock []byte) ([]byte, error)
|
||||||
|
type openSSHEncryptFunc func(PrivKeyBlock []byte) (ProtectedKeyBlock []byte, cipherName, kdfName, kdfOptions string, err error)
|
||||||
|
|
||||||
|
type openSSHEncryptedPrivateKey struct {
|
||||||
|
CipherName string
|
||||||
|
KdfName string
|
||||||
|
KdfOpts string
|
||||||
|
NumKeys uint32
|
||||||
|
PubKey []byte
|
||||||
|
PrivKeyBlock []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
type openSSHPrivateKey struct {
|
||||||
|
Check1 uint32
|
||||||
|
Check2 uint32
|
||||||
|
Keytype string
|
||||||
|
Rest []byte `ssh:"rest"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type openSSHRSAPrivateKey struct {
|
||||||
|
N *big.Int
|
||||||
|
E *big.Int
|
||||||
|
D *big.Int
|
||||||
|
Iqmp *big.Int
|
||||||
|
P *big.Int
|
||||||
|
Q *big.Int
|
||||||
|
Comment string
|
||||||
|
Pad []byte `ssh:"rest"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type openSSHEd25519PrivateKey struct {
|
||||||
|
Pub []byte
|
||||||
|
Priv []byte
|
||||||
|
Comment string
|
||||||
|
Pad []byte `ssh:"rest"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type openSSHECDSAPrivateKey struct {
|
||||||
|
Curve string
|
||||||
|
Pub []byte
|
||||||
|
D *big.Int
|
||||||
|
Comment string
|
||||||
|
Pad []byte `ssh:"rest"`
|
||||||
|
}
|
||||||
|
|
||||||
// parseOpenSSHPrivateKey parses an OpenSSH private key, using the decrypt
|
// parseOpenSSHPrivateKey parses an OpenSSH private key, using the decrypt
|
||||||
// function to unwrap the encrypted portion. unencryptedOpenSSHKey can be used
|
// function to unwrap the encrypted portion. unencryptedOpenSSHKey can be used
|
||||||
// as the decrypt function to parse an unencrypted private key. See
|
// as the decrypt function to parse an unencrypted private key. See
|
||||||
// https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key.
|
// https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key.
|
||||||
func parseOpenSSHPrivateKey(key []byte, decrypt openSSHDecryptFunc) (crypto.PrivateKey, error) {
|
func parseOpenSSHPrivateKey(key []byte, decrypt openSSHDecryptFunc) (crypto.PrivateKey, error) {
|
||||||
const magic = "openssh-key-v1\x00"
|
if len(key) < len(privateKeyAuthMagic) || string(key[:len(privateKeyAuthMagic)]) != privateKeyAuthMagic {
|
||||||
if len(key) < len(magic) || string(key[:len(magic)]) != magic {
|
|
||||||
return nil, errors.New("ssh: invalid openssh private key format")
|
return nil, errors.New("ssh: invalid openssh private key format")
|
||||||
}
|
}
|
||||||
remaining := key[len(magic):]
|
remaining := key[len(privateKeyAuthMagic):]
|
||||||
|
|
||||||
var w struct {
|
|
||||||
CipherName string
|
|
||||||
KdfName string
|
|
||||||
KdfOpts string
|
|
||||||
NumKeys uint32
|
|
||||||
PubKey []byte
|
|
||||||
PrivKeyBlock []byte
|
|
||||||
}
|
|
||||||
|
|
||||||
|
var w openSSHEncryptedPrivateKey
|
||||||
if err := Unmarshal(remaining, &w); err != nil {
|
if err := Unmarshal(remaining, &w); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1284,13 +1463,7 @@ func parseOpenSSHPrivateKey(key []byte, decrypt openSSHDecryptFunc) (crypto.Priv
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
pk1 := struct {
|
var pk1 openSSHPrivateKey
|
||||||
Check1 uint32
|
|
||||||
Check2 uint32
|
|
||||||
Keytype string
|
|
||||||
Rest []byte `ssh:"rest"`
|
|
||||||
}{}
|
|
||||||
|
|
||||||
if err := Unmarshal(privKeyBlock, &pk1); err != nil || pk1.Check1 != pk1.Check2 {
|
if err := Unmarshal(privKeyBlock, &pk1); err != nil || pk1.Check1 != pk1.Check2 {
|
||||||
if w.CipherName != "none" {
|
if w.CipherName != "none" {
|
||||||
return nil, x509.IncorrectPasswordError
|
return nil, x509.IncorrectPasswordError
|
||||||
@@ -1300,18 +1473,7 @@ func parseOpenSSHPrivateKey(key []byte, decrypt openSSHDecryptFunc) (crypto.Priv
|
|||||||
|
|
||||||
switch pk1.Keytype {
|
switch pk1.Keytype {
|
||||||
case KeyAlgoRSA:
|
case KeyAlgoRSA:
|
||||||
// https://github.com/openssh/openssh-portable/blob/master/sshkey.c#L2760-L2773
|
var key openSSHRSAPrivateKey
|
||||||
key := struct {
|
|
||||||
N *big.Int
|
|
||||||
E *big.Int
|
|
||||||
D *big.Int
|
|
||||||
Iqmp *big.Int
|
|
||||||
P *big.Int
|
|
||||||
Q *big.Int
|
|
||||||
Comment string
|
|
||||||
Pad []byte `ssh:"rest"`
|
|
||||||
}{}
|
|
||||||
|
|
||||||
if err := Unmarshal(pk1.Rest, &key); err != nil {
|
if err := Unmarshal(pk1.Rest, &key); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1337,13 +1499,7 @@ func parseOpenSSHPrivateKey(key []byte, decrypt openSSHDecryptFunc) (crypto.Priv
|
|||||||
|
|
||||||
return pk, nil
|
return pk, nil
|
||||||
case KeyAlgoED25519:
|
case KeyAlgoED25519:
|
||||||
key := struct {
|
var key openSSHEd25519PrivateKey
|
||||||
Pub []byte
|
|
||||||
Priv []byte
|
|
||||||
Comment string
|
|
||||||
Pad []byte `ssh:"rest"`
|
|
||||||
}{}
|
|
||||||
|
|
||||||
if err := Unmarshal(pk1.Rest, &key); err != nil {
|
if err := Unmarshal(pk1.Rest, &key); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1360,14 +1516,7 @@ func parseOpenSSHPrivateKey(key []byte, decrypt openSSHDecryptFunc) (crypto.Priv
|
|||||||
copy(pk, key.Priv)
|
copy(pk, key.Priv)
|
||||||
return &pk, nil
|
return &pk, nil
|
||||||
case KeyAlgoECDSA256, KeyAlgoECDSA384, KeyAlgoECDSA521:
|
case KeyAlgoECDSA256, KeyAlgoECDSA384, KeyAlgoECDSA521:
|
||||||
key := struct {
|
var key openSSHECDSAPrivateKey
|
||||||
Curve string
|
|
||||||
Pub []byte
|
|
||||||
D *big.Int
|
|
||||||
Comment string
|
|
||||||
Pad []byte `ssh:"rest"`
|
|
||||||
}{}
|
|
||||||
|
|
||||||
if err := Unmarshal(pk1.Rest, &key); err != nil {
|
if err := Unmarshal(pk1.Rest, &key); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1415,6 +1564,131 @@ func parseOpenSSHPrivateKey(key []byte, decrypt openSSHDecryptFunc) (crypto.Priv
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func marshalOpenSSHPrivateKey(key crypto.PrivateKey, comment string, encrypt openSSHEncryptFunc) (*pem.Block, error) {
|
||||||
|
var w openSSHEncryptedPrivateKey
|
||||||
|
var pk1 openSSHPrivateKey
|
||||||
|
|
||||||
|
// Random check bytes.
|
||||||
|
var check uint32
|
||||||
|
if err := binary.Read(rand.Reader, binary.BigEndian, &check); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
pk1.Check1 = check
|
||||||
|
pk1.Check2 = check
|
||||||
|
w.NumKeys = 1
|
||||||
|
|
||||||
|
// Use a []byte directly on ed25519 keys.
|
||||||
|
if k, ok := key.(*ed25519.PrivateKey); ok {
|
||||||
|
key = *k
|
||||||
|
}
|
||||||
|
|
||||||
|
switch k := key.(type) {
|
||||||
|
case *rsa.PrivateKey:
|
||||||
|
E := new(big.Int).SetInt64(int64(k.PublicKey.E))
|
||||||
|
// Marshal public key:
|
||||||
|
// E and N are in reversed order in the public and private key.
|
||||||
|
pubKey := struct {
|
||||||
|
KeyType string
|
||||||
|
E *big.Int
|
||||||
|
N *big.Int
|
||||||
|
}{
|
||||||
|
KeyAlgoRSA,
|
||||||
|
E, k.PublicKey.N,
|
||||||
|
}
|
||||||
|
w.PubKey = Marshal(pubKey)
|
||||||
|
|
||||||
|
// Marshal private key.
|
||||||
|
key := openSSHRSAPrivateKey{
|
||||||
|
N: k.PublicKey.N,
|
||||||
|
E: E,
|
||||||
|
D: k.D,
|
||||||
|
Iqmp: k.Precomputed.Qinv,
|
||||||
|
P: k.Primes[0],
|
||||||
|
Q: k.Primes[1],
|
||||||
|
Comment: comment,
|
||||||
|
}
|
||||||
|
pk1.Keytype = KeyAlgoRSA
|
||||||
|
pk1.Rest = Marshal(key)
|
||||||
|
case ed25519.PrivateKey:
|
||||||
|
pub := make([]byte, ed25519.PublicKeySize)
|
||||||
|
priv := make([]byte, ed25519.PrivateKeySize)
|
||||||
|
copy(pub, k[32:])
|
||||||
|
copy(priv, k)
|
||||||
|
|
||||||
|
// Marshal public key.
|
||||||
|
pubKey := struct {
|
||||||
|
KeyType string
|
||||||
|
Pub []byte
|
||||||
|
}{
|
||||||
|
KeyAlgoED25519, pub,
|
||||||
|
}
|
||||||
|
w.PubKey = Marshal(pubKey)
|
||||||
|
|
||||||
|
// Marshal private key.
|
||||||
|
key := openSSHEd25519PrivateKey{
|
||||||
|
Pub: pub,
|
||||||
|
Priv: priv,
|
||||||
|
Comment: comment,
|
||||||
|
}
|
||||||
|
pk1.Keytype = KeyAlgoED25519
|
||||||
|
pk1.Rest = Marshal(key)
|
||||||
|
case *ecdsa.PrivateKey:
|
||||||
|
var curve, keyType string
|
||||||
|
switch name := k.Curve.Params().Name; name {
|
||||||
|
case "P-256":
|
||||||
|
curve = "nistp256"
|
||||||
|
keyType = KeyAlgoECDSA256
|
||||||
|
case "P-384":
|
||||||
|
curve = "nistp384"
|
||||||
|
keyType = KeyAlgoECDSA384
|
||||||
|
case "P-521":
|
||||||
|
curve = "nistp521"
|
||||||
|
keyType = KeyAlgoECDSA521
|
||||||
|
default:
|
||||||
|
return nil, errors.New("ssh: unhandled elliptic curve " + name)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub := elliptic.Marshal(k.Curve, k.PublicKey.X, k.PublicKey.Y)
|
||||||
|
|
||||||
|
// Marshal public key.
|
||||||
|
pubKey := struct {
|
||||||
|
KeyType string
|
||||||
|
Curve string
|
||||||
|
Pub []byte
|
||||||
|
}{
|
||||||
|
keyType, curve, pub,
|
||||||
|
}
|
||||||
|
w.PubKey = Marshal(pubKey)
|
||||||
|
|
||||||
|
// Marshal private key.
|
||||||
|
key := openSSHECDSAPrivateKey{
|
||||||
|
Curve: curve,
|
||||||
|
Pub: pub,
|
||||||
|
D: k.D,
|
||||||
|
Comment: comment,
|
||||||
|
}
|
||||||
|
pk1.Keytype = keyType
|
||||||
|
pk1.Rest = Marshal(key)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("ssh: unsupported key type %T", k)
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
// Add padding and encrypt the key if necessary.
|
||||||
|
w.PrivKeyBlock, w.CipherName, w.KdfName, w.KdfOpts, err = encrypt(Marshal(pk1))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
b := Marshal(w)
|
||||||
|
block := &pem.Block{
|
||||||
|
Type: "OPENSSH PRIVATE KEY",
|
||||||
|
Bytes: append([]byte(privateKeyAuthMagic), b...),
|
||||||
|
}
|
||||||
|
return block, nil
|
||||||
|
}
|
||||||
|
|
||||||
func checkOpenSSHKeyPadding(pad []byte) error {
|
func checkOpenSSHKeyPadding(pad []byte) error {
|
||||||
for i, b := range pad {
|
for i, b := range pad {
|
||||||
if int(b) != i+1 {
|
if int(b) != i+1 {
|
||||||
@@ -1424,6 +1698,13 @@ func checkOpenSSHKeyPadding(pad []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func generateOpenSSHPadding(block []byte, blockSize int) []byte {
|
||||||
|
for i, l := 0, len(block); (l+i)%blockSize != 0; i++ {
|
||||||
|
block = append(block, byte(i+1))
|
||||||
|
}
|
||||||
|
return block
|
||||||
|
}
|
||||||
|
|
||||||
// FingerprintLegacyMD5 returns the user presentation of the key's
|
// FingerprintLegacyMD5 returns the user presentation of the key's
|
||||||
// fingerprint as described by RFC 4716 section 4.
|
// fingerprint as described by RFC 4716 section 4.
|
||||||
func FingerprintLegacyMD5(pubKey PublicKey) string {
|
func FingerprintLegacyMD5(pubKey PublicKey) string {
|
||||||
|
|||||||
+1
-1
@@ -142,7 +142,7 @@ func keyEq(a, b ssh.PublicKey) bool {
|
|||||||
return bytes.Equal(a.Marshal(), b.Marshal())
|
return bytes.Equal(a.Marshal(), b.Marshal())
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsAuthorityForHost can be used as a callback in ssh.CertChecker
|
// IsHostAuthority can be used as a callback in ssh.CertChecker
|
||||||
func (db *hostKeyDB) IsHostAuthority(remote ssh.PublicKey, address string) bool {
|
func (db *hostKeyDB) IsHostAuthority(remote ssh.PublicKey, address string) bool {
|
||||||
h, p, err := net.SplitHostPort(address)
|
h, p, err := net.SplitHostPort(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+7
@@ -10,6 +10,7 @@ import (
|
|||||||
"crypto/hmac"
|
"crypto/hmac"
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
|
"crypto/sha512"
|
||||||
"hash"
|
"hash"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -46,9 +47,15 @@ func (t truncatingMAC) Size() int {
|
|||||||
func (t truncatingMAC) BlockSize() int { return t.hmac.BlockSize() }
|
func (t truncatingMAC) BlockSize() int { return t.hmac.BlockSize() }
|
||||||
|
|
||||||
var macModes = map[string]*macMode{
|
var macModes = map[string]*macMode{
|
||||||
|
"[email protected]": {64, true, func(key []byte) hash.Hash {
|
||||||
|
return hmac.New(sha512.New, key)
|
||||||
|
}},
|
||||||
"[email protected]": {32, true, func(key []byte) hash.Hash {
|
"[email protected]": {32, true, func(key []byte) hash.Hash {
|
||||||
return hmac.New(sha256.New, key)
|
return hmac.New(sha256.New, key)
|
||||||
}},
|
}},
|
||||||
|
"hmac-sha2-512": {64, false, func(key []byte) hash.Hash {
|
||||||
|
return hmac.New(sha512.New, key)
|
||||||
|
}},
|
||||||
"hmac-sha2-256": {32, false, func(key []byte) hash.Hash {
|
"hmac-sha2-256": {32, false, func(key []byte) hash.Hash {
|
||||||
return hmac.New(sha256.New, key)
|
return hmac.New(sha256.New, key)
|
||||||
}},
|
}},
|
||||||
|
|||||||
+15
-1
@@ -68,7 +68,7 @@ type kexInitMsg struct {
|
|||||||
|
|
||||||
// See RFC 4253, section 8.
|
// See RFC 4253, section 8.
|
||||||
|
|
||||||
// Diffie-Helman
|
// Diffie-Hellman
|
||||||
const msgKexDHInit = 30
|
const msgKexDHInit = 30
|
||||||
|
|
||||||
type kexDHInitMsg struct {
|
type kexDHInitMsg struct {
|
||||||
@@ -349,6 +349,20 @@ type userAuthGSSAPIError struct {
|
|||||||
LanguageTag string
|
LanguageTag string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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"`
|
||||||
|
}
|
||||||
|
|
||||||
// typeTags returns the possible type bytes for the given reflect.Type, which
|
// typeTags returns the possible type bytes for the given reflect.Type, which
|
||||||
// should be a struct. The possible values are separated by a '|' character.
|
// should be a struct. The possible values are separated by a '|' character.
|
||||||
func typeTags(structType reflect.Type) (tags []byte) {
|
func typeTags(structType reflect.Type) (tags []byte) {
|
||||||
|
|||||||
+6
@@ -231,6 +231,12 @@ func (m *mux) onePacket() error {
|
|||||||
return m.handleChannelOpen(packet)
|
return m.handleChannelOpen(packet)
|
||||||
case msgGlobalRequest, msgRequestSuccess, msgRequestFailure:
|
case msgGlobalRequest, msgRequestSuccess, msgRequestFailure:
|
||||||
return m.handleGlobalPacket(packet)
|
return m.handleGlobalPacket(packet)
|
||||||
|
case msgPing:
|
||||||
|
var msg pingMsg
|
||||||
|
if err := Unmarshal(packet, &msg); err != nil {
|
||||||
|
return fmt.Errorf("failed to unmarshal [email protected] message: %w", err)
|
||||||
|
}
|
||||||
|
return m.sendMessage(pongMsg(msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
// assume a channel packet.
|
// assume a channel packet.
|
||||||
|
|||||||
+66
-16
@@ -64,12 +64,27 @@ type ServerConfig struct {
|
|||||||
// Config contains configuration shared between client and server.
|
// Config contains configuration shared between client and server.
|
||||||
Config
|
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
|
hostKeys []Signer
|
||||||
|
|
||||||
// NoClientAuth is true if clients are allowed to connect without
|
// NoClientAuth is true if clients are allowed to connect without
|
||||||
// authenticating.
|
// authenticating.
|
||||||
|
// To determine NoClientAuth at runtime, set NoClientAuth to true
|
||||||
|
// and the optional NoClientAuthCallback to a non-nil value.
|
||||||
NoClientAuth bool
|
NoClientAuth bool
|
||||||
|
|
||||||
|
// NoClientAuthCallback, if non-nil, is called when a user
|
||||||
|
// attempts to authenticate with auth method "none".
|
||||||
|
// NoClientAuth must also be set to true for this be used, or
|
||||||
|
// this func is unused.
|
||||||
|
NoClientAuthCallback func(ConnMetadata) (*Permissions, error)
|
||||||
|
|
||||||
// MaxAuthTries specifies the maximum number of authentication attempts
|
// MaxAuthTries specifies the maximum number of authentication attempts
|
||||||
// permitted per connection. If set to a negative number, the number of
|
// permitted per connection. If set to a negative number, the number of
|
||||||
// attempts are unlimited. If set to zero, the number of attempts are limited
|
// attempts are unlimited. If set to zero, the number of attempts are limited
|
||||||
@@ -193,9 +208,20 @@ func NewServerConn(c net.Conn, config *ServerConfig) (*ServerConn, <-chan NewCha
|
|||||||
if fullConf.MaxAuthTries == 0 {
|
if fullConf.MaxAuthTries == 0 {
|
||||||
fullConf.MaxAuthTries = 6
|
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
|
// Check if the config contains any unsupported key exchanges
|
||||||
for _, kex := range fullConf.KeyExchanges {
|
for _, kex := range fullConf.KeyExchanges {
|
||||||
if _, ok := serverForbiddenKexAlgos[kex]; ok {
|
if _, ok := serverForbiddenKexAlgos[kex]; ok {
|
||||||
|
c.Close()
|
||||||
return nil, nil, nil, fmt.Errorf("ssh: unsupported key exchange %s for server", kex)
|
return nil, nil, nil, fmt.Errorf("ssh: unsupported key exchange %s for server", kex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -283,15 +309,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")
|
||||||
@@ -322,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)
|
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) {
|
sessionID []byte, userAuthReq userAuthRequestMsg) (authErr error, perms *Permissions, err error) {
|
||||||
gssAPIServer := gssapiConfig.Server
|
gssAPIServer := gssapiConfig.Server
|
||||||
defer gssAPIServer.DeleteSecContext()
|
defer gssAPIServer.DeleteSecContext()
|
||||||
@@ -332,7 +349,7 @@ func gssExchangeToken(gssapiConfig *GSSAPIWithMICConfig, firstToken []byte, s *c
|
|||||||
outToken []byte
|
outToken []byte
|
||||||
needContinue bool
|
needContinue bool
|
||||||
)
|
)
|
||||||
outToken, srcName, needContinue, err = gssAPIServer.AcceptSecContext(firstToken)
|
outToken, srcName, needContinue, err = gssAPIServer.AcceptSecContext(token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err, nil, nil
|
return err, nil, nil
|
||||||
}
|
}
|
||||||
@@ -354,6 +371,7 @@ func gssExchangeToken(gssapiConfig *GSSAPIWithMICConfig, firstToken []byte, s *c
|
|||||||
if err := Unmarshal(packet, userAuthGSSAPITokenReq); err != nil {
|
if err := Unmarshal(packet, userAuthGSSAPITokenReq); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
token = userAuthGSSAPITokenReq.Token
|
||||||
}
|
}
|
||||||
packet, err := s.transport.readPacket()
|
packet, err := s.transport.readPacket()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -371,6 +389,25 @@ func gssExchangeToken(gssapiConfig *GSSAPIWithMICConfig, firstToken []byte, s *c
|
|||||||
return authErr, perms, nil
|
return authErr, perms, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isAlgoCompatible checks if the signature format is compatible with the
|
||||||
|
// selected algorithm taking into account edge cases that occur with old
|
||||||
|
// clients.
|
||||||
|
func isAlgoCompatible(algo, sigFormat string) bool {
|
||||||
|
// Compatibility for old clients.
|
||||||
|
//
|
||||||
|
// For certificate authentication with OpenSSH 7.2-7.7 signature format can
|
||||||
|
// be rsa-sha2-256 or rsa-sha2-512 for the algorithm
|
||||||
|
// [email protected].
|
||||||
|
//
|
||||||
|
// With gpg-agent < 2.2.6 the algorithm can be rsa-sha2-256 or rsa-sha2-512
|
||||||
|
// for signature format ssh-rsa.
|
||||||
|
if isRSA(algo) && isRSA(sigFormat) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
// Standard case: the underlying algorithm must match the signature format.
|
||||||
|
return underlyingAlgo(algo) == sigFormat
|
||||||
|
}
|
||||||
|
|
||||||
// ServerAuthError represents server authentication errors and is
|
// ServerAuthError represents server authentication errors and is
|
||||||
// sometimes returned by NewServerConn. It appends any authentication
|
// sometimes returned by NewServerConn. It appends any authentication
|
||||||
// errors that may occur, and is returned if all of the authentication
|
// errors that may occur, and is returned if all of the authentication
|
||||||
@@ -455,7 +492,11 @@ userAuthLoop:
|
|||||||
switch userAuthReq.Method {
|
switch userAuthReq.Method {
|
||||||
case "none":
|
case "none":
|
||||||
if config.NoClientAuth {
|
if config.NoClientAuth {
|
||||||
authErr = nil
|
if config.NoClientAuthCallback != nil {
|
||||||
|
perms, authErr = config.NoClientAuthCallback(s)
|
||||||
|
} else {
|
||||||
|
authErr = nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// allow initial attempt of 'none' without penalty
|
// allow initial attempt of 'none' without penalty
|
||||||
@@ -502,7 +543,7 @@ userAuthLoop:
|
|||||||
return nil, parseError(msgUserAuthRequest)
|
return nil, parseError(msgUserAuthRequest)
|
||||||
}
|
}
|
||||||
algo := string(algoBytes)
|
algo := string(algoBytes)
|
||||||
if !isAcceptableAlgo(algo) {
|
if !contains(config.PublicKeyAuthAlgorithms, underlyingAlgo(algo)) {
|
||||||
authErr = fmt.Errorf("ssh: algorithm %q not accepted", algo)
|
authErr = fmt.Errorf("ssh: algorithm %q not accepted", algo)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -554,17 +595,26 @@ userAuthLoop:
|
|||||||
if !ok || len(payload) > 0 {
|
if !ok || len(payload) > 0 {
|
||||||
return nil, parseError(msgUserAuthRequest)
|
return nil, parseError(msgUserAuthRequest)
|
||||||
}
|
}
|
||||||
|
// Ensure the declared public key algo is compatible with the
|
||||||
|
// decoded one. This check will ensure we don't accept e.g.
|
||||||
|
// [email protected] algorithm with ssh-rsa public
|
||||||
|
// key type. The algorithm and public key type must be
|
||||||
|
// consistent: both must be certificate algorithms, or neither.
|
||||||
|
if !contains(algorithmsForKeyFormat(pubKey.Type()), algo) {
|
||||||
|
authErr = fmt.Errorf("ssh: public key type %q not compatible with selected algorithm %q",
|
||||||
|
pubKey.Type(), algo)
|
||||||
|
break
|
||||||
|
}
|
||||||
// Ensure the public key algo and signature algo
|
// Ensure the public key algo and signature algo
|
||||||
// are supported. Compare the private key
|
// are supported. Compare the private key
|
||||||
// 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(config.PublicKeyAuthAlgorithms, sig.Format) {
|
||||||
authErr = fmt.Errorf("ssh: algorithm %q not accepted", sig.Format)
|
authErr = fmt.Errorf("ssh: algorithm %q not accepted", sig.Format)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if underlyingAlgo(algo) != sig.Format {
|
if !isAlgoCompatible(algo, sig.Format) {
|
||||||
authErr = fmt.Errorf("ssh: signature %q not compatible with selected algorithm %q", sig.Format, algo)
|
authErr = fmt.Errorf("ssh: signature %q not compatible with selected algorithm %q", sig.Format, algo)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-4
@@ -13,7 +13,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -124,7 +123,7 @@ type Session struct {
|
|||||||
// output and error.
|
// output and error.
|
||||||
//
|
//
|
||||||
// If either is nil, Run connects the corresponding file
|
// If either is nil, Run connects the corresponding file
|
||||||
// descriptor to an instance of ioutil.Discard. There is a
|
// descriptor to an instance of io.Discard. There is a
|
||||||
// fixed amount of buffering that is shared for the two streams.
|
// fixed amount of buffering that is shared for the two streams.
|
||||||
// If either blocks it may eventually cause the remote
|
// If either blocks it may eventually cause the remote
|
||||||
// command to block.
|
// command to block.
|
||||||
@@ -506,7 +505,7 @@ func (s *Session) stdout() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if s.Stdout == nil {
|
if s.Stdout == nil {
|
||||||
s.Stdout = ioutil.Discard
|
s.Stdout = io.Discard
|
||||||
}
|
}
|
||||||
s.copyFuncs = append(s.copyFuncs, func() error {
|
s.copyFuncs = append(s.copyFuncs, func() error {
|
||||||
_, err := io.Copy(s.Stdout, s.ch)
|
_, err := io.Copy(s.Stdout, s.ch)
|
||||||
@@ -519,7 +518,7 @@ func (s *Session) stderr() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if s.Stderr == nil {
|
if s.Stderr == nil {
|
||||||
s.Stderr = ioutil.Discard
|
s.Stderr = io.Discard
|
||||||
}
|
}
|
||||||
s.copyFuncs = append(s.copyFuncs, func() error {
|
s.copyFuncs = append(s.copyFuncs, func() error {
|
||||||
_, err := io.Copy(s.Stderr, s.ch.Stderr())
|
_, err := io.Copy(s.Stderr, s.ch.Stderr())
|
||||||
|
|||||||
+35
@@ -5,6 +5,7 @@
|
|||||||
package ssh
|
package ssh
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@@ -332,6 +333,40 @@ func (l *tcpListener) Addr() net.Addr {
|
|||||||
return l.laddr
|
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.
|
// Dial initiates a connection to the addr from the remote host.
|
||||||
// The resulting connection has a zero LocalAddr() and RemoteAddr().
|
// The resulting connection has a zero LocalAddr() and RemoteAddr().
|
||||||
func (c *Client) Dial(n, addr string) (net.Conn, error) {
|
func (c *Client) Dial(n, addr string) (net.Conn, error) {
|
||||||
|
|||||||
+29
-6
@@ -17,7 +17,8 @@ import (
|
|||||||
const debugTransport = false
|
const debugTransport = false
|
||||||
|
|
||||||
const (
|
const (
|
||||||
gcmCipherID = "[email protected]"
|
gcm128CipherID = "[email protected]"
|
||||||
|
gcm256CipherID = "[email protected]"
|
||||||
aes128cbcID = "aes128-cbc"
|
aes128cbcID = "aes128-cbc"
|
||||||
tripledescbcID = "3des-cbc"
|
tripledescbcID = "3des-cbc"
|
||||||
)
|
)
|
||||||
@@ -48,6 +49,9 @@ type transport struct {
|
|||||||
rand io.Reader
|
rand io.Reader
|
||||||
isClient bool
|
isClient bool
|
||||||
io.Closer
|
io.Closer
|
||||||
|
|
||||||
|
strictMode bool
|
||||||
|
initialKEXDone bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// packetCipher represents a combination of SSH encryption/MAC
|
// packetCipher represents a combination of SSH encryption/MAC
|
||||||
@@ -73,6 +77,18 @@ type connectionState struct {
|
|||||||
pendingKeyChange chan packetCipher
|
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
|
// prepareKeyChange sets up key material for a keychange. The key changes in
|
||||||
// both directions are triggered by reading and writing a msgNewKey packet
|
// both directions are triggered by reading and writing a msgNewKey packet
|
||||||
// respectively.
|
// respectively.
|
||||||
@@ -111,11 +127,12 @@ func (t *transport) printPacket(p []byte, write bool) {
|
|||||||
// Read and decrypt next packet.
|
// Read and decrypt next packet.
|
||||||
func (t *transport) readPacket() (p []byte, err error) {
|
func (t *transport) readPacket() (p []byte, err error) {
|
||||||
for {
|
for {
|
||||||
p, err = t.reader.readPacket(t.bufReader)
|
p, err = t.reader.readPacket(t.bufReader, t.strictMode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
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
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -126,7 +143,7 @@ func (t *transport) readPacket() (p []byte, err error) {
|
|||||||
return p, err
|
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)
|
packet, err := s.packetCipher.readCipherPacket(s.seqNum, r)
|
||||||
s.seqNum++
|
s.seqNum++
|
||||||
if err == nil && len(packet) == 0 {
|
if err == nil && len(packet) == 0 {
|
||||||
@@ -139,6 +156,9 @@ func (s *connectionState) readPacket(r *bufio.Reader) ([]byte, error) {
|
|||||||
select {
|
select {
|
||||||
case cipher := <-s.pendingKeyChange:
|
case cipher := <-s.pendingKeyChange:
|
||||||
s.packetCipher = cipher
|
s.packetCipher = cipher
|
||||||
|
if strictMode {
|
||||||
|
s.seqNum = 0
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("ssh: got bogus newkeys message")
|
return nil, errors.New("ssh: got bogus newkeys message")
|
||||||
}
|
}
|
||||||
@@ -169,10 +189,10 @@ func (t *transport) writePacket(packet []byte) error {
|
|||||||
if debugTransport {
|
if debugTransport {
|
||||||
t.printPacket(packet, true)
|
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
|
changeKeys := len(packet) > 0 && packet[0] == msgNewKeys
|
||||||
|
|
||||||
err := s.packetCipher.writeCipherPacket(s.seqNum, w, rand, packet)
|
err := s.packetCipher.writeCipherPacket(s.seqNum, w, rand, packet)
|
||||||
@@ -187,6 +207,9 @@ func (s *connectionState) writePacket(w *bufio.Writer, rand io.Reader, packet []
|
|||||||
select {
|
select {
|
||||||
case cipher := <-s.pendingKeyChange:
|
case cipher := <-s.pendingKeyChange:
|
||||||
s.packetCipher = cipher
|
s.packetCipher = cipher
|
||||||
|
if strictMode {
|
||||||
|
s.seqNum = 0
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
panic("ssh: no key material for msgNewKeys")
|
panic("ssh: no key material for msgNewKeys")
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -289,7 +289,7 @@ func (up *UsernamePassword) Authenticate(ctx context.Context, rw io.ReadWriter,
|
|||||||
case AuthMethodNotRequired:
|
case AuthMethodNotRequired:
|
||||||
return nil
|
return nil
|
||||||
case AuthMethodUsernamePassword:
|
case AuthMethodUsernamePassword:
|
||||||
if len(up.Username) == 0 || len(up.Username) > 255 || len(up.Password) == 0 || len(up.Password) > 255 {
|
if len(up.Username) == 0 || len(up.Username) > 255 || len(up.Password) > 255 {
|
||||||
return errors.New("invalid username/password")
|
return errors.New("invalid username/password")
|
||||||
}
|
}
|
||||||
b := []byte{authUsernamePasswordVersion}
|
b := []byte{authUsernamePasswordVersion}
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build gc
|
//go:build gc
|
||||||
// +build gc
|
|
||||||
|
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -38,7 +38,7 @@ var X86 struct {
|
|||||||
HasAVX512F bool // Advanced vector extension 512 Foundation Instructions
|
HasAVX512F bool // Advanced vector extension 512 Foundation Instructions
|
||||||
HasAVX512CD bool // Advanced vector extension 512 Conflict Detection Instructions
|
HasAVX512CD bool // Advanced vector extension 512 Conflict Detection Instructions
|
||||||
HasAVX512ER bool // Advanced vector extension 512 Exponential and Reciprocal Instructions
|
HasAVX512ER bool // Advanced vector extension 512 Exponential and Reciprocal Instructions
|
||||||
HasAVX512PF bool // Advanced vector extension 512 Prefetch Instructions Instructions
|
HasAVX512PF bool // Advanced vector extension 512 Prefetch Instructions
|
||||||
HasAVX512VL bool // Advanced vector extension 512 Vector Length Extensions
|
HasAVX512VL bool // Advanced vector extension 512 Vector Length Extensions
|
||||||
HasAVX512BW bool // Advanced vector extension 512 Byte and Word Instructions
|
HasAVX512BW bool // Advanced vector extension 512 Byte and Word Instructions
|
||||||
HasAVX512DQ bool // Advanced vector extension 512 Doubleword and Quadword Instructions
|
HasAVX512DQ bool // Advanced vector extension 512 Doubleword and Quadword Instructions
|
||||||
@@ -54,6 +54,9 @@ var X86 struct {
|
|||||||
HasAVX512VBMI2 bool // Advanced vector extension 512 Vector Byte Manipulation Instructions 2
|
HasAVX512VBMI2 bool // Advanced vector extension 512 Vector Byte Manipulation Instructions 2
|
||||||
HasAVX512BITALG bool // Advanced vector extension 512 Bit Algorithms
|
HasAVX512BITALG bool // Advanced vector extension 512 Bit Algorithms
|
||||||
HasAVX512BF16 bool // Advanced vector extension 512 BFloat16 Instructions
|
HasAVX512BF16 bool // Advanced vector extension 512 BFloat16 Instructions
|
||||||
|
HasAMXTile bool // Advanced Matrix Extension Tile instructions
|
||||||
|
HasAMXInt8 bool // Advanced Matrix Extension Int8 instructions
|
||||||
|
HasAMXBF16 bool // Advanced Matrix Extension BFloat16 instructions
|
||||||
HasBMI1 bool // Bit manipulation instruction set 1
|
HasBMI1 bool // Bit manipulation instruction set 1
|
||||||
HasBMI2 bool // Bit manipulation instruction set 2
|
HasBMI2 bool // Bit manipulation instruction set 2
|
||||||
HasCX16 bool // Compare and exchange 16 Bytes
|
HasCX16 bool // Compare and exchange 16 Bytes
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build aix
|
//go:build aix
|
||||||
// +build aix
|
|
||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build gc
|
//go:build gc
|
||||||
// +build gc
|
|
||||||
|
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build gc
|
//go:build gc
|
||||||
// +build gc
|
|
||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build gc
|
//go:build gc
|
||||||
// +build gc
|
|
||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
|
|||||||
-2
@@ -3,8 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build (386 || amd64 || amd64p32) && gc
|
//go:build (386 || amd64 || amd64p32) && gc
|
||||||
// +build 386 amd64 amd64p32
|
|
||||||
// +build gc
|
|
||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build gccgo
|
//go:build gccgo
|
||||||
// +build gccgo
|
|
||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build gccgo
|
//go:build gccgo
|
||||||
// +build gccgo
|
|
||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
|
|||||||
-2
@@ -3,8 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build (386 || amd64 || amd64p32) && gccgo
|
//go:build (386 || amd64 || amd64p32) && gccgo
|
||||||
// +build 386 amd64 amd64p32
|
|
||||||
// +build gccgo
|
|
||||||
|
|
||||||
#include <cpuid.h>
|
#include <cpuid.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|||||||
-2
@@ -3,8 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build (386 || amd64 || amd64p32) && gccgo
|
//go:build (386 || amd64 || amd64p32) && gccgo
|
||||||
// +build 386 amd64 amd64p32
|
|
||||||
// +build gccgo
|
|
||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build !386 && !amd64 && !amd64p32 && !arm64
|
//go:build !386 && !amd64 && !amd64p32 && !arm64
|
||||||
// +build !386,!amd64,!amd64p32,!arm64
|
|
||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
|
|||||||
-2
@@ -3,8 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build linux && (mips64 || mips64le)
|
//go:build linux && (mips64 || mips64le)
|
||||||
// +build linux
|
|
||||||
// +build mips64 mips64le
|
|
||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build linux && !arm && !arm64 && !mips64 && !mips64le && !ppc64 && !ppc64le && !s390x
|
//go:build linux && !arm && !arm64 && !mips64 && !mips64le && !ppc64 && !ppc64le && !s390x
|
||||||
// +build linux,!arm,!arm64,!mips64,!mips64le,!ppc64,!ppc64le,!s390x
|
|
||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
|
|||||||
-2
@@ -3,8 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build linux && (ppc64 || ppc64le)
|
//go:build linux && (ppc64 || ppc64le)
|
||||||
// +build linux
|
|
||||||
// +build ppc64 ppc64le
|
|
||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build loong64
|
//go:build loong64
|
||||||
// +build loong64
|
|
||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build mips64 || mips64le
|
//go:build mips64 || mips64le
|
||||||
// +build mips64 mips64le
|
|
||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build mips || mipsle
|
//go:build mips || mipsle
|
||||||
// +build mips mipsle
|
|
||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build !linux && arm
|
//go:build !linux && arm
|
||||||
// +build !linux,arm
|
|
||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build !linux && !netbsd && !openbsd && arm64
|
//go:build !linux && !netbsd && !openbsd && arm64
|
||||||
// +build !linux,!netbsd,!openbsd,arm64
|
|
||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
|
|||||||
-2
@@ -3,8 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build !linux && (mips64 || mips64le)
|
//go:build !linux && (mips64 || mips64le)
|
||||||
// +build !linux
|
|
||||||
// +build mips64 mips64le
|
|
||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
|
|||||||
-3
@@ -3,9 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build !aix && !linux && (ppc64 || ppc64le)
|
//go:build !aix && !linux && (ppc64 || ppc64le)
|
||||||
// +build !aix
|
|
||||||
// +build !linux
|
|
||||||
// +build ppc64 ppc64le
|
|
||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build !linux && riscv64
|
//go:build !linux && riscv64
|
||||||
// +build !linux,riscv64
|
|
||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build ppc64 || ppc64le
|
//go:build ppc64 || ppc64le
|
||||||
// +build ppc64 ppc64le
|
|
||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -3,10 +3,9 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build riscv64
|
//go:build riscv64
|
||||||
// +build riscv64
|
|
||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
const cacheLineSize = 32
|
const cacheLineSize = 64
|
||||||
|
|
||||||
func initOptions() {}
|
func initOptions() {}
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build gc
|
//go:build gc
|
||||||
// +build gc
|
|
||||||
|
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build wasm
|
//go:build wasm
|
||||||
// +build wasm
|
|
||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
|
|||||||
+7
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build 386 || amd64 || amd64p32
|
//go:build 386 || amd64 || amd64p32
|
||||||
// +build 386 amd64 amd64p32
|
|
||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
@@ -37,6 +36,9 @@ func initOptions() {
|
|||||||
{Name: "avx512vbmi2", Feature: &X86.HasAVX512VBMI2},
|
{Name: "avx512vbmi2", Feature: &X86.HasAVX512VBMI2},
|
||||||
{Name: "avx512bitalg", Feature: &X86.HasAVX512BITALG},
|
{Name: "avx512bitalg", Feature: &X86.HasAVX512BITALG},
|
||||||
{Name: "avx512bf16", Feature: &X86.HasAVX512BF16},
|
{Name: "avx512bf16", Feature: &X86.HasAVX512BF16},
|
||||||
|
{Name: "amxtile", Feature: &X86.HasAMXTile},
|
||||||
|
{Name: "amxint8", Feature: &X86.HasAMXInt8},
|
||||||
|
{Name: "amxbf16", Feature: &X86.HasAMXBF16},
|
||||||
{Name: "bmi1", Feature: &X86.HasBMI1},
|
{Name: "bmi1", Feature: &X86.HasBMI1},
|
||||||
{Name: "bmi2", Feature: &X86.HasBMI2},
|
{Name: "bmi2", Feature: &X86.HasBMI2},
|
||||||
{Name: "cx16", Feature: &X86.HasCX16},
|
{Name: "cx16", Feature: &X86.HasCX16},
|
||||||
@@ -138,6 +140,10 @@ func archInit() {
|
|||||||
eax71, _, _, _ := cpuid(7, 1)
|
eax71, _, _, _ := cpuid(7, 1)
|
||||||
X86.HasAVX512BF16 = isSet(5, eax71)
|
X86.HasAVX512BF16 = isSet(5, eax71)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
X86.HasAMXTile = isSet(24, edx7)
|
||||||
|
X86.HasAMXInt8 = isSet(25, edx7)
|
||||||
|
X86.HasAMXBF16 = isSet(22, edx7)
|
||||||
}
|
}
|
||||||
|
|
||||||
func isSet(bitpos uint, value uint32) bool {
|
func isSet(bitpos uint, value uint32) bool {
|
||||||
|
|||||||
-2
@@ -3,8 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build (386 || amd64 || amd64p32) && gc
|
//go:build (386 || amd64 || amd64p32) && gc
|
||||||
// +build 386 amd64 amd64p32
|
|
||||||
// +build gc
|
|
||||||
|
|
||||||
#include "textflag.h"
|
#include "textflag.h"
|
||||||
|
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build armbe || arm64be || m68k || mips || mips64 || mips64p32 || ppc || ppc64 || s390 || s390x || shbe || sparc || sparc64
|
//go:build armbe || arm64be || m68k || mips || mips64 || mips64p32 || ppc || ppc64 || s390 || s390x || shbe || sparc || sparc64
|
||||||
// +build armbe arm64be m68k mips mips64 mips64p32 ppc ppc64 s390 s390x shbe sparc sparc64
|
|
||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -2,8 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build 386 || amd64 || amd64p32 || alpha || arm || arm64 || loong64 || mipsle || mips64le || mips64p32le || nios2 || ppc64le || riscv || riscv64 || sh
|
//go:build 386 || amd64 || amd64p32 || alpha || arm || arm64 || loong64 || mipsle || mips64le || mips64p32le || nios2 || ppc64le || riscv || riscv64 || sh || wasm
|
||||||
// +build 386 amd64 amd64p32 alpha arm arm64 loong64 mipsle mips64le mips64p32le nios2 ppc64le riscv riscv64 sh
|
|
||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
|
|||||||
+17
-2
@@ -5,7 +5,7 @@
|
|||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -24,7 +24,22 @@ var hwCap uint
|
|||||||
var hwCap2 uint
|
var hwCap2 uint
|
||||||
|
|
||||||
func readHWCAP() error {
|
func readHWCAP() error {
|
||||||
buf, err := ioutil.ReadFile(procAuxv)
|
// For Go 1.21+, get auxv from the Go runtime.
|
||||||
|
if a := getAuxv(); len(a) > 0 {
|
||||||
|
for len(a) >= 2 {
|
||||||
|
tag, val := a[0], uint(a[1])
|
||||||
|
a = a[2:]
|
||||||
|
switch tag {
|
||||||
|
case _AT_HWCAP:
|
||||||
|
hwCap = val
|
||||||
|
case _AT_HWCAP2:
|
||||||
|
hwCap2 = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
buf, err := os.ReadFile(procAuxv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// e.g. on android /proc/self/auxv is not accessible, so silently
|
// e.g. on android /proc/self/auxv is not accessible, so silently
|
||||||
// ignore the error and leave Initialized = false. On some
|
// ignore the error and leave Initialized = false. On some
|
||||||
|
|||||||
-1
@@ -3,7 +3,6 @@
|
|||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build linux && arm64
|
//go:build linux && arm64
|
||||||
// +build linux,arm64
|
|
||||||
|
|
||||||
package cpu
|
package cpu
|
||||||
|
|
||||||
|
|||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
// Copyright 2023 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 cpu
|
||||||
|
|
||||||
|
// getAuxvFn is non-nil on Go 1.21+ (via runtime_auxv_go121.go init)
|
||||||
|
// on platforms that use auxv.
|
||||||
|
var getAuxvFn func() []uintptr
|
||||||
|
|
||||||
|
func getAuxv() []uintptr {
|
||||||
|
if getAuxvFn == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return getAuxvFn()
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user