I am running Jetty to load a public certificate in spring config.
If I hardcode the location of the file, it loads the certificate just fine, so I know that there is no issue with the cert itself. However, when I set it up in config, it copies the same to target folder and get this error at that point.
java.security.cert.CertificateException: Could not parse certificate: java.io.IOException: Invalid BER/DER data (too huge?) at sun.security.provider.X509Factory.engineGenerateCertificate(X509Factory.java:104) at java.security.cert.CertificateFactory.generateCertificate(CertificateFactory.java:339)
I do see that the size of the cert has changed after it failed to load. I am not sure if this is the an issue since the other size of other certs in the same folder have also increased and there is no issue of loading them.
Any help is appreciated
I solved this problem by adding the following to my pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<nonFilteredFileExtensions>
<!-- the CER files are included with the correct encoding when
copied into the JAR file when this configuration is present,
see https://stackoverflow.com/questions/49294378/incorrect-encoding-serving-binary-pdf-file-through-classpathresource-in-spring.
-->
<nonFilteredFileExtension>cer</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
</plugins>
</build>
I tried the resource filtering proposed by @manbu, but that was not working.
I got this exception too. I fix it with the maven resource filter configuration. The '.cer' file was filtered (modified) by the maven resource filter plugin because of the follow configuration:
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</resource>
<resources>
so, I add the follow configuration:
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/*.cer</include>
<include>**/*.jks</include>
</includes>
</resource>
</resources>
The exception gone. Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With