Attention is currently required from: Hoernchen, laforge.
Patch set 1:Code-Review +1
8 comments:
Patchset:
I have already put a lot of comments. I now carefully looked through the command packet encoder/decoder. To me it looks correct. I found no mistake, but with all those magic numbers the code is very hard to follow. I suggest to add some constants and if necessary rephrase to code so that it becomes more obvious what already happens.
Other than that, I see no further problems. Even though I didn't look at the response packet/encoder I am confident that those are bug-free too.
File pySim/ota.py:
Patch Set #1, Line 745: RPI = 0x02
maybe put a
```
# TS 102 225, section 6
```
comment behind CPI and RPI for the sake of completeness?
Patch Set #1, Line 782: padding = otak.crypt._get_padding(6 + len_sig + len(apdu), otak.crypt.blocksize)
Here we have a hardcoded length of 6.
As far as I understand this is the CNTR (5 octets) plus PCNTR (1 octet)
Patch Set #1, Line 788: cnt = otak.cntr.to_bytes(5, 'big') + bytes([pad_cnt])
Here you convert the counter value (CNTR) to bytes (5). And you append the pad_cnt, which holds the number of padding bytes.
I think this is a bit hard to follow. Maybe it makes sense to define a constant for the PCNTR length. Then use this constant here and above where the padding is calculated. Otherwise it may be hard to grasp from where those numbers come from.
(you also have different names for CNTR and PCNTR, maybe it makes sense to rename pad_cnt to pcntr? Maybe calculate the length of otak.cntr in one line and assign the result to a variable called cntr and then do the sum. I don't know. but I think this would be easier to understand.
(just ideas for possible improvements)
Patch Set #1, Line 790: cpl = len(bertlv_encode_len(chl)) + chl + len(apdu) # CHI (absent) .. end of data
I think you should put comments and a spec ref everwhere where the CHI (RHI) is absent, people who are not familiar with this detail may think that this is a bug.
(I see its mentioned in the apidoc above, but you know, people might overread this...)
Patch Set #1, Line 801: raise ValueError('Unexpected CPI 0x%02x' % encoded[0])
maybe extend this a bit with "..., was expecting CPI" and then you output self.CPI. I find it very helpful when programs output such hints. In particular when I debug systems I am not so familiar with.
(same for the response)
Patch Set #1, Line 806: hdr_len = 7
this is SPI(2) + KIc(1) + KID(1) + and TAR(3)
I think it would be good if you would define some constants for those fixed length and use those. Those magic numbers make it very difficult to follow...
Patch Set #1, Line 816: raise ValueError('CHL %u does not match SPI' % chl)
we have a lot of 6s there. But its actually 5+1 (PCNTR+CNTR), this is hard to read...
To view, visit change 43717. To unsubscribe, or for help writing mail filters, visit settings.