2014-02-14 23:21:05 +00:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2014-08-20 23:51:15 +00:00
|
|
|
#ifndef MEDIA_BASE_KEY_SOURCE_H_
|
|
|
|
#define MEDIA_BASE_KEY_SOURCE_H_
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2016-02-17 22:03:43 +00:00
|
|
|
#include <string>
|
2013-11-12 20:34:58 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2016-02-17 22:03:43 +00:00
|
|
|
#include "packager/media/base/protection_system_specific_info.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/media/base/status.h"
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2013-10-11 21:44:55 +00:00
|
|
|
namespace media {
|
|
|
|
|
2014-04-15 22:18:26 +00:00
|
|
|
struct EncryptionKey {
|
|
|
|
EncryptionKey();
|
|
|
|
~EncryptionKey();
|
|
|
|
|
2016-02-17 22:03:43 +00:00
|
|
|
std::vector<ProtectionSystemSpecificInfo> key_system_info;
|
2014-09-30 21:52:21 +00:00
|
|
|
std::vector<uint8_t> key_id;
|
|
|
|
std::vector<uint8_t> key;
|
|
|
|
std::vector<uint8_t> iv;
|
2014-04-15 22:18:26 +00:00
|
|
|
};
|
2014-01-13 19:34:08 +00:00
|
|
|
|
2014-08-20 23:51:15 +00:00
|
|
|
/// KeySource is responsible for encryption key acquisition.
|
|
|
|
class KeySource {
|
2013-10-11 21:44:55 +00:00
|
|
|
public:
|
2014-04-15 22:18:26 +00:00
|
|
|
enum TrackType {
|
|
|
|
TRACK_TYPE_UNKNOWN = 0,
|
|
|
|
TRACK_TYPE_SD = 1,
|
|
|
|
TRACK_TYPE_HD = 2,
|
2016-11-11 23:17:17 +00:00
|
|
|
TRACK_TYPE_UHD1 = 3,
|
|
|
|
TRACK_TYPE_UHD2 = 4,
|
|
|
|
TRACK_TYPE_AUDIO = 5,
|
|
|
|
TRACK_TYPE_UNSPECIFIED = 6,
|
|
|
|
NUM_VALID_TRACK_TYPES = 6
|
2014-04-15 22:18:26 +00:00
|
|
|
};
|
|
|
|
|
2016-02-19 20:23:37 +00:00
|
|
|
KeySource();
|
2014-08-20 23:51:15 +00:00
|
|
|
virtual ~KeySource();
|
|
|
|
|
|
|
|
/// Fetch keys for CENC from the key server.
|
2016-02-19 18:24:33 +00:00
|
|
|
/// @param pssh_box The entire PSSH box for the content to be decrypted
|
|
|
|
/// @return OK on success, an error status otherwise.
|
2016-02-19 20:23:37 +00:00
|
|
|
virtual Status FetchKeys(const std::vector<uint8_t>& pssh_box) = 0;
|
2016-02-19 18:24:33 +00:00
|
|
|
|
|
|
|
/// Fetch keys for CENC from the key server.
|
|
|
|
/// @param key_ids the key IDs for the keys to fetch from the server.
|
2014-08-20 23:51:15 +00:00
|
|
|
/// @return OK on success, an error status otherwise.
|
2016-02-19 20:23:37 +00:00
|
|
|
virtual Status FetchKeys(
|
|
|
|
const std::vector<std::vector<uint8_t>>& key_ids) = 0;
|
2013-11-12 20:34:58 +00:00
|
|
|
|
2014-10-09 19:56:51 +00:00
|
|
|
/// Fetch keys for WVM decryption from the key server.
|
|
|
|
/// @param asset_id is the Widevine Classic asset ID for the content to be
|
|
|
|
/// decrypted.
|
|
|
|
/// @return OK on success, an error status otherwise.
|
2016-02-19 20:23:37 +00:00
|
|
|
virtual Status FetchKeys(uint32_t asset_id) = 0;
|
2014-10-09 19:56:51 +00:00
|
|
|
|
2014-04-15 22:18:26 +00:00
|
|
|
/// Get encryption key of the specified track type.
|
2014-08-20 23:51:15 +00:00
|
|
|
/// @param track_type is the type of track for which retrieving the key.
|
|
|
|
/// @param key is a pointer to the EncryptionKey which will hold the retrieved
|
|
|
|
/// key. Owner retains ownership, and may not be NULL.
|
2014-04-15 22:18:26 +00:00
|
|
|
/// @return OK on success, an error status otherwise.
|
2016-02-19 20:23:37 +00:00
|
|
|
virtual Status GetKey(TrackType track_type, EncryptionKey* key) = 0;
|
2013-11-12 20:34:58 +00:00
|
|
|
|
2014-08-20 23:51:15 +00:00
|
|
|
/// Get the encryption key specified by the CENC key ID.
|
|
|
|
/// @param key_id is the unique identifier for the key being retreived.
|
|
|
|
/// @param key is a pointer to the EncryptionKey which will hold the retrieved
|
|
|
|
/// key. Owner retains ownership, and may not be NULL.
|
|
|
|
/// @return OK on success, or an error status otherwise.
|
2016-02-19 20:23:37 +00:00
|
|
|
virtual Status GetKey(const std::vector<uint8_t>& key_id,
|
|
|
|
EncryptionKey* key) = 0;
|
2014-08-20 23:51:15 +00:00
|
|
|
|
2014-04-18 18:49:49 +00:00
|
|
|
/// Get encryption key of the specified track type at the specified index.
|
2014-08-20 23:51:15 +00:00
|
|
|
/// @param crypto_period_index is the sequence number of the key rotation
|
|
|
|
/// period for which the key is being retrieved.
|
|
|
|
/// @param track_type is the type of track for which retrieving the key.
|
|
|
|
/// @param key is a pointer to the EncryptionKey which will hold the retrieved
|
|
|
|
/// key. Owner retains ownership, and may not be NULL.
|
2014-04-18 18:49:49 +00:00
|
|
|
/// @return OK on success, an error status otherwise.
|
2014-09-30 21:52:21 +00:00
|
|
|
virtual Status GetCryptoPeriodKey(uint32_t crypto_period_index,
|
2014-04-18 18:49:49 +00:00
|
|
|
TrackType track_type,
|
2016-02-19 20:23:37 +00:00
|
|
|
EncryptionKey* key) = 0;
|
2014-01-13 19:34:08 +00:00
|
|
|
|
2014-04-15 22:18:26 +00:00
|
|
|
/// Convert string representation of track type to enum representation.
|
|
|
|
static TrackType GetTrackTypeFromString(const std::string& track_type_string);
|
2014-01-13 19:34:08 +00:00
|
|
|
|
2014-04-15 22:18:26 +00:00
|
|
|
/// Convert TrackType to string.
|
|
|
|
static std::string TrackTypeToString(TrackType track_type);
|
2013-11-12 20:34:58 +00:00
|
|
|
|
2013-10-11 21:44:55 +00:00
|
|
|
private:
|
2014-08-20 23:51:15 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(KeySource);
|
2013-10-11 21:44:55 +00:00
|
|
|
};
|
2014-04-15 22:18:26 +00:00
|
|
|
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2013-10-11 21:44:55 +00:00
|
|
|
|
2014-08-20 23:51:15 +00:00
|
|
|
#endif // MEDIA_BASE_KEY_SOURCE_H_
|