< prev index next >

src/share/classes/sun/security/ssl/CipherSuiteList.java

Print this page
rev 11548 : 8133070: Hot lock on BulkCipher.isAvailable
Reviewed-by: mullan
Contributed-by: xuelei.fan@oracle.com, kungu.mjh@alibaba-inc.com
   1 /*
   2  * Copyright (c) 2002, 2012, 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


  57      * Create a CipherSuiteList with a single element.
  58      */
  59     CipherSuiteList(CipherSuite suite) {
  60         cipherSuites = new ArrayList<CipherSuite>(1);
  61         cipherSuites.add(suite);
  62     }
  63 
  64     /**
  65      * Construct a CipherSuiteList from a array of names. We don't bother
  66      * to eliminate duplicates.
  67      *
  68      * @exception IllegalArgumentException if the array or any of its elements
  69      * is null or if the ciphersuite name is unrecognized or unsupported
  70      * using currently installed providers.
  71      */
  72     CipherSuiteList(String[] names) {
  73         if (names == null) {
  74             throw new IllegalArgumentException("CipherSuites may not be null");
  75         }
  76         cipherSuites = new ArrayList<CipherSuite>(names.length);
  77         // refresh available cache once if a CipherSuite is not available
  78         // (maybe new JCE providers have been installed)
  79         boolean refreshed = false;
  80         for (int i = 0; i < names.length; i++) {
  81             String suiteName = names[i];
  82             CipherSuite suite = CipherSuite.valueOf(suiteName);
  83             if (suite.isAvailable() == false) {
  84                 if (refreshed == false) {
  85                     // clear the cache so that the isAvailable() call below
  86                     // does a full check
  87                     clearAvailableCache();
  88                     refreshed = true;
  89                 }
  90                 // still missing?
  91                 if (suite.isAvailable() == false) {
  92                     throw new IllegalArgumentException("Cannot support "
  93                         + suiteName + " with currently installed providers");
  94                 }
  95             }
  96             cipherSuites.add(suite);
  97         }
  98     }
  99 
 100     /**
 101      * Read a CipherSuiteList from a HandshakeInStream in V3 ClientHello
 102      * format. Does not check if the listed ciphersuites are known or
 103      * supported.
 104      */
 105     CipherSuiteList(HandshakeInStream in) throws IOException {
 106         byte[] bytes = in.getBytes16();
 107         if ((bytes.length & 1) != 0) {
 108             throw new SSLException("Invalid ClientHello message");
 109         }
 110         cipherSuites = new ArrayList<CipherSuite>(bytes.length >> 1);
 111         for (int i = 0; i < bytes.length; i += 2) {
 112             cipherSuites.add(CipherSuite.valueOf(bytes[i], bytes[i+1]));
 113         }
 114     }
 115 


 177         return suiteNames.clone();
 178     }
 179 
 180     @Override
 181     public String toString() {
 182         return cipherSuites.toString();
 183     }
 184 
 185     /**
 186      * Write this list to an HandshakeOutStream in V3 ClientHello format.
 187      */
 188     void send(HandshakeOutStream s) throws IOException {
 189         byte[] suiteBytes = new byte[cipherSuites.size() * 2];
 190         int i = 0;
 191         for (CipherSuite c : cipherSuites) {
 192             suiteBytes[i] = (byte)(c.id >> 8);
 193             suiteBytes[i+1] = (byte)c.id;
 194             i += 2;
 195         }
 196         s.putBytes16(suiteBytes);
 197     }
 198 
 199     /**
 200      * Clear cache of available ciphersuites. If we support all ciphers
 201      * internally, there is no need to clear the cache and calling this
 202      * method has no effect.
 203      */
 204     static synchronized void clearAvailableCache() {
 205         if (CipherSuite.DYNAMIC_AVAILABILITY) {
 206             CipherSuite.BulkCipher.clearAvailableCache();
 207             JsseJce.clearEcAvailable();
 208         }
 209     }
 210 }
   1 /*
   2  * Copyright (c) 2002, 2015, 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


  57      * Create a CipherSuiteList with a single element.
  58      */
  59     CipherSuiteList(CipherSuite suite) {
  60         cipherSuites = new ArrayList<CipherSuite>(1);
  61         cipherSuites.add(suite);
  62     }
  63 
  64     /**
  65      * Construct a CipherSuiteList from a array of names. We don't bother
  66      * to eliminate duplicates.
  67      *
  68      * @exception IllegalArgumentException if the array or any of its elements
  69      * is null or if the ciphersuite name is unrecognized or unsupported
  70      * using currently installed providers.
  71      */
  72     CipherSuiteList(String[] names) {
  73         if (names == null) {
  74             throw new IllegalArgumentException("CipherSuites may not be null");
  75         }
  76         cipherSuites = new ArrayList<CipherSuite>(names.length);



  77         for (int i = 0; i < names.length; i++) {
  78             String suiteName = names[i];
  79             CipherSuite suite = CipherSuite.valueOf(suiteName);
  80             if (suite.isAvailable() == false) {








  81                 throw new IllegalArgumentException("Cannot support "
  82                     + suiteName + " with currently installed providers");
  83             }

  84             cipherSuites.add(suite);
  85         }
  86     }
  87 
  88     /**
  89      * Read a CipherSuiteList from a HandshakeInStream in V3 ClientHello
  90      * format. Does not check if the listed ciphersuites are known or
  91      * supported.
  92      */
  93     CipherSuiteList(HandshakeInStream in) throws IOException {
  94         byte[] bytes = in.getBytes16();
  95         if ((bytes.length & 1) != 0) {
  96             throw new SSLException("Invalid ClientHello message");
  97         }
  98         cipherSuites = new ArrayList<CipherSuite>(bytes.length >> 1);
  99         for (int i = 0; i < bytes.length; i += 2) {
 100             cipherSuites.add(CipherSuite.valueOf(bytes[i], bytes[i+1]));
 101         }
 102     }
 103 


 165         return suiteNames.clone();
 166     }
 167 
 168     @Override
 169     public String toString() {
 170         return cipherSuites.toString();
 171     }
 172 
 173     /**
 174      * Write this list to an HandshakeOutStream in V3 ClientHello format.
 175      */
 176     void send(HandshakeOutStream s) throws IOException {
 177         byte[] suiteBytes = new byte[cipherSuites.size() * 2];
 178         int i = 0;
 179         for (CipherSuite c : cipherSuites) {
 180             suiteBytes[i] = (byte)(c.id >> 8);
 181             suiteBytes[i+1] = (byte)c.id;
 182             i += 2;
 183         }
 184         s.putBytes16(suiteBytes);












 185     }
 186 }
< prev index next >