A Maven plugin that converts OpenSSL PEM-formatted root certificate files to a format more easily and efficiently readable in a Java program.
Add this to the <build><plugins>...</plugins></build>
section of your "pom.xml":
<plugin>
<groupId>com.dropbox.maven</groupId>
<artifactId>pem-converter-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<configuration>
<input>whatever.pem</input>
<output>${project.build.directory}/generated-resources/certs/whatever.raw</output>
</configuration>
<goals>
<goal>convert</goal>
</goals>
</execution>
</executions>
</plugin>
Add this to the <build><resources>...</resources></build>
section of your "pom.xml":
<resource>
<directory>${project.build.directory}/generated-resources/certs</directory>
</resource>
Use getResourceAsStream
to read the generated resource file:
InputStream in = MyClass.class.getResourceAsStream("whatever.raw");
if (in == null) {
throw new AssertionError("Couldn't find resource \"whatever.raw\");
}
Then load the certificates from an InputStream
into a KeyStore
. Example code you can copy: RawLoader.java
There's also a command-line script that will run the conversion.
mvn compile
./run