ã¯ããã«
ã¨ã³ã¸ãã¢ï¼å¹´ç®ã®TKDSã§ãï¼
æ®æ®µä½æ°ãªã使ã£ã¦ãã»ã¨ãã©ã®Webãµã¤ãã対å¿ãã¦ããHTTPSéä¿¡ã®ä»çµã¿ã«ã¤ãã¦èª¿ã¹ã¦ã¿ã¾ããã
æ¬è¨äºã§ã¯ãWiresharkãç¨ãã¦HTTPSã®å
é¨åä½ã解æããã©ã®ããã«ãã¦ãã¼ã¿ãä¿è·ããã¦ããã®ããå
·ä½çã«è§£èª¬ãã¾ãã
è¨äºã®å¾åã§ã¯ãWiresharkã使ã£ã¦å®éã®éä¿¡ãã¼ã¿ã観å¯ããæå·åããã»ã¹ã®è©³ç´°ã確èªãã¦ã¿ã¾ãã
HTTPS(HTTP Over TLS)ã¨ã¯
HTTPS(HTTP Over TLS)ã¯ãHTTPã®æå·åçã§ãã¦ã§ããµã¤ãã¨ãã©ã¦ã¶éã®å®å
¨ãªéä¿¡ãå®ç¾ãããããã³ã«ã§ãã
TLSã使ç¨ãã¦ãHTTPéä¿¡ãæå·åãããã¨ã§ããã¼ã¿ã®æ©å¯æ§ããã¼ã¿ã®æ´åæ§ãéä¿¡å
ãµã¼ãã¼ã®ä¿¡é ¼æ§ã確èªã§ãã¾ãã
SSL/TLS
SSLï¼Secure Sockets Layerï¼ã¨TLSï¼Transport Layer Securityï¼ã¯ãã¤ã³ã¿ã¼ãããä¸ã§ãã¼ã¿ãæå·åãã¦éåä¿¡ããããã®ãããã³ã«ã§ãã
ãããã®ãããã³ã«ã¯ãã¦ã§ããã©ã¦ã¶ã¨ã¦ã§ããµã¼ãã¼éã®éä¿¡ãä¿è·ãããã¼ã¿ã®çè´ãæ¹ãããé²ãããã«ä½¿ç¨ããã¾ãã
SSLã¯1990年代åé ã«Netscape社ã«ãã£ã¦éçºããã¾ããã
æåã®ãã¼ã¸ã§ã³ã§ããSSL 2.0ã¯1995å¹´ã«ãªãªã¼ã¹ããã¾ããããã»ãã¥ãªãã£ä¸ã®èå¼±æ§ãçºè¦ããã1996å¹´ã«SSL 3.0ã«ç½®ãæãããã¾ããã
ãã®å¾ã1999å¹´ã«SSL 3.0ãåºã«ããTLS 1.0ãç»å ´ããç¾å¨ã§ã¯TLS 1.3ãææ°ãã¼ã¸ã§ã³ã¨ãã¦ä½¿ç¨ããã¦ãã¾ãã
HTTPSã®æµã
HTTPSã¯æ¬¡ã®æµãã§éä¿¡ãè¡ãã¾ãã
- ã¯ã©ã¤ã¢ã³ãããµã¼ãã¼ã«HTTPSæ¥ç¶ãè¦æ±
- ãµã¼ãã¼ãSSL/TLS証ææ¸ï¼å ¬ééµãå«ãï¼ãã¯ã©ã¤ã¢ã³ãã«éä¿¡
- ã¯ã©ã¤ã¢ã³ãã証ææ¸ãæ¤è¨¼ãããµã¼ãã¼ã®èº«å ã確èª
- ã¯ã©ã¤ã¢ã³ããã»ãã·ã§ã³éµï¼å¯¾ç§°éµï¼ãçæ
- ã¯ã©ã¤ã¢ã³ããã»ãã·ã§ã³éµããµã¼ãã¼ã®å ¬ééµã§æå·åãã¦éä¿¡
- ãµã¼ãã¼ãç§å¯éµã使ã£ã¦ã»ãã·ã§ã³éµã復å·ããã®æç¹ã§ãã¯ã©ã¤ã¢ã³ãã¨ãµã¼ãã¼ã®ä¸¡æ¹ãåãã»ãã·ã§ã³éµãå ±æã以éã®éä¿¡ã¯ãã®ã»ãã·ã§ã³éµã使ã£ã¦æå·å
- ã¯ã©ã¤ã¢ã³ããæå·åãããHTTPãªã¯ã¨ã¹ããéä¿¡
- ãµã¼ãã¼ããªã¯ã¨ã¹ãã復å·ãã¦å¦ç
- ãµã¼ãã¼ãæå·åãããHTTPã¬ã¹ãã³ã¹ãéä¿¡
- ã¯ã©ã¤ã¢ã³ããã¬ã¹ãã³ã¹ã復å·ãã¦è¡¨ç¤º
HTTPSã®æµãã®å³ã以ä¸ã«è¨è¼ãã¾ãã
æå·éµãã¯ã©ã¤ã¢ã³ãã¨ãµã¼ãã¼éã®éä¿¡ã§ä½¿ããã¨ã§å®å ¨ã«éä¿¡ãã¦ãããã¨ããããã¾ããã
å®éã«éä¿¡ã観å¯
次ã«HTTPSã観å¯ãã¦ã¿ã¾ãã
éä¿¡å
ã®ãµã¼ãã¼ãGoã§ç¨æãã¦ãcurlã§éä¿¡ãã¾ãã
èªå·±ç½²å証ææ¸ã®ç¨æ
ä»å使ã証ææ¸ãç¨æãã¾ãã
sudo apt-get update sudo apt-get install openssl openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout server.key -out server.crt
ãµã¼ãã¼ã®ä½æ
ä»å使ç¨ããhttpãµã¼ãã¼ãç¨æãã¾ãã
ãã¡ã¤ã«åã¯main.goãæ³å®ãã¦ãã¾ãã
èµ·åã¯ãgo run main.go
ã§è¡ã£ã¦ãã ããã
- HTTPãµã¼ãã¼
package main import ( "fmt" "net/http" ) func helloHandler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello, World!") } func main() { http.HandleFunc("/", helloHandler) fmt.Println("Starting HTTP server on :8080") if err := http.ListenAndServe(":8080", nil); err != nil { fmt.Println("Error starting HTTP server:", err) } }
- HTTPSãµã¼ãã¼
package main import ( "fmt" "net/http" ) func helloHandler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello, World!") } func main() { http.HandleFunc("/", helloHandler) fmt.Println("Starting HTTPS server on :8443") if err := http.ListenAndServeTLS(":8443", "server.crt", "server.key", nil); err != nil { fmt.Println("Error starting HTTPS server:", err) } }
WireSharkã®æºå
éä¿¡ã®ãã£ããã£ã¯WireSharkã使ãã¾ãã
以ä¸ã®æé ã«ãããã£ã¦æºåãã¦ãã ããã
- ã¤ã³ã¹ãã¼ã«
sudo apt-get update sudo apt-get install wireshark sudo dpkg-reconfigure wireshark-common sudo usermod -aG wireshark $USER newgrp wireshark
- èµ·å
sudo wireshark
- ãã£ããã£ãããããã¯ã¼ã¯ã¤ã³ã¿ã¼ãã§ã¼ã¹ã®é¸æ
ä»åã¯localhostãªã®ã§ãloãé¸æãã¾ãã
- ãã£ããã£ã®éå§
éå§ãã¿ã³ãæ¼ãã¨ãã£ããã£ãéå§ããã¾ãã
HTTPã®å ´åãä¸é¨ã®ãã£ã«ã¿ã«http.request and tcp.port == 8080
ãå ¥åãã¾ãã
HTTPSã®å ´åãä¸é¨ã®ãã£ã«ã¿ã«tls and tcp.port == 8443
ã¨å ¥åãã¾ãã
ãªã¯ã¨ã¹ããéä¿¡ãã¦è¦³å¯
- HTTP
httpç¨ã®ãµã¼ãã¼ãèµ·åãã¦ãããªã¯ã¨ã¹ããéãã
curl http://localhost:8080
é常ã®HTTPéä¿¡ãè¡ããã¦ããã®ã確èªã§ãã¾ãã
ãã£ã«ã¿ã®httpæå®ãå¤ãã¦ãã¹ã¦ã®éä¿¡ãã¿ã¦ããhttpsã§ã¯ãªãã®ã§æå·åã¯è¡ããã¦ããªããã¨ããããã¾ãã
- HTTPS
HTTPSç¨ã®ãµã¼ãã¼ãèµ·åãã¦ãããªã¯ã¨ã¹ããéãã
curl -k https://localhost:8443
TLSãã³ãã·ã§ã¤ã¯ãè¡ããã¦ãããã¨ã確èªã§ãã¾ãã
æå·åããã¦ããã®ã§ã©ã®httpã¡ã½ãããå®è¡ãã¦ããããã¨ã³ããã¤ã³ãã®ãã¹ã¯ãªã«ããªã©ã¯éä¿¡å
容ããèªã¿åããªããªã£ã¦ãã¾ãã
TLSã®æµããå°ãã¿ã¦ã¿ã¾ãããã
- Client Hello
TLSï¼Transport Layer Securityï¼æ¥ç¶ã®éå§æã«ã¯ã©ã¤ã¢ã³ããããµã¼ãã¼ã«éä¿¡ãããæåã®ã¡ãã»ã¼ã¸ã§ãã
ã¯ã©ã¤ã¢ã³ãããµãã¼ãããã»ãã¥ãªãã£è¨å®ããµã¼ãã¼ã«éç¥ãããµã¼ãã¼ã¨ã¯ã©ã¤ã¢ã³ãã®éã§ä½¿ç¨ããæå·åæ¹æ³ã®ãã´ã·ã¨ã¼ããéå§ãã¾ãã
- Server Hello
Server Helloãã¯ã©ã¤ã¢ã³ãã«éä¿¡ãã使ç¨ããTLSã®ãã¼ã¸ã§ã³ãæå·ã¹ã¤ã¼ããå§ç¸®æ¹æ³ã確å®ãã¾ãã
- Change Cipher Spec, Application Data
Change Cipher Specãã¯ã©ã¤ã¢ã³ãã«éä¿¡ãã以éã®éä¿¡ãæå·åããããã¨ãéç¥
以ä¸ãTLSã®æµãã§ããã
ã¾ã¨ã
ããã¾ã§èªãã§ããã ããããã¨ããããã¾ããï¼
ãã®è¨äºã§ã¯HTTPã¨HTTPSã®éä¿¡ã観å¯ããéä¿¡å
容ãæ¯è¼ãã¾ããã
ãµã¨ããçåãã調ã¹ã¯ãããå
容ã§ããããç¥èã®å¾©ç¿ããã¼ã«ã®ä½¿ãæ¹ãæãåºãå½¹ã«ç«ã¡ã¾ãã ã
æ®æ®µæèããã«ä½¿ã£ã¦ãããã®ããå®éã«èª¿ã¹ã¦ã¿ããã¨ã§ãç¥èã®å®çã«ã¤ãªããã¾ããã