Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DB layer and API for the Autofill Component #3582

Merged
merged 1 commit into from Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES_UNRELEASED.md
Expand Up @@ -3,3 +3,8 @@
# Unreleased Changes

[Full Changelog](https://github.com/mozilla/application-services/compare/v63.0.0...main)

## Autofill

### What's changed ###
- Added a basic API and database layer for the autofill component. ([#3582](https://github.com/mozilla/application-services/pull/3582))
41 changes: 41 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
@@ -1,6 +1,7 @@
[workspace]
# Note: Any additions here should be repeated in default-members below.
members = [
"components/autofill",
"components/fxa-client",
"components/fxa-client/ffi",
"components/logins",
Expand All @@ -24,6 +25,7 @@ members = [
"components/support/rc_crypto/nss/systest",
"components/support/sql",
"components/support/sync15-traits",
"components/support/types",
"components/support/viaduct-reqwest",
"components/sync_manager",
"components/sync_manager/ffi",
Expand Down Expand Up @@ -68,6 +70,7 @@ members = [
# To be clear: passing the `--all` or `--workspace` arg to cargo will make it
# use the full member set.
default-members = [
"components/autofill",
"components/fxa-client",
"components/fxa-client/ffi",
"components/logins",
Expand All @@ -88,6 +91,7 @@ default-members = [
"components/support/rc_crypto/nss/nss_sys",
"components/support/sql",
"components/support/sync15-traits",
"components/support/types",
"components/support/viaduct-reqwest",
"components/sync_manager",
"components/sync_manager/ffi",
Expand Down
33 changes: 33 additions & 0 deletions components/autofill/Cargo.toml
@@ -0,0 +1,33 @@
[package]
name = "autofill"
edition = "2018"
version = "0.1.0"
authors = ["application-services@mozilla.com"]
license = "MPL-2.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
error-support = { path = "../support/error" }
interrupt-support = { path = "../support/interrupt" }
log = "0.4"
serde = "1"
serde_derive = "1"
serde_json = "1"
sql-support = { path = "../support/sql" }
sync-guid = { path = "../support/guid", features = ["rusqlite_support", "random"] }
sync15-traits = {path = "../support/sync15-traits"}
thiserror = "1.0"
types = { path = "../support/types" }
url = { version = "2.1", features = ["serde"] }

[dependencies.rusqlite]
version = "0.23.1"
features = ["functions", "bundled", "serde_json", "unlock_notify"]

[dev-dependencies]
env_logger = { version = "0.7", default-features = false }
libsqlite3-sys = "0.18.0"

[build-dependencies]
nss_build_common = { path = "../support/rc_crypto/nss/nss_build_common" }
16 changes: 16 additions & 0 deletions components/autofill/build.rs
@@ -0,0 +1,16 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

//! Work around the fact that `sqlcipher` might get enabled by a cargo feature
//! another crate in the workspace needs, without setting up nss. (This is a
//! gross hack).

fn main() {
println!("cargo:rerun-if-changed=build.rs");
// Ugh. This is really really dumb. We don't care about sqlcipher at all. really
if nss_build_common::env_str("DEP_SQLITE3_LINK_TARGET") == Some("sqlcipher".into()) {
// If NSS_DIR isn't set, we don't really care, ignore the Err case.
let _ = nss_build_common::link_nss();
}
}
99 changes: 99 additions & 0 deletions components/autofill/sql/create_shared_schema.sql
@@ -0,0 +1,99 @@
-- This Source Code Form is subject to the terms of the Mozilla Public
-- License, v. 2.0. If a copy of the MPL was not distributed with this
-- file, You can obtain one at http://mozilla.org/MPL/2.0/.

CREATE TABLE IF NOT EXISTS addresses_data (
guid TEXT NOT NULL PRIMARY KEY,
given_name TEXT NOT NULL,
additional_name TEXT NOT NULL,
family_name TEXT NOT NULL,
organization TEXT NOT NULL, -- Company
street_address TEXT NOT NULL, -- (Multiline)
address_level3 TEXT NOT NULL, -- Suburb/Sublocality
address_level2 TEXT NOT NULL, -- City/Town
address_level1 TEXT NOT NULL, -- Province (Standardized code if possible)
postal_code TEXT NOT NULL,
country TEXT NOT NULL, -- ISO 3166
tel TEXT NOT NULL, -- Stored in E.164 format
email TEXT NOT NULL,

time_created INTEGER NOT NULL,
time_last_used INTEGER,
time_last_modified INTEGER NOT NULL,
times_used INTEGER NOT NULL DEFAULT 0,

sync_change_counter INTEGER NOT NULL DEFAULT 1
);

CREATE TABLE IF NOT EXISTS addresses_mirror (
guid TEXT NOT NULL PRIMARY KEY,
given_name TEXT NOT NULL,
additional_name TEXT NOT NULL,
family_name TEXT NOT NULL,
organization TEXT NOT NULL, -- Company
street_address TEXT NOT NULL, -- (Multiline)
address_level3 TEXT NOT NULL, -- Suburb/Sublocality
address_level2 TEXT NOT NULL, -- City/Town
address_level1 TEXT NOT NULL, -- Province (Standardized code if possible)
postal_code TEXT NOT NULL,
country TEXT NOT NULL, -- ISO 3166
tel TEXT NOT NULL, -- Stored in E.164 format
email TEXT NOT NULL,

time_created INTEGER NOT NULL,
time_last_used INTEGER,
time_last_modified INTEGER NOT NULL,
times_used INTEGER NOT NULL DEFAULT 0
);

CREATE TABLE IF NOT EXISTS addresses_tombstones (
guid TEXT PRIMARY KEY,
time_deleted INTEGER NOT NULL
) WITHOUT ROWID;

-- NOTE: The credit card tables below are not being implemented as there are still outstanding
-- questions around how we address security model.

-- CREATE TABLE IF NOT EXISTS credit_cards_data (
-- guid TEXT NOT NULL PRIMARY KEY,
-- cc_name TEXT NOT NULL, -- full name
-- cc_given_name TEXT NOT NULL,
-- cc_additonal_name TEXT NOT NULL,
-- cc_family_name TEXT NOT NULL,
-- cc_number TEXT NOT NULL,
-- cc_exp_month INTEGER,
-- cc_exp_year INTEGER,
-- cc_type TEXT NOT NULL,
-- cc_exp TEXT NOT NULL, -- text format of the expiration date e.g. "[cc_exp_year]-[cc_exp_month]"

-- time_created INTEGER NOT NULL,
-- time_last_used INTEGER,
-- time_last_modified INTEGER NOT NULL,
-- times_used INTEGER NOT NULL DEFAULT 0,

-- /* Same "sync change counter" strategy used by other components. */
-- sync_change_counter INTEGER NOT NULL DEFAULT 1
-- );

-- CREATE TABLE IF NOT EXISTS credit_cards_mirror (
-- guid TEXT NOT NULL PRIMARY KEY,
-- cc_name TEXT NOT NULL, -- full name
-- cc_given_name TEXT NOT NULL,
-- cc_additonal_name TEXT NOT NULL,
-- cc_family_name TEXT NOT NULL,
-- cc_number TEXT NOT NULL,
-- cc_exp_month INTEGER,
-- cc_exp_year INTEGER,
-- cc_type TEXT NOT NULL,
-- cc_exp TEXT NOT NULL, -- text format of the expiration date e.g. "[cc_exp_year]-[cc_exp_month]"

-- time_created INTEGER NOT NULL,
-- time_last_used INTEGER,
-- time_last_modified INTEGER NOT NULL,
-- times_used INTEGER NOT NULL DEFAULT 0
-- );

-- CREATE TABLE IF NOT EXISTS credit_cards_tombstones (
-- guid TEXT PRIMARY KEY,
-- time_deleted INTEGER NOT NULL
-- ) WITHOUT ROWID;
20 changes: 20 additions & 0 deletions components/autofill/sql/create_shared_triggers.sql
@@ -0,0 +1,20 @@

-- This Source Code Form is subject to the terms of the Mozilla Public
-- License, v. 2.0. If a copy of the MPL was not distributed with this
-- file, You can obtain one at http://mozilla.org/MPL/2.0/.

-- This file defines triggers shared between the main and Sync connections.

CREATE TEMP TRIGGER addresses_data_afterinsert_trigger
AFTER INSERT ON addresses_data
FOR EACH ROW WHEN NEW.guid IN (SELECT guid FROM addresses_tombstones)
BEGIN
SELECT RAISE(FAIL, 'guid exists in `addresses_tombstones`');
END;

CREATE TEMP TRIGGER addresses_tombstones_afterinsert_trigger
AFTER INSERT ON addresses_tombstones
WHEN NEW.guid IN (SELECT guid FROM addresses_data)
BEGIN
SELECT RAISE(FAIL, 'guid exists in `addresses_data`');
END;