/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Implements the SSL session interface, and exposes the session context
* which is maintained by SSL servers.
*
* <P> Servers have the ability to manage the sessions associated with
* their authentication context(s). They can do this by enumerating the
* IDs of the sessions which are cached, examining those sessions, and then
* perhaps invalidating a given session so that it can't be used again.
* If servers do not explicitly manage the cache, sessions will linger
* until memory is low enough that the runtime environment purges cache
* entries automatically to reclaim space.
*
* <P><em> The only reason this class is not package-private is that
* there's no other public way to get at the server session context which
* is associated with any given authentication context. </em>
*
* @author David Brownell
*/
/*
* we only really need a single null session
*/
// compression methods
/*
* The state of a single session, as described in section 7.1
* of the SSLv3 spec.
*/
private byte compressionMethod;
/*
* Information not part of the SSLv3 protocol spec, but used
* to support session management policies.
*/
private final int port;
private int sessionCount;
private boolean invalidated;
// Principals for non-certificate based cipher suites
/*
* We count session creations, eventually for statistical data but
* also since counters make shorter debugging IDs than the big ones
* we use in the protocol for uniqueness-over-time.
*/
/*
*/
private static boolean defaultRejoinable = true;
/* Class and subclass dynamic debugging support */
/*
* Create a new non-rejoinable session, using the default (null)
* cipher spec. This constructor returns a session which could
* be used either by a client or by a server, as a connection is
* first opened and before handshaking begins.
*/
private SSLSessionImpl() {
}
/*
* Create a new session, using a given cipher spec. This will
* be rejoinable if session caching is enabled; the constructor
* is intended mostly for use by serves.
*/
}
/*
* Record a new session, using a given cipher spec and session ID.
*/
this.protocolVersion = protocolVersion;
this.cipherSuite = cipherSuite;
masterSecret = null;
sessionCount = ++counter;
}
}
if (masterSecret == null) {
} else {
throw new RuntimeException("setMasterSecret() error");
}
}
/**
* Returns the master secret ... treat with extreme caution!
*/
return masterSecret;
}
}
}
localCerts = local;
}
}
}
/**
* Set the peer principal.
*/
if (peerPrincipal == null) {
}
}
/**
* Set the local principal.
*/
}
/**
* Returns true iff this session may be resumed ... sessions are
* usually resumable. Security policies may suggest otherwise,
* for example sessions that haven't been used for a while (say,
* a working day) won't be resumable, and sessions might have a
* maximum lifetime in any case.
*/
boolean isRejoinable() {
}
public synchronized boolean isValid() {
return isRejoinable();
}
/**
* Check if the authentication used when establishing this session
* is still valid. Returns true if no authentication was used
*/
boolean isLocalAuthenticationValid() {
if (localPrivateKey != null) {
try {
// if the private key is no longer valid, getAlgorithm()
// should throw an exception
// (e.g. Smartcard has been removed from the reader)
} catch (Exception e) {
invalidate();
return false;
}
}
return true;
}
/**
* Returns the ID for this session. The ID is fixed for the
* duration of the session; neither it, nor its value, changes.
*/
public byte[] getId() {
}
/**
* For server sessions, this returns the set of sessions which
* are currently valid in this process. For client sessions,
* this returns null.
*/
/*
* An interim security policy until we can do something
* more specific in 1.2. Only allow trusted code (code which
* can set system properties) to get an
* SSLSessionContext. This is to limit the ability of code to
* look up specific sessions or enumerate over them. Otherwise,
* code can only get session objects from successful SSL
* connections which implies that they must have had permission
* to make the network connection in the first place.
*/
}
return context;
}
return sessionId;
}
/**
* Returns the cipher spec in use on this session
*/
return cipherSuite;
}
/**
* Resets the cipher spec in use on this session
*/
cipherSuite = suite;
}
}
/**
* Returns the name of the cipher suite in use on this session
*/
}
return protocolVersion;
}
/**
* Returns the standard name of the protocol in use on this session
*/
return getProtocolVersion().name;
}
/**
* Returns the compression technique used in this session
*/
byte getCompression() {
return compressionMethod;
}
/**
* Returns the hashcode for this session
*/
public int hashCode() {
}
/**
* Returns true if sessions have same ids, false otherwise.
*/
if (obj == this) {
return true;
}
if (obj instanceof SSLSessionImpl) {
sess.getSessionId()));
}
return false;
}
/**
* Return the cert chain presented by the peer in the
* java.security.cert format.
* Note: This method can be used only when using certificate-based
* cipher suites; using it with non-certificate-based cipher suites,
* such as Kerberos, will throw an SSLPeerUnverifiedException.
*
* @return array of peer X.509 certs, with the peer's own cert
* first in the chain, and with the "root" CA last.
*/
throws SSLPeerUnverifiedException {
//
// clone to preserve integrity of session ... caller can't
// change record of peer identity even by accident, much
// less do it intentionally.
//
throw new SSLPeerUnverifiedException("no certificates expected"
+ " for Kerberos cipher suites");
}
throw new SSLPeerUnverifiedException("peer not authenticated");
}
// Certs are immutable objects, therefore we don't clone them.
// But do need to clone the array, so that nothing is inserted
// into peerCerts.
}
/**
* Return the cert chain presented to the peer in the
* java.security.cert format.
* Note: This method is useful only when using certificate-based
* cipher suites.
*
* @return array of peer X.509 certs, with the peer's own cert
* first in the chain, and with the "root" CA last.
*/
//
// clone to preserve integrity of session ... caller can't
// change record of peer identity even by accident, much
// less do it intentionally.
}
/**
* Return the cert chain presented by the peer in the
* javax.security.cert format.
* Note: This method can be used only when using certificate-based
* cipher suites; using it with non-certificate-based cipher suites,
* such as Kerberos, will throw an SSLPeerUnverifiedException.
*
* @return array of peer X.509 certs, with the peer's own cert
* first in the chain, and with the "root" CA last.
*/
throws SSLPeerUnverifiedException {
//
// clone to preserve integrity of session ... caller can't
// change record of peer identity even by accident, much
// less do it intentionally.
//
throw new SSLPeerUnverifiedException("no certificates expected"
+ " for Kerberos cipher suites");
}
throw new SSLPeerUnverifiedException("peer not authenticated");
}
try {
} catch (CertificateEncodingException e) {
throw new SSLPeerUnverifiedException(e.getMessage());
throw new SSLPeerUnverifiedException(e.getMessage());
}
}
return certs;
}
/**
* Return the cert chain presented by the peer.
* Note: This method can be used only when using certificate-based
* cipher suites; using it with non-certificate-based cipher suites,
* such as Kerberos, will throw an SSLPeerUnverifiedException.
*
* @return array of peer X.509 certs, with the peer's own cert
* first in the chain, and with the "root" CA last.
*/
throws SSLPeerUnverifiedException {
/*
* clone to preserve integrity of session ... caller can't
* change record of peer identity even by accident, much
* less do it intentionally.
*/
throw new SSLPeerUnverifiedException("no certificates expected"
+ " for Kerberos cipher suites");
}
} else {
throw new SSLPeerUnverifiedException("peer not authenticated");
}
}
/**
* Returns the identity of the peer which was established as part of
* defining the session.
*
* @return the peer's principal. Returns an X500Principal of the
* end-entity certificate for X509-based cipher suites, and
* Principal for Kerberos cipher suites.
*
* @throws SSLPeerUnverifiedException if the peer's identity has not
* been verified
*/
throws SSLPeerUnverifiedException
{
if (peerPrincipal == null) {
throw new SSLPeerUnverifiedException("peer not authenticated");
} else {
// Eliminate dependency on KerberosPrincipal
return peerPrincipal;
}
}
throw new SSLPeerUnverifiedException("peer not authenticated");
}
}
/**
* Returns the principal that was sent to the peer during handshaking.
*
* @return the principal sent to the peer. Returns an X500Principal
* of the end-entity certificate for X509-based cipher suites, and
* Principal for Kerberos cipher suites. If no principal was
* sent, then null is returned.
*/
// Eliminate dependency on KerberosPrincipal
}
}
/**
* Returns the time this session was created.
*/
public long getCreationTime() {
return creationTime;
}
/**
* Returns the last time this session was used to initialize
* a connection.
*/
public long getLastAccessedTime() {
}
lastUsedTime = time;
}
/**
* Returns the network address of the session's peer. This
* implementation does not insist that connections between
* different ports on the same host must necessarily belong
* to different sessions, though that is of course allowed.
*/
try {
return null;
}
}
return host;
}
/**
* Need to provide the port info for caching sessions based on
* host and port. Accessed by SSLSessionContextImpl
*/
public int getPeerPort() {
return port;
}
}
}
/**
* Invalidate a session. Active connections may still exist, but
* no connections will be able to rejoin this session.
*/
synchronized public void invalidate() {
//
// Can't invalidate the NULL session -- this would be
// attempted when we get a handshaking error on a brand
// new connection, with no "real" session yet.
//
if (this == nullSession) {
return;
}
invalidated = true;
}
}
}
/*
* Table of application-specific session data indexed by an application
* key and the calling security context. This is important since
* sessions can be shared across different protection domains.
*/
/**
* Assigns a session value. Session change events are given if
* appropriate, to any original value as well as the new value.
*/
throw new IllegalArgumentException("arguments can not be null");
}
if (oldValue instanceof SSLSessionBindingListener) {
e = new SSLSessionBindingEvent(this, key);
}
if (value instanceof SSLSessionBindingListener) {
e = new SSLSessionBindingEvent(this, key);
}
}
/**
* Returns the specified session value.
*/
throw new IllegalArgumentException("argument can not be null");
}
}
/**
* Removes the specified session value, delivering a session changed
* event as appropriate.
*/
throw new IllegalArgumentException("argument can not be null");
}
if (value instanceof SSLSessionBindingListener) {
e = new SSLSessionBindingEvent(this, key);
}
}
/**
* Lists the names of the session values.
*/
Enumeration<SecureKey> e;
key = e.nextElement();
}
}
return names;
}
/**
* Use large packet sizes now or follow RFC 2246 packet sizes (2^14)
* until changed.
*
* In the TLS specification (section 6.2.1, RFC2246), it is not
* recommended that the plaintext has more than 2^14 bytes.
* However, some TLS implementations violate the specification.
* This is a workaround for interoperability with these stacks.
*
* Application could accept large fragments up to 2^15 bytes by
* setting the system property jsse.SSLEngine.acceptLargeFragments
* to "true".
*/
private boolean acceptLargeFragments =
/**
* application data.
*/
protected synchronized void expandBufferSizes() {
acceptLargeFragments = true;
}
/**
* when using this session.
*/
public synchronized int getPacketBufferSize() {
return acceptLargeFragments ?
}
/**
* Gets the current size of the largest application data that is
* expected when using this session.
*/
public synchronized int getApplicationBufferSize() {
}
/**
* Gets an array of supported signature algorithms that the local side is
* willing to verify.
*/
if (localSupportedSignAlgs != null) {
return localSupportedSignAlgs.clone();
}
return new String[0];
}
/**
* Gets an array of supported signature algorithms that the peer is
* able to verify.
*/
if (peerSupportedSignAlgs != null) {
return peerSupportedSignAlgs.clone();
}
return new String[0];
}
/** Returns a string representation of this SSL session */
return "[Session-" + sessionCount
+ ", " + getCipherSuite()
+ "]";
}
/**
* When SSL sessions are finalized, all values bound to
* them are removed.
*/
public void finalize() {
removeValue(names[i]);
}
}
}
/**
* This "struct" class serves as a Hash Key that combines an
* application-specific key and a security context.
*/
class SecureKey {
return context;
}
this.securityCtx = getCurrentSecurityContext();
}
return appKey;
}
return securityCtx;
}
public int hashCode() {
}
}
}