ing
This commit is contained in:
parent
b486381b2a
commit
99951cc3c0
Binary file not shown.
|
@ -7,8 +7,8 @@
|
|||
"keepAlive": 60,
|
||||
"handshakeTimeout": 60,
|
||||
"maxMessageSize": 8192,
|
||||
"readBufferSize": 1024,
|
||||
"writeBufferSize": 1024,
|
||||
"readBufferSize": 4096,
|
||||
"writeBufferSize": 4096,
|
||||
"readTimeout": 0,
|
||||
"writeTimeout": 0,
|
||||
"pongTimeout": 60,
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
"keepAlive": 60,
|
||||
"handshakeTimeout": 60,
|
||||
"maxMessageSize": 8192,
|
||||
"readBufferSize": 1024,
|
||||
"writeBufferSize": 1024,
|
||||
"readBufferSize": 4096,
|
||||
"writeBufferSize": 4096,
|
||||
"readTimeout": 0,
|
||||
"writeTimeout": 0,
|
||||
"pongTimeout": 60,
|
||||
|
|
|
@ -3,9 +3,13 @@ package config
|
|||
import (
|
||||
occe "git.loafle.net/overflow/commons-go/config/external"
|
||||
ogrs "git.loafle.net/overflow/gateway_rpc/server"
|
||||
"crypto/rsa"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
ServerHandler *ogrs.ServerHandlers `json:"serverHandler"`
|
||||
External *occe.External `json:"external"`
|
||||
|
||||
VerifyKey *rsa.PublicKey
|
||||
SignKey *rsa.PrivateKey
|
||||
}
|
||||
|
|
29
main.go
29
main.go
|
@ -13,6 +13,9 @@ import (
|
|||
"git.loafle.net/commons/logging-go"
|
||||
"git.loafle.net/overflow/member_gateway_rpc/config"
|
||||
"git.loafle.net/overflow/member_gateway_rpc/server"
|
||||
"io/ioutil"
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"path"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -33,8 +36,9 @@ func main() {
|
|||
if err := configuration.Load(_config, "config.json"); nil != err {
|
||||
logging.Logger().Panic(err)
|
||||
}
|
||||
loadKey(*configDir, _config)
|
||||
|
||||
s := server.New(*configDir, _config)
|
||||
s := server.New(_config)
|
||||
|
||||
go func() {
|
||||
err := s.ListenAndServe()
|
||||
|
@ -59,3 +63,26 @@ func main() {
|
|||
logging.Logger().Errorf("error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func loadKey(configDir string, _config *config.Config) {
|
||||
|
||||
signBytes, err := ioutil.ReadFile(path.Join(configDir, "overFlow-private.key"))
|
||||
if nil != err {
|
||||
logging.Logger().Panic(err)
|
||||
}
|
||||
|
||||
_config.SignKey, err = jwt.ParseRSAPrivateKeyFromPEM(signBytes)
|
||||
if nil != err {
|
||||
logging.Logger().Panic(err)
|
||||
}
|
||||
|
||||
verifyBytes, err := ioutil.ReadFile(path.Join(configDir, "overFlow-public.pem"))
|
||||
if nil != err {
|
||||
logging.Logger().Panic(err)
|
||||
}
|
||||
|
||||
_config.VerifyKey, err = jwt.ParseRSAPublicKeyFromPEM(verifyBytes)
|
||||
if nil != err {
|
||||
logging.Logger().Panic(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,9 +6,10 @@ import (
|
|||
"git.loafle.net/overflow/member_gateway_rpc/servlet"
|
||||
)
|
||||
|
||||
func New(configDir string, _config *config.Config) *csgw.Server {
|
||||
func New(_config *config.Config) *csgw.Server {
|
||||
ws := &servlet.WebappServlets{
|
||||
ConfigDir: configDir,
|
||||
VerifyKey: _config.VerifyKey,
|
||||
SignKey: _config.SignKey,
|
||||
}
|
||||
sh := &ServerHandlers{
|
||||
ServerHandlers: *_config.ServerHandler,
|
||||
|
|
|
@ -3,11 +3,9 @@ package servlet
|
|||
import (
|
||||
"crypto/rsa"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path"
|
||||
"sync"
|
||||
|
||||
logging "git.loafle.net/commons/logging-go"
|
||||
"git.loafle.net/commons/logging-go"
|
||||
"git.loafle.net/commons/server-go"
|
||||
"git.loafle.net/commons/server-go/socket"
|
||||
og "git.loafle.net/overflow/gateway"
|
||||
|
@ -15,14 +13,10 @@ import (
|
|||
ogrs "git.loafle.net/overflow/gateway_rpc/servlet"
|
||||
"git.loafle.net/overflow/member_gateway_rpc/subscribe"
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
"github.com/satori/go.uuid"
|
||||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
var (
|
||||
verifyKey *rsa.PublicKey
|
||||
signKey *rsa.PrivateKey
|
||||
)
|
||||
|
||||
type WebappServlet interface {
|
||||
ogrs.RPCServlet
|
||||
|
@ -31,40 +25,17 @@ type WebappServlet interface {
|
|||
type WebappServlets struct {
|
||||
ogrs.RPCServlets
|
||||
|
||||
ConfigDir string
|
||||
VerifyKey *rsa.PublicKey
|
||||
SignKey *rsa.PrivateKey
|
||||
|
||||
connections sync.Map
|
||||
}
|
||||
|
||||
func (s *WebappServlets) absolutePath(fileName string) string {
|
||||
return path.Join(s.ConfigDir, fileName)
|
||||
}
|
||||
|
||||
func (s *WebappServlets) Init(serverCtx server.ServerCtx) error {
|
||||
if err := s.RPCServlets.Init(serverCtx); nil != err {
|
||||
return err
|
||||
}
|
||||
|
||||
signBytes, err := ioutil.ReadFile(s.absolutePath("overFlow-private.key"))
|
||||
if nil != err {
|
||||
return err
|
||||
}
|
||||
|
||||
signKey, err = jwt.ParseRSAPrivateKeyFromPEM(signBytes)
|
||||
if nil != err {
|
||||
return err
|
||||
}
|
||||
|
||||
verifyBytes, err := ioutil.ReadFile(s.absolutePath("overFlow-public.pem"))
|
||||
if nil != err {
|
||||
return err
|
||||
}
|
||||
|
||||
verifyKey, err = jwt.ParseRSAPublicKeyFromPEM(verifyBytes)
|
||||
if nil != err {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -105,7 +76,7 @@ func (s *WebappServlets) Handshake(servletCtx server.ServletCtx, ctx *fasthttp.R
|
|||
return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"])
|
||||
}
|
||||
// hmacSampleSecret is a []byte containing your secret, e.g. []byte("my_secret_key")
|
||||
return verifyKey, nil
|
||||
return s.VerifyKey, nil
|
||||
})
|
||||
|
||||
if nil != err {
|
||||
|
@ -121,7 +92,7 @@ func (s *WebappServlets) Handshake(servletCtx server.ServletCtx, ctx *fasthttp.R
|
|||
sessionID := uuid.NewV4().String()
|
||||
|
||||
servletCtx.SetAttribute(og.SessionIDKey, sessionID)
|
||||
servletCtx.SetAttribute(og.SessionClientTypeKey, ogs.MEMBER)
|
||||
servletCtx.SetAttribute(og.SessionClientTypeKey, og.MEMBER)
|
||||
servletCtx.SetAttribute(og.SessionTargetIDKey, userEmail)
|
||||
|
||||
return nil, nil
|
||||
|
|
Loading…
Reference in New Issue
Block a user