libgpac
Documentation of the core library of GPAC
Loading...
Searching...
No Matches
decrypt_cenc_isma.c File Reference
#include <gpac/filters.h>
#include <gpac/constants.h>
#include <gpac/crypt_tools.h>
#include <gpac/crypt.h>
#include <gpac/base_coding.h>
#include <gpac/download.h>
#include <gpac/network.h>
#include <gpac/internal/media_dev.h>

Data Structures

struct  CENCDecKey
 
struct  GF_CENCDecStream
 
struct  GF_CENCDecCtx
 
struct  ClearKeyParam
 

Macros

#define CK_MAX_BUF   1000
 
#define OFFS(_n)   #_n, offsetof(GF_CENCDecCtx, _n)
 

Enumerations

enum  { DECRYPT_STATE_ERROR =1 , DECRYPT_STATE_SETUP , DECRYPT_STATE_PLAY }
 
enum  { DECRYPT_FULL =0 , DECRYPT_NOKEY , DECRYPT_SKIP }
 

Functions

static GF_Err cenc_dec_setup_isma (GF_CENCDecCtx *ctx, GF_CENCDecStream *cstr, u32 scheme_type, u32 scheme_version, const char *scheme_uri, const char *kms_uri)
 
static GF_Err cenc_dec_access_isma (GF_CENCDecCtx *ctx, GF_CENCDecStream *cstr, Bool is_play)
 
static GF_Err cenc_dec_process_isma (GF_CENCDecCtx *ctx, GF_CENCDecStream *cstr, GF_FilterPacket *in_pck)
 
static GF_Err cenc_dec_load_keys (GF_CENCDecCtx *ctx, GF_CENCDecStream *cstr)
 
static void ck_http_io (void *usr_cbk, GF_NETIO_Parameter *par)
 
static GF_Err rfmt_dec_b64 (u8 *data, u8 *output, u32 osize)
 
static GF_Err cenc_dec_set_clearkey (GF_CENCDecCtx *ctx, GF_CENCDecStream *cstr, char *ck_url, u8 *ck_kid)
 
static GF_Err cenc_dec_set_hls_key (GF_CENCDecCtx *ctx, GF_CENCDecStream *cstr, char *key_url, u8 *key_IV)
 
static GF_Err cenc_dec_push_iv (GF_CENCDecStream *cstr, u32 key_idx, u8 *IV, u32 iv_size, u32 const_iv_size, const u8 *const_iv)
 
static GF_Err cenc_dec_load_pssh (GF_CENCDecCtx *ctx, GF_CENCDecStream *cstr, const GF_PropertyValue *pssh_prop, Bool is_pck_pssh, const GF_PropertyValue *cinfo_prop)
 
static GF_Err cenc_dec_setup_cenc (GF_CENCDecCtx *ctx, GF_CENCDecStream *cstr, u32 scheme_type, u32 scheme_version, const char *scheme_uri, const char *kms_uri)
 
static GF_Err cenc_dec_hls_saes (GF_CENCDecCtx *ctx, GF_CENCDecStream *cstr, u32 scheme_type, u32 scheme_version, const char *scheme_uri, const char *kms_uri)
 
static GF_Err cenc_dec_setup_adobe (GF_CENCDecCtx *ctx, GF_CENCDecStream *cstr, u32 scheme_type, u32 scheme_version, const char *scheme_uri, const char *kms_uri)
 
static GF_Err cenc_dec_access_cenc (GF_CENCDecCtx *ctx, GF_CENCDecStream *cstr, Bool is_play)
 
static GF_Err cenc_dec_access_adobe (GF_CENCDecCtx *ctx, GF_CENCDecStream *cstr, Bool is_play)
 
u8 key_info_get_iv_size (const u8 *key_info, u32 nb_keys, u32 idx, u8 *const_iv_size, const u8 **const_iv)
 
static GF_Err cenc_dec_process_cenc (GF_CENCDecCtx *ctx, GF_CENCDecStream *cstr, GF_FilterPacket *in_pck)
 
static GF_Err cenc_dec_process_hls_saes (GF_CENCDecCtx *ctx, GF_CENCDecStream *cstr, GF_FilterPacket *in_pck)
 
static GF_Err cenc_dec_process_adobe (GF_CENCDecCtx *ctx, GF_CENCDecStream *cstr, GF_FilterPacket *in_pck)
 
static void cenc_dec_stream_del (GF_CENCDecStream *cstr)
 
static GF_Err cenc_dec_configure_pid (GF_Filter *filter, GF_FilterPid *pid, Bool is_remove)
 
static Bool cenc_dec_process_event (GF_Filter *filter, const GF_FilterEvent *evt)
 
static GF_Err cenc_dec_process (GF_Filter *filter)
 
