amphibient
amphibient

Reputation: 31212

jarsigner plugin and special characters in storepass

I am using maven-jarsigner-plugin to sign some webstart jars:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jarsigner-plugin</artifactId>
    <version>1.4</version>
    <executions>
        <execution>
            <phase>package</phase>
            <id>sign</id>
            <goals>
                <goal>sign</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <keystore>key/mystore.jks</keystore>
        <alias>myalias</alias>
        <storepass>aBc.d:efg,H#ij^k?L</storepass>
    </configuration>
</plugin>

The problem seem to be the special characters in the storepass. When I am on Windows, providing the storepass as shown above causes the following error:

Failed executing 'cmd.exe /X /C "D:\SOFT\JDK8\jre\..\bin\jarsigner.exe ...

When I run the underlying jarsigner command:

jarsigner.exe -keystore D:\path\to\mystore.jks -storepass aBc.d:efg,H#ij^k?L D:\path\to\project\target\webstarts.jar myalias

I get a similar error but when I wrap the storepass in quotes, it works. So I went back into my pom.xml and put the storepass there in quotes:

<storepass>"aBc.d:efg,H#ij^k?L"</storepass>

And it worked. Unfortunately, when I run the same build on my build server, which is Linux, the quotes don't work -- it works only without quotes. So I tried to take the storepass literal out of the pom altogether and do something like

<storepass>${jks.storepass}</storepass>

and then

mvn clean package -Djks.storepass=aBc.d:efg,H#ij^k?L

but that didn't work with or without quotes on Windows.

I am looking for a solution that will support a storepass with special characters and will work on both Windows and Linux with the same pom. Back when we had a storepass with no special characters (like "changeme"), everything worked fine and required no quotes.

Upvotes: 0

Views: 426

Answers (1)

Pierre B.
Pierre B.

Reputation: 12933

You can leverage profile and activation per OS to use quotes on Windows and not on Linux. For example:

<profiles>
    <profile>
        <activation>
            <os>
                <family>windows</family>
            </os>
        </activation>
        <properties>
            <jks.storepass>"my?^#pass"</jks.storepass>
        </properties>
    </profile>
    <profile>
        <activation>
            <os>
                <family>unix</family>
            </os>
        </activation>
        <properties>
            <jks.storepass>my?^#pass</jks.storepass>
        </properties>
    </profile>
</profiles>

...

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jarsigner-plugin</artifactId>
    <version>1.4</version>
    <executions>
        <execution>
            <phase>package</phase>
            <id>sign</id>
            <goals>
                <goal>sign</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <keystore>key/mystore.jks</keystore>
        <alias>myalias</alias>
        <storepass>${jks.storepass}</storepass>
    </configuration>
</plugin>

If you want to run your build on other OS families, you may want to specify a profile for each of them. Available OS families and names are documented in the Enforcer plugin.

Upvotes: 0

Related Questions