Waxy.org
Waxy.org is the sandbox of Andy Baio, a journalist/programmer living in Portland, Oregon. I'm the CTO of Kickstarter, created Upcoming.org, and some other stuff too.

Contact Me: log@waxy.org or waxpancake on AIM

Search the iTunes Music Store

Posted May 9, 2003

I whipped up a quick PHP script that allows anyone (even PC users like myself) to search the iTunes Music Store. Sound clips are in Apple's proprietary M4P format, so don't expect to be able to listen to them unless you have iTunes installed.

You can try out the search for a limited time here (until it gets too popular), or download the script for your own site. Feel free to modify it however you like.

Update: Apple seems to be encrypting (or compressing?) their XML now, which breaks the script entirely. It doesn't seem to be gzip-encoding, either. Any guesses on what they're up to?

February 10, 2004: Someone sent me the e-mail below, discussing how they figured out the encryption. This is a bit above my head, but other people may find it useful.

April 17, 2004: Someone finally wrote a script to work around iTunes encryption. Go play with iTMS-4-All.

Anonymous wrote:

Last year you had a blog entry about Apple encrypting the iTunes Music Store.
I didn't see any follow ups on this, so I don't know if anyone cares anymore, but I've figured out the encryption.

The encryption is standard AES128 CBC. The iv, of course, is sent in the header, and the encryption key is:

8a 9d ad 39 9f b0 14 c1 31 be 61 18 20 d7 88 95

After decrypting, you'll end up with a gzip file.