static GF_Err cenc_dec_initialize (GF_Filter *filter)
 
static void cenc_dec_finalize (GF_Filter *filter)
 
const GF_FilterRegister * cenc_decrypt_register (GF_FilterSession *session)
 

Variables

static const GF_FilterCapability CENCDecCaps []
 
static const GF_FilterArgs GF_CENCDecArgs []
 
GF_FilterRegister CENCDecRegister
 

Data Structure Documentation

◆ CENCDecKey

struct CENCDecKey
Data Fields
GF_Crypt * crypt
bin128 key
u32 key_valid

◆ GF_CENCDecStream

struct GF_CENCDecStream
Data Fields
GF_FilterPid * ipid
GF_FilterPid * opid
u32 state
u32 pssh_crc
u32 scheme_type
u32 scheme_version
GF_Err key_error
CENCDecKey * crypts
u32 nb_crypts
char salt[8]
u64 last_IV
u32 nb_allow_play
Bool is_oma
Bool is_adobe
u32 preview_range
Bool is_nalu
Bool selective_encryption
u32 IV_length
u32 KI_length
Bool is_cenc
Bool is_cbc
u32 KID_count
Bool inband_keys
bin128 * KIDs
bin128 * keys
const GF_PropertyValue * cenc_ki
u32 multikey
const GF_PropertyValue * cenc_pattern
Bool crypt_init
Bool is_hls
bin128 hls_IV
char * hls_key_url
Bool is_hls_saes
u32 codec_id
Bool force_hls_iv
Bool gpac_master_leaf
bin128 master_key
u32 clearkey_crc

◆ GF_CENCDecCtx

struct GF_CENCDecCtx
Data Fields
const char * cfile
u32 decrypt
GF_PropUIntList drop_keys
GF_PropStringList kids
GF_PropStringList keys
GF_CryptInfo * cinfo
Bool hls_cenc_patch_iv
GF_Filter * filter
GF_List * streams
GF_BitStream * bs_r
GF_DownloadManager * dm

◆ ClearKeyParam

struct ClearKeyParam
Data Fields
u8 * data
u32 data_len
Bool hdr_done

Macro Definition Documentation

◆ CK_MAX_BUF

#define CK_MAX_BUF   1000

◆ OFFS

#define OFFS (   _n)    #_n, offsetof(GF_CENCDecCtx, _n)

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
DECRYPT_STATE_ERROR 
DECRYPT_STATE_SETUP 
DECRYPT_STATE_PLAY 

◆ anonymous enum

anonymous enum
Enumerator
DECRYPT_FULL 
DECRYPT_NOKEY 
DECRYPT_SKIP 

Function Documentation

◆ cenc_dec_setup_isma()

static GF_Err cenc_dec_setup_isma ( GF_CENCDecCtx ctx,
GF_CENCDecStream cstr,
u32  scheme_type,
u32  scheme_version,
const char *  scheme_uri,
const char *  kms_uri 
)
static

◆ cenc_dec_access_isma()

static GF_Err cenc_dec_access_isma ( GF_CENCDecCtx ctx,
GF_CENCDecStream cstr,
Bool  is_play 
)
static

◆ cenc_dec_process_isma()

static GF_Err cenc_dec_process_isma ( GF_CENCDecCtx ctx,
GF_CENCDecStream cstr,
GF_FilterPacket *  in_pck 
)
static

◆ cenc_dec_load_keys()

static GF_Err cenc_dec_load_keys ( GF_CENCDecCtx ctx,
GF_CENCDecStream cstr 
)
static

◆ ck_http_io()

static void ck_http_io ( void *  usr_cbk,
GF_NETIO_Parameter par 
)
static

◆ rfmt_dec_b64()

static GF_Err rfmt_dec_b64 ( u8 data,
u8 output,
u32  osize 
)
static

◆ cenc_dec_set_clearkey()

static GF_Err cenc_dec_set_clearkey ( GF_CENCDecCtx ctx,
GF_CENCDecStream cstr,
char *  ck_url,
u8 ck_kid 
)
static

◆ cenc_dec_set_hls_key()

static GF_Err cenc_dec_set_hls_key ( GF_CENCDecCtx ctx,
GF_CENCDecStream cstr,
char *  key_url,
u8 key_IV 
)
static

◆ cenc_dec_push_iv()

static GF_Err cenc_dec_push_iv ( GF_CENCDecStream cstr,
u32  key_idx,
u8 IV,
u32  iv_size,
u32  const_iv_size,
const u8 const_iv 
)
static

◆ cenc_dec_load_pssh()

static GF_Err cenc_dec_load_pssh ( GF_CENCDecCtx ctx,
GF_CENCDecStream cstr,
const GF_PropertyValue *  pssh_prop,
Bool  is_pck_pssh,
const GF_PropertyValue *  cinfo_prop 
)
static

