read the diversification nonce sent by the server in PublicHeader

This commit is contained in:
Marten Seemann
2016-11-07 21:37:57 +07:00
parent 56a287ab9c
commit 1cea8833c8
2 changed files with 23 additions and 0 deletions

View File

@@ -156,6 +156,18 @@ func ParsePublicHeader(b io.ByteReader, packetSentBy protocol.Perspective) (*Pub
return nil, errInvalidConnectionID
}
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
}
header.DiversificationNonce[i] = val
}
}
// Version (optional)
if header.VersionFlag && !header.ResetFlag {
var versionTag uint32

View File

@@ -49,6 +49,17 @@ var _ = Describe("Public Header", func() {
Expect(hdr.ResetFlag).To(BeTrue())
Expect(hdr.VersionFlag).To(BeFalse())
Expect(hdr.ConnectionID).To(Equal(protocol.ConnectionID(0x0807060504030201)))
})
It("reads a diversification nonce sent by the server", func() {
divNonce := []byte{0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f}
Expect(divNonce).To(HaveLen(32))
b := bytes.NewReader(append(append([]byte{0x0c, 0xf6, 0x19, 0x86, 0x66, 0x9b, 0x9f, 0xfa, 0x4c}, divNonce...), 0x37))
hdr, err := ParsePublicHeader(b, protocol.PerspectiveServer)
Expect(err).ToNot(HaveOccurred())
Expect(hdr.ConnectionID).To(Not(BeZero()))
Expect(hdr.DiversificationNonce).To(Equal(divNonce))
Expect(hdr.PacketNumber).To(Equal(protocol.PacketNumber(0x37)))
Expect(b.Len()).To(BeZero())
})