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