From 64089cc9f030d8ef7972adb5d117e0b23f47d62b Mon Sep 17 00:00:00 2001 From: mark Date: Thu, 18 May 2006 17:29:21 +0000 Subject: Imported GNU Classpath 0.90 * scripts/makemake.tcl: LocaleData.java moved to gnu/java/locale. * sources.am: Regenerated. * gcj/javaprims.h: Regenerated. * Makefile.in: Regenerated. * gcj/Makefile.in: Regenerated. * include/Makefile.in: Regenerated. * testsuite/Makefile.in: Regenerated. * gnu/java/lang/VMInstrumentationImpl.java: New override. * gnu/java/net/local/LocalSocketImpl.java: Likewise. * gnu/classpath/jdwp/VMMethod.java: Likewise. * gnu/classpath/jdwp/VMVirtualMachine.java: Update to latest interface. * java/lang/Thread.java: Add UncaughtExceptionHandler. * java/lang/reflect/Method.java: Implements GenericDeclaration and isSynthetic(), * java/lang/reflect/Field.java: Likewise. * java/lang/reflect/Constructor.java * java/lang/Class.java: Implements Type, GenericDeclaration, getSimpleName() and getEnclosing*() methods. * java/lang/Class.h: Add new public methods. * java/lang/Math.java: Add signum(), ulp() and log10(). * java/lang/natMath.cc (log10): New function. * java/security/VMSecureRandom.java: New override. * java/util/logging/Logger.java: Updated to latest classpath version. * java/util/logging/LogManager.java: New override. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@113887 138bc75d-0d04-0410-961f-82ee72b054a4 --- .../gnu/java/security/key/dss/DSSKey.java | 21 ++++++++++++++++++++- .../security/key/dss/DSSKeyPairPKCS8Codec.java | 16 ++++++++++++++-- .../java/security/key/dss/DSSKeyPairRawCodec.java | 2 -- .../gnu/java/security/key/dss/DSSPrivateKey.java | 22 ++++++++++++++++++++-- .../gnu/java/security/key/dss/DSSPublicKey.java | 20 ++++++++++++++++++-- .../gnu/java/security/key/dss/FIPS186.java | 2 -- 6 files changed, 72 insertions(+), 11 deletions(-) (limited to 'libjava/classpath/gnu/java/security/key/dss') diff --git a/libjava/classpath/gnu/java/security/key/dss/DSSKey.java b/libjava/classpath/gnu/java/security/key/dss/DSSKey.java index 428cab1e78e..40aaea89352 100644 --- a/libjava/classpath/gnu/java/security/key/dss/DSSKey.java +++ b/libjava/classpath/gnu/java/security/key/dss/DSSKey.java @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.java.security.key.dss; +import gnu.classpath.SystemProperties; import gnu.java.security.Registry; import gnu.java.security.util.FormatUtil; @@ -59,7 +60,6 @@ import java.security.spec.DSAParameterSpec; * the relevant getEncoded() methods of each of the private and * public keys.

