• R/O
  • SSH
  • HTTPS

webserver: Commit


Commit MetaInfo

Revision62 (tree)
Time2010-11-21 20:04:51
Authorhoritaku

Log Message

クッキー関連

Change Summary

Incremental Difference

--- branch/Basic 0.2x/src/servercore/tcp/TcpServer.java (revision 61)
+++ branch/Basic 0.2x/src/servercore/tcp/TcpServer.java (revision 62)
@@ -34,7 +34,6 @@
3434 }
3535 TcpInstance ins = new TcpInstance(socket);
3636 ins.start();
37-
3837 }
3938 } catch (IOException e1) {
4039 e1.printStackTrace();
--- branch/Basic 0.2x/src/servercore/servelet/ServeletJob.java (revision 61)
+++ branch/Basic 0.2x/src/servercore/servelet/ServeletJob.java (revision 62)
@@ -1,5 +0,0 @@
1-package servercore.servelet;
2-
3-public class ServeletJob {
4-
5-}
--- branch/Basic 0.2x/src/servercore/job/JobWorker.java (revision 61)
+++ branch/Basic 0.2x/src/servercore/job/JobWorker.java (revision 62)
@@ -12,6 +12,7 @@
1212 import java.util.Locale;
1313 import java.util.Set;
1414
15+import servercore.data.Cookie;
1516 import servercore.data.HtmlParam;
1617 import servercore.http.HttpRequest;
1718 import servercore.http.HttpServer;
@@ -27,10 +28,14 @@
2728
2829 System.out.print(req.getMethod() + "\t" + req.getRowPath() + "\t");
2930
31+ // ブラウザがWebSocketを要求したとき
3032 if("ws".equals(ext)) {
31- websocketTest(req, ops, ips);
33+ websocketHandShake(req, ops, ips);
3234 }
33- HttpResponse res = GeneratePage.execute(req);
35+ HttpResponse res = security(req);
36+ if(res.getStatusCore() == 200) {
37+ res = GeneratePage.execute(req);
38+ }
3439 System.out.println(res.getStatusCore());
3540
3641 String resStr = "";
@@ -163,8 +168,9 @@
163168 res.setStatusCore(200);
164169 return res;
165170 }
166- String cookie = req.getCookieValues().get("SESSIONID");
167- if("cookieok".equals(cookie)) {
171+ String cookieKey = req.getCookieValues().get("SESSIONID");
172+ Cookie cookie = SessionCheck.getCookie(cookieKey);
173+ if(cookie != null) {
168174 res.setStatusCore(200);
169175 return res;
170176 } else {
@@ -207,7 +213,7 @@
207213 String editedDate = sdf.format(new Date(milliSecound));
208214 return editedDate;
209215 }
210- public void websocketTest(HttpRequest req, OutputStream ops, InputStream ips) {
216+ public void websocketHandShake(HttpRequest req, OutputStream ops, InputStream ips) {
211217 String host = req.getHeader().get("Host");
212218 StringBuffer sb = new StringBuffer();
213219 try {
@@ -216,7 +222,7 @@
216222 String key2 = req.getHeader().get("Sec-WebSocket-Key2");
217223 String origin = req.getHeader().get("Origin");
218224 String res_ws = "ws://" + host + path;
219- byte[] c = getChalengeKey(req.headerBytes);
225+ byte[] body_code = getChalengeKey(req.headerBytes);
220226 long key1_num = chooseNum(key1);
221227 long key2_num = chooseNum(key2);
222228 int key1_s = chooseSpace(key1);
@@ -226,7 +232,7 @@
226232 byte[] key_head = bigendiean(key1_w, key2_w);
227233 byte[] byte_keys = new byte[16];
228234 System.arraycopy(key_head, 0, byte_keys, 0, 8);
229- System.arraycopy(c, 0, byte_keys, 8, 8);
235+ System.arraycopy(body_code, 0, byte_keys, 8, 8);
230236
231237 MessageDigest md = MessageDigest.getInstance("MD5");
232238 md.update(byte_keys);
@@ -267,7 +273,6 @@
267273 break;
268274 }
269275 }
270-
271276 }
272277 } catch(Exception e) {
273278 e.printStackTrace();
--- branch/Basic 0.2x/reflectAction/refrect_action/LoginCheck.java (revision 61)
+++ branch/Basic 0.2x/reflectAction/refrect_action/LoginCheck.java (revision 62)
@@ -7,6 +7,7 @@
77 import servercore.http.HttpRequest;
88 import servercore.http.HttpResponse;
99 import servercore.http.HttpServer;
10+import servercore.job.SessionCheck;
1011 import servercore.servelet.reflect.Action;
1112
1213 public class LoginCheck extends Action{
@@ -24,7 +25,11 @@
2425 md5_pass = CodeMD5.crypt(uid + ":" + pass);
2526 }
2627 if(ini_pass != null && ini_pass.equals(md5_pass)) {
27- res.addHeader("Set-Cookie", "SESSIONID=cookieok");
28+ String cookieKey = uid + ":" + pass + ":";
29+ cookieKey += System.currentTimeMillis();
30+ cookieKey = CodeMD5.crypt(cookieKey);
31+ SessionCheck.setCookie(cookieKey, "", 3600);
32+ res.addHeader("Set-Cookie", "SESSIONID=" + cookieKey);
2833 res.setStatusCore(204);
2934 } else {
3035 res.setStatusCore(403);
Show on old repository browser