File: payment_method_manifest_table.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (174 lines) | stat: -rw-r--r-- 7,364 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_PAYMENTS_CONTENT_PAYMENT_METHOD_MANIFEST_TABLE_H_
#define COMPONENTS_PAYMENTS_CONTENT_PAYMENT_METHOD_MANIFEST_TABLE_H_

#include <memory>
#include <optional>
#include <string>
#include <vector>

#include "base/strings/cstring_view.h"
#include "base/time/time.h"
#include "components/payments/content/browser_binding/browser_bound_key_metadata.h"
#include "components/webdata/common/web_database_table.h"

class WebDatabase;

namespace payments {

struct SecurePaymentConfirmationCredential;

// This class manages Web Payment tables in SQLite database. It expects the
// following schema.
//
// payment_method_manifest This table stores WebAppManifestSection.id of the
//                         supported web app in this payment method manifest.
//                         Note that a payment method manifest might contain
//                         multiple supported web apps ids.
//
//   expire_date           The expire date in seconds from 1601-01-01 00:00:00
//                         UTC.
//   method_name           The method name.
//   web_app_id            The supported web app id.
//                         (WebAppManifestSection.id).
//
// secure_payment_confirmation_instrument
//                         This table stores credential information for secure
//                         payment confirmation method. Historically it also
//                         stored instrument information, hence the name and
//                         the (no longer used) label and icon fields.
//                         This table is only used when credential store APIs
//                         are unavailable: This is controlled by the
//                         platform-specific
//                         SecurePaymentConfirmationUseCredentialStoreAPIs flag:
//                         On Android, currently, this table is not used.
//
//   credential_id         The WebAuthn credential identifier blob. Primary key.
//   relying_party_id      The relying party identifier string.
//   label                 The instrument human-readable label string.
//   icon                  The serialized SkBitmap blob.
//   data_created          The creation date in micro seconds from 1601-01-01
//                         00:00:00 UTC.
//
// secure_payment_confirmation_browser_bound_key
//                         This table stores browser bound key information for
//                         payment credentials. The primary key of this table is
//                         the pair of `credential_id` and `relying_party_id`.
//
//   credential_id         The WebAuthn credential identifier blob.
//   relying_party_id      The relying party identifier string.
//   browser_bound_key_id  The identifier of the browser bound key.
class PaymentMethodManifestTable : public WebDatabaseTable {
 public:
  PaymentMethodManifestTable();
  ~PaymentMethodManifestTable() override;

  PaymentMethodManifestTable(const PaymentMethodManifestTable& other) = delete;
  PaymentMethodManifestTable& operator=(
      const PaymentMethodManifestTable& other) = delete;

  // Retrieves the PaymentMethodManifestTable* owned by `db`.
  static PaymentMethodManifestTable* FromWebDatabase(WebDatabase* db);

  // WebDatabaseTable:
  WebDatabaseTable::TypeKey GetTypeKey() const override;
  bool CreateTablesIfNecessary() override;
  bool MigrateToVersion(int version, bool* update_compatible_version) override;

  // Remove expired data.
  void RemoveExpiredData();

  // Clears all of the secure payment confirmation credential information
  // created in the given time range `begin` and `end`. Return false for
  // failure.
  bool ClearSecurePaymentConfirmationCredentials(base::Time begin,
                                                 base::Time end);

  // Adds `payment_method`'s manifest. `web_app_ids` contains supported web apps
  // ids.
  bool AddManifest(const std::string& payment_method,
                   const std::vector<std::string>& web_app_ids);

  // Gets manifest for `payment_method`. Return empty vector if no manifest
  // exists for this method.
  std::vector<std::string> GetManifest(const std::string& payment_method);

  // Adds a secure payment confirmation `credential`. All existing data for the
  // credential's (relying_party_id, credential_id) tuple is erased before the
  // new data is added.
  //
  // Each field in the `credential` should be non-empty and `relying_party_id`
  // field should be a valid domain string. See:
  // https://url.spec.whatwg.org/#valid-domain-string
  //
  // Returns false for invalid data, e.g., credential reuse between relying
  // parties, or on failure.
  bool AddSecurePaymentConfirmationCredential(
      const SecurePaymentConfirmationCredential& credential);

  // Executes a SQL statement for testing.
  //
  // Returns true if all statements execute successfully. If a statement fails,
  // stops and returns false. Calls should be wrapped in ASSERT_TRUE().
  bool ExecuteForTest(const base::cstring_view sql);

  // Raze the database to the ground for testing.
  //
  // false is returned if the database is locked by some other
  // process.
  bool RazeForTest();

  // Returns true if a column with the given name exists in the given table.
  bool DoesColumnExistForTest(const base::cstring_view table_name,
                              const base::cstring_view column_name);

  // Gets the list of secure payment confirmation credentials for the given list
  // of `credential_ids`.
  //
  // Returns an empty vector when no data is found or when a read error occurs.
  // Does not return invalid credentials.
  //
  // Please use `std::move()` for `credential_ids` parameter to avoid extra
  // copies.
  std::vector<std::unique_ptr<SecurePaymentConfirmationCredential>>
  GetSecurePaymentConfirmationCredentials(
      std::vector<std::vector<uint8_t>> credential_ids,
      const std::string& relying_party_id);

  // Sets a browser bound key identifier for the credential id, relying party id
  // pair. If a browser bound key exists, no updates are performed and false is
  // returned.
  //
  // Returns whether the browser bound key id was set.
  bool SetBrowserBoundKey(std::vector<uint8_t> credential_id,
                          std::string_view relying_party_id,
                          std::vector<uint8_t> browser_bound_key_id);

  // Gets the browser bound key id for the given credential id, relying party id
  // pair.
  //
  // Returns the browser bound key id or nullopt when not found (or error
  // occurred during retrieval).
  std::optional<std::vector<uint8_t>> GetBrowserBoundKey(
      std::vector<uint8_t> credential_id,
      std::string_view relying_party_id);

  // Gets all browser bound key entries.
  //
  // Returns the possibly empty vector of entries or an empty vector when a read
  // error occurs.
  std::vector<BrowserBoundKeyMetadata> GetAllBrowserBoundKeys();

  // Deletes the given browser bound key entries by relying_party_id and
  // credential_id.
  bool DeleteBrowserBoundKeys(
      std::vector<BrowserBoundKeyMetadata::RelyingPartyAndCredentialId>
          passkeys);
};

}  // namespace payments

#endif  // COMPONENTS_PAYMENTS_CONTENT_PAYMENT_METHOD_MANIFEST_TABLE_H_