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?