Index: modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/JSParameters.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/JSParameters.java (revision 451900) +++ modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/JSParameters.java (working copy) @@ -100,6 +100,12 @@ // name of the provider to work with keystore private String ksProviderName; + // class name of the provider to work with message digests + private String mdProvider; + + // name of the provider to work with message digests + private String mdProviderName; + // timestamp authority URL private URI tsaURI; @@ -115,7 +121,16 @@ // topic to print help on private String helpTopic; + // true if signature file name is processed by FileNameGenerator + // false if the name that the user has set is unchanged. + private boolean isSFNameProcessed; + // algorithm of the key used to sign data + private String keyAlg; + + // algorithm of the signature used + private String sigAlg; + // set the fields of the JSParameters object to default values void setDefault(){ keyStore = null; @@ -145,6 +160,9 @@ altSigner = null; altSignerPath = null; helpTopic = null; + isSFNameProcessed = false; + keyAlg = null; + sigAlg = null; } // Getters and setters down here @@ -233,6 +251,13 @@ } /** + * @param keyAlg + */ + void setKeyAlg(String keyAlg) { + this.keyAlg = keyAlg; + } + + /** * @param keyPass */ public void setKeyPass(char[] keyPass) { @@ -275,10 +300,18 @@ } /** + * @param sigAlg + */ + void setSigAlg(String sigAlg) { + this.sigAlg = sigAlg; + } + + /** * @param sigFileName */ public void setSigFileName(String sigFileName) { this.sigFileName = sigFileName; + isSFNameProcessed = false; } /** @@ -424,6 +457,13 @@ /** * @return */ + String getKeyAlg() { + return keyAlg; + } + + /** + * @return + */ char[] getKeyPass() { return keyPass; } @@ -467,7 +507,20 @@ /** * @return */ + String getSigAlg() { + return sigAlg; + } + + /** + * @return + */ String getSigFileName() { + // If the file name is not processed by FileNameGenerator. + if (!isSFNameProcessed) { + sigFileName = FileNameGenerator + .generateFileName(sigFileName, alias); + isSFNameProcessed = true; + } return sigFileName; } Index: modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/FileNameGenerator.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/FileNameGenerator.java (revision 451900) +++ modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/FileNameGenerator.java (working copy) @@ -17,50 +17,72 @@ package org.apache.harmony.tools.jarsigner; -import java.util.Arrays; - /** - * File to build the base file names for .SF and .DSA files. + * Class to build the base file names for .SF and .DSA files. + * It is designed to be used only in JSParameters. */ -public class FileNameGenerator { +class FileNameGenerator { private static final int fileNameLength = 8; + private static final int maxExtLength = 3; /** * Generates the file name for .SF and .DSA files using - * param.getSigFileName() or alias given on the command line. - * If the alias + * sigFileName or alias given on the command line. * * @param param * @return + * @throws NullPointerException - if both parameters are null */ - static String generateFileName(JSParameters param){ - if (param.getSigFileName() != null){ - return convertString(param.getSigFileName().toUpperCase()); + static String generateFileName(String sigFileName, String alias){ + if (sigFileName != null){ + return convertString(sigFileName.toUpperCase()); } - String alias = param.getAlias(); if (alias == null){ throw new NullPointerException("Alias is null."); } int length = alias.length(); if (length > fileNameLength){ - alias = alias.substring(0, 7); - length = alias.length(); + alias = alias.substring(0, fileNameLength); + length = fileNameLength; } alias = convertString(alias); - if (length == fileNameLength){ - return alias.toUpperCase(); + return alias.toUpperCase(); + } + + /** + * Generates signature block file name, based on key algorithm. + * + * @param sigFileName + * @param keyAlg + * @return + */ + static String generateSigBlockName(String sigFileName, String keyAlg) { + // make an extension + String sigBlockFileExt; + // max allowed extension length is 3 symbols + if (keyAlg.length() > maxExtLength) { + sigBlockFileExt = "." + + (keyAlg.substring(0, maxExtLength)).toUpperCase(); } else { - char[] remainder = new char[fileNameLength - length]; - Arrays.fill(remainder, '_'); - return alias + new String(remainder); + sigBlockFileExt = "." + keyAlg.toUpperCase(); } + + // add a prefix if necessary + if (keyAlg.equalsIgnoreCase("DSA") || keyAlg.equalsIgnoreCase("RSA")) { + // no prefix + return sigFileName + sigBlockFileExt; + } else { + // add prefix "SIG-" + return "SIG-" + sigFileName + sigBlockFileExt; + } } + // Finds disallowed letters in input String and converts // them to underscores ("_"). Allowed characters are letters, digits, - // hyphens and underscores. If no changes are made the input string is - // returned. + // hyphens and underscores. If no changes are made, the input string itself + // is returned (not a copy!). private static String convertString(String input){ char [] chars = input.toCharArray(); boolean isChanged = false;