mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
add --meek flag to client to toggle the domain fronted rendezvous
This commit is contained in:
parent
dcb901e408
commit
b4a07c4192
3 changed files with 45 additions and 42 deletions
|
@ -88,4 +88,11 @@ snowflake to just use a default relay.
|
||||||
|
|
||||||
### More
|
### More
|
||||||
|
|
||||||
|
To try using the Meek signaling channel (which will soon be fully ready),
|
||||||
|
add the `--meek` flag like so:
|
||||||
|
|
||||||
|
```
|
||||||
|
ClientTransportPlugin snowflake exec ./client --meek
|
||||||
|
```
|
||||||
|
|
||||||
More documentation on the way.
|
More documentation on the way.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Exchange WebRTC SessionDescriptions over meek.
|
// Exchange WebRTC SessionDescriptions over a domain-fronted HTTP
|
||||||
// Much of this source is extracted from meek-client.go.
|
// signalling channel.
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -16,29 +16,26 @@ import (
|
||||||
// roundtrip, including variables that may come from SOCKS args or from the
|
// roundtrip, including variables that may come from SOCKS args or from the
|
||||||
// command line.
|
// command line.
|
||||||
type RequestInfo struct {
|
type RequestInfo struct {
|
||||||
// What to put in the X-Session-ID header.
|
// What to put in the X-Session-ID header - SessionID string
|
||||||
// SessionID string
|
// The desired potentially filtered URL to request.
|
||||||
// The URL to request.
|
|
||||||
URL *url.URL
|
URL *url.URL
|
||||||
// The Host header to put in the HTTP request (optional and may be
|
// The Host header to put in the HTTP request (optional and may be
|
||||||
// different from the host name in URL).
|
// different from the host name in URL).
|
||||||
Host string
|
Host string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRequestInfo(meekUrl string, front string) *RequestInfo {
|
func NewRequestInfo(targetUrl string, front string) *RequestInfo {
|
||||||
info := new(RequestInfo)
|
info := new(RequestInfo)
|
||||||
requestUrl, err := url.Parse(meekUrl)
|
requestUrl, err := url.Parse(targetUrl)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
info.URL = requestUrl
|
info.URL = requestUrl
|
||||||
info.Host = front
|
info.Host = front
|
||||||
// info.URL.Host = front
|
|
||||||
// info.Host = info.URL.Host
|
|
||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
// Meek Signalling Channel
|
// Meek Signalling Channel.
|
||||||
type MeekChannel struct {
|
type MeekChannel struct {
|
||||||
info *RequestInfo
|
info *RequestInfo
|
||||||
// Used to make all requests.
|
// Used to make all requests.
|
||||||
|
@ -58,24 +55,23 @@ func NewMeekChannel(info *RequestInfo) *MeekChannel {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do an HTTP roundtrip using the payload data in buf.
|
// Do an HTTP roundtrip using the payload data in buf.
|
||||||
func (m *MeekChannel) roundTripHTTP(buf []byte) (*http.Response, error) {
|
func (mc *MeekChannel) roundTripHTTP(buf []byte) (*http.Response, error) {
|
||||||
// Compose an innocent looking request.
|
// Compose an innocent looking request.
|
||||||
req, err := http.NewRequest("POST", m.info.Host+"/reg/123", bytes.NewReader(buf))
|
req, err := http.NewRequest("POST", mc.info.Host+"/reg/123", bytes.NewReader(buf))
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Set actually desired target host.
|
// Set actually desired host in the request.
|
||||||
req.Host = m.info.URL.String()
|
req.Host = mc.info.URL.String()
|
||||||
// req.Header.Set("X-Session-Id", m.info.SessionID)
|
// req.Header.Set("X-Session-Id", m.info.SessionID)
|
||||||
return m.transport.RoundTrip(req)
|
return mc.transport.RoundTrip(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send an SDP offer to the meek facilitator, and wait for an SDP answer from
|
// Send an SDP offer to the meek facilitator, and wait for an SDP answer from
|
||||||
// the assigned proxy in the response.
|
// the assigned proxy in the response.
|
||||||
func (m *MeekChannel) Negotiate(offer *webrtc.SessionDescription) (
|
func (mc *MeekChannel) Negotiate(offer *webrtc.SessionDescription) (
|
||||||
*webrtc.SessionDescription, error) {
|
*webrtc.SessionDescription, error) {
|
||||||
buf := []byte(offer.Serialize())
|
resp, err := mc.roundTripHTTP([]byte(offer.Serialize()))
|
||||||
resp, err := m.roundTripHTTP(buf)
|
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -85,11 +81,11 @@ func (m *MeekChannel) Negotiate(offer *webrtc.SessionDescription) (
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
log.Println("MeekChannel Body: ", string(body))
|
|
||||||
answer := webrtc.DeserializeSessionDescription(string(body))
|
answer := webrtc.DeserializeSessionDescription(string(body))
|
||||||
return answer, nil
|
return answer, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Simple interim non-fronting HTTP POST negotiation, to be removed when more
|
// Simple interim non-fronting HTTP POST negotiation, to be removed when more
|
||||||
// general fronting is present.
|
// general fronting is present.
|
||||||
func sendOfferHTTP(url string, offer *webrtc.SessionDescription) (*webrtc.SessionDescription, error) {
|
func sendOfferHTTP(url string, offer *webrtc.SessionDescription) (*webrtc.SessionDescription, error) {
|
||||||
|
|
|
@ -25,14 +25,15 @@ import (
|
||||||
// Hard-coded meek signalling channel for now.
|
// Hard-coded meek signalling channel for now.
|
||||||
// TODO: expose as param
|
// TODO: expose as param
|
||||||
const (
|
const (
|
||||||
MEEK_URL = "snowflake-reg.appspot.com"
|
// Go fully requires the protocol to make url spec
|
||||||
FRONT_DOMAIN = "https://www.google.com"
|
FRONT_URL = "https://www.google.com"
|
||||||
// FRONT_DOMAIN = "https://www.google.com"
|
BROKER_URL = "snowflake-reg.appspot.com"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ptInfo pt.ClientInfo
|
var ptInfo pt.ClientInfo
|
||||||
var logFile *os.File
|
var logFile *os.File
|
||||||
var offerURL string
|
var offerURL string
|
||||||
|
var meekEnabled bool
|
||||||
|
|
||||||
// When a connection handler starts, +1 is written to this channel; when it
|
// When a connection handler starts, +1 is written to this channel; when it
|
||||||
// ends, -1 is written.
|
// ends, -1 is written.
|
||||||
|
@ -160,7 +161,6 @@ func dialWebRTC(config *webrtc.Configuration, meek *MeekChannel) (
|
||||||
close(openChan)
|
close(openChan)
|
||||||
}
|
}
|
||||||
dc.OnMessage = func(msg []byte) {
|
dc.OnMessage = func(msg []byte) {
|
||||||
// log.Printf("OnMessage channel %d %+q", len(msg), msg)
|
|
||||||
log.Printf("OnMessage <--- %d bytes", len(msg))
|
log.Printf("OnMessage <--- %d bytes", len(msg))
|
||||||
n, err := pw.Write(msg)
|
n, err := pw.Write(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -180,20 +180,22 @@ func dialWebRTC(config *webrtc.Configuration, meek *MeekChannel) (
|
||||||
fmt.Fprintln(logFile, "\n"+offer.Serialize()+"\n")
|
fmt.Fprintln(logFile, "\n"+offer.Serialize()+"\n")
|
||||||
log.Printf("----------------")
|
log.Printf("----------------")
|
||||||
go func() {
|
go func() {
|
||||||
// log.Printf("Sending offer via meek...")
|
if meekEnabled {
|
||||||
// answer, err := meek.Negotiate(pc.LocalDescription())
|
log.Println("Sending offer via meek channel...\nTarget URL: ", BROKER_URL,
|
||||||
// if nil != err {
|
"\nFront URL: ", FRONT_URL)
|
||||||
// log.Printf("Signalling error: %s", err)
|
answer, err := meek.Negotiate(pc.LocalDescription())
|
||||||
// }
|
if nil != err {
|
||||||
// if nil == answer {
|
log.Printf("MeekChannel signaling error: %s", err)
|
||||||
// log.Printf("No answer received from meek channel.")
|
}
|
||||||
// } else {
|
if nil == answer {
|
||||||
// // TODO: Once this is correct, uncomment and remove copy-paste
|
log.Printf("MeekChannel: No answer received.")
|
||||||
// // signalling.
|
} else {
|
||||||
// log.Println("Recieved answer from Meek channel: \n",
|
log.Println("Recieved answer from Meek channel: \n\n",
|
||||||
// answer.Serialize())
|
answer.Serialize(), "\n")
|
||||||
// // signalChan <- answer
|
// TODO: Once this is correct, uncomment and remove copy-paste stuff.
|
||||||
// }
|
// signalChan <- answer
|
||||||
|
}
|
||||||
|
}
|
||||||
if offerURL != "" {
|
if offerURL != "" {
|
||||||
answer, err := sendOfferHTTP(offerURL, offer)
|
answer, err := sendOfferHTTP(offerURL, offer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -253,15 +255,12 @@ func handler(conn *pt.SocksConn) error {
|
||||||
}()
|
}()
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
// go func() {
|
|
||||||
// }()
|
|
||||||
// Prepare meek signalling channel.
|
// Prepare meek signalling channel.
|
||||||
info := NewRequestInfo(MEEK_URL, FRONT_DOMAIN)
|
info := NewRequestInfo(BROKER_URL, FRONT_URL)
|
||||||
meek := NewMeekChannel(info)
|
meek := NewMeekChannel(info)
|
||||||
|
|
||||||
config := webrtc.NewConfiguration(
|
config := webrtc.NewConfiguration(
|
||||||
webrtc.OptionIceServer("stun:stun.l.google.com:19302"))
|
webrtc.OptionIceServer("stun:stun.l.google.com:19302"))
|
||||||
// remote, err := dialWebRTC(config, nil)
|
|
||||||
remote, err := dialWebRTC(config, meek)
|
remote, err := dialWebRTC(config, meek)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
conn.Reject()
|
conn.Reject()
|
||||||
|
@ -322,7 +321,8 @@ func readSignalingMessages(f *os.File) {
|
||||||
func main() {
|
func main() {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
flag.StringVar(&offerURL, "url", "", "do signaling through URL")
|
flag.StringVar(&offerURL, "url", "", "do signalling through URL")
|
||||||
|
flag.BoolVar(&meekEnabled, "meek", false, "use domain fronted signaling")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
logFile, err = os.OpenFile("snowflake.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
|
logFile, err = os.OpenFile("snowflake.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue