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 #include <binder/IInterface.h> 18 #include <media/stagefright/foundation/ABase.h> 19 #include <media/drm/DrmAPI.h> 20 #include <media/IDrmClient.h> 21 22 #ifndef ANDROID_IDRM_H_ 23 24 #define ANDROID_IDRM_H_ 25 26 namespace android { 27 28 struct AString; 29 30 struct IDrm : public IInterface { 31 DECLARE_META_INTERFACE(Drm); 32 33 virtual status_t initCheck() const = 0; 34 35 virtual bool isCryptoSchemeSupported(const uint8_t uuid[16], const String8 &mimeType) = 0; 36 37 virtual status_t createPlugin(const uint8_t uuid[16]) = 0; 38 39 virtual status_t destroyPlugin() = 0; 40 41 virtual status_t openSession(Vector<uint8_t> &sessionId) = 0; 42 43 virtual status_t closeSession(Vector<uint8_t> const &sessionId) = 0; 44 45 virtual status_t 46 getKeyRequest(Vector<uint8_t> const &sessionId, 47 Vector<uint8_t> const &initData, 48 String8 const &mimeType, DrmPlugin::KeyType keyType, 49 KeyedVector<String8, String8> const &optionalParameters, 50 Vector<uint8_t> &request, String8 &defaultUrl) = 0; 51 52 virtual status_t provideKeyResponse(Vector<uint8_t> const &sessionId, 53 Vector<uint8_t> const &response, 54 Vector<uint8_t> &keySetId) = 0; 55 56 virtual status_t removeKeys(Vector<uint8_t> const &keySetId) = 0; 57 58 virtual status_t restoreKeys(Vector<uint8_t> const &sessionId, 59 Vector<uint8_t> const &keySetId) = 0; 60 61 virtual status_t queryKeyStatus(Vector<uint8_t> const &sessionId, 62 KeyedVector<String8, String8> &infoMap) const = 0; 63 64 virtual status_t getProvisionRequest(String8 const &certType, 65 String8 const &certAuthority, 66 Vector<uint8_t> &request, 67 String8 &defaulUrl) = 0; 68 69 virtual status_t provideProvisionResponse(Vector<uint8_t> const &response, 70 Vector<uint8_t> &certificate, 71 Vector<uint8_t> &wrappedKey) = 0; 72 73 virtual status_t unprovisionDevice() = 0; 74 75 virtual status_t getSecureStops(List<Vector<uint8_t> > &secureStops) = 0; 76 virtual status_t getSecureStop(Vector<uint8_t> const &ssid, Vector<uint8_t> &secureStop) = 0; 77 78 virtual status_t releaseSecureStops(Vector<uint8_t> const &ssRelease) = 0; 79 virtual status_t releaseAllSecureStops() = 0; 80 81 virtual status_t getPropertyString(String8 const &name, String8 &value) const = 0; 82 virtual status_t getPropertyByteArray(String8 const &name, 83 Vector<uint8_t> &value) const = 0; 84 virtual status_t setPropertyString(String8 const &name, 85 String8 const &value ) const = 0; 86 virtual status_t setPropertyByteArray(String8 const &name, 87 Vector<uint8_t> const &value) const = 0; 88 89 virtual status_t setCipherAlgorithm(Vector<uint8_t> const &sessionId, 90 String8 const &algorithm) = 0; 91 92 virtual status_t setMacAlgorithm(Vector<uint8_t> const &sessionId, 93 String8 const &algorithm) = 0; 94 95 virtual status_t encrypt(Vector<uint8_t> const &sessionId, 96 Vector<uint8_t> const &keyId, 97 Vector<uint8_t> const &input, 98 Vector<uint8_t> const &iv, 99 Vector<uint8_t> &output) = 0; 100 101 virtual status_t decrypt(Vector<uint8_t> const &sessionId, 102 Vector<uint8_t> const &keyId, 103 Vector<uint8_t> const &input, 104 Vector<uint8_t> const &iv, 105 Vector<uint8_t> &output) = 0; 106 107 virtual status_t sign(Vector<uint8_t> const &sessionId, 108 Vector<uint8_t> const &keyId, 109 Vector<uint8_t> const &message, 110 Vector<uint8_t> &signature) = 0; 111 112 virtual status_t verify(Vector<uint8_t> const &sessionId, 113 Vector<uint8_t> const &keyId, 114 Vector<uint8_t> const &message, 115 Vector<uint8_t> const &signature, 116 bool &match) = 0; 117 118 virtual status_t signRSA(Vector<uint8_t> const &sessionId, 119 String8 const &algorithm, 120 Vector<uint8_t> const &message, 121 Vector<uint8_t> const &wrappedKey, 122 Vector<uint8_t> &signature) = 0; 123 124 virtual status_t setListener(const sp<IDrmClient>& listener) = 0; 125 126 private: 127 DISALLOW_EVIL_CONSTRUCTORS(IDrm); 128 }; 129 130 struct BnDrm : public BnInterface<IDrm> { 131 virtual status_t onTransact( 132 uint32_t code, const Parcel &data, Parcel *reply, 133 uint32_t flags = 0); 134 private: 135 void readVector(const Parcel &data, Vector<uint8_t> &vector) const; 136 void writeVector(Parcel *reply, Vector<uint8_t> const &vector) const; 137 }; 138 139 } // namespace android 140 141 #endif // ANDROID_IDRM_H_ 142