Beispiel #1
0
        // GenericCheck: replace the sim address in a packet with our proxy address
        public void GenericCheck(ref uint simIP, ref ushort simPort, ref string simCaps, bool active)
        {
            IPAddress sim_ip = new IPAddress((long)simIP);

            IPEndPoint realSim = new IPEndPoint(sim_ip, Convert.ToInt32(simPort));
            IPEndPoint fakeSim = ProxySim(realSim);

            simPort = (ushort)fakeSim.Port;
            byte[] bytes = fakeSim.Address.GetAddressBytes();
            simIP = Utils.BytesToUInt(bytes);
            if (simCaps != null && simCaps.Length > 0)
            {
                CapInfo info = new CapInfo(simCaps, realSim, "SeedCapability");
                info.AddDelegate(new CapsDelegate(FixupSeedCapsResponse));
                lock (this)
                {
                    KnownCaps[simCaps] = info;
                }
                simCaps = loginURI + simCaps;
            }

            if (active)
                activeCircuit = realSim;
        }
Beispiel #2
0
        public bool FixupSeedCapsResponse(CapsRequest capReq, CapsStage stage)
        {
            if (stage != CapsStage.Response) return false;

            OSDMap nm = new OSDMap();

            if (capReq.Response.Type == OSDType.Map)
            {
                OSDMap m = (OSDMap)capReq.Response;

                foreach (string key in m.Keys)
                {
                    string val = m[key].AsString();

                    if (!String.IsNullOrEmpty(val))
                    {
                        if (!KnownCaps.ContainsKey(val))
                        {
                            CapInfo newCap = new CapInfo(val, capReq.Info.Sim, key);
                            newCap.AddDelegate(new CapsDelegate(KnownCapDelegate));
                            lock (this) { KnownCaps[val] = newCap; }
                            //Console.WriteLine("    >> Adding KnownCap " + val + " = " + newCap);
                        }
                        nm[key] = OSD.FromString(loginURI + val);
                        //Console.WriteLine("    >> Sending transformed Cap " + loginURI + val);
                    }
                    else
                    {
                        nm[key] = OSD.FromString(val);
                    }
                }
            }

            //Console.WriteLine("---------------");
            //lock (this)
            //{
            //    foreach (KeyValuePair<string, CapInfo> kvp in KnownCaps)
            //    {
            //        Console.WriteLine(" >> Key: " + kvp.Key + "; Value: " + kvp.Value.CapType);
            //    }
            //}
            //Console.WriteLine("---------------");

            capReq.Response = nm;
            return false;
        }
Beispiel #3
0
        private void ProxyLoginSD(NetworkStream netStream, byte[] content)
        {
            lock (this)
            {
                ServicePointManager.CertificatePolicy = new OpenMetaverse.AcceptAllCertificatePolicy();
                AutoResetEvent remoteComplete = new AutoResetEvent(false);
                //CapsClient loginRequest = new CapsClient(proxyConfig.remoteLoginUri);
                CapsClient loginRequest = new CapsClient(new Uri("https://login1.aditi.lindenlab.com/cgi-bin/auth.cgi"));
                OSD response = null;
                loginRequest.OnComplete += new CapsClient.CompleteCallback(
                    delegate(CapsClient client, OSD result, Exception error)
                    {
                        if (error == null)
                        {
                            if (result != null && result.Type == OSDType.Map)
                            {
                                response = result;
                            }
                        }
                        remoteComplete.Set();
                    }
                    );
                //loginRequest.StartRequest(content, "application/xml"); //xml+llsd
                loginRequest.BeginGetResponse(content, "application/xml", 20000); //xml+llsd
                remoteComplete.WaitOne(30000, false);

                if (response == null)
                {
                    byte[] wr = Encoding.ASCII.GetBytes("HTTP/1.0 500 Internal Server Error\r\nContent-Length: 0\r\n\r\n");
                    netStream.Write(wr, 0, wr.Length);
                    return;
                }

                OSDMap map = (OSDMap)response;

                OSD llsd;
                string sim_port = null, sim_ip = null, seed_capability = null;
                map.TryGetValue("sim_port", out llsd);
                if (llsd != null) sim_port = llsd.AsString();
                map.TryGetValue("sim_ip", out llsd);
                if (llsd != null) sim_ip = llsd.AsString();
                map.TryGetValue("seed_capability", out llsd);
                if (llsd != null) seed_capability = llsd.AsString();

                if (sim_port == null || sim_ip == null || seed_capability == null)
                {
                    byte[] wr = Encoding.ASCII.GetBytes("HTTP/1.0 500 Internal Server Error\r\nContent-Length: 0\r\n\r\n");
                    netStream.Write(wr, 0, wr.Length);
                    return;
                }

                IPEndPoint realSim = new IPEndPoint(IPAddress.Parse(sim_ip), Convert.ToUInt16(sim_port));
                IPEndPoint fakeSim = ProxySim(realSim);
                map["sim_ip"] = OSD.FromString(fakeSim.Address.ToString());
                map["sim_port"] = OSD.FromInteger(fakeSim.Port);
                activeCircuit = realSim;

                // start a new proxy session
                Reset();

                CapInfo info = new CapInfo(seed_capability, activeCircuit, "SeedCapability");
                info.AddDelegate(new CapsDelegate(FixupSeedCapsResponse));

                KnownCaps[seed_capability] = info;
                map["seed_capability"] = OSD.FromString(loginURI + seed_capability);

                StreamWriter writer = new StreamWriter(netStream);
                writer.Write("HTTP/1.0 200 OK\r\n");
                writer.Write("Content-type: application/xml+llsd\r\n");
                writer.Write("\r\n");
                writer.Write(OSDParser.SerializeLLSDXmlString(response));
                writer.Close();
            }
        }
