Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tls] Move handshaking behavior into SslSocketInfo. #12571

Merged
merged 11 commits into from
Aug 14, 2020
7 changes: 7 additions & 0 deletions include/envoy/network/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,19 @@ envoy_cc_library(
hdrs = ["transport_socket.h"],
deps = [
":io_handle_interface",
":post_io_action_interface",
":proxy_protocol_options_lib",
"//include/envoy/buffer:buffer_interface",
"//include/envoy/ssl:connection_interface",
],
)

envoy_cc_library(
name = "post_io_action_interface",
hdrs = ["post_io_action.h"],
deps = [],
)

envoy_cc_library(
name = "connection_balancer_interface",
hdrs = ["connection_balancer.h"],
Expand Down
17 changes: 17 additions & 0 deletions include/envoy/network/post_io_action.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

namespace Envoy {
namespace Network {

/**
* Action that should occur on a connection after I/O.
*/
enum class PostIoAction {
// Close the connection.
Close,
// Keep the connection open.
KeepOpen
};

} // namespace Network
} // namespace Envoy
13 changes: 2 additions & 11 deletions include/envoy/network/transport_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "envoy/buffer/buffer.h"
#include "envoy/common/pure.h"
#include "envoy/network/io_handle.h"
#include "envoy/network/post_io_action.h"
#include "envoy/network/proxy_protocol.h"
#include "envoy/ssl/connection.h"

Expand All @@ -16,16 +17,6 @@ namespace Network {
class Connection;
enum class ConnectionEvent;

/**
* Action that should occur on a connection after I/O.
*/
enum class PostIoAction {
// Close the connection.
Close,
// Keep the connection open.
KeepOpen
};

/**
* Result of each I/O event.
*/
Expand Down Expand Up @@ -151,7 +142,7 @@ class TransportSocket {
virtual void onConnected() PURE;

/**
* @return the const SSL connection data if this is an SSL connection, or nullptr if it is not.
* @return the SSL connection data if this is an SSL connection, or nullptr if it is not.
ambuc marked this conversation as resolved.
Show resolved Hide resolved
*/
virtual Ssl::ConnectionInfoConstSharedPtr ssl() const PURE;
};
Expand Down
17 changes: 17 additions & 0 deletions include/envoy/ssl/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ envoy_cc_library(
hdrs = ["connection.h"],
external_deps = ["abseil_optional"],
deps = [
":ssl_socket_state",
"//include/envoy/common:time_interface",
],
)
Expand Down Expand Up @@ -68,3 +69,19 @@ envoy_cc_library(
deps = [
],
)

envoy_cc_library(
name = "ssl_socket_state",
hdrs = ["ssl_socket_state.h"],
deps = [],
)

envoy_cc_library(
name = "handshaker_interface",
hdrs = ["handshaker.h"],
external_deps = ["ssl"],
deps = [
"//include/envoy/network:connection_interface",
"//include/envoy/network:post_io_action_interface",
],
)
39 changes: 39 additions & 0 deletions include/envoy/ssl/handshaker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once

#include "envoy/network/connection.h"
#include "envoy/network/post_io_action.h"

#include "openssl/ssl.h"

namespace Envoy {
namespace Ssl {

class HandshakeCallbacks {
public:
virtual ~HandshakeCallbacks() = default;

/**
* @return the connection state.
*/
virtual Network::Connection::State connectionState() const PURE;

virtual void onSuccess(SSL* ssl) PURE;
ambuc marked this conversation as resolved.
Show resolved Hide resolved
virtual void onFailure() PURE;
};

/**
* Base interface for performing TLS handshakes.
*/
class Handshaker {
public:
virtual ~Handshaker() = default;

/**
* Performs a TLS handshake and returns an action indicating
* whether the callsite should close the connection or keep it open.
*/
virtual Network::PostIoAction doHandshake() PURE;
};

} // namespace Ssl
} // namespace Envoy
9 changes: 9 additions & 0 deletions include/envoy/ssl/ssl_socket_state.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

namespace Envoy {
namespace Ssl {

enum class SocketState { PreHandshake, HandshakeInProgress, HandshakeComplete, ShutdownSent };

} // namespace Ssl
} // namespace Envoy
2 changes: 1 addition & 1 deletion source/extensions/transport_sockets/common/passthrough.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ Ssl::ConnectionInfoConstSharedPtr PassthroughSocket::ssl() const {

} // namespace TransportSockets
} // namespace Extensions
} // namespace Envoy
} // namespace Envoy
2 changes: 1 addition & 1 deletion source/extensions/transport_sockets/common/passthrough.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ class PassthroughSocket : public Network::TransportSocket {

} // namespace TransportSockets
} // namespace Extensions
} // namespace Envoy
} // namespace Envoy
2 changes: 2 additions & 0 deletions source/extensions/transport_sockets/tls/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ envoy_cc_library(
":utility_lib",
"//include/envoy/network:connection_interface",
"//include/envoy/network:transport_socket_interface",
"//include/envoy/ssl:handshaker_interface",
"//include/envoy/ssl:ssl_socket_extended_info_interface",
"//include/envoy/ssl:ssl_socket_state",
"//include/envoy/ssl/private_key:private_key_callbacks_interface",
"//include/envoy/ssl/private_key:private_key_interface",
"//include/envoy/stats:stats_macros",
Expand Down
Loading