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 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 UNUSED(sessionId); 67 return android::ERROR_DRM_CANNOT_HANDLE; 68 } 69 restoreKeys(const Vector<uint8_t> & sessionId,const Vector<uint8_t> & keySetId)70 virtual status_t restoreKeys( 71 const Vector<uint8_t>& sessionId, 72 const Vector<uint8_t>& keySetId) { 73 UNUSED(sessionId); 74 UNUSED(keySetId); 75 return android::ERROR_DRM_CANNOT_HANDLE; 76 } 77 queryKeyStatus(const Vector<uint8_t> & sessionId,KeyedVector<String8,String8> & infoMap)78 virtual status_t queryKeyStatus( 79 const Vector<uint8_t>& sessionId, 80 KeyedVector<String8, String8>& infoMap) const { 81 UNUSED(sessionId); 82 UNUSED(infoMap); 83 return android::ERROR_DRM_CANNOT_HANDLE; 84 } 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(response); 103 UNUSED(certificate); 104 UNUSED(wrappedKey); 105 return android::ERROR_DRM_CANNOT_HANDLE; 106 } 107 unprovisionDevice()108 virtual status_t unprovisionDevice() { 109 return android::ERROR_DRM_CANNOT_HANDLE; 110 } 111 getSecureStops(List<Vector<uint8_t>> & secureStops)112 virtual status_t getSecureStops(List<Vector<uint8_t> >& secureStops) { 113 UNUSED(secureStops); 114 return android::ERROR_DRM_CANNOT_HANDLE; 115 } 116 getSecureStop(Vector<uint8_t> const & ssid,Vector<uint8_t> & secureStop)117 virtual status_t getSecureStop(Vector<uint8_t> const &ssid, Vector<uint8_t> &secureStop) { 118 UNUSED(ssid); 119 UNUSED(secureStop); 120 return android::ERROR_DRM_CANNOT_HANDLE; 121 } 122 releaseSecureStops(const Vector<uint8_t> & ssRelease)123 virtual status_t releaseSecureStops(const Vector<uint8_t>& ssRelease) { 124 UNUSED(ssRelease); 125 return android::ERROR_DRM_CANNOT_HANDLE; 126 } 127 releaseAllSecureStops()128 virtual status_t releaseAllSecureStops() { 129 return android::ERROR_DRM_CANNOT_HANDLE; 130 } 131 132 virtual status_t getPropertyString( 133 const String8& name, String8& value) const; 134 getPropertyByteArray(const String8 & name,Vector<uint8_t> & value)135 virtual status_t getPropertyByteArray( 136 const String8& name, Vector<uint8_t>& value) const { 137 UNUSED(name); 138 UNUSED(value); 139 return android::ERROR_DRM_CANNOT_HANDLE; 140 } 141 setPropertyString(const String8 & name,const String8 & value)142 virtual status_t setPropertyString( 143 const String8& name, const String8& value) { 144 UNUSED(name); 145 UNUSED(value); 146 return android::ERROR_DRM_CANNOT_HANDLE; 147 } 148 setPropertyByteArray(const String8 & name,const Vector<uint8_t> & value)149 virtual status_t setPropertyByteArray( 150 const String8& name, const Vector<uint8_t>& value) { 151 UNUSED(name); 152 UNUSED(value); 153 return android::ERROR_DRM_CANNOT_HANDLE; 154 } 155 setCipherAlgorithm(const Vector<uint8_t> & sessionId,const String8 & algorithm)156 virtual status_t setCipherAlgorithm( 157 const Vector<uint8_t>& sessionId, const String8& algorithm) { 158 UNUSED(sessionId); 159 UNUSED(algorithm); 160 return android::ERROR_DRM_CANNOT_HANDLE; 161 } 162 setMacAlgorithm(const Vector<uint8_t> & sessionId,const String8 & algorithm)163 virtual status_t setMacAlgorithm( 164 const Vector<uint8_t>& sessionId, const String8& algorithm) { 165 UNUSED(sessionId); 166 UNUSED(algorithm); 167 return android::ERROR_DRM_CANNOT_HANDLE; 168 } 169 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)170 virtual status_t encrypt( 171 const Vector<uint8_t>& sessionId, 172 const Vector<uint8_t>& keyId, 173 const Vector<uint8_t>& input, 174 const Vector<uint8_t>& iv, 175 Vector<uint8_t>& output) { 176 UNUSED(sessionId); 177 UNUSED(keyId); 178 UNUSED(input); 179 UNUSED(iv); 180 UNUSED(output); 181 return android::ERROR_DRM_CANNOT_HANDLE; 182 } 183 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)184 virtual status_t decrypt( 185 const Vector<uint8_t>& sessionId, 186 const Vector<uint8_t>& keyId, 187 const Vector<uint8_t>& input, 188 const Vector<uint8_t>& iv, 189 Vector<uint8_t>& output) { 190 UNUSED(sessionId); 191 UNUSED(keyId); 192 UNUSED(input); 193 UNUSED(iv); 194 UNUSED(output); 195 return android::ERROR_DRM_CANNOT_HANDLE; 196 } 197 sign(const Vector<uint8_t> & sessionId,const Vector<uint8_t> & keyId,const Vector<uint8_t> & message,Vector<uint8_t> & signature)198 virtual status_t sign( 199 const Vector<uint8_t>& sessionId, 200 const Vector<uint8_t>& keyId, 201 const Vector<uint8_t>& message, 202 Vector<uint8_t>& signature) { 203 UNUSED(sessionId); 204 UNUSED(keyId); 205 UNUSED(message); 206 UNUSED(signature); 207 return android::ERROR_DRM_CANNOT_HANDLE; 208 } 209 verify(const Vector<uint8_t> & sessionId,const Vector<uint8_t> & keyId,const Vector<uint8_t> & message,const Vector<uint8_t> & signature,bool & match)210 virtual status_t verify( 211 const Vector<uint8_t>& sessionId, 212 const Vector<uint8_t>& keyId, 213 const Vector<uint8_t>& message, 214 const Vector<uint8_t>& signature, bool& match) { 215 UNUSED(sessionId); 216 UNUSED(keyId); 217 UNUSED(message); 218 UNUSED(signature); 219 UNUSED(match); 220 return android::ERROR_DRM_CANNOT_HANDLE; 221 } 222 signRSA(const Vector<uint8_t> & sessionId,const String8 & algorithm,const Vector<uint8_t> & message,const Vector<uint8_t> & wrappedKey,Vector<uint8_t> & signature)223 virtual status_t signRSA( 224 const Vector<uint8_t>& sessionId, 225 const String8& algorithm, 226 const Vector<uint8_t>& message, 227 const Vector<uint8_t>& wrappedKey, 228 Vector<uint8_t>& signature) { 229 UNUSED(sessionId); 230 UNUSED(algorithm); 231 UNUSED(message); 232 UNUSED(wrappedKey); 233 UNUSED(signature); 234 return android::ERROR_DRM_CANNOT_HANDLE; 235 } 236 237 private: 238 DISALLOW_EVIL_CONSTRUCTORS(DrmPlugin); 239 240 SessionLibrary* mSessionLibrary; 241 }; 242 243 } // namespace clearkeydrm 244 245 #endif // CLEARKEY_DRM_PLUGIN_H_ 246