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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With