107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root/* 207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root** 307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root** Copyright 2008, The Android Open Source Project 407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root** 507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root** Licensed under the Apache License, Version 2.0 (the "License"); 607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root** you may not use this file except in compliance with the License. 707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root** You may obtain a copy of the License at 807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root** 907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root** http://www.apache.org/licenses/LICENSE-2.0 1007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root** 1107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root** Unless required by applicable law or agreed to in writing, software 1207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root** distributed under the License is distributed on an "AS IS" BASIS, 1307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root** See the License for the specific language governing permissions and 1507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root** limitations under the License. 1607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root*/ 1707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 1807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root#include <stdint.h> 1907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root#include <sys/types.h> 2007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 2107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root#define LOG_TAG "KeystoreService" 2207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root#include <utils/Log.h> 2307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 2407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root#include <binder/Parcel.h> 2507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root#include <binder/IPCThreadState.h> 2607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root#include <binder/IServiceManager.h> 2707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 2807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root#include <keystore/IKeystoreService.h> 2907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 3007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Rootnamespace android { 3107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 3296427baf0094d50047049d329b0779c3c910402cKenny RootKeystoreArg::KeystoreArg(const void* data, size_t len) 3396427baf0094d50047049d329b0779c3c910402cKenny Root : mData(data), mSize(len) { 3496427baf0094d50047049d329b0779c3c910402cKenny Root} 3596427baf0094d50047049d329b0779c3c910402cKenny Root 3696427baf0094d50047049d329b0779c3c910402cKenny RootKeystoreArg::~KeystoreArg() { 3796427baf0094d50047049d329b0779c3c910402cKenny Root} 3896427baf0094d50047049d329b0779c3c910402cKenny Root 3996427baf0094d50047049d329b0779c3c910402cKenny Rootconst void *KeystoreArg::data() const { 4096427baf0094d50047049d329b0779c3c910402cKenny Root return mData; 4196427baf0094d50047049d329b0779c3c910402cKenny Root} 4296427baf0094d50047049d329b0779c3c910402cKenny Root 4396427baf0094d50047049d329b0779c3c910402cKenny Rootsize_t KeystoreArg::size() const { 4496427baf0094d50047049d329b0779c3c910402cKenny Root return mSize; 4596427baf0094d50047049d329b0779c3c910402cKenny Root} 4696427baf0094d50047049d329b0779c3c910402cKenny Root 4707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Rootclass BpKeystoreService: public BpInterface<IKeystoreService> 4807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root{ 4907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Rootpublic: 5007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root BpKeystoreService(const sp<IBinder>& impl) 5107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root : BpInterface<IKeystoreService>(impl) 5207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 5307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 5407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 5507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root // test ping 5607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t test() 5707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 5807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 5907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 6007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::TEST, data, &reply); 6107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 6207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("test() could not contact remote: %d\n", status); 6307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 6407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 6507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 6607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 6707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 6807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("test() caught exception %d\n", err); 6907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 7007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 7107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 7207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 7307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 7407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t get(const String16& name, uint8_t** item, size_t* itemLength) 7507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 7607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 7707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 7807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 7907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::GET, data, &reply); 8007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 8107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("get() could not contact remote: %d\n", status); 8207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 8307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 8407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 8507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ssize_t len = reply.readInt32(); 8607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (len >= 0 && (size_t) len <= reply.dataAvail()) { 8707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root size_t ulen = (size_t) len; 8807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root const void* buf = reply.readInplace(ulen); 8907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *item = (uint8_t*) malloc(ulen); 9007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (*item != NULL) { 9107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root memcpy(*item, buf, ulen); 9207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *itemLength = ulen; 9307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 9407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGE("out of memory allocating output array in get"); 9507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *itemLength = 0; 9607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 9707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 9807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *itemLength = 0; 9907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 10007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 10107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("get() caught exception %d\n", err); 10207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 10307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 10407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return 0; 10507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 10607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 1070c540aad5915e6aa34345049be96f28b64d0e84cKenny Root virtual int32_t insert(const String16& name, const uint8_t* item, size_t itemLength, int uid, 1080c540aad5915e6aa34345049be96f28b64d0e84cKenny Root int32_t flags) 10907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 11007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 11107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 11207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 11307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInt32(itemLength); 11407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root void* buf = data.writeInplace(itemLength); 11507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root memcpy(buf, item, itemLength); 116b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root data.writeInt32(uid); 1170c540aad5915e6aa34345049be96f28b64d0e84cKenny Root data.writeInt32(flags); 11807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::INSERT, data, &reply); 11907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 12007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("import() could not contact remote: %d\n", status); 12107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 12207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 12307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 12407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 12507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 12607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("import() caught exception %d\n", err); 12707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 12807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 12907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 13007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 13107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 132b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root virtual int32_t del(const String16& name, int uid) 13307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 13407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 13507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 13607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 137b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root data.writeInt32(uid); 13807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::DEL, data, &reply); 13907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 14007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("del() could not contact remote: %d\n", status); 14107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 14207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 14307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 14407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 14507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 14607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("del() caught exception %d\n", err); 14707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 14807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 14907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 15007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 15107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 152b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root virtual int32_t exist(const String16& name, int uid) 15307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 15407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 15507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 15607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 157b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root data.writeInt32(uid); 15807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::EXIST, data, &reply); 15907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 16007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("exist() could not contact remote: %d\n", status); 16107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 16207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 16307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 16407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 16507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 16607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("exist() caught exception %d\n", err); 16707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 16807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 16907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 17007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 17107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 172b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root virtual int32_t saw(const String16& name, int uid, Vector<String16>* matches) 17307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 17407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 17507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 17607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 177b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root data.writeInt32(uid); 17807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::SAW, data, &reply); 17907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 18007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("saw() could not contact remote: %d\n", status); 18107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 18207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 18307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 18407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t numMatches = reply.readInt32(); 18507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root for (int32_t i = 0; i < numMatches; i++) { 18607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root matches->push(reply.readString16()); 18707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 18807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 18907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 19007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("saw() caught exception %d\n", err); 19107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 19207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 19307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 19407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 19507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 19607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t reset() 19707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 19807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 19907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 20007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::RESET, data, &reply); 20107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 20207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("reset() could not contact remote: %d\n", status); 20307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 20407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 20507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 20607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 20707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 20807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("reset() caught exception %d\n", err); 20907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 21007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 21107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 21207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 21307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 21407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t password(const String16& password) 21507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 21607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 21707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 21807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(password); 21907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::PASSWORD, data, &reply); 22007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 22107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("password() could not contact remote: %d\n", status); 22207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 22307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 22407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 22507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 22607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 22707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("password() caught exception %d\n", err); 22807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 22907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 23007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 23107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 23207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 23307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t lock() 23407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 23507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 23607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 23707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::LOCK, data, &reply); 23807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 23907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("lock() could not contact remote: %d\n", status); 24007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 24107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 24207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 24307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 24407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 24507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("lock() caught exception %d\n", err); 24607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 24707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 24807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 24907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 25007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 25107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t unlock(const String16& password) 25207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 25307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 25407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 25507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(password); 25607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::UNLOCK, data, &reply); 25707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 25807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("unlock() could not contact remote: %d\n", status); 25907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 26007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 26107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 26207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 26307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 26407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("unlock() caught exception %d\n", err); 26507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 26607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 26707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 26807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 26907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 27007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t zero() 27107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 27207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 27307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 27407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::ZERO, data, &reply); 27507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 27607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("zero() could not contact remote: %d\n", status); 27707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 27807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 27907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 28007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 28107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 28207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("zero() caught exception %d\n", err); 28307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 28407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 28507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 28607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 28707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 28896427baf0094d50047049d329b0779c3c910402cKenny Root virtual int32_t generate(const String16& name, int32_t uid, int32_t keyType, int32_t keySize, 28996427baf0094d50047049d329b0779c3c910402cKenny Root int32_t flags, Vector<sp<KeystoreArg> >* args) 29007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 29107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 29207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 29307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 294b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root data.writeInt32(uid); 29596427baf0094d50047049d329b0779c3c910402cKenny Root data.writeInt32(keyType); 29696427baf0094d50047049d329b0779c3c910402cKenny Root data.writeInt32(keySize); 2970c540aad5915e6aa34345049be96f28b64d0e84cKenny Root data.writeInt32(flags); 29896427baf0094d50047049d329b0779c3c910402cKenny Root data.writeInt32(args->size()); 29996427baf0094d50047049d329b0779c3c910402cKenny Root for (Vector<sp<KeystoreArg> >::iterator it = args->begin(); it != args->end(); ++it) { 30096427baf0094d50047049d329b0779c3c910402cKenny Root sp<KeystoreArg> item = *it; 30196427baf0094d50047049d329b0779c3c910402cKenny Root size_t keyLength = item->size(); 30296427baf0094d50047049d329b0779c3c910402cKenny Root data.writeInt32(keyLength); 30396427baf0094d50047049d329b0779c3c910402cKenny Root void* buf = data.writeInplace(keyLength); 30496427baf0094d50047049d329b0779c3c910402cKenny Root memcpy(buf, item->data(), keyLength); 30596427baf0094d50047049d329b0779c3c910402cKenny Root } 30607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::GENERATE, data, &reply); 30707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 30807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("generate() could not contact remote: %d\n", status); 30907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 31007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 31107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 31207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 31307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 31407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("generate() caught exception %d\n", err); 31507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 31607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 31707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 31807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 31907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 3200c540aad5915e6aa34345049be96f28b64d0e84cKenny Root virtual int32_t import(const String16& name, const uint8_t* key, size_t keyLength, int uid, 3210c540aad5915e6aa34345049be96f28b64d0e84cKenny Root int flags) 32207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 32307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 32407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 32507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 32607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInt32(keyLength); 32707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root void* buf = data.writeInplace(keyLength); 32807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root memcpy(buf, key, keyLength); 329b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root data.writeInt32(uid); 3300c540aad5915e6aa34345049be96f28b64d0e84cKenny Root data.writeInt32(flags); 33107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::IMPORT, data, &reply); 33207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 33307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("import() could not contact remote: %d\n", status); 33407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 33507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 33607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 33707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 33807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 33907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("import() caught exception %d\n", err); 34007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 34107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 34207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 34307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 34407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 34507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t sign(const String16& name, const uint8_t* in, size_t inLength, uint8_t** out, 34607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root size_t* outLength) 34707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 34807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 34907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 35007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 35107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInt32(inLength); 35207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root void* buf = data.writeInplace(inLength); 35307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root memcpy(buf, in, inLength); 35407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::SIGN, data, &reply); 35507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 35607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("import() could not contact remote: %d\n", status); 35707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 35807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 35907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 36007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ssize_t len = reply.readInt32(); 36107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (len >= 0 && (size_t) len <= reply.dataAvail()) { 36207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root size_t ulen = (size_t) len; 36307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root const void* outBuf = reply.readInplace(ulen); 36407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *out = (uint8_t*) malloc(ulen); 36507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (*out != NULL) { 36607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root memcpy((void*) *out, outBuf, ulen); 36707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *outLength = ulen; 36807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 36907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGE("out of memory allocating output array in sign"); 37007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *outLength = 0; 37107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 37207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 37307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *outLength = 0; 37407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 37507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 37607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("import() caught exception %d\n", err); 37707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 37807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 37907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return 0; 38007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 38107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 38207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t verify(const String16& name, const uint8_t* in, size_t inLength, 38307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root const uint8_t* signature, size_t signatureLength) 38407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 38507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 38607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root void* buf; 38707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 38807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 38907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 39007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInt32(inLength); 39107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root buf = data.writeInplace(inLength); 39207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root memcpy(buf, in, inLength); 39307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInt32(signatureLength); 39407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root buf = data.writeInplace(signatureLength); 39507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root memcpy(buf, signature, signatureLength); 39607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::VERIFY, data, &reply); 39707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 39807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("verify() could not contact remote: %d\n", status); 39907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 40007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 40107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 40207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 40307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 40407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("verify() caught exception %d\n", err); 40507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 40607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 40707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 40807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 40907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 41007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t get_pubkey(const String16& name, uint8_t** pubkey, size_t* pubkeyLength) 41107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 41207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 41307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 41407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 41507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::GET_PUBKEY, data, &reply); 41607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 41707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("get_pubkey() could not contact remote: %d\n", status); 41807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 41907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 42007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 42107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ssize_t len = reply.readInt32(); 42207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (len >= 0 && (size_t) len <= reply.dataAvail()) { 42307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root size_t ulen = (size_t) len; 42407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root const void* buf = reply.readInplace(ulen); 42507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *pubkey = (uint8_t*) malloc(ulen); 42607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (*pubkey != NULL) { 42707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root memcpy(*pubkey, buf, ulen); 42807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *pubkeyLength = ulen; 42907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 43007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGE("out of memory allocating output array in get_pubkey"); 43107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *pubkeyLength = 0; 43207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 43307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 43407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *pubkeyLength = 0; 43507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 43607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 43707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("get_pubkey() caught exception %d\n", err); 43807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 43907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 44007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return 0; 44107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 44207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 443b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root virtual int32_t del_key(const String16& name, int uid) 44407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 44507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 44607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 44707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 448b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root data.writeInt32(uid); 44907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::DEL_KEY, data, &reply); 45007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 45107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("del_key() could not contact remote: %d\n", status); 45207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 45307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 45407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 45507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 45607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 45707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("del_key() caught exception %d\n", err); 45807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 45907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 46007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 46107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 46207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 46307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t grant(const String16& name, int32_t granteeUid) 46407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 46507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 46607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 46707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 46807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInt32(granteeUid); 46907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::GRANT, data, &reply); 47007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 47107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("grant() could not contact remote: %d\n", status); 47207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 47307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 47407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 47507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 47607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 47707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("grant() caught exception %d\n", err); 47807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 47907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 48007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 48107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 48207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 48307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t ungrant(const String16& name, int32_t granteeUid) 48407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 48507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 48607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 48707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 48807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInt32(granteeUid); 48907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::UNGRANT, data, &reply); 49007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 49107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("ungrant() could not contact remote: %d\n", status); 49207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 49307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 49407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 49507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 49607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 49707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("ungrant() caught exception %d\n", err); 49807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 49907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 50007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 50107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 50207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 50307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int64_t getmtime(const String16& name) 50407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 50507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 50607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 50707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 50807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::GETMTIME, data, &reply); 50907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 51007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("getmtime() could not contact remote: %d\n", status); 51107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 51207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 51307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 51407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int64_t ret = reply.readInt64(); 51507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 51607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("getmtime() caught exception %d\n", err); 51707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 51807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 51907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 52007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 5210225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root 522d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root virtual int32_t duplicate(const String16& srcKey, int32_t srcUid, const String16& destKey, 523d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root int32_t destUid) 5240225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root { 5250225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root Parcel data, reply; 5260225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 527d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root data.writeString16(srcKey); 528d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root data.writeInt32(srcUid); 529d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root data.writeString16(destKey); 530d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root data.writeInt32(destUid); 531d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root status_t status = remote()->transact(BnKeystoreService::DUPLICATE, data, &reply); 5320225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root if (status != NO_ERROR) { 533d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root ALOGD("duplicate() could not contact remote: %d\n", status); 5340225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root return -1; 5350225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root } 5360225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root int32_t err = reply.readExceptionCode(); 5370225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root int32_t ret = reply.readInt32(); 5380225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root if (err < 0) { 539d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root ALOGD("duplicate() caught exception %d\n", err); 5400225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root return -1; 5410225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root } 5420225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root return ret; 5430225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root } 5444306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root 5451b0e3933900c7ea21189704d5db64e7346aee7afKenny Root virtual int32_t is_hardware_backed(const String16& keyType) 5464306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root { 5474306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root Parcel data, reply; 5484306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 5491b0e3933900c7ea21189704d5db64e7346aee7afKenny Root data.writeString16(keyType); 5504306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root status_t status = remote()->transact(BnKeystoreService::IS_HARDWARE_BACKED, data, &reply); 5514306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root if (status != NO_ERROR) { 5524306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root ALOGD("is_hardware_backed() could not contact remote: %d\n", status); 5534306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root return -1; 5544306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root } 5554306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root int32_t err = reply.readExceptionCode(); 5564306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root int32_t ret = reply.readInt32(); 5574306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root if (err < 0) { 5584306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root ALOGD("is_hardware_backed() caught exception %d\n", err); 5594306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root return -1; 5604306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root } 5614306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root return ret; 5624306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root } 5632ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root 5642ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root virtual int32_t clear_uid(int64_t uid) 5652ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root { 5662ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root Parcel data, reply; 5672ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 5682ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root data.writeInt64(uid); 5692ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root status_t status = remote()->transact(BnKeystoreService::CLEAR_UID, data, &reply); 5702ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root if (status != NO_ERROR) { 5712ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root ALOGD("clear_uid() could not contact remote: %d\n", status); 5722ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root return -1; 5732ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root } 5742ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root int32_t err = reply.readExceptionCode(); 5752ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root int32_t ret = reply.readInt32(); 5762ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root if (err < 0) { 5772ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root ALOGD("clear_uid() caught exception %d\n", err); 5782ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root return -1; 5792ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root } 5802ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root return ret; 5812ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root } 5824e865753346fc6a075966972a7a98051818859dbRobin Lee 5834e865753346fc6a075966972a7a98051818859dbRobin Lee virtual int32_t reset_uid(int32_t uid) { 5844e865753346fc6a075966972a7a98051818859dbRobin Lee Parcel data, reply; 5854e865753346fc6a075966972a7a98051818859dbRobin Lee data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 5864e865753346fc6a075966972a7a98051818859dbRobin Lee data.writeInt32(uid); 5874e865753346fc6a075966972a7a98051818859dbRobin Lee status_t status = remote()->transact(BnKeystoreService::RESET_UID, data, &reply); 5884e865753346fc6a075966972a7a98051818859dbRobin Lee if (status != NO_ERROR) { 5894e865753346fc6a075966972a7a98051818859dbRobin Lee ALOGD("reset_uid() could not contact remote: %d\n", status); 5904e865753346fc6a075966972a7a98051818859dbRobin Lee return -1; 5914e865753346fc6a075966972a7a98051818859dbRobin Lee } 5924e865753346fc6a075966972a7a98051818859dbRobin Lee int32_t err = reply.readExceptionCode(); 5934e865753346fc6a075966972a7a98051818859dbRobin Lee int32_t ret = reply.readInt32(); 5944e865753346fc6a075966972a7a98051818859dbRobin Lee if (err < 0) { 5954e865753346fc6a075966972a7a98051818859dbRobin Lee ALOGD("reset_uid() caught exception %d\n", err); 5964e865753346fc6a075966972a7a98051818859dbRobin Lee return -1; 5974e865753346fc6a075966972a7a98051818859dbRobin Lee } 5984e865753346fc6a075966972a7a98051818859dbRobin Lee return ret; 5994e865753346fc6a075966972a7a98051818859dbRobin Lee 6004e865753346fc6a075966972a7a98051818859dbRobin Lee } 6014e865753346fc6a075966972a7a98051818859dbRobin Lee 6024e865753346fc6a075966972a7a98051818859dbRobin Lee virtual int32_t sync_uid(int32_t sourceUid, int32_t targetUid) 6034e865753346fc6a075966972a7a98051818859dbRobin Lee { 6044e865753346fc6a075966972a7a98051818859dbRobin Lee Parcel data, reply; 6054e865753346fc6a075966972a7a98051818859dbRobin Lee data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 6064e865753346fc6a075966972a7a98051818859dbRobin Lee data.writeInt32(sourceUid); 6074e865753346fc6a075966972a7a98051818859dbRobin Lee data.writeInt32(targetUid); 6084e865753346fc6a075966972a7a98051818859dbRobin Lee status_t status = remote()->transact(BnKeystoreService::SYNC_UID, data, &reply); 6094e865753346fc6a075966972a7a98051818859dbRobin Lee if (status != NO_ERROR) { 6104e865753346fc6a075966972a7a98051818859dbRobin Lee ALOGD("sync_uid() could not contact remote: %d\n", status); 6114e865753346fc6a075966972a7a98051818859dbRobin Lee return -1; 6124e865753346fc6a075966972a7a98051818859dbRobin Lee } 6134e865753346fc6a075966972a7a98051818859dbRobin Lee int32_t err = reply.readExceptionCode(); 6144e865753346fc6a075966972a7a98051818859dbRobin Lee int32_t ret = reply.readInt32(); 6154e865753346fc6a075966972a7a98051818859dbRobin Lee if (err < 0) { 6164e865753346fc6a075966972a7a98051818859dbRobin Lee ALOGD("sync_uid() caught exception %d\n", err); 6174e865753346fc6a075966972a7a98051818859dbRobin Lee return -1; 6184e865753346fc6a075966972a7a98051818859dbRobin Lee } 6194e865753346fc6a075966972a7a98051818859dbRobin Lee return ret; 6204e865753346fc6a075966972a7a98051818859dbRobin Lee } 6214e865753346fc6a075966972a7a98051818859dbRobin Lee 6224e865753346fc6a075966972a7a98051818859dbRobin Lee virtual int32_t password_uid(const String16& password, int32_t uid) 6234e865753346fc6a075966972a7a98051818859dbRobin Lee { 6244e865753346fc6a075966972a7a98051818859dbRobin Lee Parcel data, reply; 6254e865753346fc6a075966972a7a98051818859dbRobin Lee data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 6264e865753346fc6a075966972a7a98051818859dbRobin Lee data.writeString16(password); 6274e865753346fc6a075966972a7a98051818859dbRobin Lee data.writeInt32(uid); 6284e865753346fc6a075966972a7a98051818859dbRobin Lee status_t status = remote()->transact(BnKeystoreService::PASSWORD_UID, data, &reply); 6294e865753346fc6a075966972a7a98051818859dbRobin Lee if (status != NO_ERROR) { 6304e865753346fc6a075966972a7a98051818859dbRobin Lee ALOGD("password_uid() could not contact remote: %d\n", status); 6314e865753346fc6a075966972a7a98051818859dbRobin Lee return -1; 6324e865753346fc6a075966972a7a98051818859dbRobin Lee } 6334e865753346fc6a075966972a7a98051818859dbRobin Lee int32_t err = reply.readExceptionCode(); 6344e865753346fc6a075966972a7a98051818859dbRobin Lee int32_t ret = reply.readInt32(); 6354e865753346fc6a075966972a7a98051818859dbRobin Lee if (err < 0) { 6364e865753346fc6a075966972a7a98051818859dbRobin Lee ALOGD("password_uid() caught exception %d\n", err); 6374e865753346fc6a075966972a7a98051818859dbRobin Lee return -1; 6384e865753346fc6a075966972a7a98051818859dbRobin Lee } 6394e865753346fc6a075966972a7a98051818859dbRobin Lee return ret; 6404e865753346fc6a075966972a7a98051818859dbRobin Lee } 64107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root}; 64207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 64307438c8d7256d3788dac323b4d0055f201e0bec9Kenny RootIMPLEMENT_META_INTERFACE(KeystoreService, "android.security.keystore"); 64407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 64507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root// ---------------------------------------------------------------------- 64607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 64707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Rootstatus_t BnKeystoreService::onTransact( 64807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 64907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root{ 65007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root switch(code) { 65107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case TEST: { 65207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 65307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = test(); 65407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 65507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 65607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 65707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 65807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case GET: { 65907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 66007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 66107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root void* out = NULL; 66207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root size_t outSize = 0; 66307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = get(name, (uint8_t**) &out, &outSize); 66407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 66507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (ret == 1) { 66607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(outSize); 66707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root void* buf = reply->writeInplace(outSize); 66807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root memcpy(buf, out, outSize); 66907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root free(out); 67007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 67107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(-1); 67207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 67307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 67407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 67507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case INSERT: { 67607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 67707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 67807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ssize_t inSize = data.readInt32(); 67907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root const void* in; 68007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (inSize >= 0 && (size_t) inSize <= data.dataAvail()) { 68107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root in = data.readInplace(inSize); 68207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 68307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root in = NULL; 68407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root inSize = 0; 68507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 686b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int uid = data.readInt32(); 6870c540aad5915e6aa34345049be96f28b64d0e84cKenny Root int32_t flags = data.readInt32(); 6880c540aad5915e6aa34345049be96f28b64d0e84cKenny Root int32_t ret = insert(name, (const uint8_t*) in, (size_t) inSize, uid, flags); 68907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 69007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 69107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 69207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 69307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case DEL: { 69407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 69507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 696b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int uid = data.readInt32(); 697b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int32_t ret = del(name, uid); 69807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 69907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 70007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 70107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 70207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case EXIST: { 70307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 70407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 705b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int uid = data.readInt32(); 706b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int32_t ret = exist(name, uid); 70707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 70807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 70907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 71007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 71107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case SAW: { 71207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 71307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 714b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int uid = data.readInt32(); 71507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Vector<String16> matches; 716b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int32_t ret = saw(name, uid, &matches); 71707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 71807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(matches.size()); 71907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Vector<String16>::const_iterator it = matches.begin(); 72007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root for (; it != matches.end(); ++it) { 72107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeString16(*it); 72207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 72307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 72407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 72507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 72607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case RESET: { 72707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 72807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reset(); 72907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 73007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 73107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 73207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 73307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case PASSWORD: { 73407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 73507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 pass = data.readString16(); 73607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = password(pass); 73707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 73807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 73907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 74007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 74107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case LOCK: { 74207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 74307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = lock(); 74407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 74507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 74607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 74707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 74807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case UNLOCK: { 74907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 75007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 pass = data.readString16(); 75107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = unlock(pass); 75207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 75307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 75407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 75507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 75607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case ZERO: { 75707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 75807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = zero(); 75907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 76007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 76107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 76207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 76307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case GENERATE: { 76407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 76507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 76696427baf0094d50047049d329b0779c3c910402cKenny Root int32_t uid = data.readInt32(); 76796427baf0094d50047049d329b0779c3c910402cKenny Root int32_t keyType = data.readInt32(); 76896427baf0094d50047049d329b0779c3c910402cKenny Root int32_t keySize = data.readInt32(); 7690c540aad5915e6aa34345049be96f28b64d0e84cKenny Root int32_t flags = data.readInt32(); 77096427baf0094d50047049d329b0779c3c910402cKenny Root Vector<sp<KeystoreArg> > args; 77196427baf0094d50047049d329b0779c3c910402cKenny Root ssize_t numArgs = data.readInt32(); 77296427baf0094d50047049d329b0779c3c910402cKenny Root if (numArgs > 0) { 77396427baf0094d50047049d329b0779c3c910402cKenny Root for (size_t i = 0; i < (size_t) numArgs; i++) { 77496427baf0094d50047049d329b0779c3c910402cKenny Root ssize_t inSize = data.readInt32(); 77596427baf0094d50047049d329b0779c3c910402cKenny Root if (inSize >= 0 && (size_t) inSize <= data.dataAvail()) { 77696427baf0094d50047049d329b0779c3c910402cKenny Root sp<KeystoreArg> arg = new KeystoreArg(data.readInplace(inSize), inSize); 77796427baf0094d50047049d329b0779c3c910402cKenny Root args.push_back(arg); 77896427baf0094d50047049d329b0779c3c910402cKenny Root } else { 77996427baf0094d50047049d329b0779c3c910402cKenny Root args.push_back(NULL); 78096427baf0094d50047049d329b0779c3c910402cKenny Root } 78196427baf0094d50047049d329b0779c3c910402cKenny Root } 78296427baf0094d50047049d329b0779c3c910402cKenny Root } 78396427baf0094d50047049d329b0779c3c910402cKenny Root int32_t ret = generate(name, uid, keyType, keySize, flags, &args); 78407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 78507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 78607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 78707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 78807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case IMPORT: { 78907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 79007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 79107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ssize_t inSize = data.readInt32(); 79207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root const void* in; 79307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (inSize >= 0 && (size_t) inSize <= data.dataAvail()) { 79407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root in = data.readInplace(inSize); 79507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 79607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root in = NULL; 79707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root inSize = 0; 79807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 799b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int uid = data.readInt32(); 8000c540aad5915e6aa34345049be96f28b64d0e84cKenny Root int32_t flags = data.readInt32(); 8010c540aad5915e6aa34345049be96f28b64d0e84cKenny Root int32_t ret = import(name, (const uint8_t*) in, (size_t) inSize, uid, flags); 80207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 80307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 80407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 80507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 80607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case SIGN: { 80707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 80807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 80907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ssize_t inSize = data.readInt32(); 81007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root const void* in; 81107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (inSize >= 0 && (size_t) inSize <= data.dataAvail()) { 81207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root in = data.readInplace(inSize); 81307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 81407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root in = NULL; 81507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root inSize = 0; 81607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 81707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root void* out = NULL; 81807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root size_t outSize = 0; 81907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = sign(name, (const uint8_t*) in, (size_t) inSize, (uint8_t**) &out, &outSize); 82007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 821b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root if (outSize > 0 && out != NULL) { 822b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root reply->writeInt32(outSize); 823b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root void* buf = reply->writeInplace(outSize); 824b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root memcpy(buf, out, outSize); 825b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root free(out); 826b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root } else { 827e289c404b9d2735fbd67c42086e33c972b46aa33Kenny Root reply->writeInt32(-1); 828b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root } 82907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 83007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 83107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 83207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case VERIFY: { 83307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 83407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 83507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ssize_t inSize = data.readInt32(); 83607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root const void* in; 83707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (inSize >= 0 && (size_t) inSize <= data.dataAvail()) { 83807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root in = data.readInplace(inSize); 83907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 84007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root in = NULL; 84107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root inSize = 0; 84207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 84307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ssize_t sigSize = data.readInt32(); 84407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root const void* sig; 84507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (sigSize >= 0 && (size_t) sigSize <= data.dataAvail()) { 84607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root sig = data.readInplace(sigSize); 84707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 84807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root sig = NULL; 84907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root sigSize = 0; 85007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 85107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root bool ret = verify(name, (const uint8_t*) in, (size_t) inSize, (const uint8_t*) sig, 85207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root (size_t) sigSize); 85307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 85407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret ? 1 : 0); 85507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 85607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 85707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case GET_PUBKEY: { 85807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 85907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 86007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root void* out = NULL; 86107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root size_t outSize = 0; 86207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = get_pubkey(name, (unsigned char**) &out, &outSize); 86307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 864b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root if (outSize > 0 && out != NULL) { 865b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root reply->writeInt32(outSize); 866b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root void* buf = reply->writeInplace(outSize); 867b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root memcpy(buf, out, outSize); 868b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root free(out); 869b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root } else { 870e289c404b9d2735fbd67c42086e33c972b46aa33Kenny Root reply->writeInt32(-1); 871b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root } 87207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 87307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 874b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root } break; 87507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case DEL_KEY: { 87607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 87707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 878b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int uid = data.readInt32(); 879b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int32_t ret = del_key(name, uid); 88007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 88107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 88207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 88307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 88407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case GRANT: { 88507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 88607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 88707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t granteeUid = data.readInt32(); 88807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = grant(name, granteeUid); 88907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 89007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 89107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 89207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 89307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case UNGRANT: { 89407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 89507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 89607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t granteeUid = data.readInt32(); 89707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = ungrant(name, granteeUid); 89807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 89907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 90007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 90107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 90207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case GETMTIME: { 90307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 90407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 90507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int64_t ret = getmtime(name); 90607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 90707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt64(ret); 90807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 90907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 910d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root case DUPLICATE: { 9110225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 912d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root String16 srcKey = data.readString16(); 913d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root int32_t srcUid = data.readInt32(); 914d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root String16 destKey = data.readString16(); 915d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root int32_t destUid = data.readInt32(); 916d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root int32_t ret = duplicate(srcKey, srcUid, destKey, destUid); 9170225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root reply->writeNoException(); 9180225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root reply->writeInt32(ret); 9190225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root return NO_ERROR; 9200225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root } break; 9214306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root case IS_HARDWARE_BACKED: { 9224306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 9231b0e3933900c7ea21189704d5db64e7346aee7afKenny Root String16 keyType = data.readString16(); 9241b0e3933900c7ea21189704d5db64e7346aee7afKenny Root int32_t ret = is_hardware_backed(keyType); 9254306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root reply->writeNoException(); 9264306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root reply->writeInt32(ret); 9274306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root return NO_ERROR; 9284306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root } 9292ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root case CLEAR_UID: { 9302ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 9312ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root int64_t uid = data.readInt64(); 9322ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root int32_t ret = clear_uid(uid); 9332ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root reply->writeNoException(); 9342ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root reply->writeInt32(ret); 9352ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root return NO_ERROR; 9362ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root } 9374e865753346fc6a075966972a7a98051818859dbRobin Lee case RESET_UID: { 9384e865753346fc6a075966972a7a98051818859dbRobin Lee CHECK_INTERFACE(IKeystoreService, data, reply); 9394e865753346fc6a075966972a7a98051818859dbRobin Lee int32_t uid = data.readInt32(); 9404e865753346fc6a075966972a7a98051818859dbRobin Lee int32_t ret = reset_uid(uid); 9414e865753346fc6a075966972a7a98051818859dbRobin Lee reply->writeNoException(); 9424e865753346fc6a075966972a7a98051818859dbRobin Lee reply->writeInt32(ret); 9434e865753346fc6a075966972a7a98051818859dbRobin Lee return NO_ERROR; 9444e865753346fc6a075966972a7a98051818859dbRobin Lee } 9454e865753346fc6a075966972a7a98051818859dbRobin Lee case SYNC_UID: { 9464e865753346fc6a075966972a7a98051818859dbRobin Lee CHECK_INTERFACE(IKeystoreService, data, reply); 9474e865753346fc6a075966972a7a98051818859dbRobin Lee int32_t sourceUid = data.readInt32(); 9484e865753346fc6a075966972a7a98051818859dbRobin Lee int32_t targetUid = data.readInt32(); 9494e865753346fc6a075966972a7a98051818859dbRobin Lee int32_t ret = sync_uid(sourceUid, targetUid); 9504e865753346fc6a075966972a7a98051818859dbRobin Lee reply->writeNoException(); 9514e865753346fc6a075966972a7a98051818859dbRobin Lee reply->writeInt32(ret); 9524e865753346fc6a075966972a7a98051818859dbRobin Lee return NO_ERROR; 9534e865753346fc6a075966972a7a98051818859dbRobin Lee } 9544e865753346fc6a075966972a7a98051818859dbRobin Lee case PASSWORD_UID: { 9554e865753346fc6a075966972a7a98051818859dbRobin Lee CHECK_INTERFACE(IKeystoreService, data, reply); 9564e865753346fc6a075966972a7a98051818859dbRobin Lee String16 password = data.readString16(); 9574e865753346fc6a075966972a7a98051818859dbRobin Lee int32_t uid = data.readInt32(); 9584e865753346fc6a075966972a7a98051818859dbRobin Lee int32_t ret = password_uid(password, uid); 9594e865753346fc6a075966972a7a98051818859dbRobin Lee reply->writeNoException(); 9604e865753346fc6a075966972a7a98051818859dbRobin Lee reply->writeInt32(ret); 9614e865753346fc6a075966972a7a98051818859dbRobin Lee return NO_ERROR; 9624e865753346fc6a075966972a7a98051818859dbRobin Lee } 96307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root default: 96407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return BBinder::onTransact(code, data, reply, flags); 96507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 96607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root} 96707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 96807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root// ---------------------------------------------------------------------------- 96907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 97007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root}; // namespace android 971