From 3973fae8ef3edc4b646e19e720bd2bf8d1e73bfa Mon Sep 17 00:00:00 2001 From: Hein Gustavsen Date: Thu, 9 Oct 2025 09:44:08 +0200 Subject: [PATCH] Improve 1Password logging --- ExternalConnectors/OP/OnePasswordCli.cs | 12 +++++------ mRemoteNG/Connection/Protocol/PuttyBase.cs | 5 +++-- .../Connection/Protocol/RDP/RdpProtocol.cs | 10 ++++++---- mRemoteNG/Language/Language.Designer.cs | 20 ++++++++++++++++++- mRemoteNG/Language/Language.resx | 6 ++++++ 5 files changed, 40 insertions(+), 13 deletions(-) diff --git a/ExternalConnectors/OP/OnePasswordCli.cs b/ExternalConnectors/OP/OnePasswordCli.cs index 2987fac0..57888912 100644 --- a/ExternalConnectors/OP/OnePasswordCli.cs +++ b/ExternalConnectors/OP/OnePasswordCli.cs @@ -5,11 +5,9 @@ using System.Web; namespace ExternalConnectors.OP; -public class OnePasswordCliException : Exception +public class OnePasswordCliException(string message, string arguments) : Exception(message) { - public OnePasswordCliException(string message) : base(message) - { - } + public string Arguments { get; set; } = arguments; } public class OnePasswordCli @@ -68,11 +66,13 @@ public class OnePasswordCli password = string.Empty; privateKey = string.Empty; domain = string.Empty; - throw new OnePasswordCliException($"Error running op item get: {error}"); + throw new OnePasswordCliException($"Error running op item get: {error}", + OnePasswordCliExecutable + " " + string.Join(' ', args)); } var items = JsonSerializer.Deserialize(output, JsonSerializerOptions) ?? - throw new OnePasswordCliException("1Password returned null"); + throw new OnePasswordCliException("1Password returned null", + OnePasswordCliExecutable + " " + string.Join(' ', args)); username = items.Fields?.FirstOrDefault(x => x.Purpose == UserNamePurpose)?.Value ?? string.Empty; password = items.Fields?.FirstOrDefault(x => x.Purpose == PasswordPurpose)?.Value ?? string.Empty; privateKey = items.Fields?.FirstOrDefault(x => x.Type == SshKeyType)?.Value ?? string.Empty; diff --git a/mRemoteNG/Connection/Protocol/PuttyBase.cs b/mRemoteNG/Connection/Protocol/PuttyBase.cs index ef00d786..384938f8 100644 --- a/mRemoteNG/Connection/Protocol/PuttyBase.cs +++ b/mRemoteNG/Connection/Protocol/PuttyBase.cs @@ -156,9 +156,10 @@ namespace mRemoteNG.Connection.Protocol { ExternalConnectors.OP.OnePasswordCli.ReadPassword($"{UserViaAPI}", out username, out password, out domain, out privatekey); } - catch (Exception ex) + catch (ExternalConnectors.OP.OnePasswordCliException ex) { - Event_ErrorOccured(this, "1Password Interface Error: " + ex.Message, 0); + Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, Language.ECPOnePasswordCommandLine + ": " + ex.Arguments); + Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, Language.ECPOnePasswordReadFailed + Environment.NewLine + ex.Message); } } diff --git a/mRemoteNG/Connection/Protocol/RDP/RdpProtocol.cs b/mRemoteNG/Connection/Protocol/RDP/RdpProtocol.cs index c291b586..99111481 100644 --- a/mRemoteNG/Connection/Protocol/RDP/RdpProtocol.cs +++ b/mRemoteNG/Connection/Protocol/RDP/RdpProtocol.cs @@ -477,9 +477,10 @@ namespace mRemoteNG.Connection.Protocol.RDP string RDGUserViaAPI = InterfaceControl.Info.RDGatewayUserViaAPI; ExternalConnectors.OP.OnePasswordCli.ReadPassword($"{RDGUserViaAPI}", out gwu, out gwp, out gwd, out pkey); } - catch (Exception ex) + catch (ExternalConnectors.OP.OnePasswordCliException ex) { - Event_ErrorOccured(this, "1Password Interface Error: " + ex.Message, 0); + Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, Language.ECPOnePasswordCommandLine + ": " + ex.Arguments); + Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, Language.ECPOnePasswordReadFailed + Environment.NewLine + ex.Message); } } @@ -588,9 +589,10 @@ namespace mRemoteNG.Connection.Protocol.RDP { ExternalConnectors.OP.OnePasswordCli.ReadPassword($"{userViaApi}", out userName, out password, out domain, out pkey); } - catch (Exception ex) + catch (ExternalConnectors.OP.OnePasswordCliException ex) { - Event_ErrorOccured(this, "1Password Interface Error: " + ex.Message, 0); + Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, Language.ECPOnePasswordCommandLine + ": " + ex.Arguments); + Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, Language.ECPOnePasswordReadFailed + Environment.NewLine + ex.Message); } } diff --git a/mRemoteNG/Language/Language.Designer.cs b/mRemoteNG/Language/Language.Designer.cs index 8bbae5c4..e89a3148 100644 --- a/mRemoteNG/Language/Language.Designer.cs +++ b/mRemoteNG/Language/Language.Designer.cs @@ -19,7 +19,7 @@ namespace mRemoteNG.Resources.Language { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "18.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Language { @@ -1879,6 +1879,24 @@ namespace mRemoteNG.Resources.Language { } } + /// + /// Looks up a localized string similar to 1Password command line. + /// + internal static string ECPOnePasswordCommandLine { + get { + return ResourceManager.GetString("ECPOnePasswordCommandLine", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 1Password read failed. + /// + internal static string ECPOnePasswordReadFailed { + get { + return ResourceManager.GetString("ECPOnePasswordReadFailed", resourceCulture); + } + } + /// /// Looks up a localized string similar to Do you want to continue with no password?. /// diff --git a/mRemoteNG/Language/Language.resx b/mRemoteNG/Language/Language.resx index 395b3a7a..b3de6468 100644 --- a/mRemoteNG/Language/Language.resx +++ b/mRemoteNG/Language/Language.resx @@ -2311,6 +2311,12 @@ Nightly Channel includes Alphas, Betas & Release Candidates. 1Password + + 1Password read failed + + + 1Password command line + None