Skip to content

Instantly share code, notes, and snippets.

@tiborvass
Last active August 29, 2015 14:18
Show Gist options
  • Save tiborvass/c6876d7dce43ac04981e to your computer and use it in GitHub Desktop.
Save tiborvass/c6876d7dce43ac04981e to your computer and use it in GitHub Desktop.
tls alpn test
MacBook-Pro:~ tibor$ go run /tmp/test.go # with protos=["proto1", "proto2"]
16 3 1 0 8d 1 0 0 89 3 3 26 22 8c d6 2d c9 9a 7f 4a(J) a7 1e e b7 f3 35(5) 4c(L) e8 27 81 ca 67(g) d0 d6 4e(N) 35(5) ab 5f ed b0 e5 d4 fc 0 0 1a c0 2f c0 2b c0 11 c0 7 c0 13 c0 9 c0 14 c0 a 0 5 0 2f 0 35(5) c0 12 0 a 1 0 0 46(F) 33(3) 74(t) 0 0 0 5 0 5 1 0 0 0 0 0 a 0 8 0 6 0 17 0 18 0 19 0 b 0 2 1 0 0 d 0 a 0 8 4 1 4 3 2 1 2 3 ff 1 0 1 0 0 10 0 10 0 e 6 70(p) 72(r) 6f(o) 74(t) 6f(o) 31(1) 6 70(p) 72(r) 6f(o) 74(t) 6f(o) 32(2)
2015/04/06 14:01:38 EOF
exit status 1
MacBook-Pro:~ tibor$ go run /tmp/test.go # with protos=["proto1", "proto2"]
16 3 1 0 8d 1 0 0 89 3 3 a7 b1 94 52(R) 14 d0 a4 28 f5 cf c 28 1e e8 74(t) ae 6d(m) d4 45(E) 8d 57(W) af db db 6c(l) 47(G) bb 1d e5 c9 d4 fc 0 0 1a c0 2f c0 2b c0 11 c0 7 c0 13 c0 9 c0 14 c0 a 0 5 0 2f 0 35(5) c0 12 0 a 1 0 0 46(F) 33(3) 74(t) 0 0 0 5 0 5 1 0 0 0 0 0 a 0 8 0 6 0 17 0 18 0 19 0 b 0 2 1 0 0 d 0 a 0 8 4 1 4 3 2 1 2 3 ff 1 0 1 0 0 10 0 10 0 e 6 70(p) 72(r) 6f(o) 74(t) 6f(o) 31(1) 6 70(p) 72(r) 6f(o) 74(t) 6f(o) 32(2)
2015/04/06 14:01:44 EOF
exit status 1
MacBook-Pro:~ tibor$ go run /tmp/test.go # without protos set
16 3 1 0 8d 1 0 0 89 3 3 1d c3 7b ac 31(1) 58(X) 34(4) b8 55(U) 42(B) e7 a d0 e0 ec 20 d9 6 d3 d4 c8 d0 13 ae 1b 52(R) c2 e0 d7 9d 56(V) ca 0 0 1a c0 2f c0 2b c0 11 c0 7 c0 13 c0 9 c0 14 c0 a 0 5 0 2f 0 35(5) c0 12 0 a 1 0 0 46(F) 33(3) 74(t) 0 0 0 5 0 5 1 0 0 0 0 0 a 0 8 0 6 0 17 0 18 0 19 0 b 0 2 1 0 0 d 0 a 0 8 4 1 4 3 2 1 2 3 ff 1 0 1 0 0 10 0 10 0 e 6 70(p) 72(r) 6f(o) 74(t) 6f(o) 31(1) 6 70(p) 72(r) 6f(o) 74(t) 6f(o) 32(2)
2015/04/06 14:01:47 EOF
exit status 1
MacBook-Pro:~ tibor$ go run /tmp/test.go # without protos set
16 3 1 0 75(u) 1 0 0 71(q) 3 3 ed 90 4c(L) 8e 6f(o) 10 9a 9a 83 50(P) 3d 8 7 6c(l) c5 ce b8 10 bc 63(c) 5c 7d d2 0 a8 eb b0 98 10 99 38(8) a0 0 0 1a c0 2f c0 2b c0 11 c0 7 c0 13 c0 9 c0 14 c0 a 0 5 0 2f 0 35(5) c0 12 0 a 1 0 0 2e 0 5 0 5 1 0 0 0 0 0 a 0 8 0 6 0 17 0 18 0 19 0 b 0 2 1 0 0 d 0 a 0 8 4 1 4 3 2 1 2 3 ff 1 0 1 0
2015/04/06 14:02:01 EOF
exit status 1
MacBook-Pro:~ tibor$ go run /tmp/test.go
16 3 1 0 75(u) 1 0 0 71(q) 3 3 66(f) a6 91 80 f0 8c 6f(o) fd 99 71(q) a2 3 7b 78(x) d 88 aa 95 9a da e2 b9 d5 11 ed 34(4) 1f 98 43(C) 40 c2 6e(n) 0 0 1a c0 2f c0 2b c0 11 c0 7 c0 13 c0 9 c0 14 c0 a 0 5 0 2f 0 35(5) c0 12 0 a 1 0 0 2e 0 5 0 5 1 0 0 0 0 0 a 0 8 0 6 0 17 0 18 0 19 0 b 0 2 1 0 0 d 0 a 0 8 4 1 4 3 2 1 2 3 ff 1 0 1 0
2015/04/06 14:02:04 EOF
exit status 1
package main
import (
"bufio"
"crypto/tls"
"fmt"
"log"
"net"
"time"
)
var protos []string = nil //[]string{"proto1", "proto2"}
func main() {
ln, err := net.Listen("tcp", ":1234")
if err != nil {
log.Fatal(err)
}
go func() {
for {
conn, err := ln.Accept()
if err != nil {
log.Println(err)
}
go handleConnection(conn)
}
}()
time.Sleep(time.Second)
conn, err := tls.Dial("tcp", ":1234", &tls.Config{InsecureSkipVerify: true, NextProtos: protos})
if err != nil {
log.Fatal(err)
}
fmt.Println("exit")
conn.Close()
}
func handleConnection(conn net.Conn) {
scanner := bufio.NewScanner(conn)
scanner.Split(bufio.ScanBytes)
done := make(chan struct{})
go func() {
for scanner.Scan() {
b := scanner.Bytes()[0]
if (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || (b >= '0' && b <= '9') {
fmt.Printf("%x(%s) ", b, string(b))
} else {
fmt.Printf("%x ", b)
}
}
close(done)
}()
select {
case <-done:
case <-time.After(time.Second):
}
fmt.Println()
conn.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment