Skip to content

Commit cbaf5a3

Browse files
authored
SLIB-13 non-Baltic countries date-of-birth parsing caused error (#62)
Co-authored-by: Juhan Aasaru <Juhan.Aasaru@nortal.com>
1 parent 1b12cb8 commit cbaf5a3

4 files changed

Lines changed: 30 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
All notable changes to this project will be documented in this file.
33
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
44

5+
## [2.1.4] - Upcoming
6+
7+
### Fixed
8+
- bug where non-Baltic certificates without date-of-birth resulted with an exception
9+
510
## [2.1.3] - 2021-12-22
611

712
### Fixed

src/main/java/ee/sk/smartid/AuthenticationResponseValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ else if (rdn.getType().equalsIgnoreCase("C")) {
299299
}
300300
}
301301

302-
private static LocalDate getDateOfBirth(AuthenticationIdentity identity) {
302+
public static LocalDate getDateOfBirth(AuthenticationIdentity identity) {
303303
return Optional.ofNullable(
304304
CertificateAttributeUtil.getDateOfBirth(identity.getAuthCertificate()))
305305
.orElse(NationalIdentityNumberUtil.getDateOfBirth(identity));

src/main/java/ee/sk/smartid/util/NationalIdentityNumberUtil.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ public class NationalIdentityNumberUtil {
1717
.withResolverStyle(ResolverStyle.STRICT);
1818

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

src/test/java/ee/sk/smartid/util/NationalIdentityNumberUtilTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,22 @@ public void parseLvDateOfBirth_invalidIdCode_throwsException() {
9696
assertThat(exception.getMessage(), is("Unable get birthdate from Latvian personal code 331265-0234"));
9797
}
9898

99+
@Test
100+
public void getDateOfBirthFromIdCode_sweden_returnsNull() {
101+
AuthenticationIdentity identity = new AuthenticationIdentity();
102+
identity.setCountry("SE");
103+
identity.setIdentityNumber("1995012-79039");
104+
105+
assertThat(NationalIdentityNumberUtil.getDateOfBirth(identity), is(nullValue()));
106+
}
107+
108+
@Test
109+
public void getDateOfBirthFromIdCode_poland_returnsNull() {
110+
AuthenticationIdentity identity = new AuthenticationIdentity();
111+
identity.setCountry("PL");
112+
identity.setIdentityNumber("64120301283");
113+
114+
assertThat(NationalIdentityNumberUtil.getDateOfBirth(identity), is(nullValue()));
115+
}
116+
99117
}

0 commit comments

Comments
 (0)