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 0) +++ modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/JSParameters.java (revision 0) @@ -0,0 +1,529 @@ +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as applicable + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.apache.harmony.tools.jarsigner; + +import java.io.File; +import java.net.URI; +import java.security.KeyStore; + +/** + * The class encapsulates paramaters for jarsigner most of which are ususally + * given in command line. + */ +public class JSParameters { + /** + * Default location of the keystore. Used when the value is not supplied by + * the user. + */ + public static final String defaultKeystorePath = System + .getProperty("user.home") + + File.separator + ".keystore"; + // the keystore to work with + private KeyStore keyStore; + + // JAR file URL + private URI jarURI; + + // alias to access an entry in keystore + private String alias; + + // should the jar be verified (if it is false, JAR is to be signed) + private boolean isVerify; + + // URL of the keystore + private String storeURI; + + // type of the store. Default type is set in java.security file. + private String storeType = KeyStore.getDefaultType(); + + // password to access the store + private char[] storePass; + + // password to access the key entry + private char[] keyPass; + + // file name to be used when generating .SF and .DSA files + private String sigFileName; + + // file name to be used for signed JAR + private String signedJARName; + + // if used with -verify and -verbose options, makes jarsigner print + // certificate info + private boolean isCerts; + + // should the program be "verbose" or not + private boolean isVerbose; + + // should the .DSA file contain .SF file in it or not + private boolean isInternalSF; + + // if set to true, .SF file will not contain hash of the whole manifest file + private boolean isSectionsOnly; + + // class name of the provider to use if specific provider is not given + private String provider; + + // name of the provider to use if specific provider is not given + private String providerName; + + // class name of the provider to work with certificates + private String certProvider; + + // name of the provider to work with certificates + private String certProviderName; + + // class name of the provider to work with signatures + private String sigProvider; + + // name of the provider to work with signatures + private String sigProviderName; + + // class name of the provider to work with keystore + private String ksProvider; + + // name of the provider to work with keystore + private String ksProviderName; + + // timestamp authority URL + private URI tsaURI; + + // the alias identifiing the TSA's certificate + private String tsaCertAlias; + + // alternative signer class name + private String altSigner; + + // classpath to alternative signer package + private String altSignerPath; + + // topic to print help on + private String helpTopic; + + + // set the fields of the JSParameters object to default values + void setDefault(){ + keyStore = null; + jarURI = null; + alias = null; + storeURI = null; + storeType = KeyStore.getDefaultType(); + storePass = null; + keyPass = null; + sigFileName = null; + signedJARName = null; + isVerify = false; + isCerts = false; + isVerbose = false; + isInternalSF = false; + isSectionsOnly = false; + provider = null; + providerName = null; + certProvider = null; + certProviderName = null; + sigProvider = null; + sigProviderName = null; + ksProvider = null; + ksProviderName = null; + tsaURI = null; + tsaCertAlias = null; + altSigner = null; + altSignerPath = null; + helpTopic = null; + } + + // Getters and setters down here + /** + * @param alias + */ + public void setAlias(String alias) { + this.alias = alias; + } + + /** + * @param altSigner + */ + public void setAltSigner(String altSigner) { + this.altSigner = altSigner; + } + + /** + * @param altSignerPath + */ + public void setAltSignerPath(String altSignerPath) { + this.altSignerPath = altSignerPath; + } + + /** + * @param certProvider + */ + public void setCertProvider(String certProvider) { + this.certProvider = certProvider; + } + + /** + * @param certProviderName + */ + public void setCertProviderName(String certProviderName) { + this.certProviderName = certProviderName; + } + + /** + * @param helpTopic + */ + public void setHelpTopic(String helpTopic) { + this.helpTopic = helpTopic; + } + + /** + * @param isCerts + */ + public void setCerts(boolean isCerts) { + this.isCerts = isCerts; + } + + /** + * @param isInternalSF + */ + public void setInternalSF(boolean isInternalSF) { + this.isInternalSF = isInternalSF; + } + + /** + * @param isSectionsOnly + */ + public void setSectionsOnly(boolean isSectionsOnly) { + this.isSectionsOnly = isSectionsOnly; + } + + /** + * @param isVerbose + */ + public void setVerbose(boolean isVerbose) { + this.isVerbose = isVerbose; + } + + /** + * @param isVerify + */ + public void setVerify(boolean isVerify) { + this.isVerify = isVerify; + } + + /** + * @param jarURI + */ + public void setJarURI(URI jarURI) { + this.jarURI = jarURI; + } + + /** + * @param keyPass + */ + public void setKeyPass(char[] keyPass) { + this.keyPass = keyPass; + } + + /** + * @param keyStore + */ + void setKeyStore(KeyStore keyStore) { + this.keyStore = keyStore; + } + + /** + * @param ksProvider + */ + public void setKsProvider(String ksProvider) { + this.ksProvider = ksProvider; + } + + /** + * @param ksProviderName + */ + public void setKsProviderName(String ksProviderName) { + this.ksProviderName = ksProviderName; + } + + /** + * @param provider + */ + public void setProvider(String provider) { + this.provider = provider; + } + + /** + * @param providerName + */ + public void setProviderName(String providerName) { + this.providerName = providerName; + } + + /** + * @param sigFileName + */ + public void setSigFileName(String sigFileName) { + this.sigFileName = sigFileName; + } + + /** + * @param signedJARName + */ + public void setSignedJARName(String signedJARName) { + this.signedJARName = signedJARName; + } + + /** + * @param sigProvider + */ + public void setSigProvider(String sigProvider) { + this.sigProvider = sigProvider; + } + + /** + * @param sigProviderName + */ + public void setSigProviderName(String sigProviderName) { + this.sigProviderName = sigProviderName; + } + + /** + * @param storePass + */ + public void setStorePass(char[] storePass) { + this.storePass = storePass; + } + + /** + * @param storeType + */ + public void setStoreType(String storeType) { + this.storeType = storeType; + } + + /** + * @param storeURI + */ + public void setStoreURI(String storeURI) { + this.storeURI = storeURI; + } + + /** + * @param tsaCertAlias + */ + public void setTsaCertAlias(String tsaCertAlias) { + this.tsaCertAlias = tsaCertAlias; + } + + /** + * @param tsaURI + */ + public void setTsaURI(URI tsaURI) { + this.tsaURI = tsaURI; + } + + /** + * @return + */ + String getAlias() { + return alias; + } + + /** + * @return + */ + String getAltSigner() { + return altSigner; + } + + /** + * @return + */ + String getAltSignerPath() { + return altSignerPath; + } + + /** + * @return + */ + String getCertProvider() { + return certProvider; + } + + /** + * @return + */ + String getCertProviderName() { + return certProviderName; + } + + /** + * @return + */ + String getHelpTopic() { + return helpTopic; + } + + /** + * @return + */ + boolean isCerts() { + return isCerts; + } + + /** + * @return + */ + boolean isInternalSF() { + return isInternalSF; + } + + /** + * @return + */ + boolean isSectionsOnly() { + return isSectionsOnly; + } + + /** + * @return + */ + boolean isVerbose() { + return isVerbose; + } + + /** + * @return + */ + boolean isVerify() { + return isVerify; + } + + /** + * @return + */ + URI getJarURI() { + return jarURI; + } + + /** + * @return + */ + char[] getKeyPass() { + return keyPass; + } + + /** + * @return + */ + KeyStore getKeyStore(){ + // FIXME: use KeyStoreLoaderSaver + return keyStore; + } + + /** + * @return + */ + String getKsProvider() { + return ksProvider; + } + + /** + * @return + */ + String getKsProviderName() { + return ksProviderName; + } + + /** + * @return + */ + String getProvider() { + return provider; + } + + /** + * @return + */ + String getProviderName() { + return providerName; + } + + /** + * @return + */ + String getSigFileName() { + return sigFileName; + } + + /** + * @return + */ + String getSignedJARName() { + return signedJARName; + } + + /** + * @return + */ + String getSigProvider() { + return sigProvider; + } + + /** + * @return + */ + String getSigProviderName() { + return sigProviderName; + } + + /** + * @return + */ + char[] getStorePass() { + return storePass; + } + + /** + * @return + */ + String getStoreType() { + return storeType; + } + + /** + * @return + */ + String getStoreURI() { + return storeURI; + } + + /** + * @return + */ + String getTsaCertAlias() { + return tsaCertAlias; + } + + /** + * @return + */ + URI getTsaURI() { + return tsaURI; + } +} + Index: modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/JarSignerException.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/JarSignerException.java (revision 0) +++ modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/JarSignerException.java (revision 0) @@ -0,0 +1,63 @@ +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as applicable + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.apache.harmony.tools.jarsigner; + +/** + * Class representing the exceptions specific for jarsigner. + */ +public class JarSignerException extends Exception { + /** + * serial version UID. + */ + private static final long serialVersionUID = 5012429301200382392L; + + /** + * Default constructor. + */ + public JarSignerException() { + super(); + } + + /** + * @param msg - + * exception message to print + */ + public JarSignerException(String msg) { + super(msg); + } + + /** + * @param msg - + * exception message to print + * @param cause - + * throwable that caused this exception to be thrown + */ + public JarSignerException(String msg, Throwable cause) { + super(msg, cause); + } + + /** + * @param cause - + * throwable that caused this exception to be thrown + */ + public JarSignerException(Throwable cause) { + super(cause); + } + + +} + Index: modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/JSSigner.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/JSSigner.java (revision 0) +++ modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/JSSigner.java (revision 0) @@ -0,0 +1,25 @@ +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as applicable + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.apache.harmony.tools.jarsigner; + +/** + * Class to sign JAR files. + */ +public class JSSigner { + // TODO +} + Index: modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/Main.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/Main.java (revision 0) +++ modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/Main.java (revision 0) @@ -0,0 +1,63 @@ +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as applicable + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.apache.harmony.tools.jarsigner; + + +/** + * The main class that bundles command line parsing, interaction with the user, + * exception handling and JAR signing and verification work. + */ +public class Main { + /** + * Does the actual work on JAR signing and verification, based on the + * parameter param. If something goes wrong an exception is thrown. + * + * @param param + * @throws Exception + */ + static void doWork(JSParameters param) throws Exception { + // TODO + } + + /** + * The main method to run from another program. + * + * @param args - + * command line with options. + */ + public static void run(String[] args) throws Exception { + // TODO + } + + + /** + * The main method to run from command line. + * + * @param args - + * command line with options. + */ + public static void main(String[] args) { + try { + run(args); + } catch (Exception e) { + // System.out.println("JarSigner error: " + e); + e.printStackTrace(); + } + } + +} + Index: modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/ArgParser.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/ArgParser.java (revision 0) +++ modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/ArgParser.java (revision 0) @@ -0,0 +1,322 @@ +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as applicable + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.apache.harmony.tools.jarsigner; + +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.Provider; +import java.security.Security; +import java.security.UnrecoverableKeyException; +import java.security.cert.CertificateException; + +/** + * The class to parse the program arguments. + */ +public class ArgParser { + // TODO + // options names to compare to // + final static String sVerify = "-verify"; + + final static String sKeyStore = "-keystore"; + + final static String sStoreType = "-storetype"; + + final static String sStorePass = "-storepass"; + + final static String sKeyPass = "-keypass"; + + final static String sSigFile = "-sigfile"; + + final static String sSignedJAR = "-signedjar"; + + final static String sCerts = "-certs"; + + final static String sVerbose = "-verbose"; + + final static String sInternalSF = "-internalsf"; + + final static String sSectionsOnly = "-sectionsonly"; + + final static String sProvider = "-provider"; + + final static String sProviderName = "-providername"; + + final static String sCertProvider = "-certprovider"; + + final static String sCertProviderName = "-certprovidername"; + + final static String sSigProvider = "-sigprovider"; + + final static String sSigProviderName = "-sigprovidername"; + + final static String sKSProvider = "-ksprovider"; + + final static String sKSProviderName = "-ksprovidername"; + + final static String sTSA = "-tsa"; + + final static String sTSAcert = "-tsacert"; + + final static String sAltSigner = "-altsigner"; + + final static String sAltSignerPath = "-altsignerpath"; + + /** + * @param args + * @param param + * @return new instance of JSParameters if param is null or updated param + * object if it is non-null. Returns null if args is null or + * zero-sized, an unknown option is found or an expected option + * value is not given or not of an expected type. If null is + * returned, the param object contents is not defined. + * @throws JarSignerException + * @throws IOException + * @throws NoSuchAlgorithmException + * @throws UnrecoverableKeyException + * @throws KeyStoreException + * @throws NoSuchProviderException + * @throws CertificateException + */ + static JSParameters parseArgs(String[] args, JSParameters param) + throws JarSignerException, KeyStoreException, + UnrecoverableKeyException, NoSuchAlgorithmException, IOException, + CertificateException, NoSuchProviderException { + if (args == null){ + return null; + } + if (args.length == 0){ + return null; + } + if (param == null){ + param = new JSParameters(); + } else { + // clean param + param.setDefault(); + } + + try { + for (int i = 0; i < args.length; i++) { + if (args[i].equalsIgnoreCase(sVerify)) { + param.setVerify(true); + continue; + } + if (args[i].equalsIgnoreCase(sKeyStore)) { + param.setStoreURI(args[++i]); + continue; + } + if (args[i].equalsIgnoreCase(sStoreType)) { + param.setStoreType(args[++i]); + continue; + } + if (args[i].equalsIgnoreCase(sStorePass)) { + param.setStorePass(args[++i].toCharArray()); + continue; + } + if (args[i].equalsIgnoreCase(sKeyPass)) { + param.setKeyPass(args[++i].toCharArray()); + continue; + } + if (args[i].equalsIgnoreCase(sSigFile)) { + param.setSigFileName(args[++i]); + continue; + } + if (args[i].equalsIgnoreCase(sSignedJAR)) { + param.setSignedJARName(args[++i]); + continue; + } + if (args[i].equalsIgnoreCase(sCerts)) { + param.setCerts(true); + continue; + } + if (args[i].equalsIgnoreCase(sVerbose)) { + param.setVerbose(true); + continue; + } + if (args[i].equalsIgnoreCase(sInternalSF)) { + param.setInternalSF(true); + continue; + } + if (args[i].equalsIgnoreCase(sSectionsOnly)) { + param.setSectionsOnly(true); + continue; + } + if (args[i].equalsIgnoreCase(sProvider)) { + param.setProvider(args[++i]); + addProvider(args[i]); + continue; + } + if (args[i].equalsIgnoreCase(sProviderName)) { + param.setProviderName(args[++i]); + continue; + } + if (args[i].equalsIgnoreCase(sCertProvider)) { + param.setCertProvider(args[++i]); + addProvider(args[i]); + continue; + } + if (args[i].equalsIgnoreCase(sCertProviderName)) { + param.setCertProviderName(args[++i]); + continue; + } + if (args[i].equalsIgnoreCase(sSigProvider)) { + param.setSigProvider(args[++i]); + addProvider(args[i]); + continue; + } + if (args[i].equalsIgnoreCase(sSigProviderName)) { + param.setSigProviderName(args[++i]); + continue; + } + if (args[i].equalsIgnoreCase(sKSProvider)) { + param.setKsProvider(args[++i]); + addProvider(args[i]); + continue; + } + if (args[i].equalsIgnoreCase(sKSProviderName)) { + param.setKsProviderName(args[++i]); + continue; + } + if (args[i].equalsIgnoreCase(sTSA)) { + try { + // TODO: URI scheme + param.setTsaURI(new URI(args[++i])); + } catch (URISyntaxException e) { + throw new JarSignerException("Argument " + args[i] + + " is not a path or URL"); + } + continue; + } + if (args[i].equalsIgnoreCase(sTSAcert)) { + param.setTsaCertAlias(args[++i]); + continue; + } + if (args[i].equalsIgnoreCase(sAltSigner)) { + param.setAltSigner(args[++i]); + continue; + } + if (args[i].equalsIgnoreCase(sAltSignerPath)) { + param.setAltSignerPath(args[++i]); + continue; + } + + if ((param.isVerify() && i == args.length - 1) + || (!param.isVerify() && i == args.length - 2)) { + try { + // TODO: URI scheme + param.setJarURI(new URI(args[i])); + } catch (URISyntaxException e) { + throw new JarSignerException("Argument " + args[i] + + " is not a path or URL"); + } + continue; + } + if (!param.isVerify() && i == args.length - 1){ + param.setAlias(args[i]); + continue; + } + + System.out.println("Illegal option: " + args[i]); + return null; + } + } catch(ArrayIndexOutOfBoundsException e){ + // ignore the last option if its value is not provided + } + + // set specific provider names the same as the main provider name + String providerName = param.getProviderName(); + if (providerName != null){ + if (param.getCertProviderName() == null){ + param.setCertProviderName(providerName); + } + if (param.getSigProviderName() == null){ + param.setSigProviderName(providerName); + } + if (param.getKsProviderName() == null){ + param.setKsProviderName(providerName); + } + } + + // if the store password is not given, prompt for it + if (param.getStorePass() == null) { + param.setStorePass(UserInteractor + .getDataFromUser("Enter keystore password: ")); + } + + if (param.getAlias() == null){ + // TODO + } + // if key password is not given, try to inplace it with store password + if (param.getKeyPass() == null){ + param.setKeyPass(tryStorePassAsKeyPass(param.getKeyStore(), param + .getAlias(), param.getStorePass())); + } + + return param; + } + + + // Method tries to get the key, associated with alias, using the storePass. + // If it can be recovered using the password, storePass is returned, + // otherwise - the password is prompted for. Another attempt to recover the + // key with entered password. If it is ok, it is returned, otherwise + // UnrecoverableKeyException is thrown. + private static char[] tryStorePassAsKeyPass(KeyStore keyStore, + String alias, char[] storePass) throws KeyStoreException, + IOException, UnrecoverableKeyException, NoSuchAlgorithmException { + try { + // try to get a key with keystore password + // if succeed set key password same as that for keystore + keyStore.getKey(alias, storePass); + + // will not come here if exception is thrown + return storePass; + } catch (UnrecoverableKeyException e) { + // if key password is not equal to store password, ask for it. + char[] keyPass = UserInteractor + .getDataFromUser("Enter key password for <" + alias + ">: "); + // if the new password is incorrect an exception will be thrown + try { + keyStore.getKey(alias, keyPass); + } catch (NoSuchAlgorithmException nsae) { + throw new NoSuchAlgorithmException( + "Cannot find the algorithm to recover the key. ", e); + } + return keyPass; + } catch (NoSuchAlgorithmException e) { + throw new NoSuchAlgorithmException( + "Cannot find the algorithm to recover the key. ", e); + } + } + + // method for adding providers to java.security.Security + static int addProvider(String provider) throws JarSignerException { + try { + return Security.addProvider(Class.forName(provider).asSubclass( + Provider.class).newInstance()); + } catch (Exception e) { + throw new JarSignerException("Failed to load the provider " + + provider, e); + } + } + +} + 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 0) +++ modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/FileNameGenerator.java (revision 0) @@ -0,0 +1,85 @@ +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as applicable + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.apache.harmony.tools.jarsigner; + +import java.util.Arrays; + +/** + * File to build the base file names for .SF and .DSA files. + */ +public class FileNameGenerator { + private static final int fileNameLength = 8; + + /** + * Generates the file name for .SF and .DSA files using + * param.getSigFileName() or alias given on the command line. + * If the alias + * + * @param param + * @return + */ + static String generateFileName(JSParameters param){ + if (param.getSigFileName() != null){ + return convertString(param.getSigFileName().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 = convertString(alias); + if (length == fileNameLength){ + return alias.toUpperCase(); + } else { + char[] remainder = new char[fileNameLength - length]; + Arrays.fill(remainder, '_'); + return alias + new String(remainder); + } + } + + // 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. + private static String convertString(String input){ + char [] chars = input.toCharArray(); + boolean isChanged = false; + for (int i = 0; i < chars.length; i++){ + char current = chars[i]; + if ((current >= 'A' && current<= 'Z') || + (current >= 'a' && current <= 'z') || + (current >= '0' && current <= '9') || + current == '-' || current == '_'){ + continue; + } + + isChanged = true; + chars[i] = '_'; + } + if (isChanged){ + return new String(chars); + } else { + return input; + } + } +} + Index: modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/JSVerifier.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/JSVerifier.java (revision 0) +++ modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/JSVerifier.java (revision 0) @@ -0,0 +1,25 @@ +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as applicable + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.apache.harmony.tools.jarsigner; + +/** + * Class to verify JAR files. + */ +public class JSVerifier { + // TODO +} + Index: modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/UserInteractor.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/UserInteractor.java (revision 0) +++ modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/UserInteractor.java (revision 0) @@ -0,0 +1,50 @@ +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as applicable + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.apache.harmony.tools.jarsigner; + +import java.io.IOException; +import java.io.InputStreamReader; + +/** + * Class to interact with user - ask for confirmations, and necessary parameters + * which haven't been set in the command line. + */ +public class UserInteractor { + // used to get additional data prompted + private static InputStreamReader in = new InputStreamReader(System.in); + + // buffer for the data read + private static char[] readData = new char[256]; + + // number of symbols read + private static int charsRead; + + // length of the "\r\n" which is added to the end of the line, + // when ENTER is pressed. + private static int newLineLength = 2; + + // Prints prompt and waits the user to enter the needed data, + // tha data is returned. + static char [] getDataFromUser(String prompt) throws IOException{ + System.out.print(prompt); + charsRead = in.read(readData); + char[] password = new char[charsRead - newLineLength]; + System.arraycopy(readData, 0, password, 0, charsRead - newLineLength); + return password; + } +} + Index: modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/TimeStampGenerator.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/TimeStampGenerator.java (revision 0) +++ modules/tools/src/main/java/org/apache/harmony/tools/jarsigner/TimeStampGenerator.java (revision 0) @@ -0,0 +1,25 @@ +/* + * Copyright 2006 The Apache Software Foundation or its licensors, as applicable + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.apache.harmony.tools.jarsigner; + +/** + * Class to generate time stamps. + */ +public class TimeStampGenerator { + // TODO +} +