move SNI to separate package for both client and server

This commit is contained in:
tigerbot 2017-04-03 17:37:29 -06:00
parent dcdc26068b
commit b44fe740af
2 changed files with 5 additions and 3 deletions

View File

@ -18,6 +18,7 @@ import (
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"git.daplie.com/Daplie/go-rvpn-server/rvpn/packer" "git.daplie.com/Daplie/go-rvpn-server/rvpn/packer"
"git.daplie.com/Daplie/go-rvpn-server/rvpn/sni"
) )
type contextKey string type contextKey string
@ -160,7 +161,7 @@ func handleConnection(ctx context.Context, wConn *WedgeConn) {
wssHostName := ctx.Value(ctxWssHostName).(string) wssHostName := ctx.Value(ctxWssHostName).(string)
adminHostName := ctx.Value(ctxAdminHostName).(string) adminHostName := ctx.Value(ctxAdminHostName).(string)
sniHostName, err := getHello(peek) sniHostName, err := sni.GetHostname(peek)
if err != nil { if err != nil {
loginfo.Println(err) loginfo.Println(err)
return return

View File

@ -1,10 +1,11 @@
package server package sni
import ( import (
"errors" "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:] rest := b[5:]
current := 0 current := 0
handshakeType := rest[0] handshakeType := rest[0]