crypto support

This commit is contained in:
Eugene K
2020-02-26 14:49:51 -05:00
parent fbfcc76983
commit f8a3a4cc26
8 changed files with 34 additions and 10 deletions
@@ -53,7 +53,8 @@ func (i *SessionApiPost) ToModel(rc *response.RequestContext) *model.Session {
type NewSession struct {
*SessionApiList
Token string `json:"token"`
Token string `json:"token"`
Pubkey string `json:"pubkey"`
}
type SessionApiList struct {
@@ -165,6 +165,7 @@ func (nsr *SessionRequestResponder) RespondWithCreatedId(id string, link *respon
newSession := &NewSession{
SessionApiList: apiSession,
Token: modelSession.Token,
Pubkey: modelSession.PubKey,
}
nsr.RespondWithCreated(newSession, nil, link)
}
+15 -1
View File
@@ -69,9 +69,23 @@ func (handler *SessionHandler) ReadForIdentity(id string, identityId string) (*S
func (handler *SessionHandler) Read(id string) (*Session, error) {
entity := &Session{}
if err := handler.readEntity(id, entity); err != nil {
err := handler.GetDb().View(func(tx *bbolt.Tx) error {
if err := handler.readEntityInTx(tx, id, entity); err != nil {
return err
}
serv, err := handler.env.GetStores().EdgeService.LoadOneById(tx, entity.ServiceId)
if err != nil {
return err
}
entity.PubKey = serv.PubKey
return nil
})
if err != nil {
return nil, err
}
return entity, nil
}
+1
View File
@@ -36,6 +36,7 @@ type Session struct {
ApiSessionId string
ServiceId string
Type string
PubKey string
SessionCerts []*SessionCert
}
@@ -18,6 +18,7 @@ package persistence
import (
"crypto/rand"
"encoding/base64"
"fmt"
"testing"
"time"
@@ -230,8 +231,9 @@ func (ctx *TestContext) testUpdateServices(_ *testing.T) {
service.Binding = uuid.New().String()
service.EndpointAddress = uuid.New().String()
service.Egress = uuid.New().String()
service.PubKey = make([]byte, 32)
rand.Read(service.PubKey)
pk := make([]byte, 32)
rand.Read(pk)
service.PubKey = base64.StdEncoding.EncodeToString(pk)
service.UpdatedAt = earlier
service.CreatedAt = now
service.Tags = tags
+3 -2
View File
@@ -51,8 +51,7 @@ func (dialer *dialer) Dial(destination string, sessionId *identity.TokenId, addr
}
token := destParts[1]
log.Error("key", string(sessionId.Data[0xED6E]))
log.Debug("looking up hosted service conn", len(sessionId.Data))
listenConn, found := dialer.factory.hostedServices.Get(token)
if !found {
@@ -61,6 +60,8 @@ func (dialer *dialer) Dial(destination string, sessionId *identity.TokenId, addr
log.Debug("dialing sdk client hosting service")
dialRequest := edge.NewDialMsg(listenConn.Id(), token)
dialRequest.Headers[edge.PublicKeyHeader] = sessionId.Data[edge.PublicKeyHeader]
reply, err := listenConn.SendAndWaitWithTimeout(dialRequest, 5*time.Second)
if err != nil {
return err
+7 -4
View File
@@ -17,6 +17,7 @@
package xgress_edge
import (
"encoding/base64"
"fmt"
"github.com/michaelquigley/pfxlog"
"github.com/netfoundry/ziti-edge/gateway/internal/fabric"
@@ -152,9 +153,9 @@ func (proxy *ingressProxy) processConnect(req *channel2.Message, ch channel2.Cha
// fabric connect
log.Debug("dialing fabric")
hints := make(map[uint32][]byte)
hints[0xED6E] = []byte("this be the key")
sessionInfo, err := xgress.GetSession(proxy.listener.factory, ns.Token, ns.Service.Id, hints)
peerData := make(map[uint32][]byte)
peerData[edge.PublicKeyHeader] = req.Headers[edge.PublicKeyHeader]
sessionInfo, err := xgress.GetSession(proxy.listener.factory, ns.Token, ns.Service.Id, peerData)
if err != nil {
log.Warn("failed to dial fabric ", err)
proxy.sendStateClosedReply(err.Error(), req)
@@ -176,6 +177,8 @@ func (proxy *ingressProxy) processConnect(req *channel2.Message, ch channel2.Cha
func (proxy *ingressProxy) processBind(req *channel2.Message, ch channel2.Channel) {
token := string(req.Body)
pubKey := req.Headers[edge.PublicKeyHeader]
pubKeyStr := base64.StdEncoding.EncodeToString(pubKey)
log := pfxlog.ContextLogger(ch.Label()).WithField("sessionId", token).WithFields(edge.GetLoggerFields(req))
connId, found := req.GetUint32Header(edge.ConnIdHeader)
if !found {
@@ -202,7 +205,7 @@ func (proxy *ingressProxy) processBind(req *channel2.Message, ch channel2.Channe
}
log.Debug("binding service")
if err := xgress.BindService(proxy.listener.factory, token, ns.Service.Id, pubKey); err != nil {
if err := xgress.BindService(proxy.listener.factory, token, ns.Service.Id, pubKeyStr); err != nil {
proxy.sendStateClosedReply(err.Error(), req)
return
}
+1
View File
@@ -253,6 +253,7 @@ golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
golang.org/x/crypto v0.0.0-20191112222119-e1110fd1c708 h1:pXVtWnwHkrWD9ru3sDxY/qFK/bfc0egRovX91EjWjf4=
golang.org/x/crypto v0.0.0-20191112222119-e1110fd1c708/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72 h1:+ELyKg6m8UBf0nPFSqD0mi7zUfwPyXo23HNjMnXPz7w=
golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=