From c872e00153caa76c750bab9e25c0cb8be9418684 Mon Sep 17 00:00:00 2001 From: Zoe <174354408+Proj-Daedalus@users.noreply.github.com> Date: Fri, 19 Jul 2024 17:46:38 -0700 Subject: [PATCH 1/5] Minor changes to config & welcome message --- .../autoplug/client/configs/SSHConfig.java | 24 ++++++++++++------- .../connections/SSHServerConsoleReceive.java | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/osiris/autoplug/client/configs/SSHConfig.java b/src/main/java/com/osiris/autoplug/client/configs/SSHConfig.java index e8b0e6cc..8d297b90 100644 --- a/src/main/java/com/osiris/autoplug/client/configs/SSHConfig.java +++ b/src/main/java/com/osiris/autoplug/client/configs/SSHConfig.java @@ -8,14 +8,19 @@ package com.osiris.autoplug.client.configs; +import java.io.IOException; + import com.osiris.autoplug.client.tasks.SSHManager; import com.osiris.dyml.Yaml; import com.osiris.dyml.YamlSection; -import com.osiris.dyml.exceptions.*; +import com.osiris.dyml.exceptions.DuplicateKeyException; +import com.osiris.dyml.exceptions.IllegalKeyException; +import com.osiris.dyml.exceptions.IllegalListException; +import com.osiris.dyml.exceptions.NotLoadedException; +import com.osiris.dyml.exceptions.YamlReaderException; +import com.osiris.dyml.exceptions.YamlWriterException; import com.osiris.jlib.logger.AL; -import java.io.IOException; - public class SSHConfig extends MyYaml { public YamlSection enabled; @@ -58,7 +63,7 @@ public SSHConfig() throws IOException, DuplicateKeyException, YamlReaderExceptio enabled = put(name, "enabled").setDefValues("false") .setComments( "Enables a SSH console for remote access to AutoPlug.", - "You can connect to it via any SSH client like Putty, a custom script, or the built-in SSH client in Windows, Linux distros, MacOS, etc."); + "You can connect to it via any SSH client like Putty, Terminus, a custom script, or the built-in SSH client in Windows, Linux distros, MacOS, etc."); port = put(name, "port").setDefValues("22") .setComments( @@ -90,15 +95,18 @@ public SSHConfig() throws IOException, DuplicateKeyException, YamlReaderExceptio "The file must be in the OpenSSH format.", "Create keys with 'ssh-keygen -t rsa -b 4096' and add them to the file.", "The genereated file can be found in the .ssh directory of the user that created the key, unless a different path was specified.", - "The generated file will be a file with no extension, which contains the private key."); + "The generated file will be a file with no extension, which contains the private key.", + "In the same directory as the private key, there will also need to be a file with the same name and a .pub extension, which contains the public key."); username = put(name, "username").setDefValues("autoplug") - .setComments("The username required to connect to the SSH console."); + .setComments( + "The username required to connect to the SSH console.", + "This username must be unique and not used by any other SSH-based services on the host machine."); password = put(name, "password") .setComments( - "The password is not encrypted and can be seen in plain text in this file.", - "It is recommended to change it to a secure password."); + "WARNING: The password is not encrypted and can be seen in plain text in this file.", + "For this reason, it is recommended to use a public key instead of a password for authentication."); save(); unlockFile(); diff --git a/src/main/java/com/osiris/autoplug/client/network/online/connections/SSHServerConsoleReceive.java b/src/main/java/com/osiris/autoplug/client/network/online/connections/SSHServerConsoleReceive.java index 5ec9d502..31650ad6 100644 --- a/src/main/java/com/osiris/autoplug/client/network/online/connections/SSHServerConsoleReceive.java +++ b/src/main/java/com/osiris/autoplug/client/network/online/connections/SSHServerConsoleReceive.java @@ -76,7 +76,7 @@ public void start(ChannelSession channel, Environment env) throws IOException { out.write("│ Welcome to the AutoPlug SSH Console │\r\n".getBytes(StandardCharsets.UTF_8)); out.write("│ │\r\n".getBytes(StandardCharsets.UTF_8)); out.write("│ Programmed by │\r\n".getBytes(StandardCharsets.UTF_8)); - out.write("│ Discord user _zo3 │\r\n".getBytes(StandardCharsets.UTF_8)); + out.write("│ Discord user _z03 │\r\n".getBytes(StandardCharsets.UTF_8)); out.write("└───────────────────────────────────────┘\r\n".getBytes(StandardCharsets.UTF_8)); out.flush(); From fb7690bd076a7aee179e0ed6f2ac849bbb186ad0 Mon Sep 17 00:00:00 2001 From: Zoe <174354408+Proj-Daedalus@users.noreply.github.com> Date: Fri, 19 Jul 2024 17:53:41 -0700 Subject: [PATCH 2/5] sync --- .../com/osiris/autoplug/client/configs/SSHConfig.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/osiris/autoplug/client/configs/SSHConfig.java b/src/main/java/com/osiris/autoplug/client/configs/SSHConfig.java index 8d297b90..69b628ec 100644 --- a/src/main/java/com/osiris/autoplug/client/configs/SSHConfig.java +++ b/src/main/java/com/osiris/autoplug/client/configs/SSHConfig.java @@ -8,19 +8,14 @@ package com.osiris.autoplug.client.configs; -import java.io.IOException; - import com.osiris.autoplug.client.tasks.SSHManager; import com.osiris.dyml.Yaml; import com.osiris.dyml.YamlSection; -import com.osiris.dyml.exceptions.DuplicateKeyException; -import com.osiris.dyml.exceptions.IllegalKeyException; -import com.osiris.dyml.exceptions.IllegalListException; -import com.osiris.dyml.exceptions.NotLoadedException; -import com.osiris.dyml.exceptions.YamlReaderException; -import com.osiris.dyml.exceptions.YamlWriterException; +import com.osiris.dyml.exceptions.*; import com.osiris.jlib.logger.AL; +import java.io.IOException; + public class SSHConfig extends MyYaml { public YamlSection enabled; From c4c32cc97b680dc6c3b184fe8f16eb4f5325857a Mon Sep 17 00:00:00 2001 From: Zoe <174354408+Proj-Daedalus@users.noreply.github.com> Date: Fri, 19 Jul 2024 20:09:32 -0700 Subject: [PATCH 3/5] spelling, use default paths, add examples, correct misleading comment --- .../autoplug/client/configs/SSHConfig.java | 46 +++++++++++++------ 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/osiris/autoplug/client/configs/SSHConfig.java b/src/main/java/com/osiris/autoplug/client/configs/SSHConfig.java index 69b628ec..b0ff298a 100644 --- a/src/main/java/com/osiris/autoplug/client/configs/SSHConfig.java +++ b/src/main/java/com/osiris/autoplug/client/configs/SSHConfig.java @@ -8,14 +8,19 @@ package com.osiris.autoplug.client.configs; +import java.io.IOException; + import com.osiris.autoplug.client.tasks.SSHManager; import com.osiris.dyml.Yaml; import com.osiris.dyml.YamlSection; -import com.osiris.dyml.exceptions.*; +import com.osiris.dyml.exceptions.DuplicateKeyException; +import com.osiris.dyml.exceptions.IllegalKeyException; +import com.osiris.dyml.exceptions.IllegalListException; +import com.osiris.dyml.exceptions.NotLoadedException; +import com.osiris.dyml.exceptions.YamlReaderException; +import com.osiris.dyml.exceptions.YamlWriterException; import com.osiris.jlib.logger.AL; -import java.io.IOException; - public class SSHConfig extends MyYaml { public YamlSection enabled; @@ -63,7 +68,9 @@ public SSHConfig() throws IOException, DuplicateKeyException, YamlReaderExceptio port = put(name, "port").setDefValues("22") .setComments( "The port the SSH console listens on.", - "The default port is 22. Change it if you have a different port setup in your network, are hosting one or more other SSH-based services on the same port, or are otherwise using the default port for something else."); + "The default port is 22. Change it if you have a different port setup in your network, are hosting one or more other services on the same port, or are otherwise wanting to use the SSH service on a different port.", + "Example:", + "port: 22"); auth_method = put(name, "auth-method").setDefValues("key-only") .setComments( @@ -71,9 +78,11 @@ public SSHConfig() throws IOException, DuplicateKeyException, YamlReaderExceptio "Available options: 'user-pass-only', 'key-only', 'user-pass-key'.", "user-pass-only: Requires a username and password to connect. Requires the username and password fields below.", "key-only: Requires a public key to connect. Requires the allowed-keys-path field below.", - "user-pass-key: Requires either a username and password or a public key to connect. Requires all fields below."); + "user-pass-key: Requires either a username and password or a public key to connect. Requires all fields below.", + "Example:", + "auth-method: key-only"); - allowed_keys_path = put(name, "allowed-keys-path") + allowed_keys_path = put(name, "allowed-keys-path").setDefValues("./autoplug/allowed_ssh_keys.txt") .setComments( "The .txt file containing the public keys that are allowed to connect to the SSH console.", "The file must contain one public key per line.", @@ -81,27 +90,38 @@ public SSHConfig() throws IOException, DuplicateKeyException, YamlReaderExceptio "Exaple:", "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDf6... user@host", "Create keys with 'ssh-keygen -t rsa -b 4096' and add them to the file.", - "The genereated file can be found in the .ssh directory of the user that created the key, unless a different path was specified.", - "The generated file will be a ____.pub file, which contains the public key."); + "The generated file can be found in the .ssh directory of the user that created the key, unless a different path was specified.", + "The generated file will be a .pub file, which contains the public key.", + "Example:", + "allowed-keys-path: ./autoplug/allowed_ssh_keys.txt", + "Example connection command: `ssh -i /path/to/private/key username@server-ip-address`"); - server_private_key = put(name, "server-private-key") + server_private_key = put(name, "server-private-key").setDefValues(System.getProperty("user.dir") + "./ssh/id_rsa") .setComments( "The private key used by the server to authenticate itself to the SSH console.", "The file must be in the OpenSSH format.", "Create keys with 'ssh-keygen -t rsa -b 4096' and add them to the file.", - "The genereated file can be found in the .ssh directory of the user that created the key, unless a different path was specified.", + "The generated file can be found in the .ssh directory of the user that created the key, unless a different path was specified.", "The generated file will be a file with no extension, which contains the private key.", - "In the same directory as the private key, there will also need to be a file with the same name and a .pub extension, which contains the public key."); + "In the same directory as the private key, there will also need to be a file with the same name and a .pub extension, which contains the public key.", + "Example:", + "server-private-key: " + System.getProperty("user.dir") + "./ssh/id_rsa", + "NOTICE: The .ssh directory is not present by default, and must be created via the usage of the 'ssh-keygen' command."); username = put(name, "username").setDefValues("autoplug") .setComments( "The username required to connect to the SSH console.", - "This username must be unique and not used by any other SSH-based services on the host machine."); + "This username must be unique and not used by any other SSH-based services on the host machine.", + "This will be the username used to connect to the SSH console (`ssh username@host`).", + "Example:", + "username: minecraft-server"); password = put(name, "password") .setComments( "WARNING: The password is not encrypted and can be seen in plain text in this file.", - "For this reason, it is recommended to use a public key instead of a password for authentication."); + "For this reason, it is recommended to use a public/private keypair instead of a password for authentication.", + "Example:", + "password: MyT0pSecretP@ssw0rd"); save(); unlockFile(); From e5ea6cee133a2dec3354132bfbfb869d504ca057 Mon Sep 17 00:00:00 2001 From: Zoe <174354408+Proj-Daedalus@users.noreply.github.com> Date: Fri, 19 Jul 2024 20:11:52 -0700 Subject: [PATCH 4/5] add port forward message --- .../java/com/osiris/autoplug/client/configs/SSHConfig.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/osiris/autoplug/client/configs/SSHConfig.java b/src/main/java/com/osiris/autoplug/client/configs/SSHConfig.java index b0ff298a..144b6902 100644 --- a/src/main/java/com/osiris/autoplug/client/configs/SSHConfig.java +++ b/src/main/java/com/osiris/autoplug/client/configs/SSHConfig.java @@ -70,7 +70,8 @@ public SSHConfig() throws IOException, DuplicateKeyException, YamlReaderExceptio "The port the SSH console listens on.", "The default port is 22. Change it if you have a different port setup in your network, are hosting one or more other services on the same port, or are otherwise wanting to use the SSH service on a different port.", "Example:", - "port: 22"); + "port: 22", + "Notice: You will likely need to open this port in your firewall settings to allow incoming connections, as well as port-forward it in your router settings if you are hosting the server on a local network."); auth_method = put(name, "auth-method").setDefValues("key-only") .setComments( From 58d962ee458fa9c967913c00ea3d0bdd10996c5e Mon Sep 17 00:00:00 2001 From: Zoe <174354408+Proj-Daedalus@users.noreply.github.com> Date: Sat, 20 Jul 2024 11:41:51 -0700 Subject: [PATCH 5/5] remove unnecisary examples, fix default id_rsa fp --- .../autoplug/client/configs/SSHConfig.java | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/osiris/autoplug/client/configs/SSHConfig.java b/src/main/java/com/osiris/autoplug/client/configs/SSHConfig.java index 144b6902..f8f9ce37 100644 --- a/src/main/java/com/osiris/autoplug/client/configs/SSHConfig.java +++ b/src/main/java/com/osiris/autoplug/client/configs/SSHConfig.java @@ -10,6 +10,8 @@ import java.io.IOException; +import org.jline.utils.OSUtils; + import com.osiris.autoplug.client.tasks.SSHManager; import com.osiris.dyml.Yaml; import com.osiris.dyml.YamlSection; @@ -69,8 +71,6 @@ public SSHConfig() throws IOException, DuplicateKeyException, YamlReaderExceptio .setComments( "The port the SSH console listens on.", "The default port is 22. Change it if you have a different port setup in your network, are hosting one or more other services on the same port, or are otherwise wanting to use the SSH service on a different port.", - "Example:", - "port: 22", "Notice: You will likely need to open this port in your firewall settings to allow incoming connections, as well as port-forward it in your router settings if you are hosting the server on a local network."); auth_method = put(name, "auth-method").setDefValues("key-only") @@ -79,9 +79,7 @@ public SSHConfig() throws IOException, DuplicateKeyException, YamlReaderExceptio "Available options: 'user-pass-only', 'key-only', 'user-pass-key'.", "user-pass-only: Requires a username and password to connect. Requires the username and password fields below.", "key-only: Requires a public key to connect. Requires the allowed-keys-path field below.", - "user-pass-key: Requires either a username and password or a public key to connect. Requires all fields below.", - "Example:", - "auth-method: key-only"); + "user-pass-key: Requires either a username and password or a public key to connect. Requires all fields below."); allowed_keys_path = put(name, "allowed-keys-path").setDefValues("./autoplug/allowed_ssh_keys.txt") .setComments( @@ -93,11 +91,11 @@ public SSHConfig() throws IOException, DuplicateKeyException, YamlReaderExceptio "Create keys with 'ssh-keygen -t rsa -b 4096' and add them to the file.", "The generated file can be found in the .ssh directory of the user that created the key, unless a different path was specified.", "The generated file will be a .pub file, which contains the public key.", - "Example:", - "allowed-keys-path: ./autoplug/allowed_ssh_keys.txt", "Example connection command: `ssh -i /path/to/private/key username@server-ip-address`"); - server_private_key = put(name, "server-private-key").setDefValues(System.getProperty("user.dir") + "./ssh/id_rsa") + + String sshPath = OSUtils.IS_WINDOWS ? "%USERPROFILE%\\.ssh\\id_rsa" : "~/.ssh/id_rsa"; + server_private_key = put("server-private-key") .setComments( "The private key used by the server to authenticate itself to the SSH console.", "The file must be in the OpenSSH format.", @@ -105,17 +103,15 @@ public SSHConfig() throws IOException, DuplicateKeyException, YamlReaderExceptio "The generated file can be found in the .ssh directory of the user that created the key, unless a different path was specified.", "The generated file will be a file with no extension, which contains the private key.", "In the same directory as the private key, there will also need to be a file with the same name and a .pub extension, which contains the public key.", + "NOTICE: The .ssh directory is not present by default, and must be created via the usage of the 'ssh-keygen' command.", "Example:", - "server-private-key: " + System.getProperty("user.dir") + "./ssh/id_rsa", - "NOTICE: The .ssh directory is not present by default, and must be created via the usage of the 'ssh-keygen' command."); + "server-private-key: " + sshPath); username = put(name, "username").setDefValues("autoplug") .setComments( "The username required to connect to the SSH console.", "This username must be unique and not used by any other SSH-based services on the host machine.", - "This will be the username used to connect to the SSH console (`ssh username@host`).", - "Example:", - "username: minecraft-server"); + "This will be the username used to connect to the SSH console (`ssh username@host`)."); password = put(name, "password") .setComments(