PEM/DER certificate and key related functions in the public mongoose.h API #3635
|
Hi, I am searching for help on how to use the function
Is there a way to load the needed key and keysz data from an EC PRIVATE KEY pem certificate using only the mongoose API, or am I heading into the wrong direction with this? All crypto related functions implementing MG_TLS_BUILTIN seem to be declared static. My use case is creating a JWT Authorization: Bearer HTTP header. Currently I see no other way of loading the private key from a PEM file using a 3rd party library like OpenSSL. Mainly what mg_tls_init does when setting up certificates and keys in struct tls_data but using the public mongoose.h API. Any pointers highly appreciated. Thanks, |
Replies: 4 comments 9 replies
|
tls_builtin is not a general purpose library but TLS 1.3 support for Mongoose. Some functions are not static, but don't have a documented public API because we didn't intended them to be user callable. mg_hmac_sha256() is in the SHA256 module and is not publicly documented. Given the current "trend" on super security for everything, we might see the need to create an API for other types of HTTP authentication... maybe. As long as your case can be done with the building blocks we have, I can try to guide you. I guess some of the current stuff has to be moved to a function that can be called from within its current place and this new authentication helper. |
|
Seems all functionality is already there. Having a way to load keys and certificates over a stable API seems to be the only "missing" link to make use of the internal uecc as is without having to write a bunch of boilerplate code. I haven't had the time to read the sources in detail but am having a working demo showing what I am heading for. The internal uecc has this comment A correct RNG function is set by default when... Mongoose does not seem to follow that, so I added an additional step during initialization to set that up like: For an easy way to test things I removed the 'static' qualifier from function to have a way to load an EC private key from a PEM file quickly. So loading the key currently looks as ugly like The final JWT can then be created like using a base64 wrapper function for URI encoding Having a way to just load a key from whatever format is provided (like in mg_tls_init) really seems the only thing needed. Not sure if this is of general interest, though. |
|
When I looked at that branch it was in sync with master without any changes. I now had time to look at it. You did all of that in just a couple of hours? Wow. Some notes. Function Looking at that section others may need other values as well. Adding a |
|
Looks great and aligns nicely with mg_tls_opts. I just replaced a former function creating the jwt message based on OpenSSL to one based on this API. It reduces the lines of code from 168 to 15 including error handling. Neat. Well done. Thanks a lot. |
Wow, that's quite cool and considerate, thank you !
In my defense, actually, I meant to ask for the application itself, a brief overview on why JWT Bearer Authentication. Thanks a lot, this is great, they'll love it !
BTW, the branch has turned into a PR, #3642, and its being reviewed, possibly making it into 7.23