From patchwork Mon Jan 8 23:22:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacob Trimble X-Patchwork-Id: 7209 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.78.2 with SMTP id r2csp3235499jaa; Mon, 8 Jan 2018 15:30:50 -0800 (PST) X-Google-Smtp-Source: ACJfBotdCYy7tXmEHfQ4m5AAkqI+tv+owjtvw9GKJyiDG4eFiIXdE3Rf1HGsiJsJ6d2FH3wTE0JC X-Received: by 10.28.108.14 with SMTP id h14mr9457632wmc.32.1515454250327; Mon, 08 Jan 2018 15:30:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515454250; cv=none; d=google.com; s=arc-20160816; b=Bv5WZA77lNcmfKtWe9E/MgGO9Y5MvYnpBwwcI5BJ+D2chuxBbxnofQ+YH4g2az4V0J B0UAl0mgf0XZRicwyr8b/bGpaDdp88u1A0Ku7ZT8TtFVWEcd/eNxbE57CIohIDGRZc6V sL/NQYwy59S5BoI8QZJbveIrICAFq+edBxEhDdPXARG7B5C/JHDWKZniP88hULaGqDX7 ITyGy6Ggc15bPOxQb8byInC0I93qZ8l003w6vVanhqHz8oRMfhlgt6T0WobM7XYgN8VL GaTTPV9uEVLlTCfu1/RX28jP9Au96rHsRugVzIfLWQXdS6bfltckL/zB80KyNXw97Cz4 ln0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:to :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:delivered-to:arc-authentication-results; bh=HO62QmqCPlYolNEUE6X5QlfWF0uZdrKHhuomre4zAE4=; b=S/jOyFr0c5YKXDOOZuI1ZAiWU8GYMg/6zMPeM+kKNCqA42Dwv5JmjxL/soSLXcoZ1H GFBMcEFn+Z7LXCluKl6P+ySXn+7NS03LaT04zdb6KZ6fM+M2qaZAeAd5TyNl38Yf9TWw FSxLPXxYbxJAVM+k07T2UJZUcp/c37lhDOr5yQktlgamnxh1khU4jwfESwUojuTA3iqJ WkxRWRbuexte5wrfRBcDKr3FBIQKPpAyo5jZmCFFTnqkmpGGsPzLFOylMb+krBg3aqTF nsT6uwBT9kn+yfow6k+LTnXRyEMxEvb2ZuqTJxfPCKFsiXGmYgtkOJZXm0B9MKHGdD9Y 8ZSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.s=20161025 header.b=U+7WVDWn; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 34si9886950wrt.82.2018.01.08.15.30.49; Mon, 08 Jan 2018 15:30:50 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.s=20161025 header.b=U+7WVDWn; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 10F6D68993C; Tue, 9 Jan 2018 01:30:47 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua0-f181.google.com (mail-ua0-f181.google.com [209.85.217.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 381CC688252 for ; Tue, 9 Jan 2018 01:30:41 +0200 (EET) Received: by mail-ua0-f181.google.com with SMTP id x10so8002502ual.8 for ; Mon, 08 Jan 2018 15:30:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=RgiPtPQvtmC3xaFvb4mwr98i6/hZ2z2E8bSxOb+ke1A=; b=U+7WVDWn9ANUTTQmrwFdiCapV01BH6WPrrKJqNdWj0sumaTBSMZUj+X7ng8oL8nufI 5BYhW0TMci6OtUYeJwRQkeykUGpcFmdzQfVEWavSg3DU9trviCfuoSSmpZZZcaUligoh NEH+hLDT1OBBPJw1715L+mFDOSrJirRh96ED4qYyKgS619/3PDxPlNkm9PI7bT/NHGqh nwOvii0m5C4HCBjxi8fz8bfDGUj/18KgKr34KqTuP35h9eG5ArCI0LgY9njInCITMxKP hPMAR94j69C5qmcQKPmzBUpzQ92hir8BbLvQ/ScyhFHFdDHDIO+UzOF3aqfx83hqGeX+ 19MQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=RgiPtPQvtmC3xaFvb4mwr98i6/hZ2z2E8bSxOb+ke1A=; b=Qhv7VP466iJN5DXUiLzFqebNle57+aiDPgwPaXlg7tozX6juNpa0fKKxKBCw+DgHLg 24vx6ErmSXXVIa9FepsYYbtX63rdTytA7uDpUdSGkc0x4zv5i+oxLlbnjzNHye5BLLQX SitZeIcnCDgqsnemaOOvBXsbr16/YF1dTHTXdhBsQVGtC05fLGAyti2CYPpinRUDzj2O L4wM/4nPt45l+ccXpCeJiDzi09DVX4mCw33ykpVEoRyPHGMJAfuyNVNeNwPrm2+Ed36N BPKOJ8v4bmj9K6XH9A64B7XEp4XR1FTtvEZjVBFmOH4nT/ZN22ohtIWS+cVyzrs2z7Ri DC7w== X-Gm-Message-State: AKwxytfWhn73Q1IvzfnVcplur3LxvJhddiB1chSKDJr6NRm62Z0hV5LW z28fwlwCqWv8CvtzKFZHewmmOqVxbnGPLnjDSuS3faRV X-Received: by 10.176.3.138 with SMTP id 10mr5559910uau.84.1515453754424; Mon, 08 Jan 2018 15:22:34 -0800 (PST) MIME-Version: 1.0 Received: by 10.103.214.138 with HTTP; Mon, 8 Jan 2018 15:22:33 -0800 (PST) In-Reply-To: References: <20180105194928.104085-1-modmaker@google.com> <20180105194928.104085-3-modmaker@google.com> From: Jacob Trimble Date: Mon, 8 Jan 2018 15:22:33 -0800 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [PATCH 3/3] avformat/mov: Expose encryption info to the app. 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" On Fri, Jan 5, 2018 at 12:55 PM, Jacob Trimble wrote: > On Fri, Jan 5, 2018 at 12:43 PM, Carl Eugen Hoyos wrote: >> 2018-01-05 20:49 GMT+01:00 Jacob Trimble : >> >>> + AV_WB32(side_data, size); >>> + AV_WL32(side_data + 4, MKTAG('p','s','s','h')); >> >> I didn't check: >> Is this what applications on both big- and little-endian expect? > > Yes. This should match the MP4 atom, so the size and 'pssh' string > should be big-endian. > >> >> Carl Eugen >> _______________________________________________ >> ffmpeg-devel mailing list >> ffmpeg-devel@ffmpeg.org >> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel Updated with the new design for the side data and applied the realloc fix to avoid large allocations. From da01baef5ead8194a991470de6b477ab59424617 Mon Sep 17 00:00:00 2001 From: Jacob Trimble Date: Wed, 6 Dec 2017 16:17:54 -0800 Subject: [PATCH] avformat/mov: Expose encryption info to the app. This exposes encryption info from the container to the app. This includes key ID, IV, and subsample byte ranges. The info is passed using the new side-data AV_PKT_DATA_ENCRYPTION_DATA and AV_PKT_DATA_ENCRYPTION_INIT_DATA. Signed-off-by: Jacob Trimble --- libavformat/mov.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/libavformat/mov.c b/libavformat/mov.c index 71cc9a3af3..30165e6dc5 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -6080,6 +6080,91 @@ static int mov_read_saio(MOVContext *c, AVIOContext *pb, MOVAtom atom) return 0; } +static int mov_read_pssh(MOVContext *c, AVIOContext *pb, MOVAtom atom) +{ + AVEncryptionInitInfo *info; + uint8_t **key_ids; + AVStream *st; + uint8_t *side_data, *extra_data; + size_t side_data_size; + int ret = 0; + unsigned int version, kid_count, extra_data_size, alloc_size = 0, i = 0; + + if (c->fc->nb_streams < 1) + return 0; + st = c->fc->streams[c->fc->nb_streams-1]; + + version = avio_r8(pb); /* version */ + avio_rb24(pb); /* flags */ + + info = av_encryption_init_info_alloc(/* system_id_size */ 16, /* num_key_ids */ 0, + /* key_id_size */ 16, /* data_size */ 0); + if (!info) + return AVERROR(ENOMEM); + + if (avio_read(pb, info->system_id, 16) != 16) { + av_log(c->fc, AV_LOG_ERROR, "Failed to read the system id\n"); + ret = AVERROR_INVALIDDATA; + goto finish; + } + + if (version > 0) { + kid_count = avio_rb32(pb); + for (; i < kid_count && !pb->eof_reached; i++) { + unsigned int min_kid_count = FFMIN(FFMAX(i, 1024), kid_count); + key_ids = av_fast_realloc(info->key_ids, &alloc_size, + min_kid_count * sizeof(*key_ids)); + if (!key_ids) { + ret = AVERROR(ENOMEM); + goto finish; + } + info->key_ids = key_ids; + + info->key_ids[i] = av_mallocz(16); + if (!info->key_ids[i]) { + ret = AVERROR(ENOMEM); + goto finish; + } + info->num_key_ids = i + 1; + + if (avio_read(pb, info->key_ids[i], 16) != 16) { + av_log(c->fc, AV_LOG_ERROR, "Failed to read the key id\n"); + ret = AVERROR_INVALIDDATA; + goto finish; + } + } + + if (pb->eof_reached) { + av_log(c->fc, AV_LOG_ERROR, "Hit EOF while reading pssh\n"); + ret = AVERROR_INVALIDDATA; + goto finish; + } + } + + extra_data_size = avio_rb32(pb); + ret = mov_try_read_block(pb, extra_data_size, &extra_data); + if (ret < 0) + goto finish; + + av_freep(&info->data); // malloc(0) may still allocate something. + info->data = extra_data; + info->data_size = extra_data_size; + + side_data = av_encryption_init_info_add_side_data(info, &side_data_size); + if (!side_data) { + ret = AVERROR(ENOMEM); + goto finish; + } + ret = av_stream_add_side_data(st, AV_PKT_DATA_ENCRYPTION_INIT_DATA, + side_data, side_data_size); + if (ret < 0) + av_free(side_data); + +finish: + av_encryption_init_info_free(info); + return ret; +} + static int mov_read_schm(MOVContext *c, AVIOContext *pb, MOVAtom atom) { AVStream *st; @@ -6319,6 +6404,12 @@ static int cenc_filter(MOVContext *mov, MOVStreamContext *sc, AVPacket *pkt, int if (mov->decryption_key) { return cenc_decrypt(mov, sc, encrypted_sample, pkt->data, pkt->size); + } else { + size_t size; + uint8_t *side_data = av_encryption_info_add_side_data(encrypted_sample, &size); + if (!side_data) + return AVERROR(ENOMEM); + return av_packet_add_side_data(pkt, AV_PKT_DATA_ENCRYPTION_INFO, side_data, size); } } @@ -6452,6 +6543,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG('s','e','n','c'), mov_read_senc }, { MKTAG('s','a','i','z'), mov_read_saiz }, { MKTAG('s','a','i','o'), mov_read_saio }, +{ MKTAG('p','s','s','h'), mov_read_pssh }, { MKTAG('s','c','h','m'), mov_read_schm }, { MKTAG('s','c','h','i'), mov_read_default }, { MKTAG('t','e','n','c'), mov_read_tenc }, -- 2.16.0.rc0.223.g4a4ac83678-goog