-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/#1238-keyalias-support-for-ssl-c…
…ontext' into #1238-keyalias-support-for-ssl-context
- Loading branch information
Showing
14 changed files
with
278 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# SSL/TLS Examples | ||
|
||
|Example|Description| | ||
|---|---| | ||
|[to-backend](to-backend)|How to secure communication from the API Gateway to a backend server.| | ||
|[api-with-tls](api-with-tls)|How to protect APIs deployed on the Gateway| | ||
| Example | Description | | ||
|--------------------------------------------|--------------------------------------------------------------------------| | ||
| [to-backend](to-backend) | How to secure communication from the API Gateway to a backend server. | | ||
| [api-with-tls-pkcs12](api-with-tls-pkcs12) | How to protect APIs deployed on the Gateway with PKCS12 TLS certificates | | ||
| [api-with-tls-pem](api-with-tls-pem) | How to protect APIs deployed on the Gateway with PEM TLS certificates | |
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,75 @@ | ||
# Protecting APIs with SSL/TLS | ||
|
||
This example describes how to secure an API with SSL/TLS. | ||
|
||
|
||
## Running the Example | ||
|
||
1. Run `service-proxy.bat` or `service-proxy.sh` | ||
2. Open the following URL in your browser. Please do not forget to use `https` instead of `http`. | ||
|
||
`https://localhost/` | ||
|
||
You should get a warning that the certificate is not trustworthy. Here you can ignore the warning. In production, you should use your own certificates. | ||
|
||
3. You can also access the API using `curl`. The option `-k` suppresses the check for self-signed certificates. | ||
|
||
``` | ||
curl -k -v https://localhost/ | ||
``` | ||
|
||
The output should look like this: | ||
|
||
``` | ||
* Trying 127.0.0.1:443... | ||
* Connected to localhost (127.0.0.1) port 443 (#0) | ||
* ALPN, offering h2 | ||
* ALPN, offering http/1.1 | ||
* successfully set certificate verify locations: | ||
* CAfile: /etc/ssl/cert.pem | ||
* CApath: none | ||
* (304) (OUT), TLS handshake, Client hello (1): | ||
* (304) (IN), TLS handshake, Server hello (2): | ||
* (304) (IN), TLS handshake, Unknown (8): | ||
* (304) (IN), TLS handshake, Certificate (11): | ||
* (304) (IN), TLS handshake, CERT verify (15): | ||
* (304) (IN), TLS handshake, Finished (20): | ||
* (304) (OUT), TLS handshake, Finished (20): | ||
* SSL connection using TLSv1.3 / AEAD-CHACHA20-POLY1305-SHA256 | ||
* ALPN, server did not agree to a protocol | ||
* Server certificate: | ||
* subject: CN=membrane | ||
* start date: Aug 5 10:41:09 2015 GMT | ||
* expire date: Aug 2 10:41:09 2025 GMT | ||
* issuer: CN=membrane | ||
* SSL certificate verify result: self signed certificate (18), continuing anyway. | ||
> GET / HTTP/1.1 | ||
> Host: localhost | ||
> | ||
< HTTP/1.1 200 Ok | ||
< Content-Type: application/json | ||
< | ||
{ | ||
"success" : true | ||
} | ||
``` | ||
|
||
## Configuration | ||
|
||
Just put an SSL element into a proxy. See the [documentation](https://www.membrane-soa.org/service-proxy-doc/4.4/configuration/reference/ssl.htm). | ||
|
||
```xml | ||
<serviceProxy port="443"> | ||
<ssl> | ||
<key> | ||
<private location="<<your privateKey>>" /> | ||
<certificate location="<<your certificate>>" /> | ||
</key> | ||
</ssl> | ||
<target host="localhost" port="2000"/> | ||
</serviceProxy> | ||
``` | ||
|
||
--- | ||
See: | ||
- [ssl](https://membrane-soa.org/api-gateway-doc/current/configuration/reference/ssl.htm) reference |
52 changes: 52 additions & 0 deletions
52
distribution/examples/ssl/api-with-tls-pem/membrane-key.pem
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 |
---|---|---|
@@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qnf/u+ob3x | ||
+N+3GZJ0Js3qDDPh/KvnwGykMe1NKL7RaG0q7S0eGTTBO6iEer08glIFX5tzO6oO | ||
NXAAmvLe99GA63LNXSWmgsBSSm0QIEaG57Ic6IbI0WyTzT4OmyIB3pigu3YPpMj0 | ||
zalYKwYqE5Kl/6y9wIwHl261JvurgbY= | ||
-----END PRIVATE KEY----- |
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 CERTIFICATE----- | ||
MIIExTCCAq2gAwIBAgIEd3OJmTANBgkqhkiG9w0BAQsFADATMREwDwYDVQQDEwht | ||
ZW1icmFuZTAeFw0xNTA4MDUxMDQxMDlaFw0yNTA4MDIxMDQxMDlaMBMxETAPBgNV | ||
BAMTCG1lbWJyYW5lMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAqSsz | ||
wxZRZp/Wa+qxQ2VDOnnCVPjBtoAlWkjgpyA6ytOPh7mnNPPcA1WSj3J0bfdpJR86 | ||
SzsIuDaeFMB+HNI3i+eXWrzn0zGkD73NXfKP1d9HADcXxYvuOBqqdrFYDxW6AY7R | ||
CLu+Vf3/jdsfIoR4qPJyNhFiocedE2+5BEUURxb02ieyQi81cIQ+PFBVoxUwUn7t | ||
v7Rj8nXHWm6I/6CCLOZR4G28lSrzWQGTWDgC8iSr/c19ha1KAg/afiJ63I3bzbIY | ||
lMDK6TIKqLyK3IRhY8FVKg633IL3QxQkakuCssT4sMIGhsgHbVqbmVyfy8rOUGeq | ||
sJSHO2l2cTLHkt84dL1Vvf4BB9sHSpY5y3IymvCQ4/DsCa8082PO3TpFc7IqKDey | ||
IJohK1gFiUqtLB5LAbPghFMs2ceVBDkymSfsT5sIIdh9bAnocWkh4bKIzokmbUnZ | ||
/nx4wsqTpY2yWc9yCZyD+eP3jq4PDxrs3WKBIy2fwBGweyP+Qi0IdJght+x+HMMm | ||
S/YsXQEuW2RKzkwPOEt+AIvsKCKke3dcedq1msrDktf8xMa2U8/fcjwmiD1No/Kl | ||
55h8fNICuseaXHrA8nRBqxZO7WsOv13lq0OObRszY6JCeNSmFMTOVJt/WLLiLlbL | ||
NGF0GLjL2Vmdcg2v66aGLy+pwgwkZeiOoDwncHECAwEAAaMhMB8wHQYDVR0OBBYE | ||
FE8JEAm4kPj2CQLM+lJ9YwDsyICXMA0GCSqGSIb3DQEBCwUAA4ICAQAlaRpG0SNi | ||
wy+PR4yQOlwgCM6OTb5eG8UqIzaqU20odRJm3vtMupI3NPiENR5iZfnY9YPC3+HC | ||
vaTAWCcX02Ic0ad6rKVE4AGYgjDlW/Phe86Gykg/IyEwXMTEpcDENFIYE/3QltfZ | ||
b9DUbUsJtQbZxSIko0xvnvCqMwWU6kLqHUwigzxboDoXiIN4fGpUUzrOxqVj2HxF | ||
/0B8yDBEYk1iI+JQRH5O3KC9W8AgweUBKFjTprUKvcM3AA4zGTCsv8KBrAB9xdxW | ||
AXiBU6SOmSM0RWpLY/5NUnRnxRtSYH/xCk4gbiH4ZtT0FiGxpWD1VWp2WXHziPjT | ||
wwxMYb2q1bnZt4IbnFShVFQd/oR7fVZRyvmVBKRargoUwXxQYvK0e9ptWdZr959R | ||
TQsmTIpP5BLqWiX9tntvNPFAvz6BL7XP+oztrqob23JfI8HTH8wfj/RVR6472mQq | ||
JXXq38C/HGbfrK60SGuwjQ6nTHn6RiSQ+ynbRnr8S6QlzwNd1mGoGKdwckATxTsk | ||
zdqfCgCcE4u6L2JX4Hx4n2aoudsh/TzPovszxiNEVmQTADY4I+gs7BGBFN8lzv+K | ||
VFoJUfPX2srbV1wDXJHydJgHcOBXJrd8hD0AvnVUvuclt6qWle1cePbp1UNncx2B | ||
GGH5p3GIokdCasDetqjiGRPa3Xn1393qbw== | ||
-----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,32 @@ | ||
<spring:beans xmlns="http://membrane-soa.org/proxies/1/" | ||
xmlns:spring="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd | ||
http://membrane-soa.org/proxies/1/ http://membrane-soa.org/schemas/proxies-1.xsd"> | ||
|
||
<router> | ||
|
||
<api port="443"> | ||
<ssl> | ||
<!-- Please replace key and certificate for production! --> | ||
<key> | ||
<private location="membrane-key.pem" /> | ||
<certificate location="membrane.pem" /> | ||
</key> | ||
</ssl> | ||
<target host="localhost" port="2000"/><!-- Route here to your target --> | ||
</api> | ||
|
||
<!-- Serves as a backend API mock --> | ||
<api port="2000"> | ||
<response> | ||
<template pretty="true" contentType="application/json"> | ||
{ "success": true } | ||
</template> | ||
</response> | ||
<return statusCode="200"/> | ||
</api> | ||
|
||
</router> | ||
|
||
</spring:beans> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions
18
distribution/examples/ssl/api-with-tls-pkcs12/service-proxy.bat
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,18 @@ | ||
@echo off | ||
if not "%MEMBRANE_HOME%" == "" goto homeSet | ||
set "MEMBRANE_HOME=%cd%\..\..\.." | ||
echo "%MEMBRANE_HOME%" | ||
if exist "%MEMBRANE_HOME%\service-proxy.bat" goto homeOk | ||
|
||
:homeSet | ||
if exist "%MEMBRANE_HOME%\service-proxy.bat" goto homeOk | ||
echo Please set the MEMBRANE_HOME environment variable to point to | ||
echo the directory where you have extracted the Membrane software. | ||
exit | ||
|
||
:homeOk | ||
set "CLASSPATH=%MEMBRANE_HOME%" | ||
set "CLASSPATH=%MEMBRANE_HOME%/conf" | ||
set "CLASSPATH=%CLASSPATH%;%MEMBRANE_HOME%/starter.jar" | ||
echo Membrane Router running... | ||
java -classpath "%CLASSPATH%" com.predic8.membrane.core.Starter -c proxies.xml |
35 changes: 35 additions & 0 deletions
35
distribution/examples/ssl/api-with-tls-pkcs12/service-proxy.sh
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,35 @@ | ||
#!/bin/bash | ||
homeSet() { | ||
echo "MEMBRANE_HOME variable is now set" | ||
CLASSPATH="$MEMBRANE_HOME/conf" | ||
CLASSPATH="$CLASSPATH:$MEMBRANE_HOME/starter.jar" | ||
export CLASSPATH | ||
echo Membrane Router running... | ||
java -classpath "$CLASSPATH" com.predic8.membrane.core.Starter -c proxies.xml | ||
|
||
} | ||
|
||
terminate() { | ||
echo "Starting of Membrane Router failed." | ||
echo "Please execute this script from the appropriate subfolder of MEMBRANE_HOME/examples/" | ||
|
||
} | ||
|
||
homeNotSet() { | ||
echo "MEMBRANE_HOME variable is not set" | ||
|
||
if [ -f "`pwd`/../../../starter.jar" ] | ||
then | ||
export MEMBRANE_HOME="`pwd`/../../.." | ||
homeSet | ||
else | ||
terminate | ||
fi | ||
} | ||
|
||
|
||
if [ "$MEMBRANE_HOME" ] | ||
then homeSet | ||
else homeNotSet | ||
fi | ||
|
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
26 changes: 26 additions & 0 deletions
26
...ion/src/test/java/com/predic8/membrane/examples/tests/ssl/SSLServerApiWithTlsPemTest.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,26 @@ | ||
package com.predic8.membrane.examples.tests.ssl; | ||
|
||
import com.predic8.membrane.examples.util.DistributionExtractingTestcase; | ||
import com.predic8.membrane.examples.util.Process2; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static com.predic8.membrane.test.AssertUtils.*; | ||
|
||
public class SSLServerApiWithTlsPemTest extends DistributionExtractingTestcase { | ||
|
||
@Override | ||
protected String getExampleDirName() { | ||
return "ssl/api-with-tls-pem"; | ||
} | ||
|
||
@Test | ||
void test() throws Exception { | ||
replaceInFile2("proxies.xml", "443", "3023"); | ||
|
||
try(Process2 ignored = startServiceProxyScript()) { | ||
trustAnyHTTPSServer(3023); | ||
assertContains("success", getAndAssert200("https://localhost:3023")); | ||
} | ||
} | ||
|
||
} |
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