Browse Source

properly handle non-standard chars in key alias. PR 45820.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@697139 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
15de83a00f
5 changed files with 38 additions and 0 deletions
  1. +4
    -0
      WHATSNEW
  2. +5
    -0
      src/etc/testcases/taskdefs/signjar.xml
  3. BIN
      src/etc/testcases/testkeystore
  4. +18
    -0
      src/main/org/apache/tools/ant/taskdefs/condition/IsSigned.java
  5. +11
    -0
      src/tests/junit/org/apache/tools/ant/taskdefs/SignJarTest.java

+ 4
- 0
WHATSNEW View File

@@ -222,6 +222,10 @@ Fixed bugs:
regardless of their configuration.
Bugzilla Report 37970.

* <signjar> and <issigned> didn't handle aliases with characters other
than numbers, letters, hyphen or underscore properly.
Bugzilla Report 45820.

Other changes:
--------------



+ 5
- 0
src/etc/testcases/taskdefs/signjar.xml View File

@@ -80,6 +80,11 @@
<assertSigned/>
</target>

<target name="invalidchars" depends="jar">
<sign alias="test@nly"/>
<assertSigned/>
</target>

<target name="maxmemory" depends="jar">
<sign maxmemory="128m"/>
<assertSigned/>


BIN
src/etc/testcases/testkeystore View File


+ 18
- 0
src/main/org/apache/tools/ant/taskdefs/condition/IsSigned.java View File

@@ -23,6 +23,7 @@ import java.util.Enumeration;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.ManifestTask;
import org.apache.tools.ant.types.DataType;
import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipFile;
@@ -84,6 +85,7 @@ public class IsSigned extends DataType implements Condition {
}
return false;
}
name = replaceInvalidChars(name);
boolean shortSig = jarFile.getEntry(SIG_START
+ name.toUpperCase()
+ SIG_END) != null;
@@ -131,4 +133,20 @@ public class IsSigned extends DataType implements Condition {
}
return r;
}

private static String replaceInvalidChars(final String name) {
StringBuffer sb = new StringBuffer();
final int len = name.length();
boolean changes = false;
for (int i = 0; i < len; i++) {
final char ch = name.charAt(i);
if (ManifestTask.VALID_ATTRIBUTE_CHARS.indexOf(ch) < 0) {
sb.append("_");
changes = true;
} else {
sb.append(ch);
}
}
return changes ? sb.toString() : name;
}
}

+ 11
- 0
src/tests/junit/org/apache/tools/ant/taskdefs/SignJarTest.java View File

@@ -70,6 +70,17 @@ public class SignJarTest extends BuildFileTest {
sj.isSigned());
}

public void testInvalidChars() {
executeTarget("invalidchars");
SignJarChild sj = new SignJarChild();
sj.setAlias("test@nly");
sj.setKeystore("testkeystore");
sj.setStorepass("apacheant");
File jar = new File(getProject().getProperty("test.jar"));
sj.setJar(jar);
assertTrue(sj.isSigned());
}

/**
* subclass in order to get access to protected isSigned method if
* tests and task come from different classloaders.


Loading…
Cancel
Save