* - * @version $Revision: 1.4 $ * @see DSSPrivateKey#getEncoded * @see DSSPublicKey#getEncoded */ @@ -95,6 +95,9 @@ public abstract class DSSKey implements Key, DSAKey */ protected final int defaultFormat; + /** String representation of this key. Cached for speed. */ + private transient String str; + // Constructor(s) // ------------------------------------------------------------------------- @@ -176,6 +179,22 @@ public abstract class DSSKey implements Key, DSAKey && g.equals(that.getParams().getG()); } + public String toString() + { + if (str == null) + { + String ls = SystemProperties.getProperty("line.separator"); + str = new StringBuilder().append(ls) + .append("defaultFormat=").append(defaultFormat).append(",").append(ls) + .append("p=0x").append(p.toString(16)).append(",").append(ls) + .append("q=0x").append(q.toString(16)).append(",").append(ls) + .append("g=0x").append(g.toString(16)) + .toString(); + } + + return str; + } + // abstract methods to be implemented by subclasses ------------------------ public abstract byte[] getEncoded(int format); diff --git a/libjava/classpath/gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java b/libjava/classpath/gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java index 30e30bd144d..3a115b96378 100644 --- a/libjava/classpath/gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java +++ b/libjava/classpath/gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java @@ -55,6 +55,7 @@ import java.security.InvalidParameterException; import java.security.PrivateKey; import java.security.PublicKey; import java.util.ArrayList; +import java.util.logging.Logger; /** * An implementation of an {@link IKeyPairCodec} that knows how to encode / @@ -65,6 +66,7 @@ import java.util.ArrayList; public class DSSKeyPairPKCS8Codec implements IKeyPairCodec { + private static final Logger log = Logger.getLogger(DSSKeyPairPKCS8Codec.class.getName()); private static final OID DSA_ALG_OID = new OID(Registry.DSA_OID_STRING); // implicit 0-arguments constructor @@ -137,7 +139,9 @@ public class DSSKeyPairPKCS8Codec DERValue derAlgorithmID = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, algorithmID); - DERValue derPrivateKey = new DERValue(DER.OCTET_STRING, Util.trim(x)); + // The OCTET STRING is the DER encoding of an INTEGER. + DERValue derX = new DERValue(DER.INTEGER, x); + DERValue derPrivateKey = new DERValue(DER.OCTET_STRING, derX.getEncoded()); ArrayList pki = new ArrayList(3); pki.add(derVersion); @@ -180,6 +184,8 @@ public class DSSKeyPairPKCS8Codec */ public PrivateKey decodePrivateKey(byte[] input) { + log.entering("DSSKeyPairPKCS8Codec", "decodePrivateKey"); + if (input == null) throw new InvalidParameterException("Input bytes MUST NOT be null"); @@ -220,8 +226,13 @@ public class DSSKeyPairPKCS8Codec g = (BigInteger) val.getValue(); val = der.read(); + log.finest("val = " + val); byte[] xBytes = (byte[]) val.getValue(); - x = new BigInteger(1, xBytes); + log.finest(Util.dumpString(xBytes, "xBytes: ")); + DERReader der2 = new DERReader(xBytes); + val = der2.read(); + DerUtil.checkIsBigInteger(val, "Wrong X field"); + x = (BigInteger) val.getValue(); } catch (IOException e) { @@ -230,6 +241,7 @@ public class DSSKeyPairPKCS8Codec throw y; } + log.exiting("DSSKeyPairPKCS8Codec", "decodePrivateKey"); return new DSSPrivateKey(Registry.PKCS8_ENCODING_ID, p, q, g, x); } } diff --git a/libjava/classpath/gnu/java/security/key/dss/DSSKeyPairRawCodec.java b/libjava/classpath/gnu/java/security/key/dss/DSSKeyPairRawCodec.java index 86e5b0bef7e..7c5491d6f37 100644 --- a/libjava/classpath/gnu/java/security/key/dss/DSSKeyPairRawCodec.java +++ b/libjava/classpath/gnu/java/security/key/dss/DSSKeyPairRawCodec.java @@ -49,8 +49,6 @@ import java.security.PublicKey; /** *

An object that implements the {@link IKeyPairCodec} operations for the * Raw format to use with DSS keypairs.

