From 077c259d5b9903a9e91cbae66a9f922f4b85eac6 Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Sun, 23 Feb 2020 17:59:30 -0800 Subject: [PATCH] Migrate keys to accountsdb --- .../WhisperServerConfiguration.java | 12 -- .../textsecuregcm/WhisperServerService.java | 10 +- service/src/main/resources/accountsdb.xml | 11 + service/src/main/resources/keysdb.xml | 189 ------------------ 4 files changed, 12 insertions(+), 210 deletions(-) delete mode 100644 service/src/main/resources/keysdb.xml diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerConfiguration.java b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerConfiguration.java index 75f65f414..e9089e603 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerConfiguration.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerConfiguration.java @@ -98,19 +98,11 @@ public class WhisperServerConfiguration extends Configuration { @JsonProperty private List maxDevices = new LinkedList<>(); - @Valid - @NotNull - @JsonProperty - private DatabaseConfiguration keysDatabase; - @Valid @NotNull @JsonProperty private DatabaseConfiguration accountsDatabase; - @JsonProperty - private DatabaseConfiguration read_database; - @Valid @NotNull @JsonProperty @@ -238,10 +230,6 @@ public class WhisperServerConfiguration extends Configuration { return abuseDatabase; } - public DatabaseConfiguration getKeysDatabase() { - return keysDatabase; - } - public DatabaseConfiguration getAccountsDatabaseConfiguration() { return accountsDatabase; } diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java index 05e3ca20d..6b5ddcdef 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java @@ -115,12 +115,6 @@ public class WhisperServerService extends Application("keysdb", "keysdb.xml") { - @Override - public DataSourceFactory getDataSourceFactory(WhisperServerConfiguration configuration) { - return configuration.getKeysDatabase(); - } - }); bootstrap.addBundle(new NameableMigrationsBundle("accountdb", "accountsdb.xml") { @Override @@ -161,11 +155,9 @@ public class WhisperServerService extends Application + + + + + + + + CREATE INDEX CONCURRENTLY deleted_key_index ON keys (deleted); + + + diff --git a/service/src/main/resources/keysdb.xml b/service/src/main/resources/keysdb.xml deleted file mode 100644 index f2a9c315c..000000000 --- a/service/src/main/resources/keysdb.xml +++ /dev/null @@ -1,189 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CREATE type device_t AS (id integer, "authToken" varchar(255), salt varchar(255), "signalingKey" varchar(255), "gcmId" text, "apnId" text); - CREATE type account_t AS (number varchar(255), "supportsSms" smallint, devices device_t array); - UPDATE accounts SET data = row_to_json(row(number, supports_sms, array[row(1, auth_token, salt, signaling_key, gcm_id, apn_id)::device_t])::account_t) - - - - - - - - - - - DROP type account_t; - DROP type device_t; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CREATE OR REPLACE FUNCTION "custom_json_object_set_key"( - "json" json, - "key_to_set" TEXT, - "value_to_set" anyelement - ) - RETURNS json - LANGUAGE sql - IMMUTABLE - STRICT - AS $function$ - SELECT COALESCE( - (SELECT ('{' || string_agg(to_json("key") || ':' || "value", ',') || '}') - FROM (SELECT * - FROM json_each("json") - WHERE "key" <> "key_to_set" - UNION ALL - SELECT "key_to_set", to_json("value_to_set")) AS "fields"), - '{}' - )::json - $function$; - UPDATE accounts SET data = custom_json_object_set_key(data, 'identityKey', k.identity_key) FROM keys k WHERE (data->>'identityKey')::text is null AND k.number = data->>'number' AND k.last_resort = 1; - UPDATE accounts SET data = custom_json_object_set_key(data, 'identityKey', k.identity_key) FROM keys k WHERE (data->>'identityKey')::text is null AND k.number = data->>'number'; - - - - - - - - - - - - - - - - - - - -