Skip to content

Commit

Permalink
MOSIP-19175 MockAbis certificate and CbeffValidator issue fixed (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiranrajbs authored Dec 21, 2021
1 parent fa0f7de commit 47d7f4a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
14 changes: 6 additions & 8 deletions mock-abis/src/main/java/io/mosip/proxy/abis/CryptoCoreUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static java.util.Arrays.copyOfRange;

import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.security.InvalidAlgorithmParameterException;
Expand Down Expand Up @@ -62,16 +61,15 @@ public class CryptoCoreUtil {
public static final byte[] VERSION_RSA_2048 = "VER_R2".getBytes();

private static String UPLOAD_FOLDER = System.getProperty("user.dir")+"/keystore";
private static String PROPERTIES_FILE = UPLOAD_FOLDER+ "/partner.properties";

public static void setPropertyValues() {
Properties prop = new Properties();
try {
prop.load(new FileReader(PROPERTIES_FILE));
keystorePassword = prop.getProperty("keystore.password");
keystoreAlias = prop.getProperty("keystore.alias");
keystoreType = prop.getProperty("keystore.type");
keystoreFilename = prop.getProperty("keystore.filename");
prop.load(Helpers.readStreamFromResources("partner.properties"));
keystorePassword = prop.getProperty("certificate.password");
keystoreAlias = prop.getProperty("certificate.alias");
keystoreType = prop.getProperty("certificate.keystore");
keystoreFilename = prop.getProperty("certificate.filename");

} catch (IOException e) {

Expand Down Expand Up @@ -101,7 +99,7 @@ private PrivateKeyEntry getPrivateKeyEntryFromP12() throws KeyStoreException, No
setPropertyValues();
}
KeyStore keystoreInstance = KeyStore.getInstance(keystoreType);
InputStream is = new FileInputStream(PROPERTIES_FILE);
InputStream is = new FileInputStream(UPLOAD_FOLDER+"/"+ keystoreFilename);
keystoreInstance.load(is, keystorePassword.toCharArray());
ProtectionParameter password = new PasswordProtection(keystorePassword.toCharArray());
PrivateKeyEntry privateKeyEntry = (PrivateKeyEntry) keystoreInstance.getEntry(keystoreAlias, password);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import org.springframework.http.MediaType;
import javax.validation.Valid;
import java.io.UnsupportedEncodingException;
import java.util.Timer;
Expand Down Expand Up @@ -93,14 +93,14 @@ public ResponseEntity<Object> deleteRequest(@RequestBody RequestMO ie) {

}

@RequestMapping(value = "upload", method = RequestMethod.POST)
@RequestMapping(value = "upload", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Upload certificate Request", description = "Upload certificate Request", tags = { "Proxy Abis API" })
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "201", description = "Created", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(schema = @Schema(hidden = true))) })
public ResponseEntity<String> uploadcertificate(@RequestParam("file") MultipartFile uploadfile,
public ResponseEntity<String> uploadcertificate(@RequestBody MultipartFile uploadfile,
@RequestParam("password") String password, @RequestParam("alias") String alias,@RequestParam("keystore") String keystore) {
if (uploadfile.isEmpty())
return new ResponseEntity("Please select a file", HttpStatus.NO_CONTENT);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.mosip.proxy.abis.service.impl;

import io.mosip.kernel.biometrics.commons.CbeffValidator;
import io.mosip.kernel.core.cbeffutil.common.CbeffValidator;
import io.mosip.kernel.core.cbeffutil.jaxbclasses.BIRType;
import io.mosip.kernel.biometrics.entities.BIR;
import io.mosip.kernel.core.cbeffutil.exception.CbeffException;
import io.mosip.kernel.core.exception.ExceptionUtils;
Expand Down Expand Up @@ -60,10 +61,8 @@ public class ProxyAbisInsertServiceImpl implements ProxyAbisInsertService {

private static final Logger logger = LoggerFactory.getLogger(ProxyAbisInsertServiceImpl.class);

private static String UPLOAD_FOLDER = System.getProperty("user.dir")+"/keystore";
private static String PROPERTIES_FILE = UPLOAD_FOLDER+ "/partner.properties";


private static String UPLOAD_FOLDER = System.getProperty("user.dir")+"\\keystore";
private static String PROPERTIES_FILE = UPLOAD_FOLDER+ "\\partner.properties";

@Autowired
ProxyAbisInsertRepository proxyabis;
Expand Down Expand Up @@ -193,23 +192,23 @@ private List<BiometricData> fetchCBEFF(InsertEntity ie) throws Exception {
cbeff = cryptoUtil.decryptCbeff(cbeff);
}

BIR birs = CbeffValidator.getBIRFromXML(IOUtils.toByteArray(cbeff));
BIRType birType = CbeffValidator.getBIRFromXML(IOUtils.toByteArray(cbeff));
logger.info("Validating CBEFF data");
if (CbeffValidator.validateXML(birs)) {
if (CbeffValidator.validateXML(birType)) {
logger.info("Error while validating CBEFF");
throw new CbeffException("Invalid CBEFF");
}

logger.info("Valid CBEFF data");
logger.info("Inserting biometric details to concerned table");

for (BIR bir : birs.getBirs()) {
if (bir.getBdb() != null && bir.getBdb().length > 0) {
for (BIRType bir : birType.getBIR()) {
if (bir.getBDB() != null && bir.getBDB().length > 0) {
BiometricData bd = new BiometricData();
bd.setType(bir.getBdbInfo().getType().iterator().next().value());
if (bir.getBdbInfo().getSubtype() != null && bir.getBdbInfo().getSubtype().size() >0)
bd.setSubtype(bir.getBdbInfo().getSubtype().toString());
String hash = getSHAFromBytes(bir.getBdb());
bd.setType(bir.getBDBInfo().getType().iterator().next().value());
if (bir.getBDBInfo().getSubtype() != null && bir.getBDBInfo().getSubtype().size() >0)
bd.setSubtype(bir.getBDBInfo().getSubtype().toString());
String hash = getSHAFromBytes(bir.getBDB());
bd.setBioData(hash);
bd.setInsertEntity(ie);

Expand Down

0 comments on commit 47d7f4a

Please sign in to comment.