WiFi password encryption during Photon claim process?

photon
Tags: #<Tag:0x00007fe21cbb3d38>

#1

Hi,

I am trying to implement setting the wifi connection (as explained here).
I am doing this in Ionic 4.

While trying to do what is suggested for nodeJs in that great article written by @rickkas7, I get into a lot of trouble.
This is what I am trying to do in Ionic 4 (which is based in Angular 8):

var keyBuf = new Buffer(key, 'hex');

var rsa = new NodeRSA(keyBuf.slice(22), 'pkcs1-public-der', {
	encryptionScheme: 'pkcs1'
});

console.log("encrypted password: " + rsa.encrypt(password, 'hex'));

that is code from wifipass.js here.

For a number of reasons, I can’t make this work today in Ionic 4 (I was able to make it work with Ionic 3, for instance).

Ionic devs are suggesting me to try to implement this using another library: WebCrypto.

What I wanted to know is this:
What are the requirements for encrypting the wifi password?
Yes, I need to use the public key provided by the Photon.
Yes, I need to encrypt it somehow before sending it to the photon.
Yes, I could reverse engineer the code above and perhaps get lucky with WebCrypto.

But what I would love to know is what are the ways I could encrypt the wifi password so it gets accepted by the photon.

Where can I find that info? Perhaps one of you or @rickkas7 know by any chance?
Thank you!
Gustavo.


#2

There is nothing special about he NodeRSA library. It just happens to be able to easily encrypt a string using pkcs1. It should be possible to do this using WebCrypto, but I don’t have an example.

What I would do is given a key and password, encode it using the wifipass.js app in node.js. Then just make a simple test program using WebCrypto and play around with it until you get the same output (hex encoded pkcs1).


#3

alright, thank you. I’ll aim at that.
However I wonder if every time I run wifipass.js would give me a different output… and that will toast the plan.

Do you remember why you did this: keyBuf.slice(22) ?

Thanks again,
Gustavo.