1Hello World Example with TLS 2============================================== 3 4The example require grpc-java to already be built. You are strongly encouraged 5to **check out a git release tag**, since there will already be a build of grpc 6available: 7``` 8git checkout v<major>.<minor>.<patch> 9``` 10 11Otherwise you must follow [COMPILING](../COMPILING.md). 12 13To build the example, 14 151. **[Install gRPC Java library SNAPSHOT locally, including code generation plugin](../../COMPILING.md) (Only need this step for non-released versions, e.g. master HEAD).** 16 172. Run in this directory: 18``` 19$ ../gradlew installDist 20``` 21 22This creates the scripts `hello-world-tls-server`, `hello-world-tls-client`, 23in the 24`build/install/example-tls/bin/` directory that run the example. The 25example requires the server to be running before starting the client. 26 27Running the hello world with TLS is the same as the normal hello world, but takes additional args: 28 29**hello-world-tls-server**: 30 31```text 32USAGE: HelloWorldServerTls port certChainFilePath privateKeyFilePath [trustCertCollectionFilePath] 33 Note: You only need to supply trustCertCollectionFilePath if you want to enable Mutual TLS. 34``` 35 36**hello-world-tls-client**: 37 38```text 39USAGE: HelloWorldClientTls host port [trustCertCollectionFilePath [clientCertChainFilePath clientPrivateKeyFilePath]] 40 Note: clientCertChainFilePath and clientPrivateKeyFilePath are only needed if mutual auth is desired. 41``` 42- Note `trustCertCollectionFilePath` is not needed if you are using system default certificate authority. 43 44You can run this example with our [test credentials](../../testing/src/main/resources/certs) with 45`.overrideAuthority("foo.test.google.fr")` for `ManagedChannelBuilder` to match the Subject Alternative Names 46in the test certificates. You can generate your own self-signed certificates with commands in the test certs 47[README](../../testing/src/main/resources/certs/README). 48 49- Note you can use system default certificate authority if you are using a real server certificate. 50 51#### Hello world example with TLS (no mutual auth): 52 53```bash 54# Run the server: 55./build/install/example-tls/bin/hello-world-tls-server 50440 ../../testing/src/main/resources/certs/server1.pem ../../testing/src/main/resources/certs/server1.key 56# In another terminal run the client 57./build/install/example-tls/bin/hello-world-tls-client localhost 50440 ../../testing/src/main/resources/certs/ca.pem 58``` 59 60#### Hello world example with TLS with mutual auth: 61 62```bash 63# Run the server: 64./build/install/example-tls/bin/hello-world-tls-server 50440 ../../testing/src/main/resources/certs/server1.pem ../../testing/src/main/resources/certs/server1.key ../../testing/src/main/resources/certs/ca.pem 65# In another terminal run the client 66./build/install/example-tls/bin/hello-world-tls-client localhost 50440 ../../testing/src/main/resources/certs/ca.pem ../../testing/src/main/resources/certs/client.pem ../../testing/src/main/resources/certs/client.key 67``` 68 69That's it! 70 71## Maven 72 73If you prefer to use Maven: 74 751. **[Install gRPC Java library SNAPSHOT locally, including code generation plugin](../../COMPILING.md) (Only need this step for non-released versions, e.g. master HEAD).** 76 772. Run in this directory: 78``` 79$ mvn verify 80$ # Run the server 81$ mvn exec:java -Dexec.mainClass=io.grpc.examples.helloworldtls.HelloWorldServerTls -Dexec.args="50440 ../../testing/src/main/resources/certs/server1.pem ../../testing/src/main/resources/certs/server1.key" 82$ # In another terminal run the client 83$ mvn exec:java -Dexec.mainClass=io.grpc.examples.helloworldtls.HelloWorldClientTls -Dexec.args="localhost 50440 ../../testing/src/main/resources/certs/ca.pem" 84``` 85 86## Bazel 87 88If you prefer to use Bazel: 89``` 90$ bazel build :hello-world-tls-server :hello-world-tls-client 91$ # Run the server 92$ ../bazel-bin/hello-world-tls-server 50440 ../../testing/src/main/resources/certs/server1.pem ../../testing/src/main/resources/certs/server1.key 93$ # In another terminal run the client 94$ ../bazel-bin/hello-world-tls-client localhost 50440 ../../testing/src/main/resources/certs/ca.pem 95``` 96