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

Refactor direct SSL handshake logic #501

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/backend/postmaster/postmaster.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ ProtocolExtensionConfig default_protocol_config = {
libpq_end_command,
NULL, NULL, NULL, NULL, /* use libpq defaults for printtup*() */
NULL,
libpq_report_param_status
libpq_report_param_status,
libpq_direct_ssl_handshake
};

/* still more option variables */
Expand Down Expand Up @@ -1511,6 +1512,11 @@ libpq_end_command(QueryCompletion *qc, CommandDest dest)
EndCommand(qc, dest, false);
}

int
libpq_direct_ssl_handshake(struct Port *port)
{
return ProcessSSLStartup(port);
}

/*
* on_proc_exit callback to close server's listen sockets
Expand Down
11 changes: 5 additions & 6 deletions src/backend/tcop/backend_startup.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
bool Trace_connection_negotiation = false;
static void BackendInitialize(ClientSocket *client_sock, CAC_state cac, ProtocolExtensionConfig *protocol_config);
int ProcessStartupPacket(Port *port, bool ssl_done, bool gss_done);
static int ProcessSSLStartup(Port *port);
int ProcessSSLStartup(Port *port);
static void SendNegotiateProtocolVersion(List *unrecognized_protocol_options);
static void process_startup_packet_die(SIGNAL_ARGS);
static void StartupPacketTimeoutHandler(void);
Expand Down Expand Up @@ -253,15 +253,14 @@ BackendInitialize(ClientSocket *client_sock, CAC_state cac, ProtocolExtensionCon
RegisterTimeout(STARTUP_PACKET_TIMEOUT, StartupPacketTimeoutHandler);
enable_timeout_after(STARTUP_PACKET_TIMEOUT, AuthenticationTimeout * 1000);

/* Handle direct SSL handshake for non-TDS connections */
if (!port->is_tds_conn)
status = ProcessSSLStartup(port);
/* Handle protocol-specific direct SSL handshake */
status = port->protocol_config->fn_direct_ssl_handshake(port);

/*
* Receive the startup packet (which might turn out to be a cancel request
* packet).
*/
if (port->is_tds_conn || status == STATUS_OK)
if (status == STATUS_OK)
status = (port->protocol_config->fn_start)(port);

/*
Expand Down Expand Up @@ -360,7 +359,7 @@ BackendInitialize(ClientSocket *client_sock, CAC_state cac, ProtocolExtensionCon
* This happens before the startup packet so we are careful not to actually
* read any bytes from the stream if it's not a direct SSL connection.
*/
static int
int
ProcessSSLStartup(Port *port)
{
int firstbyte;
Expand Down
3 changes: 3 additions & 0 deletions src/include/libpq/libpq-be.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ typedef struct ProtocolExtensionConfig {
void (*fn_printtup_destroy)(DestReceiver *self);
int (*fn_process_command)(void);
void (*fn_report_param_status)(const char *name, char *val);

/* function pointer for handling direct SSL handshake */
int (*fn_direct_ssl_handshake)(struct Port *port);
} ProtocolExtensionConfig;

/*
Expand Down
1 change: 1 addition & 0 deletions src/include/postmaster/protocol_extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ extern void libpq_send_ready_for_query(CommandDest dest);
extern int libpq_read_command(StringInfo inBuf);
extern void libpq_end_command(QueryCompletion *qc, CommandDest dest);
extern void libpq_report_param_status(const char *name, char *val);
extern int libpq_direct_ssl_handshake(struct Port *port);

#endif /* _PROTOCOL_EXTENSION_H */
1 change: 1 addition & 0 deletions src/include/tcop/backend_startup.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ typedef struct BackendStartupData

extern void BackendMain(char *startup_data, size_t startup_data_len) pg_attribute_noreturn();
extern int ProcessStartupPacket(Port *port, bool ssl_done, bool gss_done);
extern int ProcessSSLStartup(Port *port);

#endif /* BACKEND_STARTUP_H */
Loading