• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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:
42     explicit DrmPlugin(SessionLibrary* sessionLibrary);
43 
~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>& mimeType,
53             const String8& initDataType,
54             KeyType keyType,
55             const KeyedVector<String8, String8>& optionalParameters,
56             Vector<uint8_t>& request,
57             String8& defaultUrl,
58             DrmPlugin::KeyRequestType *keyRequestType);
59 
60     virtual status_t provideKeyResponse(
61             const Vector<uint8_t>& scope,
62             const Vector<uint8_t>& response,
63             Vector<uint8_t>& keySetId);
64 
removeKeys(const Vector<uint8_t> & sessionId)65     virtual status_t removeKeys(const Vector<uint8_t>& sessionId) {
66         if (sessionId.size() == 0) {
67             return android::BAD_VALUE;
68         }
69 
70         return android::ERROR_DRM_CANNOT_HANDLE;
71     }
72 
restoreKeys(const Vector<uint8_t> & sessionId,const Vector<uint8_t> & keySetId)73     virtual status_t restoreKeys(
74             const Vector<uint8_t>& sessionId,
75             const Vector<uint8_t>& keySetId) {
76         if (sessionId.size() == 0 || keySetId.size() == 0) {
77             return android::BAD_VALUE;
78         }
79         return android::ERROR_DRM_CANNOT_HANDLE;
80     }
81 
82     virtual status_t queryKeyStatus(
83             const Vector<uint8_t>& sessionId,
84             KeyedVector<String8, String8>& infoMap) const;
85 
getProvisionRequest(const String8 & cert_type,const String8 & cert_authority,Vector<uint8_t> & request,String8 & defaultUrl)86     virtual status_t getProvisionRequest(
87             const String8& cert_type,
88             const String8& cert_authority,
89             Vector<uint8_t>& request,
90             String8& defaultUrl) {
91         UNUSED(cert_type);
92         UNUSED(cert_authority);
93         UNUSED(request);
94         UNUSED(defaultUrl);
95         return android::ERROR_DRM_CANNOT_HANDLE;
96     }
97 
provideProvisionResponse(const Vector<uint8_t> & response,Vector<uint8_t> & certificate,Vector<uint8_t> & wrappedKey)98     virtual status_t provideProvisionResponse(
99             const Vector<uint8_t>& response,
100             Vector<uint8_t>& certificate,
101             Vector<uint8_t>& wrappedKey) {
102         UNUSED(certificate);
103         UNUSED(wrappedKey);
104         if (response.size() == 0) {
105             // empty response
106             return android::BAD_VALUE;
107         }
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         if (ssid.size() == 0) {
118             return android::BAD_VALUE;
119         }
120 
121         UNUSED(secureStop);
122         return android::ERROR_DRM_CANNOT_HANDLE;
123     }
124 
releaseSecureStops(const Vector<uint8_t> & ssRelease)125     virtual status_t releaseSecureStops(const Vector<uint8_t>& ssRelease) {
126         if (ssRelease.size() == 0) {
127             return android::BAD_VALUE;
128         }
129         return android::ERROR_DRM_CANNOT_HANDLE;
130     }
131 
releaseAllSecureStops()132     virtual status_t releaseAllSecureStops() {
133         return android::ERROR_DRM_CANNOT_HANDLE;
134     }
135 
136     virtual status_t getPropertyString(
137             const String8& name, String8& value) const;
138 
getPropertyByteArray(const String8 & name,Vector<uint8_t> & value)139     virtual status_t getPropertyByteArray(
140             const String8& name, Vector<uint8_t>& value) const {
141         UNUSED(name);
142         UNUSED(value);
143         return android::ERROR_DRM_CANNOT_HANDLE;
144     }
145 
setPropertyString(const String8 & name,const String8 & value)146     virtual status_t setPropertyString(
147             const String8& name, const String8& value) {
148         UNUSED(name);
149         UNUSED(value);
150         return android::ERROR_DRM_CANNOT_HANDLE;
151     }
152 
setPropertyByteArray(const String8 & name,const Vector<uint8_t> & value)153     virtual status_t setPropertyByteArray(
154             const String8& name, const Vector<uint8_t>& value) {
155         UNUSED(name);
156         UNUSED(value);
157         return android::ERROR_DRM_CANNOT_HANDLE;
158     }
159 
setCipherAlgorithm(const Vector<uint8_t> & sessionId,const String8 & algorithm)160     virtual status_t setCipherAlgorithm(
161             const Vector<uint8_t>& sessionId, const String8& algorithm) {
162         if (sessionId.size() == 0 || algorithm.size() == 0) {
163             return android::BAD_VALUE;
164         }
165         return android::ERROR_DRM_CANNOT_HANDLE;
166     }
167 
setMacAlgorithm(const Vector<uint8_t> & sessionId,const String8 & algorithm)168     virtual status_t setMacAlgorithm(
169             const Vector<uint8_t>& sessionId, const String8& algorithm) {
170         if (sessionId.size() == 0 || algorithm.size() == 0) {
171             return android::BAD_VALUE;
172         }
173         return android::ERROR_DRM_CANNOT_HANDLE;
174     }
175 
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)176     virtual status_t encrypt(
177             const Vector<uint8_t>& sessionId,
178             const Vector<uint8_t>& keyId,
179             const Vector<uint8_t>& input,
180             const Vector<uint8_t>& iv,
181             Vector<uint8_t>& output) {
182         if (sessionId.size() == 0 || keyId.size() == 0 ||
183                 input.size() == 0 || iv.size() == 0) {
184             return android::BAD_VALUE;
185         }
186         UNUSED(output);
187         return android::ERROR_DRM_CANNOT_HANDLE;
188     }
189 
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)190     virtual status_t decrypt(
191             const Vector<uint8_t>& sessionId,
192             const Vector<uint8_t>& keyId,
193             const Vector<uint8_t>& input,
194             const Vector<uint8_t>& iv,
195             Vector<uint8_t>& output) {
196         if (sessionId.size() == 0 || keyId.size() == 0 ||
197                 input.size() == 0 || iv.size() == 0) {
198             return android::BAD_VALUE;
199         }
200         UNUSED(output);
201         return android::ERROR_DRM_CANNOT_HANDLE;
202     }
203 
sign(const Vector<uint8_t> & sessionId,const Vector<uint8_t> & keyId,const Vector<uint8_t> & message,Vector<uint8_t> & signature)204     virtual status_t sign(
205             const Vector<uint8_t>& sessionId,
206             const Vector<uint8_t>& keyId,
207             const Vector<uint8_t>& message,
208             Vector<uint8_t>& signature) {
209         if (sessionId.size() == 0 || keyId.size() == 0 ||
210                 message.size() == 0) {
211             return android::BAD_VALUE;
212         }
213         UNUSED(signature);
214         return android::ERROR_DRM_CANNOT_HANDLE;
215     }
216 
verify(const Vector<uint8_t> & sessionId,const Vector<uint8_t> & keyId,const Vector<uint8_t> & message,const Vector<uint8_t> & signature,bool & match)217     virtual status_t verify(
218             const Vector<uint8_t>& sessionId,
219             const Vector<uint8_t>& keyId,
220             const Vector<uint8_t>& message,
221             const Vector<uint8_t>& signature, bool& match) {
222         if (sessionId.size() == 0 || keyId.size() == 0 ||
223                 message.size() == 0 || signature.size() == 0) {
224             return android::BAD_VALUE;
225         }
226         UNUSED(match);
227         return android::ERROR_DRM_CANNOT_HANDLE;
228     }
229 
signRSA(const Vector<uint8_t> & sessionId,const String8 & algorithm,const Vector<uint8_t> & message,const Vector<uint8_t> & wrappedKey,Vector<uint8_t> & signature)230     virtual status_t signRSA(
231             const Vector<uint8_t>& sessionId,
232             const String8& algorithm,
233             const Vector<uint8_t>& message,
234             const Vector<uint8_t>& wrappedKey,
235             Vector<uint8_t>& signature) {
236         if (sessionId.size() == 0 || algorithm.size() == 0 ||
237                 message.size() == 0 || wrappedKey.size() == 0) {
238             return android::BAD_VALUE;
239         }
240         UNUSED(signature);
241         return android::ERROR_DRM_CANNOT_HANDLE;
242     }
243 
244 private:
245     void setPlayPolicy();
246 
247     android::KeyedVector<android::String8, android::String8> mPlayPolicy;
248     SessionLibrary* mSessionLibrary;
249 
250     DISALLOW_EVIL_CONSTRUCTORS(DrmPlugin);
251 };
252 
253 } // namespace clearkeydrm
254 
255 #endif // CLEARKEY_DRM_PLUGIN_H_
256