Package javax.net.ssl

Examples of javax.net.ssl.SSLEngineResult


        } else {
            tempBuffer = readBuffer;
        }

        boolean done = false;
        SSLEngineResult result;
        ByteBuffer appBuffer = ByteBuffer.allocateDirect(sslEngine.getSession().getApplicationBufferSize());

        HandshakeStatus handshakeStatus = sslEngine.getHandshakeStatus();
        while (!done) {
            switch (handshakeStatus) {
            case NEED_UNWRAP:
            case NOT_HANDSHAKING:
            case FINISHED:
                result = sslEngine.unwrap(tempBuffer, appBuffer);
                handshakeStatus = result.getHandshakeStatus();

                switch (result.getStatus()) {
                case BUFFER_UNDERFLOW:
                    /* we need more data */
                    done = true;
                    break;
                case BUFFER_OVERFLOW:
                    /* resize output buffer */
                    appBuffer = ByteBuffer.allocateDirect(appBuffer.capacity() * 2);
                    break;
                case OK:
                    if ((handshakeStatus == HandshakeStatus.NOT_HANDSHAKING) && (result.bytesProduced() > 0)) {
                        appBuffer.flip();
                        session.processMessageReceived(appBuffer);
                    }
                }
                break;
            case NEED_TASK:
                Runnable task;

                while ((task = sslEngine.getDelegatedTask()) != null) {
                    task.run();
                }
                handshakeStatus = sslEngine.getHandshakeStatus();
                break;
            case NEED_WRAP:
                result = sslEngine.wrap(EMPTY_BUFFER, appBuffer);
                handshakeStatus = result.getHandshakeStatus();
                switch (result.getStatus()) {
                case BUFFER_OVERFLOW:
                    appBuffer = ByteBuffer.allocateDirect(appBuffer.capacity() * 2);
                    break;
                case BUFFER_UNDERFLOW:
                    done = true;
View Full Code Here


        ByteBuffer appBuffer = ByteBuffer.allocate(sslEngine.getSession().getPacketBufferSize());

        try {
            while (true) {
                // Encrypt the message
                SSLEngineResult result = sslEngine.wrap(buf, appBuffer);

                switch (result.getStatus()) {
                case BUFFER_OVERFLOW:
                    // Increase the buffer size as needed
                    appBuffer = ByteBuffer.allocate(appBuffer.capacity() + 4096);
                    break;
View Full Code Here

        }
    }

    private void tearDownSSLConnection() throws Exception
    {
        SSLEngineResult result = engine.wrap(ByteBuffer.allocate(0), netData);
        Status status = result.getStatus();
        int read   = result.bytesProduced();
        while (status != Status.CLOSED)
        {
            if (status == Status.BUFFER_OVERFLOW)
            {
                netData.clear();
            }
            if(read > 0)
            {
                int limit = netData.limit();
                netData.limit(netData.position());
                netData.position(netData.position() - read);

                ByteBuffer data = netData.slice();

                netData.limit(limit);
                netData.position(netData.position() + read);

                delegate.send(data);
                flush();
            }
            result = engine.wrap(ByteBuffer.allocate(0), netData);
            status = result.getStatus();
            read   = result.bytesProduced();
        }
    }
View Full Code Here

              && !_sslStatus.getSslErrorFlag())
        {
            int read = 0;
            try
            {
                SSLEngineResult result = engine.wrap(_appData, netData);
                read   = result.bytesProduced();
                status = result.getStatus();
                handshakeStatus = result.getHandshakeStatus();
            }
            catch(SSLException e)
            {
                // Should this set _sslError??
                throw new SenderException("SSL, Error occurred while encrypting data",e);
View Full Code Here

  public ByteBuffer dispatchInboundData (ByteBuffer bb) throws SSLException {
    if (sslEngine != null) {
      if (true) throw new RuntimeException ("TLS currently unimplemented");
      System.setProperty("javax.net.debug", "all");
      ByteBuffer w = ByteBuffer.allocate(32*1024); // TODO, WRONG, preallocate this buffer.
      SSLEngineResult res = sslEngine.unwrap(bb, w);
      if (res.getHandshakeStatus() == HandshakeStatus.NEED_TASK) {
        Runnable r;
        while ((r = sslEngine.getDelegatedTask()) != null) {
          r.run();
        }
      }
View Full Code Here

                    SessionLog.debug(session, " expanded outNetBuffer:"
                            + outNetBuffer);
                }
            }

            SSLEngineResult result = sslEngine.wrap(src, outNetBuffer);
            if (SessionLog.isDebugEnabled(session)) {
                SessionLog.debug(session, " Wrap res:" + result);
            }

            if (result.getStatus() == SSLEngineResult.Status.OK) {
                if (result.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.NEED_TASK) {
                    doTasks();
                }
            } else {
                throw new SSLException("SSLEngine error during encrypt: "
                        + result.getStatus() + " src: " + src
                        + "outNetBuffer: " + outNetBuffer);
            }
        }

        outNetBuffer.flip();
View Full Code Here

        sslEngine.closeOutbound();

        // By RFC 2616, we can "fire and forget" our close_notify
        // message, so that's what we'll do here.
        outNetBuffer.clear();
        SSLEngineResult result = sslEngine.wrap(hsBB, outNetBuffer);
        if (result.getStatus() != SSLEngineResult.Status.CLOSED) {
            throw new SSLException("Improper close state: " + result);
        }
        outNetBuffer.flip();
        return true;
    }
View Full Code Here

                                .debug(session, "  Still data in out buffer!");
                    }
                    break;
                }
                outNetBuffer.clear();
                SSLEngineResult result = sslEngine.wrap(hsBB, outNetBuffer);
                if (SessionLog.isDebugEnabled(session)) {
                    SessionLog.debug(session, " Wrap res:" + result);
                }

                outNetBuffer.flip();
                handshakeStatus = result.getHandshakeStatus();
                writeNetBuffer(nextFilter);
            } else {
                throw new IllegalStateException("Invalid Handshaking State"
                        + handshakeStatus);
            }
View Full Code Here

        }

        // Prepare the net data for reading.
        inNetBuffer.flip();

        SSLEngineResult res = unwrap0();

        // prepare to be written again
        inNetBuffer.compact();
       
        checkStatus(res);
View Full Code Here

        }

        // Prepare the net data for reading.
        inNetBuffer.flip();

        SSLEngineResult res = unwrap0();
        handshakeStatus = res.getHandshakeStatus();

        checkStatus(res);

        // If handshake finished, no data was produced, and the status is still ok,
        // try to unwrap more
        if (handshakeStatus == SSLEngineResult.HandshakeStatus.FINISHED
                && res.getStatus() == SSLEngineResult.Status.OK
                && inNetBuffer.hasRemaining()) {
            res = unwrap0();
           
            // prepare to be written again
            inNetBuffer.compact();

            renegotiateIfNeeded(nextFilter, res);
        } else {
            // prepare to be written again
            inNetBuffer.compact();
        }

        return res.getStatus();
    }
View Full Code Here

TOP

Related Classes of javax.net.ssl.SSLEngineResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.