From 5d9830bb21d167eea995dcad38e77ad6835adc7e Mon Sep 17 00:00:00 2001 From: fengsongAWS Date: Thu, 22 Jun 2017 23:17:18 +0000 Subject: [PATCH] Release of version 1.1.1 --- README.md | 15 +++--- aws-iot-device-sdk-java-samples/pom.xml | 4 +- .../samples-pom.xml | 4 +- .../sample/pubSub/PublishSubscribeSample.java | 1 + .../client/sample/sampleUtil/SampleUtil.java | 46 ++++++++++--------- aws-iot-device-sdk-java/pom.xml | 4 +- pom.xml | 2 +- 7 files changed, 41 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index a0ca42916f..356baa8615 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ of your Maven project. com.amazonaws aws-iot-device-sdk-java - 1.1.0 + 1.1.1 ``` @@ -88,7 +88,7 @@ The sample applications included with the SDK can also be installed using the fo com.amazonaws aws-iot-device-sdk-java-samples - 1.1.0 + 1.1.1 ``` @@ -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); ``` @@ -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. @@ -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/ diff --git a/aws-iot-device-sdk-java-samples/pom.xml b/aws-iot-device-sdk-java-samples/pom.xml index 5305ac6ec4..1de6a8fe52 100644 --- a/aws-iot-device-sdk-java-samples/pom.xml +++ b/aws-iot-device-sdk-java-samples/pom.xml @@ -3,14 +3,14 @@ com.amazonaws aws-iot-device-sdk-java-pom - 1.1.0 + 1.1.1 aws-iot-device-sdk-java-samples com.amazonaws aws-iot-device-sdk-java - 1.1.0 + 1.1.1 diff --git a/aws-iot-device-sdk-java-samples/samples-pom.xml b/aws-iot-device-sdk-java-samples/samples-pom.xml index 3c6527665e..1b0b60af55 100644 --- a/aws-iot-device-sdk-java-samples/samples-pom.xml +++ b/aws-iot-device-sdk-java-samples/samples-pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.amazonaws aws-iot-device-sdk-java-samples - 1.1.0 + 1.1.1 org.apache.maven.plugins @@ -12,7 +12,7 @@ com.amazonaws aws-iot-device-sdk-java - 1.1.0 + 1.1.1 com.fasterxml.jackson.core diff --git a/aws-iot-device-sdk-java-samples/src/main/java/com/amazonaws/services/iot/client/sample/pubSub/PublishSubscribeSample.java b/aws-iot-device-sdk-java-samples/src/main/java/com/amazonaws/services/iot/client/sample/pubSub/PublishSubscribeSample.java index 4713444e14..4ee4e1623a 100644 --- a/aws-iot-device-sdk-java-samples/src/main/java/com/amazonaws/services/iot/client/sample/pubSub/PublishSubscribeSample.java +++ b/aws-iot-device-sdk-java-samples/src/main/java/com/amazonaws/services/iot/client/sample/pubSub/PublishSubscribeSample.java @@ -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); diff --git a/aws-iot-device-sdk-java-samples/src/main/java/com/amazonaws/services/iot/client/sample/sampleUtil/SampleUtil.java b/aws-iot-device-sdk-java-samples/src/main/java/com/amazonaws/services/iot/client/sample/sampleUtil/SampleUtil.java index e11dca30fb..0cae498fb6 100644 --- a/aws-iot-device-sdk-java-samples/src/main/java/com/amazonaws/services/iot/client/sample/sampleUtil/SampleUtil.java +++ b/aws-iot-device-sdk-java-samples/src/main/java/com/amazonaws/services/iot/client/sample/sampleUtil/SampleUtil.java @@ -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; /** @@ -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 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 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; @@ -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 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) 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); diff --git a/aws-iot-device-sdk-java/pom.xml b/aws-iot-device-sdk-java/pom.xml index 427e5ef29f..f0395aed92 100644 --- a/aws-iot-device-sdk-java/pom.xml +++ b/aws-iot-device-sdk-java/pom.xml @@ -3,7 +3,7 @@ com.amazonaws aws-iot-device-sdk-java-pom - 1.1.0 + 1.1.1 aws-iot-device-sdk-java @@ -38,7 +38,7 @@ org.eclipse.paho org.eclipse.paho.client.mqttv3 - [1.1.0,) + [1.1.0] diff --git a/pom.xml b/pom.xml index 9d5469bcfd..3d4ae791d0 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.amazonaws aws-iot-device-sdk-java-pom - 1.1.0 + 1.1.1 pom AWS IoT Device SDK for Java 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.