Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In python grpc I got a exception “No match found for server name”

Tags:

python

grpc

I create key with this command:

openssl req -newkey rsa:2048 -nodes -keyout server.key -x509 -days 365 -out server.crt

My server code:

server_credentials = grpc.ssl_server_credentials(((_private_key, _certificate_chain,),))

server = grpc.server(futures.ThreadPoolExecutor(max_workers=MAX_THREADPOOL_EXECUTOR))
server.add_secure_port('[::]:{0}'.format(AGENT_PORT), server_credentials)
server.add_insecure_port('[::]:{0}'.format(AGENT_PORT))

print("AgentServicer start at port {}...".format(AGENT_PORT))
server.start()
try:
    while True:
        # we can do something in main thread......
        time.sleep(_ONE_DAY_IN_SECONDS)
except KeyboardInterrupt:
    server.stop(0)

My client code:

credentials = grpc.ssl_channel_credentials(root_certificates=_certificate_chain)
channel = grpc.secure_channel('{}:{}'.format("localhost", 10010), credentials)

# channel = grpc.insecure_channel('{}:{}'.format("localhost", 10010))
stub = agent_pb2_grpc.AgentStub(channel)
response = stub.GetAgentVersion(agent_pb2.NoParams())
print("GreeterService client received: " + response.version)

I get an exception:

No match found for server name

What am I doing wrong?

like image 753
Jie Zhang Avatar asked Jun 29 '17 02:06

Jie Zhang


1 Answers

I suspect that your server certificate does not have CN=localhost which you are trying to connect from your client. In that case, you need to either create your server certificate to include such Common Name, or from your client you need to connect to the name that exist in your certificate.

like image 152
Ulas Keles Avatar answered Oct 17 '22 22:10

Ulas Keles