tokenizerã¨ããä¸ã¤ã®ãã¼ã¯ã³ã®èå¯
MagicWeaponã«ã¯ãtokenizerãã¨ãããä¸æã®ãã¼ã¯ã³ãçºè¡ãããã¯ã©ã¹ãããã¾ããã¡ãã£ã¨ããDBã®PKã«æ»ã¬ãã»ã©ä¾¿å©ãªã®ã§ãã使ãã¾ãã
ä¸æ¹ã§ã以åã«æ¸ããã®ã§ãã( http://d.hatena.ne.jp/gallu/20120402/p2 )ãéããã¼ã¯ã³ã®ä½ãæ¹ãããã¾ãã
ã§ãããã¡ããã¯ã使ãåãã¦ããã®ã§ããã®è¾ºã®è©±ãããããã¨ã
ãã¢ã¢ãã®ä¸é話ãèãã¦ãããããã®çã¬ããã¹ã¿ã³ã¹ã§èªãã§ãã ããï½
大ã¾ãã«çµè«å
ã«æ¸ãã¡ããã¨ã
tokenizerã¯ãä¸æã§ãããã¨ãä¿è¨¼ããããã±ã¼ã¹ã§ä½¿ã£ã¦ãããä¸åã®ãã¼ã¯ã³ã¯ãæ¨æ¸¬å°é£æ§ãã»ãããæã«ä½¿ãã¾ãã
ãâ¦ã¾ãããã¡ã®tokenizerã®ä»æ§ããã
åæã¨ãã¦ã62é²æ°ãã£ã¦ã®ã使ã£ã¦ã¾ãã
62é²æ°è¡¨è¨ã«ããã¨ã0-9ã¨a-zã¨A-Zã§è¡¨ç¾ã§ããã®ã§ãã¾ãã¾ã便å©ã§ããç´ ç´ã«base64ã§ãããã£ãã®ã§ãããã§ãããè±æ°ã ãã§è¡¨ç¾ãããã£ãã®ã§ä½ãã¾ããã
ãã§ã
tokenizerã¯ãããã©ã«ãã§
ã»ç¾å¨ã®ã¨ããã¯ã¿ã¤ã (å®éã«ã¯ãæ°å¤ãã§ãããã§ãåºå®ã®æ°å¤ãæ¸ç®ãã¦ã¾ã)
ã»ç¾å¨ã®ãã¤ã¯ãç§
ã»ããã»ã¹ID
ã»ä¹±æ°
ã®ï¼ã¤ã®æ°åããããã©ã«ãã ã¨ãâ(ãã¤ãã³)ãã§ã¤ãªãã¦ã¾ãã
ãªãã·ã§ã³ã§ãèªåã®IPã¢ãã¬ã¹ããããã«è¶³ããã®ã¨ãCã¨Javaã§çµãã§ãæã«ã¯ãã¹ã¬ããIDãã足ãã¦ã¾ããã
PHPã«ã¯ã¹ã¬ãããªããã§ããã£ããçãã¦ã¾ãã
ãããããã¨ãä¹±æ°ä»¥å¤ã®é¨åã§ãã¶ãã®ããåããã·ã³ã®åãããã»ã¹IDä¸ã§ãåãç§ï¼åããã¤ã¯ãç§ã§ãå¦çãï¼å以ä¸èµ°ããå ´åã§ãããã»ã¼ã»ã¼ããããªãã®ã§ã
ããã«ãä¸æã§ããããã¨ã大å¤ç°¡åãã¤ç¢ºå®ã«åå¾ã§ãããã§ã好ãã§ä½¿ã£ã¦ã¾ãã
ã§â¦å®è£
å½åãã¨ã¯ããæ°åãæ®éã«é£çµããã¨ããããé·ãæååãã«ãªã£ãã®ã§ã62é²æ°ä½ãã¾ããï½
ç¾å¨ãã ããã20ã30æå以å
ãããã§åã¾ãã¾ãã
ãã§ã
ãã®tokenããæ¨æ¸¬å°é£ãï¼ãã£ã¦åãããã¨ãå人çã«ã¯ãå¯è½ã¢ããï¼ãã£ã¦æã£ã¦ã¾ãã
ä¹±æ°ããã»ã©æ°ã«ããé¢æ°ä½¿ã£ã¦ã¾ããã(PHPã®å ´åmt_randã¤ãã£ã¦ã¾ãµ)ãã¨ããã¯ç§ã¯å®¹æããã¤ã¯ãç§ãããç¨åº¦ãããã¯ã¤ãã§ãããããããã»ã¹IDã ã£ã¦ãæ¡å¤ã¨ã
ãªã®ã§ãtokenizerã¯ãä¸æã§ãããã¨ãä¿è¨¼ãããã¨ããã«ä½¿ãã¾ãã
ä¸æ¹ã§ã
ã»ãã·ã§ã³IDã¨ããä»åº¦æ¸ããã©CSRFã®å²ç¬¦ãªããã«ä½¿ãããã®ã¯ãæ¨æ¸¬å°é£ãªæååããªã®ã§ã
ããããã¨ã以åãæ¸ããã®ã§ãã
$token = hash('sha512', file_get_contents('/dev/urandom', false, NULL, 0, 128), false);
ã¨ããã¨â¦
ã»urandãªã®ã§ããã¶ããã£ã¨ãããç¨åº¦è³ªã®è¯ãä¹±æ°ã§ããã¨æå¾
ã§ãã(ã¯ãï½)
ã»sha-512ãªã®ã§ãçµæ§ç©ºéåºãã®ã§ãããç°¡åã«ãå¶ç¶å½ãããã£ã¦ã®ãããã¾ãã¦
ã¨ãããããã®çºæ³ãããæ¨æ¸¬å°é£ãªIDãã»ãããæã«éå®ãã¾ãã
ä¸æ¹ã§ãããã¾ããããã ããã¨ã¯æãã®ã§ãããä¸å¿ãå¯è½æ§ã¨ãã¦ã¯ããã¤ãã©ããã§ã以åçºè¡ããIDã¨éè¤ãããå¯è½æ§ãï¼ã§ã¯ãªãã®ã§ã
åºæ¬çã«ã¯ãä¸æã®IDãã»ãããç¨éã§ã¯ãããã¾ã使ããªãã§ãã
æã èãããã®ã§ã説æãçç¥ããæå³åããè¾¼ãã¦ãããï½
PS
ããããã°â¦ãæ¨æ¸¬å°é£ããªã»ããMagicWeaponã«çµã¿è¾¼ã¿ããã®ã§ããâ¦ååã©ããï¼
UUIDã£ã½ã使ãæ¹ãããã®ã§ããâ¦ä¸å¿ãUUIDã¯16ãã¤ãã®æ°å¤ãã£ã¦æ±ºã¾ããããããªãâ¦ãä¼¼éUUIDãã¨ãã£ã¦ååã«ãããããããï¼ï½