IKeystoreService.java revision a3788b00bb221e20abdd42f747d2af419e0a088c
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 flags) throws RemoteException {
248                Parcel _data = Parcel.obtain();
249                Parcel _reply = Parcel.obtain();
250                int _result;
251                try {
252                    _data.writeInterfaceToken(DESCRIPTOR);
253                    _data.writeString(name);
254                    _data.writeInt(uid);
255                    _data.writeInt(flags);
256                    mRemote.transact(Stub.TRANSACTION_generate, _data, _reply, 0);
257                    _reply.readException();
258                    _result = _reply.readInt();
259                } finally {
260                    _reply.recycle();
261                    _data.recycle();
262                }
263                return _result;
264            }
265
266            public int import_key(String name, byte[] data, int uid, int flags)
267                    throws RemoteException {
268                Parcel _data = Parcel.obtain();
269                Parcel _reply = Parcel.obtain();
270                int _result;
271                try {
272                    _data.writeInterfaceToken(DESCRIPTOR);
273                    _data.writeString(name);
274                    _data.writeByteArray(data);
275                    _data.writeInt(uid);
276                    _data.writeInt(flags);
277                    mRemote.transact(Stub.TRANSACTION_import, _data, _reply, 0);
278                    _reply.readException();
279                    _result = _reply.readInt();
280                } finally {
281                    _reply.recycle();
282                    _data.recycle();
283                }
284                return _result;
285            }
286
287            public byte[] sign(String name, byte[] data) throws RemoteException {
288                Parcel _data = Parcel.obtain();
289                Parcel _reply = Parcel.obtain();
290                byte[] _result;
291                try {
292                    _data.writeInterfaceToken(DESCRIPTOR);
293                    _data.writeString(name);
294                    _data.writeByteArray(data);
295                    mRemote.transact(Stub.TRANSACTION_sign, _data, _reply, 0);
296                    _reply.readException();
297                    _result = _reply.createByteArray();
298                } finally {
299                    _reply.recycle();
300                    _data.recycle();
301                }
302                return _result;
303            }
304
305            public int verify(String name, byte[] data, byte[] signature) throws RemoteException {
306                Parcel _data = Parcel.obtain();
307                Parcel _reply = Parcel.obtain();
308                int _result;
309                try {
310                    _data.writeInterfaceToken(DESCRIPTOR);
311                    _data.writeString(name);
312                    _data.writeByteArray(data);
313                    _data.writeByteArray(signature);
314                    mRemote.transact(Stub.TRANSACTION_verify, _data, _reply, 0);
315                    _reply.readException();
316                    _result = _reply.readInt();
317                } finally {
318                    _reply.recycle();
319                    _data.recycle();
320                }
321                return _result;
322            }
323
324            public byte[] get_pubkey(String name) throws RemoteException {
325                Parcel _data = Parcel.obtain();
326                Parcel _reply = Parcel.obtain();
327                byte[] _result;
328                try {
329                    _data.writeInterfaceToken(DESCRIPTOR);
330                    _data.writeString(name);
331                    mRemote.transact(Stub.TRANSACTION_get_pubkey, _data, _reply, 0);
332                    _reply.readException();
333                    _result = _reply.createByteArray();
334                } finally {
335                    _reply.recycle();
336                    _data.recycle();
337                }
338                return _result;
339            }
340
341            public int del_key(String name, int uid) throws RemoteException {
342                Parcel _data = Parcel.obtain();
343                Parcel _reply = Parcel.obtain();
344                int _result;
345                try {
346                    _data.writeInterfaceToken(DESCRIPTOR);
347                    _data.writeString(name);
348                    _data.writeInt(uid);
349                    mRemote.transact(Stub.TRANSACTION_del_key, _data, _reply, 0);
350                    _reply.readException();
351                    _result = _reply.readInt();
352                } finally {
353                    _reply.recycle();
354                    _data.recycle();
355                }
356                return _result;
357            }
358
359            public int grant(String name, int granteeUid) throws RemoteException {
360                Parcel _data = Parcel.obtain();
361                Parcel _reply = Parcel.obtain();
362                int _result;
363                try {
364                    _data.writeInterfaceToken(DESCRIPTOR);
365                    _data.writeString(name);
366                    _data.writeInt(granteeUid);
367                    mRemote.transact(Stub.TRANSACTION_grant, _data, _reply, 0);
368                    _reply.readException();
369                    _result = _reply.readInt();
370                } finally {
371                    _reply.recycle();
372                    _data.recycle();
373                }
374                return _result;
375            }
376
377            public int ungrant(String name, int granteeUid) throws RemoteException {
378                Parcel _data = Parcel.obtain();
379                Parcel _reply = Parcel.obtain();
380                int _result;
381                try {
382                    _data.writeInterfaceToken(DESCRIPTOR);
383                    _data.writeString(name);
384                    _data.writeInt(granteeUid);
385                    mRemote.transact(Stub.TRANSACTION_ungrant, _data, _reply, 0);
386                    _reply.readException();
387                    _result = _reply.readInt();
388                } finally {
389                    _reply.recycle();
390                    _data.recycle();
391                }
392                return _result;
393            }
394
395            @Override
396            public long getmtime(String name) throws RemoteException {
397                Parcel _data = Parcel.obtain();
398                Parcel _reply = Parcel.obtain();
399                long _result;
400                try {
401                    _data.writeInterfaceToken(DESCRIPTOR);
402                    _data.writeString(name);
403                    mRemote.transact(Stub.TRANSACTION_getmtime, _data, _reply, 0);
404                    _reply.readException();
405                    _result = _reply.readLong();
406                } finally {
407                    _reply.recycle();
408                    _data.recycle();
409                }
410                return _result;
411            }
412
413            @Override
414            public int duplicate(String srcKey, int srcUid, String destKey, int destUid)
415                    throws RemoteException {
416                Parcel _data = Parcel.obtain();
417                Parcel _reply = Parcel.obtain();
418                int _result;
419                try {
420                    _data.writeInterfaceToken(DESCRIPTOR);
421                    _data.writeString(srcKey);
422                    _data.writeInt(srcUid);
423                    _data.writeString(destKey);
424                    _data.writeInt(destUid);
425                    mRemote.transact(Stub.TRANSACTION_duplicate, _data, _reply, 0);
426                    _reply.readException();
427                    _result = _reply.readInt();
428                } finally {
429                    _reply.recycle();
430                    _data.recycle();
431                }
432                return _result;
433            }
434
435            @Override
436            public int is_hardware_backed() throws RemoteException {
437                Parcel _data = Parcel.obtain();
438                Parcel _reply = Parcel.obtain();
439                int _result;
440                try {
441                    _data.writeInterfaceToken(DESCRIPTOR);
442                    mRemote.transact(Stub.TRANSACTION_is_hardware_backed, _data, _reply, 0);
443                    _reply.readException();
444                    _result = _reply.readInt();
445                } finally {
446                    _reply.recycle();
447                    _data.recycle();
448                }
449                return _result;
450            }
451
452            @Override
453            public int clear_uid(long uid) throws RemoteException {
454                Parcel _data = Parcel.obtain();
455                Parcel _reply = Parcel.obtain();
456                int _result;
457                try {
458                    _data.writeInterfaceToken(DESCRIPTOR);
459                    _data.writeLong(uid);
460                    mRemote.transact(Stub.TRANSACTION_clear_uid, _data, _reply, 0);
461                    _reply.readException();
462                    _result = _reply.readInt();
463                } finally {
464                    _reply.recycle();
465                    _data.recycle();
466                }
467                return _result;
468            }
469        }
470
471        private static final String DESCRIPTOR = "android.security.keystore";
472
473        static final int TRANSACTION_test = IBinder.FIRST_CALL_TRANSACTION + 0;
474        static final int TRANSACTION_get = IBinder.FIRST_CALL_TRANSACTION + 1;
475        static final int TRANSACTION_insert = IBinder.FIRST_CALL_TRANSACTION + 2;
476        static final int TRANSACTION_del = IBinder.FIRST_CALL_TRANSACTION + 3;
477        static final int TRANSACTION_exist = IBinder.FIRST_CALL_TRANSACTION + 4;
478        static final int TRANSACTION_saw = IBinder.FIRST_CALL_TRANSACTION + 5;
479        static final int TRANSACTION_reset = IBinder.FIRST_CALL_TRANSACTION + 6;
480        static final int TRANSACTION_password = IBinder.FIRST_CALL_TRANSACTION + 7;
481        static final int TRANSACTION_lock = IBinder.FIRST_CALL_TRANSACTION + 8;
482        static final int TRANSACTION_unlock = IBinder.FIRST_CALL_TRANSACTION + 9;
483        static final int TRANSACTION_zero = IBinder.FIRST_CALL_TRANSACTION + 10;
484        static final int TRANSACTION_generate = IBinder.FIRST_CALL_TRANSACTION + 11;
485        static final int TRANSACTION_import = IBinder.FIRST_CALL_TRANSACTION + 12;
486        static final int TRANSACTION_sign = IBinder.FIRST_CALL_TRANSACTION + 13;
487        static final int TRANSACTION_verify = IBinder.FIRST_CALL_TRANSACTION + 14;
488        static final int TRANSACTION_get_pubkey = IBinder.FIRST_CALL_TRANSACTION + 15;
489        static final int TRANSACTION_del_key = IBinder.FIRST_CALL_TRANSACTION + 16;
490        static final int TRANSACTION_grant = IBinder.FIRST_CALL_TRANSACTION + 17;
491        static final int TRANSACTION_ungrant = IBinder.FIRST_CALL_TRANSACTION + 18;
492        static final int TRANSACTION_getmtime = IBinder.FIRST_CALL_TRANSACTION + 19;
493        static final int TRANSACTION_duplicate = IBinder.FIRST_CALL_TRANSACTION + 20;
494        static final int TRANSACTION_is_hardware_backed = IBinder.FIRST_CALL_TRANSACTION + 21;
495        static final int TRANSACTION_clear_uid = IBinder.FIRST_CALL_TRANSACTION + 22;
496
497        /**
498         * Cast an IBinder object into an IKeystoreService interface, generating
499         * a proxy if needed.
500         */
501        public static IKeystoreService asInterface(IBinder obj) {
502            if (obj == null) {
503                return null;
504            }
505            IInterface iin = obj.queryLocalInterface(DESCRIPTOR);
506            if (iin != null && iin instanceof IKeystoreService) {
507                return (IKeystoreService) iin;
508            }
509            return new IKeystoreService.Stub.Proxy(obj);
510        }
511
512        /** Construct the stub at attach it to the interface. */
513        public Stub() {
514            attachInterface(this, DESCRIPTOR);
515        }
516
517        public IBinder asBinder() {
518            return this;
519        }
520
521        @Override
522        public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
523                throws RemoteException {
524            switch (code) {
525                case INTERFACE_TRANSACTION: {
526                    reply.writeString(DESCRIPTOR);
527                    return true;
528                }
529                case TRANSACTION_test: {
530                    data.enforceInterface(DESCRIPTOR);
531                    int resultCode = test();
532                    reply.writeNoException();
533                    reply.writeInt(resultCode);
534                    return true;
535                }
536            }
537            return super.onTransact(code, data, reply, flags);
538        }
539    }
540
541    public int test() throws RemoteException;
542
543    public byte[] get(String name) throws RemoteException;
544
545    public int insert(String name, byte[] item, int uid, int flags) throws RemoteException;
546
547    public int del(String name, int uid) throws RemoteException;
548
549    public int exist(String name, int uid) throws RemoteException;
550
551    public String[] saw(String name, int uid) throws RemoteException;
552
553    public int reset() throws RemoteException;
554
555    public int password(String password) throws RemoteException;
556
557    public int lock() throws RemoteException;
558
559    public int unlock(String password) throws RemoteException;
560
561    public int zero() throws RemoteException;
562
563    public int generate(String name, int uid, int flags) throws RemoteException;
564
565    public int import_key(String name, byte[] data, int uid, int flags) throws RemoteException;
566
567    public byte[] sign(String name, byte[] data) throws RemoteException;
568
569    public int verify(String name, byte[] data, byte[] signature) throws RemoteException;
570
571    public byte[] get_pubkey(String name) throws RemoteException;
572
573    public int del_key(String name, int uid) throws RemoteException;
574
575    public int grant(String name, int granteeUid) throws RemoteException;
576
577    public int ungrant(String name, int granteeUid) throws RemoteException;
578
579    public long getmtime(String name) throws RemoteException;
580
581    public int duplicate(String srcKey, int srcUid, String destKey, int destUid)
582            throws RemoteException;
583
584    public int is_hardware_backed() throws RemoteException;
585
586    public int clear_uid(long uid) throws RemoteException;
587}
588