Option for Choosing between jcardsim and vicc

This commit is contained in:
Frank Morgner
2016-04-14 09:46:16 -04:00
parent 67a68246c7
commit 524ef6b6aa
5 changed files with 88 additions and 12 deletions

View File

@@ -29,6 +29,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.content.LocalBroadcastManager;
@@ -96,9 +97,13 @@ public class MainActivity extends AppCompatActivity {
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Scheduled re-installation of all applets...", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
SimulatorService.destroySimulator(getApplicationContext());
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
String emulator = SP.getString("emulator", "");
if (emulator != getString(R.string.vicc)) {
Snackbar.make(view, "Scheduled re-installation of all applets...", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
SimulatorService.destroySimulator(getApplicationContext());
}
}
});

View File

@@ -175,11 +175,16 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
// to their values. When their values change, their summaries are
// updated to reflect the new value, per the Android Design
// guidelines.
bindPreferenceSummaryToValue(findPreference("emulator"));
bindPreferenceSummaryToValue(findPreference("activate_helloworld"));
bindPreferenceSummaryToValue(findPreference("activate_openpgp"));
bindPreferenceSummaryToValue(findPreference("activate_oath"));
bindPreferenceSummaryToValue(findPreference("activate_isoapplet"));
bindPreferenceSummaryToValue(findPreference("activate_gidsapplet"));
bindPreferenceSummaryToValue(findPreference("hostname"));
bindPreferenceSummaryToValue(findPreference("port"));
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {

View File

@@ -47,10 +47,8 @@ import com.mysmartlogon.gidsApplet.GidsApplet;
public class SimulatorService extends HostApduService {
private static final boolean useVPCD = false;
public static final int DEFAULT_PORT = 35963;
private static final String hostname = "192.168.42.158";
private int port = DEFAULT_PORT;
private static final String DEFAULT_HOSTNAME = "10.0.2.2";
private static Socket socket;
private static InputStream inputStream;
@@ -66,6 +64,25 @@ public class SimulatorService extends HostApduService {
private static Simulator simulator = null;
private static boolean do_destroy = false;
private boolean useVPCD() {
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(this);
String emulator = SP.getString("emulator", "");
if (emulator.equals(getString(R.string.vicc)))
return true;
return false;
}
private int port() {
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(this);
return Integer.parseInt(SP.getString("port", Integer.toString(DEFAULT_PORT)));
}
private String hostname() {
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(this);
return SP.getString("hostname", DEFAULT_HOSTNAME);
}
private void createSimulator() {
String aid, name, extra_install = "", extra_error = "";
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(this);
@@ -154,7 +171,7 @@ public class SimulatorService extends HostApduService {
do_destroy();
Log.d("", "Begin transaction");
if (useVPCD) {
if (useVPCD()) {
if (socket == null) {
try {
if (android.os.Build.VERSION.SDK_INT > 9) {
@@ -202,7 +219,7 @@ public class SimulatorService extends HostApduService {
i.putExtra(EXTRA_CAPDU, Util.byteArrayToHexString(capdu));
try {
if (useVPCD) {
if (useVPCD()) {
rapdu = transmit(capdu);
} else {
rapdu = simulator.transmitCommand(capdu);
@@ -231,7 +248,7 @@ public class SimulatorService extends HostApduService {
switch (reason) {
case DEACTIVATION_LINK_LOSS:
i.putExtra(EXTRA_DESELECT, "link lost");
if (useVPCD)
if (useVPCD())
try {
sendPowerOff();
} catch (IOException e) {
@@ -241,7 +258,7 @@ public class SimulatorService extends HostApduService {
break;
case DEACTIVATION_DESELECTED:
i.putExtra(EXTRA_DESELECT, "deactivated");
if (useVPCD)
if (useVPCD())
try {
sendReset();
} catch (IOException e) {
@@ -250,7 +267,7 @@ public class SimulatorService extends HostApduService {
}
break;
}
if (useVPCD) {
if (useVPCD()) {
//vpcdDisconnect();
}
@@ -316,6 +333,8 @@ public class SimulatorService extends HostApduService {
}
private void vpcdConnect() throws IOException {
String hostname = hostname();
int port = port();
Log.d("", "Connecting to " + hostname + ":" + Integer.toString(port));
socket = new Socket(InetAddress.getByName(hostname), port);
outputStream = socket.getOutputStream();

View File

@@ -38,5 +38,14 @@
\n
Place your device on a contact-less reader. When the reader issues a SELECT command for one of the application identifiers above, the emulator creates the appropriate applet. The emulated applet will then handle all subsequent APDUs.</string>
<string name="action_settings">Settings</string>
<string-array name="strEmulators">
<item>@string/jcardsim</item>
<item>@string/vicc</item>
</string-array>
<string name="jcardsim">Builtin Java Card Simulator</string>
<string name="vicc">Remote Virtual Smart Card</string>
<string name="vicc_config_info">If you choose the virtual smart card (VICC) as emulator, you need to start the it on your computer with the `--reversed` flag and configure the connection parameters here accordingly.</string>
<string name="hint_vicc_port">VICC Port</string>
<string name="hint_vicc_hostname">VICC Hostname</string>
</resources>

View File

@@ -1,8 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<ListPreference
android:key="emulator"
android:title="Smart Card Emulator"
android:defaultValue="@string/vicc"
android:entries="@array/strEmulators"
android:entryValues="@array/strEmulators" />
<PreferenceCategory
android:title="Java Card Emulator">
android:title="@string/jcardsim"
android:key="jc_settings"
>
<SwitchPreference
android:title="@string/applet_helloworld"
@@ -37,4 +46,33 @@
</PreferenceCategory>
<PreferenceCategory
android:title="@string/vicc"
android:key="vicc_settings"
>
<Preference
android:title="Virtual Smart Card Available on Github"
android:summary="@string/vicc_config_info">
<intent android:action="android.intent.action.VIEW"
android:data="https://frankmorgner.github.io/vsmartcard/virtualsmartcard/README.html" />
</Preference>
<EditTextPreference
android:key="hostname"
android:defaultValue="10.0.2.2"
android:title="@string/hint_vicc_hostname"
android:hint="URL or IP address"
android:inputType="textUri" />
<EditTextPreference
android:key="port"
android:defaultValue="35963"
android:title="@string/hint_vicc_port"
android:inputType="number"
android:hint="Default: 35963" />
</PreferenceCategory>
</PreferenceScreen>