baerwang opened a new issue #371:
URL: https://github.com/apache/dubbo-go-pixiu/issues/371
i use openssl cerate certificates ,test example error authentication
handshake failed
```go
func main() {
l, err := net.Listen("tcp", ":50001") //nolint:gosec
if err != nil {
panic(err)
}
s := &server{users: make(map[int32]*proto.User)}
initUsers(s)
creds, err := credentials.NewServerTLSFromFile(
"/Users/baerwang/Downloads/server.pem",
"/Users/baerwang/Downloads/server.key")
if err != nil {
panic(err)
}
gs := grpc.NewServer(grpc.Creds(creds))
proto.RegisterUserProviderServer(gs, s)
logger.Info("grpc test server is now running...")
err = gs.Serve(l)
if err != nil {
panic(err)
}
}
```
```go
var (
addr = flag.String("addr", "localhost:8881", "the address to connect
to")
)
func TestGet(t *testing.T) {
flag.Parse()
b, err := ioutil.ReadFile("/Users/baerwang/Downloads/server.pem")
if err != nil {
t.Fatal(err)
}
cp := x509.NewCertPool()
if !cp.AppendCertsFromPEM(b) {
t.Fatal(err)
}
certs := credentials.NewClientTLSFromCert(cp, "192.168.1.6")
// Set up a connection to the server.
conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(certs))
if err != nil {
log.Fatalf("did not connect: %v", err)
}
defer conn.Close()
c := pb.NewUserProviderClient(conn)
// Contact the server and print out its response.
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
r, err := c.GetUser(ctx, &pb.GetUserRequest{UserId: 1})
assert.NoError(t, err)
assert.Equal(t, "user(s) query successfully", r.Message)
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]