When I try to sign a jar with this line:
jarsigner -storetype pkcs12 -keystore cert_comodo.pfx MyJar.jar "le-01234567-0123-0123-0123-0123456789ab"
it prompts me for my password, and everything works fine. When I try to sign it with this ant target:
<target name="sign_jars" depends="obfuscated_jar">
<signjar
keystore="cert_comodo.pfx"
alias="le-01234567-0123-0123-0123-0123456789ab"
storepass="A, pa$$." <Not my real password or alias, btw>
storetype="pkcs12">
<path>
<fileset dir="." includes="*.jar" />
</path>
</signjar>
</target>
I get this error:
[signjar] jarsigner error: java.lang.RuntimeException: keystore load: failed t
o decrypt safe contents entry: javax.crypto.BadPaddingException: Given final blo
ck not properly padded
Which is the same error I get if I mistype my password.
Are the $ characters in my password being modified by Ant somehow? Is there a way I can trick ant into letting me type my password interactively? Thanks!
The problem is most likely due to ant seeing $$ as an escaped single $, thus passing the actual password string as A, pa$ to jarsigner. If the problem is still relevant, try changing the password to A, pa$$$$ for 2 $s to be escaped.
Some additional documentation from Apache Antâ„¢ Task Design Guidelines:
... Ant 1.5 passes the single dollar sign "$" through in strings; Ant 1.4 and before would strip it. To get this fix in we first had to write the test suite to expose current behaviour, then change something so that single "$" was passed through, but double "$$" got mapped to "$" for backwards compatibility.
Related
I have two ant files say antFile1.xml and antFile2.xml on windows and linux machine respectively.
antFile1.xml
<target name="executeOnLinux">
<sshexec
host="${remote.host.ip}"
username="${remote.user.id}"
password="${remote.user.ssh.password}"
command="ant -f antFile2.xml 'linuxAntTarget'"
trust="true"/>
</target>
antFile2.xml
<target name="linuxAntTarget">
<input message="Enter application edition number" addproperty="editionNo"/>
<echo message="${editionNo}"/>
</target>
When I execute the the target named "executeOnLinux" from antFile1.xml from my, it connects to the linux machine and starts executing the "linuxAntTarget" from antFile2.xml file. But, as soon as it reaches to the the point where user input is required keeps waiting since I am not able to pass the input. My question is how can I pass the value to it? Is this even possible or there is any other better way of doing it?
Since Ant 1.9.4, the sshexec task provides a useSystemIn attribute:
Whether to pass the current standard input to the remote process, defaults to false
You may also try the input attribute from the same task:
A file from which the executed command's standard input is taken. This attribute is mutually exclusive with the inputstring and inputproperty attributes.
When executing more than one command via commandResource, input will be read for each command. since Ant 1.8.0
I am learning build.xml and am confused by the following code:
<macrodef name="a-test">
<attribute name="port" default="${PORT}"/> #1
<junit printsummary=...
<env key="PORT" value="#{port}" /> #2
...
when I run java with commandLine including -DPORT=8080 and then in java code I get port value 8080 by calling
String port = System.getenv(PORT).
What is the above build.xml doing? So far I know $ is to represent a property while # is to represent an attribute. Besides, the above code is the only place where PORT and port appear. What happens here so that port value are finally obtained in java code? Thanks.
The other question, what is the difference btw. using "env key" and using "sysproperty"? according to http://etutorials.org/Programming/Java+extreme+programming/Chapter+3.+Ant/3.6+Passing+Arguments+to+a+Buildfile/
sysproperty can be use to parse argument -D to java code, while env key is used to do the same thing right? Thanks.
Is there any detailed document about build.xml? the one I google from internet describer things so briefly.
What you see is macrodef in ant. There will be another place in build.xml(or other build.xml) where this is called by like
<a-test port=<value> ..
I would like to ask you for some help. How can I use an scp task when my username contains an # sign?
I tried to escape the character in many ways but it isn't working. In the following example, my username is user#host.com
<scp file="test.txt" todir=""user#host.com":password#ftp.host.com:/" trust="true" sftp="true"/>
<scp file="test.txt" todir="'user#host.com':password#ftp.host.com:/" trust="true" sftp="true"/>
<scp file="test.txt" todir="user\#host.com:password#ftp.host.com:/" trust="true" sftp="true"/>
But the output is always the same:
neither password nor keyfile for user "user has been given. Can't authenticate.
Please, is there anyway to force the task to parse this string correctly? Thank you very much.
By the way, I don't know why but with my current provider it is impossible to create a username without appending the hostname.
I use the SCP task in my build.xml and it's form looks like this:
<scp file="package/ROOT.war" todir="user#example.com:~" trust="true" password="${password}"/>
Looking at the source of the SCP Task at the function parseUri(String uri) (line 370) it appears that the task can support a username with a # symbol. The restrictions appear to be with paths that have a : or # in them as seen by this comment:
// user:password#host:/path notation
// everything upto the last # before the last : is considered
// password. (so if the path contains an # and a : it will not work)
The code doesn't seem to support this comment (as pointed out by
martin clayton). You can also see the error you are referring which is triggered when the password or the keyfile is missing. Maybe the combination of a password in user:password#host:/path notation and a username with an # is causing problems?
Present ant version -1.9.4 operating system:-16.04 Ubuntu did not work.
Changed to 1.9.3 and pointed to /usr/bin/ant ssh was successful
observation:
16.04 and ant 1.9.3 is working
14.04 ant 1.9.4 is working
I would like to ask you for some help. How can I use an scp task when my username contains an # sign?
I tried to escape the character in many ways but it isn't working. In the following example, my username is user#host.com
<scp file="test.txt" todir=""user#host.com":password#ftp.host.com:/" trust="true" sftp="true"/>
<scp file="test.txt" todir="'user#host.com':password#ftp.host.com:/" trust="true" sftp="true"/>
<scp file="test.txt" todir="user\#host.com:password#ftp.host.com:/" trust="true" sftp="true"/>
But the output is always the same:
neither password nor keyfile for user "user has been given. Can't authenticate.
Please, is there anyway to force the task to parse this string correctly? Thank you very much.
By the way, I don't know why but with my current provider it is impossible to create a username without appending the hostname.
I use the SCP task in my build.xml and it's form looks like this:
<scp file="package/ROOT.war" todir="user#example.com:~" trust="true" password="${password}"/>
Looking at the source of the SCP Task at the function parseUri(String uri) (line 370) it appears that the task can support a username with a # symbol. The restrictions appear to be with paths that have a : or # in them as seen by this comment:
// user:password#host:/path notation
// everything upto the last # before the last : is considered
// password. (so if the path contains an # and a : it will not work)
The code doesn't seem to support this comment (as pointed out by
martin clayton). You can also see the error you are referring which is triggered when the password or the keyfile is missing. Maybe the combination of a password in user:password#host:/path notation and a username with an # is causing problems?
Present ant version -1.9.4 operating system:-16.04 Ubuntu did not work.
Changed to 1.9.3 and pointed to /usr/bin/ant ssh was successful
observation:
16.04 and ant 1.9.3 is working
14.04 ant 1.9.4 is working
I have an Ant script running a standard -task after taking in an inputed password:
<input message="Password:" addproperty="password">
<handler classname="org.apache.tools.ant.input.SecureInputHandler" />
</input>
<exec executable="/bin/sh" input="${password}" failonerror="true">
<arg line='-c "myScript.sh"' />
</exec>
The script myScript.sh prompts the user for a password, and, it was my understanding that from the Ant documentation that input is supposed relay input into whatever the <exec> task is executing, but instead I get (for entering the password foobar)
[exec] Failed to open /usr/local/foobar
which is followed by a stack trace from my script complaining about an incorrect password...so obviously I've understood the documentation wrong. Does anybody know how to handle prompted input from external scripts in Ant?
input="${password}"
This will try to read from the file ${password} and send the contents into your script. Try using:
inputstring="${password}"
instead. This will send the string itself instead of treating it like a filename