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

Commit

Permalink
Merge pull request #251 from findy-network/repare-move-translator-fin…
Browse files Browse the repository at this point in the history
…dy-agent

Repair Translator transfer to Agency
  • Loading branch information
lainio authored Apr 8, 2024
2 parents c3b0be2 + fc39c3f commit 423f806
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
7 changes: 4 additions & 3 deletions acator/grpcenclave/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var (
// TODO: dart playground
// cert = flag.String("cert", "../../../scripts/test-cert/", "TLS cert path")

cert = flag.String("cert", "../../../../findy-agent/grpc/cert", "pki cert path")
cmd = flag.String("cmd", "login", "FIDO2 cmd: login/register")
user = flag.String("user", "elli", "test user name")
serverAddr = flag.String("addr", "localhost", "agency host gRPC address")
Expand Down Expand Up @@ -53,12 +54,12 @@ func main() {
flag.Parse()
glog.CopyStandardLogTo("ERROR")

conn = try.To1(rpcclient.New(*serverAddr, *port))
defer conn.Close()

ctx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

conn = try.To1(rpcclient.New(*cert, *serverAddr, *port))
defer conn.Close()

statusCh := try.To1(rpcclient.DoEnter(conn, ctx, &pb.Cmd{
Type: pb.Cmd_Type(pb.Cmd_Type_value[strings.ToUpper(*cmd)]),
UserName: *user,
Expand Down
9 changes: 7 additions & 2 deletions acator/grpcenclave/rpcclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ import (
"google.golang.org/grpc"
)

func New(addr string, port int) (conn *grpc.ClientConn, err error) {
func New(cert, addr string, port int) (conn *grpc.ClientConn, err error) {
defer err2.Handle(&err)

cfg := client.BuildInsecureClientConnBase(addr, port, nil)
var cfg *rpc.ClientCfg
if cert == "" {
cfg = client.BuildInsecureClientConnBase(addr, port, nil)
} else {
cfg = client.BuildClientConnBase(cert, addr, port, nil)
}
return rpc.ClientConn(*cfg)
}

Expand Down
29 changes: 23 additions & 6 deletions acator/grpcenclave/rpcserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/findy-network/findy-agent-auth/acator/authn"
"github.com/findy-network/findy-agent-auth/acator/grpcenclave"
pb "github.com/findy-network/findy-common-go/grpc/authn/v1"
"github.com/findy-network/findy-common-go/jwt"
"github.com/findy-network/findy-common-go/rpc"
"github.com/golang/glog"
"github.com/lainio/err2"
Expand All @@ -17,26 +18,42 @@ import (
"google.golang.org/grpc"
)

func RegisterAuthnServer(s *grpc.Server) error {
pb.RegisterAuthnServiceServer(s, &authnServer{})
glog.V(1).Infoln("GRPC registration for authnServer")
return nil
}

func Serve(port int) {
rpc.Serve(&rpc.ServerCfg{
NoAuthorization: true,

Port: port,
Register: func(s *grpc.Server) error {
pb.RegisterAuthnServiceServer(s, &authnServer{})
glog.V(10).Infoln("GRPC registration all done")
return nil
},
Port: port,
Register: RegisterAuthnServer,
})
}

type authnServer struct {
pb.UnimplementedAuthnServiceServer
atomic.Int64

root string

authnCmd *authn.Cmd
}

func (a *authnServer) AuthFuncOverride(
ctx context.Context,
fullMethodName string,
) (
context.Context,
error,
) {
glog.V(1).Infoln("======== AuthFuncOverride", fullMethodName)
// let's set some user name for future use, etc.
return jwt.NewContextWithUser(ctx, a.root), nil
}

func (a *authnServer) Enter(
cmd *pb.Cmd,
server pb.AuthnService_EnterServer,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
toolchain go1.21.0

require (
github.com/findy-network/findy-common-go v0.2.69
github.com/findy-network/findy-common-go v0.2.70-0.20240408093930-fea7b4cd528d
github.com/fxamacker/cbor/v2 v2.6.0
github.com/go-webauthn/webauthn v0.10.2
github.com/golang/glog v1.2.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/findy-network/findy-common-go v0.2.69 h1:4Qie4pxSGmMCodthzmeXrw4FnbTYKp/xNu8RK6R6Hi0=
github.com/findy-network/findy-common-go v0.2.69/go.mod h1:t8sVeRI7iNeUHDOdjjHv8DXwBLEp+K+Wvy6HzdC7F6c=
github.com/findy-network/findy-common-go v0.2.70-0.20240408093930-fea7b4cd528d h1:vNacVI0NVy9ufWIHgsGfLcS7YqMBCiY50ERY3IKw1xg=
github.com/findy-network/findy-common-go v0.2.70-0.20240408093930-fea7b4cd528d/go.mod h1:t8sVeRI7iNeUHDOdjjHv8DXwBLEp+K+Wvy6HzdC7F6c=
github.com/form3tech-oss/jwt-go v3.2.5+incompatible h1:/l4kBbb4/vGSsdtB5nUe8L7B9mImVMaBPw9L/0TBHU8=
github.com/form3tech-oss/jwt-go v3.2.5+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
Expand Down

0 comments on commit 423f806

Please sign in to comment.