diff --git a/.github/workflows/push_trigger.yml b/.github/workflows/push_trigger.yml
index eb9583675b..069ca0539f 100644
--- a/.github/workflows/push_trigger.yml
+++ b/.github/workflows/push_trigger.yml
@@ -56,7 +56,7 @@ jobs:
- name: Build with Maven
run: |
cd commons-packet
- mvn -U -B package -DskipTests --file pom.xml -s $GITHUB_WORKSPACE/settings.xml
+ mvn -U -B package --file pom.xml -s $GITHUB_WORKSPACE/settings.xml
- name: Ready the springboot artifacts
run: find -name '*.jar' -executable -type f -exec zip release.zip {} +
@@ -120,12 +120,12 @@ jobs:
- name: Build with Maven
run: |
cd commons-packet
- mvn -B package -DskipTests --file pom.xml -s $GITHUB_WORKSPACE/settings.xml
+ mvn -B package --file pom.xml -s $GITHUB_WORKSPACE/settings.xml
- name: Publish the maven package
run: |
cd commons-packet
- mvn -B deploy -DskipTests -DaltDeploymentRepository=ossrh::default::${{ secrets.OSSRH_SNAPSHOT_URL }} -s $GITHUB_WORKSPACE/settings.xml -f pom.xml
+ mvn -B deploy -DaltDeploymentRepository=ossrh::default::${{ secrets.OSSRH_SNAPSHOT_URL }} -s $GITHUB_WORKSPACE/settings.xml -f pom.xml
env:
GITHUB_TOKEN: ${{secrets.RELEASE_TOKEN}}
GPG_TTY: $(tty)
@@ -137,7 +137,6 @@ jobs:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} # required
if: failure() # Pick up events even if the job fails or is canceled.
-
docker-commons-packet-service:
needs: build
@@ -198,7 +197,7 @@ jobs:
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} # required
if: failure() # Pick up events even if the job fails or is canceled.
-
+
sonar_analysis:
runs-on: ubuntu-latest
steps:
@@ -222,23 +221,21 @@ jobs:
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-${{ env.BRANCH_NAME }}
-
- - name: Install xmllint
- run: |
- sudo apt-get update
- sudo apt-get install libxml2-utils
-
- name: Setup the settings file for ossrh server
run: echo " ossrh ${{secrets.ossrh_user}} ${{secrets.ossrh_secret}} ossrh true gpg2 ${{secrets.gpg_secret}} allow-snapshots true snapshots-repo https://oss.sonatype.org/content/repositories/snapshots false true releases-repo https://oss.sonatype.org/service/local/staging/deploy/maven2 true false sonar . https://sonarcloud.io false " > $GITHUB_WORKSPACE/settings.xml
+ - name: Build with Maven
+ run: |
+ cd commons-packet
+ mvn -B package -s $GITHUB_WORKSPACE/settings.xml --file pom.xml
- name: Analyze with SonarCloud
run: |
cd commons-packet
- mvn -B -Dgpg.skip -DskipTests verify sonar:sonar -Dsonar.projectKey=mosip_${{ github.event.repository.name }} -Dsonar.organization=${{ secrets.ORG_KEY }} -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }}
+ mvn -B -Dgpg.skip verify sonar:sonar -Dsonar.projectKey=mosip_${{ github.event.repository.name }} -Dsonar.organization=${{ secrets.ORG_KEY }} -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
-
+
- uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
diff --git a/commons-packet/commons-packet-manager/pom.xml b/commons-packet/commons-packet-manager/pom.xml
index f7685333da..1234072f71 100644
--- a/commons-packet/commons-packet-manager/pom.xml
+++ b/commons-packet/commons-packet-manager/pom.xml
@@ -146,6 +146,11 @@
${junit.version}
test
+
+ org.apache.commons
+ commons-collections4
+ 4.4
+
diff --git a/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/audit/AuditLogEntry.java b/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/audit/AuditLogEntry.java
index 2a266135c2..b846060655 100644
--- a/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/audit/AuditLogEntry.java
+++ b/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/audit/AuditLogEntry.java
@@ -30,7 +30,6 @@ public class AuditLogEntry {
@Autowired
@Lazy
- @Qualifier("restTemplate")
private RestTemplate restTemplate;
@Autowired
diff --git a/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/constants/PacketManagerConstants.java b/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/constants/PacketManagerConstants.java
index ec2746a467..9d22232ff1 100644
--- a/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/constants/PacketManagerConstants.java
+++ b/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/constants/PacketManagerConstants.java
@@ -86,6 +86,7 @@ public class PacketManagerConstants {
public static final String VALUE = "value";
public static final String TYPE = "type";
public static final String FORMAT = "format";
+ public static final String REFNUMBER = "refNumber";
public static final String IDSCHEMA_URL = "IDSCHEMA";
public static final String SCHEMA_JSON = "schemaJson";
diff --git a/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/constants/PacketUtilityErrorCodes.java b/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/constants/PacketUtilityErrorCodes.java
index 30de54991f..586e69b0cb 100644
--- a/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/constants/PacketUtilityErrorCodes.java
+++ b/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/constants/PacketUtilityErrorCodes.java
@@ -1,52 +1,53 @@
-package io.mosip.commons.packet.constants;
-
-public enum PacketUtilityErrorCodes {
-
- UNKNOWN_RESOURCE_EXCEPTION("KER-PUT-001",
- "Unknown resource provided"),
- FILE_NOT_FOUND_IN_DESTINATION("KER-PUT-002", "Unable to Find File in Destination Folder"),
- PACKET_DECRYPTION_FAILURE_EXCEPTION("KER-PUT-003", "Packet decryption failed"),
- API_NOT_ACCESSIBLE_EXCEPTION("KER-PUT-005", "API not accessible"),
- SYS_IO_EXCEPTION("KER-PUT-004", "Unable to Find File in Destination Folder"),
- GET_ALL_IDENTITY_EXCEPTION("KER-PUT-005", "Unable to fetch identity json from all sub packets"),
- NO_AVAILABLE_PROVIDER("KER-PUT-006", "No available provider for given source and process"),
- BIOMETRIC_FIELDNAME_NOT_FOUND("KER-PUT-007", "Biometric fieldname is not present inside packet"),
- GET_ALL_METAINFO_EXCEPTION("KER-PUT-008", "Unable to fetch meta information from all sub packets"),
- ZIP_PARSING_EXCEPTION("KER-PUT-009", "Unable to parse the zip"),
- SIGNATURE_EXCEPTION("KER-PUT-010", "Failed to generate digital signature"),
- DOCUMENT_EXCEPTION("KER-PUT-011", "Failed to get document"),
- BIOMETRIC_EXCEPTION("KER-PUT-012", "Unable to get biometric"),
- OS_ADAPTER_EXCEPTION("KER-PUT-013", "No Object store adapter found."),
- PACKET_KEEPER_GET_ERROR("KER-PUT-014", "Packet keeper exception occured."),
- PACKET_KEEPER_PUT_ERROR("KER-PUT-015", "Packet keeper exception occured."),
- PACKET_KEEPER_GETMETA_ERROR("KER-PUT-016", "Packet keeper exception occured."),
- PACKET_KEEPER_INTEGRITY_ERROR("KER-PUT-017", "Packet keeper exception occured."),
- CRYPTO_EXCEPTION("KER-PUT-018", "No available crypto service exception."),
- INTEGRITY_FAILURE("KER-PUT-019", "Packet Integrity check failed."),
- PACKET_VALIDATION_FAILED("KER-PUT-020", "Packet Validation exception occured."),
- TAGGING_FAILED("KER-PUT-021", "Failed to add tags."),
- TAG_ALREADY_EXIST("KER-PUT-022", "Tag Already Exist."),
- GET_TAG_EXCEPTION("KER-PUT-023","Failed to get tags"),
- TAG_NOT_FOUND("KER-PUT-024", "Requested tag not present"),
- SOURCE_NOT_PRESENT("KER-PUT-025", "Source not present in request."),
- DELETE_TAGGING_FAILED("KER-PUT-026", "Failed to delete tags.");
-
-
-
-
- private final String errorCode;
- private final String errorMessage;
-
- private PacketUtilityErrorCodes(final String errorCode, final String errorMessage) {
- this.errorCode = errorCode;
- this.errorMessage = errorMessage;
- }
-
- public String getErrorCode() {
- return errorCode;
- }
-
- public String getErrorMessage() {
- return errorMessage;
- }
-}
+package io.mosip.commons.packet.constants;
+
+public enum PacketUtilityErrorCodes {
+
+ UNKNOWN_RESOURCE_EXCEPTION("KER-PUT-001",
+ "Unknown resource provided"),
+ FILE_NOT_FOUND_IN_DESTINATION("KER-PUT-002", "Unable to Find File in Destination Folder"),
+ PACKET_DECRYPTION_FAILURE_EXCEPTION("KER-PUT-003", "Packet decryption failed"),
+ API_NOT_ACCESSIBLE_EXCEPTION("KER-PUT-005", "API not accessible"),
+ SYS_IO_EXCEPTION("KER-PUT-004", "Unable to Find File in Destination Folder"),
+ GET_ALL_IDENTITY_EXCEPTION("KER-PUT-005", "Unable to fetch identity json from all sub packets"),
+ NO_AVAILABLE_PROVIDER("KER-PUT-006", "No available provider for given source and process"),
+ BIOMETRIC_FIELDNAME_NOT_FOUND("KER-PUT-007", "Biometric fieldname is not present inside packet"),
+ GET_ALL_METAINFO_EXCEPTION("KER-PUT-008", "Unable to fetch meta information from all sub packets"),
+ ZIP_PARSING_EXCEPTION("KER-PUT-009", "Unable to parse the zip"),
+ SIGNATURE_EXCEPTION("KER-PUT-010", "Failed to generate digital signature"),
+ DOCUMENT_EXCEPTION("KER-PUT-011", "Failed to get document"),
+ BIOMETRIC_EXCEPTION("KER-PUT-012", "Unable to get biometric"),
+ OS_ADAPTER_EXCEPTION("KER-PUT-013", "No Object store adapter found."),
+ PACKET_KEEPER_GET_ERROR("KER-PUT-014", "Packet keeper exception occured."),
+ PACKET_KEEPER_PUT_ERROR("KER-PUT-015", "Packet keeper exception occured."),
+ PACKET_KEEPER_GETMETA_ERROR("KER-PUT-016", "Packet keeper exception occured."),
+ PACKET_KEEPER_INTEGRITY_ERROR("KER-PUT-017", "Packet keeper exception occured."),
+ CRYPTO_EXCEPTION("KER-PUT-018", "No available crypto service exception."),
+ INTEGRITY_FAILURE("KER-PUT-019", "Packet Integrity check failed."),
+ PACKET_VALIDATION_FAILED("KER-PUT-020", "Packet Validation exception occured."),
+ TAGGING_FAILED("KER-PUT-021", "Failed to add tags."),
+ TAG_ALREADY_EXIST("KER-PUT-022", "Tag Already Exist."),
+ GET_TAG_EXCEPTION("KER-PUT-023","Failed to get tags"),
+ TAG_NOT_FOUND("KER-PUT-024", "Requested tag not present"),
+ SOURCE_NOT_PRESENT("KER-PUT-025", "Invalid source or process."),
+ DELETE_TAGGING_FAILED("KER-PUT-026", "Failed to delete tags."),
+ OBJECT_DOESNOT_EXISTS("KER-PUT-027", "Object doesnot exists."),;
+
+
+
+
+ private final String errorCode;
+ private final String errorMessage;
+
+ private PacketUtilityErrorCodes(final String errorCode, final String errorMessage) {
+ this.errorCode = errorCode;
+ this.errorMessage = errorMessage;
+ }
+
+ public String getErrorCode() {
+ return errorCode;
+ }
+
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+}
diff --git a/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/exception/ObjectDoesnotExistsException.java b/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/exception/ObjectDoesnotExistsException.java
new file mode 100644
index 0000000000..bb207eeb39
--- /dev/null
+++ b/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/exception/ObjectDoesnotExistsException.java
@@ -0,0 +1,26 @@
+package io.mosip.commons.packet.exception;
+
+import io.mosip.commons.packet.constants.PacketUtilityErrorCodes;
+import io.mosip.kernel.core.exception.BaseUncheckedException;
+
+public class ObjectDoesnotExistsException extends BaseUncheckedException {
+
+ public ObjectDoesnotExistsException() {
+ super(PacketUtilityErrorCodes.OBJECT_DOESNOT_EXISTS.getErrorCode(),
+ PacketUtilityErrorCodes.OBJECT_DOESNOT_EXISTS.getErrorMessage());
+ }
+
+ public ObjectDoesnotExistsException(String message) {
+ super(PacketUtilityErrorCodes.OBJECT_DOESNOT_EXISTS.getErrorCode(),
+ message);
+ }
+
+ public ObjectDoesnotExistsException(Throwable e) {
+ super(PacketUtilityErrorCodes.OBJECT_DOESNOT_EXISTS.getErrorCode(),
+ PacketUtilityErrorCodes.OBJECT_DOESNOT_EXISTS.getErrorMessage(), e);
+ }
+
+ public ObjectDoesnotExistsException(String errorMessage, Throwable t) {
+ super(PacketUtilityErrorCodes.OBJECT_DOESNOT_EXISTS.getErrorCode(), errorMessage, t);
+ }
+}
diff --git a/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/impl/OfflinePacketCryptoServiceImpl.java b/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/impl/OfflinePacketCryptoServiceImpl.java
index 8ec3fdcd05..73e7a4b843 100644
--- a/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/impl/OfflinePacketCryptoServiceImpl.java
+++ b/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/impl/OfflinePacketCryptoServiceImpl.java
@@ -60,29 +60,28 @@ public class OfflinePacketCryptoServiceImpl implements IPacketCryptoService {
@Override
public byte[] sign(byte[] packet) {
TpmSignRequestDto signRequest = new TpmSignRequestDto();
- signRequest.setData(CryptoUtil.encodeBase64(packet));
- return CryptoUtil.decodeBase64(getTpmCryptoService().csSign(signRequest).getData());
+ signRequest.setData(CryptoUtil.encodeToURLSafeBase64(packet));
+ return CryptoUtil.decodeURLSafeBase64(getTpmCryptoService().csSign(signRequest).getData());
}
@Override
public byte[] encrypt(String refId, byte[] packet) {
- String packetString = CryptoUtil.encodeBase64String(packet);
+ String packetString = CryptoUtil.encodeToURLSafeBase64(packet);
CryptomanagerRequestDto cryptomanagerRequestDto = new CryptomanagerRequestDto();
cryptomanagerRequestDto.setApplicationId(APPLICATION_ID);
cryptomanagerRequestDto.setData(packetString);
cryptomanagerRequestDto.setReferenceId(refId);
- cryptomanagerRequestDto.setPrependThumbprint(isPrependThumbprintEnabled);
SecureRandom sRandom = new SecureRandom();
byte[] nonce = new byte[CryptomanagerConstant.GCM_NONCE_LENGTH];
byte[] aad = new byte[CryptomanagerConstant.GCM_AAD_LENGTH];
sRandom.nextBytes(nonce);
sRandom.nextBytes(aad);
- cryptomanagerRequestDto.setAad(CryptoUtil.encodeBase64String(aad));
- cryptomanagerRequestDto.setSalt(CryptoUtil.encodeBase64String(nonce));
+ cryptomanagerRequestDto.setAad(CryptoUtil.encodeToURLSafeBase64(aad));
+ cryptomanagerRequestDto.setSalt(CryptoUtil.encodeToURLSafeBase64(nonce));
cryptomanagerRequestDto.setTimeStamp(DateUtils.getUTCCurrentDateTime());
- byte[] encryptedData = CryptoUtil.decodeBase64(getCryptomanagerService().encrypt(cryptomanagerRequestDto).getData());
+ byte[] encryptedData = CryptoUtil.decodeURLSafeBase64(getCryptomanagerService().encrypt(cryptomanagerRequestDto).getData());
return EncryptionUtil.mergeEncryptedData(encryptedData, nonce, aad);
}
@@ -97,20 +96,19 @@ public byte[] decrypt(String refId, byte[] packet) {
CryptomanagerRequestDto cryptomanagerRequestDto = new CryptomanagerRequestDto();
cryptomanagerRequestDto.setApplicationId(APPLICATION_ID);
cryptomanagerRequestDto.setReferenceId(refId);
- cryptomanagerRequestDto.setAad(CryptoUtil.encodeBase64String(aad));
- cryptomanagerRequestDto.setSalt(CryptoUtil.encodeBase64String(nonce));
- cryptomanagerRequestDto.setData(CryptoUtil.encodeBase64String(encryptedData));
- cryptomanagerRequestDto.setPrependThumbprint(isPrependThumbprintEnabled);
+ cryptomanagerRequestDto.setAad(CryptoUtil.encodeToURLSafeBase64(aad));
+ cryptomanagerRequestDto.setSalt(CryptoUtil.encodeToURLSafeBase64(nonce));
+ cryptomanagerRequestDto.setData(CryptoUtil.encodeToURLSafeBase64(encryptedData));
cryptomanagerRequestDto.setTimeStamp(DateUtils.getUTCCurrentDateTime());
- return CryptoUtil.decodeBase64(getCryptomanagerService().decrypt(cryptomanagerRequestDto).getData());
+ return CryptoUtil.decodeURLSafeBase64(getCryptomanagerService().decrypt(cryptomanagerRequestDto).getData());
}
@Override
public boolean verify(String machineId, byte[] packet, byte[] signature) {
TpmSignVerifyRequestDto tpmSignVerifyRequestDto = new TpmSignVerifyRequestDto();
- tpmSignVerifyRequestDto.setData(CryptoUtil.encodeBase64(packet));
- tpmSignVerifyRequestDto.setSignature(CryptoUtil.encodeBase64(signature));
+ tpmSignVerifyRequestDto.setData(CryptoUtil.encodeToURLSafeBase64(packet));
+ tpmSignVerifyRequestDto.setSignature(CryptoUtil.encodeToURLSafeBase64(signature));
//TODO - get public key based on machine Id
//tpmSignVerifyRequestDto.setPublicKey(<>);
TpmSignVerifyResponseDto tpmSignVerifyResponseDto = getTpmCryptoService().csVerify(tpmSignVerifyRequestDto);
diff --git a/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/impl/OnlinePacketCryptoServiceImpl.java b/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/impl/OnlinePacketCryptoServiceImpl.java
index 27c34dcf14..3e2556eb33 100644
--- a/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/impl/OnlinePacketCryptoServiceImpl.java
+++ b/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/impl/OnlinePacketCryptoServiceImpl.java
@@ -65,7 +65,6 @@ public class OnlinePacketCryptoServiceImpl implements IPacketCryptoService {
private boolean isPrependThumbprintEnabled;
@Autowired
- @Qualifier("restTemplate")
private RestTemplate restTemplate;
@Autowired
@@ -88,7 +87,7 @@ public byte[] sign(byte[] packet) {
try {
TpmSignRequestDto dto = new TpmSignRequestDto();
- dto.setData(CryptoUtil.encodeBase64(packet));
+ dto.setData(CryptoUtil.encodeToURLSafeBase64(packet));
RequestWrapper request = new RequestWrapper<>();
request.setRequest(dto);
request.setMetadata(null);
@@ -101,7 +100,7 @@ public byte[] sign(byte[] packet) {
String.class);
LinkedHashMap responseMap = (LinkedHashMap) mapper.readValue(response.getBody(), LinkedHashMap.class).get("response");
if (responseMap != null && responseMap.size() > 0)
- return CryptoUtil.decodeBase64((String) responseMap.get("data"));
+ return CryptoUtil.decodeURLSafeBase64((String) responseMap.get("data"));
else
throw new SignatureException();
} catch (IOException e) {
@@ -116,7 +115,7 @@ public byte[] encrypt(String refId, byte[] packet) {
byte[] encryptedPacket = null;
try {
- String packetString = CryptoUtil.encodeBase64String(packet);
+ String packetString = CryptoUtil.encodeToURLSafeBase64(packet);
CryptomanagerRequestDto cryptomanagerRequestDto = new CryptomanagerRequestDto();
RequestWrapper request = new RequestWrapper<>();
cryptomanagerRequestDto.setApplicationId(APPLICATION_ID);
@@ -129,8 +128,8 @@ public byte[] encrypt(String refId, byte[] packet) {
byte[] aad = new byte[CryptomanagerConstant.GCM_AAD_LENGTH];
sRandom.nextBytes(nonce);
sRandom.nextBytes(aad);
- cryptomanagerRequestDto.setAad(CryptoUtil.encodeBase64String(aad));
- cryptomanagerRequestDto.setSalt(CryptoUtil.encodeBase64String(nonce));
+ cryptomanagerRequestDto.setAad(CryptoUtil.encodeToURLSafeBase64(aad));
+ cryptomanagerRequestDto.setSalt(CryptoUtil.encodeToURLSafeBase64(nonce));
cryptomanagerRequestDto.setTimeStamp(DateUtils.getUTCCurrentDateTime());
request.setId(DECRYPT_SERVICE_ID);
@@ -154,7 +153,7 @@ public byte[] encrypt(String refId, byte[] packet) {
"Packet encryption failure message : " + error.getMessage());
throw new PacketDecryptionFailureException(error.getMessage());
}
- byte[] encryptedData = CryptoUtil.decodeBase64(responseObject.getResponse().getData());
+ byte[] encryptedData = CryptoUtil.decodeURLSafeBase64(responseObject.getResponse().getData());
encryptedPacket = EncryptionUtil.mergeEncryptedData(encryptedData, nonce, aad);
LOGGER.info(PacketManagerLogger.SESSIONID, PacketManagerLogger.REFERENCEID, refId,
"Successfully encrypted Packet");
@@ -197,9 +196,9 @@ public byte[] decrypt(String refId, byte[] packet) {
CryptomanagerConstant.GCM_NONCE_LENGTH + CryptomanagerConstant.GCM_AAD_LENGTH);
byte[] encryptedData = Arrays.copyOfRange(packet, CryptomanagerConstant.GCM_NONCE_LENGTH + CryptomanagerConstant.GCM_AAD_LENGTH,
packet.length);
- cryptomanagerRequestDto.setAad(CryptoUtil.encodeBase64String(aad));
- cryptomanagerRequestDto.setSalt(CryptoUtil.encodeBase64String(nonce));
- cryptomanagerRequestDto.setData(CryptoUtil.encodeBase64String(encryptedData));
+ cryptomanagerRequestDto.setAad(CryptoUtil.encodeToURLSafeBase64(aad));
+ cryptomanagerRequestDto.setSalt(CryptoUtil.encodeToURLSafeBase64(nonce));
+ cryptomanagerRequestDto.setData(CryptoUtil.encodeToURLSafeBase64(encryptedData));
cryptomanagerRequestDto.setPrependThumbprint(isPrependThumbprintEnabled);
cryptomanagerRequestDto.setTimeStamp(DateUtils.getUTCCurrentDateTime());
@@ -226,7 +225,7 @@ public byte[] decrypt(String refId, byte[] packet) {
"Error message : " + error.getMessage());
throw new PacketDecryptionFailureException(error.getMessage());
}
- decryptedPacket = CryptoUtil.decodeBase64(responseObject.getResponse().getData());
+ decryptedPacket = CryptoUtil.decodeURLSafeBase64(responseObject.getResponse().getData());
LOGGER.info(PacketManagerLogger.SESSIONID, PacketManagerLogger.REFERENCEID, refId,
"Successfully decrypted Packet");
} catch (IOException e) {
@@ -257,11 +256,10 @@ public byte[] decrypt(String refId, byte[] packet) {
@Override
public boolean verify(String refId, byte[] packet, byte[] signature) {
try {
- String machineId = refId.split("_")[1];
- String publicKey=getPublicKey(machineId);
+ String publicKey=getPublicKey(refId);
TpmSignVerifyRequestDto dto = new TpmSignVerifyRequestDto();
- dto.setData(CryptoUtil.encodeBase64(packet));
- dto.setSignature(CryptoUtil.encodeBase64(signature));
+ dto.setData(CryptoUtil.encodeToURLSafeBase64(packet));
+ dto.setSignature(CryptoUtil.encodeToURLSafeBase64(signature));
dto.setPublicKey(publicKey);
RequestWrapper request = new RequestWrapper<>();
request.setRequest(dto);
@@ -274,11 +272,15 @@ public boolean verify(String refId, byte[] packet, byte[] signature) {
ResponseEntity response = restTemplate.exchange(keymanagerCsverifysignUrl, HttpMethod.POST, httpEntity,
String.class);
LinkedHashMap responseMap = (LinkedHashMap) mapper.readValue(response.getBody(), LinkedHashMap.class).get("response");//.get("signature");
- if (responseMap != null && responseMap.size() > 0)
- return responseMap.get("verified") != null && responseMap.get("verified").toString().equalsIgnoreCase("true");
- else {
- LOGGER.error(PacketManagerLogger.SESSIONID, "SIGNATURE", new String(signature),
- "Failed to verify signature");
+ if (responseMap != null && responseMap.size() > 0) {
+ boolean result = responseMap.get("verified") != null && responseMap.get("verified").toString().equalsIgnoreCase("true");
+ if (!result)
+ LOGGER.error(PacketManagerLogger.SESSIONID, PacketManagerLogger.REFERENCEID, refId,
+ "Signature verification Failed.");
+ return result;
+ } else {
+ LOGGER.error(PacketManagerLogger.SESSIONID, PacketManagerLogger.REFERENCEID, refId,
+ "Failed to verify signature. Received error response from keymanager verify API.");
throw new SignatureException();
}
} catch (IOException e) {
@@ -292,15 +294,16 @@ public boolean verify(String refId, byte[] packet, byte[] signature) {
}
}
- private String getPublicKey(String machineId) throws IOException {
+ private String getPublicKey(String refId) throws IOException {
+ String machineId = refId.split("_")[1];
ResponseEntity response = restTemplate.exchange(syncdataGetTpmKeyUrl+machineId, HttpMethod.GET, null,
String.class);
LinkedHashMap responseMap = (LinkedHashMap) mapper.readValue(response.getBody(), LinkedHashMap.class).get("response");//.get("signature");
if (responseMap != null && responseMap.size() > 0)
- return (String) responseMap.get("signingPublicKey") ;
+ return (String) responseMap.get("signingPublicKey");
else {
- LOGGER.error(PacketManagerLogger.SESSIONID, "PUBLIC_KEY", machineId,
- "Failed to get public key");
+ LOGGER.error(PacketManagerLogger.SESSIONID, PacketManagerLogger.REFERENCEID, refId,
+ "Failed to get public key. Error Response : " + response.getBody());
throw new SignatureException();
}
}
diff --git a/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/impl/PacketReaderImpl.java b/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/impl/PacketReaderImpl.java
index 1d3608ce95..b259ef9653 100644
--- a/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/impl/PacketReaderImpl.java
+++ b/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/impl/PacketReaderImpl.java
@@ -5,6 +5,7 @@
import static io.mosip.commons.packet.constants.PacketManagerConstants.IDENTITY;
import static io.mosip.commons.packet.constants.PacketManagerConstants.LABEL;
import static io.mosip.commons.packet.constants.PacketManagerConstants.META_INFO_OPERATIONS_DATA;
+import static io.mosip.commons.packet.constants.PacketManagerConstants.REFNUMBER;
import static io.mosip.commons.packet.constants.PacketManagerConstants.TYPE;
import static io.mosip.commons.packet.constants.PacketManagerConstants.VALUE;
@@ -18,6 +19,7 @@
import java.util.List;
import java.util.Map;
+import io.mosip.commons.packet.facade.PacketReader;
import io.mosip.kernel.biometrics.constant.BiometricType;
import io.mosip.kernel.core.util.JsonUtils;
import org.apache.commons.collections4.CollectionUtils;
@@ -74,6 +76,9 @@ public class PacketReaderImpl implements IPacketReader {
@Value("${mosip.commons.packetnames}")
private String packetNames;
+ @Autowired
+ private PacketReader packetReader;
+
@Autowired
private PacketKeeper packetKeeper;
@@ -100,13 +105,13 @@ public class PacketReaderImpl implements IPacketReader {
public boolean validatePacket(String id, String source, String process) {
try {
return packetValidator.validate(id, source, process);
- } catch (BaseCheckedException | IOException | NoSuchAlgorithmException e) {
+ } catch (Exception e) {
LOGGER.error(PacketManagerLogger.SESSIONID, PacketManagerLogger.REGISTRATIONID, id,
"Packet Validation exception : " + ExceptionUtils.getStackTrace(e));
if (e instanceof BaseCheckedException)
throw new PacketValidationFailureException(((BaseCheckedException) e).getMessage(), e);
else
- throw new PacketValidationFailureException(((IOException) e).getMessage(), e);
+ throw new PacketValidationFailureException((e).getMessage(), e);
}
}
@@ -158,10 +163,10 @@ else if (value != null && (value instanceof String))
ExceptionUtils.getStackTrace(e));
if (e instanceof BaseCheckedException) {
BaseCheckedException ex = (BaseCheckedException) e;
- throw new GetAllIdentityException(ex.getErrorCode(), ex.getMessage());
+ throw new GetAllIdentityException(ex.getErrorCode(), ex.getErrorText());
} else if (e instanceof BaseUncheckedException) {
BaseUncheckedException ex = (BaseUncheckedException) e;
- throw new GetAllIdentityException(ex.getErrorCode(), ex.getMessage());
+ throw new GetAllIdentityException(ex.getErrorCode(), ex.getErrorText());
}
throw new GetAllIdentityException(e.getMessage());
}
@@ -197,12 +202,10 @@ public Map getFields(String id, List fields, String sour
public Document getDocument(String id, String documentName, String source, String process) {
LOGGER.info(PacketManagerLogger.SESSIONID, PacketManagerLogger.REGISTRATIONID, id,
"getDocument :: for - " + documentName);
- Map idobjectMap = getAll(id, source, process);
- Double schemaVersion = idobjectMap.get(PacketManagerConstants.IDSCHEMA_VERSION) != null
- ? Double.valueOf(idobjectMap.get(PacketManagerConstants.IDSCHEMA_VERSION).toString())
- : null;
- String documentString = (String) idobjectMap.get(documentName);
try {
+ String schemaVersionString = packetReader.getField(id, idSchemaUtils.getIdschemaVersionFromMappingJson(), source, process, false);
+ Double schemaVersion = schemaVersionString != null ? Double.valueOf(schemaVersionString) : null;
+ String documentString = packetReader.getField(id, documentName, source, process, false);
if (documentString != null && schemaVersion != null) {
JSONObject documentMap = new JSONObject(documentString);
String packetName = idSchemaUtils.getSource(documentName, schemaVersion);
@@ -213,13 +216,13 @@ public Document getDocument(String id, String documentName, String source, Strin
Document document = new Document();
document.setDocument(IOUtils.toByteArray(documentStream));
document.setValue(value);
- document.setType(documentMap.get(TYPE) != null ? documentMap.get(TYPE).toString() : null);
- document.setFormat(documentMap.get(FORMAT) != null ? documentMap.get(FORMAT).toString() : null);
+ document.setType(documentMap.has(TYPE) ? documentMap.get(TYPE).toString() : null);
+ document.setFormat(documentMap.has(FORMAT) ? documentMap.get(FORMAT).toString() : null);
+ document.setRefNumber(documentMap.has(REFNUMBER) ? documentMap.get(REFNUMBER).toString() : null);
return document;
}
}
- } catch (IOException | ApiNotAccessibleException | PacketDecryptionFailureException | JSONException
- | PacketKeeperException e) {
+ } catch (Exception e) {
LOGGER.error(PacketManagerLogger.SESSIONID, PacketManagerLogger.REGISTRATIONID, id,
ExceptionUtils.getStackTrace(e));
throw new GetDocumentException(e.getMessage());
@@ -236,8 +239,7 @@ public BiometricRecord getBiometric(String id, String biometricFieldName, List idobjectMap = getAll(id, source, process);
- String bioString = (String) idobjectMap.get(biometricFieldName);
+ String bioString = packetReader.getField(id, biometricFieldName, source, process, false);//(String) idobjectMap.get(biometricFieldName);
JSONObject biometricMap = null;
if (bioString != null)
biometricMap = new JSONObject(bioString);
@@ -258,9 +260,9 @@ public BiometricRecord getBiometric(String id, String biometricFieldName, List metaMap = PacketManagerHelper.getMetaMap(packetInfo);
metaMap = getAdapter().addObjectMetaData(PACKET_MANAGER_ACCOUNT,
packet.getPacketInfo().getId(), packet.getPacketInfo().getSource(), packet.getPacketInfo().getProcess(), packet.getPacketInfo().getPacketName(), metaMap);
diff --git a/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/util/IdSchemaUtils.java b/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/util/IdSchemaUtils.java
index 181fea0f74..7f883ccc84 100644
--- a/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/util/IdSchemaUtils.java
+++ b/commons-packet/commons-packet-manager/src/main/java/io/mosip/commons/packet/util/IdSchemaUtils.java
@@ -10,10 +10,15 @@
import static io.mosip.commons.packet.constants.PacketManagerConstants.SCHEMA_JSON;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.ArrayUtils;
+import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
@@ -37,7 +42,34 @@
@Component
public class IdSchemaUtils {
+ private org.json.simple.JSONObject mappingJsonObject = null;
+ private static Map categorySubpacketMapping = new HashMap<>();
private Map idschema = null;
+ public static final String RESPONSE = "response";
+ public static final String PROPERTIES = "properties";
+ public static final String IDENTITY = "identity";
+ public static final String SCHEMA_CATEGORY = "fieldCategory";
+ public static final String SCHEMA_ID = "id";
+ public static final String SCHEMA_TYPE = "type";
+ public static final String SCHEMA_REF = "$ref";
+ public static final String IDSCHEMA_URL = "IDSCHEMA";
+ public static final String SCHEMA_JSON = "schemaJson";
+ public static final String SCHEMA_VERSION_QUERY_PARAM = "schemaVersion";
+ public static final String SCHEMA_REF_DEFINITIONS_PREFIX = "#/definitions/";
+
+ static {
+ categorySubpacketMapping.put("pvt", "id");
+ categorySubpacketMapping.put("kyc", "id");
+ categorySubpacketMapping.put("none", "id,evidence,optional");
+ categorySubpacketMapping.put("evidence", "evidence");
+ categorySubpacketMapping.put("optional", "optional");
+ }
+
+ @Value("${config.server.file.storage.uri}")
+ private String configServerUrl;
+
+ @Value("${registration.processor.identityjson}")
+ private String mappingjsonFileName;
@Value("${packet.default.source:REGISTRATION_CLIENT}")
private String defaultSource;
@@ -47,9 +79,11 @@ public class IdSchemaUtils {
@Value("${IDSCHEMAURL:null}")
private String idschemaUrl;
+
+ @Autowired
+ private ObjectMapper objMapper;
@Autowired
- @Qualifier("restTemplate")
private RestTemplate restTemplate;
@@ -158,4 +192,83 @@ private JSONObject getJSONObjFromStr(String jsonString, String id) {
return null;
}
}
+
+ public List getDefaultFields(Double schemaVersion) throws JSONException, IOException {
+ List fieldList = new ArrayList<>();
+ List