diff options
author | Matt Caswell <matt@openssl.org> | 2022-07-22 15:38:26 +0100 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2022-08-18 16:38:13 +0100 |
commit | d0b17ea025477ce13ebe5d802ada232a57e1a2f2 (patch) | |
tree | b0aaa1792f10815c6df7bec661cf4384e8f5d546 /ssl | |
parent | d4ee3456e98b1137a1ba013cf01f1052891dd3db (diff) |
Implement a human readable state function for the record layer
This allows querying of the record layer to get a human readable state
string out. This resolves two outstanding TODO comments and enables us
to remove the rstate variable from s->rlayer.
Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18132)
Diffstat (limited to 'ssl')
-rw-r--r-- | ssl/record/methods/dtls_meth.c | 3 | ||||
-rw-r--r-- | ssl/record/methods/ktls_meth.c | 3 | ||||
-rw-r--r-- | ssl/record/methods/recmethod_local.h | 2 | ||||
-rw-r--r-- | ssl/record/methods/tls_common.c | 26 | ||||
-rw-r--r-- | ssl/record/rec_layer_s3.c | 35 | ||||
-rw-r--r-- | ssl/record/record.h | 2 | ||||
-rw-r--r-- | ssl/record/recordmethod.h | 6 |
7 files changed, 49 insertions, 28 deletions
diff --git a/ssl/record/methods/dtls_meth.c b/ssl/record/methods/dtls_meth.c index 2609724b9e..3366a3e558 100644 --- a/ssl/record/methods/dtls_meth.c +++ b/ssl/record/methods/dtls_meth.c @@ -728,5 +728,6 @@ const OSSL_RECORD_METHOD ossl_dtls_record_method = { NULL, tls_set_first_handshake, tls_set_max_pipelines, - dtls_set_in_init + dtls_set_in_init, + tls_get_state }; diff --git a/ssl/record/methods/ktls_meth.c b/ssl/record/methods/ktls_meth.c index 036e46f8e9..241558600d 100644 --- a/ssl/record/methods/ktls_meth.c +++ b/ssl/record/methods/ktls_meth.c @@ -542,5 +542,6 @@ const OSSL_RECORD_METHOD ossl_ktls_record_method = { tls_set_plain_alerts, tls_set_first_handshake, tls_set_max_pipelines, - NULL + NULL, + tls_get_state }; diff --git a/ssl/record/methods/recmethod_local.h b/ssl/record/methods/recmethod_local.h index 5f3bc6bf6a..2b0fe26827 100644 --- a/ssl/record/methods/recmethod_local.h +++ b/ssl/record/methods/recmethod_local.h @@ -284,4 +284,6 @@ int tls_set_protocol_version(OSSL_RECORD_LAYER *rl, int version); void tls_set_plain_alerts(OSSL_RECORD_LAYER *rl, int allow); void tls_set_first_handshake(OSSL_RECORD_LAYER *rl, int first); void tls_set_max_pipelines(OSSL_RECORD_LAYER *rl, size_t max_pipelines); +void tls_get_state(OSSL_RECORD_LAYER *rl, const char **shortstr, + const char **longstr); int rlayer_setup_read_buffer(OSSL_RECORD_LAYER *rl); diff --git a/ssl/record/methods/tls_common.c b/ssl/record/methods/tls_common.c index 34497f4cc0..8dace6c21a 100644 --- a/ssl/record/methods/tls_common.c +++ b/ssl/record/methods/tls_common.c @@ -1341,6 +1341,29 @@ void tls_set_max_pipelines(OSSL_RECORD_LAYER *rl, size_t max_pipelines) rl->read_ahead = 1; } +void tls_get_state(OSSL_RECORD_LAYER *rl, const char **shortstr, + const char **longstr) +{ + const char *shrt, *lng; + switch (rl->rstate) { + case SSL_ST_READ_HEADER: + shrt = "RH"; + lng = "read header"; + break; + case SSL_ST_READ_BODY: + shrt = "RB"; + lng = "read body"; + break; + default: + shrt = lng = "unknown"; + break; + } + if (shortstr != NULL) + *shortstr = shrt; + if (longstr != NULL) + *longstr = lng; +} + const OSSL_RECORD_METHOD ossl_tls_record_method = { tls_new_record_layer, tls_free, @@ -1361,5 +1384,6 @@ const OSSL_RECORD_METHOD ossl_tls_record_method = { tls_set_plain_alerts, tls_set_first_handshake, tls_set_max_pipelines, - NULL + NULL, + tls_get_state }; diff --git a/ssl/record/rec_layer_s3.c b/ssl/record/rec_layer_s3.c index 16247031bb..041e069a88 100644 --- a/ssl/record/rec_layer_s3.c +++ b/ssl/record/rec_layer_s3.c @@ -34,8 +34,6 @@ void RECORD_LAYER_init(RECORD_LAYER *rl, SSL_CONNECTION *s) void RECORD_LAYER_clear(RECORD_LAYER *rl) { - rl->rstate = SSL_ST_READ_HEADER; - rl->wnum = 0; memset(rl->handshake_fragment, 0, sizeof(rl->handshake_fragment)); rl->handshake_fragment_len = 0; @@ -141,43 +139,34 @@ void SSL_set_default_read_buffer_len(SSL *s, size_t len) const char *SSL_rstate_string_long(const SSL *s) { const SSL_CONNECTION *sc = SSL_CONNECTION_FROM_CONST_SSL(s); + const char *lng; if (sc == NULL) return NULL; - /* TODO(RECLAYER): Fix me */ - switch (sc->rlayer.rstate) { - case SSL_ST_READ_HEADER: - return "read header"; - case SSL_ST_READ_BODY: - return "read body"; - case SSL_ST_READ_DONE: - return "read done"; - default: + if (sc->rlayer.rrlmethod == NULL || sc->rlayer.rrl == NULL) return "unknown"; - } + + sc->rlayer.rrlmethod->get_state(sc->rlayer.rrl, NULL, &lng); + + return lng; } const char *SSL_rstate_string(const SSL *s) { const SSL_CONNECTION *sc = SSL_CONNECTION_FROM_CONST_SSL(s); + const char *shrt; if (sc == NULL) return NULL; - /* TODO(RECLAYER): Fix me */ - switch (sc->rlayer.rstate) { - case SSL_ST_READ_HEADER: - return "RH"; - case SSL_ST_READ_BODY: - return "RB"; - case SSL_ST_READ_DONE: - return "RD"; - default: + if (sc->rlayer.rrlmethod == NULL || sc->rlayer.rrl == NULL) return "unknown"; - } -} + sc->rlayer.rrlmethod->get_state(sc->rlayer.rrl, &shrt, NULL); + + return shrt; +} /* * Call this to write data in records of type 'type' It will return <= 0 if diff --git a/ssl/record/record.h b/ssl/record/record.h index b75d8c86f3..8facdb27ce 100644 --- a/ssl/record/record.h +++ b/ssl/record/record.h @@ -163,8 +163,6 @@ typedef struct record_layer_st { * non-blocking reads) */ int read_ahead; - /* where we are when reading */ - int rstate; /* How many pipelines can be used to write data */ size_t numwpipes; /* write IO goes into here */ diff --git a/ssl/record/recordmethod.h b/ssl/record/recordmethod.h index 95732cae2c..f2579b6cf4 100644 --- a/ssl/record/recordmethod.h +++ b/ssl/record/recordmethod.h @@ -314,6 +314,12 @@ struct ossl_record_method_st { * not. Default at creation of the record layer is "yes". */ void (*set_in_init)(OSSL_RECORD_LAYER *rl, int in_init); + + /* + * Get a short or long human readable description of the record layer state + */ + void (*get_state)(OSSL_RECORD_LAYER *rl, const char **shortstr, + const char **longstr); }; |