Send full IMEI in ctxParams1 for AuthenticateServer APDU request

This commit is contained in:
Peter Cai 2022-05-18 21:55:51 -04:00
parent 0d2bdb3868
commit fba95a3a2c
9 changed files with 25 additions and 24 deletions

View File

@ -7,6 +7,7 @@ data class EuiccChannelInfo(
val slotId: Int,
val cardId: Int,
val name: String,
val imei: String,
val removable: Boolean,
)
@ -16,6 +17,7 @@ abstract class EuiccChannel(
val slotId = info.slotId
val cardId = info.cardId
val name = info.name
val imei = info.imei
val removable = info.removable
abstract val lpa: LocalProfileAssistant

View File

@ -66,6 +66,7 @@ class EuiccChannelManager(private val context: Context) {
uiccInfo.slotIndex,
uiccInfo.cardId,
"SIM ${uiccInfo.slotIndex}",
tm.getImei(uiccInfo.slotIndex),
uiccInfo.isRemovable
)

View File

@ -128,7 +128,7 @@ class ProfileDownloadFragment : DialogFragment(), EuiccFragmentMarker, Toolbar.O
}
private suspend fun doDownloadProfile(server: String, code: String) = withContext(Dispatchers.IO) {
channel.lpa.downloadProfile("1\$${server}\$${code}", DownloadProgress().apply {
channel.lpa.downloadProfile("1\$${server}\$${code}", channel.imei, DownloadProgress().apply {
setProgressListener { _, _, percentage, _ ->
binding.progress.isIndeterminate = false
binding.progress.progress = (percentage * 100).toInt()

View File

@ -1,10 +0,0 @@
package com.truphone.es9plus;
public class LpaUtils {
public static String generateCtxParams1() {
return "";
}
}

View File

@ -19,7 +19,7 @@ public interface LocalProfileAssistant {
String setDefaultSMDP(String smdpAddress, Progress progress);
void downloadProfile(String matchingId, DownloadProgress progress) throws Exception;
void downloadProfile(String matchingId, String imei, DownloadProgress progress) throws Exception;
List<LocalProfileInfo> getProfiles();

View File

@ -34,9 +34,16 @@ public class ApduUtils {
return apdu.toString();
}
public static String generateCtxParams1(String matchingId, String imei) {
String tac = imei.substring(0, 8);
return ToTLV.toTLV("A0",
ToTLV.toTLV("80", matchingId) + ToTLV.toTLV("A1",
ToTLV.toTLV("80", tac) + ToTLV.toTLV("A1", "") + ToTLV.toTLV("82", imei + "F")
));
}
public static List<String> authenticateServerApdu(String smdpSigned1, String smdpSignature1, String euiccCiPKIdToBeUsed,
String cert, String matchingId) {
String sctxParams1 = ToTLV.toTLV("A0", ToTLV.toTLV("80", matchingId) + ToTLV.toTLV("A1", ToTLV.toTLV("80", "35550607") + ToTLV.toTLV("A1", "")));
String cert, String sctxParams1) {
String data = ToTLV.toTLV("BF38", smdpSigned1 + smdpSignature1 + euiccCiPKIdToBeUsed + cert + sctxParams1);
return subCommandData(data, len, false);

View File

@ -17,11 +17,13 @@ class DownloadProfileWorker {
private final DownloadProgress progress;
private final Es9PlusImpl es9Module;
private String matchingId;
private final String imei;
private ApduTransmitter apduTransmitter;
DownloadProfileWorker(String matchingId, DownloadProgress progress, ApduChannel apduChannel, Es9PlusImpl es9Module) {
DownloadProfileWorker(String matchingId, String imei, DownloadProgress progress, ApduChannel apduChannel, Es9PlusImpl es9Module) {
this.matchingId = matchingId;
this.imei = imei;
this.progress = progress;
this.es9Module = es9Module;
apduTransmitter = new ApduTransmitter(apduChannel);
@ -59,7 +61,7 @@ class DownloadProfileWorker {
authenticatingPhaseWorker.getEuiccInfo(),
authenticatingPhaseWorker.getEuiccChallenge(matchingId));
authenticatingPhaseWorker.initiateAuthentication(initialAuthenticationKeys);
authenticatingPhaseWorker.initiateAuthentication(initialAuthenticationKeys, matchingId, imei);
downloadAndInstallProfilePackage(initialAuthenticationKeys,
downloadPhaseWorker.prepareDownload(authenticatingPhaseWorker.authenticateClient(initialAuthenticationKeys,
authenticatingPhaseWorker.authenticateWithEuicc(initialAuthenticationKeys))), downloadPhaseWorker);

View File

@ -74,10 +74,10 @@ public class LocalProfileAssistantImpl implements LocalProfileAssistant {
}
@Override
public void downloadProfile(final String matchingId,
public void downloadProfile(final String matchingId, final String imei,
final DownloadProgress progress) throws Exception {
new DownloadProfileWorker(matchingId, progress, apduChannel, es9Module).run();
new DownloadProfileWorker(matchingId, imei, progress, apduChannel, es9Module).run();
}
@Override

View File

@ -2,7 +2,6 @@ package com.truphone.lpa.impl.download;
import com.truphone.es9plus.Es9PlusImpl;
import com.truphone.es9plus.LpaUtils;
import com.truphone.es9plus.message.response.AuthenticateClientResp;
import com.truphone.es9plus.message.response.InitiateAuthenticationResp;
import com.truphone.lpa.apdu.ApduUtils;
@ -126,7 +125,7 @@ public class AuthenticatingPhaseWorker {
}
}
public void initiateAuthentication(InitialAuthenticationKeys initialAuthenticationKeys) {
public void initiateAuthentication(InitialAuthenticationKeys initialAuthenticationKeys, String matchingId, String imei) {
progress.stepExecuted(DOWNLOAD_PROFILE_INITIATE_AUTHENTICATION, "initiateAuthentication retrieving...");
@ -142,14 +141,14 @@ public class AuthenticatingPhaseWorker {
setServerCertificate(initialAuthenticationKeys, initiateAuthenticationResp);
setTransactionId(initialAuthenticationKeys, initiateAuthenticationResp);
setMatchingId(initialAuthenticationKeys);
setCtxParams1(initialAuthenticationKeys);
setCtxParams1(initialAuthenticationKeys, matchingId, imei);
progress.stepExecuted(DOWNLOAD_PROFILE_INITIATED_AUTHENTICATION, "initiateAuthentication initiated...");
}
private void setCtxParams1(InitialAuthenticationKeys initialAuthenticationKeys) {
private void setCtxParams1(InitialAuthenticationKeys initialAuthenticationKeys, String matchingId, String imei) {
initialAuthenticationKeys.setCtxParams1(LpaUtils.generateCtxParams1());
initialAuthenticationKeys.setCtxParams1(ApduUtils.generateCtxParams1(matchingId, imei));
if (LogStub.getInstance().isDebugEnabled()) {
LogStub.getInstance().logDebug(LOG, LogStub.getInstance().getTag() + " - ctxParams1: " + initialAuthenticationKeys.getCtxParams1());
@ -276,7 +275,7 @@ public class AuthenticatingPhaseWorker {
String authenticateServerResponse = apduTransmitter.transmitApdus(ApduUtils.authenticateServerApdu(initialAuthenticationKeys.getServerSigned1(),
initialAuthenticationKeys.getServerSignature1(),
initialAuthenticationKeys.getEuiccCiPKIdTobeUsed(), initialAuthenticationKeys.getServerCertificate(),
initialAuthenticationKeys.getMatchingId()));
initialAuthenticationKeys.getCtxParams1()));
String encodedAuthenticateServerResponse = Base64.encodeBase64String(Util.hexStringToByteArray(authenticateServerResponse));
if (LogStub.getInstance().isDebugEnabled()) {