|
24 | 24 | # You should have received a copy of the GNU General Public License |
25 | 25 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
26 | 26 |
|
27 | | -__version__ = "0.3.1" |
| 27 | +__version__ = "0.3.2" |
28 | 28 | __author__ = "Freek van Tienen, Jan Dumon, Mefistotelis @ Original Gangsters" |
29 | 29 | __license__ = "GPL" |
30 | 30 |
|
@@ -824,7 +824,7 @@ def imah_read_fwsig_head(po): |
824 | 824 | minames = minames_s.split(' ') |
825 | 825 | pkghead.chunk_num = len(minames) |
826 | 826 | pkghead.header_size = sizeof(pkghead) + sizeof(ImgChunkHeader)*pkghead.chunk_num |
827 | | - pkghead.signature_size = 256 |
| 827 | + pkghead.signature_size = 384 # Depends on auth key length - just storing plausible value now |
828 | 828 | pkghead.update_payload_size(0) |
829 | 829 |
|
830 | 830 | del parser |
@@ -933,13 +933,19 @@ def imah_unsign(po, fwsigfile): |
933 | 933 | print("Computed header checksum 0x{:08X} and digest:\n{:s}" |
934 | 934 | .format(checksum_enc, ' '.join("{:02X}".format(x) for x in header_digest.digest()))) |
935 | 935 |
|
936 | | - if pkghead.signature_size != 256: # 2048 bit key length |
| 936 | + # 2048 bit key (and therefore signature) length - used since introduction of IMaH until 2022 (header_ver=1,2) |
| 937 | + # 3072 bit key (and therefore signature) length - used since wm260,zv900 in 2022 (header_ver=2) |
| 938 | + if pkghead.signature_size != 256 and pkghead.signature_size != 384: |
937 | 939 | raise_or_warn(po, ValueError("Signed image file head signature has unexpected size.")) |
938 | 940 | head_signature = fwsigfile.read(pkghead.signature_size) |
939 | 941 | if len(head_signature) != pkghead.signature_size: |
940 | 942 | raise EOFError("Could not read signature of signed image file head.") |
941 | 943 |
|
942 | 944 | auth_key = imah_get_auth_params(po, pkghead) |
| 945 | + |
| 946 | + if (auth_key.size_in_bytes() != len(head_signature)): |
| 947 | + raise_or_warn(po, ValueError("Image file head signature does not match the length of auth key.")) |
| 948 | + |
943 | 949 | try: |
944 | 950 | if pkgformat >= 2018: |
945 | 951 | mgf = lambda x, y: pss.MGF1(x, y, SHA256) |
@@ -1117,6 +1123,9 @@ def imah_sign(po, fwsigfile): |
1117 | 1123 | else: |
1118 | 1124 | chunk = imah_read_fwentry_head(po, i, miname) |
1119 | 1125 | chunks.append(chunk) |
| 1126 | + # Figure out signature length |
| 1127 | + auth_key = imah_get_auth_params(po, pkghead) |
| 1128 | + pkghead.signature_size = auth_key.size_in_bytes() |
1120 | 1129 | # Write the unfinished headers |
1121 | 1130 | fwsigfile.write(bytes(pkghead)) |
1122 | 1131 | for chunk in chunks: |
@@ -1260,7 +1269,6 @@ def imah_sign(po, fwsigfile): |
1260 | 1269 | print("{}: Computed header digest:\n{:s}".format(fwsigfile.name, |
1261 | 1270 | ' '.join("{:02X}".format(x) for x in header_digest.digest()))) |
1262 | 1271 |
|
1263 | | - auth_key = imah_get_auth_params(po, pkghead) |
1264 | 1272 | if not hasattr(auth_key, 'd'): |
1265 | 1273 | raise ValueError("Cannot compute image file head signature, auth key '{:s}' has no private part." |
1266 | 1274 | .format(pkghead.auth_key.decode("utf-8"))) |
|
0 commit comments