add tests for inchoate CHLO

This commit is contained in:
Marten Seemann
2016-11-08 16:24:06 +07:00
parent 651a0de9d3
commit 214a37ac39
2 changed files with 43 additions and 5 deletions

View File

@@ -36,7 +36,10 @@ func NewCryptoSetupClient(
}
func (h *cryptoSetupClient) HandleCryptoStream() error {
h.sendInchoateCHLO()
err := h.sendInchoateCHLO()
if err != nil {
return err
}
for {
var chloData bytes.Buffer
@@ -73,14 +76,19 @@ func (h *cryptoSetupClient) HandshakeComplete() bool {
return false
}
func (h *cryptoSetupClient) sendInchoateCHLO() error {
b := &bytes.Buffer{}
func (h *cryptoSetupClient) getInchoateCHLOValues() map[Tag][]byte {
tags := make(map[Tag][]byte)
tags[TagSNI] = []byte("quic.clemente.io") // TODO: use real SNI here
tags[TagPDMD] = []byte("X509")
tags[TagPAD] = bytes.Repeat([]byte("0"), 1000)
tags[TagPAD] = bytes.Repeat([]byte("0"), protocol.ClientHelloMinimumSize)
return tags
}
func (h *cryptoSetupClient) sendInchoateCHLO() error {
b := &bytes.Buffer{}
tags := h.getInchoateCHLOValues()
WriteHandshakeMessage(b, TagCHLO, tags)
_, err := h.cryptoStream.Write(b.Bytes())

View File

@@ -1 +1,31 @@
package handshake
import (
"github.com/lucas-clemente/quic-go/protocol"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Crypto setup", func() {
var cs cryptoSetupClient
BeforeEach(func() {
cs = cryptoSetupClient{
cryptoStream: &mockStream{},
}
})
Context("Inchoate CHLO", func() {
It("has the right values", func() {
tags := cs.getInchoateCHLOValues()
Expect(tags).To(HaveKey(TagSNI))
Expect(tags[TagPDMD]).To(Equal([]byte("X509")))
})
It("is longer than the miminum client hello size", func() {
err := cs.sendInchoateCHLO()
Expect(err).ToNot(HaveOccurred())
Expect(cs.cryptoStream.(*mockStream).dataWritten.Len()).To(BeNumerically(">", protocol.ClientHelloMinimumSize))
})
})
})