FileDocCategorySizeDatePackage
SSLSessionImpl.javaAPI DocAndroid 1.5 API11283Wed May 06 22:41:06 BST 2009org.apache.harmony.xnet.provider.jsse

SSLSessionImpl

public class SSLSessionImpl extends Object implements SSLSession
SSLSession implementation
see
javax.net.ssl.SSLSession

Fields Summary
public static final SSLSessionImpl
NULL_SESSION
Session object reporting an invalid cipher suite of "SSL_NULL_WITH_NULL_NULL"
private long
creationTime
private boolean
isValid
private org.apache.harmony.luni.util.TwoKeyHashMap
values
byte[]
id
ID of the session
long
lastAccessedTime
Last time the session was accessed
ProtocolVersion
protocol
Protocol used in the session
CipherSuite
cipherSuite
CipherSuite used in the session
SSLSessionContext
context
Context of the session
X509Certificate[]
localCertificates
certificates were sent to the peer
X509Certificate[]
peerCertificates
Peer certificates
String
peerHost
Peer host name
int
peerPort
Peer port number
byte[]
master_secret
Master secret
byte[]
clientRandom
clientRandom
byte[]
serverRandom
serverRandom
boolean
isServer
True if this entity is considered the server
Constructors Summary
public SSLSessionImpl(CipherSuite cipher_suite, SecureRandom sr)
Creates SSLSession implementation

param
cipher_suite
param
sr


                
         
        creationTime = System.currentTimeMillis();
        lastAccessedTime = creationTime;
        if (cipher_suite == null) {
            this.cipherSuite = CipherSuite.TLS_NULL_WITH_NULL_NULL;
            id = new byte[0];
            isServer = false;
        } else {
            this.cipherSuite = cipher_suite;
            id = new byte[32];
            sr.nextBytes(id);
            long time = new java.util.Date().getTime() / 1000;
            id[28] = (byte) ((time & 0xFF000000) >>> 24);
            id[29] = (byte) ((time & 0xFF0000) >>> 16);
            id[30] = (byte) ((time & 0xFF00) >>> 8);
            id[31] = (byte) (time & 0xFF);
            isServer = true;
        }

    
public SSLSessionImpl(SecureRandom sr)
Creates SSLSession implementation

param
sr

        this(null, sr);
    
private SSLSessionImpl()

    
Methods Summary
public java.lang.Objectclone()

        SSLSessionImpl ses = new SSLSessionImpl();
        ses.id = this.id;
        ses.creationTime = this.creationTime;
        ses.lastAccessedTime = this.lastAccessedTime;
        ses.isValid = this.isValid;
        ses.cipherSuite = this.cipherSuite;
        ses.localCertificates = this.localCertificates;
        ses.peerCertificates = this.peerCertificates;
        ses.master_secret = this.master_secret;
        ses.clientRandom = this.clientRandom;
        ses.serverRandom = this.serverRandom;
        ses.peerHost = this.peerHost;
        ses.peerPort = this.peerPort;
        ses.isServer = this.isServer;
        ses.context = this.context;
        ses.protocol = this.protocol;
        ses.values = this.values;
        return ses;
    
public intgetApplicationBufferSize()

see
javax.net.ssl.SSLSession#getApplicationBufferSize()

        return SSLRecordProtocol.MAX_DATA_LENGTH;
    
public java.lang.StringgetCipherSuite()

see
javax.net.ssl.SSLSession#getCipherSuite()

        return cipherSuite.getName();
    
public longgetCreationTime()

see
javax.net.ssl.SSLSession#getCreationTime()

        return creationTime;
    
public byte[]getId()

see
javax.net.ssl.SSLSession#getId()

        return id;
    
public longgetLastAccessedTime()

see
javax.net.ssl.SSLSession#getLastAccessedTime()

        return lastAccessedTime;
    
public java.security.cert.Certificate[]getLocalCertificates()

see
javax.net.ssl.SSLSession#getLocalCertificates()

        return localCertificates;
    
public java.security.PrincipalgetLocalPrincipal()

see
javax.net.ssl.SSLSession#getLocalPrincipal()

        if (localCertificates != null && localCertificates.length > 0) {
            return localCertificates[0].getSubjectX500Principal();
        } else {
            return null;
        }
    
public intgetPacketBufferSize()

see
javax.net.ssl.SSLSession#getPacketBufferSize()

        return SSLRecordProtocol.MAX_SSL_PACKET_SIZE;
    
