Skip to content

Commit e82d625

Browse files
authored
revert: "fix: rust alert getter should not modify" (#5766)
1 parent 9540470 commit e82d625

File tree

5 files changed

+8
-62
lines changed

5 files changed

+8
-62
lines changed

api/s2n.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3423,9 +3423,6 @@ S2N_API extern int s2n_connection_get_key_exchange_group(struct s2n_connection *
34233423
* Function to get the alert that caused a connection to close. s2n-tls considers all
34243424
* TLS alerts fatal and shuts down a connection whenever one is received.
34253425
*
3426-
* @warning This method mutates the connection and consumes any available alert.
3427-
* Calling it twice without receiving a second alert will cause an error.
3428-
*
34293426
* @param conn A pointer to the s2n connection
34303427
* @returns The TLS alert code that caused a connection to be shut down
34313428
*/

bindings/rust/extended/s2n-tls/src/connection.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -775,11 +775,10 @@ impl Connection {
775775

776776
/// Returns the TLS alert code, if any
777777
///
778-
/// Corresponds to [s2n_connection_get_alert], but does not modify the connection
779-
/// or consume the alert.
778+
/// Corresponds to [s2n_connection_get_alert].
780779
pub fn alert(&self) -> Option<u8> {
781780
let alert =
782-
unsafe { s2n_connection_peek_alert(self.connection.as_ptr()).into_result() }.ok()?;
781+
unsafe { s2n_connection_get_alert(self.connection.as_ptr()).into_result() }.ok()?;
783782
Some(alert as u8)
784783
}
785784

tests/unit/s2n_connection_test.c

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,40 +1109,6 @@ int main(int argc, char **argv)
11091109
};
11101110
};
11111111

1112-
/* Test s2n_connection_peek_alert */
1113-
{
1114-
/* Safety */
1115-
{
1116-
EXPECT_FAILURE_WITH_ERRNO(s2n_connection_peek_alert(NULL), S2N_ERR_NULL);
1117-
}
1118-
1119-
/* Test: no alert */
1120-
{
1121-
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT),
1122-
s2n_connection_ptr_free);
1123-
EXPECT_FAILURE_WITH_ERRNO(s2n_connection_peek_alert(conn), S2N_ERR_NO_ALERT);
1124-
}
1125-
1126-
/* Test: Does not interfere with s2n_connection_get_alert */
1127-
{
1128-
DEFER_CLEANUP(struct s2n_connection *conn = s2n_connection_new(S2N_CLIENT),
1129-
s2n_connection_ptr_free);
1130-
const uint8_t alert_code = 42;
1131-
EXPECT_SUCCESS(s2n_stuffer_write_uint8(&conn->alert_in, 0));
1132-
EXPECT_SUCCESS(s2n_stuffer_write_uint8(&conn->alert_in, alert_code));
1133-
1134-
/* We can repeatedly peek at alerts */
1135-
for (size_t i = 0; i < 10; i++) {
1136-
EXPECT_EQUAL(s2n_connection_peek_alert(conn), alert_code);
1137-
}
1138-
1139-
/* We can still read the alert once */
1140-
EXPECT_EQUAL(s2n_connection_get_alert(conn), alert_code);
1141-
/* But we can't read the alert twice */
1142-
EXPECT_FAILURE_WITH_ERRNO(s2n_connection_get_alert(conn), S2N_ERR_NO_ALERT);
1143-
}
1144-
}
1145-
11461112
EXPECT_SUCCESS(s2n_cert_chain_and_key_free(ecdsa_chain_and_key));
11471113
EXPECT_SUCCESS(s2n_cert_chain_and_key_free(rsa_chain_and_key));
11481114
END_TEST();

tls/s2n_connection.c

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,30 +1127,19 @@ int s2n_connection_client_cert_used(struct s2n_connection *conn)
11271127
return 0;
11281128
}
11291129

1130-
static int s2n_connection_get_alert_impl(struct s2n_stuffer *alert)
1130+
int s2n_connection_get_alert(struct s2n_connection *conn)
11311131
{
1132-
S2N_ERROR_IF(s2n_stuffer_data_available(alert) != 2, S2N_ERR_NO_ALERT);
1132+
POSIX_ENSURE_REF(conn);
1133+
1134+
S2N_ERROR_IF(s2n_stuffer_data_available(&conn->alert_in) != 2, S2N_ERR_NO_ALERT);
11331135

11341136
uint8_t alert_code = 0;
1135-
POSIX_GUARD(s2n_stuffer_read_uint8(alert, &alert_code));
1136-
POSIX_GUARD(s2n_stuffer_read_uint8(alert, &alert_code));
1137+
POSIX_GUARD(s2n_stuffer_read_uint8(&conn->alert_in, &alert_code));
1138+
POSIX_GUARD(s2n_stuffer_read_uint8(&conn->alert_in, &alert_code));
11371139

11381140
return alert_code;
11391141
}
11401142

1141-
int s2n_connection_get_alert(struct s2n_connection *conn)
1142-
{
1143-
POSIX_ENSURE_REF(conn);
1144-
return s2n_connection_get_alert_impl(&conn->alert_in);
1145-
}
1146-
1147-
int s2n_connection_peek_alert(struct s2n_connection *conn)
1148-
{
1149-
POSIX_ENSURE_REF(conn);
1150-
struct s2n_stuffer alert_in_copy = conn->alert_in;
1151-
return s2n_connection_get_alert_impl(&alert_in_copy);
1152-
}
1153-
11541143
int s2n_set_server_name(struct s2n_connection *conn, const char *server_name)
11551144
{
11561145
POSIX_ENSURE_REF(conn);

tls/s2n_internal.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,3 @@ S2N_PRIVATE_API int s2n_config_add_cert_chain(struct s2n_config *config,
5959
* is still waiting for encryption.
6060
*/
6161
S2N_PRIVATE_API int s2n_flush(struct s2n_connection *conn, s2n_blocked_status *blocked);
62-
63-
/*
64-
* An alternative to s2n_connection_get_alert that does not mutate the connection.
65-
*/
66-
S2N_PRIVATE_API int s2n_connection_peek_alert(struct s2n_connection *conn);

0 commit comments

Comments
 (0)