don't depend on APK signing
removes authentication and secure data transfer between ACardEmulator and TCardEmulator
This commit is contained in:
@@ -23,11 +23,7 @@
|
||||
|
||||
package com.vsmartcard.acardemulator;
|
||||
|
||||
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;
|
||||
@@ -43,12 +39,7 @@ import com.samsung.android.sdk.accessory.SAPeerAgent;
|
||||
import com.samsung.android.sdk.accessory.SASocket;
|
||||
import com.vsmartcard.acardemulator.emulators.EmulatorSingleton;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.security.cert.CertificateException;
|
||||
import javax.security.cert.X509Certificate;
|
||||
|
||||
public class SmartcardProviderService extends SAAgent {
|
||||
private static final String TAG = "ACardEmulator";
|
||||
@@ -110,7 +101,8 @@ public class SmartcardProviderService extends SAAgent {
|
||||
@Override
|
||||
protected void onServiceConnectionRequested(SAPeerAgent peerAgent) {
|
||||
if (peerAgent != null) {
|
||||
authenticatePeerAgent(peerAgent);
|
||||
//TODO: Check for keys and everything
|
||||
acceptServiceConnectionRequest(peerAgent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,36 +118,12 @@ 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) {
|
||||
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);
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -229,7 +197,7 @@ public class SmartcardProviderService extends SAAgent {
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
mConnectionHandler.secureSend(ACCESSORY_CHANNEL_ID, sendResponse);
|
||||
mConnectionHandler.send(ACCESSORY_CHANNEL_ID, sendResponse);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user