From 4a88422d9f3bac537084990d8e5d06076ea8ce00 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Fri, 2 Dec 2016 19:21:42 +0700 Subject: [PATCH] add workaround for incorrect public flag values sent by Google servers --- public_header.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/public_header.go b/public_header.go index 0e0f7379..797f130e 100644 --- a/public_header.go +++ b/public_header.go @@ -157,14 +157,19 @@ func ParsePublicHeader(b *bytes.Reader, packetSentBy protocol.Perspective) (*Pub } if packetSentBy == protocol.PerspectiveServer && publicFlagByte&0x04 > 0 { - header.DiversificationNonce = make([]byte, 32) - for i := 0; i < 32; i++ { - var val byte - val, err = b.ReadByte() - if err != nil { - return nil, err + // TODO: remove the if once the Google servers send the correct value + // assume that a packet doesn't contain a diversification nonce if the version flag or the reset flag is set, no matter what the public flag says + // see https://github.com/lucas-clemente/quic-go/issues/232 + if !header.VersionFlag && !header.ResetFlag { + header.DiversificationNonce = make([]byte, 32) + for i := 0; i < 32; i++ { + var val byte + val, err = b.ReadByte() + if err != nil { + return nil, err + } + header.DiversificationNonce[i] = val } - header.DiversificationNonce[i] = val } }