Skip to content

Commit

Permalink
Merge pull request #1107 from nandhu-kumar/develop
Browse files Browse the repository at this point in the history
Update release 1.2.0.1 with develop branch
  • Loading branch information
lsivanand authored Oct 9, 2023
2 parents a2d3a03 + 2fd7da9 commit 8d6cbad
Show file tree
Hide file tree
Showing 1,330 changed files with 22,922 additions and 15,853 deletions.
127 changes: 64 additions & 63 deletions .github/workflows/push_trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,76 +9,77 @@ on:
- develop
- MOSIP-*
- "0.9"
- 115_compatible_Test

jobs:
build-authentication-demo-service:
runs-on: ubuntu-latest
env:
NAMESPACE: ${{ secrets.dev_namespace_docker_hub }}
SERVICE_NAME: authentication-demo-service
SERVICE_LOCATION: authentication-demo-service
# build-authentication-demo-service:
# runs-on: ubuntu-latest
# env:
# NAMESPACE: ${{ secrets.dev_namespace_docker_hub }}
# SERVICE_NAME: authentication-demo-service
# SERVICE_LOCATION: authentication-demo-service

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
ref: ${{ github.ref }}
java-version: 11
server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
# steps:
# - uses: actions/checkout@v2
# - name: Set up JDK 11
# uses: actions/setup-java@v1
# with:
# ref: ${{ github.ref }}
# java-version: 11
# server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml
# settings-path: ${{ github.workspace }} # location for the settings.xml file

- name: Setup branch and env
run: |
# Strip git ref prefix from version
echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV
echo "GPG_TTY=$(tty)" >> $GITHUB_ENV
- uses: actions/cache@v1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-${{ env.BRANCH_NAME }}
- 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: Setup branch and env
# run: |
# # Strip git ref prefix from version
# echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV
# echo "GPG_TTY=$(tty)" >> $GITHUB_ENV
# - uses: actions/cache@v1
# with:
# path: ~/.m2/repository
# key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
# restore-keys: |
# ${{ runner.os }}-maven-${{ env.BRANCH_NAME }}
# - 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 ${{ env.SERVICE_LOCATION}}
mvn clean package -s $GITHUB_WORKSPACE/settings.xml
- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
# - name: Build with Maven
# run: |
# cd ${{ env.SERVICE_LOCATION}}
# mvn clean package -s $GITHUB_WORKSPACE/settings.xml
# - name: Get current date
# id: date
# run: echo "::set-output name=date::$(date +'%Y-%m-%d')"

- name: Build image
run: |
cd "./${{env.SERVICE_LOCATION}}"
docker build . --build-arg SOURCE=mosip --build-arg COMMIT_HASH=$(git rev-parse HEAD) --build-arg COMMIT_ID=$(git rev-parse --short HEAD) --build-arg BUILD_TIME=${{steps.date.outputs.date}} --file Dockerfile --tag ${{ env.SERVICE_NAME }}
- name: Log into registry
run: echo "${{ secrets.release_docker_hub }}" | docker login -u ${{ secrets.actor_docker_hub }} --password-stdin
# - name: Build image
# run: |
# cd "./${{env.SERVICE_LOCATION}}"
# docker build . --build-arg SOURCE=mosip --build-arg COMMIT_HASH=$(git rev-parse HEAD) --build-arg COMMIT_ID=$(git rev-parse --short HEAD) --build-arg BUILD_TIME=${{steps.date.outputs.date}} --file Dockerfile --tag ${{ env.SERVICE_NAME }}
# - name: Log into registry
# run: echo "${{ secrets.release_docker_hub }}" | docker login -u ${{ secrets.actor_docker_hub }} --password-stdin

