IKeystoreService.cpp revision 0c540aad5915e6aa34345049be96f28b64d0e84c
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 3207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Rootclass BpKeystoreService: public BpInterface<IKeystoreService> 3307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root{ 3407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Rootpublic: 3507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root BpKeystoreService(const sp<IBinder>& impl) 3607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root : BpInterface<IKeystoreService>(impl) 3707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 3807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 3907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 4007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root // test ping 4107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t test() 4207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 4307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 4407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 4507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::TEST, data, &reply); 4607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 4707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("test() could not contact remote: %d\n", status); 4807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 4907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 5007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 5107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 5207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 5307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("test() caught exception %d\n", err); 5407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 5507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 5607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 5707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 5807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 5907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t get(const String16& name, uint8_t** item, size_t* itemLength) 6007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 6107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 6207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 6307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 6407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::GET, data, &reply); 6507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 6607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("get() could not contact remote: %d\n", status); 6707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 6807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 6907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 7007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ssize_t len = reply.readInt32(); 7107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (len >= 0 && (size_t) len <= reply.dataAvail()) { 7207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root size_t ulen = (size_t) len; 7307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root const void* buf = reply.readInplace(ulen); 7407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *item = (uint8_t*) malloc(ulen); 7507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (*item != NULL) { 7607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root memcpy(*item, buf, ulen); 7707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *itemLength = ulen; 7807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 7907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGE("out of memory allocating output array in get"); 8007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *itemLength = 0; 8107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 8207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 8307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *itemLength = 0; 8407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 8507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 8607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("get() caught exception %d\n", err); 8707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 8807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 8907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return 0; 9007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 9107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 920c540aad5915e6aa34345049be96f28b64d0e84cKenny Root virtual int32_t insert(const String16& name, const uint8_t* item, size_t itemLength, int uid, 930c540aad5915e6aa34345049be96f28b64d0e84cKenny Root int32_t flags) 9407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 9507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 9607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 9707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 9807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInt32(itemLength); 9907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root void* buf = data.writeInplace(itemLength); 10007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root memcpy(buf, item, itemLength); 101b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root data.writeInt32(uid); 1020c540aad5915e6aa34345049be96f28b64d0e84cKenny Root data.writeInt32(flags); 10307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::INSERT, data, &reply); 10407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 10507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("import() could not contact remote: %d\n", status); 10607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 10707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 10807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 10907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 11007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 11107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("import() caught exception %d\n", err); 11207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 11307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 11407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 11507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 11607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 117b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root virtual int32_t del(const String16& name, int uid) 11807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 11907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 12007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 12107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 122b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root data.writeInt32(uid); 12307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::DEL, data, &reply); 12407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 12507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("del() could not contact remote: %d\n", status); 12607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 12707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 12807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 12907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 13007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 13107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("del() caught exception %d\n", err); 13207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 13307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 13407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 13507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 13607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 137b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root virtual int32_t exist(const String16& name, int uid) 13807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 13907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 14007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 14107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 142b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root data.writeInt32(uid); 14307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::EXIST, data, &reply); 14407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 14507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("exist() could not contact remote: %d\n", status); 14607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 14707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 14807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 14907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 15007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 15107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("exist() caught exception %d\n", err); 15207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 15307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 15407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 15507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 15607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 157b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root virtual int32_t saw(const String16& name, int uid, Vector<String16>* matches) 15807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 15907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 16007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 16107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 162b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root data.writeInt32(uid); 16307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::SAW, data, &reply); 16407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 16507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("saw() could not contact remote: %d\n", status); 16607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 16707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 16807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 16907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t numMatches = reply.readInt32(); 17007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root for (int32_t i = 0; i < numMatches; i++) { 17107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root matches->push(reply.readString16()); 17207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 17307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 17407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 17507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("saw() caught exception %d\n", err); 17607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 17707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 17807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 17907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 18007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 18107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t reset() 18207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 18307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 18407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 18507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::RESET, data, &reply); 18607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 18707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("reset() could not contact remote: %d\n", status); 18807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 18907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 19007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 19107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 19207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 19307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("reset() caught exception %d\n", err); 19407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 19507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 19607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 19707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 19807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 19907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t password(const String16& password) 20007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 20107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 20207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 20307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(password); 20407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::PASSWORD, data, &reply); 20507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 20607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("password() could not contact remote: %d\n", status); 20707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 20807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 20907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 21007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 21107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 21207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("password() caught exception %d\n", err); 21307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 21407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 21507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 21607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 21707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 21807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t lock() 21907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 22007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 22107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 22207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::LOCK, data, &reply); 22307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 22407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("lock() could not contact remote: %d\n", status); 22507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 22607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 22707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 22807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 22907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 23007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("lock() caught exception %d\n", err); 23107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 23207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 23307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 23407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 23507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 23607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t unlock(const String16& password) 23707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 23807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 23907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 24007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(password); 24107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::UNLOCK, data, &reply); 24207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 24307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("unlock() could not contact remote: %d\n", status); 24407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 24507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 24607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 24707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 24807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 24907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("unlock() caught exception %d\n", err); 25007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 25107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 25207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 25307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 25407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 25507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t zero() 25607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 25707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 25807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 25907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::ZERO, data, &reply); 26007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 26107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("zero() could not contact remote: %d\n", status); 26207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 26307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 26407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 26507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 26607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 26707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("zero() caught exception %d\n", err); 26807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 26907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 27007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 27107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 27207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 2730c540aad5915e6aa34345049be96f28b64d0e84cKenny Root virtual int32_t generate(const String16& name, int uid, int32_t flags) 27407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 27507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 27607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 27707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 278b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root data.writeInt32(uid); 2790c540aad5915e6aa34345049be96f28b64d0e84cKenny Root data.writeInt32(flags); 28007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::GENERATE, data, &reply); 28107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 28207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("generate() could not contact remote: %d\n", status); 28307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 28407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 28507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 28607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 28707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 28807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("generate() caught exception %d\n", err); 28907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 29007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 29107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 29207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 29307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 2940c540aad5915e6aa34345049be96f28b64d0e84cKenny Root virtual int32_t import(const String16& name, const uint8_t* key, size_t keyLength, int uid, 2950c540aad5915e6aa34345049be96f28b64d0e84cKenny Root int flags) 29607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 29707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 29807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 29907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 30007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInt32(keyLength); 30107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root void* buf = data.writeInplace(keyLength); 30207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root memcpy(buf, key, keyLength); 303b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root data.writeInt32(uid); 3040c540aad5915e6aa34345049be96f28b64d0e84cKenny Root data.writeInt32(flags); 30507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::IMPORT, data, &reply); 30607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 30707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("import() could not contact remote: %d\n", status); 30807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 30907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 31007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 31107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 31207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 31307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("import() caught exception %d\n", err); 31407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 31507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 31607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 31707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 31807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 31907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t sign(const String16& name, const uint8_t* in, size_t inLength, uint8_t** out, 32007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root size_t* outLength) 32107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 32207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 32307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 32407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 32507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInt32(inLength); 32607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root void* buf = data.writeInplace(inLength); 32707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root memcpy(buf, in, inLength); 32807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::SIGN, data, &reply); 32907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 33007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("import() could not contact remote: %d\n", status); 33107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 33207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 33307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 33407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ssize_t len = reply.readInt32(); 33507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (len >= 0 && (size_t) len <= reply.dataAvail()) { 33607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root size_t ulen = (size_t) len; 33707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root const void* outBuf = reply.readInplace(ulen); 33807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *out = (uint8_t*) malloc(ulen); 33907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (*out != NULL) { 34007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root memcpy((void*) *out, outBuf, ulen); 34107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *outLength = ulen; 34207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 34307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGE("out of memory allocating output array in sign"); 34407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *outLength = 0; 34507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 34607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 34707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *outLength = 0; 34807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 34907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 35007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("import() caught exception %d\n", err); 35107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 35207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 35307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return 0; 35407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 35507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 35607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t verify(const String16& name, const uint8_t* in, size_t inLength, 35707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root const uint8_t* signature, size_t signatureLength) 35807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 35907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 36007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root void* buf; 36107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 36207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 36307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 36407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInt32(inLength); 36507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root buf = data.writeInplace(inLength); 36607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root memcpy(buf, in, inLength); 36707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInt32(signatureLength); 36807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root buf = data.writeInplace(signatureLength); 36907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root memcpy(buf, signature, signatureLength); 37007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::VERIFY, data, &reply); 37107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 37207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("verify() could not contact remote: %d\n", status); 37307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 37407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 37507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 37607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 37707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 37807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("verify() caught exception %d\n", err); 37907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 38007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 38107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 38207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 38307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 38407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t get_pubkey(const String16& name, uint8_t** pubkey, size_t* pubkeyLength) 38507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 38607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 38707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 38807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 38907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::GET_PUBKEY, data, &reply); 39007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 39107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("get_pubkey() could not contact remote: %d\n", status); 39207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 39307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 39407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 39507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ssize_t len = reply.readInt32(); 39607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (len >= 0 && (size_t) len <= reply.dataAvail()) { 39707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root size_t ulen = (size_t) len; 39807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root const void* buf = reply.readInplace(ulen); 39907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *pubkey = (uint8_t*) malloc(ulen); 40007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (*pubkey != NULL) { 40107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root memcpy(*pubkey, buf, ulen); 40207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *pubkeyLength = ulen; 40307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 40407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGE("out of memory allocating output array in get_pubkey"); 40507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *pubkeyLength = 0; 40607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 40707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 40807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *pubkeyLength = 0; 40907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 41007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 41107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("get_pubkey() caught exception %d\n", err); 41207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 41307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 41407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return 0; 41507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 41607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 417b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root virtual int32_t del_key(const String16& name, int uid) 41807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 41907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 42007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 42107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 422b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root data.writeInt32(uid); 42307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::DEL_KEY, data, &reply); 42407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 42507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("del_key() could not contact remote: %d\n", status); 42607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 42707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 42807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 42907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 43007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 43107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("del_key() caught exception %d\n", err); 43207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 43307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 43407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 43507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 43607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 43707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t grant(const String16& name, int32_t granteeUid) 43807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 43907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 44007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 44107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 44207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInt32(granteeUid); 44307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::GRANT, data, &reply); 44407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 44507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("grant() could not contact remote: %d\n", status); 44607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 44707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 44807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 44907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 45007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 45107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("grant() caught exception %d\n", err); 45207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 45307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 45407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 45507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 45607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 45707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t ungrant(const String16& name, int32_t granteeUid) 45807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 45907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 46007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 46107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 46207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInt32(granteeUid); 46307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::UNGRANT, data, &reply); 46407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 46507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("ungrant() could not contact remote: %d\n", status); 46607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 46707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 46807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 46907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 47007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 47107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("ungrant() caught exception %d\n", err); 47207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 47307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 47407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 47507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 47607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 47707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int64_t getmtime(const String16& name) 47807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 47907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 48007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 48107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 48207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::GETMTIME, data, &reply); 48307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 48407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("getmtime() could not contact remote: %d\n", status); 48507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 48607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 48707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 48807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int64_t ret = reply.readInt64(); 48907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 49007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("getmtime() caught exception %d\n", err); 49107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 49207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 49307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 49407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 4950225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root 496d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root virtual int32_t duplicate(const String16& srcKey, int32_t srcUid, const String16& destKey, 497d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root int32_t destUid) 4980225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root { 4990225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root Parcel data, reply; 5000225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 501d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root data.writeString16(srcKey); 502d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root data.writeInt32(srcUid); 503d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root data.writeString16(destKey); 504d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root data.writeInt32(destUid); 505d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root status_t status = remote()->transact(BnKeystoreService::DUPLICATE, data, &reply); 5060225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root if (status != NO_ERROR) { 507d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root ALOGD("duplicate() could not contact remote: %d\n", status); 5080225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root return -1; 5090225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root } 5100225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root int32_t err = reply.readExceptionCode(); 5110225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root int32_t ret = reply.readInt32(); 5120225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root if (err < 0) { 513d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root ALOGD("duplicate() caught exception %d\n", err); 5140225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root return -1; 5150225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root } 5160225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root return ret; 5170225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root } 5184306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root 5194306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root virtual int32_t is_hardware_backed() 5204306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root { 5214306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root Parcel data, reply; 5224306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 5234306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root status_t status = remote()->transact(BnKeystoreService::IS_HARDWARE_BACKED, data, &reply); 5244306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root if (status != NO_ERROR) { 5254306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root ALOGD("is_hardware_backed() could not contact remote: %d\n", status); 5264306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root return -1; 5274306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root } 5284306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root int32_t err = reply.readExceptionCode(); 5294306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root int32_t ret = reply.readInt32(); 5304306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root if (err < 0) { 5314306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root ALOGD("is_hardware_backed() caught exception %d\n", err); 5324306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root return -1; 5334306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root } 5344306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root return ret; 5354306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root } 5362ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root 5372ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root virtual int32_t clear_uid(int64_t uid) 5382ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root { 5392ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root Parcel data, reply; 5402ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 5412ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root data.writeInt64(uid); 5422ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root status_t status = remote()->transact(BnKeystoreService::CLEAR_UID, data, &reply); 5432ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root if (status != NO_ERROR) { 5442ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root ALOGD("clear_uid() could not contact remote: %d\n", status); 5452ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root return -1; 5462ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root } 5472ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root int32_t err = reply.readExceptionCode(); 5482ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root int32_t ret = reply.readInt32(); 5492ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root if (err < 0) { 5502ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root ALOGD("clear_uid() caught exception %d\n", err); 5512ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root return -1; 5522ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root } 5532ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root return ret; 5542ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root } 55507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root}; 55607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 55707438c8d7256d3788dac323b4d0055f201e0bec9Kenny RootIMPLEMENT_META_INTERFACE(KeystoreService, "android.security.keystore"); 55807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 55907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root// ---------------------------------------------------------------------- 56007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 56107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Rootstatus_t BnKeystoreService::onTransact( 56207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 56307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root{ 56407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root switch(code) { 56507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case TEST: { 56607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 56707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = test(); 56807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 56907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 57007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 57107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 57207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case GET: { 57307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 57407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 57507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root void* out = NULL; 57607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root size_t outSize = 0; 57707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = get(name, (uint8_t**) &out, &outSize); 57807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 57907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (ret == 1) { 58007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(outSize); 58107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root void* buf = reply->writeInplace(outSize); 58207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root memcpy(buf, out, outSize); 58307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root free(out); 58407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 58507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(-1); 58607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 58707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 58807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 58907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case INSERT: { 59007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 59107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 59207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ssize_t inSize = data.readInt32(); 59307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root const void* in; 59407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (inSize >= 0 && (size_t) inSize <= data.dataAvail()) { 59507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root in = data.readInplace(inSize); 59607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 59707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root in = NULL; 59807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root inSize = 0; 59907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 600b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int uid = data.readInt32(); 6010c540aad5915e6aa34345049be96f28b64d0e84cKenny Root int32_t flags = data.readInt32(); 6020c540aad5915e6aa34345049be96f28b64d0e84cKenny Root int32_t ret = insert(name, (const uint8_t*) in, (size_t) inSize, uid, flags); 60307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 60407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 60507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 60607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 60707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case DEL: { 60807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 60907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 610b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int uid = data.readInt32(); 611b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int32_t ret = del(name, uid); 61207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 61307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 61407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 61507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 61607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case EXIST: { 61707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 61807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 619b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int uid = data.readInt32(); 620b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int32_t ret = exist(name, uid); 62107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 62207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 62307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 62407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 62507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case SAW: { 62607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 62707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 628b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int uid = data.readInt32(); 62907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Vector<String16> matches; 630b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int32_t ret = saw(name, uid, &matches); 63107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 63207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(matches.size()); 63307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Vector<String16>::const_iterator it = matches.begin(); 63407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root for (; it != matches.end(); ++it) { 63507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeString16(*it); 63607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 63707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 63807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 63907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 64007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case RESET: { 64107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 64207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reset(); 64307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 64407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 64507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 64607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 64707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case PASSWORD: { 64807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 64907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 pass = data.readString16(); 65007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = password(pass); 65107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 65207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 65307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 65407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 65507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case LOCK: { 65607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 65707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = lock(); 65807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 65907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 66007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 66107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 66207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case UNLOCK: { 66307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 66407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 pass = data.readString16(); 66507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = unlock(pass); 66607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 66707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 66807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 66907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 67007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case ZERO: { 67107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 67207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = zero(); 67307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 67407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 67507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 67607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 67707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case GENERATE: { 67807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 67907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 680b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int uid = data.readInt32(); 6810c540aad5915e6aa34345049be96f28b64d0e84cKenny Root int32_t flags = data.readInt32(); 6820c540aad5915e6aa34345049be96f28b64d0e84cKenny Root int32_t ret = generate(name, uid, flags); 68307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 68407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 68507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 68607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 68707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case IMPORT: { 68807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 68907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 69007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ssize_t inSize = data.readInt32(); 69107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root const void* in; 69207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (inSize >= 0 && (size_t) inSize <= data.dataAvail()) { 69307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root in = data.readInplace(inSize); 69407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 69507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root in = NULL; 69607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root inSize = 0; 69707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 698b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int uid = data.readInt32(); 6990c540aad5915e6aa34345049be96f28b64d0e84cKenny Root int32_t flags = data.readInt32(); 7000c540aad5915e6aa34345049be96f28b64d0e84cKenny Root int32_t ret = import(name, (const uint8_t*) in, (size_t) inSize, uid, flags); 70107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 70207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 70307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 70407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 70507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case SIGN: { 70607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 70707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 70807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ssize_t inSize = data.readInt32(); 70907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root const void* in; 71007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (inSize >= 0 && (size_t) inSize <= data.dataAvail()) { 71107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root in = data.readInplace(inSize); 71207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 71307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root in = NULL; 71407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root inSize = 0; 71507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 71607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root void* out = NULL; 71707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root size_t outSize = 0; 71807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = sign(name, (const uint8_t*) in, (size_t) inSize, (uint8_t**) &out, &outSize); 71907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 720b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root if (outSize > 0 && out != NULL) { 721b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root reply->writeInt32(outSize); 722b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root void* buf = reply->writeInplace(outSize); 723b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root memcpy(buf, out, outSize); 724b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root free(out); 725b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root } else { 726e289c404b9d2735fbd67c42086e33c972b46aa33Kenny Root reply->writeInt32(-1); 727b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root } 72807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 72907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 73007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 73107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case VERIFY: { 73207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 73307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 73407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ssize_t inSize = data.readInt32(); 73507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root const void* in; 73607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (inSize >= 0 && (size_t) inSize <= data.dataAvail()) { 73707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root in = data.readInplace(inSize); 73807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 73907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root in = NULL; 74007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root inSize = 0; 74107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 74207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ssize_t sigSize = data.readInt32(); 74307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root const void* sig; 74407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (sigSize >= 0 && (size_t) sigSize <= data.dataAvail()) { 74507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root sig = data.readInplace(sigSize); 74607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 74707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root sig = NULL; 74807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root sigSize = 0; 74907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 75007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root bool ret = verify(name, (const uint8_t*) in, (size_t) inSize, (const uint8_t*) sig, 75107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root (size_t) sigSize); 75207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 75307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret ? 1 : 0); 75407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 75507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 75607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case GET_PUBKEY: { 75707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 75807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 75907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root void* out = NULL; 76007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root size_t outSize = 0; 76107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = get_pubkey(name, (unsigned char**) &out, &outSize); 76207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 763b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root if (outSize > 0 && out != NULL) { 764b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root reply->writeInt32(outSize); 765b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root void* buf = reply->writeInplace(outSize); 766b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root memcpy(buf, out, outSize); 767b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root free(out); 768b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root } else { 769e289c404b9d2735fbd67c42086e33c972b46aa33Kenny Root reply->writeInt32(-1); 770b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root } 77107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 77207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 773b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root } break; 77407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case DEL_KEY: { 77507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 77607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 777b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int uid = data.readInt32(); 778b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int32_t ret = del_key(name, uid); 77907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 78007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 78107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 78207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 78307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case GRANT: { 78407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 78507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 78607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t granteeUid = data.readInt32(); 78707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = grant(name, granteeUid); 78807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 78907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 79007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 79107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 79207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case UNGRANT: { 79307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 79407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 79507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t granteeUid = data.readInt32(); 79607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = ungrant(name, granteeUid); 79707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 79807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 79907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 80007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 80107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case GETMTIME: { 80207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 80307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 80407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int64_t ret = getmtime(name); 80507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 80607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt64(ret); 80707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 80807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 809d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root case DUPLICATE: { 8100225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 811d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root String16 srcKey = data.readString16(); 812d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root int32_t srcUid = data.readInt32(); 813d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root String16 destKey = data.readString16(); 814d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root int32_t destUid = data.readInt32(); 815d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root int32_t ret = duplicate(srcKey, srcUid, destKey, destUid); 8160225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root reply->writeNoException(); 8170225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root reply->writeInt32(ret); 8180225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root return NO_ERROR; 8190225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root } break; 8204306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root case IS_HARDWARE_BACKED: { 8214306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 8224306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root int32_t ret = is_hardware_backed(); 8234306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root reply->writeNoException(); 8244306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root reply->writeInt32(ret); 8254306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root return NO_ERROR; 8264306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root } 8272ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root case CLEAR_UID: { 8282ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 8292ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root int64_t uid = data.readInt64(); 8302ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root int32_t ret = clear_uid(uid); 8312ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root reply->writeNoException(); 8322ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root reply->writeInt32(ret); 8332ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root return NO_ERROR; 8342ecc7a1efbb21d86d38b9e0348dfbf0e1213d920Kenny Root } 83507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root default: 83607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return BBinder::onTransact(code, data, reply, flags); 83707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 83807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root} 83907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 84007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root// ---------------------------------------------------------------------------- 84107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 84207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root}; // namespace android 843