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