- name: Push image
run: |
IMAGE_ID=$NAMESPACE/$SERVICE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
echo "push version ${{steps.getPomVersion.outputs.info}}"
if [[ $BRANCH_NAME == master ]]; then
VERSION=latest
else
VERSION=$BRANCH_NAME
fi
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $SERVICE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
- uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,message,commit,workflow,job # selectable (default: repo,message)
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_DEVOPS_WEBHOOK }} # required
if: failure() # Pick up events even if the job fails or is canceled.
# - name: Push image
# run: |
# IMAGE_ID=$NAMESPACE/$SERVICE_NAME
# # Change all uppercase to lowercase
# IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# echo "push version ${{steps.getPomVersion.outputs.info}}"
# if [[ $BRANCH_NAME == master ]]; then
# VERSION=latest
# else
# VERSION=$BRANCH_NAME
# fi
# echo IMAGE_ID=$IMAGE_ID
# echo VERSION=$VERSION
# docker tag $SERVICE_NAME $IMAGE_ID:$VERSION
# docker push $IMAGE_ID:$VERSION
# - uses: 8398a7/action-slack@v3
# with:
# status: ${{ job.status }}
# fields: repo,message,commit,workflow,job # selectable (default: repo,message)
# env:
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_DEVOPS_WEBHOOK }} # required
# if: failure() # Pick up events even if the job fails or is canceled.

build-automationtests:
runs-on: ubuntu-latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import javax.crypto.NoSuchPaddingException;
import javax.xml.bind.DatatypeConverter;

import io.mosip.testrig.authentication.demo.service.dto.*;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.IOUtils;
import org.bouncycastle.operator.OperatorCreationException;
Expand All @@ -62,12 +63,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
Expand All @@ -90,9 +86,6 @@
import io.mosip.kernel.core.util.DateUtils;
import io.mosip.kernel.core.util.HMACUtils2;
import io.mosip.testrig.authentication.demo.service.controller.Encrypt.SplittedEncryptedData;
import io.mosip.testrig.authentication.demo.service.dto.CertificateChainResponseDto;
import io.mosip.testrig.authentication.demo.service.dto.EncryptionRequestDto;
import io.mosip.testrig.authentication.demo.service.dto.EncryptionResponseDto;
import io.mosip.testrig.authentication.demo.service.helper.CertificateTypes;
import io.mosip.testrig.authentication.demo.service.helper.KeyMgrUtil;
import io.mosip.testrig.authentication.demo.service.helper.PartnerTypes;
Expand Down Expand Up @@ -177,6 +170,8 @@ public class AuthRequestController {

private static final String IDA_KYC_EXCHANGE_REQUEST_TEMPLATE = "ida.kycExchangeRequest.template";

private static final String IDA_VCI_EXCHANGE_REQUEST_TEMPLATE = "ida.vciExchangeRequest.template";

private static final String ID = "id";

private static final String CLASSPATH = "classpath";
Expand Down Expand Up @@ -574,6 +569,68 @@ public ResponseEntity<String> createKycExchangeRequest(@RequestParam(name = ID,
String.format(IdAuthenticationErrorConstants.MISSING_INPUT_PARAMETER.getErrorMessage(), IDENTITY));
}
}

