Skip to content

Commit

Permalink
Release of version 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fengsongAWS committed Nov 14, 2016
1 parent e14223a commit c8765af
Show file tree
Hide file tree
Showing 13 changed files with 186 additions and 93 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ of your Maven project.
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-iot-device-sdk-java</artifactId>
<version>1.0.1</version>
<version>1.1.0</version>
</dependency>
</dependencies>
```
Expand All @@ -88,7 +88,7 @@ The sample applications included with the SDK can also be installed using the fo
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-iot-device-sdk-java-samples</artifactId>
<version>1.0.1</version>
<version>1.1.0</version>
</dependency>
</dependencies>
```
Expand All @@ -99,8 +99,7 @@ and copy the JAR files to your project's library directory, and then update your
include them to your library build path.

You will also need to add two libraries the SDK depends on:

* Jackson 2.x, including Jackson-core and Jackson-databind. [download instructions][jackson-download]
* Jackson 2.x, including [Jackson-core] [jackson-core] and [Jackson-databind] [jackson-databind]
* Paho MQTT client for Java 1.1.x. [download instructions][paho-mqtt-java-download]

### Build the SDK from the GitHub Source
Expand Down Expand Up @@ -216,7 +215,7 @@ To subscribe to a topic:

```java
public class MyTopic extends AWSIotTopic {
public MyOwnMessage(String topic, AWSIotQos qos) {
public MyTopic(String topic, AWSIotQos qos) {
super(topic, qos);
}

Expand Down Expand Up @@ -259,7 +258,7 @@ To access a shadow using a non-blocking API:

```java
public class MyShadowMessage extends AWSIotMessage {
public MyMessage() {
public MyShadowMessage() {
super(null, null);
}

Expand Down Expand Up @@ -484,9 +483,10 @@ For any other questions about AWS IoT, contact [AWS Support][aws-support].
[aws-iot-forum]: https://forums.aws.amazon.com/forum.jspa?forumID=210
[aws-iot-console]: http://aws.amazon.com/iot/
[latest-jar]: https://s3.amazonaws.com/aws-iot-device-sdk-java/aws-iot-device-sdk-java-LATEST.zip
[jackson-download]: http://wiki.fasterxml.com/JacksonDownload
[jackson-core]: https://github.com/FasterXML/jackson-core
[jackson-databind]: https://github.com/FasterXML/jackson-databind
[paho-mqtt-java-download]: https://eclipse.org/paho/clients/java/
[api-docs]: http://aws-iot-device-sdk-java-docs.s3-website-us-east-1.amazonaws.com/
[aws-iot-ecc-blog]: https://aws.amazon.com/blogs/iot/elliptic-curve-cryptography-and-forward-secrecy-support-in-aws-iot-3/
[aws-support]: https://aws.amazon.com/contact-us
[apache-license-2]: http://www.apache.org/licenses/LICENSE-2.0
[apache-license-2]: http://www.apache.org/licenses/LICENSE-2.0
4 changes: 2 additions & 2 deletions aws-iot-device-sdk-java-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<parent>
<groupId>com.amazonaws</groupId>
<artifactId>aws-iot-device-sdk-java-pom</artifactId>
<version>1.0.1</version>
<version>1.1.0</version>
</parent>
<artifactId>aws-iot-device-sdk-java-samples</artifactId>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-iot-device-sdk-java</artifactId>
<version>1.0.1</version>
<version>1.1.0</version>
</dependency>
</dependencies>
<build>
Expand Down
4 changes: 2 additions & 2 deletions aws-iot-device-sdk-java-samples/samples-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.amazonaws</groupId>
<artifactId>aws-iot-device-sdk-java-samples</artifactId>
<version>1.0.1</version>
<version>1.1.0</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -12,7 +12,7 @@
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-iot-device-sdk-java</artifactId>
<version>1.0.1</version>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
public class PublishSubscribeSample {

private static final String TestTopic = "sdkTest/sub";
private static final String TestTopic = "sdk/test/java";
private static final AWSIotQos TestTopicQos = AWSIotQos.QOS0;

private static AWSIotMqttClient awsIotClient;
Expand Down
2 changes: 1 addition & 1 deletion aws-iot-device-sdk-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.amazonaws</groupId>
<artifactId>aws-iot-device-sdk-java-pom</artifactId>
<version>1.0.1</version>
<version>1.1.0</version>
</parent>
<artifactId>aws-iot-device-sdk-java</artifactId>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,25 @@ public AWSIotMqttClient(String clientEndpoint, String clientId, String awsAccess
super(clientEndpoint, clientId, awsAccessKeyId, awsSecretAccessKey, sessionToken);
}

/**
* Updates credentials used for signing Secure WebSocket URLs. When temporary
* credentails used for the WebSocket connection are expired, newer
* credentails can be supplied through this API to allow new connections to
* be reestablished using the new credentails.
*
* @param awsAccessKeyId
* the AWS access key id
* @param awsSecretAccessKey
* the AWS secret access key
* @param sessionToken
* Session token received along with the temporary credentials
* from services like STS server, AssumeRole, or Amazon Cognito.
*/
@Override
public void updateCredentials(String awsAccessKeyId, String awsSecretAccessKey, String sessionToken) {
super.updateCredentials(awsAccessKeyId, awsSecretAccessKey, sessionToken);
}

/**
* Gets the number of client threads currently configured. Each client has
* their own thread pool, which is used to execute user callback functions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ protected AbstractAwsIotClient(String clientEndpoint, String clientId, String aw
this.connectionType = null;
}

public void updateCredentials(String awsAccessKeyId, String awsSecretAccessKey, String sessionToken) {
this.connection.updateCredentials(awsAccessKeyId, awsSecretAccessKey, sessionToken);
}

public void connect() throws AWSIotException {
try {
connect(0, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,22 @@ public void publish(AWSIotMessage message) throws AWSIotException {
}
}

/**
* Updates credentials for the connection, which will be used for new
* connections.
*
* @param awsAccessKeyId
* the AWS access key id
* @param awsSecretAccessKey
* the AWS secret access key
* @param sessionToken
* Session token received along with the temporary credentials
* from services like STS server, AssumeRole, or Amazon Cognito.
*/
public void updateCredentials(String awsAccessKeyId, String awsSecretAccessKey, String sessionToken) {
// default implementation does nothing
}

/**
* The actual subscribe method exposed by this class.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
*/
public class AwsIotWebsocketConnection extends AwsIotMqttConnection {

private AwsIotWebSocketUrlSigner urlSigner;

public AwsIotWebsocketConnection(AbstractAwsIotClient client, String awsAccessKeyId, String awsSecretAccessKey)
throws AWSIotException {
this(client, awsAccessKeyId, awsSecretAccessKey, null);
Expand All @@ -39,13 +41,27 @@ public AwsIotWebsocketConnection(AbstractAwsIotClient client, String awsAccessKe

// Port number must be included in the endpoint for signing otherwise
// the signature verification will fail. This is because the Paho client
// library (1.0.3) always includes port number in the host line of the HTTP
// request header, e.g "Host: data.iot.us-east-1.amazonaws.com:443".
String signedUrl = AwsIotWebSocketUrlSigner.getSignedUrl(client.getClientEndpoint() + ":443", awsAccessKeyId,
awsSecretAccessKey, sessionToken, null);
// library always includes port number in the host line of the
// HTTP request header, e.g "Host: data.iot.us-east-1.amazonaws.com:443".
urlSigner = new AwsIotWebSocketUrlSigner(client.getClientEndpoint() + ":443");
urlSigner.updateCredentials(awsAccessKeyId, awsSecretAccessKey, sessionToken);
}

@Override
public void updateCredentials(String awsAccessKeyId, String awsSecretAccessKey, String sessionToken) {
urlSigner.updateCredentials(awsAccessKeyId, awsSecretAccessKey, sessionToken);
}

@Override
public Set<String> getServerUris() {
Set<String> uris = new HashSet<>();
uris.add(signedUrl);
this.setServerUris(uris);
try {
uris.add(urlSigner.getSignedUrl(null));
} catch (AWSIotException e) {
throw new AwsIotRuntimeException(e);
}

return uris;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public class AwsIotMqttConnection extends AwsIotConnection {
private MqttAsyncClient mqttClient;
private AwsIotMqttMessageListener messageListener;
private AwsIotMqttClientListener clientListener;
private Set<String> serverUris;

public AwsIotMqttConnection(AbstractAwsIotClient client, SocketFactory socketFactory, String serverUri)
throws AWSIotException {
Expand Down Expand Up @@ -137,11 +136,7 @@ public void unsubscribeTopic(AWSIotMessage message) throws AWSIotException, AwsI
}

public Set<String> getServerUris() {
return new HashSet<>(serverUris);
}

public void setServerUris(Set<String> serverUris) {
this.serverUris = new HashSet<>(serverUris);
return new HashSet<>();
}

private MqttConnectOptions buildMqttConnectOptions(AbstractAwsIotClient client, SocketFactory socketFactory) {
Expand All @@ -152,6 +147,7 @@ private MqttConnectOptions buildMqttConnectOptions(AbstractAwsIotClient client,
options.setConnectionTimeout(client.getConnectionTimeout() / 1000);
options.setKeepAliveInterval(client.getKeepAliveInterval() / 1000);

Set<String> serverUris = getServerUris();
if (serverUris != null && !serverUris.isEmpty()) {
String[] uriArray = new String[serverUris.size()];
serverUris.toArray(uriArray);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;

Expand Down Expand Up @@ -117,6 +118,11 @@ public Socket createSocket(InetAddress address, int port, InetAddress localAddre
private Socket ensureTls(Socket socket) {
if (socket != null && (socket instanceof SSLSocket)) {
((SSLSocket) socket).setEnabledProtocols(new String[] { TLS_V_1_2 });

// Ensure hostname is validated againt the CN in the certificate
SSLParameters sslParams = new SSLParameters();
sslParams.setEndpointIdentificationAlgorithm("HTTPS");
((SSLSocket) socket).setSSLParameters(sslParams);
}
return socket;
}
Expand Down
Loading

0 comments on commit c8765af

Please sign in to comment.