Option for Choosing between jcardsim and vicc
This commit is contained in:
@@ -29,6 +29,7 @@ import android.content.Intent;
|
|||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
@@ -96,9 +97,13 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
fab.setOnClickListener(new View.OnClickListener() {
|
fab.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
Snackbar.make(view, "Scheduled re-installation of all applets...", Snackbar.LENGTH_LONG)
|
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||||
.setAction("Action", null).show();
|
String emulator = SP.getString("emulator", "");
|
||||||
SimulatorService.destroySimulator(getApplicationContext());
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -175,11 +175,16 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|||||||
// to their values. When their values change, their summaries are
|
// to their values. When their values change, their summaries are
|
||||||
// updated to reflect the new value, per the Android Design
|
// updated to reflect the new value, per the Android Design
|
||||||
// guidelines.
|
// guidelines.
|
||||||
|
bindPreferenceSummaryToValue(findPreference("emulator"));
|
||||||
|
|
||||||
bindPreferenceSummaryToValue(findPreference("activate_helloworld"));
|
bindPreferenceSummaryToValue(findPreference("activate_helloworld"));
|
||||||
bindPreferenceSummaryToValue(findPreference("activate_openpgp"));
|
bindPreferenceSummaryToValue(findPreference("activate_openpgp"));
|
||||||
bindPreferenceSummaryToValue(findPreference("activate_oath"));
|
bindPreferenceSummaryToValue(findPreference("activate_oath"));
|
||||||
bindPreferenceSummaryToValue(findPreference("activate_isoapplet"));
|
bindPreferenceSummaryToValue(findPreference("activate_isoapplet"));
|
||||||
bindPreferenceSummaryToValue(findPreference("activate_gidsapplet"));
|
bindPreferenceSummaryToValue(findPreference("activate_gidsapplet"));
|
||||||
|
|
||||||
|
bindPreferenceSummaryToValue(findPreference("hostname"));
|
||||||
|
bindPreferenceSummaryToValue(findPreference("port"));
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
|||||||
@@ -47,10 +47,8 @@ import com.mysmartlogon.gidsApplet.GidsApplet;
|
|||||||
|
|
||||||
public class SimulatorService extends HostApduService {
|
public class SimulatorService extends HostApduService {
|
||||||
|
|
||||||
private static final boolean useVPCD = false;
|
|
||||||
public static final int DEFAULT_PORT = 35963;
|
public static final int DEFAULT_PORT = 35963;
|
||||||
private static final String hostname = "192.168.42.158";
|
private static final String DEFAULT_HOSTNAME = "10.0.2.2";
|
||||||
private int port = DEFAULT_PORT;
|
|
||||||
|
|
||||||
private static Socket socket;
|
private static Socket socket;
|
||||||
private static InputStream inputStream;
|
private static InputStream inputStream;
|
||||||
@@ -66,6 +64,25 @@ public class SimulatorService extends HostApduService {
|
|||||||
private static Simulator simulator = null;
|
private static Simulator simulator = null;
|
||||||
private static boolean do_destroy = false;
|
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() {
|
private void createSimulator() {
|
||||||
String aid, name, extra_install = "", extra_error = "";
|
String aid, name, extra_install = "", extra_error = "";
|
||||||
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
@@ -154,7 +171,7 @@ public class SimulatorService extends HostApduService {
|
|||||||
do_destroy();
|
do_destroy();
|
||||||
|
|
||||||
Log.d("", "Begin transaction");
|
Log.d("", "Begin transaction");
|
||||||
if (useVPCD) {
|
if (useVPCD()) {
|
||||||
if (socket == null) {
|
if (socket == null) {
|
||||||
try {
|
try {
|
||||||
if (android.os.Build.VERSION.SDK_INT > 9) {
|
if (android.os.Build.VERSION.SDK_INT > 9) {
|
||||||
@@ -202,7 +219,7 @@ public class SimulatorService extends HostApduService {
|
|||||||
|
|
||||||
i.putExtra(EXTRA_CAPDU, Util.byteArrayToHexString(capdu));
|
i.putExtra(EXTRA_CAPDU, Util.byteArrayToHexString(capdu));
|
||||||
try {
|
try {
|
||||||
if (useVPCD) {
|
if (useVPCD()) {
|
||||||
rapdu = transmit(capdu);
|
rapdu = transmit(capdu);
|
||||||
} else {
|
} else {
|
||||||
rapdu = simulator.transmitCommand(capdu);
|
rapdu = simulator.transmitCommand(capdu);
|
||||||
@@ -231,7 +248,7 @@ public class SimulatorService extends HostApduService {
|
|||||||
switch (reason) {
|
switch (reason) {
|
||||||
case DEACTIVATION_LINK_LOSS:
|
case DEACTIVATION_LINK_LOSS:
|
||||||
i.putExtra(EXTRA_DESELECT, "link lost");
|
i.putExtra(EXTRA_DESELECT, "link lost");
|
||||||
if (useVPCD)
|
if (useVPCD())
|
||||||
try {
|
try {
|
||||||
sendPowerOff();
|
sendPowerOff();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -241,7 +258,7 @@ public class SimulatorService extends HostApduService {
|
|||||||
break;
|
break;
|
||||||
case DEACTIVATION_DESELECTED:
|
case DEACTIVATION_DESELECTED:
|
||||||
i.putExtra(EXTRA_DESELECT, "deactivated");
|
i.putExtra(EXTRA_DESELECT, "deactivated");
|
||||||
if (useVPCD)
|
if (useVPCD())
|
||||||
try {
|
try {
|
||||||
sendReset();
|
sendReset();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -250,7 +267,7 @@ public class SimulatorService extends HostApduService {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (useVPCD) {
|
if (useVPCD()) {
|
||||||
//vpcdDisconnect();
|
//vpcdDisconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,6 +333,8 @@ public class SimulatorService extends HostApduService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void vpcdConnect() throws IOException {
|
private void vpcdConnect() throws IOException {
|
||||||
|
String hostname = hostname();
|
||||||
|
int port = port();
|
||||||
Log.d("", "Connecting to " + hostname + ":" + Integer.toString(port));
|
Log.d("", "Connecting to " + hostname + ":" + Integer.toString(port));
|
||||||
socket = new Socket(InetAddress.getByName(hostname), port);
|
socket = new Socket(InetAddress.getByName(hostname), port);
|
||||||
outputStream = socket.getOutputStream();
|
outputStream = socket.getOutputStream();
|
||||||
|
|||||||
@@ -38,5 +38,14 @@
|
|||||||
\n
|
\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>
|
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 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>
|
</resources>
|
||||||
|
|||||||
@@ -1,8 +1,17 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
<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
|
<PreferenceCategory
|
||||||
android:title="Java Card Emulator">
|
android:title="@string/jcardsim"
|
||||||
|
android:key="jc_settings"
|
||||||
|
>
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:title="@string/applet_helloworld"
|
android:title="@string/applet_helloworld"
|
||||||
@@ -37,4 +46,33 @@
|
|||||||
|
|
||||||
</PreferenceCategory>
|
</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>
|
</PreferenceScreen>
|
||||||
Reference in New Issue
Block a user