forked from phuslu/nginx-ssl-fingerprint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenssl.openssl-3.2.patch
183 lines (180 loc) · 5.7 KB
/
openssl.openssl-3.2.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
diff --git a/include/openssl/ssl.h.in b/include/openssl/ssl.h.in
index 9f91039f8a..81b9c51892 100644
--- a/include/openssl/ssl.h.in
+++ b/include/openssl/ssl.h.in
@@ -1894,6 +1894,7 @@ size_t SSL_client_hello_get0_ciphers(SSL *s, const unsigned char **out);
size_t SSL_client_hello_get0_compression_methods(SSL *s,
const unsigned char **out);
int SSL_client_hello_get1_extensions_present(SSL *s, int **out, size_t *outlen);
+size_t SSL_client_hello_get_ja3_data(SSL *s, unsigned char *data);
int SSL_client_hello_get_extension_order(SSL *s, uint16_t *exts,
size_t *num_exts);
int SSL_client_hello_get0_ext(SSL *s, unsigned int type,
diff --git a/include/openssl/tls1.h b/include/openssl/tls1.h
index 7e3d1a725b..ecee15e29f 100644
--- a/include/openssl/tls1.h
+++ b/include/openssl/tls1.h
@@ -142,6 +142,13 @@ extern "C" {
/* ExtensionType value from RFC7627 */
# define TLSEXT_TYPE_extended_master_secret 23
+/* ExtensionType value from RFC6961 */
+# define TLSEXT_TYPE_status_request_v2 17
+/* ExtensionType value from RFC8449 */
+# define TLSEXT_TYPE_record_size_limit 28
+/* ExtensionType value from RFC7639 */
+# define TLSEXT_TYPE_application_settings 17513
+
/* ExtensionType value from RFC8879 */
# define TLSEXT_TYPE_compress_certificate 27
diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c
index 26cae27dae..f5d1d8013a 100644
--- a/ssl/ssl_lib.c
+++ b/ssl/ssl_lib.c
@@ -6572,6 +6572,99 @@ int SSL_client_hello_get1_extensions_present(SSL *s, int **out, size_t *outlen)
return 0;
}
+size_t SSL_client_hello_get_ja3_data(SSL *s, unsigned char *data)
+{
+ RAW_EXTENSION *ext;
+ PACKET *groups = NULL, *formats = NULL;
+ size_t num = 0, i;
+ unsigned char *ptr = data;
+ const SSL_CONNECTION *sc = SSL_CONNECTION_FROM_SSL(s);
+
+ if (sc == NULL)
+ return 0;
+
+ if (sc->clienthello == NULL)
+ return 0;
+
+ if (data == NULL) {
+ num = 8 + PACKET_remaining(&sc->clienthello->ciphersuites);
+ for (i = 0; i < sc->clienthello->pre_proc_exts_len; i++) {
+ ext = sc->clienthello->pre_proc_exts + i;
+ if (ext->present) {
+ if (ext->type== TLSEXT_TYPE_supported_groups)
+ groups = &ext->data;
+ if (ext->type== TLSEXT_TYPE_ec_point_formats)
+ formats = &ext->data;
+ num += 2;
+ }
+ }
+ if (groups) {
+ num += PACKET_remaining(groups);
+ }
+ if (formats) {
+ num += PACKET_remaining(formats);
+ }
+ return num;
+ }
+
+ /* version */
+ *(uint16_t*)ptr = (uint16_t)sc->clienthello->legacy_version;
+ ptr += 2;
+
+ /* ciphers */
+ num = PACKET_remaining(&sc->clienthello->ciphersuites);
+ *(uint16_t*)ptr = (uint16_t)num;
+ ptr += 2;
+ memcpy(ptr, PACKET_data(&sc->clienthello->ciphersuites), num);
+ ptr += num;
+
+ /* extensions */
+ num = 0;
+ for (i = 0; i < sc->clienthello->pre_proc_exts_len; i++) {
+ ext = sc->clienthello->pre_proc_exts + i;
+ if (ext->present)
+ num++;
+ }
+ *(uint16_t*)ptr = (uint16_t)num*2;
+ ptr += 2;
+ for (i = 0; i < sc->clienthello->pre_proc_exts_len; i++) {
+ ext = sc->clienthello->pre_proc_exts + i;
+ if (ext->present) {
+ if (ext->received_order >= num)
+ break;
+ if (ext->type== TLSEXT_TYPE_supported_groups)
+ groups = &ext->data;
+ if (ext->type== TLSEXT_TYPE_ec_point_formats)
+ formats = &ext->data;
+ ((uint16_t*)(ptr))[ext->received_order] = (uint16_t)ext->type;
+ }
+ }
+ ptr += num*2;
+
+ /* groups */
+ if (groups) {
+ num = PACKET_remaining(groups);
+ memcpy(ptr, PACKET_data(groups), num);
+ *(uint16_t*)ptr = (uint16_t)num;
+ ptr += num;
+ } else {
+ *(uint16_t*)ptr = 0;
+ ptr += 2;
+ }
+
+ /* formats */
+ if (formats) {
+ num = PACKET_remaining(formats);
+ memcpy(ptr, PACKET_data(formats), num);
+ *ptr = (uint8_t)num;
+ ptr += num;
+ } else {
+ *ptr++ = 0;
+ }
+
+ return ptr - data;
+}
+
int SSL_client_hello_get_extension_order(SSL *s, uint16_t *exts, size_t *num_exts)
{
RAW_EXTENSION *ext;
diff --git a/ssl/ssl_local.h b/ssl/ssl_local.h
index 0d3acfbe66..01ceec6897 100644
--- a/ssl/ssl_local.h
+++ b/ssl/ssl_local.h
@@ -707,6 +707,9 @@ typedef enum tlsext_index_en {
TLSEXT_IDX_compress_certificate,
TLSEXT_IDX_early_data,
TLSEXT_IDX_certificate_authorities,
+ TLSEXT_IDX_status_request_v2,
+ TLSEXT_IDX_record_size_limit,
+ TLSEXT_IDX_application_settings,
TLSEXT_IDX_padding,
TLSEXT_IDX_psk,
/* Dummy index - must always be the last entry */
diff --git a/ssl/statem/extensions.c b/ssl/statem/extensions.c
index 0a64ca2246..9460207d1f 100644
--- a/ssl/statem/extensions.c
+++ b/ssl/statem/extensions.c
@@ -411,6 +411,30 @@ static const EXTENSION_DEFINITION ext_defs[] = {
tls_construct_certificate_authorities,
tls_construct_certificate_authorities, NULL,
},
+ {
+ TLSEXT_TYPE_status_request_v2,
+ SSL_EXT_CLIENT_HELLO,
+ NULL,
+ NULL, NULL,
+ NULL,
+ NULL, NULL,
+ },
+ {
+ TLSEXT_TYPE_record_size_limit,
+ SSL_EXT_CLIENT_HELLO,
+ NULL,
+ NULL, NULL,
+ NULL,
+ NULL, NULL,
+ },
+ {
+ TLSEXT_TYPE_application_settings,
+ SSL_EXT_CLIENT_HELLO,
+ NULL,
+ NULL, NULL,
+ NULL,
+ NULL, NULL,
+ },
{
/* Must be immediately before pre_shared_key */
TLSEXT_TYPE_padding,