Skip to content

Commit

Permalink
Release of version 1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
fengsongAWS committed Jun 22, 2017
1 parent c8765af commit 5d9830b
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 35 deletions.
15 changes: 9 additions & 6 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.1.0</version>
<version>1.1.1</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.1.0</version>
<version>1.1.1</version>
</dependency>
</dependencies>
```
Expand Down Expand Up @@ -225,10 +225,10 @@ public class MyTopic extends AWSIotTopic {
}
}

String topic = "my/own/topic";
String topicName = "my/own/topic";
AWSIotQos qos = AWSIotQos.QOS0;

MyTopic topic = new MyTopic(topic, qos);
MyTopic topic = new MyTopic(topicName, qos);
client.subscribe(topic);
```

Expand Down Expand Up @@ -425,10 +425,12 @@ through the command line:
* clientId: client ID
* thingName: AWS IoT thing name (not required for the Publish/Subscribe sample)

You will also need to private either set of the following arguments for authentication.
You will also need to provide either set of the following arguments for authentication.
For an MQTT connection, provide these arguments:

* certificateFile: X.509 based certificate file
* certificateFile: X.509 based certificate file (For Just-in-time registration, this
is the concatenated file from both the device certificate and CA certificate. For more information
about Just-in-Time Registration, please see [this blog][Just-in-Time-Registration].
* privateKeyFile: private key file
* keyAlgorithm: (optional) RSA or EC. If not specified, RSA is used.

Expand Down Expand Up @@ -490,3 +492,4 @@ For any other questions about AWS IoT, contact [AWS Support][aws-support].
[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
[Just-in-Time-Registration]: https://aws.amazon.com/blogs/iot/just-in-time-registration-of-device-certificates-on-aws-iot/
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.1.0</version>
<version>1.1.1</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.1.0</version>
<version>1.1.1</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.1.0</version>
<version>1.1.1</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.1.0</version>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ private static void initClient(CommandArguments arguments) {
String privateKeyFile = arguments.get("privateKeyFile", SampleUtil.getConfig("privateKeyFile"));
if (awsIotClient == null && certificateFile != null && privateKeyFile != null) {
String algorithm = arguments.get("keyAlgorithm", SampleUtil.getConfig("keyAlgorithm"));

KeyStorePasswordPair pair = SampleUtil.getKeyStorePasswordPair(certificateFile, privateKeyFile, algorithm);

awsIotClient = new AWSIotMqttClient(clientEndpoint, clientId, pair.keyStore, pair.keyPassword);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.util.List;
import java.util.Properties;

/**
Expand Down Expand Up @@ -70,37 +71,40 @@ public static String getConfig(String name) {
}
}

public static KeyStorePasswordPair getKeyStorePasswordPair(String certificateFile, String privateKeyFile) {
public static KeyStorePasswordPair getKeyStorePasswordPair(final String certificateFile, final String privateKeyFile) {
return getKeyStorePasswordPair(certificateFile, privateKeyFile, null);
}

public static KeyStorePasswordPair getKeyStorePasswordPair(String certificateFile, String privateKeyFile,
public static KeyStorePasswordPair getKeyStorePasswordPair(final String certificateFile, final String privateKeyFile,
String keyAlgorithm) {
if (certificateFile == null || privateKeyFile == null) {
System.out.println("Certificate or private key file missing");
return null;
}
System.out.println("Cert file:" +certificateFile + " Private key: "+ privateKeyFile);

Certificate certificate = loadCertificateFromFile(certificateFile);
PrivateKey privateKey = loadPrivateKeyFromFile(privateKeyFile, keyAlgorithm);
if (certificate == null || privateKey == null) {
return null;
}
final PrivateKey privateKey = loadPrivateKeyFromFile(privateKeyFile, keyAlgorithm);

final List<Certificate> certChain = loadCertificatesFromFile(certificateFile);

if (certChain == null || privateKey == null) return null;

return getKeyStorePasswordPair(certificate, privateKey);
return getKeyStorePasswordPair(certChain, privateKey);
}

public static KeyStorePasswordPair getKeyStorePasswordPair(Certificate certificate, PrivateKey privateKey) {
KeyStore keyStore = null;
String keyPassword = null;
public static KeyStorePasswordPair getKeyStorePasswordPair(final List<Certificate> certificates, final PrivateKey privateKey) {
KeyStore keyStore;
String keyPassword;
try {
keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(null);
keyStore.setCertificateEntry("alias", certificate);

// randomly generated key password for the key in the KeyStore
keyPassword = new BigInteger(128, new SecureRandom()).toString(32);
keyStore.setKeyEntry("alias", privateKey, keyPassword.toCharArray(), new Certificate[] { certificate });

Certificate[] certChain = new Certificate[certificates.size()];
certChain = certificates.toArray(certChain);
keyStore.setKeyEntry("alias", privateKey, keyPassword.toCharArray(), certChain);
} catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | IOException e) {
System.out.println("Failed to create key store");
return null;
Expand All @@ -109,25 +113,23 @@ public static KeyStorePasswordPair getKeyStorePasswordPair(Certificate certifica
return new KeyStorePasswordPair(keyStore, keyPassword);
}

private static Certificate loadCertificateFromFile(String filename) {
Certificate certificate = null;

private static List<Certificate> loadCertificatesFromFile(final String filename) {
File file = new File(filename);
if (!file.exists()) {
System.out.println("Certificate file not found: " + filename);
System.out.println("Certificate file: " + filename + " is not found.");
return null;
}

try (BufferedInputStream stream = new BufferedInputStream(new FileInputStream(file))) {
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
certificate = certFactory.generateCertificate(stream);
final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
return (List<Certificate>) certFactory.generateCertificates(stream);
} catch (IOException | CertificateException e) {
System.out.println("Failed to load certificate file " + filename);
}

return certificate;
return null;
}

private static PrivateKey loadPrivateKeyFromFile(String filename, String algorithm) {
private static PrivateKey loadPrivateKeyFromFile(final String filename, final String algorithm) {
PrivateKey privateKey = null;

File file = new File(filename);
Expand Down
4 changes: 2 additions & 2 deletions 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.1.0</version>
<version>1.1.1</version>
</parent>
<artifactId>aws-iot-device-sdk-java</artifactId>
<dependencies>
Expand Down Expand Up @@ -38,7 +38,7 @@
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>[1.1.0,)</version>
<version>[1.1.0]</version>
</dependency>
</dependencies>
<build>
Expand Down
2 changes: 1 addition & 1 deletion 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-pom</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
<packaging>pom</packaging>
<name>AWS IoT Device SDK for Java</name>
<description>The AWS IoT Device SDK for Java provides Java APIs for devices to connect to AWS IoT service using the MQTT protocol. The SDK also provides support for AWS IoT specific features, such as Thing Shadow and Thing Shadow abstraction.</description>
Expand Down

0 comments on commit 5d9830b

Please sign in to comment.