read source address token and server nonce from SHLO

This commit is contained in:
Marten Seemann
2016-11-10 17:42:31 +07:00
parent 5b72a535d0
commit dbee83b8de
2 changed files with 41 additions and 0 deletions

View File

@@ -21,6 +21,9 @@ type cryptoSetupClient struct {
cryptoStream utils.Stream
serverConfig *serverConfigClient
stk []byte
sno []byte
diversificationNonce []byte
}
@@ -67,8 +70,27 @@ func (h *cryptoSetupClient) HandleCryptoStream() error {
utils.Debugf("Got SHLO:\n%s", printHandshakeMessage(cryptoData))
panic("SHLOs not yet implemented.")
}
if messageTag == TagREJ {
err = h.handleREJMessage(cryptoData)
if err != nil {
return err
}
}
}
}
func (h *cryptoSetupClient) handleREJMessage(cryptoData map[Tag][]byte) error {
utils.Debugf("Got REJ:\n%s", printHandshakeMessage(cryptoData))
if stk, ok := cryptoData[TagSTK]; ok {
h.stk = stk
}
if sno, ok := cryptoData[TagSNO]; ok {
h.sno = sno
}
return nil
}
func (h *cryptoSetupClient) Open(dst, src []byte, packetNumber protocol.PacketNumber, associatedData []byte) ([]byte, error) {
return (&crypto.NullAEAD{}).Open(dst, src, packetNumber, associatedData)

View File

@@ -43,6 +43,25 @@ var _ = Describe("Crypto setup", func() {
// note that if this was a complete handshake message, HandleCryptoStream would fail with a qerr.InvalidCryptoMessageType
Expect(err).To(MatchError(qerr.HandshakeFailed))
})
It("passes the message on for parsing, and reads the source address token", func() {
stk := []byte("foobar")
tagMap[TagSTK] = stk
WriteHandshakeMessage(&stream.dataToRead, TagREJ, tagMap)
// this will throw a qerr.HandshakeFailed due to an EOF in WriteHandshakeMessage
// this is because the mockStream doesn't block if there's no data to read
err := cs.HandleCryptoStream()
Expect(err).To(MatchError(qerr.HandshakeFailed))
Expect(cs.stk).Should(Equal(stk))
})
It("saves the server nonce", func() {
nonc := []byte("servernonce")
tagMap[TagSNO] = nonc
err := cs.handleREJMessage(tagMap)
Expect(err).ToNot(HaveOccurred())
Expect(cs.sno).To(Equal(nonc))
})
})
Context("CHLO generation", func() {