Home / Function/ handshake() — netty Function Reference

handshake() — netty Function Reference

Architecture documentation for the handshake() function in ReferenceCountedOpenSslEngine.java from the netty codebase.

Function java Buffer Allocators calls 9 called by 3

Entity Profile

Dependency Diagram

graph TD
  70ac8c99_3ca9_c202_a13f_16dda4571164["handshake()"]
  df1ad81e_e5bf_85e6_4418_db301b4c3e66["ReferenceCountedOpenSslEngine"]
  70ac8c99_3ca9_c202_a13f_16dda4571164 -->|defined in| df1ad81e_e5bf_85e6_4418_db301b4c3e66
  9f77679b_188a_ea47_0bb0_025af752e7f4["SSLEngineResult()"]
  9f77679b_188a_ea47_0bb0_025af752e7f4 -->|calls| 70ac8c99_3ca9_c202_a13f_16dda4571164
  91f19139_f45d_587f_8928_e46af45c559d["beginHandshake()"]
  91f19139_f45d_587f_8928_e46af45c559d -->|calls| 70ac8c99_3ca9_c202_a13f_16dda4571164
  8f4bc60d_a2f3_a1d5_59ca_53b86ada8b7f["mayFinishHandshake()"]
  8f4bc60d_a2f3_a1d5_59ca_53b86ada8b7f -->|calls| 70ac8c99_3ca9_c202_a13f_16dda4571164
  45db14f5_962d_6891_30d4_e421c0aed253["checkEngineClosed()"]
  70ac8c99_3ca9_c202_a13f_16dda4571164 -->|calls| 45db14f5_962d_6891_30d4_e421c0aed253
  bd3db87e_15bb_10ab_35c4_8c54c4a424e8["handshakeException()"]
  70ac8c99_3ca9_c202_a13f_16dda4571164 -->|calls| bd3db87e_15bb_10ab_35c4_8c54c4a424e8
  419ba6c0_f87d_c7d3_6d67_9985e6c830d4["sslPointer()"]
  70ac8c99_3ca9_c202_a13f_16dda4571164 -->|calls| 419ba6c0_f87d_c7d3_6d67_9985e6c830d4
  17e34f47_e150_b998_da7c_4a4714e421af["getPeerPort()"]
  70ac8c99_3ca9_c202_a13f_16dda4571164 -->|calls| 17e34f47_e150_b998_da7c_4a4714e421af
  0df93b1e_6ec5_8163_ec8f_ad4169ec0aa3["prepareHandshake()"]
  70ac8c99_3ca9_c202_a13f_16dda4571164 -->|calls| 0df93b1e_6ec5_8163_ec8f_ad4169ec0aa3
  dbe753a6_af57_f6b0_c03a_92d1b7a3514b["pendingStatus()"]
  70ac8c99_3ca9_c202_a13f_16dda4571164 -->|calls| dbe753a6_af57_f6b0_c03a_92d1b7a3514b
  81956eeb_a1af_02d8_62af_119ce69fd3b9["needWrapAgain()"]
  70ac8c99_3ca9_c202_a13f_16dda4571164 -->|calls| 81956eeb_a1af_02d8_62af_119ce69fd3b9
  6a172ec1_1af9_cb55_7e05_2b066e89e30e["handshakeFinished()"]
  70ac8c99_3ca9_c202_a13f_16dda4571164 -->|calls| 6a172ec1_1af9_cb55_7e05_2b066e89e30e
  32e59755_0296_2b44_3000_4e40f149f5d1["selectApplicationProtocol()"]
  70ac8c99_3ca9_c202_a13f_16dda4571164 -->|calls| 32e59755_0296_2b44_3000_4e40f149f5d1
  style 70ac8c99_3ca9_c202_a13f_16dda4571164 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

handler/src/main/java/io/netty/handler/ssl/ReferenceCountedOpenSslEngine.java lines 1951–2021

    private SSLEngineResult.HandshakeStatus handshake() throws SSLException {
        if (needTask) {
            return NEED_TASK;
        }
        if (handshakeState == HandshakeState.FINISHED) {
            return FINISHED;
        }

        checkEngineClosed();

        if (pendingException != null) {
            // Let's call SSL.doHandshake(...) again in case there is some async operation pending that would fill the
            // outbound buffer.
            if (SSL.doHandshake(ssl) <= 0) {
                // Clear any error that was put on the stack by the handshake
                SSL.clearError();
            }
            return handshakeException();
        }

        // Adding the OpenSslEngine to the OpenSslEngineMap so it can be used in the AbstractCertificateVerifier.
        engines.put(sslPointer(), this);

        if (!sessionSet) {
            if (!parentContext.sessionContext().setSessionFromCache(ssl, session, getPeerHost(), getPeerPort())) {
                // The session was not reused via the cache. Call prepareHandshake() to ensure we remove all previous
                // stored key-value pairs.
                session.prepareHandshake();
            }
            sessionSet = true;
        }

        int code = SSL.doHandshake(ssl);
        if (code <= 0) {
            int sslError = SSL.getError(ssl, code);
            if (sslError == SSL.SSL_ERROR_WANT_READ || sslError == SSL.SSL_ERROR_WANT_WRITE) {
                return pendingStatus(SSL.bioLengthNonApplication(networkBIO));
            }

            if (sslError == SSL.SSL_ERROR_WANT_X509_LOOKUP ||
                    sslError == SSL.SSL_ERROR_WANT_CERTIFICATE_VERIFY ||
                    sslError == SSL.SSL_ERROR_WANT_PRIVATE_KEY_OPERATION) {
                return NEED_TASK;
            }

            int errorNumber = SSL.getLastErrorNumber();
            if (needWrapAgain(errorNumber)) {
                // There is something that needs to be send to the remote peer before we can teardown.
                // This is most likely some alert.
                return NEED_WRAP;
            }
            // Check if we have a pending exception that was created during the handshake and if so throw it after
            // shutdown the connection.
            if (pendingException != null) {
                return handshakeException();
            }

            // Everything else is considered as error
            throw shutdownWithError("SSL_do_handshake", sslError, errorNumber);
        }
        // We have produced more data as part of the handshake if this is the case the user should call wrap(...)
        if (SSL.bioLengthNonApplication(networkBIO) > 0) {
            return NEED_WRAP;
        }
        // if SSL_do_handshake returns > 0 or sslError == SSL.SSL_ERROR_NAME it means the handshake was finished.
        session.handshakeFinished(SSL.getSessionId(ssl), SSL.getCipherForSSL(ssl), SSL.getVersion(ssl),
                SSL.getPeerCertificate(ssl), SSL.getPeerCertChain(ssl),
                SSL.getTime(ssl) * 1000L, parentContext.sessionTimeout() * 1000L);
        selectApplicationProtocol();
        return FINISHED;
    }

Domain

Subdomains

Frequently Asked Questions

What does handshake() do?
handshake() is a function in the netty codebase, defined in handler/src/main/java/io/netty/handler/ssl/ReferenceCountedOpenSslEngine.java.
Where is handshake() defined?
handshake() is defined in handler/src/main/java/io/netty/handler/ssl/ReferenceCountedOpenSslEngine.java at line 1951.
What does handshake() call?
handshake() calls 9 function(s): checkEngineClosed, getPeerPort, handshakeException, handshakeFinished, needWrapAgain, pendingStatus, prepareHandshake, selectApplicationProtocol, and 1 more.
What calls handshake()?
handshake() is called by 3 function(s): SSLEngineResult, beginHandshake, mayFinishHandshake.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free