diff --git a/etc/utils/fmtcheck.sh b/etc/utils/fmtcheck.sh new file mode 100755 index 0000000..50e45e0 --- /dev/null +++ b/etc/utils/fmtcheck.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# Copyright 2012 The Go Authors. All rights reserved. +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. + +gofiles=$(find . -iname "*.go" ! -path "*/_dev/*") +#[ -z "$gofiles" ] && exit 0 + +unformatted=$(gofmt -l $gofiles) +[ -z "$unformatted" ] && exit 0 + +# Some files are not gofmt'd. Print message and fail. + +echo >&2 "Go files must be formatted with gofmt. Please run:" +for fn in $unformatted; do + echo >&2 " gofmt -w $PWD/$fn" +done + +exit 1 + diff --git a/etc/utils/pre-commit b/etc/utils/pre-commit new file mode 100755 index 0000000..387f555 --- /dev/null +++ b/etc/utils/pre-commit @@ -0,0 +1,27 @@ +#!/bin/sh +# Copyright 2012 The Go Authors. All rights reserved. +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. + +# git gofmt pre-commit hook +# +# To use, store as .git/hooks/pre-commit inside your repository and make sure +# it has execute permissions. +# +# This script does not handle file names that contain spaces. + +gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep '\.go$') +[ -z "$gofiles" ] && exit 0 + +unformatted=$(gofmt -l $gofiles) +[ -z "$unformatted" ] && exit 0 + +# Some files are not gofmt'd. Print message and fail. + +echo >&2 "Go files must be formatted with gofmt. Please run:" +for fn in $unformatted; do + echo >&2 " gofmt -w $PWD/$fn" +done + +exit 1 + diff --git a/examples/.gitignore b/examples/.gitignore new file mode 100644 index 0000000..23c0b93 --- /dev/null +++ b/examples/.gitignore @@ -0,0 +1,6 @@ +/GOROOT +/go +/tris-localserver/tris-localserver +/tris-testclient/tris-testclient +/caddy/caddy +/caddy/echo diff --git a/examples/tls_examples/Makefile b/examples/tls_examples/Makefile new file mode 100644 index 0000000..6a49d52 --- /dev/null +++ b/examples/tls_examples/Makefile @@ -0,0 +1,7 @@ +# Used to build examples. Must be compiled from current directory and after "make build-all" + +build: + GOROOT=../GOROOT/linux_amd64 go build ems_client.go + +run: + ./ems_client google.com:443 diff --git a/examples/tls_examples/ems_client.go b/examples/tls_examples/ems_client.go new file mode 100644 index 0000000..f99a50d --- /dev/null +++ b/examples/tls_examples/ems_client.go @@ -0,0 +1,75 @@ +package main + +import ( + "bufio" + "crypto/tls" + "flag" + "fmt" + "io" + "net/http" + "net/url" + "os" +) + +var tlsVersionToName = map[string]uint16{ + "tls10": tls.VersionTLS10, + "tls11": tls.VersionTLS11, + "tls12": tls.VersionTLS12, + "tls13": tls.VersionTLS13, +} + +// Usage client args host:port +func main() { + var version string + var addr string + var enableEMS bool + var resume bool + var config tls.Config + var cache tls.ClientSessionCache + cache = tls.NewLRUClientSessionCache(0) + flag.StringVar(&version, "version", "tls12", "Version of TLS to use") + flag.BoolVar(&enableEMS, "m", false, "Enable EMS") + flag.BoolVar(&resume, "r", false, "Attempt Resumption") + flag.Parse() + config.MinVersion = tlsVersionToName[version] + config.MaxVersion = tlsVersionToName[version] + config.InsecureSkipVerify = true + config.UseExtendedMasterSecret = !enableEMS + config.ClientSessionCache = cache + var iters int + if resume { + iters = 2 + } else { + iters = 1 + } + addr = flag.Arg(0) + for ; iters > 0; iters-- { + conn, err := tls.Dial("tcp", addr, &config) + if err != nil { + fmt.Println("Error %s", err) + os.Exit(1) + } + var req http.Request + var response *http.Response + req.Method = "GET" + req.URL, err = url.Parse("https://" + addr + "/") + if err != nil { + fmt.Println("Failed to parse url") + os.Exit(1) + } + req.Write(conn) + reader := bufio.NewReader(conn) + response, err = http.ReadResponse(reader, nil) + if err != nil { + fmt.Println("HTTP problem") + fmt.Println(err) + os.Exit(1) + } + io.Copy(os.Stdout, response.Body) + conn.Close() + if resume && iters == 2 { + fmt.Println("Attempting resumption") + } + } + os.Exit(0) +}