public javax.security.cert.X509Certificate[]getPeerCertificateChain()

see
javax.net.ssl.SSLSession#getPeerCertificateChain()

        if (peerCertificates == null) {
            throw new SSLPeerUnverifiedException("No peer certificate");
        }
        javax.security.cert.X509Certificate[] certs = new javax.security.cert.X509Certificate[peerCertificates.length];
        for (int i = 0; i < certs.length; i++) {
            try {
                certs[i] = javax.security.cert.X509Certificate
                        .getInstance(peerCertificates[i].getEncoded());
            } catch (javax.security.cert.CertificateException e) {
            } catch (CertificateEncodingException e) {
            }
        }
        return certs;
    
public java.security.cert.Certificate[]getPeerCertificates()

see
javax.net.ssl.SSLSession#getPeerCertificates()

        if (peerCertificates == null) {
            throw new SSLPeerUnverifiedException("No peer certificate");
        }
        return peerCertificates;
    
public java.lang.StringgetPeerHost()

see
javax.net.ssl.SSLSession#getPeerHost()

        return peerHost;
    
public intgetPeerPort()

see
javax.net.ssl.SSLSession#getPeerPort()

        return peerPort;
    
public java.security.PrincipalgetPeerPrincipal()

see
javax.net.ssl.SSLSession#getPeerPrincipal()

        if (peerCertificates == null) {
            throw new SSLPeerUnverifiedException("No peer certificate");
        }
        return peerCertificates[0].getSubjectX500Principal();
    
public java.lang.StringgetProtocol()

see
javax.net.ssl.SSLSession#getProtocol()

        return protocol.name;
    
public javax.net.ssl.SSLSessionContextgetSessionContext()

see
javax.net.ssl.SSLSession#getSessionContext()

        SecurityManager sm = System.getSecurityManager();
        if (sm != null) {
            sm.checkPermission(new SSLPermission("getSSLSessionContext"));
        }
        return context;
    
public java.lang.ObjectgetValue(java.lang.String name)

see
javax.net.ssl.SSLSession#getValue(String name)

        if (name == null) {
            throw new IllegalArgumentException("Parameter is null");
        }
        return values.get(name, AccessController.getContext());
    
public java.lang.String[]getValueNames()

see
javax.net.ssl.SSLSession#getValueNames()

        Vector v = new Vector();
        AccessControlContext current = AccessController.getContext();
        AccessControlContext cont;
        for (Iterator it = values.entrySet().iterator(); it.hasNext();) {
            TwoKeyHashMap.Entry entry = (TwoKeyHashMap.Entry) it.next();
            cont = (AccessControlContext) entry.getKey2();
            if ((current == null && cont == null)
                    || (current != null && current.equals(cont))) {
                v.add(entry.getKey1());
            }
        }
        return (String[]) v.toArray(new String[0]);
    
public voidinvalidate()

see
javax.net.ssl.SSLSession#invalidate()

        isValid = false;
    
public booleanisValid()

see
javax.net.ssl.SSLSession#isValid()

        if (isValid
                && context != null
                && context.getSessionTimeout() != 0
                && lastAccessedTime + context.getSessionTimeout() > System
                        .currentTimeMillis()) {
            isValid = false;
        }
        return isValid;
    
public voidputValue(java.lang.String name, java.lang.Object value)

see
javax.net.ssl.SSLSession#putValue(String name, Object value)

        if (name == null || value == null) {
            throw new IllegalArgumentException("Parameter is null");
        }
        Object old = values.put(name, AccessController.getContext(), value);
        if (value instanceof SSLSessionBindingListener) {
            ((SSLSessionBindingListener) value)
                    .valueBound(new SSLSessionBindingEvent(this, name));
        }
        if (old != null && old instanceof SSLSessionBindingListener) {
            ((SSLSessionBindingListener) old)
                    .valueUnbound(new SSLSessionBindingEvent(this, name));
        }

    
public voidremoveValue(java.lang.String name)

see
javax.net.ssl.SSLSession#removeValue(String name)

        if (name == null) {
            throw new IllegalArgumentException("Parameter is null");
        }
        values.remove(name, AccessController.getContext());

    
voidsetPeer(java.lang.String peerHost, int peerPort)
Sets the address of the peer

param
peerHost
param
peerPort

        this.peerHost = peerHost;
        this.peerPort = peerPort;