1 /* 2 * Copyright (C) 2013 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 DRM_H_ 18 19 #define DRM_H_ 20 21 #include "SharedLibrary.h" 22 23 #include <media/IDrm.h> 24 #include <media/IDrmClient.h> 25 #include <utils/threads.h> 26 27 namespace android { 28 29 struct DrmFactory; 30 struct DrmPlugin; 31 32 struct Drm : public BnDrm, 33 public IBinder::DeathRecipient, 34 public DrmPluginListener { 35 Drm(); 36 virtual ~Drm(); 37 38 virtual status_t initCheck() const; 39 40 virtual bool isCryptoSchemeSupported(const uint8_t uuid[16], const String8 &mimeType); 41 42 virtual status_t createPlugin(const uint8_t uuid[16]); 43 44 virtual status_t destroyPlugin(); 45 46 virtual status_t openSession(Vector<uint8_t> &sessionId); 47 48 virtual status_t closeSession(Vector<uint8_t> const &sessionId); 49 50 virtual status_t 51 getKeyRequest(Vector<uint8_t> const &sessionId, 52 Vector<uint8_t> const &initData, 53 String8 const &mimeType, DrmPlugin::KeyType keyType, 54 KeyedVector<String8, String8> const &optionalParameters, 55 Vector<uint8_t> &request, String8 &defaultUrl); 56 57 virtual status_t provideKeyResponse(Vector<uint8_t> const &sessionId, 58 Vector<uint8_t> const &response, 59 Vector<uint8_t> &keySetId); 60 61 virtual status_t removeKeys(Vector<uint8_t> const &keySetId); 62 63 virtual status_t restoreKeys(Vector<uint8_t> const &sessionId, 64 Vector<uint8_t> const &keySetId); 65 66 virtual status_t queryKeyStatus(Vector<uint8_t> const &sessionId, 67 KeyedVector<String8, String8> &infoMap) const; 68 69 virtual status_t getProvisionRequest(Vector<uint8_t> &request, 70 String8 &defaulUrl); 71 72 virtual status_t provideProvisionResponse(Vector<uint8_t> const &response); 73 74 virtual status_t getSecureStops(List<Vector<uint8_t> > &secureStops); 75 76 virtual status_t releaseSecureStops(Vector<uint8_t> const &ssRelease); 77 78 virtual status_t getPropertyString(String8 const &name, String8 &value ) const; 79 virtual status_t getPropertyByteArray(String8 const &name, 80 Vector<uint8_t> &value ) const; 81 virtual status_t setPropertyString(String8 const &name, String8 const &value ) const; 82 virtual status_t setPropertyByteArray(String8 const &name, 83 Vector<uint8_t> const &value ) const; 84 85 virtual status_t setCipherAlgorithm(Vector<uint8_t> const &sessionId, 86 String8 const &algorithm); 87 88 virtual status_t setMacAlgorithm(Vector<uint8_t> const &sessionId, 89 String8 const &algorithm); 90 91 virtual status_t encrypt(Vector<uint8_t> const &sessionId, 92 Vector<uint8_t> const &keyId, 93 Vector<uint8_t> const &input, 94 Vector<uint8_t> const &iv, 95 Vector<uint8_t> &output); 96 97 virtual status_t decrypt(Vector<uint8_t> const &sessionId, 98 Vector<uint8_t> const &keyId, 99 Vector<uint8_t> const &input, 100 Vector<uint8_t> const &iv, 101 Vector<uint8_t> &output); 102 103 virtual status_t sign(Vector<uint8_t> const &sessionId, 104 Vector<uint8_t> const &keyId, 105 Vector<uint8_t> const &message, 106 Vector<uint8_t> &signature); 107 108 virtual status_t verify(Vector<uint8_t> const &sessionId, 109 Vector<uint8_t> const &keyId, 110 Vector<uint8_t> const &message, 111 Vector<uint8_t> const &signature, 112 bool &match); 113 114 virtual status_t setListener(const sp<IDrmClient>& listener); 115 116 virtual void sendEvent(DrmPlugin::EventType eventType, int extra, 117 Vector<uint8_t> const *sessionId, 118 Vector<uint8_t> const *data); 119 120 virtual void binderDied(const wp<IBinder> &the_late_who); 121 122 private: 123 mutable Mutex mLock; 124 125 status_t mInitCheck; 126 127 sp<IDrmClient> mListener; 128 mutable Mutex mEventLock; 129 mutable Mutex mNotifyLock; 130 131 sp<SharedLibrary> mLibrary; 132 DrmFactory *mFactory; 133 DrmPlugin *mPlugin; 134 135 static KeyedVector<Vector<uint8_t>, String8> mUUIDToLibraryPathMap; 136 static KeyedVector<String8, wp<SharedLibrary> > mLibraryPathToOpenLibraryMap; 137 static Mutex mMapLock; 138 139 void findFactoryForScheme(const uint8_t uuid[16]); 140 bool loadLibraryForScheme(const String8 &path, const uint8_t uuid[16]); 141 void closeFactory(); 142 143 144 DISALLOW_EVIL_CONSTRUCTORS(Drm); 145 }; 146 147 } // namespace android 148 149 #endif // CRYPTO_H_ 150