package aspects; import java.io.InputStream; import java.io.OutputStream; import java.net.Socket; import com.sun.javacard.apduio.CadDevice; import com.sun.javacard.apduio.Apdu; import com.sun.javacard.apduio.CadClient; import mixconfig.tools.dataretention.smartcard.ConnectionManager; import mixconfig.tools.dataretention.smartcard.SmartCardProxy; import mixconfig.tools.dataretention.smartcard.commands.AbstractCommand; import mixconfig.tools.dataretention.smartcard.commands.BeginInstallationCommand; import mixconfig.tools.dataretention.smartcard.commands.EndInstallationCommand; import mixconfig.tools.dataretention.smartcard.commands.ErrorCodeException; import mixconfig.tools.dataretention.smartcard.commands.InstallAnonCardAppletCommand; import mixconfig.tools.dataretention.smartcard.commands.SelectInstallerAppletCommand; import javax.smartcardio.CommandAPDU; import javax.smartcardio.ResponseAPDU; import javax.smartcardio.CardChannel; /** Singleton **/ privileged public aspect MixConfigConnectionManagerAspect { protected CadClient channelToEmulator; boolean around(ConnectionManager connectionManager) : target(connectionManager) && call(* connectToSmartCard()) { if (connectionManager.smartCard == null) { Socket sock; try { sock = new Socket("localhost", 9025); InputStream is = sock.getInputStream(); OutputStream os = sock.getOutputStream(); channelToEmulator = new CadClient(is, os); // CadClient.exchangeApdu installAnonApplet(connectionManager); connectionManager.selectAnonApplet(); } catch (Exception e) { e.printStackTrace(); } connectionManager.smartCard = new SmartCardProxy(connectionManager); } return true; } private void installAnonApplet(ConnectionManager connectionManager) { AbstractCommand command = new SelectInstallerAppletCommand(); try { connectionManager.processCommand(command); command = new BeginInstallationCommand(); connectionManager.processCommand(command); command = new InstallAnonCardAppletCommand(); connectionManager.processCommand(command); command = new EndInstallationCommand(); connectionManager.processCommand(command); } catch (ErrorCodeException e) { e.printStackTrace(); } } ResponseAPDU around(CommandAPDU commandApdu) : target (CardChannel) && call(* transmit(CommandAPDU)) && args(commandApdu) { System.out.println("Card channel"); return null; } }