IKeystoreService.java revision a39859889b7de0ad3190386cc732fa4bdcbe5504
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, int flags) 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 _data.writeInt(flags); 91 mRemote.transact(Stub.TRANSACTION_insert, _data, _reply, 0); 92 _reply.readException(); 93 _result = _reply.readInt(); 94 } finally { 95 _reply.recycle(); 96 _data.recycle(); 97 } 98 return _result; 99 } 100 101 public int del(String name, int uid) throws RemoteException { 102 Parcel _data = Parcel.obtain(); 103 Parcel _reply = Parcel.obtain(); 104 int _result; 105 try { 106 _data.writeInterfaceToken(DESCRIPTOR); 107 _data.writeString(name); 108 _data.writeInt(uid); 109 mRemote.transact(Stub.TRANSACTION_del, _data, _reply, 0); 110 _reply.readException(); 111 _result = _reply.readInt(); 112 } finally { 113 _reply.recycle(); 114 _data.recycle(); 115 } 116 return _result; 117 } 118 119 public int exist(String name, int uid) throws RemoteException { 120 Parcel _data = Parcel.obtain(); 121 Parcel _reply = Parcel.obtain(); 122 int _result; 123 try { 124 _data.writeInterfaceToken(DESCRIPTOR); 125 _data.writeString(name); 126 _data.writeInt(uid); 127 mRemote.transact(Stub.TRANSACTION_exist, _data, _reply, 0); 128 _reply.readException(); 129 _result = _reply.readInt(); 130 } finally { 131 _reply.recycle(); 132 _data.recycle(); 133 } 134 return _result; 135 } 136 137 public String[] saw(String name, int uid) throws RemoteException { 138 Parcel _data = Parcel.obtain(); 139 Parcel _reply = Parcel.obtain(); 140 String[] _result; 141 try { 142 _data.writeInterfaceToken(DESCRIPTOR); 143 _data.writeString(name); 144 _data.writeInt(uid); 145 mRemote.transact(Stub.TRANSACTION_saw, _data, _reply, 0); 146 _reply.readException(); 147 int size = _reply.readInt(); 148 _result = new String[size]; 149 for (int i = 0; i < size; i++) { 150 _result[i] = _reply.readString(); 151 } 152 int _ret = _reply.readInt(); 153 if (_ret != 1) { 154 return null; 155 } 156 } finally { 157 _reply.recycle(); 158 _data.recycle(); 159 } 160 return _result; 161 } 162 163 @Override 164 public int reset() throws RemoteException { 165 Parcel _data = Parcel.obtain(); 166 Parcel _reply = Parcel.obtain(); 167 int _result; 168 try { 169 _data.writeInterfaceToken(DESCRIPTOR); 170 mRemote.transact(Stub.TRANSACTION_reset, _data, _reply, 0); 171 _reply.readException(); 172 _result = _reply.readInt(); 173 } finally { 174 _reply.recycle(); 175 _data.recycle(); 176 } 177 return _result; 178 } 179 180 public int password(String password) throws RemoteException { 181 Parcel _data = Parcel.obtain(); 182 Parcel _reply = Parcel.obtain(); 183 int _result; 184 try { 185 _data.writeInterfaceToken(DESCRIPTOR); 186 _data.writeString(password); 187 mRemote.transact(Stub.TRANSACTION_password, _data, _reply, 0); 188 _reply.readException(); 189 _result = _reply.readInt(); 190 } finally { 191 _reply.recycle(); 192 _data.recycle(); 193 } 194 return _result; 195 } 196 197 public int lock() throws RemoteException { 198 Parcel _data = Parcel.obtain(); 199 Parcel _reply = Parcel.obtain(); 200 int _result; 201 try { 202 _data.writeInterfaceToken(DESCRIPTOR); 203 mRemote.transact(Stub.TRANSACTION_lock, _data, _reply, 0); 204 _reply.readException(); 205 _result = _reply.readInt(); 206 } finally { 207 _reply.recycle(); 208 _data.recycle(); 209 } 210 return _result; 211 } 212 213 public int unlock(String password) throws RemoteException { 214 Parcel _data = Parcel.obtain(); 215 Parcel _reply = Parcel.obtain(); 216 int _result; 217 try { 218 _data.writeInterfaceToken(DESCRIPTOR); 219 _data.writeString(password); 220 mRemote.transact(Stub.TRANSACTION_unlock, _data, _reply, 0); 221 _reply.readException(); 222 _result = _reply.readInt(); 223 } finally { 224 _reply.recycle(); 225 _data.recycle(); 226 } 227 return _result; 228 } 229 230 @Override 231 public int zero() throws RemoteException { 232 Parcel _data = Parcel.obtain(); 233 Parcel _reply = Parcel.obtain(); 234 int _result; 235 try { 236 _data.writeInterfaceToken(DESCRIPTOR); 237 mRemote.transact(Stub.TRANSACTION_zero, _data, _reply, 0); 238 _reply.readException(); 239 _result = _reply.readInt(); 240 } finally { 241 _reply.recycle(); 242 _data.recycle(); 243 } 244 return _result; 245 } 246 247 public int generate(String name, int uid, int keyType, int keySize, int flags, 248 byte[][] args) throws RemoteException { 249 Parcel _data = Parcel.obtain(); 250 Parcel _reply = Parcel.obtain(); 251 int _result; 252 try { 253 _data.writeInterfaceToken(DESCRIPTOR); 254 _data.writeString(name); 255 _data.writeInt(uid); 256 _data.writeInt(keyType); 257 _data.writeInt(keySize); 258 _data.writeInt(flags); 259 if (args == null) { 260 _data.writeInt(0); 261 } else { 262 _data.writeInt(args.length); 263 for (int i = 0; i < args.length; i++) { 264 _data.writeByteArray(args[i]); 265 } 266 } 267 mRemote.transact(Stub.TRANSACTION_generate, _data, _reply, 0); 268 _reply.readException(); 269 _result = _reply.readInt(); 270 } finally { 271 _reply.recycle(); 272 _data.recycle(); 273 } 274 return _result; 275 } 276 277 public int import_key(String name, byte[] data, int uid, int flags) 278 throws RemoteException { 279 Parcel _data = Parcel.obtain(); 280 Parcel _reply = Parcel.obtain(); 281 int _result; 282 try { 283 _data.writeInterfaceToken(DESCRIPTOR); 284 _data.writeString(name); 285 _data.writeByteArray(data); 286 _data.writeInt(uid); 287 _data.writeInt(flags); 288 mRemote.transact(Stub.TRANSACTION_import, _data, _reply, 0); 289 _reply.readException(); 290 _result = _reply.readInt(); 291 } finally { 292 _reply.recycle(); 293 _data.recycle(); 294 } 295 return _result; 296 } 297 298 public byte[] sign(String name, byte[] data) throws RemoteException { 299 Parcel _data = Parcel.obtain(); 300 Parcel _reply = Parcel.obtain(); 301 byte[] _result; 302 try { 303 _data.writeInterfaceToken(DESCRIPTOR); 304 _data.writeString(name); 305 _data.writeByteArray(data); 306 mRemote.transact(Stub.TRANSACTION_sign, _data, _reply, 0); 307 _reply.readException(); 308 _result = _reply.createByteArray(); 309 } finally { 310 _reply.recycle(); 311 _data.recycle(); 312 } 313 return _result; 314 } 315 316 public int verify(String name, byte[] data, byte[] signature) throws RemoteException { 317 Parcel _data = Parcel.obtain(); 318 Parcel _reply = Parcel.obtain(); 319 int _result; 320 try { 321 _data.writeInterfaceToken(DESCRIPTOR); 322 _data.writeString(name); 323 _data.writeByteArray(data); 324 _data.writeByteArray(signature); 325 mRemote.transact(Stub.TRANSACTION_verify, _data, _reply, 0); 326 _reply.readException(); 327 _result = _reply.readInt(); 328 } finally { 329 _reply.recycle(); 330 _data.recycle(); 331 } 332 return _result; 333 } 334 335 public byte[] get_pubkey(String name) throws RemoteException { 336 Parcel _data = Parcel.obtain(); 337 Parcel _reply = Parcel.obtain(); 338 byte[] _result; 339 try { 340 _data.writeInterfaceToken(DESCRIPTOR); 341 _data.writeString(name); 342 mRemote.transact(Stub.TRANSACTION_get_pubkey, _data, _reply, 0); 343 _reply.readException(); 344 _result = _reply.createByteArray(); 345 } finally { 346 _reply.recycle(); 347 _data.recycle(); 348 } 349 return _result; 350 } 351 352 public int del_key(String name, int uid) throws RemoteException { 353 Parcel _data = Parcel.obtain(); 354 Parcel _reply = Parcel.obtain(); 355 int _result; 356 try { 357 _data.writeInterfaceToken(DESCRIPTOR); 358 _data.writeString(name); 359 _data.writeInt(uid); 360 mRemote.transact(Stub.TRANSACTION_del_key, _data, _reply, 0); 361 _reply.readException(); 362 _result = _reply.readInt(); 363 } finally { 364 _reply.recycle(); 365 _data.recycle(); 366 } 367 return _result; 368 } 369 370 public int grant(String name, int granteeUid) throws RemoteException { 371 Parcel _data = Parcel.obtain(); 372 Parcel _reply = Parcel.obtain(); 373 int _result; 374 try { 375 _data.writeInterfaceToken(DESCRIPTOR); 376 _data.writeString(name); 377 _data.writeInt(granteeUid); 378 mRemote.transact(Stub.TRANSACTION_grant, _data, _reply, 0); 379 _reply.readException(); 380 _result = _reply.readInt(); 381 } finally { 382 _reply.recycle(); 383 _data.recycle(); 384 } 385 return _result; 386 } 387 388 public int ungrant(String name, int granteeUid) throws RemoteException { 389 Parcel _data = Parcel.obtain(); 390 Parcel _reply = Parcel.obtain(); 391 int _result; 392 try { 393 _data.writeInterfaceToken(DESCRIPTOR); 394 _data.writeString(name); 395 _data.writeInt(granteeUid); 396 mRemote.transact(Stub.TRANSACTION_ungrant, _data, _reply, 0); 397 _reply.readException(); 398 _result = _reply.readInt(); 399 } finally { 400 _reply.recycle(); 401 _data.recycle(); 402 } 403 return _result; 404 } 405 406 @Override 407 public long getmtime(String name) throws RemoteException { 408 Parcel _data = Parcel.obtain(); 409 Parcel _reply = Parcel.obtain(); 410 long _result; 411 try { 412 _data.writeInterfaceToken(DESCRIPTOR); 413 _data.writeString(name); 414 mRemote.transact(Stub.TRANSACTION_getmtime, _data, _reply, 0); 415 _reply.readException(); 416 _result = _reply.readLong(); 417 } finally { 418 _reply.recycle(); 419 _data.recycle(); 420 } 421 return _result; 422 } 423 424 @Override 425 public int duplicate(String srcKey, int srcUid, String destKey, int destUid) 426 throws RemoteException { 427 Parcel _data = Parcel.obtain(); 428 Parcel _reply = Parcel.obtain(); 429 int _result; 430 try { 431 _data.writeInterfaceToken(DESCRIPTOR); 432 _data.writeString(srcKey); 433 _data.writeInt(srcUid); 434 _data.writeString(destKey); 435 _data.writeInt(destUid); 436 mRemote.transact(Stub.TRANSACTION_duplicate, _data, _reply, 0); 437 _reply.readException(); 438 _result = _reply.readInt(); 439 } finally { 440 _reply.recycle(); 441 _data.recycle(); 442 } 443 return _result; 444 } 445 446 @Override 447 public int is_hardware_backed() throws RemoteException { 448 Parcel _data = Parcel.obtain(); 449 Parcel _reply = Parcel.obtain(); 450 int _result; 451 try { 452 _data.writeInterfaceToken(DESCRIPTOR); 453 mRemote.transact(Stub.TRANSACTION_is_hardware_backed, _data, _reply, 0); 454 _reply.readException(); 455 _result = _reply.readInt(); 456 } finally { 457 _reply.recycle(); 458 _data.recycle(); 459 } 460 return _result; 461 } 462 463 @Override 464 public int clear_uid(long uid) throws RemoteException { 465 Parcel _data = Parcel.obtain(); 466 Parcel _reply = Parcel.obtain(); 467 int _result; 468 try { 469 _data.writeInterfaceToken(DESCRIPTOR); 470 _data.writeLong(uid); 471 mRemote.transact(Stub.TRANSACTION_clear_uid, _data, _reply, 0); 472 _reply.readException(); 473 _result = _reply.readInt(); 474 } finally { 475 _reply.recycle(); 476 _data.recycle(); 477 } 478 return _result; 479 } 480 } 481 482 private static final String DESCRIPTOR = "android.security.keystore"; 483 484 static final int TRANSACTION_test = IBinder.FIRST_CALL_TRANSACTION + 0; 485 static final int TRANSACTION_get = IBinder.FIRST_CALL_TRANSACTION + 1; 486 static final int TRANSACTION_insert = IBinder.FIRST_CALL_TRANSACTION + 2; 487 static final int TRANSACTION_del = IBinder.FIRST_CALL_TRANSACTION + 3; 488 static final int TRANSACTION_exist = IBinder.FIRST_CALL_TRANSACTION + 4; 489 static final int TRANSACTION_saw = IBinder.FIRST_CALL_TRANSACTION + 5; 490 static final int TRANSACTION_reset = IBinder.FIRST_CALL_TRANSACTION + 6; 491 static final int TRANSACTION_password = IBinder.FIRST_CALL_TRANSACTION + 7; 492 static final int TRANSACTION_lock = IBinder.FIRST_CALL_TRANSACTION + 8; 493 static final int TRANSACTION_unlock = IBinder.FIRST_CALL_TRANSACTION + 9; 494 static final int TRANSACTION_zero = IBinder.FIRST_CALL_TRANSACTION + 10; 495 static final int TRANSACTION_generate = IBinder.FIRST_CALL_TRANSACTION + 11; 496 static final int TRANSACTION_import = IBinder.FIRST_CALL_TRANSACTION + 12; 497 static final int TRANSACTION_sign = IBinder.FIRST_CALL_TRANSACTION + 13; 498 static final int TRANSACTION_verify = IBinder.FIRST_CALL_TRANSACTION + 14; 499 static final int TRANSACTION_get_pubkey = IBinder.FIRST_CALL_TRANSACTION + 15; 500 static final int TRANSACTION_del_key = IBinder.FIRST_CALL_TRANSACTION + 16; 501 static final int TRANSACTION_grant = IBinder.FIRST_CALL_TRANSACTION + 17; 502 static final int TRANSACTION_ungrant = IBinder.FIRST_CALL_TRANSACTION + 18; 503 static final int TRANSACTION_getmtime = IBinder.FIRST_CALL_TRANSACTION + 19; 504 static final int TRANSACTION_duplicate = IBinder.FIRST_CALL_TRANSACTION + 20; 505 static final int TRANSACTION_is_hardware_backed = IBinder.FIRST_CALL_TRANSACTION + 21; 506 static final int TRANSACTION_clear_uid = IBinder.FIRST_CALL_TRANSACTION + 22; 507 508 /** 509 * Cast an IBinder object into an IKeystoreService interface, generating 510 * a proxy if needed. 511 */ 512 public static IKeystoreService asInterface(IBinder obj) { 513 if (obj == null) { 514 return null; 515 } 516 IInterface iin = obj.queryLocalInterface(DESCRIPTOR); 517 if (iin != null && iin instanceof IKeystoreService) { 518 return (IKeystoreService) iin; 519 } 520 return new IKeystoreService.Stub.Proxy(obj); 521 } 522 523 /** Construct the stub at attach it to the interface. */ 524 public Stub() { 525 attachInterface(this, DESCRIPTOR); 526 } 527 528 public IBinder asBinder() { 529 return this; 530 } 531 532 @Override 533 public boolean onTransact(int code, Parcel data, Parcel reply, int flags) 534 throws RemoteException { 535 switch (code) { 536 case INTERFACE_TRANSACTION: { 537 reply.writeString(DESCRIPTOR); 538 return true; 539 } 540 case TRANSACTION_test: { 541 data.enforceInterface(DESCRIPTOR); 542 int resultCode = test(); 543 reply.writeNoException(); 544 reply.writeInt(resultCode); 545 return true; 546 } 547 } 548 return super.onTransact(code, data, reply, flags); 549 } 550 } 551 552 public int test() throws RemoteException; 553 554 public byte[] get(String name) throws RemoteException; 555 556 public int insert(String name, byte[] item, int uid, int flags) throws RemoteException; 557 558 public int del(String name, int uid) throws RemoteException; 559 560 public int exist(String name, int uid) throws RemoteException; 561 562 public String[] saw(String name, int uid) throws RemoteException; 563 564 public int reset() throws RemoteException; 565 566 public int password(String password) throws RemoteException; 567 568 public int lock() throws RemoteException; 569 570 public int unlock(String password) throws RemoteException; 571 572 public int zero() throws RemoteException; 573 574 public int generate(String name, int uid, int keyType, int keySize, int flags, byte[][] args) 575 throws RemoteException; 576 577 public int import_key(String name, byte[] data, int uid, int flags) throws RemoteException; 578 579 public byte[] sign(String name, byte[] data) throws RemoteException; 580 581 public int verify(String name, byte[] data, byte[] signature) throws RemoteException; 582 583 public byte[] get_pubkey(String name) throws RemoteException; 584 585 public int del_key(String name, int uid) throws RemoteException; 586 587 public int grant(String name, int granteeUid) throws RemoteException; 588 589 public int ungrant(String name, int granteeUid) throws RemoteException; 590 591 public long getmtime(String name) throws RemoteException; 592 593 public int duplicate(String srcKey, int srcUid, String destKey, int destUid) 594 throws RemoteException; 595 596 public int is_hardware_backed() throws RemoteException; 597 598 public int clear_uid(long uid) throws RemoteException; 599} 600