Skip to content

Conversation

runeflobakk
Copy link
Member

Implementation was based on an assumption that a path string obtained from a classpath URL can always be converted
to a Path instance, which is not the case, esp. on Windows.

Doing e.g. Paths.get("file:/C:/path/WEB-INF/lib/lib.jar!/file/in/jar") will make
sun.nio.fs.WindowsPathParser throw an InvalidPathException.

The bug was introduced by yours truly yours truly in v6.1:
https://github.com/digipost/signature-api-client-java/blob/6.1/src/main/java/no/digipost/signature/client/core/internal/security/TrustStoreLoader.java#L89
Will backport this fix to v6.1.1.

Exception stacktrace

no.digipost.signature.client.core.exceptions.ConfigurationException: Unable to load certificate from classpath: /certificates/test/Buypass_Class_3_Test4_CA_3.cer
at no.digipost.signature.client.core.internal.security.TrustStoreLoader$ClassPathResourceLoader.forEachFile(TrustStoreLoader.java:91)
at no.digipost.signature.client.core.internal.security.TrustStoreLoader.loadCertificatesInto(TrustStoreLoader.java:54)
at no.digipost.signature.client.core.internal.security.TrustStoreLoader.build(TrustStoreLoader.java:37)
at no.digipost.signature.client.ClientConfiguration.getSSLContext(ClientConfiguration.java:157)
at no.digipost.signature.client.core.internal.http.SignatureHttpClientFactory.create(SignatureHttpClientFactory.java:17)
at no.digipost.signature.client.portal.PortalClient.<init>(PortalClient.java:37)

...
Caused by: java.nio.file.InvalidPathException: Illegal char <:> at index 4: file:/C:/path/WEB-INF/lib/lib.jar!/certificates/test/Buypass_Class_3_Test4_CA_3.cer
at java.base/sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)
at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
at java.base/sun.nio.fs.WindowsPath.parse(WindowsPath.java:92)
at java.base/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:229)
at java.base/java.nio.file.Path.of(Path.java:147)
at java.base/java.nio.file.Paths.get(Paths.java:69)
at no.digipost.signature.client.core.internal.security.TrustStoreLoader$ClassPathResourceLoader.forEachFile(TrustStoreLoader.java:89)

Was based on an assumption that a path string obtained from a classpath URL can always be converted
to a Path instance, which is not the case, esp. on Windows.

Doing e.g. Paths.get("file:/C:/path/WEB-INF/lib/lib.jar!/file/in/jar") will make
sun.nio.fs.WindowsPathParser throw an InvalidPathException.
Copy link
Contributor

@simenstoa simenstoa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙆‍♂️

@runeflobakk runeflobakk merged commit bd979b7 into main Jun 28, 2022
@runeflobakk runeflobakk deleted the fix-certloading-windows-bug branch June 28, 2022 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants