Andres Morales | 2d08dce | 2015-04-03 16:40:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015, 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_TAG "GateKeeperService" |
| 18 | #include <utils/Log.h> |
| 19 | |
| 20 | #include "IGateKeeperService.h" |
| 21 | |
| 22 | namespace android { |
| 23 | |
| 24 | const android::String16 IGateKeeperService::descriptor("android.service.gatekeeper.IGateKeeperService"); |
| 25 | const android::String16& IGateKeeperService::getInterfaceDescriptor() const { |
| 26 | return IGateKeeperService::descriptor; |
| 27 | } |
| 28 | |
| 29 | status_t BnGateKeeperService::onTransact( |
| 30 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { |
| 31 | switch(code) { |
| 32 | case ENROLL: { |
| 33 | CHECK_INTERFACE(IGateKeeperService, data, reply); |
| 34 | uint32_t uid = data.readInt32(); |
| 35 | |
| 36 | ssize_t currentPasswordHandleSize = data.readInt32(); |
| 37 | const uint8_t *currentPasswordHandle = |
| 38 | static_cast<const uint8_t *>(data.readInplace(currentPasswordHandleSize)); |
| 39 | if (!currentPasswordHandle) currentPasswordHandleSize = 0; |
| 40 | |
| 41 | ssize_t currentPasswordSize = data.readInt32(); |
| 42 | const uint8_t *currentPassword = |
| 43 | static_cast<const uint8_t *>(data.readInplace(currentPasswordSize)); |
| 44 | if (!currentPassword) currentPasswordSize = 0; |
| 45 | |
| 46 | ssize_t desiredPasswordSize = data.readInt32(); |
| 47 | const uint8_t *desiredPassword = |
| 48 | static_cast<const uint8_t *>(data.readInplace(desiredPasswordSize)); |
| 49 | if (!desiredPassword) desiredPasswordSize = 0; |
| 50 | |
| 51 | uint8_t *out = NULL; |
| 52 | uint32_t outSize = 0; |
| 53 | status_t ret = enroll(uid, currentPasswordHandle, currentPasswordHandleSize, |
| 54 | currentPassword, currentPasswordSize, desiredPassword, |
| 55 | desiredPasswordSize, &out, &outSize); |
| 56 | |
| 57 | reply->writeNoException(); |
| 58 | if (ret == NO_ERROR && outSize > 0 && out != NULL) { |
| 59 | reply->writeInt32(outSize); |
| 60 | void *buf = reply->writeInplace(outSize); |
| 61 | memcpy(buf, out, outSize); |
| 62 | free(out); |
| 63 | } else { |
| 64 | reply->writeInt32(-1); |
| 65 | } |
| 66 | return NO_ERROR; |
| 67 | } |
| 68 | case VERIFY: { |
| 69 | CHECK_INTERFACE(IGateKeeperService, data, reply); |
| 70 | uint32_t uid = data.readInt32(); |
Andres Morales | 851b57c | 2015-04-09 19:23:48 -0700 | [diff] [blame^] | 71 | uint64_t challenge = data.readInt64(); |
Andres Morales | 2d08dce | 2015-04-03 16:40:15 -0700 | [diff] [blame] | 72 | ssize_t currentPasswordHandleSize = data.readInt32(); |
| 73 | const uint8_t *currentPasswordHandle = |
| 74 | static_cast<const uint8_t *>(data.readInplace(currentPasswordHandleSize)); |
| 75 | if (!currentPasswordHandle) currentPasswordHandleSize = 0; |
| 76 | |
| 77 | ssize_t currentPasswordSize = data.readInt32(); |
| 78 | const uint8_t *currentPassword = |
| 79 | static_cast<const uint8_t *>(data.readInplace(currentPasswordSize)); |
| 80 | if (!currentPassword) currentPasswordSize = 0; |
| 81 | |
Andres Morales | 851b57c | 2015-04-09 19:23:48 -0700 | [diff] [blame^] | 82 | status_t ret = verify(uid, challenge, (uint8_t *) currentPasswordHandle, |
| 83 | currentPasswordHandleSize, (uint8_t *) currentPassword, currentPasswordSize); |
Andres Morales | 2d08dce | 2015-04-03 16:40:15 -0700 | [diff] [blame] | 84 | reply->writeNoException(); |
| 85 | reply->writeInt32(ret == NO_ERROR ? 1 : 0); |
| 86 | return NO_ERROR; |
| 87 | } |
| 88 | default: |
| 89 | return BBinder::onTransact(code, data, reply, flags); |
| 90 | } |
| 91 | }; |
| 92 | |
| 93 | |
| 94 | }; // namespace android |