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

support signature algorithms embedded in ClientHello message for TLSv1.2 #97

Merged
merged 2 commits into from
Aug 26, 2024
Merged
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
35 changes: 20 additions & 15 deletions tlse.c
Original file line number Diff line number Diff line change
Expand Up @@ -888,13 +888,17 @@ typedef enum {
_md5_sha1 = 255
} TLSHashAlgorithm;

#define TLS_HASH_ALGO_NUMBER (sha512 - md5 + 1)

typedef enum {
anonymous = 0,
rsa = 1,
dsa = 2,
ecdsa = 3
} TLSSignatureAlgorithm;

#define TLS_SIGN_ALGO_NUMBER (ecdsa - rsa + 1)

struct _private_OID_chain {
void *top;
unsigned char *oid;
Expand Down Expand Up @@ -6151,6 +6155,11 @@ struct TLSPacket *tls_build_hello(struct TLSContext *context, int tls13_downgrad
#endif
}
#endif
if ((context->version == TLS_V12) || (context->version == DTLS_V12)) {
// signature algorithms
extension_len += 6 + 2 * TLS_HASH_ALGO_NUMBER * TLS_SIGN_ALGO_NUMBER;
}

tls_packet_uint16(packet, extension_len);

if (sni_len) {
Expand Down Expand Up @@ -6306,25 +6315,21 @@ struct TLSPacket *tls_build_hello(struct TLSContext *context, int tls13_downgrad
#endif
}
}
}
#endif
if ((context->version == TLS_V12) || (context->version == TLS_V13) || (context->version == DTLS_V13)) {
if (!context->is_server) {
// signature algorithms
tls_packet_uint16(packet, 0x0D);
tls_packet_uint16(packet, 24);
tls_packet_uint16(packet, 22);
tls_packet_uint16(packet, 0x0403);
tls_packet_uint16(packet, 0x0503);
tls_packet_uint16(packet, 0x0603);
tls_packet_uint16(packet, 0x0804);
tls_packet_uint16(packet, 0x0805);
tls_packet_uint16(packet, 0x0806);
tls_packet_uint16(packet, 0x0401);
tls_packet_uint16(packet, 0x0501);
tls_packet_uint16(packet, 0x0601);
tls_packet_uint16(packet, 0x0203);
tls_packet_uint16(packet, 0x0201);
tls_packet_uint16(packet, 0x0D); // type
tls_packet_uint16(packet, 2 + 2 * TLS_HASH_ALGO_NUMBER * TLS_SIGN_ALGO_NUMBER); // length
tls_packet_uint16(packet, 2 * TLS_HASH_ALGO_NUMBER * TLS_SIGN_ALGO_NUMBER); // actual length of the list and items themselves further
for (TLSHashAlgorithm hash = md5; !(hash > sha512); ++hash) {
for (TLSSignatureAlgorithm sign = rsa; !(sign > ecdsa); ++sign) {
tls_packet_uint16(packet, ((uint16_t)(hash) << 8) | (sign & 0xFF));
}
}
}
}
#endif

if ((!packet->broken) && (packet->buf)) {
int remaining = packet->len - start_len;
Expand Down