SSLEngine getSession - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for SSLEngine getSession method.

This code example shows how to use the following methods:getSession, setUseClientMode
 
        // set the property before initialization SSLEngine. 
        System.setProperty("jsse.SSLEngine.acceptLargeFragments", "true");
 
        SSLEngine cliEngine = context.createSSLEngine();
        cliEngine.setUseClientMode(true);
 
        SSLEngine srvEngine = context.createSSLEngine();
        srvEngine.setUseClientMode(false);
 
        SSLSession cliSession = cliEngine.getSession();
        SSLSession srvSession = srvEngine.getSession();
 
        // check packet buffer sizes. 
        if (cliSession.getPacketBufferSize() < 33049 ||
            srvSession.getPacketBufferSize() < 33049) {
                throw new Exception("Don't accept large SSL/TLS fragments");
        } 
 
        // check application data buffer sizes. 
6
CodeRank
This code example shows how to use the following methods:getSession, setUseClientMode
 
  public SecureSocketWrapper(SocketWrapper wrapper) throws NoSuchAlgorithmException {
    this.channel = wrapper.getSocket();
    SSLContext context = SSLContext.getDefault();
    sslEngine = context.createSSLEngine();
    sslEngine.setUseClientMode(true);
    in = ByteBuffer.allocate(sslEngine.getSession().getPacketBufferSize());
    unwrappedIn = ByteBuffer.allocate(sslEngine.getSession().getApplicationBufferSize());
    out = ByteBuffer.allocate(sslEngine.getSession().getPacketBufferSize());
    empty = ByteBuffer.allocate(0);
  } 
 
  @Override 
  public SelectionKey register(Selector sel, int ops) throws ClosedChannelException {
    return channel.register(sel, ops);
  } 
 
  @Override 
  public boolean connect(SocketAddress remote) throws IOException {
    return channel.connect(remote);
6
CodeRank
This code example shows how to use the following methods:getSession, setEnabledCipherSuites, setNeedClientAuth, setUseClientMode
	 */ 
	public SSLEngineHelper(String host, int port, NIOJICPConnection connection) throws ICPException {
		SSLContext context = SSLHelper.createContext();
		// get a SSLEngine, use host and port for optimization 
		ssle = context.createSSLEngine(host, port);
		ssle.setUseClientMode(false);
		ssle.setNeedClientAuth(SSLHelper.needAuth());
		if (!SSLHelper.needAuth()) { 
			// if we don't do authentication we restrict our ssl connection to use specific cipher suites 
			ssle.setEnabledCipherSuites(SSLHelper.getSupportedKeys());
		} 
 
		SSLSession session = ssle.getSession();
		// TODO prevent buffer overflow, why *2? 
		unwrapData = ByteBuffer.allocateDirect(session.getApplicationBufferSize() + 1500);
		wrapData = ByteBuffer.allocateDirect(session.getPacketBufferSize());
		sendData = ByteBuffer.allocateDirect(wrapData.capacity());;
		this.connection = connection;
	} 
	/** 
6
CodeRank
This code example shows how to use the following methods:beginHandshake, getSession, setNeedClientAuth, setWantClientAuth
5
CodeRank
This code example shows how to use the following methods:beginHandshake, getSession, setNeedClientAuth, setWantClientAuth
5
CodeRank
This code example shows how to use the following methods:getSession, setUseClientMode
 
        // set the property before initialization SSLEngine. 
        System.setProperty("jsse.SSLEngine.acceptLargeFragments", "true");
 
        SSLEngine cliEngine = context.createSSLEngine();
        cliEngine.setUseClientMode(true);
 
        SSLEngine srvEngine = context.createSSLEngine();
        srvEngine.setUseClientMode(false);
 
        SSLSession cliSession = cliEngine.getSession();
        SSLSession srvSession = srvEngine.getSession();
 
        // check packet buffer sizes. 
        if (cliSession.getPacketBufferSize() < 33049 ||
            srvSession.getPacketBufferSize() < 33049) {
                throw new Exception("Don't accept large SSL/TLS fragments");
        } 
 
        // check application data buffer sizes. 
5
CodeRank
This code example shows how to use the following methods:closeOutbound, getHandshakeStatus, getSession, wrap
        if (doLog) {
            System.out.println("\n--- doClose: ");
        } 
        ByteBuffer buffer = ByteBuffer.allocate(
                // +100 because we put the data into the buffer multiple times 
                server.getSession().getPacketBufferSize()+100);
        ByteBuffer app_data_buffer = ByteBuffer.allocate(
                client.getSession().getApplicationBufferSize());
        SSLEngineResult result;
        // first: send 0 just for fun 
        if (doLog) {
            System.out.println("\nServer sends pending outboud data:");
        } 
        print(result = server.wrap(ByteBuffer.wrap(new byte[] {0}), buffer));
        assertEquals("Unexpected status of operation:",
                SSLEngineResult.Status.OK,
                result.getStatus());
        assertEquals("Unexpected status of operation:",
                SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING,
                result.getHandshakeStatus());

5
CodeRank
This code example shows how to use the following methods:closeOutbound, getSession, wrap
		} 
	} 
 
	private synchronized ByteBuffer wrap( ByteBuffer b ) throws SSLException {
		outCrypt.compact();
		engineResult = sslEngine.wrap( b, outCrypt );
		outCrypt.flip();
		return outCrypt;
	} 
 
	private synchronized ByteBuffer unwrap() throws SSLException {
		int rem;
		do { 
			rem = inData.remaining();
			engineResult = sslEngine.unwrap( inCrypt, inData );
			engineStatus = engineResult.getStatus();
		} while ( engineStatus == SSLEngineResult.Status.OK && ( rem != inData.remaining() || engineResult.getHandshakeStatus() == HandshakeStatus.NEED_UNWRAP ) );
 
		inData.flip();
		return inData;

5
CodeRank
This code example shows how to use the following methods:beginHandshake, getHandshakeStatus, getSession
     
    public SecureNioChannel(SocketChannel channel, SSLEngine engine, 
                            ApplicationBufferHandler bufHandler, NioSelectorPool pool) throws IOException {
        super(channel,bufHandler);
        this.sslEngine = engine;
        int appBufSize = sslEngine.getSession().getApplicationBufferSize();
        int netBufSize = sslEngine.getSession().getPacketBufferSize();
        //allocate network buffers - TODO, add in optional direct non-direct buffers 
        if ( netInBuffer == null ) netInBuffer = ByteBuffer.allocateDirect(netBufSize);
        if ( netOutBuffer == null ) netOutBuffer = ByteBuffer.allocateDirect(netBufSize);
         
        //selector pool for blocking operations 
        this.pool = pool;
         
        //ensure that the application has a large enough read/write buffers 
        //by doing this, we should not encounter any buffer overflow errors 
        bufHandler.expand(bufHandler.getReadBuffer(), appBufSize);
        bufHandler.expand(bufHandler.getWriteBuffer(), appBufSize);
        reset(); 
    } 

5
CodeRank
This code example shows how to use the following methods:getSession
    } 
 
    private void createOutNetBuffer(int expectedRemaining) {
        // SSLEngine requires us to allocate unnecessarily big buffer 
        // even for small data. *Shrug* 
        int capacity = Math.max(expectedRemaining, sslEngine.getSession().getPacketBufferSize());
 
        if (outNetBuffer != null) {
            outNetBuffer.capacity(capacity);
        } else { 
            outNetBuffer = IoBuffer.allocate(capacity).minimumCapacity(0);
        } 
    } 
 
    /* no qualifier */WriteFuture writeNetBuffer(NextFilter nextFilter) throws SSLException {
        // Check if any net data needed to be writen 
        if (outNetBuffer == null || !outNetBuffer.hasRemaining()) {
            // no; bail out 
            return null; 
        } 
3
CodeRank
getSession Method Overview
Returns the SSL session for this engine instance.
See Code Examples for other Java 8 SSLEngine Methods: