Skip to content

Commit 2cf1550

Browse files
authored
add possibility to request mobile device IP address to be returned (#78)
* add possibility to request mobile device IP address to be returned * add implements Serializable --------- Co-authored-by: juhanaasaru <Juhan.Aasaru@nortal.com>
1 parent f8ec2ef commit 2cf1550

17 files changed

Lines changed: 341 additions & 21 deletions

CHANGELOG.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,20 @@
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.3] - UPCOMING
6+
- To request the IP address of the device running Smart-ID app, the following methods were added:
7+
- AuthenticationRequestBuilder.withShareMdClientIpAddress(boolean)
8+
- CertificateRequestBuilder.withShareMdClientIpAddress(boolean)
9+
- SignatureRequestBuilder.withShareMdClientIpAddress(boolean)
10+
- The IP address returned can be read out using:
11+
- SmartIdAuthenticationResponse.getDeviceIpAddress()
12+
- SmartIdCertificate.getDeviceIpAddress()
13+
- SmartIdSignature.getDeviceIpAddress()
14+
515
## [2.2.2] - 2022-11-14
616

717
### Changed
8-
- upgrade jackson, jersey and dependency-check-maven plugin
18+
- upgrade jackson, jersey and dependency-check-maven plugin
919
### Documented
1020
- How to extract date-of-birth from a certificate added as a separate paragraph to readme.
1121
- Added two tests into SmartIdIntegrationTest that demonstrate fetching and parsing a certificate with date-of-birth
@@ -84,7 +94,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
8494
- all endpoints using `NationalIdentityNumber` are now removed as this functionality has been removed from Smart-ID API 2.0
8595
- errors that the caller cannot recover from are now removed from method throws list.
8696
- Hard-coded certificates were removed together with methods:
87-
- SmartIdClient.useDemoEnvSSLCertificates()
97+
- SmartIdClient.useDemoEnvSSLCertificates()
8898
- SmartIdClient.useLiveEnvSSLCertificates()
8999

90100
## [1.6] - 2020-05-25
@@ -101,6 +111,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
101111
- AuthenticationRequestBuilder method withRequestProperties access modifier changed to public
102112

103113
### Added
114+
104115
- Maven wrapper to project
105116

106117
## [1.5] - 2019-11-12
@@ -127,7 +138,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
127138
## [1.3] - 2019-09-13
128139
### Added
129140
- Capabilities parameter ([#25](https://github.com/SK-EID/smart-id-java-client/pull/25))
130-
- [Request properties](https://github.com/SK-EID/smart-id-documentation#416-request-properties) (vcChoice) for authentication and signing ([#21](https://github.com/SK-EID/smart-id-java-client/pull/21))
141+
- [Request properties](https://github.com/SK-EID/smart-id-documentation#416-request-properties) (vcChoice) for authentication and signing ([#21](https://github.com/SK-EID/smart-id-java-client/pull/21))
131142

132143
## [1.2] - 2019-08-21
133144
### Added

README.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,21 @@ logging.level.ee.sk.smartid.rest.LoggingFilter: trace
102102

103103
### Get the IP address of user's device
104104

105-
Smart-ID API returns the IP address of the user's device for subscribed Relying Parties.
106-
This info can be retrieved using one of:
105+
Smart-ID API returns the IP address of the user's device for subscribed Relying Parties who
106+
ask it to be returned.
107107

108-
* [SmartIdAuthenticationResponse.getDeviceIpAddress()](src/main/java/ee/sk/smartid/SmartIdAuthenticationResponse.java#:~:text=getDeviceIpAddress())
109-
* [SmartIdSignature.getDeviceIpAddress()](src/main/java/ee/sk/smartid/SmartIdSignature.java#:~:text=getDeviceIpAddress())
110-
* [SessionStatus.getDeviceIpAddress()](src/main/java/ee/sk/smartid/rest/dao/SessionStatus.java#:~:text=getDeviceIpAddress())
108+
Requesting for the IP address to be returned:
109+
110+
* [AuthenticationRequestBuilder.withShareMdClientIpAddress()](src/main/java/ee/sk/smartid/AuthenticationRequestBuilder.java) -> withShareMdClientIpAddress()
111+
* [SignatureRequestBuilder.withShareMdClientIpAddress()](src/main/java/ee/sk/smartid/SignatureRequestBuilder.java) -> withShareMdClientIpAddress()
112+
* [CertificateRequestBuilder.withShareMdClientIpAddress()](src/main/java/ee/sk/smartid/CertificateRequestBuilder.java) -> withShareMdClientIpAddress()
113+
114+
115+
The returned info can be retrieved using one of:
116+
117+
* [SmartIdAuthenticationResponse.getDeviceIpAddress()](src/main/java/ee/sk/smartid/SmartIdAuthenticationResponse.java) -> getDeviceIpAddress()
118+
* [SmartIdSignature.getDeviceIpAddress()](src/main/java/ee/sk/smartid/SmartIdSignature.java) -> getDeviceIpAddress()
119+
* [SessionStatus.getDeviceIpAddress()](src/main/java/ee/sk/smartid/rest/dao/SessionStatus.java) -> getDeviceIpAddress()
111120

112121

113122
## Example of configuring the client
@@ -188,10 +197,16 @@ SmartIdAuthenticationResponse authenticationResponse = client
188197
.withAllowedInteractionsOrder(
189198
Collections.singletonList(Interaction.displayTextAndPIN("Log in to self-service?")
190199
))
200+
// we want to get the IP address of the device running Smart-ID app
201+
// for the IP to be returned the service provider (SK) must switch on this option
202+
.withShareMdClientIpAddress(true)
191203
.authenticate();
192204

193205
// You need this later to pull user's signing certificate
194206
String documentNumberForFurtherReference = authenticationResponse.getDocumentNumber();
207+
208+
// We get IP of Smart-ID app since we made the request .withShareMdClientIpAddress(true)
209+
String deviceIpAddress = authenticationResponse.getDeviceIpAddress();
195210
```
196211

197212
Note that verificationCode should be displayed by the web service, so the person signing through the Smart-ID mobile app can verify if the verification code displayed on the phone matches with the one shown on the web page.

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public AuthenticationRequestBuilder withCapabilities(Capability... capabilities)
227227
* Specifies capabilities of the user
228228
* <p>
229229
*
230-
* By default there are no specified capabilities.
230+
* By default, there are no specified capabilities.
231231
* The capabilities need to be specified in case of
232232
* a restricted Smart ID user
233233
* {@link #withCapabilities(Capability...)}
@@ -250,6 +250,17 @@ public AuthenticationRequestBuilder withAllowedInteractionsOrder(List<Interactio
250250
return this;
251251
}
252252

253+
/**
254+
* Ask to return the IP address of the mobile device where Smart-ID app was running.
255+
* @see <a href="https://github.com/SK-EID/smart-id-documentation#238-mobile-device-ip-sharing">Mobile Device IP sharing</a>
256+
*
257+
* @return this builder
258+
*/
259+
public AuthenticationRequestBuilder withShareMdClientIpAddress(boolean shareMdClientIpAddress) {
260+
this.shareMdClientIpAddress = shareMdClientIpAddress;
261+
return this;
262+
}
263+
253264
/**
254265
* Send the authentication request and get the response
255266
* <p>
@@ -360,6 +371,13 @@ private AuthenticationSessionRequest createAuthenticationSessionRequest() {
360371
request.setNonce(getNonce());
361372
request.setCapabilities(getCapabilities());
362373
request.setAllowedInteractionsOrder(getAllowedInteractionsOrder());
374+
375+
RequestProperties requestProperties = new RequestProperties();
376+
requestProperties.setShareMdClientIpAddress(this.shareMdClientIpAddress);
377+
if (requestProperties.hasProperties()) {
378+
request.setRequestProperties(requestProperties);
379+
}
380+
363381
return request;
364382
}
365383

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,17 @@ public CertificateRequestBuilder withSemanticsIdentifier(SemanticsIdentifier sem
221221
return this;
222222
}
223223

224+
/**
225+
* Ask to return the IP address of the mobile device where Smart-ID app was running.
226+
* @see <a href="https://github.com/SK-EID/smart-id-documentation#238-mobile-device-ip-sharing">Mobile Device IP sharing</a>
227+
*
228+
* @return this builder
229+
*/
230+
public CertificateRequestBuilder withShareMdClientIpAddress(boolean shareMdClientIpAddress) {
231+
this.shareMdClientIpAddress = shareMdClientIpAddress;
232+
return this;
233+
}
234+
224235
/**
225236
* Send the certificate choice request and get the response
226237
*x
@@ -278,6 +289,8 @@ public SmartIdCertificate createSmartIdCertificate(SessionStatus sessionStatus)
278289
smartIdCertificate.setCertificate(CertificateParser.parseX509Certificate(certificate.getValue()));
279290
smartIdCertificate.setCertificateLevel(certificate.getCertificateLevel());
280291
smartIdCertificate.setDocumentNumber(getDocumentNumber(sessionStatus));
292+
smartIdCertificate.setDeviceIpAddress(sessionStatus.getDeviceIpAddress());
293+
281294
return smartIdCertificate;
282295
}
283296

@@ -300,6 +313,13 @@ private CertificateRequest createCertificateRequest() {
300313
request.setCertificateLevel(getCertificateLevel());
301314
request.setNonce(getNonce());
302315
request.setCapabilities(getCapabilities());
316+
317+
RequestProperties requestProperties = new RequestProperties();
318+
requestProperties.setShareMdClientIpAddress(this.shareMdClientIpAddress);
319+
if (requestProperties.hasProperties()) {
320+
request.setRequestProperties(requestProperties);
321+
}
322+
303323
return request;
304324
}
305325

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,18 @@ public SignatureRequestBuilder withCapabilities(String... capabilities) {
253253
this.capabilities = new HashSet<>(Arrays.asList(capabilities));
254254
return this;
255255
}
256-
256+
257+
/**
258+
* Ask to return the IP address of the mobile device where Smart-ID app was running.
259+
* @see <a href="https://github.com/SK-EID/smart-id-documentation#238-mobile-device-ip-sharing">Mobile Device IP sharing</a>
260+
*
261+
* @return this builder
262+
*/
263+
public SignatureRequestBuilder withShareMdClientIpAddress(boolean shareMdClientIpAddress) {
264+
this.shareMdClientIpAddress = shareMdClientIpAddress;
265+
return this;
266+
}
267+
257268
/**
258269
* @param allowedInteractionsOrder Preferred order of what dialog to present to user. What actually gets displayed depends on user's device and its software version.
259270
* First option from this list that the device is capable of handling is displayed to the user.
@@ -360,6 +371,13 @@ private SignatureSessionRequest createSignatureSessionRequest() {
360371
request.setNonce(getNonce());
361372
request.setCapabilities(getCapabilities());
362373
request.setAllowedInteractionsOrder(getAllowedInteractionsOrder());
374+
375+
RequestProperties requestProperties = new RequestProperties();
376+
requestProperties.setShareMdClientIpAddress(this.shareMdClientIpAddress);
377+
if (requestProperties.hasProperties()) {
378+
request.setRequestProperties(requestProperties);
379+
}
380+
363381
return request;
364382
}
365383
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class SmartIdCertificate implements Serializable {
3434
private X509Certificate certificate;
3535
private String documentNumber;
3636
private String certificateLevel;
37+
private String deviceIpAddress;
3738

3839
public void setCertificate(X509Certificate certificate) {
3940
this.certificate = certificate;
@@ -58,4 +59,13 @@ public String getCertificateLevel() {
5859
public void setCertificateLevel(String certificateLevel) {
5960
this.certificateLevel = certificateLevel;
6061
}
62+
63+
public void setDeviceIpAddress(String deviceIpAddress) {
64+
this.deviceIpAddress = deviceIpAddress;
65+
}
66+
67+
public String getDeviceIpAddress() {
68+
return deviceIpAddress;
69+
}
70+
6171
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public abstract class SmartIdRequestBuilder {
6060
protected String nonce;
6161
protected Set<String> capabilities;
6262
protected List<Interaction> allowedInteractionsOrder;
63+
protected Boolean shareMdClientIpAddress;
6364

6465
protected SmartIdRequestBuilder(SmartIdConnector connector, SessionStatusPoller sessionStatusPoller) {
6566
this.connector = connector;

src/main/java/ee/sk/smartid/rest/dao/AuthenticationSessionRequest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public class AuthenticationSessionRequest implements Serializable {
5454
@JsonInclude(JsonInclude.Include.NON_EMPTY)
5555
private List<Interaction> allowedInteractionsOrder;
5656

57+
@JsonInclude(JsonInclude.Include.NON_NULL)
58+
private RequestProperties requestProperties;
59+
5760
public String getCertificateLevel() {
5861
return certificateLevel;
5962
}
@@ -121,4 +124,13 @@ public List<Interaction> getAllowedInteractionsOrder() {
121124
public void setAllowedInteractionsOrder(List<Interaction> allowedInteractionsOrder) {
122125
this.allowedInteractionsOrder = allowedInteractionsOrder;
123126
}
127+
128+
public RequestProperties getRequestProperties() {
129+
return requestProperties;
130+
}
131+
132+
public void setRequestProperties(RequestProperties requestProperties) {
133+
this.requestProperties = requestProperties;
134+
}
135+
124136
}

src/main/java/ee/sk/smartid/rest/dao/CertificateRequest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,21 @@
3434
public class CertificateRequest implements Serializable {
3535

3636
private String relyingPartyUUID;
37+
3738
private String relyingPartyName;
39+
3840
@JsonInclude(JsonInclude.Include.NON_EMPTY)
3941
private String certificateLevel;
42+
4043
@JsonInclude(JsonInclude.Include.NON_EMPTY)
4144
private String nonce;
45+
4246
@JsonInclude(JsonInclude.Include.NON_NULL)
4347
private Set capabilities;
4448

49+
@JsonInclude(JsonInclude.Include.NON_NULL)
50+
private RequestProperties requestProperties;
51+
4552
public String getCertificateLevel() {
4653
return certificateLevel;
4754
}
@@ -81,4 +88,13 @@ public Set getCapabilities() {
8188
public void setCapabilities(Set capabilities) {
8289
this.capabilities = capabilities;
8390
}
91+
92+
public RequestProperties getRequestProperties() {
93+
return requestProperties;
94+
}
95+
96+
public void setRequestProperties(RequestProperties requestProperties) {
97+
this.requestProperties = requestProperties;
98+
}
99+
84100
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package ee.sk.smartid.rest.dao;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnore;
4+
import com.fasterxml.jackson.annotation.JsonInclude;
5+
6+
import java.io.Serializable;
7+
8+
public class RequestProperties implements Serializable {
9+
10+
@JsonInclude(JsonInclude.Include.NON_NULL)
11+
Boolean shareMdClientIpAddress;
12+
13+
public Boolean getShareMdClientIpAddress() {
14+
return shareMdClientIpAddress;
15+
}
16+
17+
public void setShareMdClientIpAddress(Boolean shareMdClientIpAddress) {
18+
this.shareMdClientIpAddress = shareMdClientIpAddress;
19+
}
20+
21+
@JsonIgnore
22+
public boolean hasProperties() {
23+
return shareMdClientIpAddress != null;
24+
}
25+
26+
}

0 commit comments

Comments
 (0)