From c4c02f80365e5f7a82efa6a4d4f247503f54a5d8 Mon Sep 17 00:00:00 2001 From: zhenwei pi Date: Tue, 14 Jun 2022 19:17:28 +0800 Subject: Introduce TLS specified APIs Introduce .get_peer_cert, .get_ctx and .get_client_ctx for TLS, also hide redis_tls_ctx & redis_tls_client_ctx. Then outside could access the variables by connection API only: - redis_tls_ctx -> connTypeGetCtx(CONN_TYPE_TLS) - redis_tls_client_ctx -> connTypeGetClientCtx(CONN_TYPE_TLS) Also remove connTLSGetPeerCert(), use connGetPeerCert() instead. Signed-off-by: zhenwei pi --- src/connection.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/connection.h') diff --git a/src/connection.h b/src/connection.h index dac4dc3ea..4cb74c4dc 100644 --- a/src/connection.h +++ b/src/connection.h @@ -95,6 +95,11 @@ typedef struct ConnectionType { /* pending data */ int (*has_pending_data)(void); int (*process_pending_data)(void); + + /* TLS specified methods */ + sds (*get_peer_cert)(struct connection *conn); + void* (*get_ctx)(void); + void* (*get_client_ctx)(void); } ConnectionType; struct connection { @@ -335,7 +340,17 @@ int connSendTimeout(connection *conn, long long ms); int connRecvTimeout(connection *conn, long long ms); /* Helpers for tls special considerations */ -sds connTLSGetPeerCert(connection *conn); +void *connTypeGetCtx(int type); +void *connTypeGetClientCtx(int type); + +/* Get cert for the secure connection */ +static inline sds connGetPeerCert(connection *conn) { + if (conn->type->get_peer_cert) { + return conn->type->get_peer_cert(conn); + } + + return NULL; +} /* Initialize the redis connection framework */ int connTypeInitialize(); -- cgit v1.2.1