IKeystoreService.java revision e151f281d527f4bea5cbdf4219d5e0507a6668b0
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                } finally {
152                    _reply.recycle();
153                    _data.recycle();
154                }
155                return _result;
156            }
157
158            @Override
159            public int reset() throws RemoteException {
160                Parcel _data = Parcel.obtain();
161                Parcel _reply = Parcel.obtain();
162                int _result;
163                try {
164                    _data.writeInterfaceToken(DESCRIPTOR);
165                    mRemote.transact(Stub.TRANSACTION_reset, _data, _reply, 0);
166                    _reply.readException();
167                    _result = _reply.readInt();
168                } finally {
169                    _reply.recycle();
170                    _data.recycle();
171                }
172                return _result;
173            }
174
175            public int password(String password) throws RemoteException {
176                Parcel _data = Parcel.obtain();
177                Parcel _reply = Parcel.obtain();
178                int _result;
179                try {
180                    _data.writeInterfaceToken(DESCRIPTOR);
181                    _data.writeString(password);
182                    mRemote.transact(Stub.TRANSACTION_password, _data, _reply, 0);
183                    _reply.readException();
184                    _result = _reply.readInt();
185                } finally {
186                    _reply.recycle();
187                    _data.recycle();
188                }
189                return _result;
190            }
191
192            public int lock() throws RemoteException {
193                Parcel _data = Parcel.obtain();
194                Parcel _reply = Parcel.obtain();
195                int _result;
196                try {
197                    _data.writeInterfaceToken(DESCRIPTOR);
198                    mRemote.transact(Stub.TRANSACTION_lock, _data, _reply, 0);
199                    _reply.readException();
200                    _result = _reply.readInt();
201                } finally {
202                    _reply.recycle();
203                    _data.recycle();
204                }
205                return _result;
206            }
207
208            public int unlock(String password) throws RemoteException {
209                Parcel _data = Parcel.obtain();
210                Parcel _reply = Parcel.obtain();
211                int _result;
212                try {
213                    _data.writeInterfaceToken(DESCRIPTOR);
214                    _data.writeString(password);
215                    mRemote.transact(Stub.TRANSACTION_unlock, _data, _reply, 0);
216                    _reply.readException();
217                    _result = _reply.readInt();
218                } finally {
219                    _reply.recycle();
220                    _data.recycle();
221                }
222                return _result;
223            }
224
225            @Override
226            public int zero() throws RemoteException {
227                Parcel _data = Parcel.obtain();
228                Parcel _reply = Parcel.obtain();
229                int _result;
230                try {
231                    _data.writeInterfaceToken(DESCRIPTOR);
232                    mRemote.transact(Stub.TRANSACTION_zero, _data, _reply, 0);
233                    _reply.readException();
234                    _result = _reply.readInt();
235                } finally {
236                    _reply.recycle();
237                    _data.recycle();
238                }
239                return _result;
240            }
241
242            public int generate(String name, int uid) throws RemoteException {
243                Parcel _data = Parcel.obtain();
244                Parcel _reply = Parcel.obtain();
245                int _result;
246                try {
247                    _data.writeInterfaceToken(DESCRIPTOR);
248                    _data.writeString(name);
249                    _data.writeInt(uid);
250                    mRemote.transact(Stub.TRANSACTION_generate, _data, _reply, 0);
251                    _reply.readException();
252                    _result = _reply.readInt();
253                } finally {
254                    _reply.recycle();
255                    _data.recycle();
256                }
257                return _result;
258            }
259
260            public int import_key(String name, byte[] data, int uid) throws RemoteException {
261                Parcel _data = Parcel.obtain();
262                Parcel _reply = Parcel.obtain();
263                int _result;
264                try {
265                    _data.writeInterfaceToken(DESCRIPTOR);
266                    _data.writeString(name);
267                    _data.writeByteArray(data);
268                    _data.writeInt(uid);
269                    mRemote.transact(Stub.TRANSACTION_import, _data, _reply, 0);
270                    _reply.readException();
271                    _result = _reply.readInt();
272                } finally {
273                    _reply.recycle();
274                    _data.recycle();
275                }
276                return _result;
277            }
278
279            public byte[] sign(String name, byte[] data) throws RemoteException {
280                Parcel _data = Parcel.obtain();
281                Parcel _reply = Parcel.obtain();
282                byte[] _result;
283                try {
284                    _data.writeInterfaceToken(DESCRIPTOR);
285                    _data.writeString(name);
286                    _data.writeByteArray(data);
287                    mRemote.transact(Stub.TRANSACTION_sign, _data, _reply, 0);
288                    _reply.readException();
289                    _result = _reply.createByteArray();
290                } finally {
291                    _reply.recycle();
292                    _data.recycle();
293                }
294                return _result;
295            }
296
297            public int verify(String name, byte[] data, byte[] signature) throws RemoteException {
298                Parcel _data = Parcel.obtain();
299                Parcel _reply = Parcel.obtain();
300                int _result;
301                try {
302                    _data.writeInterfaceToken(DESCRIPTOR);
303                    _data.writeString(name);
304                    _data.writeByteArray(data);
305                    _data.writeByteArray(signature);
306                    mRemote.transact(Stub.TRANSACTION_verify, _data, _reply, 0);
307                    _reply.readException();
308                    _result = _reply.readInt();
309                } finally {
310                    _reply.recycle();
311                    _data.recycle();
312                }
313                return _result;
314            }
315
316            public byte[] get_pubkey(String name) throws RemoteException {
317                Parcel _data = Parcel.obtain();
318                Parcel _reply = Parcel.obtain();
319                byte[] _result;
320                try {
321                    _data.writeInterfaceToken(DESCRIPTOR);
322                    _data.writeString(name);
323                    mRemote.transact(Stub.TRANSACTION_get_pubkey, _data, _reply, 0);
324                    _reply.readException();
325                    _result = _reply.createByteArray();
326                } finally {
327                    _reply.recycle();
328                    _data.recycle();
329                }
330                return _result;
331            }
332
333            public int del_key(String name, int uid) throws RemoteException {
334                Parcel _data = Parcel.obtain();
335                Parcel _reply = Parcel.obtain();
336                int _result;
337                try {
338                    _data.writeInterfaceToken(DESCRIPTOR);
339                    _data.writeString(name);
340                    _data.writeInt(uid);
341                    mRemote.transact(Stub.TRANSACTION_del_key, _data, _reply, 0);
342                    _reply.readException();
343                    _result = _reply.readInt();
344                } finally {
345                    _reply.recycle();
346                    _data.recycle();
347                }
348                return _result;
349            }
350
351            public int grant(String name, int granteeUid) throws RemoteException {
352                Parcel _data = Parcel.obtain();
353                Parcel _reply = Parcel.obtain();
354                int _result;
355                try {
356                    _data.writeInterfaceToken(DESCRIPTOR);
357                    _data.writeString(name);
358                    _data.writeInt(granteeUid);
359                    mRemote.transact(Stub.TRANSACTION_grant, _data, _reply, 0);
360                    _reply.readException();
361                    _result = _reply.readInt();
362                } finally {
363                    _reply.recycle();
364                    _data.recycle();
365                }
366                return _result;
367            }
368
369            public int ungrant(String name, int granteeUid) throws RemoteException {
370                Parcel _data = Parcel.obtain();
371                Parcel _reply = Parcel.obtain();
372                int _result;
373                try {
374                    _data.writeInterfaceToken(DESCRIPTOR);
375                    _data.writeString(name);
376                    _data.writeInt(granteeUid);
377                    mRemote.transact(Stub.TRANSACTION_ungrant, _data, _reply, 0);
378                    _reply.readException();
379                    _result = _reply.readInt();
380                } finally {
381                    _reply.recycle();
382                    _data.recycle();
383                }
384                return _result;
385            }
386
387            @Override
388            public long getmtime(String name) throws RemoteException {
389                Parcel _data = Parcel.obtain();
390                Parcel _reply = Parcel.obtain();
391                long _result;
392                try {
393                    _data.writeInterfaceToken(DESCRIPTOR);
394                    _data.writeString(name);
395                    mRemote.transact(Stub.TRANSACTION_getmtime, _data, _reply, 0);
396                    _reply.readException();
397                    _result = _reply.readLong();
398                } finally {
399                    _reply.recycle();
400                    _data.recycle();
401                }
402                return _result;
403            }
404        }
405
406        private static final String DESCRIPTOR = "android.security.keystore";
407
408        static final int TRANSACTION_test = IBinder.FIRST_CALL_TRANSACTION + 0;
409        static final int TRANSACTION_get = IBinder.FIRST_CALL_TRANSACTION + 1;
410        static final int TRANSACTION_insert = IBinder.FIRST_CALL_TRANSACTION + 2;
411        static final int TRANSACTION_del = IBinder.FIRST_CALL_TRANSACTION + 3;
412        static final int TRANSACTION_exist = IBinder.FIRST_CALL_TRANSACTION + 4;
413        static final int TRANSACTION_saw = IBinder.FIRST_CALL_TRANSACTION + 5;
414        static final int TRANSACTION_reset = IBinder.FIRST_CALL_TRANSACTION + 6;
415        static final int TRANSACTION_password = IBinder.FIRST_CALL_TRANSACTION + 7;
416        static final int TRANSACTION_lock = IBinder.FIRST_CALL_TRANSACTION + 8;
417        static final int TRANSACTION_unlock = IBinder.FIRST_CALL_TRANSACTION + 9;
418        static final int TRANSACTION_zero = IBinder.FIRST_CALL_TRANSACTION + 10;
419        static final int TRANSACTION_generate = IBinder.FIRST_CALL_TRANSACTION + 11;
420        static final int TRANSACTION_import = IBinder.FIRST_CALL_TRANSACTION + 12;
421        static final int TRANSACTION_sign = IBinder.FIRST_CALL_TRANSACTION + 13;
422        static final int TRANSACTION_verify = IBinder.FIRST_CALL_TRANSACTION + 14;
423        static final int TRANSACTION_get_pubkey = IBinder.FIRST_CALL_TRANSACTION + 15;
424        static final int TRANSACTION_del_key = IBinder.FIRST_CALL_TRANSACTION + 16;
425        static final int TRANSACTION_grant = IBinder.FIRST_CALL_TRANSACTION + 17;
426        static final int TRANSACTION_ungrant = IBinder.FIRST_CALL_TRANSACTION + 18;
427        static final int TRANSACTION_getmtime = IBinder.FIRST_CALL_TRANSACTION + 19;
428
429        /**
430         * Cast an IBinder object into an IKeystoreService interface, generating
431         * a proxy if needed.
432         */
433        public static IKeystoreService asInterface(IBinder obj) {
434            if (obj == null) {
435                return null;
436            }
437            IInterface iin = obj.queryLocalInterface(DESCRIPTOR);
438            if (iin != null && iin instanceof IKeystoreService) {
439                return (IKeystoreService) iin;
440            }
441            return new IKeystoreService.Stub.Proxy(obj);
442        }
443
444        /** Construct the stub at attach it to the interface. */
445        public Stub() {
446            attachInterface(this, DESCRIPTOR);
447        }
448
449        public IBinder asBinder() {
450            return this;
451        }
452
453        @Override
454        public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
455                throws RemoteException {
456            switch (code) {
457                case INTERFACE_TRANSACTION: {
458                    reply.writeString(DESCRIPTOR);
459                    return true;
460                }
461                case TRANSACTION_test: {
462                    data.enforceInterface(DESCRIPTOR);
463                    int resultCode = test();
464                    reply.writeNoException();
465                    reply.writeInt(resultCode);
466                    return true;
467                }
468            }
469            return super.onTransact(code, data, reply, flags);
470        }
471    }
472
473    public int test() throws RemoteException;
474
475    public byte[] get(String name) throws RemoteException;
476
477    public int insert(String name, byte[] item, int uid) throws RemoteException;
478
479    public int del(String name, int uid) throws RemoteException;
480
481    public int exist(String name, int uid) throws RemoteException;
482
483    public String[] saw(String name, int uid) throws RemoteException;
484
485    public int reset() throws RemoteException;
486
487    public int password(String password) throws RemoteException;
488
489    public int lock() throws RemoteException;
490
491    public int unlock(String password) throws RemoteException;
492
493    public int zero() throws RemoteException;
494
495    public int generate(String name, int uid) throws RemoteException;
496
497    public int import_key(String name, byte[] data, int uid) throws RemoteException;
498
499    public byte[] sign(String name, byte[] data) throws RemoteException;
500
501    public int verify(String name, byte[] data, byte[] signature) throws RemoteException;
502
503    public byte[] get_pubkey(String name) throws RemoteException;
504
505    public int del_key(String name, int uid) throws RemoteException;
506
507    public int grant(String name, int granteeUid) throws RemoteException;
508
509    public int ungrant(String name, int granteeUid) throws RemoteException;
510
511    public long getmtime(String name) throws RemoteException;
512}
513