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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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 // This file contains utilities related to working with "facets".
6 //
7 // A "facet" is defined as the manifestation of a logical application on a given
8 // platform. For example, "My Bank" may have released an Android application
9 // and a Web application accessible from a browser. These are all facets of the
10 // "My Bank" logical application.
11 //
12 // Facets that belong to the same logical application are said to be affiliated
13 // with each other. Conceptually, "affiliations" can be seen as an equivalence
14 // relation defined over the set of all facets. Each equivalence class contains
15 // facets that belong to the same logical application, and therefore should be
16 // treated as synonymous for certain purposes, e.g., sharing credentials.
17 //
18 // A valid facet identifier will be a URI of the form:
19 //
20 // * https://<host>[:<port>]/
21 // For web sites. Only HTTPS sites are supported, and URI must not contain
22 // components other than the scheme, host, and a port (which is optional).
23 //
24 // * android://<cert_hash>@<package_name>/
25 // For Android applications. The <cert_hash> is hash of the certificate
26 // used to sign the APK, normally calculated as:
27 // echo -n -e "$PEM_KEY" | \
28 // openssl x509 -outform DER | \
29 // openssl sha -sha512 -binary | base64 | tr '+/' '-_'
30 //
31 // The canonical form of both kinds of facet URI should be calculated the same
32 // way as it is calculated for a standard URL. Note that this will cause '='
33 // padding characters in <cert_hash> to be percent encoded into "%3D".
34
35 #ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_UTILS_H_
36 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_UTILS_H_
37
38 #include <string>
39 #include <vector>
40
41 namespace password_manager {
42
43 // Encapsulates a facet URI in canonical form.
44 //
45 // This is a very light-weight wrapper around an std::string containing the text
46 // of the URI, and can be passed around as a value. The main reason this class
47 // exists is to make it clearer in the code when a certain URI is known to be a
48 // valid facet URI in canonical form, and to allow verifying/converting URIs to
49 // such canonical form.
50 //
51 // Note that it would be impractical to use GURL to represent facet URIs, as
52 // GURL has built-in logic to parse the rest of the URI according to its scheme,
53 // and obviously, it does not recognize the "android" scheme. Therefore, after
54 // parsing, everything ends up in the path component, which is not too helpful.
55 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
56 public:
57 // As a light-weight std::string wrapper, allow copy and assign.
58 FacetURI();
59 FacetURI(const FacetURI&) = default;
60 FacetURI& operator=(const FacetURI&) = default;
61
62 // 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.
63 // The resulting instance will be invalid if |uri| was not a valid facet URI.
64 static FacetURI FromPotentiallyInvalidURI(const std::string& uri);
65
66 // 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.
67 static FacetURI FromCanonicalFacetURI(const std::string& canonical_facet_uri);
68
69 // Comparison operators.
70 bool operator==(const FacetURI& other) const {
71 return canonical_uri_ == other.canonical_uri_;
72 }
73 bool operator!=(const FacetURI& other) const {
74 return canonical_uri_ != other.canonical_uri_;
75 }
76
77 // Relational operators so that FacetURI can be used in sorted containers.
78 bool operator<(const FacetURI& other) const {
79 return canonical_uri_ < other.canonical_uri_;
80 }
81 bool operator>(const FacetURI& other) const {
82 return canonical_uri_ > other.canonical_uri_;
83 }
84
85 // Returns whether or not this instance represents a valid facet identifier
86 // referring to either a Web or an Android application.
87 bool is_valid() const {
88 return is_valid_;
89 }
90
91 // Returns the text of the encapsulated canonical URI.
92 const std::string& canonical_uri() const {
93 return canonical_uri_;
94 }
95
96 // Returns whether or not this instance represents a valid facet identifier
97 // referring to a Web application.
98 bool IsValidWebFacetURI() const;
99
100 // Returns whether or not this instance represents a valid facet identifier
101 // referring to an Android application.
102 bool IsValidAndroidFacetURI() const;
103
104 private:
105 // Internal constructor to be used by the static factory methods.
106 FacetURI(const std::string& canonical_facet_uri, bool is_valid);
107
108 // Whether or not |canonical_uri_| contains a valid facet URI in canonical
109 // form.
110 bool is_valid_;
111
112 // The canonical form of the URI this instance was constructed with.
113 // If |is_valid_| is true, then this is also a valid facet URI.
114 std::string canonical_uri_;
115 };
116
117 // A collection of facets affiliated with each other, i.e. an equivalence class.
118 typedef std::vector<FacetURI> AffiliatedFacets;
119
120 // Returns whether or not equivalence classes |a| and |b| are equal, that is,
121 // whether or not they consist of the same set of facets.
122 //
123 // Note that this will do some sorting, so it can be expensive for large inputs.
124 bool AreEquivalenceClassesEqual(const AffiliatedFacets& a,
125 const AffiliatedFacets& b);
126
127 } // namespace password_manager
128
129 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_UTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698