QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // 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 | |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame^] | 8 | #include <string> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9 | #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 team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 15 | #include "net/third_party/quiche/src/quic/platform/api/quic_string_piece.h" |
| 16 | |
| 17 | namespace 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. |
| 31 | class 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. |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 40 | 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 team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 44 | |
| 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, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 50 | const std::vector<std::string>& cached_certs, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 51 | const CommonCertSets* common_sets, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 52 | std::vector<std::string>* out_certs); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | } // namespace quic |
| 56 | |
| 57 | #endif // QUICHE_QUIC_CORE_CRYPTO_CERT_COMPRESSOR_H_ |