IKeystoreService.java revision 78ad849163a7b01073b46fbd7d818392720005d1
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 17package android.security; 18 19import android.os.Binder; 20import android.os.IBinder; 21import android.os.IInterface; 22import android.os.Parcel; 23import android.os.RemoteException; 24 25/** 26 * This must be kept manually in sync with system/security/keystore until AIDL 27 * can generate both Java and C++ bindings. 28 * 29 * @hide 30 */ 31public interface IKeystoreService extends IInterface { 32 public static abstract class Stub extends Binder implements IKeystoreService { 33 private static class Proxy implements IKeystoreService { 34 private final IBinder mRemote; 35 36 Proxy(IBinder remote) { 37 mRemote = remote; 38 } 39 40 public IBinder asBinder() { 41 return mRemote; 42 } 43 44 public String getInterfaceDescriptor() { 45 return DESCRIPTOR; 46 } 47 48 public int test() throws RemoteException { 49 Parcel _data = Parcel.obtain(); 50 Parcel _reply = Parcel.obtain(); 51 int _result; 52 try { 53 _data.writeInterfaceToken(DESCRIPTOR); 54 mRemote.transact(Stub.TRANSACTION_test, _data, _reply, 0); 55 _reply.readException(); 56 _result = _reply.readInt(); 57 } finally { 58 _reply.recycle(); 59 _data.recycle(); 60 } 61 return _result; 62 } 63 64 public byte[] get(String name) throws RemoteException { 65 Parcel _data = Parcel.obtain(); 66 Parcel _reply = Parcel.obtain(); 67 byte[] _result; 68 try { 69 _data.writeInterfaceToken(DESCRIPTOR); 70 _data.writeString(name); 71 mRemote.transact(Stub.TRANSACTION_get, _data, _reply, 0); 72 _reply.readException(); 73 _result = _reply.createByteArray(); 74 } finally { 75 _reply.recycle(); 76 _data.recycle(); 77 } 78 return _result; 79 } 80 81 public int insert(String name, byte[] item, int uid) throws RemoteException { 82 Parcel _data = Parcel.obtain(); 83 Parcel _reply = Parcel.obtain(); 84 int _result; 85 try { 86 _data.writeInterfaceToken(DESCRIPTOR); 87 _data.writeString(name); 88 _data.writeByteArray(item); 89 _data.writeInt(uid); 90 mRemote.transact(Stub.TRANSACTION_insert, _data, _reply, 0); 91 _reply.readException(); 92 _result = _reply.readInt(); 93 } finally { 94 _reply.recycle(); 95 _data.recycle(); 96 } 97 return _result; 98 } 99 100 public int del(String name, int uid) throws RemoteException { 101 Parcel _data = Parcel.obtain(); 102 Parcel _reply = Parcel.obtain(); 103 int _result; 104 try { 105 _data.writeInterfaceToken(DESCRIPTOR); 106 _data.writeString(name); 107 _data.writeInt(uid); 108 mRemote.transact(Stub.TRANSACTION_del, _data, _reply, 0); 109 _reply.readException(); 110 _result = _reply.readInt(); 111 } finally { 112 _reply.recycle(); 113 _data.recycle(); 114 } 115 return _result; 116 } 117 118 public int exist(String name, int uid) throws RemoteException { 119 Parcel _data = Parcel.obtain(); 120 Parcel _reply = Parcel.obtain(); 121 int _result; 122 try { 123 _data.writeInterfaceToken(DESCRIPTOR); 124 _data.writeString(name); 125 _data.writeInt(uid); 126 mRemote.transact(Stub.TRANSACTION_exist, _data, _reply, 0); 127 _reply.readException(); 128 _result = _reply.readInt(); 129 } finally { 130 _reply.recycle(); 131 _data.recycle(); 132 } 133 return _result; 134 } 135 136 public String[] saw(String name, int uid) throws RemoteException { 137 Parcel _data = Parcel.obtain(); 138 Parcel _reply = Parcel.obtain(); 139 String[] _result; 140 try { 141 _data.writeInterfaceToken(DESCRIPTOR); 142 _data.writeString(name); 143 _data.writeInt(uid); 144 mRemote.transact(Stub.TRANSACTION_saw, _data, _reply, 0); 145 _reply.readException(); 146 int size = _reply.readInt(); 147 _result = new String[size]; 148 for (int i = 0; i < size; i++) { 149 _result[i] = _reply.readString(); 150 } 151 int _ret = _reply.readInt(); 152 if (_ret != 1) { 153 return null; 154 } 155 } finally { 156 _reply.recycle(); 157 _data.recycle(); 158 } 159 return _result; 160 } 161 162 @Override 163 public int reset() throws RemoteException { 164 Parcel _data = Parcel.obtain(); 165 Parcel _reply = Parcel.obtain(); 166 int _result; 167 try { 168 _data.writeInterfaceToken(DESCRIPTOR); 169 mRemote.transact(Stub.TRANSACTION_reset, _data, _reply, 0); 170 _reply.readException(); 171 _result = _reply.readInt(); 172 } finally { 173 _reply.recycle(); 174 _data.recycle(); 175 } 176 return _result; 177 } 178 179 public int password(String password) throws RemoteException { 180 Parcel _data = Parcel.obtain(); 181 Parcel _reply = Parcel.obtain(); 182 int _result; 183 try { 184 _data.writeInterfaceToken(DESCRIPTOR); 185 _data.writeString(password); 186 mRemote.transact(Stub.TRANSACTION_password, _data, _reply, 0); 187 _reply.readException(); 188 _result = _reply.readInt(); 189 } finally { 190 _reply.recycle(); 191 _data.recycle(); 192 } 193 return _result; 194 } 195 196 public int lock() throws RemoteException { 197 Parcel _data = Parcel.obtain(); 198 Parcel _reply = Parcel.obtain(); 199 int _result; 200 try { 201 _data.writeInterfaceToken(DESCRIPTOR); 202 mRemote.transact(Stub.TRANSACTION_lock, _data, _reply, 0); 203 _reply.readException(); 204 _result = _reply.readInt(); 205 } finally { 206 _reply.recycle(); 207 _data.recycle(); 208 } 209 return _result; 210 } 211 212 public int unlock(String password) throws RemoteException { 213 Parcel _data = Parcel.obtain(); 214 Parcel _reply = Parcel.obtain(); 215 int _result; 216 try { 217 _data.writeInterfaceToken(DESCRIPTOR); 218 _data.writeString(password); 219 mRemote.transact(Stub.TRANSACTION_unlock, _data, _reply, 0); 220 _reply.readException(); 221 _result = _reply.readInt(); 222 } finally { 223 _reply.recycle(); 224 _data.recycle(); 225 } 226 return _result; 227 } 228 229 @Override 230 public int zero() throws RemoteException { 231 Parcel _data = Parcel.obtain(); 232 Parcel _reply = Parcel.obtain(); 233 int _result; 234 try { 235 _data.writeInterfaceToken(DESCRIPTOR); 236 mRemote.transact(Stub.TRANSACTION_zero, _data, _reply, 0); 237 _reply.readException(); 238 _result = _reply.readInt(); 239 } finally { 240 _reply.recycle(); 241 _data.recycle(); 242 } 243 return _result; 244 } 245 246 public int generate(String name, int uid) throws RemoteException { 247 Parcel _data = Parcel.obtain(); 248 Parcel _reply = Parcel.obtain(); 249 int _result; 250 try { 251 _data.writeInterfaceToken(DESCRIPTOR); 252 _data.writeString(name); 253 _data.writeInt(uid); 254 mRemote.transact(Stub.TRANSACTION_generate, _data, _reply, 0); 255 _reply.readException(); 256 _result = _reply.readInt(); 257 } finally { 258 _reply.recycle(); 259 _data.recycle(); 260 } 261 return _result; 262 } 263 264 public int import_key(String name, byte[] data, int uid) throws RemoteException { 265 Parcel _data = Parcel.obtain(); 266 Parcel _reply = Parcel.obtain(); 267 int _result; 268 try { 269 _data.writeInterfaceToken(DESCRIPTOR); 270 _data.writeString(name); 271 _data.writeByteArray(data); 272 _data.writeInt(uid); 273 mRemote.transact(Stub.TRANSACTION_import, _data, _reply, 0); 274 _reply.readException(); 275 _result = _reply.readInt(); 276 } finally { 277 _reply.recycle(); 278 _data.recycle(); 279 } 280 return _result; 281 } 282 283 public byte[] sign(String name, byte[] data) throws RemoteException { 284 Parcel _data = Parcel.obtain(); 285 Parcel _reply = Parcel.obtain(); 286 byte[] _result; 287 try { 288 _data.writeInterfaceToken(DESCRIPTOR); 289 _data.writeString(name); 290 _data.writeByteArray(data); 291 mRemote.transact(Stub.TRANSACTION_sign, _data, _reply, 0); 292 _reply.readException(); 293 _result = _reply.createByteArray(); 294 } finally { 295 _reply.recycle(); 296 _data.recycle(); 297 } 298 return _result; 299 } 300 301 public int verify(String name, byte[] data, byte[] signature) throws RemoteException { 302 Parcel _data = Parcel.obtain(); 303 Parcel _reply = Parcel.obtain(); 304 int _result; 305 try { 306 _data.writeInterfaceToken(DESCRIPTOR); 307 _data.writeString(name); 308 _data.writeByteArray(data); 309 _data.writeByteArray(signature); 310 mRemote.transact(Stub.TRANSACTION_verify, _data, _reply, 0); 311 _reply.readException(); 312 _result = _reply.readInt(); 313 } finally { 314 _reply.recycle(); 315 _data.recycle(); 316 } 317 return _result; 318 } 319 320 public byte[] get_pubkey(String name) throws RemoteException { 321 Parcel _data = Parcel.obtain(); 322 Parcel _reply = Parcel.obtain(); 323 byte[] _result; 324 try { 325 _data.writeInterfaceToken(DESCRIPTOR); 326 _data.writeString(name); 327 mRemote.transact(Stub.TRANSACTION_get_pubkey, _data, _reply, 0); 328 _reply.readException(); 329 _result = _reply.createByteArray(); 330 } finally { 331 _reply.recycle(); 332 _data.recycle(); 333 } 334 return _result; 335 } 336 337 public int del_key(String name, int uid) throws RemoteException { 338 Parcel _data = Parcel.obtain(); 339 Parcel _reply = Parcel.obtain(); 340 int _result; 341 try { 342 _data.writeInterfaceToken(DESCRIPTOR); 343 _data.writeString(name); 344 _data.writeInt(uid); 345 mRemote.transact(Stub.TRANSACTION_del_key, _data, _reply, 0); 346 _reply.readException(); 347 _result = _reply.readInt(); 348 } finally { 349 _reply.recycle(); 350 _data.recycle(); 351 } 352 return _result; 353 } 354 355 public int grant(String name, int granteeUid) throws RemoteException { 356 Parcel _data = Parcel.obtain(); 357 Parcel _reply = Parcel.obtain(); 358 int _result; 359 try { 360 _data.writeInterfaceToken(DESCRIPTOR); 361 _data.writeString(name); 362 _data.writeInt(granteeUid); 363 mRemote.transact(Stub.TRANSACTION_grant, _data, _reply, 0); 364 _reply.readException(); 365 _result = _reply.readInt(); 366 } finally { 367 _reply.recycle(); 368 _data.recycle(); 369 } 370 return _result; 371 } 372 373 public int ungrant(String name, int granteeUid) throws RemoteException { 374 Parcel _data = Parcel.obtain(); 375 Parcel _reply = Parcel.obtain(); 376 int _result; 377 try { 378 _data.writeInterfaceToken(DESCRIPTOR); 379 _data.writeString(name); 380 _data.writeInt(granteeUid); 381 mRemote.transact(Stub.TRANSACTION_ungrant, _data, _reply, 0); 382 _reply.readException(); 383 _result = _reply.readInt(); 384 } finally { 385 _reply.recycle(); 386 _data.recycle(); 387 } 388 return _result; 389 } 390 391 @Override 392 public long getmtime(String name) throws RemoteException { 393 Parcel _data = Parcel.obtain(); 394 Parcel _reply = Parcel.obtain(); 395 long _result; 396 try { 397 _data.writeInterfaceToken(DESCRIPTOR); 398 _data.writeString(name); 399 mRemote.transact(Stub.TRANSACTION_getmtime, _data, _reply, 0); 400 _reply.readException(); 401 _result = _reply.readLong(); 402 } finally { 403 _reply.recycle(); 404 _data.recycle(); 405 } 406 return _result; 407 } 408 } 409 410 private static final String DESCRIPTOR = "android.security.keystore"; 411 412 static final int TRANSACTION_test = IBinder.FIRST_CALL_TRANSACTION + 0; 413 static final int TRANSACTION_get = IBinder.FIRST_CALL_TRANSACTION + 1; 414 static final int TRANSACTION_insert = IBinder.FIRST_CALL_TRANSACTION + 2; 415 static final int TRANSACTION_del = IBinder.FIRST_CALL_TRANSACTION + 3; 416 static final int TRANSACTION_exist = IBinder.FIRST_CALL_TRANSACTION + 4; 417 static final int TRANSACTION_saw = IBinder.FIRST_CALL_TRANSACTION + 5; 418 static final int TRANSACTION_reset = IBinder.FIRST_CALL_TRANSACTION + 6; 419 static final int TRANSACTION_password = IBinder.FIRST_CALL_TRANSACTION + 7; 420 static final int TRANSACTION_lock = IBinder.FIRST_CALL_TRANSACTION + 8; 421 static final int TRANSACTION_unlock = IBinder.FIRST_CALL_TRANSACTION + 9; 422 static final int TRANSACTION_zero = IBinder.FIRST_CALL_TRANSACTION + 10; 423 static final int TRANSACTION_generate = IBinder.FIRST_CALL_TRANSACTION + 11; 424 static final int TRANSACTION_import = IBinder.FIRST_CALL_TRANSACTION + 12; 425 static final int TRANSACTION_sign = IBinder.FIRST_CALL_TRANSACTION + 13; 426 static final int TRANSACTION_verify = IBinder.FIRST_CALL_TRANSACTION + 14; 427 static final int TRANSACTION_get_pubkey = IBinder.FIRST_CALL_TRANSACTION + 15; 428 static final int TRANSACTION_del_key = IBinder.FIRST_CALL_TRANSACTION + 16; 429 static final int TRANSACTION_grant = IBinder.FIRST_CALL_TRANSACTION + 17; 430 static final int TRANSACTION_ungrant = IBinder.FIRST_CALL_TRANSACTION + 18; 431 static final int TRANSACTION_getmtime = IBinder.FIRST_CALL_TRANSACTION + 19; 432 433 /** 434 * Cast an IBinder object into an IKeystoreService interface, generating 435 * a proxy if needed. 436 */ 437 public static IKeystoreService asInterface(IBinder obj) { 438 if (obj == null) { 439 return null; 440 } 441 IInterface iin = obj.queryLocalInterface(DESCRIPTOR); 442 if (iin != null && iin instanceof IKeystoreService) { 443 return (IKeystoreService) iin; 444 } 445 return new IKeystoreService.Stub.Proxy(obj); 446 } 447 448 /** Construct the stub at attach it to the interface. */ 449 public Stub() { 450 attachInterface(this, DESCRIPTOR); 451 } 452 453 public IBinder asBinder() { 454 return this; 455 } 456 457 @Override 458 public boolean onTransact(int code, Parcel data, Parcel reply, int flags) 459 throws RemoteException { 460 switch (code) { 461 case INTERFACE_TRANSACTION: { 462 reply.writeString(DESCRIPTOR); 463 return true; 464 } 465 case TRANSACTION_test: { 466 data.enforceInterface(DESCRIPTOR); 467 int resultCode = test(); 468 reply.writeNoException(); 469 reply.writeInt(resultCode); 470 return true; 471 } 472 } 473 return super.onTransact(code, data, reply, flags); 474 } 475 } 476 477 public int test() throws RemoteException; 478 479 public byte[] get(String name) throws RemoteException; 480 481 public int insert(String name, byte[] item, int uid) throws RemoteException; 482 483 public int del(String name, int uid) throws RemoteException; 484 485 public int exist(String name, int uid) throws RemoteException; 486 487 public String[] saw(String name, int uid) throws RemoteException; 488 489 public int reset() throws RemoteException; 490 491 public int password(String password) throws RemoteException; 492 493 public int lock() throws RemoteException; 494 495 public int unlock(String password) throws RemoteException; 496 497 public int zero() throws RemoteException; 498 499 public int generate(String name, int uid) throws RemoteException; 500 501 public int import_key(String name, byte[] data, int uid) throws RemoteException; 502 503 public byte[] sign(String name, byte[] data) throws RemoteException; 504 505 public int verify(String name, byte[] data, byte[] signature) throws RemoteException; 506 507 public byte[] get_pubkey(String name) throws RemoteException; 508 509 public int del_key(String name, int uid) throws RemoteException; 510 511 public int grant(String name, int granteeUid) throws RemoteException; 512 513 public int ungrant(String name, int granteeUid) throws RemoteException; 514 515 public long getmtime(String name) throws RemoteException; 516} 517