< prev index next >

## src/java.base/share/classes/java/security/cert/CertificateRevokedException.java

Print this page

      1 /*
      2  * Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved.
      3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
      4  *
      5  * This code is free software; you can redistribute it and/or modify it
      6  * under the terms of the GNU General Public License version 2 only, as
      7  * published by the Free Software Foundation.  Oracle designates this
      8  * particular file as subject to the "Classpath" exception as provided
      9  * by Oracle in the LICENSE file that accompanied this code.
     10  *
     11  * This code is distributed in the hope that it will be useful, but WITHOUT
     12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     14  * version 2 for more details (a copy is included in the LICENSE file that
     15  * accompanied this code).
     16  *
     17  * You should have received a copy of the GNU General Public License version
     18  * 2 along with this work; if not, write to the Free Software Foundation,
     19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
     20  *
     21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
     22  * or visit www.oracle.com if you need additional information or have any
    175     public Map<String, Extension> getExtensions() {
    176         return Collections.unmodifiableMap(extensions);
    177     }
    178
    179     @Override
    180     public String getMessage() {
    181         return "Certificate has been revoked, reason: "
    182                + reason + ", revocation date: " + revocationDate
    183                + ", authority: " + authority + ", extension OIDs: "
    184                + extensions.keySet();
    185     }
    186
    187     /**
    188      * Serialize this {@code CertificateRevokedException} instance.
    189      *
    190      * @serialData the size of the extensions map (int), followed by all of
    191      * the extensions in the map, in no particular order. For each extension,
    192      * the following data is emitted: the OID String (Object), the criticality
    193      * flag (boolean), the length of the encoded extension value byte array
    194      * (int), and the encoded extension value bytes.

    195      */
    196     @java.io.Serial
    197     private void writeObject(ObjectOutputStream oos) throws IOException {
    198         // Write out the non-transient fields
    199         // (revocationDate, reason, authority)
    200         oos.defaultWriteObject();
    201
    202         // Write out the size (number of mappings) of the extensions map
    203         oos.writeInt(extensions.size());
    204
    205         // For each extension in the map, the following are emitted (in order):
    206         // the OID String (Object), the criticality flag (boolean), the length
    207         // of the encoded extension value byte array (int), and the encoded
    208         // extension value byte array. The extensions themselves are emitted
    209         // in no particular order.
    210         for (Map.Entry<String, Extension> entry : extensions.entrySet()) {
    211             Extension ext = entry.getValue();
    212             oos.writeObject(ext.getId());
    213             oos.writeBoolean(ext.isCritical());
    214             byte[] extVal = ext.getValue();
    215             oos.writeInt(extVal.length);
    216             oos.write(extVal);
    217         }
    218     }
    219
    220     /**
    221      * Deserialize the {@code CertificateRevokedException} instance.

    222      */
    223     @java.io.Serial
    224     private void readObject(ObjectInputStream ois)
    225         throws IOException, ClassNotFoundException {
    226         // Read in the non-transient fields
    227         // (revocationDate, reason, authority)
    228         ois.defaultReadObject();
    229
    230         // Defensively copy the revocation date
    231         revocationDate = new Date(revocationDate.getTime());
    232
    233         // Read in the size (number of mappings) of the extensions map
    234         // and create the extensions map
    235         int size = ois.readInt();
    236         if (size == 0) {
    237             extensions = Collections.emptyMap();
    238         } else if (size < 0) {
    239             throw new IOException("size cannot be negative");
    240         } else {
    241             extensions = new HashMap<>(size > 20 ? 20 : size);
      1 /*
      2  * Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
      3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
      4  *
      5  * This code is free software; you can redistribute it and/or modify it
      6  * under the terms of the GNU General Public License version 2 only, as
      7  * published by the Free Software Foundation.  Oracle designates this
      8  * particular file as subject to the "Classpath" exception as provided
      9  * by Oracle in the LICENSE file that accompanied this code.
     10  *
     11  * This code is distributed in the hope that it will be useful, but WITHOUT
     12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     14  * version 2 for more details (a copy is included in the LICENSE file that
     15  * accompanied this code).
     16  *
     17  * You should have received a copy of the GNU General Public License version
     18  * 2 along with this work; if not, write to the Free Software Foundation,
     19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
     20  *
     21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
     22  * or visit www.oracle.com if you need additional information or have any
    175     public Map<String, Extension> getExtensions() {
    176         return Collections.unmodifiableMap(extensions);
    177     }
    178
    179     @Override
    180     public String getMessage() {
    181         return "Certificate has been revoked, reason: "
    182                + reason + ", revocation date: " + revocationDate
    183                + ", authority: " + authority + ", extension OIDs: "
    184                + extensions.keySet();
    185     }
    186
    187     /**
    188      * Serialize this {@code CertificateRevokedException} instance.
    189      *
    190      * @serialData the size of the extensions map (int), followed by all of
    191      * the extensions in the map, in no particular order. For each extension,
    192      * the following data is emitted: the OID String (Object), the criticality
    193      * flag (boolean), the length of the encoded extension value byte array
    194      * (int), and the encoded extension value bytes.
    195      *
    196      * @param  oos the {@code ObjectOutputStream} to which data is written
    197      * @throws IOException if an I/O error occurs
    198      */
    199     @java.io.Serial
    200     private void writeObject(ObjectOutputStream oos) throws IOException {
    201         // Write out the non-transient fields
    202         // (revocationDate, reason, authority)
    203         oos.defaultWriteObject();
    204
    205         // Write out the size (number of mappings) of the extensions map
    206         oos.writeInt(extensions.size());
    207
    208         // For each extension in the map, the following are emitted (in order):
    209         // the OID String (Object), the criticality flag (boolean), the length
    210         // of the encoded extension value byte array (int), and the encoded
    211         // extension value byte array. The extensions themselves are emitted
    212         // in no particular order.
    213         for (Map.Entry<String, Extension> entry : extensions.entrySet()) {
    214             Extension ext = entry.getValue();
    215             oos.writeObject(ext.getId());
    216             oos.writeBoolean(ext.isCritical());
    217             byte[] extVal = ext.getValue();
    218             oos.writeInt(extVal.length);
    219             oos.write(extVal);
    220         }
    221     }
    222
    223     /**
    224      * Deserialize the {@code CertificateRevokedException} instance.
    225      *
    226      * @param  ois the {@code ObjectInputStream} from which data is read
    227      * @throws IOException if an I/O error occurs
    228      * @throws ClassNotFoundException if a serialized class cannot be loaded
    229      */
    230     @java.io.Serial
    231     private void readObject(ObjectInputStream ois)
    232         throws IOException, ClassNotFoundException {
    233         // Read in the non-transient fields
    234         // (revocationDate, reason, authority)
    235         ois.defaultReadObject();
    236
    237         // Defensively copy the revocation date
    238         revocationDate = new Date(revocationDate.getTime());
    239
    240         // Read in the size (number of mappings) of the extensions map
    241         // and create the extensions map
    242         int size = ois.readInt();
    243         if (size == 0) {
    244             extensions = Collections.emptyMap();
    245         } else if (size < 0) {
    246             throw new IOException("size cannot be negative");
    247         } else {
    248             extensions = new HashMap<>(size > 20 ? 20 : size);

< prev index next >