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

[+] Export SSL handler of HTTP/3 connection for ssl_protocol, ssl_cipher, etc. #310

Merged
merged 3 commits into from
Jun 27, 2023
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
14 changes: 14 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,13 @@ xqc_int_t xqc_conn_get_errno(xqc_connection_t *conn);
Get error code of specified connection.


#### xqc_conn_get_ssl
```
void *xqc_conn_get_ssl(xqc_connection_t *conn);
```
Get ssl handler of specified connection.


#### xqc_conn_set_transport_user_data
```
void xqc_conn_set_transport_user_data(xqc_connection_t *conn, void *user_data);
Expand Down Expand Up @@ -839,6 +846,13 @@ xqc_int_t xqc_h3_conn_get_errno(xqc_h3_conn_t *h3c);
Get connection error code.


#### xqc_h3_conn_get_ssl
```
void *xqc_h3_conn_get_ssl(xqc_h3_conn_t *h3c);
```
Get ssl handler of http3 connection.


#### xqc_h3_conn_set_user_data
```
void xqc_h3_conn_set_user_data(xqc_h3_conn_t *h3c, void *user_data);
Expand Down
16 changes: 13 additions & 3 deletions include/xquic/xqc_http3.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,16 @@ XQC_EXPORT_PUBLIC_API
xqc_int_t xqc_h3_conn_get_errno(xqc_h3_conn_t *h3c);


/**
* @brief get ssl handler of http3 connection
*
* @param h3c handler of http3 connection
* @return ssl handler of http3 connection
*/
XQC_EXPORT_PUBLIC_API
void *xqc_h3_conn_get_ssl(xqc_h3_conn_t *h3c);


/**
* @brief set user_data for http3 connection, user_data could be the application layer context of
* http3 connection
Expand All @@ -480,7 +490,7 @@ void xqc_h3_conn_set_user_data(xqc_h3_conn_t *h3c, void *user_data);
* @return user_data
*/
XQC_EXPORT_PUBLIC_API
void* xqc_h3_conn_get_user_data(xqc_h3_conn_t *h3_conn);
void *xqc_h3_conn_get_user_data(xqc_h3_conn_t *h3_conn);


/**
Expand Down Expand Up @@ -742,7 +752,7 @@ void xqc_h3_ext_bytestream_set_user_data(xqc_h3_ext_bytestream_t *h3_ext_bs,
* @return the pointer of user data
*/
XQC_EXPORT_PUBLIC_API
void* xqc_h3_ext_bytestream_get_user_data(xqc_h3_ext_bytestream_t *h3_ext_bs);
void *xqc_h3_ext_bytestream_get_user_data(xqc_h3_ext_bytestream_t *h3_ext_bs);

/**
* @brief get statistics of a bytestream
Expand Down Expand Up @@ -809,7 +819,7 @@ void xqc_h3_ext_datagram_set_user_data(xqc_h3_conn_t *conn, void *user_data);
* @return the user_data of all datagram callbacks
*/
XQC_EXPORT_PUBLIC_API
void* xqc_h3_ext_datagram_get_user_data(xqc_h3_conn_t *conn);
void *xqc_h3_ext_datagram_get_user_data(xqc_h3_conn_t *conn);


/**
Expand Down
9 changes: 8 additions & 1 deletion include/xquic/xquic.h
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,13 @@ XQC_EXPORT_PUBLIC_API
xqc_int_t xqc_conn_get_errno(xqc_connection_t *conn);


/**
* Get ssl handler of specified connection
*/
XQC_EXPORT_PUBLIC_API
void *xqc_conn_get_ssl(xqc_connection_t *conn);


/**
* @brief get latest rtt sample of the initial path
*
Expand Down Expand Up @@ -1613,7 +1620,7 @@ void xqc_datagram_set_user_data(xqc_connection_t *conn, void *dgram_data);
* @dgram_data: the user_data of all datagram callbacks
*/
XQC_EXPORT_PUBLIC_API
void* xqc_datagram_get_user_data(xqc_connection_t *conn);
void *xqc_datagram_get_user_data(xqc_connection_t *conn);

