blob: 5dafe438c76339f2cf6c3ff8a768e72458560055 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef QUICHE_QUIC_CORE_CRYPTO_CERT_COMPRESSOR_H_
6#define QUICHE_QUIC_CORE_CRYPTO_CERT_COMPRESSOR_H_
7
vasilvv872e7a32019-03-12 16:42:44 -07008#include <string>
QUICHE teama6ef0a62019-03-07 20:34:33 -05009#include <vector>
10
11#include "base/macros.h"
12#include "net/third_party/quiche/src/quic/core/crypto/common_cert_set.h"
13#include "net/third_party/quiche/src/quic/core/crypto/crypto_protocol.h"
14#include "net/third_party/quiche/src/quic/platform/api/quic_export.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050015#include "net/third_party/quiche/src/quic/platform/api/quic_string_piece.h"
16
17namespace quic {
18
19// CertCompressor provides functions for compressing and decompressing
20// certificate chains using three techniquies:
21// 1) The peer may provide a list of a 64-bit, FNV-1a hashes of certificates
22// that they already have. In the event that one of them is to be
23// compressed, it can be replaced with just the hash.
24// 2) The peer may provide a number of hashes that represent sets of
25// pre-shared certificates (CommonCertSets). If one of those certificates
26// is to be compressed, and it's known to the given CommonCertSets, then it
27// can be replaced with a set hash and certificate index.
28// 3) Otherwise the certificates are compressed with zlib using a pre-shared
29// dictionary that consists of the certificates handled with the above
30// methods and a small chunk of common substrings.
31class QUIC_EXPORT_PRIVATE CertCompressor {
32 public:
33 CertCompressor() = delete;
34
35 // CompressChain compresses the certificates in |certs| and returns a
36 // compressed representation. |common_sets| contains the common certificate
37 // sets known locally and |client_common_set_hashes| contains the hashes of
38 // the common sets known to the peer. |client_cached_cert_hashes| contains
39 // 64-bit, FNV-1a hashes of certificates that the peer already possesses.
vasilvvc48c8712019-03-11 13:38:16 -070040 static std::string CompressChain(const std::vector<std::string>& certs,
41 QuicStringPiece client_common_set_hashes,
42 QuicStringPiece client_cached_cert_hashes,
43 const CommonCertSets* common_sets);
QUICHE teama6ef0a62019-03-07 20:34:33 -050044
45 // DecompressChain decompresses the result of |CompressChain|, given in |in|,
46 // into a series of certificates that are written to |out_certs|.
47 // |cached_certs| contains certificates that the peer may have omitted and
48 // |common_sets| contains the common certificate sets known locally.
49 static bool DecompressChain(QuicStringPiece in,
vasilvvc48c8712019-03-11 13:38:16 -070050 const std::vector<std::string>& cached_certs,
QUICHE teama6ef0a62019-03-07 20:34:33 -050051 const CommonCertSets* common_sets,
vasilvvc48c8712019-03-11 13:38:16 -070052 std::vector<std::string>* out_certs);
QUICHE teama6ef0a62019-03-07 20:34:33 -050053};
54
55} // namespace quic
56
57#endif // QUICHE_QUIC_CORE_CRYPTO_CERT_COMPRESSOR_H_