From b44fe740af11ae2405457267910c7aeea060db9a Mon Sep 17 00:00:00 2001 From: tigerbot Date: Mon, 3 Apr 2017 17:37:29 -0600 Subject: [PATCH] move SNI to separate package for both client and server --- rvpn/server/listener_generic.go | 3 ++- rvpn/{server/tls_get_hello.go => sni/tls_get_hostname.go} | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) rename rvpn/{server/tls_get_hello.go => sni/tls_get_hostname.go} (91%) diff --git a/rvpn/server/listener_generic.go b/rvpn/server/listener_generic.go index ad56bdc..0f68e52 100644 --- a/rvpn/server/listener_generic.go +++ b/rvpn/server/listener_generic.go @@ -18,6 +18,7 @@ import ( "github.com/gorilla/websocket" "git.daplie.com/Daplie/go-rvpn-server/rvpn/packer" + "git.daplie.com/Daplie/go-rvpn-server/rvpn/sni" ) type contextKey string @@ -160,7 +161,7 @@ func handleConnection(ctx context.Context, wConn *WedgeConn) { wssHostName := ctx.Value(ctxWssHostName).(string) adminHostName := ctx.Value(ctxAdminHostName).(string) - sniHostName, err := getHello(peek) + sniHostName, err := sni.GetHostname(peek) if err != nil { loginfo.Println(err) return diff --git a/rvpn/server/tls_get_hello.go b/rvpn/sni/tls_get_hostname.go similarity index 91% rename from rvpn/server/tls_get_hello.go rename to rvpn/sni/tls_get_hostname.go index 8aa78c4..606fdf7 100644 --- a/rvpn/server/tls_get_hello.go +++ b/rvpn/sni/tls_get_hostname.go @@ -1,10 +1,11 @@ -package server +package sni import ( "errors" ) -func getHello(b []byte) (string, error) { +// GetHostname uses SNI to determine the intended target of a new TLS connection. +func GetHostname(b []byte) (string, error) { rest := b[5:] current := 0 handshakeType := rest[0]