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 | c828ae8 | 2015-04-10 21:03:07 -0700 | [diff] [blame] | 71 | ssize_t currentPasswordHandleSize = data.readInt32(); |
| 72 | const uint8_t *currentPasswordHandle = |
| 73 | static_cast<const uint8_t *>(data.readInplace(currentPasswordHandleSize)); |
| 74 | if (!currentPasswordHandle) currentPasswordHandleSize = 0; |
| 75 | |
| 76 | ssize_t currentPasswordSize = data.readInt32(); |
| 77 | const uint8_t *currentPassword = |
| 78 | static_cast<const uint8_t *>(data.readInplace(currentPasswordSize)); |
| 79 | if (!currentPassword) currentPasswordSize = 0; |
| 80 | |
| 81 | status_t ret = verify(uid, (uint8_t *) currentPasswordHandle, |
| 82 | currentPasswordHandleSize, (uint8_t *) currentPassword, currentPasswordSize); |
| 83 | reply->writeNoException(); |
| 84 | reply->writeInt32(ret == NO_ERROR ? 1 : 0); |
| 85 | return NO_ERROR; |
| 86 | } |
| 87 | case VERIFY_CHALLENGE: { |
| 88 | CHECK_INTERFACE(IGateKeeperService, data, reply); |
| 89 | uint32_t uid = data.readInt32(); |
Andres Morales | 851b57c | 2015-04-09 19:23:48 -0700 | [diff] [blame] | 90 | uint64_t challenge = data.readInt64(); |
Andres Morales | 2d08dce | 2015-04-03 16:40:15 -0700 | [diff] [blame] | 91 | ssize_t currentPasswordHandleSize = data.readInt32(); |
| 92 | const uint8_t *currentPasswordHandle = |
| 93 | static_cast<const uint8_t *>(data.readInplace(currentPasswordHandleSize)); |
| 94 | if (!currentPasswordHandle) currentPasswordHandleSize = 0; |
| 95 | |
| 96 | ssize_t currentPasswordSize = data.readInt32(); |
| 97 | const uint8_t *currentPassword = |
| 98 | static_cast<const uint8_t *>(data.readInplace(currentPasswordSize)); |
| 99 | if (!currentPassword) currentPasswordSize = 0; |
| 100 | |
Andres Morales | c828ae8 | 2015-04-10 21:03:07 -0700 | [diff] [blame] | 101 | |
| 102 | uint8_t *out = NULL; |
| 103 | uint32_t outSize = 0; |
| 104 | status_t ret = verifyChallenge(uid, challenge, (uint8_t *) currentPasswordHandle, |
| 105 | currentPasswordHandleSize, (uint8_t *) currentPassword, currentPasswordSize, |
| 106 | &out, &outSize); |
Andres Morales | 2d08dce | 2015-04-03 16:40:15 -0700 | [diff] [blame] | 107 | reply->writeNoException(); |
Andres Morales | c828ae8 | 2015-04-10 21:03:07 -0700 | [diff] [blame] | 108 | if (ret == NO_ERROR && outSize > 0 && out != NULL) { |
| 109 | reply->writeInt32(outSize); |
| 110 | void *buf = reply->writeInplace(outSize); |
| 111 | memcpy(buf, out, outSize); |
| 112 | free(out); |
| 113 | } else { |
| 114 | reply->writeInt32(-1); |
| 115 | } |
Andres Morales | 2d08dce | 2015-04-03 16:40:15 -0700 | [diff] [blame] | 116 | return NO_ERROR; |
| 117 | } |
Andres Morales | 6a49c2f | 2015-04-16 13:16:24 -0700 | [diff] [blame^] | 118 | case GET_SECURE_USER_ID: { |
| 119 | CHECK_INTERFACE(IGateKeeperService, data, reply); |
| 120 | uint32_t uid = data.readInt32(); |
| 121 | uint64_t sid = getSecureUserId(uid); |
| 122 | reply->writeNoException(); |
| 123 | reply->writeInt64(sid); |
| 124 | return NO_ERROR; |
| 125 | } |
Andres Morales | 2d08dce | 2015-04-03 16:40:15 -0700 | [diff] [blame] | 126 | default: |
| 127 | return BBinder::onTransact(code, data, reply, flags); |
| 128 | } |
| 129 | }; |
| 130 | |
| 131 | |
| 132 | }; // namespace android |