[kaffe] CVS kaffe (robilad): Added remaining missing security files

Kaffe CVS cvs-commits at kaffe.org
Wed Nov 10 14:56:44 PST 2004


PatchSet 5435 
Date: 2004/11/10 22:52:25
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Added remaining missing security files

Members: 
	libraries/javalib/gnu/java/security/x509/ext/AuthorityKeyIdentifier.java:INITIAL->1.1 
	libraries/javalib/gnu/java/security/x509/ext/BasicConstraints.java:INITIAL->1.1 
	libraries/javalib/gnu/java/security/x509/ext/CRLNumber.java:INITIAL->1.1 
	libraries/javalib/gnu/java/security/x509/ext/CertificatePolicies.java:INITIAL->1.1 
	libraries/javalib/gnu/java/security/x509/ext/ExtendedKeyUsage.java:INITIAL->1.1 
	libraries/javalib/gnu/java/security/x509/ext/Extension.java:INITIAL->1.1 
	libraries/javalib/gnu/java/security/x509/ext/GeneralNames.java:INITIAL->1.1 
	libraries/javalib/gnu/java/security/x509/ext/IssuerAlternativeNames.java:INITIAL->1.1 
	libraries/javalib/gnu/java/security/x509/ext/KeyUsage.java:INITIAL->1.1 
	libraries/javalib/gnu/java/security/x509/ext/PolicyConstraint.java:INITIAL->1.1 
	libraries/javalib/gnu/java/security/x509/ext/PolicyMappings.java:INITIAL->1.1 
	libraries/javalib/gnu/java/security/x509/ext/PrivateKeyUsagePeriod.java:INITIAL->1.1 
	libraries/javalib/gnu/java/security/x509/ext/ReasonCode.java:INITIAL->1.1 
	libraries/javalib/gnu/java/security/x509/ext/SubjectAlternativeNames.java:INITIAL->1.1 
	libraries/javalib/gnu/java/security/x509/ext/SubjectKeyIdentifier.java:INITIAL->1.1 

