public int read(ByteBuffer plain) throws IOException { if ( engine.getHandshakeStatus()!=NOT_HANDSHAKING ) { handshake(); } return secure_read(plain); }
public void setNext(ProtocolCodec next) { this.next = next; initNext(); }
public void handshake() throws IOException { if( !transportFlush() ) { return; secure_write(ByteBuffer.allocate(0)); break; if( secure_read(ByteBuffer.allocate(0)) == -1) { throw new EOFException("Peer disconnected during ssl handshake");
private int secure_write(ByteBuffer plain) throws IOException { if( !transportFlush() ) { // can't write anymore until the write_secured_buffer gets fully flushed out.. return 0; } int rc = 0; while ( plain.hasRemaining() ^ engine.getHandshakeStatus()==NEED_WRAP ) { SSLEngineResult result = engine.wrap(plain, writeBuffer); assert result.getStatus()!= BUFFER_OVERFLOW; rc += result.bytesConsumed(); if( !transportFlush() ) { break; } } if( plain.remaining()==0 && engine.getHandshakeStatus()!=NOT_HANDSHAKING ) { handshake(); } return rc; }
public SslProtocolCodec client() throws Exception { initializeEngine(); engine.setUseClientMode(true); engine.beginHandshake(); return this; }
public SslProtocolCodec server(ClientAuth clientAuth) throws Exception { initializeEngine(); engine.setUseClientMode(false); switch (clientAuth) { case WANT: engine.setWantClientAuth(true); break; case NEED: engine.setNeedClientAuth(true); break; case NONE: engine.setWantClientAuth(false); break; } engine.beginHandshake(); return this; }
public int write(ByteBuffer plain) throws IOException { if ( engine.getHandshakeStatus()!=NOT_HANDSHAKING ) { handshake(); } return secure_write(plain); }
public void setTransport(Transport transport) { this.transport = transport; this.readChannel = transport.getReadChannel(); this.writeChannel = transport.getWriteChannel(); initNext(); }