- * - * @version $Revision: 1.1 $ */ public class DSSKeyPairRawCodec implements IKeyPairCodec { diff --git a/libjava/classpath/gnu/java/security/key/dss/DSSPrivateKey.java b/libjava/classpath/gnu/java/security/key/dss/DSSPrivateKey.java index c81eb93b078..fe59cb6d77b 100644 --- a/libjava/classpath/gnu/java/security/key/dss/DSSPrivateKey.java +++ b/libjava/classpath/gnu/java/security/key/dss/DSSPrivateKey.java @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.java.security.key.dss; +import gnu.classpath.SystemProperties; import gnu.java.security.Registry; import gnu.java.security.key.IKeyPairCodec; @@ -48,21 +49,24 @@ import java.security.interfaces.DSAPrivateKey; /** *

An object that embodies a DSS (Digital Signature Standard) private key.

* - * @version $Revision: 1.2 $ * @see #getEncoded */ public class DSSPrivateKey extends DSSKey implements PrivateKey, DSAPrivateKey { - // Constants and variables // ------------------------------------------------------------------------- + private static final boolean DEBUG = false; + /** *

A randomly or pseudorandomly generated integer with 0 < x < * q.

*/ private final BigInteger x; + /** String representation of this key. Cached for speed. */ + private transient String str; + // Constructor(s) // ------------------------------------------------------------------------- @@ -198,4 +202,18 @@ public class DSSPrivateKey extends DSSKey implements PrivateKey, DSAPrivateKey DSAPrivateKey that = (DSAPrivateKey) obj; return super.equals(that) && x.equals(that.getX()); } + + public String toString() + { + if (str == null) + { + String ls = SystemProperties.getProperty("line.separator"); + str = new StringBuilder(this.getClass().getName()).append("(") + .append(super.toString()).append(",").append(ls) + .append("x=0x").append(DEBUG ? x.toString(16) : "**...*").append(ls) + .append(")").toString(); + } + + return str; + } } diff --git a/libjava/classpath/gnu/java/security/key/dss/DSSPublicKey.java b/libjava/classpath/gnu/java/security/key/dss/DSSPublicKey.java index 93bb6402203..52292131336 100644 --- a/libjava/classpath/gnu/java/security/key/dss/DSSPublicKey.java +++ b/libjava/classpath/gnu/java/security/key/dss/DSSPublicKey.java @@ -38,6 +38,7 @@ exception statement from your version. */ package gnu.java.security.key.dss; +import gnu.classpath.SystemProperties; import gnu.java.security.Registry; import gnu.java.security.key.IKeyPairCodec; @@ -48,12 +49,10 @@ import java.security.interfaces.DSAPublicKey; /** *

An object that embodies a DSS (Digital Signature Standard) public key.

* - * @version $Revision: 1.2 $ * @see #getEncoded */ public class DSSPublicKey extends DSSKey implements PublicKey, DSAPublicKey { - // Constants and variables // ------------------------------------------------------------------------- @@ -63,6 +62,9 @@ public class DSSPublicKey extends DSSKey implements PublicKey, DSAPublicKey */ private final BigInteger y; + /** String representation of this key. Cached for speed. */ + private transient String str; + // Constructor(s) // ------------------------------------------------------------------------- @@ -198,4 +200,18 @@ public class DSSPublicKey extends DSSKey implements PublicKey, DSAPublicKey DSAPublicKey that = (DSAPublicKey) obj; return super.equals(that) && y.equals(that.getY()); } + + public String toString() + { + if (str == null) + { + String ls = SystemProperties.getProperty("line.separator"); + str = new StringBuilder(this.getClass().getName()).append("(") + .append(super.toString()).append(",").append(ls) + .append("y=0x").append(y.toString(16)).append(ls) + .append(")").toString(); + } + + return str; + } } diff --git a/libjava/classpath/gnu/java/security/key/dss/FIPS186.java b/libjava/classpath/gnu/java/security/key/dss/FIPS186.java index 74be626f58e..5984bcc9393 100644 --- a/libjava/classpath/gnu/java/security/key/dss/FIPS186.java +++ b/libjava/classpath/gnu/java/security/key/dss/FIPS186.java @@ -53,8 +53,6 @@ import java.security.SecureRandom; * Digital Signature * Standard (DSS), Federal Information Processing Standards Publication 186. * National Institute of Standards and Technology. - * - * @version $Revision: 1.2 $ */ public class FIPS186 { -- cgit v1.2.3