From 2d46c7c27cd94e4b155526419ccd0ebd026ced75 Mon Sep 17 00:00:00 2001 From: Hans Ridder Date: Wed, 21 Sep 2016 15:23:00 -0700 Subject: [PATCH] Make RDE SSH key identity injectable ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=133883090 --- java/google/registry/config/ConfigModule.java | 12 ++++++++++++ java/google/registry/rde/JSchModule.java | 4 +++- .../google/registry/rde/RdeUploadActionTest.java | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/java/google/registry/config/ConfigModule.java b/java/google/registry/config/ConfigModule.java index 8711c1554..8e696c404 100644 --- a/java/google/registry/config/ConfigModule.java +++ b/java/google/registry/config/ConfigModule.java @@ -406,6 +406,18 @@ public final class ConfigModule { return Duration.standardHours(2); } + /** + * Returns the identity (an email address) used for the SSH keys used in RDE SFTP uploads. + * + * @see google.registry.keyring.api.Keyring#getRdeSshClientPublicKey() + * @see google.registry.keyring.api.Keyring#getRdeSshClientPrivateKey() + */ + @Provides + @Config("rdeSshIdentity") + public static String provideSshIdentity() { + return "rde@charlestonroadregistry.com"; + } + /** * Returns SFTP URL containing a username, hostname, port (optional), and directory (optional) to * which cloud storage files are uploaded. The password should not be included, as it's better to diff --git a/java/google/registry/rde/JSchModule.java b/java/google/registry/rde/JSchModule.java index b31379257..e26a24a59 100644 --- a/java/google/registry/rde/JSchModule.java +++ b/java/google/registry/rde/JSchModule.java @@ -21,6 +21,7 @@ import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; import dagger.Module; import dagger.Provides; +import google.registry.config.ConfigModule.Config; import google.registry.keyring.api.KeyModule.Key; /** Dagger module for {@link JSch} which provides SSH/SFTP connectivity. */ @@ -29,13 +30,14 @@ public final class JSchModule { @Provides static JSch provideJSch( + @Config("rdeSshIdentity") String identity, @Key("rdeSshClientPrivateKey") String privateKey, @Key("rdeSshClientPublicKey") String publicKey) { applyAppEngineKludge(); JSch jsch = new JSch(); try { jsch.addIdentity( - "rde@charlestonroadregistry.com", + identity, privateKey.getBytes(UTF_8), publicKey.getBytes(UTF_8), null); diff --git a/javatests/google/registry/rde/RdeUploadActionTest.java b/javatests/google/registry/rde/RdeUploadActionTest.java index 612b3b43a..802768fc1 100644 --- a/javatests/google/registry/rde/RdeUploadActionTest.java +++ b/javatests/google/registry/rde/RdeUploadActionTest.java @@ -181,6 +181,7 @@ public class RdeUploadActionTest { action.ghostryde = new Ghostryde(BUFFER_SIZE); action.jsch = JSchModule.provideJSch( + "user@ignored", keyring.getRdeSshClientPrivateKey(), keyring.getRdeSshClientPublicKey()); action.jschSshSessionFactory = new JSchSshSessionFactory(standardSeconds(3)); action.response = response;