Subject: | Store might not send a x-apple-crypto-iv header |
Without the x-apple-crypto-iv header, Crypt::Rijndael gets upset at init
time, because there's no iv. Attached patch only initializes it if there
is such a header. This isn't quite correct - forcing decrypt will still
fail of there isn't a header, but at least the simple case actually
works for me now.
Subject: | Net-iTMS.patch |
diff -ru Net-iTMS-0.15/lib/Net/iTMS/Request.pm Net-iTMS-0.15-tomi/lib/Net/iTMS/Request.pm
--- Net-iTMS-0.15/lib/Net/iTMS/Request.pm 2005-03-29 15:48:07.000000000 +0100
+++ Net-iTMS-0.15-tomi/lib/Net/iTMS/Request.pm 2006-06-11 17:05:33.000000000 +0100
@@ -192,21 +192,6 @@
if ($opt->{decrypt}) {
$self->_debug('Decrypting content...');
- # Since the key is static, we can just hard-code it here
- my $iTunesKey = pack 'H*', '8a9dad399fb014c131be611820d78895';
-
- #
- # Create the AES CBC decryption object using the iTunes key and the
- # initialization vector (x-apple-crypto-iv)
- #
- my $cbc = Crypt::CBC->new({
- key => $iTunesKey,
- cipher => 'Rijndael',
- iv => pack ('H*', $res->header('x-apple-crypto-iv')),
- regenerate_key => 0,
- padding => 'standard',
- prepend_iv => 0,
- });
# Try to intelligently determine whether content is actually
# encrypted. If it isn't, skip the decryption unless the caller
@@ -215,6 +200,23 @@
my $decrypted;
if ($opt->{decrypt} == 2 or $res->header('x-apple-crypto-iv')) {
+
+ # Since the key is static, we can just hard-code it here
+ my $iTunesKey = pack 'H*', '8a9dad399fb014c131be611820d78895';
+
+ #
+ # Create the AES CBC decryption object using the iTunes key and the
+ # initialization vector (x-apple-crypto-iv)
+ #
+ my $cbc = Crypt::CBC->new({
+ key => $iTunesKey,
+ cipher => 'Rijndael',
+ iv => pack ('H*', $res->header('x-apple-crypto-iv')),
+ regenerate_key => 0,
+ padding => 'standard',
+ prepend_iv => 0,
+ });
+
$decrypted = $cbc->decrypt($res->content);
} else {
$self->_debug(' Content looks unencrypted... skipping decryption');