Skip to content

Commit

Permalink
Merge pull request #33 from OSGP/feature/FDP-2217
Browse files Browse the repository at this point in the history
FDP-2217: Implement mutual TLS
  • Loading branch information
jasperkamerling authored Jun 7, 2024
2 parents ee93bca + da4fd6a commit 7eee3d0
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 4 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@ To test this flow locally:
8. When the crest device service receives a message from the device (simulator), a psk set command will be sent in the downlink response to the device (simulator). The new key will be set to pending.
1. When the crest device service receives a success result code in the subsequent message from the device (simulator), the pending key will be set to active and the old key will become inactive.
2. When the crest device service receives a failure result code in the subsequent message from the device (simulator), the pending key will be set to invalid.


## Mutual TLS
Communication between the COAP HTTP Proxy and the Crest device service should be encrypted using mutual TLS.

The repositories contain test certificates that can be used for local testing. (they are not included in the jar or docker image)
They can be also be (re)generated using the [generate_certificates.sh](generate_certificates.sh) script.
7 changes: 7 additions & 0 deletions application/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.springframework.boot.gradle.tasks.bundling.BootJar

// SPDX-FileCopyrightText: Contributors to the GXF project
//
// SPDX-License-Identifier: Apache-2.0
Expand Down Expand Up @@ -43,6 +45,11 @@ dependencies {
jacocoAggregation(project(":application"))
}

tasks.withType<BootJar> {
// Exclude test keys and certificates
exclude("ssl/*.pem")
}

