• 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:
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 
releaseSecureStops(const Vector<uint8_t> & ssRelease)116     virtual status_t releaseSecureStops(const Vector<uint8_t>& ssRelease) {
117         UNUSED(ssRelease);
118         return android::ERROR_DRM_CANNOT_HANDLE;
119     }
120 
121     virtual status_t getPropertyString(
122             const String8& name, String8& value) const;
123 
getPropertyByteArray(const String8 & name,Vector<uint8_t> & value)124     virtual status_t getPropertyByteArray(
125             const String8& name, Vector<uint8_t>& value) const {
126         UNUSED(name);
127         UNUSED(value);
128         return android::ERROR_DRM_CANNOT_HANDLE;
129     }
130 
setPropertyString(const String8 & name,const String8 & value)131     virtual status_t setPropertyString(
132             const String8& name, const String8& value) {
133         UNUSED(name);
134         UNUSED(value);
135         return android::ERROR_DRM_CANNOT_HANDLE;
136     }
137 
setPropertyByteArray(const String8 & name,const Vector<uint8_t> & value)138     virtual status_t setPropertyByteArray(
139             const String8& name, const Vector<uint8_t>& value) {
140         UNUSED(name);
141         UNUSED(value);
142         return android::ERROR_DRM_CANNOT_HANDLE;
143     }
144 
setCipherAlgorithm(const Vector<uint8_t> & sessionId,const String8 & algorithm)145     virtual status_t setCipherAlgorithm(
146             const Vector<uint8_t>& sessionId, const String8& algorithm) {
147         UNUSED(sessionId);
148         UNUSED(algorithm);
149         return android::ERROR_DRM_CANNOT_HANDLE;
150     }
151 
setMacAlgorithm(const Vector<uint8_t> & sessionId,const String8 & algorithm)152     virtual status_t setMacAlgorithm(
153             const Vector<uint8_t>& sessionId, const String8& algorithm) {
154         UNUSED(sessionId);
155         UNUSED(algorithm);
156         return android::ERROR_DRM_CANNOT_HANDLE;
157     }
158 
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)159     virtual status_t encrypt(
160             const Vector<uint8_t>& sessionId,
161             const Vector<uint8_t>& keyId,
162             const Vector<uint8_t>& input,
163             const Vector<uint8_t>& iv,
164             Vector<uint8_t>& output) {
165         UNUSED(sessionId);
166         UNUSED(keyId);
167         UNUSED(input);
168         UNUSED(iv);
169         UNUSED(output);
170         return android::ERROR_DRM_CANNOT_HANDLE;
171     }
172 
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)173     virtual status_t decrypt(
174             const Vector<uint8_t>& sessionId,
175             const Vector<uint8_t>& keyId,
176             const Vector<uint8_t>& input,
177             const Vector<uint8_t>& iv,
178             Vector<uint8_t>& output) {
179         UNUSED(sessionId);
180         UNUSED(keyId);
181         UNUSED(input);
182         UNUSED(iv);
183         UNUSED(output);
184         return android::ERROR_DRM_CANNOT_HANDLE;
185     }
186 
sign(const Vector<uint8_t> & sessionId,const Vector<uint8_t> & keyId,const Vector<uint8_t> & message,Vector<uint8_t> & signature)187     virtual status_t sign(
188             const Vector<uint8_t>& sessionId,
189             const Vector<uint8_t>& keyId,
190             const Vector<uint8_t>& message,
191             Vector<uint8_t>& signature) {
192         UNUSED(sessionId);
193         UNUSED(keyId);
194         UNUSED(message);
195         UNUSED(signature);
196         return android::ERROR_DRM_CANNOT_HANDLE;
197     }
198 
verify(const Vector<uint8_t> & sessionId,const Vector<uint8_t> & keyId,const Vector<uint8_t> & message,const Vector<uint8_t> & signature,bool & match)199     virtual status_t verify(
200             const Vector<uint8_t>& sessionId,
201             const Vector<uint8_t>& keyId,
202             const Vector<uint8_t>& message,
203             const Vector<uint8_t>& signature, bool& match) {
204         UNUSED(sessionId);
205         UNUSED(keyId);
206         UNUSED(message);
207         UNUSED(signature);
208         UNUSED(match);
209         return android::ERROR_DRM_CANNOT_HANDLE;
210     }
211 
signRSA(const Vector<uint8_t> & sessionId,const String8 & algorithm,const Vector<uint8_t> & message,const Vector<uint8_t> & wrappedKey,Vector<uint8_t> & signature)212     virtual status_t signRSA(
213             const Vector<uint8_t>& sessionId,
214             const String8& algorithm,
215             const Vector<uint8_t>& message,
216             const Vector<uint8_t>& wrappedKey,
217             Vector<uint8_t>& signature) {
218         UNUSED(sessionId);
219         UNUSED(algorithm);
220         UNUSED(message);
221         UNUSED(wrappedKey);
222         UNUSED(signature);
223         return android::ERROR_DRM_CANNOT_HANDLE;
224     }
225 
226 private:
227     DISALLOW_EVIL_CONSTRUCTORS(DrmPlugin);
228 
229     SessionLibrary* mSessionLibrary;
230 };
231 
232 } // namespace clearkeydrm
233 
234 #endif // CLEARKEY_DRM_PLUGIN_H_
235