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

Updated certificate API changes #62

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions src/main/environment/common_ci.properties
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ [email protected]_Account_ID_BASE_URL@/api/v1/account/profile
getAbdmFacilityServicies= @env.ABDM_BASE_URL@/devservice/v1/bridges/getServices

##ABDM V3 APIs
abdmV3UserAuthenticate = @env.ABDM_BASE_URL@/api/hiecm/gateway/v3/sessions
getAuthCertPublicKey = @env.ABDM_HEALTH_ID_BASE_URL@/api/v1/auth/cert
requestOtpForEnrollment = @env.ABDM_BASE_URL@/abha/api/v3/enrollment/request/otp
abhaEnrollByAadhaar = @env.ABDM_BASE_URL@/abha/api/v3/enrollment/enrol/byAadhaar
Expand Down
1 change: 1 addition & 0 deletions src/main/environment/common_dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ [email protected]_Account_ID_BASE_URL@/api/v1/account/profile
getAbdmFacilityServicies= https://dev.abdm.gov.in/devservice/v1/bridges/getServices

##ABDM V3 APIs
abdmV3UserAuthenticate = https://dev.abdm.gov.in/api/hiecm/gateway/v3/sessions
getAuthCertPublicKey = https://healthidsbx.abdm.gov.in/api/v1/auth/cert
requestOtpForEnrollment = https://abhasbx.abdm.gov.in/abha/api/v3/enrollment/request/otp
abhaEnrollByAadhaar = https://abhasbx.abdm.gov.in/abha/api/v3/enrollment/enrol/byAadhaar
Expand Down
1 change: 1 addition & 0 deletions src/main/environment/common_example.properties
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ [email protected]_Account_ID_BASE_URL@/api/v1/account/profile
getAbdmFacilityServicies= https://dev.abdm.gov.in/devservice/v1/bridges/getServices

##ABDM V3 APIs
abdmV3UserAuthenticate = https://dev.abdm.gov.in/api/hiecm/gateway/v3/sessions
getAuthCertPublicKey = https://healthidsbx.abdm.gov.in/api/v1/auth/cert
requestOtpForEnrollment = https://abhasbx.abdm.gov.in/abha/api/v3/enrollment/request/otp
abhaEnrollByAadhaar = https://abhasbx.abdm.gov.in/abha/api/v3/enrollment/enrol/byAadhaar
Expand Down
1 change: 1 addition & 0 deletions src/main/environment/common_test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ [email protected]_Account_ID_BASE_URL@/api/v1/account/profile
getAbdmFacilityServicies= https://dev.abdm.gov.in/devservice/v1/bridges/getServices

##ABDM V3 APIs
abdmV3UserAuthenticate = https://dev.abdm.gov.in/api/hiecm/gateway/v3/sessions
getAuthCertPublicKey = https://healthidsbx.abdm.gov.in/api/v1/auth/cert
requestOtpForEnrollment = https://abhasbx.abdm.gov.in/abha/api/v3/enrollment/request/otp
abhaEnrollByAadhaar = https://abhasbx.abdm.gov.in/abha/api/v3/enrollment/enrol/byAadhaar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

public interface CertificateKeyService {

public String getCertPublicKey() throws FHIRException;
public String getCertPublicKey(String ndhmAuthToken) throws FHIRException;

}
Original file line number Diff line number Diff line change
@@ -1,41 +1,73 @@
package com.wipro.fhir.service.v3.abha;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.wipro.fhir.service.ndhm.Common_NDHMService;
import com.wipro.fhir.utils.exception.FHIRException;

