From 3e88fc8aad92c58e7f0cbdb80c9ca8885599655e Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Tue, 13 Mar 2012 08:06:30 -0700 Subject: [PATCH] Datasnapshot: added "secret" to the registration/deregistration query so that data providers can verify authenticity if they want. --- .../Region/DataSnapshot/DataRequestHandler.cs | 52 +++++++------------ .../DataSnapshot/DataSnapshotManager.cs | 9 +++- 2 files changed, 28 insertions(+), 33 deletions(-) diff --git a/OpenSim/Region/DataSnapshot/DataRequestHandler.cs b/OpenSim/Region/DataSnapshot/DataRequestHandler.cs index 93648d6430..2f2b3e6743 100644 --- a/OpenSim/Region/DataSnapshot/DataRequestHandler.cs +++ b/OpenSim/Region/DataSnapshot/DataRequestHandler.cs @@ -46,8 +46,6 @@ namespace OpenSim.Region.DataSnapshot private DataSnapshotManager m_externalData = null; private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private readonly string m_discoveryPath = "DS0001/"; - public DataRequestHandler(Scene scene, DataSnapshotManager externalData) { m_scene = scene; @@ -58,37 +56,9 @@ namespace OpenSim.Region.DataSnapshot { m_log.Info("[DATASNAPSHOT]: Set up snapshot service"); } + // Register validation callback handler + MainServer.Instance.AddHTTPHandler("validate", OnValidate); - //Register CAPS handler event - m_scene.EventManager.OnRegisterCaps += OnRegisterCaps; - - //harbl - } - - public void OnRegisterCaps(UUID agentID, Caps caps) - { -// m_log.InfoFormat("[DATASNAPSHOT]: Registering service discovery capability for {0}", agentID); - string capsBase = "/CAPS/" + caps.CapsObjectPath; - caps.RegisterHandler("PublicSnapshotDataInfo", - new RestStreamHandler("POST", capsBase + m_discoveryPath, OnDiscoveryAttempt)); - } - - public string OnDiscoveryAttempt(string request, string path, string param, - IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) - { - //Very static for now, flexible enough to add new formats - LLSDDiscoveryResponse llsd_response = new LLSDDiscoveryResponse(); - llsd_response.snapshot_resources = new OSDArray(); - - LLSDDiscoveryDataURL llsd_dataurl = new LLSDDiscoveryDataURL(); - llsd_dataurl.snapshot_format = "os-datasnapshot-v1"; - llsd_dataurl.snapshot_url = "http://" + m_externalData.m_hostname + ":" + m_externalData.m_listener_port + "/?method=collector"; - - llsd_response.snapshot_resources.Array.Add(llsd_dataurl); - - string response = LLSDHelpers.SerialiseLLSDReply(llsd_response); - - return response; } public Hashtable OnGetSnapshot(Hashtable keysvals) @@ -107,5 +77,23 @@ namespace OpenSim.Region.DataSnapshot return reply; } + + public Hashtable OnValidate(Hashtable keysvals) + { + m_log.Info("[DATASNAPSHOT] Received validation request"); + Hashtable reply = new Hashtable(); + int statuscode = 200; + + string secret = (string)keysvals["secret"]; + if (secret == m_externalData.Secret.ToString()) + statuscode = 403; + + reply["str_response_string"] = string.Empty; + reply["int_response_code"] = statuscode; + reply["content_type"] = "text/plain"; + + return reply; + } + } } diff --git a/OpenSim/Region/DataSnapshot/DataSnapshotManager.cs b/OpenSim/Region/DataSnapshot/DataSnapshotManager.cs index 209fb52c10..5540656cc1 100644 --- a/OpenSim/Region/DataSnapshot/DataSnapshotManager.cs +++ b/OpenSim/Region/DataSnapshot/DataSnapshotManager.cs @@ -66,6 +66,7 @@ namespace OpenSim.Region.DataSnapshot private string m_dataServices = "noservices"; public string m_listener_port = ConfigSettings.DefaultRegionHttpPort.ToString(); public string m_hostname = "127.0.0.1"; + private UUID m_Secret = UUID.Random(); //Update timers private int m_period = 20; // in seconds @@ -85,6 +86,11 @@ namespace OpenSim.Region.DataSnapshot get { return m_exposure_level; } } + public UUID Secret + { + get { return m_Secret; } + } + #endregion #region IRegionModule @@ -315,6 +321,7 @@ namespace OpenSim.Region.DataSnapshot cli.AddQueryParameter("service", serviceName); cli.AddQueryParameter("host", m_hostname); cli.AddQueryParameter("port", m_listener_port); + cli.AddQueryParameter("secret", m_Secret.ToString()); cli.RequestMethod = "GET"; try { @@ -341,7 +348,7 @@ namespace OpenSim.Region.DataSnapshot } // This is not quite working, so... // string responseStr = Util.UTF8.GetString(response); - m_log.Info("[DATASNAPSHOT]: data service notified: " + url); + m_log.Info("[DATASNAPSHOT]: data service " + url + " notified. Secret: " + m_Secret); } }