From eb86986cf49c36c148137604d847462a5579c47d Mon Sep 17 00:00:00 2001 From: Chris Eager Date: Fri, 8 Oct 2021 17:30:42 -0700 Subject: [PATCH] Add /v2/directory/auth endpoint --- service/config/sample.yml | 4 + .../WhisperServerConfiguration.java | 10 ++ .../textsecuregcm/WhisperServerService.java | 7 ++ .../ExternalServiceCredentialGenerator.java | 97 ++++++------------- .../DirectoryV2ClientConfiguration.java | 22 +++++ .../DirectoryV2Configuration.java | 21 ++++ .../controllers/DirectoryV2Controller.java | 49 ++++++++++ .../textsecuregcm/util/Util.java | 24 +++-- .../DirectoryControllerV2Test.java | 49 ++++++++++ 9 files changed, 204 insertions(+), 79 deletions(-) create mode 100644 service/src/main/java/org/whispersystems/textsecuregcm/configuration/DirectoryV2ClientConfiguration.java create mode 100644 service/src/main/java/org/whispersystems/textsecuregcm/configuration/DirectoryV2Configuration.java create mode 100644 service/src/main/java/org/whispersystems/textsecuregcm/controllers/DirectoryV2Controller.java create mode 100644 service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/DirectoryControllerV2Test.java diff --git a/service/config/sample.yml b/service/config/sample.yml index 96497bfd9..a87c8d21c 100644 --- a/service/config/sample.yml +++ b/service/config/sample.yml @@ -83,6 +83,10 @@ directory: replicationPassword: # CDS replication endpoint password replicationCaCertificate: # CDS replication endpoint TLS certificate trust root +directoryV2: + client: # Configuration for interfacing with Contact Discovery Service v2 cluster + userAuthenticationTokenSharedSecret: # hex-encoded secret shared with CDS to generate auth tokens for Signal users + messageCache: # Redis server configuration for message store cache persistDelayMinutes: diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerConfiguration.java b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerConfiguration.java index ba2031566..17cc07b3f 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerConfiguration.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerConfiguration.java @@ -27,6 +27,7 @@ import org.whispersystems.textsecuregcm.configuration.DatabaseConfiguration; import org.whispersystems.textsecuregcm.configuration.DatadogConfiguration; import org.whispersystems.textsecuregcm.configuration.DeletedAccountsDynamoDbConfiguration; import org.whispersystems.textsecuregcm.configuration.DirectoryConfiguration; +import org.whispersystems.textsecuregcm.configuration.DirectoryV2Configuration; import org.whispersystems.textsecuregcm.configuration.DonationConfiguration; import org.whispersystems.textsecuregcm.configuration.DynamoDbClientConfiguration; import org.whispersystems.textsecuregcm.configuration.DynamoDbConfiguration; @@ -125,6 +126,11 @@ public class WhisperServerConfiguration extends Configuration { @JsonProperty private DirectoryConfiguration directory; + @NotNull + @Valid + @JsonProperty + private DirectoryV2Configuration directoryV2; + @NotNull @Valid @JsonProperty @@ -390,6 +396,10 @@ public class WhisperServerConfiguration extends Configuration { return directory; } + public DirectoryV2Configuration getDirectoryV2Configuration() { + return directoryV2; + } + public SecureStorageServiceConfiguration getSecureStorageServiceConfiguration() { return storageService; } diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java index fa3eb7aec..4939d8df6 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java @@ -87,6 +87,7 @@ import org.whispersystems.textsecuregcm.controllers.CertificateController; import org.whispersystems.textsecuregcm.controllers.ChallengeController; import org.whispersystems.textsecuregcm.controllers.DeviceController; import org.whispersystems.textsecuregcm.controllers.DirectoryController; +import org.whispersystems.textsecuregcm.controllers.DirectoryV2Controller; import org.whispersystems.textsecuregcm.controllers.DonationController; import org.whispersystems.textsecuregcm.controllers.KeepAliveController; import org.whispersystems.textsecuregcm.controllers.KeysController; @@ -426,6 +427,11 @@ public class WhisperServerService extends Application dynamicConfigurationManager = new DynamicConfigurationManager<>(config.getAppConfig().getApplication(), @@ -632,6 +638,7 @@ public class WhisperServerService extends Application new Pair<>(account, mock(Device.class)))).getEntity(); + + assertEquals(credentials.getUsername(), "EREREREREREREREREREREQAAAABZvPKn"); + assertEquals(credentials.getPassword(), "1633738643:ff03669c64f3f938a279"); + assertEquals(32, credentials.getUsername().length()); + assertEquals(31, credentials.getPassword().length()); + } + +}