Skip to content

Commit 94c50fa

Browse files
committed
remvoe support for sha1 and md5 hashing for public keys
Signed-off-by: Sanskar Jaiswal <[email protected]>
1 parent 7501e86 commit 94c50fa

File tree

3 files changed

+6
-31
lines changed

3 files changed

+6
-31
lines changed

pkg/git/libgit2/managed/ssh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func (t *sshSmartSubtransport) Action(transportOptionsURL string, action git2go.
165165
cert := &git2go.Certificate{
166166
Kind: git2go.CertificateHostkey,
167167
Hostkey: git2go.HostkeyCertificate{
168-
Kind: git2go.HostkeySHA256,
168+
Kind: git2go.HostkeySHA256 | git2go.HostkeyRaw,
169169
HashSHA256: sha256.Sum256(marshaledKey),
170170
Hostkey: marshaledKey,
171171
SSHPublicKey: key,

pkg/git/libgit2/managed/transport.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package managed
22

33
import (
4-
"crypto/md5"
5-
"crypto/sha1"
64
"crypto/sha256"
75
"fmt"
86
"hash"
@@ -49,16 +47,8 @@ func KnownHostsCallback(host string, knownHosts []byte) git2go.CertificateCheckC
4947
case cert.Hostkey.Kind&git2go.HostkeySHA256 > 0:
5048
fingerprint = cert.Hostkey.HashSHA256[:]
5149
hasher = sha256.New()
52-
// SHA1 and MD5 are present here, because they're used for unmanaged transport.
53-
// TODO: get rid of this, when unmanaged transport is completely removed.
54-
case cert.Hostkey.Kind&git2go.HostkeySHA1 > 0:
55-
fingerprint = cert.Hostkey.HashSHA1[:]
56-
hasher = sha1.New()
57-
case cert.Hostkey.Kind&git2go.HostkeyMD5 > 0:
58-
fingerprint = cert.Hostkey.HashMD5[:]
59-
hasher = md5.New()
6050
default:
61-
return fmt.Errorf("invalid host key kind, expected to be one of SHA256, SHA1, MD5")
51+
return fmt.Errorf("invalid host key kind, expected to be of kind SHA256")
6252
}
6353

6454
// We are now certain that the configured host and the hostname

pkg/git/libgit2/managed/transport_test.go

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,31 @@ func TestKnownHostsCallback(t *testing.T) {
2929
name: "Match",
3030
host: "github.com",
3131
knownHosts: []byte(knownHostsFixture),
32-
hostkey: git2go.HostkeyCertificate{Kind: git2go.HostkeySHA1 | git2go.HostkeyMD5, HashSHA1: sha1Fingerprint("v2toJdKXfFEaR1u++4iq1UqSrHM")},
32+
hostkey: git2go.HostkeyCertificate{Kind: git2go.HostkeySHA256, HashSHA256: sha256Fingerprint("nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8")},
3333
expectedHost: "github.com",
3434
want: nil,
3535
},
3636
{
3737
name: "Match with port",
3838
host: "github.com",
3939
knownHosts: []byte(knownHostsFixture),
40-
hostkey: git2go.HostkeyCertificate{Kind: git2go.HostkeySHA1 | git2go.HostkeyMD5, HashSHA1: sha1Fingerprint("v2toJdKXfFEaR1u++4iq1UqSrHM")},
40+
hostkey: git2go.HostkeyCertificate{Kind: git2go.HostkeySHA256, HashSHA256: sha256Fingerprint("nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8")},
4141
expectedHost: "github.com:22",
4242
want: nil,
4343
},
4444
{
4545
name: "Hostname mismatch",
4646
host: "github.com",
4747
knownHosts: []byte(knownHostsFixture),
48-
hostkey: git2go.HostkeyCertificate{Kind: git2go.HostkeySHA1 | git2go.HostkeyMD5, HashSHA1: sha1Fingerprint("v2toJdKXfFEaR1u++4iq1UqSrHM")},
48+
hostkey: git2go.HostkeyCertificate{Kind: git2go.HostkeySHA256, HashSHA256: sha256Fingerprint("nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8")},
4949
expectedHost: "example.com",
5050
want: fmt.Errorf("host mismatch: %q %q", "example.com", "github.com"),
5151
},
5252
{
5353
name: "Hostkey mismatch",
5454
host: "github.com",
5555
knownHosts: []byte(knownHostsFixture),
56-
hostkey: git2go.HostkeyCertificate{Kind: git2go.HostkeyMD5, HashMD5: md5Fingerprint("\xb6\x03\x0e\x39\x97\x9e\xd0\xe7\x24\xce\xa3\x77\x3e\x01\x42\x09")},
56+
hostkey: git2go.HostkeyCertificate{Kind: git2go.HostkeySHA256, HashSHA256: sha256Fingerprint("ROQFvPThGrW4RuWLoL9tq9I9zJ42fK4XywyRtbOz/EQ")},
5757
expectedHost: "github.com",
5858
want: fmt.Errorf("hostkey could not be verified"),
5959
},
@@ -73,21 +73,6 @@ func TestKnownHostsCallback(t *testing.T) {
7373
})
7474
}
7575
}
76-
func md5Fingerprint(in string) [16]byte {
77-
var out [16]byte
78-
copy(out[:], in)
79-
return out
80-
}
81-
82-
func sha1Fingerprint(in string) [20]byte {
83-
d, err := base64.RawStdEncoding.DecodeString(in)
84-
if err != nil {
85-
panic(err)
86-
}
87-
var out [20]byte
88-
copy(out[:], d)
89-
return out
90-
}
9176

9277
func sha256Fingerprint(in string) [32]byte {
9378
d, err := base64.RawStdEncoding.DecodeString(in)

0 commit comments

Comments
 (0)