OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [gnu/] [java/] [security/] [x509/] [X509CRLEntry.java] - Blame information for rev 769

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 769 jeremybenn
/* X509CRLEntry.java -- an entry in a X.509 CRL.
2
   Copyright (C) 2003, 2004  Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
 
39
package gnu.java.security.x509;
40
 
41
import gnu.java.security.Configuration;
42
import gnu.java.security.OID;
43
import gnu.java.security.der.DERReader;
44
import gnu.java.security.der.DERValue;
45
import gnu.java.security.x509.ext.Extension;
46
 
47
import java.io.IOException;
48
import java.math.BigInteger;
49
import java.security.cert.CRLException;
50
import java.util.Collection;
51
import java.util.Collections;
52
import java.util.Date;
53
import java.util.HashMap;
54
import java.util.HashSet;
55
import java.util.Iterator;
56
import java.util.Set;
57
import java.util.logging.Logger;
58
 
59
/**
60
 * A single entry in a X.509 certificate revocation list.
61
 *
62
 * @see X509CRL
63
 * @author Casey Marshall
64
 */
65
class X509CRLEntry extends java.security.cert.X509CRLEntry
66
  implements GnuPKIExtension
67
{
68
  private static final Logger log = Logger.getLogger(X509CRLEntry.class.getName());
69
  /** The DER encoded form of this CRL entry. */
70
  private byte[] encoded;
71
 
72
  /** The revoked certificate's serial number. */
73
  private BigInteger serialNo;
74
 
75
  /** The date the certificate was revoked. */
76
  private Date revocationDate;
77
 
78
  /** The CRL entry extensions. */
79
  private HashMap extensions;
80
 
81
  // Constructor.
82
  // ------------------------------------------------------------------------
83
 
84
  /**
85
   * Create a new X.509 certificate revocation list entry from the given
86
   * input stream and CRL version number.
87
   *
88
   * @param version The CRL version.
89
   * @param encoded The stream of DER bytes.
90
   * @throws CRLException If the ASN.1 structure is invalid.
91
   * @throws IOException  If the bytes cannot be read.
92
   */
93
  X509CRLEntry(int version, DERReader encoded)
94
    throws CRLException, IOException
95
  {
96
    super();
97
    extensions = new HashMap();
98
    try
99
      {
100
        parse(version, encoded);
101
      }
102
    catch (IOException ioe)
103
      {
104
        throw ioe;
105
      }
106
    catch (Exception x)
107
      {
108
        throw new CRLException(x.toString());
109
      }
110
  }
111
 
112
  // X509CRLEntry methods.
113
  // ------------------------------------------------------------------------
114
 
115
  public boolean equals(Object o)
116
  {
117
    if (!(o instanceof X509CRLEntry))
118
      return false;
119
    return ((X509CRLEntry) o).getSerialNumber().equals(serialNo) &&
120
           ((X509CRLEntry) o).getRevocationDate().equals(revocationDate);
121
  }
122
 
123
  public int hashCode()
124
  {
125
    return serialNo.hashCode();
126
  }
127
 
128
  public byte[] getEncoded() throws CRLException
129
  {
130
    return (byte[]) encoded.clone();
131
  }
132
 
133
  public BigInteger getSerialNumber()
134
  {
135
    return serialNo;
136
  }
137
 
138
  public Date getRevocationDate()
139
  {
140
    return (Date) revocationDate.clone();
141
  }
142
 
143
  public boolean hasExtensions()
144
  {
145
    return ! extensions.isEmpty();
146
  }
147
 
148
  public String toString()
149
  {
150
    return "X509CRLEntry serial=" + serialNo + " revocation date="
151
      + revocationDate + " ext=" + extensions;
152
  }
153
 
154
  // X509Extension methods.
155
  // -------------------------------------------------------------------------
156
 
157
  public boolean hasUnsupportedCriticalExtension()
158
  {
159
    for (Iterator it = extensions.values().iterator(); it.hasNext(); )
160
      {
161
        Extension e = (Extension) it.next();
162
        if (e.isCritical() && !e.isSupported())
163
          return true;
164
      }
165
    return false;
166
  }
167
 
168
  public Set getCriticalExtensionOIDs()
169
  {
170
    HashSet s = new HashSet();
171
    for (Iterator it = extensions.values().iterator(); it.hasNext(); )
172
      {
173
        Extension e = (Extension) it.next();
174
        if (e.isCritical())
175
          s.add(e.getOid().toString());
176
      }
177
    return Collections.unmodifiableSet(s);
178
  }
179
 
180
  public Set getNonCriticalExtensionOIDs()
181
  {
182
    HashSet s = new HashSet();
183
    for (Iterator it = extensions.values().iterator(); it.hasNext(); )
184
      {
185
        Extension e = (Extension) it.next();
186
        if (!e.isCritical())
187
          s.add(e.getOid().toString());
188
      }
189
    return Collections.unmodifiableSet(s);
190
  }
191
 
192
  public byte[] getExtensionValue(String oid)
193
  {
194
    Extension e = getExtension(new OID(oid));
195
    if (e != null)
196
      {
197
        return e.getValue().getEncoded();
198
      }
199
    return null;
200
  }
201
 
202
  // GnuPKIExtension method.
203
  // -------------------------------------------------------------------------
204
 
205
  public Extension getExtension(OID oid)
206
  {
207
    return (Extension) extensions.get(oid);
208
  }
209
 
210
  public Collection getExtensions()
211
  {
212
    return extensions.values();
213
  }
214
 
215
  // Own methods.
216
  // -------------------------------------------------------------------------
217
 
218
  private void parse(int version, DERReader der) throws Exception
219
  {
220
    // RevokedCertificate ::= SEQUENCE {
221
    DERValue entry = der.read();
222
    if (Configuration.DEBUG)
223
      log.fine("start CRL entry   len == " + entry.getLength());
224
    if (!entry.isConstructed())
225
      throw new IOException("malformed revokedCertificate");
226
    encoded = entry.getEncoded();
227
    int len = 0;
228
    if (Configuration.DEBUG)
229
      log.fine("encoded entry:\n" + Util.hexDump(encoded, ">>>> "));
230
 
231
    //   userCertificate   CertificateSerialNumber,
232
    DERValue val = der.read();
233
    serialNo = (BigInteger) val.getValue();
234
    len += val.getEncodedLength();
235
    if (Configuration.DEBUG)
236
      log.fine("userCertificate == " + serialNo + "  current count == " + len);
237
 
238
    //   revocationDate   Time,
239
    val = der.read();
240
    revocationDate = (Date) val.getValue();
241
    len += val.getEncodedLength();
242
    if (Configuration.DEBUG)
243
      log.fine("revocationDate == " + revocationDate + "  current count == "
244
               + len);
245
    //   crlEntryExtensions   Extensions OPTIONAL
246
    //                          -- if present MUST be v2
247
    if (len < entry.getLength())
248
      {
249
        if (version < 2)
250
          throw new IOException("extra data in CRL entry");
251
        DERValue exts = der.read();
252
        if (!exts.isConstructed())
253
          throw new IOException("malformed Extensions");
254
        if (Configuration.DEBUG)
255
          log.fine("start Extensions  len == " + exts.getLength());
256
        len = 0;
257
        while (len < exts.getLength())
258
          {
259
            val = der.read();
260
            if (!val.isConstructed())
261
              throw new IOException("malformed Extension");
262
            if (Configuration.DEBUG)
263
              log.fine("start Extension  len == " + val.getLength());
264
            Extension e = new Extension(val.getEncoded());
265
            extensions.put(e.getOid(), e);
266
            der.skip(val.getLength());
267
            len += val.getEncodedLength();
268
            if (Configuration.DEBUG)
269
              log.fine("current count == " + len);
270
          }
271
      }
272
  }
273
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.