jdk/src/share/classes/javax/net/ssl/SSLEngine.java
author alanb
Mon, 10 Jun 2013 12:58:32 +0100
changeset 18156 edb590d448c5
parent 14194 971f46db533d
child 21955 abc02575919c
permissions -rw-r--r--
8016217: More javadoc warnings Reviewed-by: lancea, chegar, psandoz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10915
diff changeset
     2
 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.net.ssl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.nio.ByteBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.nio.ReadOnlyBufferException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * A class which enables secure communications using protocols such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * the Secure Sockets Layer (SSL) or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <A HREF="http://www.ietf.org/rfc/rfc2246.txt"> IETF RFC 2246 "Transport
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * Layer Security" (TLS) </A> protocols, but is transport independent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * The secure communications modes include: <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *      <LI> <em>Integrity Protection</em>.  SSL/TLS protects against
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *      modification of messages by an active wiretapper.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *      <LI> <em>Authentication</em>.  In most modes, SSL/TLS provides
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *      peer authentication.  Servers are usually authenticated, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *      clients may be authenticated as requested by servers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *      <LI> <em>Confidentiality (Privacy Protection)</em>.  In most
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *      modes, SSL/TLS encrypts data being sent between client and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *      server.  This protects the confidentiality of data, so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *      passive wiretappers won't see sensitive data such as financial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *      information or personal information of many kinds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *      </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * These kinds of protection are specified by a "cipher suite", which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * is a combination of cryptographic algorithms used by a given SSL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * connection.  During the negotiation process, the two endpoints must
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * agree on a cipher suite that is available in both environments.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * there is no such suite in common, no SSL connection can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * established, and no data can be exchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * The cipher suite used is established by a negotiation process called
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * "handshaking".  The goal of this process is to create or rejoin a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * "session", which may protect many connections over time.  After
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * handshaking has completed, you can access session attributes by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * using the {@link #getSession()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * The <code>SSLSocket</code> class provides much of the same security
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * functionality, but all of the inbound and outbound data is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * automatically transported using the underlying {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * java.net.Socket Socket}, which by design uses a blocking model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * While this is appropriate for many applications, this model does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * provide the scalability required by large servers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * The primary distinction of an <code>SSLEngine</code> is that it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * operates on inbound and outbound byte streams, independent of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * transport mechanism.  It is the responsibility of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <code>SSLEngine</code> user to arrange for reliable I/O transport to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * the peer.  By separating the SSL/TLS abstraction from the I/O
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * transport mechanism, the <code>SSLEngine</code> can be used for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * wide variety of I/O types, such as {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * java.nio.channels.spi.AbstractSelectableChannel#configureBlocking(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * non-blocking I/O (polling)}, {@link java.nio.channels.Selector
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * selectable non-blocking I/O}, {@link java.net.Socket Socket} and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * traditional Input/OutputStreams, local {@link java.nio.ByteBuffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * ByteBuffers} or byte arrays, <A
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * HREF="http://www.jcp.org/en/jsr/detail?id=203"> future asynchronous
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * I/O models </A>, and so on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * At a high level, the <code>SSLEngine</code> appears thus:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *                   app data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *                |           ^
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *                |     |     |
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *                v     |     |
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *           +----+-----|-----+----+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *           |          |          |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *           |       SSL|Engine    |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *   wrap()  |          |          |  unwrap()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 *           | OUTBOUND | INBOUND  |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 *           |          |          |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 *           +----+-----|-----+----+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *                |     |     ^
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 *                |     |     |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 *                v           |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 *                   net data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * Application data (also known as plaintext or cleartext) is data which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * is produced or consumed by an application.  Its counterpart is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * network data, which consists of either handshaking and/or ciphertext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * (encrypted) data, and destined to be transported via an I/O
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * mechanism.  Inbound data is data which has been received from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * peer, and outbound data is destined for the peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * (In the context of an <code>SSLEngine</code>, the term "handshake
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * data" is taken to mean any data exchanged to establish and control a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * secure connection.  Handshake data includes the SSL/TLS messages
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * "alert", "change_cipher_spec," and "handshake.")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * There are five distinct phases to an <code>SSLEngine</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * <OL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 *     <li> Creation - The <code>SSLEngine</code> has been created and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 *     initialized, but has not yet been used.  During this phase, an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 *     application may set any <code>SSLEngine</code>-specific settings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 *     (enabled cipher suites, whether the <code>SSLEngine</code> should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 *     handshake in client or server mode, and so on).  Once
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 *     handshaking has begun, though, any new settings (except
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 *     client/server mode, see below) will be used for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 *     the next handshake.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 *     <li> Initial Handshake - The initial handshake is a procedure by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 *     which the two peers exchange communication parameters until an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 *     SSLSession is established.  Application data can not be sent during
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 *     this phase.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 *     <li> Application Data - Once the communication parameters have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 *     been established and the handshake is complete, application data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 *     may flow through the <code>SSLEngine</code>.  Outbound
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 *     application messages are encrypted and integrity protected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 *     and inbound messages reverse the process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 *     <li>  Rehandshaking - Either side may request a renegotiation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 *     the session at any time during the Application Data phase.  New
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 *     handshaking data can be intermixed among the application data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 *     Before starting the rehandshake phase, the application may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 *     reset the SSL/TLS communication parameters such as the list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 *     enabled ciphersuites and whether to use client authentication,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 *     but can not change between client/server modes.  As before, once
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 *     handshaking has begun, any new <code>SSLEngine</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 *     configuration settings will not be used until the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 *     handshake.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 *     <li>  Closure - When the connection is no longer needed, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 *     application should close the <code>SSLEngine</code> and should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 *     send/receive any remaining messages to the peer before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 *     closing the underlying transport mechanism.  Once an engine is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 *     closed, it is not reusable:  a new <code>SSLEngine</code> must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 *     be created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * </OL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * An <code>SSLEngine</code> is created by calling {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * SSLContext#createSSLEngine()} from an initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 * <code>SSLContext</code>.  Any configuration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 * parameters should be set before making the first call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 * <code>wrap()</code>, <code>unwrap()</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 * <code>beginHandshake()</code>.  These methods all trigger the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 * initial handshake.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * Data moves through the engine by calling {@link #wrap(ByteBuffer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * ByteBuffer) wrap()} or {@link #unwrap(ByteBuffer, ByteBuffer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * unwrap()} on outbound or inbound data, respectively.  Depending on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * the state of the <code>SSLEngine</code>, a <code>wrap()</code> call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * may consume application data from the source buffer and may produce
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * network data in the destination buffer.  The outbound data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 * may contain application and/or handshake data.  A call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 * <code>unwrap()</code> will examine the source buffer and may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 * advance the handshake if the data is handshaking information, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 * may place application data in the destination buffer if the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 * is application.  The state of the underlying SSL/TLS algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 * will determine when data is consumed and produced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 * Calls to <code>wrap()</code> and <code>unwrap()</code> return an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * <code>SSLEngineResult</code> which indicates the status of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 * operation, and (optionally) how to interact with the engine to make
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * progress.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 * The <code>SSLEngine</code> produces/consumes complete SSL/TLS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 * packets only, and does not store application data internally between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 * calls to <code>wrap()/unwrap()</code>.  Thus input and output
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 * <code>ByteBuffer</code>s must be sized appropriately to hold the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 * maximum record that can be produced.  Calls to {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 * SSLSession#getPacketBufferSize()} and {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 * SSLSession#getApplicationBufferSize()} should be used to determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
 * the appropriate buffer sizes.  The size of the outbound application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 * data buffer generally does not matter.  If buffer conditions do not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 * allow for the proper consumption/production of data, the application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 * must determine (via {@link SSLEngineResult}) and correct the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
 * problem, and then try the call again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 * For example, <code>unwrap()</code> will return a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 * SSLEngineResult.Status#BUFFER_OVERFLOW} result if the engine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 * determines that there is not enough destination buffer space available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 * Applications should call {@link SSLSession#getApplicationBufferSize()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 * and compare that value with the space available in the destination buffer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 * enlarging the buffer if necessary.  Similarly, if <code>unwrap()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 * were to return a {@link SSLEngineResult.Status#BUFFER_UNDERFLOW}, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
 * application should call {@link SSLSession#getPacketBufferSize()} to ensure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
 * that the source buffer has enough room to hold a record (enlarging if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
 * necessary), and then obtain more inbound data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
 *
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 14194
diff changeset
   214
 * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
 *   SSLEngineResult r = engine.unwrap(src, dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
 *   switch (r.getStatus()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
 *   BUFFER_OVERFLOW:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
 *       // Could attempt to drain the dst buffer of any already obtained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
 *       // data, but we'll just increase it to the size needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
 *       int appSize = engine.getSession().getApplicationBufferSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
 *       ByteBuffer b = ByteBuffer.allocate(appSize + dst.position());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
 *       dst.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
 *       b.put(dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
 *       dst = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
 *       // retry the operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
 *       break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
 *   BUFFER_UNDERFLOW:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
 *       int netSize = engine.getSession().getPacketBufferSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
 *       // Resize buffer if needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
 *       if (netSize > dst.capacity()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
 *           ByteBuffer b = ByteBuffer.allocate(netSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
 *           src.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
 *           b.put(src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
 *           src = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
 *       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
 *       // Obtain more inbound network data for src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
 *       // then retry the operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
 *       break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
 *   // other cases: CLOSED, OK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
 *   }
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 14194
diff changeset
   241
 * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
 * Unlike <code>SSLSocket</code>, all methods of SSLEngine are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
 * non-blocking.  <code>SSLEngine</code> implementations may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
 * require the results of tasks that may take an extended period of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
 * time to complete, or may even block.  For example, a TrustManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
 * may need to connect to a remote certificate validation service,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
 * or a KeyManager might need to prompt a user to determine which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
 * certificate to use as part of client authentication.  Additionally,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
 * creating cryptographic signatures and verifying them can be slow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
 * seemingly blocking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
 * For any operation which may potentially block, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
 * <code>SSLEngine</code> will create a {@link java.lang.Runnable}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
 * delegated task.  When <code>SSLEngineResult</code> indicates that a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
 * delegated task result is needed, the application must call {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
 * #getDelegatedTask()} to obtain an outstanding delegated task and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
 * call its {@link java.lang.Runnable#run() run()} method (possibly using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
 * a different thread depending on the compute strategy).  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
 * application should continue obtaining delegated tasks until no more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
 * exist, and try the original operation again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
 * At the end of a communication session, applications should properly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
 * close the SSL/TLS link.  The SSL/TLS protocols have closure handshake
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
 * messages, and these messages should be communicated to the peer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
 * before releasing the <code>SSLEngine</code> and closing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
 * underlying transport mechanism.  A close can be initiated by one of:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
 * an SSLException, an inbound closure handshake message, or one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
 * close methods.  In all cases, closure handshake messages are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
 * generated by the engine, and <code>wrap()</code> should be repeatedly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
 * called until the resulting <code>SSLEngineResult</code>'s status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
 * returns "CLOSED", or {@link #isOutboundDone()} returns true.  All
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
 * data obtained from the <code>wrap()</code> method should be sent to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
 * peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
 * {@link #closeOutbound()} is used to signal the engine that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
 * application will not be sending any more data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
 * A peer will signal its intent to close by sending its own closure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
 * handshake message.  After this message has been received and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
 * processed by the local <code>SSLEngine</code>'s <code>unwrap()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
 * call, the application can detect the close by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
 * <code>unwrap()</code> and looking for a <code>SSLEngineResult</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
 * with status "CLOSED", or if {@link #isInboundDone()} returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
 * If for some reason the peer closes the communication link without
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
 * sending the proper SSL/TLS closure message, the application can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
 * detect the end-of-stream and can signal the engine via {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
 * #closeInbound()} that there will no more inbound messages to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
 * process.  Some applications might choose to require orderly shutdown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
 * messages from a peer, in which case they can check that the closure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
 * was generated by a handshake message and not by an end-of-stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
 * condition.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
 * There are two groups of cipher suites which you will need to know
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
 * about when managing cipher suites:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
 * <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
 *      <LI> <em>Supported</em> cipher suites:  all the suites which are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
 *      supported by the SSL implementation.  This list is reported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
 *      using {@link #getSupportedCipherSuites()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
 *      <LI> <em>Enabled</em> cipher suites, which may be fewer than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
 *      the full set of supported suites.  This group is set using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
 *      {@link #setEnabledCipherSuites(String [])} method, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
 *      queried using the {@link #getEnabledCipherSuites()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
 *      Initially, a default set of cipher suites will be enabled on a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
 *      new engine that represents the minimum suggested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
 *      configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
 * </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
 * Implementation defaults require that only cipher suites which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
 * authenticate servers and provide confidentiality be enabled by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
 * default.  Only if both sides explicitly agree to unauthenticated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
 * and/or non-private (unencrypted) communications will such a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
 * cipher suite be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
 * Each SSL/TLS connection must have one client and one server, thus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
 * each endpoint must decide which role to assume.  This choice determines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
 * who begins the handshaking process as well as which type of messages
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
 * should be sent by each party.  The method {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
 * #setUseClientMode(boolean)} configures the mode.  Once the initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
 * handshaking has started, an <code>SSLEngine</code> can not switch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
 * between client and server modes, even when performing renegotiations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
 * Applications might choose to process delegated tasks in different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
 * threads.  When an <code>SSLEngine</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
 * is created, the current {@link java.security.AccessControlContext}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
 * is saved.  All future delegated tasks will be processed using this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
 * context:  that is, all access control decisions will be made using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
 * context captured at engine creation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
 * <HR>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
 * <B>Concurrency Notes</B>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
 * There are two concurrency issues to be aware of:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
 * <OL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
 *      <li>The <code>wrap()</code> and <code>unwrap()</code> methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
 *      may execute concurrently of each other.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
 *      <li> The SSL/TLS protocols employ ordered packets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
 *      Applications must take care to ensure that generated packets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
 *      are delivered in sequence.  If packets arrive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
 *      out-of-order, unexpected or fatal results may occur.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
 *      For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
 *      <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
 *              synchronized (outboundLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
 *                  sslEngine.wrap(src, dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
 *                  outboundQueue.put(dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
 *              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
 *      </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
 *      As a corollary, two threads must not attempt to call the same method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
 *      (either <code>wrap()</code> or <code>unwrap()</code>) concurrently,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
 *      because there is no way to guarantee the eventual packet ordering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
 * </OL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
 * @see SSLContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
 * @see SSLSocket
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
 * @see SSLServerSocket
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
 * @see SSLSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
 * @see java.net.Socket
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
 * @author Brad R. Wetmore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
public abstract class SSLEngine {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    private String peerHost = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    private int peerPort = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * Constructor for an <code>SSLEngine</code> providing no hints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * for an internal session reuse strategy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * @see     SSLContext#createSSLEngine()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * @see     SSLSessionContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    protected SSLEngine() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * Constructor for an <code>SSLEngine</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * <code>SSLEngine</code> implementations may use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * <code>peerHost</code> and <code>peerPort</code> parameters as hints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * for their internal session reuse strategy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * Some cipher suites (such as Kerberos) require remote hostname
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * information. Implementations of this class should use this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * constructor to use Kerberos.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * The parameters are not authenticated by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * <code>SSLEngine</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @param   peerHost the name of the peer host
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * @param   peerPort the port number of the peer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @see     SSLContext#createSSLEngine(String, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * @see     SSLSessionContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    protected SSLEngine(String peerHost, int peerPort) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        this.peerHost = peerHost;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        this.peerPort = peerPort;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * Returns the host name of the peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * Note that the value is not authenticated, and should not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * relied upon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @return  the host name of the peer, or null if nothing is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *          available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    public String getPeerHost() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        return peerHost;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * Returns the port number of the peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * Note that the value is not authenticated, and should not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * relied upon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * @return  the port number of the peer, or -1 if nothing is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *          available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    public int getPeerPort() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        return peerPort;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * Attempts to encode a buffer of plaintext application data into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * SSL/TLS network data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * An invocation of this method behaves in exactly the same manner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * as the invocation:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * {@link #wrap(ByteBuffer [], int, int, ByteBuffer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     *     engine.wrap(new ByteBuffer [] { src }, 0, 1, dst);}
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 14194
diff changeset
   445
     * </pre></blockquote>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @param   src
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     *          a <code>ByteBuffer</code> containing outbound application data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * @param   dst
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     *          a <code>ByteBuffer</code> to hold outbound network data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * @return  an <code>SSLEngineResult</code> describing the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     *          of this operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * @throws  SSLException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     *          A problem was encountered while processing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     *          data that caused the <code>SSLEngine</code> to abort.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     *          See the class description for more information on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     *          engine closure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * @throws  ReadOnlyBufferException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     *          if the <code>dst</code> buffer is read-only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * @throws  IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *          if either <code>src</code> or <code>dst</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     *          is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * @throws  IllegalStateException if the client/server mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *          has not yet been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * @see     #wrap(ByteBuffer [], int, int, ByteBuffer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    public SSLEngineResult wrap(ByteBuffer src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            ByteBuffer dst) throws SSLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        return wrap(new ByteBuffer [] { src }, 0, 1, dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * Attempts to encode plaintext bytes from a sequence of data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * buffers into SSL/TLS network data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * An invocation of this method behaves in exactly the same manner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * as the invocation:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * {@link #wrap(ByteBuffer [], int, int, ByteBuffer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     *     engine.wrap(srcs, 0, srcs.length, dst);}
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 14194
diff changeset
   481
     * </pre></blockquote>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * @param   srcs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     *          an array of <code>ByteBuffers</code> containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     *          outbound application data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * @param   dst
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     *          a <code>ByteBuffer</code> to hold outbound network data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * @return  an <code>SSLEngineResult</code> describing the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     *          of this operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * @throws  SSLException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     *          A problem was encountered while processing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     *          data that caused the <code>SSLEngine</code> to abort.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     *          See the class description for more information on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     *          engine closure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * @throws  ReadOnlyBufferException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     *          if the <code>dst</code> buffer is read-only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * @throws  IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     *          if either <code>srcs</code> or <code>dst</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     *          is null, or if any element in <code>srcs</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * @throws  IllegalStateException if the client/server mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     *          has not yet been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @see     #wrap(ByteBuffer [], int, int, ByteBuffer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    public SSLEngineResult wrap(ByteBuffer [] srcs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            ByteBuffer dst) throws SSLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        if (srcs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            throw new IllegalArgumentException("src == null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        return wrap(srcs, 0, srcs.length, dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * Attempts to encode plaintext bytes from a subsequence of data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * buffers into SSL/TLS network data.  This <i>"gathering"</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * operation encodes, in a single invocation, a sequence of bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * from one or more of a given sequence of buffers.  Gathering
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * wraps are often useful when implementing network protocols or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * file formats that, for example, group data into segments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * consisting of one or more fixed-length headers followed by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * variable-length body.  See
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * {@link java.nio.channels.GatheringByteChannel} for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * information on gathering, and {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * java.nio.channels.GatheringByteChannel#write(ByteBuffer[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * int, int)} for more information on the subsequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * Depending on the state of the SSLEngine, this method may produce
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * network data without consuming any application data (for example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * it may generate handshake data.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * The application is responsible for reliably transporting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * network data to the peer, and for ensuring that data created by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * multiple calls to wrap() is transported in the same order in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * it was generated.  The application must properly synchronize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * multiple calls to this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * If this <code>SSLEngine</code> has not yet started its initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * handshake, this method will automatically start the handshake.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * <P>
10915
1e20964cebf3 7064341: jsse/runtime security problem
xuelei
parents: 7043
diff changeset
   541
     * This method will attempt to produce SSL/TLS records, and will
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * consume as much source data as possible, but will never consume
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * more than the sum of the bytes remaining in each buffer.  Each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * <code>ByteBuffer</code>'s position is updated to reflect the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * amount of data consumed or produced.  The limits remain the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * The underlying memory used by the <code>srcs</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * <code>dst ByteBuffer</code>s must not be the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * See the class description for more information on engine closure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * @param   srcs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     *          an array of <code>ByteBuffers</code> containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     *          outbound application data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * @param   offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     *          The offset within the buffer array of the first buffer from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     *          which bytes are to be retrieved; it must be non-negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     *          and no larger than <code>srcs.length</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * @param   length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     *          The maximum number of buffers to be accessed; it must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     *          non-negative and no larger than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     *          <code>srcs.length</code>&nbsp;-&nbsp;<code>offset</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * @param   dst
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     *          a <code>ByteBuffer</code> to hold outbound network data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * @return  an <code>SSLEngineResult</code> describing the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     *          of this operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * @throws  SSLException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     *          A problem was encountered while processing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     *          data that caused the <code>SSLEngine</code> to abort.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     *          See the class description for more information on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     *          engine closure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * @throws  IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     *          if the preconditions on the <code>offset</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     *          <code>length</code> parameters do not hold.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * @throws  ReadOnlyBufferException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     *          if the <code>dst</code> buffer is read-only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * @throws  IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     *          if either <code>srcs</code> or <code>dst</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     *          is null, or if any element in the <code>srcs</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     *          subsequence specified is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * @throws  IllegalStateException if the client/server mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     *          has not yet been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * @see     java.nio.channels.GatheringByteChannel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * @see     java.nio.channels.GatheringByteChannel#write(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     *              ByteBuffer[], int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    public abstract SSLEngineResult wrap(ByteBuffer [] srcs, int offset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            int length, ByteBuffer dst) throws SSLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * Attempts to decode SSL/TLS network data into a plaintext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * application data buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * An invocation of this method behaves in exactly the same manner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * as the invocation:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * {@link #unwrap(ByteBuffer, ByteBuffer [], int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     *     engine.unwrap(src, new ByteBuffer [] { dst }, 0, 1);}
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 14194
diff changeset
   600
     * </pre></blockquote>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * @param   src
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     *          a <code>ByteBuffer</code> containing inbound network data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * @param   dst
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     *          a <code>ByteBuffer</code> to hold inbound application data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * @return  an <code>SSLEngineResult</code> describing the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     *          of this operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * @throws  SSLException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     *          A problem was encountered while processing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     *          data that caused the <code>SSLEngine</code> to abort.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     *          See the class description for more information on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     *          engine closure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * @throws  ReadOnlyBufferException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     *          if the <code>dst</code> buffer is read-only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * @throws  IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     *          if either <code>src</code> or <code>dst</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     *          is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * @throws  IllegalStateException if the client/server mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     *          has not yet been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * @see     #unwrap(ByteBuffer, ByteBuffer [], int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    public SSLEngineResult unwrap(ByteBuffer src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            ByteBuffer dst) throws SSLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        return unwrap(src, new ByteBuffer [] { dst }, 0, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * Attempts to decode SSL/TLS network data into a sequence of plaintext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * application data buffers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * An invocation of this method behaves in exactly the same manner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * as the invocation:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * {@link #unwrap(ByteBuffer, ByteBuffer [], int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     *     engine.unwrap(src, dsts, 0, dsts.length);}
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 14194
diff changeset
   636
     * </pre></blockquote>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * @param   src
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     *          a <code>ByteBuffer</code> containing inbound network data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * @param   dsts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     *          an array of <code>ByteBuffer</code>s to hold inbound
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     *          application data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * @return  an <code>SSLEngineResult</code> describing the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     *          of this operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * @throws  SSLException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     *          A problem was encountered while processing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     *          data that caused the <code>SSLEngine</code> to abort.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     *          See the class description for more information on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     *          engine closure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * @throws  ReadOnlyBufferException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     *          if any of the <code>dst</code> buffers are read-only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * @throws  IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     *          if either <code>src</code> or <code>dsts</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     *          is null, or if any element in <code>dsts</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * @throws  IllegalStateException if the client/server mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     *          has not yet been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * @see     #unwrap(ByteBuffer, ByteBuffer [], int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    public SSLEngineResult unwrap(ByteBuffer src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            ByteBuffer [] dsts) throws SSLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        if (dsts == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            throw new IllegalArgumentException("dsts == null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        return unwrap(src, dsts, 0, dsts.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * Attempts to decode SSL/TLS network data into a subsequence of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * plaintext application data buffers.  This <i>"scattering"</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * operation decodes, in a single invocation, a sequence of bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * into one or more of a given sequence of buffers.  Scattering
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * unwraps are often useful when implementing network protocols or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * file formats that, for example, group data into segments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * consisting of one or more fixed-length headers followed by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * variable-length body.  See
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * {@link java.nio.channels.ScatteringByteChannel} for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * information on scattering, and {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * java.nio.channels.ScatteringByteChannel#read(ByteBuffer[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * int, int)} for more information on the subsequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * Depending on the state of the SSLEngine, this method may consume
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * network data without producing any application data (for example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * it may consume handshake data.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * The application is responsible for reliably obtaining the network
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * data from the peer, and for invoking unwrap() on the data in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * order it was received.  The application must properly synchronize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * multiple calls to this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * If this <code>SSLEngine</code> has not yet started its initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * handshake, this method will automatically start the handshake.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * This method will attempt to consume one complete SSL/TLS network
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * packet, but will never consume more than the sum of the bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * remaining in the buffers.  Each <code>ByteBuffer</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * position is updated to reflect the amount of data consumed or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * produced.  The limits remain the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * The underlying memory used by the <code>src</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * <code>dsts ByteBuffer</code>s must not be the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * The inbound network buffer may be modified as a result of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * call:  therefore if the network data packet is required for some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * secondary purpose, the data should be duplicated before calling this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * method.  Note:  the network data will not be useful to a second
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * SSLEngine, as each SSLEngine contains unique random state which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * influences the SSL/TLS messages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * See the class description for more information on engine closure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * @param   src
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     *          a <code>ByteBuffer</code> containing inbound network data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * @param   dsts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     *          an array of <code>ByteBuffer</code>s to hold inbound
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     *          application data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * @param   offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     *          The offset within the buffer array of the first buffer from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     *          which bytes are to be transferred; it must be non-negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     *          and no larger than <code>dsts.length</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * @param   length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     *          The maximum number of buffers to be accessed; it must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     *          non-negative and no larger than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     *          <code>dsts.length</code>&nbsp;-&nbsp;<code>offset</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * @return  an <code>SSLEngineResult</code> describing the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     *          of this operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * @throws  SSLException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     *          A problem was encountered while processing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     *          data that caused the <code>SSLEngine</code> to abort.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     *          See the class description for more information on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     *          engine closure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * @throws  IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     *          If the preconditions on the <code>offset</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     *          <code>length</code> parameters do not hold.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * @throws  ReadOnlyBufferException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     *          if any of the <code>dst</code> buffers are read-only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * @throws  IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     *          if either <code>src</code> or <code>dsts</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     *          is null, or if any element in the <code>dsts</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     *          subsequence specified is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * @throws  IllegalStateException if the client/server mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     *          has not yet been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * @see     java.nio.channels.ScatteringByteChannel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * @see     java.nio.channels.ScatteringByteChannel#read(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     *              ByteBuffer[], int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    public abstract SSLEngineResult unwrap(ByteBuffer src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            ByteBuffer [] dsts, int offset, int length) throws SSLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * Returns a delegated <code>Runnable</code> task for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * this <code>SSLEngine</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * <code>SSLEngine</code> operations may require the results of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * operations that block, or may take an extended period of time to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * complete.  This method is used to obtain an outstanding {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * java.lang.Runnable} operation (task).  Each task must be assigned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * a thread (possibly the current) to perform the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * java.lang.Runnable#run() run} operation.  Once the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * <code>run</code> method returns, the <code>Runnable</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * is no longer needed and may be discarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * Delegated tasks run in the <code>AccessControlContext</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * in place when this object was created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * A call to this method will return each outstanding task
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * exactly once.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * Multiple delegated tasks can be run in parallel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * @return  a delegated <code>Runnable</code> task, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     *          if none are available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    public abstract Runnable getDelegatedTask();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * Signals that no more inbound network data will be sent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * to this <code>SSLEngine</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * If the application initiated the closing process by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * {@link #closeOutbound()}, under some circumstances it is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * required that the initiator wait for the peer's corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * close message.  (See section 7.2.1 of the TLS specification (<A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * HREF="http://www.ietf.org/rfc/rfc2246.txt">RFC 2246</A>) for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * information on waiting for closure alerts.)  In such cases, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * method need not be called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * But if the application did not initiate the closure process, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * if the circumstances above do not apply, this method should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * called whenever the end of the SSL/TLS data stream is reached.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * This ensures closure of the inbound side, and checks that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * peer followed the SSL/TLS close procedure properly, thus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * detecting possible truncation attacks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * This method is idempotent:  if the inbound side has already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * been closed, this method does not do anything.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * {@link #wrap(ByteBuffer, ByteBuffer) wrap()} should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * called to flush any remaining handshake data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * @throws  SSLException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     *          if this engine has not received the proper SSL/TLS close
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     *          notification message from the peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * @see     #isInboundDone()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * @see     #isOutboundDone()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    public abstract void closeInbound() throws SSLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     * Returns whether {@link #unwrap(ByteBuffer, ByteBuffer)} will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * accept any more inbound data messages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * @return  true if the <code>SSLEngine</code> will not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     *          consume anymore network data (and by implication,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     *          will not produce any more application data.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * @see     #closeInbound()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    public abstract boolean isInboundDone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * Signals that no more outbound application data will be sent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * on this <code>SSLEngine</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * This method is idempotent:  if the outbound side has already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * been closed, this method does not do anything.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * {@link #wrap(ByteBuffer, ByteBuffer)} should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * called to flush any remaining handshake data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * @see     #isOutboundDone()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    public abstract void closeOutbound();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * Returns whether {@link #wrap(ByteBuffer, ByteBuffer)} will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * produce any more outbound data messages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * Note that during the closure phase, a <code>SSLEngine</code> may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * generate handshake closure data that must be sent to the peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * <code>wrap()</code> must be called to generate this data.  When
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * this method returns true, no more outbound data will be created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * @return  true if the <code>SSLEngine</code> will not produce
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     *          any more network data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * @see     #closeOutbound()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * @see     #closeInbound()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    public abstract boolean isOutboundDone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * Returns the names of the cipher suites which could be enabled for use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * on this engine.  Normally, only a subset of these will actually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * be enabled by default, since this list may include cipher suites which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * do not meet quality of service requirements for those defaults.  Such
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * cipher suites might be useful in specialized applications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * @return  an array of cipher suite names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * @see     #getEnabledCipherSuites()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * @see     #setEnabledCipherSuites(String [])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    public abstract String [] getSupportedCipherSuites();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * Returns the names of the SSL cipher suites which are currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * enabled for use on this engine.  When an SSLEngine is first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * created, all enabled cipher suites support a minimum quality of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * service.  Thus, in some environments this value might be empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * Even if a suite has been enabled, it might never be used.  (For
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * example, the peer does not support it, the requisite
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * certificates/private keys for the suite are not available, or an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * anonymous suite is enabled but authentication is required.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * @return  an array of cipher suite names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * @see     #getSupportedCipherSuites()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * @see     #setEnabledCipherSuites(String [])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
    public abstract String [] getEnabledCipherSuites();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     * Sets the cipher suites enabled for use on this engine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * Each cipher suite in the <code>suites</code> parameter must have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     * been listed by getSupportedCipherSuites(), or the method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * fail.  Following a successful call to this method, only suites
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * listed in the <code>suites</code> parameter are enabled for use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * See {@link #getEnabledCipherSuites()} for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     * on why a specific cipher suite may never be used on a engine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * @param   suites Names of all the cipher suites to enable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     * @throws  IllegalArgumentException when one or more of the ciphers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     *          named by the parameter is not supported, or when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     *          parameter is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     * @see     #getSupportedCipherSuites()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * @see     #getEnabledCipherSuites()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    public abstract void setEnabledCipherSuites(String suites []);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * Returns the names of the protocols which could be enabled for use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     * with this <code>SSLEngine</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * @return  an array of protocols supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    public abstract String [] getSupportedProtocols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * Returns the names of the protocol versions which are currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * enabled for use with this <code>SSLEngine</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * @return  an array of protocols
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * @see     #setEnabledProtocols(String [])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
    public abstract String [] getEnabledProtocols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     * Set the protocol versions enabled for use on this engine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     * The protocols must have been listed by getSupportedProtocols()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     * as being supported.  Following a successful call to this method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     * only protocols listed in the <code>protocols</code> parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     * are enabled for use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     * @param   protocols Names of all the protocols to enable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     * @throws  IllegalArgumentException when one or more of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     *          the protocols named by the parameter is not supported or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     *          when the protocols parameter is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     * @see     #getEnabledProtocols()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
    public abstract void setEnabledProtocols(String protocols[]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     * Returns the <code>SSLSession</code> in use in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     * <code>SSLEngine</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     * These can be long lived, and frequently correspond to an entire
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     * login session for some user.  The session specifies a particular
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     * cipher suite which is being actively used by all connections in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     * that session, as well as the identities of the session's client
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     * and server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     * Unlike {@link SSLSocket#getSession()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     * this method does not block until handshaking is complete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     * Until the initial handshake has completed, this method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     * a session object which reports an invalid cipher suite of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     * "SSL_NULL_WITH_NULL_NULL".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     * @return  the <code>SSLSession</code> for this <code>SSLEngine</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
     * @see     SSLSession
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
    public abstract SSLSession getSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
    /**
7043
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   971
     * Returns the {@code SSLSession} being constructed during a SSL/TLS
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   972
     * handshake.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   973
     * <p>
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   974
     * TLS protocols may negotiate parameters that are needed when using
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   975
     * an instance of this class, but before the {@code SSLSession} has
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   976
     * been completely initialized and made available via {@code getSession}.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   977
     * For example, the list of valid signature algorithms may restrict
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   978
     * the type of certificates that can used during TrustManager
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   979
     * decisions, or the maximum TLS fragment packet sizes can be
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   980
     * resized to better support the network environment.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   981
     * <p>
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   982
     * This method provides early access to the {@code SSLSession} being
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   983
     * constructed.  Depending on how far the handshake has progressed,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   984
     * some data may not yet be available for use.  For example, if a
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   985
     * remote server will be sending a Certificate chain, but that chain
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   986
     * has yet not been processed, the {@code getPeerCertificates}
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   987
     * method of {@code SSLSession} will throw a
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   988
     * SSLPeerUnverifiedException.  Once that chain has been processed,
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   989
     * {@code getPeerCertificates} will return the proper value.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   990
     *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   991
     * @see SSLSocket
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   992
     * @see SSLSession
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   993
     * @see ExtendedSSLSession
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   994
     * @see X509ExtendedKeyManager
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   995
     * @see X509ExtendedTrustManager
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   996
     *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   997
     * @return null if this instance is not currently handshaking, or
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   998
     *         if the current handshake has not progressed far enough to
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
   999
     *         create a basic SSLSession.  Otherwise, this method returns the
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1000
     *         {@code SSLSession} currently being negotiated.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1001
     * @throws UnsupportedOperationException if the underlying provider
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1002
     *         does not implement the operation.
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1003
     *
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1004
     * @since 1.7
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1005
     */
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1006
    public SSLSession getHandshakeSession() {
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1007
        throw new UnsupportedOperationException();
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1008
    }
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1009
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1010
5e2d1edeb2c7 6916074: Add support for TLS 1.2
xuelei
parents: 5506
diff changeset
  1011
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * Initiates handshaking (initial or renegotiation) on this SSLEngine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     * This method is not needed for the initial handshake, as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     * <code>wrap()</code> and <code>unwrap()</code> methods will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     * implicitly call this method if handshaking has not already begun.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * Note that the peer may also request a session renegotiation with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * this <code>SSLEngine</code> by sending the appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * session renegotiate handshake message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     * Unlike the {@link SSLSocket#startHandshake()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     * SSLSocket#startHandshake()} method, this method does not block
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * until handshaking is completed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     * To force a complete SSL/TLS session renegotiation, the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     * session should be invalidated prior to calling this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     * Some protocols may not support multiple handshakes on an existing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * engine and may throw an <code>SSLException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     * @throws  SSLException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     *          if a problem was encountered while signaling the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     *          <code>SSLEngine</code> to begin a new handshake.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     *          See the class description for more information on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     *          engine closure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     * @throws  IllegalStateException if the client/server mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     *          has not yet been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     * @see     SSLSession#invalidate()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    public abstract void beginHandshake() throws SSLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     * Returns the current handshake status for this <code>SSLEngine</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     * @return  the current <code>SSLEngineResult.HandshakeStatus</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
    public abstract SSLEngineResult.HandshakeStatus getHandshakeStatus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     * Configures the engine to use client (or server) mode when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     * handshaking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
     * This method must be called before any handshaking occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     * Once handshaking has begun, the mode can not be reset for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
     * life of this engine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     * Servers normally authenticate themselves, and clients
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     * are not required to do so.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * @param   mode true if the engine should start its handshaking
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     *          in "client" mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     * @throws  IllegalArgumentException if a mode change is attempted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     *          after the initial handshake has begun.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     * @see     #getUseClientMode()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
    public abstract void setUseClientMode(boolean mode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     * Returns true if the engine is set to use client mode when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     * handshaking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     * @return  true if the engine should do handshaking
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     *          in "client" mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     * @see     #setUseClientMode(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
    public abstract boolean getUseClientMode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
     * Configures the engine to <i>require</i> client authentication.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
     * option is only useful for engines in the server mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     * An engine's client authentication setting is one of the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
     * <li> client authentication required
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
     * <li> client authentication requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
     * <li> no client authentication desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
     * Unlike {@link #setWantClientAuth(boolean)}, if this option is set and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
     * the client chooses not to provide authentication information
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
     * about itself, <i>the negotiations will stop and the engine will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
     * begin its closure procedure</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
     * Calling this method overrides any previous setting made by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
     * this method or {@link #setWantClientAuth(boolean)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     * @param   need set to true if client authentication is required,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     *          or false if no client authentication is desired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     * @see     #getNeedClientAuth()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     * @see     #setWantClientAuth(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
     * @see     #getWantClientAuth()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
     * @see     #setUseClientMode(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
    public abstract void setNeedClientAuth(boolean need);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     * Returns true if the engine will <i>require</i> client authentication.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     * This option is only useful to engines in the server mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     * @return  true if client authentication is required,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
     *          or false if no client authentication is desired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
     * @see     #setNeedClientAuth(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
     * @see     #setWantClientAuth(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
     * @see     #getWantClientAuth()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
     * @see     #setUseClientMode(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
    public abstract boolean getNeedClientAuth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
     * Configures the engine to <i>request</i> client authentication.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     * This option is only useful for engines in the server mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
     * An engine's client authentication setting is one of the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     * <li> client authentication required
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
     * <li> client authentication requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     * <li> no client authentication desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     * Unlike {@link #setNeedClientAuth(boolean)}, if this option is set and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     * the client chooses not to provide authentication information
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     * about itself, <i>the negotiations will continue</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     * Calling this method overrides any previous setting made by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     * this method or {@link #setNeedClientAuth(boolean)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     * @param   want set to true if client authentication is requested,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     *          or false if no client authentication is desired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     * @see     #getWantClientAuth()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     * @see     #setNeedClientAuth(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     * @see     #getNeedClientAuth()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
     * @see     #setUseClientMode(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
    public abstract void setWantClientAuth(boolean want);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     * Returns true if the engine will <i>request</i> client authentication.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
     * This option is only useful for engines in the server mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
     * @return  true if client authentication is requested,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
     *          or false if no client authentication is desired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
     * @see     #setNeedClientAuth(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
     * @see     #getNeedClientAuth()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
     * @see     #setWantClientAuth(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     * @see     #setUseClientMode(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
    public abstract boolean getWantClientAuth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     * Controls whether new SSL sessions may be established by this engine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     * If session creations are not allowed, and there are no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     * existing sessions to resume, there will be no successful
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     * handshaking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     * @param   flag true indicates that sessions may be created; this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     *          is the default.  false indicates that an existing session
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     *          must be resumed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     * @see     #getEnableSessionCreation()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
    public abstract void setEnableSessionCreation(boolean flag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
     * Returns true if new SSL sessions may be established by this engine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
     * @return  true indicates that sessions may be created; this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     *          is the default.  false indicates that an existing session
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     *          must be resumed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     * @see     #setEnableSessionCreation(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
    public abstract boolean getEnableSessionCreation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     * Returns the SSLParameters in effect for this SSLEngine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     * The ciphersuites and protocols of the returned SSLParameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     * are always non-null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
     * @return the SSLParameters in effect for this SSLEngine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
    public SSLParameters getSSLParameters() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        SSLParameters params = new SSLParameters();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        params.setCipherSuites(getEnabledCipherSuites());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
        params.setProtocols(getEnabledProtocols());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        if (getNeedClientAuth()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            params.setNeedClientAuth(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
        } else if (getWantClientAuth()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
            params.setWantClientAuth(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
        return params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
     * Applies SSLParameters to this engine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
     * <p>This means:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
     * <ul>
14194
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10915
diff changeset
  1217
     * <li>If {@code params.getCipherSuites()} is non-null,
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10915
diff changeset
  1218
     *   {@code setEnabledCipherSuites()} is called with that value.</li>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10915
diff changeset
  1219
     * <li>If {@code params.getProtocols()} is non-null,
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10915
diff changeset
  1220
     *   {@code setEnabledProtocols()} is called with that value.</li>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10915
diff changeset
  1221
     * <li>If {@code params.getNeedClientAuth()} or
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10915
diff changeset
  1222
     *   {@code params.getWantClientAuth()} return {@code true},
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10915
diff changeset
  1223
     *   {@code setNeedClientAuth(true)} and
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10915
diff changeset
  1224
     *   {@code setWantClientAuth(true)} are called, respectively;
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10915
diff changeset
  1225
     *   otherwise {@code setWantClientAuth(false)} is called.</li>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10915
diff changeset
  1226
     * <li>If {@code params.getServerNames()} is non-null, the engine will
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10915
diff changeset
  1227
     *   configure its server names with that value.</li>
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10915
diff changeset
  1228
     * <li>If {@code params.getSNIMatchers()} is non-null, the engine will
971f46db533d 7068321: Support TLS Server Name Indication (SNI) Extension in JSSE Server
xuelei
parents: 10915
diff changeset
  1229
     *   configure its SNI matchers with that value.</li>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     * @param params the parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     * @throws IllegalArgumentException if the setEnabledCipherSuites() or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     *    the setEnabledProtocols() call fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
    public void setSSLParameters(SSLParameters params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        String[] s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
        s = params.getCipherSuites();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
        if (s != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
            setEnabledCipherSuites(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
        s = params.getProtocols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
        if (s != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
            setEnabledProtocols(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        if (params.getNeedClientAuth()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
            setNeedClientAuth(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
        } else if (params.getWantClientAuth()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
            setWantClientAuth(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
            setWantClientAuth(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
}