blob: f5bbbf1f2596f4be07d076768ae9b386f69d78f8 [file] [log] [blame]
Andres Morales2d08dce2015-04-03 16:40:15 -07001/*
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
22namespace android {
23
24const android::String16 IGateKeeperService::descriptor("android.service.gatekeeper.IGateKeeperService");
25const android::String16& IGateKeeperService::getInterfaceDescriptor() const {
26 return IGateKeeperService::descriptor;
27}
28
29status_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 Moralesc828ae82015-04-10 21:03:07 -070071 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 Morales851b57c2015-04-09 19:23:48 -070090 uint64_t challenge = data.readInt64();
Andres Morales2d08dce2015-04-03 16:40:15 -070091 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 Moralesc828ae82015-04-10 21:03:07 -0700101
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 Morales2d08dce2015-04-03 16:40:15 -0700107 reply->writeNoException();
Andres Moralesc828ae82015-04-10 21:03:07 -0700108 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 Morales2d08dce2015-04-03 16:40:15 -0700116 return NO_ERROR;
117 }
Andres Morales6a49c2f2015-04-16 13:16:24 -0700118 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 Morales7c9c3bc2015-04-16 15:57:17 -0700126 case CLEAR_SECURE_USER_ID: {
127 CHECK_INTERFACE(IGateKeeperService, data, reply);
128 uint32_t uid = data.readInt32();
129 clearSecureUserId(uid);
130 reply->writeNoException();
131 return NO_ERROR;
132 }
Andres Morales2d08dce2015-04-03 16:40:15 -0700133 default:
134 return BBinder::onTransact(code, data, reply, flags);
135 }
136};
137
138
139}; // namespace android