Authentication for ACardEmulator/TCardEmulator
secure sending and with high priority
This commit is contained in:
committed by
Frank Morgner
parent
45273626eb
commit
9c758ffda0
2
ACardEmulator/app/.gitignore
vendored
2
ACardEmulator/app/.gitignore
vendored
@@ -1 +1 @@
|
||||
/build
|
||||
/build
|
||||
@@ -71,14 +71,6 @@
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
|
||||
@@ -87,6 +79,14 @@
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
|
||||
@@ -108,6 +108,7 @@
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-support" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/restart-dex" />
|
||||
|
||||
@@ -1,9 +1,20 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
def keystorePropertiesFile = rootProject.file("keystore.properties")
|
||||
def keystoreProperties = new Properties()
|
||||
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
|
||||
|
||||
android {
|
||||
signingConfigs {
|
||||
config {
|
||||
keyAlias keystoreProperties['keyAlias']
|
||||
keyPassword keystoreProperties['keyPassword']
|
||||
storeFile keystoreProperties['storeFile']
|
||||
storePassword keystoreProperties['storePassword']
|
||||
}
|
||||
}
|
||||
compileSdkVersion 23
|
||||
buildToolsVersion "23.0.1"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.vsmartcard.acardemulator"
|
||||
minSdkVersion 19
|
||||
@@ -15,6 +26,10 @@ android {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
signingConfig signingConfigs.config
|
||||
}
|
||||
debug {
|
||||
signingConfig signingConfigs.config
|
||||
}
|
||||
}
|
||||
sourceSets {
|
||||
@@ -49,7 +64,7 @@ android.applicationVariants.all { variant ->
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
compile fileTree(include: ['*.jar'], dir: 'libs')
|
||||
compile 'com.android.support:appcompat-v7:23.0.1'
|
||||
compile 'com.android.support:support-v4:23.0.1'
|
||||
compile 'com.android.support:design:23.2.1'
|
||||
|
||||
@@ -23,12 +23,17 @@
|
||||
|
||||
package com.vsmartcard.acardemulator;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import javax.security.cert.CertificateException;
|
||||
import javax.security.cert.X509Certificate;
|
||||
import java.util.Arrays;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.Signature;
|
||||
import android.os.Binder;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
@@ -40,8 +45,8 @@ import com.samsung.android.sdk.accessory.*;
|
||||
import com.vsmartcard.acardemulator.emulators.EmulatorSingleton;
|
||||
|
||||
public class SmartcardProviderService extends SAAgent {
|
||||
private static final String TAG = "HelloAccessory(P)";
|
||||
private static final int HELLOACCESSORY_CHANNEL_ID = 104;
|
||||
private static final String TAG = "ACardEmulator";
|
||||
private static final int ACCESSORY_CHANNEL_ID = 104;
|
||||
private static final Class<ServiceConnection> SASOCKET_CLASS = ServiceConnection.class;
|
||||
private final IBinder mBinder = new LocalBinder();
|
||||
private ServiceConnection mConnectionHandler = null;
|
||||
@@ -99,8 +104,7 @@ public class SmartcardProviderService extends SAAgent {
|
||||
@Override
|
||||
protected void onServiceConnectionRequested(SAPeerAgent peerAgent) {
|
||||
if (peerAgent != null) {
|
||||
//TODO: Check for keys and everything
|
||||
acceptServiceConnectionRequest(peerAgent);
|
||||
authenticatePeerAgent(peerAgent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,12 +120,36 @@ public class SmartcardProviderService extends SAAgent {
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] getApplicationCertificate(Context context) {
|
||||
byte[] cert = new byte[0];
|
||||
String packageName = context.getPackageName();
|
||||
try {
|
||||
PackageInfo pkgInfo = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
|
||||
if (pkgInfo != null) {
|
||||
Signature[] sigs = pkgInfo.signatures;
|
||||
if (sigs != null) {
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream(sigs[0].toByteArray());
|
||||
X509Certificate x509cert = X509Certificate.getInstance(stream);
|
||||
cert = x509cert.getPublicKey().getEncoded();
|
||||
}
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException | CertificateException e) {
|
||||
Log.e(TAG, e.getMessage());
|
||||
}
|
||||
return cert;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAuthenticationResponse(SAPeerAgent peerAgent, SAAuthenticationToken authToken, int error) {
|
||||
/*
|
||||
* The authenticatePeerAgent(peerAgent) API may not be working properly depending on the firmware
|
||||
* version of accessory device. Please refer to another sample application for Security.
|
||||
*/
|
||||
if (authToken.getAuthenticationType() == SAAuthenticationToken.AUTHENTICATION_TYPE_CERTIFICATE_X509) {
|
||||
byte[] myAppKey = getApplicationCertificate(getApplicationContext());
|
||||
if (authToken.getKey().length == myAppKey.length) {
|
||||
if (Arrays.equals(authToken.getKey(), myAppKey)) {
|
||||
acceptServiceConnectionRequest(peerAgent);
|
||||
}
|
||||
}
|
||||
}
|
||||
rejectServiceConnectionRequest(peerAgent);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -175,7 +203,7 @@ public class SmartcardProviderService extends SAAgent {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
mConnectionHandler.send(HELLOACCESSORY_CHANNEL_ID, response);
|
||||
mConnectionHandler.secureSend(ACCESSORY_CHANNEL_ID, response);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
<serviceChannel
|
||||
id="104"
|
||||
dataRate="low"
|
||||
priority="low"
|
||||
priority="high"
|
||||
reliability= "enable"/>
|
||||
</serviceProfile>
|
||||
</application>
|
||||
|
||||
Reference in New Issue
Block a user