Last active
January 20, 2022 09:04
-
-
Save tfrench/c3f27cf2aacbee5d04e8278aed8c08b2 to your computer and use it in GitHub Desktop.
Server code for using SSL and server-side authentication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
Thanks. Good catch - updated.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note line 4 is missing closing the string literal for the 'open' mode; it should be: