0

Using protoc, in golang in my case, the generated server files are not bound to a TLS certificate and key that I have created. In fact I had to instantiate the grpc server using this approach:

creds, _ := credentials.NewServerTLSFromFile("server.crt", "server.key")
s := grpc.NewServer(grpc.Creds(creds))
s.Serve(listener)

and because this code is not the generated one, I need to use the above to register my service descriptor and handler:

s.RegisterService(&_My_serviceDesc, &handler.MailServer{})

The original generated _My_serviceDesc variable is in the generated package, therefore inaccessible from my main package, so I had to define it in mythemain package where I am starting the server above. Also, this same variable references a handler defined with an underscore _My_Handler which I also had to redefine in the main package.

I chacked the protoc documentation and help and there seems to be no way to do this otherwise. I wonder why it is not possible to associate it to the certificates that I need. This seems very odd...

gextra
  • 8,439
  • 8
  • 40
  • 62

1 Answers1

0

TLS config is done on the gRPC server (when calling grpc.NewServer). You can register service on the created server as normal.

See the TLS example here: https://github.com/grpc/grpc-go/tree/master/examples/features/encryption

menghanl
  • 751
  • 6
  • 7
  • my point was that the protoc code generator does little or no effort to produce server code that can be easily applied to specific certificates. By default it operates on root certs and the additional options require to considerably modify the generated server code – gextra Jun 30 '20 at 04:52