diff --git a/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/DisableProfileWorker.java b/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/DisableProfileWorker.java index b504baa..7c96efa 100644 --- a/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/DisableProfileWorker.java +++ b/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/DisableProfileWorker.java @@ -7,8 +7,7 @@ import com.truphone.lpad.progress.Progress; import com.truphone.lpad.progress.ProgressStep; import com.truphone.rsp.dto.asn1.rspdefinitions.DisableProfileResponse; import com.truphone.util.LogStub; -import org.apache.commons.codec.DecoderException; -import org.apache.commons.codec.binary.Hex; +import com.truphone.util.TextUtil; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -41,7 +40,7 @@ class DisableProfileWorker { progress.stepExecuted(ProgressStep.DISABLE_PROFILE_CONVERTING_RESPONSE, "Converting response"); try { - InputStream is = new ByteArrayInputStream(Hex.decodeHex(eResponse.toCharArray())); + InputStream is = new ByteArrayInputStream(TextUtil.decodeHex(eResponse)); DisableProfileResponse disableProfileResponse = new DisableProfileResponse(); disableProfileResponse.decode(is); @@ -67,7 +66,7 @@ class DisableProfileWorker { LOG.log(Level.SEVERE, LogStub.getInstance().getTag() + " - iccid: " + iccid + " profile failed to be disabled"); throw new RuntimeException("Unable to disable profile: " + iccid + ", response: " + eResponse); - } catch (DecoderException e) { + } catch (NumberFormatException e) { LOG.log(Level.SEVERE, LogStub.getInstance().getTag() + " - " + e.getMessage(), e); LOG.log(Level.SEVERE, LogStub.getInstance().getTag() + " - iccid: " + iccid + " profile failed to be disabled. Exception in Decoder:" + e.getMessage()); diff --git a/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/EnableProfileWorker.java b/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/EnableProfileWorker.java index 8010c54..24ef9bc 100644 --- a/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/EnableProfileWorker.java +++ b/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/EnableProfileWorker.java @@ -7,8 +7,7 @@ import com.truphone.lpad.progress.Progress; import com.truphone.lpad.progress.ProgressStep; import com.truphone.rsp.dto.asn1.rspdefinitions.EnableProfileResponse; import com.truphone.util.LogStub; -import org.apache.commons.codec.DecoderException; -import org.apache.commons.codec.binary.Hex; +import com.truphone.util.TextUtil; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -42,7 +41,7 @@ class EnableProfileWorker { try { EnableProfileResponse enableProfileResponse = new EnableProfileResponse(); - InputStream is = new ByteArrayInputStream(Hex.decodeHex(eResponse.toCharArray())); + InputStream is = new ByteArrayInputStream(TextUtil.decodeHex(eResponse)); enableProfileResponse.decode(is); @@ -72,7 +71,7 @@ class EnableProfileWorker { LOG.severe(LogStub.getInstance().getTag() + " - iccid: " + iccid + " profile failed to be enabled. message: " + e.getMessage()); throw new RuntimeException("Unable to enable profile: " + iccid + ", response: " + eResponse); - } catch (DecoderException e) { + } catch (NumberFormatException e) { LOG.log(Level.SEVERE, LogStub.getInstance().getTag() + " - " + e.getMessage(), e); LOG.severe(LogStub.getInstance().getTag() + " - iccid: " + iccid + " profile failed to be enabled. Exception in Decoder:" + e.getMessage()); diff --git a/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/GetSMDPAddressWorker.java b/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/GetSMDPAddressWorker.java index d991010..f82f665 100644 --- a/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/GetSMDPAddressWorker.java +++ b/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/GetSMDPAddressWorker.java @@ -16,8 +16,6 @@ import java.io.IOException; import java.io.InputStream; import java.util.logging.Level; import java.util.logging.Logger; -import org.apache.commons.codec.DecoderException; -import org.apache.commons.codec.binary.Hex; /** * diff --git a/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/ListProfilesWorker.kt b/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/ListProfilesWorker.kt index 3120078..9c5d150 100644 --- a/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/ListProfilesWorker.kt +++ b/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/ListProfilesWorker.kt @@ -18,13 +18,13 @@ import com.truphone.lpa.ApduChannel import com.truphone.lpa.LocalProfileInfo import com.truphone.rsp.dto.asn1.rspdefinitions.ProfileInfoListResponse import com.truphone.util.LogStub -import org.apache.commons.codec.DecoderException -import org.apache.commons.codec.binary.Hex import com.truphone.lpa.apdu.ApduUtils +import com.truphone.util.TextUtil import com.truphone.util.TextUtil.iccidBigToLittle import java.io.ByteArrayInputStream import java.io.IOException import java.io.InputStream +import java.lang.NumberFormatException import java.lang.RuntimeException import java.util.logging.Level import java.util.logging.Logger @@ -56,7 +56,7 @@ internal class ListProfilesWorker(private val apduChannel: ApduChannel) { ) } profileList - } catch (e: DecoderException) { + } catch (e: NumberFormatException) { LOG.log(Level.SEVERE, LogStub.getInstance().tag + " - " + e.message, e) LOG.log( Level.SEVERE, @@ -69,9 +69,9 @@ internal class ListProfilesWorker(private val apduChannel: ApduChannel) { } } - @Throws(DecoderException::class, IOException::class) + @Throws(NumberFormatException::class, IOException::class) private fun decodeProfiles(profilesInfo: String, profiles: ProfileInfoListResponse) { - val `is`: InputStream = ByteArrayInputStream(Hex.decodeHex(profilesInfo.toCharArray())) + val `is`: InputStream = ByteArrayInputStream(TextUtil.decodeHex(profilesInfo)) profiles.decode(`is`) if (LogStub.getInstance().isDebugEnabled) { LogStub.getInstance().logDebug(LOG, "Profile list object: $profiles") diff --git a/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/SetNicknameWorker.kt b/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/SetNicknameWorker.kt index 3ff406f..c399814 100644 --- a/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/SetNicknameWorker.kt +++ b/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/SetNicknameWorker.kt @@ -17,13 +17,13 @@ package com.truphone.lpa.impl import com.truphone.lpa.ApduChannel import com.truphone.util.LogStub import com.truphone.lpa.apdu.ApduUtils -import org.apache.commons.codec.binary.Hex import com.truphone.rsp.dto.asn1.rspdefinitions.SetNicknameResponse -import org.apache.commons.codec.DecoderException +import com.truphone.util.TextUtil import com.truphone.util.Util import java.io.ByteArrayInputStream import java.io.IOException import java.io.InputStream +import java.lang.NumberFormatException import java.lang.RuntimeException import java.util.logging.Level import java.util.logging.Logger @@ -51,7 +51,7 @@ class SetNicknameWorker internal constructor( ) val eResponse = apduChannel.transmitAPDU(apdu) return try { - val `is`: InputStream = ByteArrayInputStream(Hex.decodeHex(eResponse.toCharArray())) + val `is`: InputStream = ByteArrayInputStream(TextUtil.decodeHex(eResponse)) val response = SetNicknameResponse() response.decode(`is`) if ("0" == response.setNicknameResult.toString()) { @@ -75,7 +75,7 @@ class SetNicknameWorker internal constructor( LogStub.getInstance().tag + " - iccid: " + iccid + " profile failed to be renamed" ) throw RuntimeException("Unable to rename profile: $iccid, response: $eResponse") - } catch (e: DecoderException) { + } catch (e: NumberFormatException) { LOG.log(Level.SEVERE, LogStub.getInstance().tag + " - " + e.message, e) LOG.log( Level.SEVERE, diff --git a/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/SmdsRetrieveEventsWorker.java b/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/SmdsRetrieveEventsWorker.java index 61d5a77..a75dc1b 100644 --- a/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/SmdsRetrieveEventsWorker.java +++ b/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/SmdsRetrieveEventsWorker.java @@ -16,8 +16,6 @@ import java.io.IOException; import java.io.InputStream; import java.util.logging.Level; import java.util.logging.Logger; -import org.apache.commons.codec.DecoderException; -import org.apache.commons.codec.binary.Hex; /** * diff --git a/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/download/ConnectingPhaseWorker.java b/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/download/ConnectingPhaseWorker.java index 2cc6e31..012ed38 100644 --- a/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/download/ConnectingPhaseWorker.java +++ b/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/download/ConnectingPhaseWorker.java @@ -7,8 +7,7 @@ import com.truphone.lpa.progress.DownloadProgressPhase; import com.truphone.lpad.progress.ProgressStep; import com.truphone.rsp.dto.asn1.rspdefinitions.EuiccConfiguredAddressesResponse; import com.truphone.util.LogStub; -import org.apache.commons.codec.DecoderException; -import org.apache.commons.codec.binary.Hex; +import com.truphone.util.TextUtil; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -59,7 +58,7 @@ public class ConnectingPhaseWorker { } return euiccConfiguredAddress; - } catch (DecoderException e) { + } catch (NumberFormatException e) { LOG.log(Level.SEVERE, "KOL.007" + e.getMessage(), e); LOG.severe(LogStub.getInstance().getTag() + " - matchingId: " + matchingId + " Unable to retrieve eUICC configured address. Exception in Decoder:" + e.getMessage()); @@ -74,12 +73,12 @@ public class ConnectingPhaseWorker { } } - private EuiccConfiguredAddressesResponse decodeEuiccConfiguredAddressesResponse(String euiCCConfiguredAddressAPDUResponse) throws DecoderException, IOException { + private EuiccConfiguredAddressesResponse decodeEuiccConfiguredAddressesResponse(String euiCCConfiguredAddressAPDUResponse) throws NumberFormatException, IOException { InputStream is = null; try { EuiccConfiguredAddressesResponse euiccConfiguredAddressesResponse = new EuiccConfiguredAddressesResponse(); - is = new ByteArrayInputStream(Hex.decodeHex(euiCCConfiguredAddressAPDUResponse.toCharArray())); + is = new ByteArrayInputStream(TextUtil.decodeHex(euiCCConfiguredAddressAPDUResponse)); euiccConfiguredAddressesResponse.decode(is); diff --git a/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/download/GeneratePhaseWorker.java b/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/download/GeneratePhaseWorker.java index 285ece2..5d7a118 100644 --- a/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/download/GeneratePhaseWorker.java +++ b/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/download/GeneratePhaseWorker.java @@ -8,8 +8,7 @@ import com.truphone.lpa.progress.DownloadProgressPhase; import com.truphone.lpad.progress.ProgressStep; import com.truphone.rsp.dto.asn1.rspdefinitions.BoundProfilePackage; import com.truphone.util.LogStub; -import org.apache.commons.codec.DecoderException; -import org.apache.commons.codec.binary.Hex; +import com.truphone.util.TextUtil; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -100,12 +99,12 @@ public class GeneratePhaseWorker { BoundProfilePackage bppObj = new BoundProfilePackage(); try { - bppIs = new ByteArrayInputStream(Hex.decodeHex(bpp.toCharArray())); + bppIs = new ByteArrayInputStream(TextUtil.decodeHex(bpp)); bppObj.decode(bppIs); LogStub.getInstance().logDebug(LOG, LogStub.getInstance().getTag() + " - BPP Object is: " + bppObj); - } catch (DecoderException e) { + } catch (NumberFormatException e) { LOG.log(Level.INFO, LogStub.getInstance().getTag() + " - " + e.getMessage(), e); } finally { CloseResources.closeResources(bppIs); diff --git a/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/download/InstallationPhaseWorker.java b/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/download/InstallationPhaseWorker.java index 9916693..537e8cb 100644 --- a/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/download/InstallationPhaseWorker.java +++ b/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/download/InstallationPhaseWorker.java @@ -9,9 +9,6 @@ import com.truphone.rsp.dto.asn1.rspdefinitions.ProfileInstallationResultData; import com.truphone.util.LogStub; import com.truphone.util.TextUtil; -import org.apache.commons.codec.DecoderException; -import org.apache.commons.codec.binary.Hex; - import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -168,7 +165,7 @@ public class InstallationPhaseWorker { throw new RuntimeException(errorMessage); } - } catch (DecoderException e) { + } catch (NumberFormatException e) { LOG.log(Level.SEVERE, LogStub.getInstance().getTag() + " - " + e.getMessage(), e); LOG.severe(LogStub.getInstance().getTag() + " - Unable to retrieve Profile Installation Result. Exception in Decoder:" + e.getMessage()); @@ -199,7 +196,7 @@ public class InstallationPhaseWorker { return errorMessage; } - private ProfileInstallationResult getProfileInstallationResult(String profileInstallationResultRaw) throws DecoderException, IOException { + private ProfileInstallationResult getProfileInstallationResult(String profileInstallationResultRaw) throws NumberFormatException, IOException { InputStream is = null; if (LogStub.getInstance().isDebugEnabled()) { @@ -209,7 +206,7 @@ public class InstallationPhaseWorker { try { ProfileInstallationResult profileInstallationResult = new ProfileInstallationResult(); - is = new ByteArrayInputStream(Hex.decodeHex(profileInstallationResultRaw.toCharArray())); + is = new ByteArrayInputStream(TextUtil.decodeHex(profileInstallationResultRaw)); profileInstallationResult.decode(is, true); diff --git a/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpad/worker/DeleteProfileWorker.java b/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpad/worker/DeleteProfileWorker.java index 7c9d5fe..cd0a43c 100644 --- a/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpad/worker/DeleteProfileWorker.java +++ b/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpad/worker/DeleteProfileWorker.java @@ -9,9 +9,6 @@ import com.truphone.rsp.dto.asn1.rspdefinitions.DeleteProfileResponse; import com.truphone.util.LogStub; import com.truphone.util.TextUtil; -import org.apache.commons.codec.DecoderException; -import org.apache.commons.codec.binary.Hex; - import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -71,7 +68,7 @@ public class DeleteProfileWorker implements LpadWorker, logDebug("Decoding response: " + eidapduResponseStr); - InputStream is = new ByteArrayInputStream(Hex.decodeHex(eidapduResponseStr.toCharArray())); + InputStream is = new ByteArrayInputStream(TextUtil.decodeHex(eidapduResponseStr)); logDebug("Decoding with GetEuiccDataResponse"); @@ -82,7 +79,7 @@ public class GetEidLpadWorker implements LpadWorker, progress.stepExecuted(ProgressStep.GET_EID_CONVERTED, "getEID converted..."); return eidResponse.getEidValue().toString(); - } catch (DecoderException e) { + } catch (NumberFormatException e) { LOG.log(Level.SEVERE, LogStub.getInstance().getTag() + " - " + e.getMessage(), e); LOG.log(Level.SEVERE, LogStub.getInstance().getTag() + " - Unable to retrieve EID. Exception in Decoder:" + e.getMessage()); diff --git a/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/util/TextUtil.kt b/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/util/TextUtil.kt index 014da14..9d7e6c6 100644 --- a/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/util/TextUtil.kt +++ b/libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/util/TextUtil.kt @@ -1,6 +1,7 @@ package com.truphone.util import java.io.InputStream +import java.lang.NumberFormatException import java.lang.StringBuilder object TextUtil { @@ -44,6 +45,21 @@ object TextUtil { return String(result) } + /* + * Decodes a hex string into a byte array + * Adapted from + */ + @JvmStatic + fun decodeHex(str: String): ByteArray { + if (str.length % 2 == 0) { + throw NumberFormatException("Must have an even length") + } + + return str.chunked(2) + .map { it.toInt(16).toByte() } + .toByteArray() + } + /** * Converts a big-endian representation of ICCID into little-endian * Big-endian representation is used internally in communication with the SIM.