Skip to content

Commit

Permalink
Refactor handshake msg header parsing etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
fwh-dc committed Jun 12, 2024
1 parent a4bb3b8 commit 45faed7
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 153 deletions.
4 changes: 0 additions & 4 deletions include/internal/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,6 @@ __owur static ossl_inline int ossl_assert_int(int expr, const char *exprstr,
(((unsigned long)((c)[1]))<< 8)| \
(((unsigned long)((c)[2])) )),(c)+=3)

# define l2n3(l,c) (((c)[0]=(unsigned char)(((l)>>16)&0xff), \
(c)[1]=(unsigned char)(((l)>> 8)&0xff), \
(c)[2]=(unsigned char)(((l) )&0xff)),(c)+=3)

#define l3n2(c,l) (l =((uint64_t)(*((c)++)))<<16, \
l|=((uint64_t)(*((c)++)))<< 8, \
l|=((uint64_t)(*((c)++))))
Expand Down
6 changes: 3 additions & 3 deletions ssl/record/rec_layer_d1.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ int dtls1_read_bytes(SSL *s, uint8_t type, uint8_t *recvd_type,
* Unexpected handshake message (Client Hello, or protocol violation)
*/
if (rr->type == SSL3_RT_HANDSHAKE && !ossl_statem_get_in_handshake(sc)) {
struct hm_header_st msg_hdr;
unsigned char msg_type;

/*
* This may just be a stale retransmit. Also sanity check that we have
Expand All @@ -503,13 +503,13 @@ int dtls1_read_bytes(SSL *s, uint8_t type, uint8_t *recvd_type,
goto start;
}

dtls1_get_message_header(rr->data, &msg_hdr);
msg_type = *rr->data;

/*
* If we are server, we may have a repeated FINISHED of the client
* here, then retransmit our CCS and FINISHED.
*/
if (msg_hdr.type == SSL3_MT_FINISHED) {
if (msg_type == SSL3_MT_FINISHED) {
if (dtls1_check_timeout_num(sc) < 0) {
/* SSLfatal) already called */
return -1;
Expand Down
16 changes: 5 additions & 11 deletions ssl/ssl_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -1943,10 +1943,10 @@ struct dtls1_retransmit_state {

struct hm_header_st {
unsigned char type;
size_t msg_len;
unsigned long msg_len;
unsigned short seq;
size_t frag_off;
size_t frag_len;
unsigned long frag_off;
unsigned long frag_len;
unsigned int is_ccs;
struct dtls1_retransmit_state saved_retransmit_state;
};
Expand Down Expand Up @@ -1995,7 +1995,7 @@ typedef struct dtls1_state_st {
size_t link_mtu; /* max on-the-wire DTLS packet size */
size_t mtu; /* max DTLS packet size */
struct hm_header_st w_msg_hdr;
struct hm_header_st r_msg_hdr;
unsigned short r_msg_seq;
/* Number of alerts received so far */
unsigned int timeout_num_alerts;
/*
Expand Down Expand Up @@ -2706,11 +2706,7 @@ __owur int ssl_get_min_max_version(const SSL_CONNECTION *s, int *min_version,
int *max_version, int *real_max);

__owur OSSL_TIME tls1_default_timeout(void);
__owur int dtls1_do_write(SSL_CONNECTION *s, uint8_t type);
void dtls1_set_message_header(SSL_CONNECTION *s,
unsigned char mt,
size_t len,
size_t frag_off, size_t frag_len);
__owur int dtls1_do_write(SSL_CONNECTION *s, uint8_t recordtype);

int dtls1_write_app_data_bytes(SSL *s, uint8_t type, const void *buf_,
size_t len, size_t *written);
Expand All @@ -2723,8 +2719,6 @@ __owur int dtls1_get_queue_priority(unsigned short seq, int is_ccs);
int dtls1_retransmit_buffered_messages(SSL_CONNECTION *s);
void dtls1_clear_received_buffer(SSL_CONNECTION *s);
void dtls1_clear_sent_buffer(SSL_CONNECTION *s);
void dtls1_get_message_header(const unsigned char *data,
struct hm_header_st *msg_hdr);
__owur OSSL_TIME dtls1_default_timeout(void);
__owur int dtls1_get_timeout(const SSL_CONNECTION *s, OSSL_TIME *timeleft);
__owur int dtls1_check_timeout_num(SSL_CONNECTION *s);
Expand Down
Loading

0 comments on commit 45faed7

Please sign in to comment.