1 /* 2 * Copyright (C) 2017 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 17 package com.android.weaver.core; 18 19 import javacard.framework.AID; 20 import javacard.framework.APDU; 21 import javacard.framework.Applet; 22 import javacard.framework.Shareable; 23 24 class WeaverCore extends Applet { 25 public static final byte[] COMMAPP_APPLET_AID 26 = new byte[] {(byte) 0xA0, 0x00, 0x00, 0x04, 0x76, 0x57, 0x56, 27 0x52, 0x43, 0x4F, 0x4D, 0x4D, 0x30}; 28 29 private CoreSlots mSlots; 30 WeaverCore()31 protected WeaverCore() { 32 // Allocate all memory up front 33 mSlots = new CoreSlots(); 34 register(); 35 } 36 37 /** 38 * Installs this applet. 39 * 40 * @param params the installation parameters 41 * @param offset the starting offset of the parameters 42 * @param length the length of the parameters 43 */ install(byte[] params, short offset, byte length)44 public static void install(byte[] params, short offset, byte length) { 45 new WeaverCore(); 46 } 47 48 /** 49 * Returns and instance of the {@link Slots} interface. 50 * 51 * @param AID The requesting applet's AID must be that of the CoreApp. 52 * @param arg Must be {@link #SLOTS_INTERFACE} else returns {@code null}. 53 */ 54 @Override getShareableInterfaceObject(AID clientAid, byte arg)55 public Shareable getShareableInterfaceObject(AID clientAid, byte arg) { 56 if (!clientAid.partialEquals(COMMAPP_APPLET_AID, (short) 0, (byte) COMMAPP_APPLET_AID.length)) { 57 return null; 58 } 59 return (arg == 0) ? mSlots : null; 60 } 61 62 /** 63 * Should never be called. 64 */ 65 @Override process(APDU apdu)66 public void process(APDU apdu) { 67 } 68 } 69