Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Commit

Permalink
multi-tenant grpcenclave
Browse files Browse the repository at this point in the history
  • Loading branch information
lainio committed Apr 14, 2024
1 parent 71fe988 commit b7ec660
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions acator/grpcenclave/rpcserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import (
)

func RegisterAuthnServer(s *grpc.Server) error {
pb.RegisterAuthnServiceServer(s, &authnServer{})
authnServ := &authnServer{authnCmd: make(map[int64]*authn.Cmd, 128)}
pb.RegisterAuthnServiceServer(s, authnServ)
glog.V(1).Infoln("GRPC registration for authnServer")
return nil
}
Expand All @@ -39,7 +40,7 @@ type authnServer struct {

root string

authnCmd *authn.Cmd
authnCmd map[int64]*authn.Cmd
}

func (a *authnServer) AuthFuncOverride(
Expand Down Expand Up @@ -73,10 +74,10 @@ func (a *authnServer) Enter(
// NOTE. Authentication is done by mutual TLS or must be done for this
// service!

glog.V(3).Infoln("=== authn Enter cmd:", cmd.Type)
cmdID := a.Add(1)
glog.V(3).Infof("=== authn Enter cmd:%v, cmdID: %v", cmd.Type, cmdID)

a.authnCmd = &authn.Cmd{
a.authnCmd[cmdID] = &authn.Cmd{
SubCmd: strings.ToLower(cmd.GetType().String()),
UserName: cmd.GetUserName(),
PublicDIDSeed: cmd.GetPublicDIDSeed(),
Expand All @@ -92,7 +93,7 @@ func (a *authnServer) Enter(
OutChan: make(chan *pb.CmdStatus),
InChan: make(chan *pb.SecretMsg),
}
a.authnCmd.SecEnclave = secEnc
a.authnCmd[cmdID].SecEnclave = secEnc

go func() {
defer err2.Catch(err2.Err(func(err error) {
Expand All @@ -108,7 +109,7 @@ func (a *authnServer) Enter(
}
close(secEnc.OutChan)
}))
r := try.To1(a.authnCmd.Exec(nil))
r := try.To1(a.authnCmd[cmdID].Exec(nil))
secEnc.OutChan <- &pb.CmdStatus{
CmdID: cmdID,
Type: pb.CmdStatus_READY_OK,
Expand All @@ -123,10 +124,12 @@ func (a *authnServer) Enter(
}()

for status := range secEnc.OutChan {
glog.V(1).Infoln("<== status:", status.CmdType, status.CmdID)
glog.V(3).Infoln("<== status:", status.CmdType, status.CmdID)
try.To(server.Send(status))
}
glog.V(1).Infoln("end Enter\n===============\n\n")
glog.V(3).Infoln("end Enter, delete cmdID:", cmdID, "...")
delete(a.authnCmd, cmdID)
glog.V(3).Infoln("... ", cmdID, " deleted from map")
return nil
}

Expand All @@ -145,8 +148,8 @@ func (a *authnServer) EnterSecret(
return err
})

glog.V(1).Infoln("secret:", smsg.GetType(), smsg.GetCmdID())
secEnc, ok := a.authnCmd.SecEnclave.(*grpcenclave.Enclave)
glog.V(3).Infof("secret type: %v, ID: %v", smsg.GetType(), smsg.GetCmdID())
secEnc, ok := a.authnCmd[smsg.GetCmdID()].SecEnclave.(*grpcenclave.Enclave)
assert.That(ok)
assert.NotNil(secEnc)
assert.CNotNil(secEnc.InChan)
Expand Down

0 comments on commit b7ec660

Please sign in to comment.