Datasnapshot: added "secret" to the registration/deregistration query so that data providers can verify authenticity if they want.

0.7.4.1
Diva Canto 2012-03-13 08:06:30 -07:00
parent 13fb582c12
commit 4eb2605c79
2 changed files with 28 additions and 33 deletions

View File

@ -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;
}
}
}

View File

@ -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);
}
}