Skip to content

Commit 1eb043a

Browse files
committed
Added information about PEM encoding issues.
1 parent 0696b60 commit 1eb043a

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ Description of utilising Spring Boot
3737

3838
1) [Misc](#misc)
3939

40+
1) [Known Issues](#known-issues)-
41+
Known issues using the libraries
42+
4043
1) [Support](#support)-
4144
Please feel free to reach out
4245

@@ -215,6 +218,67 @@ For more information and to see an example of this in use take a look at the Spr
215218
If necessary, this can be overridden by setting the `yoti.api.url` system property.
216219
* 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)
217220
* 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 see an error 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+
218282
## Support
219283

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

0 commit comments

Comments
 (0)