Skip to content

Commit 10f0788

Browse files
authored
Merge pull request #13 from getyoti/doc-updates
Maven Wrapper, Security Scanner & Documentation Updates
2 parents 79a9300 + 5bfa901 commit 10f0788

File tree

13 files changed

+548
-18
lines changed

13 files changed

+548
-18
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ dependency-reduced-pom.xml
2525
buildNumber.properties
2626
.mvn/timing.properties
2727

28+
# Exclude maven wrapper
29+
!/.mvn/wrapper/maven-wrapper.jar
30+
2831

2932
### Intellij ###
3033
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
@@ -201,4 +204,4 @@ $RECYCLE.BIN/
201204
*.lnk
202205

203206
.idea
204-
*.iml
207+
*.iml

.mvn/wrapper/maven-wrapper.jar

48.4 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip

README.md

Lines changed: 114 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,39 @@ Welcome to the Yoti Java SDK. This repo contains the tools and step by step inst
88
1) [An Architectural view](#an-architectural-view) -
99
High level overview of integration
1010

11-
2) [Requirements](#requirements)
11+
1) [Requirements](#requirements)
1212
Everything you need to get started
1313

14-
3) [Enabling the SDK](#enabling-the-sdk)-
14+
1) [Building From Source](#building-from-source)
15+
Everything you need to build from source
16+
17+
1) [Enabling the SDK](#enabling-the-sdk)-
1518
Description on importing your SDK
1619

17-
4) [Client Initialisation](#client-initialisation)-
20+
1) [Client Initialisation](#client-initialisation)-
1821
Description on setting up your SDK
1922

20-
5) [Profile Retrieval](#profile-retrieval) -
23+
1) [Profile Retrieval](#profile-retrieval) -
2124
Description on setting up profile
2225

23-
6) [Handling Users](#handling-users) -
26+
1) [Handling Users](#handling-users) -
2427
Description on handling user log on's
2528

26-
7) [Connectivity Requirements](#connectivity-requirements)-
29+
1) [Connectivity Requirements](#connectivity-requirements)-
2730
Description of network connectivity requirements
2831

29-
7) [Modules](#modules)-
32+
1) [Modules](#modules)-
3033
The Modules above explained
3134

32-
8) [Spring Boot Auto Configuration](#spring-boot-auto-configuration)-
35+
1) [Spring Boot Auto Configuration](#spring-boot-auto-configuration)-
3336
Description of utilising Spring Boot
3437

35-
9) [Misc](#misc)
38+
1) [Misc](#misc)
39+
40+
1) [Known Issues](#known-issues)-
41+
Known issues using the libraries
3642

37-
10) [Support](#support)-
43+
1) [Support](#support)-
3844
Please feel free to reach out
3945

4046
## An Architectural view
@@ -55,6 +61,27 @@ Yoti also allows you to enable user details verification from your mobile app by
5561
* Java 1.6 or higher
5662
* SLF4J
5763

64+
## Building From Source
65+
66+
Building from source is generally not necessary for third parties since artifacts are published in Maven Central. However, if you want to build from source you can do so using the [Maven Wrapper](https://github.com/takari/maven-wrapper) that is bundled with this distribution. For those familiar with Gradle this is much like the Gradle Wrapper and ensures that the correct version of Maven is being used.
67+
68+
From the top level directory:
69+
70+
```bash
71+
./mvnw clean install
72+
```
73+
74+
Notable flags that you may wish to use to skip certain static analysis/code quality tools are listed below. This is only recommended if you find that these tools are taking too long during development or are flagging false positives that you are yet to exclude. **They should not be ignored when building a candidate for a release unless you are sure that the issues being raised are not a cause for concern.**
75+
76+
* `-Dfindbugs.skip=true`: skips findbugs and the findbugs security extension.
77+
* `-Ddependency-check.skip=true`: skips the OWASP dependency scanner.
78+
79+
### Example usage
80+
81+
```bash
82+
./mvnw clean install -Dfindbugs.skip=true -Ddependency-check.skip=true
83+
```
84+
5885
## Enabling the SDK
5986

6087
To import the Yoti SDK inside your project, you can use your favourite dependency management system.
@@ -71,11 +98,17 @@ If you are using Gradle, here is the dependency to add:
7198

7299
`compile group: 'com.yoti', name: 'java-sdk-impl', version: '1.1'`
73100

101+
You will find all classes packaged under `com.yoti.api`
102+
74103

75104
## Client initialisation
76105

77106
The YotiClient is the SDK entry point. To initialise it you need include the following snippet inside your endpoint initialisation section:
78107
```java
108+
import com.yoti.api.client.YotiClient;
109+
import com.yoti.api.client.YotiClientBuilder;
110+
import static com.yoti.api.client.FileKeyPairSource.fromFile;
111+
79112
YotiClient client = YotiClientBuilder.newInstance()
80113
.forApplication(<YOUR_CLIENT_SDK_ID>)
81114
.withKeyPair(fromFile(<PATH/TO/YOUR/APPLICATION/KEY_PAIR.pem>)).build();
@@ -90,11 +123,18 @@ Where:
90123
When your application receives a token via the exposed endpoint (it will be assigned to a query string parameter named `token`), you can easily retrieve the user profile by adding the following to your endpoint handler:
91124

92125
```java
126+
import com.yoti.api.client.ActivityDetails;
127+
93128
ActivityDetails activityDetails = client.getActivityDetails(encryptedToken);
94129
```
95130
or, for a more detailed example:
96131

97132
```java
133+
import com.yoti.api.client.YotiClient;
134+
import com.yoti.api.client.ActivityDetails;
135+
import com.yoti.api.client.HumanProfile;
136+
import com.yoti.api.client.ProfileException;
137+
98138
try {
99139
final ActivityDetails activityDetails = client.getActivityDetails(token);
100140
final HumanProfile profile = activityDetails.getUserProfile();
@@ -133,11 +173,11 @@ try {
133173
Where `yourUserSearchMethod` is a piece of logic in your app that is supposed to find a user, given a userId.
134174
No matter if the user is a new or an existing one, Yoti will always provide her/his profile, so you don't necessarily need to store it.
135175

136-
The `HumanProfile` class provides a set of methods to retrieve different user attributes. Whether the attributes are present or not depends on the settings you have applied to your app on Yoti Dashboard.
176+
The `com.yoti.api.client.HumanProfile` class provides a set of methods to retrieve different user attributes. Whether the attributes are present or not depends on the settings you have applied to your app on Yoti Dashboard.
137177

138178
## Connectivity Requirements
139179

140-
Interacting with the `YotiClient` to get `ActivityDetails` is not an offline operation. Your application will need to be able to establish an outbound TCP connection to port 443 to the Yoti servers at `https://api.yoti.com` (by default - see the [Misc](#misc) section).
180+
Interacting with the `com.yoti.api.client.YotiClient` to get `com.yoti.api.client.ActivityDetails` is not an offline operation. Your application will need to be able to establish an outbound TCP connection to port 443 to the Yoti servers at `https://api.yoti.com` (by default - see the [Misc](#misc) section).
141181

142182
By default the Yoti Client will block indefinitely when connecting to the remote server or reading data. Consequently it is **possible that your application thread could be blocked**.
143183

@@ -175,9 +215,70 @@ For more information and to see an example of this in use take a look at the Spr
175215
## Misc
176216

177217
* By default, Yoti SDKs fetch profiles from [https://api.yoti.com/api/v1](https://api.yoti.com/api/v1).
178-
If necessary, this can be overridden by setting the *yoti.api.url* system property.
218+
If necessary, this can be overridden by setting the `yoti.api.url` system property.
179219
* Yoti Java SDK uses AES-256 encryption. If you are using the Oracle JDK, this key length is not enabled by default. The following stack overflow question explains how to fix this: [http://stackoverflow.com/questions/6481627/java-security-illegal-key-size-or-default-parameters](http://stackoverflow.com/questions/6481627/java-security-illegal-key-size-or-default-parameters)
180220
* To find out how to set up your Java project in order to use this SDK, you can check the Spring Boot example in this repo.
221+
222+
## Known Issues
223+
224+
### Loading Private Keys
225+
226+
#### Affects
227+
228+
* Version 1.1 onwards.
229+
230+
#### Description
231+
232+
There was a known issue with the encoding of RSA private key PEM files that were issued in the past by Yoti Dashboard (most likely where you downloaded the private key for your application).
233+
234+
Some software is more accepting that others and will have been able to cope with the incorrect encoding, whereas some stricter libraries will not accept this encoding.
235+
236+
At version `1.1` of this client the Java Security Provider that we use (`Bouncy Castle`) was [upgraded](https://www.bouncycastle.org/releasenotes.html) from `1.51` -> `1.57`. This upgrade appears to have made the key parser more strict in terms of encoding since it no longer accepts these incorrectly encoded keys.
237+
238+
#### Symptoms
239+
240+
This error usually manifests itself when constructing and instance of the Yoti Client to read the private key.
241+
242+
Generally you'll encounter an exception with an message and stack trace as follows:
243+
244+
```java
245+
com.yoti.api.client.InitialisationException: Cannot load key pair
246+
at com.yoti.api.client.spi.remote.SecureYotiClient.loadKeyPair(SecureYotiClient.java:99)
247+
at com.yoti.api.client.spi.remote.SecureYotiClient.<init>(SecureYotiClient.java:73)
248+
at com.yoti.api.client.spi.remote.SecureYotiClientFactory.getInstance(SecureYotiClientFactory.java:25)
249+
at com.yoti.api.client.ServiceLocatorYotiClientBuilder.build(ServiceLocatorYotiClientBuilder.java:40)
250+
at com.yoti.api.spring.YotiClientAutoConfiguration.yotiClient(YotiClientAutoConfiguration.java:48)
251+
252+
Caused by: org.bouncycastle.openssl.PEMException: problem creating RSA private key: java.lang.IllegalArgumentException: failed to construct sequence from byte[]: corrupted stream detected
253+
at org.bouncycastle.openssl.PEMParser$KeyPairParser.parseObject(Unknown Source)
254+
at org.bouncycastle.openssl.PEMParser.readObject(Unknown Source)
255+
at com.yoti.api.client.spi.remote.SecureYotiClient$KeyStreamVisitor.findKeyPair(SecureYotiClient.java:269)
256+
at com.yoti.api.client.spi.remote.SecureYotiClient$KeyStreamVisitor.accept(SecureYotiClient.java:260)
257+
at com.yoti.api.spring.SpringResourceKeyPairSource.getFromStream(SpringResourceKeyPairSource.java:28)
258+
at com.yoti.api.client.spi.remote.SecureYotiClient.loadKeyPair(SecureYotiClient.java:97)
259+
... 52 common frames omitted
260+
261+
Caused by: org.bouncycastle.openssl.PEMException: problem creating RSA private key: java.lang.IllegalArgumentException: failed to construct sequence from byte[]: corrupted stream detected
262+
at org.bouncycastle.openssl.PEMParser$RSAKeyPairParser.parse(Unknown Source)
263+
... 58 common frames omitted
264+
265+
Caused by: java.lang.IllegalArgumentException: failed to construct sequence from byte[]: corrupted stream detected
266+
at org.bouncycastle.asn1.ASN1Sequence.getInstance(Unknown Source)
267+
... 59 common frames omitted
268+
```
269+
270+
#### How To Fix
271+
272+
You can re-encode the badly encoded PEM file using some software that is more accepting of the incorrect encoding and saving the new key.
273+
274+
An example of software able to do this is `OpenSSL` versions `1.0.2g` and `1.1.0` using the command:
275+
276+
```bash
277+
openssl rsa -in input-file.pem -out fixed-input-file.pem
278+
```
279+
280+
Using the new (correctly encoded) file should now be compatible with versions 1.1 onwards (as well as older versions like `1.0` prior to this).
281+
181282
## Support
182283

183284
For any questions or support please email [[email protected]](mailto:[email protected]).

java-sdk-api/pom.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<groupId>com.yoti</groupId>
66
<artifactId>java-sdk-api</artifactId>
77
<version>1.1</version>
8-
<name>Yoti Java SDK</name>
8+
<name>Yoti Java SDK API</name>
99
<description>Java SDK for simple integration with the Yoti platform</description>
1010
<url>https://github.com/getyoti/java</url>
1111

@@ -102,6 +102,13 @@
102102
<configuration>
103103
<effort>Max</effort>
104104
<threshold>Low</threshold>
105+
<plugins>
106+
<plugin>
107+
<groupId>com.h3xstream.findsecbugs</groupId>
108+
<artifactId>findsecbugs-plugin</artifactId>
109+
<version>1.7.1</version>
110+
</plugin>
111+
</plugins>
105112
</configuration>
106113
</plugin>
107114
</plugins>

java-sdk-impl/findbugs-rules.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,14 @@
2121
<Package name="com.yoti.api.client.spi.remote.proto"/>
2222
<Bug pattern="MS_SHOULD_BE_FINAL,SE_BAD_FIELD,DLS_DEAD_LOCAL_STORE,UCF_USELESS_CONTROL_FLOW"/>
2323
</Match>
24+
25+
<Match>
26+
<Class name="com.yoti.api.client.spi.remote.SecureYotiClient"/>
27+
<Bug pattern="CIPHER_INTEGRITY"/>
28+
</Match>
29+
30+
<Match>
31+
<Bug pattern="CRLF_INJECTION_LOGS"/>
32+
</Match>
2433
</FindBugsFilter>
2534

java-sdk-impl/pom.xml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@
128128
<effort>Max</effort>
129129
<threshold>Low</threshold>
130130
<excludeFilterFile>findbugs-rules.xml</excludeFilterFile>
131+
<plugins>
132+
<plugin>
133+
<groupId>com.h3xstream.findsecbugs</groupId>
134+
<artifactId>findsecbugs-plugin</artifactId>
135+
<version>1.7.1</version>
136+
</plugin>
137+
</plugins>
131138
</configuration>
132139
</plugin>
133140
</plugins>
@@ -136,9 +143,6 @@
136143
<plugin>
137144
<groupId>org.owasp</groupId>
138145
<artifactId>dependency-check-maven</artifactId>
139-
<configuration>
140-
<skip>true</skip>
141-
</configuration>
142146
<executions>
143147
<execution>
144148
<goals>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<!--
4+
Various filters for the FindBugs output
5+
-->
6+
7+
<FindBugsFilter>
8+
9+
<Match>
10+
<Bug pattern="CRLF_INJECTION_LOGS"/>
11+
</Match>
12+
</FindBugsFilter>
13+

java-sdk-spring-boot-auto-config/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@
108108
<configuration>
109109
<effort>Max</effort>
110110
<threshold>Low</threshold>
111+
<excludeFilterFile>findbugs-rules.xml</excludeFilterFile>
112+
<plugins>
113+
<plugin>
114+
<groupId>com.h3xstream.findsecbugs</groupId>
115+
<artifactId>findsecbugs-plugin</artifactId>
116+
<version>1.7.1</version>
117+
</plugin>
118+
</plugins>
111119
</configuration>
112120
</plugin>
113121
</plugins>

java-sdk-springboot-example/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<groupId>com.yoti</groupId>
66
<artifactId>java-sdk-springboot-example</artifactId>
77
<version>1.0-SNAPSHOT</version>
8+
<name>Yoti Java Spring Boot Example</name>
89
<parent>
910
<groupId>org.springframework.boot</groupId>
1011
<artifactId>spring-boot-starter-parent</artifactId>

0 commit comments

Comments
 (0)