-
Notifications
You must be signed in to change notification settings - Fork 13.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updater signature validation - format incompatible w/RFC8017 #6201
Comments
Just updated your title to be a little clearer what the issue is when we look at these things. While I'm not quite sure of the use case for this, it's probably better to handle things in a standardized way. A PR would be great, if you can supply one, otherwise it will get onto the backlog here and we'll track it. A transition signing menu option (ugh, another one), or a config file/ |
So, if I'm correct there are currently 4 methods to update the ESP. Below are these four methods and my suggestions on guidance to update to the new signature format. We'll have to provide two files to allow people to upgrade and use signed firmware:
Suggestions for clear names/extensions are most welcome. For now I'm using:
Serial update Web Browser OTA and HTTP Server OTA
Arduino IDE OTA Line 144 in 653f58e
Users that are calling the espota.py script manually are already selecting the signed file to upload, so these will fall into the same category as the two above. My work so far is in my branch pkcs1_fix. I'm really looking forward to your ideas and suggestions for further improvement. We could use this issue or I could create a PR, whatever suits your needs. Terms used:
|
Howdy, @qistoph . I looked quickly at your branch and it looks good so far. I didn't see the ASN.1 yet, but I imagine that's en-route. BearSSL has a reader for ASN.1, but not a writer, so we may want to consider a simple hardcoded ASN.1 wrapper with signature replacement to match the RFC requirements. For ArduinoOTA, I would not worry too much. ArduinoOTA is not a routable protocol AFAIK (or at least shouldn't be used over the internet), and since signing was only added in 2.5.2 I doubt there are any users concerned with it and signing now. Extensions seem fine, and are a minor detail. I've been working on other bits of the core recently, but look forward to seeing more updates on this. Thanks! |
Thanks for your feedback @earlephilhower! The ASN.1 verification is actually already in BearSSL. The changes in my first commit are actually really enough to make the signature check use it. Instead of NULL, now an OID is passed to br_rsa_pkcs1_sig_unpad(const unsigned char *sig, size_t sig_len,
const unsigned char *hash_oid, size_t hash_len,
unsigned char *hash_out) This part of BearSSL creates the ASN.1 part to verify against the signed data at line 89. |
Ah, got it. That's very elegant! |
* Add hash OID to signature verification (#6201) * Add legacy signing option * Describe and use the legacy option of signing.py
Closing, your PR is now merged. |
Basic Infos
Platform
Settings in IDE (although not relevant imho)
Problem Description
The signed updates code (#5213) does not correctly implement PKCS#1. This makes it harder to verify the updates in other applications, like a python script.
According to the RFC 8017 section 9.2 step 2:
Currently the signed data looks like this:
RFC 8017 step 5 says the encoded message is a concatenation of:
EM = 0x00 || 0x01 || PS || 0x00 || T
T
should be the DER of DigestInfo. In this case the DigestInfo should look like:That would encode to
EM
:The currently used version of BearSSL seems to support proper PKCS#1 signatures, with an OID.
The signing.py is executing:
openssl rsautl -sign -inkey <privatekey>
on a pre-computed hash.To create a signature with a valid PKCS#1 padded signature it should use
openssl dgst -sha256 -sign <privatekey>
on the raw binary.Changing this might require additional effort to make it backwards compatible. Old firmware will most likely not accept these new signatures. Intermediate firmware might be required that checks for the new signature format, but is signed with the old method. This might be challenging for users, though since signing updates is relatively new (Oct 2018) it is probably better to do as soon as possible, before even more people are affected.
I'm willing to look into writing a PR for this, but would first like to check if that's appreciated and what the requirements would be.
The text was updated successfully, but these errors were encountered: