Apple and iPods are not as Evil as people think ?

Via Adriana’s furl, I found a slightly hysterical-in-an-unfunny-way Boing-Boing posting which linked to an original blog post – the latter being a blog with only two postings.

The paragraphs below are from the Boing-Boing posting; my mental responses to the paragraphs are infix and bold.

The latest iPods have a cryptographic “checksum” in their song databases that prevents third-party applications from synching with the portable music players.

Hmmm, okay…

This means that iPods can no longer be used with operating systems where iTunes doesn’t exist — like Linux, where gtkpod and Amarok are common free tools used by iPod owners to load their players.

Errr… but a cryptographic checksum can’t do that without a nonce which will be en-clair in iTunes, and someone will rip that out with a debugger, so what’s the problem? Do you know the difference between a cryptographic checksum, an HMAC, and a signature?

Notice that this has nothing to do with piracy — this is about Apple limiting the choices available to people who buy their iPod hardware.

Errr… if they were embedding private certificates in players and then signing the databases with a public key, then I would agree. To me this just sounds like worrying about on-disk database corruption.

The new hardware limits the number of potential customers for Apple’s products, adding engineering cost to a device in order to reduce its functionality.

Um… Bullshit?

…and lo and behold, on the original complaining blog, is a self-congratulatory back-slapping followup dated today.

Indeed, it is posting :

Thanks to some inspired work by a few heroes, we’ve managed to work out how to get everything working again.

This is what we’ve found out: the hash at 0x58 is the one that matters. And we know how to generate it.

It’s a cryptographic signature combining data from the iTunesDB and a device specific identifier (called the firewireid) and some (formally) secret numbers.

Instructions for linux users on how to fix their iTunesDB files are here. Windows users are going to have to wait a little while. (For interested programmers, the code to generate the hash is here.)

The heroes in question include wtbw, nopcode, teuf, simon and many others from #gtkpod.

Let’s all hope that (if they haven’t already from the iPhone unlocking) Apple learn that fighting against us is pointless. It’s a waste of their time if the open source crowd is going to get past it in just a weekend.

…or, as I read it “we finally worked out how to use a debugger and reverse-engineered this change to the database format; next time maybe Apple will warn us when they have the temerity to change their own proprietary software like iTunes, so that we don’t have to think so hard”.

If it’s SHA-1, well for god’s sake it’s only the world’s defacto standard hash algorithm. Perhaps you can bitch at Apple for not publishing their iTunes database format as a RFC, or something like that, but you can’t blame them for modifying their own code.

And the manner in which the ipodminusitunes.blogspot.com crowd are painting this is right up there in my mind with “now you see the violence inherent in the system, help, help, i’m being repressed.”

People who don’t know how to drive crypto, shouldn’t throw PR stones.

Comments

