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

Unified Diff: net/base/x509_cert_types.h

Issue 10545166: Support SHA-256 in public key pins for HTTPS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 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 | « net/base/transport_security_state_unittest.cc ('k') | net/socket/ssl_client_socket_nss.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/x509_cert_types.h
===================================================================
--- net/base/x509_cert_types.h (revision 142157)
+++ net/base/x509_cert_types.h (working copy)
@@ -8,10 +8,12 @@
#include <string.h>
+#include <algorithm>
#include <set>
#include <string>
#include <vector>
+#include "base/logging.h"
#include "base/string_piece.h"
#include "build/build_config.h"
#include "net/base/net_export.h"
@@ -37,13 +39,6 @@
unsigned char data[20];
};
-// In the future there will be a generic Fingerprint type, with at least two
-// implementations: SHA1 and SHA256. See http://crbug.com/117914. Until that
-// work is done (in a separate patch) this typedef bridges the gap.
-typedef SHA1Fingerprint Fingerprint;
-
-typedef std::vector<Fingerprint> FingerprintVector;
-
class NET_EXPORT SHA1FingerprintLessThan {
public:
bool operator() (const SHA1Fingerprint& lhs,
@@ -52,6 +47,96 @@
}
};
+struct NET_EXPORT SHA256Fingerprint {
+ bool Equals(const SHA256Fingerprint& other) const {
+ return memcmp(data, other.data, sizeof(data)) == 0;
+ }
+
+ unsigned char data[32];
+};
+
+class NET_EXPORT SHA256FingerprintLessThan {
+ public:
+ bool operator() (const SHA256Fingerprint& lhs,
+ const SHA256Fingerprint& rhs) const {
+ return memcmp(lhs.data, rhs.data, sizeof(lhs.data)) < 0;
+ }
+};
+
+enum FingerprintTag {
+ FINGERPRINT_SHA1,
+ FINGERPRINT_SHA256,
+};
+
+struct NET_EXPORT Fingerprint {
wtc 2012/06/18 17:00:29 It would be nice to come up with a better name tha
+ bool Equals(const Fingerprint& other) const {
+ if (tag != other.tag)
+ return false;
+ switch (tag) {
+ case FINGERPRINT_SHA1:
+ return fingerprint.sha1.Equals(other.fingerprint.sha1);
+ break;
+ case FINGERPRINT_SHA256:
+ return fingerprint.sha256.Equals(other.fingerprint.sha256);
+ break;
+ default:
+ DCHECK(false) << "Unknown FingerprintTag " << tag;
Ryan Sleevi 2012/06/15 21:44:00 NOTREACHED() rather than DCHECK(false). You can st
palmer 2012/06/15 22:40:49 Done.
+ return false;
+ }
+ }
+
+ size_t size() const {
+ switch (tag) {
+ case FINGERPRINT_SHA1:
+ return sizeof(fingerprint.sha1.data);
+ break;
+ case FINGERPRINT_SHA256:
+ return sizeof(fingerprint.sha256.data);
+ break;
+ default:
+ DCHECK(false) << "Unknown FingerprintTag " << tag;
+ return false;
Ryan Sleevi 2012/06/15 21:44:00 return 0;
palmer 2012/06/15 22:40:49 Done.
+ }
+ }
+
+ unsigned char* data() const {
Ryan Sleevi 2012/06/15 21:44:00 This should either be: const unsigned char* data(
palmer 2012/06/15 22:40:49 Done.
+ switch (tag) {
+ case FINGERPRINT_SHA1:
+ return const_cast<unsigned char*>(fingerprint.sha1.data);
+ break;
+ case FINGERPRINT_SHA256:
+ return const_cast<unsigned char*>(fingerprint.sha256.data);
+ break;
+ default:
+ DCHECK(false) << "Unknown FingerprintTag " << tag;
+ return NULL;
+ }
+ }
+
+ FingerprintTag tag;
+
+ union {
+ SHA1Fingerprint sha1;
+ SHA256Fingerprint sha256;
+ } fingerprint;
+};
+
+class NET_EXPORT FingerprintLessThan {
+ public:
+ bool operator() (const Fingerprint& lhs,
+ const Fingerprint& rhs) const {
Ryan Sleevi 2012/06/15 21:44:00 You should compare their types & sizes first, befo
palmer 2012/06/15 22:40:49 What should I do if they don't match? This is for
Ryan Sleevi 2012/06/15 22:51:45 Compare their tags/sizes. SHA1 sorts lexically SH
Ryan Sleevi 2012/06/15 22:54:49 sorry, the last one would be return memcmp(lhs.da
+ size_t lhs_size = lhs.size();
+ size_t rhs_size = rhs.size();
+ int r = memcmp(lhs.data(), rhs.data(), std::min(lhs_size, rhs_size));
+
+ if (r == 0 && lhs_size != rhs_size)
+ return lhs_size < rhs_size;
+ return r < 0;
+ }
+};
+
+typedef std::vector<Fingerprint> FingerprintVector;
+
// IsSHA1HashInSortedArray returns true iff |hash| is in |array|, a sorted
// array of SHA1 hashes.
bool NET_EXPORT IsSHA1HashInSortedArray(const SHA1Fingerprint& hash,
« no previous file with comments | « net/base/transport_security_state_unittest.cc ('k') | net/socket/ssl_client_socket_nss.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698