From patchwork Sat Aug 5 00:17:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: DHE X-Patchwork-Id: 4627 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.46.211 with SMTP id u202csp75013vsu; Fri, 4 Aug 2017 17:18:03 -0700 (PDT) X-Received: by 10.28.66.147 with SMTP id k19mr2258239wmi.31.1501892283443; Fri, 04 Aug 2017 17:18:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501892283; cv=none; d=google.com; s=arc-20160816; b=W4wTC3rgoW3OnAOx7IMNLm1Bb6Luwpoj75Tv1BGdHAG7MSkW6BfDYTlwtt9dH+XEpe k+vuiSv8r7Xo7iUa087bdFSeqGrk3eIWracJZa0bu8g6481JOsiiGOTP505MWw9wjc2W LuuQv7IhwYguvr3YVJ2X2hGtNJd+09ngSn8dueyLX0ahaDFqX5DAp6+Bm2p0pDZwFhL2 RIwbrgf8ieLS5x3vY6LQJaxj28hZOddmRXYHJ/GYrt8kRc/NPg7B/SMWTS+kWMxsZvuD X0g2rdaUsp4oknInUy/yCzW9tA4yfY5pvQaBW1BjemVG9/oa81Q3OGPPPk8bR3+jEuXA a+Gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:content-language:mime-version:user-agent:date :message-id:from:to:delivered-to:arc-authentication-results; bh=O0vMtyRNN4+fGAkdOM7TBJVJ+Mngp2fEa1dpnpySA4Y=; b=ajh9ullqIZvqWem5MYXfLQu0nhB+Z4OVfGCgOmHAoa1hoyOVGp6ZoCc6fufUdtgBbd I01448uTQnDPVietsJySEVrpder9Wp6zQ1V1ZCCq25ySbIKjMippN2HSbqDFQOHJ70kT NXYfnO/glem1pec3Ors9z3Y1tmkiz2Av4oxpI1AnCIavsxCVXRbfEVuc4LABr7kNtZcu Om94RWVjApaju0tsQIoDygroze8ttT8Aplo9a8sdTf6dDMKd8UIlND6Zix5WR+1rIZQQ YEZJ3yPJyNROgMd0zWPuN6/qRTTVj2i4MoJ/JvC8vUUW5F9r2ZOIqpT+F8oVlinaInY5 29/w== ARC-Authentication-Results: i=1; mx.google.com; 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 1si4355604wry.114.2017.08.04.17.18.02; Fri, 04 Aug 2017 17:18:03 -0700 (PDT) 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; 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 5CD93680D56; Sat, 5 Aug 2017 03:17:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtp2.execulink.net (smtp2.execulink.net [69.63.44.83]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8CC2368091A for ; Sat, 5 Aug 2017 03:17:52 +0300 (EEST) Received: from 23-248-133-105.tpia.execulink.com ([23.248.133.105]) by smtp2.execulink.net with esmtpsa (UNKNOWN:AES256-SHA:256) (Exim 4.77) (envelope-from ) id 1ddmms-0008I7-RP for ffmpeg-devel@ffmpeg.org; Fri, 04 Aug 2017 20:17:51 -0400 To: ffmpeg-devel@ffmpeg.org From: DeHackEd Message-ID: Date: Fri, 4 Aug 2017 20:17:44 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 Content-Language: en-GB Subject: [FFmpeg-devel] [PATCH] libaf/hlsenc: allow dynamic encryption key rotation 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" Signed-off-by: DHE --- doc/muxers.texi | 7 ++++++- libavformat/hlsenc.c | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/doc/muxers.texi b/doc/muxers.texi index 94472ce..a7324a4 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -551,7 +551,7 @@ format. The optional third line specifies the initialization vector (IV) as a hexadecimal string to be used instead of the segment sequence number (default) for encryption. Changes to @var{key_info_file} will result in segment encryption with the new key/IV and an entry in the playlist for the new key -URI/IV. +URI/IV if @code{hls_flags periodic_rekey} is enabled. Key info file format: @example @@ -665,6 +665,11 @@ first segment's information. @item omit_endlist Do not append the @code{EXT-X-ENDLIST} tag at the end of the playlist. +@item periodic_rekey +The file specified by @code{hls_key_info} will be checked periodically and +detect updates to the encryption info. Be sure to replace this file atomically, +including the file containing the AES encryption key. + @item split_by_time Allow segments to start on frames other than keyframes. This improves behavior on some players when the time between keyframes is inconsistent, diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 5cf8c89..4d2e7fb 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -85,6 +85,7 @@ typedef enum HLSFlags { HLS_SECOND_LEVEL_SEGMENT_DURATION = (1 << 9), // include segment duration (microsec) in segment filenames when use_localtime e.g.: %%09t HLS_SECOND_LEVEL_SEGMENT_SIZE = (1 << 10), // include segment size (bytes) in segment filenames when use_localtime e.g.: %%014s HLS_TEMP_FILE = (1 << 11), + HLS_PERIODIC_REKEY = (1 << 12), } HLSFlags; typedef enum { @@ -1236,7 +1237,7 @@ static int hls_start(AVFormatContext *s) " will use -hls_key_info_file priority\n"); } - if (c->number <= 1) { + if (c->number <= 1 && !(c->flags & HLS_PERIODIC_REKEY)) { if (c->key_info_file) { if ((err = hls_encryption_start(s)) < 0) goto fail; @@ -1804,6 +1805,7 @@ static const AVOption options[] = { {"second_level_segment_index", "include segment index in segment filenames when use_localtime", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_SECOND_LEVEL_SEGMENT_INDEX }, 0, UINT_MAX, E, "flags"}, {"second_level_segment_duration", "include segment duration in segment filenames when use_localtime", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_SECOND_LEVEL_SEGMENT_DURATION }, 0, UINT_MAX, E, "flags"}, {"second_level_segment_size", "include segment size in segment filenames when use_localtime", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_SECOND_LEVEL_SEGMENT_SIZE }, 0, UINT_MAX, E, "flags"}, + {"periodic_rekey", "reload keyinfo file periodically for re-keying", 0, AV_OPT_TYPE_CONST, {.i64 = HLS_PERIODIC_REKEY }, 0, UINT_MAX, E, "flags"}, {"use_localtime", "set filename expansion with strftime at segment creation", OFFSET(use_localtime), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, E }, {"use_localtime_mkdir", "create last directory component in strftime-generated filename", OFFSET(use_localtime_mkdir), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, E }, {"hls_playlist_type", "set the HLS playlist type", OFFSET(pl_type), AV_OPT_TYPE_INT, {.i64 = PLAYLIST_TYPE_NONE }, 0, PLAYLIST_TYPE_NB-1, E, "pl_type" },