1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef KEYSTORE_IKEYSTORESERVICE_H 18 #define KEYSTORE_IKEYSTORESERVICE_H 19 20 #include <utils/RefBase.h> 21 #include <binder/IInterface.h> 22 #include <binder/Parcel.h> 23 24 namespace android { 25 26 class KeystoreArg : public RefBase { 27 public: 28 KeystoreArg(const void *data, size_t len); 29 ~KeystoreArg(); 30 31 const void* data() const; 32 size_t size() const; 33 34 private: 35 const void* mData; 36 size_t mSize; 37 }; 38 39 /* 40 * This must be kept manually in sync with frameworks/base's IKeystoreService.java 41 */ 42 class IKeystoreService: public IInterface { 43 public: 44 enum { 45 TEST = IBinder::FIRST_CALL_TRANSACTION + 0, 46 GET = IBinder::FIRST_CALL_TRANSACTION + 1, 47 INSERT = IBinder::FIRST_CALL_TRANSACTION + 2, 48 DEL = IBinder::FIRST_CALL_TRANSACTION + 3, 49 EXIST = IBinder::FIRST_CALL_TRANSACTION + 4, 50 SAW = IBinder::FIRST_CALL_TRANSACTION + 5, 51 RESET = IBinder::FIRST_CALL_TRANSACTION + 6, 52 PASSWORD = IBinder::FIRST_CALL_TRANSACTION + 7, 53 LOCK = IBinder::FIRST_CALL_TRANSACTION + 8, 54 UNLOCK = IBinder::FIRST_CALL_TRANSACTION + 9, 55 ZERO = IBinder::FIRST_CALL_TRANSACTION + 10, 56 GENERATE = IBinder::FIRST_CALL_TRANSACTION + 11, 57 IMPORT = IBinder::FIRST_CALL_TRANSACTION + 12, 58 SIGN = IBinder::FIRST_CALL_TRANSACTION + 13, 59 VERIFY = IBinder::FIRST_CALL_TRANSACTION + 14, 60 GET_PUBKEY = IBinder::FIRST_CALL_TRANSACTION + 15, 61 DEL_KEY = IBinder::FIRST_CALL_TRANSACTION + 16, 62 GRANT = IBinder::FIRST_CALL_TRANSACTION + 17, 63 UNGRANT = IBinder::FIRST_CALL_TRANSACTION + 18, 64 GETMTIME = IBinder::FIRST_CALL_TRANSACTION + 19, 65 DUPLICATE = IBinder::FIRST_CALL_TRANSACTION + 20, 66 IS_HARDWARE_BACKED = IBinder::FIRST_CALL_TRANSACTION + 21, 67 CLEAR_UID = IBinder::FIRST_CALL_TRANSACTION + 22, 68 RESET_UID = IBinder::FIRST_CALL_TRANSACTION + 23, 69 SYNC_UID = IBinder::FIRST_CALL_TRANSACTION + 24, 70 PASSWORD_UID = IBinder::FIRST_CALL_TRANSACTION + 25, 71 }; 72 73 DECLARE_META_INTERFACE(KeystoreService); 74 75 virtual int32_t test() = 0; 76 77 virtual int32_t get(const String16& name, uint8_t** item, size_t* itemLength) = 0; 78 79 virtual int32_t insert(const String16& name, const uint8_t* item, size_t itemLength, int uid, 80 int32_t flags) = 0; 81 82 virtual int32_t del(const String16& name, int uid) = 0; 83 84 virtual int32_t exist(const String16& name, int uid) = 0; 85 86 virtual int32_t saw(const String16& name, int uid, Vector<String16>* matches) = 0; 87 88 virtual int32_t reset() = 0; 89 90 virtual int32_t password(const String16& password) = 0; 91 92 virtual int32_t lock() = 0; 93 94 virtual int32_t unlock(const String16& password) = 0; 95 96 virtual int32_t zero() = 0; 97 98 virtual int32_t generate(const String16& name, int32_t uid, int32_t keyType, int32_t keySize, 99 int32_t flags, Vector<sp<KeystoreArg> >* args) = 0; 100 101 virtual int32_t import(const String16& name, const uint8_t* data, size_t length, int uid, 102 int32_t flags) = 0; 103 104 virtual int32_t sign(const String16& name, const uint8_t* data, size_t length, uint8_t** out, 105 size_t* outLength) = 0; 106 107 virtual int32_t verify(const String16& name, const uint8_t* data, size_t dataLength, 108 const uint8_t* signature, size_t signatureLength) = 0; 109 110 virtual int32_t get_pubkey(const String16& name, uint8_t** pubkey, size_t* pubkeyLength) = 0; 111 112 virtual int32_t del_key(const String16& name, int uid) = 0; 113 114 virtual int32_t grant(const String16& name, int32_t granteeUid) = 0; 115 116 virtual int32_t ungrant(const String16& name, int32_t granteeUid) = 0; 117 118 virtual int64_t getmtime(const String16& name) = 0; 119 120 virtual int32_t duplicate(const String16& srcKey, int32_t srcUid, const String16& destKey, 121 int32_t destUid) = 0; 122 123 virtual int32_t is_hardware_backed(const String16& keyType) = 0; 124 125 virtual int32_t clear_uid(int64_t uid) = 0; 126 127 virtual int32_t reset_uid(int32_t uid) = 0; 128 129 virtual int32_t sync_uid(int32_t sourceUid, int32_t targetUid) = 0; 130 131 virtual int32_t password_uid(const String16& password, int32_t uid) = 0; 132 }; 133 134 // ---------------------------------------------------------------------------- 135 136 class BnKeystoreService: public BnInterface<IKeystoreService> { 137 public: 138 virtual status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, 139 uint32_t flags = 0); 140 }; 141 142 } // namespace android 143 144 #endif 145