Skip to content

Instantly share code, notes, and snippets.

@tfrench
Last active January 20, 2022 09:04
Show Gist options
  • Save tfrench/c3f27cf2aacbee5d04e8278aed8c08b2 to your computer and use it in GitHub Desktop.
Save tfrench/c3f27cf2aacbee5d04e8278aed8c08b2 to your computer and use it in GitHub Desktop.
Server code for using SSL and server-side authentication
# read in key and certificate
with open('server.key', 'rb') as f:
private_key = f.read()
with open('server.crt', 'rb') as f:
certificate_chain = f.read()
# create server credentials
server_credentials = grpc.ssl_server_credentials(
((private_key, certificate_chain,),))
# create server
server = grpc.server(futures.ThreadPoolExecutor(max_workers=1))
service_pb2_grpc.add_ServerServicer_to_server(ServerServicer(), server)
# add secure port using crendentials
server.add_secure_port('[::]:'+port, server_credentials)
@thiagorobert
Copy link

Note line 4 is missing closing the string literal for the 'open' mode; it should be:

with open('server.crt', 'rb') as f:

@tfrench
Copy link
Author

tfrench commented Jan 11, 2022

Thanks. Good catch - updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment