diff options
Diffstat (limited to 'OpenGridServices-Source/OpenGrid.Framework.Data.SQLite/SQLiteGridData.cs')
-rw-r--r-- | OpenGridServices-Source/OpenGrid.Framework.Data.SQLite/SQLiteGridData.cs | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/OpenGridServices-Source/OpenGrid.Framework.Data.SQLite/SQLiteGridData.cs b/OpenGridServices-Source/OpenGrid.Framework.Data.SQLite/SQLiteGridData.cs new file mode 100644 index 0000000..4850f12 --- /dev/null +++ b/OpenGridServices-Source/OpenGrid.Framework.Data.SQLite/SQLiteGridData.cs | |||
@@ -0,0 +1,136 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using OpenGrid.Framework.Data; | ||
5 | |||
6 | namespace 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 | 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 | } | ||