Closed Krieke closed 8 years ago
//begin module /**
@access public */ module.exports = function(options) {
// verify certificate paths if (isUndefined(options.keyPath) && isUndefined(options.privateKey)) { throw new Error(exceptions.NO_KEY_OPTION); } if (isUndefined(options.certPath) && isUndefined(options.clientCert)) { throw new Error(exceptions.NO_CERT_OPTION); } if (isUndefined(options.caPath) && isUndefined(options.caCert)) { throw new Error(exceptions.NO_CA_OPTION); } // // Certificates and private keys may be passed in files using options // ending in 'Path', e.g. 'keyPath', 'certPath', and 'caPath'. In addition, // they can also be passed in as buffers or files using the options // 'privateKey', 'clientCert', and 'caCert'. This second set is the one // that the AWS Console generates a JSON configuration document for. // if (!isUndefined(options.caCert)) { if (Buffer.isBuffer(options.caCert)) { options.ca = options.caCert; } else { ## if (filesys.existsSync(options.caCert)) { options.ca = filesys.readFileSync(options.caCert); } else { throw new Error(exceptions.INVALID_CA_CERT_OPTION); } } }
fs.exists(path, callback)# Added in: v0.0.2 Deprecated since: v1.0.0 Stability: 0 - Deprecated: Use fs.stat() or fs.access() instead.
First thought, since the browser can't access local files, you may want to put the key/certs in buffers and include them in the bundle, or (preferably) use Cognito authentication just like all of the browser examples .
@rongsaws : i think it is related to a deprecate function.... it doesn't recognize it as a function at the moment...I am running in all in plain javascript that is perfectly capable of accessing the local file system.
Daniel Vangrieken
Email : daniel.vangrieken@gmail.com Phone: +32 (0) 476 / 99 65 61
2016-07-20 21:00 GMT+02:00 rongsaws notifications@github.com:
First thought, since the browser can't access local files, you may want to put the key/certs in buffers and include them in the bundle, or (preferably) use Cognito authentication just like all of the browser examples .
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/aws/aws-iot-device-sdk-js/issues/76#issuecomment-234048040, or mute the thread https://github.com/notifications/unsubscribe-auth/AS4X3nDnkgT7C69VNkFNkPmC2MQ9awr4ks5qXnBkgaJpZM4JQ78y .
Are you not running your script in browser?
Yes... sorry for the confusion. But supporting "window.File, window.FileReader. I started with buffering, but maybe I just should go directly to Cognito authentication. Actually : I will try both
Daniel Vangrieken
Email : daniel.vangrieken@gmail.com Phone: +32 (0) 476 / 99 65 61
2016-07-20 21:22 GMT+02:00 rongsaws notifications@github.com:
Are you not running your script in browser?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/aws/aws-iot-device-sdk-js/issues/76#issuecomment-234054112, or mute the thread https://github.com/notifications/unsubscribe-auth/AS4X3qgvcKIgdvMKeeYqOhxT3DDjPNxrks5qXnWFgaJpZM4JQ78y .
I don't think Browserify transforms fs to HTML5 local file APIs, yet. In the mean time, using Cognito or passing cert buffers through the parameters below is probably your best bet.
clientCert: same as certPath, but can also accept a buffer containing client certificate data
privateKey: same as keyPath, but can also accept a buffer containing private key data
caCert: same as caPath, but can also accept a buffer containing CA certificate data
Hey rongsaws : any javascript tips on creating these buffers?
Would something like this work for you?
C:\Users\rongs>node --version
v4.4.3
C:\Users\rongs>node
> var cert = new Buffer('--begin certificate-- ab...cd --end certifcate--');
undefined
> Buffer.isBuffer(cert)
true
Actually not : I have a plain javascript project and this Buffer is part of the nodejs package "buffer.js". Also we can't use Cognito authentication since for privacy law we can only make use of Frankfurt which currently is not supporting this service. So my only option left here is to make this buffer mechanism work otherwise this PoC becomes not a success for our customers.
Wouldn't Browserify transform buffer.js into the bundle too? It should work.
@rongsaws : I indeed can use the buffer.js with browserify, but then I have to browserify my own app code as well which I actually didn't want to do (Ok maybe I am overlooking something, but the whole nodejs stuff is fairly new to me being a C developer and trying to prototype a plain javascript app asap. On the aws-iot-device-sdk bundle I could just depend by adding require in my main script since this was exported by the aws....bundle. But HOW DO I DO THIS for buffer = A NICE example would be welcome
By the way : when providing the keys in a buffer (I managed due to read above moving my whole project in a bundle) it still will not work via a browser since you still trigger these lines of code :
Lines 157 - 174 (in the browserified aws bundle). // Parse PEM files. Options ending in 'Path' must be files // and will override options which do not end in 'Path'.
if (filesys.existsSync(options.keyPath)) { options.key = filesys.readFileSync(options.keyPath); } else if (!isUndefined(options.keyPath)) { throw new Error(exceptions.INVALID_KEY_PATH_OPTION); } if (filesys.existsSync(options.certPath)) { options.cert = filesys.readFileSync(options.certPath); } else if (!isUndefined(options.certPath)) { throw new Error(exceptions.INVALID_CERT_PATH_OPTION); } if (filesys.existsSync(options.caPath)) { options.ca = filesys.readFileSync(options.caPath); } else if (!isUndefined(options.caPath)) { throw new Error(exceptions.INVALID_CA_PATH_OPTION); }
So the conclusion is that based on this sdk everyone with a browser have to modify the code or use Cognito authentication which we can't since we can only use Frankfurt region.
I first had to read the documentation: apperently AWS only support mqtt over wss. I thought that with the modern browser raw tcp protocol was also implemented in the sdk so mqtt over tcp could be supported. So the buffering is not required anymore and the above remark about hitting this code can also be ignored.
This topic issue can be closed... unless you guys want to provide support in browsers for mqtts via tcp ;-)
Since you are doing a prototype, instead of using Cognito, you could use IAM key and credential to initialize your Websocket connection. Browserifying TSL connection is currently not supported unfortunately, so you may want to stick with the Websocket solution for browser applications for now.
Indeed... I currently got my prototype working... with WSS. So I am pubbing as a device, as a thingshadow and reading the last state via REST... this will do for my current PoC
Thx for responding.
Next step will be to write a more advance app using Angular + Ionic. : will see when I have the time to dive in to this... at least this has a lower priority since I have a bunch of other tasks to do.
Regards,
Daniel
Daniel Vangrieken
Email : daniel.vangrieken@gmail.com Phone: +32 (0) 476 / 99 65 61
2016-07-23 2:23 GMT+02:00 rongsaws notifications@github.com:
Since you are doing a prototype, instead of using Cognito, you could use IAM key and credential to initialize your Websocket connection. Browserifying TSL connection is currently not supported unfortunately, so you want to stick with the Websocket solution for browser applications for now.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/aws/aws-iot-device-sdk-js/issues/76#issuecomment-234686712, or mute the thread https://github.com/notifications/unsubscribe-auth/AS4X3uWGReaB1QSRWKS95uHLOYO9LcWhks5qYV8XgaJpZM4JQ78y .
I've created an app using create-react-app and installed aws-iot-device-sdk. Now I am trying use this sdk in browser environment and getting the same issue. Then I went through the docs and generated browser bundle for this sdk and added that js file in public/index.html. No luck, still getting the issue. Any inputs to get rid of this issue
Anybody has solved this question ?
i am also getting same problem how can i solve this issue pls tell me
I posted a question regarding the same issue on another open post here:
Using the aws-iot-sdk-browser-bundle.js (browsery of node.js aws-iot-device-sdk module);