===================================================================
Checking out kaffe/libraries/javalib/gnu/java/security/x509/ext/AuthorityKeyIdentifier.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/gnu/java/security/x509/ext/AuthorityKeyIdentifier.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/gnu/java/security/x509/ext/AuthorityKeyIdentifier.java	Wed Nov 10 22:56:43 2004
@@ -0,0 +1,134 @@
+/* AuthorityKeyIdentifier.java -- Authority key identifier extension.
+   Copyright (C) 2004  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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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.x509.ext;
+
+import java.io.IOException;
+import java.math.BigInteger;
+import java.util.List;
+
+import gnu.java.security.OID;
+import gnu.java.security.der.DER;
+import gnu.java.security.der.DERReader;
+import gnu.java.security.der.DERValue;
+import gnu.java.security.x509.Util;
+
+public class AuthorityKeyIdentifier extends Extension.Value
+{
+
+  // Constants and fields.
+  // -------------------------------------------------------------------------
+
+  public static final OID ID = new OID("2.5.29.35");
+
+  private final byte[] keyIdentifier;
+  private final GeneralNames authorityCertIssuer;
+  private final BigInteger authorityCertSerialNumber;
+
+  // Contstructor.
+  // -------------------------------------------------------------------------
+
+  public AuthorityKeyIdentifier(final byte[] encoded) throws IOException
+  {
+    super(encoded);
+    DERReader der = new DERReader(encoded);
+
+    // AuthorityKeyIdentifier ::= SEQUENCE {
+    DERValue val = der.read();
+    if (!val.isConstructed())
+      throw new IOException("malformed AuthorityKeyIdentifier");
+    if (val.getLength() > 0)
+      val = der.read();
+
+    //   keyIdentifier  [0] KeyIdentifier OPTIONAL,
+    //   KeyIdentifier ::= OCTET STRING
+    if (val.getTagClass() == DER.APPLICATION && val.getTag() == 0)
+      {
+        keyIdentifier = (byte[]) val.getValue();
+        val = der.read();
+      }
+    else
+      keyIdentifier = null;
+
+    //   authorityCertIssuer  [1] GeneralNames OPTIONAL,
+    if (val.getTagClass() == DER.APPLICATION && val.getTag() == 1)
+      {
+        byte[] b = val.getEncoded();
+        b[0] = (byte) (DER.CONSTRUCTED|DER.SEQUENCE);
+        authorityCertIssuer = new GeneralNames(b);
+        der.skip(val.getLength());
+        val = der.read();
+      }
+    else
+      authorityCertIssuer = null;
+
+    //   authorityCertSerialNumber  [2] CertificateSerialNumber OPTIONAL }
+    if (val.getTagClass() == DER.APPLICATION && val.getTag() == 2)
+      {
+        authorityCertSerialNumber = new BigInteger((byte[]) val.getValue());
+      }
+    else
+      authorityCertSerialNumber = null;
+  }
+
+  // Instance methods.
+  // -------------------------------------------------------------------------
+
+  public byte[] getKeyIdentifier()
+  {
+    return keyIdentifier != null ? (byte[]) keyIdentifier.clone() : null;
+  }
+
+  public GeneralNames getAuthorityCertIssuer()
+  {
+    return authorityCertIssuer;
+  }
+
+  public BigInteger getAuthorityCertSerialNumber()
+  {
+    return authorityCertSerialNumber;
+  }
+
+  public String toString()
+  {
+    return AuthorityKeyIdentifier.class.getName() + " [ keyId=" +
+      (keyIdentifier != null ? Util.toHexString (keyIdentifier, ':') : "nil") +
+      " authorityCertIssuer=" + authorityCertIssuer +
+      " authorityCertSerialNumbe=" + authorityCertSerialNumber + " ]";
+  }
+}
===================================================================
Checking out kaffe/libraries/javalib/gnu/java/security/x509/ext/BasicConstraints.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/gnu/java/security/x509/ext/BasicConstraints.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/gnu/java/security/x509/ext/BasicConstraints.java	Wed Nov 10 22:56:43 2004
@@ -0,0 +1,129 @@
+/* BasicConstraints.java -- the basic constraints extension.
+   Copyright (C) 2004  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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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.x509.ext;
+
+import java.io.IOException;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
+
+import gnu.java.security.OID;
+import gnu.java.security.der.DER;
+import gnu.java.security.der.DERReader;
+import gnu.java.security.der.DERValue;
+
+public class BasicConstraints extends Extension.Value
+{
+
+  // Constants and fields.
+  // -------------------------------------------------------------------------
+
+  public static final OID ID = new OID("2.5.29.19");
+
+  private final boolean ca;
+  private final int pathLenConstraint;
+
+  // Constructor.
+  // -------------------------------------------------------------------------
+
+  public BasicConstraints(final byte[] encoded) throws IOException
+  {
+    super(encoded);
+    DERReader der = new DERReader(encoded);
+    DERValue bc = der.read();
+    if (!bc.isConstructed())
+      throw new IOException("malformed BasicConstraints");
+    DERValue val = bc;
+    if (bc.getLength() > 0)
+      val = der.read();
+    if (val.getTag() == DER.BOOLEAN)
+      {
+        ca = ((Boolean) val.getValue()).booleanValue();
+        if (val.getEncodedLength() < bc.getLength())
+          val = der.read();
+      }
+    else
+      ca = false;
+    if (val.getTag() == DER.INTEGER)
+      {
+        pathLenConstraint = ((BigInteger) val.getValue()).intValue();
+      }
+    else
+      pathLenConstraint = -1;
+  }
+
+  public BasicConstraints (final boolean ca, final int pathLenConstraint)
+  {
+    this.ca = ca;
+    this.pathLenConstraint = pathLenConstraint;
+  }
+
+  // Instance methods.
+  // -------------------------------------------------------------------------
+
+  public boolean isCA()
+  {
+    return ca;
+  }
+
+  public int getPathLengthConstraint()
+  {
+    return pathLenConstraint;
+  }
+
+  public byte[] getEncoded()
+  {
+    if (encoded == null)
+      {
+        List bc = new ArrayList (2);
+        bc.add (new DERValue (DER.BOOLEAN, new Boolean (ca)));
+        if (pathLenConstraint >= 0)
+          bc.add (new DERValue (DER.INTEGER,
+                                BigInteger.valueOf ((long) pathLenConstraint)));
+        encoded = new DERValue (DER.CONSTRUCTED|DER.SEQUENCE, bc).getEncoded();
+      }
+    return (byte[]) encoded.clone();
+  }
+
+  public String toString()
+  {
+    return BasicConstraints.class.getName() + " [ isCA=" + ca +
+      " pathLen=" + pathLenConstraint + " ]";
+  }
+}
===================================================================
Checking out kaffe/libraries/javalib/gnu/java/security/x509/ext/CRLNumber.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/gnu/java/security/x509/ext/CRLNumber.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/gnu/java/security/x509/ext/CRLNumber.java	Wed Nov 10 22:56:43 2004
@@ -0,0 +1,97 @@
+/* CRLNumber.java -- CRL number extension.
+   Copyright (C) 2004  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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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.x509.ext;
+
+import java.io.IOException;
+import java.math.BigInteger;
+
+import gnu.java.security.OID;
+import gnu.java.security.der.DER;
+import gnu.java.security.der.DERReader;
+import gnu.java.security.der.DERValue;
+
+public class CRLNumber extends Extension.Value
+{
+
+  // Constants and fields.
+  // -------------------------------------------------------------------------
+
+  public static final OID ID = new OID("2.5.29.20");
+
+  private final BigInteger number;
+
+  // Constructor.
+  // -------------------------------------------------------------------------
+
+  public CRLNumber(final byte[] encoded) throws IOException
+  {
+    super(encoded);
+    DERValue val = DERReader.read(encoded);
+    if (val.getTag() != DER.INTEGER)
+      throw new IOException("malformed CRLNumber");
+    number = (BigInteger) val.getValue();
+  }
+
+  public CRLNumber (final BigInteger number)
+  {
+    this.number = number;
+  }
+
+  // Instance method.
+  // -------------------------------------------------------------------------
+
+  public BigInteger getNumber()
+  {
+    return number;
+  }
+
+  public byte[] getEncoded()
+  {
+    if (encoded == null)
+      {
+        encoded = new DERValue (DER.INTEGER, number).getEncoded();
+      }
+    return (byte[]) encoded.clone();
+  }
+
+  public String toString()
+  {
+    return CRLNumber.class.getName() + " [ " + number + " ]";
+  }
+}
===================================================================
Checking out kaffe/libraries/javalib/gnu/java/security/x509/ext/CertificatePolicies.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/gnu/java/security/x509/ext/CertificatePolicies.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/gnu/java/security/x509/ext/CertificatePolicies.java	Wed Nov 10 22:56:43 2004
@@ -0,0 +1,191 @@
+/* CertificatePolicies.java -- certificate policy extension.
+   Copyright (C) 2004  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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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.x509.ext;
+
+import java.io.IOException;
+import java.math.BigInteger;
+import java.security.cert.PolicyQualifierInfo;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import gnu.java.security.OID;
+import gnu.java.security.der.DER;
+import gnu.java.security.der.DERReader;
+import gnu.java.security.der.DERValue;
+
+public class CertificatePolicies extends Extension.Value
+{
+
+  // Constants and fields.
+  // -------------------------------------------------------------------------
+
+  public static final OID ID = new OID("2.5.29.32");
+
+  private final List policies;
+  private final Map policyQualifierInfos;
+
+  // Constructor.
+  // -------------------------------------------------------------------------
+
+  public CertificatePolicies(final byte[] encoded) throws IOException
+  {
+    super(encoded);
+    DERReader der = new DERReader(encoded);
+    DERValue pol = der.read();
+    if (!pol.isConstructed())
+      throw new IOException("malformed CertificatePolicies");
+
+    int len = 0;
+    LinkedList policyList = new LinkedList();
+    HashMap qualifierMap = new HashMap();
+    while (len < pol.getLength())
+      {
+        DERValue policyInfo = der.read();
+        if (!policyInfo.isConstructed())
+          throw new IOException("malformed PolicyInformation");
+        DERValue val = der.read();
+        if (val.getTag() != DER.OBJECT_IDENTIFIER)
+          throw new IOException("malformed CertPolicyId");
+        OID policyId = (OID) val.getValue();
+        policyList.add(policyId);
+        if (val.getEncodedLength() < policyInfo.getLength())
+          {
+            DERValue qual = der.read();
+            int len2 = 0;
+            LinkedList quals = new LinkedList();
+            while (len2 < qual.getLength())
+              {
+                val = der.read();
+                quals.add(new PolicyQualifierInfo(val.getEncoded()));
+                der.skip(val.getLength());
+                len2 += val.getEncodedLength();
+              }
+            qualifierMap.put(policyId, quals);
+          }
+        len += policyInfo.getEncodedLength();
+      }
+
+    policies = Collections.unmodifiableList(policyList);
+    policyQualifierInfos = Collections.unmodifiableMap(qualifierMap);
+  }
+
+  public CertificatePolicies (final List policies,
+                              final Map 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();)
+      {
+        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))
+            throw new IllegalArgumentException
+              ("policyQualifierInfos values must be Lists of PolicyQualifierInfos");
+      }
+    this.policies = Collections.unmodifiableList (new ArrayList (policies));
+    this.policyQualifierInfos = Collections.unmodifiableMap
+      (new HashMap (policyQualifierInfos));
+  }
+
+  // Instance methods.
+  // -------------------------------------------------------------------------
+
+  public List getPolicies()
+  {
+    return policies;
+  }
+
+  public List getPolicyQualifierInfos(OID oid)
+  {
+    return (List) policyQualifierInfos.get(oid);
+  }
+
+  public byte[] getEncoded()
+  {
+    if (encoded == null)
+      {
+        List pol = new ArrayList (policies.size());
+        for (Iterator it = policies.iterator(); it.hasNext(); )
+          {
+            OID policy = (OID) it.next();
+            List qualifiers = getPolicyQualifierInfos (policy);
+            List l = new ArrayList (qualifiers == null ? 1 : 2);
+            l.add (new DERValue (DER.OBJECT_IDENTIFIER, policy));
+            if (qualifiers != null)
+              {
+                List ll = new ArrayList (qualifiers.size());
+                for (Iterator it2 = qualifiers.iterator(); it.hasNext(); )
+                  {
+                    PolicyQualifierInfo info = (PolicyQualifierInfo) it2.next();
+                    try
+                      {
+                        ll.add (DERReader.read (info.getEncoded()));
+                      }
+                    catch (IOException ioe)
+                      {
+                      }
+                  }
+                l.add (new DERValue (DER.CONSTRUCTED|DER.SEQUENCE, ll));
+              }
+            pol.add (new DERValue (DER.CONSTRUCTED|DER.SEQUENCE, l));
+          }
+        encoded = new DERValue (DER.CONSTRUCTED|DER.SEQUENCE, pol).getEncoded();
+      }
+    return (byte[]) encoded.clone();
+  }
+
+  public String toString()
+  {
+    return CertificatePolicies.class.getName() + " [ policies=" + policies +
+      " policyQualifierInfos=" + policyQualifierInfos + " ]";
+  }
+}
===================================================================
Checking out kaffe/libraries/javalib/gnu/java/security/x509/ext/ExtendedKeyUsage.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/gnu/java/security/x509/ext/ExtendedKeyUsage.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/gnu/java/security/x509/ext/ExtendedKeyUsage.java	Wed Nov 10 22:56:43 2004
@@ -0,0 +1,95 @@
+/* ExtendedKeyUsage.java -- the extended key usage extension.
+   Copyright (C) 2004  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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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.x509.ext;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
+import gnu.java.security.OID;
+import gnu.java.security.der.DER;
+import gnu.java.security.der.DERReader;
+import gnu.java.security.der.DERValue;
+
+public class ExtendedKeyUsage extends Extension.Value
+{
+
+  // Constants and fields.
+  // -------------------------------------------------------------------------
+
+  public static final OID ID = new OID("2.5.29.37");
+
+  private final List purposeIds;
+
+  // Constructor.
+  // -------------------------------------------------------------------------
+
+  public ExtendedKeyUsage(final byte[] encoded) throws IOException
+  {
+    super(encoded);
+    DERReader der = new DERReader(encoded);
+    DERValue usageList = der.read();
+    if (!usageList.isConstructed())
+      throw new IOException("malformed ExtKeyUsageSyntax");
+    int len = 0;
+    purposeIds = new LinkedList();
+    while (len < usageList.getLength())
+      {
+        DERValue val = der.read();
+        if (val.getTag() != DER.OBJECT_IDENTIFIER)
+          throw new IOException("malformed KeyPurposeId");
+        purposeIds.add(val.getValue());
+        len += val.getEncodedLength();
+      }
+  }
+
+  // Instance method.
+  // -------------------------------------------------------------------------
+
+  public List getPurposeIds()
+  {
+    return Collections.unmodifiableList(purposeIds);
+  }
+
+  public String toString()
+  {
+    return ExtendedKeyUsage.class.getName() + " [ " + purposeIds + " ]";
+  }
+}
===================================================================
Checking out kaffe/libraries/javalib/gnu/java/security/x509/ext/Extension.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/gnu/java/security/x509/ext/Extension.java,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/gnu/java/security/x509/ext/Extension.java	Wed Nov 10 22:56:43 2004
@@ -0,0 +1,289 @@
+/* Extension.java -- an X.509 certificate or CRL extension.
+   Copyright (C) 2004  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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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.x509.ext;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import gnu.java.security.OID;
+import gnu.java.security.der.DER;
+import gnu.java.security.der.DERReader;
+import gnu.java.security.der.DERValue;
+import gnu.java.security.x509.Util;
+
+public class Extension
+{
+
+  // Fields.
+  // -------------------------------------------------------------------------
+
+  private static final boolean DEBUG = false;
+  private static void debug(String msg)
+  {
+    System.err.print(">> Extension: ");
+    System.err.println(msg);
+  }
+
+  /**
+   * This extension's object identifier.
+   */
+  protected final OID oid;
+
+  /**
+   * The criticality flag.
+   */
+  protected final boolean critical;
+
+  /**
+   * Whether or not this extension is locally supported.
+   */
+  protected boolean isSupported;
+
+  /**
+   * The extension value.
+   */
+  protected final Value value;
+
+  /**
+   * The DER encoded form.
+   */
+  protected byte[] encoded;
+
+  // Constructors.
+  // -------------------------------------------------------------------------
+
+  public Extension(byte[] encoded) throws IOException
+  {
+    this.encoded = (byte[]) encoded.clone();
+    DERReader der = new DERReader(encoded);
+
+    // Extension ::= SEQUENCE {
+    DERValue val = der.read();
+    if (DEBUG) debug("read val  tag == " + val.getTag() + " len == " + val.getLength());
+    if (!val.isConstructed())
+      throw new IOException("malformed Extension");
+
+    //   extnID    OBJECT IDENTIFIER,
+    val = der.read();
+    if (val.getTag() != DER.OBJECT_IDENTIFIER)
+      throw new IOException("expecting OBJECT IDENTIFIER");
+    oid = (OID) val.getValue();
+    if (DEBUG) debug("read oid == " + oid);
+
+    //   critical  BOOLEAN DEFAULT FALSE,
+    val = der.read();
+    if (val.getTag() == DER.BOOLEAN)
+      {
+        critical = ((Boolean) val.getValue()).booleanValue();
+        val = der.read();
+      }
+    else
+      critical = false;
+    if (DEBUG) debug("is critical == " + critical);
+
+    //   extnValue OCTET STRING }
+    if (val.getTag() != DER.OCTET_STRING)
+      throw new IOException("expecting OCTET STRING");
+    byte[] encval = (byte[]) val.getValue();
+    isSupported = true;
+    if (oid.equals(AuthorityKeyIdentifier.ID))
+      {
+        value = new AuthorityKeyIdentifier(encval);
+      }
+    else if (oid.equals(SubjectKeyIdentifier.ID))
+      {
+        value = new SubjectKeyIdentifier(encval);
+      }
+    else if (oid.equals(KeyUsage.ID))
+      {
+        value = new KeyUsage(encval);
+      }
+    else if (oid.equals(PrivateKeyUsagePeriod.ID))
+      {
+        value = new PrivateKeyUsagePeriod(encval);
+      }
+    else if (oid.equals(CertificatePolicies.ID))
+      {
+        value = new CertificatePolicies(encval);
+      }
+    else if (oid.equals (PolicyConstraint.ID))
+      {
+        value = new PolicyConstraint (encval);
+      }
+    else if (oid.equals(PolicyMappings.ID))
+      {
+        value = new PolicyMappings(encval);
+      }
+    else if (oid.equals(SubjectAlternativeNames.ID))
+      {
+        value = new SubjectAlternativeNames(encval);
+      }
+    else if (oid.equals(IssuerAlternativeNames.ID))
+      {
+        value = new IssuerAlternativeNames(encval);
+      }
+    else if (oid.equals(BasicConstraints.ID))
+      {
+        value = new BasicConstraints(encval);
+      }
+    else if (oid.equals(ExtendedKeyUsage.ID))
+      {
+        value = new ExtendedKeyUsage(encval);
+      }
+    else if (oid.equals(CRLNumber.ID))
+      {
+        value = new CRLNumber(encval);
+      }
+    else if (oid.equals(ReasonCode.ID))
+      {
+        value = new ReasonCode(encval);
+      }
+    else
+      {
+        value = new Value(encval);
+        isSupported = false;
+      }
+    if (DEBUG) debug("read value == " + value);
+  }
+
+  public Extension (final OID oid, final Value value, final boolean critical)
+  {
+    this.oid = oid;
+    this.value = value;
+    this.critical = critical;
+    isSupported = true;
+  }
+
+  // Instance methods.
+  // -------------------------------------------------------------------------
+
+  public OID getOid()
+  {
+    return oid;
+  }
+
+  public boolean isCritical()
+  {
+    return critical;
+  }
+
+  public boolean isSupported()
+  {
+    return isSupported;
+  }
+
+  public Value getValue()
+  {
+    return value;
+  }
+
+  public byte[] getEncoded()
+  {
+    if (encoded == null)
+      encode();
+    return (byte[]) encoded.clone();
+  }
+
+  public String toString()
+  {
+    return Extension.class.getName() + " [ id=" + oid + " critical=" +
+      critical + " value=" + value + " ]";
+  }
+
+  public DERValue getDerValue()
+  {
+    List ext = new ArrayList (3);
+    ext.add (new DERValue (DER.OBJECT_IDENTIFIER, oid));
+    ext.add (new DERValue (DER.BOOLEAN, new Boolean (critical)));
+    ext.add (new DERValue (DER.OCTET_STRING, value.getEncoded()));
+    return new DERValue (DER.CONSTRUCTED|DER.SEQUENCE, ext);
+  }
+
+  // Own methods.
+  // -------------------------------------------------------------------------
+
+  private void encode()
+  {
+    encoded = getDerValue().getEncoded();
+  }
+
+  // Inner class.
+  // -------------------------------------------------------------------------
+
+  public static class Value
+  {
+
+    // Fields.
+    // -----------------------------------------------------------------------
+
+    protected byte[] encoded;
+
+    // Constructor.
+    // -----------------------------------------------------------------------
+
+    public Value(byte[] encoded)
+    {
+      this.encoded = (byte[]) encoded.clone();
+    }
+
+    protected Value() { }
+
+    // Instance methods.
+    // -----------------------------------------------------------------------
+
+    public byte[] getEncoded()
+    {
+      return (byte[]) encoded;
+    }
+
+    public boolean equals(Object o)
+    {
+      if (!(o instanceof Value))
+        return false;
+      return Arrays.equals(encoded, ((Value) o).encoded);

*** Patch too long, truncated ***




More information about the kaffe mailing list