Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Unified Diff: net/cert/ct_ev_whitelist.h

Issue 462543002: Certificate Transparency: Code for unpacking EV cert hashes whitelist (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing comments + adding method for determining presence of valid EV whitelist. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/cert/ct_ev_whitelist.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/cert/ct_ev_whitelist.h
diff --git a/net/cert/ct_ev_whitelist.h b/net/cert/ct_ev_whitelist.h
new file mode 100644
index 0000000000000000000000000000000000000000..458a988bee911e0e40717e3fb041b0be36ec0058
--- /dev/null
+++ b/net/cert/ct_ev_whitelist.h
@@ -0,0 +1,93 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_CERT_CT_EV_WHITELIST_H_
+#define NET_CERT_CT_EV_WHITELIST_H_
+
+#include <set>
+#include <string>
+
+#include "base/files/file_path.h"
+#include "net/base/net_export.h"
+
+namespace net {
+
+namespace ct {
+
+namespace internal {
+
+// Abstraction over a stream of bits, to be read independently
+// of the bytes they're packed into. Bits are read MSB-first from the stream.
+// It is limited to 64-bit reads and is inefficient as a design choice - Since
+// it is used infrequently to unpack the Golomb-coded EV certificate hashes
+// whitelist in a blocking thread.
+//
+// This class is declared here so it can be tested.
+class NET_EXPORT_PRIVATE BitStreamReader {
+ public:
+ BitStreamReader(const char* source, size_t length);
+
+ // Reads unary-encoded number into |out|. Returns true if
+ // there was at least one bit to read, false otherwise.
+ bool ReadUnaryEncoding(uint64* out);
+ // Reads |num_bits| (up to 64) into |out|. |out| is filled from the MSB to the
+ // LSB. If |num_bits| is less than 64, the most significant |64 - num_bits|
+ // bits are unused and left as zeros. Returns true if the stream had the
+ // requested |num_bits|, false otherwise.
+ bool ReadBits(uint8 num_bits, uint64* out);
+ // Returns the number of bits left in the stream.
+ uint64 BitsLeft() const;
+
+ private:
+ // Reads a single bit. Within a byte, the bits are read from the MSB to the
+ // LSB.
+ uint8 ReadBit();
+
+ const char* const source_;
+ const size_t length_;
+
+ // Index of the byte currently being read from.
+ uint64 current_byte_;
+ // Index of the last bit read within |current_byte_|. Since bits are read
+ // from the MSB to the LSB, this value is initialized to 7 and decremented
+ // after each read.
+ int8 current_bit_;
+};
+
+// Given a Golomb-coded list of hashes in |compressed_whitelist|, unpack into
+// |uncompressed_list|. Returns true if the format of the compressed whitelist
+// is valid, false otherwise.
+NET_EXPORT_PRIVATE bool UncompressEVWhitelist(
+ const std::string& compressed_whitelist,
+ std::set<std::string>* uncompressed_list);
+
+// Sets the given |ev_whitelist| into the global context.
+// Note that |ev_whitelist| will contain the old EV whitelist data after this
+// call as the implementation is using set::swap() to efficiently switch the
+// sets.
+NET_EXPORT_PRIVATE void SetEVWhitelistData(std::set<std::string>& ev_whitelist);
+
+} // namespace internal
+
+// Sets the global EV certificate hashes whitelist from
+// |compressed_whitelist_file| in the global context, after uncompressing it.
+// If the data in |compressed_whitelist_file| is not a valid compressed
+// whitelist, does nothing.
+NET_EXPORT void SetEVWhitelistFromFile(
+ const base::FilePath& compressed_whitelist_file);
+
+// Returns true if the |certificate_hash| appears in the EV certificate hashes
+// whitelist.
+NET_EXPORT bool IsCertificateHashInWhitelist(
+ const std::string& certificate_hash);
+
+// Returns true if the global EV certificate hashes whitelist is non-empty,
+// false otherwise.
+NET_EXPORT bool HasValidEVWhitelist();
+
+} // namespace ct
+
+} // namespace net
+
+#endif // NET_CERT_CT_EV_WHITELIST_H_
« no previous file with comments | « no previous file | net/cert/ct_ev_whitelist.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698