| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 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 | //#define LOG_NDEBUG 0 |
| 18 | #define LOG_TAG "IDrm" |
| 19 | #include <utils/Log.h> |
| 20 | |
| 21 | #include <binder/Parcel.h> |
| 22 | #include <media/IDrm.h> |
| 23 | #include <media/stagefright/MediaErrors.h> |
| 24 | #include <media/stagefright/foundation/ADebug.h> |
| 25 | #include <media/stagefright/foundation/AString.h> |
| 26 | |
| 27 | namespace android { |
| 28 | |
| 29 | enum { |
| 30 | INIT_CHECK = IBinder::FIRST_CALL_TRANSACTION, |
| 31 | IS_CRYPTO_SUPPORTED, |
| 32 | CREATE_PLUGIN, |
| 33 | DESTROY_PLUGIN, |
| 34 | OPEN_SESSION, |
| 35 | CLOSE_SESSION, |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 36 | GET_KEY_REQUEST, |
| 37 | PROVIDE_KEY_RESPONSE, |
| 38 | REMOVE_KEYS, |
| 39 | RESTORE_KEYS, |
| 40 | QUERY_KEY_STATUS, |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 41 | GET_PROVISION_REQUEST, |
| 42 | PROVIDE_PROVISION_RESPONSE, |
| 43 | GET_SECURE_STOPS, |
| 44 | RELEASE_SECURE_STOPS, |
| 45 | GET_PROPERTY_STRING, |
| 46 | GET_PROPERTY_BYTE_ARRAY, |
| 47 | SET_PROPERTY_STRING, |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 48 | SET_PROPERTY_BYTE_ARRAY, |
| 49 | SET_CIPHER_ALGORITHM, |
| 50 | SET_MAC_ALGORITHM, |
| 51 | ENCRYPT, |
| 52 | DECRYPT, |
| 53 | SIGN, |
| Jeff Tinker | 68d9d71 | 2014-03-04 13:21:31 -0800 | [diff] [blame] | 54 | SIGN_RSA, |
| Jeff Tinker | c0d5f1f | 2013-04-02 13:08:05 -0700 | [diff] [blame] | 55 | VERIFY, |
| Jeff Tinker | 68b1555 | 2014-04-30 10:19:03 -0700 | [diff] [blame] | 56 | SET_LISTENER, |
| Jeff Tinker | 3c1285e | 2014-10-31 00:55:16 -0700 | [diff] [blame] | 57 | UNPROVISION_DEVICE, |
| 58 | GET_SECURE_STOP, |
| 59 | RELEASE_ALL_SECURE_STOPS |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | struct BpDrm : public BpInterface<IDrm> { |
| 63 | BpDrm(const sp<IBinder> &impl) |
| 64 | : BpInterface<IDrm>(impl) { |
| 65 | } |
| 66 | |
| 67 | virtual status_t initCheck() const { |
| 68 | Parcel data, reply; |
| 69 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 70 | status_t status = remote()->transact(INIT_CHECK, data, &reply); |
| 71 | if (status != OK) { |
| 72 | return status; |
| 73 | } |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 74 | |
| 75 | return reply.readInt32(); |
| 76 | } |
| 77 | |
| Jeff Tinker | 9cf69e0 | 2013-08-21 11:59:23 -0700 | [diff] [blame] | 78 | virtual bool isCryptoSchemeSupported(const uint8_t uuid[16], const String8 &mimeType) { |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 79 | Parcel data, reply; |
| 80 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 81 | data.write(uuid, 16); |
| Jeff Tinker | 9cf69e0 | 2013-08-21 11:59:23 -0700 | [diff] [blame] | 82 | data.writeString8(mimeType); |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 83 | status_t status = remote()->transact(IS_CRYPTO_SUPPORTED, data, &reply); |
| 84 | if (status != OK) { |
| 85 | ALOGE("isCryptoSchemeSupported: binder call failed: %d", status); |
| 86 | return false; |
| 87 | } |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 88 | |
| 89 | return reply.readInt32() != 0; |
| 90 | } |
| 91 | |
| 92 | virtual status_t createPlugin(const uint8_t uuid[16]) { |
| 93 | Parcel data, reply; |
| 94 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 95 | data.write(uuid, 16); |
| 96 | |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 97 | status_t status = remote()->transact(CREATE_PLUGIN, data, &reply); |
| 98 | if (status != OK) { |
| 99 | return status; |
| 100 | } |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 101 | |
| 102 | return reply.readInt32(); |
| 103 | } |
| 104 | |
| 105 | virtual status_t destroyPlugin() { |
| 106 | Parcel data, reply; |
| 107 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 108 | status_t status = remote()->transact(DESTROY_PLUGIN, data, &reply); |
| 109 | if (status != OK) { |
| 110 | return status; |
| 111 | } |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 112 | |
| 113 | return reply.readInt32(); |
| 114 | } |
| 115 | |
| 116 | virtual status_t openSession(Vector<uint8_t> &sessionId) { |
| 117 | Parcel data, reply; |
| 118 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 119 | |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 120 | status_t status = remote()->transact(OPEN_SESSION, data, &reply); |
| 121 | if (status != OK) { |
| 122 | return status; |
| 123 | } |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 124 | readVector(reply, sessionId); |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 125 | |
| 126 | return reply.readInt32(); |
| 127 | } |
| 128 | |
| 129 | virtual status_t closeSession(Vector<uint8_t> const &sessionId) { |
| 130 | Parcel data, reply; |
| 131 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 132 | |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 133 | writeVector(data, sessionId); |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 134 | status_t status = remote()->transact(CLOSE_SESSION, data, &reply); |
| 135 | if (status != OK) { |
| 136 | return status; |
| 137 | } |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 138 | |
| 139 | return reply.readInt32(); |
| 140 | } |
| 141 | |
| 142 | virtual status_t |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 143 | getKeyRequest(Vector<uint8_t> const &sessionId, |
| 144 | Vector<uint8_t> const &initData, |
| 145 | String8 const &mimeType, DrmPlugin::KeyType keyType, |
| 146 | KeyedVector<String8, String8> const &optionalParameters, |
| Jeff Tinker | d072c90 | 2015-03-16 13:39:29 -0700 | [diff] [blame] | 147 | Vector<uint8_t> &request, String8 &defaultUrl, |
| 148 | DrmPlugin::KeyRequestType *keyRequestType) { |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 149 | Parcel data, reply; |
| 150 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 151 | |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 152 | writeVector(data, sessionId); |
| 153 | writeVector(data, initData); |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 154 | data.writeString8(mimeType); |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 155 | data.writeInt32((uint32_t)keyType); |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 156 | |
| 157 | data.writeInt32(optionalParameters.size()); |
| 158 | for (size_t i = 0; i < optionalParameters.size(); ++i) { |
| 159 | data.writeString8(optionalParameters.keyAt(i)); |
| 160 | data.writeString8(optionalParameters.valueAt(i)); |
| 161 | } |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 162 | |
| 163 | status_t status = remote()->transact(GET_KEY_REQUEST, data, &reply); |
| 164 | if (status != OK) { |
| 165 | return status; |
| 166 | } |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 167 | |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 168 | readVector(reply, request); |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 169 | defaultUrl = reply.readString8(); |
| Jeff Tinker | d072c90 | 2015-03-16 13:39:29 -0700 | [diff] [blame] | 170 | *keyRequestType = static_cast<DrmPlugin::KeyRequestType>(reply.readInt32()); |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 171 | |
| 172 | return reply.readInt32(); |
| 173 | } |
| 174 | |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 175 | virtual status_t provideKeyResponse(Vector<uint8_t> const &sessionId, |
| 176 | Vector<uint8_t> const &response, |
| 177 | Vector<uint8_t> &keySetId) { |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 178 | Parcel data, reply; |
| 179 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 180 | writeVector(data, sessionId); |
| 181 | writeVector(data, response); |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 182 | |
| 183 | status_t status = remote()->transact(PROVIDE_KEY_RESPONSE, data, &reply); |
| 184 | if (status != OK) { |
| 185 | return status; |
| 186 | } |
| 187 | |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 188 | readVector(reply, keySetId); |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 189 | |
| 190 | return reply.readInt32(); |
| 191 | } |
| 192 | |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 193 | virtual status_t removeKeys(Vector<uint8_t> const &keySetId) { |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 194 | Parcel data, reply; |
| 195 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 196 | |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 197 | writeVector(data, keySetId); |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 198 | status_t status = remote()->transact(REMOVE_KEYS, data, &reply); |
| 199 | if (status != OK) { |
| 200 | return status; |
| 201 | } |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 202 | |
| 203 | return reply.readInt32(); |
| 204 | } |
| 205 | |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 206 | virtual status_t restoreKeys(Vector<uint8_t> const &sessionId, |
| 207 | Vector<uint8_t> const &keySetId) { |
| 208 | Parcel data, reply; |
| 209 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 210 | |
| 211 | writeVector(data, sessionId); |
| 212 | writeVector(data, keySetId); |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 213 | status_t status = remote()->transact(RESTORE_KEYS, data, &reply); |
| 214 | if (status != OK) { |
| 215 | return status; |
| 216 | } |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 217 | |
| 218 | return reply.readInt32(); |
| 219 | } |
| 220 | |
| 221 | virtual status_t queryKeyStatus(Vector<uint8_t> const &sessionId, |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 222 | KeyedVector<String8, String8> &infoMap) const { |
| 223 | Parcel data, reply; |
| 224 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 225 | |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 226 | writeVector(data, sessionId); |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 227 | status_t status = remote()->transact(QUERY_KEY_STATUS, data, &reply); |
| 228 | if (status != OK) { |
| 229 | return status; |
| 230 | } |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 231 | |
| 232 | infoMap.clear(); |
| 233 | size_t count = reply.readInt32(); |
| 234 | for (size_t i = 0; i < count; i++) { |
| 235 | String8 key = reply.readString8(); |
| 236 | String8 value = reply.readString8(); |
| 237 | infoMap.add(key, value); |
| 238 | } |
| 239 | return reply.readInt32(); |
| 240 | } |
| 241 | |
| Jeff Tinker | 68d9d71 | 2014-03-04 13:21:31 -0800 | [diff] [blame] | 242 | virtual status_t getProvisionRequest(String8 const &certType, |
| 243 | String8 const &certAuthority, |
| 244 | Vector<uint8_t> &request, |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 245 | String8 &defaultUrl) { |
| 246 | Parcel data, reply; |
| 247 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 248 | |
| Jeff Tinker | 68d9d71 | 2014-03-04 13:21:31 -0800 | [diff] [blame] | 249 | data.writeString8(certType); |
| 250 | data.writeString8(certAuthority); |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 251 | status_t status = remote()->transact(GET_PROVISION_REQUEST, data, &reply); |
| 252 | if (status != OK) { |
| 253 | return status; |
| 254 | } |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 255 | |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 256 | readVector(reply, request); |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 257 | defaultUrl = reply.readString8(); |
| 258 | |
| 259 | return reply.readInt32(); |
| 260 | } |
| 261 | |
| Jeff Tinker | 68d9d71 | 2014-03-04 13:21:31 -0800 | [diff] [blame] | 262 | virtual status_t provideProvisionResponse(Vector<uint8_t> const &response, |
| 263 | Vector<uint8_t> &certificate, |
| 264 | Vector<uint8_t> &wrappedKey) { |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 265 | Parcel data, reply; |
| 266 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 267 | |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 268 | writeVector(data, response); |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 269 | status_t status = remote()->transact(PROVIDE_PROVISION_RESPONSE, data, &reply); |
| 270 | if (status != OK) { |
| 271 | return status; |
| 272 | } |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 273 | |
| Jeff Tinker | 68d9d71 | 2014-03-04 13:21:31 -0800 | [diff] [blame] | 274 | readVector(reply, certificate); |
| 275 | readVector(reply, wrappedKey); |
| 276 | |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 277 | return reply.readInt32(); |
| 278 | } |
| 279 | |
| Jeff Tinker | 68b1555 | 2014-04-30 10:19:03 -0700 | [diff] [blame] | 280 | virtual status_t unprovisionDevice() { |
| 281 | Parcel data, reply; |
| 282 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 283 | |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 284 | status_t status = remote()->transact(UNPROVISION_DEVICE, data, &reply); |
| 285 | if (status != OK) { |
| 286 | return status; |
| 287 | } |
| Jeff Tinker | 68b1555 | 2014-04-30 10:19:03 -0700 | [diff] [blame] | 288 | |
| 289 | return reply.readInt32(); |
| 290 | } |
| 291 | |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 292 | virtual status_t getSecureStops(List<Vector<uint8_t> > &secureStops) { |
| 293 | Parcel data, reply; |
| 294 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 295 | |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 296 | status_t status = remote()->transact(GET_SECURE_STOPS, data, &reply); |
| 297 | if (status != OK) { |
| 298 | return status; |
| 299 | } |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 300 | |
| 301 | secureStops.clear(); |
| 302 | uint32_t count = reply.readInt32(); |
| 303 | for (size_t i = 0; i < count; i++) { |
| 304 | Vector<uint8_t> secureStop; |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 305 | readVector(reply, secureStop); |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 306 | secureStops.push_back(secureStop); |
| 307 | } |
| 308 | return reply.readInt32(); |
| 309 | } |
| 310 | |
| Jeff Tinker | 3c1285e | 2014-10-31 00:55:16 -0700 | [diff] [blame] | 311 | virtual status_t getSecureStop(Vector<uint8_t> const &ssid, Vector<uint8_t> &secureStop) { |
| 312 | Parcel data, reply; |
| 313 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 314 | |
| 315 | writeVector(data, ssid); |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 316 | status_t status = remote()->transact(GET_SECURE_STOP, data, &reply); |
| 317 | if (status != OK) { |
| 318 | return status; |
| 319 | } |
| Jeff Tinker | 3c1285e | 2014-10-31 00:55:16 -0700 | [diff] [blame] | 320 | |
| 321 | readVector(reply, secureStop); |
| 322 | return reply.readInt32(); |
| 323 | } |
| 324 | |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 325 | virtual status_t releaseSecureStops(Vector<uint8_t> const &ssRelease) { |
| 326 | Parcel data, reply; |
| 327 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 328 | |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 329 | writeVector(data, ssRelease); |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 330 | status_t status = remote()->transact(RELEASE_SECURE_STOPS, data, &reply); |
| 331 | if (status != OK) { |
| 332 | return status; |
| 333 | } |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 334 | |
| 335 | return reply.readInt32(); |
| 336 | } |
| 337 | |
| Jeff Tinker | 3c1285e | 2014-10-31 00:55:16 -0700 | [diff] [blame] | 338 | virtual status_t releaseAllSecureStops() { |
| 339 | Parcel data, reply; |
| 340 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 341 | |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 342 | status_t status = remote()->transact(RELEASE_ALL_SECURE_STOPS, data, &reply); |
| 343 | if (status != OK) { |
| 344 | return status; |
| 345 | } |
| Jeff Tinker | 3c1285e | 2014-10-31 00:55:16 -0700 | [diff] [blame] | 346 | |
| 347 | return reply.readInt32(); |
| 348 | } |
| 349 | |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 350 | virtual status_t getPropertyString(String8 const &name, String8 &value) const { |
| 351 | Parcel data, reply; |
| 352 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 353 | |
| 354 | data.writeString8(name); |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 355 | status_t status = remote()->transact(GET_PROPERTY_STRING, data, &reply); |
| 356 | if (status != OK) { |
| 357 | return status; |
| 358 | } |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 359 | |
| 360 | value = reply.readString8(); |
| 361 | return reply.readInt32(); |
| 362 | } |
| 363 | |
| 364 | virtual status_t getPropertyByteArray(String8 const &name, Vector<uint8_t> &value) const { |
| 365 | Parcel data, reply; |
| 366 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 367 | |
| 368 | data.writeString8(name); |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 369 | status_t status = remote()->transact(GET_PROPERTY_BYTE_ARRAY, data, &reply); |
| 370 | if (status != OK) { |
| 371 | return status; |
| 372 | } |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 373 | |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 374 | readVector(reply, value); |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 375 | return reply.readInt32(); |
| 376 | } |
| 377 | |
| 378 | virtual status_t setPropertyString(String8 const &name, String8 const &value) const { |
| 379 | Parcel data, reply; |
| 380 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 381 | |
| 382 | data.writeString8(name); |
| 383 | data.writeString8(value); |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 384 | status_t status = remote()->transact(SET_PROPERTY_STRING, data, &reply); |
| 385 | if (status != OK) { |
| 386 | return status; |
| 387 | } |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 388 | |
| 389 | return reply.readInt32(); |
| 390 | } |
| 391 | |
| 392 | virtual status_t setPropertyByteArray(String8 const &name, |
| 393 | Vector<uint8_t> const &value) const { |
| 394 | Parcel data, reply; |
| 395 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 396 | |
| 397 | data.writeString8(name); |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 398 | writeVector(data, value); |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 399 | status_t status = remote()->transact(SET_PROPERTY_BYTE_ARRAY, data, &reply); |
| 400 | if (status != OK) { |
| 401 | return status; |
| 402 | } |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 403 | |
| 404 | return reply.readInt32(); |
| 405 | } |
| 406 | |
| 407 | |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 408 | virtual status_t setCipherAlgorithm(Vector<uint8_t> const &sessionId, |
| 409 | String8 const &algorithm) { |
| 410 | Parcel data, reply; |
| 411 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 412 | |
| 413 | writeVector(data, sessionId); |
| 414 | data.writeString8(algorithm); |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 415 | status_t status = remote()->transact(SET_CIPHER_ALGORITHM, data, &reply); |
| 416 | if (status != OK) { |
| 417 | return status; |
| 418 | } |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 419 | return reply.readInt32(); |
| 420 | } |
| 421 | |
| 422 | virtual status_t setMacAlgorithm(Vector<uint8_t> const &sessionId, |
| 423 | String8 const &algorithm) { |
| 424 | Parcel data, reply; |
| 425 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 426 | |
| 427 | writeVector(data, sessionId); |
| 428 | data.writeString8(algorithm); |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 429 | status_t status = remote()->transact(SET_MAC_ALGORITHM, data, &reply); |
| 430 | if (status != OK) { |
| 431 | return status; |
| 432 | } |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 433 | return reply.readInt32(); |
| 434 | } |
| 435 | |
| 436 | virtual status_t encrypt(Vector<uint8_t> const &sessionId, |
| 437 | Vector<uint8_t> const &keyId, |
| 438 | Vector<uint8_t> const &input, |
| 439 | Vector<uint8_t> const &iv, |
| 440 | Vector<uint8_t> &output) { |
| 441 | Parcel data, reply; |
| 442 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 443 | |
| 444 | writeVector(data, sessionId); |
| 445 | writeVector(data, keyId); |
| 446 | writeVector(data, input); |
| 447 | writeVector(data, iv); |
| 448 | |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 449 | status_t status = remote()->transact(ENCRYPT, data, &reply); |
| 450 | if (status != OK) { |
| 451 | return status; |
| 452 | } |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 453 | readVector(reply, output); |
| 454 | |
| 455 | return reply.readInt32(); |
| 456 | } |
| 457 | |
| 458 | virtual status_t decrypt(Vector<uint8_t> const &sessionId, |
| 459 | Vector<uint8_t> const &keyId, |
| 460 | Vector<uint8_t> const &input, |
| 461 | Vector<uint8_t> const &iv, |
| 462 | Vector<uint8_t> &output) { |
| 463 | Parcel data, reply; |
| 464 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 465 | |
| 466 | writeVector(data, sessionId); |
| 467 | writeVector(data, keyId); |
| 468 | writeVector(data, input); |
| 469 | writeVector(data, iv); |
| 470 | |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 471 | status_t status = remote()->transact(DECRYPT, data, &reply); |
| 472 | if (status != OK) { |
| 473 | return status; |
| 474 | } |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 475 | readVector(reply, output); |
| 476 | |
| 477 | return reply.readInt32(); |
| 478 | } |
| 479 | |
| 480 | virtual status_t sign(Vector<uint8_t> const &sessionId, |
| 481 | Vector<uint8_t> const &keyId, |
| 482 | Vector<uint8_t> const &message, |
| 483 | Vector<uint8_t> &signature) { |
| 484 | Parcel data, reply; |
| 485 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 486 | |
| 487 | writeVector(data, sessionId); |
| 488 | writeVector(data, keyId); |
| 489 | writeVector(data, message); |
| 490 | |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 491 | status_t status = remote()->transact(SIGN, data, &reply); |
| 492 | if (status != OK) { |
| 493 | return status; |
| 494 | } |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 495 | readVector(reply, signature); |
| 496 | |
| 497 | return reply.readInt32(); |
| 498 | } |
| 499 | |
| 500 | virtual status_t verify(Vector<uint8_t> const &sessionId, |
| 501 | Vector<uint8_t> const &keyId, |
| 502 | Vector<uint8_t> const &message, |
| 503 | Vector<uint8_t> const &signature, |
| 504 | bool &match) { |
| 505 | Parcel data, reply; |
| 506 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 507 | |
| 508 | writeVector(data, sessionId); |
| 509 | writeVector(data, keyId); |
| 510 | writeVector(data, message); |
| 511 | writeVector(data, signature); |
| 512 | |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 513 | status_t status = remote()->transact(VERIFY, data, &reply); |
| 514 | if (status != OK) { |
| 515 | return status; |
| 516 | } |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 517 | match = (bool)reply.readInt32(); |
| 518 | return reply.readInt32(); |
| 519 | } |
| 520 | |
| Jeff Tinker | 68d9d71 | 2014-03-04 13:21:31 -0800 | [diff] [blame] | 521 | virtual status_t signRSA(Vector<uint8_t> const &sessionId, |
| 522 | String8 const &algorithm, |
| 523 | Vector<uint8_t> const &message, |
| 524 | Vector<uint8_t> const &wrappedKey, |
| 525 | Vector<uint8_t> &signature) { |
| 526 | Parcel data, reply; |
| 527 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 528 | |
| 529 | writeVector(data, sessionId); |
| 530 | data.writeString8(algorithm); |
| 531 | writeVector(data, message); |
| 532 | writeVector(data, wrappedKey); |
| 533 | |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 534 | status_t status = remote()->transact(SIGN_RSA, data, &reply); |
| 535 | if (status != OK) { |
| 536 | return status; |
| 537 | } |
| Jeff Tinker | 68d9d71 | 2014-03-04 13:21:31 -0800 | [diff] [blame] | 538 | readVector(reply, signature); |
| 539 | |
| 540 | return reply.readInt32(); |
| 541 | } |
| 542 | |
| Jeff Tinker | c0d5f1f | 2013-04-02 13:08:05 -0700 | [diff] [blame] | 543 | virtual status_t setListener(const sp<IDrmClient>& listener) { |
| 544 | Parcel data, reply; |
| 545 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 546 | data.writeStrongBinder(IInterface::asBinder(listener)); |
| Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 547 | status_t status = remote()->transact(SET_LISTENER, data, &reply); |
| 548 | if (status != OK) { |
| 549 | return status; |
| 550 | } |
| Jeff Tinker | c0d5f1f | 2013-04-02 13:08:05 -0700 | [diff] [blame] | 551 | return reply.readInt32(); |
| 552 | } |
| 553 | |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 554 | private: |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 555 | void readVector(Parcel &reply, Vector<uint8_t> &vector) const { |
| 556 | uint32_t size = reply.readInt32(); |
| 557 | vector.insertAt((size_t)0, size); |
| 558 | reply.read(vector.editArray(), size); |
| 559 | } |
| 560 | |
| 561 | void writeVector(Parcel &data, Vector<uint8_t> const &vector) const { |
| 562 | data.writeInt32(vector.size()); |
| 563 | data.write(vector.array(), vector.size()); |
| 564 | } |
| 565 | |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 566 | DISALLOW_EVIL_CONSTRUCTORS(BpDrm); |
| 567 | }; |
| 568 | |
| 569 | IMPLEMENT_META_INTERFACE(Drm, "android.drm.IDrm"); |
| 570 | |
| 571 | //////////////////////////////////////////////////////////////////////////////// |
| 572 | |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 573 | void BnDrm::readVector(const Parcel &data, Vector<uint8_t> &vector) const { |
| 574 | uint32_t size = data.readInt32(); |
| Jeff Tinker | b41a527 | 2017-10-09 11:52:18 -0700 | [diff] [blame] | 575 | if (vector.insertAt((size_t)0, size) < 0) { |
| 576 | vector.clear(); |
| 577 | } |
| 578 | if (data.read(vector.editArray(), size) != NO_ERROR) { |
| 579 | vector.clear(); |
| 580 | android_errorWriteWithInfoLog(0x534e4554, "62872384", -1, NULL, 0); |
| 581 | } |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | void BnDrm::writeVector(Parcel *reply, Vector<uint8_t> const &vector) const { |
| 585 | reply->writeInt32(vector.size()); |
| 586 | reply->write(vector.array(), vector.size()); |
| 587 | } |
| 588 | |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 589 | status_t BnDrm::onTransact( |
| 590 | uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) { |
| 591 | switch (code) { |
| 592 | case INIT_CHECK: |
| 593 | { |
| 594 | CHECK_INTERFACE(IDrm, data, reply); |
| 595 | reply->writeInt32(initCheck()); |
| 596 | return OK; |
| 597 | } |
| 598 | |
| 599 | case IS_CRYPTO_SUPPORTED: |
| 600 | { |
| 601 | CHECK_INTERFACE(IDrm, data, reply); |
| 602 | uint8_t uuid[16]; |
| 603 | data.read(uuid, sizeof(uuid)); |
| Jeff Tinker | 9cf69e0 | 2013-08-21 11:59:23 -0700 | [diff] [blame] | 604 | String8 mimeType = data.readString8(); |
| 605 | reply->writeInt32(isCryptoSchemeSupported(uuid, mimeType)); |
| 606 | |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 607 | return OK; |
| 608 | } |
| 609 | |
| 610 | case CREATE_PLUGIN: |
| 611 | { |
| 612 | CHECK_INTERFACE(IDrm, data, reply); |
| 613 | uint8_t uuid[16]; |
| 614 | data.read(uuid, sizeof(uuid)); |
| 615 | reply->writeInt32(createPlugin(uuid)); |
| 616 | return OK; |
| 617 | } |
| 618 | |
| 619 | case DESTROY_PLUGIN: |
| 620 | { |
| 621 | CHECK_INTERFACE(IDrm, data, reply); |
| 622 | reply->writeInt32(destroyPlugin()); |
| 623 | return OK; |
| 624 | } |
| 625 | |
| 626 | case OPEN_SESSION: |
| 627 | { |
| 628 | CHECK_INTERFACE(IDrm, data, reply); |
| 629 | Vector<uint8_t> sessionId; |
| 630 | status_t result = openSession(sessionId); |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 631 | writeVector(reply, sessionId); |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 632 | reply->writeInt32(result); |
| 633 | return OK; |
| 634 | } |
| 635 | |
| 636 | case CLOSE_SESSION: |
| 637 | { |
| 638 | CHECK_INTERFACE(IDrm, data, reply); |
| 639 | Vector<uint8_t> sessionId; |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 640 | readVector(data, sessionId); |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 641 | reply->writeInt32(closeSession(sessionId)); |
| 642 | return OK; |
| 643 | } |
| 644 | |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 645 | case GET_KEY_REQUEST: |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 646 | { |
| 647 | CHECK_INTERFACE(IDrm, data, reply); |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 648 | Vector<uint8_t> sessionId, initData; |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 649 | |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 650 | readVector(data, sessionId); |
| 651 | readVector(data, initData); |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 652 | String8 mimeType = data.readString8(); |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 653 | DrmPlugin::KeyType keyType = (DrmPlugin::KeyType)data.readInt32(); |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 654 | |
| 655 | KeyedVector<String8, String8> optionalParameters; |
| 656 | uint32_t count = data.readInt32(); |
| 657 | for (size_t i = 0; i < count; ++i) { |
| 658 | String8 key, value; |
| 659 | key = data.readString8(); |
| 660 | value = data.readString8(); |
| 661 | optionalParameters.add(key, value); |
| 662 | } |
| 663 | |
| 664 | Vector<uint8_t> request; |
| 665 | String8 defaultUrl; |
| Jeff Tinker | 8aff777 | 2016-02-08 17:52:25 -0800 | [diff] [blame] | 666 | DrmPlugin::KeyRequestType keyRequestType = DrmPlugin::kKeyRequestType_Unknown; |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 667 | |
| Jeff Tinker | d072c90 | 2015-03-16 13:39:29 -0700 | [diff] [blame] | 668 | status_t result = getKeyRequest(sessionId, initData, mimeType, |
| 669 | keyType, optionalParameters, request, defaultUrl, |
| 670 | &keyRequestType); |
| 671 | |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 672 | writeVector(reply, request); |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 673 | reply->writeString8(defaultUrl); |
| Jeff Tinker | d072c90 | 2015-03-16 13:39:29 -0700 | [diff] [blame] | 674 | reply->writeInt32(static_cast<int32_t>(keyRequestType)); |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 675 | reply->writeInt32(result); |
| 676 | return OK; |
| 677 | } |
| 678 | |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 679 | case PROVIDE_KEY_RESPONSE: |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 680 | { |
| 681 | CHECK_INTERFACE(IDrm, data, reply); |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 682 | Vector<uint8_t> sessionId, response, keySetId; |
| 683 | readVector(data, sessionId); |
| 684 | readVector(data, response); |
| 685 | uint32_t result = provideKeyResponse(sessionId, response, keySetId); |
| 686 | writeVector(reply, keySetId); |
| 687 | reply->writeInt32(result); |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 688 | return OK; |
| 689 | } |
| 690 | |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 691 | case REMOVE_KEYS: |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 692 | { |
| 693 | CHECK_INTERFACE(IDrm, data, reply); |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 694 | Vector<uint8_t> keySetId; |
| 695 | readVector(data, keySetId); |
| 696 | reply->writeInt32(removeKeys(keySetId)); |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 697 | return OK; |
| 698 | } |
| 699 | |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 700 | case RESTORE_KEYS: |
| 701 | { |
| 702 | CHECK_INTERFACE(IDrm, data, reply); |
| 703 | Vector<uint8_t> sessionId, keySetId; |
| 704 | readVector(data, sessionId); |
| 705 | readVector(data, keySetId); |
| 706 | reply->writeInt32(restoreKeys(sessionId, keySetId)); |
| 707 | return OK; |
| 708 | } |
| 709 | |
| 710 | case QUERY_KEY_STATUS: |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 711 | { |
| 712 | CHECK_INTERFACE(IDrm, data, reply); |
| 713 | Vector<uint8_t> sessionId; |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 714 | readVector(data, sessionId); |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 715 | KeyedVector<String8, String8> infoMap; |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 716 | status_t result = queryKeyStatus(sessionId, infoMap); |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 717 | size_t count = infoMap.size(); |
| 718 | reply->writeInt32(count); |
| 719 | for (size_t i = 0; i < count; ++i) { |
| 720 | reply->writeString8(infoMap.keyAt(i)); |
| 721 | reply->writeString8(infoMap.valueAt(i)); |
| 722 | } |
| 723 | reply->writeInt32(result); |
| 724 | return OK; |
| 725 | } |
| 726 | |
| 727 | case GET_PROVISION_REQUEST: |
| 728 | { |
| 729 | CHECK_INTERFACE(IDrm, data, reply); |
| Jeff Tinker | 68d9d71 | 2014-03-04 13:21:31 -0800 | [diff] [blame] | 730 | String8 certType = data.readString8(); |
| 731 | String8 certAuthority = data.readString8(); |
| 732 | |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 733 | Vector<uint8_t> request; |
| 734 | String8 defaultUrl; |
| Jeff Tinker | 68d9d71 | 2014-03-04 13:21:31 -0800 | [diff] [blame] | 735 | status_t result = getProvisionRequest(certType, certAuthority, |
| 736 | request, defaultUrl); |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 737 | writeVector(reply, request); |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 738 | reply->writeString8(defaultUrl); |
| 739 | reply->writeInt32(result); |
| 740 | return OK; |
| 741 | } |
| 742 | |
| 743 | case PROVIDE_PROVISION_RESPONSE: |
| 744 | { |
| 745 | CHECK_INTERFACE(IDrm, data, reply); |
| 746 | Vector<uint8_t> response; |
| Jeff Tinker | 68d9d71 | 2014-03-04 13:21:31 -0800 | [diff] [blame] | 747 | Vector<uint8_t> certificate; |
| 748 | Vector<uint8_t> wrappedKey; |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 749 | readVector(data, response); |
| Jeff Tinker | 68d9d71 | 2014-03-04 13:21:31 -0800 | [diff] [blame] | 750 | status_t result = provideProvisionResponse(response, certificate, wrappedKey); |
| 751 | writeVector(reply, certificate); |
| 752 | writeVector(reply, wrappedKey); |
| 753 | reply->writeInt32(result); |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 754 | return OK; |
| 755 | } |
| 756 | |
| Jeff Tinker | 68b1555 | 2014-04-30 10:19:03 -0700 | [diff] [blame] | 757 | case UNPROVISION_DEVICE: |
| 758 | { |
| 759 | CHECK_INTERFACE(IDrm, data, reply); |
| 760 | status_t result = unprovisionDevice(); |
| 761 | reply->writeInt32(result); |
| 762 | return OK; |
| 763 | } |
| 764 | |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 765 | case GET_SECURE_STOPS: |
| 766 | { |
| 767 | CHECK_INTERFACE(IDrm, data, reply); |
| 768 | List<Vector<uint8_t> > secureStops; |
| 769 | status_t result = getSecureStops(secureStops); |
| 770 | size_t count = secureStops.size(); |
| 771 | reply->writeInt32(count); |
| 772 | List<Vector<uint8_t> >::iterator iter = secureStops.begin(); |
| 773 | while(iter != secureStops.end()) { |
| 774 | size_t size = iter->size(); |
| 775 | reply->writeInt32(size); |
| 776 | reply->write(iter->array(), iter->size()); |
| Jeff Tinker | 423e33c | 2013-04-08 15:23:17 -0700 | [diff] [blame] | 777 | iter++; |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 778 | } |
| 779 | reply->writeInt32(result); |
| 780 | return OK; |
| 781 | } |
| 782 | |
| Jeff Tinker | 3c1285e | 2014-10-31 00:55:16 -0700 | [diff] [blame] | 783 | case GET_SECURE_STOP: |
| 784 | { |
| 785 | CHECK_INTERFACE(IDrm, data, reply); |
| 786 | Vector<uint8_t> ssid, secureStop; |
| 787 | readVector(data, ssid); |
| 788 | status_t result = getSecureStop(ssid, secureStop); |
| 789 | writeVector(reply, secureStop); |
| 790 | reply->writeInt32(result); |
| 791 | return OK; |
| 792 | } |
| 793 | |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 794 | case RELEASE_SECURE_STOPS: |
| 795 | { |
| 796 | CHECK_INTERFACE(IDrm, data, reply); |
| 797 | Vector<uint8_t> ssRelease; |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 798 | readVector(data, ssRelease); |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 799 | reply->writeInt32(releaseSecureStops(ssRelease)); |
| 800 | return OK; |
| 801 | } |
| 802 | |
| Jeff Tinker | 3c1285e | 2014-10-31 00:55:16 -0700 | [diff] [blame] | 803 | case RELEASE_ALL_SECURE_STOPS: |
| 804 | { |
| 805 | CHECK_INTERFACE(IDrm, data, reply); |
| 806 | reply->writeInt32(releaseAllSecureStops()); |
| 807 | return OK; |
| 808 | } |
| 809 | |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 810 | case GET_PROPERTY_STRING: |
| 811 | { |
| 812 | CHECK_INTERFACE(IDrm, data, reply); |
| 813 | String8 name = data.readString8(); |
| 814 | String8 value; |
| 815 | status_t result = getPropertyString(name, value); |
| 816 | reply->writeString8(value); |
| 817 | reply->writeInt32(result); |
| 818 | return OK; |
| 819 | } |
| 820 | |
| 821 | case GET_PROPERTY_BYTE_ARRAY: |
| 822 | { |
| 823 | CHECK_INTERFACE(IDrm, data, reply); |
| 824 | String8 name = data.readString8(); |
| 825 | Vector<uint8_t> value; |
| 826 | status_t result = getPropertyByteArray(name, value); |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 827 | writeVector(reply, value); |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 828 | reply->writeInt32(result); |
| 829 | return OK; |
| 830 | } |
| 831 | |
| 832 | case SET_PROPERTY_STRING: |
| 833 | { |
| 834 | CHECK_INTERFACE(IDrm, data, reply); |
| 835 | String8 name = data.readString8(); |
| 836 | String8 value = data.readString8(); |
| 837 | reply->writeInt32(setPropertyString(name, value)); |
| 838 | return OK; |
| 839 | } |
| 840 | |
| 841 | case SET_PROPERTY_BYTE_ARRAY: |
| 842 | { |
| 843 | CHECK_INTERFACE(IDrm, data, reply); |
| 844 | String8 name = data.readString8(); |
| 845 | Vector<uint8_t> value; |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 846 | readVector(data, value); |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 847 | reply->writeInt32(setPropertyByteArray(name, value)); |
| 848 | return OK; |
| 849 | } |
| 850 | |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 851 | case SET_CIPHER_ALGORITHM: |
| 852 | { |
| 853 | CHECK_INTERFACE(IDrm, data, reply); |
| 854 | Vector<uint8_t> sessionId; |
| 855 | readVector(data, sessionId); |
| 856 | String8 algorithm = data.readString8(); |
| 857 | reply->writeInt32(setCipherAlgorithm(sessionId, algorithm)); |
| 858 | return OK; |
| 859 | } |
| 860 | |
| 861 | case SET_MAC_ALGORITHM: |
| 862 | { |
| 863 | CHECK_INTERFACE(IDrm, data, reply); |
| 864 | Vector<uint8_t> sessionId; |
| 865 | readVector(data, sessionId); |
| 866 | String8 algorithm = data.readString8(); |
| 867 | reply->writeInt32(setMacAlgorithm(sessionId, algorithm)); |
| 868 | return OK; |
| 869 | } |
| 870 | |
| 871 | case ENCRYPT: |
| 872 | { |
| 873 | CHECK_INTERFACE(IDrm, data, reply); |
| 874 | Vector<uint8_t> sessionId, keyId, input, iv, output; |
| 875 | readVector(data, sessionId); |
| 876 | readVector(data, keyId); |
| 877 | readVector(data, input); |
| 878 | readVector(data, iv); |
| 879 | uint32_t result = encrypt(sessionId, keyId, input, iv, output); |
| 880 | writeVector(reply, output); |
| 881 | reply->writeInt32(result); |
| 882 | return OK; |
| 883 | } |
| 884 | |
| 885 | case DECRYPT: |
| 886 | { |
| 887 | CHECK_INTERFACE(IDrm, data, reply); |
| 888 | Vector<uint8_t> sessionId, keyId, input, iv, output; |
| 889 | readVector(data, sessionId); |
| 890 | readVector(data, keyId); |
| 891 | readVector(data, input); |
| 892 | readVector(data, iv); |
| 893 | uint32_t result = decrypt(sessionId, keyId, input, iv, output); |
| 894 | writeVector(reply, output); |
| 895 | reply->writeInt32(result); |
| 896 | return OK; |
| 897 | } |
| 898 | |
| 899 | case SIGN: |
| 900 | { |
| 901 | CHECK_INTERFACE(IDrm, data, reply); |
| 902 | Vector<uint8_t> sessionId, keyId, message, signature; |
| 903 | readVector(data, sessionId); |
| 904 | readVector(data, keyId); |
| 905 | readVector(data, message); |
| 906 | uint32_t result = sign(sessionId, keyId, message, signature); |
| 907 | writeVector(reply, signature); |
| 908 | reply->writeInt32(result); |
| 909 | return OK; |
| 910 | } |
| 911 | |
| 912 | case VERIFY: |
| 913 | { |
| 914 | CHECK_INTERFACE(IDrm, data, reply); |
| 915 | Vector<uint8_t> sessionId, keyId, message, signature; |
| 916 | readVector(data, sessionId); |
| 917 | readVector(data, keyId); |
| 918 | readVector(data, message); |
| 919 | readVector(data, signature); |
| Jeff Tinker | 9a6861c | 2016-09-02 11:36:46 -0700 | [diff] [blame] | 920 | bool match = false; |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 921 | uint32_t result = verify(sessionId, keyId, message, signature, match); |
| 922 | reply->writeInt32(match); |
| 923 | reply->writeInt32(result); |
| 924 | return OK; |
| 925 | } |
| 926 | |
| Jeff Tinker | 68d9d71 | 2014-03-04 13:21:31 -0800 | [diff] [blame] | 927 | case SIGN_RSA: |
| 928 | { |
| 929 | CHECK_INTERFACE(IDrm, data, reply); |
| 930 | Vector<uint8_t> sessionId, message, wrappedKey, signature; |
| 931 | readVector(data, sessionId); |
| 932 | String8 algorithm = data.readString8(); |
| 933 | readVector(data, message); |
| 934 | readVector(data, wrappedKey); |
| 935 | uint32_t result = signRSA(sessionId, algorithm, message, wrappedKey, signature); |
| 936 | writeVector(reply, signature); |
| 937 | reply->writeInt32(result); |
| 938 | return OK; |
| 939 | } |
| 940 | |
| Jeff Tinker | c0d5f1f | 2013-04-02 13:08:05 -0700 | [diff] [blame] | 941 | case SET_LISTENER: { |
| 942 | CHECK_INTERFACE(IDrm, data, reply); |
| 943 | sp<IDrmClient> listener = |
| 944 | interface_cast<IDrmClient>(data.readStrongBinder()); |
| 945 | reply->writeInt32(setListener(listener)); |
| 946 | return NO_ERROR; |
| 947 | } break; |
| 948 | |
| Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 949 | default: |
| 950 | return BBinder::onTransact(code, data, reply, flags); |
| Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 951 | } |
| 952 | } |
| 953 | |
| 954 | } // namespace android |