Skip to content

Instantly share code, notes, and snippets.

@yuroyoro
Last active February 15, 2018 04:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuroyoro/c26ba2f34fee3b8398a987b2e39e9368 to your computer and use it in GitHub Desktop.
Save yuroyoro/c26ba2f34fee3b8398a987b2e39e9368 to your computer and use it in GitHub Desktop.
GoでhttpsをMiTMするProxyの作り方メモ

GoでhttpsをMiTMするProxyの作り方

  1. CONNECTメソッドのリクエストから、http.Hijackerを使って生のTCPコネクションを取り出す
  2. クライアントには200 okを返す
  3. 接続先ホストの証明書を、予め用意してあるroot証明書でサインして生成する
  4. 生成した証明書でクライアントとtls接続を確立する (root証明書が登録されていないとブラウザで警告が出る)
  5. goroutine起こして、クライアントとのtls接続からhttp requestを読み込む
  6. 受けたhttp requestをそのまま接続先hostに送信する
  7. 接続先hostからのhttp responseを、クライアントtls接続に書き込む
  8. EOFが来るまで 5-7繰り返し

https://github.com/elazarl/goproxy/blob/master/https.go#L67 https://github.com/moriyoshi/devproxy/blob/master/server.go#L208

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment