get SHA1 hash #545
Replies: 37 comments
-
Posted at 2015-10-20 by @gfwilliams There's a bug open for it here - while you could hack something up in JS you'd basically be creating your own web server from scratch. It's much better if it's built into the Espruino firmware itself. I pasted some code there that does most of what's needed to enable WebSockets, minus the SHA1. However, there's also a branch (AES) on GitHub which contains |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-22 by sameh.hady I am actually working on adding it to the ws module, yes it is a 1 big function and still trying to figure out how to save memory. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-22 by @gfwilliams Do you actually need it for on the client side? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-22 by sameh.hady No, I thought I would extend the ws module and make it cover both the client and server. So we can use it like:
And thats why I wanted a way to only require the sha1 function if I am creating a server but for the client I really don't need it. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-22 by @gfwilliams As I'd said above, it'd be much better if someone could actually just build this into Espruino, in C. It'd be faster and would use much less memory. While you can do a server in JS, if you're planning on making it serve up webpages too (which you'll have to if using Pico+ESP8266 because you can only have one webserver at a time), you'd have to implement your own HTTP server in JS and not use Espruino's own one. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-22 by @gfwilliams At the very least I'd create a new module called |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-22 by sameh.hady yup i guess that will be my only choice, since I am not good in C i am trying my best to implement it with js. I guess for now we can have 2 modules ws & wss |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-23 by JumJum @sameh.hady, may be we can share our experience. Base is the same, since my knowledge of C is poor. May be waiting for somebody adding a server to Espruino, as suggested by @gordon, would be a better way. But at least I learned a lot around datahandling with sockets ;-)
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-23 by sameh.hady Nice work @jumjum, in my case I've used a longer Sha1 function which I couldn't include in ESP8266 because of its memory limit. So I couldnt test it actually till now. For the keep alive all what you need is sending the ping message to the clients on interval and also pong pack if the client sent a ping. In my ws client I found that the server was not sending me any pings and thats why I made the client keep the connections alive by sending ping requests to the server and wait for it's pong. Is there any difference between net.createServer & http.createServer? I thought it is better to use the net one. I will try your code when I am back home and will let you know |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-23 by @gfwilliams
To be honest, if @jumjum's code can use the built in HTTP server that's awesome, and I take back everything I said about the JS implementation :) it might actually be the best way to do it if you can use the existing HTTP server with it. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-23 by JumJum @gordon is right, I used the HTTP server to get headers parsed. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-23 by @gfwilliams Wow, |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-23 by sameh.hady in websockets you need to convert string to sha1 then to hex then base64 this hex
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-23 by @gfwilliams Instead of |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-23 by sameh.hady make sense :D everyday learning something new. still the sha1 function is dang big and in both ways will consume lots of memory. Funny part is I had an idea to make an http request from Espruino to a php page to get the encoded string directly. I guess this would consume way less memory :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-25 by sameh.hady Actually I do think this option is the best one so far, I am into doing a POC to see how will it work |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-25 by @allObjects Cool...embedded objects are better than sepeate to install plug-ins / extension - and they are safe as long as they are signed... I guess that - and the perforance in the early days - made them rarely appear. Since applets have full access to all resources and therefore have to prompt the user for permission, it is still something that meddles with the user's trust. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-29 by d0773d @gordon would something like https://libwebsockets.org/index.html work? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2015-10-29 by @gfwilliams @d0773d I'm not sure that would really help... The majority of the work would just be getting WebSockets to work with a JS API - as all the header parsing and connection stuff is already part of Espruino. As I posted right at the top or this thread, there's a bug open for support where I pasted the code that basically sets up the server side of this. All it needs is the SHA1 hash - which is part of mbedtls in the AES branch on GitHub. The whole thing can also be developed and tested under Linux. It shouldn't be a lot of work, what it needs is for someone to write some C code - but it looks like that person might end up being me. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-02-11 by Wilberforce I've managed to get web sockets working using @jumjum 's js implementation from here: It would be great to get SHA1 function into the core. I've attempted to build the crypto module for the esp8266, however get build errors (sorry can't recall what they were specifically) I wondering if the hashlib library would be a good place to add the sha1 function, so then the ws.js could use this rather than rely on crypto? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-02-11 by @gfwilliams Which board are you doing this on? The Pico would 'just work'.
It is in the core though. You just need the crypto library to be built in.
Seriously, just figure out why mbedtls library isn't building (I guess this is for ESP8266?) rather than just duplicating something that already exists and works fine. I'm planning to remove Perhaps one issue is that you only want SHA1 and not AES/etc - but that could be tweaked with some ifdefs pretty easily. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-02-12 by Wilberforce I'm trying to build crypto for esp8266.
The issue appears to be the flash_str #define:
static char name[] vs const char * Is there a simple way to resolve this? I'm not sure the protocol here - should I raise as a github issue? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-02-15 by @gfwilliams It looks like you have? it's probably best to discuss build-related stuff in there... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-02-15 by Wilberforce Yes - I did raise it on github -I thought I would document what I had discovered while it was fresh. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-02-25 by Wilberforce I've written a crypto module to use on boards without the crypto module in firmware - it implements the SHA1 used by the web sockets module. The ws module does not need to be modified. For testing if the crypto.js file is copied down to a web ide project it can be tested. The following code assumes the ESP8266 has a wifi.save and is connected to a network.
Start a browser at your Eps8266 address and see: If you click the button, you can see the event appear in the Web IDE console. Every 2nd click causes the server to send back to the browser.... two way socket! https://github.com/wilberforce/EspruinoDocs/blob/master/modules/crypto.js For clarity, this the code that gets sent to the browser, using a CDN to get the bootstrap css:
Attachments: |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-02-25 by @gfwilliams Nice - thanks for posting it up! We just need to find a nice way of adding it such that it doesn't interfere with the in-built crypto library on other boards. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-02-25 by Wilberforce Sure. I was hoping that a require("crypto") would look for a native install first, and then look in modules on espruino site. Does it not work this way? The other thing I tried and could quite pull off was using a require("path to github raw") and then attempted to add that to the modules cache, so that a later require("crypto") would find the module already loaded. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-02-25 by @gfwilliams
Yes - it should do this, but it needs a bit of tweaking on my side first as currently the list of internal modules reported by espruino.com isn't entirely accurate.
You could probably do something really hacky by modifying the module cache directly:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-03-20 by user63214 Works great! Thanks! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-03-28 by Wilberforce I've managed to get the sha functions compiling on the esp8266 build, by disabling the aes functions. I'll get that up on github and do a pull request. Then this can be part of the esp8266 core, with little additional overhead on the current build... |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2015-10-19 by JumJum
Just playing around a bit with websockets.
I wonder if there is a way to create a websocket server on Espruino.
Right now my problem is to calculate SHA1-hash from a given Sec-WebSocket-Key, to initiate a connection between client and server.
There are some sources available, but it would take away a lot of available memory.
Beta Was this translation helpful? Give feedback.
All reactions