Hello,I want use grpc post data to deviceQueue,the following is my code:
the client log:
lp-> any error: rpc error: code = Unavailable desc = all SubConns are in TransientFailure, latest connection error: connection error: desc = "transport: authentication handshake failed: x509: cannot validate certificate for 192.168.1.200 because it doesn’t contain any IP SANs
the server log(docker-compose logs -f appserver):
appserver_1 | 2018/05/15 08:43:37 http: TLS handshake error from 192.168.1.215:52106: remote error: tls: bad certificate
“192.168.1.215” is my client pc’s ip.
“192.168.1.200” is my server pc’s ip.
I think it should have something to do with HTTPS.
=========================code start===========================
package main
import (
“context”
“github.com/brocaar/lora-app-server/api”
“google.golang.org/grpc”
“google.golang.org/grpc/credentials”
“log”
)
const (
RPC_SERVER_ADDRESS = “192.168.1.200:8080”
OpenTLS = true
)
type CustomCredential struct{}
func (c CustomCredential) GetRequestMetadata(ctx context.Context, uri …string) (map[string]string, error) {
return map[string]string{
“authorization”: “eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJsb3JhLWFwcC1zZXJ2ZXIiLCJhdWQiOiJsb3JhLWFwcC1zZXJ2ZXIiLCJuYmYiOjE1MTMwNzE1NjYsImV4cCI6MTU0MzE1Nzk2Niwic3ViIjoidXNlciIsInVzZXJuYW1lIjoiYWRtaW4ifQ.x7aMoKQiqndmU4xDI8SSPLffoeLTjDN4cWxudQQ85ZQ”,
}, nil
}
func (c CustomCredential) RequireTransportSecurity() bool {
return OpenTLS
}
func send2DeviceQueue() {
var opts []grpc.DialOption
if OpenTLS {
creds, err := credentials.NewClientTLSFromFile("../certs/http.pem", "")
if err != nil {
log.Println("lp-> open tls--error:", err)
}
opts = append(opts, grpc.WithTransportCredentials(creds))
} else {
opts = append(opts, grpc.WithInsecure())
}
//opts = append(opts, grpc.WithPerRPCCredentials(new(CustomCredential)))
clientConn, err := grpc.Dial(RPC_SERVER_ADDRESS, opts...)
if err != nil {
log.Fatal("lp-> grpc-conn-error:", err)
}
data := []byte{1, 2, 3, 4, 5, 6}
//defer clientConn.Close()
deviceQueueApi := api.NewDeviceQueueClient(clientConn)
r, err := deviceQueueApi.Enqueue(context.Background(), &api.EnqueueDeviceQueueItemRequest{
DevEUI: "0102030405060708",
Reference: "abcdef",
Confirmed: true,
FPort: 6,
Data: data,
})
if err != nil {
log.Fatalln("lp-> any error:", err)
}
log.Fatalln("lp-> result:", r)
}
func main() {
send2DeviceQueue()
}
=========================code end============================