Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.teslamotors.plugins.ble;
- import android.content.ComponentName;
- import android.content.Intent;
- import android.content.ServiceConnection;
- import android.nfc.cardemulation.HostApduService;
- import android.os.Bundle;
- import android.os.Handler;
- import android.os.IBinder;
- import android.os.Message;
- import android.os.Messenger;
- import android.os.Parcelable;
- import android.os.RemoteException;
- import com.teslamotors.plugins.ble.p140b.C3295c;
- import com.teslamotors.plugins.ble.p140b.C3299e;
- import com.teslamotors.plugins.ble.p140b.C3304h;
- import com.teslamotors.plugins.client.C3356b;
- import java.io.ByteArrayOutputStream;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.Arrays;
- public class TeslaCardEmulationService extends HostApduService {
- /* access modifiers changed from: private */
- /* renamed from: c */
- public static final String f9558c = "TeslaCardEmulationService";
- /* renamed from: d */
- private static final byte[] f9559d = {111, 0};
- /* renamed from: e */
- private static final byte[] f9560e = {110, 0};
- /* renamed from: f */
- private static final byte[] f9561f = {109, 0};
- /* renamed from: g */
- private static final byte[] f9562g = {-112, 0};
- /* renamed from: h */
- private static final byte[] f9563h = {109, 0};
- /* renamed from: i */
- private static final byte[] f9564i = {107, 0};
- /* renamed from: a */
- Messenger f9565a;
- /* renamed from: b */
- boolean f9566b;
- /* renamed from: j */
- private final Messenger f9567j = new Messenger(new C3277a());
- /* renamed from: k */
- private final ServiceConnection f9568k = new ServiceConnection() {
- public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
- C3356b.m16680b(TeslaCardEmulationService.f9558c, "onServiceConnected");
- TeslaCardEmulationService.this.f9565a = new Messenger(iBinder);
- TeslaCardEmulationService.this.f9566b = true;
- }
- public void onServiceDisconnected(ComponentName componentName) {
- if (TeslaCardEmulationService.this.f9566b) {
- TeslaCardEmulationService.this.f9566b = false;
- C3356b.m16680b(TeslaCardEmulationService.f9558c, "onServiceDisconnected");
- }
- TeslaCardEmulationService.this.f9565a = null;
- }
- };
- /* renamed from: com.teslamotors.plugins.ble.TeslaCardEmulationService$a */
- class C3277a extends Handler {
- C3277a() {
- }
- public void handleMessage(Message message) {
- Bundle data = message.getData();
- data.setClassLoader(getClass().getClassLoader());
- switch (C3299e.m16415a(message.what)) {
- case NFCGetPublicKeyBytesInfo:
- Parcelable parcelable = data.getParcelable(C3299e.NFCGetPublicKeyBytesInfo.mo16523b());
- if (parcelable != null) {
- TeslaCardEmulationService.this.m16295a((C3304h) parcelable);
- return;
- }
- C3356b.m16680b(TeslaCardEmulationService.f9558c, "Pub key not ready yet, resend the request");
- Message obtain = Message.obtain();
- obtain.what = C3299e.NFCGetPublicKeyBytes.mo16522a();
- sendMessage(obtain);
- return;
- case NFCEncryptWithSharedSecretResponse:
- Parcelable parcelable2 = data.getParcelable(C3299e.NFCEncryptWithSharedSecretResponse.mo16523b());
- if (parcelable2 != null) {
- TeslaCardEmulationService.this.m16294a((C3295c) parcelable2);
- return;
- } else {
- C3356b.m16680b(TeslaCardEmulationService.f9558c, "NFC auth response not ready yet");
- return;
- }
- case RegisterComplete:
- C3356b.m16680b(TeslaCardEmulationService.f9558c, "Successfully registered to received callbacks from BLE service");
- return;
- default:
- return;
- }
- }
- }
- public void onCreate() {
- C3356b.m16680b(f9558c, "onCreate called");
- bindService(new Intent(this, BLEService.class), this.f9568k, 1);
- }
- public void onDestroy() {
- if (this.f9566b) {
- this.f9566b = false;
- }
- this.f9565a = null;
- unbindService(this.f9568k);
- C3356b.m16680b(f9558c, "onDestroy called");
- }
- public void onDeactivated(int i) {
- String str = f9558c;
- StringBuilder sb = new StringBuilder();
- sb.append("Deactivated: ");
- sb.append(i);
- C3356b.m16680b(str, sb.toString());
- }
- /* renamed from: a */
- private static byte[] m16297a(short s) {
- return new byte[]{(byte) (s >> 8), (byte) (s & 255)};
- }
- /* renamed from: a */
- private boolean m16296a(Message message) {
- String str = f9558c;
- StringBuilder sb = new StringBuilder();
- sb.append("Sending message:");
- sb.append(C3299e.m16416b(message.what));
- C3356b.m16680b(str, sb.toString());
- boolean z = false;
- if (this.f9566b) {
- Messenger messenger = this.f9565a;
- if (messenger != null) {
- try {
- message.replyTo = this.f9567j;
- messenger.send(message);
- z = true;
- String str2 = f9558c;
- StringBuilder sb2 = new StringBuilder();
- sb2.append("Sent to Server from client :");
- sb2.append(this.f9565a.toString());
- sb2.append("Reply to ");
- sb2.append(this.f9567j.toString());
- C3356b.m16680b(str2, sb2.toString());
- return true;
- } catch (RemoteException e) {
- String str3 = f9558c;
- StringBuilder sb3 = new StringBuilder();
- sb3.append("Failed to send message - Remote Exception! : ");
- sb3.append(e.getMessage());
- C3356b.m16681c(str3, sb3.toString());
- return z;
- }
- }
- }
- C3356b.m16680b(f9558c, "Failed to send message - service not bound");
- return false;
- }
- /* access modifiers changed from: private */
- /* renamed from: a */
- public void m16295a(C3304h hVar) {
- byte[] b = hVar.mo16537b();
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- if (b != null) {
- try {
- byteArrayOutputStream.write(b);
- byteArrayOutputStream.write(f9562g);
- } catch (IOException e) {
- String str = f9558c;
- StringBuilder sb = new StringBuilder();
- sb.append("IOException adding public key to array");
- sb.append(e.getMessage());
- C3356b.m16681c(str, sb.toString());
- }
- } else {
- byteArrayOutputStream.write(m16297a(28435));
- }
- sendResponseApdu(byteArrayOutputStream.toByteArray());
- String str2 = f9558c;
- StringBuilder sb2 = new StringBuilder();
- sb2.append("APDU Response (Get Pub key):");
- sb2.append(byteArrayOutputStream.toByteArray().toString());
- C3356b.m16680b(str2, sb2.toString());
- String str3 = f9558c;
- StringBuilder sb3 = new StringBuilder();
- sb3.append("APDU Response (Get Pub key):Length =");
- sb3.append(byteArrayOutputStream.size());
- C3356b.m16680b(str3, sb3.toString());
- }
- /* access modifiers changed from: private */
- /* renamed from: a */
- public void m16294a(C3295c cVar) {
- byte[] a = cVar.mo16505a();
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- if (a != null) {
- try {
- byteArrayOutputStream.write(Arrays.copyOfRange(a, 0, 16));
- byteArrayOutputStream.write(f9562g);
- } catch (IOException e) {
- String str = f9558c;
- StringBuilder sb = new StringBuilder();
- sb.append("Exception adding encrypted response to the message");
- sb.append(e.getMessage());
- C3356b.m16681c(str, sb.toString());
- }
- } else {
- byteArrayOutputStream.write(m16297a(28442));
- }
- sendResponseApdu(byteArrayOutputStream.toByteArray());
- String str2 = f9558c;
- StringBuilder sb2 = new StringBuilder();
- sb2.append("APDU Response (Get Auth response):");
- sb2.append(byteArrayOutputStream.toByteArray().toString());
- C3356b.m16680b(str2, sb2.toString());
- String str3 = f9558c;
- StringBuilder sb3 = new StringBuilder();
- sb3.append("APDU Response (Get Auth response):Length =");
- sb3.append(byteArrayOutputStream.size());
- C3356b.m16680b(str3, sb3.toString());
- }
- public byte[] processCommandApdu(byte[] bArr, Bundle bundle) {
- C3356b.m16680b(f9558c, "Called Tesla Logic applet");
- byte[] bArr2 = f9562g;
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- byte b = bArr[1];
- if (b == -92) {
- bArr2 = f9562g;
- C3356b.m16680b(f9558c, "Called to enable Tesla Logic applet");
- } else if (b != 4) {
- if (b != 17) {
- if (b == 20) {
- try {
- byteArrayOutputStream.write(m16297a(49));
- } catch (IOException e) {
- String str = f9558c;
- StringBuilder sb = new StringBuilder();
- sb.append("Exception when sending form factor");
- sb.append(e.getMessage());
- C3356b.m16681c(str, sb.toString());
- }
- } else if (b != 27) {
- bArr2 = f9563h;
- } else {
- C3356b.m16680b(f9558c, "Got Vehicle Info");
- if (bArr[4] < 30) {
- byte[] copyOfRange = Arrays.copyOfRange(bArr, 5, bArr[4] + 5);
- String str2 = f9558c;
- StringBuilder sb2 = new StringBuilder();
- sb2.append("From Vehicle Protobuf : ");
- sb2.append(C3332g.m16627a(copyOfRange));
- C3356b.m16680b(str2, sb2.toString());
- Message obtain = Message.obtain();
- obtain.what = C3299e.NFCProtoMessage.mo16522a();
- Bundle bundle2 = new Bundle();
- bundle2.putByteArray(C3299e.NFCProtoMessage.mo16523b(), copyOfRange);
- obtain.setData(bundle2);
- if (!m16296a(obtain)) {
- bArr2 = m16297a(28442);
- }
- } else {
- C3356b.m16680b(f9558c, "Ignore Vehicle proto, too long info");
- }
- }
- } else if (((short) bArr[2]) != 0) {
- bArr2 = f9564i;
- } else if (bArr[4] != 81) {
- bArr2 = m16297a(28441);
- } else {
- byte[] copyOfRange2 = Arrays.copyOfRange(bArr, 5, 70);
- byte[] copyOfRange3 = Arrays.copyOfRange(bArr, 70, 86);
- String str3 = f9558c;
- StringBuilder sb3 = new StringBuilder();
- sb3.append("Requested Vehicle Public Key :");
- sb3.append(C3332g.m16627a(copyOfRange2));
- C3356b.m16680b(str3, sb3.toString());
- String str4 = f9558c;
- StringBuilder sb4 = new StringBuilder();
- sb4.append("Requested Vehicle Token :");
- sb4.append(C3332g.m16627a(copyOfRange3));
- C3356b.m16680b(str4, sb4.toString());
- Message obtain2 = Message.obtain();
- obtain2.what = C3299e.NFCEncryptWithSharedSecret.mo16522a();
- Bundle bundle3 = new Bundle();
- ArrayList arrayList = new ArrayList();
- arrayList.add(C3332g.m16627a(copyOfRange3));
- arrayList.add(C3332g.m16627a(copyOfRange2));
- bundle3.putStringArrayList(C3299e.NFCEncryptWithSharedSecret.mo16523b(), arrayList);
- obtain2.setData(bundle3);
- if (m16296a(obtain2)) {
- return null;
- }
- bArr2 = m16297a(28442);
- }
- } else if (((short) bArr[2]) != 0) {
- bArr2 = f9564i;
- } else {
- Message obtain3 = Message.obtain();
- obtain3.what = C3299e.NFCGetPublicKeyBytes.mo16522a();
- if (m16296a(obtain3)) {
- return null;
- }
- bArr2 = m16297a(28435);
- }
- try {
- byteArrayOutputStream.write(bArr2);
- } catch (IOException e2) {
- String str5 = f9558c;
- StringBuilder sb5 = new StringBuilder();
- sb5.append("Exception adding status code");
- sb5.append(e2.getMessage());
- C3356b.m16681c(str5, sb5.toString());
- }
- String str6 = f9558c;
- StringBuilder sb6 = new StringBuilder();
- sb6.append("APDU Response :");
- sb6.append(byteArrayOutputStream.toByteArray().toString());
- C3356b.m16680b(str6, sb6.toString());
- String str7 = f9558c;
- StringBuilder sb7 = new StringBuilder();
- sb7.append("APDU Response :Length =");
- sb7.append(byteArrayOutputStream.size());
- C3356b.m16680b(str7, sb7.toString());
- return byteArrayOutputStream.toByteArray();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement