2015-04-04 01:40:15 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LOG_TAG "gatekeeperd"
|
|
|
|
|
|
|
|
#include "IGateKeeperService.h"
|
|
|
|
|
2015-04-16 22:16:24 +02:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2016-09-28 19:07:20 +02:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdint.h>
|
2015-04-16 22:16:24 +02:00
|
|
|
#include <unistd.h>
|
2017-08-16 11:54:20 +02:00
|
|
|
#include <memory>
|
2015-04-16 22:16:24 +02:00
|
|
|
|
2017-11-14 21:53:39 +01:00
|
|
|
#include <android/security/IKeystoreService.h>
|
2015-04-04 01:40:15 +02:00
|
|
|
#include <binder/IPCThreadState.h>
|
|
|
|
#include <binder/IServiceManager.h>
|
|
|
|
#include <binder/PermissionCache.h>
|
2015-04-16 22:16:24 +02:00
|
|
|
#include <gatekeeper/password_handle.h> // for password_handle_t
|
2015-04-04 01:40:15 +02:00
|
|
|
#include <hardware/gatekeeper.h>
|
2015-04-16 22:16:24 +02:00
|
|
|
#include <hardware/hw_auth_token.h>
|
2016-09-28 19:07:20 +02:00
|
|
|
#include <keystore/keystore.h> // For error code
|
2017-11-14 21:53:39 +01:00
|
|
|
#include <keystore/keystore_return_types.h>
|
2017-01-10 22:19:54 +01:00
|
|
|
#include <log/log.h>
|
2016-09-28 19:07:20 +02:00
|
|
|
#include <utils/Log.h>
|
|
|
|
#include <utils/String16.h>
|
2015-04-04 01:40:15 +02:00
|
|
|
|
2015-05-13 00:37:20 +02:00
|
|
|
#include "SoftGateKeeperDevice.h"
|
|
|
|
|
2016-10-18 22:59:26 +02:00
|
|
|
#include <hidl/HidlSupport.h>
|
|
|
|
#include <android/hardware/gatekeeper/1.0/IGatekeeper.h>
|
|
|
|
|
|
|
|
using android::sp;
|
|
|
|
using android::hardware::gatekeeper::V1_0::IGatekeeper;
|
|
|
|
using android::hardware::gatekeeper::V1_0::GatekeeperStatusCode;
|
|
|
|
using android::hardware::gatekeeper::V1_0::GatekeeperResponse;
|
|
|
|
using android::hardware::Return;
|
|
|
|
|
2015-04-04 01:40:15 +02:00
|
|
|
namespace android {
|
|
|
|
|
|
|
|
static const String16 KEYGUARD_PERMISSION("android.permission.ACCESS_KEYGUARD_SECURE_STORAGE");
|
|
|
|
static const String16 DUMP_PERMISSION("android.permission.DUMP");
|
|
|
|
|
|
|
|
class GateKeeperProxy : public BnGateKeeperService {
|
|
|
|
public:
|
|
|
|
GateKeeperProxy() {
|
2017-04-12 22:03:04 +02:00
|
|
|
clear_state_if_needed_done = false;
|
2017-01-24 22:09:39 +01:00
|
|
|
hw_device = IGatekeeper::getService();
|
2015-07-07 19:28:15 +02:00
|
|
|
|
2016-10-18 22:59:26 +02:00
|
|
|
if (hw_device == nullptr) {
|
2015-05-13 00:37:20 +02:00
|
|
|
ALOGW("falling back to software GateKeeper");
|
|
|
|
soft_device.reset(new SoftGateKeeperDevice());
|
|
|
|
}
|
2015-04-04 01:40:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~GateKeeperProxy() {
|
|
|
|
}
|
|
|
|
|
2015-04-16 22:16:24 +02:00
|
|
|
void store_sid(uint32_t uid, uint64_t sid) {
|
|
|
|
char filename[21];
|
2016-03-02 23:02:55 +01:00
|
|
|
snprintf(filename, sizeof(filename), "%u", uid);
|
2015-04-16 22:16:24 +02:00
|
|
|
int fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR);
|
|
|
|
if (fd < 0) {
|
2015-04-17 18:00:28 +02:00
|
|
|
ALOGE("could not open file: %s: %s", filename, strerror(errno));
|
2015-04-16 22:16:24 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
write(fd, &sid, sizeof(sid));
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
2017-04-12 22:03:04 +02:00
|
|
|
void clear_state_if_needed() {
|
|
|
|
if (clear_state_if_needed_done) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mark_cold_boot()) {
|
|
|
|
ALOGI("cold boot: clearing state");
|
|
|
|
if (hw_device != nullptr) {
|
|
|
|
hw_device->deleteAllUsers([](const GatekeeperResponse &){});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
clear_state_if_needed_done = true;
|
|
|
|
}
|
|
|
|
|
2015-06-24 19:21:16 +02:00
|
|
|
bool mark_cold_boot() {
|
|
|
|
const char *filename = ".coldboot";
|
|
|
|
if (access(filename, F_OK) == -1) {
|
|
|
|
int fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR);
|
|
|
|
if (fd < 0) {
|
|
|
|
ALOGE("could not open file: %s : %s", filename, strerror(errno));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-16 22:16:24 +02:00
|
|
|
void maybe_store_sid(uint32_t uid, uint64_t sid) {
|
|
|
|
char filename[21];
|
2016-03-02 23:02:55 +01:00
|
|
|
snprintf(filename, sizeof(filename), "%u", uid);
|
2015-04-16 22:16:24 +02:00
|
|
|
if (access(filename, F_OK) == -1) {
|
|
|
|
store_sid(uid, sid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t read_sid(uint32_t uid) {
|
|
|
|
char filename[21];
|
|
|
|
uint64_t sid;
|
2016-03-02 23:02:55 +01:00
|
|
|
snprintf(filename, sizeof(filename), "%u", uid);
|
2015-04-16 22:16:24 +02:00
|
|
|
int fd = open(filename, O_RDONLY);
|
|
|
|
if (fd < 0) return 0;
|
|
|
|
read(fd, &sid, sizeof(sid));
|
2015-07-10 18:47:09 +02:00
|
|
|
close(fd);
|
2015-04-16 22:16:24 +02:00
|
|
|
return sid;
|
|
|
|
}
|
|
|
|
|
2015-04-17 18:00:28 +02:00
|
|
|
void clear_sid(uint32_t uid) {
|
|
|
|
char filename[21];
|
2016-03-02 23:02:55 +01:00
|
|
|
snprintf(filename, sizeof(filename), "%u", uid);
|
2015-04-17 18:00:28 +02:00
|
|
|
if (remove(filename) < 0) {
|
|
|
|
ALOGE("%s: could not remove file [%s], attempting 0 write", __func__, strerror(errno));
|
|
|
|
store_sid(uid, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-18 18:26:19 +02:00
|
|
|
virtual int enroll(uint32_t uid,
|
2015-04-04 01:40:15 +02:00
|
|
|
const uint8_t *current_password_handle, uint32_t current_password_handle_length,
|
|
|
|
const uint8_t *current_password, uint32_t current_password_length,
|
|
|
|
const uint8_t *desired_password, uint32_t desired_password_length,
|
|
|
|
uint8_t **enrolled_password_handle, uint32_t *enrolled_password_handle_length) {
|
|
|
|
IPCThreadState* ipc = IPCThreadState::self();
|
|
|
|
const int calling_pid = ipc->getCallingPid();
|
|
|
|
const int calling_uid = ipc->getCallingUid();
|
|
|
|
if (!PermissionCache::checkPermission(KEYGUARD_PERMISSION, calling_pid, calling_uid)) {
|
|
|
|
return PERMISSION_DENIED;
|
|
|
|
}
|
|
|
|
|
2017-04-12 22:03:04 +02:00
|
|
|
// Make sure to clear any state from before factory reset as soon as a credential is
|
|
|
|
// enrolled (which may happen during device setup).
|
|
|
|
clear_state_if_needed();
|
|
|
|
|
2015-04-04 01:40:15 +02:00
|
|
|
// need a desired password to enroll
|
|
|
|
if (desired_password_length == 0) return -EINVAL;
|
2015-05-13 00:37:20 +02:00
|
|
|
|
|
|
|
int ret;
|
2016-10-18 22:59:26 +02:00
|
|
|
if (hw_device != nullptr) {
|
2015-06-04 00:06:24 +02:00
|
|
|
const gatekeeper::password_handle_t *handle =
|
|
|
|
reinterpret_cast<const gatekeeper::password_handle_t *>(current_password_handle);
|
|
|
|
|
2015-06-25 03:40:24 +02:00
|
|
|
if (handle != NULL && handle->version != 0 && !handle->hardware_backed) {
|
2015-06-04 00:06:24 +02:00
|
|
|
// handle is being re-enrolled from a software version. HAL probably won't accept
|
|
|
|
// the handle as valid, so we nullify it and enroll from scratch
|
|
|
|
current_password_handle = NULL;
|
|
|
|
current_password_handle_length = 0;
|
|
|
|
current_password = NULL;
|
|
|
|
current_password_length = 0;
|
|
|
|
}
|
|
|
|
|
2016-10-18 22:59:26 +02:00
|
|
|
android::hardware::hidl_vec<uint8_t> curPwdHandle;
|
|
|
|
curPwdHandle.setToExternal(const_cast<uint8_t*>(current_password_handle),
|
|
|
|
current_password_handle_length);
|
|
|
|
android::hardware::hidl_vec<uint8_t> curPwd;
|
|
|
|
curPwd.setToExternal(const_cast<uint8_t*>(current_password),
|
|
|
|
current_password_length);
|
|
|
|
android::hardware::hidl_vec<uint8_t> newPwd;
|
|
|
|
newPwd.setToExternal(const_cast<uint8_t*>(desired_password),
|
|
|
|
desired_password_length);
|
|
|
|
|
|
|
|
Return<void> hwRes = hw_device->enroll(uid, curPwdHandle, curPwd, newPwd,
|
|
|
|
[&ret, enrolled_password_handle, enrolled_password_handle_length]
|
|
|
|
(const GatekeeperResponse &rsp) {
|
|
|
|
ret = static_cast<int>(rsp.code); // propagate errors
|
|
|
|
if (rsp.code >= GatekeeperStatusCode::STATUS_OK) {
|
|
|
|
if (enrolled_password_handle != nullptr &&
|
|
|
|
enrolled_password_handle_length != nullptr) {
|
|
|
|
*enrolled_password_handle = new uint8_t[rsp.data.size()];
|
|
|
|
*enrolled_password_handle_length = rsp.data.size();
|
|
|
|
memcpy(*enrolled_password_handle, rsp.data.data(),
|
|
|
|
*enrolled_password_handle_length);
|
|
|
|
}
|
|
|
|
ret = 0; // all success states are reported as 0
|
|
|
|
} else if (rsp.code == GatekeeperStatusCode::ERROR_RETRY_TIMEOUT && rsp.timeout > 0) {
|
|
|
|
ret = rsp.timeout;
|
|
|
|
}
|
|
|
|
});
|
2017-01-04 02:01:27 +01:00
|
|
|
if (!hwRes.isOk()) {
|
2016-10-18 22:59:26 +02:00
|
|
|
ALOGE("enroll transaction failed\n");
|
|
|
|
ret = -1;
|
|
|
|
}
|
2015-05-13 00:37:20 +02:00
|
|
|
} else {
|
|
|
|
ret = soft_device->enroll(uid,
|
|
|
|
current_password_handle, current_password_handle_length,
|
|
|
|
current_password, current_password_length,
|
|
|
|
desired_password, desired_password_length,
|
|
|
|
enrolled_password_handle, enrolled_password_handle_length);
|
|
|
|
}
|
|
|
|
|
2016-09-08 03:51:28 +02:00
|
|
|
if (ret == GATEKEEPER_RESPONSE_OK && (*enrolled_password_handle == nullptr ||
|
|
|
|
*enrolled_password_handle_length != sizeof(password_handle_t))) {
|
|
|
|
ret = GATEKEEPER_RESPONSE_ERROR;
|
|
|
|
ALOGE("HAL: password_handle=%p size_of_handle=%" PRIu32 "\n",
|
|
|
|
*enrolled_password_handle, *enrolled_password_handle_length);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == GATEKEEPER_RESPONSE_OK) {
|
2015-04-16 22:16:24 +02:00
|
|
|
gatekeeper::password_handle_t *handle =
|
|
|
|
reinterpret_cast<gatekeeper::password_handle_t *>(*enrolled_password_handle);
|
|
|
|
store_sid(uid, handle->user_id);
|
2015-06-02 02:23:04 +02:00
|
|
|
bool rr;
|
|
|
|
|
|
|
|
// immediately verify this password so we don't ask the user to enter it again
|
|
|
|
// if they just created it.
|
|
|
|
verify(uid, *enrolled_password_handle, sizeof(password_handle_t), desired_password,
|
|
|
|
desired_password_length, &rr);
|
2015-04-16 22:16:24 +02:00
|
|
|
}
|
2015-05-18 18:26:19 +02:00
|
|
|
|
|
|
|
return ret;
|
2015-04-04 01:40:15 +02:00
|
|
|
}
|
|
|
|
|
2015-05-18 18:26:19 +02:00
|
|
|
virtual int verify(uint32_t uid,
|
2015-04-04 01:40:15 +02:00
|
|
|
const uint8_t *enrolled_password_handle, uint32_t enrolled_password_handle_length,
|
2015-05-18 18:26:19 +02:00
|
|
|
const uint8_t *provided_password, uint32_t provided_password_length, bool *request_reenroll) {
|
2015-04-11 06:03:07 +02:00
|
|
|
uint8_t *auth_token;
|
|
|
|
uint32_t auth_token_length;
|
|
|
|
return verifyChallenge(uid, 0, enrolled_password_handle, enrolled_password_handle_length,
|
|
|
|
provided_password, provided_password_length,
|
2015-05-18 18:26:19 +02:00
|
|
|
&auth_token, &auth_token_length, request_reenroll);
|
2015-04-11 06:03:07 +02:00
|
|
|
}
|
|
|
|
|
2015-05-18 18:26:19 +02:00
|
|
|
virtual int verifyChallenge(uint32_t uid, uint64_t challenge,
|
2015-04-11 06:03:07 +02:00
|
|
|
const uint8_t *enrolled_password_handle, uint32_t enrolled_password_handle_length,
|
|
|
|
const uint8_t *provided_password, uint32_t provided_password_length,
|
2015-05-18 18:26:19 +02:00
|
|
|
uint8_t **auth_token, uint32_t *auth_token_length, bool *request_reenroll) {
|
2015-04-04 01:40:15 +02:00
|
|
|
IPCThreadState* ipc = IPCThreadState::self();
|
|
|
|
const int calling_pid = ipc->getCallingPid();
|
|
|
|
const int calling_uid = ipc->getCallingUid();
|
|
|
|
if (!PermissionCache::checkPermission(KEYGUARD_PERMISSION, calling_pid, calling_uid)) {
|
|
|
|
return PERMISSION_DENIED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// can't verify if we're missing either param
|
|
|
|
if ((enrolled_password_handle_length | provided_password_length) == 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2015-05-13 00:37:20 +02:00
|
|
|
int ret;
|
2016-10-18 22:59:26 +02:00
|
|
|
if (hw_device != nullptr) {
|
2015-06-04 00:06:24 +02:00
|
|
|
const gatekeeper::password_handle_t *handle =
|
|
|
|
reinterpret_cast<const gatekeeper::password_handle_t *>(enrolled_password_handle);
|
2015-06-25 03:40:24 +02:00
|
|
|
// handle version 0 does not have hardware backed flag, and thus cannot be upgraded to
|
|
|
|
// a HAL if there was none before
|
|
|
|
if (handle->version == 0 || handle->hardware_backed) {
|
2016-10-18 22:59:26 +02:00
|
|
|
android::hardware::hidl_vec<uint8_t> curPwdHandle;
|
|
|
|
curPwdHandle.setToExternal(const_cast<uint8_t*>(enrolled_password_handle),
|
|
|
|
enrolled_password_handle_length);
|
|
|
|
android::hardware::hidl_vec<uint8_t> enteredPwd;
|
|
|
|
enteredPwd.setToExternal(const_cast<uint8_t*>(provided_password),
|
|
|
|
provided_password_length);
|
|
|
|
Return<void> hwRes = hw_device->verify(uid, challenge, curPwdHandle, enteredPwd,
|
|
|
|
[&ret, request_reenroll, auth_token, auth_token_length]
|
|
|
|
(const GatekeeperResponse &rsp) {
|
|
|
|
ret = static_cast<int>(rsp.code); // propagate errors
|
|
|
|
if (auth_token != nullptr && auth_token_length != nullptr &&
|
|
|
|
rsp.code >= GatekeeperStatusCode::STATUS_OK) {
|
|
|
|
*auth_token = new uint8_t[rsp.data.size()];
|
|
|
|
*auth_token_length = rsp.data.size();
|
|
|
|
memcpy(*auth_token, rsp.data.data(), *auth_token_length);
|
|
|
|
if (request_reenroll != nullptr) {
|
|
|
|
*request_reenroll = (rsp.code == GatekeeperStatusCode::STATUS_REENROLL);
|
|
|
|
}
|
|
|
|
ret = 0; // all success states are reported as 0
|
|
|
|
} else if (rsp.code == GatekeeperStatusCode::ERROR_RETRY_TIMEOUT &&
|
|
|
|
rsp.timeout > 0) {
|
|
|
|
ret = rsp.timeout;
|
|
|
|
}
|
|
|
|
});
|
2017-01-04 02:01:27 +01:00
|
|
|
if (!hwRes.isOk()) {
|
2016-10-18 22:59:26 +02:00
|
|
|
ALOGE("verify transaction failed\n");
|
|
|
|
ret = -1;
|
|
|
|
}
|
2015-06-04 00:06:24 +02:00
|
|
|
} else {
|
|
|
|
// upgrade scenario, a HAL has been added to this device where there was none before
|
|
|
|
SoftGateKeeperDevice soft_dev;
|
|
|
|
ret = soft_dev.verify(uid, challenge,
|
|
|
|
enrolled_password_handle, enrolled_password_handle_length,
|
|
|
|
provided_password, provided_password_length, auth_token, auth_token_length,
|
|
|
|
request_reenroll);
|
|
|
|
|
|
|
|
if (ret == 0) {
|
|
|
|
// success! re-enroll with HAL
|
|
|
|
*request_reenroll = true;
|
|
|
|
}
|
|
|
|
}
|
2015-05-13 00:37:20 +02:00
|
|
|
} else {
|
|
|
|
ret = soft_device->verify(uid, challenge,
|
|
|
|
enrolled_password_handle, enrolled_password_handle_length,
|
2015-05-18 18:26:19 +02:00
|
|
|
provided_password, provided_password_length, auth_token, auth_token_length,
|
|
|
|
request_reenroll);
|
2015-05-13 00:37:20 +02:00
|
|
|
}
|
2015-04-04 01:40:15 +02:00
|
|
|
|
2015-05-18 18:26:19 +02:00
|
|
|
if (ret == 0 && *auth_token != NULL && *auth_token_length > 0) {
|
2015-04-04 01:40:15 +02:00
|
|
|
// TODO: cache service?
|
|
|
|
sp<IServiceManager> sm = defaultServiceManager();
|
|
|
|
sp<IBinder> binder = sm->getService(String16("android.security.keystore"));
|
2017-11-14 21:53:39 +01:00
|
|
|
sp<security::IKeystoreService> service =
|
|
|
|
interface_cast<security::IKeystoreService>(binder);
|
2015-04-04 01:40:15 +02:00
|
|
|
if (service != NULL) {
|
2017-11-14 21:53:39 +01:00
|
|
|
std::vector<uint8_t> auth_token_vector(*auth_token,
|
|
|
|
(*auth_token) + *auth_token_length);
|
|
|
|
int result = 0;
|
2018-01-30 00:55:16 +01:00
|
|
|
auto binder_result = service->addAuthToken(auth_token_vector, &result);
|
2017-11-14 21:53:39 +01:00
|
|
|
if (!binder_result.isOk() || !keystore::KeyStoreServiceReturnCode(result).isOk()) {
|
|
|
|
ALOGE("Failure sending auth token to KeyStore: %" PRId32, result);
|
2015-04-04 01:40:15 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ALOGE("Unable to communicate with KeyStore");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-18 18:26:19 +02:00
|
|
|
if (ret == 0) {
|
2015-04-16 22:16:24 +02:00
|
|
|
maybe_store_sid(uid, reinterpret_cast<const gatekeeper::password_handle_t *>(
|
|
|
|
enrolled_password_handle)->user_id);
|
|
|
|
}
|
|
|
|
|
2015-05-18 18:26:19 +02:00
|
|
|
return ret;
|
2015-04-16 22:16:24 +02:00
|
|
|
}
|
|
|
|
|
2017-06-28 20:03:58 +02:00
|
|
|
virtual uint64_t getSecureUserId(uint32_t uid) { return read_sid(uid); }
|
2015-04-04 01:40:15 +02:00
|
|
|
|
2015-04-17 00:57:17 +02:00
|
|
|
virtual void clearSecureUserId(uint32_t uid) {
|
|
|
|
IPCThreadState* ipc = IPCThreadState::self();
|
|
|
|
const int calling_pid = ipc->getCallingPid();
|
|
|
|
const int calling_uid = ipc->getCallingUid();
|
|
|
|
if (!PermissionCache::checkPermission(KEYGUARD_PERMISSION, calling_pid, calling_uid)) {
|
|
|
|
ALOGE("%s: permission denied for [%d:%d]", __func__, calling_pid, calling_uid);
|
|
|
|
return;
|
|
|
|
}
|
2015-04-17 18:00:28 +02:00
|
|
|
clear_sid(uid);
|
2015-06-24 19:21:16 +02:00
|
|
|
|
2016-10-18 22:59:26 +02:00
|
|
|
if (hw_device != nullptr) {
|
|
|
|
hw_device->deleteUser(uid, [] (const GatekeeperResponse &){});
|
2015-06-24 19:21:16 +02:00
|
|
|
}
|
2015-04-17 00:57:17 +02:00
|
|
|
}
|
|
|
|
|
2017-04-12 22:03:04 +02:00
|
|
|
virtual void reportDeviceSetupComplete() {
|
|
|
|
IPCThreadState* ipc = IPCThreadState::self();
|
|
|
|
const int calling_pid = ipc->getCallingPid();
|
|
|
|
const int calling_uid = ipc->getCallingUid();
|
|
|
|
if (!PermissionCache::checkPermission(KEYGUARD_PERMISSION, calling_pid, calling_uid)) {
|
|
|
|
ALOGE("%s: permission denied for [%d:%d]", __func__, calling_pid, calling_uid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
clear_state_if_needed();
|
|
|
|
}
|
|
|
|
|
2015-04-04 01:40:15 +02:00
|
|
|
virtual status_t dump(int fd, const Vector<String16> &) {
|
|
|
|
IPCThreadState* ipc = IPCThreadState::self();
|
|
|
|
const int pid = ipc->getCallingPid();
|
|
|
|
const int uid = ipc->getCallingUid();
|
|
|
|
if (!PermissionCache::checkPermission(DUMP_PERMISSION, pid, uid)) {
|
|
|
|
return PERMISSION_DENIED;
|
|
|
|
}
|
|
|
|
|
2016-10-18 22:59:26 +02:00
|
|
|
if (hw_device == NULL) {
|
2015-04-04 01:40:15 +02:00
|
|
|
const char *result = "Device not available";
|
|
|
|
write(fd, result, strlen(result) + 1);
|
|
|
|
} else {
|
|
|
|
const char *result = "OK";
|
|
|
|
write(fd, result, strlen(result) + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-10-18 22:59:26 +02:00
|
|
|
sp<IGatekeeper> hw_device;
|
2017-08-16 11:54:20 +02:00
|
|
|
std::unique_ptr<SoftGateKeeperDevice> soft_device;
|
2017-04-12 22:03:04 +02:00
|
|
|
|
|
|
|
bool clear_state_if_needed_done;
|
2015-04-04 01:40:15 +02:00
|
|
|
};
|
|
|
|
}// namespace android
|
|
|
|
|
2015-04-16 22:16:24 +02:00
|
|
|
int main(int argc, char* argv[]) {
|
2015-04-04 01:40:15 +02:00
|
|
|
ALOGI("Starting gatekeeperd...");
|
2015-04-16 22:16:24 +02:00
|
|
|
if (argc < 2) {
|
|
|
|
ALOGE("A directory must be specified!");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (chdir(argv[1]) == -1) {
|
|
|
|
ALOGE("chdir: %s: %s", argv[1], strerror(errno));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-04-04 01:40:15 +02:00
|
|
|
android::sp<android::IServiceManager> sm = android::defaultServiceManager();
|
|
|
|
android::sp<android::GateKeeperProxy> proxy = new android::GateKeeperProxy();
|
|
|
|
android::status_t ret = sm->addService(
|
|
|
|
android::String16("android.service.gatekeeper.IGateKeeperService"), proxy);
|
|
|
|
if (ret != android::OK) {
|
|
|
|
ALOGE("Couldn't register binder service!");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We're the only thread in existence, so we're just going to process
|
|
|
|
* Binder transaction as a single-threaded program.
|
|
|
|
*/
|
|
|
|
android::IPCThreadState::self()->joinThreadPool();
|
|
|
|
return 0;
|
|
|
|
}
|