blob: f8bf45b4a7a1e4bfc16d7fd65abb226d56ceacad [file] [log] [blame]
Kenny Root6b776452012-11-02 15:40:32 -07001/*
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
Kenny Roota3788b02013-04-10 10:37:55 -070081 public int insert(String name, byte[] item, int uid, int flags) throws RemoteException {
Kenny Root6b776452012-11-02 15:40:32 -070082 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);
Kenny Roote151f282013-02-13 15:22:25 -080089 _data.writeInt(uid);
Kenny Roota3788b02013-04-10 10:37:55 -070090 _data.writeInt(flags);
Kenny Root6b776452012-11-02 15:40:32 -070091 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
Kenny Roote151f282013-02-13 15:22:25 -0800101 public int del(String name, int uid) throws RemoteException {
Kenny Root6b776452012-11-02 15:40:32 -0700102 Parcel _data = Parcel.obtain();
103 Parcel _reply = Parcel.obtain();
104 int _result;
105 try {
106 _data.writeInterfaceToken(DESCRIPTOR);
107 _data.writeString(name);
Kenny Roote151f282013-02-13 15:22:25 -0800108 _data.writeInt(uid);
Kenny Root6b776452012-11-02 15:40:32 -0700109 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
Kenny Roote151f282013-02-13 15:22:25 -0800119 public int exist(String name, int uid) throws RemoteException {
Kenny Root6b776452012-11-02 15:40:32 -0700120 Parcel _data = Parcel.obtain();
121 Parcel _reply = Parcel.obtain();
122 int _result;
123 try {
124 _data.writeInterfaceToken(DESCRIPTOR);
125 _data.writeString(name);
Kenny Roote151f282013-02-13 15:22:25 -0800126 _data.writeInt(uid);
Kenny Root6b776452012-11-02 15:40:32 -0700127 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
Kenny Roote151f282013-02-13 15:22:25 -0800137 public String[] saw(String name, int uid) throws RemoteException {
Kenny Root6b776452012-11-02 15:40:32 -0700138 Parcel _data = Parcel.obtain();
139 Parcel _reply = Parcel.obtain();
140 String[] _result;
141 try {
142 _data.writeInterfaceToken(DESCRIPTOR);
143 _data.writeString(name);
Kenny Roote151f282013-02-13 15:22:25 -0800144 _data.writeInt(uid);
Kenny Root6b776452012-11-02 15:40:32 -0700145 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 }
Kenny Root78ad8492013-02-13 17:02:57 -0800152 int _ret = _reply.readInt();
153 if (_ret != 1) {
154 return null;
155 }
Kenny Root6b776452012-11-02 15:40:32 -0700156 } 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
Kenny Roota3985982013-08-16 14:03:29 -0700247 public int generate(String name, int uid, int keyType, int keySize, int flags,
248 byte[][] args) throws RemoteException {
Kenny Root6b776452012-11-02 15:40:32 -0700249 Parcel _data = Parcel.obtain();
250 Parcel _reply = Parcel.obtain();
251 int _result;
252 try {
253 _data.writeInterfaceToken(DESCRIPTOR);
254 _data.writeString(name);
Kenny Roote151f282013-02-13 15:22:25 -0800255 _data.writeInt(uid);
Kenny Roota3985982013-08-16 14:03:29 -0700256 _data.writeInt(keyType);
257 _data.writeInt(keySize);
Kenny Roota3788b02013-04-10 10:37:55 -0700258 _data.writeInt(flags);
Kenny Roota3985982013-08-16 14:03:29 -0700259 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 }
Kenny Root6b776452012-11-02 15:40:32 -0700267 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
Kenny Roota3788b02013-04-10 10:37:55 -0700277 public int import_key(String name, byte[] data, int uid, int flags)
278 throws RemoteException {
Kenny Root6b776452012-11-02 15:40:32 -0700279 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);
Kenny Roote151f282013-02-13 15:22:25 -0800286 _data.writeInt(uid);
Kenny Roota3788b02013-04-10 10:37:55 -0700287 _data.writeInt(flags);
Kenny Root6b776452012-11-02 15:40:32 -0700288 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
Kenny Roote151f282013-02-13 15:22:25 -0800352 public int del_key(String name, int uid) throws RemoteException {
Kenny Root6b776452012-11-02 15:40:32 -0700353 Parcel _data = Parcel.obtain();
354 Parcel _reply = Parcel.obtain();
355 int _result;
356 try {
357 _data.writeInterfaceToken(DESCRIPTOR);
358 _data.writeString(name);
Kenny Roote151f282013-02-13 15:22:25 -0800359 _data.writeInt(uid);
Kenny Root6b776452012-11-02 15:40:32 -0700360 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 }
Kenny Rootbd794192013-03-20 11:36:50 -0700423
424 @Override
Kenny Root5f1d9652013-03-21 14:21:50 -0700425 public int duplicate(String srcKey, int srcUid, String destKey, int destUid)
426 throws RemoteException {
Kenny Rootbd794192013-03-20 11:36:50 -0700427 Parcel _data = Parcel.obtain();
428 Parcel _reply = Parcel.obtain();
429 int _result;
430 try {
431 _data.writeInterfaceToken(DESCRIPTOR);
Kenny Root5f1d9652013-03-21 14:21:50 -0700432 _data.writeString(srcKey);
433 _data.writeInt(srcUid);
434 _data.writeString(destKey);
435 _data.writeInt(destUid);
436 mRemote.transact(Stub.TRANSACTION_duplicate, _data, _reply, 0);
Kenny Rootbd794192013-03-20 11:36:50 -0700437 _reply.readException();
438 _result = _reply.readInt();
439 } finally {
440 _reply.recycle();
441 _data.recycle();
442 }
443 return _result;
444 }
Kenny Root5cb5cec2013-03-29 11:14:17 -0700445
446 @Override
Kenny Rootb91773b2013-09-05 13:03:16 -0700447 public int is_hardware_backed(String keyType) throws RemoteException {
Kenny Root5cb5cec2013-03-29 11:14:17 -0700448 Parcel _data = Parcel.obtain();
449 Parcel _reply = Parcel.obtain();
450 int _result;
451 try {
452 _data.writeInterfaceToken(DESCRIPTOR);
Kenny Rootb91773b2013-09-05 13:03:16 -0700453 _data.writeString(keyType);
Kenny Root5cb5cec2013-03-29 11:14:17 -0700454 mRemote.transact(Stub.TRANSACTION_is_hardware_backed, _data, _reply, 0);
455 _reply.readException();
456 _result = _reply.readInt();
457 } finally {
458 _reply.recycle();
459 _data.recycle();
460 }
461 return _result;
462 }
Kenny Rootd72317a2013-04-01 15:59:59 -0700463
464 @Override
465 public int clear_uid(long uid) throws RemoteException {
466 Parcel _data = Parcel.obtain();
467 Parcel _reply = Parcel.obtain();
468 int _result;
469 try {
470 _data.writeInterfaceToken(DESCRIPTOR);
471 _data.writeLong(uid);
472 mRemote.transact(Stub.TRANSACTION_clear_uid, _data, _reply, 0);
473 _reply.readException();
474 _result = _reply.readInt();
475 } finally {
476 _reply.recycle();
477 _data.recycle();
478 }
479 return _result;
480 }
Kenny Root6b776452012-11-02 15:40:32 -0700481 }
482
483 private static final String DESCRIPTOR = "android.security.keystore";
484
485 static final int TRANSACTION_test = IBinder.FIRST_CALL_TRANSACTION + 0;
486 static final int TRANSACTION_get = IBinder.FIRST_CALL_TRANSACTION + 1;
487 static final int TRANSACTION_insert = IBinder.FIRST_CALL_TRANSACTION + 2;
488 static final int TRANSACTION_del = IBinder.FIRST_CALL_TRANSACTION + 3;
489 static final int TRANSACTION_exist = IBinder.FIRST_CALL_TRANSACTION + 4;
490 static final int TRANSACTION_saw = IBinder.FIRST_CALL_TRANSACTION + 5;
491 static final int TRANSACTION_reset = IBinder.FIRST_CALL_TRANSACTION + 6;
492 static final int TRANSACTION_password = IBinder.FIRST_CALL_TRANSACTION + 7;
493 static final int TRANSACTION_lock = IBinder.FIRST_CALL_TRANSACTION + 8;
494 static final int TRANSACTION_unlock = IBinder.FIRST_CALL_TRANSACTION + 9;
495 static final int TRANSACTION_zero = IBinder.FIRST_CALL_TRANSACTION + 10;
496 static final int TRANSACTION_generate = IBinder.FIRST_CALL_TRANSACTION + 11;
497 static final int TRANSACTION_import = IBinder.FIRST_CALL_TRANSACTION + 12;
498 static final int TRANSACTION_sign = IBinder.FIRST_CALL_TRANSACTION + 13;
499 static final int TRANSACTION_verify = IBinder.FIRST_CALL_TRANSACTION + 14;
500 static final int TRANSACTION_get_pubkey = IBinder.FIRST_CALL_TRANSACTION + 15;
501 static final int TRANSACTION_del_key = IBinder.FIRST_CALL_TRANSACTION + 16;
502 static final int TRANSACTION_grant = IBinder.FIRST_CALL_TRANSACTION + 17;
503 static final int TRANSACTION_ungrant = IBinder.FIRST_CALL_TRANSACTION + 18;
504 static final int TRANSACTION_getmtime = IBinder.FIRST_CALL_TRANSACTION + 19;
Kenny Root5f1d9652013-03-21 14:21:50 -0700505 static final int TRANSACTION_duplicate = IBinder.FIRST_CALL_TRANSACTION + 20;
Kenny Root5cb5cec2013-03-29 11:14:17 -0700506 static final int TRANSACTION_is_hardware_backed = IBinder.FIRST_CALL_TRANSACTION + 21;
Kenny Rootd72317a2013-04-01 15:59:59 -0700507 static final int TRANSACTION_clear_uid = IBinder.FIRST_CALL_TRANSACTION + 22;
Kenny Root6b776452012-11-02 15:40:32 -0700508
509 /**
510 * Cast an IBinder object into an IKeystoreService interface, generating
511 * a proxy if needed.
512 */
513 public static IKeystoreService asInterface(IBinder obj) {
514 if (obj == null) {
515 return null;
516 }
517 IInterface iin = obj.queryLocalInterface(DESCRIPTOR);
518 if (iin != null && iin instanceof IKeystoreService) {
519 return (IKeystoreService) iin;
520 }
521 return new IKeystoreService.Stub.Proxy(obj);
522 }
523
524 /** Construct the stub at attach it to the interface. */
525 public Stub() {
526 attachInterface(this, DESCRIPTOR);
527 }
528
529 public IBinder asBinder() {
530 return this;
531 }
532
533 @Override
534 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
535 throws RemoteException {
536 switch (code) {
537 case INTERFACE_TRANSACTION: {
538 reply.writeString(DESCRIPTOR);
539 return true;
540 }
541 case TRANSACTION_test: {
542 data.enforceInterface(DESCRIPTOR);
543 int resultCode = test();
544 reply.writeNoException();
545 reply.writeInt(resultCode);
546 return true;
547 }
548 }
549 return super.onTransact(code, data, reply, flags);
550 }
551 }
552
553 public int test() throws RemoteException;
554
555 public byte[] get(String name) throws RemoteException;
556
Kenny Roota3788b02013-04-10 10:37:55 -0700557 public int insert(String name, byte[] item, int uid, int flags) throws RemoteException;
Kenny Root6b776452012-11-02 15:40:32 -0700558
Kenny Roote151f282013-02-13 15:22:25 -0800559 public int del(String name, int uid) throws RemoteException;
Kenny Root6b776452012-11-02 15:40:32 -0700560
Kenny Roote151f282013-02-13 15:22:25 -0800561 public int exist(String name, int uid) throws RemoteException;
Kenny Root6b776452012-11-02 15:40:32 -0700562
Kenny Roote151f282013-02-13 15:22:25 -0800563 public String[] saw(String name, int uid) throws RemoteException;
Kenny Root6b776452012-11-02 15:40:32 -0700564
565 public int reset() throws RemoteException;
566
567 public int password(String password) throws RemoteException;
568
569 public int lock() throws RemoteException;
570
571 public int unlock(String password) throws RemoteException;
572
573 public int zero() throws RemoteException;
574
Kenny Roota3985982013-08-16 14:03:29 -0700575 public int generate(String name, int uid, int keyType, int keySize, int flags, byte[][] args)
576 throws RemoteException;
Kenny Root6b776452012-11-02 15:40:32 -0700577
Kenny Roota3788b02013-04-10 10:37:55 -0700578 public int import_key(String name, byte[] data, int uid, int flags) throws RemoteException;
Kenny Root6b776452012-11-02 15:40:32 -0700579
580 public byte[] sign(String name, byte[] data) throws RemoteException;
581
582 public int verify(String name, byte[] data, byte[] signature) throws RemoteException;
583
584 public byte[] get_pubkey(String name) throws RemoteException;
585
Kenny Roote151f282013-02-13 15:22:25 -0800586 public int del_key(String name, int uid) throws RemoteException;
Kenny Root6b776452012-11-02 15:40:32 -0700587
588 public int grant(String name, int granteeUid) throws RemoteException;
589
590 public int ungrant(String name, int granteeUid) throws RemoteException;
591
592 public long getmtime(String name) throws RemoteException;
Kenny Rootbd794192013-03-20 11:36:50 -0700593
Kenny Root5f1d9652013-03-21 14:21:50 -0700594 public int duplicate(String srcKey, int srcUid, String destKey, int destUid)
595 throws RemoteException;
Kenny Root5cb5cec2013-03-29 11:14:17 -0700596
Kenny Rootb91773b2013-09-05 13:03:16 -0700597 public int is_hardware_backed(String string) throws RemoteException;
Kenny Rootd72317a2013-04-01 15:59:59 -0700598
599 public int clear_uid(long uid) throws RemoteException;
Kenny Root6b776452012-11-02 15:40:32 -0700600}