◆ cenc_dec_setup_cenc()

static GF_Err cenc_dec_setup_cenc ( GF_CENCDecCtx ctx,
GF_CENCDecStream cstr,
u32  scheme_type,
u32  scheme_version,
const char *  scheme_uri,
const char *  kms_uri 
)
static

◆ cenc_dec_hls_saes()

static GF_Err cenc_dec_hls_saes ( GF_CENCDecCtx ctx,
GF_CENCDecStream cstr,
u32  scheme_type,
u32  scheme_version,
const char *  scheme_uri,
const char *  kms_uri 
)
static

◆ cenc_dec_setup_adobe()

static GF_Err cenc_dec_setup_adobe ( GF_CENCDecCtx ctx,
GF_CENCDecStream cstr,
u32  scheme_type,
u32  scheme_version,
const char *  scheme_uri,
const char *  kms_uri 
)
static

◆ cenc_dec_access_cenc()

static GF_Err cenc_dec_access_cenc ( GF_CENCDecCtx ctx,
GF_CENCDecStream cstr,
Bool  is_play 
)
static

◆ cenc_dec_access_adobe()

static GF_Err cenc_dec_access_adobe ( GF_CENCDecCtx ctx,
GF_CENCDecStream cstr,
Bool  is_play 
)
static

◆ key_info_get_iv_size()

u8 key_info_get_iv_size ( const u8 key_info,
u32  nb_keys,
u32  idx,
u8 const_iv_size,
const u8 **  const_iv 
)

◆ cenc_dec_process_cenc()

static GF_Err cenc_dec_process_cenc ( GF_CENCDecCtx ctx,
GF_CENCDecStream cstr,
GF_FilterPacket *  in_pck 
)
static

◆ cenc_dec_process_hls_saes()

static GF_Err cenc_dec_process_hls_saes ( GF_CENCDecCtx ctx,
GF_CENCDecStream cstr,
GF_FilterPacket *  in_pck 
)
static

◆ cenc_dec_process_adobe()

static GF_Err cenc_dec_process_adobe ( GF_CENCDecCtx ctx,
GF_CENCDecStream cstr,
GF_FilterPacket *  in_pck 
)
static

◆ cenc_dec_stream_del()

static void cenc_dec_stream_del ( GF_CENCDecStream cstr)
static

◆ cenc_dec_configure_pid()

static GF_Err cenc_dec_configure_pid ( GF_Filter *  filter,
GF_FilterPid *  pid,
Bool  is_remove 
)
static

◆ cenc_dec_process_event()

static Bool cenc_dec_process_event ( GF_Filter *  filter,
const GF_FilterEvent *  evt 
)
static

◆ cenc_dec_process()

static GF_Err cenc_dec_process ( GF_Filter *  filter)
static

◆ cenc_dec_initialize()

static GF_Err cenc_dec_initialize ( GF_Filter *  filter)
static

◆ cenc_dec_finalize()

static void cenc_dec_finalize ( GF_Filter *  filter)
static

◆ cenc_decrypt_register()

const GF_FilterRegister * cenc_decrypt_register ( GF_FilterSession *  session)

Variable Documentation

◆ CENCDecCaps

const GF_FilterCapability CENCDecCaps[]
static
Initial value:
=
{
}
#define GF_HLS_SAMPLE_AES_SCHEME
Definition constants.h:1165
@ GF_CODECID_NONE
Definition constants.h:367
@ GF_STREAM_ENCRYPTED
Definition constants.h:102
@ GF_STREAM_FILE
Definition constants.h:104
#define CAP_UINT(_f, _a, _b)
Definition filters.h:1955
#define CAP_4CC(_f, _a, _b)
Definition filters.h:1957
#define GF_CAPS_INPUT_EXCLUDED
Definition filters.h:2009
#define GF_CAPS_OUTPUT_EXCLUDED
Definition filters.h:2017
#define CAP_BOOL(_f, _a, _b)
Definition filters.h:1963
#define GF_CAPS_INPUT
Definition filters.h:2001
@ GF_PROP_PID_CODECID
Definition filters.h:1020
@ GF_PROP_PID_STREAM_TYPE
Definition filters.h:1016
@ GF_PROP_PID_UNFRAMED
Definition filters.h:1022
@ GF_PROP_PID_PROTECTION_SCHEME_TYPE
Definition filters.h:1110
@ GF_ISOM_ADOBE_SCHEME
Definition isomedia.h:5465
@ GF_ISOM_PIFF_SCHEME
Definition isomedia.h:5471
@ GF_ISOM_CBCS_SCHEME
Definition isomedia.h:5469
@ GF_ISOM_CENC_SCHEME
Definition isomedia.h:5461
@ GF_ISOM_CBC_SCHEME
Definition isomedia.h:5463
@ GF_ISOM_OMADRM_SCHEME
Definition isomedia.h:5459
@ GF_ISOM_CENS_SCHEME
Definition isomedia.h:5467
@ GF_ISOM_ISMACRYP_SCHEME
Definition isomedia.h:5457
@ GF_TRUE
Definition setup.h:435

