1

Im trying to figure out how to use the mqtt broker in my android application with the AWS IoT Java SDK (https://github.com/aws/aws-iot-device-sdk-java). I know that there is an Android SDK but there are specific issues which are not part of this question. So my question is if its possible to use the Java code snippet in Android. Is there a way to have the file path of the certificate and keystore as String

String clientEndpoint = "XXXX.amazonaws.com";
String clientId ="XXX-" + System.currentTimeMillis();  
String certificateFile = "/my/path/XXXX-certificate.pem.crt";
String privateKeyFile = "/my/path/XXXXX-private.pem.key";

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

AWSIotMqttClient mqttclient = new AWSIotMqttClient(clientEndpoint, clientId, 
pair.keyStore, pair.keyPassword);

mqttclient.connect();

To get keystorePasswordPair the filepath is used like that in the SampleUtil class:

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

The loadCertificateFromFile method generates a File with the filename (certificateFile) as String and obviously the file is not found because of an invalid filepath :

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

    try (BufferedInputStream stream = new BufferedInputStream(new FileInputStream(file))) {
        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 null;
}

Is there a way to make this work if i store the files in raw,assets or on any other place?

hardillb
  • 54,545
  • 11
  • 67
  • 105
King Bufo
  • 181
  • 1
  • 13
  • try using this way https://stackoverflow.com/questions/15912825/how-to-read-file-from-res-raw-by-name and let me know – varnit Jan 04 '19 at 16:12
  • 1
    I work on the AWS Mobile SDK team and am curious about what issues are preventing you from using the Android IOT SDK. It will be fantastic if you could open those as issues in the github repository or share them here with me and I'll get those issues created, that way they can be properly addressed and help you and other developers.. – Bommas Jan 23 '19 at 14:22
  • hi @Bommas, can I have the link of the SDK? – Rafael Pereira Ramos Nov 08 '20 at 21:40

0 Answers0