10 responses to “Apple and iPods are not as Evil as people think ?”

  1. Anoher possible use for a SHA1-HMAC here is to help identify a given db to a device to support multiple hosts/users/devices.

  2. […] Apple for their atrocious behaviour over ringtones, but that does not extend to complaining about tweaking the iTunes database format) Posted by alecm on Tuesday, September 18, 2007, at 18:44, and filed under Uncategorized. Follow […]

  3. wtbw

    As the commenter above mentioned, it was using standard HMAC SHA-1 on the database, but with a complex proprietary key generation based on the iPod FireWireGUID. While I understand the potential uses of hashing the database, and potentially even of doing it in a device dependent way, making the procedure so complex (rather than just hashing the GUID directly to produce the key, or even just using the GUID raw) has no purpose beyond deterring reverse engineering that I can see.

    Also, the code itself was highly obfuscated, hence why it took 36 hours to “work out how to use a debugger”.

    It’s possible they use the generated key for other purposes too, and that the obfuscation is a general technique applied to all their crypto routines, making this a knock-on effect. I think that the intention is a little less clear cut than either you or some of the “repression” reports are making out.

    Furthermore, personally I did this for the fun of reversing, so I’m more than happy for them to change it again. I didn’t even own an iPod until I saw the initial story 🙂

  4. Hi wtbw,

    To get a better picture of the effort required, i would be really interested in the obfuscation techniques you’ve overcome – are we talking “stripped symbol tables” here, or are we talking (like some Windows apps) about encrypted code being decrypted on the fly into a scratch page which is locked from being swapped out, and then dynamically jumped-to?

    There are degrees of obfuscation, and it would intrigue me how far apple have gone.

  5. wtbw

    There are no debug symbols available for the exe, as far as I’m aware. The .pdb is probably Apple internal.

    The code isn’t decrypted somewhere, it’s actual obfuscation in place. Not sure if it’s terribly legal to paste exact code, but I’ll give you an invented example:

    MOV EDX,DWORD PTR SS:[EBP-47C]
    IMUL EDX,EDX,A832B741
    MOV DWORD PTR SS:[EBP-214],EDX
    MOV EAX,DWORD PTR SS:[EBP-214]
    SUB EAX,79AE5435
    MOV DWORD PTR SS:[EBP-214],EAX
    MOV ECX,DWORD PTR SS:[EBP-214]
    IMUL ECX,ECX,983DDE23
    MOV DWORD PTR SS:[EBP-C4],ECX
    MOV EDX,DWORD PTR SS:[EBP-214]
    IMUL EDX,EDX,D97F0941
    MOV DWORD PTR SS:[EBP-68],EDX
    MOV EAX,DWORD PTR SS:[EBP-214]
    IMUL EAX,EAX,F48EF2BF
    MOV DWORD PTR SS:[EBP-214],EAX
    MOV ECX,DWORD PTR SS:[EBP-C4]
    ADD ECX,788DAC34
    MOV DWORD PTR SS:[EBP-24C],ECX
    MOV EDX,DWORD PTR SS:[EBP-214]
    SUB EDX,788DAC35
    MOV DWORD PTR SS:[EBP-C4],EDX
    MOV EAX,DWORD PTR SS:[EBP-214]
    SUB EAX,788DAC36
    MOV DWORD PTR SS:[EBP-214],EAX
    MOV ECX,DWORD PTR SS:[EBP-C4]
    OR ECX,DWORD PTR SS:[EBP-214]
    MOV DWORD PTR SS:[EBP-214],ECX
    MOV EDX,DWORD PTR SS:[EBP-24C]
    AND EDX,DWORD PTR SS:[EBP-214]
    MOV DWORD PTR SS:[EBP-214],EDX
    OR EAX,FFFFFFFF
    SUB EAX,DWORD PTR SS:[EBP-214]
    MOV DWORD PTR SS:[EBP-214],EAX
    MOV ECX,DWORD PTR SS:[EBP-68]
    ADD ECX,3317FD06
    MOV DWORD PTR SS:[EBP-2F0],ECX
    MOV EDX,DWORD PTR SS:[EBP-214]
    MOV DWORD PTR SS:[EBP-380],EDX

    Pages and pages of code like this – often resulting in the changes cancelling out, but sometimes with real calculations intermingled. Also, there was some attempt to hide the flow of the code with, for example, switches on some of these values in loops. Values are also passed to functions modified (and then reconstructed, eventually, in the functions themselves). It’s quite a mess, but not insurpassable – needless to say, trace logs came in very handy.

  6. i’ve seen disassemblies like this before[1], and I agree it looks like any of a number of table-lookup-driven algorithms (“loop over a vector of words or bytes, doing a OR/AND/SHIFT on the basis of a table looked-up in memory, and INCREMENT/DECREMENT the table counter” … which gets especially confusing after a code-inlining optimiser has had a go at it.

    Beyond that it becomes a matter of intent; what is the output of this code extract? A int? long? or is it operating on a string that was passed in to it?


    [1] I still have nightmares about the evening I spent manually unwrapping DES S-boxes using awk scripts.

  7. wtbw

    Edit: Bah – less than sign messed it up!

    There’s no table lookup in the majority of this code… it’s mostly fixed constants being applied to local variables (one original variable may be split into several temporary ones before being recombined into the original value – for no other reason than to waste analysts’ time). As I say, most of them cancel out with others, so if you trace you can see the real values reappearing sporadically throughout.

    It does many of these functionally useless sequences on each variable involved in the various functions it is applied to, be they 8-bit, 16-bit, 32-bit, signed, unsigned (when dealing with under 32-bit variables, the sequences can treat the remaining parts of the register as junk) – and the real calculations are done inbetween many of these junk instructions, to make the overall calculations done by the functions hard to work out. For example, the function that calculates lowest common multiple ends up about 1000 instructions long.

    No optimizing compiler would output this, as most of it would be eliminated. My guess would be a tool applied at source level, and then optimization disabled for the relevant files.

  8. Hmmm… I’m willing to be convinced that maybe they’ve run it through an obfuscator – though I am still not yet convinced that it’s a pseudo-DRM device – but I’m intrigued enough to take a look.

    What’s the function entrypoint? Using the stock Apple-supplied devkit tools one can do:

    $ otool -tV /Applications/iTunes.app/Contents/MacOS/iTunes | less

    …and then browse moderately happily, without requiring any special tools.

  9. wtbw

    All this work was done on the Windows iTunes exe. I haven’t looked at the Mac version at all.

    In the Windows 7.4.1 binary:

    Call to main checksum calculation function is at 56191A (calling 55A100)
    Call to memcmp checking result is at 56193D

    Within 55A100:
    Call to “HashInit” (note: these are names made up by us) at 55A13B (calling 9A7C70)
    Calls to “HashUpdate” at 55A229 (headers) and 55A2B8 (body, called every 256kb) (calling 9A7D80)
    Call to “HashFinalize” at 55A2E3 (calling 9A7ED0)

    Within HashInit (9A7C70), DD9250 is the most interesting function, generating the key and so on.
    The aforementioned LCM function is at DDCDC0 (called 4 times within DD9250, once for each pair of bytes in the FireWireGUID).

    For more details about the key generation algorithm, see my (quickly put together) code at http://main.wtbw.co.uk/hash58.zip .

    I haven’t looked at 7.4.2 beyond checking that the solution still worked.

  10. […] Alec Muffet no cree que Apple sea tan malo – (link) […]

Leave a Reply

Your email address will not be published. Required fields are marked *