This repository was archived by the owner on May 16, 2024. It is now read-only.
Repository navigation
Improvements based on Mark's third review. Removed dead code; added a Common Problems section; fixed typos. #14
Closed
Closed
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
848f42b
Updating samples so it refers to the new 'shared' service plan, so it…
dickeyf efeeead
Merge pull request #1 from dickeyf/master
dickeyf a215c9d
Merge branch 'master' of https://github.com/SolaceDev/solace-samples-…
benhaig 6512204
Update "Common Setup"
benhaig a70436a
Improve deployment instructions
benhaig 83a7513
Fixed links to tutorials
benhaig b6d62ef
Update VCAP_SERVICES example
benhaig f37c8af
Updated service instance name to match sample code
benhaig ca68c2b
Merge branch 'master' of https://github.com/SolaceSamples/solace-samp…
MichaelDavisSolace 6ff051b
Added tls support
MichaelDavisSolace dd5e7de
Merge branch 'master' of https://github.com/SolaceSamples/solace-samp…
MichaelDavisSolace 5b3905d
java-tls work in progress.
MichaelDavisSolace fba5ff4
Added secure-app, the TLS tutorial
MichaelDavisSolace 7a7df8e
minor improvements to the secure-sessions tutorial.
MichaelDavisSolace f347576
Editorial changes from review
mdspielman 02bb150
Added build dir to gitignore
MichaelDavisSolace 320dbc7
Merge remote-tracking branch 'origin/mdspielman-patch-1' into tls-sup…
MichaelDavisSolace 89cb009
Merge remote-tracking branch 'public/master'
MichaelDavisSolace 77bca79
Merge branch 'master' into tls-support
MichaelDavisSolace 9590cc9
Improvements to the secure-session tutorial based on Mark Spielman's …
MichaelDavisSolace c23db37
Improved secure-session tutorial based on the third review.
MichaelDavisSolace File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -14,3 +14,5 @@ spring-cloud/build/ | |
| libs/ | ||
| .DS_Store | ||
| docs/_site | ||
| /.nb-gradle/ | ||
| /secure-app/build/ | ||
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -2,3 +2,4 @@ | |
| tutorials: | ||
| - java-app | ||
| - spring-cloud | ||
| - secure-session | ||
This file contains hidden or 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,200 @@ | ||
| --- | ||
| layout: tutorials | ||
| title: Secure Session | ||
| summary: A simple Spring Cloud application showing how to connect with the Solace Messaging service using Transport Level Security (TLS). | ||
| icon: ssl_icon.gif | ||
| --- | ||
|
|
||
| * [Overview](#overview) | ||
| * [Goals](#goals) | ||
| * [Assumptions](#assumptions) | ||
| * [Working with a trusted certificate](#working-with-a-trusted-certificate) | ||
| * [Code walk through - trusted certificates](#code-walk-through---trusted-certificates) | ||
| * [Working with a self-signed certificate](#working-with-a-self-signed-certificate) | ||
| * [Building](#building) | ||
| * [Cloud Foundry Setup](#cloud-foundry-setup) | ||
| * [Deploying](#deploying) | ||
| * [Trying Out the Application](#trying-out-the-application) | ||
| * [Common Problems](#common-problems) | ||
|
|
||
|
|
||
| ## Overview | ||
|
|
||
| This tutorial is part of a series of tutorials which aims to introduce users to Solace Messaging in Pivotal Cloud Foundry. Solace Messaging in Pivotal Cloud Foundry is delivered as a tile on the [Pivotal Network](https://network.pivotal.io/){:target="_blank"}. you can see the [Solace Messaging for Pivotal Cloud Foundry documentation](http://docs.pivotal.io/solace-messaging/){:target="_blank"} for full details. | ||
|
|
||
|
|
||
| This tutorial is based on the [Spring Cloud]({{ site.baseurl }}/spring-cloud) tutorial, adding a demonstration on how to connect to the Solace Messaging service using TLS. | ||
|
|
||
| ## Goals | ||
|
|
||
| The goal of this tutorial is to demonstrate how to connect to the Solace Messaging service instance using TLS. This tutorial will show you how to establish a connection to the solace messaging service using both self-signed and Certificate Authority approved certificates. | ||
|
|
||
| ## Assumptions | ||
|
|
||
| This tutorial assumes the following: | ||
|
|
||
| * You have completed the [Spring Cloud]({{ site.baseurl }}/spring-cloud) tutorial. | ||
| * You are familiar with [Transport Level Security](https://en.wikipedia.org/wiki/Transport_Layer_Security){:target="_blank"} concepts, including how to create or obtain certificates. | ||
|
|
||
|
|
||
| ## Working with a Trusted Certificate | ||
|
|
||
| In order to use Transport Level Security, your Solace Message Router needs to be configured for TLS with an installed servcer certificate. | ||
| The instructions for doing that are described in the Pivotal/Solace Messaging documentation - | ||
| see [Tile Installation and Configuration]({{ site.links-tls-server }}){:target="_blank"}, | ||
| look for the step named Configure Message Routers RSA certificate. | ||
|
|
||
| This section assumes that you have a Solace Messaging Service Instance properly configured for TLS access with a certificate that has been purchased from a certificate authority. Instructions for working with self-signed certificates are below. | ||
|
|
||
| ## Code Walk Through - Trusted Certificates | ||
|
|
||
| when we initialize the connection to the service, we can specify whether to use TLS or not. to use TLS, we replaced this line from the Spring Cloud tutorial: | ||
|
|
||
| ```java | ||
| properties.setProperty(JCSMPProperties.HOST, solaceMessagingServiceInfo.getSmfHost()); | ||
| ``` | ||
|
|
||
| with this: | ||
|
|
||
| ```java | ||
| properties.setProperty(JCSMPProperties.HOST, solaceMessagingServiceInfo.getSmfTlsHost()); | ||
| ``` | ||
|
|
||
| When you use the TLS host, you can also specify whether the client should validate the TLS certificate. | ||
| This should always be done in production environments. We do this by setting the `JCSMPProperties`: | ||
|
|
||
| ```java | ||
| properties.setproperty(JCSMPProperties.SSL_VALIDATE_CERTIFICATE, true); | ||
| properties.setproperty(JCSMPProperties.SSL_VALIDATE_CERTIFICATE_DATE, true); | ||
| properties.setProperty(JCSMPProperties.SSL_TRUST_STORE, "path-to-trust-store"); | ||
| properties.setProperty(JCSMPProperties.SSL_TRUST_STORE_PASSWORD, "changeit"); | ||
| ``` | ||
| In Cloud Foundry, the path to the trust store is | ||
| `/home/vcap/app/.java-buildpack/open_jdk_jre/lib/security/cacerts` | ||
| and the password is the default JRE keystore password, `changeit`. | ||
|
|
||
| That is all that is required when using a Certificate Authority issued certificate. | ||
| The JRE's trusted store comes pre-configured with certificates that are sufficient | ||
| to validated your CA-issued certificate. | ||
|
|
||
| ## Working with a Self-signed Certificate | ||
|
|
||
| You can install your Solace Messaging service for PCF with a self-signed certificate. For instructions on how to do this see the [Solace Messaging Documentation]({{ site.links-tls-server }}){:target="_blank"}. | ||
|
|
||
| With self-signed certificates you have two choices. Either you can have the client validate the self-signed certificate, | ||
| or not. For testing purposes, you can choose to not validate the certificate simply by | ||
| setting the following properties to false: | ||
|
|
||
| ```java | ||
| properties.setproperty(JCSMPProperties.SSL_VALIDATE_CERTIFICATE, false); | ||
| properties.setproperty(JCSMPProperties.SSL_VALIDATE_CERTIFICATE_DATE, false); | ||
| ``` | ||
|
|
||
| Note that this is insecure and should never be done in production. This provides you with a TLS encrypted connection to the Solace Message Router but no validation of the identity so you're still exposed to a variety of attacks. | ||
|
|
||
| It is also possible to validate the self-signed certificate. This provides an environment that is a little closer to production. To do this, you must provide a certificate to the client-side trust store. This is tricky because the trust store is bundled along with the JRE together with the Cloud Foundry app. It must be added after the application is deployed but before it connects with the Solace Messaging service. Follow these steps: | ||
|
|
||
| 1. Copy the certificate (the *.pem file) to the directory secure-app/src/main/resources. | ||
| 1. Edit the file. Remove the private key section and just leave the lines starting with -----BEGIN CERTIFICATE----- and ending with ----- END CERTIFICATE-----. | ||
| 1. In the CertificateUtil class, change the `CERTIFICATE_FILE_NAME` to match your certificate's file name. | ||
| 1. In the SolaceController class, enable certificate validation. | ||
|
|
||
| ```java | ||
| private static final boolean VALIDATE_CERTIFICATE = true; | ||
| // and set these further down... | ||
| properties.setproperty(JCSMPProperties.SSL_VALIDATE_CERTIFICATE, true); | ||
| properties.setproperty(JCSMPProperties.SSL_VALIDATE_CERTIFICATE_DATE, true); | ||
| ``` | ||
|
|
||
| When you set `INSTALL_CERTIFICATE` to `true`, it instructs the SolaceController class to install the certificate in the JRE's trusted store before trying to connect to the service. | ||
|
|
||
| The way it works is this. When you copy the certificate into the src/main/resources file, it gets packaged with the application. The application can then read the file from its local file system at runtime. | ||
|
|
||
| The standard location for a trusted store, relative to a JRE directory, is in a file at lib/security/cacerts. | ||
|
|
||
| The JRE is provided at runtime by Cloud Foundry, and from the point of view of an application the path to the jre is | ||
| ``` | ||
| /home/vcap/app/.java-buildpack/open_jdk_jre | ||
| ``` | ||
|
|
||
| The SolaceController class reads the certificate and installs it in the trusted store when the application starts running, but before it tries to connect to the service. | ||
|
|
||
| Note that we only need to do this when we want the client to validate a self-signed certificate. There should never be a need to do this kind of thing in a production system. | ||
|
|
||
| ## Building | ||
|
|
||
| The full source code for this example is available in [GitHub]({{ site.repository }}){:target="_blank"}. To build, just clone and use gradle. Here is an example: | ||
|
|
||
| ``` | ||
| git clone {{ site.repository }} | ||
| cd {{ site.baseurl | remove: '/'}} | ||
| ./gradlew build | ||
| ``` | ||
|
|
||
| ## Cloud Foundry Setup | ||
|
|
||
| The sample application specifies a dependency on a service instance named `solace-messaging-sample-instance` in its manifiest (See `secure-session/manifest.yml`). This must be an instance of the Solace Messaging Service which can be created with this command: | ||
|
|
||
| ``` | ||
| cf create-service solace-messaging shared solace-messaging-sample-instance | ||
| ``` | ||
|
|
||
| ## Deploying | ||
|
|
||
| To deploy this tutorial's application you first need to go inside it's project directory and then push the application: | ||
|
|
||
| ``` | ||
| cd secure-session | ||
| cf push | ||
| ``` | ||
|
|
||
| This will push the application and will give the application the name specified by the manifest: `solace-sample-secure-session`. | ||
|
|
||
| ## Trying Out The Application | ||
|
|
||
| As described above, the sample application has a simple REST interface that allows you to: | ||
|
|
||
| * Subscribe | ||
| * Send a message | ||
| * Receive a message | ||
|
|
||
| In order to interact with the application you need to determine the application's URL. These shell commands can be used to quickly find out the URL: | ||
|
|
||
| ``` | ||
| export APP_NAME=solace-sample-secure-session | ||
| export APP_URL=`cf apps | grep $APP_NAME | grep started | awk '{ print $6}'` | ||
| echo "The application URL is: ${APP_URL}" | ||
| ``` | ||
|
|
||
| To demonstrate the application we will make the application send a message to itself. Then we will read the message back to confirm the successful delivery of the message : | ||
|
|
||
| ``` | ||
| # Subscribes the application to the topic "test" | ||
| curl -X POST -H "Content-Type: application/json;charset=UTF-8" -d '{"subscription": "test"}' http://$APP_URL/subscription | ||
|
|
||
| # Send message with topic "test" and this content: "TEST_MESSAGE" | ||
| curl -X POST -H "Content-Type: application/json;charset=UTF-8" -d '{"topic": "test", "body": "Test Message"}' http://$APP_URL/message | ||
|
|
||
| # The message should have been asynchronously received by the application. Check that the message was indeed received: | ||
| curl -X GET http://$APP_URL/message | ||
| ``` | ||
|
|
||
| ## Common Problems | ||
|
|
||
| If you see: | ||
|
|
||
| ``` | ||
| JCSMPTransportException: Error communicating with the router, ConnectException: Connection Refused | ||
| ``` | ||
|
|
||
| This can happen if a TLS server certificate was not configured in the Tile in which case the VMR will reject incoming TLS connections. | ||
|
|
||
| If you see: | ||
| ``` | ||
| CertificateException: Path does not chain with any of the trust anchors | ||
| ``` | ||
|
|
||
| it is because the application could not validate the certificate it received from the server. This can happen when you install a self-signed certificate on the router, but didn't package it with the app, or didn't set INSTALL_CERTIFICATE to true. | ||
|
|
||
|
|
||
|
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 hidden or 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,50 @@ | ||
| buildscript { | ||
| ext { | ||
| springBootVersion = '1.3.3.RELEASE' | ||
| springCloudVersion = '1.2.3.RELEASE' | ||
| solaceJCSMPVersion = '10.+' | ||
| solaceCloudVersion = '0.1+' | ||
| } | ||
| repositories { | ||
| mavenCentral() | ||
| } | ||
| dependencies { | ||
| classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") | ||
| } | ||
| } | ||
|
|
||
| apply plugin: 'java' | ||
| apply plugin: 'eclipse' | ||
| apply plugin: 'idea' | ||
| apply plugin: 'spring-boot' | ||
|
|
||
| jar { | ||
| baseName = 'solace-sample-secure-session' | ||
| version = '' | ||
| } | ||
|
|
||
| repositories { | ||
| mavenCentral() | ||
| } | ||
|
|
||
| dependencies { | ||
| compile("org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}") | ||
| compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}") | ||
|
|
||
| // Spring Cloud Connectors | ||
| compile("org.springframework.cloud:spring-cloud-spring-service-connector:${springCloudVersion}") | ||
| compile("org.springframework.cloud:spring-cloud-cloudfoundry-connector:${springCloudVersion}") | ||
|
|
||
| // Alternatively using spring-boot-starter inclusion... | ||
| //compile("org.springframework.boot:spring-boot-starter-cloud-connectors:${springBootVersion}") | ||
|
|
||
| // Solace Messaging Spring Cloud Connector | ||
| compile("com.solace.labs.cloud.cloudfoundry:solace-labs-spring-cloud-connector:${solaceCloudVersion}") | ||
|
|
||
| // Solace Java API | ||
| compile("com.solacesystems:sol-jcsmp:${solaceJCSMPVersion}") | ||
| } | ||
|
|
||
| task wrapper(type: Wrapper) { | ||
| gradleVersion = '2.14' | ||
| } |
This file contains hidden or 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,7 @@ | ||
| --- | ||
| applications: | ||
| - name: solace-sample-secure | ||
| memory: 512M | ||
| path: build/libs/solace-sample-secure-session.jar | ||
| services: | ||
| - solace-messaging-sample-instance |
32 changes: 32 additions & 0 deletions
32
secure-session/src/main/java/com/solace/samples/cloudfoundry/securesession/Application.java
This file contains hidden or 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 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package com.solace.samples.cloudfoundry.securesession; | ||
|
|
||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
|
||
| @SpringBootApplication | ||
| public class Application { | ||
|
|
||
| public static void main(String[] args) { | ||
| SpringApplication.run(Application.class, args); | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be no need to modify this tutorial. All TLS is handled in your secure sessions