RDK Documentation (Open Sourced RDK Components)
ClearKeyDrmSession.h
Go to the documentation of this file.
1 /*
2  * If not stated otherwise in this file or this component's license file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2018 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 /**
21  * @file ClearKeyDrmSession.h
22  * @brief Header file for ClearKeySession
23  */
24 
25 #ifndef ClearKeySession_h
26 #define ClearKeySession_h
27 
28 #include "AampDrmSession.h"
29 #include "openssl/evp.h"
30 #include "_base64.h"
31 
32 #include <memory>
33 #include <pthread.h>
34 #include <cjson/cJSON.h>
35 
36 using namespace std;
37 
38 /**
39  * @class ClearKeySession
40  * @brief Open CDM DRM session
41  */
43 {
44 
45 private:
46  pthread_mutex_t decryptMutex;
47 
48  KeyState m_eKeyState;
49  string m_sessionID;
50  unsigned char* m_keyStr;
51  size_t m_keyLen;
52  unsigned char* m_keyId;
53  size_t m_keyIdLen;
54  /**
55  * @fn initAampDRMSession
56  */
57  void initAampDRMSession();
58 #if OPENSSL_VERSION_NUMBER >= 0x10100000L
59  EVP_CIPHER_CTX *mOpensslCtx;
60 #else
61  EVP_CIPHER_CTX mOpensslCtx;
62 #endif
63 public:
64 
65  /**
66  * @fn ClearKeySession
67  */
69 
70  /**
71  * @fn ~ClearKeySession
72  */
73  ~ClearKeySession();
74  /**
75  * @brief Copy constructor disabled
76  *
77  */
78  ClearKeySession(const ClearKeySession&) = delete;
79  /**
80  * @brief assignment operator disabled
81  *
82  */
83  ClearKeySession& operator=(const ClearKeySession&) = delete;
84 
85  /**
86  * @fn generateAampDRMSession
87  * @param f_pbInitData pointer to initdata
88  * @param f_cbInitData init data size
89  */
90  void generateAampDRMSession(const uint8_t *f_pbInitData,
91  uint32_t f_cbInitData, std::string &customData);
92 
93  /**
94  * @fn aampGenerateKeyRequest
95  * @param destinationURL : gets updated with license server url
96  * @param timeout: max timeout untill which to wait for cdm key generation.
97  * @retval Pointer to DrmData containing license request, NULL if failure.
98  */
99  DrmData * aampGenerateKeyRequest(string& destinationURL, uint32_t timeout);
100 
101  /**
102  * @fn aampDRMProcessKey
103  * @param key : License key from license server.
104  * @param timeout: max timeout untill which to wait for cdm processing.
105  * @retval DRM_SUCCESS(1) if no errors encountered
106  */
107  int aampDRMProcessKey(DrmData* key, uint32_t timeout);
108 
109  /**
110  * @fn setKeyId
111  * @param keyId Clear key ID
112  * @param keyIDLen key length
113  */
114  void setKeyId(const char* keyId, int32_t keyIDLen);
115 
116  /**
117  * @fn decrypt
118  * @param f_pbIV : Initialization vector.
119  * @param f_cbIV : Initialization vector length.
120  * @param payloadData : Data to decrypt.
121  * @param payloadDataSize : Size of data.
122  * @param ppOpaqueData : pointer to opaque buffer in case of SVP.
123  * @retval Returns 0 on success.
124  */
125  int decrypt(const uint8_t *f_pbIV, uint32_t f_cbIV,
126  const uint8_t *payloadData, uint32_t payloadDataSize, uint8_t **ppOpaqueData);
127 
128  //If OCDM_ADAPTOR is in use below decrypt funtion wil be invoked from plugin
129  /**
130  * @fn decrypt
131  * @param keyIDBuffer : keyID Buffer.
132  * @param ivBuffer : Initialization vector buffer.
133  * @param buffer : Data to decrypt.
134  * @param subSampleCount : subSampleCount in buffer
135  * @param subSamplesBuffer : sub Samples Buffer.
136  * @retval Returns 0 on success.
137  */
138  int decrypt(GstBuffer* keyIDBuffer, GstBuffer* ivBuffer, GstBuffer* buffer, unsigned subSampleCount,
139  GstBuffer* subSamplesBuffer, GstCaps* caps);
140 
141  /**
142  * @fn getState
143  * @retval KeyState
144  */
145  KeyState getState();
146 
147  /**
148  * @fn clearDecryptContext
149  */
150  void clearDecryptContext();
151 };
152 
153 #endif
154 
DrmData
To hold DRM key, license request etc.
Definition: AampDrmData.h:32
ClearKeySession
Open CDM DRM session.
Definition: ClearKeyDrmSession.h:42
AampLogManager
AampLogManager Class.
Definition: AampLogManager.h:150
AampDrmSession
Base class for DRM sessions.
Definition: AampDrmSession.h:69
_base64.h
base64 source Encoder/Decoder
KeyState
KeyState
DRM session states.
Definition: AampDrmSession.h:54
AampDrmSession.h
Header file for AampDrmSession.