aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/HypergridService
diff options
context:
space:
mode:
authorDiva Canto2010-01-28 19:19:42 -0800
committerDiva Canto2010-01-28 19:19:42 -0800
commit00f7d622cbc2c2e61d2efaacd8275da3f9821d8b (patch)
tree1bfc6dd3ac2a93443bc75baa03ceefba4cfacc1e /OpenSim/Services/HypergridService
parentAdded ExternalName config on Gatekeeper. (diff)
downloadopensim-SC_OLD-00f7d622cbc2c2e61d2efaacd8275da3f9821d8b.zip
opensim-SC_OLD-00f7d622cbc2c2e61d2efaacd8275da3f9821d8b.tar.gz
opensim-SC_OLD-00f7d622cbc2c2e61d2efaacd8275da3f9821d8b.tar.bz2
opensim-SC_OLD-00f7d622cbc2c2e61d2efaacd8275da3f9821d8b.tar.xz
HG 1.5 is in place. Tested in standalone only.
Diffstat (limited to 'OpenSim/Services/HypergridService')
-rw-r--r--OpenSim/Services/HypergridService/GatekeeperService.cs77
-rw-r--r--OpenSim/Services/HypergridService/HomeUsersSecurityService.cs67
-rw-r--r--OpenSim/Services/HypergridService/UserAgentService.cs210
3 files changed, 242 insertions, 112 deletions
diff --git a/OpenSim/Services/HypergridService/GatekeeperService.cs b/OpenSim/Services/HypergridService/GatekeeperService.cs
index 3cb5d50..3bf0836 100644
--- a/OpenSim/Services/HypergridService/GatekeeperService.cs
+++ b/OpenSim/Services/HypergridService/GatekeeperService.cs
@@ -34,6 +34,7 @@ using OpenSim.Framework;
34using OpenSim.Services.Interfaces; 34using OpenSim.Services.Interfaces;
35using GridRegion = OpenSim.Services.Interfaces.GridRegion; 35using GridRegion = OpenSim.Services.Interfaces.GridRegion;
36using OpenSim.Server.Base; 36using OpenSim.Server.Base;
37using OpenSim.Services.Connectors.Hypergrid;
37 38
38using OpenMetaverse; 39using OpenMetaverse;
39 40
@@ -50,9 +51,8 @@ namespace OpenSim.Services.HypergridService
50 51
51 IGridService m_GridService; 52 IGridService m_GridService;
52 IPresenceService m_PresenceService; 53 IPresenceService m_PresenceService;
53 IAuthenticationService m_AuthenticationService;
54 IUserAccountService m_UserAccountService; 54 IUserAccountService m_UserAccountService;
55 IHomeUsersSecurityService m_HomeUsersSecurityService; 55 IUserAgentService m_UserAgentService;
56 ISimulationService m_SimulationService; 56 ISimulationService m_SimulationService;
57 57
58 string m_AuthDll; 58 string m_AuthDll;
@@ -69,12 +69,12 @@ namespace OpenSim.Services.HypergridService
69 throw new Exception(String.Format("No section GatekeeperService in config file")); 69 throw new Exception(String.Format("No section GatekeeperService in config file"));
70 70
71 string accountService = serverConfig.GetString("UserAccountService", String.Empty); 71 string accountService = serverConfig.GetString("UserAccountService", String.Empty);
72 string homeUsersSecurityService = serverConfig.GetString("HomeUsersSecurityService", string.Empty); 72 string homeUsersService = serverConfig.GetString("HomeUsersSecurityService", string.Empty);
73 string gridService = serverConfig.GetString("GridService", String.Empty); 73 string gridService = serverConfig.GetString("GridService", String.Empty);
74 string presenceService = serverConfig.GetString("PresenceService", String.Empty); 74 string presenceService = serverConfig.GetString("PresenceService", String.Empty);
75 string simulationService = serverConfig.GetString("SimulationService", String.Empty); 75 string simulationService = serverConfig.GetString("SimulationService", String.Empty);
76 76
77 m_AuthDll = serverConfig.GetString("AuthenticationService", String.Empty); 77 //m_AuthDll = serverConfig.GetString("AuthenticationService", String.Empty);
78 78
79 // These 3 are mandatory, the others aren't 79 // These 3 are mandatory, the others aren't
80 if (gridService == string.Empty || presenceService == string.Empty || m_AuthDll == string.Empty) 80 if (gridService == string.Empty || presenceService == string.Empty || m_AuthDll == string.Empty)
@@ -92,8 +92,8 @@ namespace OpenSim.Services.HypergridService
92 92
93 if (accountService != string.Empty) 93 if (accountService != string.Empty)
94 m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(accountService, args); 94 m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(accountService, args);
95 if (homeUsersSecurityService != string.Empty) 95 if (homeUsersService != string.Empty)
96 m_HomeUsersSecurityService = ServerUtils.LoadPlugin<IHomeUsersSecurityService>(homeUsersSecurityService, args); 96 m_UserAgentService = ServerUtils.LoadPlugin<IUserAgentService>(homeUsersService, args);
97 97
98 if (simService != null) 98 if (simService != null)
99 m_SimulationService = simService; 99 m_SimulationService = simService;
@@ -206,13 +206,12 @@ namespace OpenSim.Services.HypergridService
206 account = m_UserAccountService.GetUserAccount(m_ScopeID, aCircuit.AgentID); 206 account = m_UserAccountService.GetUserAccount(m_ScopeID, aCircuit.AgentID);
207 if (account != null) 207 if (account != null)
208 { 208 {
209 // Make sure this is the user coming home, and not a fake 209 // Make sure this is the user coming home, and not a foreign user with same UUID as a local user
210 if (m_HomeUsersSecurityService != null) 210 if (m_UserAgentService != null)
211 { 211 {
212 Object ep = m_HomeUsersSecurityService.GetEndPoint(aCircuit.SessionID); 212 if (!m_UserAgentService.AgentIsComingHome(aCircuit.SessionID, m_ExternalName))
213 if (ep == null)
214 { 213 {
215 // This is a fake, this session never left this grid 214 // Can't do, sorry
216 reason = "Unauthorized"; 215 reason = "Unauthorized";
217 m_log.InfoFormat("[GATEKEEPER SERVICE]: Foreign agent {0} {1} has same ID as local user. Refusing service.", 216 m_log.InfoFormat("[GATEKEEPER SERVICE]: Foreign agent {0} {1} has same ID as local user. Refusing service.",
218 aCircuit.firstname, aCircuit.lastname); 217 aCircuit.firstname, aCircuit.lastname);
@@ -266,32 +265,35 @@ namespace OpenSim.Services.HypergridService
266 // 265 //
267 // Finally launch the agent at the destination 266 // Finally launch the agent at the destination
268 // 267 //
269 return m_SimulationService.CreateAgent(destination, aCircuit, 0, out reason); 268 return m_SimulationService.CreateAgent(destination, aCircuit, (uint)Constants.TeleportFlags.ViaLogin, out reason);
270 } 269 }
271 270
272 protected bool Authenticate(AgentCircuitData aCircuit) 271 protected bool Authenticate(AgentCircuitData aCircuit)
273 { 272 {
274 string authURL = string.Empty; 273 if (!CheckAddress(aCircuit.ServiceSessionID))
274 return false;
275
276 string userURL = string.Empty;
275 if (aCircuit.ServiceURLs.ContainsKey("HomeURI")) 277 if (aCircuit.ServiceURLs.ContainsKey("HomeURI"))
276 authURL = aCircuit.ServiceURLs["HomeURI"].ToString(); 278 userURL = aCircuit.ServiceURLs["HomeURI"].ToString();
277 279
278 if (authURL == string.Empty) 280 if (userURL == string.Empty)
279 { 281 {
280 m_log.DebugFormat("[GATEKEEPER SERVICE]: Agent did not provide an authentication server URL"); 282 m_log.DebugFormat("[GATEKEEPER SERVICE]: Agent did not provide an authentication server URL");
281 return false; 283 return false;
282 } 284 }
283 285
284 Object[] args = new Object[] { authURL }; 286 Object[] args = new Object[] { userURL };
285 IAuthenticationService authService = ServerUtils.LoadPlugin<IAuthenticationService>(m_AuthDll, args); 287 IUserAgentService userAgentService = new UserAgentServiceConnector(userURL); //ServerUtils.LoadPlugin<IUserAgentService>(m_AuthDll, args);
286 if (authService != null) 288 if (userAgentService != null)
287 { 289 {
288 try 290 try
289 { 291 {
290 return authService.Verify(aCircuit.AgentID, aCircuit.SecureSessionID.ToString(), 30); 292 return userAgentService.VerifyAgent(aCircuit.SessionID, aCircuit.ServiceSessionID);
291 } 293 }
292 catch 294 catch
293 { 295 {
294 m_log.DebugFormat("[GATEKEEPER SERVICE]: Unable to contact authentication service at {0}", authURL); 296 m_log.DebugFormat("[GATEKEEPER SERVICE]: Unable to contact authentication service at {0}", userURL);
295 return false; 297 return false;
296 } 298 }
297 } 299 }
@@ -299,35 +301,20 @@ namespace OpenSim.Services.HypergridService
299 return false; 301 return false;
300 } 302 }
301 303
302 #endregion 304 // Check that the service token was generated for *this* grid.
303 305 // If it wasn't then that's a fake agent.
304 public GridRegion GetHomeRegion(UUID userID, out Vector3 position, out Vector3 lookAt) 306 protected bool CheckAddress(string serviceToken)
305 { 307 {
306 position = new Vector3(128, 128, 0); lookAt = Vector3.UnitY; 308 string[] parts = serviceToken.Split(new char[] { ';' });
309 if (parts.Length < 2)
310 return false;
307 311
308 m_log.DebugFormat("[GATEKEEPER SERVICE]: Request to get home region of user {0}", userID); 312 string addressee = parts[0];
313 return (addressee == m_ExternalName);
314 }
309 315
310 GridRegion home = null; 316 #endregion
311 PresenceInfo[] presences = m_PresenceService.GetAgents(new string[] { userID.ToString() });
312 if (presences != null && presences.Length > 0)
313 {
314 UUID homeID = presences[0].HomeRegionID;
315 if (homeID != UUID.Zero)
316 {
317 home = m_GridService.GetRegionByUUID(m_ScopeID, homeID);
318 position = presences[0].HomePosition;
319 lookAt = presences[0].HomeLookAt;
320 }
321 if (home == null)
322 {
323 List<GridRegion> defs = m_GridService.GetDefaultRegions(m_ScopeID);
324 if (defs != null && defs.Count > 0)
325 home = defs[0];
326 }
327 }
328 317
329 return home;
330 }
331 318
332 #region Misc 319 #region Misc
333 320
diff --git a/OpenSim/Services/HypergridService/HomeUsersSecurityService.cs b/OpenSim/Services/HypergridService/HomeUsersSecurityService.cs
deleted file mode 100644
index a7adfc1..0000000
--- a/OpenSim/Services/HypergridService/HomeUsersSecurityService.cs
+++ /dev/null
@@ -1,67 +0,0 @@
1using System;
2using System.Collections.Generic;
3using System.Net;
4using System.Reflection;
5
6using OpenSim.Services.Interfaces;
7
8using OpenMetaverse;
9using log4net;
10using Nini.Config;
11
12namespace OpenSim.Services.HypergridService
13{
14 /// <summary>
15 /// This service is for HG1.5 only, to make up for the fact that clients don't
16 /// keep any private information in themselves, and that their 'home service'
17 /// needs to do it for them.
18 /// Once we have better clients, this shouldn't be needed.
19 /// </summary>
20 public class HomeUsersSecurityService : IHomeUsersSecurityService
21 {
22 private static readonly ILog m_log =
23 LogManager.GetLogger(
24 MethodBase.GetCurrentMethod().DeclaringType);
25
26 //
27 // This is a persistent storage wannabe for dealing with the
28 // quirks of HG1.5. We don't really want to store this in a table.
29 // But this is the necessary information for securing clients
30 // coming home.
31 //
32 protected static Dictionary<UUID, IPEndPoint> m_ClientEndPoints = new Dictionary<UUID, IPEndPoint>();
33
34 public HomeUsersSecurityService(IConfigSource config)
35 {
36 m_log.DebugFormat("[HOME USERS SECURITY]: Starting...");
37 }
38
39 public void SetEndPoint(UUID sessionID, IPEndPoint ep)
40 {
41 m_log.DebugFormat("[HOME USERS SECURITY]: Set EndPoint {0} for session {1}", ep.ToString(), sessionID);
42
43 lock (m_ClientEndPoints)
44 m_ClientEndPoints[sessionID] = ep;
45 }
46
47 public IPEndPoint GetEndPoint(UUID sessionID)
48 {
49 lock (m_ClientEndPoints)
50 if (m_ClientEndPoints.ContainsKey(sessionID))
51 {
52 m_log.DebugFormat("[HOME USERS SECURITY]: Get EndPoint {0} for session {1}", m_ClientEndPoints[sessionID].ToString(), sessionID);
53 return m_ClientEndPoints[sessionID];
54 }
55
56 return null;
57 }
58
59 public void RemoveEndPoint(UUID sessionID)
60 {
61 m_log.DebugFormat("[HOME USERS SECURITY]: Remove EndPoint for session {0}", sessionID);
62 lock (m_ClientEndPoints)
63 if (m_ClientEndPoints.ContainsKey(sessionID))
64 m_ClientEndPoints.Remove(sessionID);
65 }
66 }
67}
diff --git a/OpenSim/Services/HypergridService/UserAgentService.cs b/OpenSim/Services/HypergridService/UserAgentService.cs
new file mode 100644
index 0000000..0873a2b
--- /dev/null
+++ b/OpenSim/Services/HypergridService/UserAgentService.cs
@@ -0,0 +1,210 @@
1using System;
2using System.Collections.Generic;
3using System.Net;
4using System.Reflection;
5
6using OpenSim.Framework;
7using OpenSim.Services.Connectors.Hypergrid;
8using OpenSim.Services.Interfaces;
9using GridRegion = OpenSim.Services.Interfaces.GridRegion;
10using OpenSim.Server.Base;
11
12using OpenMetaverse;
13using log4net;
14using Nini.Config;
15
16namespace OpenSim.Services.HypergridService
17{
18 /// <summary>
19 /// This service is for HG1.5 only, to make up for the fact that clients don't
20 /// keep any private information in themselves, and that their 'home service'
21 /// needs to do it for them.
22 /// Once we have better clients, this shouldn't be needed.
23 /// </summary>
24 public class UserAgentService : IUserAgentService
25 {
26 private static readonly ILog m_log =
27 LogManager.GetLogger(
28 MethodBase.GetCurrentMethod().DeclaringType);
29
30 // This will need to go into a DB table
31 static Dictionary<UUID, TravelingAgentInfo> m_TravelingAgents = new Dictionary<UUID, TravelingAgentInfo>();
32
33 static bool m_Initialized = false;
34
35 protected static IPresenceService m_PresenceService;
36 protected static IGridService m_GridService;
37 protected static GatekeeperServiceConnector m_GatekeeperConnector;
38
39 public UserAgentService(IConfigSource config)
40 {
41 if (!m_Initialized)
42 {
43 m_log.DebugFormat("[HOME USERS SECURITY]: Starting...");
44
45 IConfig serverConfig = config.Configs["UserAgentService"];
46 if (serverConfig == null)
47 throw new Exception(String.Format("No section UserAgentService in config file"));
48
49 string gridService = serverConfig.GetString("GridService", String.Empty);
50 string presenceService = serverConfig.GetString("PresenceService", String.Empty);
51
52 if (gridService == string.Empty || presenceService == string.Empty)
53 throw new Exception(String.Format("Incomplete specifications, UserAgent Service cannot function."));
54
55 Object[] args = new Object[] { config };
56 m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args);
57 m_PresenceService = ServerUtils.LoadPlugin<IPresenceService>(presenceService, args);
58 m_GatekeeperConnector = new GatekeeperServiceConnector();
59
60 m_Initialized = true;
61 }
62 }
63
64 public GridRegion GetHomeRegion(UUID userID, out Vector3 position, out Vector3 lookAt)
65 {
66 position = new Vector3(128, 128, 0); lookAt = Vector3.UnitY;
67
68 m_log.DebugFormat("[USER AGENT SERVICE]: Request to get home region of user {0}", userID);
69
70 GridRegion home = null;
71 PresenceInfo[] presences = m_PresenceService.GetAgents(new string[] { userID.ToString() });
72 if (presences != null && presences.Length > 0)
73 {
74 UUID homeID = presences[0].HomeRegionID;
75 if (homeID != UUID.Zero)
76 {
77 home = m_GridService.GetRegionByUUID(UUID.Zero, homeID);
78 position = presences[0].HomePosition;
79 lookAt = presences[0].HomeLookAt;
80 }
81 if (home == null)
82 {
83 List<GridRegion> defs = m_GridService.GetDefaultRegions(UUID.Zero);
84 if (defs != null && defs.Count > 0)
85 home = defs[0];
86 }
87 }
88
89 return home;
90 }
91
92 public bool LoginAgentToGrid(AgentCircuitData agentCircuit, GridRegion gatekeeper, GridRegion finalDestination, out string reason)
93 {
94 m_log.DebugFormat("[USER AGENT SERVICE]: Request to login user {0} {1} to grid {2}",
95 agentCircuit.firstname, agentCircuit.lastname, gatekeeper.ExternalHostName +":"+ gatekeeper.HttpPort);
96
97 // Take the IP address + port of the gatekeeper (reg) plus the info of finalDestination
98 GridRegion region = new GridRegion(gatekeeper);
99 region.RegionName = finalDestination.RegionName;
100 region.RegionID = finalDestination.RegionID;
101 region.RegionLocX = finalDestination.RegionLocX;
102 region.RegionLocY = finalDestination.RegionLocY;
103
104 // Generate a new service session
105 agentCircuit.ServiceSessionID = "http://" + region.ExternalHostName + ":" + region.HttpPort + ";" + UUID.Random();
106 TravelingAgentInfo old = UpdateTravelInfo(agentCircuit, region);
107
108 bool success = m_GatekeeperConnector.CreateAgent(region, agentCircuit, (uint)Constants.TeleportFlags.ViaLogin, out reason);
109
110 if (!success)
111 {
112 m_log.DebugFormat("[USER AGENT SERVICE]: Unable to login user {0} {1} to grid {2}, reason: {3}",
113 agentCircuit.firstname, agentCircuit.lastname, region.ExternalHostName + ":" + region.HttpPort, reason);
114
115 // restore the old travel info
116 lock (m_TravelingAgents)
117 m_TravelingAgents[agentCircuit.SessionID] = old;
118
119 return false;
120 }
121
122 return true;
123 }
124
125 TravelingAgentInfo UpdateTravelInfo(AgentCircuitData agentCircuit, GridRegion region)
126 {
127 TravelingAgentInfo travel = new TravelingAgentInfo();
128 TravelingAgentInfo old = null;
129 lock (m_TravelingAgents)
130 {
131 if (m_TravelingAgents.ContainsKey(agentCircuit.SessionID))
132 {
133 old = m_TravelingAgents[agentCircuit.SessionID];
134 }
135
136 m_TravelingAgents[agentCircuit.SessionID] = travel;
137 }
138 travel.UserID = agentCircuit.AgentID;
139 travel.GridExternalName = region.ExternalHostName + ":" + region.HttpPort;
140 travel.ServiceToken = agentCircuit.ServiceSessionID;
141 if (old != null)
142 travel.ClientToken = old.ClientToken;
143
144 return old;
145 }
146
147 public void LogoutAgent(UUID userID, UUID sessionID)
148 {
149 m_log.DebugFormat("[USER AGENT SERVICE]: User {0} logged out", userID);
150
151 lock (m_TravelingAgents)
152 {
153 List<UUID> travels = new List<UUID>();
154 foreach (KeyValuePair<UUID, TravelingAgentInfo> kvp in m_TravelingAgents)
155 if (kvp.Value.UserID == userID)
156 travels.Add(kvp.Key);
157 foreach (UUID session in travels)
158 m_TravelingAgents.Remove(session);
159 }
160 }
161
162 // We need to prevent foreign users with the same UUID as a local user
163 public bool AgentIsComingHome(UUID sessionID, string thisGridExternalName)
164 {
165 if (!m_TravelingAgents.ContainsKey(sessionID))
166 return false;
167
168 TravelingAgentInfo travel = m_TravelingAgents[sessionID];
169 return travel.GridExternalName == thisGridExternalName;
170 }
171
172 public bool VerifyClient(UUID sessionID, string token)
173 {
174 if (m_TravelingAgents.ContainsKey(sessionID))
175 {
176 // Aquiles heel. Must trust the first grid upon login
177 if (m_TravelingAgents[sessionID].ClientToken == string.Empty)
178 {
179 m_TravelingAgents[sessionID].ClientToken = token;
180 return true;
181 }
182 return m_TravelingAgents[sessionID].ClientToken == token;
183 }
184 return false;
185 }
186
187 public bool VerifyAgent(UUID sessionID, string token)
188 {
189 if (m_TravelingAgents.ContainsKey(sessionID))
190 {
191 m_log.DebugFormat("[USER AGENT SERVICE]: Verifying agent token {0} against {1}", token, m_TravelingAgents[sessionID].ServiceToken);
192 return m_TravelingAgents[sessionID].ServiceToken == token;
193 }
194
195 m_log.DebugFormat("[USER AGENT SERVICE]: Token verification for session {0}: no such session", sessionID);
196
197 return false;
198 }
199
200 }
201
202 class TravelingAgentInfo
203 {
204 public UUID UserID;
205 public string GridExternalName = string.Empty;
206 public string ServiceToken = string.Empty;
207 public string ClientToken = string.Empty;
208 }
209
210}