Beispiel #4
0
 public CapsRequest(CapInfo info)
 {
     Info = info;
 }
Beispiel #5
0
        private void ProxyLogin(NetworkStream netStream, byte[] content)
        {
            lock (this)
            {
                // convert the body into an XML-RPC request
                XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(Encoding.UTF8.GetString(content));

                // call the loginRequestDelegate
                if (loginRequestDelegate != null)
                    try
                    {
                        loginRequestDelegate(request);
                    }
                    catch (Exception e)
                    {
                        Log("exception in login request deligate: " + e.Message, true);
                        Log(e.StackTrace, true);
                    }

                XmlRpcResponse response;
                try
                {
                    // forward the XML-RPC request to the server
                    Console.WriteLine("---> Calling " + remoteLoginURI);
                    response = (XmlRpcResponse)request.Send(/*proxyConfig.remoteLoginUri.ToString()*/ remoteLoginURI,
                        30 * 1000); // 30 second timeout

                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return;
                }

                if (response.IsFault)
                {
                    Console.WriteLine("XmlRpc failed " + response.FaultString);
                }

                System.Collections.Hashtable hash = (System.Collections.Hashtable)response.Value;

                // proxy any simulator address given in the XML-RPC response
                if (hash.Contains("sim_ip") && hash.Contains("sim_port"))
                {
                    hash["real_sim_ip"] = hash["sim_ip"];
                    hash["real_sim_port"] = hash["sim_port"];

                    IPEndPoint realSim = new IPEndPoint(IPAddress.Parse((string)hash["sim_ip"]), Convert.ToUInt16(hash["sim_port"]));
                    IPEndPoint fakeSim = ProxySim(realSim);
                    hash["sim_ip"] = fakeSim.Address.ToString();
                    hash["sim_port"] = fakeSim.Port;

                    activeCircuit = realSim;
                }

                // start a new proxy session
                Reset();

                if (hash.Contains("seed_capability"))
                {
                    CapInfo info = new CapInfo((string)hash["seed_capability"], activeCircuit, "SeedCapability");
                    info.AddDelegate(new CapsDelegate(FixupSeedCapsResponse));

                    KnownCaps[(string)hash["seed_capability"]] = info;
                    hash["seed_capability"] = loginURI + hash["seed_capability"];
                }

                // call the loginResponseDelegate
                if (loginResponseDelegate != null)
                {
                    try
                    {
                        loginResponseDelegate(response);
                    }
                    catch (Exception e)
                    {
                        Log("exception in login response delegate: " + e.Message, true);
                        Log(e.StackTrace, true);
                    }
                }

                // forward the XML-RPC response to the client
                StreamWriter writer = new StreamWriter(netStream);
                writer.Write("HTTP/1.0 200 OK\r\n");
                writer.Write("Content-type: text/xml\r\n");
                writer.Write("\r\n");

                XmlTextWriter responseWriter = new XmlTextWriter(writer);
                XmlRpcResponseSerializer.Singleton.Serialize(responseWriter, response);
                responseWriter.Close(); writer.Close();
            }
        }