The key is actually generated from the following code snippet:
(using openssl's md5)
MD5_CTX ctx
unsigned char key[16];
MD5_Init(&ctx);
MD5_Update(&ctx,"Accept-Language",15);
MD5_Update(&ctx,"user-agent",10);
MD5_Update(&ctx,"max-age",7);
MD5_Final(key,&ctx);
// key[16] contains the AES key now

Hope this helps revive everyone's ITMS interfaces.

22 Comments (Add Yours)

May 9, 2003
4:24 PM  
Andy Baio wrote:

Quicktime 6 for Windows won't play the M4P clips.


May 9, 2003
11:17 PM  
Olen Anderson wrote:

They're encoded in regular old vanilla AAC. I'm sure there's a player that supports that in Windows somewhere, it'ss hardly new.


May 10, 2003
5:38 AM  
Konstantinos wrote:

Andy, are you sure it still works? I tried a few searches on popular artists/albums/songs and got zero results each time.


May 10, 2003
5:56 AM  
Konstantinos wrote:

(Also, a link which may be of interest to the programmers out there: Apple, XML and the Music Store.)


May 10, 2003
9:48 AM  
Marcus wrote:

The latest version of Winamp 2x supports AAC encoding. But then I read here that older AAC plugins for Winamp won't play iTunes Musc Store stuff. So I'm not sure if that means the new native support doesn't work either.

This thread on the Winamp forum is still developing and contains some useful info re: AAC and .m4a.


May 10, 2003
4:51 PM  
Andy Baio wrote:

The clips were M4P files, which is Apple's DRM-added version of AAC. I doubt they'll play on anything besides Quicktime, and it doesn't appear that the newest Quicktime for the PC supports it yet.


May 10, 2003
7:53 PM  
Jack wrote:

Apple is now using the Rijndael-256 algorithm in addition to gzip compression for encoding data from the iTunes store.

Here's the HTTP header response from iTunes following a search request:

HTTP/1.1 200 Apple
Date: Sun, 11 May 2003 02:13:05 GMT
Content-Length: 3616
Content-Type: text/xml; charset=iso-8859-1
Cache-Control: no-transform
Server: Apache/1.3.27 (Darwin)
content-encoding: gzip, x-aes-cbc
x-apple-max-age: 3600
x-apple-crypto-iv: d9e5395496e7e82498105ea9041c6102
x-apple-protocol-key: 2
x-apple-asset-version: 186
x-apple-application-instance: 1
Via: 1.1 netcache01 (NetCache NetApp/5.2.1R2D2)

I tried writing something to decrypt their XML but ran into some roadblocks. Firstly, the IV for decryption is given, but there's no telling what additional encryption is needed on the key itself (which I assume is 'x-apple-protocol-key'). I also don't know if the data is gzipped and then encrypted or vice-verse.

I don't know man, I'm stuck.


May 10, 2003
8:47 PM  
David Weekly wrote:

Looks like Apple has got a set of AES keys built into iTunes. The HTTP response header indicates which key (key 2 in build 186) should be used, along with the IV to use.

Some handy work with a debugger should help you pry out the keys from iTunes. This is what the DeCSS folks did with Xing's software to grab a CSS key.


May 10, 2003
8:49 PM  
Jack Driscoll wrote:

If you figure it out I'd love to plug the key into the script I have thus far.


May 11, 2003
5:04 AM  
Blo wrote:

Are all artists covered in the Apple music store?


May 11, 2003
5:54 PM  
frank wrote:

you have excelent content here. now you are in my blogroll list.


May 11, 2003
11:52 PM  
Fash wrote:

Using toast titanium was the easiest for me. I bought an album, drug the .m4p's to toast, wrote an image, mounted the image, used itunes to MP3 them, and then dropped them on my PC over the network.


May 12, 2003
5:25 AM  
Konstantinos wrote:

Fash, if I got that right, you're doing some transcoding [.m4p→.wav(if you're using Toast Titanium to create an Audio CD)→.mp3] here, which results in a serious loss of quality (which, in turn, is something that's not highly desirable).


May 12, 2003
5:40 PM  
carson wrote:

iTunes is a bugger to, well, debug. So many threads! So much data! Knowing where to "break" becomes rather arbitrary as I don't know of any specific system calls that would be used in working with encryption. I wonder how big the key is? It seems unlikely, but maybe it could be brute forced.


May 13, 2003
2:43 PM  
dace wrote:

rename the file extension to : .mp4


May 13, 2003
3:58 PM  
Andy Baio wrote:

Renaming the file does nothing. It's still unplayable by Quicktime.


May 13, 2003
8:04 PM  
Lag wrote:

Hmmm... why bother with iTunes... or anything made by Apple, for that matter? Just let them die the silent death that's been waiting since Steve first hoisted that skull and crossbones flag.


May 21, 2003
2:08 PM  
hehe wrote:

the small clips (30 secs) of the apple store can be played back with mplayer (which uses faad2 / and openQT (openQuicktime) used by ffmpeg)


Oct 21, 2003
1:14 AM  
roeles wrote:

My iTunes 4 sends this string to the music store:

GET /WebObjects/MZStore.woa/wa/com.apple.jingle.app.store.DirectAction/browse?path=%2F4 HTTP/1.1.Accept-Language: en-en, en;q=0.75, en-us;q=0.50, fr;q=0.25.
User-Agent: iTunes/4.1 ($OS)
Accept-Encoding: gzip, x-aes-cbc.
Host: ax.phobos.apple.com.edgesuite.net.
Cookie: countryVerified=1.
.

Not the Accept-Encoding part :)


Apr 17, 2004
2:29 PM  
James wrote:

If you use playfair or m4p2mp4 you can remove the DRM on the m4p files, or just use VLC which has the decryption built in.
Someone's written a perl interface here: http://hcsoftware.sourceforge.net/jason-rohrer/itms4all/


Apr 27, 2004
2:53 PM  
cottonbuds wrote:

Here's an interesting site that converted the Perl interface into PHP.
I think if he's using PHP it is going to be a lot easier for other web site to follow, since the Perl implemetation of itms-4-all is quite difficult because of the decryption library that needed to be installed the web site.


Link


Jul 7, 2004
4:36 PM  
Jon Lech Johansen wrote:

I've released FairKeys, a tool which lets you retrieve your FairPlay keys from Apple's servers.



