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 1 commit
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_ssl_handshake
roshan0708 marked this conversation as resolved.
Show resolved Hide resolved
};

/* 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_ssl_handshake(struct Port *port)
{
return WrapperProcessSSLStartup(port);
}

/*
* on_proc_exit callback to close server's listen sockets
Expand Down
16 changes: 12 additions & 4 deletions src/backend/tcop/backend_startup.c
Original file line number Diff line number Diff line change
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 SSL handshake */
roshan0708 marked this conversation as resolved.
Show resolved Hide resolved
status = port->protocol_config->fn_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 @@ -889,3 +888,12 @@ StartupPacketTimeoutHandler(void)
{
_exit(1);
}

/*
* Wrapper for ProcessSSLStartup to handle direct SSL handshake
*/
int
WrapperProcessSSLStartup(Port *port)
{
return ProcessSSLStartup(port);
}
roshan0708 marked this conversation as resolved.
Show resolved Hide resolved
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_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_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 WrapperProcessSSLStartup(Port *port);

#endif /* BACKEND_STARTUP_H */
Loading