diff options
Diffstat (limited to 'gnu')
-rw-r--r-- | gnu/classpath/debug/Component.java | 159 | ||||
-rw-r--r-- | gnu/classpath/debug/PreciseFilter.java | 105 | ||||
-rw-r--r-- | gnu/classpath/debug/SystemLogger.java | 71 | ||||
-rw-r--r-- | gnu/java/security/x509/X509Certificate.java | 94 |
4 files changed, 383 insertions, 46 deletions
diff --git a/gnu/classpath/debug/Component.java b/gnu/classpath/debug/Component.java new file mode 100644 index 000000000..3dfc8927b --- /dev/null +++ b/gnu/classpath/debug/Component.java @@ -0,0 +1,159 @@ +/* Component.java -- a component log level. + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is a 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 of the License, 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; 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.classpath.debug; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.logging.Level; + +public final class Component extends Level +{ + + /* + * HOW TO ADD NEW COMPONENTS: + * + * If you want to add a new, simple component, that you will use in + * logging statements, simply create a new class variable that + * instantiates this class, and choose an appropriate string name + * and a integer constant not used by any other component level. + * + * For example, if my component had to do with 'frobbing', I would + * add this entry below: + * + * private static final Component FROBBING = new Component ("FROBBING", 7); + * + * Then, I would update the component 'EVERYTHING' to have and end + * index ONE GREATER THAN the index of the new component. + * + * ADDING NEW COMPONENT CLASSES: + * + * A "component class" is a run of more than one component, which can + * be enabled all at once. EVERYTHING and SSL are examples of component + * classes. To add a new class, create a new component with a start index + * equal to the index of the first member component, and with an end + * index equal to the index of the last member component plus one. + */ + + /** + * Signifies that everything should be logged. This should be used to + * enable or disable levels only; logging code should not use it. + */ + public static final Component EVERYTHING = new Component ("*", 0, 7); + + /** + * Signifies that all SSL related messages should be logged. This should + * be used to enable or disable levels only; logging code should not use + * it. + */ + public static final Component SSL = new Component ("SSL", 0, 5); + + /** + * Traces the progression of an SSL handshake. + */ + public static final Component SSL_HANDSHAKE = new Component ("SSL HANDSHAKE", 0); + + /** + * Traces the application messages during SSL communications. + */ + public static final Component SSL_APPLICATION = new Component ("SSL APPLICATION", 1); + + /** + * Trace details about the SSL key exchange. + */ + public static final Component SSL_KEY_EXCHANGE = new Component ("SSL KEY EXCHANGE", 2); + + /* Indices 3 and 4 reserved for future use by SSL components. */ + + /** + * Trace the operation of cryptographic primitives. + */ + public static final Component CRYPTO = new Component ("CRYPTO", 5); + + /** + * Trace the parsing of X.509 certificates and related objects. + */ + public static final Component X509 = new Component ("X.509", 6); + + private final int startIndex; + private final int endIndex; + + private Component (final String name, final int bitIndex) + { + this (name, bitIndex, bitIndex + 1); + } + + private Component (final String name, final int startIndex, final int endIndex) + { + super (name, Level.FINE.intValue ()); + this.startIndex = startIndex; + this.endIndex = endIndex; + } + + /** + * Return the component for the given name. + * + * @param name The name of the component to get. + * @return The named component, or null if there is no such component. + */ + public static Component forName (final String name) + { + try + { + Field f = Component.class.getField (name.toUpperCase ()); + if (!Modifier.isStatic (f.getModifiers ()) + || Component.class.isAssignableFrom (f.getClass ())) + return null; + return (Component) f.get (null); + } + catch (Throwable _) + { + return null; + } + } + + public int startIndex () + { + return startIndex; + } + + public int endIndex () + { + return endIndex; + } +}
\ No newline at end of file diff --git a/gnu/classpath/debug/PreciseFilter.java b/gnu/classpath/debug/PreciseFilter.java new file mode 100644 index 000000000..7b88b2c8c --- /dev/null +++ b/gnu/classpath/debug/PreciseFilter.java @@ -0,0 +1,105 @@ +/* PreciseFilter.java -- filter log messages by precise level. + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is a 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 of the License, 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; 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.classpath.debug; + +import java.util.BitSet; +import java.util.logging.Filter; +import java.util.logging.LogRecord; + +public final class PreciseFilter implements Filter +{ + + /** + * The singleton filter instance. + */ + public static final PreciseFilter GLOBAL = new PreciseFilter (); + + private final BitSet enabled; + + private PreciseFilter () + { + enabled = new BitSet (); + } + + /** + * Disable logging of a component. + * + * @param component The component to disable logging for. + * @throws NullPointerException If component is null. + */ + public void disable (final Component component) + { + enabled.clear (component.startIndex (), component.endIndex ()); + } + + /** + * Enable logging of a component. + * + * @param component The component to enable logging for. + * @throws NullPointerException If component is null. + */ + public void enable (final Component component) + { + enabled.set (component.startIndex (), component.endIndex ()); + } + + /** + * Tell if a component is enabled for logging. + * + * @param component The component to test. + * @return True iff the specified component is enabled for logging. + * @throws NullPointerException If component is null. + */ + public boolean isEnabled (final Component component) + { + return (enabled.get (component.startIndex ())); + } + + public boolean isLoggable (final LogRecord record) + { + try + { + return isEnabled ((Component) record.getLevel ()); + } + catch (ClassCastException cce) + { + return true; + } + } +}
\ No newline at end of file diff --git a/gnu/classpath/debug/SystemLogger.java b/gnu/classpath/debug/SystemLogger.java new file mode 100644 index 000000000..94aa93f69 --- /dev/null +++ b/gnu/classpath/debug/SystemLogger.java @@ -0,0 +1,71 @@ +/* SystemLogger.java -- Classpath's system debugging logger. + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is a 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 of the License, 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; 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.classpath.debug; + +import gnu.classpath.SystemProperties; +import java.util.StringTokenizer; +import java.util.logging.Logger; + +public final class SystemLogger +{ + public static final Logger SYSTEM = Logger.getLogger ("gnu.classpath"); + + static + { + SYSTEM.setFilter (PreciseFilter.GLOBAL); + + String defaults = SystemProperties.getProperty ("gnu.classpath.debug.components"); + + if (defaults != null) + { + StringTokenizer tok = new StringTokenizer (defaults, ","); + while (tok.hasMoreTokens ()) + { + Component c = Component.forName (tok.nextToken ()); + if (c != null) + PreciseFilter.GLOBAL.enable (c); + SYSTEM.log (java.util.logging.Level.INFO, "enabled: {0}", c); + } + } + + java.util.logging.Handler[] h = SYSTEM.getHandlers (); + for (int i = 0; i < h.length; i++) + System.out.println (h[i]); + } +} diff --git a/gnu/java/security/x509/X509Certificate.java b/gnu/java/security/x509/X509Certificate.java index 94a02aa72..14ac43a25 100644 --- a/gnu/java/security/x509/X509Certificate.java +++ b/gnu/java/security/x509/X509Certificate.java @@ -38,6 +38,9 @@ exception statement from your version. */ package gnu.java.security.x509; +import gnu.classpath.debug.Component; +import gnu.classpath.debug.SystemLogger; + import gnu.java.security.OID; import gnu.java.security.der.BitString; import gnu.java.security.der.DER; @@ -86,6 +89,9 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; + import javax.security.auth.x500.X500Principal; /** @@ -100,23 +106,7 @@ public class X509Certificate extends java.security.cert.X509Certificate // Constants and fields. // ------------------------------------------------------------------------ - private static final boolean DEBUG = false; - private static void debug(String msg) - { - if (DEBUG) - { - System.err.print(">> X509Certificate: "); - System.err.println(msg); - } - } - private static void debug(Throwable t) - { - if (DEBUG) - { - System.err.print(">> X509Certificate: "); - t.printStackTrace(); - } - } + private static final Logger logger = SystemLogger.SYSTEM; protected static final OID ID_DSA = new OID ("1.2.840.10040.4.1"); protected static final OID ID_DSA_WITH_SHA1 = new OID ("1.2.840.10040.4.3"); @@ -177,12 +167,12 @@ public class X509Certificate extends java.security.cert.X509Certificate } catch (IOException ioe) { - debug(ioe); + logger.log (Component.X509, "", ioe); throw ioe; } catch (Exception e) { - debug(e); + logger.log (Component.X509, "", e); CertificateException ce = new CertificateException(e.getMessage()); ce.initCause (e); throw ce; @@ -543,7 +533,8 @@ public class X509Certificate extends java.security.cert.X509Certificate private void doVerify(Signature sig, PublicKey key) throws CertificateException, InvalidKeyException, SignatureException { - debug("verifying sig=" + sig + " key=" + key); + logger.log (Component.X509, "verifying sig={0} key={1}", + new Object[] { sig, key }); sig.initVerify(key); sig.update(tbsCertBytes); if (!sig.verify(signature)) @@ -563,7 +554,8 @@ public class X509Certificate extends java.security.cert.X509Certificate // Certificate ::= SEQUENCE { DERValue cert = der.read(); - debug("start Certificate len == " + cert.getLength()); + logger.log (Component.X509, "start Certificate len == {0}", + new Integer (cert.getLength())); this.encoded = cert.getEncoded(); if (!cert.isConstructed()) @@ -578,7 +570,8 @@ public class X509Certificate extends java.security.cert.X509Certificate throw new IOException("malformed TBSCertificate"); } tbsCertBytes = tbsCert.getEncoded(); - debug("start TBSCertificate len == " + tbsCert.getLength()); + logger.log (Component.X509, "start TBSCertificate len == {0}", + new Integer (tbsCert.getLength())); // Version ::= INTEGER [0] { v1(0), v2(1), v3(2) } DERValue val = der.read(); @@ -591,11 +584,12 @@ public class X509Certificate extends java.security.cert.X509Certificate { version = 1; } - debug("read version == " + version); + logger.log (Component.X509, "read version == {0}", + new Integer (version)); // SerialNumber ::= INTEGER serialNo = (BigInteger) val.getValue(); - debug("read serial number == " + serialNo); + logger.log (Component.X509, "read serial number == {0}", serialNo); // AlgorithmIdentifier ::= SEQUENCE { val = der.read(); @@ -604,12 +598,13 @@ public class X509Certificate extends java.security.cert.X509Certificate throw new IOException("malformed AlgorithmIdentifier"); } int certAlgLen = val.getLength(); - debug("start AlgorithmIdentifier len == " + certAlgLen); + logger.log (Component.X509, "start AlgorithmIdentifier len == {0}", + new Integer (certAlgLen)); val = der.read(); // algorithm OBJECT IDENTIFIER, algId = (OID) val.getValue(); - debug("read algorithm ID == " + algId); + logger.log (Component.X509, "read algorithm ID == {0}", algId); // parameters ANY DEFINED BY algorithm OPTIONAL } if (certAlgLen > val.getEncodedLength()) @@ -622,18 +617,18 @@ public class X509Certificate extends java.security.cert.X509Certificate else { algVal = val.getEncoded(); - - if (val.isConstructed()) - encoded.skip(val.getLength()); + + if (val.isConstructed()) + encoded.skip(val.getLength()); } - debug("read algorithm parameters == " + algVal); + logger.log (Component.X509, "read algorithm parameters == {0}", algVal); } // issuer Name, val = der.read(); issuer = new X500DistinguishedName(val.getEncoded()); der.skip(val.getLength()); - debug("read issuer == " + issuer); + logger.log (Component.X509, "read issuer == {0}", issuer); // Validity ::= SEQUENCE { // notBefore Time, @@ -643,15 +638,15 @@ public class X509Certificate extends java.security.cert.X509Certificate throw new IOException("malformed Validity"); } notBefore = (Date) der.read().getValue(); + logger.log (Component.X509, "read notBefore == {0}", notBefore); notAfter = (Date) der.read().getValue(); - debug("read notBefore == " + notBefore); - debug("read notAfter == " + notAfter); + logger.log (Component.X509, "read notAfter == {0}", notAfter); // subject Name, val = der.read(); subject = new X500DistinguishedName(val.getEncoded()); der.skip(val.getLength()); - debug("read subject == " + subject); + logger.log (Component.X509, "read subject == {0}", subject); // SubjectPublicKeyInfo ::= SEQUENCE { // algorithm AlgorithmIdentifier, @@ -664,7 +659,7 @@ public class X509Certificate extends java.security.cert.X509Certificate KeyFactory spkFac = KeyFactory.getInstance("X.509"); subjectKey = spkFac.generatePublic(new X509EncodedKeySpec(spki.getEncoded())); der.skip(spki.getLength()); - debug("read subjectPublicKey == " + subjectKey); + logger.log (Component.X509, "read subjectPublicKey == {0}", subjectKey); if (version > 1) { @@ -674,43 +669,50 @@ public class X509Certificate extends java.security.cert.X509Certificate { byte[] b = (byte[]) val.getValue(); issuerUniqueId = new BitString(b, 1, b.length-1, b[0] & 0xFF); - debug("read issuerUniqueId == " + issuerUniqueId); + logger.log (Component.X509, "read issuerUniqueId == {0}", issuerUniqueId); val = der.read(); } if (version >= 2 && val.getTagClass() != DER.UNIVERSAL && val.getTag() == 2) { byte[] b = (byte[]) val.getValue(); subjectUniqueId = new BitString(b, 1, b.length-1, b[0] & 0xFF); - debug("read subjectUniqueId == " + subjectUniqueId); + logger.log (Component.X509, "read subjectUniqueId == {0}", subjectUniqueId); val = der.read(); } if (version >= 3 && val.getTagClass() != DER.UNIVERSAL && val.getTag() == 3) { val = der.read(); - debug("start Extensions len == " + val.getLength()); + logger.log (Component.X509, "start Extensions len == {0}", + new Integer (val.getLength())); int len = 0; while (len < val.getLength()) { DERValue ext = der.read(); - debug("start extension len == " + ext.getLength()); + logger.log (Component.X509, "start extension len == {0}", + new Integer (ext.getLength())); Extension e = new Extension(ext.getEncoded()); extensions.put(e.getOid(), e); der.skip(ext.getLength()); len += ext.getEncodedLength(); - debug("count == " + len); + logger.log (Component.X509, "read extension {0} == {1}", + new Object[] { e.getOid (), e }); + logger.log (Component.X509, "count == {0}", new Integer (len)); } + + val = der.read (); } - val = der.read(); + logger.log (Component.X509, "read value {0}", val); if (!val.isConstructed()) { - throw new IOException("malformed AlgorithmIdentifier"); + throw new CertificateException ("malformed AlgorithmIdentifier"); } int sigAlgLen = val.getLength(); - debug("start AlgorithmIdentifier len == " + sigAlgLen); + logger.log (Component.X509, "start AlgorithmIdentifier len == {0}", + new Integer (sigAlgLen)); val = der.read(); sigAlgId = (OID) val.getValue(); - debug("read algorithm id == " + sigAlgId); + logger.log (Component.X509, "read algorithm id == {0}", sigAlgId); if (sigAlgLen > val.getEncodedLength()) { val = der.read(); @@ -735,9 +737,9 @@ public class X509Certificate extends java.security.cert.X509Certificate { encoded.skip(val.getLength()); } - debug("read parameters == " + sigAlgVal); + logger.log (Component.X509, "read parameters == {0}", sigAlgVal); } signature = ((BitString) der.read().getValue()).toByteArray(); - debug("read signature ==\n" + Util.hexDump(signature, ">>>> ")); + logger.log (Component.X509, "read signature ==\n{0}", Util.hexDump(signature, ">>>> ")); } } |