implement cert compression with cached certificates

This commit is contained in:
Lucas Clemente
2016-05-11 15:31:05 +02:00
parent 552efb57de
commit ea83ca8950
9 changed files with 248 additions and 72 deletions

View File

@@ -99,7 +99,7 @@ func (h *CryptoSetup) HandleCryptoStream() error {
}
// We have an inchoate or non-matching CHLO, we now send a rejection
reply, err = h.handleInchoateCHLO(sni, chloData)
reply, err = h.handleInchoateCHLO(sni, chloData, cryptoData)
if err != nil {
return err
}
@@ -164,7 +164,7 @@ func (h *CryptoSetup) isInchoateCHLO(cryptoData map[Tag][]byte) bool {
return false
}
func (h *CryptoSetup) handleInchoateCHLO(sni string, data []byte) ([]byte, error) {
func (h *CryptoSetup) handleInchoateCHLO(sni string, data []byte, cryptoData map[Tag][]byte) ([]byte, error) {
var chloOrNil []byte
if h.version > protocol.VersionNumber(30) {
chloOrNil = data
@@ -175,7 +175,10 @@ func (h *CryptoSetup) handleInchoateCHLO(sni string, data []byte) ([]byte, error
return nil, err
}
certCompressed, err := h.scfg.GetCertsCompressed(sni)
commonSetHashes := cryptoData[TagCCS]
cachedCertsHashes := cryptoData[TagCCRT]
certCompressed, err := h.scfg.GetCertsCompressed(sni, commonSetHashes, cachedCertsHashes)
if err != nil {
return nil, err
}

View File

@@ -39,7 +39,7 @@ func (s *mockSigner) SignServerProof(sni string, chlo []byte, serverConfigData [
}
return []byte("proof"), nil
}
func (*mockSigner) GetCertsCompressed(sni string) ([]byte, error) {
func (*mockSigner) GetCertsCompressed(sni string, common, cached []byte) ([]byte, error) {
return []byte("certcompressed"), nil
}
func (*mockSigner) GetLeafCert(sni string) ([]byte, error) {
@@ -125,7 +125,7 @@ var _ = Describe("Crypto setup", func() {
Context("when responding to client messages", func() {
It("generates REJ messages", func() {
response, err := cs.handleInchoateCHLO("", []byte("chlo"))
response, err := cs.handleInchoateCHLO("", []byte("chlo"), nil)
Expect(err).ToNot(HaveOccurred())
Expect(response).To(HavePrefix("REJ"))
Expect(response).To(ContainSubstring("certcompressed"))
@@ -135,7 +135,7 @@ var _ = Describe("Crypto setup", func() {
It("generates REJ messages for version 30", func() {
cs.version = protocol.VersionNumber(30)
_, err := cs.handleInchoateCHLO("", sampleCHLO)
_, err := cs.handleInchoateCHLO("", sampleCHLO, nil)
Expect(err).ToNot(HaveOccurred())
Expect(signer.gotCHLO).To(BeFalse())
})

View File

@@ -50,6 +50,6 @@ func (s *ServerConfig) Sign(sni string, chlo []byte) ([]byte, error) {
}
// GetCertsCompressed returns the certificate data
func (s *ServerConfig) GetCertsCompressed(sni string) ([]byte, error) {
return s.signer.GetCertsCompressed(sni)
func (s *ServerConfig) GetCertsCompressed(sni string, commonSetHashes, compressedHashes []byte) ([]byte, error) {
return s.signer.GetCertsCompressed(sni, commonSetHashes, compressedHashes)
}

View File

@@ -17,8 +17,10 @@ const (
TagSNI Tag = 'S' + 'N'<<8 + 'I'<<16
// TagVER is the QUIC version
TagVER Tag = 'V' + 'E'<<8 + 'R'<<16
// TagCCS is the hash of the common certificate sets
// TagCCS are the hashes of the common certificate sets
TagCCS Tag = 'C' + 'C'<<8 + 'S'<<16
// TagCCRT are the hashes of the cached certificates
TagCCRT Tag = 'C' + 'C'<<8 + 'R'<<16 + 'T'<<24
// TagMSPC is max streams per connection
TagMSPC Tag = 'M' + 'S'<<8 + 'P'<<16 + 'C'<<24
// TagUAID is the user agent ID