@Service
public class CertificateKeyServiceImpl implements CertificateKeyService{

public class CertificateKeyServiceImpl implements CertificateKeyService {

@Autowired
private Common_NDHMService common_NDHMService;

@Value("${getAuthCertPublicKey}")
String getAuthCertPublicKey;

private final Logger logger = LoggerFactory.getLogger(this.getClass().getName());

@Override
public String getCertPublicKey() throws FHIRException {
public String getCertPublicKey(String ndhmAuthToken) throws FHIRException {

RestTemplate restTemplate = new RestTemplate();
HttpEntity<Void> requestEntity = new HttpEntity<>(null);
String publicKey = null;

ResponseEntity<String> certResp = restTemplate.exchange(getAuthCertPublicKey, HttpMethod.GET, requestEntity,
String.class);
String body = certResp.getBody();
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("Content-Type", MediaType.APPLICATION_JSON + ";charset=utf-8");
headers.add("REQUEST-ID", UUID.randomUUID().toString());

TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
df.setTimeZone(tz);
String nowAsISO = df.format(new Date());
headers.add("TIMESTAMP", nowAsISO);
headers.add("Authorization", ndhmAuthToken);

String publicKeyString = body.replace("-----BEGIN PUBLIC KEY-----", "").replace("-----END PUBLIC KEY-----", "")
.replaceAll("\\s+", "");
HttpEntity<String> httpEntity = new HttpEntity<>(null, headers);

ResponseEntity<String> certResp = restTemplate.exchange(getAuthCertPublicKey, HttpMethod.GET, httpEntity,
String.class);
String responseStrLogin = common_NDHMService.getBody(certResp);
if (certResp.getStatusCode() == HttpStatusCode.valueOf(200) && certResp.hasBody()) {
JsonObject jsnOBJ = JsonParser.parseString(responseStrLogin).getAsJsonObject();
publicKey = jsnOBJ.get("publicKey").getAsString();

logger.info("publicKeyString : " + publicKeyString);
logger.info("publicKeyString : " + publicKey);

return publicKeyString;
return publicKey;

}
return publicKey;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public String getOtpForEnrollment(String request) throws FHIRException {
RequestOTPEnrollment reqOtpEnrollment = new RequestOTPEnrollment();
LoginMethod loginMethod = InputMapper.gson().fromJson(request, LoginMethod.class);

publicKeyString = certificateKeyService.getCertPublicKey();
publicKeyString = certificateKeyService.getCertPublicKey(ndhmAuthToken);
if (loginMethod.getLoginId() != null) {
encryptedLoginId = encryption.encrypt(loginMethod.getLoginId(), publicKeyString);
}
Expand Down Expand Up @@ -169,10 +169,9 @@ public String enrollmentByAadhaar(String request) throws FHIRException {
headers.add("Authorization", ndhmAuthToken);

// Create the enrollByAadhar object
EnrollByAadhaar enrollByAadhar = new EnrollByAadhaar();
LoginMethod loginData = InputMapper.gson().fromJson(request, LoginMethod.class);

publicKeyString = certificateKeyService.getCertPublicKey();
publicKeyString = certificateKeyService.getCertPublicKey(ndhmAuthToken);
if (loginData.getLoginId() != null) {
encryptedLoginId = encryption.encrypt(loginData.getLoginId(), publicKeyString);
}
Expand Down Expand Up @@ -263,7 +262,7 @@ public String verifyAuthByAbdm(String request) throws FHIRException {

LoginMethod loginMethod = InputMapper.gson().fromJson(request, LoginMethod.class);

publicKeyString = certificateKeyService.getCertPublicKey();
publicKeyString = certificateKeyService.getCertPublicKey(ndhmAuthToken);
if (loginMethod.getLoginId() != null) {
encryptedLoginId = encryption.encrypt(loginMethod.getLoginId(), publicKeyString);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public String requestOtpForAbhaLogin(String request) throws FHIRException {
RequestOTPEnrollment reqOtpEnrollment = new RequestOTPEnrollment();
LoginAbhaRequest loginAbhaRequest = InputMapper.gson().fromJson(request, LoginAbhaRequest.class);

publicKeyString = certificateKeyService.getCertPublicKey();
publicKeyString = certificateKeyService.getCertPublicKey(ndhmAuthToken);
if (loginAbhaRequest.getLoginId() != null) {
encryptedLoginId = encryption.encrypt(loginAbhaRequest.getLoginId(), publicKeyString);
reqOtpEnrollment.setLoginId(encryptedLoginId);
Expand Down Expand Up @@ -181,8 +181,7 @@ public String verifyAbhaLogin(String request) throws FHIRException {
// Create the enrollByAadhar object
VerifyAbhaLogin verifyAbhaLogin = new VerifyAbhaLogin();
LoginMethod loginData = InputMapper.gson().fromJson(request, LoginMethod.class);

publicKeyString = certificateKeyService.getCertPublicKey();
publicKeyString = certificateKeyService.getCertPublicKey(ndhmAuthToken);
if (loginData.getLoginId() != null) {
encryptedLoginId = encryption.encrypt(loginData.getLoginId(), publicKeyString);
}
Expand Down
Loading