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 77 virtual status_t releaseSecureStops(Vector<uint8_t> const &ssRelease) = 0; 78 79 virtual status_t getPropertyString(String8 const &name, String8 &value) const = 0; 80 virtual status_t getPropertyByteArray(String8 const &name, 81 Vector<uint8_t> &value) const = 0; 82 virtual status_t setPropertyString(String8 const &name, 83 String8 const &value ) const = 0; 84 virtual status_t setPropertyByteArray(String8 const &name, 85 Vector<uint8_t> const &value) const = 0; 86 87 virtual status_t setCipherAlgorithm(Vector<uint8_t> const &sessionId, 88 String8 const &algorithm) = 0; 89 90 virtual status_t setMacAlgorithm(Vector<uint8_t> const &sessionId, 91 String8 const &algorithm) = 0; 92 93 virtual status_t encrypt(Vector<uint8_t> const &sessionId, 94 Vector<uint8_t> const &keyId, 95 Vector<uint8_t> const &input, 96 Vector<uint8_t> const &iv, 97 Vector<uint8_t> &output) = 0; 98 99 virtual status_t decrypt(Vector<uint8_t> const &sessionId, 100 Vector<uint8_t> const &keyId, 101 Vector<uint8_t> const &input, 102 Vector<uint8_t> const &iv, 103 Vector<uint8_t> &output) = 0; 104 105 virtual status_t sign(Vector<uint8_t> const &sessionId, 106 Vector<uint8_t> const &keyId, 107 Vector<uint8_t> const &message, 108 Vector<uint8_t> &signature) = 0; 109 110 virtual status_t verify(Vector<uint8_t> const &sessionId, 111 Vector<uint8_t> const &keyId, 112 Vector<uint8_t> const &message, 113 Vector<uint8_t> const &signature, 114 bool &match) = 0; 115 116 virtual status_t signRSA(Vector<uint8_t> const &sessionId, 117 String8 const &algorithm, 118 Vector<uint8_t> const &message, 119 Vector<uint8_t> const &wrappedKey, 120 Vector<uint8_t> &signature) = 0; 121 122 virtual status_t setListener(const sp<IDrmClient>& listener) = 0; 123 124 private: 125 DISALLOW_EVIL_CONSTRUCTORS(IDrm); 126 }; 127 128 struct BnDrm : public BnInterface<IDrm> { 129 virtual status_t onTransact( 130 uint32_t code, const Parcel &data, Parcel *reply, 131 uint32_t flags = 0); 132 private: 133 void readVector(const Parcel &data, Vector<uint8_t> &vector) const; 134 void writeVector(Parcel *reply, Vector<uint8_t> const &vector) const; 135 }; 136 137 } // namespace android 138 139 #endif // ANDROID_IDRM_H_ 140 141