This is an automated email from the git hooks/post-receive script. ebourg-guest pushed a commit to branch master in repository ca-certificates-java.
commit 2552e5c6e2ca6d8a03b2a48d7ed3f5087b5965c8 Author: Emmanuel Bourg <[email protected]> Date: Mon Mar 24 10:48:07 2014 +0000 Split Exceptions into distinct classes --- src/main/java/org/debian/security/Exceptions.java | 62 ---------------------- .../security/InvalidKeystorePasswordException.java | 31 +++++++++++ .../security/UnableToSaveKeystoreException.java | 30 +++++++++++ .../org/debian/security/UnknownInputException.java | 30 +++++++++++ .../org/debian/security/UpdateCertificates.java | 22 ++++---- .../debian/security/UpdateCertificatesTest.java | 38 +++++++------ 6 files changed, 120 insertions(+), 93 deletions(-) diff --git a/src/main/java/org/debian/security/Exceptions.java b/src/main/java/org/debian/security/Exceptions.java deleted file mode 100644 index 8474f92..0000000 --- a/src/main/java/org/debian/security/Exceptions.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2012 Damien Raude-Morvan <[email protected]> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -package org.debian.security; - -/** - * Custom exceptions used by {@link UpdateCertificates} - * - * @author Damien Raude-Morvan <[email protected]> - */ -public class Exceptions { - - /** - * Data send in stdin is invalid (neither "+" or "-" command). - */ - public static class UnknownInput extends Exception { - private static final long serialVersionUID = 5698253678856993527L; - - public UnknownInput(final String message) { - super(message); - } - } - - /** - * Unable to save keystore to provided location. - */ - public static class UnableToSaveKeystore extends Exception { - private static final long serialVersionUID = 3632154306237688490L; - - public UnableToSaveKeystore(final String message, final Exception e) { - super(message, e); - } - } - - /** - * Unable to open keystore from provided location (might be an invalid password - * or IO error). - */ - public static class InvalidKeystorePassword extends Exception { - private static final long serialVersionUID = 7004201816889107694L; - - public InvalidKeystorePassword(final String message, final Exception e) { - super(message, e); - } - } -} diff --git a/src/main/java/org/debian/security/InvalidKeystorePasswordException.java b/src/main/java/org/debian/security/InvalidKeystorePasswordException.java new file mode 100644 index 0000000..a6234a7 --- /dev/null +++ b/src/main/java/org/debian/security/InvalidKeystorePasswordException.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2012 Damien Raude-Morvan <[email protected]> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.debian.security; + +/** + * Unable to open keystore from provided location (might be an invalid password + * or IO error). + */ +public class InvalidKeystorePasswordException extends Exception { + private static final long serialVersionUID = 7004201816889107694L; + + public InvalidKeystorePasswordException(String message, Exception e) { + super(message, e); + } +} diff --git a/src/main/java/org/debian/security/UnableToSaveKeystoreException.java b/src/main/java/org/debian/security/UnableToSaveKeystoreException.java new file mode 100644 index 0000000..3dc95c0 --- /dev/null +++ b/src/main/java/org/debian/security/UnableToSaveKeystoreException.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2012 Damien Raude-Morvan <[email protected]> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.debian.security; + +/** + * Unable to save keystore to provided location. + */ +public class UnableToSaveKeystoreException extends Exception { + private static final long serialVersionUID = 3632154306237688490L; + + public UnableToSaveKeystoreException(String message, Exception e) { + super(message, e); + } +} diff --git a/src/main/java/org/debian/security/UnknownInputException.java b/src/main/java/org/debian/security/UnknownInputException.java new file mode 100644 index 0000000..03e6da0 --- /dev/null +++ b/src/main/java/org/debian/security/UnknownInputException.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2012 Damien Raude-Morvan <[email protected]> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.debian.security; + +/** + * Data send in stdin is invalid (neither "+" or "-" command). + */ +public class UnknownInputException extends Exception { + private static final long serialVersionUID = 5698253678856993527L; + + public UnknownInputException(String message) { + super(message); + } +} diff --git a/src/main/java/org/debian/security/UpdateCertificates.java b/src/main/java/org/debian/security/UpdateCertificates.java index 8f3a23a..495f37e 100644 --- a/src/main/java/org/debian/security/UpdateCertificates.java +++ b/src/main/java/org/debian/security/UpdateCertificates.java @@ -56,7 +56,7 @@ public class UpdateCertificates { if (args.length == 2 && args[0].equals("-storepass")) { passwordString = args[1]; } else if (args.length > 0) { - System.err.println("Usage: java UpdateCertificates [-storepass <password>]"); + System.err.println("Usage: java org.debian.security.UpdateCertificates [-storepass <password>]"); System.exit(1); } @@ -65,16 +65,16 @@ public class UpdateCertificates { // Force reading of inputstream in UTF-8 uc.processChanges(new InputStreamReader(System.in, "UTF8")); uc.writeKeyStore(); - } catch (Exceptions.InvalidKeystorePassword e) { + } catch (InvalidKeystorePasswordException e) { e.printStackTrace(System.err); System.exit(1); - } catch (Exceptions.UnableToSaveKeystore e) { + } catch (UnableToSaveKeystoreException e) { e.printStackTrace(System.err); System.exit(1); } } - public UpdateCertificates(final String passwordString, final String keystoreFile) throws IOException, GeneralSecurityException, Exceptions.InvalidKeystorePassword { + public UpdateCertificates(final String passwordString, final String keystoreFile) throws IOException, GeneralSecurityException, InvalidKeystorePasswordException { this.password = passwordString.toCharArray(); this.ksFilename = keystoreFile; this.ks = openKeyStore(); @@ -84,7 +84,7 @@ public class UpdateCertificates { /** * Try to open a existing keystore or create an new one. */ - private KeyStore openKeyStore() throws GeneralSecurityException, IOException, Exceptions.InvalidKeystorePassword { + private KeyStore openKeyStore() throws GeneralSecurityException, IOException, InvalidKeystorePasswordException { KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); File certInputFile = new File(this.ksFilename); FileInputStream certInputStream = null; @@ -94,7 +94,7 @@ public class UpdateCertificates { try { ks.load(certInputStream, this.password); } catch (IOException e) { - throw new Exceptions.InvalidKeystorePassword("Cannot open Java keystore. Is the password correct?", e); + throw new InvalidKeystorePasswordException("Cannot open Java keystore. Is the password correct?", e); } if (certInputStream != null) { certInputStream.close(); @@ -111,7 +111,7 @@ public class UpdateCertificates { while ((line = bufferedStdinReader.readLine()) != null) { try { parseLine(line); - } catch (Exceptions.UnknownInput e) { + } catch (UnknownInputException e) { System.err.println("Unknown input: " + line); // Keep processing for others lines } @@ -122,7 +122,7 @@ public class UpdateCertificates { * Parse given line to choose between {@link #addAlias(String, Certificate)} * or {@link #deleteAlias(String)}. */ - protected void parseLine(final String line) throws GeneralSecurityException, IOException, Exceptions.UnknownInput { + protected void parseLine(final String line) throws GeneralSecurityException, IOException, UnknownInputException { assert this.ks != null; String path = line.substring(1); @@ -140,7 +140,7 @@ public class UpdateCertificates { // removed after the release of Wheezy. deleteAlias(filename); } else { - throw new Exceptions.UnknownInput(line); + throw new UnknownInputException(line); } } @@ -201,7 +201,7 @@ public class UpdateCertificates { /** * Write actual keystore content to disk. */ - protected void writeKeyStore() throws GeneralSecurityException, Exceptions.UnableToSaveKeystore { + protected void writeKeyStore() throws GeneralSecurityException, UnableToSaveKeystoreException { assert this.ks != null; try { @@ -209,7 +209,7 @@ public class UpdateCertificates { this.ks.store(certOutputFile, this.password); certOutputFile.close(); } catch (IOException e) { - throw new Exceptions.UnableToSaveKeystore("There was a problem saving the new Java keystore.", e); + throw new UnableToSaveKeystoreException("There was a problem saving the new Java keystore.", e); } } } diff --git a/src/test/java/org/debian/security/UpdateCertificatesTest.java b/src/test/java/org/debian/security/UpdateCertificatesTest.java index 38dbc82..d80ce83 100644 --- a/src/test/java/org/debian/security/UpdateCertificatesTest.java +++ b/src/test/java/org/debian/security/UpdateCertificatesTest.java @@ -57,7 +57,7 @@ public class UpdateCertificatesTest { */ @Test public void testNoop() throws IOException, GeneralSecurityException, - Exceptions.InvalidKeystorePassword, Exceptions.UnableToSaveKeystore { + InvalidKeystorePasswordException, UnableToSaveKeystoreException { UpdateCertificates uc = new UpdateCertificates(this.ksPassword, this.ksFilename); uc.writeKeyStore(); @@ -70,12 +70,12 @@ public class UpdateCertificatesTest { */ @Test public void testWriteThenOpenWrongPwd() throws IOException, - GeneralSecurityException, Exceptions.UnableToSaveKeystore { + GeneralSecurityException, UnableToSaveKeystoreException { try { UpdateCertificates uc = new UpdateCertificates(this.ksPassword, this.ksFilename); uc.writeKeyStore(); - } catch (Exceptions.InvalidKeystorePassword e) { + } catch (InvalidKeystorePasswordException e) { Assert.fail(); } @@ -84,7 +84,7 @@ public class UpdateCertificatesTest { this.ksFilename); Assert.fail(); uc.writeKeyStore(); - } catch (Exceptions.InvalidKeystorePassword e) { + } catch (InvalidKeystorePasswordException e) { Assert.assertEquals( "Cannot open Java keystore. Is the password correct?", e.getMessage()); @@ -97,8 +97,7 @@ public class UpdateCertificatesTest { * will throw an UnableToSaveKeystore */ @Test - public void testDeleteThenWrite() throws IOException, - GeneralSecurityException, Exceptions.InvalidKeystorePassword { + public void testDeleteThenWrite() throws IOException, GeneralSecurityException, InvalidKeystorePasswordException { try { UpdateCertificates uc = new UpdateCertificates(this.ksPassword, this.ksFilename); @@ -111,7 +110,7 @@ public class UpdateCertificatesTest { // Will fail with some IOException uc.writeKeyStore(); Assert.fail(); - } catch (Exceptions.UnableToSaveKeystore e) { + } catch (UnableToSaveKeystoreException e) { Assert.assertEquals( "There was a problem saving the new Java keystore.", e.getMessage()); @@ -122,14 +121,13 @@ public class UpdateCertificatesTest { * Try to send an invalid command ("x") in parseLine : throw UnknownInput */ @Test - public void testWrongCommand() throws IOException, - GeneralSecurityException, Exceptions.InvalidKeystorePassword { + public void testWrongCommand() throws IOException, GeneralSecurityException, InvalidKeystorePasswordException { UpdateCertificates uc = new UpdateCertificates(this.ksPassword, this.ksFilename); try { uc.parseLine(INVALID_CACERT); Assert.fail(); - } catch (Exceptions.UnknownInput e) { + } catch (UnknownInputException e) { Assert.assertEquals(INVALID_CACERT, e.getMessage()); } } @@ -139,8 +137,8 @@ public class UpdateCertificatesTest { */ @Test public void testAdd() throws IOException, GeneralSecurityException, - Exceptions.UnknownInput, Exceptions.InvalidKeystorePassword, - Exceptions.UnableToSaveKeystore { + UnknownInputException, InvalidKeystorePasswordException, + UnableToSaveKeystoreException { UpdateCertificates uc = new UpdateCertificates(this.ksPassword, this.ksFilename); uc.parseLine(ADD_CACERT); @@ -155,8 +153,8 @@ public class UpdateCertificatesTest { */ @Test public void testAddInvalidCert() throws IOException, - GeneralSecurityException, Exceptions.UnknownInput, - Exceptions.InvalidKeystorePassword, Exceptions.UnableToSaveKeystore { + GeneralSecurityException, UnknownInputException, + InvalidKeystorePasswordException, UnableToSaveKeystoreException { UpdateCertificates uc = new UpdateCertificates(this.ksPassword, this.ksFilename); uc.parseLine("+/usr/share/ca-certificates/null.crt"); @@ -171,8 +169,8 @@ public class UpdateCertificatesTest { */ @Test public void testReplace() throws IOException, GeneralSecurityException, - Exceptions.UnknownInput, Exceptions.InvalidKeystorePassword, - Exceptions.UnableToSaveKeystore { + UnknownInputException, InvalidKeystorePasswordException, + UnableToSaveKeystoreException { UpdateCertificates uc = new UpdateCertificates(this.ksPassword, this.ksFilename); uc.parseLine(ADD_CACERT); @@ -187,8 +185,8 @@ public class UpdateCertificatesTest { */ @Test public void testRemove() throws IOException, GeneralSecurityException, - Exceptions.UnknownInput, Exceptions.InvalidKeystorePassword, - Exceptions.UnableToSaveKeystore { + UnknownInputException, InvalidKeystorePasswordException, + UnableToSaveKeystoreException { UpdateCertificates uc = new UpdateCertificates(this.ksPassword, this.ksFilename); uc.parseLine(REMOVE_CACERT); @@ -203,8 +201,8 @@ public class UpdateCertificatesTest { */ @Test public void testAddThenRemove() throws IOException, - GeneralSecurityException, Exceptions.UnknownInput, - Exceptions.InvalidKeystorePassword, Exceptions.UnableToSaveKeystore { + GeneralSecurityException, UnknownInputException, + InvalidKeystorePasswordException, UnableToSaveKeystoreException { UpdateCertificates ucAdd = new UpdateCertificates(this.ksPassword, this.ksFilename); ucAdd.parseLine(ADD_CACERT); -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/ca-certificates-java.git _______________________________________________ pkg-java-commits mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-java-commits

