Skip to content

Commit 2146852

Browse files
authored
Merge pull request #1449 from InvisibleRain/master
Fix the MITM vulnerability
2 parents f526e74 + 9ec5b63 commit 2146852

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

app/cmd/client.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,11 @@ func (c *clientConfig) fillTLSConfig(hyConfig *client.Config) error {
275275
if c.TLS.PinSHA256 != "" {
276276
nHash := normalizeCertHash(c.TLS.PinSHA256)
277277
hyConfig.TLSConfig.VerifyPeerCertificate = func(rawCerts [][]byte, _ [][]*x509.Certificate) error {
278-
for _, cert := range rawCerts {
279-
hash := sha256.Sum256(cert)
280-
hashHex := hex.EncodeToString(hash[:])
281-
if hashHex == nHash {
282-
return nil
283-
}
278+
cert := rawCerts[0] // only check the end-entity cert hash in the chain of trust
279+
hash := sha256.Sum256(cert)
280+
hashHex := hex.EncodeToString(hash[:])
281+
if hashHex == nHash {
282+
return nil
284283
}
285284
// No match
286285
return errors.New("no certificate matches the pinned hash")

0 commit comments

Comments
 (0)