Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Taken latest changes from 1.2.0-rc2 #21

Merged
merged 15 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions .github/workflows/push_trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 {} +

Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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 "<settings> <servers> <server> <id>ossrh</id> <username>${{secrets.ossrh_user}}</username> <password>${{secrets.ossrh_secret}}</password> </server> </servers> <profiles> <profile> <id>ossrh</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <gpg.executable>gpg2</gpg.executable> <gpg.passphrase>${{secrets.gpg_secret}}</gpg.passphrase> </properties> </profile> <profile> <id>allow-snapshots</id> <activation><activeByDefault>true</activeByDefault></activation> <repositories> <repository> <id>snapshots-repo</id> <url>https://oss.sonatype.org/content/repositories/snapshots</url> <releases><enabled>false</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> <repository> <id>releases-repo</id> <url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>false</enabled></snapshots> </repository> </repositories> </profile> <profile> <id>sonar</id> <properties> <sonar.sources>.</sonar.sources> <sonar.host.url>https://sonarcloud.io</sonar.host.url> </properties> <activation> <activeByDefault>false</activeByDefault> </activation> </profile> </profiles> </settings>" > $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 }}
Expand Down
5 changes: 5 additions & 0 deletions commons-packet/commons-packet-manager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.4</version>
</dependency>
</dependencies>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class AuditLogEntry {

@Autowired
@Lazy
@Qualifier("restTemplate")
private RestTemplate restTemplate;

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
Expand Down
Loading