IKeystoreService.cpp revision 4306123e81371bd8bd85f77c2375d29ac53ff771
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 92b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root virtual int32_t insert(const String16& name, const uint8_t* item, size_t itemLength, int uid) 9307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 9407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 9507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 9607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 9707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInt32(itemLength); 9807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root void* buf = data.writeInplace(itemLength); 9907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root memcpy(buf, item, itemLength); 100b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root data.writeInt32(uid); 10107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::INSERT, data, &reply); 10207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 10307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("import() could not contact remote: %d\n", status); 10407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 10507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 10607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 10707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 10807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 10907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("import() caught exception %d\n", err); 11007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 11107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 11207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 11307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 11407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 115b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root virtual int32_t del(const String16& name, int uid) 11607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 11707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 11807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 11907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 120b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root data.writeInt32(uid); 12107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::DEL, data, &reply); 12207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 12307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("del() could not contact remote: %d\n", status); 12407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 12507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 12607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 12707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 12807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 12907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("del() caught exception %d\n", err); 13007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 13107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 13207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 13307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 13407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 135b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root virtual int32_t exist(const String16& name, int uid) 13607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 13707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 13807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 13907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 140b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root data.writeInt32(uid); 14107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::EXIST, data, &reply); 14207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 14307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("exist() could not contact remote: %d\n", status); 14407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 14507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 14607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 14707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 14807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 14907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("exist() caught exception %d\n", err); 15007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 15107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 15207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 15307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 15407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 155b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root virtual int32_t saw(const String16& name, int uid, Vector<String16>* matches) 15607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 15707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 15807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 15907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 160b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root data.writeInt32(uid); 16107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::SAW, data, &reply); 16207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 16307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("saw() could not contact remote: %d\n", status); 16407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 16507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 16607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 16707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t numMatches = reply.readInt32(); 16807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root for (int32_t i = 0; i < numMatches; i++) { 16907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root matches->push(reply.readString16()); 17007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 17107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 17207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 17307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("saw() caught exception %d\n", err); 17407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 17507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 17607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 17707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 17807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 17907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t reset() 18007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 18107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 18207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 18307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::RESET, data, &reply); 18407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 18507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("reset() could not contact remote: %d\n", status); 18607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 18707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 18807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 18907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 19007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 19107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("reset() caught exception %d\n", err); 19207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 19307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 19407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 19507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 19607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 19707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t password(const String16& password) 19807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 19907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 20007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 20107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(password); 20207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::PASSWORD, data, &reply); 20307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 20407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("password() could not contact remote: %d\n", status); 20507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 20607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 20707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 20807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 20907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 21007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("password() caught exception %d\n", err); 21107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 21207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 21307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 21407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 21507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 21607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t lock() 21707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 21807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 21907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 22007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::LOCK, data, &reply); 22107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 22207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("lock() could not contact remote: %d\n", status); 22307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 22407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 22507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 22607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 22707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 22807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("lock() caught exception %d\n", err); 22907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 23007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 23107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 23207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 23307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 23407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t unlock(const String16& password) 23507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 23607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 23707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 23807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(password); 23907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::UNLOCK, data, &reply); 24007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 24107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("unlock() could not contact remote: %d\n", status); 24207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 24307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 24407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 24507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 24607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 24707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("unlock() caught exception %d\n", err); 24807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 24907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 25007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 25107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 25207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 25307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t zero() 25407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 25507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 25607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 25707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::ZERO, data, &reply); 25807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 25907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("zero() could not contact remote: %d\n", status); 26007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 26107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 26207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 26307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 26407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 26507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("zero() caught exception %d\n", err); 26607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 26707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 26807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 26907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 27007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 271b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root virtual int32_t generate(const String16& name, int uid) 27207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 27307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 27407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 27507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 276b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root data.writeInt32(uid); 27707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::GENERATE, data, &reply); 27807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 27907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("generate() could not contact remote: %d\n", status); 28007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 28107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 28207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 28307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 28407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 28507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("generate() caught exception %d\n", err); 28607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 28707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 28807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 28907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 29007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 291b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root virtual int32_t import(const String16& name, const uint8_t* key, size_t keyLength, int uid) 29207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 29307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 29407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 29507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 29607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInt32(keyLength); 29707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root void* buf = data.writeInplace(keyLength); 29807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root memcpy(buf, key, keyLength); 299b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root data.writeInt32(uid); 30007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::IMPORT, data, &reply); 30107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 30207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("import() could not contact remote: %d\n", status); 30307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 30407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 30507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 30607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 30707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 30807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("import() caught exception %d\n", err); 30907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 31007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 31107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 31207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 31307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 31407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t sign(const String16& name, const uint8_t* in, size_t inLength, uint8_t** out, 31507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root size_t* outLength) 31607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 31707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 31807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 31907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 32007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInt32(inLength); 32107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root void* buf = data.writeInplace(inLength); 32207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root memcpy(buf, in, inLength); 32307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::SIGN, data, &reply); 32407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 32507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("import() could not contact remote: %d\n", status); 32607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 32707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 32807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 32907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ssize_t len = reply.readInt32(); 33007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (len >= 0 && (size_t) len <= reply.dataAvail()) { 33107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root size_t ulen = (size_t) len; 33207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root const void* outBuf = reply.readInplace(ulen); 33307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *out = (uint8_t*) malloc(ulen); 33407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (*out != NULL) { 33507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root memcpy((void*) *out, outBuf, ulen); 33607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *outLength = ulen; 33707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 33807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGE("out of memory allocating output array in sign"); 33907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *outLength = 0; 34007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 34107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 34207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *outLength = 0; 34307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 34407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 34507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("import() caught exception %d\n", err); 34607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 34707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 34807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return 0; 34907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 35007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 35107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t verify(const String16& name, const uint8_t* in, size_t inLength, 35207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root const uint8_t* signature, size_t signatureLength) 35307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 35407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 35507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root void* buf; 35607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 35707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 35807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 35907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInt32(inLength); 36007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root buf = data.writeInplace(inLength); 36107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root memcpy(buf, in, inLength); 36207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInt32(signatureLength); 36307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root buf = data.writeInplace(signatureLength); 36407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root memcpy(buf, signature, signatureLength); 36507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::VERIFY, data, &reply); 36607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 36707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("verify() could not contact remote: %d\n", status); 36807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 36907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 37007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 37107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 37207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 37307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("verify() caught exception %d\n", err); 37407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 37507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 37607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 37707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 37807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 37907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t get_pubkey(const String16& name, uint8_t** pubkey, size_t* pubkeyLength) 38007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 38107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 38207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 38307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 38407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::GET_PUBKEY, data, &reply); 38507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 38607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("get_pubkey() could not contact remote: %d\n", status); 38707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 38807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 38907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 39007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ssize_t len = reply.readInt32(); 39107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (len >= 0 && (size_t) len <= reply.dataAvail()) { 39207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root size_t ulen = (size_t) len; 39307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root const void* buf = reply.readInplace(ulen); 39407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *pubkey = (uint8_t*) malloc(ulen); 39507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (*pubkey != NULL) { 39607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root memcpy(*pubkey, buf, ulen); 39707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *pubkeyLength = ulen; 39807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 39907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGE("out of memory allocating output array in get_pubkey"); 40007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *pubkeyLength = 0; 40107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 40207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 40307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root *pubkeyLength = 0; 40407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 40507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 40607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("get_pubkey() caught exception %d\n", err); 40707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 40807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 40907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return 0; 41007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 41107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 412b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root virtual int32_t del_key(const String16& name, int uid) 41307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 41407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 41507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 41607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 417b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root data.writeInt32(uid); 41807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::DEL_KEY, data, &reply); 41907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 42007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("del_key() could not contact remote: %d\n", status); 42107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 42207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 42307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 42407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 42507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 42607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("del_key() caught exception %d\n", err); 42707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 42807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 42907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 43007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 43107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 43207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t grant(const String16& name, int32_t granteeUid) 43307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 43407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 43507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 43607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 43707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInt32(granteeUid); 43807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::GRANT, data, &reply); 43907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 44007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("grant() could not contact remote: %d\n", status); 44107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 44207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 44307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 44407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 44507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 44607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("grant() caught exception %d\n", err); 44707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 44807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 44907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 45007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 45107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 45207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root virtual int32_t ungrant(const String16& name, int32_t granteeUid) 45307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 45407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 45507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 45607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 45707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInt32(granteeUid); 45807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::UNGRANT, data, &reply); 45907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 46007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("ungrant() could not contact remote: %d\n", status); 46107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 46207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 46307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 46407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reply.readInt32(); 46507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 46607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("ungrant() caught exception %d\n", err); 46707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 46807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 46907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 47007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 47107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 47207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int64_t getmtime(const String16& name) 47307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root { 47407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Parcel data, reply; 47507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 47607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root data.writeString16(name); 47707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root status_t status = remote()->transact(BnKeystoreService::GETMTIME, data, &reply); 47807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (status != NO_ERROR) { 47907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("getmtime() could not contact remote: %d\n", status); 48007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 48107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 48207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t err = reply.readExceptionCode(); 48307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int64_t ret = reply.readInt64(); 48407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (err < 0) { 48507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ALOGD("getmtime() caught exception %d\n", err); 48607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return -1; 48707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 48807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return ret; 48907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 4900225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root 491d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root virtual int32_t duplicate(const String16& srcKey, int32_t srcUid, const String16& destKey, 492d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root int32_t destUid) 4930225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root { 4940225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root Parcel data, reply; 4950225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 496d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root data.writeString16(srcKey); 497d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root data.writeInt32(srcUid); 498d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root data.writeString16(destKey); 499d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root data.writeInt32(destUid); 500d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root status_t status = remote()->transact(BnKeystoreService::DUPLICATE, data, &reply); 5010225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root if (status != NO_ERROR) { 502d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root ALOGD("duplicate() could not contact remote: %d\n", status); 5030225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root return -1; 5040225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root } 5050225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root int32_t err = reply.readExceptionCode(); 5060225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root int32_t ret = reply.readInt32(); 5070225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root if (err < 0) { 508d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root ALOGD("duplicate() caught exception %d\n", err); 5090225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root return -1; 5100225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root } 5110225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root return ret; 5120225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root } 5134306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root 5144306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root virtual int32_t is_hardware_backed() 5154306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root { 5164306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root Parcel data, reply; 5174306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); 5184306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root status_t status = remote()->transact(BnKeystoreService::IS_HARDWARE_BACKED, data, &reply); 5194306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root if (status != NO_ERROR) { 5204306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root ALOGD("is_hardware_backed() could not contact remote: %d\n", status); 5214306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root return -1; 5224306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root } 5234306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root int32_t err = reply.readExceptionCode(); 5244306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root int32_t ret = reply.readInt32(); 5254306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root if (err < 0) { 5264306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root ALOGD("is_hardware_backed() caught exception %d\n", err); 5274306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root return -1; 5284306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root } 5294306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root return ret; 5304306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root } 53107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root}; 53207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 53307438c8d7256d3788dac323b4d0055f201e0bec9Kenny RootIMPLEMENT_META_INTERFACE(KeystoreService, "android.security.keystore"); 53407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 53507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root// ---------------------------------------------------------------------- 53607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 53707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Rootstatus_t BnKeystoreService::onTransact( 53807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 53907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root{ 54007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root switch(code) { 54107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case TEST: { 54207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 54307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = test(); 54407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 54507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 54607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 54707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 54807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case GET: { 54907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 55007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 55107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root void* out = NULL; 55207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root size_t outSize = 0; 55307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = get(name, (uint8_t**) &out, &outSize); 55407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 55507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (ret == 1) { 55607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(outSize); 55707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root void* buf = reply->writeInplace(outSize); 55807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root memcpy(buf, out, outSize); 55907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root free(out); 56007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 56107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(-1); 56207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 56307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 56407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 56507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case INSERT: { 56607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 56707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 56807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ssize_t inSize = data.readInt32(); 56907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root const void* in; 57007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (inSize >= 0 && (size_t) inSize <= data.dataAvail()) { 57107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root in = data.readInplace(inSize); 57207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 57307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root in = NULL; 57407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root inSize = 0; 57507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 576b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int uid = data.readInt32(); 577b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int32_t ret = insert(name, (const uint8_t*) in, (size_t) inSize, uid); 57807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 57907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 58007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 58107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 58207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case DEL: { 58307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 58407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 585b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int uid = data.readInt32(); 586b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int32_t ret = del(name, uid); 58707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 58807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 58907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 59007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 59107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case EXIST: { 59207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 59307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 594b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int uid = data.readInt32(); 595b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int32_t ret = exist(name, uid); 59607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 59707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 59807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 59907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 60007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case SAW: { 60107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 60207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 603b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int uid = data.readInt32(); 60407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Vector<String16> matches; 605b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int32_t ret = saw(name, uid, &matches); 60607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 60707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(matches.size()); 60807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root Vector<String16>::const_iterator it = matches.begin(); 60907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root for (; it != matches.end(); ++it) { 61007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeString16(*it); 61107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 61207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 61307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 61407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 61507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case RESET: { 61607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 61707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = reset(); 61807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 61907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 62007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 62107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 62207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case PASSWORD: { 62307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 62407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 pass = data.readString16(); 62507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = password(pass); 62607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 62707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 62807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 62907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 63007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case LOCK: { 63107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 63207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = lock(); 63307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 63407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 63507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 63607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 63707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case UNLOCK: { 63807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 63907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 pass = data.readString16(); 64007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = unlock(pass); 64107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 64207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 64307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 64407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 64507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case ZERO: { 64607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 64707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = zero(); 64807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 64907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 65007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 65107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 65207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case GENERATE: { 65307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 65407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 655b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int uid = data.readInt32(); 656b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int32_t ret = generate(name, uid); 65707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 65807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 65907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 66007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 66107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case IMPORT: { 66207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 66307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 66407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ssize_t inSize = data.readInt32(); 66507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root const void* in; 66607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (inSize >= 0 && (size_t) inSize <= data.dataAvail()) { 66707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root in = data.readInplace(inSize); 66807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 66907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root in = NULL; 67007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root inSize = 0; 67107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 672b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int uid = data.readInt32(); 673b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int32_t ret = import(name, (const uint8_t*) in, (size_t) inSize, uid); 67407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 67507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 67607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 67707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 67807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case SIGN: { 67907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 68007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 68107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ssize_t inSize = data.readInt32(); 68207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root const void* in; 68307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (inSize >= 0 && (size_t) inSize <= data.dataAvail()) { 68407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root in = data.readInplace(inSize); 68507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 68607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root in = NULL; 68707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root inSize = 0; 68807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 68907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root void* out = NULL; 69007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root size_t outSize = 0; 69107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = sign(name, (const uint8_t*) in, (size_t) inSize, (uint8_t**) &out, &outSize); 69207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 693b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root if (outSize > 0 && out != NULL) { 694b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root reply->writeInt32(outSize); 695b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root void* buf = reply->writeInplace(outSize); 696b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root memcpy(buf, out, outSize); 697b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root free(out); 698b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root } else { 699e289c404b9d2735fbd67c42086e33c972b46aa33Kenny Root reply->writeInt32(-1); 700b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root } 70107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 70207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 70307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 70407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case VERIFY: { 70507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 70607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 70707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ssize_t inSize = data.readInt32(); 70807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root const void* in; 70907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (inSize >= 0 && (size_t) inSize <= data.dataAvail()) { 71007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root in = data.readInplace(inSize); 71107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 71207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root in = NULL; 71307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root inSize = 0; 71407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 71507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root ssize_t sigSize = data.readInt32(); 71607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root const void* sig; 71707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root if (sigSize >= 0 && (size_t) sigSize <= data.dataAvail()) { 71807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root sig = data.readInplace(sigSize); 71907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } else { 72007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root sig = NULL; 72107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root sigSize = 0; 72207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 72307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root bool ret = verify(name, (const uint8_t*) in, (size_t) inSize, (const uint8_t*) sig, 72407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root (size_t) sigSize); 72507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 72607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret ? 1 : 0); 72707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 72807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 72907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case GET_PUBKEY: { 73007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 73107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 73207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root void* out = NULL; 73307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root size_t outSize = 0; 73407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = get_pubkey(name, (unsigned char**) &out, &outSize); 73507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 736b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root if (outSize > 0 && out != NULL) { 737b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root reply->writeInt32(outSize); 738b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root void* buf = reply->writeInplace(outSize); 739b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root memcpy(buf, out, outSize); 740b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root free(out); 741b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root } else { 742e289c404b9d2735fbd67c42086e33c972b46aa33Kenny Root reply->writeInt32(-1); 743b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root } 74407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 74507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 746b03c9fb5f9c058a8ae0485c986a8ab934ab73eaaKenny Root } break; 74707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case DEL_KEY: { 74807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 74907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 750b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int uid = data.readInt32(); 751b88c3eb96625513df4cc998d739d17266ebaf89fKenny Root int32_t ret = del_key(name, uid); 75207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 75307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 75407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 75507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 75607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case GRANT: { 75707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 75807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 75907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t granteeUid = data.readInt32(); 76007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = grant(name, granteeUid); 76107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 76207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 76307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 76407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 76507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case UNGRANT: { 76607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 76707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 76807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t granteeUid = data.readInt32(); 76907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int32_t ret = ungrant(name, granteeUid); 77007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 77107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt32(ret); 77207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 77307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 77407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root case GETMTIME: { 77507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 77607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root String16 name = data.readString16(); 77707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root int64_t ret = getmtime(name); 77807438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeNoException(); 77907438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root reply->writeInt64(ret); 78007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return NO_ERROR; 78107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } break; 782d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root case DUPLICATE: { 7830225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 784d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root String16 srcKey = data.readString16(); 785d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root int32_t srcUid = data.readInt32(); 786d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root String16 destKey = data.readString16(); 787d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root int32_t destUid = data.readInt32(); 788d53bc92f1cc4eb669ec015480cebe5ae7aaaf7cfKenny Root int32_t ret = duplicate(srcKey, srcUid, destKey, destUid); 7890225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root reply->writeNoException(); 7900225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root reply->writeInt32(ret); 7910225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root return NO_ERROR; 7920225407783ee339164a0cd8ca5ef04c99d27c59aKenny Root } break; 7934306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root case IS_HARDWARE_BACKED: { 7944306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root CHECK_INTERFACE(IKeystoreService, data, reply); 7954306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root int32_t ret = is_hardware_backed(); 7964306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root reply->writeNoException(); 7974306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root reply->writeInt32(ret); 7984306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root return NO_ERROR; 7994306123e81371bd8bd85f77c2375d29ac53ff771Kenny Root } 80007438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root default: 80107438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root return BBinder::onTransact(code, data, reply, flags); 80207438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root } 80307438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root} 80407438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 80507438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root// ---------------------------------------------------------------------------- 80607438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root 80707438c8d7256d3788dac323b4d0055f201e0bec9Kenny Root}; // namespace android 808