Skip to content

Commit

Permalink
MOSIP-36530 : Separate Error Codes (#321)
Browse files Browse the repository at this point in the history
Signed-off-by: nagendra0721 <[email protected]>
Co-authored-by: mahammedtaheer <[email protected]>
  • Loading branch information
nagendra0721 and mahammedtaheer authored Nov 12, 2024
1 parent 4ecc936 commit 50e0457
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ public enum KeymanagerErrorConstant {

EC_SIGN_REFERENCE_ID_NOT_SUPPORTED("KER-KMS-030", "EC Sign Reference Id Not Supported for the Application ID."),

SIGN_APP_ID_REFERENCEID_NOT_ALLOWED("KER-KMS-031", "Application Id with KERNEL & Reference Id with Sign not allowed to upload Partner certificate."),

VALID_KEY_ALREADY_EXIST("KER-KMS-032", "Valid Key already Exist, not allowed to upload another Certificate."),

OTHER_DOMAIN_VALID_KEY_NOT_EXIST("KER-KMS-033", "Other Domain Valid key not available, Upload other domain valid Key certificate."),

PRIVATE_KEY_FOUND("KER-KMS-034", "PrivateKey available, for Other Domain Certificate, Private Key should not available."),

CERTIFICATE_ALREADY_EXIST("KER-KMS-035", "Certificate Already Exist, not allowed to upload same certificate again"),

INTERNAL_SERVER_ERROR("KER-KMS-500", "Internal server error");

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -977,16 +977,16 @@ public UploadCertificateResponseDto uploadOtherDomainCertificate(UploadCertifica
if (appId.equalsIgnoreCase(signApplicationid) && refId.equalsIgnoreCase(certificateSignRefID)) {
LOGGER.error(KeymanagerConstant.SESSIONID, KeymanagerConstant.APPLICATIONID, appId,
"Not allowed to upload other domain certificate with AppId: " + signApplicationid + " & RefId: SIGN.");
throw new KeymanagerServiceException(KeymanagerErrorConstant.UPLOAD_NOT_ALLOWED.getErrorCode(),
KeymanagerErrorConstant.UPLOAD_NOT_ALLOWED.getErrorMessage());
throw new KeymanagerServiceException(KeymanagerErrorConstant.SIGN_APP_ID_REFERENCEID_NOT_ALLOWED.getErrorCode(),
KeymanagerErrorConstant.SIGN_APP_ID_REFERENCEID_NOT_ALLOWED.getErrorMessage());
}
if (keymanagerUtil.isValidReferenceId(refId) &&
(Arrays.stream(KeyReferenceIdConsts.values()).anyMatch((rId) -> rId.name().equals(refId)))) {
LOGGER.error(KeymanagerConstant.SESSIONID, KeymanagerConstant.APPLICATIONID, appId,
"Not allowed to upload other domain certificate with RefId: " + refId
+ ", This refId is reserve for ECC algorithms.");
throw new KeymanagerServiceException(KeymanagerErrorConstant.UPLOAD_NOT_ALLOWED.getErrorCode(),
KeymanagerErrorConstant.UPLOAD_NOT_ALLOWED.getErrorMessage());
throw new KeymanagerServiceException(KeymanagerErrorConstant.EC_SIGN_REFERENCE_ID_NOT_SUPPORTED.getErrorCode(),
KeymanagerErrorConstant.EC_SIGN_REFERENCE_ID_NOT_SUPPORTED.getErrorMessage());
}

LOGGER.info(KeymanagerConstant.SESSIONID, KeymanagerConstant.APPLICATIONID, appId,
Expand Down Expand Up @@ -1019,8 +1019,8 @@ public UploadCertificateResponseDto uploadOtherDomainCertificate(UploadCertifica
if (!keyFromDBStore.isPresent()) {
LOGGER.error(KeymanagerConstant.SESSIONID, KeymanagerConstant.EMPTY, KeymanagerConstant.EMPTY,
"Other valid key is available, so not allowed to upload certificate.");
throw new KeymanagerServiceException(KeymanagerErrorConstant.UPLOAD_NOT_ALLOWED.getErrorCode(),
KeymanagerErrorConstant.UPLOAD_NOT_ALLOWED.getErrorMessage());
throw new KeymanagerServiceException(KeymanagerErrorConstant.VALID_KEY_ALREADY_EXIST.getErrorCode(),
KeymanagerErrorConstant.VALID_KEY_ALREADY_EXIST.getErrorMessage());
}
return storeAndBuildResponse(appId, refId, reqX509Cert, notBeforeDate, notAfterDate, certThumbprint);
}
Expand All @@ -1031,8 +1031,8 @@ public UploadCertificateResponseDto uploadOtherDomainCertificate(UploadCertifica
if (!keyFromDBStore.isPresent() && currentKeyAlias.size() == 1) {
LOGGER.error(KeymanagerConstant.SESSIONID, KeymanagerConstant.EMPTY, KeymanagerConstant.EMPTY,
"Other domain valid key is not available in key store, so not allowed to upload certificate.");
throw new KeymanagerServiceException(KeymanagerErrorConstant.UPLOAD_NOT_ALLOWED.getErrorCode(),
KeymanagerErrorConstant.UPLOAD_NOT_ALLOWED.getErrorMessage());
throw new KeymanagerServiceException(KeymanagerErrorConstant.OTHER_DOMAIN_VALID_KEY_NOT_EXIST.getErrorCode(),
KeymanagerErrorConstant.OTHER_DOMAIN_VALID_KEY_NOT_EXIST.getErrorMessage());
}

// master key alias & key alias should be same & private key should not available for other domain certificates.
Expand All @@ -1041,17 +1041,17 @@ public UploadCertificateResponseDto uploadOtherDomainCertificate(UploadCertifica
if (!keyAlias.equals(masterKeyAlias) || !privateKeyObj.equals(KeymanagerConstant.KS_PK_NA)) {
LOGGER.error(KeymanagerConstant.SESSIONID, KeymanagerConstant.APPLICATIONID, null,
"Not Allowed to update certificate for other domains if private key available.");
throw new KeymanagerServiceException(KeymanagerErrorConstant.UPLOAD_NOT_ALLOWED.getErrorCode(),
KeymanagerErrorConstant.UPLOAD_NOT_ALLOWED.getErrorMessage());
throw new KeymanagerServiceException(KeymanagerErrorConstant.PRIVATE_KEY_FOUND.getErrorCode(),
KeymanagerErrorConstant.PRIVATE_KEY_FOUND.getErrorMessage());
}

//
if (currentKeyAlias.get(0).getCertThumbprint().equals(certThumbprint)) {
LOGGER.error(KeymanagerConstant.SESSIONID, KeymanagerConstant.APPLICATIONID, appId,
"Not Allowed to upload same certificate for other domains. " +
"Current available certificate thumbprint matching with input certificate thumbprint.");
throw new KeymanagerServiceException(KeymanagerErrorConstant.UPLOAD_NOT_ALLOWED.getErrorCode(),
KeymanagerErrorConstant.UPLOAD_NOT_ALLOWED.getErrorMessage());
throw new KeymanagerServiceException(KeymanagerErrorConstant.CERTIFICATE_ALREADY_EXIST.getErrorCode(),
KeymanagerErrorConstant.CERTIFICATE_ALREADY_EXIST.getErrorMessage());
}

LocalDateTime expireTime = timestamp.minusMinutes(1L);
Expand Down

0 comments on commit 50e0457

Please sign in to comment.