diff options
author | Dr Scofield | 2008-10-06 19:42:03 +0000 |
---|---|---|
committer | Dr Scofield | 2008-10-06 19:42:03 +0000 |
commit | a1f34090326d6d567aecb2052ec4ba0b6c4f52e2 (patch) | |
tree | ecb16e81c39802184fefc72dad585b0976dba8d3 /OpenSim/Framework/Servers/BaseHttpServer.cs | |
parent | * Made Mapitems more failure friendly (diff) | |
download | opensim-SC-a1f34090326d6d567aecb2052ec4ba0b6c4f52e2.zip opensim-SC-a1f34090326d6d567aecb2052ec4ba0b6c4f52e2.tar.gz opensim-SC-a1f34090326d6d567aecb2052ec4ba0b6c4f52e2.tar.bz2 opensim-SC-a1f34090326d6d567aecb2052ec4ba0b6c4f52e2.tar.xz |
cleaning up OSHttpRequest removing old Http stuff. also adding test
case for OSHttpRequest (not very fancy yet, but still).
Diffstat (limited to 'OpenSim/Framework/Servers/BaseHttpServer.cs')
-rw-r--r-- | OpenSim/Framework/Servers/BaseHttpServer.cs | 186 |
1 files changed, 2 insertions, 184 deletions
diff --git a/OpenSim/Framework/Servers/BaseHttpServer.cs b/OpenSim/Framework/Servers/BaseHttpServer.cs index 2c0cb5c..d1c22d6 100644 --- a/OpenSim/Framework/Servers/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/BaseHttpServer.cs | |||
@@ -103,120 +103,13 @@ namespace OpenSim.Framework.Servers | |||
103 | { | 103 | { |
104 | m_ssl = ssl; | 104 | m_ssl = ssl; |
105 | m_port = port; | 105 | m_port = port; |
106 | |||
106 | if (m_ssl) | 107 | if (m_ssl) |
107 | { | 108 | { |
108 | //SetupSsl((int)sslport, CN); | ||
109 | m_sslport = sslport; | 109 | m_sslport = sslport; |
110 | } | 110 | } |
111 | } | 111 | } |
112 | 112 | ||
113 | |||
114 | /* | ||
115 | * | ||
116 | public bool SetupSsl(int port, string CN) | ||
117 | { | ||
118 | string searchCN = Environment.MachineName.ToUpper(); | ||
119 | |||
120 | if (CN.Length > 0) | ||
121 | searchCN = CN.ToUpper(); | ||
122 | |||
123 | m_SSLCommonName = searchCN; | ||
124 | |||
125 | Type t = Type.GetType("Mono.Runtime"); | ||
126 | if (t != null) | ||
127 | { | ||
128 | // TODO Mono User Friendly HTTPS setup | ||
129 | // if this doesn't exist, then mono people can still manually use httpcfg | ||
130 | } | ||
131 | else | ||
132 | { | ||
133 | // Windows. | ||
134 | // Search through the store for a certificate with a Common name specified in OpenSim.ini. | ||
135 | // We need to find it's hash so we can pass it to httpcfg | ||
136 | X509Store store = new X509Store(StoreLocation.LocalMachine); | ||
137 | //Use the first cert to configure Ssl | ||
138 | store.Open(OpenFlags.ReadOnly); | ||
139 | //Assumption is we have certs. If not then this call will fail :( | ||
140 | try | ||
141 | { | ||
142 | bool found = false; | ||
143 | //X509Certificate2.CreateFromCertFile("testCert.cer"); | ||
144 | |||
145 | foreach (X509Certificate2 cert in store.Certificates) | ||
146 | { | ||
147 | String certHash = cert.GetCertHashString(); | ||
148 | //Only install certs issued for the machine and has the name as the machine name | ||
149 | if (cert.Subject.ToUpper().IndexOf(searchCN) >= 0) | ||
150 | { | ||
151 | string httpcfgparams = String.Format("set ssl -i 0.0.0.0:{1} -c \"MY\" -h {0}", certHash, port); | ||
152 | try | ||
153 | { | ||
154 | found = true; | ||
155 | |||
156 | ExecuteHttpcfgCommand(httpcfgparams); | ||
157 | |||
158 | break; | ||
159 | } | ||
160 | catch (Exception e) | ||
161 | { | ||
162 | m_log.WarnFormat("[HTTPS]: Automatic HTTPS setup failed. Do you have httpcfg.exe in your path? If not, you can download it in the windowsXP Service Pack 2 Support Tools, here: http://www.microsoft.com/downloads/details.aspx?FamilyID=49ae8576-9bb9-4126-9761-ba8011fabf38&displaylang=en. When you get it installed type, httpcfg {0} - {1}", httpcfgparams, e); | ||
163 | return false; | ||
164 | } | ||
165 | } | ||
166 | } | ||
167 | |||
168 | if (!found) | ||
169 | { | ||
170 | m_log.WarnFormat("[HTTPS]: We didn't find a certificate that matched the common name {0}. Automatic HTTPS setup failed, you may have certificate errors. To fix this, make sure you generate a certificate request(CSR) using OpenSSL or the IIS snap-in with the common name you specified in opensim.ini. Then get it signed by a certification authority or sign it yourself with OpenSSL and the junkCA. Finally, be sure to import the cert to the 'MY' store(StoreLocation.LocalMachine)", searchCN); | ||
171 | return false; | ||
172 | } | ||
173 | |||
174 | } | ||
175 | catch (Exception e) | ||
176 | { | ||
177 | m_log.WarnFormat("[HTTPS]: We didn't any certificates in your LocalMachine certificate store. Automatic HTTPS setup failed, you may have certificate errors. To fix this, make sure you generate a certificate request(CSR) using OpenSSL or the IIS snap-inwith the common name you specified in opensim.ini. Then get it signed by a certification authority or sign it yourself with OpenSSL and the junkCA. Finally, be sure to import the cert to the 'MY' store(StoreLocation.LocalMachine). The configured common name is {0} - {1}", searchCN, e); | ||
178 | return false; | ||
179 | } | ||
180 | finally | ||
181 | { | ||
182 | if (store != null) | ||
183 | { | ||
184 | store.Close(); | ||
185 | } | ||
186 | } | ||
187 | } | ||
188 | return true; | ||
189 | } | ||
190 | |||
191 | private void ExecuteHttpcfgCommand(string p) | ||
192 | { | ||
193 | |||
194 | string file = "httpcfg"; | ||
195 | |||
196 | ProcessStartInfo info = new ProcessStartInfo(file, p); | ||
197 | // Redirect output so we can read it. | ||
198 | info.RedirectStandardOutput = true; | ||
199 | // To redirect, we must not use shell execute. | ||
200 | info.UseShellExecute = false; | ||
201 | |||
202 | // Create and execute the process. | ||
203 | Process httpcfgprocess = Process.Start(info); | ||
204 | httpcfgprocess.Start(); | ||
205 | string result = httpcfgprocess.StandardOutput.ReadToEnd(); | ||
206 | if (result.Contains("HttpSetServiceConfiguration completed with")) | ||
207 | { | ||
208 | //success | ||
209 | |||
210 | } | ||
211 | else | ||
212 | { | ||
213 | //fail | ||
214 | m_log.WarnFormat("[HTTPS]:Error binding certificate with the requested port. Message:{0}", result); | ||
215 | } | ||
216 | |||
217 | } | ||
218 | */ | ||
219 | |||
220 | /// <summary> | 113 | /// <summary> |
221 | /// Add a stream handler to the http server. If the handler already exists, then nothing happens. | 114 | /// Add a stream handler to the http server. If the handler already exists, then nothing happens. |
222 | /// </summary> | 115 | /// </summary> |
@@ -311,81 +204,6 @@ namespace OpenSim.Framework.Servers | |||
311 | return true; | 204 | return true; |
312 | } | 205 | } |
313 | 206 | ||
314 | /// <summary> | ||
315 | /// HttpListener Handle an individual http request. This method is given to a worker in the thread pool. | ||
316 | /// </summary> | ||
317 | /// <param name="stateinfo"></param> | ||
318 | public virtual void HandleRequest(Object stateinfo) | ||
319 | { | ||
320 | // force the culture to en-US | ||
321 | |||
322 | |||
323 | // If we don't catch the exception here it will just disappear into the thread pool and we'll be none the wiser | ||
324 | try | ||
325 | { | ||
326 | HttpListenerContext context = (HttpListenerContext)stateinfo; | ||
327 | |||
328 | OSHttpRequest request = new OSHttpRequest(context.Request); | ||
329 | OSHttpResponse response = new OSHttpResponse(context.Response); | ||
330 | |||
331 | HandleRequest(request, response); | ||
332 | |||
333 | } | ||
334 | catch (SocketException e) | ||
335 | { | ||
336 | // At least on linux, it appears that if the client makes a request without requiring the response, | ||
337 | // an unconnected socket exception is thrown when we close the response output stream. There's no | ||
338 | // obvious way to tell if the client didn't require the response, so instead we'll catch and ignore | ||
339 | // the exception instead. | ||
340 | // | ||
341 | // An alternative may be to turn off all response write exceptions on the HttpListener, but let's go | ||
342 | // with the minimum first | ||
343 | m_log.WarnFormat("[BASE HTTP SERVER]: HandleRequest threw {0}.\nNOTE: this may be spurious on Linux", e); | ||
344 | } | ||
345 | catch (Exception e) | ||
346 | { | ||
347 | m_log.ErrorFormat("[BASE HTTP SERVER]: HandleRequest() threw {0}", e); | ||
348 | } | ||
349 | } | ||
350 | |||
351 | /* | ||
352 | /// <summary> | ||
353 | /// HttpListener Handle an individual http request. This method is given to a worker in the thread pool. | ||
354 | /// </summary> | ||
355 | /// <param name="stateinfo"></param> | ||
356 | public virtual void HandleRequestHttpServer(Object stateinfo) | ||
357 | { | ||
358 | // force the culture to en-US | ||
359 | |||
360 | |||
361 | // If we don't catch the exception here it will just disappear into the thread pool and we'll be none the wiser | ||
362 | try | ||
363 | { | ||
364 | HttpServerContextObj context = (HttpServerContextObj)stateinfo; | ||
365 | |||
366 | OSHttpRequest request = new OSHttpRequest(context.Request); | ||
367 | OSHttpResponse response = new OSHttpResponse(context.Response); | ||
368 | |||
369 | HandleRequest(request, response); | ||
370 | |||
371 | } | ||
372 | catch (SocketException e) | ||
373 | { | ||
374 | // At least on linux, it appears that if the client makes a request without requiring the response, | ||
375 | // an unconnected socket exception is thrown when we close the response output stream. There's no | ||
376 | // obvious way to tell if the client didn't require the response, so instead we'll catch and ignore | ||
377 | // the exception instead. | ||
378 | // | ||
379 | // An alternative may be to turn off all response write exceptions on the HttpListener, but let's go | ||
380 | // with the minimum first | ||
381 | m_log.WarnFormat("[BASE HTTP SERVER]: HandleRequest threw {0}.\nNOTE: this may be spurious on Linux", e); | ||
382 | } | ||
383 | catch (Exception e) | ||
384 | { | ||
385 | m_log.ErrorFormat("[BASE HTTP SERVER]: HandleRequest() threw {0}", e); | ||
386 | } | ||
387 | } | ||
388 | */ | ||
389 | public void OnHandleRequestIOThread(IHttpClientContext context, IHttpRequest request) | 207 | public void OnHandleRequestIOThread(IHttpClientContext context, IHttpRequest request) |
390 | { | 208 | { |
391 | OSHttpRequest req = new OSHttpRequest(context, request); | 209 | OSHttpRequest req = new OSHttpRequest(context, request); |
@@ -845,7 +663,7 @@ namespace OpenSim.Framework.Servers | |||
845 | if (TryGetLLSDHandler(request.RawUrl, out llsdhandler) && !LegacyLLSDLoginLibOMV) | 663 | if (TryGetLLSDHandler(request.RawUrl, out llsdhandler) && !LegacyLLSDLoginLibOMV) |
846 | { | 664 | { |
847 | // we found a registered llsd handler to service this request | 665 | // we found a registered llsd handler to service this request |
848 | llsdResponse = llsdhandler(request.RawUrl, llsdRequest, (request.RemoteIPEndPoint == null)? "" : request.RemoteIPEndPoint.ToString()); | 666 | llsdResponse = llsdhandler(request.RawUrl, llsdRequest, request.RemoteIPEndPoint.ToString()); |
849 | } | 667 | } |
850 | else | 668 | else |
851 | { | 669 | { |