You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 3.5 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # Encryption
  2. The example for encryption includes two individual examples for TLS and ALTS
  3. encryption mechanism respectively.
  4. ## Try it
  5. In each example's subdirectory:
  6. ```
  7. go run server/main.go
  8. ```
  9. ```
  10. go run client/main.go
  11. ```
  12. ## Explanation
  13. ### TLS
  14. TLS is a commonly used cryptographic protocol to provide end-to-end
  15. communication security. In the example, we show how to set up a server
  16. authenticated TLS connection to transmit RPC.
  17. In our `grpc/credentials` package, we provide several convenience methods to
  18. create grpc
  19. [`credentials.TransportCredentials`](https://godoc.org/google.golang.org/grpc/credentials#TransportCredentials)
  20. base on TLS. Refer to the
  21. [godoc](https://godoc.org/google.golang.org/grpc/credentials) for details.
  22. In our example, we use the public/private keys created ahead:
  23. * "server1.pem" contains the server certificate (public key).
  24. * "server1.key" contains the server private key.
  25. * "ca.pem" contains the certificate (certificate authority)
  26. that can verify the server's certificate.
  27. On server side, we provide the paths to "server1.pem" and "server1.key" to
  28. configure TLS and create the server credential using
  29. [`credentials.NewServerTLSFromFile`](https://godoc.org/google.golang.org/grpc/credentials#NewServerTLSFromFile).
  30. On client side, we provide the path to the "ca.pem" to configure TLS and create
  31. the client credential using
  32. [`credentials.NewClientTLSFromFile`](https://godoc.org/google.golang.org/grpc/credentials#NewClientTLSFromFile).
  33. Note that we override the server name with "x.test.youtube.com", as the server
  34. certificate is valid for *.test.youtube.com but not localhost. It is solely for
  35. the convenience of making an example.
  36. Once the credentials have been created at both sides, we can start the server
  37. with the just created server credential (by calling
  38. [`grpc.Creds`](https://godoc.org/google.golang.org/grpc#Creds)) and let client dial
  39. to the server with the created client credential (by calling
  40. [`grpc.WithTransportCredentials`](https://godoc.org/google.golang.org/grpc#WithTransportCredentials))
  41. And finally we make an RPC call over the created `grpc.ClientConn` to test the secure
  42. connection based upon TLS is successfully up.
  43. ### ALTS
  44. ALTS is the Google's Application Layer Transport Security, which supports mutual
  45. authentication and transport encryption. Note that ALTS is currently only
  46. supported on Google Cloud Platform, and therefore you can only run the example
  47. successfully in a GCP environment. In our example, we show how to initiate a
  48. secure connection that is based on ALTS.
  49. Unlike TLS, ALTS makes certificate/key management transparent to user. So it is
  50. easier to set up.
  51. On server side, first call
  52. [`alts.DefaultServerOptions`](https://godoc.org/google.golang.org/grpc/credentials/alts#DefaultServerOptions)
  53. to get the configuration for alts and then provide the configuration to
  54. [`alts.NewServerCreds`](https://godoc.org/google.golang.org/grpc/credentials/alts#NewServerCreds)
  55. to create the server credential based upon alts.
  56. On client side, first call
  57. [`alts.DefaultClientOptions`](https://godoc.org/google.golang.org/grpc/credentials/alts#DefaultClientOptions)
  58. to get the configuration for alts and then provide the configuration to
  59. [`alts.NewClientCreds`](https://godoc.org/google.golang.org/grpc/credentials/alts#NewClientCreds)
  60. to create the client credential based upon alts.
  61. Next, same as TLS, start the server with the server credential and let client
  62. dial to server with the client credential.
  63. Finally, make an RPC to test the secure connection based upon ALTS is
  64. successfully up.