From patchwork Wed Apr 8 03:54:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vesselin Bontchev X-Patchwork-Id: 18775 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 0170B44B092 for ; Wed, 8 Apr 2020 06:59:50 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D004968B73E; Wed, 8 Apr 2020 06:59:49 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from forward400j.mail.yandex.net (forward400j.mail.yandex.net [5.45.198.245]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6DF5068B73B for ; Wed, 8 Apr 2020 06:59:43 +0300 (EEST) Received: from mxback1j.mail.yandex.net (mxback1j.mail.yandex.net [IPv6:2a02:6b8:0:1619::10a]) by forward400j.mail.yandex.net (Yandex) with ESMTP id 613CE6E0C26 for ; Wed, 8 Apr 2020 06:54:23 +0300 (MSK) Received: from localhost (localhost [::1]) by mxback1j.mail.yandex.net (mxback/Yandex) with ESMTP id UGfqIXyRPQ-sMTqtYwj; Wed, 08 Apr 2020 06:54:22 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.com; s=mail; t=1586318062; bh=PUyYLk/EvvUPBPU9nuRmHabydL9lAW2pBj8Cc885lDc=; h=Message-Id:Date:Subject:To:From; b=ZbaaAz6N+e67RFgho/oUMTRXGX5hhAKMjCCGZGGo5J2JOWSdaMxgSltGfSzUaYVVZ PFTQBTpmYWewKzFehnTARSUU8pyYkv7BC5cHkWkInLFOXCRKnCpAxsDt7lvC9w0NLy B/cZcr4Bp5EDMRZTe8V2mvxmjElf6+enqjx1+QtI= Authentication-Results: mxback1j.mail.yandex.net; dkim=pass header.i=@yandex.com Received: by sas8-da6d7485e0c7.qloud-c.yandex.net with HTTP; Wed, 08 Apr 2020 06:54:22 +0300 From: Vesselin Bontchev Envelope-From: vesselin-bontchev@yandex.com To: FFmpeg development discussions and patches MIME-Version: 1.0 X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Wed, 08 Apr 2020 06:54:22 +0300 Message-Id: <3986281586317437@iva3-67f911cb3a01.qloud-c.yandex.net> X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: [FFmpeg-devel] [PATCH v3] Add support for playing Audible AAXC (.aaxc) files X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From cb25a130797370e2801cecc34740764c6d2d264b Mon Sep 17 00:00:00 2001 From: Vesselin Bontchev Date: Sat, 1 Jan 2000 09:00:00 +0000 Subject: [PATCH v3] Add support for playing Audible AAXC (.aaxc) files The AAXC container format is the same as the (already supported) Audible AAX format but it uses a different encryption scheme. Note: audible_key and audible_iv values are variable (per file) and are externally fed. It is possible to extend https://github.com/mkb79/Audible to derive the audible_key and audible_key values. Relevant code: def decrypt_voucher(deviceSerialNumber, customerId, deviceType, asin, voucher): buf = (deviceType + deviceSerialNumber + customerId + asin).encode("ascii") digest = hashlib.sha256(buf).digest() key = digest[0:16] iv = digest[16:] # decrypt "voucher" using AES in CBC mode with no padding cipher = AES.new(key, AES.MODE_CBC, iv) plaintext = cipher.decrypt(voucher).rstrip(b"\x00") return json.loads(plaintext) The decrypted "voucher" has the required audible_key and audible_iv values. Signed-off-by: Vesselin Bontchev --- libavformat/isom.h | 4 ++++ libavformat/mov.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/libavformat/isom.h b/libavformat/isom.h index 4943b80ccf..6f7de09155 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -285,6 +285,10 @@ typedef struct MOVContext { int activation_bytes_size; void *audible_fixed_key; int audible_fixed_key_size; + void *audible_key; + int audible_key_size; + void *audible_iv; + int audible_iv_size; struct AVAES *aes_decrypt; uint8_t *decryption_key; int decryption_key_len; diff --git a/libavformat/mov.c b/libavformat/mov.c index 0c4e468dd4..d31653eb6e 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1085,6 +1085,39 @@ fail: return ret; } +static int mov_aaxc_crypto(MOVContext *c) +{ + int ret = 0; + + /* verify audible_key */ + if (c->audible_key_size != 16) { + av_log(c->fc, AV_LOG_FATAL, "[aaxc] audible_key value needs to be 16 bytes!\n"); + ret = AVERROR(EINVAL); + goto fail; + } + + /* verify audible_iv */ + if (c->audible_iv_size != 16) { + av_log(c->fc, AV_LOG_FATAL, "[aaxc] audible_iv value needs to be 16 bytes!\n"); + ret = AVERROR(EINVAL); + goto fail; + } + + c->aes_decrypt = av_aes_alloc(); + if (!c->aes_decrypt) { + ret = AVERROR(ENOMEM); + goto fail; + } + + memcpy(c->file_key, c->audible_key, 16); + memcpy(c->file_iv, c->audible_iv, 16); + c->aax_mode = 1; + +fail: + + return ret; +} + // Audible AAX (and AAX+) bytestream decryption static int aax_filter(uint8_t *input, int size, MOVContext *c) { @@ -1133,6 +1166,11 @@ static int mov_read_ftyp(MOVContext *c, AVIOContext *pb, MOVAtom atom) av_dict_set(&c->fc->metadata, "compatible_brands", comp_brands_str, AV_DICT_DONT_STRDUP_VAL); + // Logic for handling Audible's .aaxc files + if (!strcmp(type, "aaxc")) { + mov_aaxc_crypto(c); + } + return 0; } @@ -8073,6 +8111,10 @@ static const AVOption mov_options[] = { AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, .flags = FLAGS }, { "activation_bytes", "Secret bytes for Audible AAX files", OFFSET(activation_bytes), AV_OPT_TYPE_BINARY, .flags = AV_OPT_FLAG_DECODING_PARAM }, + { "audible_key", "AES-128 Key for Audible AAXC files", OFFSET(audible_key), + AV_OPT_TYPE_BINARY, .flags = AV_OPT_FLAG_DECODING_PARAM }, + { "audible_iv", "AES-128 IV for Audible AAXC files", OFFSET(audible_iv), + AV_OPT_TYPE_BINARY, .flags = AV_OPT_FLAG_DECODING_PARAM }, { "audible_fixed_key", // extracted from libAAX_SDK.so and AAXSDKWin.dll files! "Fixed key used for handling Audible AAX files", OFFSET(audible_fixed_key), AV_OPT_TYPE_BINARY, {.str="77214d4b196a87cd520045fd20a51d67"}, -- 2.26.0