diff options
Diffstat (limited to 'gnu/java/security')
81 files changed, 712 insertions, 619 deletions
diff --git a/gnu/java/security/Engine.java b/gnu/java/security/Engine.java index 969fcef6c..8313631be 100644 --- a/gnu/java/security/Engine.java +++ b/gnu/java/security/Engine.java @@ -1,5 +1,5 @@ /* Engine -- generic getInstance method. - Copyright (C) 2003, 2006 Free Software Foundation, Inc. + Copyright (C) 2003, 2006, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -147,7 +147,7 @@ public final class Engine if (initArgs == null) throw new IllegalArgumentException("Constructor's parameters MUST NOT be null"); - Enumeration enumer = provider.propertyNames(); + Enumeration<?> enumer = provider.propertyNames(); String key = null; String alias; int count = 0; @@ -192,9 +192,9 @@ public final class Engine } // Find and instantiate the implementation - Class clazz = null; + Class<?> clazz = null; ClassLoader loader = provider.getClass().getClassLoader(); - Constructor constructor = null; + Constructor<?> constructor = null; String className = provider.getProperty(key); sb.append("Class [").append(className).append("] for algorithm [") .append(algorithm).append("] of type [").append(service) @@ -255,14 +255,14 @@ public final class Engine * @throws NoSuchMethodException If no constructor of the given class * can take the specified argument array. */ - private static Constructor getCompatibleConstructor(Class clazz, - Object[] initArgs) + private static Constructor<?> getCompatibleConstructor(Class<?> clazz, + Object[] initArgs) throws NoSuchMethodException { - Constructor[] c = clazz.getConstructors(); + Constructor<?>[] c = clazz.getConstructors(); outer:for (int i = 0; i < c.length; i++) { - Class[] argTypes = c[i].getParameterTypes(); + Class<?>[] argTypes = c[i].getParameterTypes(); if (argTypes.length != initArgs.length) continue; for (int j = 0; j < argTypes.length; j++) diff --git a/gnu/java/security/OID.java b/gnu/java/security/OID.java index c7efe6557..c6b977e00 100644 --- a/gnu/java/security/OID.java +++ b/gnu/java/security/OID.java @@ -1,5 +1,5 @@ /* OID.java -- numeric representation of an object identifier - Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 2003, 2004, 2005, 2006, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -67,7 +67,7 @@ import java.util.StringTokenizer; * * @author Casey Marshall (csm@gnu.org) */ -public class OID implements Cloneable, Comparable, java.io.Serializable +public class OID implements Cloneable, Comparable<OID>, java.io.Serializable { // Fields. @@ -410,11 +410,11 @@ public class OID implements Cloneable, Comparable, java.io.Serializable * argument. * @throws ClassCastException If <i>o</i> is not an OID. */ - public int compareTo(Object o) + public int compareTo(OID o) { if (equals(o)) return 0; - int[] components2 = ((OID) o).components; + int[] components2 = o.components; int len = Math.min(components.length, components2.length); for (int i = 0; i < len; i++) { diff --git a/gnu/java/security/Properties.java b/gnu/java/security/Properties.java index 1a4bf2276..7a664fc74 100644 --- a/gnu/java/security/Properties.java +++ b/gnu/java/security/Properties.java @@ -1,5 +1,5 @@ /* Properties.java -- run-time configuration properties. - Copyright (C) 2003, 2004, 2006, 2010 Free Software Foundation, Inc. + Copyright (C) 2003, 2004, 2006, 2010, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -71,7 +71,8 @@ public final class Properties private static final String FALSE = Boolean.FALSE.toString(); - private static final HashMap props = new HashMap(); + private static final HashMap<String,String> props = + new HashMap<String,String>(); private static Properties singleton = null; @@ -108,7 +109,7 @@ public final class Properties key = key.trim().toLowerCase(); if ("".equals(key)) return null; - return (String) props.get(key); + return props.get(key); } /** @@ -269,9 +270,10 @@ public final class Properties String propFile = null; try { - propFile = (String) AccessController.doPrivileged(new PrivilegedAction() + propFile = AccessController.doPrivileged(new PrivilegedAction<String>() { - public Object run() + @Override + public String run() { return System.getProperty(PROPERTIES_FILE); } @@ -290,7 +292,8 @@ public final class Properties final FileInputStream fin = new FileInputStream(propFile); temp.load(fin); temp.list(System.out); - props.putAll(temp); + for (String key : temp.stringPropertyNames()) + props.put(key, temp.getProperty(key)); } catch (IOException ioe) { diff --git a/gnu/java/security/action/SetAccessibleAction.java b/gnu/java/security/action/SetAccessibleAction.java index d3e3c0f90..e1f58ae71 100644 --- a/gnu/java/security/action/SetAccessibleAction.java +++ b/gnu/java/security/action/SetAccessibleAction.java @@ -1,5 +1,5 @@ /* SetAccessibleAction.java - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -50,7 +50,7 @@ import java.security.PrivilegedAction; * AccessController.doPrivileged(new SetAccessibleAction(dataField)); * </code> */ -public class SetAccessibleAction implements PrivilegedAction +public class SetAccessibleAction implements PrivilegedAction<AccessibleObject> { AccessibleObject member; @@ -63,7 +63,8 @@ public class SetAccessibleAction implements PrivilegedAction this.member = member; } - public Object run() + @Override + public AccessibleObject run() { member.setAccessible(true); return null; diff --git a/gnu/java/security/ber/BEREncodingException.java b/gnu/java/security/ber/BEREncodingException.java index aad10932c..0b2f494f1 100644 --- a/gnu/java/security/ber/BEREncodingException.java +++ b/gnu/java/security/ber/BEREncodingException.java @@ -1,5 +1,5 @@ /* BEREncodingException.java --- BER Encoding Exception - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -42,6 +42,8 @@ import gnu.java.security.der.DEREncodingException; public class BEREncodingException extends DEREncodingException { + private static final long serialVersionUID = 5155616917834322362L; + public BEREncodingException() { super (); diff --git a/gnu/java/security/der/BitString.java b/gnu/java/security/der/BitString.java index ac10be22e..c7032ccfc 100644 --- a/gnu/java/security/der/BitString.java +++ b/gnu/java/security/der/BitString.java @@ -1,5 +1,5 @@ /* BitString.java -- Java representation of the BIT STRING type. - Copyright (C) 2003 Free Software Foundation, Inc. + Copyright (C) 2003, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -55,7 +55,7 @@ import java.util.Arrays; * * @author Casey Marshall (csm@gnu.org) */ -public class BitString implements Cloneable, Comparable +public class BitString implements Cloneable, Comparable<BitString> { // Fields. @@ -273,9 +273,9 @@ public class BitString implements Cloneable, Comparable } } - public int compareTo(Object o) + @Override + public int compareTo(BitString that) { - BitString that = (BitString) o; if (this.equals(that)) return 0; if (this.bytes.length != that.bytes.length) diff --git a/gnu/java/security/der/DEREncodingException.java b/gnu/java/security/der/DEREncodingException.java index 90042a3fc..de3b44426 100644 --- a/gnu/java/security/der/DEREncodingException.java +++ b/gnu/java/security/der/DEREncodingException.java @@ -1,5 +1,5 @@ /* DEREncodingException.java --- DER Encoding Exception - Copyright (C) 1999,2003 Free Software Foundation, Inc. + Copyright (C) 1999,2003,2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -42,6 +42,8 @@ import java.io.IOException; public class DEREncodingException extends IOException { + private static final long serialVersionUID = 5763366374058841017L; + public DEREncodingException() { super (); diff --git a/gnu/java/security/der/DERWriter.java b/gnu/java/security/der/DERWriter.java index cea3fa31d..6f3b1b486 100644 --- a/gnu/java/security/der/DERWriter.java +++ b/gnu/java/security/der/DERWriter.java @@ -1,5 +1,5 @@ /* DERWriter.java -- write Java types in DER format. - Copyright (C) 2003, 2004, 2005, 2010 Free Software Foundation, Inc. + Copyright (C) 2003, 2004, 2005, 2010, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -106,9 +106,17 @@ public class DERWriter implements DER else if (value instanceof String) return writeString(out, object.getExternalTag(), (String) value); else if (value instanceof List) - return writeSequence(out, (List) value); + { + @SuppressWarnings("unchecked") + List<DERValue> dvList = (List<DERValue>) value; + return writeSequence(out, dvList); + } else if (value instanceof Set) - return writeSet(out, (Set) value); + { + @SuppressWarnings("unchecked") + Set<DERValue> dvSet = (Set<DERValue>) value; + return writeSet(out, dvSet); + } else if (value instanceof BitString) return writeBitString(out, (BitString) value); else if (value instanceof OID) @@ -181,13 +189,13 @@ public class DERWriter implements DER return bytes.length; } - private static int writeSequence(OutputStream out, List sequence) + private static int writeSequence(OutputStream out, List<DERValue> sequence) throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); - for (Iterator i = sequence.iterator(); i.hasNext(); ) + for (Iterator<DERValue> i = sequence.iterator(); i.hasNext(); ) { - write(bout, (DERValue) i.next()); + write(bout, i.next()); } byte[] buf = bout.toByteArray(); writeLength(out, buf.length); @@ -195,13 +203,13 @@ public class DERWriter implements DER return buf.length; } - private static int writeSet(OutputStream out, Set set) + private static int writeSet(OutputStream out, Set<DERValue> set) throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); - for (Iterator i = set.iterator(); i.hasNext(); ) + for (Iterator<DERValue> i = set.iterator(); i.hasNext(); ) { - write(bout, (DERValue) i.next()); + write(bout, i.next()); } byte[] buf = bout.toByteArray(); writeLength(out, buf.length); diff --git a/gnu/java/security/hash/HashFactory.java b/gnu/java/security/hash/HashFactory.java index 1210ff4db..688afc4c9 100644 --- a/gnu/java/security/hash/HashFactory.java +++ b/gnu/java/security/hash/HashFactory.java @@ -1,5 +1,5 @@ /* HashFactory.java -- - Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc. + Copyright (C) 2001, 2002, 2003, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -114,9 +114,9 @@ public class HashFactory * * @return a {@link Set} of hash names (Strings). */ - public static final Set getNames() + public static final Set<String> getNames() { - HashSet hs = new HashSet(); + HashSet<String> hs = new HashSet<String>(); hs.add(Registry.WHIRLPOOL_HASH); hs.add(Registry.RIPEMD128_HASH); hs.add(Registry.RIPEMD160_HASH); diff --git a/gnu/java/security/hash/Whirlpool.java b/gnu/java/security/hash/Whirlpool.java index 29eed59ba..bb1174e2e 100644 --- a/gnu/java/security/hash/Whirlpool.java +++ b/gnu/java/security/hash/Whirlpool.java @@ -1,5 +1,5 @@ /* Whirlpool.java -- - Copyright (C) 2001, 2002, 2006, 2010 Free Software Foundation, Inc. + Copyright (C) 2001, 2002, 2006, 2010, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -136,7 +136,6 @@ public final class Whirlpool int i, r, j; long s1, s2, s4, s5, s8, s9, t; char c; - final byte[] S = new byte[256]; for (i = 0; i < 256; i++) { c = S_box.charAt(i >>> 1); diff --git a/gnu/java/security/jce/prng/HavalRandomSpi.java b/gnu/java/security/jce/prng/HavalRandomSpi.java index ebf80f2d7..bce621cc9 100644 --- a/gnu/java/security/jce/prng/HavalRandomSpi.java +++ b/gnu/java/security/jce/prng/HavalRandomSpi.java @@ -1,5 +1,5 @@ /* HavalRandomSpi.java -- - Copyright (C) 2003, 2006 Free Software Foundation, Inc. + Copyright (C) 2003, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -47,6 +47,8 @@ import gnu.java.security.Registry; public class HavalRandomSpi extends SecureRandomAdapter { + private static final long serialVersionUID = -8063732691196112589L; + public HavalRandomSpi() { super(Registry.HAVAL_HASH); diff --git a/gnu/java/security/jce/prng/MD2RandomSpi.java b/gnu/java/security/jce/prng/MD2RandomSpi.java index 8b9abe4e9..96c6ef06d 100644 --- a/gnu/java/security/jce/prng/MD2RandomSpi.java +++ b/gnu/java/security/jce/prng/MD2RandomSpi.java @@ -1,5 +1,5 @@ /* MD2RandomSpi.java -- - Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2001, 2002, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -47,6 +47,8 @@ import gnu.java.security.Registry; public class MD2RandomSpi extends SecureRandomAdapter { + private static final long serialVersionUID = -4057743457589764490L; + public MD2RandomSpi() { super(Registry.MD2_HASH); diff --git a/gnu/java/security/jce/prng/MD4RandomSpi.java b/gnu/java/security/jce/prng/MD4RandomSpi.java index 2a71d6a0d..986905c0a 100644 --- a/gnu/java/security/jce/prng/MD4RandomSpi.java +++ b/gnu/java/security/jce/prng/MD4RandomSpi.java @@ -1,5 +1,5 @@ /* MD4RandomSpi.java -- - Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2001, 2002, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -47,6 +47,8 @@ import gnu.java.security.Registry; public class MD4RandomSpi extends SecureRandomAdapter { + private static final long serialVersionUID = -2812563232122795714L; + public MD4RandomSpi() { super(Registry.MD4_HASH); diff --git a/gnu/java/security/jce/prng/MD5RandomSpi.java b/gnu/java/security/jce/prng/MD5RandomSpi.java index 8fb50e16f..655e795e7 100644 --- a/gnu/java/security/jce/prng/MD5RandomSpi.java +++ b/gnu/java/security/jce/prng/MD5RandomSpi.java @@ -1,5 +1,5 @@ /* MD5RandomSpi.java -- - Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2001, 2002, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -47,6 +47,8 @@ import gnu.java.security.Registry; public class MD5RandomSpi extends SecureRandomAdapter { + private static final long serialVersionUID = -8922813416432084255L; + public MD5RandomSpi() { super(Registry.MD5_HASH); diff --git a/gnu/java/security/jce/prng/RipeMD128RandomSpi.java b/gnu/java/security/jce/prng/RipeMD128RandomSpi.java index 6f8dde0e0..0657ef5b8 100644 --- a/gnu/java/security/jce/prng/RipeMD128RandomSpi.java +++ b/gnu/java/security/jce/prng/RipeMD128RandomSpi.java @@ -1,5 +1,5 @@ /* RipeMD128RandomSpi.java -- - Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2001, 2002, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -47,6 +47,8 @@ import gnu.java.security.Registry; public class RipeMD128RandomSpi extends SecureRandomAdapter { + private static final long serialVersionUID = -5746104868781660155L; + public RipeMD128RandomSpi() { super(Registry.RIPEMD128_HASH); diff --git a/gnu/java/security/jce/prng/RipeMD160RandomSpi.java b/gnu/java/security/jce/prng/RipeMD160RandomSpi.java index 6bb4e2b50..3e64dcf71 100644 --- a/gnu/java/security/jce/prng/RipeMD160RandomSpi.java +++ b/gnu/java/security/jce/prng/RipeMD160RandomSpi.java @@ -1,5 +1,5 @@ /* RipeMD160RandomSpi.java -- - Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2001, 2002, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -47,6 +47,8 @@ import gnu.java.security.Registry; public class RipeMD160RandomSpi extends SecureRandomAdapter { + private static final long serialVersionUID = -1826833146069540489L; + public RipeMD160RandomSpi() { super(Registry.RIPEMD160_HASH); diff --git a/gnu/java/security/jce/prng/SecureRandomAdapter.java b/gnu/java/security/jce/prng/SecureRandomAdapter.java index 9307cfa7f..0d5b060ed 100644 --- a/gnu/java/security/jce/prng/SecureRandomAdapter.java +++ b/gnu/java/security/jce/prng/SecureRandomAdapter.java @@ -1,5 +1,5 @@ /* SecureRandomAdapter.java -- - Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc. + Copyright (C) 2001, 2002, 2003, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -71,15 +71,13 @@ import java.net.URL; public abstract class SecureRandomAdapter extends SecureRandomSpi { + private static final long serialVersionUID = 999603727925481878L; private boolean isSeeded = false; /** Our underlying prng instance. */ private MDGenerator adaptee = new MDGenerator(); - /** The name of the message digest algorithm used by the adaptee. */ - private String mdName; - private static final Logger logger = Logger.getLogger(SecureRandom.class.getName()); @@ -95,8 +93,7 @@ public abstract class SecureRandomAdapter { super(); - this.mdName = mdName; - adaptee.init (Collections.singletonMap (MDGenerator.MD_NAME, mdName)); + adaptee.init (Collections.singletonMap (MDGenerator.MD_NAME, (Object) mdName)); } public static final byte[] getSeed(int numBytes) @@ -110,7 +107,7 @@ public abstract class SecureRandomAdapter new GetSecurityPropertyAction(SECURERANDOM_SOURCE); try { - urlStr = (String) AccessController.doPrivileged(action); + urlStr = AccessController.doPrivileged(action); if (urlStr != null) sourceUrl = new URL(urlStr); } @@ -156,11 +153,13 @@ public abstract class SecureRandomAdapter return buffer; } + @Override public byte[] engineGenerateSeed(int numBytes) { return getSeed(numBytes); } + @Override public void engineNextBytes(byte[] bytes) { if (!isSeeded) @@ -176,6 +175,7 @@ public abstract class SecureRandomAdapter } } + @Override public void engineSetSeed(byte[] seed) { adaptee.addRandomBytes (seed); diff --git a/gnu/java/security/jce/prng/Sha160RandomSpi.java b/gnu/java/security/jce/prng/Sha160RandomSpi.java index ba4d22265..674a7095f 100644 --- a/gnu/java/security/jce/prng/Sha160RandomSpi.java +++ b/gnu/java/security/jce/prng/Sha160RandomSpi.java @@ -1,5 +1,5 @@ /* Sha160RandomSpi.java -- - Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2001, 2002, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -47,6 +47,8 @@ import gnu.java.security.Registry; public class Sha160RandomSpi extends SecureRandomAdapter { + private static final long serialVersionUID = -225998056826896890L; + public Sha160RandomSpi() { super(Registry.SHA160_HASH); diff --git a/gnu/java/security/jce/prng/Sha256RandomSpi.java b/gnu/java/security/jce/prng/Sha256RandomSpi.java index a6ddb70af..0c8bd6916 100644 --- a/gnu/java/security/jce/prng/Sha256RandomSpi.java +++ b/gnu/java/security/jce/prng/Sha256RandomSpi.java @@ -1,5 +1,5 @@ /* Sha256RandomSpi.java -- - Copyright (C) 2003, 2006 Free Software Foundation, Inc. + Copyright (C) 2003, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -47,6 +47,8 @@ import gnu.java.security.Registry; public class Sha256RandomSpi extends SecureRandomAdapter { + private static final long serialVersionUID = -8748894083942397288L; + public Sha256RandomSpi() { super(Registry.SHA256_HASH); diff --git a/gnu/java/security/jce/prng/Sha384RandomSpi.java b/gnu/java/security/jce/prng/Sha384RandomSpi.java index 4954b1be7..e13d875ff 100644 --- a/gnu/java/security/jce/prng/Sha384RandomSpi.java +++ b/gnu/java/security/jce/prng/Sha384RandomSpi.java @@ -1,5 +1,5 @@ /* Sha384RandomSpi.java -- - Copyright (C) 2003, 2006 Free Software Foundation, Inc. + Copyright (C) 2003, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -47,6 +47,8 @@ import gnu.java.security.Registry; public class Sha384RandomSpi extends SecureRandomAdapter { + private static final long serialVersionUID = -5865689279889026842L; + public Sha384RandomSpi() { super(Registry.SHA384_HASH); diff --git a/gnu/java/security/jce/prng/Sha512RandomSpi.java b/gnu/java/security/jce/prng/Sha512RandomSpi.java index 27de7f319..8e9d378d4 100644 --- a/gnu/java/security/jce/prng/Sha512RandomSpi.java +++ b/gnu/java/security/jce/prng/Sha512RandomSpi.java @@ -1,5 +1,5 @@ /* Sha512RandomSpi.java -- - Copyright (C) 2003, 2006 Free Software Foundation, Inc. + Copyright (C) 2003, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -47,6 +47,8 @@ import gnu.java.security.Registry; public class Sha512RandomSpi extends SecureRandomAdapter { + private static final long serialVersionUID = 3471561597377786188L; + public Sha512RandomSpi() { super(Registry.SHA512_HASH); diff --git a/gnu/java/security/jce/prng/TigerRandomSpi.java b/gnu/java/security/jce/prng/TigerRandomSpi.java index 722ab3279..e6daac297 100644 --- a/gnu/java/security/jce/prng/TigerRandomSpi.java +++ b/gnu/java/security/jce/prng/TigerRandomSpi.java @@ -1,5 +1,5 @@ /* TigerRandomSpi.java -- - Copyright (C) 2003, 2006 Free Software Foundation, Inc. + Copyright (C) 2003, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -47,6 +47,8 @@ import gnu.java.security.Registry; public class TigerRandomSpi extends SecureRandomAdapter { + private static final long serialVersionUID = -4562391018186836733L; + public TigerRandomSpi() { super(Registry.TIGER_HASH); diff --git a/gnu/java/security/jce/prng/WhirlpoolRandomSpi.java b/gnu/java/security/jce/prng/WhirlpoolRandomSpi.java index 5da43d77e..1e423d712 100644 --- a/gnu/java/security/jce/prng/WhirlpoolRandomSpi.java +++ b/gnu/java/security/jce/prng/WhirlpoolRandomSpi.java @@ -1,5 +1,5 @@ /* WhirlpoolRandomSpi.java -- - Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2001, 2002, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -47,6 +47,8 @@ import gnu.java.security.Registry; public class WhirlpoolRandomSpi extends SecureRandomAdapter { + private static final long serialVersionUID = -3118094409789615934L; + public WhirlpoolRandomSpi() { super(Registry.WHIRLPOOL_HASH); diff --git a/gnu/java/security/jce/sig/DSSKeyFactory.java b/gnu/java/security/jce/sig/DSSKeyFactory.java index ec993432c..d52f09948 100644 --- a/gnu/java/security/jce/sig/DSSKeyFactory.java +++ b/gnu/java/security/jce/sig/DSSKeyFactory.java @@ -1,5 +1,5 @@ /* DSSKeyFactory.java -- JCE DSA key factory Adapter - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -69,6 +69,7 @@ public class DSSKeyFactory { // implicit 0-arguments constructor + @Override protected PublicKey engineGeneratePublic(KeySpec keySpec) throws InvalidKeySpecException { @@ -99,6 +100,7 @@ public class DSSKeyFactory throw new InvalidKeySpecException("Unsupported (public) key specification"); } + @Override protected PrivateKey engineGeneratePrivate(KeySpec keySpec) throws InvalidKeySpecException { @@ -129,7 +131,8 @@ public class DSSKeyFactory throw new InvalidKeySpecException("Unsupported (private) key specification"); } - protected KeySpec engineGetKeySpec(Key key, Class keySpec) + @Override + protected <T extends KeySpec> T engineGetKeySpec(Key key, Class<T> keySpec) throws InvalidKeySpecException { if (key instanceof DSAPublicKey) @@ -141,7 +144,7 @@ public class DSSKeyFactory BigInteger q = dsaKey.getParams().getQ(); BigInteger g = dsaKey.getParams().getG(); BigInteger y = dsaKey.getY(); - return new DSAPublicKeySpec(y, p, q, g); + return keySpec.cast(new DSAPublicKeySpec(y, p, q, g)); } if (keySpec.isAssignableFrom(X509EncodedKeySpec.class)) { @@ -149,12 +152,12 @@ public class DSSKeyFactory { DSSPublicKey dssKey = (DSSPublicKey) key; byte[] encoded = dssKey.getEncoded(Registry.X509_ENCODING_ID); - return new X509EncodedKeySpec(encoded); + return keySpec.cast(new X509EncodedKeySpec(encoded)); } if (Registry.X509_ENCODING_SORT_NAME.equalsIgnoreCase(key.getFormat())) { byte[] encoded = key.getEncoded(); - return new X509EncodedKeySpec(encoded); + return keySpec.cast(new X509EncodedKeySpec(encoded)); } throw new InvalidKeySpecException( "Wrong key type or unsupported (public) key specification"); @@ -170,7 +173,7 @@ public class DSSKeyFactory BigInteger q = dsaKey.getParams().getQ(); BigInteger g = dsaKey.getParams().getG(); BigInteger x = dsaKey.getX(); - return new DSAPrivateKeySpec(x, p, q, g); + return keySpec.cast(new DSAPrivateKeySpec(x, p, q, g)); } if (keySpec.isAssignableFrom(PKCS8EncodedKeySpec.class)) { @@ -178,12 +181,12 @@ public class DSSKeyFactory { DSSPrivateKey dssKey = (DSSPrivateKey) key; byte[] encoded = dssKey.getEncoded(Registry.PKCS8_ENCODING_ID); - return new PKCS8EncodedKeySpec(encoded); + return keySpec.cast(new PKCS8EncodedKeySpec(encoded)); } if (Registry.PKCS8_ENCODING_SHORT_NAME.equalsIgnoreCase(key.getFormat())) { byte[] encoded = key.getEncoded(); - return new PKCS8EncodedKeySpec(encoded); + return keySpec.cast(new PKCS8EncodedKeySpec(encoded)); } throw new InvalidKeySpecException( "Wrong key type or unsupported (private) key specification"); @@ -193,6 +196,7 @@ public class DSSKeyFactory throw new InvalidKeySpecException("Wrong key type or unsupported key specification"); } + @Override protected Key engineTranslateKey(Key key) throws InvalidKeyException { if ((key instanceof DSSPublicKey) || (key instanceof DSSPrivateKey)) diff --git a/gnu/java/security/jce/sig/DSSKeyPairGeneratorSpi.java b/gnu/java/security/jce/sig/DSSKeyPairGeneratorSpi.java index 2d33e1621..971cffe92 100644 --- a/gnu/java/security/jce/sig/DSSKeyPairGeneratorSpi.java +++ b/gnu/java/security/jce/sig/DSSKeyPairGeneratorSpi.java @@ -1,5 +1,5 @@ /* DSSKeyPairGeneratorSpi.java -- - Copyright 2001, 2002, 2006 Free Software Foundation, Inc. + Copyright 2001, 2002, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -75,7 +75,7 @@ public class DSSKeyPairGeneratorSpi public void initialize(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException { - HashMap attributes = new HashMap(); + HashMap<String,Object> attributes = new HashMap<String,Object>(); if (params != null) { if (! (params instanceof DSAParameterSpec)) @@ -99,6 +99,7 @@ public class DSSKeyPairGeneratorSpi } } + @Override public void initialize(DSAParams params, SecureRandom random) throws InvalidParameterException { @@ -119,10 +120,11 @@ public class DSSKeyPairGeneratorSpi } } + @Override public void initialize(int modlen, boolean genParams, SecureRandom random) throws InvalidParameterException { - HashMap attributes = new HashMap(); + HashMap<String,Object> attributes = new HashMap<String,Object>(); attributes.put(DSSKeyPairGenerator.MODULUS_LENGTH, Integer.valueOf(modlen)); if (random != null) attributes.put(DSSKeyPairGenerator.SOURCE_OF_RANDOMNESS, random); diff --git a/gnu/java/security/jce/sig/DSSParameters.java b/gnu/java/security/jce/sig/DSSParameters.java index fbf778dae..775ab1a66 100644 --- a/gnu/java/security/jce/sig/DSSParameters.java +++ b/gnu/java/security/jce/sig/DSSParameters.java @@ -1,5 +1,5 @@ /* DSSParameters.java -- DSS parameters DAO - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -85,6 +85,7 @@ public class DSSParameters // default 0-arguments constructor + @Override protected void engineInit(AlgorithmParameterSpec spec) throws InvalidParameterSpecException { @@ -109,6 +110,7 @@ public class DSSParameters * } * </pre> */ + @Override protected void engineInit(byte[] params) throws IOException { DERReader der = new DERReader(params); @@ -127,6 +129,7 @@ public class DSSParameters g = (BigInteger) val.getValue(); } + @Override protected void engineInit(byte[] params, String format) throws IOException { if (format != null) @@ -141,13 +144,14 @@ public class DSSParameters engineInit(params); } - protected AlgorithmParameterSpec engineGetParameterSpec(Class paramSpec) + @Override + protected <T extends AlgorithmParameterSpec> T engineGetParameterSpec(Class<T> paramSpec) throws InvalidParameterSpecException { if (! paramSpec.isAssignableFrom(DSAParameterSpec.class)) throw new InvalidParameterSpecException("Wrong AlgorithmParameterSpec type: " + paramSpec.getName()); - return new DSAParameterSpec(p, q, g); + return paramSpec.cast(new DSAParameterSpec(p, q, g)); } /** @@ -162,13 +166,14 @@ public class DSSParameters * } * </pre> */ + @Override protected byte[] engineGetEncoded() throws IOException { DERValue derP = new DERValue(DER.INTEGER, p); DERValue derQ = new DERValue(DER.INTEGER, q); DERValue derG = new DERValue(DER.INTEGER, g); - ArrayList params = new ArrayList(3); + ArrayList<DERValue> params = new ArrayList<DERValue>(3); params.add(derP); params.add(derQ); params.add(derG); @@ -181,6 +186,7 @@ public class DSSParameters return result; } + @Override protected byte[] engineGetEncoded(String format) throws IOException { if (format != null) @@ -195,6 +201,7 @@ public class DSSParameters return engineGetEncoded(); } + @Override protected String engineToString() { CPStringBuilder sb = new CPStringBuilder("p="); diff --git a/gnu/java/security/jce/sig/EncodedKeyFactory.java b/gnu/java/security/jce/sig/EncodedKeyFactory.java index ec7420138..df8bb14b1 100644 --- a/gnu/java/security/jce/sig/EncodedKeyFactory.java +++ b/gnu/java/security/jce/sig/EncodedKeyFactory.java @@ -1,5 +1,5 @@ /* EncodedKeyFactory.java -- JCE Encoded key factory Adapter - Copyright (C) 2006, 2010 Free Software Foundation, Inc. + Copyright (C) 2006, 2010, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -84,10 +84,10 @@ public class EncodedKeyFactory private static Object invokeConstructor(String className, Object[] params) throws InvalidKeySpecException { - Class clazz = getConcreteClass(className); + Class<?> clazz = getConcreteClass(className); try { - Constructor ctor = getConcreteCtor(clazz); + Constructor<?> ctor = getConcreteCtor(clazz); Object result = ctor.newInstance(params); return result; } @@ -105,12 +105,12 @@ public class EncodedKeyFactory } } - private static Class getConcreteClass(String className) + private static Class<?> getConcreteClass(String className) throws InvalidKeySpecException { try { - Class result = Class.forName(className); + Class<?> result = Class.forName(className); return result; } catch (ClassNotFoundException x) @@ -119,12 +119,12 @@ public class EncodedKeyFactory } } - private static Constructor getConcreteCtor(Class clazz) + private static Constructor<?> getConcreteCtor(Class<?> clazz) throws InvalidKeySpecException { try { - Constructor result = clazz.getConstructor(new Class[] {int.class, + Constructor<?> result = clazz.getConstructor(new Class[] {int.class, BigInteger.class, BigInteger.class, BigInteger.class, @@ -140,7 +140,7 @@ public class EncodedKeyFactory private static Object invokeValueOf(String className, byte[] encoded) throws InvalidKeySpecException { - Class clazz = getConcreteClass(className); + Class<?> clazz = getConcreteClass(className); try { Method valueOf = getValueOfMethod(clazz); @@ -157,7 +157,7 @@ public class EncodedKeyFactory } } - private static Method getValueOfMethod(Class clazz) + private static Method getValueOfMethod(Class<?> clazz) throws InvalidKeySpecException { try @@ -171,6 +171,7 @@ public class EncodedKeyFactory } } + @Override protected PublicKey engineGeneratePublic(KeySpec keySpec) throws InvalidKeySpecException { @@ -222,7 +223,8 @@ public class EncodedKeyFactory log.exiting(this.getClass().getName(), "engineGeneratePublic()", result); return result; } - + + @Override protected PrivateKey engineGeneratePrivate(KeySpec keySpec) throws InvalidKeySpecException { @@ -274,23 +276,25 @@ public class EncodedKeyFactory log.exiting(this.getClass().getName(), "engineGeneratePrivate()", result); return result; } - - protected KeySpec engineGetKeySpec(Key key, Class keySpec) + + @Override + protected <T extends KeySpec> T engineGetKeySpec(Key key, Class<T> keySpec) throws InvalidKeySpecException { if (key instanceof PublicKey && Registry.X509_ENCODING_SORT_NAME.equalsIgnoreCase(key.getFormat()) && keySpec.isAssignableFrom(X509EncodedKeySpec.class)) - return new X509EncodedKeySpec(key.getEncoded()); + return keySpec.cast(new X509EncodedKeySpec(key.getEncoded())); if (key instanceof PrivateKey && Registry.PKCS8_ENCODING_SHORT_NAME.equalsIgnoreCase(key.getFormat()) && keySpec.isAssignableFrom(PKCS8EncodedKeySpec.class)) - return new PKCS8EncodedKeySpec(key.getEncoded()); + return keySpec.cast(new PKCS8EncodedKeySpec(key.getEncoded())); throw new InvalidKeySpecException("Unsupported format or invalid key spec class"); } + @Override protected Key engineTranslateKey(Key key) throws InvalidKeyException { throw new InvalidKeyException("Key translation not supported"); diff --git a/gnu/java/security/jce/sig/RSAKeyFactory.java b/gnu/java/security/jce/sig/RSAKeyFactory.java index 3ba49edc2..07019dae3 100644 --- a/gnu/java/security/jce/sig/RSAKeyFactory.java +++ b/gnu/java/security/jce/sig/RSAKeyFactory.java @@ -1,5 +1,5 @@ /* RSAKeyFactory.java -- RSA key-factory JCE Adapter - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -66,6 +66,7 @@ public class RSAKeyFactory { // implicit 0-arguments constructor + @Override protected PublicKey engineGeneratePublic(KeySpec keySpec) throws InvalidKeySpecException { @@ -80,7 +81,6 @@ public class RSAKeyFactory { X509EncodedKeySpec spec = (X509EncodedKeySpec) keySpec; byte[] encoded = spec.getEncoded(); - PublicKey result; try { return new RSAKeyPairX509Codec().decodePublicKey(encoded); @@ -93,6 +93,7 @@ public class RSAKeyFactory throw new InvalidKeySpecException("Unsupported (public) key specification"); } + @Override protected PrivateKey engineGeneratePrivate(KeySpec keySpec) throws InvalidKeySpecException { @@ -114,7 +115,6 @@ public class RSAKeyFactory { PKCS8EncodedKeySpec spec = (PKCS8EncodedKeySpec) keySpec; byte[] encoded = spec.getEncoded(); - PrivateKey result; try { return new RSAKeyPairPKCS8Codec().decodePrivateKey(encoded); @@ -127,7 +127,8 @@ public class RSAKeyFactory throw new InvalidKeySpecException("Unsupported (private) key specification"); } - protected KeySpec engineGetKeySpec(Key key, Class keySpec) + @Override + protected <T extends KeySpec> T engineGetKeySpec(Key key, Class<T> keySpec) throws InvalidKeySpecException { if (key instanceof RSAPublicKey) @@ -137,7 +138,7 @@ public class RSAKeyFactory RSAPublicKey rsaKey = (RSAPublicKey) key; BigInteger n = rsaKey.getModulus(); BigInteger e = rsaKey.getPublicExponent(); - return new RSAPublicKeySpec(n, e); + return keySpec.cast(new RSAPublicKeySpec(n, e)); } if (keySpec.isAssignableFrom(X509EncodedKeySpec.class)) { @@ -145,13 +146,13 @@ public class RSAKeyFactory { GnuRSAPublicKey rsaKey = (GnuRSAPublicKey) key; byte[] encoded = rsaKey.getEncoded(Registry.X509_ENCODING_ID); - return new X509EncodedKeySpec(encoded); + return keySpec.cast(new X509EncodedKeySpec(encoded)); } if (Registry.X509_ENCODING_SORT_NAME.equalsIgnoreCase(key.getFormat())) { byte[] encoded = key.getEncoded(); - return new X509EncodedKeySpec(encoded); + return keySpec.cast(new X509EncodedKeySpec(encoded)); } throw new InvalidKeySpecException( "Wrong key type or unsupported (public) key specification"); @@ -170,7 +171,7 @@ public class RSAKeyFactory BigInteger dP = rsaKey.getPrimeExponentP(); BigInteger dQ = rsaKey.getPrimeExponentQ(); BigInteger qInv = rsaKey.getCrtCoefficient(); - return new RSAPrivateCrtKeySpec(n, e, d, p, q, dP, dQ, qInv); + return keySpec.cast(new RSAPrivateCrtKeySpec(n, e, d, p, q, dP, dQ, qInv)); } if ((key instanceof RSAPrivateKey) && keySpec.isAssignableFrom(RSAPrivateKeySpec.class)) @@ -178,7 +179,7 @@ public class RSAKeyFactory RSAPrivateKey rsaKey = (RSAPrivateKey) key; BigInteger n = rsaKey.getModulus(); BigInteger d = rsaKey.getPrivateExponent(); - return new RSAPrivateKeySpec(n, d); + return keySpec.cast(new RSAPrivateKeySpec(n, d)); } if (keySpec.isAssignableFrom(PKCS8EncodedKeySpec.class)) { @@ -186,12 +187,12 @@ public class RSAKeyFactory { GnuRSAPrivateKey rsaKey = (GnuRSAPrivateKey) key; byte[] encoded = rsaKey.getEncoded(Registry.PKCS8_ENCODING_ID); - return new PKCS8EncodedKeySpec(encoded); + return keySpec.cast(new PKCS8EncodedKeySpec(encoded)); } if (Registry.PKCS8_ENCODING_SHORT_NAME.equalsIgnoreCase(key.getFormat())) { byte[] encoded = key.getEncoded(); - return new PKCS8EncodedKeySpec(encoded); + return keySpec.cast(new PKCS8EncodedKeySpec(encoded)); } throw new InvalidKeySpecException( "Wrong key type or unsupported (private) key specification"); @@ -200,6 +201,7 @@ public class RSAKeyFactory "Wrong key type or unsupported key specification"); } + @Override protected Key engineTranslateKey(Key key) throws InvalidKeyException { if ((key instanceof GnuRSAPublicKey) || (key instanceof GnuRSAPrivateKey)) diff --git a/gnu/java/security/jce/sig/RSAKeyPairGeneratorSpi.java b/gnu/java/security/jce/sig/RSAKeyPairGeneratorSpi.java index ef53b8115..fa3cbd5a8 100644 --- a/gnu/java/security/jce/sig/RSAKeyPairGeneratorSpi.java +++ b/gnu/java/security/jce/sig/RSAKeyPairGeneratorSpi.java @@ -1,5 +1,5 @@ /* RSAKeyPairGeneratorSpi.java -- JCE RSA KeyPairGenerator Adapter - Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2001, 2002, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -65,7 +65,7 @@ public class RSAKeyPairGeneratorSpi public void initialize(int keysize, SecureRandom random) { - HashMap attributes = new HashMap(); + HashMap<String,Object> attributes = new HashMap<String,Object>(); attributes.put(RSAKeyPairGenerator.MODULUS_LENGTH, Integer.valueOf(keysize)); if (random != null) attributes.put(RSAKeyPairGenerator.SOURCE_OF_RANDOMNESS, random); @@ -78,7 +78,7 @@ public class RSAKeyPairGeneratorSpi public void initialize(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException { - HashMap attributes = new HashMap(); + HashMap<String,Object> attributes = new HashMap<String,Object>(); if (params != null) { if (! (params instanceof RSAKeyGenParameterSpec)) diff --git a/gnu/java/security/jce/sig/SignatureAdapter.java b/gnu/java/security/jce/sig/SignatureAdapter.java index efe3681ca..7f7c1569f 100644 --- a/gnu/java/security/jce/sig/SignatureAdapter.java +++ b/gnu/java/security/jce/sig/SignatureAdapter.java @@ -1,5 +1,5 @@ /* SignatureAdapter.java -- - Copyright 2001, 2002, 2006, 2010 Free Software Foundation, Inc. + Copyright 2001, 2002, 2006, 2010, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -114,9 +114,10 @@ class SignatureAdapter return new SignatureAdapter((ISignature) adaptee.clone(), codec); } + @Override public void engineInitVerify(PublicKey publicKey) throws InvalidKeyException { - HashMap attributes = new HashMap(); + HashMap<String,Object> attributes = new HashMap<String,Object>(); attributes.put(BaseSignature.VERIFIER_KEY, publicKey); try { @@ -128,9 +129,10 @@ class SignatureAdapter } } + @Override public void engineInitSign(PrivateKey privateKey) throws InvalidKeyException { - HashMap attributes = new HashMap(); + HashMap<String,Object> attributes = new HashMap<String,Object>(); attributes.put(BaseSignature.SIGNER_KEY, privateKey); try { @@ -142,10 +144,11 @@ class SignatureAdapter } } + @Override public void engineInitSign(PrivateKey privateKey, SecureRandom random) throws InvalidKeyException { - HashMap attributes = new HashMap(); + HashMap<String,Object> attributes = new HashMap<String,Object>(); attributes.put(BaseSignature.SIGNER_KEY, privateKey); attributes.put(BaseSignature.SOURCE_OF_RANDOMNESS, random); try @@ -158,6 +161,7 @@ class SignatureAdapter } } + @Override public void engineUpdate(byte b) throws SignatureException { try @@ -170,6 +174,7 @@ class SignatureAdapter } } + @Override public void engineUpdate(byte[] b, int off, int len) throws SignatureException { @@ -183,6 +188,7 @@ class SignatureAdapter } } + @Override public byte[] engineSign() throws SignatureException { Object signature = null; @@ -198,6 +204,7 @@ class SignatureAdapter return result; } + @Override public int engineSign(byte[] outbuf, int offset, int len) throws SignatureException { @@ -210,6 +217,7 @@ class SignatureAdapter return result; } + @Override public boolean engineVerify(byte[] sigBytes) throws SignatureException { if (Configuration.DEBUG) @@ -231,18 +239,21 @@ class SignatureAdapter } // Deprecated. Replaced by engineSetParameter. + @Override public void engineSetParameter(String param, Object value) throws InvalidParameterException { throw new InvalidParameterException("deprecated"); } + @Override public void engineSetParameter(AlgorithmParameterSpec params) throws InvalidAlgorithmParameterException { } // Deprecated + @Override public Object engineGetParameter(String param) throws InvalidParameterException { diff --git a/gnu/java/security/key/IKeyPairGenerator.java b/gnu/java/security/key/IKeyPairGenerator.java index 72aac2463..e7d96b22a 100644 --- a/gnu/java/security/key/IKeyPairGenerator.java +++ b/gnu/java/security/key/IKeyPairGenerator.java @@ -1,5 +1,5 @@ /* IKeyPairGenerator.java -- - Copyright 2001, 2002, 2006 Free Software Foundation, Inc. + Copyright 2001, 2002, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -61,7 +61,7 @@ public interface IKeyPairGenerator * @exception IllegalArgumentException if at least one of the mandatory * attributes is missing or an invalid value was specified. */ - void setup(Map attributes); + void setup(Map<String,Object> attributes); /** * Generates a new keypair based on the attributes used to configure the diff --git a/gnu/java/security/key/KeyPairCodecFactory.java b/gnu/java/security/key/KeyPairCodecFactory.java index d42866423..b4d96e2e2 100644 --- a/gnu/java/security/key/KeyPairCodecFactory.java +++ b/gnu/java/security/key/KeyPairCodecFactory.java @@ -1,5 +1,5 @@ /* KeyPairCodecFactory.java -- - Copyright 2001, 2002, 2006 Free Software Foundation, Inc. + Copyright 2001, 2002, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -62,7 +62,7 @@ import java.util.Set; */ public class KeyPairCodecFactory { - private static Set names; + private static Set<String> names; /** Trivial constructor to enforce Singleton pattern. */ private KeyPairCodecFactory() @@ -194,11 +194,11 @@ public class KeyPairCodecFactory * * @return a {@link Set} of the names of supported key-pair codec (Strings). */ - public static synchronized final Set getNames() + public static synchronized final Set<String> getNames() { if (names == null) { - HashSet hs = new HashSet(); + HashSet<String> hs = new HashSet<String>(); hs.add(Registry.DSS_KPG + "/" + Registry.RAW_ENCODING_SHORT_NAME); hs.add(Registry.DSS_KPG + "/" + Registry.X509_ENCODING_SORT_NAME); hs.add(Registry.DSS_KPG + "/" + Registry.PKCS8_ENCODING_SHORT_NAME); @@ -216,8 +216,8 @@ public class KeyPairCodecFactory { try { - Class c = Class.forName (clazz); - Constructor ctor = c.getConstructor (new Class[0]); + Class<?> c = Class.forName (clazz); + Constructor<?> ctor = c.getConstructor (new Class[0]); return (IKeyPairCodec) ctor.newInstance (new Object[0]); } catch (Exception x) @@ -234,7 +234,7 @@ public class KeyPairCodecFactory { try { - Class c = Class.forName (clazz); + Class<?> c = Class.forName (clazz); return c.isAssignableFrom (o.getClass ()); } catch (Exception x) diff --git a/gnu/java/security/key/KeyPairGeneratorFactory.java b/gnu/java/security/key/KeyPairGeneratorFactory.java index 151cace39..a5ae8997b 100644 --- a/gnu/java/security/key/KeyPairGeneratorFactory.java +++ b/gnu/java/security/key/KeyPairGeneratorFactory.java @@ -1,5 +1,5 @@ /* KeyPairGeneratorFactory.java -- - Copyright 2001, 2002, 2003, 2006 Free Software Foundation, Inc. + Copyright 2001, 2002, 2003, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -92,9 +92,9 @@ public class KeyPairGeneratorFactory * * @return a {@link Set} of keypair generator names (Strings). */ - public static final Set getNames() + public static final Set<String> getNames() { - HashSet hs = new HashSet(); + HashSet<String> hs = new HashSet<String>(); hs.add(Registry.DSS_KPG); hs.add(Registry.DSA_KPG); hs.add(Registry.RSA_KPG); @@ -107,8 +107,8 @@ public class KeyPairGeneratorFactory { try { - Class c = Class.forName(clazz); - Constructor ctor = c.getConstructor(new Class[0]); + Class<?> c = Class.forName(clazz); + Constructor<?> ctor = c.getConstructor(new Class[0]); return (IKeyPairGenerator) ctor.newInstance(new Object[0]); } catch (Exception x) diff --git a/gnu/java/security/key/dss/DSSKey.java b/gnu/java/security/key/dss/DSSKey.java index 49f229f7b..0641ff872 100644 --- a/gnu/java/security/key/dss/DSSKey.java +++ b/gnu/java/security/key/dss/DSSKey.java @@ -1,5 +1,5 @@ /* DSSKey.java -- - Copyright 2001, 2002, 2003, 2006 Free Software Foundation, Inc. + Copyright 2001, 2002, 2003, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -73,6 +73,8 @@ import java.security.spec.DSAParameterSpec; public abstract class DSSKey implements Key, DSAKey { + private static final long serialVersionUID = -621913609497224901L; + /** * A prime modulus, where * <code>2<sup>L-1</sup> < p < 2<sup>L</sup></code> for diff --git a/gnu/java/security/key/dss/DSSKeyPairGenerator.java b/gnu/java/security/key/dss/DSSKeyPairGenerator.java index 70df734a9..9a19947fe 100644 --- a/gnu/java/security/key/dss/DSSKeyPairGenerator.java +++ b/gnu/java/security/key/dss/DSSKeyPairGenerator.java @@ -1,5 +1,5 @@ /* DSSKeyPairGenerator.java -- - Copyright 2001, 2002, 2003, 2006, 2010 Free Software Foundation, Inc. + Copyright 2001, 2002, 2003, 2006, 2010, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -211,6 +211,7 @@ public class DSSKeyPairGenerator /** Preferred encoding format of generated keys. */ private int preferredFormat; + @Override public String name() { return Registry.DSS_KPG; @@ -224,7 +225,8 @@ public class DSSKeyPairGenerator * is not greater than 512, less than 1024 and not of the form * <code>512 + 64j</code>. */ - public void setup(Map attributes) + @Override + public void setup(Map<String,Object> attributes) { // find out the modulus length Integer l = (Integer) attributes.get(MODULUS_LENGTH); @@ -299,6 +301,7 @@ public class DSSKeyPairGenerator XKEY = new BigInteger(1, kb).setBit(159).setBit(0); } + @Override public KeyPair generate() { if (p == null) diff --git a/gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java b/gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java index 1806ecf58..e99446636 100644 --- a/gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java +++ b/gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java @@ -1,5 +1,5 @@ /* DSSKeyPairPKCS8Codec.java -- PKCS#8 Encoding/Decoding handler - Copyright (C) 2006, 2010 Free Software Foundation, Inc. + Copyright (C) 2006, 2010, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -74,6 +74,7 @@ public class DSSKeyPairPKCS8Codec // implicit 0-arguments constructor + @Override public int getFormatID() { return PKCS8_FORMAT; @@ -82,6 +83,7 @@ public class DSSKeyPairPKCS8Codec /** * @throws InvalidParameterException ALWAYS. */ + @Override public byte[] encodePublicKey(PublicKey key) { throw new InvalidParameterException("Wrong format for public keys"); @@ -115,6 +117,7 @@ public class DSSKeyPairPKCS8Codec * @throw InvalidParameterException if an error occurs during the marshalling * process. */ + @Override public byte[] encodePrivateKey(PrivateKey key) { if (! (key instanceof DSSPrivateKey)) @@ -130,13 +133,13 @@ public class DSSKeyPairPKCS8Codec BigInteger g = pk.getParams().getG(); BigInteger x = pk.getX(); - ArrayList params = new ArrayList(3); + ArrayList<DERValue> params = new ArrayList<DERValue>(3); params.add(new DERValue(DER.INTEGER, p)); params.add(new DERValue(DER.INTEGER, q)); params.add(new DERValue(DER.INTEGER, g)); DERValue derParams = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, params); - ArrayList algorithmID = new ArrayList(2); + ArrayList<DERValue> algorithmID = new ArrayList<DERValue>(2); algorithmID.add(derOID); algorithmID.add(derParams); DERValue derAlgorithmID = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, @@ -146,7 +149,7 @@ public class DSSKeyPairPKCS8Codec DERValue derX = new DERValue(DER.INTEGER, x); DERValue derPrivateKey = new DERValue(DER.OCTET_STRING, derX.getEncoded()); - ArrayList pki = new ArrayList(3); + ArrayList<DERValue> pki = new ArrayList<DERValue>(3); pki.add(derVersion); pki.add(derAlgorithmID); pki.add(derPrivateKey); @@ -171,6 +174,7 @@ public class DSSKeyPairPKCS8Codec /** * @throws InvalidParameterException ALWAYS. */ + @Override public PublicKey decodePublicKey(byte[] input) { throw new InvalidParameterException("Wrong format for public keys"); @@ -184,6 +188,7 @@ public class DSSKeyPairPKCS8Codec * @throw InvalidParameterException if an exception occurs during the * unmarshalling process. */ + @Override public PrivateKey decodePrivateKey(byte[] input) { if (Configuration.DEBUG) diff --git a/gnu/java/security/key/dss/DSSKeyPairX509Codec.java b/gnu/java/security/key/dss/DSSKeyPairX509Codec.java index 8c26910f1..678924851 100644 --- a/gnu/java/security/key/dss/DSSKeyPairX509Codec.java +++ b/gnu/java/security/key/dss/DSSKeyPairX509Codec.java @@ -1,5 +1,5 @@ /* DSSKeyPairX509Codec.java -- X.509 Encoding/Decoding handler - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -137,14 +137,14 @@ public class DSSKeyPairX509Codec DERValue derQ = new DERValue(DER.INTEGER, q); DERValue derG = new DERValue(DER.INTEGER, g); - ArrayList params = new ArrayList(3); + ArrayList<DERValue> params = new ArrayList<DERValue>(3); params.add(derP); params.add(derQ); params.add(derG); derParams = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, params); } - ArrayList algorithmID = new ArrayList(2); + ArrayList<DERValue> algorithmID = new ArrayList<DERValue>(2); algorithmID.add(derOID); algorithmID.add(derParams); DERValue derAlgorithmID = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, @@ -155,7 +155,7 @@ public class DSSKeyPairX509Codec byte[] yBytes = derDSAPublicKey.getEncoded(); DERValue derSPK = new DERValue(DER.BIT_STRING, new BitString(yBytes)); - ArrayList spki = new ArrayList(2); + ArrayList<DERValue> spki = new ArrayList<DERValue>(2); spki.add(derAlgorithmID); spki.add(derSPK); DERValue derSPKI = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, spki); diff --git a/gnu/java/security/key/dss/DSSPrivateKey.java b/gnu/java/security/key/dss/DSSPrivateKey.java index de3668c01..4b3ccc72d 100644 --- a/gnu/java/security/key/dss/DSSPrivateKey.java +++ b/gnu/java/security/key/dss/DSSPrivateKey.java @@ -1,5 +1,5 @@ /* DSSPrivateKey.java -- - Copyright 2001, 2002, 2003, 2006 Free Software Foundation, Inc. + Copyright 2001, 2002, 2003, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -59,6 +59,8 @@ public class DSSPrivateKey extends DSSKey implements PrivateKey, DSAPrivateKey { + private static final long serialVersionUID = -4273348785094844114L; + /** * A randomly or pseudorandomly generated integer with <code>0 < x < * q</code>. diff --git a/gnu/java/security/key/dss/DSSPublicKey.java b/gnu/java/security/key/dss/DSSPublicKey.java index d7c1afe15..0f4c08e78 100644 --- a/gnu/java/security/key/dss/DSSPublicKey.java +++ b/gnu/java/security/key/dss/DSSPublicKey.java @@ -1,5 +1,5 @@ /* DSSPublicKey.java -- - Copyright 2001, 2002, 2003, 2006 Free Software Foundation, Inc. + Copyright 2001, 2002, 2003, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -58,6 +58,8 @@ public class DSSPublicKey extends DSSKey implements PublicKey, DSAPublicKey { + private static final long serialVersionUID = 4662188565230532792L; + /** * <code>y = g<sup>x</sup> mod p</code> where <code>x</code> is the * private part of the DSA key. diff --git a/gnu/java/security/key/rsa/GnuRSAKey.java b/gnu/java/security/key/rsa/GnuRSAKey.java index 38530ee4c..f8d89af38 100644 --- a/gnu/java/security/key/rsa/GnuRSAKey.java +++ b/gnu/java/security/key/rsa/GnuRSAKey.java @@ -1,5 +1,5 @@ /* GnuRSAKey.java -- - Copyright 2001, 2002, 2003, 2006 Free Software Foundation, Inc. + Copyright 2001, 2002, 2003, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -55,6 +55,8 @@ import java.security.interfaces.RSAKey; public abstract class GnuRSAKey implements Key, RSAKey { + private static final long serialVersionUID = -7321530024326974635L; + /** The public modulus of an RSA key pair. */ private final BigInteger n; diff --git a/gnu/java/security/key/rsa/GnuRSAPrivateKey.java b/gnu/java/security/key/rsa/GnuRSAPrivateKey.java index 39f91cbe4..379650a81 100644 --- a/gnu/java/security/key/rsa/GnuRSAPrivateKey.java +++ b/gnu/java/security/key/rsa/GnuRSAPrivateKey.java @@ -1,5 +1,5 @@ /* GnuRSAPrivateKey.java -- - Copyright 2001, 2002, 2003, 2006 Free Software Foundation, Inc. + Copyright 2001, 2002, 2003, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -67,6 +67,8 @@ public class GnuRSAPrivateKey extends GnuRSAKey implements PrivateKey, RSAPrivateCrtKey { + private static final long serialVersionUID = -2208207842306185913L; + /** The first prime divisor of the modulus. */ private final BigInteger p; diff --git a/gnu/java/security/key/rsa/GnuRSAPublicKey.java b/gnu/java/security/key/rsa/GnuRSAPublicKey.java index 0bad92881..b8e1ea5b1 100644 --- a/gnu/java/security/key/rsa/GnuRSAPublicKey.java +++ b/gnu/java/security/key/rsa/GnuRSAPublicKey.java @@ -1,5 +1,5 @@ /* GnuRSAPublicKey.java -- - Copyright 2001, 2002, 2003, 2006 Free Software Foundation, Inc. + Copyright 2001, 2002, 2003, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -65,6 +65,8 @@ public class GnuRSAPublicKey extends GnuRSAKey implements PublicKey, RSAPublicKey { + private static final long serialVersionUID = -1206860366945100193L; + /** String representation of this key. Cached for speed. */ private transient String str; diff --git a/gnu/java/security/key/rsa/RSAKeyPairGenerator.java b/gnu/java/security/key/rsa/RSAKeyPairGenerator.java index 99c313944..a7fc21efe 100644 --- a/gnu/java/security/key/rsa/RSAKeyPairGenerator.java +++ b/gnu/java/security/key/rsa/RSAKeyPairGenerator.java @@ -1,5 +1,5 @@ /* RSAKeyPairGenerator.java -- - Copyright 2001, 2002, 2003, 2006, 2010 Free Software Foundation, Inc. + Copyright 2001, 2002, 2003, 2006, 2010, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -129,6 +129,7 @@ public class RSAKeyPairGenerator // implicit 0-arguments constructor + @Override public String name() { return Registry.RSA_KPG; @@ -141,7 +142,8 @@ public class RSAKeyPairGenerator * @exception IllegalArgumentException if the designated MODULUS_LENGTH value * is less than 1024. */ - public void setup(Map attributes) + @Override + public void setup(Map<String,Object> attributes) { if (Configuration.DEBUG) log.entering(this.getClass().getName(), "setup", attributes); @@ -179,6 +181,7 @@ public class RSAKeyPairGenerator * * @return an RSA keypair. */ + @Override public KeyPair generate() { if (Configuration.DEBUG) diff --git a/gnu/java/security/key/rsa/RSAKeyPairPKCS8Codec.java b/gnu/java/security/key/rsa/RSAKeyPairPKCS8Codec.java index b07ed667c..ec9874d80 100644 --- a/gnu/java/security/key/rsa/RSAKeyPairPKCS8Codec.java +++ b/gnu/java/security/key/rsa/RSAKeyPairPKCS8Codec.java @@ -1,5 +1,5 @@ /* RSAKeyPairPKCS8Codec.java -- PKCS#8 Encoding/Decoding handler - Copyright (C) 2006, 2010 Free Software Foundation, Inc. + Copyright (C) 2006, 2010, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -145,7 +145,7 @@ public class RSAKeyPairPKCS8Codec DERValue derOID = new DERValue(DER.OBJECT_IDENTIFIER, RSA_ALG_OID); - ArrayList algorithmID = new ArrayList(2); + ArrayList<DERValue> algorithmID = new ArrayList<DERValue>(2); algorithmID.add(derOID); algorithmID.add(new DERValue(DER.NULL, null)); DERValue derAlgorithmID = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, @@ -161,7 +161,7 @@ public class RSAKeyPairPKCS8Codec DERValue derDQ = new DERValue(DER.INTEGER, dQ); DERValue derQInv = new DERValue(DER.INTEGER, qInv); - ArrayList rsaPrivateKey = new ArrayList(); + ArrayList<DERValue> rsaPrivateKey = new ArrayList<DERValue>(); rsaPrivateKey.add(derRSAVersion); rsaPrivateKey.add(derN); rsaPrivateKey.add(derE); @@ -176,7 +176,7 @@ public class RSAKeyPairPKCS8Codec byte[] pkBytes = derRSAPrivateKey.getEncoded(); DERValue derPrivateKey = new DERValue(DER.OCTET_STRING, pkBytes); - ArrayList pki = new ArrayList(3); + ArrayList<DERValue> pki = new ArrayList<DERValue>(3); pki.add(derVersion); pki.add(derAlgorithmID); pki.add(derPrivateKey); diff --git a/gnu/java/security/key/rsa/RSAKeyPairX509Codec.java b/gnu/java/security/key/rsa/RSAKeyPairX509Codec.java index 36fd75c98..3eed1ef25 100644 --- a/gnu/java/security/key/rsa/RSAKeyPairX509Codec.java +++ b/gnu/java/security/key/rsa/RSAKeyPairX509Codec.java @@ -1,5 +1,5 @@ /* RSAKeyPairX509Codec.java -- X.509 Encoding/Decoding handler - Copyright (C) 2006, 2010 Free Software Foundation, Inc. + Copyright (C) 2006, 2010, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -72,6 +72,7 @@ public class RSAKeyPairX509Codec // implicit 0-arguments constructor + @Override public int getFormatID() { return X509_FORMAT; @@ -115,6 +116,7 @@ public class RSAKeyPairX509Codec * of {@link GnuRSAPublicKey} or if an exception occurs during the * marshalling process. */ + @Override public byte[] encodePublicKey(PublicKey key) { if (Configuration.DEBUG) @@ -131,13 +133,13 @@ public class RSAKeyPairX509Codec DERValue derN = new DERValue(DER.INTEGER, n); DERValue derE = new DERValue(DER.INTEGER, e); - ArrayList algorithmID = new ArrayList(2); + ArrayList<DERValue> algorithmID = new ArrayList<DERValue>(2); algorithmID.add(derOID); algorithmID.add(new DERValue(DER.NULL, null)); DERValue derAlgorithmID = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, algorithmID); - ArrayList publicKey = new ArrayList(2); + ArrayList<DERValue> publicKey = new ArrayList<DERValue>(2); publicKey.add(derN); publicKey.add(derE); DERValue derPublicKey = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, @@ -145,7 +147,7 @@ public class RSAKeyPairX509Codec byte[] spkBytes = derPublicKey.getEncoded(); DERValue derSPK = new DERValue(DER.BIT_STRING, new BitString(spkBytes)); - ArrayList spki = new ArrayList(2); + ArrayList<DERValue> spki = new ArrayList<DERValue>(2); spki.add(derAlgorithmID); spki.add(derSPK); DERValue derSPKI = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, spki); @@ -171,6 +173,7 @@ public class RSAKeyPairX509Codec /** * @throws InvalidParameterException ALWAYS. */ + @Override public byte[] encodePrivateKey(PrivateKey key) { throw new InvalidParameterException("Wrong format for private keys"); @@ -184,6 +187,7 @@ public class RSAKeyPairX509Codec * @throw InvalidParameterException if an exception occurs during the * unmarshalling process. */ + @Override public PublicKey decodePublicKey(byte[] input) { if (Configuration.DEBUG) @@ -245,6 +249,7 @@ public class RSAKeyPairX509Codec /** * @throws InvalidParameterException ALWAYS. */ + @Override public PrivateKey decodePrivateKey(byte[] input) { throw new InvalidParameterException("Wrong format for private keys"); diff --git a/gnu/java/security/pkcs/PKCS7SignedData.java b/gnu/java/security/pkcs/PKCS7SignedData.java index e479d2e8c..eccd69141 100644 --- a/gnu/java/security/pkcs/PKCS7SignedData.java +++ b/gnu/java/security/pkcs/PKCS7SignedData.java @@ -1,5 +1,5 @@ /* PKCS7SignedData.java -- reader/writer for PKCS#7 signedData objects - Copyright (C) 2004, 2005, 2006, 2010 Free Software Foundation, Inc. + Copyright (C) 2004, 2005, 2006, 2010, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -53,6 +53,8 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; import java.math.BigInteger; import java.security.cert.CRL; import java.security.cert.CRLException; @@ -84,12 +86,12 @@ public class PKCS7SignedData public static final OID PKCS7_SIGNED_DATA = new OID("1.2.840.113549.1.7.2"); private BigInteger version; - private Set digestAlgorithms; + private Set<DERValue> digestAlgorithms; private OID contentType; private byte[] content; private Certificate[] certificates; private CRL[] crls; - private Set signerInfos; + private Set<SignerInfo> signerInfos; public PKCS7SignedData(InputStream in) throws CRLException, CertificateException, IOException @@ -183,7 +185,7 @@ public class PKCS7SignedData if (Configuration.DEBUG) log.fine(" Version: " + version); - digestAlgorithms = new HashSet(); + digestAlgorithms = new HashSet<DERValue>(); val = ber.read(); if (!val.isConstructed()) throw new BEREncodingException("malformed DigestAlgorithmIdentifiers"); @@ -200,20 +202,17 @@ public class PKCS7SignedData log.fine(" AlgorithmIdentifier: " + val2); count += val2.getEncodedLength(); val2 = ber.read(); - if (val2.getTag() != BER.OBJECT_IDENTIFIER) + if (val2.getTag() != DER.OBJECT_IDENTIFIER) throw new BEREncodingException("malformed AlgorithmIdentifier"); if (Configuration.DEBUG) log.fine(" digestAlgorithmIdentifiers OID: " + val2.getValue()); - List algId = new ArrayList(2); - algId.add(val2.getValue()); + List<DERValue> algId = new ArrayList<DERValue>(2); + algId.add(val2); val2 = ber.read(); if (val2 != BER.END_OF_SEQUENCE) { count += val2.getEncodedLength(); - if (val2.getTag() == BER.NULL) - algId.add(null); - else - algId.add(val2.getEncoded()); + algId.add(val2); if (val2.isConstructed()) ber.skip(val2.getLength()); @@ -222,15 +221,15 @@ public class PKCS7SignedData val2 = ber.read(); } else - algId.add(null); + algId.add(new DERValue(DER.NULL, null)); if (Configuration.DEBUG) { log.fine(" digestAlgorithmIdentifiers params: "); - log.fine(Util.dumpString((byte[]) algId.get(1), + log.fine(Util.dumpString(algId.get(1).getEncoded(), " digestAlgorithmIdentifiers params: ")); } - digestAlgorithms.add(algId); + digestAlgorithms.add(new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, algId)); } val = ber.read(); @@ -270,7 +269,7 @@ public class PKCS7SignedData log.fine(" ExtendedCertificatesAndCertificates: " + val); count = 0; val2 = ber.read(); - List certs = new LinkedList(); + List<Certificate> certs = new LinkedList<Certificate>(); while (val2 != BER.END_OF_SEQUENCE && (val.getLength() > 0 && val.getLength() > count)) { @@ -284,7 +283,7 @@ public class PKCS7SignedData if (BERValue.isIndefinite(val) || val.getLength() > count) val2 = ber.read(); } - certificates = (Certificate[]) certs.toArray(new Certificate[certs.size()]); + certificates = certs.toArray(new Certificate[certs.size()]); val = ber.read(); } @@ -296,7 +295,7 @@ public class PKCS7SignedData log.fine(" CertificateRevocationLists: " + val); count = 0; val2 = ber.read(); - List crls = new LinkedList(); + List<CRL> crls = new LinkedList<CRL>(); while (val2 != BER.END_OF_SEQUENCE && (val.getLength() > 0 && val.getLength() > count)) { @@ -309,11 +308,11 @@ public class PKCS7SignedData if (BERValue.isIndefinite(val) || val.getLength() > count) val2 = ber.read(); } - this.crls = (CRL[]) crls.toArray(new CRL[crls.size()]); + this.crls = crls.toArray(new CRL[crls.size()]); val = ber.read(); } - signerInfos = new HashSet(); + signerInfos = new HashSet<SignerInfo>(); if (!val.isConstructed()) throw new BEREncodingException("malformed SignerInfos"); if (Configuration.DEBUG) @@ -349,9 +348,9 @@ public class PKCS7SignedData * the data referenced by this <code>PKCS7SignedData</code> * instance. */ - public PKCS7SignedData(Set digestAlgorithms, PKCS7Data data, + public PKCS7SignedData(Set<DERValue> digestAlgorithms, PKCS7Data data, Certificate[] certificates, X509CRL[] crls, - Set signerInfos) + Set<SignerInfo> signerInfos) { super(); @@ -385,16 +384,35 @@ public class PKCS7SignedData return (content != null ? (byte[]) content.clone() : null); } - public Set getDigestAlgorithms() + public Set<DERValue> getDigestAlgorithms() { - // FIXME copy contents too, they are mutable!!! - return Collections.unmodifiableSet(digestAlgorithms); + Set<DERValue> daClone = new HashSet<DERValue>(digestAlgorithms.size()); + for (DERValue dv : digestAlgorithms) + { + Object clone = null; + Object obj = dv.getValue(); + if (obj != null && obj instanceof Cloneable) + { + try + { + Method m = obj.getClass().getDeclaredMethod("clone"); + m.setAccessible(true); + clone = m.invoke(obj); + } + catch (NoSuchMethodException e) { /* Impossible */ } + catch (IllegalAccessException e) { /* Ignored */ } + catch (InvocationTargetException e) { /* Ignored */ } + } + if (clone == null) clone = obj; + daClone.add(new DERValue(dv.getTag(), dv.getLength(), clone, dv.getEncoded())); + } + return Collections.unmodifiableSet(daClone); } - public Set getSignerInfos() + public Set<SignerInfo> getSignerInfos() { - Set copy = new HashSet(); - for (Iterator it = signerInfos.iterator(); it.hasNext(); ) + Set<SignerInfo> copy = new HashSet<SignerInfo>(); + for (Iterator<SignerInfo> it = signerInfos.iterator(); it.hasNext(); ) copy.add(it.next()); return Collections.unmodifiableSet(copy); } @@ -420,7 +438,7 @@ public class PKCS7SignedData DERValue derContentType = new DERValue(DER.OBJECT_IDENTIFIER, PKCS7Data.PKCS7_DATA); - ArrayList contentInfo = new ArrayList(2); + ArrayList<Object> contentInfo = new ArrayList<Object>(2); contentInfo.add(derContentType); if (content == null) contentInfo.add(new DERValue(DER.NULL, null)); @@ -453,9 +471,8 @@ public class PKCS7SignedData } baos.reset(); - for (Iterator it = signerInfos.iterator(); it.hasNext();) + for (SignerInfo signerInfo : signerInfos) { - SignerInfo signerInfo = (SignerInfo) it.next(); signerInfo.encode(baos); } baos.flush(); @@ -463,7 +480,7 @@ public class PKCS7SignedData DERValue derSignerInfos = new DERValue(DER.CONSTRUCTED | DER.SET, b3.length, b3, null); - ArrayList signedData = new ArrayList(6); + ArrayList<DERValue> signedData = new ArrayList<DERValue>(6); signedData.add(derVersion); signedData.add(derDigestAlgorithms); signedData.add(derContentInfo); @@ -475,7 +492,7 @@ public class PKCS7SignedData DERValue derSignedData = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, signedData); // now the outer contents - ArrayList outer = new ArrayList(3); + ArrayList<DERValue> outer = new ArrayList<DERValue>(3); outer.add(new DERValue(DER.OBJECT_IDENTIFIER, PKCS7_SIGNED_DATA)); outer.add(new DERValue(DER.CONTEXT | 0, null)); outer.add(derSignedData); diff --git a/gnu/java/security/pkcs/SignerInfo.java b/gnu/java/security/pkcs/SignerInfo.java index 07ce4d71b..155eaaefa 100644 --- a/gnu/java/security/pkcs/SignerInfo.java +++ b/gnu/java/security/pkcs/SignerInfo.java @@ -1,5 +1,5 @@ /* SignerInfo.java -- a SignerInfo object, from PKCS #7 - Copyright (C) 2004, 2005, 2010 Free Software Foundation, Inc. + Copyright (C) 2004, 2005, 2010. 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -144,7 +144,6 @@ public class SignerInfo if (Configuration.DEBUG) log.fine(" DigestAlgorithmIdentifier: " + val); - int count = 0; DERValue val2 = ber.read(); if (val2.getTag() != BER.OBJECT_IDENTIFIER) throw new BEREncodingException("malformed AlgorithmIdentifier"); @@ -205,7 +204,6 @@ public class SignerInfo throw new BEREncodingException("malformed DigestEncryptionAlgorithmIdentifier"); if (Configuration.DEBUG) log.fine(" DigestEncryptionAlgorithmIdentifier: " + val); - count = 0; val2 = ber.read(); if (val2.getTag() != BER.OBJECT_IDENTIFIER) throw new BEREncodingException("malformed AlgorithmIdentifier"); @@ -390,7 +388,7 @@ public class SignerInfo DERValue derDigestAlgorithmOID = new DERValue(DER.OBJECT_IDENTIFIER, digestAlgorithmId); - ArrayList digestAlgorithmIdentifier = new ArrayList(1); + ArrayList<DERValue> digestAlgorithmIdentifier = new ArrayList<DERValue>(1); digestAlgorithmIdentifier.add(derDigestAlgorithmOID); DERValue derDigestAlgorithmIdentifier = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, digestAlgorithmIdentifier); @@ -404,7 +402,7 @@ public class SignerInfo DERValue derDigestEncryptionAlgorithmOID = new DERValue(DER.OBJECT_IDENTIFIER, digestEncryptionAlgorithmId); - ArrayList digestEncryptionAlgorithmIdentifier = new ArrayList(1); + ArrayList<DERValue> digestEncryptionAlgorithmIdentifier = new ArrayList<DERValue>(1); digestEncryptionAlgorithmIdentifier.add(derDigestEncryptionAlgorithmOID); DERValue derDigestEncryptionAlgorithmIdentifier = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, digestEncryptionAlgorithmIdentifier); @@ -418,12 +416,14 @@ public class SignerInfo derUnauthenticatedAttributes = new DERValue(DER.CONSTRUCTED | DER.SET, unauthenticatedAttributes); - ArrayList signerInfo = new ArrayList(5); + ArrayList<DERValue> signerInfo = new ArrayList<DERValue>(7); signerInfo.add(derVersion); signerInfo.add(derIssuerAndSerialNumber); signerInfo.add(derDigestAlgorithmIdentifier); + signerInfo.add(derAuthenticatedAttributes); signerInfo.add(derDigestEncryptionAlgorithmIdentifier); signerInfo.add(derEncryptedDigest); + signerInfo.add(derUnauthenticatedAttributes); DERValue derSignerInfo = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, signerInfo); DERWriter.write(out, derSignerInfo); diff --git a/gnu/java/security/prng/BasePRNG.java b/gnu/java/security/prng/BasePRNG.java index eb5ada71c..35b6c441a 100644 --- a/gnu/java/security/prng/BasePRNG.java +++ b/gnu/java/security/prng/BasePRNG.java @@ -1,5 +1,5 @@ /* BasePRNG.java -- - Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2001, 2002, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -72,12 +72,14 @@ public abstract class BasePRNG buffer = new byte[0]; } + @Override public String name() { return name; } - public void init(Map attributes) + @Override + public void init(Map<String,Object> attributes) { this.setup(attributes); @@ -85,6 +87,7 @@ public abstract class BasePRNG initialised = true; } + @Override public byte nextByte() throws IllegalStateException, LimitReachedException { if (! initialised) @@ -99,6 +102,7 @@ public abstract class BasePRNG nextBytes(out, 0, out.length); } + @Override public void nextBytes(byte[] out, int offset, int length) throws IllegalStateException, LimitReachedException { @@ -132,16 +136,19 @@ public abstract class BasePRNG } } + @Override public void addRandomByte(byte b) { throw new UnsupportedOperationException("random state is non-modifiable"); } + @Override public void addRandomBytes(byte[] buffer) { addRandomBytes(buffer, 0, buffer.length); } + @Override public void addRandomBytes(byte[] buffer, int offset, int length) { throw new UnsupportedOperationException("random state is non-modifiable"); @@ -163,6 +170,7 @@ public abstract class BasePRNG return buffer[ndx++]; } + @Override public Object clone() throws CloneNotSupportedException { BasePRNG result = (BasePRNG) super.clone(); @@ -172,7 +180,7 @@ public abstract class BasePRNG return result; } - public abstract void setup(Map attributes); + public abstract void setup(Map<String,Object> attributes); public abstract void fillBlock() throws LimitReachedException; } diff --git a/gnu/java/security/prng/IRandom.java b/gnu/java/security/prng/IRandom.java index eb1495dd8..418abaf33 100644 --- a/gnu/java/security/prng/IRandom.java +++ b/gnu/java/security/prng/IRandom.java @@ -1,5 +1,5 @@ /* IRandom.java -- - Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc. + Copyright (C) 2001, 2002, 2003, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -93,7 +93,7 @@ public interface IRandom * @exception IllegalArgumentException if at least one of the defined name/ * value pairs contains invalid data. */ - void init(Map attributes); + void init(Map<String,Object> attributes); /** * Returns the next 8 bits of random data generated from this instance. diff --git a/gnu/java/security/prng/LimitReachedException.java b/gnu/java/security/prng/LimitReachedException.java index 028c74553..97e7d6419 100644 --- a/gnu/java/security/prng/LimitReachedException.java +++ b/gnu/java/security/prng/LimitReachedException.java @@ -1,5 +1,5 @@ /* LimitReachedException.java -- - Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2001, 2002, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -45,6 +45,8 @@ package gnu.java.security.prng; public class LimitReachedException extends Exception { + private static final long serialVersionUID = 6859108040075545065L; + public LimitReachedException() { super(); diff --git a/gnu/java/security/prng/MDGenerator.java b/gnu/java/security/prng/MDGenerator.java index b110486f4..66c1bd85a 100644 --- a/gnu/java/security/prng/MDGenerator.java +++ b/gnu/java/security/prng/MDGenerator.java @@ -1,5 +1,5 @@ /* MDGenerator.java -- - Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2001, 2002, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -71,7 +71,8 @@ public class MDGenerator super(Registry.MD_PRNG); } - public void setup(Map attributes) + @Override + public void setup(Map<String,Object> attributes) { // find out which hash to use String underlyingMD = (String) attributes.get(MD_NAME); @@ -95,6 +96,7 @@ public class MDGenerator md.update(seed, 0, seed.length); } + @Override public void fillBlock() throws LimitReachedException { IMessageDigest mdc = (IMessageDigest) md.clone(); @@ -102,6 +104,7 @@ public class MDGenerator md.update(buffer, 0, buffer.length); } + @Override public void addRandomByte(final byte b) { if (md == null) @@ -109,6 +112,7 @@ public class MDGenerator md.update(b); } + @Override public void addRandomBytes(final byte[] buf, final int off, final int len) { if (md == null) @@ -116,6 +120,7 @@ public class MDGenerator md.update(buf, off, len); } + @Override public Object clone() throws CloneNotSupportedException { MDGenerator result = (MDGenerator) super.clone(); diff --git a/gnu/java/security/prng/PRNGFactory.java b/gnu/java/security/prng/PRNGFactory.java index b57d7c7bb..550cc1e95 100644 --- a/gnu/java/security/prng/PRNGFactory.java +++ b/gnu/java/security/prng/PRNGFactory.java @@ -1,5 +1,5 @@ /* PRNGFactory.java -- - Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc. + Copyright (C) 2001, 2002, 2003, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -83,9 +83,9 @@ public class PRNGFactory * @return a {@link Set} of pseudo-random number generator algorithm names * (Strings). */ - public static final Set getNames() + public static final Set<String> getNames() { - HashSet hs = new HashSet(); + HashSet<String> hs = new HashSet<String>(); hs.add(MD_PRNG); return Collections.unmodifiableSet(hs); } diff --git a/gnu/java/security/prng/RandomEvent.java b/gnu/java/security/prng/RandomEvent.java index fc4607a8a..eea21b576 100644 --- a/gnu/java/security/prng/RandomEvent.java +++ b/gnu/java/security/prng/RandomEvent.java @@ -1,5 +1,5 @@ /* RandomEvent.java -- an event with random data. - Copyright (C) 2004, 2006 Free Software Foundation, Inc. + Copyright (C) 2004, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -46,6 +46,8 @@ import java.util.EventObject; public class RandomEvent extends EventObject { + private static final long serialVersionUID = 2750214083590538430L; + private final byte sourceNumber; private final byte poolNumber; diff --git a/gnu/java/security/provider/CollectionCertStoreImpl.java b/gnu/java/security/provider/CollectionCertStoreImpl.java index 4bf3d5434..474aaf89e 100644 --- a/gnu/java/security/provider/CollectionCertStoreImpl.java +++ b/gnu/java/security/provider/CollectionCertStoreImpl.java @@ -1,5 +1,5 @@ /* CollectionCertStore.java -- Collection-based cert store. - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -57,7 +57,7 @@ public final class CollectionCertStoreImpl extends CertStoreSpi // Fields. // ------------------------------------------------------------------------- - private final Collection store; + private final Collection<?> store; // Constructors. // ------------------------------------------------------------------------- @@ -74,28 +74,30 @@ public final class CollectionCertStoreImpl extends CertStoreSpi // Instance methods. // ------------------------------------------------------------------------- - public Collection engineGetCertificates(CertSelector selector) + @Override + public Collection<? extends Certificate> engineGetCertificates(CertSelector selector) throws CertStoreException { - LinkedList result = new LinkedList(); - for (Iterator it = store.iterator(); it.hasNext(); ) + LinkedList<Certificate> result = new LinkedList<Certificate>(); + for (Iterator<?> it = store.iterator(); it.hasNext(); ) { Object o = it.next(); if ((o instanceof Certificate) && selector.match((Certificate) o)) - result.add(o); + result.add((Certificate) o); } return result; } - public Collection engineGetCRLs(CRLSelector selector) + @Override + public Collection<? extends CRL> engineGetCRLs(CRLSelector selector) throws CertStoreException { - LinkedList result = new LinkedList(); - for (Iterator it = store.iterator(); it.hasNext(); ) + LinkedList<CRL> result = new LinkedList<CRL>(); + for (Iterator<?> it = store.iterator(); it.hasNext(); ) { Object o = it.next(); if ((o instanceof CRL) && selector.match((CRL) o)) - result.add(o); + result.add((CRL) o); } return result; } diff --git a/gnu/java/security/provider/Gnu.java b/gnu/java/security/provider/Gnu.java index 62bb0a29e..1410d9cbf 100644 --- a/gnu/java/security/provider/Gnu.java +++ b/gnu/java/security/provider/Gnu.java @@ -1,5 +1,5 @@ /* Gnu.java --- Gnu provider main class - Copyright (C) 1999, 2002, 2003, 2005 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2003, 2005, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -45,6 +45,9 @@ import java.security.Provider; public final class Gnu extends Provider { + + private static final long serialVersionUID = -7055664012204311089L; + public Gnu() { super("GNU", 1.0, @@ -52,9 +55,9 @@ public final class Gnu + "Certificates and CRLs, PKIX certificate path validators, " + "Collection cert stores, Diffie-Hellman key agreement and " + "key pair generator"); - AccessController.doPrivileged (new PrivilegedAction() + AccessController.doPrivileged (new PrivilegedAction<Void>() { - public Object run() + public Void run() { // Note that all implementation class names are referenced by using // Class.getName(). That way when we staticly link the Gnu provider diff --git a/gnu/java/security/provider/PKIXCertPathValidatorImpl.java b/gnu/java/security/provider/PKIXCertPathValidatorImpl.java index e0d318777..7d6169175 100644 --- a/gnu/java/security/provider/PKIXCertPathValidatorImpl.java +++ b/gnu/java/security/provider/PKIXCertPathValidatorImpl.java @@ -1,5 +1,5 @@ /* PKIXCertPathValidatorImpl.java -- PKIX certificate path validator. - Copyright (C) 2004, 2005, 2006, 2010 Free Software Foundation, Inc. + Copyright (C) 2004, 2005, 2006, 2010, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -57,6 +57,7 @@ import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.PublicKey; import java.security.cert.CRL; +import java.security.cert.Certificate; import java.security.cert.CertPath; import java.security.cert.CertPathParameters; import java.security.cert.CertPathValidatorException; @@ -68,6 +69,8 @@ import java.security.cert.CertificateException; import java.security.cert.PKIXCertPathChecker; import java.security.cert.PKIXCertPathValidatorResult; import java.security.cert.PKIXParameters; +import java.security.cert.PolicyNode; +import java.security.cert.PolicyQualifierInfo; import java.security.cert.TrustAnchor; import java.security.cert.X509CRL; import java.security.cert.X509Certificate; @@ -126,7 +129,7 @@ public class PKIXCertPathValidatorImpl // Because this is the X.509 algorithm, we also check if all // cerificates are of type X509Certificate. PolicyNodeImpl rootNode = new PolicyNodeImpl(); - Set initPolicies = ((PKIXParameters) params).getInitialPolicies(); + Set<String> initPolicies = ((PKIXParameters) params).getInitialPolicies(); rootNode.setValidPolicy(ANY_POLICY); rootNode.setCritical(false); rootNode.setDepth(0); @@ -134,8 +137,8 @@ public class PKIXCertPathValidatorImpl rootNode.addAllExpectedPolicies(initPolicies); else rootNode.addExpectedPolicy(ANY_POLICY); - List checks = ((PKIXParameters) params).getCertPathCheckers(); - List l = path.getCertificates(); + List<PKIXCertPathChecker> checks = ((PKIXParameters) params).getCertPathCheckers(); + List<? extends Certificate> l = path.getCertificates(); if (l == null || l.size() == 0) throw new CertPathValidatorException(); X509Certificate[] p = null; @@ -152,7 +155,7 @@ public class PKIXCertPathValidatorImpl Date now = ((PKIXParameters) params).getDate(); if (now == null) now = new Date(); - LinkedList policyConstraints = new LinkedList(); + LinkedList<int[]> policyConstraints = new LinkedList<int[]>(); for (int i = p.length - 1; i >= 0; i--) { try @@ -163,12 +166,12 @@ public class PKIXCertPathValidatorImpl { throw new CertPathValidatorException(ce.toString()); } - Set uce = getCritExts(p[i]); - for (Iterator check = checks.iterator(); check.hasNext();) + Set<String> uce = getCritExts(p[i]); + for (PKIXCertPathChecker checker : checks) { try { - ((PKIXCertPathChecker) check.next()).check(p[i], uce); + checker.check(p[i], uce); } catch (Exception x) { @@ -259,14 +262,13 @@ public class PKIXCertPathValidatorImpl { throw new CertPathValidatorException("error selecting CRLs"); } - List certStores = ((PKIXParameters) params).getCertStores(); - List crls = new LinkedList(); - for (Iterator it = certStores.iterator(); it.hasNext();) + List<CertStore> certStores = ((PKIXParameters) params).getCertStores(); + List<CRL> crls = new LinkedList<CRL>(); + for (CertStore cs : certStores) { - CertStore cs = (CertStore) it.next(); try { - Collection c = cs.getCRLs(selector); + Collection<? extends CRL> c = cs.getCRLs(selector); crls.addAll(c); } catch (CertStoreException cse) @@ -276,9 +278,8 @@ public class PKIXCertPathValidatorImpl if (crls.isEmpty()) throw new CertPathValidatorException("no CRLs for issuer"); boolean certOk = false; - for (Iterator it = crls.iterator(); it.hasNext();) + for (CRL crl : crls) { - CRL crl = (CRL) it.next(); if (! (crl instanceof X509CRL)) continue; X509CRL xcrl = (X509CRL) crl; @@ -298,10 +299,9 @@ public class PKIXCertPathValidatorImpl // Now ensure that the first certificate in the chain was issued // by a trust anchor. Exception cause = null; - Set anchors = ((PKIXParameters) params).getTrustAnchors(); - for (Iterator i = anchors.iterator(); i.hasNext();) + Set<TrustAnchor> anchors = ((PKIXParameters) params).getTrustAnchors(); + for (TrustAnchor anchor : anchors) { - TrustAnchor anchor = (TrustAnchor) i.next(); X509Certificate anchorCert = null; PublicKey anchorKey = null; if (anchor.getTrustedCert() != null) @@ -335,14 +335,13 @@ public class PKIXCertPathValidatorImpl } else selector.addIssuerName(anchor.getCAName()); - List certStores = ((PKIXParameters) params).getCertStores(); - List crls = new LinkedList(); - for (Iterator it = certStores.iterator(); it.hasNext();) + List<CertStore> certStores = ((PKIXParameters) params).getCertStores(); + List<CRL> crls = new LinkedList<CRL>(); + for (CertStore cs : certStores) { - CertStore cs = (CertStore) it.next(); try { - Collection c = cs.getCRLs(selector); + Collection<? extends CRL> c = cs.getCRLs(selector); crls.addAll(c); } catch (CertStoreException cse) @@ -351,9 +350,8 @@ public class PKIXCertPathValidatorImpl } if (crls.isEmpty()) continue; - for (Iterator it = crls.iterator(); it.hasNext();) + for (CRL crl : crls) { - CRL crl = (CRL) it.next(); if (! (crl instanceof X509CRL)) continue; X509CRL xcrl = (X509CRL) crl; @@ -414,7 +412,7 @@ public class PKIXCertPathValidatorImpl */ private static boolean checkCRL(X509CRL crl, X509Certificate[] path, Date now, X509Certificate pubKeyCert, - PublicKey pubKey, List certStores) + PublicKey pubKey, List<CertStore> certStores) { Date nextUpdate = crl.getNextUpdate(); if (nextUpdate != null && nextUpdate.compareTo(now) < 0) @@ -461,10 +459,10 @@ public class PKIXCertPathValidatorImpl { X509CertSelectorImpl select = new X509CertSelectorImpl(); select.addSubjectName(crl.getIssuerDN()); - List certs = new LinkedList(); - for (Iterator it = certStores.iterator(); it.hasNext();) + List<Certificate> certs = new LinkedList<Certificate>(); + for (Iterator<CertStore> it = certStores.iterator(); it.hasNext();) { - CertStore cs = (CertStore) it.next(); + CertStore cs = it.next(); try { certs.addAll(cs.getCertificates(select)); @@ -473,7 +471,7 @@ public class PKIXCertPathValidatorImpl { } } - for (Iterator it = certs.iterator(); it.hasNext();) + for (Iterator<Certificate> it = certs.iterator(); it.hasNext();) { X509Certificate c = (X509Certificate) it.next(); for (int i = 0; i < path.length; i++) @@ -509,15 +507,15 @@ public class PKIXCertPathValidatorImpl return false; } - private static Set getCritExts(X509Certificate cert) + private static Set<String> getCritExts(X509Certificate cert) { - HashSet s = new HashSet(); + HashSet<String> s = new HashSet<String>(); if (cert instanceof GnuPKIExtension) { - Collection exts = ((GnuPKIExtension) cert).getExtensions(); - for (Iterator it = exts.iterator(); it.hasNext();) + Collection<Extension> exts = + ((GnuPKIExtension) cert).getExtensions(); + for (Extension ext : exts) { - Extension ext = (Extension) it.next(); if (ext.isCritical() && ! ext.isSupported()) s.add(ext.getOid().toString()); } @@ -582,16 +580,16 @@ public class PKIXCertPathValidatorImpl { if (Configuration.DEBUG) log.fine("updatePolicyTree depth == " + depth); - Set nodes = new HashSet(); - LinkedList stack = new LinkedList(); - Iterator current = null; + Set<PolicyNode> nodes = new HashSet<PolicyNode>(); + LinkedList<Iterator<? extends PolicyNode>> stack = new LinkedList<Iterator<? extends PolicyNode>>(); + Iterator<? extends PolicyNode> current = null; stack.addLast(Collections.singleton(root).iterator()); do { - current = (Iterator) stack.removeLast(); + current = stack.removeLast(); while (current.hasNext()) { - PolicyNodeImpl p = (PolicyNodeImpl) current.next(); + PolicyNode p = current.next(); if (Configuration.DEBUG) log.fine("visiting node == " + p); if (p.getDepth() == depth - 1) @@ -613,7 +611,6 @@ public class PKIXCertPathValidatorImpl Extension e = null; CertificatePolicies policies = null; - List qualifierInfos = null; if (cert instanceof GnuPKIExtension) { e = ((GnuPKIExtension) cert).getExtension(CertificatePolicies.ID); @@ -621,25 +618,24 @@ public class PKIXCertPathValidatorImpl policies = (CertificatePolicies) e.getValue(); } - List cp = null; + List<OID> cp = null; if (policies != null) cp = policies.getPolicies(); else - cp = Collections.EMPTY_LIST; + cp = Collections.emptyList(); boolean match = false; if (Configuration.DEBUG) { log.fine("nodes are == " + nodes); log.fine("cert policies are == " + cp); } - for (Iterator it = nodes.iterator(); it.hasNext();) + for (Iterator<PolicyNode> it = nodes.iterator(); it.hasNext();) { PolicyNodeImpl parent = (PolicyNodeImpl) it.next(); if (Configuration.DEBUG) log.fine("adding policies to " + parent); - for (Iterator it2 = cp.iterator(); it2.hasNext();) + for (OID policy : cp) { - OID policy = (OID) it2.next(); if (Configuration.DEBUG) log.fine("trying to add policy == " + policy); if (policy.toString().equals(ANY_POLICY) @@ -665,7 +661,8 @@ public class PKIXCertPathValidatorImpl } if (match && policies != null) { - List qualifiers = policies.getPolicyQualifierInfos(policy); + List<PolicyQualifierInfo> qualifiers = + policies.getPolicyQualifierInfos(policy); if (qualifiers != null) child.addAllPolicyQualifiers(qualifiers); } @@ -675,13 +672,12 @@ public class PKIXCertPathValidatorImpl throw new CertPathValidatorException("policy tree building failed"); } - private boolean checkExplicitPolicy(int depth, List explicitPolicies) + private boolean checkExplicitPolicy(int depth, List<int[]> explicitPolicies) { if (Configuration.DEBUG) log.fine("checkExplicitPolicy depth=" + depth); - for (Iterator it = explicitPolicies.iterator(); it.hasNext();) + for (int[] i : explicitPolicies) { - int[] i = (int[]) it.next(); int caDepth = i[0]; int limit = i[1]; if (Configuration.DEBUG) diff --git a/gnu/java/security/provider/X509CertificateFactory.java b/gnu/java/security/provider/X509CertificateFactory.java index 644033156..4fc13d238 100644 --- a/gnu/java/security/provider/X509CertificateFactory.java +++ b/gnu/java/security/provider/X509CertificateFactory.java @@ -1,5 +1,5 @@ /* X509CertificateFactory.java -- generates X.509 certificates. - Copyright (C) 2003 Free Software Foundation, Inc. + Copyright (C) 2003, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -76,6 +76,7 @@ public class X509CertificateFactory super(); } + @Override public Certificate engineGenerateCertificate(InputStream inStream) throws CertificateException { @@ -91,10 +92,11 @@ public class X509CertificateFactory } } - public Collection engineGenerateCertificates(InputStream inStream) + @Override + public Collection<? extends Certificate> engineGenerateCertificates(InputStream inStream) throws CertificateException { - LinkedList certs = new LinkedList(); + LinkedList<X509Certificate> certs = new LinkedList<X509Certificate>(); while (true) { try @@ -115,6 +117,7 @@ public class X509CertificateFactory return certs; } + @Override public CRL engineGenerateCRL(InputStream inStream) throws CRLException { try @@ -129,10 +132,11 @@ public class X509CertificateFactory } } - public Collection engineGenerateCRLs(InputStream inStream) + @Override + public Collection<? extends CRL> engineGenerateCRLs(InputStream inStream) throws CRLException { - LinkedList crls = new LinkedList(); + LinkedList<X509CRL> crls = new LinkedList<X509CRL>(); while (true) { try @@ -153,24 +157,28 @@ public class X509CertificateFactory return crls; } - public CertPath engineGenerateCertPath(List certs) + @Override + public CertPath engineGenerateCertPath(List<? extends Certificate> certs) { return new X509CertPath(certs); } + @Override public CertPath engineGenerateCertPath(InputStream in) throws CertificateEncodingException { return new X509CertPath(in); } + @Override public CertPath engineGenerateCertPath(InputStream in, String encoding) throws CertificateEncodingException { return new X509CertPath(in, encoding); } - public Iterator engineGetCertPathEncodings() + @Override + public Iterator<String> engineGetCertPathEncodings() { return X509CertPath.ENCODINGS.iterator(); } diff --git a/gnu/java/security/sig/BaseSignature.java b/gnu/java/security/sig/BaseSignature.java index ef4d87f26..09db44bf8 100644 --- a/gnu/java/security/sig/BaseSignature.java +++ b/gnu/java/security/sig/BaseSignature.java @@ -1,5 +1,5 @@ /* BaseSignature.java -- - Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc. + Copyright (C) 2001, 2002, 2003, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -94,12 +94,15 @@ public abstract class BaseSignature this.md = md; } + @Override public String name() { return schemeName + "-" + md.name(); } - public void setupVerify(Map attributes) throws IllegalArgumentException + @Override + public void setupVerify(Map<String,Object> attributes) + throws IllegalArgumentException { setup(attributes); // do we have a public key? @@ -108,7 +111,9 @@ public abstract class BaseSignature setupForVerification(key); } - public void setupSign(Map attributes) throws IllegalArgumentException + @Override + public void setupSign(Map<String,Object> attributes) + throws IllegalArgumentException { setup(attributes); // do we have a private key? @@ -117,6 +122,7 @@ public abstract class BaseSignature setupForSigning(key); } + @Override public void update(byte b) { if (md == null) @@ -125,6 +131,7 @@ public abstract class BaseSignature md.update(b); } + @Override public void update(byte[] b, int off, int len) { if (md == null) @@ -133,6 +140,7 @@ public abstract class BaseSignature md.update(b, off, len); } + @Override public Object sign() { if (md == null || privateKey == null) @@ -141,6 +149,7 @@ public abstract class BaseSignature return generateSignature(); } + @Override public boolean verify(Object sig) { if (md == null || publicKey == null) @@ -149,6 +158,7 @@ public abstract class BaseSignature return verifySignature(sig); } + @Override public abstract Object clone(); protected abstract void setupForVerification(PublicKey key) @@ -198,7 +208,7 @@ public abstract class BaseSignature getDefaultPRNG().nextBytes(buffer); } - private void setup(Map attributes) + private void setup(Map<String,Object> attributes) { init(); // do we have a Random or SecureRandom, or should we use our own? diff --git a/gnu/java/security/sig/ISignature.java b/gnu/java/security/sig/ISignature.java index be98f9a9b..0fa036618 100644 --- a/gnu/java/security/sig/ISignature.java +++ b/gnu/java/security/sig/ISignature.java @@ -1,5 +1,5 @@ /* ISignature.java -- - Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc. + Copyright (C) 2001, 2002, 2003, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -89,7 +89,8 @@ public interface ISignature * @see #SOURCE_OF_RANDOMNESS * @see #VERIFIER_KEY */ - void setupVerify(Map attributes) throws IllegalArgumentException; + void setupVerify(Map<String,Object> attributes) + throws IllegalArgumentException; /** * Initialises this instance for signature generation. @@ -100,7 +101,8 @@ public interface ISignature * @see #SOURCE_OF_RANDOMNESS * @see #SIGNER_KEY */ - void setupSign(Map attributes) throws IllegalArgumentException; + void setupSign(Map<String,Object> attributes) + throws IllegalArgumentException; /** * Digests one byte of a message for signing or verification purposes. diff --git a/gnu/java/security/sig/SignatureCodecFactory.java b/gnu/java/security/sig/SignatureCodecFactory.java index 0026ad164..7bf04ff40 100644 --- a/gnu/java/security/sig/SignatureCodecFactory.java +++ b/gnu/java/security/sig/SignatureCodecFactory.java @@ -1,5 +1,5 @@ /* SignatureCodecFactory.java -- Factory to instantiate Signature codecs - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -49,7 +49,6 @@ import gnu.java.security.util.FormatUtil; import java.util.Collections; import java.util.HashSet; -import java.util.Iterator; import java.util.Set; /** @@ -57,7 +56,7 @@ import java.util.Set; */ public class SignatureCodecFactory { - private static Set names; + private static Set<String> names; /** Trivial constructor to enforce Singleton pattern. */ private SignatureCodecFactory() @@ -156,17 +155,15 @@ public class SignatureCodecFactory * * @return a {@link Set} of the names of supported signature codec (Strings). */ - public static synchronized final Set getNames() + public static synchronized final Set<String> getNames() { if (names == null) { - HashSet hs = new HashSet(); + HashSet<String> hs = new HashSet<String>(); hs.add(Registry.DSS_SIG + "/" + Registry.RAW_ENCODING_SHORT_NAME); hs.add(Registry.DSS_SIG + "/" + Registry.X509_ENCODING_SORT_NAME); - Set hashNames = HashFactory.getNames(); - for (Iterator it = hashNames.iterator(); it.hasNext();) + for (String mdName : HashFactory.getNames()) { - String mdName = (String) it.next(); String name = Registry.RSA_PKCS1_V1_5_SIG + "-" + mdName; hs.add(name + "/" + Registry.RAW_ENCODING_SHORT_NAME); hs.add(name + "/" + Registry.X509_ENCODING_SORT_NAME); diff --git a/gnu/java/security/sig/SignatureFactory.java b/gnu/java/security/sig/SignatureFactory.java index 6cdaf6544..2ee5dd0a4 100644 --- a/gnu/java/security/sig/SignatureFactory.java +++ b/gnu/java/security/sig/SignatureFactory.java @@ -1,5 +1,5 @@ /* SignatureFactory.java -- - Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc. + Copyright (C) 2001, 2002, 2003, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -51,7 +51,7 @@ import java.util.Set; */ public class SignatureFactory { - private static Set names; + private static Set<String> names; /** Trivial constructor to enforce Singleton pattern. */ private SignatureFactory() @@ -87,11 +87,11 @@ public class SignatureFactory * * @return a {@link Set} of signature-with-appendix scheme names (Strings). */ - public static synchronized final Set getNames() + public static synchronized final Set<String> getNames() { if (names == null) { - HashSet hs = new HashSet(); + HashSet<String> hs = new HashSet<String>(); hs.add(Registry.DSS_SIG); hs.addAll(RSASignatureFactory.getNames()); names = Collections.unmodifiableSet(hs); diff --git a/gnu/java/security/sig/dss/DSSSignature.java b/gnu/java/security/sig/dss/DSSSignature.java index 024521ba4..5e098e337 100644 --- a/gnu/java/security/sig/dss/DSSSignature.java +++ b/gnu/java/security/sig/dss/DSSSignature.java @@ -1,5 +1,5 @@ /* DSSSignature.java -- - Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc. + Copyright (C) 2001, 2002, 2003, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -133,7 +133,7 @@ public class DSSSignature public static final BigInteger[] sign(final DSAPrivateKey k, final byte[] h) { final DSSSignature sig = new DSSSignature(); - final Map attributes = new HashMap(); + final Map<String,Object> attributes = new HashMap<String,Object>(); attributes.put(ISignature.SIGNER_KEY, k); sig.setupSign(attributes); return sig.computeRS(h); @@ -143,7 +143,7 @@ public class DSSSignature Random rnd) { final DSSSignature sig = new DSSSignature(); - final Map attributes = new HashMap(); + final Map<String,Object> attributes = new HashMap<String,Object>(); attributes.put(ISignature.SIGNER_KEY, k); if (rnd != null) attributes.put(ISignature.SOURCE_OF_RANDOMNESS, rnd); @@ -156,7 +156,7 @@ public class DSSSignature IRandom irnd) { final DSSSignature sig = new DSSSignature(); - final Map attributes = new HashMap(); + final Map<String,Object> attributes = new HashMap<String,Object>(); attributes.put(ISignature.SIGNER_KEY, k); if (irnd != null) attributes.put(ISignature.SOURCE_OF_RANDOMNESS, irnd); @@ -169,17 +169,19 @@ public class DSSSignature final BigInteger[] rs) { final DSSSignature sig = new DSSSignature(); - final Map attributes = new HashMap(); + final Map<String,Object> attributes = new HashMap<String,Object>(); attributes.put(ISignature.VERIFIER_KEY, k); sig.setupVerify(attributes); return sig.checkRS(rs, h); } + @Override public Object clone() { return new DSSSignature(this); } + @Override protected void setupForVerification(PublicKey k) throws IllegalArgumentException { @@ -189,6 +191,7 @@ public class DSSSignature this.publicKey = k; } + @Override protected void setupForSigning(PrivateKey k) throws IllegalArgumentException { if (! (k instanceof DSAPrivateKey)) @@ -197,12 +200,14 @@ public class DSSSignature this.privateKey = k; } + @Override protected Object generateSignature() throws IllegalStateException { final BigInteger[] rs = computeRS(md.digest()); return encodeSignature(rs[0], rs[1]); } + @Override protected boolean verifySignature(Object sig) throws IllegalStateException { final BigInteger[] rs = decodeSignature(sig); diff --git a/gnu/java/security/sig/dss/DSSSignatureX509Codec.java b/gnu/java/security/sig/dss/DSSSignatureX509Codec.java index d0a0188fb..f7aeda4f0 100644 --- a/gnu/java/security/sig/dss/DSSSignatureX509Codec.java +++ b/gnu/java/security/sig/dss/DSSSignatureX509Codec.java @@ -1,5 +1,5 @@ /* DSSSignatureX509Codec.java -- X.509 encoder/decoder for DSS signatures - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -130,7 +130,7 @@ public class DSSSignatureX509Codec DERValue derR = new DERValue(DER.INTEGER, rs[0]); DERValue derS = new DERValue(DER.INTEGER, rs[1]); - ArrayList dssSigValue = new ArrayList(2); + ArrayList<DERValue> dssSigValue = new ArrayList<DERValue>(2); dssSigValue.add(derR); dssSigValue.add(derS); DERValue derDssSigValue = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, diff --git a/gnu/java/security/sig/rsa/EMSA_PKCS1_V1_5.java b/gnu/java/security/sig/rsa/EMSA_PKCS1_V1_5.java index 3cddab4aa..fad0ac552 100644 --- a/gnu/java/security/sig/rsa/EMSA_PKCS1_V1_5.java +++ b/gnu/java/security/sig/rsa/EMSA_PKCS1_V1_5.java @@ -1,5 +1,5 @@ /* EMSA_PKCS1_V1_5.java -- - Copyright (C) 2003, 2006 Free Software Foundation, Inc. + Copyright (C) 2003, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -116,9 +116,6 @@ public class EMSA_PKCS1_V1_5 /** The underlying hash function to use with this instance. */ private IMessageDigest hash; - /** The output size of the hash function in octets. */ - private int hLen; // TODO: field not used!!! investigate - /** The DER part of DigestInfo not containing the hash value itself. */ private byte[] prefix; @@ -132,7 +129,6 @@ public class EMSA_PKCS1_V1_5 super(); this.hash = hash; - hLen = hash.hashSize(); final String name = hash.name(); if (name.equals(Registry.MD2_HASH)) prefix = MD2_PREFIX; diff --git a/gnu/java/security/sig/rsa/RSASignatureFactory.java b/gnu/java/security/sig/rsa/RSASignatureFactory.java index ba5121b46..8a49ddc01 100644 --- a/gnu/java/security/sig/rsa/RSASignatureFactory.java +++ b/gnu/java/security/sig/rsa/RSASignatureFactory.java @@ -1,5 +1,5 @@ /* RSASignatureFactory.java -- A Factory class to instantiate RSA Signatures - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -53,7 +53,7 @@ import gnu.java.security.sig.ISignature; */ public class RSASignatureFactory { - private static Set names; + private static Set<String> names; /** * Private constructor to enforce usage through Factory (class) methods. @@ -105,15 +105,15 @@ public class RSASignatureFactory * * @return a {@link Set} of RSA Signature algorithm names (Strings). */ - public static synchronized final Set getNames() + public static synchronized final Set<String> getNames() { if (names == null) { - Set hashNames = HashFactory.getNames(); - HashSet hs = new HashSet(); - for (Iterator it = hashNames.iterator(); it.hasNext();) + Set<String> hashNames = HashFactory.getNames(); + HashSet<String> hs = new HashSet<String>(); + for (Iterator<String> it = hashNames.iterator(); it.hasNext();) { - String mdName = (String) it.next(); + String mdName = it.next(); hs.add(Registry.RSA_PSS_SIG + "-" + mdName); } diff --git a/gnu/java/security/util/IntegerUtil.java b/gnu/java/security/util/IntegerUtil.java deleted file mode 100644 index 106dc4d66..000000000 --- a/gnu/java/security/util/IntegerUtil.java +++ /dev/null @@ -1,109 +0,0 @@ -/* IntegerUtil.java -- JDK 5 Integer methods with 1.4 API - Copyright (C) 2006 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath 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, or (at your option) -any later version. - -GNU Classpath 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 GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -package gnu.java.security.util; - -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * Utility class which offers Integer related methods found in RI's version 5 - * but written with RI's 1.4 API. - */ -public abstract class IntegerUtil -{ - /** Maximum size of our cache of constructed Integers. */ - private static final int CACHE_SIZE = 100; - /** LRU (Least Recently Used) cache, of the last accessed 100 Integers. */ - private static final Map cache = new LinkedHashMap(CACHE_SIZE + 1, 0.75F, true) - { - public boolean removeEldestEntry(Map.Entry entry) - { - return size() > CACHE_SIZE; - } - }; - - /** Trivial private constructor to enforce Singleton usage. */ - private IntegerUtil() - { - super(); - } - - /** - * Similar to {@link Integer#valueOf(String)} except it caches the result in - * a local LRU cache of 100 elements, organized by access order. - * <p> - * This method MUST be used in the gnu.java.security and gnu.javax.crypto - * packages to ensure they would work with a version 1.4 only of the Java - * class library API. - * - * @param aString a string representation of an integer. - * @return the {@link Integer} object representing the designated string. - */ - public static final Integer valueOf(String aString) - { - Integer result; - synchronized (cache) - { - result = (Integer) cache.get(aString); - if (result == null) - { - result = Integer.valueOf(aString); - cache.put(aString, result); - } - } - return result; - } - - /** - * Simulates the <code>valueOf(int)</code> method found in {@link Integer} of - * the RI's version 1.5 using a local LRU cache of 100 elements, organized by - * access order. - * <p> - * This method MUST be used in the gnu.java.security and gnu.javax.crypto - * packages to ensure they would work with a version 1.4 only of the Java - * class library API. - * - * @param anInt a decimal integer. - * @return the {@link Integer} object representing the designated primitive. - */ - public static final Integer valueOf(int anInt) - { - return valueOf(Integer.toString(anInt, 10)); - } -} diff --git a/gnu/java/security/util/PRNG.java b/gnu/java/security/util/PRNG.java index 1bed04dcd..a7d3b4f63 100644 --- a/gnu/java/security/util/PRNG.java +++ b/gnu/java/security/util/PRNG.java @@ -1,5 +1,5 @@ /* PRNG.java -- A Utility methods for default source of randomness - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -72,16 +72,7 @@ public class PRNG IRandom delegate = new MDGenerator(); try { - HashMap map = new HashMap(); - // initialise it with a seed - long t = System.currentTimeMillis(); - byte[] seed = new byte[] { - (byte)(t >>> 56), (byte)(t >>> 48), - (byte)(t >>> 40), (byte)(t >>> 32), - (byte)(t >>> 24), (byte)(t >>> 16), - (byte)(t >>> 8), (byte) t }; - map.put(MDGenerator.SEEED, seed); - delegate.init(map); // default is to use SHA-1 hash + initialiseDelegate(delegate); } catch (Exception x) { @@ -121,15 +112,7 @@ public class PRNG { try { - HashMap map = new HashMap(); - long t = System.currentTimeMillis(); - byte[] seed = new byte[] { - (byte)(t >>> 56), (byte)(t >>> 48), - (byte)(t >>> 40), (byte)(t >>> 32), - (byte)(t >>> 24), (byte)(t >>> 16), - (byte)(t >>> 8), (byte) t }; - map.put(MDGenerator.SEEED, seed); - delegate.init(map); // default is to use SHA-1 hash + initialiseDelegate(delegate); delegate.nextBytes(buffer, offset, length); } catch (Exception y) @@ -138,4 +121,24 @@ public class PRNG } } } + + /** + * Initialise the delegate with a seed. + * + * @param the delegate to initialise. + */ + private static final void initialiseDelegate(IRandom delegate) + { + HashMap<String,Object> map = new HashMap<String,Object>(); + // initialise it with a seed + long t = System.currentTimeMillis(); + byte[] seed = new byte[] { + (byte)(t >>> 56), (byte)(t >>> 48), + (byte)(t >>> 40), (byte)(t >>> 32), + (byte)(t >>> 24), (byte)(t >>> 16), + (byte)(t >>> 8), (byte) t }; + map.put(MDGenerator.SEEED, seed); + delegate.init(map); // default is to use SHA-1 hash + } + } diff --git a/gnu/java/security/util/Sequence.java b/gnu/java/security/util/Sequence.java index 63086d2bd..8069ce891 100644 --- a/gnu/java/security/util/Sequence.java +++ b/gnu/java/security/util/Sequence.java @@ -1,5 +1,5 @@ /* Sequence.java -- a sequence of integers. - Copyright (C) 2004, 2006 Free Software Foundation, Inc. + Copyright (C) 2004, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -45,7 +45,7 @@ import java.util.LinkedList; * A monotonic sequence of integers in the finite field 2<sup>32</sup>. */ public final class Sequence - extends AbstractList + extends AbstractList<Integer> { private final Integer[] sequence; @@ -105,16 +105,17 @@ public final class Sequence } else { - LinkedList l = new LinkedList(); + LinkedList<Integer> l = new LinkedList<Integer>(); for (int i = start; i != end; i += span) l.add(Integer.valueOf(i)); l.add(Integer.valueOf(end)); - sequence = (Integer[]) l.toArray(new Integer[l.size()]); + sequence = l.toArray(new Integer[l.size()]); } } - public Object get(int index) + @Override + public Integer get(int index) { if (index < 0 || index >= size()) throw new IndexOutOfBoundsException("index=" + index + ", size=" + size()); diff --git a/gnu/java/security/util/SimpleList.java b/gnu/java/security/util/SimpleList.java index 15d54c988..2d3bd3525 100644 --- a/gnu/java/security/util/SimpleList.java +++ b/gnu/java/security/util/SimpleList.java @@ -1,5 +1,5 @@ /* SimpleList.java -- simple way to make tuples. - Copyright (C) 2004, 2006 Free Software Foundation, Inc. + Copyright (C) 2004, 2006, 2014 Free Software Foundation, Inc. This file is a part of GNU Classpath. @@ -40,7 +40,6 @@ package gnu.java.security.util; import java.util.AbstractList; import java.util.Collection; -import java.util.Iterator; /** * A simple way to create immutable n-tuples. This class can be created with up @@ -48,7 +47,7 @@ import java.util.Iterator; * of arbitrary size. */ public final class SimpleList - extends AbstractList + extends AbstractList<Object> { private final Object[] elements; @@ -122,14 +121,14 @@ public final class SimpleList * natural order, the created n-tuple will have the order that the elements * are returned by the collection's iterator. * - * @param c The collection. + * @param coll The collection. */ - public SimpleList(Collection c) + public SimpleList(Collection<? extends Object> coll) { - elements = new Object[c.size()]; + elements = new Object[coll.size()]; int i = 0; - for (Iterator it = c.iterator(); it.hasNext() && i < elements.length;) - elements[i++] = it.next(); + for (Object o : coll) + elements[i++] = o; } public int size() diff --git a/gnu/java/security/x509/GnuPKIExtension.java b/gnu/java/security/x509/GnuPKIExtension.java index 8e74b8b24..774a8a55e 100644 --- a/gnu/java/security/x509/GnuPKIExtension.java +++ b/gnu/java/security/x509/GnuPKIExtension.java @@ -1,5 +1,5 @@ /* GnuPKIExtension.java -- interface for GNU PKI extensions. - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -55,5 +55,5 @@ public interface GnuPKIExtension extends X509Extension */ Extension getExtension(OID oid); - Collection getExtensions(); + Collection<Extension> getExtensions(); } diff --git a/gnu/java/security/x509/PolicyNodeImpl.java b/gnu/java/security/x509/PolicyNodeImpl.java index 60d35574d..65dd472c7 100644 --- a/gnu/java/security/x509/PolicyNodeImpl.java +++ b/gnu/java/security/x509/PolicyNodeImpl.java @@ -1,5 +1,5 @@ /* PolicyNodeImpl.java -- An implementation of a policy tree node. - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -56,9 +56,9 @@ public final class PolicyNodeImpl implements PolicyNode // ------------------------------------------------------------------------- private String policy; - private final Set expectedPolicies; - private final Set qualifiers; - private final Set children; + private final Set<String> expectedPolicies; + private final Set<PolicyQualifierInfo> qualifiers; + private final Set<PolicyNode> children; private PolicyNodeImpl parent; private int depth; private boolean critical; @@ -69,9 +69,9 @@ public final class PolicyNodeImpl implements PolicyNode public PolicyNodeImpl() { - expectedPolicies = new HashSet(); - qualifiers = new HashSet(); - children = new HashSet(); + expectedPolicies = new HashSet<String>(); + qualifiers = new HashSet<PolicyQualifierInfo>(); + children = new HashSet<PolicyNode>(); readOnly = false; critical = false; } @@ -90,11 +90,13 @@ public final class PolicyNodeImpl implements PolicyNode children.add(node); } - public Iterator getChildren() + @Override + public Iterator<? extends PolicyNode> getChildren() { return Collections.unmodifiableSet(children).iterator(); } + @Override public int getDepth() { return depth; @@ -107,7 +109,7 @@ public final class PolicyNodeImpl implements PolicyNode this.depth = depth; } - public void addAllExpectedPolicies(Set policies) + public void addAllExpectedPolicies(Set<String> policies) { if (readOnly) throw new IllegalStateException("read only"); @@ -121,24 +123,26 @@ public final class PolicyNodeImpl implements PolicyNode expectedPolicies.add(policy); } - public Set getExpectedPolicies() + @Override + public Set<String> getExpectedPolicies() { return Collections.unmodifiableSet(expectedPolicies); } + @Override public PolicyNode getParent() { return parent; } - public void addAllPolicyQualifiers (Collection qualifiers) + public void addAllPolicyQualifiers (Collection<? extends PolicyQualifierInfo> qualifiers) { - for (Iterator it = qualifiers.iterator(); it.hasNext(); ) + for (Iterator<? extends PolicyQualifierInfo> it = qualifiers.iterator(); it.hasNext(); ) { if (!(it.next() instanceof PolicyQualifierInfo)) throw new IllegalArgumentException ("can only add PolicyQualifierInfos"); } - qualifiers.addAll (qualifiers); + this.qualifiers.addAll (qualifiers); } public void addPolicyQualifier (PolicyQualifierInfo qualifier) @@ -148,11 +152,13 @@ public final class PolicyNodeImpl implements PolicyNode qualifiers.add(qualifier); } - public Set getPolicyQualifiers() + @Override + public Set<? extends PolicyQualifierInfo> getPolicyQualifiers() { return Collections.unmodifiableSet(qualifiers); } + @Override public String getValidPolicy() { return policy; @@ -165,6 +171,7 @@ public final class PolicyNodeImpl implements PolicyNode this.policy = policy; } + @Override public boolean isCritical() { return critical; @@ -182,7 +189,7 @@ public final class PolicyNodeImpl implements PolicyNode if (readOnly) return; readOnly = true; - for (Iterator it = getChildren(); it.hasNext(); ) + for (Iterator<? extends PolicyNode> it = getChildren(); it.hasNext(); ) ((PolicyNodeImpl) it.next()).setReadOnly(); } @@ -205,7 +212,7 @@ public final class PolicyNodeImpl implements PolicyNode buf.append(expectedPolicies); buf.append(") (children ("); final String nl = System.getProperty("line.separator"); - for (Iterator it = getChildren(); it.hasNext(); ) + for (Iterator<? extends PolicyNode> it = getChildren(); it.hasNext(); ) { buf.append(nl); buf.append(it.next().toString()); diff --git a/gnu/java/security/x509/X500DistinguishedName.java b/gnu/java/security/x509/X500DistinguishedName.java index e2e05c57e..ab7f99aa9 100644 --- a/gnu/java/security/x509/X500DistinguishedName.java +++ b/gnu/java/security/x509/X500DistinguishedName.java @@ -1,5 +1,5 @@ /* X500DistinguishedName.java -- X.500 distinguished name. - Copyright (C) 2004, 2006 Free Software Foundation, Inc. + Copyright (C) 2004, 2006, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -83,8 +83,8 @@ public class X500DistinguishedName implements Principal public static final OID DC = new OID("0.9.2342.19200300.100.1.25"); public static final OID UID = new OID("0.9.2342.19200300.100.1.1"); - private List components; - private Map currentRdn; + private List<Map<OID,String>> components; + private Map<OID,String> currentRdn; private boolean fixed; private String stringRep; private byte[] encoded; @@ -94,8 +94,8 @@ public class X500DistinguishedName implements Principal public X500DistinguishedName() { - components = new LinkedList(); - currentRdn = new LinkedHashMap(); + components = new LinkedList<Map<OID,String>>(); + currentRdn = new LinkedHashMap<OID,String>(); components.add(currentRdn); } @@ -135,7 +135,7 @@ public class X500DistinguishedName implements Principal public void newRelativeDistinguishedName() { if (fixed || currentRdn.isEmpty()) return; - currentRdn = new LinkedHashMap(); + currentRdn = new LinkedHashMap<OID,String>(); components.add(currentRdn); } @@ -147,19 +147,19 @@ public class X500DistinguishedName implements Principal public int countComponents() { int count = 0; - for (Iterator it = components.iterator(); it.hasNext(); ) + for (Iterator<Map<OID,String>> it = components.iterator(); it.hasNext(); ) { - count += ((Map) it.next()).size(); + count += it.next().size(); } return count; } public boolean containsComponent(OID oid, String value) { - for (Iterator it = components.iterator(); it.hasNext(); ) + for (Iterator<Map<OID,String>> it = components.iterator(); it.hasNext(); ) { - Map rdn = (Map) it.next(); - String s = (String) rdn.get(oid); + Map<OID,String> rdn = it.next(); + String s = rdn.get(oid); if (s == null) continue; if (compressWS(value).equalsIgnoreCase(compressWS(s))) @@ -170,11 +170,11 @@ public class X500DistinguishedName implements Principal public String getComponent(OID oid) { - for (Iterator it = components.iterator(); it.hasNext(); ) + for (Iterator<Map<OID,String>> it = components.iterator(); it.hasNext(); ) { - Map rdn = (Map) it.next(); + Map<OID,String> rdn = it.next(); if (rdn.containsKey(oid)) - return (String) rdn.get(oid); + return rdn.get(oid); } return null; } @@ -183,7 +183,7 @@ public class X500DistinguishedName implements Principal { if (rdn >= size()) return null; - return (String) ((Map) components.get(rdn)).get(oid); + return components.get(rdn).get(oid); } public void putComponent(OID oid, String value) @@ -234,26 +234,26 @@ public class X500DistinguishedName implements Principal { if (fixed) return; fixed = true; - List newComps = new ArrayList(components.size()); - for (Iterator it = components.iterator(); it.hasNext(); ) + List<Map<OID,String>> newComps = + new ArrayList<Map<OID,String>>(components.size()); + for (Iterator<Map<OID,String>> it = components.iterator(); it.hasNext(); ) { - Map rdn = (Map) it.next(); + Map<OID,String> rdn = it.next(); rdn = Collections.unmodifiableMap(rdn); newComps.add(rdn); } components = Collections.unmodifiableList(newComps); - currentRdn = Collections.EMPTY_MAP; + currentRdn = Collections.emptyMap(); } public int hashCode() { int sum = 0; - for (Iterator it = components.iterator(); it.hasNext(); ) + for (Iterator<Map<OID,String>> it = components.iterator(); it.hasNext(); ) { - Map m = (Map) it.next(); - for (Iterator it2 = m.entrySet().iterator(); it2.hasNext(); ) + Map<OID,String> m = it.next(); + for (Map.Entry<OID,String> e : m.entrySet()) { - Map.Entry e = (Map.Entry) it2.next(); sum += e.getKey().hashCode(); sum += e.getValue().hashCode(); } @@ -269,12 +269,11 @@ public class X500DistinguishedName implements Principal return false; for (int i = 0; i < size(); i++) { - Map m = (Map) components.get(i); - for (Iterator it2 = m.entrySet().iterator(); it2.hasNext(); ) + Map<OID,String> m = components.get(i); + for (Map.Entry<OID,String> e : m.entrySet()) { - Map.Entry e = (Map.Entry) it2.next(); - OID oid = (OID) e.getKey(); - String v1 = (String) e.getValue(); + OID oid = e.getKey(); + String v1 = e.getValue(); String v2 = ((X500DistinguishedName) o).getComponent(oid, i); if (!compressWS(v1).equalsIgnoreCase(compressWS(v2))) return false; @@ -288,14 +287,15 @@ public class X500DistinguishedName implements Principal if (fixed && stringRep != null) return stringRep; CPStringBuilder str = new CPStringBuilder(); - for (Iterator it = components.iterator(); it.hasNext(); ) + for (Iterator<Map<OID,String>> it = components.iterator(); it.hasNext(); ) { - Map m = (Map) it.next(); - for (Iterator it2 = m.entrySet().iterator(); it2.hasNext(); ) + Map<OID,String> m = it.next(); + for (Iterator<Map.Entry<OID,String>> it2 = m.entrySet().iterator(); + it2.hasNext(); ) { - Map.Entry entry = (Map.Entry) it2.next(); - OID oid = (OID) entry.getKey(); - String value = (String) entry.getValue(); + Map.Entry<OID,String> entry = it2.next(); + OID oid = entry.getKey(); + String value = entry.getValue(); if (oid.equals(CN)) str.append("CN"); else if (oid.equals(C)) @@ -334,18 +334,16 @@ public class X500DistinguishedName implements Principal if (fixed && encoded != null) return (byte[]) encoded.clone(); - ArrayList name = new ArrayList(components.size()); - for (Iterator it = components.iterator(); it.hasNext(); ) + ArrayList<DERValue> name = new ArrayList<DERValue>(components.size()); + for (Map<OID,String> m : components) { - Map m = (Map) it.next(); if (m.isEmpty()) continue; - Set rdn = new HashSet(); - for (Iterator it2 = m.entrySet().iterator(); it2.hasNext(); ) + Set<DERValue> rdn = new HashSet<DERValue>(); + for (Map.Entry<OID,String> e : m.entrySet()) { - Map.Entry e = (Map.Entry) it2.next(); - ArrayList atav = new ArrayList(2); + ArrayList<DERValue> atav = new ArrayList<DERValue>(2); atav.add(new DERValue(DER.OBJECT_IDENTIFIER, e.getKey())); atav.add(new DERValue(DER.UTF8_STRING, e.getValue())); rdn.add(new DERValue(DER.SEQUENCE|DER.CONSTRUCTED, atav)); diff --git a/gnu/java/security/x509/X509CRL.java b/gnu/java/security/x509/X509CRL.java index 518edaa24..9e1ed0f5c 100644 --- a/gnu/java/security/x509/X509CRL.java +++ b/gnu/java/security/x509/X509CRL.java @@ -1,5 +1,5 @@ /* X509CRL.java -- X.509 certificate revocation list. - Copyright (C) 2003, 2004, 2010 Free Software Foundation, Inc. + Copyright (C) 2003, 2004, 2010, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -63,7 +63,6 @@ import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.Set; import java.util.logging.Logger; @@ -92,12 +91,11 @@ public class X509CRL extends java.security.cert.X509CRL private byte[] tbsCRLBytes; private int version; private OID algId; - private byte[] algParams; private Date thisUpdate; private Date nextUpdate; private X500DistinguishedName issuerDN; - private HashMap revokedCerts; - private HashMap extensions; + private HashMap<BigInteger,X509CRLEntry> revokedCerts; + private HashMap<OID,Extension> extensions; private OID sigAlg; private byte[] sigAlgParams; @@ -117,8 +115,8 @@ public class X509CRL extends java.security.cert.X509CRL public X509CRL(InputStream encoded) throws CRLException, IOException { super(); - revokedCerts = new HashMap(); - extensions = new HashMap(); + revokedCerts = new HashMap<BigInteger,X509CRLEntry>(); + extensions = new HashMap<OID,Extension>(); try { parse(encoded); @@ -150,11 +148,13 @@ public class X509CRL extends java.security.cert.X509CRL return revokedCerts.hashCode(); } + @Override public byte[] getEncoded() throws CRLException { return (byte[]) encoded.clone(); } + @Override public void verify(PublicKey key) throws CRLException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException @@ -163,6 +163,7 @@ public class X509CRL extends java.security.cert.X509CRL doVerify(sig, key); } + @Override public void verify(PublicKey key, String provider) throws CRLException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException @@ -171,11 +172,13 @@ public class X509CRL extends java.security.cert.X509CRL doVerify(sig, key); } + @Override public int getVersion() { return version; } + @Override public Principal getIssuerDN() { return issuerDN; @@ -186,11 +189,13 @@ public class X509CRL extends java.security.cert.X509CRL return new X500Principal(issuerDN.getDer()); } + @Override public Date getThisUpdate() { return (Date) thisUpdate.clone(); } + @Override public Date getNextUpdate() { if (nextUpdate != null) @@ -198,26 +203,31 @@ public class X509CRL extends java.security.cert.X509CRL return null; } + @Override public java.security.cert.X509CRLEntry getRevokedCertificate(BigInteger serialNo) { - return (java.security.cert.X509CRLEntry) revokedCerts.get(serialNo); + return revokedCerts.get(serialNo); } - public Set getRevokedCertificates() + @Override + public Set<? extends X509CRLEntry> getRevokedCertificates() { - return Collections.unmodifiableSet(new HashSet(revokedCerts.values())); + return Collections.unmodifiableSet(new HashSet<X509CRLEntry>(revokedCerts.values())); } + @Override public byte[] getTBSCertList() throws CRLException { return (byte[]) tbsCRLBytes.clone(); } + @Override public byte[] getSignature() { return (byte[]) rawSig.clone(); } + @Override public String getSigAlgName() { if (sigAlg.equals(ID_DSA_WITH_SHA1)) @@ -231,11 +241,13 @@ public class X509CRL extends java.security.cert.X509CRL return "unknown"; } + @Override public String getSigAlgOID() { return sigAlg.toString(); } + @Override public byte[] getSigAlgParams() { if (sigAlgParams != null) @@ -248,33 +260,30 @@ public class X509CRL extends java.security.cert.X509CRL public boolean hasUnsupportedCriticalExtension() { - for (Iterator it = extensions.values().iterator(); it.hasNext(); ) + for (Extension e : extensions.values()) { - Extension e = (Extension) it.next(); if (e.isCritical() && !e.isSupported()) return true; } return false; } - public Set getCriticalExtensionOIDs() + public Set<String> getCriticalExtensionOIDs() { - HashSet s = new HashSet(); - for (Iterator it = extensions.values().iterator(); it.hasNext(); ) + HashSet<String> s = new HashSet<String>(); + for (Extension e : extensions.values()) { - Extension e = (Extension) it.next(); if (e.isCritical()) s.add(e.getOid().toString()); } return Collections.unmodifiableSet(s); } - public Set getNonCriticalExtensionOIDs() + public Set<String> getNonCriticalExtensionOIDs() { - HashSet s = new HashSet(); - for (Iterator it = extensions.values().iterator(); it.hasNext(); ) + HashSet<String> s = new HashSet<String>(); + for (Extension e : extensions.values()) { - Extension e = (Extension) it.next(); if (!e.isCritical()) s.add(e.getOid().toString()); } @@ -294,12 +303,14 @@ public class X509CRL extends java.security.cert.X509CRL // GnuPKIExtension method. // ------------------------------------------------------------------------- + @Override public Extension getExtension(OID oid) { - return (Extension) extensions.get(oid); + return extensions.get(oid); } - public Collection getExtensions() + @Override + public Collection<Extension> getExtensions() { return extensions.values(); } @@ -307,6 +318,7 @@ public class X509CRL extends java.security.cert.X509CRL // CRL methods. // ------------------------------------------------------------------------- + @Override public String toString() { return X509CRL.class.getName(); @@ -382,7 +394,6 @@ public class X509CRL extends java.security.cert.X509CRL val = der.read(); if (Configuration.DEBUG) log.fine("read parameters len == " + val.getEncodedLength()); - algParams = val.getEncoded(); if (val.isConstructed()) in.skip(val.getLength()); } diff --git a/gnu/java/security/x509/X509CRLEntry.java b/gnu/java/security/x509/X509CRLEntry.java index 64adf7f69..b54f8eae6 100644 --- a/gnu/java/security/x509/X509CRLEntry.java +++ b/gnu/java/security/x509/X509CRLEntry.java @@ -1,5 +1,5 @@ /* X509CRLEntry.java -- an entry in a X.509 CRL. - Copyright (C) 2003, 2004, 2010 Free Software Foundation, Inc. + Copyright (C) 2003, 2004, 2010, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -52,7 +52,6 @@ import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.Set; import java.util.logging.Logger; @@ -78,7 +77,7 @@ class X509CRLEntry extends java.security.cert.X509CRLEntry private Date revocationDate; /** The CRL entry extensions. */ - private HashMap extensions; + private HashMap<OID,Extension> extensions; // Constructor. // ------------------------------------------------------------------------ @@ -96,7 +95,7 @@ class X509CRLEntry extends java.security.cert.X509CRLEntry throws CRLException, IOException { super(); - extensions = new HashMap(); + extensions = new HashMap<OID,Extension>(); try { parse(version, encoded); @@ -114,6 +113,7 @@ class X509CRLEntry extends java.security.cert.X509CRLEntry // X509CRLEntry methods. // ------------------------------------------------------------------------ + @Override public boolean equals(Object o) { if (!(o instanceof X509CRLEntry)) @@ -122,31 +122,37 @@ class X509CRLEntry extends java.security.cert.X509CRLEntry ((X509CRLEntry) o).getRevocationDate().equals(revocationDate); } + @Override public int hashCode() { return serialNo.hashCode(); } + @Override public byte[] getEncoded() throws CRLException { return (byte[]) encoded.clone(); } + @Override public BigInteger getSerialNumber() { return serialNo; } + @Override public Date getRevocationDate() { return (Date) revocationDate.clone(); } + @Override public boolean hasExtensions() { return ! extensions.isEmpty(); } + @Override public String toString() { return "X509CRLEntry serial=" + serialNo + " revocation date=" @@ -158,33 +164,30 @@ class X509CRLEntry extends java.security.cert.X509CRLEntry public boolean hasUnsupportedCriticalExtension() { - for (Iterator it = extensions.values().iterator(); it.hasNext(); ) + for (Extension e : extensions.values()) { - Extension e = (Extension) it.next(); if (e.isCritical() && !e.isSupported()) return true; } return false; } - public Set getCriticalExtensionOIDs() + public Set<String> getCriticalExtensionOIDs() { - HashSet s = new HashSet(); - for (Iterator it = extensions.values().iterator(); it.hasNext(); ) + HashSet<String> s = new HashSet<String>(); + for (Extension e : extensions.values()) { - Extension e = (Extension) it.next(); if (e.isCritical()) s.add(e.getOid().toString()); } return Collections.unmodifiableSet(s); } - public Set getNonCriticalExtensionOIDs() + public Set<String> getNonCriticalExtensionOIDs() { - HashSet s = new HashSet(); - for (Iterator it = extensions.values().iterator(); it.hasNext(); ) + HashSet<String> s = new HashSet<String>(); + for (Extension e : extensions.values()) { - Extension e = (Extension) it.next(); if (!e.isCritical()) s.add(e.getOid().toString()); } @@ -204,12 +207,14 @@ class X509CRLEntry extends java.security.cert.X509CRLEntry // GnuPKIExtension method. // ------------------------------------------------------------------------- + @Override public Extension getExtension(OID oid) { - return (Extension) extensions.get(oid); + return extensions.get(oid); } - public Collection getExtensions() + @Override + public Collection<Extension> getExtensions() { return extensions.values(); } diff --git a/gnu/java/security/x509/X509CRLSelectorImpl.java b/gnu/java/security/x509/X509CRLSelectorImpl.java index 582d18583..c8f25d58d 100644 --- a/gnu/java/security/x509/X509CRLSelectorImpl.java +++ b/gnu/java/security/x509/X509CRLSelectorImpl.java @@ -1,5 +1,5 @@ /* X509CRLSelectorImpl.java -- implementation of an X509CRLSelector. - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -48,7 +48,6 @@ import java.security.cert.X509CRL; import java.util.Collection; import java.util.Collections; import java.util.HashSet; -import java.util.Iterator; import java.util.Set; import javax.security.auth.x500.X500Principal; @@ -63,14 +62,14 @@ public class X509CRLSelectorImpl implements CRLSelector // Fields. // ------------------------------------------------------------------------- - private Set issuerNames; + private Set<X500DistinguishedName> issuerNames; // Constructor. // ------------------------------------------------------------------------- public X509CRLSelectorImpl() { - issuerNames = new HashSet(); + issuerNames = new HashSet<X500DistinguishedName>(); } // Instance methods. @@ -89,18 +88,19 @@ public class X509CRLSelectorImpl implements CRLSelector public void addIssuerName(Principal issuerName) throws IOException { if (issuerName instanceof X500DistinguishedName) - issuerNames.add(issuerName); + issuerNames.add((X500DistinguishedName) issuerName); else if (issuerName instanceof X500Principal) issuerNames.add(new X500DistinguishedName(((X500Principal) issuerName).getEncoded())); else issuerNames.add(new X500DistinguishedName(issuerName.getName())); } - public Collection getIssuerNames() + public Collection<X500DistinguishedName> getIssuerNames() { return Collections.unmodifiableSet(issuerNames); } + @Override public Object clone() { X509CRLSelectorImpl copy = new X509CRLSelectorImpl(); @@ -108,6 +108,7 @@ public class X509CRLSelectorImpl implements CRLSelector return copy; } + @Override public boolean match(CRL crl) { if (!(crl instanceof X509CRL)) @@ -122,9 +123,8 @@ public class X509CRLSelectorImpl implements CRLSelector thisName = new X500DistinguishedName(((X500Principal) p).getEncoded()); else thisName = new X500DistinguishedName(p.getName()); - for (Iterator it = issuerNames.iterator(); it.hasNext(); ) + for (X500DistinguishedName name : issuerNames) { - X500DistinguishedName name = (X500DistinguishedName) it.next(); if (thisName.equals(name)) return true; } diff --git a/gnu/java/security/x509/X509CertPath.java b/gnu/java/security/x509/X509CertPath.java index e8ed6bf35..d2e12d269 100644 --- a/gnu/java/security/x509/X509CertPath.java +++ b/gnu/java/security/x509/X509CertPath.java @@ -1,5 +1,5 @@ /* X509CertPath.java -- an X.509 certificate path. - Copyright (C) 2004 Free Software Fonudation, Inc. + Copyright (C) 2004, 2014 Free Software Fonudation, Inc. This file is part of GNU Classpath. @@ -71,25 +71,25 @@ public class X509CertPath extends CertPath // Fields. // ------------------------------------------------------------------------- - public static final List ENCODINGS = Collections.unmodifiableList( + public static final List<String> ENCODINGS = Collections.unmodifiableList( Arrays.asList(new String[] { "PkiPath", "PKCS7" })); private static final OID PKCS7_SIGNED_DATA = new OID("1.2.840.113549.1.7.2"); private static final OID PKCS7_DATA = new OID("1.2.840.113549.1.7.1"); /** The certificate path. */ - private List path; + private List<Certificate> path; /** The cached PKCS #7 encoded bytes. */ - private byte[] pkcs_encoded; + private byte[] pkcsEncoded; /** The cached PkiPath encoded bytes. */ - private byte[] pki_encoded; + private byte[] pkiEncoded; // Constructor. // ------------------------------------------------------------------------- - public X509CertPath(List path) + public X509CertPath(List<? extends Certificate> path) { super("X.509"); this.path = Collections.unmodifiableList(path); @@ -97,7 +97,7 @@ public class X509CertPath extends CertPath public X509CertPath(InputStream in) throws CertificateEncodingException { - this(in, (String) ENCODINGS.get(0)); + this(in, ENCODINGS.get(0)); } public X509CertPath(InputStream in, String encoding) @@ -117,53 +117,53 @@ public class X509CertPath extends CertPath // Instance methods. // ------------------------------------------------------------------------- - public List getCertificates() + public List<Certificate> getCertificates() { return path; // already unmodifiable } public byte[] getEncoded() throws CertificateEncodingException { - return getEncoded((String) ENCODINGS.get(0)); + return getEncoded(ENCODINGS.get(0)); } public byte[] getEncoded(String encoding) throws CertificateEncodingException { if (encoding.equalsIgnoreCase("PkiPath")) { - if (pki_encoded == null) + if (pkiEncoded == null) { try { - pki_encoded = encodePki(); + pkiEncoded = encodePki(); } catch (IOException ioe) { throw new CertificateEncodingException(); } } - return (byte[]) pki_encoded.clone(); + return (byte[]) pkiEncoded.clone(); } else if (encoding.equalsIgnoreCase("PKCS7")) { - if (pkcs_encoded == null) + if (pkcsEncoded == null) { try { - pkcs_encoded = encodePKCS(); + pkcsEncoded = encodePKCS(); } catch (IOException ioe) { throw new CertificateEncodingException(); } } - return (byte[]) pkcs_encoded.clone(); + return (byte[]) pkcsEncoded.clone(); } else throw new CertificateEncodingException("unknown encoding: " + encoding); } - public Iterator getEncodings() + public Iterator<String> getEncodings() { return ENCODINGS.iterator(); // already unmodifiable } @@ -233,7 +233,7 @@ public class X509CertPath extends CertPath else throw new CertificateEncodingException("unknown encoding: " + encoding); - LinkedList certs = new LinkedList(); + LinkedList<Certificate> certs = new LinkedList<Certificate>(); int len = 0; while (len < path.getLength()) { @@ -259,9 +259,9 @@ public class X509CertPath extends CertPath synchronized (path) { ByteArrayOutputStream out = new ByteArrayOutputStream(); - for (Iterator i = path.iterator(); i.hasNext(); ) + for (Iterator<Certificate> i = path.iterator(); i.hasNext(); ) { - out.write(((Certificate) i.next()).getEncoded()); + out.write(i.next().getEncoded()); } byte[] b = out.toByteArray(); DERValue val = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, @@ -275,7 +275,7 @@ public class X509CertPath extends CertPath { synchronized (path) { - ArrayList signedData = new ArrayList(5); + ArrayList<DERValue> signedData = new ArrayList<DERValue>(5); signedData.add(new DERValue(DER.INTEGER, BigInteger.ONE)); signedData.add(new DERValue(DER.CONSTRUCTED | DER.SET, Collections.EMPTY_SET)); @@ -283,9 +283,9 @@ public class X509CertPath extends CertPath Collections.singletonList( new DERValue(DER.OBJECT_IDENTIFIER, PKCS7_DATA)))); ByteArrayOutputStream out = new ByteArrayOutputStream(); - for (Iterator i = path.iterator(); i.hasNext(); ) + for (Iterator<Certificate> i = path.iterator(); i.hasNext(); ) { - out.write(((Certificate) i.next()).getEncoded()); + out.write(i.next().getEncoded()); } byte[] b = out.toByteArray(); signedData.add(new DERValue(DER.CONSTRUCTED | DER.CONTEXT, @@ -293,7 +293,7 @@ public class X509CertPath extends CertPath DERValue sdValue = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, signedData); - ArrayList contentInfo = new ArrayList(2); + ArrayList<DERValue> contentInfo = new ArrayList<DERValue>(2); contentInfo.add(new DERValue(DER.OBJECT_IDENTIFIER, PKCS7_SIGNED_DATA)); contentInfo.add(new DERValue(DER.CONSTRUCTED | DER.CONTEXT, sdValue)); return new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, diff --git a/gnu/java/security/x509/X509CertSelectorImpl.java b/gnu/java/security/x509/X509CertSelectorImpl.java index 5201a76b9..e7c7ff81b 100644 --- a/gnu/java/security/x509/X509CertSelectorImpl.java +++ b/gnu/java/security/x509/X509CertSelectorImpl.java @@ -1,5 +1,5 @@ /* X509CertSelectorImpl.java -- implementation of an X509CertSelector. - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -61,16 +61,16 @@ public class X509CertSelectorImpl implements CertSelector // Fields. // ------------------------------------------------------------------------- - private Set issuerNames; - private Set subjectNames; + private Set<X500DistinguishedName> issuerNames; + private Set<X500DistinguishedName> subjectNames; // Constructor. // ------------------------------------------------------------------------- public X509CertSelectorImpl() { - issuerNames = new HashSet(); - subjectNames = new HashSet(); + issuerNames = new HashSet<X500DistinguishedName>(); + subjectNames = new HashSet<X500DistinguishedName>(); } // Instance methods. @@ -89,14 +89,14 @@ public class X509CertSelectorImpl implements CertSelector public void addIssuerName(Principal issuerName) throws IOException { if (issuerName instanceof X500DistinguishedName) - issuerNames.add(issuerName); + issuerNames.add((X500DistinguishedName) issuerName); else if (issuerName instanceof X500Principal) issuerNames.add(new X500DistinguishedName(((X500Principal) issuerName).getEncoded())); else issuerNames.add(new X500DistinguishedName(issuerName.getName())); } - public Collection getIssuerNames() + public Collection<X500DistinguishedName> getIssuerNames() { return Collections.unmodifiableSet(issuerNames); } @@ -114,18 +114,19 @@ public class X509CertSelectorImpl implements CertSelector public void addSubjectName(Principal subjectName) throws IOException { if (subjectName instanceof X500DistinguishedName) - subjectNames.add(subjectName); + subjectNames.add((X500DistinguishedName) subjectName); else if (subjectName instanceof X500Principal) subjectNames.add(new X500DistinguishedName(((X500Principal) subjectName).getEncoded())); else subjectNames.add(new X500DistinguishedName(subjectName.getName())); } - public Collection getSubjectNames() + public Collection<X500DistinguishedName> getSubjectNames() { return Collections.unmodifiableSet(subjectNames); } + @Override public Object clone() { X509CertSelectorImpl copy = new X509CertSelectorImpl(); @@ -134,6 +135,7 @@ public class X509CertSelectorImpl implements CertSelector return copy; } + @Override public boolean match(Certificate cert) { if (!(cert instanceof X509Certificate)) @@ -154,9 +156,9 @@ public class X509CertSelectorImpl implements CertSelector matchIssuer = true; else { - for (Iterator it = issuerNames.iterator(); it.hasNext(); ) + for (Iterator<X500DistinguishedName> it = issuerNames.iterator(); it.hasNext(); ) { - X500DistinguishedName name = (X500DistinguishedName) it.next(); + X500DistinguishedName name = it.next(); if (thisName.equals(name)) { matchIssuer = true; @@ -177,9 +179,9 @@ public class X509CertSelectorImpl implements CertSelector matchSubject = true; else { - for (Iterator it = subjectNames.iterator(); it.hasNext(); ) + for (Iterator<X500DistinguishedName> it = subjectNames.iterator(); it.hasNext(); ) { - X500DistinguishedName name = (X500DistinguishedName) it.next(); + X500DistinguishedName name = it.next(); if (thisName.equals(name)) { matchSubject = true; diff --git a/gnu/java/security/x509/X509Certificate.java b/gnu/java/security/x509/X509Certificate.java index 14c565264..c7856bd0c 100644 --- a/gnu/java/security/x509/X509Certificate.java +++ b/gnu/java/security/x509/X509Certificate.java @@ -1,5 +1,5 @@ /* X509Certificate.java -- X.509 certificate. - Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc. + Copyright (C) 2003, 2004, 2006, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -84,7 +84,6 @@ import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -389,9 +388,8 @@ public class X509Certificate extends java.security.cert.X509Certificate public boolean hasUnsupportedCriticalExtension() { - for (Iterator it = extensions.values().iterator(); it.hasNext(); ) + for (Extension e : extensions.values()) { - Extension e = (Extension) it.next(); if (e.isCritical() && !e.isSupported()) return true; } @@ -433,12 +431,14 @@ public class X509Certificate extends java.security.cert.X509Certificate // GnuPKIExtension method. // ------------------------------------------------------------------------- + @Override public Extension getExtension(OID oid) { - return (Extension) extensions.get(oid); + return extensions.get(oid); } - public Collection getExtensions() + @Override + public Collection<Extension> getExtensions() { return extensions.values(); } @@ -502,9 +502,9 @@ public class X509Certificate extends java.security.cert.X509Certificate out.println(" issuerUniqueId = " + issuerUniqueId + ";"); out.println(" subjectUniqueId = " + subjectUniqueId + ";"); out.println(" extensions = {"); - for (Iterator it = extensions.values().iterator(); it.hasNext(); ) + for (Extension e : extensions.values()) { - out.println(" " + it.next()); + out.println(" " + e); } out.println(" }"); out.println(" }"); @@ -520,6 +520,7 @@ public class X509Certificate extends java.security.cert.X509Certificate return subjectKey; } + @Override public boolean equals(Object other) { if (!(other instanceof X509Certificate)) diff --git a/gnu/java/security/x509/ext/BasicConstraints.java b/gnu/java/security/x509/ext/BasicConstraints.java index d8f5c6158..52d9f39cd 100644 --- a/gnu/java/security/x509/ext/BasicConstraints.java +++ b/gnu/java/security/x509/ext/BasicConstraints.java @@ -1,5 +1,5 @@ /* BasicConstraints.java -- the basic constraints extension. - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -111,7 +111,7 @@ public class BasicConstraints extends Extension.Value { if (encoded == null) { - List bc = new ArrayList (2); + List<DERValue> bc = new ArrayList<DERValue> (2); bc.add (new DERValue (DER.BOOLEAN, Boolean.valueOf (ca))); if (pathLenConstraint >= 0) bc.add (new DERValue (DER.INTEGER, diff --git a/gnu/java/security/x509/ext/CertificatePolicies.java b/gnu/java/security/x509/ext/CertificatePolicies.java index 874b8eeeb..9b36485b2 100644 --- a/gnu/java/security/x509/ext/CertificatePolicies.java +++ b/gnu/java/security/x509/ext/CertificatePolicies.java @@ -1,5 +1,5 @@ /* CertificatePolicies.java -- certificate policy extension. - Copyright (C) 2004, 2006 Free Software Foundation, Inc. + Copyright (C) 2004, 2006, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -113,24 +113,49 @@ public class CertificatePolicies extends Extension.Value public CertificatePolicies (final List<OID> policies, final Map<OID, List<PolicyQualifierInfo>> policyQualifierInfos) { - for (Iterator it = policies.iterator(); it.hasNext(); ) - if (!(it.next() instanceof OID)) - throw new IllegalArgumentException ("policies must be OIDs"); - for (Iterator it = policyQualifierInfos.entrySet().iterator(); it.hasNext();) + List<OID> polCopy = new ArrayList<OID>(policies.size()); + try { - Map.Entry e = (Map.Entry) it.next(); - if (!(e.getKey() instanceof OID) || !policies.contains (e.getKey())) - throw new IllegalArgumentException - ("policyQualifierInfos keys must be OIDs"); - if (!(e.getValue() instanceof List)) - throw new IllegalArgumentException - ("policyQualifierInfos values must be Lists of PolicyQualifierInfos"); - for (Iterator it2 = ((List) e.getValue()).iterator(); it.hasNext(); ) - if (!(it2.next() instanceof PolicyQualifierInfo)) + for (OID o : policies) { polCopy.add(o); } + } + catch (ClassCastException e) + { + throw new IllegalArgumentException ("policies must be OIDs", e); + } + for (Map.Entry<OID,List<PolicyQualifierInfo>> e : policyQualifierInfos.entrySet()) + { + try + { + if (!policies.contains (e.getKey())) + throw new IllegalArgumentException + ("policyQualifierInfos keys must be OIDs"); + } + catch (ClassCastException cce) + { + throw new IllegalArgumentException + ("policyQualifierInfos keys must be OIDs", cce); + } + try + { + e.getValue(); + } + catch (ClassCastException cce) + { + throw new IllegalArgumentException + ("policyQualifierInfos values must be Lists of PolicyQualifierInfos", cce); + } + try + { + for (Iterator<PolicyQualifierInfo> i = e.getValue().iterator(); + i.hasNext(); i.next()); + } + catch (ClassCastException cce) + { throw new IllegalArgumentException - ("policyQualifierInfos values must be Lists of PolicyQualifierInfos"); + ("policyQualifierInfos values must be Lists of PolicyQualifierInfos", cce); + } } - this.policies = Collections.unmodifiableList (new ArrayList<OID>(policies)); + this.policies = Collections.unmodifiableList (polCopy); this.policyQualifierInfos = Collections.unmodifiableMap (new HashMap<OID, List<PolicyQualifierInfo>>(policyQualifierInfos)); } diff --git a/gnu/java/security/x509/ext/PolicyMappings.java b/gnu/java/security/x509/ext/PolicyMappings.java index 0493ed89d..eeac340d3 100644 --- a/gnu/java/security/x509/ext/PolicyMappings.java +++ b/gnu/java/security/x509/ext/PolicyMappings.java @@ -1,5 +1,5 @@ /* PolicyMappings.java -- policy mappings extension. - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2014 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -56,7 +56,7 @@ public class PolicyMappings extends Extension.Value public static final OID ID = new OID("2.5.29.33"); - private final Map mappings; + private final Map<OID,OID> mappings; // Constructor. // ------------------------------------------------------------------------- @@ -69,7 +69,7 @@ public class PolicyMappings extends Extension.Value if (!maps.isConstructed()) throw new IOException("malformed PolicyMappings"); int len = 0; - HashMap _mappings = new HashMap(); + HashMap<OID,OID> _mappings = new HashMap<OID,OID>(); while (len < maps.getLength()) { DERValue map = der.read(); @@ -94,7 +94,7 @@ public class PolicyMappings extends Extension.Value public OID getSubjectDomainPolicy(OID issuerDomainPolicy) { - return (OID) mappings.get(issuerDomainPolicy); + return mappings.get(issuerDomainPolicy); } public String toString() |