2

Hello Stackoverflow Community,

When trying to compile my maven project that uses the bouncycastle security provider, I get this error: java.lang.SecurityException: JCE cannot authenticate the provider BC I am aware that the jar must be signed, so I have added this to the pom.xml to prevent an error with compilation:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.3</version>
        <configuration>
            <filters>
                <filter>
                    <artifact>*:*</artifact>
                    <excludes>
                        <exclude>META-INF/*.SF</exclude>
                        <exclude>META-INF/*.DSA</exclude>
                        <exclude>META-INF/*.RSA</exclude>
                    </excludes>
                </filter>
            </filters>
        </configuration>
        <executions>
            <execution>
                <phase>
                    package
                </phase>
                <goals>
                    <goal>shade</goal>
                </goals>
            </execution>
        </executions>
</plugin>

Based on this (bouncycastle provider can't find classes needed for algorithm) I have added this: Security.setProperty("java.policy", "unlimited"); and I have added the provider with this: Security.addProvider(new BouncyCastleProvider()); in my public static void main.

Unfortunately, this didn't work. Do you have any suggestions of how to implement the thing shown in the post linked above without having to implement it for every JRE separately? Thanks in advance for any help.

A. Tork
  • 43
  • 1
  • 7

1 Answers1

0

I have found a solution with the executable packer maven plugin (https://github.com/nthuemmel/executable-packer-maven-plugin) from this question: How do I put all required JAR files in a library folder inside the final JAR file with Maven? It

<plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>de.ntcomputer</groupId>
            <artifactId>executable-packer-maven-plugin</artifactId>
            <version>1.0.1</version>
            <configuration>
                <mainClass>mh.cryptomail.CryptoMail</mainClass>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>pack-executable-jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.2.0</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>mh.cryptomail.CryptoMail</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>

It copies all jars to the resultant jar unmodified, but it takes a bit longer on startup (about 15s) since it has to register a custom classloader, but it works.

A. Tork
  • 43
  • 1
  • 7