aboutsummaryrefslogtreecommitdiff
path: root/ssh/keys.go
diff options
context:
space:
mode:
authorAdam Langley <agl@golang.org>2018-08-31 15:38:59 -0700
committerAdam Langley <agl@golang.org>2018-09-04 16:38:35 +0000
commit0709b304e793a5edb4a2c0145f281ecdc20838a4 (patch)
tree9f46c5cf38a843e891d9c715145d1e64091dbcea /ssh/keys.go
parent182538f80094b6a8efaade63a8fd8e0d9d5843dd (diff)
downloadgo-x-crypto-0709b304e793a5edb4a2c0145f281ecdc20838a4.tar.xz
ssh: don't panic if a key is too short.
Change-Id: I810eb1c5d4cacc710a427e2ce031db1e9c292454 Reviewed-on: https://go-review.googlesource.com/132656 Run-TryBot: Adam Langley <agl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Filippo Valsorda <filippo@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'ssh/keys.go')
-rw-r--r--ssh/keys.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/ssh/keys.go b/ssh/keys.go
index 34d9582..2261dc3 100644
--- a/ssh/keys.go
+++ b/ssh/keys.go
@@ -903,8 +903,8 @@ func ParseDSAPrivateKey(der []byte) (*dsa.PrivateKey, error) {
// Implemented based on the documentation at
// https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key
func parseOpenSSHPrivateKey(key []byte) (crypto.PrivateKey, error) {
- magic := append([]byte("openssh-key-v1"), 0)
- if !bytes.Equal(magic, key[0:len(magic)]) {
+ const magic = "openssh-key-v1\x00"
+ if len(key) < len(magic) || string(key[:len(magic)]) != magic {
return nil, errors.New("ssh: invalid openssh private key format")
}
remaining := key[len(magic):]