x-apple-protocol-key 3:

98d1e22caa0d8abd65d143ad275a5ee7


 

Leave a comment





Waxy Links
Ads via The Deck
November 20, 2009
Regretsy gets a book deal — the anonymous author turned out to be April Winchell, collector of audio oddities
Google Chrome OS Demo — a world without a local filesystem and apps; also, the Chrome UI concept video (via)
Patrick Moberg's Internet Vices — funny, Tumblr feels more like beer than wine to me
Charlotte Gainsbourg and Beck's "Heaven Can Wait" — Keith Schofield's surreal video and insane treatment were inspired by FFFFOUND and Reddit, but maybe too explicitly (via)
November 19, 2009
YouTube adds machine-translated automatic captions — starting with some partner channels, but auto-timing is available to everyone today
Microsoft tries to patent Edward Tufte's sparklines — they were recently added to Excel
Leonard Lin's Retweet Avatars for Greasemonkey — a subtle change, but a big improvement
Web-ops god John Allspaw leaves Flickr to join Etsy — he's the last of the original Ludicorp team to go (via)
November 18, 2009
Laptop Steering Wheel Desk — don't miss the product photos
Interview with Ralph Eggleston, Pixar's production designer on WALL-E — from last February, but new to me; I didn't know the Axiom had three passenger classes
NSFW: Animated pixel-art video for Flair's "Trucker's Delight" — warning: very offensive and sexist, but the attention to 16-bit detail by director Jérémie Perin is incredible
NY Observer on Anil Dash's new government 2.0 incubator project — Expert Labs debuted at Web 2.0 today, funded with a $500k grant from the MacArthur Foundation
November 17, 2009
Google's Dan Morrill explains how the Droid autofocus breaks every 24.5 days — this gets second-place for quirkiest Android bug (via)
Conan O'Brien and Andy Richter on Zach Galifianakis' Between Two Ferns — his style of comedy usually makes me uncomfortable, but this made me laugh
The Pirate Bay shuts down their tracker for good — they're switching to DHT instead
November 16, 2009
How Darren at Link Machine Go found Belle de Jour's identity five years ago — Brooke was part of the early UK blog scene
ICU64, real-time visualization of Commodore 64 memory — the developer also posted videos of Paradroid and Boulder Dash (via)
Russell Davies on pretending and "barely games" — his SAP prototype looks like great ambient fun (via)
NYT Magazine on the indie gaming movement — nothing new here, but good overview with a wonderful closing anecdote from Cactus
Tim O'Reilly on the pending War for the Web — "more than that, it's a war against the web as an interoperable platform"
November 14, 2009
Jason Scott rounds up Geocities' top 10 most popular MIDI files — along with a torrent with 51,000 MIDIs rescued by Archive Team
Matt Haughey on the discovery of his brain tumor, treatment, and the Internet's response — there were about 1,000 #mathowielove tweets in 24 hours
Belle de Jour reveals herself after six year of anonymity — only six people in the world knew, she only told her parents yesterday (via)
Paul F. Tompkins debates comedy ethics with Improv Everywhere's Charlie Todd — great discussion, and it's hard not to see where both are coming from (via)
November 13, 2009
Rogue Amoeba stops iPhone app development after App Store idiocy — I'm with Marco, the only fix is allowing external apps, but it's unlikely (via)
Numb3rs on IRC — "Luckily, I speak l33t."
Prank War 8: The Skydiving Prank — hard to say if life-threatening situations are funnier than public humiliation
301 Works, Internet Archive works to preserve URL shortener data — the shorteners will provide regular backups and hand over data on closure, though TinyURL's conspicuously missing
November 12, 2009
Quizipedia — simple game with trivia scraped from Wikipedia entries
Kill Screen, funding a new art magazine about videogames — sounds like the English analogue of Amusement I was hoping for

Andy Baio lives here. Some rights reserved, for your pleasure.