Browse Source

get rid of apache commons codec entirely

master
Peter Cai 3 weeks ago
parent
commit
2034d72b60
  1. 1
      libs/lpad-sm-dp-plus-connector/build.gradle
  2. 27
      libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/HandleNotificationsWorker.java
  3. 31
      libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/download/AuthenticatingPhaseWorker.java
  4. 6
      libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/download/DownloadPhaseWorker.java

1
libs/lpad-sm-dp-plus-connector/build.gradle

@ -9,7 +9,6 @@ dependencies {
tool 'javax.xml.bind:jaxb-api:2.3.0'
tool 'com.beanit:asn1bean-compiler:1.13.0'
implementation 'com.beanit:asn1bean:1.13.0'
implementation 'commons-codec:commons-codec:1.11'
implementation 'com.google.code.gson:gson:2.8.4'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-all:1.10.19'

27
libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/HandleNotificationsWorker.java

@ -1,20 +1,19 @@
package com.truphone.lpa.impl;
import com.truphone.rsp.dto.asn1.rspdefinitions.*;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
import com.beanit.asn1bean.ber.ReverseByteArrayOutputStream;
import com.truphone.es9plus.Es9PlusImpl;
import com.truphone.lpa.ApduChannel;
import com.truphone.lpa.apdu.ApduUtils;
import com.truphone.lpa.apdu.NotificationType;
import com.truphone.util.LogStub;
import com.truphone.util.TextUtil;
import com.truphone.util.Util;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Base64;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -48,7 +47,7 @@ public class HandleNotificationsWorker {
handlePendingNotification(seqNo, notificationListResponse);
}
} 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 profiles. Exception in Decoder:" + e.getMessage());
@ -60,8 +59,8 @@ public class HandleNotificationsWorker {
}
}
private void decodeNotificationList(String notificationList, ListNotificationResponse list) throws DecoderException, IOException {
InputStream is = new ByteArrayInputStream(Hex.decodeHex(notificationList.toCharArray()));
private void decodeNotificationList(String notificationList, ListNotificationResponse list) throws NumberFormatException, IOException {
InputStream is = new ByteArrayInputStream(TextUtil.decodeHex(notificationList));
list.decode(is, true);
@ -93,7 +92,7 @@ public class HandleNotificationsWorker {
return notificationList;
}
private void handlePendingNotification(int seqNo, RetrieveNotificationsListResponse notificationListResponse) throws IOException, DecoderException {
private void handlePendingNotification(int seqNo, RetrieveNotificationsListResponse notificationListResponse) throws IOException, NumberFormatException {
if (notificationListResponse != null && notificationListResponse.getNotificationList() != null &&
notificationListResponse.getNotificationList().getPendingNotification() != null)
@ -114,7 +113,7 @@ public class HandleNotificationsWorker {
}
}
private RetrieveNotificationsListResponse getRetrieveNotificationsListResponse(int seqNo) throws DecoderException, IOException {
private RetrieveNotificationsListResponse getRetrieveNotificationsListResponse(int seqNo) throws NumberFormatException, IOException {
String retrieveNotificationFromListApdu = ApduUtils.retrievePendingNotificationsListApdu(seqNo);
if (LogStub.getInstance().isDebugEnabled()) {
@ -130,8 +129,8 @@ public class HandleNotificationsWorker {
return decodeNotificationResponse(notificationResponse);
}
private RetrieveNotificationsListResponse decodeNotificationResponse(String notificationResponse) throws DecoderException, IOException {
InputStream is3 = new ByteArrayInputStream(Hex.decodeHex(notificationResponse.toCharArray()));
private RetrieveNotificationsListResponse decodeNotificationResponse(String notificationResponse) throws NumberFormatException, IOException {
InputStream is3 = new ByteArrayInputStream(TextUtil.decodeHex(notificationResponse));
RetrieveNotificationsListResponse notificationListResponse = new RetrieveNotificationsListResponse();
notificationListResponse.decode(is3, true);
@ -154,7 +153,7 @@ public class HandleNotificationsWorker {
LogStub.getInstance().logDebug(LOG, LogStub.getInstance().getTag() + " - Pending notification: " + pendingNotificationStr);
}
String encodedPendingNotification = Base64.encodeBase64String(Util.hexStringToByteArray(pendingNotificationStr));
String encodedPendingNotification = Base64.getEncoder().encodeToString(Util.hexStringToByteArray(pendingNotificationStr));
if (LogStub.getInstance().isDebugEnabled()) {
LogStub.getInstance().logDebug(LOG, LogStub.getInstance().getTag() + " - Encoded pending notification: " + encodedPendingNotification);
@ -164,7 +163,7 @@ public class HandleNotificationsWorker {
return encodedPendingNotification;
}
private void removeNotification(int seqNo) throws DecoderException, IOException {
private void removeNotification(int seqNo) throws NumberFormatException, IOException {
String removeNotificationApdu = ApduUtils.removeNotificationFromListApdu(seqNo);
if (LogStub.getInstance().isDebugEnabled()) {
@ -180,8 +179,8 @@ public class HandleNotificationsWorker {
decodeRemoveNotification(removeNotificationResponse);
}
private void decodeRemoveNotification(String removeNotificationResponse) throws DecoderException, IOException {
InputStream is2 = new ByteArrayInputStream(Hex.decodeHex(removeNotificationResponse.toCharArray()));
private void decodeRemoveNotification(String removeNotificationResponse) throws NumberFormatException, IOException {
InputStream is2 = new ByteArrayInputStream(TextUtil.decodeHex(removeNotificationResponse));
NotificationSentResponse notificationSentResponse = new NotificationSentResponse();
notificationSentResponse.decode(is2, true);

31
libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/download/AuthenticatingPhaseWorker.java

@ -11,14 +11,13 @@ import com.truphone.lpa.progress.DownloadProgress;
import com.truphone.lpa.progress.DownloadProgressPhase;
import com.truphone.rsp.dto.asn1.rspdefinitions.GetEuiccChallengeResponse;
import com.truphone.util.LogStub;
import com.truphone.util.TextUtil;
import com.truphone.util.Util;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Base64;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -57,7 +56,7 @@ public class AuthenticatingPhaseWorker {
LogStub.getInstance().logDebug(LOG, LogStub.getInstance().getTag() + " - EUICC Info Object: " + euiccInfo1);
}
euiccInfo1 = Base64.encodeBase64String(Util.hexStringToByteArray(euiccInfo1));
euiccInfo1 = Base64.getEncoder().encodeToString(Util.hexStringToByteArray(euiccInfo1));
if (LogStub.getInstance().isDebugEnabled()) {
LogStub.getInstance().logDebug(LOG, LogStub.getInstance().getTag() + " - EUICC Info Object (Base 64): " + euiccInfo1);
@ -81,12 +80,12 @@ public class AuthenticatingPhaseWorker {
progress.stepExecuted(DOWNLOAD_PROFILE_CONVERTING_EUICC_CHALLENGE, "convertEuiccChallenge converting...");
try {
euiccChallenge = Base64.encodeBase64String(Util.hexStringToByteArray(decodeGetEuiccChallengeResponse(euiccChallengeApduResponse)));
euiccChallenge = Base64.getEncoder().encodeToString(Util.hexStringToByteArray(decodeGetEuiccChallengeResponse(euiccChallengeApduResponse)));
if (LogStub.getInstance().isDebugEnabled()) {
LogStub.getInstance().logDebug(LOG, LogStub.getInstance().getTag() + " - eUICCChallenge is " + euiccChallenge);
}
} 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 challenge. Exception in Decoder:" + e.getMessage());
@ -105,13 +104,13 @@ public class AuthenticatingPhaseWorker {
return euiccChallenge;
}
private String decodeGetEuiccChallengeResponse(String euiccChallengeApduResponse) throws DecoderException, IOException {
private String decodeGetEuiccChallengeResponse(String euiccChallengeApduResponse) throws NumberFormatException, IOException {
InputStream is = null;
try {
GetEuiccChallengeResponse euiccChallengeResponse = new GetEuiccChallengeResponse();
is = new ByteArrayInputStream(Hex.decodeHex(euiccChallengeApduResponse.toCharArray()));
is = new ByteArrayInputStream(TextUtil.decodeHex(euiccChallengeApduResponse));
euiccChallengeResponse.decode(is);
@ -176,7 +175,7 @@ public class AuthenticatingPhaseWorker {
private void setServerCertificate(InitialAuthenticationKeys initialAuthenticationKeys, InitiateAuthenticationResp initiateAuthenticationResp) {
initialAuthenticationKeys.setServerCertificate(initiateAuthenticationResp.getServerCertificate());
initialAuthenticationKeys.setServerCertificate(Util.byteArrayToHexString(Base64.decodeBase64(initialAuthenticationKeys.getServerCertificate()), ""));
initialAuthenticationKeys.setServerCertificate(Util.byteArrayToHexString(Base64.getDecoder().decode(initialAuthenticationKeys.getServerCertificate()), ""));
if (LogStub.getInstance().isDebugEnabled()) {
LogStub.getInstance().logDebug(LOG, LogStub.getInstance().getTag() + " - serverCertificate: " + initialAuthenticationKeys.getServerCertificate());
@ -186,7 +185,7 @@ public class AuthenticatingPhaseWorker {
private void setEuiccCiPKIdToveUsed(InitialAuthenticationKeys initialAuthenticationKeys, InitiateAuthenticationResp initiateAuthenticationResp) {
initialAuthenticationKeys.setEuiccCiPKIdTobeUsed(initiateAuthenticationResp.getEuiccCiPKIdToBeUsed());
initialAuthenticationKeys.setEuiccCiPKIdTobeUsed(Util.byteArrayToHexString(Base64.decodeBase64(initialAuthenticationKeys.getEuiccCiPKIdTobeUsed()), ""));
initialAuthenticationKeys.setEuiccCiPKIdTobeUsed(Util.byteArrayToHexString(Base64.getDecoder().decode(initialAuthenticationKeys.getEuiccCiPKIdTobeUsed()), ""));
if (LogStub.getInstance().isDebugEnabled()) {
LogStub.getInstance().logDebug(LOG, LogStub.getInstance().getTag() + " - euiccCiPKIdTobeUsed: " + initialAuthenticationKeys.getEuiccCiPKIdTobeUsed());
@ -196,7 +195,7 @@ public class AuthenticatingPhaseWorker {
private void setServerSignature1(InitialAuthenticationKeys initialAuthenticationKeys, InitiateAuthenticationResp initiateAuthenticationResp) {
initialAuthenticationKeys.setServerSignature1(initiateAuthenticationResp.getServerSignature1());
initialAuthenticationKeys.setServerSignature1(Util.byteArrayToHexString(Base64.decodeBase64(initialAuthenticationKeys.getServerSignature1()), ""));
initialAuthenticationKeys.setServerSignature1(Util.byteArrayToHexString(Base64.getDecoder().decode(initialAuthenticationKeys.getServerSignature1()), ""));
if (LogStub.getInstance().isDebugEnabled()) {
LogStub.getInstance().logDebug(LOG, LogStub.getInstance().getTag() + " - serverSignature1: " + initialAuthenticationKeys.getServerSignature1());
@ -206,7 +205,7 @@ public class AuthenticatingPhaseWorker {
private void setServerSigned1(InitialAuthenticationKeys initialAuthenticationKeys, InitiateAuthenticationResp initiateAuthenticationResp) {
initialAuthenticationKeys.setServerSigned1(initiateAuthenticationResp.getServerSigned1());
initialAuthenticationKeys.setServerSigned1(Util.byteArrayToHexString(Base64.decodeBase64(initialAuthenticationKeys.getServerSigned1()), ""));
initialAuthenticationKeys.setServerSigned1(Util.byteArrayToHexString(Base64.getDecoder().decode(initialAuthenticationKeys.getServerSigned1()), ""));
if (LogStub.getInstance().isDebugEnabled()) {
LogStub.getInstance().logDebug(LOG, LogStub.getInstance().getTag() + " - serverSigned1: " + initialAuthenticationKeys.getServerSigned1());
@ -239,9 +238,9 @@ public class AuthenticatingPhaseWorker {
private AuthenticateClientSmDp convertAuthenticateClientResp(AuthenticateClientResp authenticateClientResp) {
AuthenticateClientSmDp authenticateClientSmDp = new AuthenticateClientSmDp();
authenticateClientSmDp.setSmdpSigned2(Util.byteArrayToHexString(Base64.decodeBase64(authenticateClientResp.getSmdpSigned2()), ""));
authenticateClientSmDp.setSmdpSignature2(Util.byteArrayToHexString(Base64.decodeBase64(authenticateClientResp.getSmdpSignature2()), ""));
authenticateClientSmDp.setSmdpCertificate(Util.byteArrayToHexString(Base64.decodeBase64(authenticateClientResp.getSmdpCertificate()), ""));
authenticateClientSmDp.setSmdpSigned2(Util.byteArrayToHexString(Base64.getDecoder().decode(authenticateClientResp.getSmdpSigned2()), ""));
authenticateClientSmDp.setSmdpSignature2(Util.byteArrayToHexString(Base64.getDecoder().decode(authenticateClientResp.getSmdpSignature2()), ""));
authenticateClientSmDp.setSmdpCertificate(Util.byteArrayToHexString(Base64.getDecoder().decode(authenticateClientResp.getSmdpCertificate()), ""));
if (LogStub.getInstance().isDebugEnabled()) {
LogStub.getInstance().logDebug(LOG, LogStub.getInstance().getTag() + " - authenticateClient returning: " + authenticateClientSmDp);
@ -276,7 +275,7 @@ public class AuthenticatingPhaseWorker {
initialAuthenticationKeys.getServerSignature1(),
initialAuthenticationKeys.getEuiccCiPKIdTobeUsed(), initialAuthenticationKeys.getServerCertificate(),
initialAuthenticationKeys.getCtxParams1()));
String encodedAuthenticateServerResponse = Base64.encodeBase64String(Util.hexStringToByteArray(authenticateServerResponse));
String encodedAuthenticateServerResponse = Base64.getEncoder().encodeToString(Util.hexStringToByteArray(authenticateServerResponse));
if (LogStub.getInstance().isDebugEnabled()) {
LogStub.getInstance().logDebug(LOG, LogStub.getInstance().getTag() + " - Authenticate server response (base64): " + encodedAuthenticateServerResponse);

6
libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/lpa/impl/download/DownloadPhaseWorker.java

@ -2,7 +2,6 @@ package com.truphone.lpa.impl.download;
import com.truphone.lpa.impl.InitialAuthenticationKeys;
import org.apache.commons.codec.binary.Base64;
import com.truphone.es9plus.Es9PlusImpl;
import com.truphone.es9plus.message.response.GetBoundProfilePackageResp;
import com.truphone.lpa.apdu.ApduUtils;
@ -13,6 +12,7 @@ import com.truphone.lpad.progress.ProgressStep;
import com.truphone.util.LogStub;
import com.truphone.util.Util;
import java.util.Base64;
import java.util.logging.Logger;
public class DownloadPhaseWorker {
@ -37,7 +37,7 @@ public class DownloadPhaseWorker {
String prepareDownloadResponse = apduTransmitter.transmitApdus(ApduUtils.prepareDownloadApdu(authenticateClientSmDp.getSmdpSigned2(),
authenticateClientSmDp.getSmdpSignature2(), authenticateClientSmDp.getSmdpCertificate(),
null));
String encodedPrepareDownloadResponse = Base64.encodeBase64String(Util.hexStringToByteArray(prepareDownloadResponse));
String encodedPrepareDownloadResponse = Base64.getEncoder().encodeToString(Util.hexStringToByteArray(prepareDownloadResponse));
if (LogStub.getInstance().isDebugEnabled()) {
LogStub.getInstance().logDebug(LOG, LogStub.getInstance().getTag() + " - Prepare download response (base64): " + encodedPrepareDownloadResponse);
@ -54,7 +54,7 @@ public class DownloadPhaseWorker {
"downloadAndInstallProfilePackage retrieving...");
GetBoundProfilePackageResp getBoundProfilePackageResp = getGetBoundProfilePackageResp(initialAuthenticationKeys, encodedPrepareDownloadResponse, initialAuthenticationKeys.getEuiccConfiguredAddress());
String bpp = Util.byteArrayToHexString(Base64.decodeBase64(getBoundProfilePackageResp.getBoundProfilePackage()), "");
String bpp = Util.byteArrayToHexString(Base64.getDecoder().decode(getBoundProfilePackageResp.getBoundProfilePackage()), "");
progress.stepExecuted(ProgressStep.DOWNLOAD_PROFILE_BOUND_PROFILE_PACKAGE_RETRIEVED,
"downloadAndInstallProfilePackage retrieved...");

Loading…
Cancel
Save