3261N/A * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * given a non-blocking SocketChannel, it produces 0N/A * and handle the SSL handshaking automatically. 0N/A /* held by thread doing the hand-shake on this connection */ 0N/A /* tiger compatibility */ 0N/A * cleanup resources allocated inside this object 0N/A * return the SSL InputStream 0N/A * return the SSL OutputStream 0N/A * request the engine to repeat the handshake on this session 0N/A * Normally, not necessary to call this. 0N/A /* if passed in buffer was not big enough then the 0N/A * a reallocated buffer is returned here 0N/A synchronized (
this) {
0N/A /* reallocates the buffer by :- 0N/A * 1. creating a new buffer double the size of the old one 0N/A * 2. putting the contents of the old buffer into the new one 0N/A * 3. set xx_buf_size to the new size if it was smaller than new size 0N/A * flip is set to true if the old buffer needs to be flipped 0N/A * before it is copied. 0N/A synchronized (
this) {
0N/A * This is a thin wrapper over SSLEngine and the SocketChannel, 0N/A * which guarantees the ordering of wraps/unwraps with respect to the underlying 0N/A * It does not handle the handshaking status codes, or the CLOSED status code 0N/A * though once the engine is closed, any attempt to read/write to it 0N/A * will get an exception. The overall result is returned. 0N/A int u_remaining;
// the number of bytes left in unwrap_src after an unwrap() 0N/A /* try to wrap and send the data in src. Handles OVERFLOW. 0N/A * Might block if there is an outbound blockage or if another 0N/A * thread is calling wrap(). Also, might not send any data 0N/A * if an unwrap is needed. 0N/A /* block until a complete message is available and return it 0N/A * in dst, together with the Result. dst may have been re-allocated 0N/A * so caller should check the returned value in Result 0N/A * If handshaking is in progress then, possibly no data is returned 0N/A /* buffer not big enough */ 0N/A /* Buffer not full, just need to read more 0N/A * data off the channel. Reset pointers 0N/A * for reading off SocketChannel 0N/A * send the data in the given ByteBuffer. If a handshake is needed 0N/A * then this is handled within this method. When this call returns, 0N/A * all of the given user data has been sent and any handshake has been 0N/A * completed. Caller should check if engine has been closed. 0N/A * read data thru the engine into the given ByteBuffer. If the 0N/A * given buffer was not large enough, a new one is allocated 0N/A * and returned. This call handles handshaking automatically. 0N/A * Caller should check if engine has been closed. 0N/A /* we wait until some user data arrives */ 0N/A /* we've received a close notify. Need to call wrap to send 0N/A /* do the (complete) handshake after acquiring the handshake lock. 0N/A * If two threads call this at the same time, then we depend 0N/A * on the wrapper methods being idempotent. eg. if wrapAndSend() 0N/A * is called with no data to send then there must be no problem 0N/A /* run in current thread, because we are already 0N/A * running an external Executor 0N/A /* fall thru - call wrap again */ 0N/A * represents an SSL input stream. Multiple https requests can 0N/A * be sent over one stream. closing this stream causes an SSL close 0N/A /* this stream eof */ 0N/A /* copy as much as possible from buf into users buf */ 0N/A return false;
/* not possible with SSLEngine */ 0N/A * close the SSL connection. All data must have been consumed 0N/A * before this is called. Otherwise an exception will be thrown. 0N/A * [Note. May need to revisit this. not quite the normal close() symantics 0N/A * represents an SSL output stream. plain text data written to this stream 0N/A * is encrypted by the stream. Multiple HTTPS responses can be sent on 0N/A * one stream. closing this stream initiates an SSL closure