| 1 |
/* |
| 2 |
* Copyright (C) 2005-2018 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#pragma once |
| 10 |
|
| 11 |
#include "commons/Buffer.h" |
| 12 |
|
| 13 |
#include <map> |
| 14 |
#include <string> |
| 15 |
#include <vector> |
| 16 |
|
| 17 |
namespace DRM |
| 18 |
{ |
| 19 |
class CCryptoSession; |
| 20 |
|
| 21 |
typedef CCryptoSession* (*GET_CRYPTO_SESSION_INTERFACE_FN)(const std::string& UUID, const std::string& cipherAlgo, const std::string& hmacAlgo); |
| 22 |
|
| 23 |
class CCryptoSession |
| 24 |
{ |
| 25 |
public: |
| 26 |
// Interface registration |
| 27 |
static CCryptoSession* GetCryptoSession(const std::string& UUID, const std::string& cipherAlgo, const std::string& macAlgo); |
| 28 |
virtual ~CCryptoSession() = default; |
| 29 |
|
| 30 |
// Interface methods |
| 31 |
virtual XbmcCommons::Buffer GetKeyRequest(const XbmcCommons::Buffer& init, const std::string& mimeType, bool offlineKey, const std::map<std::string, std::string>& parameters) = 0; |
| 32 |
virtual std::string GetPropertyString(const std::string& name) = 0; |
| 33 |
virtual std::string ProvideKeyResponse(const XbmcCommons::Buffer& response) = 0; |
| 34 |
virtual void RemoveKeys() = 0; |
| 35 |
virtual void RestoreKeys(const std::string& keySetId) = 0; |
| 36 |
virtual void SetPropertyString(const std::string& name, const std::string& value) = 0; |
| 37 |
|
| 38 |
// Crypto methods |
| 39 |
virtual XbmcCommons::Buffer Decrypt(const XbmcCommons::Buffer& cipherKeyId, const XbmcCommons::Buffer& input, const XbmcCommons::Buffer& iv) = 0; |
| 40 |
virtual XbmcCommons::Buffer Encrypt(const XbmcCommons::Buffer& cipherKeyId, const XbmcCommons::Buffer& input, const XbmcCommons::Buffer& iv) = 0; |
| 41 |
virtual XbmcCommons::Buffer Sign(const XbmcCommons::Buffer& macKeyId, const XbmcCommons::Buffer& message) = 0; |
| 42 |
virtual bool Verify(const XbmcCommons::Buffer& macKeyId, const XbmcCommons::Buffer& message, const XbmcCommons::Buffer& signature ) = 0; |
| 43 |
|
| 44 |
protected: |
| 45 |
static void RegisterInterface(GET_CRYPTO_SESSION_INTERFACE_FN fn); |
| 46 |
|
| 47 |
private: |
| 48 |
static std::vector<GET_CRYPTO_SESSION_INTERFACE_FN> s_registeredInterfaces; |
| 49 |
}; |
| 50 |
|
| 51 |
} //namespace |