1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef CLEARKEY_DRM_PLUGIN_H_
18 #define CLEARKEY_DRM_PLUGIN_H_
19 
20 #include <media/drm/DrmAPI.h>
21 #include <media/stagefright/foundation/ABase.h>
22 #include <media/stagefright/MediaErrors.h>
23 #include <utils/Errors.h>
24 #include <utils/KeyedVector.h>
25 #include <utils/List.h>
26 #include <utils/String8.h>
27 #include <utils/Vector.h>
28 
29 #include "SessionLibrary.h"
30 #include "Utils.h"
31 
32 namespace clearkeydrm {
33 
34 using android::KeyedVector;
35 using android::List;
36 using android::status_t;
37 using android::String8;
38 using android::Vector;
39 
40 class DrmPlugin : public android::DrmPlugin {
41 public:
DrmPlugin(SessionLibrary * sessionLibrary)42     DrmPlugin(SessionLibrary* sessionLibrary)
43             : mSessionLibrary(sessionLibrary) {}
~DrmPlugin()44     virtual ~DrmPlugin() {}
45 
46     virtual status_t openSession(Vector<uint8_t>& sessionId);
47 
48     virtual status_t closeSession(const Vector<uint8_t>& sessionId);
49 
50     virtual status_t getKeyRequest(
51             const Vector<uint8_t>& scope,
52             const Vector<uint8_t>& initData,
53             const String8& initDataType,
54             KeyType keyType,
55             const KeyedVector<String8, String8>& optionalParameters,
56             Vector<uint8_t>& request,
57             String8& defaultUrl);
58 
59     virtual status_t provideKeyResponse(
60             const Vector<uint8_t>& scope,
61             const Vector<uint8_t>& response,
62             Vector<uint8_t>& keySetId);
63 
removeKeys(const Vector<uint8_t> & sessionId)64     virtual status_t removeKeys(const Vector<uint8_t>& sessionId) {
65         UNUSED(sessionId);
66         return android::ERROR_DRM_CANNOT_HANDLE;
67     }
68 
restoreKeys(const Vector<uint8_t> & sessionId,const Vector<uint8_t> & keySetId)69     virtual status_t restoreKeys(
70             const Vector<uint8_t>& sessionId,
71             const Vector<uint8_t>& keySetId) {
72         UNUSED(sessionId);
73         UNUSED(keySetId);
74         return android::ERROR_DRM_CANNOT_HANDLE;
75     }
76 
queryKeyStatus(const Vector<uint8_t> & sessionId,KeyedVector<String8,String8> & infoMap)77     virtual status_t queryKeyStatus(
78             const Vector<uint8_t>& sessionId,
79             KeyedVector<String8, String8>& infoMap) const {
80         UNUSED(sessionId);
81         UNUSED(infoMap);
82         return android::ERROR_DRM_CANNOT_HANDLE;
83     }
84 
getProvisionRequest(const String8 & cert_type,const String8 & cert_authority,Vector<uint8_t> & request,String8 & defaultUrl)85     virtual status_t getProvisionRequest(
86             const String8& cert_type,
87             const String8& cert_authority,
88             Vector<uint8_t>& request,
89             String8& defaultUrl) {
90         UNUSED(cert_type);
91         UNUSED(cert_authority);
92         UNUSED(request);
93         UNUSED(defaultUrl);
94         return android::ERROR_DRM_CANNOT_HANDLE;
95     }
96 
provideProvisionResponse(const Vector<uint8_t> & response,Vector<uint8_t> & certificate,Vector<uint8_t> & wrappedKey)97     virtual status_t provideProvisionResponse(
98             const Vector<uint8_t>& response,
99             Vector<uint8_t>& certificate,
100             Vector<uint8_t>& wrappedKey) {
101         UNUSED(response);
102         UNUSED(certificate);
103         UNUSED(wrappedKey);
104         return android::ERROR_DRM_CANNOT_HANDLE;
105     }
106 
unprovisionDevice()107     virtual status_t unprovisionDevice() {
108         return android::ERROR_DRM_CANNOT_HANDLE;
109     }
110 
getSecureStops(List<Vector<uint8_t>> & secureStops)111     virtual status_t getSecureStops(List<Vector<uint8_t> >& secureStops) {
112         UNUSED(secureStops);
113         return android::ERROR_DRM_CANNOT_HANDLE;
114     }
115 
getSecureStop(Vector<uint8_t> const & ssid,Vector<uint8_t> & secureStop)116     virtual status_t getSecureStop(Vector<uint8_t> const &ssid, Vector<uint8_t> &secureStop) {
117         UNUSED(ssid);
118         UNUSED(secureStop);
119         return android::ERROR_DRM_CANNOT_HANDLE;
120     }
121 
releaseSecureStops(const Vector<uint8_t> & ssRelease)122     virtual status_t releaseSecureStops(const Vector<uint8_t>& ssRelease) {
123         UNUSED(ssRelease);
124         return android::ERROR_DRM_CANNOT_HANDLE;
125     }
126 
releaseAllSecureStops()127     virtual status_t releaseAllSecureStops() {
128         return android::ERROR_DRM_CANNOT_HANDLE;
129     }
130 
131     virtual status_t getPropertyString(
132             const String8& name, String8& value) const;
133 
getPropertyByteArray(const String8 & name,Vector<uint8_t> & value)134     virtual status_t getPropertyByteArray(
135             const String8& name, Vector<uint8_t>& value) const {
136         UNUSED(name);
137         UNUSED(value);
138         return android::ERROR_DRM_CANNOT_HANDLE;
139     }
140 
setPropertyString(const String8 & name,const String8 & value)141     virtual status_t setPropertyString(
142             const String8& name, const String8& value) {
143         UNUSED(name);
144         UNUSED(value);
145         return android::ERROR_DRM_CANNOT_HANDLE;
146     }
147 
setPropertyByteArray(const String8 & name,const Vector<uint8_t> & value)148     virtual status_t setPropertyByteArray(
149             const String8& name, const Vector<uint8_t>& value) {
150         UNUSED(name);
151         UNUSED(value);
152         return android::ERROR_DRM_CANNOT_HANDLE;
153     }
154 
setCipherAlgorithm(const Vector<uint8_t> & sessionId,const String8 & algorithm)155     virtual status_t setCipherAlgorithm(
156             const Vector<uint8_t>& sessionId, const String8& algorithm) {
157         UNUSED(sessionId);
158         UNUSED(algorithm);
159         return android::ERROR_DRM_CANNOT_HANDLE;
160     }
161 
setMacAlgorithm(const Vector<uint8_t> & sessionId,const String8 & algorithm)162     virtual status_t setMacAlgorithm(
163             const Vector<uint8_t>& sessionId, const String8& algorithm) {
164         UNUSED(sessionId);
165         UNUSED(algorithm);
166         return android::ERROR_DRM_CANNOT_HANDLE;
167     }
168 
encrypt(const Vector<uint8_t> & sessionId,const Vector<uint8_t> & keyId,const Vector<uint8_t> & input,const Vector<uint8_t> & iv,Vector<uint8_t> & output)169     virtual status_t encrypt(
170             const Vector<uint8_t>& sessionId,
171             const Vector<uint8_t>& keyId,
172             const Vector<uint8_t>& input,
173             const Vector<uint8_t>& iv,
174             Vector<uint8_t>& output) {
175         UNUSED(sessionId);
176         UNUSED(keyId);
177         UNUSED(input);
178         UNUSED(iv);
179         UNUSED(output);
180         return android::ERROR_DRM_CANNOT_HANDLE;
181     }
182 
decrypt(const Vector<uint8_t> & sessionId,const Vector<uint8_t> & keyId,const Vector<uint8_t> & input,const Vector<uint8_t> & iv,Vector<uint8_t> & output)183     virtual status_t decrypt(
184             const Vector<uint8_t>& sessionId,
185             const Vector<uint8_t>& keyId,
186             const Vector<uint8_t>& input,
187             const Vector<uint8_t>& iv,
188             Vector<uint8_t>& output) {
189         UNUSED(sessionId);
190         UNUSED(keyId);
191         UNUSED(input);
192         UNUSED(iv);
193         UNUSED(output);
194         return android::ERROR_DRM_CANNOT_HANDLE;
195     }
196 
sign(const Vector<uint8_t> & sessionId,const Vector<uint8_t> & keyId,const Vector<uint8_t> & message,Vector<uint8_t> & signature)197     virtual status_t sign(
198             const Vector<uint8_t>& sessionId,
199             const Vector<uint8_t>& keyId,
200             const Vector<uint8_t>& message,
201             Vector<uint8_t>& signature) {
202         UNUSED(sessionId);
203         UNUSED(keyId);
204         UNUSED(message);
205         UNUSED(signature);
206         return android::ERROR_DRM_CANNOT_HANDLE;
207     }
208 
verify(const Vector<uint8_t> & sessionId,const Vector<uint8_t> & keyId,const Vector<uint8_t> & message,const Vector<uint8_t> & signature,bool & match)209     virtual status_t verify(
210             const Vector<uint8_t>& sessionId,
211             const Vector<uint8_t>& keyId,
212             const Vector<uint8_t>& message,
213             const Vector<uint8_t>& signature, bool& match) {
214         UNUSED(sessionId);
215         UNUSED(keyId);
216         UNUSED(message);
217         UNUSED(signature);
218         UNUSED(match);
219         return android::ERROR_DRM_CANNOT_HANDLE;
220     }
221 
signRSA(const Vector<uint8_t> & sessionId,const String8 & algorithm,const Vector<uint8_t> & message,const Vector<uint8_t> & wrappedKey,Vector<uint8_t> & signature)222     virtual status_t signRSA(
223             const Vector<uint8_t>& sessionId,
224             const String8& algorithm,
225             const Vector<uint8_t>& message,
226             const Vector<uint8_t>& wrappedKey,
227             Vector<uint8_t>& signature) {
228         UNUSED(sessionId);
229         UNUSED(algorithm);
230         UNUSED(message);
231         UNUSED(wrappedKey);
232         UNUSED(signature);
233         return android::ERROR_DRM_CANNOT_HANDLE;
234     }
235 
236 private:
237     DISALLOW_EVIL_CONSTRUCTORS(DrmPlugin);
238 
239     SessionLibrary* mSessionLibrary;
240 };
241 
242 } // namespace clearkeydrm
243 
244 #endif // CLEARKEY_DRM_PLUGIN_H_
245