/**
* @brief the API to send a datagram over the QUIC connection
Expand Down
2 changes: 2 additions & 0 deletions scripts/xquic.lds
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ XQUIC_VERS_1.0 {
xqc_h3_conn_close;
xqc_scid_str;
xqc_h3_conn_get_errno;
xqc_h3_conn_get_ssl;
xqc_h3_conn_set_user_data;
xqc_h3_conn_get_peer_addr;
xqc_h3_conn_get_local_addr;
Expand All @@ -34,6 +35,7 @@ XQUIC_VERS_1.0 {
xqc_connect;
xqc_conn_close;
xqc_conn_get_errno;
xqc_conn_get_ssl;
xqc_conn_set_transport_user_data;
xqc_conn_get_peer_addr;
xqc_conn_get_local_addr;
Expand Down
11 changes: 11 additions & 0 deletions src/http3/xqc_h3_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,17 @@ xqc_h3_conn_get_errno(xqc_h3_conn_t *h3_conn)
}


void *
xqc_h3_conn_get_ssl(xqc_h3_conn_t *h3_conn)
{
if (h3_conn->conn) {
return xqc_conn_get_ssl(h3_conn->conn);
}

return NULL;
}


void
xqc_h3_conn_set_user_data(xqc_h3_conn_t *h3_conn,
void *user_data)
Expand Down
2 changes: 1 addition & 1 deletion src/http3/xqc_h3_ext_bytestream.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ xqc_h3_ext_bytestream_set_user_data(xqc_h3_ext_bytestream_t *h3_ext_bs,



void*
void *
xqc_h3_ext_bytestream_get_user_data(xqc_h3_ext_bytestream_t *h3_ext_bs)
{
return h3_ext_bs->user_data;
Expand Down
2 changes: 1 addition & 1 deletion src/http3/xqc_h3_ext_dgram.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ xqc_h3_ext_datagram_set_user_data(xqc_h3_conn_t *conn, void *user_data)
xqc_datagram_set_user_data(conn->conn, user_data);
}

void*
void *
xqc_h3_ext_datagram_get_user_data(xqc_h3_conn_t *conn)
{
return xqc_datagram_get_user_data(conn->conn);
Expand Down
4 changes: 2 additions & 2 deletions src/tls/babassl/xqc_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <openssl/ssl.h>
#include <openssl/err.h>

void*
void *
xqc_aead_ctx_new(const xqc_pkt_protect_aead_t *pp_aead, xqc_key_type_t type,
const uint8_t *key, size_t noncelen)
{
Expand Down Expand Up @@ -176,7 +176,7 @@ xqc_ossl_aead_decrypt(const xqc_pkt_protect_aead_t *pp_aead, void *aead_ctx,
return -XQC_TLS_DECRYPT_DATA_ERROR;
}

void*
void *
xqc_hp_ctx_new(const xqc_hdr_protect_cipher_t *hp_cipher, const uint8_t *key)
{
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
Expand Down
4 changes: 2 additions & 2 deletions src/tls/boringssl/xqc_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <openssl/chacha.h>


void*
void *
xqc_aead_ctx_new(const xqc_pkt_protect_aead_t *pp_aead, xqc_key_type_t type,
const uint8_t *key, size_t noncelen)
{
Expand Down Expand Up @@ -86,7 +86,7 @@ xqc_bssl_aead_decrypt(const xqc_pkt_protect_aead_t *pp_aead, void *aead_ctx,
}


void*
void *
xqc_hp_ctx_new(const xqc_hdr_protect_cipher_t *hp_cipher, const uint8_t *key)
{
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
Expand Down
10 changes: 10 additions & 0 deletions src/tls/xqc_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,16 @@ xqc_tls_get_selected_alpn(xqc_tls_t *tls, const char **out_alpn,
(unsigned *)out_len);
}

void *
xqc_tls_get_ssl(xqc_tls_t *tls)
{
if (!tls) {
return NULL;
}

return tls->ssl;
}


/**
* ============================================================================
Expand Down
4 changes: 4 additions & 0 deletions src/tls/xqc_tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ void xqc_tls_get_selected_alpn(xqc_tls_t *tls, const char **out_alpn,

xqc_int_t xqc_tls_update_tp(xqc_tls_t *tls, uint8_t *tp_buf, size_t tp_len);

/**
* @brief get SSL handler
*/
void *xqc_tls_get_ssl(xqc_tls_t *tls);


#endif
10 changes: 10 additions & 0 deletions src/transport/xqc_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -2156,6 +2156,16 @@ xqc_conn_get_errno(xqc_connection_t *conn)
return conn->conn_err;
}

void *
xqc_conn_get_ssl(xqc_connection_t *conn)
{
if (conn->tls) {
return xqc_tls_get_ssl(conn->tls);
}

return NULL;
}

xqc_int_t
xqc_conn_immediate_close(xqc_connection_t *conn)
{
Expand Down
2 changes: 1 addition & 1 deletion src/transport/xqc_datagram.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ xqc_datagram_set_user_data(xqc_connection_t *conn, void *dgram_data)
conn->dgram_data = dgram_data;
}

void*
void *
xqc_datagram_get_user_data(xqc_connection_t *conn)
{
return conn->dgram_data;
Expand Down