@PostMapping(path = "/create-vci-exchange-request", consumes = MediaType.APPLICATION_JSON_VALUE, produces = {
MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<String> createVciExchangeRequest(@RequestParam(name = ID, required = true) @Nullable String id,
@RequestParam(name = ID_TYPE, required = false) @Nullable String idType,
@RequestParam(name = "Authtype", required = false) @Nullable String reqAuth,
@RequestParam(name = TRANSACTION_ID, required = false) @Nullable String transactionId,
@RequestParam(name = "requestTime", required = false) @Nullable String requestTime,
@RequestParam(name = "vcFormat", required = false) @Nullable String vcFormat,
@RequestParam(name = "credSubjectId", required = false)@Nullable String credSubjectId,
@RequestParam(name = "vcAuthToken", required = false)@Nullable String vcAuthToken,
@RequestParam(name = "keyFileNameByPartnerName", required = false)boolean keyFileNameByPartnerName,
@RequestParam(name = "partnerName", required = false)@Nullable String partnerName,
@RequestBody Map<String, Object> request,
@RequestParam(name = "certsDir", required = false) String certsDir,
@RequestParam(name = "moduleName", required = false) String moduleName) throws Exception {
String authRequestTemplate = environment.getProperty(IDA_VCI_EXCHANGE_REQUEST_TEMPLATE);
Map<String, Object> reqValues = new HashMap<>();

if (requestTime == null) {
requestTime = DateUtils.getUTCCurrentDateTimeString(environment.getProperty("datetime.pattern"));
}

reqValues.put(ID, id);
reqValues.put("individualIdType", idType == null || idType.trim().length() == 0 ? IdType.UIN.toString() : idType);
reqValues.put(AUTH_TYPE, reqAuth);
reqValues.put(TIMESTAMP, requestTime);
reqValues.put(TXN, transactionId == null ? "1234567890" : transactionId);
reqValues.put(VER, environment.getProperty(IDA_API_VERSION));
reqValues.put("vcFormat", vcFormat);
reqValues.put("credSubjectId", credSubjectId);
reqValues.put("vcAuthToken", vcAuthToken);

StringWriter writer = new StringWriter();
InputStream templateValue;
if (request != null && request.size() > 0) {
templateValue = templateManager
.merge(new ByteArrayInputStream(authRequestTemplate.getBytes(StandardCharsets.UTF_8)), reqValues);

if (templateValue != null) {
IOUtils.copy(templateValue, writer, StandardCharsets.UTF_8);
String res = writer.toString();
ObjectNode response = mapper.readValue(res.getBytes(), ObjectNode.class);

HttpHeaders httpHeaders = new HttpHeaders();
String responseStr = response.toString();

String rpSignature = signRequest(PartnerTypes.MISP, partnerName, keyFileNameByPartnerName, responseStr, certsDir, moduleName);
httpHeaders.add("signature", rpSignature);
return new ResponseEntity<>(responseStr, httpHeaders, HttpStatus.OK);
} else {
throw new IdAuthenticationBusinessException(
IdAuthenticationErrorConstants.MISSING_INPUT_PARAMETER.getErrorCode(), String.format(
IdAuthenticationErrorConstants.MISSING_INPUT_PARAMETER.getErrorMessage(), TEMPLATE));
}
} else {
throw new IdAuthenticationBusinessException(
IdAuthenticationErrorConstants.MISSING_INPUT_PARAMETER.getErrorCode(),
String.format(IdAuthenticationErrorConstants.MISSING_INPUT_PARAMETER.getErrorMessage(), IDENTITY));
}
}


/**
* this method is used to create the auth request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,7 @@ public String decryptEkycData(
@RequestParam(name = "keyFileNameByPartnerName", required = false) boolean keyFileNameByPartnerName,
@RequestParam(name = "certsDir", required = false) String certsDir,
@RequestParam(name = "moduleName", required = false) String moduleName
) throws CertificateException, IOException,
NoSuchAlgorithmException, UnrecoverableEntryException, KeyStoreException, OperatorCreationException,
InvalidKeyException, NoSuchPaddingException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {
) throws Exception {

String identity = requestData.get("identity");
PrivateKeyEntry ekycKey = keyMgrUtil.getKeyEntry(keyMgrUtil.getKeysDirPath(certsDir, moduleName), PartnerTypes.EKYC, partnerName, keyFileNameByPartnerName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,7 @@ public SplittedEncryptedData encryptBiometrics(@RequestBody String bioValue,
@RequestParam(name = "timestamp", required = false) @Nullable String timestamp,
@RequestParam(name = "transactionId", required = false) @Nullable String transactionId,
@RequestParam(name = "isInternal", required = false) @Nullable boolean isInternal)
throws KeyManagementException, NoSuchAlgorithmException, IOException, JSONException, InvalidKeyException,
NoSuchPaddingException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException,
InvalidKeySpecException {
throws Exception {
RestTemplate restTemplate = createRestTemplate();

byte[] xorBytes = BytesUtil.getXOR(timestamp, transactionId);
Expand Down Expand Up @@ -256,12 +254,23 @@ public static <T> RequestWrapper<T> createRequest(T t) {
}

@PostMapping(path = "/splitEncryptedData", produces = MediaType.APPLICATION_JSON_VALUE)
public SplittedEncryptedData splitEncryptedData(@RequestBody String data) {
public SplittedEncryptedData splitEncryptedData(@RequestBody String data) throws Exception {
boolean encryptedDataHasVersion = env.getProperty("encryptedDataHasVersion", boolean.class, false);
byte[] dataBytes = CryptoUtil.decodeURLSafeBase64(data);
byte[][] splits = splitAtFirstOccurance(dataBytes, keySplitter.getBytes());
byte[] thumbPrintAndSessionKey = splits[0];
byte[] thumbPrint = Arrays.copyOfRange(thumbPrintAndSessionKey, 6, 38);//Skip the 6 bytes version and take 32 bytes
byte[] sessionKey = Arrays.copyOfRange(thumbPrintAndSessionKey, 38, thumbPrintAndSessionKey.length);
byte[] sessionKey;
byte[] thumbPrint;

if (thumbPrintAndSessionKey.length >= 288) {
thumbPrint = Arrays.copyOfRange(thumbPrintAndSessionKey, thumbPrintAndSessionKey.length - 288,
thumbPrintAndSessionKey.length - 256);// Skip the 6 bytes version and take 32 bytes
sessionKey = Arrays.copyOfRange(thumbPrintAndSessionKey, thumbPrintAndSessionKey.length - 256,
thumbPrintAndSessionKey.length);
}
else {
throw new Exception("Invalid Encrypted Session Key"); }

byte[] encryptedData = splits[1];
return new SplittedEncryptedData(CryptoUtil.encodeToURLSafeBase64(sessionKey), CryptoUtil.encodeToURLSafeBase64(encryptedData), digestAsPlainText(thumbPrint));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ public static String getFileContent(FileInputStream fis, String encoding) throws
* NoSuchAlgorithmException, CertificateException, InvalidKeyException,
* NoSuchProviderException, SignatureException, CertificateParsingException,
* CertificateEncodingException, JoseException { String commonName = "sanz";
* String organizationalUnit = "Mindtree Hi-Tech World"; String organization =
* "Mindtree Limited"; String country = "india";
* String organizationalUnit = " Hi-Tech World"; String organization =
* "XYZ Limited"; String country = "india";
*
* int keySize = 2048; int validDays = 9999; X500Name distinguishedName = new
* X500Name(commonName, organizationalUnit, organization, country); KeyPair kp =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ida-demo.api.version=v1
server.port = 8082
ida.authRequest.template={"consentObtained":true,"id":"mosip.identity.$authType","individualId":"$id","keyIndex":"string","request":"$encRequest","requestHMAC":"$encHmac","requestSessionKey":"$encSessionKey","requestTime":"$timestamp","transactionID":"$txn","version":"$ver","domainUri":"$domainUri","env":"$env","specVersion":"1.0","thumbprint":"$thumbprint"}
ida.kycExchangeRequest.template={"consentObtained":["true"],"locales":["eng"],"id":"mosip.identity.$authType","individualId":"$id","individualIdType":"$individualIdType","kycToken":"$kycToken","respType":"$respType","metadata":"$request","requestTime":"$timestamp","transactionID":"$txn","version":"$ver"}
ida.vciExchangeRequest.template={"consentObtained":["true"],"locales":["eng"],"id":"mosip.identity.$authType","individualId":"$id","individualIdType":"$individualIdType","kycToken":"$kycToken","respType":"$respType","metadata":"$request","requestTime":"$timestamp","transactionID":"$txn","version":"$ver","vcAuthToken":"$vcAuthToken","credSubjectId":"$credSubjectId","vcAuthToken":"$vcAuthToken","vcFormat":"$vcFormat"}
otpRequestTemplate={\
"id": "$reqId",\
"individualId": "$id",\
Expand Down Expand Up @@ -64,7 +65,7 @@ ida.api.version=1.0
javax.persistence.jdbc.driver=org.postgresql.Driver
javax.persistence.jdbc.url=jdbc:postgresql://localhost:5432/ida_db
javax.persistence.jdbc.user=postgres
javax.persistence.jdbc.password=admin
javax.persistence.jdbc.password=postgres


# ********* Hibernate Properties ***********
Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit 8d6cbad

Please sign in to comment.