43 import java.nio.channels.*;
44 import javax.net.ssl.*;
45 import javax.net.ssl.SSLEngineResult.*;
128 private static ByteBuffer
hsBB = ByteBuffer.allocate(0);
157 SSLContext sslc)
throws IOException {
188 SSLContext sslc)
throws IOException {
213 ByteBuffer bb = ByteBuffer.allocate(
netBBSize);
224 private boolean tryFlush(ByteBuffer bb)
throws IOException {
226 return !bb.hasRemaining();
287 sk.interestOps(SelectionKey.OP_READ);
313 switch (
result.getStatus()) {
317 case NOT_HANDSHAKING:
318 throw new IOException(
319 "Not handshaking during initial handshake");
332 case BUFFER_UNDERFLOW:
343 sk.interestOps(SelectionKey.OP_READ);
347 case BUFFER_OVERFLOW:
350 sslEngine.getSession().getApplicationBufferSize();
354 throw new IOException(
"Received" +
result.getStatus() +
355 "during initial handshaking");
378 switch (
result.getStatus()) {
386 sk.interestOps(SelectionKey.OP_WRITE);
392 throw new IOException(
"Received" +
result.getStatus() +
393 "during initial handshaking");
398 throw new RuntimeException(
"Invalid Handshaking State" +
408 private SSLEngineResult.HandshakeStatus
doTasks() {
416 while ((runnable =
sslEngine.getDelegatedTask()) !=
null) {
431 int read() throws IOException {
435 throw new IllegalStateException();
457 switch (
result.getStatus()) {
459 case BUFFER_OVERFLOW:
464 case BUFFER_UNDERFLOW:
473 if (
result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
479 throw new IOException(
"sslEngine error during data read: " +
482 }
while ((
inNetBB.position() != 0) &&
483 result.getStatus() != Status.BUFFER_UNDERFLOW);
491 int write(ByteBuffer src)
throws IOException {
494 throw new IllegalStateException();
508 private int doWrite(ByteBuffer src)
throws IOException {
521 retValue =
result.bytesConsumed();
525 switch (
result.getStatus()) {
528 if (
result.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
534 throw new IOException(
"sslEngine error during data write: " +
562 long transferTo(FileChannel fc,
long pos,
long len)
throws IOException {
565 throw new IllegalStateException();
593 boolean fileFlushed =
true;
598 }
else if (
outNetBB.hasRemaining()) {
602 return (fileFlushed && !
outNetBB.hasRemaining());
630 if (
result.getStatus() != Status.CLOSED) {
631 throw new SSLException(
"Improper close state");
644 (
result.getHandshakeStatus() != HandshakeStatus.NEED_WRAP));