tasks.withType<org.springframework.boot.gradle.tasks.bundling.BootBuildImage> {
imageName.set("ghcr.io/osgp/gxf-sng-crest-device-service:${version}")
if (project.hasProperty("publishImage")) {
Expand Down
12 changes: 8 additions & 4 deletions application/src/main/resources/application-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ spring:
url: "jdbc:postgresql://localhost:5432/crest_device_service"
username: "postgres"
password: "1234"
jpa:
properties:
hibernate:
dialect: "org.hibernate.dialect.PostgreSQLDialect"
kafka:
bootstrap-servers: "localhost:9092"

# Local testing certificates
mutual-tls:
keystore:
private-key: "classpath:ssl/dev-device-service-key.pem"
certificate: "classpath:ssl/dev-device-service-cert.pem"
truststore:
certificate: "classpath:ssl/dev-proxy-cert.pem"

server:
port: 9000

Expand Down
25 changes: 25 additions & 0 deletions application/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
#SPDX-FileCopyrightText: Contributors to the GXF project
#
#SPDX-License-Identifier: Apache-2.0

# The crest device service should always require mutual tls
server:
ssl:
enabled: true
client-auth: need
bundle: "crest-device-service"

# Run the actuator under a different not tls port
management:
server:
port: 8081
ssl:
enabled: false
endpoints:
web:
exposure:
include: "prometheus"

# Default server ssl bundle
spring:
ssl:
bundle:
pem:
crest-device-service:
keystore:
private-key: "${mutual-tls.keystore.private-key}"
certificate: "${mutual-tls.keystore.certificate}"
truststore:
certificate: "${mutual-tls.truststore.certificate}"

logging:
level:
com:
Expand Down
33 changes: 33 additions & 0 deletions application/src/main/resources/ssl/dev-device-service-cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
-----BEGIN CERTIFICATE-----
MIIFsTCCA5mgAwIBAgIUY0NujZU+uRqek0Fi6QoY1Qo4AKAwDQYJKoZIhvcNAQEL
BQAwaDELMAkGA1UEBhMCTkwxEzARBgNVBAgMCkdlbGRlcmxhbmQxDzANBgNVBAcM
BkFybmhlbTESMBAGA1UECgwJQWxsaWFuZGVyMQswCQYDVQQLDAJJVDESMBAGA1UE
AwwJbG9jYWxob3N0MB4XDTI0MDYwNzEwNTExMVoXDTM0MDYwNTEwNTExMVowaDEL
MAkGA1UEBhMCTkwxEzARBgNVBAgMCkdlbGRlcmxhbmQxDzANBgNVBAcMBkFybmhl
bTESMBAGA1UECgwJQWxsaWFuZGVyMQswCQYDVQQLDAJJVDESMBAGA1UEAwwJbG9j
YWxob3N0MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA86nNd5UwicED
H861toiRZLsol3m11GVBGXBYLNlDE6gK0Ib9ST7tf3sV/des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JUjBaBn1FgO60yDLFAFQwYUAYKm
MhYUuG32k23Ywx7fM495Le6exRpjGu/ZniYQyz1nKzuobQNrEIjTHFGGmaqJfzu4
030Jq8dvi1Pi+HNIqnTOcmxEzvfj3ie4aBzGjTNPAI1O94doUxGf5EcD330fYIKG
xo8Rkqv+uV48jiZ/2cG+e5NAktuiBOiYq28QP+2RnkLH2S2WPN9Qmk7Norb20Gs8
V4hH/EMt6Qduh0X5vLNg8gKy6cIuqlmSQ2cMNKMXNaCwSvRuDOnJt/Ko2lKAWc6r
uPlh9grkF5EvfoPAG47kdlclyzChVPvNIIsWE9WT7mQ30RORSffjqXdG55F/Igf/
Idj2vIFKNQlLkpMPSANa2B1u1/mH
-----END CERTIFICATE-----
52 changes: 52 additions & 0 deletions application/src/main/resources/ssl/dev-device-service-key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-----BEGIN PRIVATE KEY-----
MIIJQQIBADANBgkqhkiG9w0BAQEFAASCCSswggknAgEAAoICAQDzqc13lTCJwQMf
zrW2iJFkuyiXebXUZUEZcFgs2UMTqArQhv1JPu1/exX916xr0mdB0YmfnFJl/QdE
pKGza7doHa91jVlN4Gdp0hp6Q0tWKX3ZSDh88GqGBo1CAdZ/Xa9lL0ib3sl9QtMC
YEYk3a7mnWi2Rf2Co8PwgdXnWFWmWtfJQSmJKGJv8oVwbg87KvRvpEYEFKFzE2aW
XS3nv+MhCrnSo5/RqW0U0Mx7c5J5Swd6nGE8g8NbS+g3h46iB1+Rovli8neUGDiG
hqxWHCavj+T4LlERhPxtvNAgC4rYTbxH/qsGbapyXO8LnTSnIRvc/EtCcOy6L5oa
cyDE6v4P7dhuqZCzGVOh1+S1OEbyDe5PRZQuOYXdYDE6WK1gwRdvpTTz43BkkDSF
889XGi+SQ1RNNUMpp5y/+T3RHpzuqETSlCiOR1vv+nHqPjMmA5FfjMBfKjxRSsA4
uEHQEytSuNoNJS0yaY/ByHmmzqDBIRRhBk9yEb0fuHVTwdqvgSkEV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X8Y5HLcj+XdV6hz
WODDcmegueY0+HjiGb5Z4zwQO9WhOz4Prrpe4zkmvA5aDuOMMK9s119GkIvehzqT
9d4IbhMLsaFUpwPyFzE7outwatcO39uTGbUqBGhtP3FS98AyguuhPacSBLDUw9pq
JwKCAQA1bQ77h4wyfuC0EryDOobfLUaLDF7qD0bZMakFVTBKA1M63MQiZ04H1hJD
/eSHn1BS5tNW/xP3SjtN7w7qm4zN1K9C6PIstY2A5MnUzgiJFzecQLy8OhCF6dRZ
k3uleK4K+UZOlvVNW+biCrw8u19hevY665HY9mxa8nPwFWqVxh+NZ0+ypfp768k3
Yq5o9i9E9r3gQEuZGLZGuXlcwMfA/ziKk0HTjpRuKS/qqIlwYgi4N7cYYJUJEJS6
McSGVUtsld1Qu8we+aELMAn7GuZgE88qP3hoDEyV6eaUxIAwubCn/jiIqyAB+8N0
2JMuaHHHTnDTanBCbkbJxkJmV4L7
-----END PRIVATE KEY-----
33 changes: 33 additions & 0 deletions application/src/main/resources/ssl/dev-proxy-cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
-----BEGIN CERTIFICATE-----
MIIFsTCCA5mgAwIBAgIUQz2Jfjg4JkSsca8BVSafqt8mB0cwDQYJKoZIhvcNAQEL
BQAwaDELMAkGA1UEBhMCTkwxEzARBgNVBAgMCkdlbGRlcmxhbmQxDzANBgNVBAcM
BkFybmhlbTESMBAGA1UECgwJQWxsaWFuZGVyMQswCQYDVQQLDAJJVDESMBAGA1UE
AwwJbG9jYWxob3N0MB4XDTI0MDYwNzEwNTExMVoXDTM0MDYwNTEwNTExMVowaDEL
MAkGA1UEBhMCTkwxEzARBgNVBAgMCkdlbGRlcmxhbmQxDzANBgNVBAcMBkFybmhl
bTESMBAGA1UECgwJQWxsaWFuZGVyMQswCQYDVQQLDAJJVDESMBAGA1UEAwwJbG9j
YWxob3N0MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEApGs2eERv8/XM
FwN1B8puQLT7+b1r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jd0kW/FIa0C4Lm8pHNH
qeFwLjQTMocFUaTLkbZVD2vPsGsl8PmzpWTt04EWd03kQGnFWtp4J9Gd1FQWPYMQ
zNYKvwmDKq9odQTViNzU6xHQmwo+mZM17KqRwkqKRPmXYH6mtqdpmxKEWynkWhwQ
jfBsJfqfJqrSfVyID0IbxZIAEgD2MOcH8KET8iImdvZyQcHC0NWJF8EDVvwnG2If
4oAlfKIwSxe4FQ0pG01MCGnWwncQt76d75k7fs1FO9DORCCYQdDxcI8M1uwzdxJG
1UQ/WbRxSlKalAwgzP8rL9LTA9naVR7FDjZTBaP3JJHcI7cEwkYiGDxYdFzjy8b2
dU5fGUoSNoWABVIGAQxpDlNqS4AZaQQxA9g7KHBUuLXaDvnG59yK36g0YlQBUbyh
7mN89Z4HwosPDcA5cIfi/Wie/kfZ
-----END CERTIFICATE-----
34 changes: 34 additions & 0 deletions generate_certificates.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
# SPDX-FileCopyrightText: Copyright Contributors to the GXF project
#
# SPDX-License-Identifier: Apache-2.0

HOST_NAME=localhost

RESOURCE_DIR=application/src/main/resources/ssl
DEVICE_SERVICE_RESOURCE_DIR="./${RESOURCE_DIR}"
COAP_HTTP_PROXY_RESOURCE_DIR="../sng-coap-http-proxy/${RESOURCE_DIR}"

echo "Generating new proxy certificate"

openssl req -newkey rsa:4096 -new -nodes -x509 -days 3650 \
-keyout dev-proxy-key.pem -out dev-proxy-cert.pem \
-subj "/C=NL/ST=Gelderland/L=Arnhem/O=Alliander/OU=IT/CN=${HOST_NAME}"

openssl req -newkey rsa:4096 -new -nodes -x509 -days 3650 \
-keyout dev-device-service-key.pem -out dev-device-service-cert.pem \
-subj "/C=NL/ST=Gelderland/L=Arnhem/O=Alliander/OU=IT/CN=${HOST_NAME}"

# Device service files
cp dev-device-service-key.pem "${DEVICE_SERVICE_RESOURCE_DIR}"
cp dev-device-service-cert.pem "${DEVICE_SERVICE_RESOURCE_DIR}"
cp dev-proxy-cert.pem "${DEVICE_SERVICE_RESOURCE_DIR}"

# Proxy files
cp dev-proxy-key.pem "${COAP_HTTP_PROXY_RESOURCE_DIR}"
cp dev-proxy-cert.pem "${COAP_HTTP_PROXY_RESOURCE_DIR}"
cp dev-device-service-cert.pem "${COAP_HTTP_PROXY_RESOURCE_DIR}"

rm ./*.pem

echo "Generated all certificates and stores"

0 comments on commit 7eee3d0

Please sign in to comment.