-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmain.go
51 lines (46 loc) · 1.28 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"crypto/tls"
"flag"
"fmt"
"io"
"log"
"net"
"net/http"
oohttp "github.com/ooni/oohttp"
"github.com/ooni/oohttp/example/internal/utlsx"
)
// newTransport returns a new http.Transport using the provided tls dialer.
func newTransport(f func(conn net.Conn, config *tls.Config) oohttp.TLSConn) http.RoundTripper {
return utlsx.NewOOHTTPTransport(
oohttp.ProxyFromEnvironment,
f,
nil, // we're using f to wrap dialed connections
)
}
// newClient creates a new http.Client using the given transport.
func newClient(txp http.RoundTripper) *http.Client {
return &http.Client{Transport: txp}
}
func main() {
// The default URL we use should return us the JA3 fingerprint
// we're using to communicate with the server. We expect such a
// fingerprint to change when we use the `-utls` flag.
url := flag.String("url", "https://ja3er.com/json", "the URL to get")
utls := flag.Bool("utls", false, "try using uTLS")
flag.Parse()
var ffun func(conn net.Conn, config *tls.Config) oohttp.TLSConn
if *utls {
ffun = (&utlsx.FactoryWithParrot{}).NewUTLSConn
}
resp, err := newClient(newTransport(ffun)).Get(*url)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
data, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", data)
}