Skip to content

Commit

Permalink
SLIB-13 non-Baltic countries date-of-birth parsing caused error (#62)
Browse files Browse the repository at this point in the history
Co-authored-by: Juhan Aasaru <[email protected]>
  • Loading branch information
aasaru and aasaru authored Jan 14, 2022
1 parent 1b12cb8 commit cbaf5a3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [2.1.4] - Upcoming

### Fixed
- bug where non-Baltic certificates without date-of-birth resulted with an exception

## [2.1.3] - 2021-12-22

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ else if (rdn.getType().equalsIgnoreCase("C")) {
}
}

private static LocalDate getDateOfBirth(AuthenticationIdentity identity) {
public static LocalDate getDateOfBirth(AuthenticationIdentity identity) {
return Optional.ofNullable(
CertificateAttributeUtil.getDateOfBirth(identity.getAuthCertificate()))
.orElse(NationalIdentityNumberUtil.getDateOfBirth(identity));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ public class NationalIdentityNumberUtil {
.withResolverStyle(ResolverStyle.STRICT);

/**
* Detect date-of-birth from national identification number if possible or return null.
* Detect date-of-birth from a Baltic national identification number if possible or return null.
*
* This method always returns the value for all Estonian and Lithuanian national identification numbers.
*
* It also works for older Latvian personal codes but Latvian personal codes issued after July 1st 2017
* (starting with "32") do not carry date-of-birth.
*
* Some (but not all) Smart-ID certificates have date-of-birth on a separate attribute.
* For non-Baltic countries (countries other than Estonia, Latvia or Lithuania) it always returns null
* (even if it would be possible to deduce date of birth from national identity number).
*
* Newer (but not all) Smart-ID certificates have date-of-birth on a separate attribute.
* It is recommended to use that value if present.
* @see CertificateAttributeUtil#getDateOfBirth(java.security.cert.X509Certificate)
*
Expand All @@ -41,7 +44,7 @@ public static LocalDate getDateOfBirth(AuthenticationIdentity authenticationIden
case "LV":
return parseLvDateOfBirth(identityNumber);
default:
throw new UnprocessableSmartIdResponseException("Unknown country: " + authenticationIdentity.getCountry());
return null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,22 @@ public void parseLvDateOfBirth_invalidIdCode_throwsException() {
assertThat(exception.getMessage(), is("Unable get birthdate from Latvian personal code 331265-0234"));
}

@Test
public void getDateOfBirthFromIdCode_sweden_returnsNull() {
AuthenticationIdentity identity = new AuthenticationIdentity();
identity.setCountry("SE");
identity.setIdentityNumber("1995012-79039");

assertThat(NationalIdentityNumberUtil.getDateOfBirth(identity), is(nullValue()));
}

@Test
public void getDateOfBirthFromIdCode_poland_returnsNull() {
AuthenticationIdentity identity = new AuthenticationIdentity();
identity.setCountry("PL");
identity.setIdentityNumber("64120301283");

assertThat(NationalIdentityNumberUtil.getDateOfBirth(identity), is(nullValue()));
}

}

0 comments on commit cbaf5a3

Please sign in to comment.