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