From 903b26bfca4acf7d399c2fe3669d2e1304aeb50a Mon Sep 17 00:00:00 2001 From: Sylvie Crowe <107814465+oneirocosm@users.noreply.github.com> Date: Thu, 8 Feb 2024 19:16:56 -0800 Subject: [PATCH] Use ssh library: add user input (#281) * feat: create backend for user input requests This is the first part of a change that allows the backend to request user input from the frontend. Essentially, the backend will send a request for the user to answer some query, and the frontend will send that answer back. It is blocking, so it needs to be used within a goroutine. There is some placeholder code in the frontend that will be updated in future commits. Similarly, there is some debug code in the backend remote.go file. * feat: create frontend for user input requests This is part of a change to allow the backend to request user input from the frontend. This adds a component specifically for handling this logic. It is only a starting point, and does not work perfectly yet. * refactor: update user input backend/interface This updates the user input backend to fix a few potential bugs. It also refactors the user input request and response types to better handle markdown and errors while making it more convenient to work with. A couple frontend changes were made to keep everything compatible. * fix: add props to user input request modal There was a second place that the modals were created that I previously missed. This fixes that second casel * feat: complete user input modal This rounds out the most immediate concerns for the new user input modal. The frontend now includes a timer to show how much time is left and will close itself once it reaches zero. Css formatting has been cleaned up to be more reasonable. There is still some test code present on the back end. This will be removed once actuall examples of the new modal are in place. * feat: create first pass known_hosts detection Manually integrating with golang's ssh library means that the code must authenticate known_hosts on its own. This is a first pass at creating a system that parses the known hosts files and denys a connection if there is a mismatch. This needs to be updated with a means to add keys to the known-hosts file if the user requests it. * feat: allow writing to known_hosts first pass As a follow-up to the previous change, we now allow the user to respond to interactive queries in order to determine if an unknown known hosts key can be added to a known_hosts file if it is missing. This needs to be refined further, but it gets the basic functionality there. * feat: add user input for kbd-interactive auth This adds a modal so the user can respond to prompts provided using the keyboard interactive authentication method. * feat: add interactive password authentication This makes the ssh password authentication interactive with its own user input modal. Unfortunately, this method does not allow trying a default first. This will need to be expanded in the future to accomodate that. * fix: allow automatic and interactive auth together Previously, it was impossible to use to separate methods of the same type to try ssh authentication. This made it impossible to make an auto attempt before a manual one. This change restricts that by combining them into one method where the auto attempt is tried once first and cannot be tried again. Following that, interactive authentication can be tried separately. It also lowers the time limit on kbd interactive authentication to 15 seconds due to limitations on the library we are using. * fix: set number of retries to one in ssh Number of retries means number of attempts after the fact, not number of total attempts. It has been adjusted from 2 to 1 to reflect this. * refactor: change argument order in GetUserInput This is a simple change to move the context to the first argument of GetUserInput to match the convention used elsewhere in the code. * fix: set number of retries to two again I was wrong in my previous analysis. The number given is the total number of tries. This is confusing when keyboard authentication and password authentication are both available which usually doesn't happen. * feat: create naive ui for ssh key passphrases This isn't quite as reactive as the other methods, but it does attempt to use publickey without a passphrase, then attempt to use the password as the passphrase, and finally prompting the user for a passphrase. The problem with this approach is that if multiple keys are used and they all have passphrases, they need to all be checked up front. In practice, this will not happen often, but it is something to be aware of. * fix: add the userinput.tsx changes These were missed in the previous commit. Adding them now. --- src/app/appconst.ts | 1 + src/app/common/elements/markdown.less | 1 + src/app/common/elements/passwordfield.tsx | 8 +- src/app/common/modals/index.tsx | 1 + src/app/common/modals/provider.tsx | 2 +- src/app/common/modals/registry.tsx | 22 +- src/app/common/modals/userinput.less | 15 + src/app/common/modals/userinput.tsx | 88 +++++ src/models/modals.ts | 6 +- src/models/model.ts | 10 + src/models/model_old.ts | 16 +- src/types/types.ts | 21 ++ wavesrv/pkg/remote/remote.go | 2 +- wavesrv/pkg/remote/sshclient.go | 407 ++++++++++++++++++++-- wavesrv/pkg/scpacket/scpacket.go | 101 +++++- wavesrv/pkg/scws/scws.go | 12 + wavesrv/pkg/sstore/sstore.go | 66 +--- wavesrv/pkg/sstore/updatebus.go | 78 ++++- 18 files changed, 736 insertions(+), 121 deletions(-) create mode 100644 src/app/common/modals/userinput.less create mode 100644 src/app/common/modals/userinput.tsx diff --git a/src/app/appconst.ts b/src/app/appconst.ts index 6a0df44be..24e177e1f 100644 --- a/src/app/appconst.ts +++ b/src/app/appconst.ts @@ -8,6 +8,7 @@ export const SESSION_SETTINGS = "sessionSettings"; export const LINE_SETTINGS = "lineSettings"; export const CLIENT_SETTINGS = "clientSettings"; export const TAB_SWITCHER = "tabSwitcher"; +export const USER_INPUT = "userInput"; export const LineContainer_Main = "main"; export const LineContainer_History = "history"; diff --git a/src/app/common/elements/markdown.less b/src/app/common/elements/markdown.less index ef8943132..1e68db420 100644 --- a/src/app/common/elements/markdown.less +++ b/src/app/common/elements/markdown.less @@ -5,6 +5,7 @@ margin-bottom: 10px; font-family: @markdown-font; font-size: 14px; + overflow-wrap: break-word; code { background-color: @markdown-highlight; diff --git a/src/app/common/elements/passwordfield.tsx b/src/app/common/elements/passwordfield.tsx index b2781e03b..de49ed31c 100644 --- a/src/app/common/elements/passwordfield.tsx +++ b/src/app/common/elements/passwordfield.tsx @@ -60,7 +60,13 @@ class PasswordField extends TextField { }; return ( -