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

Unified Diff: components/password_manager/core/browser/affiliation_utils.h

Issue 771173002: Added utility functions related to working with "facets". (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Introduced FacetURI. Created 6 years 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
Index: components/password_manager/core/browser/affiliation_utils.h
diff --git a/components/password_manager/core/browser/affiliation_utils.h b/components/password_manager/core/browser/affiliation_utils.h
new file mode 100644
index 0000000000000000000000000000000000000000..c2c3b035fb6d4b7f0c1301ee4412535153388ce7
--- /dev/null
+++ b/components/password_manager/core/browser/affiliation_utils.h
@@ -0,0 +1,129 @@
+// 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.
+
+// This file contains utilities related to working with "facets".
+//
+// A "facet" is defined as the manifestation of a logical application on a given
+// platform. For example, "My Bank" may have released an Android application
+// and a Web application accessible from a browser. These are all facets of the
+// "My Bank" logical application.
+//
+// Facets that belong to the same logical application are said to be affiliated
+// with each other. Conceptually, "affiliations" can be seen as an equivalence
+// relation defined over the set of all facets. Each equivalence class contains
+// facets that belong to the same logical application, and therefore should be
+// treated as synonymous for certain purposes, e.g., sharing credentials.
+//
+// A valid facet identifier will be a URI of the form:
+//
+// * https://<host>[:<port>]/
+// For web sites. Only HTTPS sites are supported, and URI must not contain
+// components other than the scheme, host, and a port (which is optional).
+//
+// * android://<cert_hash>@<package_name>/
+// For Android applications. The <cert_hash> is hash of the certificate
+// used to sign the APK, normally calculated as:
+// echo -n -e "$PEM_KEY" | \
+// openssl x509 -outform DER | \
+// openssl sha -sha512 -binary | base64 | tr '+/' '-_'
+//
+// The canonical form of both kinds of facet URI should be calculated the same
+// way as it is calculated for a standard URL. Note that this will cause '='
+// padding characters in <cert_hash> to be percent encoded into "%3D".
+
+#ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_UTILS_H_
+#define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_UTILS_H_
+
+#include <string>
+#include <vector>
+
+namespace password_manager {
+
+// Encapsulates a facet URI in canonical form.
+//
+// This is a very light-weight wrapper around an std::string containing the text
+// of the URI, and can be passed around as a value. The main reason this class
+// exists is to make it clearer in the code when a certain URI is known to be a
+// valid facet URI in canonical form, and to allow verifying/converting URIs to
+// such canonical form.
+//
+// Note that it would be impractical to use GURL to represent facet URIs, as
+// GURL has built-in logic to parse the rest of the URI according to its scheme,
+// and obviously, it does not recognize the "android" scheme. Therefore, after
+// parsing, everything ends up in the path component, which is not too helpful.
+class FacetURI {
Mike West 2014/12/03 22:58:35 Nit: I think you should split this out into a sepa
engedy 2014/12/08 20:53:16 That would mean having really tiny files. How abou
+ public:
+ // As a light-weight std::string wrapper, allow copy and assign.
+ FacetURI();
+ FacetURI(const FacetURI&) = default;
+ FacetURI& operator=(const FacetURI&) = default;
+
+ // Constructs a FacetURI instance to encapsulates the canonical form of |uri|.
Mike West 2014/12/03 22:58:35 s/encapsulates/encapsulate/
engedy 2014/12/08 20:53:16 Done.
+ // The resulting instance will be invalid if |uri| was not a valid facet URI.
+ static FacetURI FromPotentiallyInvalidURI(const std::string& uri);
+
+ // Constructs a valid FacetURI instance from a valid |canonical_facet_uri|.
Mike West 2014/12/03 22:58:35 Can you describe here what happens if an invalid U
engedy 2014/12/08 20:53:16 Done.
+ static FacetURI FromCanonicalFacetURI(const std::string& canonical_facet_uri);
+
+ // Comparison operators.
+ bool operator==(const FacetURI& other) const {
+ return canonical_uri_ == other.canonical_uri_;
+ }
+ bool operator!=(const FacetURI& other) const {
+ return canonical_uri_ != other.canonical_uri_;
+ }
+
+ // Relational operators so that FacetURI can be used in sorted containers.
+ bool operator<(const FacetURI& other) const {
+ return canonical_uri_ < other.canonical_uri_;
+ }
+ bool operator>(const FacetURI& other) const {
+ return canonical_uri_ > other.canonical_uri_;
+ }
+
+ // Returns whether or not this instance represents a valid facet identifier
+ // referring to either a Web or an Android application.
+ bool is_valid() const {
+ return is_valid_;
+ }
+
+ // Returns the text of the encapsulated canonical URI.
+ const std::string& canonical_uri() const {
+ return canonical_uri_;
+ }
+
+ // Returns whether or not this instance represents a valid facet identifier
+ // referring to a Web application.
+ bool IsValidWebFacetURI() const;
+
+ // Returns whether or not this instance represents a valid facet identifier
+ // referring to an Android application.
+ bool IsValidAndroidFacetURI() const;
+
+ private:
+ // Internal constructor to be used by the static factory methods.
+ FacetURI(const std::string& canonical_facet_uri, bool is_valid);
+
+ // Whether or not |canonical_uri_| contains a valid facet URI in canonical
+ // form.
+ bool is_valid_;
+
+ // The canonical form of the URI this instance was constructed with.
+ // If |is_valid_| is true, then this is also a valid facet URI.
+ std::string canonical_uri_;
+};
+
+// A collection of facets affiliated with each other, i.e. an equivalence class.
+typedef std::vector<FacetURI> AffiliatedFacets;
+
+// Returns whether or not equivalence classes |a| and |b| are equal, that is,
+// whether or not they consist of the same set of facets.
+//
+// Note that this will do some sorting, so it can be expensive for large inputs.
+bool AreEquivalenceClassesEqual(const AffiliatedFacets& a,
+ const AffiliatedFacets& b);
+
+} // namespace password_manager
+
+#endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_UTILS_H_

Powered by Google App Engine
This is Rietveld 408576698