Conversation
e1f509f to
04f118e
Compare
apritzel
left a comment
There was a problem hiding this comment.
Hi James, thanks for the contribution, TOC0 was indeed some kind of blind spot for the tool.
However this patch is quite massive, can you possibly split this up? If you have any fixes (PREFIX default) or refactorings, they come first. Then I'd see one patch that just extents the reporting of the TOC0 header and items, without the validation parts. That's a nice extra, but ideally I'd make this optional, to avoid the OpenSSL dependency.
Some first comments inside, in general please adhere to kernel coding style, and allow streaming data, so no backward seeks.
Makefile
Outdated
| CFLAGS=-Wall -g -O | ||
| PREFIX ?=/usr/local | ||
| CFLAGS=$(shell pkg-config --cflags openssl) -Wall -g -O | ||
| LDFLAGS=$(shell pkg-config --libs openssl) -lfdt |
There was a problem hiding this comment.
Can we please make this OpenSSL dependency optional somehow? I like to keep a statically compiled version around, and verifying TOC0 images is quite a niche use case, so I don't think this justifies this dependency.
There was a problem hiding this comment.
Can we please make this OpenSSL dependency optional somehow?
Yeah, let me see how best to do that.
I like to keep a statically compiled version around, and verifying TOC0 images is quite a niche use case, so I don't think this justifies this dependency.
I don't think this prevents statically linking openssl right? I think in general this is a bit of a niche tool so I'm not sure how important it would be to make a common dependency like OpenSSL optional.
Makefile
Outdated
| PREFIX ?=/usr/local | ||
| CFLAGS=$(shell pkg-config --cflags openssl) -Wall -g -O | ||
| LDFLAGS=$(shell pkg-config --libs openssl) -lfdt | ||
| PREFIX ?= /usr/local |
There was a problem hiding this comment.
That's indeed fixing an omission, but can you put this in a separate patch, please?
There was a problem hiding this comment.
The prefix? I'm not sure what you're referring to.
| #include <unistd.h> | ||
| #include <errno.h> | ||
| #include <openssl/sha.h> | ||
| #include <openssl/core_names.h> |
There was a problem hiding this comment.
This is an OpenSSL3 header file, thus breaks compilation on older installations. Officially 1.1.1 is obsolete, but there are maintained packages of that, with backports. And I'd appreciate if you don't break the build on my Slackware 15.0 installation (shipping 1.1.1zb) ;-)
U-Boot's mkimage manages to get away with an 1.1.1 subset of functions as well, so can you please refrain to use only functions and features that both versions support?
There was a problem hiding this comment.
If we make openssl optional then this isn't a major concern right?
sunxi-toc0.c
Outdated
| } totalSequence; | ||
| }; | ||
|
|
||
| static inline bool is_rsa_pubkey_tag(const uint8_t *buf) { |
There was a problem hiding this comment.
Kernel coding style please, so opening brackets for functions on a new line. And inline is not useful here, please remove.
| uint32_t *buf = (uint32_t *)buff; | ||
| uint32_t sum = BROM_STAMP_VALUE; | ||
| for (uint32_t i = 0; i < length / 4; ++i) | ||
| sum += buf[i]; |
sunxi-toc0.c
Outdated
| } | ||
|
|
||
| static int verify_signature(const uint8_t *sig, size_t sig_len, | ||
| const uint8_t *tbs, size_t tbs_len, |
There was a problem hiding this comment.
Please observe kernel indentation rules and 80 columns, if possible.
There was a problem hiding this comment.
Ran this through clang-format with kernel style configs.
sunxi-toc0.c
Outdated
|
|
||
| bld = OSSL_PARAM_BLD_new(); | ||
| if (!bld || | ||
| !OSSL_PARAM_BLD_push_BN(bld, "n", BN_bin2bn(mod, mod_len, NULL)) || |
There was a problem hiding this comment.
kernel indentation style please: so line continuation vertically aligned with the opening bracket, so that the body of the function sticks out because of the different alignment.
sunxi-toc0.c
Outdated
| } | ||
|
|
||
| int output_toc0_info(void *sector, FILE *inf, FILE *outf, bool verbose) { | ||
| fseek(inf, 0, SEEK_END); |
There was a problem hiding this comment.
Sorry, but this is breaking an assumption this tool makes: the input data could be a stream, for instance from a piped decompressor (xz -cd foo.img.xz | sunxi-fw info), so no absolute seeks. There is pseek() if you need to skip some bytes.
There was a problem hiding this comment.
Yeah, I guess I can probably just use the size pulled from the header instead.
sunxi-toc0.c
Outdated
| if (file_size <= 0) | ||
| return -EINVAL; | ||
|
|
||
| uint8_t *toc0_data = malloc(file_size); |
There was a problem hiding this comment.
Please gather all variable declarations at the beginning of the function. If you find this too far away, consider splitting up the function.
d081142 to
80c19d7
Compare
It's handy to be able to extract and compute everything needed to calculate the rotpk from toc0 for validating that images are being generated correctly.
80c19d7 to
b2ac8ee
Compare
I think the PREFIX default was already set on a different line wasn't it? There wasn't really much code here so there's not really much refactoring.
It's a bit tricky to split up further IMO, I mean already this is just an initial attempt at parsing some of the values out, there's still a lot needed to fully parse these toc0 files AFAIU. |
It's handy to be able to extract and compute everything needed to calculate the rotpk from toc0 for validating that images are being generated correctly. Probably not everything is being computed correctly but it does look like the rotpk hash at least is correct.
Example output: