NAME
iTunes::Sid -- Apple iTunes SC Info common user database file interface
SYNOPSIS
DESCRIPTION
This module allows reading and writing of Apple iTunes type
I<SC info.sid> databases, including the sidb and sidd files
used by iTunes for storage of keys and certificates.
METHODS
- new
-
my $sid = iTunes::Sid( file => "sidb", $key => 'FIND', $iv => 'FIND' ); my $sid = iTunes::Sid( file => "sidb", regdata => 'filename', iTunes_platform => 'Darwin' ); Create an iTunes::Sid object. The file => $filename named argument specifies a data file to be read. The $key and $iv arguments are for decryption, if needed. regdata is a pathname of a file containing hardware data for key calculation. iTunes_platform => 'Darwin' means to look for an existing OS X installation on the mounted drives. The default is to look for an accessible Windows partition on which to find the SC Info data. my $sid = iTunes::Sid( file => 'SCINFOSIDB', regdata => 'filename' ); my $sid = iTunes::Sid( file => 'SCINFOSIDD', regdata => 'filename', scinfo_directory => '/media/windisk/ProgramData/Apple Computer/iTunes/SC Info' ); SCINFOSIDB and SCINFOSIDD are 'magic' file names indicating we should look for the SC Info/Sc Info.sid[b|d] files and open them if found. scinfo_directory is a location to look for the SC Info.sid? files. Remember to mount the Windows drive first, and take note of its assigned name once mounted. my $sid = iTunes::Sid( file => "SCINFOSIDB", REGDATAFILE => 'regdata' ); Read the Sc Info/Sc Info.sidb file using a key calculated from the regdata file created with the following Windows command file, run on the XP or Vista installation for which iTunes created its SC Info files: =========================================================================== @echo off rem file get_hwdata.cmd, run as "get_hwdata.cmd > \regdata" from Windows command prompt REG query "HKLM\HARDWARE\DESCRIPTION\System" /v SystemBiosVersion REG query "HKLM\HARDWARE\DESCRIPTION\System\CentralProcessor\0" /v ProcessorNameString REG query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion" /v ProductId DIR C:\Windows\PROTOCOL.INI =========================================================================== See the examples directory also, and see the LINUX_HOWTO in the examples.
- DESTROY
-
Not to be called directly-- this cleans up circular references, if any.
- ReadFile
-
Read a file in for parsing.
- ParseBuffer
-
Parse the data in the buffer.
- WriteFile
-
$sid->WriteFile( file => "sidb2", $key => 'FIND', $iv => 'FIND' ); Write the (possibly modified) file to the filename given. $key and $iv are as in the new() method.
- WriteFileEncrypted
-
$sid->WriteFileEncrypted( file => "sidb2", $key => 'FIND', $iv => 'FIND' ); Write the (possibly modified) file to the filename given. The file is encrypted before writing (default is to use the key and iv used to decrypt originally).
- ParseSidContainer
-
Parse a container in the buffer position given.
- SidType
-
Return the iTunes::Sid file type (sidb or sidd, etc).
- AtomTree
-
Return an html tree structure for the Sid.
- DumpTree
-
Dump data tree to a file, or to standard output by default.
- FindAtom
-
my @list = $sid->FindAtom("key "); Find any or all atoms in the sid of a given type.
- encrypt
- decrypt
- mac
-
Get or set hardware ID (the MAC address OR a derived machine signature).
- iv
-
Get or set iv.
- key
-
Get or set key.
- sid_version
-
Version of the sid file, from the vers atom.
- find_veggie_for_userID
-
Find the veeggie table and special shuffle case for the key's key.
- fetch_all_user_keys
-
Find and decode all the keys in the SC Info.sidb file.
- write_all_user_keys_to_drms_dir
-
Write all the decoded keys to files in the user's .drms directory file for use by VLC and compatible media players.
PUBLIC FUNCTIONS (function interfaces only)
- check_encrypted_sid
-
my $ok_check = check_encrypted_sid( $encrypted_sid_buffer ); Check an encrypted sid (in memory) for correct form to attemy decryption.
- process_encrypted
-
process_encrypted( $buf_ref, $key, $iv ); process_encrypted( $buf_ref, 'FIND', 'FIND' ); Process the memory referred to by the scalar reference $buf_ref to decrypt it using $key and $iv. Attempt to find $key and $iv if 'FIND' is specified, using iTunes 7 algorithms and local machine data.
- get_sid_key
-
my $key = get_sid_key( $mac ); Using iTunes / QuickTime based algorithms based on characteristics of the local machine, try to calculate the shuffled key for AES cryptography .
- get_sid_iv
-
my $iv = get_sid_iv(); Return the default iTunes / QuickTime based iv for SC Info databases.
LINUX HOWTO
The following is intended for fair use of purchased music by the purchaser, not for piracy. In order to format the FairPlay keys used by iTunes for use by a music player such as VLC under Linux, the keys must be pulled from the SC Info.sidb file, translated using information in the SC Info. sidd file, and then written to a directory where VLC will read the keys for its use. Note that such use does not remove the DRM from the purchased music files themselves, but makes them far more useable under Linux, without resorting to Wine.
Procedure:
1. Set up a machine for dual boot under the iTunes installation OS (OS X or Windows). One partition is to boot OS X or Windows, another Linux. Make sure that your Darwin or NTFS partition is mounted at least for reading!
2A. (iTunes for Windows) Run the file ./examples/get_hwdata.cmd in the iTunes::Sid /examples directory in this distribution, which creates an output file as c:\regdata, as in
c:> get_hwdata.cmd
Then reboot to Linux and mount the windows partion (it should be attached
to /media/disk1/ or /media/disk2, etc).
Run the file ./examples/get_keys_for_vlc.pl (the file pathname on line 10
may need to be changed to be directed to the output file of the Windows
command file above).
2B. (iTunes for OS X) Dual boot may "just work" since the key is derived from the computer's LAN card MAC address. If attaching to the OS X machine over a network share, you may get the mac address of the source machine by running ./examples/print_mac.pl and redirecting this to a file, then copying that file to your home directory into a subdirectory called '.drms' and a file called 'mac' in that directory. iTunes::Sid will look for this file, and use it for the mac adddress if it finds that file.
3. Run the ./examples/get_keys_for_vlc.pl perl script to allow any DRM-laden iTMS purchases to play under VLC or other compatible media players.
If the above fails, you may be able to run the above under OS X or Windows,
and then copy the drms directory and its keys to your linux home directory,
renaming 'drms' to '.drms' and then run VLC to play music as usual. (The same
must be done if the keys are generated under the /root account-- copy the
/root/.drms directory to your home directory).
SEE ALSO
BUGS
Initial setup almost requires a dual boot machine.
Searches for SC Info files are subject to file finding errors.
No doubt many others.
AUTHOR
William Herrera ( wherrera@skylightview.com ).
SUPPORT
Questions, feature requests and bug reports should go to <wherrera@skylightview.com>.
NOTES
Regarding the US DMCA Law
The U.S. Digital Millenum Copyright Act states in section 102, part (f):
-----------------------------------------------------------------------
`(f) REVERSE ENGINEERING- (1) Notwithstanding the provisions of subsection
(a)(1)(A), a person who has lawfully obtained the right to use a copy
of a computer program may circumvent a technological measure that
effectively controls access to a particular portion of that program
for the sole purpose of identifying and analyzing those elements of
the program that are necessary to achieve interoperability of an
independently created computer program with other programs, and that
have not previously been readily available to the person engaging
in the circumvention, to the extent any such acts of identification
and analysis do not constitute infringement under this title.
`(2) Notwithstanding the provisions of subsections (a)(2) and (b),
a person may develop and employ technological means to circumvent a
technological measure, or to circumvent protection afforded by a
technological measure, in order to enable the identification and
analysis under paragraph (1), or for the purpose of enabling
interoperability of an independently created computer program with
other programs, if such means are necessary to achieve such
interoperability, to the extent that doing so does not constitute
infringement under this title.
`(3) The information acquired through the acts permitted under
paragraph (1), and the means permitted under paragraph (2), may be
made available to others if the person referred to in paragraph (1)
or (2), as the case may be, provides such information or means solely
for the purpose of enabling interoperability of an independently
created computer program with other programs, and to the extent
that doing so does not constitute infringement under this title or
violate applicable law other than this section.
----------------------------------------------------------------------
Our take on why this code is an example of free and protected speech:
The portion of the DMCA quoted above allows usage of protected content to
enable interoperability beween Linux and other systems. Therefore, since
this package and related Perl code are primarily designed to allow Linux,
Solaris, and Unix systems to achieve interoperability with iTunes and the
iTunes Music Store, they ARE legal under the DMCA. We are somewhat
concerned about the word "solely" in the text above, since this package
works under OS X and Windows as well as Linux. For "solely" that reason,
please also see the COPYRIGHT below.
COPYRIGHT
Copyright (c) 2008 William Herrera. All rights reserved.
Licensing Terms
a) The terms of Perl itself, plus the following:
b) UNDER NO CIRCUMSTANCES CAN THIS CODE BE USED FOR CIRCUMVENTION OF ANY
TECHNOLOGICAL MEASURE WHICH EFFECTIVELY CONTROLS A PROTECTED MEDIA WORK
UNDER THE DCMA (USA, 1998) OR EU COPYRIGHT DIRECTIVE (EUCD, ARTICLE 6,
OF 2001), UNDER ANY OPERATING SYSTEM PLATFORM SUPPORTED BY APPLE COMPUTER
CORPORATION FOR ITS ITUNES OR IPOD PLAYER SOFTWARE IN ANY APPLE CORPORATION
DISTRIBUTED BINARY FORMAT OF ITUNES FOR THE PLATFORM UNDER WHICH THAT MEDIA
IS TO BE PLAYED. AS OF 2008, PROHIBITED PLATFORMS INCLUDE THE IPOD, IPHONE,
APPLE OS X, AND MICROSOFT WINDOWS, BUT NOT LINUX, BSD, OR SOLARIS. UNDER NO
CIRCUMSTANCES CAN THE AUTHOR(S) OF THIS CODE BE HELD LIABLE FOR ANY
INFRINGEMENT INVOLVING THE PROHIBITED PLATFORMS ABOVE.
c) Use, storage, or distribution of this code implies that you accept that
its intended purpose is legal and legitimate under any applicable US or EU
law, as above, and agree that any and all risk as to the quality,
performance, and legality of this code lies with you.