aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenGridServices/OpenGrid.Framework.Data.MSSQL/MSSQLGridData.cs
diff options
context:
space:
mode:
authorMW2007-05-26 13:40:19 +0000
committerMW2007-05-26 13:40:19 +0000
commit3436961bb5c01d659d09be134368f4f69460cef9 (patch)
tree3753ba4d7818df2a6bce0bbe863ff033cdfd568a /OpenGridServices/OpenGrid.Framework.Data.MSSQL/MSSQLGridData.cs
downloadopensim-SC-3436961bb5c01d659d09be134368f4f69460cef9.zip
opensim-SC-3436961bb5c01d659d09be134368f4f69460cef9.tar.gz
opensim-SC-3436961bb5c01d659d09be134368f4f69460cef9.tar.bz2
opensim-SC-3436961bb5c01d659d09be134368f4f69460cef9.tar.xz
Start of rewrite 5279!
Diffstat (limited to 'OpenGridServices/OpenGrid.Framework.Data.MSSQL/MSSQLGridData.cs')
-rw-r--r--OpenGridServices/OpenGrid.Framework.Data.MSSQL/MSSQLGridData.cs136
1 files changed, 136 insertions, 0 deletions
diff --git a/OpenGridServices/OpenGrid.Framework.Data.MSSQL/MSSQLGridData.cs b/OpenGridServices/OpenGrid.Framework.Data.MSSQL/MSSQLGridData.cs
new file mode 100644
index 0000000..0925df1
--- /dev/null
+++ b/OpenGridServices/OpenGrid.Framework.Data.MSSQL/MSSQLGridData.cs
@@ -0,0 +1,136 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using OpenGrid.Framework.Data;
5
6namespace OpenGrid.Framework.Data.MSSQL
7{
8 public class SqlGridData : IGridData
9 {
10 private MSSqlManager database;
11
12 /// <summary>
13 /// Initialises the Grid Interface
14 /// </summary>
15 public void Initialise()
16 {
17 database = new MSSqlManager("localhost", "db", "user", "password", "false");
18 }
19
20 /// <summary>
21 /// Shuts down the grid interface
22 /// </summary>
23 public void Close()
24 {
25 database.Close();
26 }
27
28 public string getName()
29 {
30 return "Sql OpenGridData";
31 }
32
33 public string getVersion()
34 {
35 return "0.1";
36 }
37
38 public SimProfileData[] GetProfilesInRange(uint a, uint b, uint c, uint d)
39 {
40 return null;
41 }
42
43 /// <summary>
44 /// Returns a sim profile from it's location
45 /// </summary>
46 /// <param name="handle">Region location handle</param>
47 /// <returns>Sim profile</returns>
48 public SimProfileData GetProfileByHandle(ulong handle)
49 {
50 Dictionary<string, string> param = new Dictionary<string, string>();
51 param["handle"] = handle.ToString();
52
53 System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE handle = @handle", param);
54 System.Data.IDataReader reader = result.ExecuteReader();
55
56 SimProfileData row = database.getRow(reader);
57 reader.Close();
58 result.Dispose();
59
60 return row;
61 }
62
63 /// <summary>
64 /// Returns a sim profile from it's UUID
65 /// </summary>
66 /// <param name="uuid">The region UUID</param>
67 /// <returns>The sim profile</returns>
68 public SimProfileData GetProfileByLLUUID(libsecondlife.LLUUID uuid)
69 {
70 Dictionary<string, string> param = new Dictionary<string, string>();
71 param["uuid"] = uuid.ToStringHyphenated();
72
73 System.Data.IDbCommand result = database.Query("SELECT * FROM regions WHERE uuid = @uuid", param);
74 System.Data.IDataReader reader = result.ExecuteReader();
75
76 SimProfileData row = database.getRow(reader);
77 reader.Close();
78 result.Dispose();
79
80 return row;
81 }
82
83 public DataResponse AddProfile(SimProfileData profile)
84 {
85 if (database.insertRow(profile))
86 {
87 return DataResponse.RESPONSE_OK;
88 }
89 else
90 {
91 return DataResponse.RESPONSE_ERROR;
92 }
93 }
94
95 /// <summary>
96 /// DEPRECIATED. Attempts to authenticate a region by comparing a shared secret.
97 /// </summary>
98 /// <param name="uuid">The UUID of the challenger</param>
99 /// <param name="handle">The attempted regionHandle of the challenger</param>
100 /// <param name="authkey">The secret</param>
101 /// <returns>Whether the secret and regionhandle match the database entry for UUID</returns>
102 public bool AuthenticateSim(libsecondlife.LLUUID uuid, ulong handle, string authkey)
103 {
104 bool throwHissyFit = false; // Should be true by 1.0
105
106 if (throwHissyFit)
107 throw new Exception("CRYPTOWEAK AUTHENTICATE: Refusing to authenticate due to replay potential.");
108
109 SimProfileData data = GetProfileByLLUUID(uuid);
110
111 return (handle == data.regionHandle && authkey == data.regionSecret);
112 }
113
114 /// <summary>
115 /// NOT YET FUNCTIONAL. Provides a cryptographic authentication of a region
116 /// </summary>
117 /// <remarks>This requires a security audit.</remarks>
118 /// <param name="uuid"></param>
119 /// <param name="handle"></param>
120 /// <param name="authhash"></param>
121 /// <param name="challenge"></param>
122 /// <returns></returns>
123 public bool AuthenticateSim(libsecondlife.LLUUID uuid, ulong handle, string authhash, string challenge)
124 {
125 System.Security.Cryptography.SHA512Managed HashProvider = new System.Security.Cryptography.SHA512Managed();
126 System.Text.ASCIIEncoding TextProvider = new ASCIIEncoding();
127
128 byte[] stream = TextProvider.GetBytes(uuid.ToStringHyphenated() + ":" + handle.ToString() + ":" + challenge);
129 byte[] hash = HashProvider.ComputeHash(stream);
130
131 return false;
132 }
133 }
134
135
136}