private 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; } } nm[key] = OSD.FromString(loginURI + val); } else { nm[key] = OSD.FromString(val); } } } capReq.Response = nm; return false; }
private bool KnownCapDelegate(CapsRequest capReq, CapsStage stage) { lock (this) { if (!KnownCapsDelegates.ContainsKey(capReq.Info.CapType)) return false; if (stage == CapsStage.Response) { if (capReq.Response != null) { OSDMap map = (OSDMap)capReq.Response; if (map.ContainsKey("uploader")) { string val = map["uploader"].AsString(); if (!KnownCaps.ContainsKey(val)) { CapInfo newCap = new CapInfo(val, capReq.Info.Sim, capReq.Info.CapType, CapsDataFormat.Binary, CapsDataFormat.OSD); newCap.AddDelegate(new CapsDelegate(KnownCapDelegate)); lock (this) { KnownCaps[val] = newCap; } } map["uploader"] = OSD.FromString(loginURI + val); } } } List<CapsDelegate> delegates = KnownCapsDelegates[capReq.Info.CapType]; foreach (CapsDelegate d in delegates) { if (d(capReq, stage)) { return true; } } } return false; }
// GenericCheck: replace the sim address in a packet with our proxy address private 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; }
private void ProxyLoginSD(NetworkStream netStream, byte[] content) { lock (this) { AutoResetEvent remoteComplete = new AutoResetEvent(false); CapsClient loginRequest = new CapsClient(proxyConfig.remoteLoginUri); 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.BeginGetResponse(content, "application/llsd+xml", 1000 * 100); remoteComplete.WaitOne(1000 * 100, 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) { if (map != null) { OpenMetaverse.Logger.Log("Connection to server failed, returned LLSD error follows:\n" + map.ToString(), Helpers.LogLevel.Error); } 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(); } }
private void ProxyLogin(NetworkStream netStream, byte[] content) { lock (this) { // incase some silly person tries to access with their web browser if (content.Length <= 0) return; // convert the body into an XML-RPC request XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(Encoding.UTF8.GetString(content)); // call the loginRequestDelegate lock (loginRequestDelegates) { foreach (XmlRpcRequestDelegate d in loginRequestDelegates) { try { d(this, new XmlRpcRequestEventArgs(request)); } //try { d(request); } catch (Exception e) { OpenMetaverse.Logger.Log("Exception in login request delegate" + e, Helpers.LogLevel.Error, e); } } } XmlRpcResponse response; try { // forward the XML-RPC request to the server response = (XmlRpcResponse)request.Send(proxyConfig.remoteLoginUri.ToString(), 30 * 1000); // 30 second timeout } catch (Exception e) { OpenMetaverse.Logger.Log("Error during login response", Helpers.LogLevel.Error, e); return; } System.Collections.Hashtable responseData; try { responseData = (System.Collections.Hashtable)response.Value; } catch (Exception e) { OpenMetaverse.Logger.Log(e.Message, Helpers.LogLevel.Error); return; } // proxy any simulator address given in the XML-RPC response if (responseData.Contains("sim_ip") && responseData.Contains("sim_port")) { IPEndPoint realSim = new IPEndPoint(IPAddress.Parse((string)responseData["sim_ip"]), Convert.ToUInt16(responseData["sim_port"])); IPEndPoint fakeSim = ProxySim(realSim); responseData["sim_ip"] = fakeSim.Address.ToString(); responseData["sim_port"] = fakeSim.Port; activeCircuit = realSim; } // start a new proxy session Reset(); if (responseData.Contains("seed_capability")) { CapInfo info = new CapInfo((string)responseData["seed_capability"], activeCircuit, "SeedCapability"); info.AddDelegate(new CapsDelegate(FixupSeedCapsResponse)); KnownCaps[(string)responseData["seed_capability"]] = info; responseData["seed_capability"] = loginURI + responseData["seed_capability"]; } // 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(); lock (loginResponseDelegates) { foreach (XmlRpcResponseDelegate d in loginResponseDelegates) { try { d(response); } catch (Exception e) { OpenMetaverse.Logger.Log("Exception in login response delegate" + e, Helpers.LogLevel.Error, e); } } } } }
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 response = (XmlRpcResponse)request.Send(proxyConfig.remoteLoginUri.ToString(), 30 * 1000); // 30 second timeout } catch (Exception e) { Console.WriteLine(e.Message); return; } System.Collections.Hashtable responseData = (System.Collections.Hashtable)response.Value; // proxy any simulator address given in the XML-RPC response if (responseData.Contains("sim_ip") && responseData.Contains("sim_port")) { IPEndPoint realSim = new IPEndPoint(IPAddress.Parse((string)responseData["sim_ip"]), Convert.ToUInt16(responseData["sim_port"])); IPEndPoint fakeSim = ProxySim(realSim); responseData["sim_ip"] = fakeSim.Address.ToString(); responseData["sim_port"] = fakeSim.Port; activeCircuit = realSim; } // start a new proxy session Reset(); if (responseData.Contains("seed_capability")) { CapInfo info = new CapInfo((string)responseData["seed_capability"], activeCircuit, "SeedCapability"); info.AddDelegate(new CapsDelegate(FixupSeedCapsResponse)); KnownCaps[(string)responseData["seed_capability"]] = info; responseData["seed_capability"] = loginURI + responseData["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(); } }
private void ProxyLoginLLSD(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")); LLSD response = null; loginRequest.OnComplete += new CapsClient.CompleteCallback( delegate(CapsClient client, LLSD result, Exception error) { if (error == null) { if (result != null && result.Type == LLSDType.Map) { response = result; } } remoteComplete.Set(); } ); loginRequest.StartRequest(content, "application/xml"); //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; } LLSDMap map = (LLSDMap)response; LLSD 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"] = LLSD.FromString(fakeSim.Address.ToString()); map["sim_port"] = LLSD.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"] = LLSD.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(LLSDParser.SerializeXmlString(response)); writer.Close(); } }