-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
36 changed files
with
386 additions
and
52 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
## Run Example | ||
|
||
1. Generate certificates: | ||
|
||
```shell | ||
openssl genpkey -algorithm RSA -out ca.key | ||
openssl req -new -key ca.key -out ca.csr | ||
openssl x509 -req -in ca.csr -signkey ca.key -out ca.crt | ||
|
||
openssl genpkey -algorithm RSA -out server.key | ||
openssl req -new -key server.key -out server.csr | ||
|
||
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -out server.crt | ||
``` | ||
|
||
2. Run tests |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
plugins { | ||
id 'org.springframework.boot' | ||
} | ||
|
||
dependencies { | ||
implementation(project(":grpc-starters:grpc-boot-starter")) | ||
implementation("io.grpc:grpc-testing-proto") | ||
|
||
testImplementation(project(":grpc-starters:grpc-starter-test")) | ||
} | ||
|
||
apply from: "${rootDir}/gradle/protobuf-with-pgv.gradle" | ||
|
17 changes: 17 additions & 0 deletions
17
examples/tls/src/main/java/com/freemanan/example/TLSApp.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.freemanan.example; | ||
|
||
import com.freemanan.starter.grpc.client.EnableGrpcClients; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
/** | ||
* @author Freeman | ||
*/ | ||
@SpringBootApplication | ||
@EnableGrpcClients({"io.grpc"}) | ||
public class TLSApp { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(TLSApp.class, args); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
examples/tls/src/main/java/com/freemanan/example/controller/SimpleServiceController.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.freemanan.example.controller; | ||
|
||
import io.grpc.stub.StreamObserver; | ||
import io.grpc.testing.protobuf.SimpleRequest; | ||
import io.grpc.testing.protobuf.SimpleResponse; | ||
import io.grpc.testing.protobuf.SimpleServiceGrpc; | ||
import org.springframework.stereotype.Controller; | ||
|
||
/** | ||
* @author Freeman | ||
*/ | ||
@Controller | ||
public class SimpleServiceController extends SimpleServiceGrpc.SimpleServiceImplBase { | ||
|
||
@Override | ||
public void unaryRpc(SimpleRequest request, StreamObserver<SimpleResponse> responseObserver) { | ||
SimpleResponse response = SimpleResponse.newBuilder() | ||
.setResponseMessage("Hi, I got your message: " + request.getRequestMessage()) | ||
.build(); | ||
responseObserver.onNext(response); | ||
responseObserver.onCompleted(); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
grpc: | ||
server: | ||
reflection: | ||
enabled: true | ||
tls: | ||
key-manager: | ||
cert-chain: classpath:server.crt | ||
private-key: classpath:server.key | ||
client: | ||
authority: localhost:${grpc.server.port:9090} | ||
tls: | ||
trust-manager: | ||
root-certs: classpath:ca.crt |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIDOTCCAiECFCq3XQnKaNcPpk6aK5ZevTj/wuTiMA0GCSqGSIb3DQEBCwUAMFkx | ||
CzAJBgNVBAYTAkNOMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRl | ||
cm5ldCBXaWRnaXRzIFB0eSBMdGQxEjAQBgNVBAMMCWxvY2FsaG9zdDAeFw0yMzA5 | ||
MjkwNzEwMDRaFw0yMzEwMjkwNzEwMDRaMFkxCzAJBgNVBAYTAkNOMRMwEQYDVQQI | ||
DApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQx | ||
EjAQBgNVBAMMCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC | ||
ggEBALIl80v24VGL5hfPjqe+AFeHRH9PaqIYygQlvlBkROfkg6UjBn4h/sr/bxNJ | ||
NpdV1b2k/T5eyIgHFBKwd/LRcw4v15XCrCRcoJGdIctbKWRetA77C4Gx9c145BWE | ||
gidgU3KawRfjwngbrezE6+SZlGFKRZER1o7/wSebyonQ1rO8cJqwdZOvsBgmhP59 | ||
d9banrHgB9gq7wTRmmZSHxEcXqUQ+9SJRmsM7hKTIZuGtcZ8YaJMBS36LWGNvxY7 | ||
PO+UzybhgtIXZGccrUx4B8qr10F7Y7hgcrumoPAwu9IyvSvQvRqn8II3xeCTGb6h | ||
uuJo40cSaTSTZBe5ucTWt/qX+2MCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAHmZt | ||
Wr6h3qBvUgaUbx/V7GLBXI+/8C8u0wEV17Ech6kzZMzbvSbVlOwnEYyyre7KgNKa | ||
OWuzTKrtNNu7TDmnXaQiT2mckCiNokcy+dVuYEfSpKOZrRA8zxYU1DczwHBjmNAY | ||
ZfopcFQIjXAjyZljBfx9+liq0r+TFvAOug9CPzCWYUopegqvuN2t2hM77getFm6U | ||
NK4Ds0OGalVZXFjEkQ5wzsUcVAaEWVnjESEtgeYhit4NqCbMOZuPhp5CNCEhogDC | ||
sUZLOcZhT0BReGbjP7iWEsMXzhT+oniHfQY1HmYnfooyD/5SDtbBUKM0Dnxpk366 | ||
H5Yd+n9LKMOR9CWU7A== | ||
-----END CERTIFICATE----- |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIDOTCCAiECFGXI9CSDVWVjt698kfJAdtvT+RX9MA0GCSqGSIb3DQEBCwUAMFkx | ||
CzAJBgNVBAYTAkNOMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRl | ||
cm5ldCBXaWRnaXRzIFB0eSBMdGQxEjAQBgNVBAMMCWxvY2FsaG9zdDAeFw0yMzA5 | ||
MjkwNzEwNTBaFw0yMzEwMjkwNzEwNTBaMFkxCzAJBgNVBAYTAkNOMRMwEQYDVQQI | ||
DApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQx | ||
EjAQBgNVBAMMCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC | ||
ggEBAKRtx94G7wD3O8SZT1fMJO9+BLyNAa1noLH0RxLwprrV8MxEB+sgKm4EvfRW | ||
ewDXv0k0Ofs1b6o20JiCIWRqDrfZmCAx6fWNZ23/rh1Ywc4PGFB9kOwbMQmhAf8b | ||
Q4LTBqR+pISR6O/yg0ModshgOwodCLxI5FgxG6EWFhQMZv0pdvFIqFlSjbw9EHQc | ||
EaO+ovwahux5NyWvufPp6ATWthcwgaNSD+8AVpdPgxfAjSZNTgsoHJldT7iyuMNA | ||
7bQnBzogS2r2f1smnRH91zLRzM2UG5g3EvaEje+OWGp+QFymFYhlXY6BmBSXX3Sb | ||
xE3SOQTEMHARz2iosqFRrChcFR8CAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAc05G | ||
5pCr37ZFLWYqi/NTyHfcpO7LdLJGmtSTFxn3jzRnvUFeWnxf6PWl/o7RFOHtJE5b | ||
YGNgrBE33wMRf9RKzKMLUUsX8y2QmfSdlZ2TJPiWtFd5Mqb4lYCZIe4btuYVkNId | ||
vcx1cYwEgyXcsIbumh/GnzKo5iW2/x+3vxlW5VhylgO6N8xy4/OHiRIq7EzqRPAM | ||
YicDd2fPxeenVRezlsXGaLQ161TPI+AHXMe8uXICu5Z9F40juGikstMz/lgPLIxz | ||
5J19nUwXLBM5qHQbpYeMFvB2lA+6NEGHdDYB8swqPNQK+ginhabsYXyLYUC8zPoa | ||
eIB21mo5Gav/1z80hQ== | ||
-----END CERTIFICATE----- |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCkbcfeBu8A9zvE | ||
mU9XzCTvfgS8jQGtZ6Cx9EcS8Ka61fDMRAfrICpuBL30VnsA179JNDn7NW+qNtC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| ||
tz+IzqJbWk+Rbymq4h5nVIYnWTuNoLedzMOeY3csvHRA8s2m28qIEfdRsZZEss+C | ||
0yW29jDWAWtk9ZC74APHN8FbFkgiZSVcYdqDYkFRIeN4qi7+aEoJLfrvAoGAGPvW | ||
bkgCULyftJ1vYX+oyPbCtpduFYcQCACTn4PoGLjNxxHgDNOt5q72yFckxzMu71RT | ||
fhy6S2aqvpIqgRqNztji1LXrqOzSRTiRJv25v8SFtFtwDhm0rSvUtksMQLdL79OF | ||
b4W4yiI6IJgM30e/cnu5fXZGG+fBs4EkMWqQ5HECgYBLmGwa9I1UnbHncieCBEDU | ||
xyiydebDHFX+ZP5ecTU+5Ob5IBso1bWnsoOo/N5Gb86YX3W/TmECnE0yOz2RtPR+ | ||
1qzSb1s/IurcHpPNU4JMakiLRyeVX0SfResJcbFkbfwvvg02d03cBPHBYZ/8WSH4 | ||
bkF/XFMlYZZl/C8qNGsKOQ== | ||
-----END PRIVATE KEY----- |
29 changes: 29 additions & 0 deletions
29
examples/tls/src/test/java/com/freemanan/example/TLSAppTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.freemanan.example; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import io.grpc.testing.protobuf.SimpleRequest; | ||
import io.grpc.testing.protobuf.SimpleServiceGrpc; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@SpringBootTest( | ||
properties = { | ||
"grpc.test.enabled=false", | ||
"grpc.server.port=12345", | ||
"grpc.client.authority=localhost:12345", | ||
}) | ||
class TLSAppTest { | ||
|
||
@Autowired | ||
SimpleServiceGrpc.SimpleServiceBlockingStub simpleServiceBlockingStub; | ||
|
||
@Test | ||
void testUnaryRpc() { | ||
String responseMessage = simpleServiceBlockingStub | ||
.unaryRpc(SimpleRequest.newBuilder().setRequestMessage("Hello").build()) | ||
.getResponseMessage(); | ||
assertThat(responseMessage).isEqualTo("Hi, I got your message: Hello"); | ||
} | ||
} |
This file contains 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
File renamed without changes.
File renamed without changes.
This file contains 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
This file contains 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
Oops, something went wrong.