public void TestUnixAgentDispose() { const string socketFileName = "test1.socket"; if (File.Exists (socketFileName)) { File.Delete(socketFileName); } using (var agent = new UnixAgent(socketFileName)) { Assert.That(File.Exists(socketFileName), Is.True, "Failed to create socket file"); } // check that temporary directory was cleaned up after dispose Assert.That(File.Exists(socketFileName), Is.False, "Socket file was not deleted"); }
public void TestUnixAgentBadMessage() { const string socketFileName = "test2.socket"; if (File.Exists (socketFileName)) { File.Delete(socketFileName); } using (var agent = new UnixAgent(socketFileName)) using (var client = new Mono.Unix.UnixClient(socketFileName)) using (var stream = client.GetStream ()) { var message = new byte[] { 0, 0, 0, 0 }; stream.Write(message, 0, message.Length); // send garbage stream.Flush(); var reply = new byte[5]; stream.Read(reply, 0, reply.Length); var expected = new byte [] { 0, 0, 0, 1, (byte)Agent.Message.SSH_AGENT_FAILURE, }; Assert.That(reply, Is.EqualTo(expected)); } }
public override bool Initialize(IPluginHost host) { pluginHost = host; uiHelper = new UIHelper(pluginHost); removeKeyList = new List<ISshKey>(); debug = (pluginHost .CommandLineArgs[AppDefs.CommandLineOptions.Debug] != null); LoadOptions(); if (debug) Log("Loading KeeAgent..."); var isWindows = Environment.OSVersion.Platform == PlatformID.Win32NT; var domainSocketPath = Environment.GetEnvironmentVariable (UnixClient.SshAuthSockName); try { if (Options.AgentMode != AgentMode.Client) { if (isWindows) { // In windows, try to start an agent. If Pageant is running, we will // get an exception. try { var pagent = new PageantAgent(); pagent.Locked += PageantAgent_Locked; pagent.KeyUsed += PageantAgent_KeyUsed; pagent.KeyAdded += PageantAgent_KeyAdded; pagent.KeyRemoved += PageantAgent_KeyRemoved; pagent.MessageReceived += PageantAgent_MessageReceived; // IMPORTANT: if you change either of these callbacks, you need // to make sure that they do not block the main event loop. pagent.FilterKeyListCallback = FilterKeyList; pagent.ConfirmUserPermissionCallback = Default.ConfirmCallback; agent = pagent; if (Options.UseCygwinSocket) { StartCygwinSocket(); } if (Options.UseMsysSocket) { StartMsysSocket(); } } catch (PageantRunningException) { if (Options.AgentMode != AgentMode.Auto) { throw; } } } else { // In Unix, we only try to start an agent if Agent mode was explicitly // selected or there is no agent running (indicated by environment variable). if (Options.AgentMode == AgentMode.Server || string.IsNullOrWhiteSpace (domainSocketPath)) { var unixAgent = new UnixAgent(); unixAgent.Locked += PageantAgent_Locked; unixAgent.KeyUsed += PageantAgent_KeyUsed; unixAgent.KeyAdded += PageantAgent_KeyAdded; unixAgent.KeyRemoved += PageantAgent_KeyRemoved; unixAgent.MessageReceived += PageantAgent_MessageReceived; // IMPORTANT: if you change either of these callbacks, you need // to make sure that they do not block the main event loop. unixAgent.FilterKeyListCallback = FilterKeyList; unixAgent.ConfirmUserPermissionCallback = Default.ConfirmCallback; agent = unixAgent; try { var socketPath = Options.UnixSocketPath.ExpandEnvironmentVariables(); unixAgent.StartUnixSocket (socketPath); } catch (ArgumentNullException) { var autoModeMessage = Options.AgentMode == AgentMode.Auto ? " to use KeeAgent in Agent mode or enable an external SSH agent in your " + "desktop session manager to use KeeAgent in Client mode." : "."; MessageService.ShowWarning("KeeAgent: No path specified for Agent socket file.", "Please enter a file in the KeeAgent options (Tools > Options... > KeeAgent tab)" + autoModeMessage); } catch (Exception ex) { MessageService.ShowWarning(ex.Message); } } } } if (agent == null) { if (isWindows) { agent = new PageantClient(); } else { agent = new UnixClient(); } } pluginHost.MainWindow.FileOpened += MainForm_FileOpened; pluginHost.MainWindow.FileClosingPost += MainForm_FileClosing; pluginHost.MainWindow.FileClosed += MainForm_FileClosed; // load all database that are already opened foreach (var database in pluginHost.MainWindow.DocumentManager.Documents) { MainForm_FileOpened(this, new FileOpenedEventArgs(database.Database)); } AddMenuItems(); GlobalWindowManager.WindowAdded += WindowAddedHandler; MessageService.MessageShowing += MessageService_MessageShowing; columnProvider = new KeeAgentColumnProvider(this); host.ColumnProviderPool.Add(columnProvider); SprEngine.FilterCompile += SprEngine_FilterCompile; SprEngine.FilterPlaceholderHints.Add(keyFilePathSprPlaceholder); SprEngine.FilterPlaceholderHints.Add(identFileOptSprPlaceholder); return true; } catch (PageantRunningException) { ShowPageantRunningErrorMessage(); } catch (Exception ex) { MessageService.ShowWarning("KeeAgent failed to load:", ex.Message); } Terminate(); return false; }
public void TestUnixAgentGoodMessage() { const string socketFileName = "test3.socket"; if (File.Exists(socketFileName)) { File.Delete(socketFileName); } using (var agent = new UnixAgent(socketFileName)) using (var client = new Mono.Unix.UnixClient(socketFileName)) using (var stream = client.GetStream()) { var message = new byte[] { 0, 0, 0, 1, (byte)Agent.Message.SSH1_AGENTC_REQUEST_RSA_IDENTITIES, }; stream.Write(message, 0, message.Length); // send message stream.Flush(); var reply = new byte[9]; stream.Read(reply, 0, reply.Length); var expected = new byte[] { 0, 0, 0, 5, (byte)Agent.Message.SSH1_AGENT_RSA_IDENTITIES_ANSWER, 0, 0, 0, 0, }; Assert.That(reply, Is.EqualTo(expected)); } }