< prev index next >

src/java.base/share/classes/sun/security/ssl/SSLEngineOutputRecord.java

Print this page


   1 /*
   2  * Copyright (c) 1996, 2019, 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


  34 
  35 /**
  36  * {@code OutputRecord} implementation for {@code SSLEngine}.
  37  */
  38 final class SSLEngineOutputRecord extends OutputRecord implements SSLRecord {
  39 
  40     private HandshakeFragment fragmenter = null;
  41     private boolean isTalkingToV2 = false;      // SSLv2Hello
  42     private ByteBuffer v2ClientHello = null;    // SSLv2Hello
  43 
  44     private volatile boolean isCloseWaiting = false;
  45 
  46     SSLEngineOutputRecord(HandshakeHash handshakeHash) {
  47         super(handshakeHash, SSLWriteCipher.nullTlsWriteCipher());
  48 
  49         this.packetSize = SSLRecord.maxRecordSize;
  50         this.protocolVersion = ProtocolVersion.NONE;
  51     }
  52 
  53     @Override
  54     public void close() throws IOException {
  55         recordLock.lock();
  56         try {
  57             if (!isClosed) {
  58                 if (fragmenter != null && fragmenter.hasAlert()) {
  59                     isCloseWaiting = true;
  60                 } else {
  61                     super.close();
  62                 }
  63             }
  64         } finally {
  65             recordLock.unlock();
  66         }
  67     }
  68 
  69     boolean isClosed() {
  70         return isClosed || isCloseWaiting;
  71     }
  72 
  73     @Override
  74     void encodeAlert(byte level, byte description) throws IOException {
  75         if (isClosed()) {
  76             if (SSLLogger.isOn && SSLLogger.isOn("ssl")) {
  77                 SSLLogger.warning("outbound has closed, ignore outbound " +
  78                     "alert message: " + Alert.nameOf(description));
  79             }
  80             return;
  81         }
  82 
  83         if (fragmenter == null) {
  84            fragmenter = new HandshakeFragment();
  85         }


   1 /*
   2  * Copyright (c) 1996, 2018, 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


  34 
  35 /**
  36  * {@code OutputRecord} implementation for {@code SSLEngine}.
  37  */
  38 final class SSLEngineOutputRecord extends OutputRecord implements SSLRecord {
  39 
  40     private HandshakeFragment fragmenter = null;
  41     private boolean isTalkingToV2 = false;      // SSLv2Hello
  42     private ByteBuffer v2ClientHello = null;    // SSLv2Hello
  43 
  44     private volatile boolean isCloseWaiting = false;
  45 
  46     SSLEngineOutputRecord(HandshakeHash handshakeHash) {
  47         super(handshakeHash, SSLWriteCipher.nullTlsWriteCipher());
  48 
  49         this.packetSize = SSLRecord.maxRecordSize;
  50         this.protocolVersion = ProtocolVersion.NONE;
  51     }
  52 
  53     @Override
  54     public synchronized void close() throws IOException {
  55         if (!isClosed) {
  56             if (fragmenter != null && fragmenter.hasAlert()) {
  57                 isCloseWaiting = true;
  58             } else {
  59                 super.close();



  60             }


  61         }
  62     }
  63 
  64     boolean isClosed() {
  65         return isClosed || isCloseWaiting;
  66     }
  67 
  68     @Override
  69     void encodeAlert(byte level, byte description) throws IOException {
  70         if (isClosed()) {
  71             if (SSLLogger.isOn && SSLLogger.isOn("ssl")) {
  72                 SSLLogger.warning("outbound has closed, ignore outbound " +
  73                     "alert message: " + Alert.nameOf(description));
  74             }
  75             return;
  76         }
  77 
  78         if (fragmenter == null) {
  79            fragmenter = new HandshakeFragment();
  80         }


< prev index next >