Пример #1
0
        public void TestUnixAgentGoodMessage()
        {
            const string socketFileName = "test3.socket";

            if (File.Exists(socketFileName))
            {
                File.Delete(socketFileName);
            }

            using (var agent = new UnixAgent()) {
                agent.StartUnixSocket(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));
                    }
            }
        }
Пример #2
0
        public void TestUnixAgentBadMessage()
        {
            const string socketFileName = "test2.socket";

            if (File.Exists(socketFileName))
            {
                File.Delete(socketFileName);
            }

            using (var agent = new UnixAgent()) {
                agent.StartUnixSocket(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));
                    }
            }
        }
Пример #3
0
		public void TestPassUnixFd ()
		{
			using (ListenUnix (FASTCGI_SOCKET_PATH, FastCgiAccept))
			using (ListenUnix (FPM_SOCKET_PATH, FpmUnixAccept)) {
				var webserver = new UnixClient (FPM_SOCKET_PATH);
				string read;
				using (var stream = webserver.GetStream ())
				using (var reader = new StreamReader(stream))
					read = reader.ReadLine ();
				Assert.AreEqual (MESSAGE, read);
			}
		}
Пример #4
0
        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));
              }
        }
Пример #5
0
		/*
		 * Loads the specific agent assembly into this vm.
		 */
		public void Attach (string agent, string args) {
			string user = UnixUserInfo.GetRealUser ().UserName;

			// Check whenever the attach socket exists
			string socket_file = "/tmp/mono-" + user + "/.mono-" + pid;

			if (!File.Exists (socket_file)) {
				string trigger_file = "/tmp/.mono_attach_pid" + pid;
				FileStream trigger = null;

				try {
					trigger = File.Create (trigger_file);
					trigger.Close ();

					// Ask the vm to start the attach mechanism
					Syscall.kill ((int)pid, Signum.SIGQUIT);

					// Wait for the socket file to materialize
					int i;
					for (i = 0; i < 10; ++i) {
						if (File.Exists (socket_file))
							break;
						Thread.Sleep (100);
					}

					if (i == 10)
						throw new Exception (String.Format ("Runtime failed to create attach socket '{0}'.", socket_file));
				} finally {
					File.Delete (trigger_file);
				}
			}

			/* 
			 * We communicate with the agent inside the runtime using a simlified
			 * version of the .net remoting protocol.
			 */

			string path = "/tmp/mono-" + user + "/.mono-" + pid;

			UnixClient client = new UnixClient (path);

			NetworkStream stream = client.GetStream ();

			// Compose payload
			MemoryStream ms = new MemoryStream ();
			BinaryWriter writer = new BinaryWriter (ms);
			write_string (writer, "attach");
			write_string (writer, agent);
			write_string (writer, args);

			// Write header
			byte[] magic = new byte [] { (byte)'M', (byte)'O', (byte)'N', (byte)'O', 1, 0 };
			stream.Write (magic, 0, magic.Length);

			// Write payload length
			new BinaryWriter (stream).Write ((int)ms.Length);

			// Write payload
			stream.Write (ms.GetBuffer (), 0, (int)ms.Length);
		}
Пример #6
0
		protected override void SendRequest (RequestMessage request)
		{
			client = new UnixClient (this.socket_name);
			client.SendBufferSize = 4096;
			client.ReceiveBufferSize = 4096;
			NetworkStream stream = client.GetStream ();
			
			base.SendRequest (request, stream);
		}
Пример #7
0
        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));
              }
        }