◆ GF_CENCDecArgs

const GF_FilterArgs GF_CENCDecArgs[]
static
Initial value:
=
{
{ OFFS(cfile), "crypt file location", GF_PROP_STRING, NULL, NULL, 0},
{ OFFS(decrypt), "decrypt mode (CENC only)\n"
"- full: decrypt everything, throwing error if keys are not found\n"
"- nokey: decrypt everything for which a key is found, skip decryption otherwise\n"
"- skip: decrypt nothing"
, GF_PROP_UINT, "full", "full|nokey|skip", GF_ARG_HINT_ADVANCED},
{ OFFS(drop_keys), "consider keys with given 1-based indexes as not available (multi-key debug)", GF_PROP_UINT_LIST, NULL, NULL, GF_ARG_HINT_EXPERT},
{ OFFS(kids), "define KIDs. If `keys` is empty, consider keys with given KID (as hex string) as not available (debug)", GF_PROP_STRING_LIST, NULL, NULL, GF_ARG_HINT_EXPERT},
{ OFFS(keys), "define key values for each of the specified KID", GF_PROP_STRING_LIST, NULL, NULL, GF_ARG_HINT_EXPERT},
{ OFFS(hls_cenc_patch_iv), "ignore IV updates in some broken HLS+CENC streams", GF_PROP_BOOL, "false", NULL, GF_ARG_HINT_EXPERT},
{0}
}
#define OFFS(_n)
Definition decrypt_cenc_isma.c:2320
@ GF_PROP_BOOL
Definition filters.h:767
@ GF_PROP_STRING
Definition filters.h:785
@ GF_PROP_UINT_LIST
Definition filters.h:806
@ GF_PROP_STRING_LIST
Definition filters.h:804
@ GF_PROP_UINT
Definition filters.h:761
#define GF_ARG_HINT_ADVANCED
Definition main.h:121
#define GF_ARG_HINT_EXPERT
Definition main.h:123

◆ CENCDecRegister

GF_FilterRegister CENCDecRegister
Initial value:
= {
.name = "cdcrypt",
GF_FS_SET_HELP("The CENC decryptor supports decrypting CENC, ISMA, HLS Sample-AES (MPEG2 ts) and Adobe streams.\n"
"\n"
"For HLS, key is retrieved according to the key URI in the manifest.\n"
"Otherwise, the filter uses a configuration file.\n"
"The syntax is available at https://wiki.gpac.io/Common-Encryption\n"
"The DRM config file can be set per PID using the property `DecryptInfo` (highest priority), `CryptInfo` (lower priority) "
"or set at the filter level using [-cfile]() (lowest priority).\n"
"When the file is set per PID, the first `CryptInfo` with the same ID is used, otherwise the first `CryptInfo` is used."
"When the file is set globally (not per PID), the first `CrypTrack` in the DRM config file with the same ID is used, otherwise the first `CrypTrack` with ID 0 or not set is used.\n"
)
.private_size = sizeof(GF_CENCDecCtx),
.max_extra_pids=-1,
.configure_pid = cenc_dec_configure_pid,
.initialize = cenc_dec_initialize,
.finalize = cenc_dec_finalize,
.process = cenc_dec_process,
.process_event = cenc_dec_process_event
}
static const GF_FilterArgs GF_CENCDecArgs[]
Definition decrypt_cenc_isma.c:2321
static GF_Err cenc_dec_initialize(GF_Filter *filter)
Definition decrypt_cenc_isma.c:2259
static GF_Err cenc_dec_process(GF_Filter *filter)
Definition decrypt_cenc_isma.c:2218
static Bool cenc_dec_process_event(GF_Filter *filter, const GF_FilterEvent *evt)
Definition decrypt_cenc_isma.c:2184
static void cenc_dec_finalize(GF_Filter *filter)
Definition decrypt_cenc_isma.c:2285
static GF_Err cenc_dec_configure_pid(GF_Filter *filter, GF_FilterPid *pid, Bool is_remove)
Definition decrypt_cenc_isma.c:2011
static const GF_FilterCapability CENCDecCaps[]
Definition decrypt_cenc_isma.c:2300
Definition decrypt_cenc_isma.c:113
#define GF_FS_SET_HELP(_help)
Definition filters.h:2152
#define SETCAPS(__struct)
Definition filters.h:2144
attribute Array args
Definition jsf.idl:24