00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef _AP4_OMA_DCF_H_
00030 #define _AP4_OMA_DCF_H_
00031
00032
00033
00034
00035 #include "Ap4Types.h"
00036 #include "Ap4SampleEntry.h"
00037 #include "Ap4Atom.h"
00038 #include "Ap4AtomFactory.h"
00039 #include "Ap4SampleDescription.h"
00040 #include "Ap4Processor.h"
00041 #include "Ap4Protection.h"
00042
00043
00044
00045
00046 class AP4_CtrStreamCipher;
00047 class AP4_OdafAtom;
00048 class AP4_StreamCipher;
00049 class AP4_CbcStreamCipher;
00050 class AP4_CtrStreamCipher;
00051
00052
00053
00054
00055 const AP4_UI32 AP4_PROTECTION_SCHEME_TYPE_OMA = AP4_ATOM_TYPE('o','d','k','m');
00056 const AP4_UI32 AP4_PROTECTION_SCHEME_VERSION_OMA_20 = 0x00000200;
00057 const AP4_UI32 AP4_OMA_DCF_BRAND_ODCF = AP4_ATOM_TYPE('o','d','c','f');
00058 const AP4_UI32 AP4_OMA_DCF_BRAND_OPF2 = AP4_ATOM_TYPE('o','p','f','2');
00059
00060 typedef enum {
00061 AP4_OMA_DCF_CIPHER_MODE_CTR,
00062 AP4_OMA_DCF_CIPHER_MODE_CBC
00063 } AP4_OmaDcfCipherMode;
00064
00065
00066
00067
00068 class AP4_OmaDcfAtomDecrypter {
00069 public:
00070
00071 static AP4_Result DecryptAtoms(AP4_AtomParent& atoms,
00072 AP4_Processor::ProgressListener* listener,
00073 AP4_BlockCipherFactory* block_cipher_factory,
00074 AP4_ProtectionKeyMap& key_map);
00075
00076
00077
00078 static AP4_Result CreateDecryptingStream(AP4_ContainerAtom& odrm_atom,
00079 const AP4_UI08* key,
00080 AP4_Size key_size,
00081 AP4_BlockCipherFactory* block_cipher_factory,
00082 AP4_ByteStream*& stream);
00083
00084
00085
00086
00087
00088 static AP4_Result CreateDecryptingStream(AP4_OmaDcfCipherMode mode,
00089 AP4_ByteStream& encrypted_stream,
00090 AP4_LargeSize cleartext_size,
00091 const AP4_UI08* key,
00092 AP4_Size key_size,
00093 AP4_BlockCipherFactory* block_cipher_factory,
00094 AP4_ByteStream*& stream);
00095 };
00096
00097
00098
00099
00100 class AP4_OmaDcfSampleDecrypter : public AP4_SampleDecrypter
00101 {
00102 public:
00103
00104 static AP4_Result Create(AP4_ProtectedSampleDescription* sample_description,
00105 const AP4_UI08* key,
00106 AP4_Size key_size,
00107 AP4_BlockCipherFactory* block_cipher_factory,
00108 AP4_OmaDcfSampleDecrypter*& cipher);
00109
00110
00111 AP4_OmaDcfSampleDecrypter(AP4_Size iv_length,
00112 bool selective_encryption) :
00113 m_IvLength(iv_length),
00114 m_SelectiveEncryption(selective_encryption) {}
00115
00116
00117 virtual AP4_Size GetDecryptedSampleSize(AP4_Sample& sample) = 0;
00118
00119 protected:
00120 AP4_Size m_IvLength;
00121 AP4_Size m_KeyIndicatorLength;
00122 bool m_SelectiveEncryption;
00123 };
00124
00125
00126
00127
00128 class AP4_OmaDcfCtrSampleDecrypter : public AP4_OmaDcfSampleDecrypter
00129 {
00130 public:
00131
00132 AP4_OmaDcfCtrSampleDecrypter(AP4_BlockCipher* block_cipher,
00133 AP4_Size iv_length,
00134 bool selective_encryption);
00135 ~AP4_OmaDcfCtrSampleDecrypter();
00136
00137
00138 virtual AP4_Result DecryptSampleData(AP4_DataBuffer& data_in,
00139 AP4_DataBuffer& data_out);
00140 virtual AP4_Size GetDecryptedSampleSize(AP4_Sample& sample);
00141
00142 private:
00143
00144 AP4_CtrStreamCipher* m_Cipher;
00145 };
00146
00147
00148
00149
00150 class AP4_OmaDcfCbcSampleDecrypter : public AP4_OmaDcfSampleDecrypter
00151 {
00152 public:
00153
00154 AP4_OmaDcfCbcSampleDecrypter(AP4_BlockCipher* block_cipher,
00155 bool selective_encryption);
00156 ~AP4_OmaDcfCbcSampleDecrypter();
00157
00158
00159 virtual AP4_Result DecryptSampleData(AP4_DataBuffer& data_in,
00160 AP4_DataBuffer& data_out);
00161 virtual AP4_Size GetDecryptedSampleSize(AP4_Sample& sample);
00162
00163 private:
00164
00165 AP4_CbcStreamCipher* m_Cipher;
00166 };
00167
00168
00169
00170
00171 class AP4_OmaDcfTrackDecrypter : public AP4_Processor::TrackHandler {
00172 public:
00173
00174 static AP4_Result Create(const AP4_UI08* key,
00175 AP4_Size key_size,
00176 AP4_ProtectedSampleDescription* sample_description,
00177 AP4_SampleEntry* sample_entry,
00178 AP4_BlockCipherFactory* block_cipher_factory,
00179 AP4_OmaDcfTrackDecrypter*& decrypter);
00180 virtual ~AP4_OmaDcfTrackDecrypter();
00181
00182
00183 virtual AP4_Size GetProcessedSampleSize(AP4_Sample& sample);
00184 virtual AP4_Result ProcessTrack();
00185 virtual AP4_Result ProcessSample(AP4_DataBuffer& data_in,
00186 AP4_DataBuffer& data_out);
00187
00188 private:
00189
00190 AP4_OmaDcfTrackDecrypter(AP4_OmaDcfSampleDecrypter* cipher,
00191 AP4_SampleEntry* sample_entry,
00192 AP4_UI32 original_format);
00193
00194
00195 AP4_OmaDcfSampleDecrypter* m_Cipher;
00196 AP4_SampleEntry* m_SampleEntry;
00197 AP4_UI32 m_OriginalFormat;
00198 };
00199
00200
00201
00202
00203 class AP4_OmaDcfSampleEncrypter
00204 {
00205 public:
00206
00207 AP4_OmaDcfSampleEncrypter(const AP4_UI08* salt);
00208 virtual ~AP4_OmaDcfSampleEncrypter() {}
00209
00210
00211 virtual AP4_Result EncryptSampleData(AP4_DataBuffer& data_in,
00212 AP4_DataBuffer& data_out,
00213 AP4_UI64 bso,
00214 bool skip_encryption) = 0;
00215 virtual AP4_Size GetEncryptedSampleSize(AP4_Sample& sample) = 0;
00216
00217 protected:
00218
00219 AP4_UI08 m_Salt[16];
00220 };
00221
00222
00223
00224
00225 class AP4_OmaDcfCtrSampleEncrypter : public AP4_OmaDcfSampleEncrypter
00226 {
00227 public:
00228
00229 AP4_OmaDcfCtrSampleEncrypter(AP4_BlockCipher* block_cipher,
00230 const AP4_UI08* salt);
00231 ~AP4_OmaDcfCtrSampleEncrypter();
00232
00233
00234 virtual AP4_Result EncryptSampleData(AP4_DataBuffer& data_in,
00235 AP4_DataBuffer& data_out,
00236 AP4_UI64 bso,
00237 bool skip_encryption);
00238 virtual AP4_Size GetEncryptedSampleSize(AP4_Sample& sample);
00239
00240 private:
00241
00242 AP4_CtrStreamCipher* m_Cipher;
00243 };
00244
00245
00246
00247
00248 class AP4_OmaDcfCbcSampleEncrypter : public AP4_OmaDcfSampleEncrypter
00249 {
00250 public:
00251
00252 AP4_OmaDcfCbcSampleEncrypter(AP4_BlockCipher* block_cipher,
00253 const AP4_UI08* salt);
00254 ~AP4_OmaDcfCbcSampleEncrypter();
00255
00256
00257 virtual AP4_Result EncryptSampleData(AP4_DataBuffer& data_in,
00258 AP4_DataBuffer& data_out,
00259 AP4_UI64 bso,
00260 bool skip_encryption);
00261 virtual AP4_Size GetEncryptedSampleSize(AP4_Sample& sample);
00262
00263 private:
00264
00265 AP4_CbcStreamCipher* m_Cipher;
00266 };
00267
00268
00269
00270
00271 class AP4_TrackPropertyMap
00272 {
00273 public:
00274
00275 AP4_Result SetProperty(AP4_UI32 track_id, const char* name, const char* value);
00276 AP4_Result SetProperties(const AP4_TrackPropertyMap& properties);
00277 const char* GetProperty(AP4_UI32 track_id, const char* name);
00278 AP4_Result GetTextualHeaders(AP4_UI32 track_id, AP4_DataBuffer& buffer);
00279
00280
00281
00282 virtual ~AP4_TrackPropertyMap();
00283
00284 private:
00285
00286 class Entry {
00287 public:
00288 Entry(AP4_UI32 track_id, const char* name, const char* value) :
00289 m_TrackId(track_id), m_Name(name), m_Value(value) {}
00290 AP4_UI32 m_TrackId;
00291 AP4_String m_Name;
00292 AP4_String m_Value;
00293 };
00294
00295
00296 AP4_List<Entry> m_Entries;
00297 };
00298
00299
00300
00301
00306 class AP4_OmaDcfDecryptingProcessor : public AP4_Processor
00307 {
00308 public:
00309
00310 AP4_OmaDcfDecryptingProcessor(const AP4_ProtectionKeyMap* key_map = NULL,
00311 AP4_BlockCipherFactory* block_cipher_factory = NULL);
00312
00313
00314 AP4_ProtectionKeyMap& GetKeyMap() { return m_KeyMap; }
00315
00316
00317 virtual AP4_Result Initialize(AP4_AtomParent& top_level,
00318 AP4_ByteStream& stream,
00319 ProgressListener* listener);
00320
00321 private:
00322
00323 AP4_BlockCipherFactory* m_BlockCipherFactory;
00324 AP4_ProtectionKeyMap m_KeyMap;
00325 };
00326
00327
00328
00329
00330 class AP4_OmaDcfEncryptingProcessor : public AP4_Processor
00331 {
00332 public:
00333
00334 AP4_OmaDcfEncryptingProcessor(AP4_OmaDcfCipherMode cipher_mode,
00335 AP4_BlockCipherFactory* block_cipher_factory = NULL);
00336
00337
00338 AP4_ProtectionKeyMap& GetKeyMap() { return m_KeyMap; }
00339 AP4_TrackPropertyMap& GetPropertyMap() { return m_PropertyMap; }
00340
00341
00342 virtual AP4_Result Initialize(AP4_AtomParent& top_level,
00343 AP4_ByteStream& stream,
00344 AP4_Processor::ProgressListener* listener = NULL);
00345 virtual AP4_Processor::TrackHandler* CreateTrackHandler(AP4_TrakAtom* trak);
00346
00347 private:
00348
00349 AP4_OmaDcfCipherMode m_CipherMode;
00350 AP4_BlockCipherFactory* m_BlockCipherFactory;
00351 AP4_ProtectionKeyMap m_KeyMap;
00352 AP4_TrackPropertyMap m_PropertyMap;
00353 };
00354
00355 #endif // _AP4_OMA_DCF_H_