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") # improve this! return json.loads(plaintext) The decrypted "voucher" has the required audible_key and audible_iv values. Update (Nov-2020): This patch has now been tested by multiple folks - details at the following URL: https://github.com/mkb79/Audible/issues/3
Showing the changes to libavformat (2 of 2 files). Show all
Unified · Split
| @@ -286,6 +286,10 @@ typedef struct MOVContext { · 285 unmodified lines | |||
| 286 | int activation_bytes_size; | 286 | int activation_bytes_size; |
| 287 | void *audible_fixed_key; | 287 | void *audible_fixed_key; |
| 288 | int audible_fixed_key_size; | 288 | int audible_fixed_key_size; |
| 289 | void *audible_key; | ||
| 290 | int audible_key_size; | ||
| 291 | void *audible_iv; | ||
| 292 | int audible_iv_size; | ||
| 289 | struct AVAES *aes_decrypt; | 293 | struct AVAES *aes_decrypt; |
| 290 | uint8_t *decryption_key; | 294 | uint8_t *decryption_key; |
| 291 | int decryption_key_len; | 295 | int decryption_key_len; |
| @@ -1075,6 +1075,30 @@ fail: · 1074 unmodified lines | |||
| 1075 | return ret; | 1075 | return ret; |
| 1076 | } | 1076 | } |
| 1077 | 1077 | ||
| 1078 | static int mov_aaxc_crypto(MOVContext *c) | ||
| 1079 | { | ||
| 1080 | if (c->audible_key_size != 16) { | ||
| 1081 | av_log(c->fc, AV_LOG_FATAL, "[aaxc] audible_key value needs to be 16 bytes!\n"); | ||
| 1082 | return AVERROR(EINVAL); | ||
| 1083 | } | ||
| 1084 | |||
| 1085 | if (c->audible_iv_size != 16) { | ||
| 1086 | av_log(c->fc, AV_LOG_FATAL, "[aaxc] audible_iv value needs to be 16 bytes!\n"); | ||
| 1087 | return AVERROR(EINVAL); | ||
| 1088 | } | ||
| 1089 | |||
| 1090 | c->aes_decrypt = av_aes_alloc(); | ||
| 1091 | if (!c->aes_decrypt) { | ||
| 1092 | return AVERROR(ENOMEM); | ||
| 1093 | } | ||
| 1094 | |||
| 1095 | memcpy(c->file_key, c->audible_key, 16); | ||
| 1096 | memcpy(c->file_iv, c->audible_iv, 16); | ||
| 1097 | c->aax_mode = 1; | ||
| 1098 | |||
| 1099 | return 0; | ||
| 1100 | } | ||
| 1101 | |||
| 1078 | // Audible AAX (and AAX+) bytestream decryption | 1102 | // Audible AAX (and AAX+) bytestream decryption |
| 1079 | static int aax_filter(uint8_t *input, int size, MOVContext *c) | 1103 | static int aax_filter(uint8_t *input, int size, MOVContext *c) |
| 1080 | { | 1104 | { |
| @@ -1123,6 +1147,11 @@ static int mov_read_ftyp(MOVContext *c, AVIOContext *pb, MOVAtom atom) · 42 unmodified lines | |||
| 1123 | av_dict_set(&c->fc->metadata, "compatible_brands", | 1147 | av_dict_set(&c->fc->metadata, "compatible_brands", |
| 1124 | comp_brands_str, AV_DICT_DONT_STRDUP_VAL); | 1148 | comp_brands_str, AV_DICT_DONT_STRDUP_VAL); |
| 1125 | 1149 | ||
| 1150 | // Logic for handling Audible's .aaxc files | ||
| 1151 | if (!strcmp(type, "aaxc")) { | ||
| 1152 | mov_aaxc_crypto(c); | ||
| 1153 | } | ||
| 1154 | |||
| 1126 | return 0; | 1155 | return 0; |
| 1127 | } | 1156 | } |
| 1128 | 1157 | ||
| @@ -8170,6 +8199,10 @@ static const AVOption mov_options[] = { · 7041 unmodified lines | |||
| 8170 | AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, .flags = FLAGS }, | 8199 | AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, .flags = FLAGS }, |
| 8171 | { "activation_bytes", "Secret bytes for Audible AAX files", OFFSET(activation_bytes), | 8200 | { "activation_bytes", "Secret bytes for Audible AAX files", OFFSET(activation_bytes), |
| 8172 | AV_OPT_TYPE_BINARY, .flags = AV_OPT_FLAG_DECODING_PARAM }, | 8201 | AV_OPT_TYPE_BINARY, .flags = AV_OPT_FLAG_DECODING_PARAM }, |
| 8202 | { "audible_key", "AES-128 Key for Audible AAXC files", OFFSET(audible_key), | ||
| 8203 | AV_OPT_TYPE_BINARY, .flags = AV_OPT_FLAG_DECODING_PARAM }, | ||
| 8204 | { "audible_iv", "AES-128 IV for Audible AAXC files", OFFSET(audible_iv), | ||
| 8205 | AV_OPT_TYPE_BINARY, .flags = AV_OPT_FLAG_DECODING_PARAM }, | ||
| 8173 | { "audible_fixed_key", // extracted from libAAX_SDK.so and AAXSDKWin.dll files! | 8206 | { "audible_fixed_key", // extracted from libAAX_SDK.so and AAXSDKWin.dll files! |
| 8174 | "Fixed key used for handling Audible AAX files", OFFSET(audible_fixed_key), | 8207 | "Fixed key used for handling Audible AAX files", OFFSET(audible_fixed_key), |
| 8175 | AV_OPT_TYPE_BINARY, {.str="77214d4b196a87cd520045fd20a51d67"}, | 8208 | AV_OPT_TYPE_BINARY, {.str="77214d4b196a87cd520045fd20a51d67"}, |