Skip to content

Commit

Permalink
[ES-1233] updated authFactor from KBA to KBI (#202)
Browse files Browse the repository at this point in the history
* [ES-1233] updated authFactor from KBA to KBI

Signed-off-by: Venkata Saidurga Polamraju <[email protected]>

* [ES-1233] reviewed comments

Signed-off-by: Venkata Saidurga Polamraju <[email protected]>

---------

Signed-off-by: Venkata Saidurga Polamraju <[email protected]>
  • Loading branch information
pvsaidurga authored Jun 19, 2024
1 parent bf3f7f0 commit 609791a
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 57 deletions.
2 changes: 1 addition & 1 deletion docs/esignet-signup-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ components:
type: string
enum:
- OTP
- KBA
- KBI
required:
- challenge
- format
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@
],
"body": {
"mode": "raw",
"raw": "{\n \"requestTime\": \"{{$isoTimestamp}}\",\n \"request\": {\n \"identifier\": \"+855{{randomPhoneNumber}}\",\n \"challengeInfo\": [{\n \"challenge\": \"111111\",\n \"format\": \"alpha-numeric\",\n \"type\" : \"OTP\"\n },{\n \"challenge\": \"eyJmdWxsTmFtZSI6W3sibGFuZ3VhZ2UiOiJraG0iLCJ2YWx1ZSI6IuGeluGetuGegOGfkuGemeGen-GemOGfkuGehOGetuGej-GfiyJ9XX0\",\"format\":\"base64url-encoded-json\",\n \"type\" : \"KBA\"\n }]\n }\n}",
"raw": "{\n \"requestTime\": \"{{$isoTimestamp}}\",\n \"request\": {\n \"identifier\": \"+855{{randomPhoneNumber}}\",\n \"challengeInfo\": [{\n \"challenge\": \"111111\",\n \"format\": \"alpha-numeric\",\n \"type\" : \"OTP\"\n },{\n \"challenge\": \"eyJmdWxsTmFtZSI6W3sibGFuZ3VhZ2UiOiJraG0iLCJ2YWx1ZSI6IuGeluGetuGegOGfkuGemeGen-GemOGfkuGehOGetuGej-GfiyJ9XX0\",\"format\":\"base64url-encoded-json\",\n \"type\" : \"KBI\"\n }]\n }\n}",
"options": {
"raw": {
"language": "json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,24 +435,24 @@ private void checkActiveIdentityExists(String transactionId,
throw new SignUpException(ErrorConstants.IDENTITY_INACTIVE);
}

Optional<ChallengeInfo> kbaChallenge = verifyChallengeRequest.getChallengeInfo().stream()
.filter(challengeInfo -> challengeInfo.getType().equals("KBA"))
Optional<ChallengeInfo> kbiChallenge = verifyChallengeRequest.getChallengeInfo().stream()
.filter(challengeInfo -> challengeInfo.getType().equals("KBI"))
.findFirst();
if (kbaChallenge.isEmpty()){
throw new SignUpException(ErrorConstants.KBA_CHALLENGE_NOT_FOUND);
if (kbiChallenge.isEmpty()){
throw new SignUpException(ErrorConstants.KBI_CHALLENGE_NOT_FOUND);
}

List<LanguageTaggedValue> fullNameFromIdRepo = restResponseWrapper.getResponse().getIdentity()
.getFullName().stream()
.filter(fullName -> fullName.getLanguage().equals("khm"))
.collect(Collectors.toList());

String jsonObject = new String(Base64.getUrlDecoder().decode(kbaChallenge.get().getChallenge().getBytes()));
String jsonObject = new String(Base64.getUrlDecoder().decode(kbiChallenge.get().getChallenge().getBytes()));
KnowledgeBaseChallenge knowledgeBaseChallenge = null;
try {
knowledgeBaseChallenge = objectMapper.readValue(jsonObject, KnowledgeBaseChallenge.class);
}catch (JsonProcessingException exception){
throw new SignUpException(ErrorConstants.INVALID_KBA_CHALLENGE);
throw new SignUpException(ErrorConstants.INVALID_KBI_CHALLENGE);
}

if (!knowledgeBaseChallenge.getFullName().equals(fullNameFromIdRepo)){
Expand Down Expand Up @@ -681,7 +681,7 @@ private void validateChallengeFormatAndType(ChallengeInfo challengeInfo) throws
throw new SignUpException(ErrorConstants.CHALLENGE_FORMAT_AND_TYPE_MISMATCH);
}

if (challengeInfo.getType().equals("KBA") && !challengeInfo.getFormat().equals("base64url-encoded-json")){
if (challengeInfo.getType().equals("KBI") && !challengeInfo.getFormat().equals("base64url-encoded-json")){
throw new SignUpException(ErrorConstants.CHALLENGE_FORMAT_AND_TYPE_MISMATCH);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class ErrorConstants {
public static final String UNSUPPORTED_PURPOSE = "unsupported_purpose";
public static final String IDENTIFIER_ALREADY_REGISTERED = "identifier_already_registered";
public static final String IDENTIFIER_NOT_FOUND = "identifier_not_found";
public static final String INVALID_KBA_CHALLENGE = "invalid_KBA_challenge";
public static final String KBA_CHALLENGE_NOT_FOUND = "kba_challenge_not_found";
public static final String INVALID_KBI_CHALLENGE = "invalid_KBI_challenge";
public static final String KBI_CHALLENGE_NOT_FOUND = "kbi_challenge_not_found";
public static final String IDENTITY_INACTIVE = "identity_inactive";
public static final String FETCH_IDENTITY_FAILED = "fetch_identity_failed";
public static final String CHALLENGE_FORMAT_AND_TYPE_MISMATCH = "challenge_format_and_type_mismatch";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ mosip.signup.task.max.pool.size=4
## ------------------------------------- challenge configuration -------------------------------------------------------
mosip.signup.supported.generate-challenge-type=OTP
mosip.signup.supported.challenge-format-types={'alpha-numeric', 'base64url-encoded-json'}
mosip.signup.supported.challenge-types={'OTP', 'KBA'}
mosip.signup.supported.challenge-types={'OTP', 'KBI'}
mosip.signup.supported.challenge.otp.length=6

## ------------------------------------- Cache configuration -----------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,14 @@ public void doVerifyChallengeInResetPassword_withOTPMismatchFormat_throwChalleng
}

@Test
public void doVerifyChallengeInResetPassword_withKBAMismatchFormat_throwChallengeFormatAndTypeMismatch() {
ChallengeInfo challengeInfoKBA = new ChallengeInfo();
challengeInfoKBA.setFormat("base64url-json");
challengeInfoKBA.setChallenge("111111");
challengeInfoKBA.setType("KBA");
public void doVerifyChallengeInResetPassword_withKBIMismatchFormat_throwChallengeFormatAndTypeMismatch() {
ChallengeInfo challengeInfoKBI = new ChallengeInfo();
challengeInfoKBI.setFormat("base64url-json");
challengeInfoKBI.setChallenge("111111");
challengeInfoKBI.setType("KBI");

List<ChallengeInfo> challengeList = new ArrayList<>();
challengeList.add(challengeInfoKBA);
challengeList.add(challengeInfoKBI);

VerifyChallengeRequest verifyChallengeRequest = new VerifyChallengeRequest();
verifyChallengeRequest.setIdentifier("123456");
Expand All @@ -356,7 +356,7 @@ public void doVerifyChallengeInResetPassword_withKBAMismatchFormat_throwChalleng
String mockTransactionId = "mock-transactionId";
RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85512123123", Purpose.RESET_PASSWORD);
String challengeHash = IdentityProviderUtil.generateB64EncodedHash(IdentityProviderUtil.ALGO_SHA3_256,
challengeInfoKBA.getChallenge());
challengeInfoKBI.getChallenge());
registrationTransaction.setChallengeHash(challengeHash);
registrationTransaction.setIdentifier(verifyChallengeRequest.getIdentifier());
registrationTransaction.setLastRetryAt(LocalDateTime.now(ZoneOffset.UTC));
Expand All @@ -371,20 +371,20 @@ public void doVerifyChallengeInResetPassword_withKBAMismatchFormat_throwChalleng
}

@Test
public void doVerifyChallengeInResetPassword_withInvalidKBAChallenge_throwInvalidKBAChallenge() {
public void doVerifyChallengeInResetPassword_withInvalidKBIChallenge_throwInvalidKBIChallenge() {

ChallengeInfo challengeInfoKBA = new ChallengeInfo();
challengeInfoKBA.setFormat("base64url-encoded-json");
challengeInfoKBA.setChallenge("eyAiZnVsbE5hbWUiOiBbeyJsYW5ndWFnZSI6ImtobSIsICJ2YWx1ZSI6ICLhnoThnpPhn4sg4Z6Y4Z==");
challengeInfoKBA.setType("KBA");
ChallengeInfo challengeInfoKBI = new ChallengeInfo();
challengeInfoKBI.setFormat("base64url-encoded-json");
challengeInfoKBI.setChallenge("eyAiZnVsbE5hbWUiOiBbeyJsYW5ndWFnZSI6ImtobSIsICJ2YWx1ZSI6ICLhnoThnpPhn4sg4Z6Y4Z==");
challengeInfoKBI.setType("KBI");

ChallengeInfo challengeInfoOTP = new ChallengeInfo();
challengeInfoOTP.setFormat("alpha-numeric");
challengeInfoOTP.setChallenge("111111");
challengeInfoOTP.setType("OTP");

List<ChallengeInfo> challengeList = new ArrayList<>();
challengeList.add(challengeInfoKBA);
challengeList.add(challengeInfoKBI);
challengeList.add(challengeInfoOTP);

VerifyChallengeRequest verifyChallengeRequest = new VerifyChallengeRequest();
Expand Down Expand Up @@ -425,25 +425,25 @@ public void doVerifyChallengeInResetPassword_withInvalidKBAChallenge_throwInvali
registrationService.verifyChallenge(verifyChallengeRequest, mockTransactionId);
Assert.fail();
} catch (SignUpException signUpException) {
Assert.assertEquals("invalid_KBA_challenge", signUpException.getErrorCode());
Assert.assertEquals("invalid_KBI_challenge", signUpException.getErrorCode());
}
}

@Test
public void doVerifyChallengeInResetPassword_withFullNameMismatch_throwKnowledgeBaseMismatch() {

ChallengeInfo challengeInfoKBA = new ChallengeInfo();
challengeInfoKBA.setFormat("base64url-encoded-json");
challengeInfoKBA.setChallenge("eyAiZnVsbE5hbWUiOiBbeyJsYW5ndWFnZSI6ImtobSIsICJ2YWx1ZSI6ICJNYW5val9raG0ifV0gfQ==");
challengeInfoKBA.setType("KBA");
ChallengeInfo challengeInfoKBI = new ChallengeInfo();
challengeInfoKBI.setFormat("base64url-encoded-json");
challengeInfoKBI.setChallenge("eyAiZnVsbE5hbWUiOiBbeyJsYW5ndWFnZSI6ImtobSIsICJ2YWx1ZSI6ICJNYW5val9raG0ifV0gfQ==");
challengeInfoKBI.setType("KBI");

ChallengeInfo challengeInfoOTP = new ChallengeInfo();
challengeInfoOTP.setFormat("alpha-numeric");
challengeInfoOTP.setChallenge("111111");
challengeInfoOTP.setType("OTP");

List<ChallengeInfo> challengeList = new ArrayList<>();
challengeList.add(challengeInfoKBA);
challengeList.add(challengeInfoKBI);
challengeList.add(challengeInfoOTP);

VerifyChallengeRequest verifyChallengeRequest = new VerifyChallengeRequest();
Expand Down Expand Up @@ -491,18 +491,18 @@ public void doVerifyChallengeInResetPassword_withFullNameMismatch_throwKnowledge
@Test
public void doVerifyChallengeInResetPassword_thenSuccess() {

ChallengeInfo challengeInfoKBA = new ChallengeInfo();
challengeInfoKBA.setFormat("base64url-encoded-json");
challengeInfoKBA.setChallenge("eyAiZnVsbE5hbWUiOiBbeyJsYW5ndWFnZSI6ImtobSIsICJ2YWx1ZSI6ICLhnoThnpPhn4sg4Z6Y4Z-J4Z-B4Z6E4Z6b4Z624Z6EIn1dIH0");
challengeInfoKBA.setType("KBA");
ChallengeInfo challengeInfoKBI = new ChallengeInfo();
challengeInfoKBI.setFormat("base64url-encoded-json");
challengeInfoKBI.setChallenge("eyAiZnVsbE5hbWUiOiBbeyJsYW5ndWFnZSI6ImtobSIsICJ2YWx1ZSI6ICLhnoThnpPhn4sg4Z6Y4Z-J4Z-B4Z6E4Z6b4Z624Z6EIn1dIH0");
challengeInfoKBI.setType("KBI");

ChallengeInfo challengeInfoOTP = new ChallengeInfo();
challengeInfoOTP.setFormat("alpha-numeric");
challengeInfoOTP.setChallenge("111111");
challengeInfoOTP.setType("OTP");

List<ChallengeInfo> challengeList = new ArrayList<>();
challengeList.add(challengeInfoKBA);
challengeList.add(challengeInfoKBI);
challengeList.add(challengeInfoOTP);

VerifyChallengeRequest verifyChallengeRequest = new VerifyChallengeRequest();
Expand Down Expand Up @@ -579,18 +579,18 @@ public void doVerifyChallenge_withInvalidFormatForOTPChallenge_throwChallengeFor
@Test
public void doVerifyChallengeInResetPassword_withInactiveIdentity_throwIdentityInactive() {

ChallengeInfo challengeInfoKBA = new ChallengeInfo();
challengeInfoKBA.setFormat("base64url-encoded-json");
challengeInfoKBA.setChallenge("eyAiZnVsbE5hbWUiOiBbeyJsYW5ndWFnZSI6ImtobSIsICJ2YWx1ZSI6ICLhnoThnpPhn4sg4Z6Y4Z-J4Z-B4Z6E4Z6b4Z624Z6EIn1dIH0");
challengeInfoKBA.setType("KBA");
ChallengeInfo challengeInfoKBI = new ChallengeInfo();
challengeInfoKBI.setFormat("base64url-encoded-json");
challengeInfoKBI.setChallenge("eyAiZnVsbE5hbWUiOiBbeyJsYW5ndWFnZSI6ImtobSIsICJ2YWx1ZSI6ICLhnoThnpPhn4sg4Z6Y4Z-J4Z-B4Z6E4Z6b4Z624Z6EIn1dIH0");
challengeInfoKBI.setType("KBI");

ChallengeInfo challengeInfoOTP = new ChallengeInfo();
challengeInfoOTP.setFormat("alpha-numeric");
challengeInfoOTP.setChallenge("111111");
challengeInfoOTP.setType("OTP");

List<ChallengeInfo> challengeList = new ArrayList<>();
challengeList.add(challengeInfoKBA);
challengeList.add(challengeInfoKBI);
challengeList.add(challengeInfoOTP);

VerifyChallengeRequest verifyChallengeRequest = new VerifyChallengeRequest();
Expand Down Expand Up @@ -635,7 +635,7 @@ public void doVerifyChallengeInResetPassword_withInactiveIdentity_throwIdentityI
}

@Test
public void doVerifyChallengeInResetPassword_withKBAChallengeNotFound_throwIdentityInactive() {
public void doVerifyChallengeInResetPassword_withKBIChallengeNotFound_throwIdentityInactive() {

ChallengeInfo challengeInfoOTP = new ChallengeInfo();
challengeInfoOTP.setFormat("alpha-numeric");
Expand Down Expand Up @@ -689,18 +689,18 @@ public void doVerifyChallengeInResetPassword_withKBAChallengeNotFound_throwIdent
@Test
public void doVerifyChallengeInResetPassword_whenGetIdentityNullResponse_throwFetchFailed() {

ChallengeInfo challengeInfoKBA = new ChallengeInfo();
challengeInfoKBA.setFormat("base64url-encoded-json");
challengeInfoKBA.setChallenge("eyAiZnVsbE5hbWUiOiBbeyJsYW5ndWFnZSI6ImtobSIsICJ2YWx1ZSI6ICLhnoThnpPhn4sg4Z6Y4Z-J4Z-B4Z6E4Z6b4Z624Z6EIn1dIH0");
challengeInfoKBA.setType("KBA");
ChallengeInfo challengeInfoKBI = new ChallengeInfo();
challengeInfoKBI.setFormat("base64url-encoded-json");
challengeInfoKBI.setChallenge("eyAiZnVsbE5hbWUiOiBbeyJsYW5ndWFnZSI6ImtobSIsICJ2YWx1ZSI6ICLhnoThnpPhn4sg4Z6Y4Z-J4Z-B4Z6E4Z6b4Z624Z6EIn1dIH0");
challengeInfoKBI.setType("KBI");

ChallengeInfo challengeInfoOTP = new ChallengeInfo();
challengeInfoOTP.setFormat("alpha-numeric");
challengeInfoOTP.setChallenge("111111");
challengeInfoOTP.setType("OTP");

List<ChallengeInfo> challengeList = new ArrayList<>();
challengeList.add(challengeInfoKBA);
challengeList.add(challengeInfoKBI);
challengeList.add(challengeInfoOTP);

VerifyChallengeRequest verifyChallengeRequest = new VerifyChallengeRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ mosip.signup.status.request.limit=10
## ------------------------------------- challenge configuration -------------------------------------------------------
mosip.signup.supported.generate-challenge-type=OTP
mosip.signup.supported.challenge-format-types={'alpha-numeric', 'base64url-encoded-json'}
mosip.signup.supported.challenge-types={'OTP', 'KBA'}
mosip.signup.supported.challenge-types={'OTP', 'KBI'}
mosip.signup.supported.challenge.otp.length=6

## ------------------------------------- Cache configuration -----------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions signup-ui/public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@
"reset_pwd_failed": "Reset Password Failed",
"identifier_already_registered": "Identifier already registered",
"identifier_not_found": "Invalid number or name. Please enter a registered mobile number and full name.",
"invalid_kba_challenge": "Invalid number or name. Please enter a registered mobile number and full name.",
"kba_challenge_not_found": "Invalid number or name. Please enter a registered mobile number and full name.",
"invalid_kbi_challenge": "Invalid number or name. Please enter a registered mobile number and full name.",
"kbi_challenge_not_found": "Invalid number or name. Please enter a registered mobile number and full name.",
"identity_inactive": "Identifier inactive",
"fetch_identity_failed": "Fetch Identifier Failed",
"challenge_format_and_type_mismatch": "Challenge format and type mismatch",
Expand Down
4 changes: 2 additions & 2 deletions signup-ui/public/locales/km.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@
"reset_pwd_failed": "ការកំណត់ពាក្យសម្ងាត់ឡើងវិញបានបរាជ័យ",
"identifier_already_registered": "អត្តសញ្ញាណបានចុះឈ្មោះរួចហើយ",
"identifier_not_found": "លេខទូរស័ព្ទ ឬឈ្មោះមិនត្រឹមត្រូវ។ សូមបញ្ចូលលេខទូរស័ព្ទនិងឈ្មោះដែលបានចុះឈ្មោះ។",
"invalid_kba_challenge": "លេខទូរស័ព្ទ ឬឈ្មោះមិនត្រឹមត្រូវ។ សូមបញ្ចូលលេខទូរស័ព្ទនិងឈ្មោះដែលបានចុះឈ្មោះ។",
"kba_challenge_not_found": "លេខទូរស័ព្ទ ឬឈ្មោះមិនត្រឹមត្រូវ។ សូមបញ្ចូលលេខទូរស័ព្ទនិងឈ្មោះដែលបានចុះឈ្មោះ។",
"invalid_kbi_challenge": "លេខទូរស័ព្ទ ឬឈ្មោះមិនត្រឹមត្រូវ។ សូមបញ្ចូលលេខទូរស័ព្ទនិងឈ្មោះដែលបានចុះឈ្មោះ។",
"kbi_challenge_not_found": "លេខទូរស័ព្ទ ឬឈ្មោះមិនត្រឹមត្រូវ។ សូមបញ្ចូលលេខទូរស័ព្ទនិងឈ្មោះដែលបានចុះឈ្មោះ។",
"identity_inactive": "អត្តសញ្ញាណអសកម្ម",
"fetch_identity_failed": "ទាញ​យក​លេខ​សម្គាល់​បាន​បរាជ័យ",
"challenge_format_and_type_mismatch": "លេខទូរស័ព្ទ ឬឈ្មោះមិនត្រឹមត្រូវ។ សូមបញ្ចូលលេខទូរស័ព្ទនិងឈ្មោះដែលបានចុះឈ្មោះ។",
Expand Down
2 changes: 1 addition & 1 deletion signup-ui/src/pages/ResetPasswordPage/Otp/Otp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export const Otp = ({ methods, settings }: OtpProps) => {
{
challenge: base64FullName(getValues("fullname"), "khm"),
format: "base64url-encoded-json",
type: "KBA",
type: "KBI",
},
],
},
Expand Down
8 changes: 4 additions & 4 deletions signup-ui/src/typings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ export type RegisterStatusErrors =
export const ResetPasswordPossibleInvalid = [
"knowledgebase_mismatch",
"identifier_not_found",
"invalid_kba_challenge",
"invalid_kbi_challenge",
"challenge_format_and_type_mismatch",
"kba_challenge_not_found"
"kbi_challenge_not_found"
];

const ResetPasswordPossibleErrors = [
Expand All @@ -65,9 +65,9 @@ const ResetPasswordPossibleErrors = [
"reset_pwd_failed",
"knowledgebase_mismatch",
"identifier_not_found",
"invalid_kba_challenge",
"invalid_kbi_challenge",
"challenge_format_and_type_mismatch",
"kba_challenge_not_found",
"kbi_challenge_not_found",
] as const;

export type ResetPasswordErrors = (typeof ResetPasswordPossibleErrors)[number];
Expand Down

0 comments on commit 609791a

Please sign in to comment.