From 4877f181fb1935d0790dcf17f95dfe3d4b86169e Mon Sep 17 00:00:00 2001 From: qwerty287 Date: Thu, 20 Nov 2025 01:32:28 +0000 Subject: [PATCH] Only prompt for SSH passphrase if necessary (#844) Since one of the last updates (I cannot tell you exactly which one, but likely 0.10 or 0.11), tea always asks me for my ssh passphrase without actually needing it. I do not have anything configured regarding SSH keys. The passphrase is not even verified, you can enter anything there. But as this is quite annoying, I fixed this by moving the prompt to only be used when a ssh key/cert is configured. Would be nice to get this in. Thanks! Reviewed-on: https://gitea.com/gitea/tea/pulls/844 Reviewed-by: Lunny Xiao Co-authored-by: qwerty287 Co-committed-by: qwerty287 --- modules/config/login.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/modules/config/login.go b/modules/config/login.go index 0a7b0ca..fb71b9e 100644 --- a/modules/config/login.go +++ b/modules/config/login.go @@ -282,23 +282,13 @@ func (l *Login) Client(options ...gitea.ClientOption) *gitea.Client { options = append(options, gitea.SetDebugMode()) } - if ok, err := utils.IsKeyEncrypted(l.SSHKey); ok && err == nil && l.SSHPassphrase == "" { - if err := huh.NewInput(). - Title("ssh-key is encrypted please enter the passphrase: "). - Validate(huh.ValidateNotEmpty()). - EchoMode(huh.EchoModePassword). - Value(&l.SSHPassphrase). - WithTheme(theme.GetTheme()). - Run(); err != nil { - log.Fatal(err) - } - } - if l.SSHCertPrincipal != "" { + l.askForSSHPassphrase() options = append(options, gitea.UseSSHCert(l.SSHCertPrincipal, l.SSHKey, l.SSHPassphrase)) } if l.SSHKeyFingerprint != "" { + l.askForSSHPassphrase() options = append(options, gitea.UseSSHPubkey(l.SSHKeyFingerprint, l.SSHKey, l.SSHPassphrase)) } @@ -313,6 +303,20 @@ func (l *Login) Client(options ...gitea.ClientOption) *gitea.Client { return client } +func (l *Login) askForSSHPassphrase() { + if ok, err := utils.IsKeyEncrypted(l.SSHKey); ok && err == nil && l.SSHPassphrase == "" { + if err := huh.NewInput(). + Title("ssh-key is encrypted please enter the passphrase: "). + Validate(huh.ValidateNotEmpty()). + EchoMode(huh.EchoModePassword). + Value(&l.SSHPassphrase). + WithTheme(theme.GetTheme()). + Run(); err != nil { + log.Fatal(err) + } + } +} + // GetSSHHost returns SSH host name func (l *Login) GetSSHHost() string { if l.SSHHost != "" {